Merge branch 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfashe...
authorLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Oct 2008 23:34:11 +0000 (16:34 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Tue, 14 Oct 2008 23:34:11 +0000 (16:34 -0700)
* 'upstream-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mfasheh/ocfs2: (56 commits)
  ocfs2: Make cached block reads the common case.
  ocfs2: Kill the last naked wait_on_buffer() for cached reads.
  ocfs2: Move ocfs2_bread() into dir.c
  ocfs2: Simplify ocfs2_read_block()
  ocfs2: Require an inode for ocfs2_read_block(s)().
  ocfs2: Separate out sync reads from ocfs2_read_blocks()
  ocfs2: Refactor xattr list and remove ocfs2_xattr_handler().
  ocfs2: Calculate EA hash only by its suffix.
  ocfs2: Move trusted and user attribute support into xattr.c
  ocfs2: Uninline ocfs2_xattr_name_hash()
  ocfs2: Don't check for NULL before brelse()
  ocfs2: use smaller counters in ocfs2_remove_xattr_clusters_from_cache
  ocfs2: Documentation update for user_xattr / nouser_xattr mount options
  ocfs2: make la_debug_mutex static
  ocfs2: Remove pointless !!
  ocfs2: Add empty bucket support in xattr.
  ocfs2/xattr.c: Fix a bug when inserting xattr.
  ocfs2: Add xattr mount option in ocfs2_show_options()
  ocfs2: Switch over to JBD2.
  ocfs2: Add the 'inode64' mount option.
  ...

746 files changed:
Documentation/ABI/testing/sysfs-class-regulator
Documentation/laptops/disk-shock-protection.txt [new file with mode: 0644]
Documentation/pcmcia/driver-changes.txt
Documentation/power/regulator/machine.txt
Documentation/power/regulator/regulator.txt
Documentation/video4linux/CARDLIST.bttv
Documentation/video4linux/CARDLIST.cx23885
Documentation/video4linux/CARDLIST.cx88
Documentation/video4linux/CARDLIST.em28xx
Documentation/video4linux/CARDLIST.saa7134
Documentation/video4linux/CARDLIST.tuner
Documentation/video4linux/gspca.txt
Documentation/video4linux/m5602.txt [new file with mode: 0644]
Documentation/video4linux/soc-camera.txt [new file with mode: 0644]
MAINTAINERS
arch/arm/mach-pxa/include/mach/camera.h
arch/m68k/Kconfig
arch/m68k/amiga/config.c
arch/m68k/atari/Makefile
arch/m68k/atari/ataints.c
arch/m68k/atari/atakeyb.c
arch/m68k/atari/config.c
arch/m68k/atari/hades-pci.c [deleted file]
arch/m68k/atari/time.c
arch/m68k/bvme6000/config.c
arch/m68k/bvme6000/rtc.c
arch/m68k/kernel/Makefile
arch/m68k/kernel/bios32.c [deleted file]
arch/m68k/kernel/dma.c
arch/m68k/kernel/ints.c
arch/m68k/kernel/process.c
arch/m68k/kernel/traps.c
arch/m68k/kernel/vmlinux-std.lds
arch/m68k/mm/kmap.c
arch/m68k/mvme16x/rtc.c
arch/m68k/q40/config.c
arch/m68k/sun3x/time.c
arch/mips/include/asm/mach-generic/ide.h
arch/x86/kernel/rtc.c
arch/xtensa/kernel/setup.c
drivers/acpi/glue.c
drivers/ata/pata_pcmcia.c
drivers/block/ataflop.c
drivers/bluetooth/bluecard_cs.c
drivers/bluetooth/bt3c_cs.c
drivers/bluetooth/btuart_cs.c
drivers/bluetooth/dtl1_cs.c
drivers/char/pcmcia/cm4000_cs.c
drivers/char/pcmcia/cm4040_cs.c
drivers/char/pcmcia/ipwireless/main.c
drivers/char/pcmcia/synclink_cs.c
drivers/char/vt.c
drivers/ide/Kconfig
drivers/ide/Makefile
drivers/ide/arm/icside.c
drivers/ide/h8300/ide-h8300.c
drivers/ide/ide-acpi.c
drivers/ide/ide-atapi.c
drivers/ide/ide-cd.c
drivers/ide/ide-cd.h
drivers/ide/ide-disk.c
drivers/ide/ide-disk.h [new file with mode: 0644]
drivers/ide/ide-disk_ioctl.c [new file with mode: 0644]
drivers/ide/ide-disk_proc.c [new file with mode: 0644]
drivers/ide/ide-dma-sff.c [new file with mode: 0644]
drivers/ide/ide-dma.c
drivers/ide/ide-floppy.c
drivers/ide/ide-floppy.h
drivers/ide/ide-floppy_ioctl.c
drivers/ide/ide-floppy_proc.c [new file with mode: 0644]
drivers/ide/ide-generic.c
drivers/ide/ide-io.c
drivers/ide/ide-ioctls.c
drivers/ide/ide-iops.c
drivers/ide/ide-lib.c
drivers/ide/ide-park.c [new file with mode: 0644]
drivers/ide/ide-probe.c
drivers/ide/ide-proc.c
drivers/ide/ide-tape.c
drivers/ide/ide-taskfile.c
drivers/ide/ide.c
drivers/ide/legacy/ali14xx.c
drivers/ide/legacy/ht6560b.c
drivers/ide/legacy/ide-4drives.c
drivers/ide/legacy/ide-cs.c
drivers/ide/legacy/qd65xx.c
drivers/ide/mips/au1xxx-ide.c
drivers/ide/pci/aec62xx.c
drivers/ide/pci/alim15x3.c
drivers/ide/pci/amd74xx.c
drivers/ide/pci/atiixp.c
drivers/ide/pci/cmd640.c
drivers/ide/pci/cmd64x.c
drivers/ide/pci/cs5520.c
drivers/ide/pci/cs5530.c
drivers/ide/pci/cs5535.c
drivers/ide/pci/cy82c693.c
drivers/ide/pci/delkin_cb.c
drivers/ide/pci/generic.c
drivers/ide/pci/hpt34x.c
drivers/ide/pci/hpt366.c
drivers/ide/pci/it8213.c
drivers/ide/pci/it821x.c
drivers/ide/pci/jmicron.c
drivers/ide/pci/ns87415.c
drivers/ide/pci/opti621.c
drivers/ide/pci/pdc202xx_new.c
drivers/ide/pci/pdc202xx_old.c
drivers/ide/pci/piix.c
drivers/ide/pci/rz1000.c
drivers/ide/pci/sc1200.c
drivers/ide/pci/scc_pata.c
drivers/ide/pci/serverworks.c
drivers/ide/pci/sgiioc4.c
drivers/ide/pci/siimage.c
drivers/ide/pci/sis5513.c
drivers/ide/pci/sl82c105.c
drivers/ide/pci/slc90e66.c
drivers/ide/pci/tc86c001.c
drivers/ide/pci/triflex.c
drivers/ide/pci/trm290.c
drivers/ide/pci/via82cxxx.c
drivers/ide/ppc/pmac.c
drivers/input/misc/hp_sdc_rtc.c
drivers/input/serio/hp_sdc.c
drivers/isdn/hardware/avm/avm_cs.c
drivers/isdn/hisax/avma1_cs.c
drivers/isdn/hisax/elsa_cs.c
drivers/isdn/hisax/sedlbauer_cs.c
drivers/isdn/hisax/teles_cs.c
drivers/isdn/mISDN/dsp_cmx.c
drivers/isdn/mISDN/timerdev.c
drivers/md/Kconfig
drivers/media/common/ir-keymaps.c
drivers/media/common/saa7146_core.c
drivers/media/common/saa7146_fops.c
drivers/media/common/tuners/mt2060.c
drivers/media/common/tuners/mxl5007t.c
drivers/media/common/tuners/tda18271-fe.c
drivers/media/common/tuners/tda827x.c
drivers/media/common/tuners/tda827x.h
drivers/media/common/tuners/tda8290.c
drivers/media/common/tuners/tda8290.h
drivers/media/common/tuners/tda9887.c
drivers/media/common/tuners/tuner-simple.c
drivers/media/common/tuners/tuner-types.c
drivers/media/common/tuners/tuner-xc2028.c
drivers/media/common/tuners/tuner-xc2028.h
drivers/media/common/tuners/xc5000.c
drivers/media/common/tuners/xc5000.h
drivers/media/common/tuners/xc5000_priv.h [deleted file]
drivers/media/dvb/Kconfig
drivers/media/dvb/Makefile
drivers/media/dvb/b2c2/flexcop-dma.c
drivers/media/dvb/bt8xx/dvb-bt8xx.c
drivers/media/dvb/cinergyT2/Kconfig [deleted file]
drivers/media/dvb/cinergyT2/Makefile [deleted file]
drivers/media/dvb/cinergyT2/cinergyT2.c [deleted file]
drivers/media/dvb/dm1105/Kconfig [new file with mode: 0644]
drivers/media/dvb/dm1105/Makefile [new file with mode: 0644]
drivers/media/dvb/dm1105/dm1105.c [new file with mode: 0644]
drivers/media/dvb/dvb-core/dvb_frontend.c
drivers/media/dvb/dvb-core/dvb_frontend.h
drivers/media/dvb/dvb-usb/Kconfig
drivers/media/dvb/dvb-usb/Makefile
drivers/media/dvb/dvb-usb/af9005-remote.c
drivers/media/dvb/dvb-usb/af9005-script.h
drivers/media/dvb/dvb-usb/af9005.c
drivers/media/dvb/dvb-usb/af9015.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/af9015.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/anysee.c
drivers/media/dvb/dvb-usb/cinergyT2-core.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/cinergyT2-fe.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/cinergyT2.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/cxusb.c
drivers/media/dvb/dvb-usb/dib0700.h
drivers/media/dvb/dvb-usb/dib0700_core.c
drivers/media/dvb/dvb-usb/dib0700_devices.c
drivers/media/dvb/dvb-usb/dtv5100.c [new file with mode: 0644]
drivers/media/dvb/dvb-usb/dtv5100.h [new file with mode: 0644]
drivers/media/dvb/dvb-usb/dvb-usb-ids.h
drivers/media/dvb/dvb-usb/dw2102.c
drivers/media/dvb/dvb-usb/dw2102.h
drivers/media/dvb/frontends/Kconfig
drivers/media/dvb/frontends/Makefile
drivers/media/dvb/frontends/af9013.c [new file with mode: 0644]
drivers/media/dvb/frontends/af9013.h [new file with mode: 0644]
drivers/media/dvb/frontends/af9013_priv.h [new file with mode: 0644]
drivers/media/dvb/frontends/au8522.c
drivers/media/dvb/frontends/au8522.h
drivers/media/dvb/frontends/cx24110.h
drivers/media/dvb/frontends/cx24116.c [new file with mode: 0644]
drivers/media/dvb/frontends/cx24116.h [new file with mode: 0644]
drivers/media/dvb/frontends/dib0070.h
drivers/media/dvb/frontends/dib7000m.c
drivers/media/dvb/frontends/dib7000p.c
drivers/media/dvb/frontends/dib7000p.h
drivers/media/dvb/frontends/drx397xD.c
drivers/media/dvb/frontends/drx397xD.h
drivers/media/dvb/frontends/dvb_dummy_fe.c
drivers/media/dvb/frontends/eds1547.h [new file with mode: 0644]
drivers/media/dvb/frontends/lgs8gl5.c [new file with mode: 0644]
drivers/media/dvb/frontends/lgs8gl5.h [new file with mode: 0644]
drivers/media/dvb/frontends/nxt200x.c
drivers/media/dvb/frontends/or51211.c
drivers/media/dvb/frontends/si21xx.c [new file with mode: 0644]
drivers/media/dvb/frontends/si21xx.h [new file with mode: 0644]
drivers/media/dvb/frontends/sp887x.c
drivers/media/dvb/frontends/stb6000.c [new file with mode: 0644]
drivers/media/dvb/frontends/stb6000.h [new file with mode: 0644]
drivers/media/dvb/frontends/stv0288.c [new file with mode: 0644]
drivers/media/dvb/frontends/stv0288.h [new file with mode: 0644]
drivers/media/dvb/frontends/stv0299.c
drivers/media/dvb/frontends/stv0299.h
drivers/media/dvb/frontends/tdhd1.h [new file with mode: 0644]
drivers/media/dvb/ttpci/Kconfig
drivers/media/dvb/ttpci/av7110.c
drivers/media/dvb/ttpci/av7110.h
drivers/media/dvb/ttpci/av7110_av.c
drivers/media/dvb/ttpci/budget-av.c
drivers/media/dvb/ttpci/budget-ci.c
drivers/media/dvb/ttpci/budget-core.c
drivers/media/dvb/ttpci/budget-patch.c
drivers/media/dvb/ttpci/budget.c
drivers/media/dvb/ttpci/budget.h
drivers/media/dvb/ttusb-budget/dvb-ttusb-budget.c
drivers/media/dvb/ttusb-dec/ttusb_dec.c
drivers/media/dvb/ttusb-dec/ttusbdecfe.c
drivers/media/radio/Kconfig
drivers/media/radio/Makefile
drivers/media/radio/dsbr100.c
drivers/media/radio/radio-aimslab.c
drivers/media/radio/radio-aztech.c
drivers/media/radio/radio-cadet.c
drivers/media/radio/radio-gemtek-pci.c
drivers/media/radio/radio-gemtek.c
drivers/media/radio/radio-maestro.c
drivers/media/radio/radio-maxiradio.c
drivers/media/radio/radio-mr800.c [new file with mode: 0644]
drivers/media/radio/radio-rtrack2.c
drivers/media/radio/radio-sf16fmi.c
drivers/media/radio/radio-sf16fmr2.c
drivers/media/radio/radio-si470x.c
drivers/media/radio/radio-terratec.c
drivers/media/radio/radio-trust.c
drivers/media/radio/radio-typhoon.c
drivers/media/radio/radio-zoltrix.c
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/arv.c
drivers/media/video/au0828/au0828-cards.c
drivers/media/video/au0828/au0828-dvb.c
drivers/media/video/au0828/au0828.h
drivers/media/video/bt856.c
drivers/media/video/bt8xx/bttv-cards.c
drivers/media/video/bt8xx/bttv-driver.c
drivers/media/video/bt8xx/bttv-input.c
drivers/media/video/bt8xx/bttv.h
drivers/media/video/btcx-risc.c
drivers/media/video/bw-qcam.c
drivers/media/video/bw-qcam.h
drivers/media/video/c-qcam.c
drivers/media/video/cafe_ccic.c
drivers/media/video/cpia.c
drivers/media/video/cpia2/cpia2_core.c
drivers/media/video/cpia2/cpia2_usb.c
drivers/media/video/cpia2/cpia2_v4l.c
drivers/media/video/cx18/Makefile
drivers/media/video/cx18/cx18-audio.c
drivers/media/video/cx18/cx18-av-core.c
drivers/media/video/cx18/cx18-av-core.h
drivers/media/video/cx18/cx18-av-firmware.c
drivers/media/video/cx18/cx18-cards.c
drivers/media/video/cx18/cx18-driver.c
drivers/media/video/cx18/cx18-driver.h
drivers/media/video/cx18/cx18-dvb.c
drivers/media/video/cx18/cx18-fileops.c
drivers/media/video/cx18/cx18-firmware.c
drivers/media/video/cx18/cx18-gpio.c
drivers/media/video/cx18/cx18-gpio.h
drivers/media/video/cx18/cx18-i2c.c
drivers/media/video/cx18/cx18-io.c [new file with mode: 0644]
drivers/media/video/cx18/cx18-io.h [new file with mode: 0644]
drivers/media/video/cx18/cx18-ioctl.c
drivers/media/video/cx18/cx18-irq.c
drivers/media/video/cx18/cx18-mailbox.c
drivers/media/video/cx18/cx18-queue.c
drivers/media/video/cx18/cx18-scb.c
drivers/media/video/cx18/cx18-streams.c
drivers/media/video/cx18/cx18-version.h
drivers/media/video/cx18/cx23418.h
drivers/media/video/cx2341x.c
drivers/media/video/cx23885/Kconfig
drivers/media/video/cx23885/cx23885-417.c
drivers/media/video/cx23885/cx23885-cards.c
drivers/media/video/cx23885/cx23885-core.c
drivers/media/video/cx23885/cx23885-dvb.c
drivers/media/video/cx23885/cx23885-vbi.c
drivers/media/video/cx23885/cx23885-video.c
drivers/media/video/cx23885/cx23885.h
drivers/media/video/cx25840/cx25840-vbi.c
drivers/media/video/cx88/Kconfig
drivers/media/video/cx88/cx88-blackbird.c
drivers/media/video/cx88/cx88-cards.c
drivers/media/video/cx88/cx88-dvb.c
drivers/media/video/cx88/cx88-i2c.c
drivers/media/video/cx88/cx88-input.c
drivers/media/video/cx88/cx88-video.c
drivers/media/video/cx88/cx88.h
drivers/media/video/dabusb.c
drivers/media/video/dpc7146.c [deleted file]
drivers/media/video/em28xx/em28xx-cards.c
drivers/media/video/em28xx/em28xx-dvb.c
drivers/media/video/em28xx/em28xx-i2c.c
drivers/media/video/em28xx/em28xx-video.c
drivers/media/video/em28xx/em28xx.h
drivers/media/video/et61x251/et61x251_core.c
drivers/media/video/gspca/Kconfig
drivers/media/video/gspca/Makefile
drivers/media/video/gspca/conex.c
drivers/media/video/gspca/etoms.c
drivers/media/video/gspca/finepix.c [new file with mode: 0644]
drivers/media/video/gspca/gspca.c
drivers/media/video/gspca/gspca.h
drivers/media/video/gspca/m5602/Kconfig [new file with mode: 0644]
drivers/media/video/gspca/m5602/Makefile [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_bridge.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_core.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_mt9m111.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_mt9m111.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_ov9650.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_ov9650.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_po1030.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_po1030.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_s5k4aa.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_s5k4aa.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_s5k83a.c [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_s5k83a.h [new file with mode: 0644]
drivers/media/video/gspca/m5602/m5602_sensor.h [new file with mode: 0644]
drivers/media/video/gspca/mars.c
drivers/media/video/gspca/ov519.c
drivers/media/video/gspca/pac207.c
drivers/media/video/gspca/pac7311.c
drivers/media/video/gspca/sonixb.c
drivers/media/video/gspca/sonixj.c
drivers/media/video/gspca/spca500.c
drivers/media/video/gspca/spca501.c
drivers/media/video/gspca/spca505.c
drivers/media/video/gspca/spca506.c
drivers/media/video/gspca/spca508.c
drivers/media/video/gspca/spca561.c
drivers/media/video/gspca/stk014.c
drivers/media/video/gspca/sunplus.c
drivers/media/video/gspca/t613.c
drivers/media/video/gspca/tv8532.c
drivers/media/video/gspca/vc032x.c
drivers/media/video/gspca/zc3xx.c
drivers/media/video/ir-kbd-i2c.c
drivers/media/video/ivtv/ivtv-cards.h
drivers/media/video/ivtv/ivtv-driver.c
drivers/media/video/ivtv/ivtv-driver.h
drivers/media/video/ivtv/ivtv-fileops.c
drivers/media/video/ivtv/ivtv-fileops.h
drivers/media/video/ivtv/ivtv-gpio.c
drivers/media/video/ivtv/ivtv-gpio.h
drivers/media/video/ivtv/ivtv-i2c.c
drivers/media/video/ivtv/ivtv-ioctl.c
drivers/media/video/ivtv/ivtv-irq.c
drivers/media/video/ivtv/ivtv-streams.c
drivers/media/video/ivtv/ivtv-vbi.c
drivers/media/video/ivtv/ivtv-yuv.c
drivers/media/video/ivtv/ivtvfb.c
drivers/media/video/meye.c
drivers/media/video/meye.h
drivers/media/video/mt9m001.c
drivers/media/video/mt9m111.c [new file with mode: 0644]
drivers/media/video/mt9v022.c
drivers/media/video/mxb.c
drivers/media/video/ov511.c
drivers/media/video/ov511.h
drivers/media/video/ovcamchip/ovcamchip_core.c
drivers/media/video/ovcamchip/ovcamchip_priv.h
drivers/media/video/pms.c
drivers/media/video/pvrusb2/pvrusb2-ctrl.c
drivers/media/video/pvrusb2/pvrusb2-ctrl.h
drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
drivers/media/video/pvrusb2/pvrusb2-hdw.c
drivers/media/video/pvrusb2/pvrusb2-hdw.h
drivers/media/video/pvrusb2/pvrusb2-i2c-chips-v4l2.c
drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.c
drivers/media/video/pvrusb2/pvrusb2-i2c-cmd-v4l2.h
drivers/media/video/pvrusb2/pvrusb2-i2c-core.c
drivers/media/video/pvrusb2/pvrusb2-main.c
drivers/media/video/pvrusb2/pvrusb2-sysfs.c
drivers/media/video/pvrusb2/pvrusb2-v4l2.c
drivers/media/video/pwc/pwc-ctrl.c
drivers/media/video/pwc/pwc-if.c
drivers/media/video/pwc/pwc-v4l.c
drivers/media/video/pxa_camera.c
drivers/media/video/s2255drv.c
drivers/media/video/saa5246a.c
drivers/media/video/saa5246a.h [deleted file]
drivers/media/video/saa5249.c
drivers/media/video/saa7115.c
drivers/media/video/saa7134/saa6752hs.c
drivers/media/video/saa7134/saa7134-cards.c
drivers/media/video/saa7134/saa7134-core.c
drivers/media/video/saa7134/saa7134-dvb.c
drivers/media/video/saa7134/saa7134-empress.c
drivers/media/video/saa7134/saa7134-i2c.c
drivers/media/video/saa7134/saa7134-input.c
drivers/media/video/saa7134/saa7134-ts.c
drivers/media/video/saa7134/saa7134-video.c
drivers/media/video/saa7134/saa7134.h
drivers/media/video/se401.c
drivers/media/video/sh_mobile_ceu_camera.c
drivers/media/video/sn9c102/sn9c102_core.c
drivers/media/video/sn9c102/sn9c102_devtable.h
drivers/media/video/sn9c102/sn9c102_hv7131d.c
drivers/media/video/sn9c102/sn9c102_hv7131r.c
drivers/media/video/sn9c102/sn9c102_mi0343.c
drivers/media/video/sn9c102/sn9c102_mi0360.c
drivers/media/video/sn9c102/sn9c102_mt9v111.c
drivers/media/video/sn9c102/sn9c102_ov7630.c
drivers/media/video/sn9c102/sn9c102_ov7660.c
drivers/media/video/sn9c102/sn9c102_pas106b.c
drivers/media/video/sn9c102/sn9c102_pas202bcb.c
drivers/media/video/sn9c102/sn9c102_tas5110c1b.c
drivers/media/video/sn9c102/sn9c102_tas5110d.c
drivers/media/video/sn9c102/sn9c102_tas5130d1b.c
drivers/media/video/stk-webcam.c
drivers/media/video/stk-webcam.h
drivers/media/video/stradis.c
drivers/media/video/stv680.c
drivers/media/video/tda9840.c
drivers/media/video/tda9840.h
drivers/media/video/tea6415c.c
drivers/media/video/tea6420.c
drivers/media/video/tuner-3036.c [deleted file]
drivers/media/video/tuner-core.c
drivers/media/video/usbvideo/ibmcam.c
drivers/media/video/usbvideo/konicawc.c
drivers/media/video/usbvideo/quickcam_messenger.c
drivers/media/video/usbvideo/ultracam.c
drivers/media/video/usbvideo/usbvideo.c
drivers/media/video/usbvideo/vicam.c
drivers/media/video/usbvision/usbvision-core.c
drivers/media/video/usbvision/usbvision-i2c.c
drivers/media/video/usbvision/usbvision-video.c
drivers/media/video/uvc/uvc_ctrl.c
drivers/media/video/uvc/uvc_driver.c
drivers/media/video/uvc/uvc_status.c
drivers/media/video/uvc/uvc_v4l2.c
drivers/media/video/uvc/uvc_video.c
drivers/media/video/uvc/uvcvideo.h
drivers/media/video/v4l2-common.c
drivers/media/video/v4l2-dev.c
drivers/media/video/v4l2-ioctl.c
drivers/media/video/videocodec.c [deleted file]
drivers/media/video/videocodec.h [deleted file]
drivers/media/video/vino.c
drivers/media/video/vivi.c
drivers/media/video/vpx3220.c
drivers/media/video/w9966.c
drivers/media/video/zc0301/zc0301_core.c
drivers/media/video/zoran.h [deleted file]
drivers/media/video/zoran/Kconfig [new file with mode: 0644]
drivers/media/video/zoran/Makefile [new file with mode: 0644]
drivers/media/video/zoran/videocodec.c [new file with mode: 0644]
drivers/media/video/zoran/videocodec.h [new file with mode: 0644]
drivers/media/video/zoran/zoran.h [new file with mode: 0644]
drivers/media/video/zoran/zoran_card.c [new file with mode: 0644]
drivers/media/video/zoran/zoran_card.h [new file with mode: 0644]
drivers/media/video/zoran/zoran_device.c [new file with mode: 0644]
drivers/media/video/zoran/zoran_device.h [new file with mode: 0644]
drivers/media/video/zoran/zoran_driver.c [new file with mode: 0644]
drivers/media/video/zoran/zoran_procfs.c [new file with mode: 0644]
drivers/media/video/zoran/zoran_procfs.h [new file with mode: 0644]
drivers/media/video/zoran/zr36016.c [new file with mode: 0644]
drivers/media/video/zoran/zr36016.h [new file with mode: 0644]
drivers/media/video/zoran/zr36050.c [new file with mode: 0644]
drivers/media/video/zoran/zr36050.h [new file with mode: 0644]
drivers/media/video/zoran/zr36057.h [new file with mode: 0644]
drivers/media/video/zoran/zr36060.c [new file with mode: 0644]
drivers/media/video/zoran/zr36060.h [new file with mode: 0644]
drivers/media/video/zoran_card.c [deleted file]
drivers/media/video/zoran_card.h [deleted file]
drivers/media/video/zoran_device.c [deleted file]
drivers/media/video/zoran_device.h [deleted file]
drivers/media/video/zoran_driver.c [deleted file]
drivers/media/video/zoran_procfs.c [deleted file]
drivers/media/video/zoran_procfs.h [deleted file]
drivers/media/video/zr36016.c [deleted file]
drivers/media/video/zr36016.h [deleted file]
drivers/media/video/zr36050.c [deleted file]
drivers/media/video/zr36050.h [deleted file]
drivers/media/video/zr36057.h [deleted file]
drivers/media/video/zr36060.c [deleted file]
drivers/media/video/zr36060.h [deleted file]
drivers/media/video/zr364xx.c
drivers/mfd/Kconfig
drivers/mfd/Makefile
drivers/mfd/wm8350-core.c [new file with mode: 0644]
drivers/mfd/wm8350-gpio.c [new file with mode: 0644]
drivers/mfd/wm8350-i2c.c [new file with mode: 0644]
drivers/mfd/wm8350-regmap.c [new file with mode: 0644]
drivers/mfd/wm8400-core.c [new file with mode: 0644]
drivers/mtd/maps/pcmciamtd.c
drivers/net/3c501.c
drivers/net/3c515.c
drivers/net/Kconfig
drivers/net/appletalk/cops.c
drivers/net/cxgb3/adapter.h
drivers/net/cxgb3/ael1002.c
drivers/net/cxgb3/common.h
drivers/net/cxgb3/cxgb3_ctl_defs.h
drivers/net/cxgb3/cxgb3_defs.h
drivers/net/cxgb3/cxgb3_ioctl.h
drivers/net/cxgb3/cxgb3_main.c
drivers/net/cxgb3/cxgb3_offload.c
drivers/net/cxgb3/cxgb3_offload.h
drivers/net/cxgb3/firmware_exports.h
drivers/net/cxgb3/l2t.c
drivers/net/cxgb3/l2t.h
drivers/net/cxgb3/mc5.c
drivers/net/cxgb3/sge.c
drivers/net/cxgb3/t3_cpl.h
drivers/net/cxgb3/t3_hw.c
drivers/net/cxgb3/t3cdev.h
drivers/net/cxgb3/version.h
drivers/net/cxgb3/vsc8211.c
drivers/net/cxgb3/xgmac.c
drivers/net/eexpress.c
drivers/net/enic/enic_main.c
drivers/net/ibmlana.c
drivers/net/jme.c
drivers/net/macmace.c
drivers/net/pcmcia/3c574_cs.c
drivers/net/pcmcia/3c589_cs.c
drivers/net/pcmcia/axnet_cs.c
drivers/net/pcmcia/com20020_cs.c
drivers/net/pcmcia/fmvj18x_cs.c
drivers/net/pcmcia/ibmtr_cs.c
drivers/net/pcmcia/nmclan_cs.c
drivers/net/pcmcia/pcnet_cs.c
drivers/net/pcmcia/smc91c92_cs.c
drivers/net/pcmcia/xirc2ps_cs.c
drivers/net/phy/mdio_bus.c
drivers/net/phy/phy_device.c
drivers/net/qlge/qlge.h
drivers/net/qlge/qlge_main.c
drivers/net/tlan.c
drivers/net/tokenring/smctr.c
drivers/net/tulip/de2104x.c
drivers/net/tulip/dmfe.c
drivers/net/via-velocity.c
drivers/net/wan/z85230.c
drivers/net/wan/z85230.h
drivers/net/wireless/airo_cs.c
drivers/net/wireless/atmel_cs.c
drivers/net/wireless/b43/pcmcia.c
drivers/net/wireless/hostap/hostap_cs.c
drivers/net/wireless/libertas/if_cs.c
drivers/net/wireless/netwave_cs.c
drivers/net/wireless/orinoco_cs.c
drivers/net/wireless/ray_cs.c
drivers/net/wireless/spectrum_cs.c
drivers/net/wireless/wavelan.c
drivers/net/wireless/wavelan.p.h
drivers/net/wireless/wavelan_cs.c
drivers/net/wireless/wl3501_cs.c
drivers/parport/parport_cs.c
drivers/pcmcia/Makefile
drivers/pcmcia/au1000_generic.c
drivers/pcmcia/au1000_generic.h
drivers/pcmcia/au1000_pb1x00.c
drivers/pcmcia/au1000_xxs1500.c
drivers/pcmcia/cardbus.c
drivers/pcmcia/cistpl.c
drivers/pcmcia/cs.c
drivers/pcmcia/cs_internal.h
drivers/pcmcia/ds.c
drivers/pcmcia/ds_internal.h [deleted file]
drivers/pcmcia/hd64465_ss.c
drivers/pcmcia/i82365.c
drivers/pcmcia/m32r_cfc.c
drivers/pcmcia/m32r_pcc.c
drivers/pcmcia/m8xx_pcmcia.c
drivers/pcmcia/o2micro.h
drivers/pcmcia/pcmcia_ioctl.c
drivers/pcmcia/pcmcia_resource.c
drivers/pcmcia/pxa2xx_base.c
drivers/pcmcia/rsrc_nonstatic.c
drivers/pcmcia/soc_common.c
drivers/pcmcia/soc_common.h
drivers/pcmcia/socket_sysfs.c
drivers/pcmcia/tcic.c
drivers/pcmcia/ti113x.h
drivers/pcmcia/yenta_socket.c
drivers/regulator/Kconfig
drivers/regulator/Makefile
drivers/regulator/bq24022.c
drivers/regulator/core.c
drivers/regulator/da903x.c [new file with mode: 0644]
drivers/regulator/wm8350-regulator.c [new file with mode: 0644]
drivers/regulator/wm8400-regulator.c [new file with mode: 0644]
drivers/rtc/rtc-cmos.c
drivers/s390/net/claw.c
drivers/scsi/Kconfig
drivers/scsi/atari_dma_emul.c [deleted file]
drivers/scsi/atari_scsi.c
drivers/scsi/ide-scsi.c
drivers/scsi/pcmcia/aha152x_stub.c
drivers/scsi/pcmcia/fdomain_stub.c
drivers/scsi/pcmcia/nsp_cs.c
drivers/scsi/pcmcia/qlogic_stub.c
drivers/scsi/pcmcia/sym53c500_cs.c
drivers/serial/8250.c
drivers/serial/serial_cs.c
drivers/ssb/pcmcia.c
drivers/telephony/ixj_pcmcia.c
drivers/usb/host/sl811_cs.c
drivers/video/console/fbcon.c
drivers/video/console/mdacon.c
drivers/video/console/sticon.c
drivers/video/console/vgacon.c
fs/Kconfig
fs/Makefile
fs/lockd/Makefile
fs/lockd/clntlock.c
fs/lockd/grace.c [new file with mode: 0644]
fs/lockd/host.c
fs/lockd/mon.c
fs/lockd/svc.c
fs/lockd/svc4proc.c
fs/lockd/svclock.c
fs/lockd/svcproc.c
fs/lockd/svcsubs.c
fs/lockd/xdr.c
fs/lockd/xdr4.c
fs/nfs/callback.c
fs/nfsd/lockd.c
fs/nfsd/nfs3proc.c
fs/nfsd/nfs4callback.c
fs/nfsd/nfs4proc.c
fs/nfsd/nfs4state.c
fs/nfsd/nfs4xdr.c
fs/nfsd/nfsctl.c
fs/nfsd/nfsfh.c
fs/nfsd/nfsproc.c
fs/nfsd/nfssvc.c
fs/nfsd/vfs.c
fs/proc/proc_misc.c
include/asm-m68k/atarihw.h
include/asm-m68k/dma-mapping.h
include/asm-m68k/dma.h
include/asm-m68k/entry.h
include/asm-m68k/io.h
include/asm-m68k/pci.h
include/asm-m68k/virtconvert.h
include/linux/console_struct.h
include/linux/dvb/frontend.h
include/linux/dvb/version.h
include/linux/fs.h
include/linux/i2c-id.h
include/linux/ide.h
include/linux/if_ether.h
include/linux/if_fddi.h
include/linux/if_hippi.h
include/linux/igmp.h
include/linux/ivtv.h
include/linux/lockd/bind.h
include/linux/lockd/lockd.h
include/linux/lockd/xdr.h
include/linux/mfd/wm8350/audio.h [new file with mode: 0644]
include/linux/mfd/wm8350/comparator.h [new file with mode: 0644]
include/linux/mfd/wm8350/core.h [new file with mode: 0644]
include/linux/mfd/wm8350/gpio.h [new file with mode: 0644]
include/linux/mfd/wm8350/pmic.h [new file with mode: 0644]
include/linux/mfd/wm8350/rtc.h [new file with mode: 0644]
include/linux/mfd/wm8350/supply.h [new file with mode: 0644]
include/linux/mfd/wm8350/wdt.h [new file with mode: 0644]
include/linux/mfd/wm8400-audio.h [new file with mode: 0644]
include/linux/mfd/wm8400-private.h [new file with mode: 0644]
include/linux/mfd/wm8400.h [new file with mode: 0644]
include/linux/netdevice.h
include/linux/nfsd/nfsd.h
include/linux/regulator/driver.h
include/linux/regulator/machine.h
include/linux/sunrpc/clnt.h
include/linux/sunrpc/svc.h
include/linux/sunrpc/svc_rdma.h
include/linux/sunrpc/svcsock.h
include/linux/videodev2.h
include/media/ir-common.h
include/media/saa7115.h
include/media/saa7146.h
include/media/sh_mobile_ceu.h
include/media/soc_camera.h
include/media/tuner.h
include/media/v4l2-chip-ident.h
include/media/v4l2-common.h
include/media/v4l2-dev.h
include/media/v4l2-ioctl.h
include/pcmcia/ciscode.h
include/pcmcia/cistpl.h
include/pcmcia/cs.h
include/pcmcia/cs_types.h
include/pcmcia/device_id.h
include/pcmcia/ds.h
include/pcmcia/ss.h
include/sound/tea575x-tuner.h
init/do_mounts_md.c
init/main.c
kernel/sys_ni.c
kernel/sysctl.c
net/802/psnap.c
net/appletalk/ddp.c
net/core/datagram.c
net/core/dev_mcast.c
net/core/pktgen.c
net/core/skbuff.c
net/core/stream.c
net/dsa/Kconfig
net/ipv4/icmp.c
net/ipv4/igmp.c
net/ipv4/ip_fragment.c
net/ipv4/ip_input.c
net/ipv4/ipip.c
net/ipv4/ipmr.c
net/ipv4/udp.c
net/ipv6/af_inet6.c
net/netlink/af_netlink.c
net/rfkill/rfkill-input.c
net/sunrpc/clnt.c
net/sunrpc/rpcb_clnt.c
net/sunrpc/svc.c
net/sunrpc/svc_xprt.c
net/sunrpc/svcsock.c
net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
net/sunrpc/xprtrdma/svc_rdma_sendto.c
net/sunrpc/xprtrdma/svc_rdma_transport.c
net/sunrpc/xprtsock.c
net/unix/af_unix.c
scripts/bootgraph.pl [new file with mode: 0644]
sound/i2c/other/tea575x-tuner.c

index 79a4a75b2d2ceb7af8e07c3efa6289c3722d6342..3731f6f29bcb3f07d5551d7fa41f00f8c0c0ed9a 100644 (file)
@@ -1,7 +1,7 @@
 What:          /sys/class/regulator/.../state
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                state. This holds the regulator output state.
@@ -27,7 +27,7 @@ Description:
 What:          /sys/class/regulator/.../type
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                type. This holds the regulator type.
@@ -51,7 +51,7 @@ Description:
 What:          /sys/class/regulator/.../microvolts
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                microvolts. This holds the regulator output voltage setting
@@ -65,7 +65,7 @@ Description:
 What:          /sys/class/regulator/.../microamps
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                microamps. This holds the regulator output current limit
@@ -79,7 +79,7 @@ Description:
 What:          /sys/class/regulator/.../opmode
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                opmode. This holds the regulator operating mode setting.
@@ -102,7 +102,7 @@ Description:
 What:          /sys/class/regulator/.../min_microvolts
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                min_microvolts. This holds the minimum safe working regulator
@@ -116,7 +116,7 @@ Description:
 What:          /sys/class/regulator/.../max_microvolts
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                max_microvolts. This holds the maximum safe working regulator
@@ -130,7 +130,7 @@ Description:
 What:          /sys/class/regulator/.../min_microamps
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                min_microamps. This holds the minimum safe working regulator
@@ -145,7 +145,7 @@ Description:
 What:          /sys/class/regulator/.../max_microamps
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                max_microamps. This holds the maximum safe working regulator
@@ -157,10 +157,23 @@ Description:
                platform code.
 
 
+What:          /sys/class/regulator/.../name
+Date:          October 2008
+KernelVersion: 2.6.28
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
+Description:
+               Each regulator directory will contain a field called
+               name. This holds a string identifying the regulator for
+               display purposes.
+
+               NOTE: this will be empty if no suitable name is provided
+               by platform or regulator drivers.
+
+
 What:          /sys/class/regulator/.../num_users
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                num_users. This holds the number of consumer devices that
@@ -170,7 +183,7 @@ Description:
 What:          /sys/class/regulator/.../requested_microamps
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                requested_microamps. This holds the total requested load
@@ -181,7 +194,7 @@ Description:
 What:          /sys/class/regulator/.../parent
 Date:          April 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Some regulator directories will contain a link called parent.
                This points to the parent or supply regulator if one exists.
@@ -189,7 +202,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_mem_microvolts
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_mem_microvolts. This holds the regulator output
@@ -203,7 +216,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_disk_microvolts
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_disk_microvolts. This holds the regulator output
@@ -217,7 +230,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_standby_microvolts
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_standby_microvolts. This holds the regulator output
@@ -231,7 +244,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_mem_mode
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_mem_mode. This holds the regulator operating mode
@@ -245,7 +258,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_disk_mode
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_disk_mode. This holds the regulator operating mode
@@ -258,7 +271,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_standby_mode
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_standby_mode. This holds the regulator operating mode
@@ -272,7 +285,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_mem_state
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_mem_state. This holds the regulator operating state
@@ -287,7 +300,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_disk_state
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_disk_state. This holds the regulator operating state
@@ -302,7 +315,7 @@ Description:
 What:          /sys/class/regulator/.../suspend_standby_state
 Date:          May 2008
 KernelVersion: 2.6.26
-Contact:       Liam Girdwood <lg@opensource.wolfsonmicro.com>
+Contact:       Liam Girdwood <lrg@slimlogic.co.uk>
 Description:
                Each regulator directory will contain a field called
                suspend_standby_state. This holds the regulator operating
diff --git a/Documentation/laptops/disk-shock-protection.txt b/Documentation/laptops/disk-shock-protection.txt
new file mode 100644 (file)
index 0000000..0e6ba26
--- /dev/null
@@ -0,0 +1,149 @@
+Hard disk shock protection
+==========================
+
+Author: Elias Oltmanns <eo@nebensachen.de>
+Last modified: 2008-10-03
+
+
+0. Contents
+-----------
+
+1. Intro
+2. The interface
+3. References
+4. CREDITS
+
+
+1. Intro
+--------
+
+ATA/ATAPI-7 specifies the IDLE IMMEDIATE command with unload feature.
+Issuing this command should cause the drive to switch to idle mode and
+unload disk heads. This feature is being used in modern laptops in
+conjunction with accelerometers and appropriate software to implement
+a shock protection facility. The idea is to stop all I/O operations on
+the internal hard drive and park its heads on the ramp when critical
+situations are anticipated. The desire to have such a feature
+available on GNU/Linux systems has been the original motivation to
+implement a generic disk head parking interface in the Linux kernel.
+Please note, however, that other components have to be set up on your
+system in order to get disk shock protection working (see
+section 3. References below for pointers to more information about
+that).
+
+
+2. The interface
+----------------
+
+For each ATA device, the kernel exports the file
+block/*/device/unload_heads in sysfs (here assumed to be mounted under
+/sys). Access to /sys/block/*/device/unload_heads is denied with
+-EOPNOTSUPP if the device does not support the unload feature.
+Otherwise, writing an integer value to this file will take the heads
+of the respective drive off the platter and block all I/O operations
+for the specified number of milliseconds. When the timeout expires and
+no further disk head park request has been issued in the meantime,
+normal operation will be resumed. The maximal value accepted for a
+timeout is 30000 milliseconds. Exceeding this limit will return
+-EOVERFLOW, but heads will be parked anyway and the timeout will be
+set to 30 seconds. However, you can always change a timeout to any
+value between 0 and 30000 by issuing a subsequent head park request
+before the timeout of the previous one has expired. In particular, the
+total timeout can exceed 30 seconds and, more importantly, you can
+cancel a previously set timeout and resume normal operation
+immediately by specifying a timeout of 0. Values below -2 are rejected
+with -EINVAL (see below for the special meaning of -1 and -2). If the
+timeout specified for a recent head park request has not yet expired,
+reading from /sys/block/*/device/unload_heads will report the number
+of milliseconds remaining until normal operation will be resumed;
+otherwise, reading the unload_heads attribute will return 0.
+
+For example, do the following in order to park the heads of drive
+/dev/sda and stop all I/O operations for five seconds:
+
+# echo 5000 > /sys/block/sda/device/unload_heads
+
+A simple
+
+# cat /sys/block/sda/device/unload_heads
+
+will show you how many milliseconds are left before normal operation
+will be resumed.
+
+A word of caution: The fact that the interface operates on a basis of
+milliseconds may raise expectations that cannot be satisfied in
+reality. In fact, the ATA specs clearly state that the time for an
+unload operation to complete is vendor specific. The hint in ATA-7
+that this will typically be within 500 milliseconds apparently has
+been dropped in ATA-8.
+
+There is a technical detail of this implementation that may cause some
+confusion and should be discussed here. When a head park request has
+been issued to a device successfully, all I/O operations on the
+controller port this device is attached to will be deferred. That is
+to say, any other device that may be connected to the same port will
+be affected too. The only exception is that a subsequent head unload
+request to that other device will be executed immediately. Further
+operations on that port will be deferred until the timeout specified
+for either device on the port has expired. As far as PATA (old style
+IDE) configurations are concerned, there can only be two devices
+attached to any single port. In SATA world we have port multipliers
+which means that a user-issued head parking request to one device may
+actually result in stopping I/O to a whole bunch of devices. However,
+since this feature is supposed to be used on laptops and does not seem
+to be very useful in any other environment, there will be mostly one
+device per port. Even if the CD/DVD writer happens to be connected to
+the same port as the hard drive, it generally *should* recover just
+fine from the occasional buffer under-run incurred by a head park
+request to the HD. Actually, when you are using an ide driver rather
+than its libata counterpart (i.e. your disk is called /dev/hda
+instead of /dev/sda), then parking the heads of one drive (drive X)
+will generally not affect the mode of operation of another drive
+(drive Y) on the same port as described above. It is only when a port
+reset is required to recover from an exception on drive Y that further
+I/O operations on that drive (and the reset itself) will be delayed
+until drive X is no longer in the parked state.
+
+Finally, there are some hard drives that only comply with an earlier
+version of the ATA standard than ATA-7, but do support the unload
+feature nonetheless. Unfortunately, there is no safe way Linux can
+detect these devices, so you won't be able to write to the
+unload_heads attribute. If you know that your device really does
+support the unload feature (for instance, because the vendor of your
+laptop or the hard drive itself told you so), then you can tell the
+kernel to enable the usage of this feature for that drive by writing
+the special value -1 to the unload_heads attribute:
+
+# echo -1 > /sys/block/sda/device/unload_heads
+
+will enable the feature for /dev/sda, and giving -2 instead of -1 will
+disable it again.
+
+
+3. References
+-------------
+
+There are several laptops from different vendors featuring shock
+protection capabilities. As manufacturers have refused to support open
+source development of the required software components so far, Linux
+support for shock protection varies considerably between different
+hardware implementations. Ideally, this section should contain a list
+of pointers at different projects aiming at an implementation of shock
+protection on different systems. Unfortunately, I only know of a
+single project which, although still considered experimental, is fit
+for use. Please feel free to add projects that have been the victims
+of my ignorance.
+
+- http://www.thinkwiki.org/wiki/HDAPS
+  See this page for information about Linux support of the hard disk
+  active protection system as implemented in IBM/Lenovo Thinkpads.
+
+
+4. CREDITS
+----------
+
+This implementation of disk head parking has been inspired by a patch
+originally published by Jon Escombe <lists@dresco.co.uk>. My efforts
+to develop an implementation of this feature that is fit to be merged
+into mainline have been aided by various kernel developers, in
+particular by Tejun Heo and Bartlomiej Zolnierkiewicz.
index 96f155e687506096e0f694591aa3b9fd722e4a48..059934363cafaf18a15ebff592e167f8c84ee539 100644 (file)
@@ -1,5 +1,11 @@
 This file details changes in 2.6 which affect PCMCIA card driver authors:
 
+* New configuration loop helper (as of 2.6.28)
+   By calling pcmcia_loop_config(), a driver can iterate over all available
+   configuration options. During a driver's probe() phase, one doesn't need
+   to use pcmcia_get_{first,next}_tuple, pcmcia_get_tuple_data and
+   pcmcia_parse_tuple directly in most if not all cases.
+
 * New release helper (as of 2.6.17)
    Instead of calling pcmcia_release_{configuration,io,irq,win}, all that's
    necessary now is calling pcmcia_disable_device. As there is no valid
index c9a35665cf7072c52c92027a715e980c9479a3b7..ce3487d99abedef8b3616740bc3a980d3607bdd3 100644 (file)
@@ -2,17 +2,8 @@ Regulator Machine Driver Interface
 ===================================
 
 The regulator machine driver interface is intended for board/machine specific
-initialisation code to configure the regulator subsystem. Typical things that
-machine drivers would do are :-
+initialisation code to configure the regulator subsystem.
 
- 1. Regulator -> Device mapping.
- 2. Regulator supply configuration.
- 3. Power Domain constraint setting.
-
-
-
-1. Regulator -> device mapping
-==============================
 Consider the following machine :-
 
   Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
@@ -21,81 +12,82 @@ Consider the following machine :-
 
 The drivers for consumers A & B must be mapped to the correct regulator in
 order to control their power supply. This mapping can be achieved in machine
-initialisation code by calling :-
+initialisation code by creating a struct regulator_consumer_supply for
+each regulator.
+
+struct regulator_consumer_supply {
+       struct device *dev;     /* consumer */
+       const char *supply;     /* consumer supply - e.g. "vcc" */
+};
 
-int regulator_set_device_supply(const char *regulator, struct device *dev,
-                               const char *supply);
+e.g. for the machine above
 
-and is shown with the following code :-
+static struct regulator_consumer_supply regulator1_consumers[] = {
+{
+       .dev    = &platform_consumerB_device.dev,
+       .supply = "Vcc",
+},};
 
-regulator_set_device_supply("Regulator-1", devB, "Vcc");
-regulator_set_device_supply("Regulator-2", devA, "Vcc");
+static struct regulator_consumer_supply regulator2_consumers[] = {
+{
+       .dev    = &platform_consumerA_device.dev,
+       .supply = "Vcc",
+},};
 
 This maps Regulator-1 to the 'Vcc' supply for Consumer B and maps Regulator-2
 to the 'Vcc' supply for Consumer A.
 
-
-2. Regulator supply configuration.
-==================================
-Consider the following machine (again) :-
-
-  Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
-               |
-               +-> [Consumer B @ 3.3V]
+Constraints can now be registered by defining a struct regulator_init_data
+for each regulator power domain. This structure also maps the consumers
+to their supply regulator :-
+
+static struct regulator_init_data regulator1_data = {
+       .constraints = {
+               .min_uV = 3300000,
+               .max_uV = 3300000,
+               .valid_modes_mask = REGULATOR_MODE_NORMAL,
+       },
+       .num_consumer_supplies = ARRAY_SIZE(regulator1_consumers),
+       .consumer_supplies = regulator1_consumers,
+};
 
 Regulator-1 supplies power to Regulator-2. This relationship must be registered
 with the core so that Regulator-1 is also enabled when Consumer A enables it's
-supply (Regulator-2).
-
-This relationship can be register with the core via :-
-
-int regulator_set_supply(const char *regulator, const char *regulator_supply);
-
-In this example we would use the following code :-
-
-regulator_set_supply("Regulator-2", "Regulator-1");
-
-Relationships can be queried by calling :-
-
-const char *regulator_get_supply(const char *regulator);
-
-
-3. Power Domain constraint setting.
-===================================
-Each power domain within a system has physical constraints on voltage and
-current. This must be defined in software so that the power domain is always
-operated within specifications.
-
-Consider the following machine (again) :-
-
-  Regulator-1 -+-> Regulator-2 --> [Consumer A @ 1.8 - 2.0V]
-               |
-               +-> [Consumer B @ 3.3V]
-
-This gives us two regulators and two power domains:
-
-                   Domain 1: Regulator-2, Consumer B.
-                   Domain 2: Consumer A.
-
-Constraints can be registered by calling :-
-
-int regulator_set_platform_constraints(const char *regulator,
-       struct regulation_constraints *constraints);
-
-The example is defined as follows :-
-
-struct regulation_constraints domain_1 = {
-       .min_uV = 3300000,
-       .max_uV = 3300000,
-       .valid_modes_mask = REGULATOR_MODE_NORMAL,
+supply (Regulator-2). The supply regulator is set by the supply_regulator_dev
+field below:-
+
+static struct regulator_init_data regulator2_data = {
+       .supply_regulator_dev = &platform_regulator1_device.dev,
+       .constraints = {
+               .min_uV = 1800000,
+               .max_uV = 2000000,
+               .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
+               .valid_modes_mask = REGULATOR_MODE_NORMAL,
+       },
+       .num_consumer_supplies = ARRAY_SIZE(regulator2_consumers),
+       .consumer_supplies = regulator2_consumers,
 };
 
-struct regulation_constraints domain_2 = {
-       .min_uV = 1800000,
-       .max_uV = 2000000,
-       .valid_ops_mask = REGULATOR_CHANGE_VOLTAGE,
-       .valid_modes_mask = REGULATOR_MODE_NORMAL,
+Finally the regulator devices must be registered in the usual manner.
+
+static struct platform_device regulator_devices[] = {
+{
+       .name = "regulator",
+       .id = DCDC_1,
+       .dev = {
+               .platform_data = &regulator1_data,
+       },
+},
+{
+       .name = "regulator",
+       .id = DCDC_2,
+       .dev = {
+               .platform_data = &regulator2_data,
+       },
+},
 };
+/* register regulator 1 device */
+platform_device_register(&wm8350_regulator_devices[0]);
 
-regulator_set_platform_constraints("Regulator-1", &domain_1);
-regulator_set_platform_constraints("Regulator-2", &domain_2);
+/* register regulator 2 device */
+platform_device_register(&wm8350_regulator_devices[1]);
index a69050143592236cdcf39655027c30bb8aeccb47..4200accb9bba981b0c582c6089a6a07fcc215fae 100644 (file)
@@ -10,11 +10,11 @@ Registration
 
 Drivers can register a regulator by calling :-
 
-struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
-                                         void *reg_data);
+struct regulator_dev *regulator_register(struct device *dev,
+       struct regulator_desc *regulator_desc);
 
-This will register the regulators capabilities and operations the regulator
-core. The core does not touch reg_data (private to regulator driver).
+This will register the regulators capabilities and operations to the regulator
+core.
 
 Regulators can be unregistered by calling :-
 
index f32efb6fb12c5111de62f875ec8361af5152e091..60ba66836038215952c9be46dcbff58edb19b319 100644 (file)
 149 -> Typhoon TV-Tuner PCI (50684)
 150 -> Geovision GV-600                                    [008a:763c]
 151 -> Kozumi KTV-01C
+152 -> Encore ENL TV-FM-2                                  [1000:1801]
index f0e613ba55b8bd2f1ed0f39b7e93699ec3b9d5bc..64823ccacd69013ae48401705e7704a39ce38136 100644 (file)
@@ -9,3 +9,5 @@
   8 -> Hauppauge WinTV-HVR1700                             [0070:8101]
   9 -> Hauppauge WinTV-HVR1400                             [0070:8010]
  10 -> DViCO FusionHDTV7 Dual Express                      [18ac:d618]
+ 11 -> DViCO FusionHDTV DVB-T Dual Express                 [18ac:db78]
+ 12 -> Leadtek Winfast PxDVR3200 H                         [107d:6681]
index 7cf5685d36452f64216a0f304e69f7b71ed43703..a5227e308f4ab91146dc2426a2bd694d95d63043 100644 (file)
  65 -> DViCO FusionHDTV 7 Gold                             [18ac:d610]
  66 -> Prolink Pixelview MPEG 8000GT                       [1554:4935]
  67 -> Kworld PlusTV HD PCI 120 (ATSC 120)                 [17de:08c1]
+ 68 -> Hauppauge WinTV-HVR4000 DVB-S/S2/T/Hybrid           [0070:6900,0070:6904,0070:6902]
+ 69 -> Hauppauge WinTV-HVR4000(Lite) DVB-S/S2              [0070:6905,0070:6906]
+ 70 -> TeVii S460 DVB-S/S2                                 [d460:9022]
+ 71 -> Omicom SS4 DVB-S/S2 PCI                             [A044:2011]
+ 72 -> TBS 8920 DVB-S/S2                                   [8920:8888]
+ 73 -> TeVii S420 DVB-S                                    [d420:9022]
+ 74 -> Prolink Pixelview Global Extreme                    [1554:4976]
+ 75 -> PROF 7300 DVB-S/S2                                  [B033:3033]
index 53449cb99b17c71e3714949b090fd2252e7e4492..187cc48d092469a045ccd52fb16d4239bf6c447e 100644 (file)
@@ -1,5 +1,5 @@
   0 -> Unknown EM2800 video grabber             (em2800)        [eb1a:2800]
-  1 -> Unknown EM2750/28xx video grabber        (em2820/em2840) [eb1a:2820,eb1a:2821,eb1a:2860,eb1a:2861,eb1a:2870,eb1a:2881,eb1a:2883]
+  1 -> Unknown EM2750/28xx video grabber        (em2820/em2840) [eb1a:2820,eb1a:2860,eb1a:2861,eb1a:2870,eb1a:2881,eb1a:2883]
   2 -> Terratec Cinergy 250 USB                 (em2820/em2840) [0ccd:0036]
   3 -> Pinnacle PCTV USB 2                      (em2820/em2840) [2304:0208]
   4 -> Hauppauge WinTV USB 2                    (em2820/em2840) [2040:4200,2040:4201]
@@ -12,7 +12,7 @@
  11 -> Terratec Hybrid XS                       (em2880)        [0ccd:0042]
  12 -> Kworld PVR TV 2800 RF                    (em2820/em2840)
  13 -> Terratec Prodigy XS                      (em2880)        [0ccd:0047]
- 14 -> Pixelview Prolink PlayTV USB 2.0         (em2820/em2840)
+ 14 -> Pixelview Prolink PlayTV USB 2.0         (em2820/em2840) [eb1a:2821]
  15 -> V-Gear PocketTV                          (em2800)
  16 -> Hauppauge WinTV HVR 950                  (em2883)        [2040:6513,2040:6517,2040:651b,2040:651f]
  17 -> Pinnacle PCTV HD Pro Stick               (em2880)        [2304:0227]
index 39868af9cf9fe665a6bbd991a4927e55061232d3..dc67eef38ff92071995b9c0d12f901ef4e3837b9 100644 (file)
@@ -76,7 +76,7 @@
  75 -> AVerMedia AVerTVHD MCE A180              [1461:1044]
  76 -> SKNet MonsterTV Mobile                   [1131:4ee9]
  77 -> Pinnacle PCTV 40i/50i/110i (saa7133)     [11bd:002e]
- 78 -> ASUSTeK P7131 Dual                       [1043:4862,1043:4857]
+ 78 -> ASUSTeK P7131 Dual                       [1043:4862]
  79 -> Sedna/MuchTV PC TV Cardbus TV/Radio (ITO25 Rev:2B)
  80 -> ASUS Digimatrix TV                       [1043:0210]
  81 -> Philips Tiger reference design           [1131:2018]
 144 -> Beholder BeholdTV M6 Extra               [5ace:6193]
 145 -> AVerMedia MiniPCI DVB-T Hybrid M103      [1461:f636]
 146 -> ASUSTeK P7131 Analog
+147 -> Asus Tiger 3in1                          [1043:4878]
+148 -> Encore ENLTV-FM v5.3                     [1a7f:2008]
+149 -> Avermedia PCI pure analog (M135A)        [1461:f11d]
+150 -> Zogis Real Angel 220
+151 -> ADS Tech Instant HDTV                    [1421:0380]
+152 -> Asus Tiger Rev:1.00                      [1043:4857]
index 0e2394695bb86843fb89a166eaa83727a2d9a37e..30bbdda68d03bc17dd91b215764ef3aa71f5e614 100644 (file)
@@ -74,3 +74,4 @@ tuner=72 - Thomson FE6600
 tuner=73 - Samsung TCPG 6121P30A
 tuner=75 - Philips TEA5761 FM Radio
 tuner=76 - Xceive 5000 tuner
+tuner=77 - TCL tuner MF02GIP-5N-E
index 9a3e4d797fa858d0925e30d64be6c381fe6bae24..004818fab040ab0bb04078be639c5346a688f772 100644 (file)
@@ -7,6 +7,7 @@ The modules are:
 xxxx           vend:prod
 ----
 spca501                0000:0000       MystFromOri Unknow Camera
+m5602          0402:5602       ALi Video Camera Controller
 spca501                040a:0002       Kodak DVC-325
 spca500                040a:0300       Kodak EZ200
 zc3xx          041e:041e       Creative WebCam Live!
@@ -42,6 +43,7 @@ zc3xx         0458:7007       Genius VideoCam V2
 zc3xx          0458:700c       Genius VideoCam V3
 zc3xx          0458:700f       Genius VideoCam Web V2
 sonixj         0458:7025       Genius Eye 311Q
+sonixj         0458:702e       Genius Slim 310 NB
 sonixj         045e:00f5       MicroSoft VX3000
 sonixj         045e:00f7       MicroSoft VX1000
 ov519          045e:028c       Micro$oft xbox cam
@@ -81,7 +83,7 @@ spca561               046d:092b       Labtec Webcam Plus
 spca561                046d:092c       Logitech QC chat Elch2
 spca561                046d:092d       Logitech QC Elch2
 spca561                046d:092e       Logitech QC Elch2
-spca561                046d:092f       Logitech QC Elch2
+spca561                046d:092f       Logitech  QuickCam Express Plus
 sunplus                046d:0960       Logitech ClickSmart 420
 sunplus                0471:0322       Philips DMVC1300K
 zc3xx          0471:0325       Philips SPC 200 NC
@@ -96,6 +98,29 @@ sunplus              04a5:3003       Benq DC 1300
 sunplus                04a5:3008       Benq DC 1500
 sunplus                04a5:300a       Benq DC 3410
 spca500                04a5:300c       Benq DC 1016
+finepix                04cb:0104       Fujifilm FinePix 4800
+finepix                04cb:0109       Fujifilm FinePix A202
+finepix                04cb:010b       Fujifilm FinePix A203
+finepix                04cb:010f       Fujifilm FinePix A204
+finepix                04cb:0111       Fujifilm FinePix A205
+finepix                04cb:0113       Fujifilm FinePix A210
+finepix                04cb:0115       Fujifilm FinePix A303
+finepix                04cb:0117       Fujifilm FinePix A310
+finepix                04cb:0119       Fujifilm FinePix F401
+finepix                04cb:011b       Fujifilm FinePix F402
+finepix                04cb:011d       Fujifilm FinePix F410
+finepix                04cb:0121       Fujifilm FinePix F601
+finepix                04cb:0123       Fujifilm FinePix F700
+finepix                04cb:0125       Fujifilm FinePix M603
+finepix                04cb:0127       Fujifilm FinePix S300
+finepix                04cb:0129       Fujifilm FinePix S304
+finepix                04cb:012b       Fujifilm FinePix S500
+finepix                04cb:012d       Fujifilm FinePix S602
+finepix                04cb:012f       Fujifilm FinePix S700
+finepix                04cb:0131       Fujifilm FinePix unknown model
+finepix                04cb:013b       Fujifilm FinePix unknown model
+finepix                04cb:013d       Fujifilm FinePix unknown model
+finepix                04cb:013f       Fujifilm FinePix F420
 sunplus                04f1:1001       JVC GC A50
 spca561                04fc:0561       Flexcam 100
 sunplus                04fc:500c       Sunplus CA500C
@@ -181,6 +206,7 @@ pac207              093a:2468       PAC207
 pac207         093a:2470       Genius GF112
 pac207         093a:2471       Genius VideoCam ge111
 pac207         093a:2472       Genius VideoCam ge110
+pac207         093a:2476       Genius e-Messenger 112
 pac7311                093a:2600       PAC7311 Typhoon
 pac7311                093a:2601       Philips SPC 610 NC
 pac7311                093a:2603       PAC7312
diff --git a/Documentation/video4linux/m5602.txt b/Documentation/video4linux/m5602.txt
new file mode 100644 (file)
index 0000000..4450ab1
--- /dev/null
@@ -0,0 +1,12 @@
+This document describes the ALi m5602 bridge connected
+to the following supported sensors:
+OmniVision OV9650,
+Samsung s5k83a,
+Samsung s5k4aa,
+Micron mt9m111,
+Pixel plus PO1030
+
+This driver mimics the windows drivers, which have a braindead implementation sending bayer-encoded frames at VGA resolution.
+In a perfect world we should be able to reprogram the m5602 and the connected sensor in hardware instead, supporting a range of resolutions and pixelformats
+
+Anyway, have fun and please report any bugs to m560x-driver-devel@lists.sourceforge.net
diff --git a/Documentation/video4linux/soc-camera.txt b/Documentation/video4linux/soc-camera.txt
new file mode 100644 (file)
index 0000000..178ef3c
--- /dev/null
@@ -0,0 +1,120 @@
+                       Soc-Camera Subsystem
+                       ====================
+
+Terminology
+-----------
+
+The following terms are used in this document:
+ - camera / camera device / camera sensor - a video-camera sensor chip, capable
+   of connecting to a variety of systems and interfaces, typically uses i2c for
+   control and configuration, and a parallel or a serial bus for data.
+ - camera host - an interface, to which a camera is connected. Typically a
+   specialised interface, present on many SoCs, e.g., PXA27x and PXA3xx, SuperH,
+   AVR32, i.MX27, i.MX31.
+ - camera host bus - a connection between a camera host and a camera. Can be
+   parallel or serial, consists of data and control lines, e.g., clock, vertical
+   and horizontal synchronization signals.
+
+Purpose of the soc-camera subsystem
+-----------------------------------
+
+The soc-camera subsystem provides a unified API between camera host drivers and
+camera sensor drivers. It implements a V4L2 interface to the user, currently
+only the mmap method is supported.
+
+This subsystem has been written to connect drivers for System-on-Chip (SoC)
+video capture interfaces with drivers for CMOS camera sensor chips to enable
+the reuse of sensor drivers with various hosts. The subsystem has been designed
+to support multiple camera host interfaces and multiple cameras per interface,
+although most applications have only one camera sensor.
+
+Existing drivers
+----------------
+
+As of 2.6.27-rc4 there are two host drivers in the mainline: pxa_camera.c for
+PXA27x SoCs and sh_mobile_ceu_camera.c for SuperH SoCs, and four sensor drivers:
+mt9m001.c, mt9m111.c, mt9v022.c and a generic soc_camera_platform.c driver. This
+list is not supposed to be updated, look for more examples in your tree.
+
+Camera host API
+---------------
+
+A host camera driver is registered using the
+
+soc_camera_host_register(struct soc_camera_host *);
+
+function. The host object can be initialized as follows:
+
+static struct soc_camera_host pxa_soc_camera_host = {
+       .drv_name       = PXA_CAM_DRV_NAME,
+       .ops            = &pxa_soc_camera_host_ops,
+};
+
+All camera host methods are passed in a struct soc_camera_host_ops:
+
+static struct soc_camera_host_ops pxa_soc_camera_host_ops = {
+       .owner          = THIS_MODULE,
+       .add            = pxa_camera_add_device,
+       .remove         = pxa_camera_remove_device,
+       .suspend        = pxa_camera_suspend,
+       .resume         = pxa_camera_resume,
+       .set_fmt_cap    = pxa_camera_set_fmt_cap,
+       .try_fmt_cap    = pxa_camera_try_fmt_cap,
+       .init_videobuf  = pxa_camera_init_videobuf,
+       .reqbufs        = pxa_camera_reqbufs,
+       .poll           = pxa_camera_poll,
+       .querycap       = pxa_camera_querycap,
+       .try_bus_param  = pxa_camera_try_bus_param,
+       .set_bus_param  = pxa_camera_set_bus_param,
+};
+
+.add and .remove methods are called when a sensor is attached to or detached
+from the host, apart from performing host-internal tasks they shall also call
+sensor driver's .init and .release methods respectively. .suspend and .resume
+methods implement host's power-management functionality and its their
+responsibility to call respective sensor's methods. .try_bus_param and
+.set_bus_param are used to negotiate physical connection parameters between the
+host and the sensor. .init_videobuf is called by soc-camera core when a
+video-device is opened, further video-buffer management is implemented completely
+by the specific camera host driver. The rest of the methods are called from
+respective V4L2 operations.
+
+Camera API
+----------
+
+Sensor drivers can use struct soc_camera_link, typically provided by the
+platform, and used to specify to which camera host bus the sensor is connected,
+and arbitrarily provide platform .power and .reset methods for the camera.
+soc_camera_device_register() and soc_camera_device_unregister() functions are
+used to add a sensor driver to or remove one from the system. The registration
+function takes a pointer to struct soc_camera_device as the only parameter.
+This struct can be initialized as follows:
+
+       /* link to driver operations */
+       icd->ops        = &mt9m001_ops;
+       /* link to the underlying physical (e.g., i2c) device */
+       icd->control    = &client->dev;
+       /* window geometry */
+       icd->x_min      = 20;
+       icd->y_min      = 12;
+       icd->x_current  = 20;
+       icd->y_current  = 12;
+       icd->width_min  = 48;
+       icd->width_max  = 1280;
+       icd->height_min = 32;
+       icd->height_max = 1024;
+       icd->y_skip_top = 1;
+       /* camera bus ID, typically obtained from platform data */
+       icd->iface      = icl->bus_id;
+
+struct soc_camera_ops provides .probe and .remove methods, which are called by
+the soc-camera core, when a camera is matched against or removed from a camera
+host bus, .init, .release, .suspend, and .resume are called from the camera host
+driver as discussed above. Other members of this struct provide respective V4L2
+functionality.
+
+struct soc_camera_device also links to an array of struct soc_camera_data_format,
+listing pixel formats, supported by the camera.
+
+--
+Author: Guennadi Liakhovetski <g.liakhovetski@gmx.de>
index 74b80820531203f96f51c6ed3c5327f18df5f609..5d0b8a23d63968e8d1c57640024fb2951cb1efcc 100644 (file)
@@ -72,8 +72,8 @@ M: Mail patches to
 L: Mailing list that is relevant to this area
 W: Web-page with status/info
 T: SCM tree type and location.  Type is one of: git, hg, quilt.
-S: Status, one of the following:
 F: Applicable files and/or directories
+S: Status, one of the following:
 
        Supported:      Someone is actually paid to look after this.
        Maintained:     Someone actually looks after it.
@@ -4520,10 +4520,11 @@ S:      Maintained
 
 VOLTAGE AND CURRENT REGULATOR FRAMEWORK
 P:     Liam Girdwood
-M:     lg@opensource.wolfsonmicro.com
+M:     lrg@slimlogic.co.uk
 P:     Mark Brown
 M:     broonie@opensource.wolfsonmicro.com
 W:     http://opensource.wolfsonmicro.com/node/15
+W:     http://www.slimlogic.co.uk/?page_id=5
 T:     git kernel.org/pub/scm/linux/kernel/git/lrg/voltage-2.6.git
 S:     Supported
 
index 39516ced8b1f5470c24463e05211b3faafe3f270..31abe6d514b896b259224cbf48ae01d0213b4893 100644 (file)
@@ -36,8 +36,6 @@
 
 struct pxacamera_platform_data {
        int (*init)(struct device *);
-       int (*power)(struct device *, int);
-       int (*reset)(struct device *, int);
 
        unsigned long flags;
        unsigned long mclk_10khz;
index 41e5bf02e230716f860290555066df3d532440cb..677c93a490f6f49501e4c7d2e375fd42bb4dabc5 100644 (file)
@@ -105,21 +105,9 @@ config PCMCIA
          To compile this driver as modules, choose M here: the
          modules will be called pcmcia_core and ds.
 
-config SUN3
-       bool "Sun3 support"
-       select M68020
-       select MMU_SUN3 if MMU
-       help
-         This option enables support for the Sun 3 series of workstations
-         (3/50, 3/60, 3/1xx, 3/2xx systems). Enabling this option requires
-         that all other hardware types must be disabled, as Sun 3 kernels
-         are incompatible with all other m68k targets (including Sun 3x!).
-
-         If you don't want to compile a kernel exclusively for a Sun 3, say N.
-
 config AMIGA
        bool "Amiga support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          This option enables support for the Amiga series of computers. If
          you plan to use this kernel on an Amiga, say Y here and browse the
@@ -127,33 +115,16 @@ config AMIGA
 
 config ATARI
        bool "Atari support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          This option enables support for the 68000-based Atari series of
          computers (including the TT, Falcon and Medusa). If you plan to use
          this kernel on an Atari, say Y here and browse the material
          available in <file:Documentation/m68k>; otherwise say N.
 
-config HADES
-       bool "Hades support"
-       depends on ATARI && BROKEN
-       help
-         This option enables support for the Hades Atari clone. If you plan
-         to use this kernel on a Hades, say Y here; otherwise say N.
-
-config PCI
-       bool
-       depends on HADES
-       default y
-       help
-         Find out whether you have a PCI motherboard. PCI is the name of a
-         bus system, i.e. the way the CPU talks to the other stuff inside
-         your box. Other bus systems are ISA, EISA, MicroChannel (MCA) or
-         VESA. If you have PCI, say Y, otherwise N.
-
 config MAC
        bool "Macintosh support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          This option enables support for the Apple Macintosh series of
          computers (yes, there is experimental support now, at least for part
@@ -174,14 +145,14 @@ config M68K_L2_CACHE
 
 config APOLLO
        bool "Apollo support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          Say Y here if you want to run Linux on an MC680x0-based Apollo
          Domain workstation such as the DN3500.
 
 config VME
        bool "VME (Motorola and BVM) support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          Say Y here if you want to build a kernel for a 680x0 based VME
          board.  Boards currently supported include Motorola boards MVME147,
@@ -218,7 +189,7 @@ config BVME6000
 
 config HP300
        bool "HP9000/300 and HP9000/400 support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          This option enables support for the HP9000/300 and HP9000/400 series
          of workstations. Support for these machines is still somewhat
@@ -237,7 +208,7 @@ config DIO
 
 config SUN3X
        bool "Sun3x support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        select M68030
        help
          This option enables support for the Sun 3x series of workstations.
@@ -250,7 +221,7 @@ config SUN3X
 
 config Q40
        bool "Q40/Q60 support"
-       depends on !MMU_SUN3
+       select MMU_MOTOROLA if MMU
        help
          The Q40 is a Motorola 68040-based successor to the Sinclair QL
          manufactured in Germany.  There is an official Q40 home page at
@@ -258,6 +229,19 @@ config Q40
          Q60. Select your CPU below.  For 68LC060 don't forget to enable FPU
          emulation.
 
+config SUN3
+       bool "Sun3 support"
+       depends on !MMU_MOTOROLA
+       select MMU_SUN3 if MMU
+       select M68020
+       help
+         This option enables support for the Sun 3 series of workstations
+         (3/50, 3/60, 3/1xx, 3/2xx systems). Enabling this option requires
+         that all other hardware types must be disabled, as Sun 3 kernels
+         are incompatible with all other m68k targets (including Sun 3x!).
+
+         If you don't want to compile a kernel exclusively for a Sun 3, say N.
+
 comment "Processor type"
 
 config M68020
@@ -295,10 +279,10 @@ config M68060
 config MMU_MOTOROLA
        bool
        depends on MMU && !MMU_SUN3
-       default y
 
 config MMU_SUN3
        bool
+       depends on MMU && !MMU_MOTOROLA
 
 config M68KFPU_EMU
        bool "Math emulation support (EXPERIMENTAL)"
index df679d96b1cb790de2b64478cd46306d407f9451..0a3f9e8ebde0db468365abf2a429a11a04c1e934 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/interrupt.h>
 #include <linux/zorro.h>
 #include <linux/module.h>
+#include <linux/keyboard.h>
 
 #include <asm/bootinfo.h>
 #include <asm/setup.h>
@@ -984,3 +985,11 @@ static int amiga_get_hardware_list(char *buffer)
 
        return len;
 }
+
+/*
+ * The Amiga keyboard driver needs key_maps, but we cannot export it in
+ * drivers/char/defkeymap.c, as it is autogenerated
+ */
+#ifdef CONFIG_HW_CONSOLE
+EXPORT_SYMBOL_GPL(key_maps);
+#endif
index 2cd905efe63abb15572d653fd6ee71b485c952b3..0cac723306f936befae82e5e21dc673a36507c5f 100644 (file)
@@ -5,7 +5,4 @@
 obj-y          := config.o time.o debug.o ataints.o stdma.o \
                        atasound.o stram.o
 
-ifeq ($(CONFIG_PCI),y)
-obj-$(CONFIG_HADES)    += hades-pci.o
-endif
 obj-$(CONFIG_ATARI_KBD_CORE)   += atakeyb.o
index b45593a60bddf67bfdb57e611ded063f3b386993..dba4afabb444a41bb7c294475825726e607f1881 100644 (file)
@@ -407,10 +407,8 @@ void __init atari_init_IRQ(void)
                 * gets overruns)
                 */
 
-               if (!MACH_IS_HADES) {
-                       vectors[VEC_INT2] = falcon_hblhandler;
-                       vectors[VEC_INT4] = falcon_hblhandler;
-               }
+               vectors[VEC_INT2] = falcon_hblhandler;
+               vectors[VEC_INT4] = falcon_hblhandler;
        }
 
        if (ATARIHW_PRESENT(PCM_8BIT) && ATARIHW_PRESENT(MICROWIRE)) {
index bb959fbab2dc2b74805052b409142ffd2c43b965..c038b7c7eff0e8ea20f009b83eb4b1658040a229 100644 (file)
@@ -635,15 +635,3 @@ int atari_keyb_init(void)
        return 0;
 }
 EXPORT_SYMBOL_GPL(atari_keyb_init);
-
-int atari_kbd_translate(unsigned char keycode, unsigned char *keycodep, char raw_mode)
-{
-#ifdef CONFIG_MAGIC_SYSRQ
-       /* ALT+HELP pressed? */
-       if ((keycode == 98) && ((shift_state & 0xff) == 8))
-               *keycodep = 0xff;
-       else
-#endif
-               *keycodep = keycode;
-       return 1;
-}
index 5945e15055582821ee0b1adcab4d640c8d3b1b56..af031855f796f4b61bd716f092d5065c97d1bc12 100644 (file)
@@ -231,7 +231,7 @@ void __init config_atari(void)
         */
 
        printk("Atari hardware found: ");
-       if (MACH_IS_MEDUSA || MACH_IS_HADES) {
+       if (MACH_IS_MEDUSA) {
                /* There's no Atari video hardware on the Medusa, but all the
                 * addresses below generate a DTACK so no bus error occurs! */
        } else if (hwreg_present(f030_xreg)) {
@@ -269,10 +269,6 @@ void __init config_atari(void)
                ATARIHW_SET(SCSI_DMA);
                printk("TT_SCSI_DMA ");
        }
-       if (!MACH_IS_HADES && hwreg_present(&st_dma.dma_hi)) {
-               ATARIHW_SET(STND_DMA);
-               printk("STND_DMA ");
-       }
        /*
         * The ST-DMA address registers aren't readable
         * on all Medusas, so the test below may fail
@@ -294,12 +290,11 @@ void __init config_atari(void)
                ATARIHW_SET(YM_2149);
                printk("YM2149 ");
        }
-       if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
-               hwreg_present(&tt_dmasnd.ctrl)) {
+       if (!MACH_IS_MEDUSA && hwreg_present(&tt_dmasnd.ctrl)) {
                ATARIHW_SET(PCM_8BIT);
                printk("PCM ");
        }
-       if (!MACH_IS_HADES && hwreg_present(&falcon_codec.unused5)) {
+       if (hwreg_present(&falcon_codec.unused5)) {
                ATARIHW_SET(CODEC);
                printk("CODEC ");
        }
@@ -313,7 +308,7 @@ void __init config_atari(void)
            (tt_scc_dma.dma_ctrl = 0x01, (tt_scc_dma.dma_ctrl & 1) == 1) &&
            (tt_scc_dma.dma_ctrl = 0x00, (tt_scc_dma.dma_ctrl & 1) == 0)
 #else
-           !MACH_IS_MEDUSA && !MACH_IS_HADES
+           !MACH_IS_MEDUSA
 #endif
            ) {
                ATARIHW_SET(SCC_DMA);
@@ -327,10 +322,7 @@ void __init config_atari(void)
                ATARIHW_SET(ST_ESCC);
                printk("ST_ESCC ");
        }
-       if (MACH_IS_HADES) {
-               ATARIHW_SET(VME);
-               printk("VME ");
-       } else if (hwreg_present(&tt_scu.sys_mask)) {
+       if (hwreg_present(&tt_scu.sys_mask)) {
                ATARIHW_SET(SCU);
                /* Assume a VME bus if there's a SCU */
                ATARIHW_SET(VME);
@@ -340,7 +332,7 @@ void __init config_atari(void)
                ATARIHW_SET(ANALOG_JOY);
                printk("ANALOG_JOY ");
        }
-       if (!MACH_IS_HADES && hwreg_present(blitter.halftone)) {
+       if (hwreg_present(blitter.halftone)) {
                ATARIHW_SET(BLITTER);
                printk("BLITTER ");
        }
@@ -349,8 +341,7 @@ void __init config_atari(void)
                printk("IDE ");
        }
 #if 1 /* This maybe wrong */
-       if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
-           hwreg_present(&tt_microwire.data) &&
+       if (!MACH_IS_MEDUSA && hwreg_present(&tt_microwire.data) &&
            hwreg_present(&tt_microwire.mask) &&
            (tt_microwire.mask = 0x7ff,
             udelay(1),
@@ -369,19 +360,18 @@ void __init config_atari(void)
                mach_hwclk = atari_tt_hwclk;
                mach_set_clock_mmss = atari_tt_set_clock_mmss;
        }
-       if (!MACH_IS_HADES && hwreg_present(&mste_rtc.sec_ones)) {
+       if (hwreg_present(&mste_rtc.sec_ones)) {
                ATARIHW_SET(MSTE_CLK);
                printk("MSTE_CLK ");
                mach_hwclk = atari_mste_hwclk;
                mach_set_clock_mmss = atari_mste_set_clock_mmss;
        }
-       if (!MACH_IS_MEDUSA && !MACH_IS_HADES &&
-           hwreg_present(&dma_wd.fdc_speed) &&
+       if (!MACH_IS_MEDUSA && hwreg_present(&dma_wd.fdc_speed) &&
            hwreg_write(&dma_wd.fdc_speed, 0)) {
                ATARIHW_SET(FDCSPEED);
                printk("FDC_SPEED ");
        }
-       if (!MACH_IS_HADES && !ATARIHW_PRESENT(ST_SCSI)) {
+       if (!ATARIHW_PRESENT(ST_SCSI)) {
                ATARIHW_SET(ACSI);
                printk("ACSI ");
        }
@@ -449,7 +439,7 @@ void __init config_atari(void)
         * 0xFFxxxxxx -> 0x00xxxxxx, so that the first 16MB is accessible
         * in the last 16MB of the address space.
         */
-       tos_version = (MACH_IS_MEDUSA || MACH_IS_HADES) ?
+       tos_version = (MACH_IS_MEDUSA) ?
                        0xfff : *(unsigned short *)0xff000002;
        atari_rtc_year_offset = (tos_version < 0x306) ? 70 : 68;
 }
@@ -511,8 +501,7 @@ static void atari_reset(void)
         * On the Medusa, phys. 0x4 may contain garbage because it's no
         * ROM.  See above for explanation why we cannot use PTOV(4).
         */
-       reset_addr = MACH_IS_HADES ? 0x7fe00030 :
-                    MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 :
+       reset_addr = MACH_IS_MEDUSA || MACH_IS_AB40 ? 0xe00030 :
                     *(unsigned long *) 0xff000004;
 
        /* reset ACIA for switch off OverScan, if it's active */
@@ -606,8 +595,6 @@ static void atari_get_model(char *model)
                if (MACH_IS_MEDUSA)
                        /* Medusa has TT _MCH cookie */
                        strcat(model, "Medusa");
-               else if (MACH_IS_HADES)
-                       strcat(model, "Hades");
                else
                        strcat(model, "TT");
                break;
diff --git a/arch/m68k/atari/hades-pci.c b/arch/m68k/atari/hades-pci.c
deleted file mode 100644 (file)
index 2bbabc0..0000000
+++ /dev/null
@@ -1,440 +0,0 @@
-/*
- * hades-pci.c - Hardware specific PCI BIOS functions the Hades Atari clone.
- *
- * Written by Wout Klaren.
- */
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-#include <asm/io.h>
-
-#if 0
-# define DBG_DEVS(args)                printk args
-#else
-# define DBG_DEVS(args)
-#endif
-
-#if defined(CONFIG_PCI) && defined(CONFIG_HADES)
-
-#include <linux/slab.h>
-#include <linux/mm.h>
-#include <linux/pci.h>
-
-#include <asm/atarihw.h>
-#include <asm/atariints.h>
-#include <asm/byteorder.h>
-#include <asm/pci.h>
-
-#define HADES_MEM_BASE         0x80000000
-#define HADES_MEM_SIZE         0x20000000
-#define HADES_CONFIG_BASE      0xA0000000
-#define HADES_CONFIG_SIZE      0x10000000
-#define HADES_IO_BASE          0xB0000000
-#define HADES_IO_SIZE          0x10000000
-#define HADES_VIRT_IO_SIZE     0x00010000      /* Only 64k is remapped and actually used. */
-
-#define N_SLOTS                                4                       /* Number of PCI slots. */
-
-static const char pci_mem_name[] = "PCI memory space";
-static const char pci_io_name[] = "PCI I/O space";
-static const char pci_config_name[] = "PCI config space";
-
-static struct resource config_space = {
-    .name = pci_config_name,
-    .start = HADES_CONFIG_BASE,
-    .end = HADES_CONFIG_BASE + HADES_CONFIG_SIZE - 1
-};
-static struct resource io_space = {
-    .name = pci_io_name,
-    .start = HADES_IO_BASE,
-    .end = HADES_IO_BASE + HADES_IO_SIZE - 1
-};
-
-static const unsigned long pci_conf_base_phys[] = {
-    0xA0080000, 0xA0040000, 0xA0020000, 0xA0010000
-};
-static unsigned long pci_conf_base_virt[N_SLOTS];
-static unsigned long pci_io_base_virt;
-
-/*
- * static void *mk_conf_addr(unsigned char bus, unsigned char device_fn,
- *                          unsigned char where)
- *
- * Calculate the address of the PCI configuration area of the given
- * device.
- *
- * BUG: boards with multiple functions are probably not correctly
- * supported.
- */
-
-static void *mk_conf_addr(struct pci_dev *dev, int where)
-{
-       int device = dev->devfn >> 3, function = dev->devfn & 7;
-       void *result;
-
-       DBG_DEVS(("mk_conf_addr(bus=%d ,device_fn=0x%x, where=0x%x, pci_addr=0x%p)\n",
-                 dev->bus->number, dev->devfn, where, pci_addr));
-
-       if (device > 3)
-       {
-               DBG_DEVS(("mk_conf_addr: device (%d) > 3, returning NULL\n", device));
-               return NULL;
-       }
-
-       if (dev->bus->number != 0)
-       {
-               DBG_DEVS(("mk_conf_addr: bus (%d) > 0, returning NULL\n", device));
-               return NULL;
-       }
-
-       result = (void *) (pci_conf_base_virt[device] | (function << 8) | (where));
-       DBG_DEVS(("mk_conf_addr: returning pci_addr 0x%lx\n", (unsigned long) result));
-       return result;
-}
-
-static int hades_read_config_byte(struct pci_dev *dev, int where, u8 *value)
-{
-       volatile unsigned char *pci_addr;
-
-       *value = 0xff;
-
-       if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       *value = *pci_addr;
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-static int hades_read_config_word(struct pci_dev *dev, int where, u16 *value)
-{
-       volatile unsigned short *pci_addr;
-
-       *value = 0xffff;
-
-       if (where & 0x1)
-               return PCIBIOS_BAD_REGISTER_NUMBER;
-
-       if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       *value = le16_to_cpu(*pci_addr);
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-static int hades_read_config_dword(struct pci_dev *dev, int where, u32 *value)
-{
-       volatile unsigned int *pci_addr;
-       unsigned char header_type;
-       int result;
-
-       *value = 0xffffffff;
-
-       if (where & 0x3)
-               return PCIBIOS_BAD_REGISTER_NUMBER;
-
-       if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       *value = le32_to_cpu(*pci_addr);
-
-       /*
-        * Check if the value is an address on the bus. If true, add the
-        * base address of the PCI memory or PCI I/O area on the Hades.
-        */
-
-       if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE,
-                                            &header_type)) != PCIBIOS_SUCCESSFUL)
-               return result;
-
-       if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) ||
-           ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) &&
-                                                        (where <= PCI_BASE_ADDRESS_5))))
-       {
-               if ((*value & PCI_BASE_ADDRESS_SPACE) == PCI_BASE_ADDRESS_SPACE_IO)
-               {
-                       /*
-                        * Base address register that contains an I/O address. If the
-                        * address is valid on the Hades (0 <= *value < HADES_VIRT_IO_SIZE),
-                        * add 'pci_io_base_virt' to the value.
-                        */
-
-                       if (*value < HADES_VIRT_IO_SIZE)
-                               *value += pci_io_base_virt;
-               }
-               else
-               {
-                       /*
-                        * Base address register that contains an memory address. If the
-                        * address is valid on the Hades (0 <= *value < HADES_MEM_SIZE),
-                        * add HADES_MEM_BASE to the value.
-                        */
-
-                       if (*value == 0)
-                       {
-                               /*
-                                * Base address is 0. Test if this base
-                                * address register is used.
-                                */
-
-                               *pci_addr = 0xffffffff;
-                               if (*pci_addr != 0)
-                               {
-                                       *pci_addr = *value;
-                                       if (*value < HADES_MEM_SIZE)
-                                               *value += HADES_MEM_BASE;
-                               }
-                       }
-                       else
-                       {
-                               if (*value < HADES_MEM_SIZE)
-                                       *value += HADES_MEM_BASE;
-                       }
-               }
-       }
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-static int hades_write_config_byte(struct pci_dev *dev, int where, u8 value)
-{
-       volatile unsigned char *pci_addr;
-
-       if ((pci_addr = (unsigned char *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       *pci_addr = value;
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-static int hades_write_config_word(struct pci_dev *dev, int where, u16 value)
-{
-       volatile unsigned short *pci_addr;
-
-       if ((pci_addr = (unsigned short *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       *pci_addr = cpu_to_le16(value);
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-static int hades_write_config_dword(struct pci_dev *dev, int where, u32 value)
-{
-       volatile unsigned int *pci_addr;
-       unsigned char header_type;
-       int result;
-
-       if ((pci_addr = (unsigned int *) mk_conf_addr(dev, where)) == NULL)
-               return PCIBIOS_DEVICE_NOT_FOUND;
-
-       /*
-        * Check if the value is an address on the bus. If true, subtract the
-        * base address of the PCI memory or PCI I/O area on the Hades.
-        */
-
-       if ((result = hades_read_config_byte(dev, PCI_HEADER_TYPE,
-                                            &header_type)) != PCIBIOS_SUCCESSFUL)
-               return result;
-
-       if (((where >= PCI_BASE_ADDRESS_0) && (where <= PCI_BASE_ADDRESS_1)) ||
-           ((header_type != PCI_HEADER_TYPE_BRIDGE) && ((where >= PCI_BASE_ADDRESS_2) &&
-                                                        (where <= PCI_BASE_ADDRESS_5))))
-       {
-               if ((value & PCI_BASE_ADDRESS_SPACE) ==
-                   PCI_BASE_ADDRESS_SPACE_IO)
-               {
-                       /*
-                        * I/O address. Check if the address is valid address on
-                        * the Hades (pci_io_base_virt <= value < pci_io_base_virt +
-                        * HADES_VIRT_IO_SIZE) or if the value is 0xffffffff. If not
-                        * true do not write the base address register. If it is a
-                        * valid base address subtract 'pci_io_base_virt' from the value.
-                        */
-
-                       if ((value >= pci_io_base_virt) && (value < (pci_io_base_virt +
-                                                                                                                HADES_VIRT_IO_SIZE)))
-                               value -= pci_io_base_virt;
-                       else
-                       {
-                               if (value != 0xffffffff)
-                                       return PCIBIOS_SET_FAILED;
-                       }
-               }
-               else
-               {
-                       /*
-                        * Memory address. Check if the address is valid address on
-                        * the Hades (HADES_MEM_BASE <= value < HADES_MEM_BASE + HADES_MEM_SIZE) or
-                        * if the value is 0xffffffff. If not true do not write
-                        * the base address register. If it is a valid base address
-                        * subtract HADES_MEM_BASE from the value.
-                        */
-
-                       if ((value >= HADES_MEM_BASE) && (value < (HADES_MEM_BASE + HADES_MEM_SIZE)))
-                               value -= HADES_MEM_BASE;
-                       else
-                       {
-                               if (value != 0xffffffff)
-                                       return PCIBIOS_SET_FAILED;
-                       }
-               }
-       }
-
-       *pci_addr = cpu_to_le32(value);
-
-       return PCIBIOS_SUCCESSFUL;
-}
-
-/*
- * static inline void hades_fixup(void)
- *
- * Assign IRQ numbers as used by Linux to the interrupt pins
- * of the PCI cards.
- */
-
-static void __init hades_fixup(int pci_modify)
-{
-       char irq_tab[4] = {
-               [0] = IRQ_TT_MFP_IO0,           /* Slot 0. */
-               [1] = IRQ_TT_MFP_IO1,           /* Slot 1. */
-               [2] = IRQ_TT_MFP_SCC,           /* Slot 2. */
-               [3] = IRQ_TT_MFP_SCSIDMA        /* Slot 3. */
-       };
-       struct pci_dev *dev = NULL;
-       unsigned char slot;
-
-       /*
-        * Go through all devices, fixing up irqs as we see fit:
-        */
-
-       while ((dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev)) != NULL)
-       {
-               if (dev->class >> 16 != PCI_BASE_CLASS_BRIDGE)
-               {
-                       slot = PCI_SLOT(dev->devfn);    /* Determine slot number. */
-                       dev->irq = irq_tab[slot];
-                       if (pci_modify)
-                               pci_write_config_byte(dev, PCI_INTERRUPT_LINE, dev->irq);
-               }
-       }
-}
-
-/*
- * static void hades_conf_device(struct pci_dev *dev)
- *
- * Machine dependent Configure the given device.
- *
- * Parameters:
- *
- * dev         - the pci device.
- */
-
-static void __init hades_conf_device(struct pci_dev *dev)
-{
-       pci_write_config_byte(dev, PCI_CACHE_LINE_SIZE, 0);
-}
-
-static struct pci_ops hades_pci_ops = {
-       .read_byte =    hades_read_config_byte,
-       .read_word =    hades_read_config_word,
-       .read_dword =   hades_read_config_dword,
-       .write_byte =   hades_write_config_byte,
-       .write_word =   hades_write_config_word,
-       .write_dword =  hades_write_config_dword
-};
-
-/*
- * struct pci_bus_info *init_hades_pci(void)
- *
- * Machine specific initialisation:
- *
- * - Allocate and initialise a 'pci_bus_info' structure
- * - Initialise hardware
- *
- * Result: pointer to 'pci_bus_info' structure.
- */
-
-struct pci_bus_info * __init init_hades_pci(void)
-{
-       struct pci_bus_info *bus;
-       int i;
-
-       /*
-        * Remap I/O and configuration space.
-        */
-
-       pci_io_base_virt = (unsigned long) ioremap(HADES_IO_BASE, HADES_VIRT_IO_SIZE);
-
-       for (i = 0; i < N_SLOTS; i++)
-               pci_conf_base_virt[i] = (unsigned long) ioremap(pci_conf_base_phys[i], 0x10000);
-
-       /*
-        * Allocate memory for bus info structure.
-        */
-
-       bus = kzalloc(sizeof(struct pci_bus_info), GFP_KERNEL);
-       if (unlikely(!bus))
-               goto iounmap_base_virt;
-
-       /*
-        * Claim resources. The m68k has no separate I/O space, both
-        * PCI memory space and PCI I/O space are in memory space. Therefore
-        * the I/O resources are requested in memory space as well.
-        */
-
-       if (unlikely(request_resource(&iomem_resource, &config_space) != 0))
-               goto free_bus;
-
-       if (unlikely(request_resource(&iomem_resource, &io_space) != 0))
-               goto release_config_space;
-
-       bus->mem_space.start = HADES_MEM_BASE;
-       bus->mem_space.end = HADES_MEM_BASE + HADES_MEM_SIZE - 1;
-       bus->mem_space.name = pci_mem_name;
-#if 1
-       if (unlikely(request_resource(&iomem_resource, &bus->mem_space) != 0))
-               goto release_io_space;
-#endif
-       bus->io_space.start = pci_io_base_virt;
-       bus->io_space.end = pci_io_base_virt + HADES_VIRT_IO_SIZE - 1;
-       bus->io_space.name = pci_io_name;
-#if 1
-       if (unlikely(request_resource(&ioport_resource, &bus->io_space) != 0))
-               goto release_bus_mem_space;
-#endif
-       /*
-        * Set hardware dependent functions.
-        */
-
-       bus->m68k_pci_ops = &hades_pci_ops;
-       bus->fixup = hades_fixup;
-       bus->conf_device = hades_conf_device;
-
-       /*
-        * Select high to low edge for PCI interrupts.
-        */
-
-       tt_mfp.active_edge &= ~0x27;
-
-       return bus;
-
-release_bus_mem_space:
-       release_resource(&bus->mem_space);
-release_io_space:
-       release_resource(&io_space);
-release_config_space:
-       release_resource(&config_space);
-free_bus:
-       kfree(bus);
-iounmap_base_virt:
-       iounmap((void *)pci_io_base_virt);
-
-       for (i = 0; i < N_SLOTS; i++)
-               iounmap((void *)pci_conf_base_virt[i]);
-
-       return NULL;
-}
-#endif
index e0d3c8bfb40864791b6c333e3926be8212ba7bc5..1edde27fa32dbb600dd5d07822cfd0bb5281b992 100644 (file)
@@ -20,6 +20,9 @@
 
 #include <asm/atariints.h>
 
+DEFINE_SPINLOCK(rtc_lock);
+EXPORT_SYMBOL_GPL(rtc_lock);
+
 void __init
 atari_sched_init(irq_handler_t timer_routine)
 {
@@ -191,13 +194,14 @@ int atari_tt_hwclk( int op, struct rtc_time *t )
         }
 
         if (!(ctrl & RTC_DM_BINARY)) {
-            BIN_TO_BCD(sec);
-            BIN_TO_BCD(min);
-            BIN_TO_BCD(hour);
-            BIN_TO_BCD(day);
-            BIN_TO_BCD(mon);
-            BIN_TO_BCD(year);
-            if (wday >= 0) BIN_TO_BCD(wday);
+           sec = bin2bcd(sec);
+           min = bin2bcd(min);
+           hour = bin2bcd(hour);
+           day = bin2bcd(day);
+           mon = bin2bcd(mon);
+           year = bin2bcd(year);
+           if (wday >= 0)
+               wday = bin2bcd(wday);
         }
     }
 
@@ -252,13 +256,13 @@ int atari_tt_hwclk( int op, struct rtc_time *t )
        }
 
        if (!(ctrl & RTC_DM_BINARY)) {
-            BCD_TO_BIN(sec);
-            BCD_TO_BIN(min);
-            BCD_TO_BIN(hour);
-            BCD_TO_BIN(day);
-            BCD_TO_BIN(mon);
-            BCD_TO_BIN(year);
-            BCD_TO_BIN(wday);
+           sec = bcd2bin(sec);
+           min = bcd2bin(min);
+           hour = bcd2bin(hour);
+           day = bcd2bin(day);
+           mon = bcd2bin(mon);
+           year = bcd2bin(year);
+           wday = bcd2bin(wday);
         }
 
         if (!(ctrl & RTC_24H)) {
@@ -318,7 +322,7 @@ int atari_tt_set_clock_mmss (unsigned long nowtime)
 
     rtc_minutes = RTC_READ (RTC_MINUTES);
     if (!(save_control & RTC_DM_BINARY))
-        BCD_TO_BIN (rtc_minutes);
+       rtc_minutes = bcd2bin(rtc_minutes);
 
     /* Since we're only adjusting minutes and seconds, don't interfere
        with hour overflow.  This avoids messing with unknown time zones
@@ -329,8 +333,8 @@ int atari_tt_set_clock_mmss (unsigned long nowtime)
         {
             if (!(save_control & RTC_DM_BINARY))
                 {
-                    BIN_TO_BCD (real_seconds);
-                    BIN_TO_BCD (real_minutes);
+                   real_seconds = bin2bcd(real_seconds);
+                   real_minutes = bin2bcd(real_minutes);
                 }
             RTC_WRITE (RTC_SECONDS, real_seconds);
             RTC_WRITE (RTC_MINUTES, real_minutes);
index 9433a88a33c4093866e6ea603182f0975e6b0e54..65c9204ab9ac626aaec3066967bdce9b1792ea60 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/genhd.h>
 #include <linux/rtc.h>
 #include <linux/interrupt.h>
+#include <linux/bcd.h>
 
 #include <asm/bootinfo.h>
 #include <asm/system.h>
@@ -46,9 +47,6 @@ extern void bvme6000_reset (void);
 extern void bvme6000_waitbut(void);
 void bvme6000_set_vectors (void);
 
-static unsigned char bcd2bin (unsigned char b);
-static unsigned char bin2bcd (unsigned char b);
-
 /* Save tick handler routine pointer, will point to do_timer() in
  * kernel/sched.c, called via bvme6000_process_int() */
 
@@ -264,17 +262,6 @@ unsigned long bvme6000_gettimeoffset (void)
     return v;
 }
 
-static unsigned char bcd2bin (unsigned char b)
-{
-       return ((b>>4)*10 + (b&15));
-}
-
-static unsigned char bin2bcd (unsigned char b)
-{
-       return (((b/10)*16) + (b%10));
-}
-
-
 /*
  * Looks like op is non-zero for setting the clock, and zero for
  * reading the clock.
index e8ac3f7d72df6dd457aded95444e69655d16f7c1..808c9018b115022dd2ba8dee88a070fc003448ce 100644 (file)
@@ -57,16 +57,16 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                rtc->msr = 0x40;
                memset(&wtime, 0, sizeof(struct rtc_time));
                do {
-                       wtime.tm_sec =  BCD2BIN(rtc->bcd_sec);
-                       wtime.tm_min =  BCD2BIN(rtc->bcd_min);
-                       wtime.tm_hour = BCD2BIN(rtc->bcd_hr);
-                       wtime.tm_mday =  BCD2BIN(rtc->bcd_dom);
-                       wtime.tm_mon =  BCD2BIN(rtc->bcd_mth)-1;
-                       wtime.tm_year = BCD2BIN(rtc->bcd_year);
+                       wtime.tm_sec =  bcd2bin(rtc->bcd_sec);
+                       wtime.tm_min =  bcd2bin(rtc->bcd_min);
+                       wtime.tm_hour = bcd2bin(rtc->bcd_hr);
+                       wtime.tm_mday =  bcd2bin(rtc->bcd_dom);
+                       wtime.tm_mon =  bcd2bin(rtc->bcd_mth)-1;
+                       wtime.tm_year = bcd2bin(rtc->bcd_year);
                        if (wtime.tm_year < 70)
                                wtime.tm_year += 100;
-                       wtime.tm_wday = BCD2BIN(rtc->bcd_dow)-1;
-               } while (wtime.tm_sec != BCD2BIN(rtc->bcd_sec));
+                       wtime.tm_wday = bcd2bin(rtc->bcd_dow)-1;
+               } while (wtime.tm_sec != bcd2bin(rtc->bcd_sec));
                rtc->msr = msr;
                local_irq_restore(flags);
                return copy_to_user(argp, &wtime, sizeof wtime) ?
@@ -114,14 +114,14 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
 
                rtc->t0cr_rtmr = yrs%4;
                rtc->bcd_tenms = 0;
-               rtc->bcd_sec   = BIN2BCD(sec);
-               rtc->bcd_min   = BIN2BCD(min);
-               rtc->bcd_hr    = BIN2BCD(hrs);
-               rtc->bcd_dom   = BIN2BCD(day);
-               rtc->bcd_mth   = BIN2BCD(mon);
-               rtc->bcd_year  = BIN2BCD(yrs%100);
+               rtc->bcd_sec   = bin2bcd(sec);
+               rtc->bcd_min   = bin2bcd(min);
+               rtc->bcd_hr    = bin2bcd(hrs);
+               rtc->bcd_dom   = bin2bcd(day);
+               rtc->bcd_mth   = bin2bcd(mon);
+               rtc->bcd_year  = bin2bcd(yrs%100);
                if (rtc_tm.tm_wday >= 0)
-                       rtc->bcd_dow = BIN2BCD(rtc_tm.tm_wday+1);
+                       rtc->bcd_dow = bin2bcd(rtc_tm.tm_wday+1);
                rtc->t0cr_rtmr = yrs%4 | 0x08;
 
                rtc->msr = msr;
index 3a7f622255045e958a1d4f733978b06eb89f1950..55d5d6b680a211376390499ee2aee7d2e5d41b61 100644 (file)
@@ -14,5 +14,4 @@ obj-y := entry.o process.o traps.o ints.o signal.o ptrace.o module.o \
 
 devres-y = ../../../kernel/irq/devres.o
 
-obj-$(CONFIG_PCI)      += bios32.o
 obj-y$(CONFIG_MMU_SUN3) += dma.o       # no, it's not a typo
diff --git a/arch/m68k/kernel/bios32.c b/arch/m68k/kernel/bios32.c
deleted file mode 100644 (file)
index af170c2..0000000
+++ /dev/null
@@ -1,514 +0,0 @@
-/*
- * bios32.c - PCI BIOS functions for m68k systems.
- *
- * Written by Wout Klaren.
- *
- * Based on the DEC Alpha bios32.c by Dave Rusling and David Mosberger.
- */
-
-#include <linux/init.h>
-#include <linux/kernel.h>
-
-#if 0
-# define DBG_DEVS(args)                printk args
-#else
-# define DBG_DEVS(args)
-#endif
-
-#ifdef CONFIG_PCI
-
-/*
- * PCI support for Linux/m68k. Currently only the Hades is supported.
- *
- * The support for PCI bridges in the DEC Alpha version has
- * been removed in this version.
- */
-
-#include <linux/pci.h>
-#include <linux/slab.h>
-#include <linux/mm.h>
-
-#include <asm/io.h>
-#include <asm/pci.h>
-#include <asm/uaccess.h>
-
-#define KB             1024
-#define MB             (1024*KB)
-#define GB             (1024*MB)
-
-#define MAJOR_REV      0
-#define MINOR_REV      5
-
-/*
- * Align VAL to ALIGN, which must be a power of two.
- */
-
-#define ALIGN(val,align)       (((val) + ((align) - 1)) & ~((align) - 1))
-
-/*
- * Offsets relative to the I/O and memory base addresses from where resources
- * are allocated.
- */
-
-#define IO_ALLOC_OFFSET                0x00004000
-#define MEM_ALLOC_OFFSET       0x04000000
-
-/*
- * Declarations of hardware specific initialisation functions.
- */
-
-extern struct pci_bus_info *init_hades_pci(void);
-
-/*
- * Bus info structure of the PCI bus. A pointer to this structure is
- * put in the sysdata member of the pci_bus structure.
- */
-
-static struct pci_bus_info *bus_info;
-
-static int pci_modify = 1;             /* If set, layout the PCI bus ourself. */
-static int skip_vga;                   /* If set do not modify base addresses
-                                          of vga cards.*/
-static int disable_pci_burst;          /* If set do not allow PCI bursts. */
-
-static unsigned int io_base;
-static unsigned int mem_base;
-
-/*
- * static void disable_dev(struct pci_dev *dev)
- *
- * Disable PCI device DEV so that it does not respond to I/O or memory
- * accesses.
- *
- * Parameters:
- *
- * dev - device to disable.
- */
-
-static void __init disable_dev(struct pci_dev *dev)
-{
-       unsigned short cmd;
-
-       if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) ||
-            (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) ||
-            (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga)
-               return;
-
-       pci_read_config_word(dev, PCI_COMMAND, &cmd);
-
-       cmd &= (~PCI_COMMAND_IO & ~PCI_COMMAND_MEMORY & ~PCI_COMMAND_MASTER);
-       pci_write_config_word(dev, PCI_COMMAND, cmd);
-}
-
-/*
- * static void layout_dev(struct pci_dev *dev)
- *
- * Layout memory and I/O for a device.
- *
- * Parameters:
- *
- * device      - device to layout memory and I/O for.
- */
-
-static void __init layout_dev(struct pci_dev *dev)
-{
-       unsigned short cmd;
-       unsigned int base, mask, size, reg;
-       unsigned int alignto;
-       int i;
-
-       /*
-        * Skip video cards if requested.
-        */
-
-       if (((dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA) ||
-            (dev->class >> 8 == PCI_CLASS_DISPLAY_VGA) ||
-            (dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)) && skip_vga)
-               return;
-
-       pci_read_config_word(dev, PCI_COMMAND, &cmd);
-
-       for (reg = PCI_BASE_ADDRESS_0, i = 0; reg <= PCI_BASE_ADDRESS_5; reg += 4, i++)
-       {
-               /*
-                * Figure out how much space and of what type this
-                * device wants.
-                */
-
-               pci_write_config_dword(dev, reg, 0xffffffff);
-               pci_read_config_dword(dev, reg, &base);
-
-               if (!base)
-               {
-                       /* this base-address register is unused */
-                       dev->resource[i].start = 0;
-                       dev->resource[i].end = 0;
-                       dev->resource[i].flags = 0;
-                       continue;
-               }
-
-               /*
-                * We've read the base address register back after
-                * writing all ones and so now we must decode it.
-                */
-
-               if (base & PCI_BASE_ADDRESS_SPACE_IO)
-               {
-                       /*
-                        * I/O space base address register.
-                        */
-
-                       cmd |= PCI_COMMAND_IO;
-
-                       base &= PCI_BASE_ADDRESS_IO_MASK;
-                       mask = (~base << 1) | 0x1;
-                       size = (mask & base) & 0xffffffff;
-
-                       /*
-                        * Align to multiple of size of minimum base.
-                        */
-
-                       alignto = max_t(unsigned int, 0x040, size);
-                       base = ALIGN(io_base, alignto);
-                       io_base = base + size;
-                       pci_write_config_dword(dev, reg, base | PCI_BASE_ADDRESS_SPACE_IO);
-
-                       dev->resource[i].start = base;
-                       dev->resource[i].end = dev->resource[i].start + size - 1;
-                       dev->resource[i].flags = IORESOURCE_IO | PCI_BASE_ADDRESS_SPACE_IO;
-
-                       DBG_DEVS(("layout_dev: IO address: %lX\n", base));
-               }
-               else
-               {
-                       unsigned int type;
-
-                       /*
-                        * Memory space base address register.
-                        */
-
-                       cmd |= PCI_COMMAND_MEMORY;
-                       type = base & PCI_BASE_ADDRESS_MEM_TYPE_MASK;
-                       base &= PCI_BASE_ADDRESS_MEM_MASK;
-                       mask = (~base << 1) | 0x1;
-                       size = (mask & base) & 0xffffffff;
-                       switch (type)
-                       {
-                       case PCI_BASE_ADDRESS_MEM_TYPE_32:
-                       case PCI_BASE_ADDRESS_MEM_TYPE_64:
-                               break;
-
-                       case PCI_BASE_ADDRESS_MEM_TYPE_1M:
-                               printk("bios32 WARNING: slot %d, function %d "
-                                      "requests memory below 1MB---don't "
-                                      "know how to do that.\n",
-                                      PCI_SLOT(dev->devfn),
-                                      PCI_FUNC(dev->devfn));
-                               continue;
-                       }
-
-                       /*
-                        * Align to multiple of size of minimum base.
-                        */
-
-                       alignto = max_t(unsigned int, 0x1000, size);
-                       base = ALIGN(mem_base, alignto);
-                       mem_base = base + size;
-                       pci_write_config_dword(dev, reg, base);
-
-                       dev->resource[i].start = base;
-                       dev->resource[i].end = dev->resource[i].start + size - 1;
-                       dev->resource[i].flags = IORESOURCE_MEM;
-
-                       if (type == PCI_BASE_ADDRESS_MEM_TYPE_64)
-                       {
-                               /*
-                                * 64-bit address, set the highest 32 bits
-                                * to zero.
-                                */
-
-                               reg += 4;
-                               pci_write_config_dword(dev, reg, 0);
-
-                               i++;
-                               dev->resource[i].start = 0;
-                               dev->resource[i].end = 0;
-                               dev->resource[i].flags = 0;
-                       }
-               }
-       }
-
-       /*
-        * Enable device:
-        */
-
-       if (dev->class >> 8 == PCI_CLASS_NOT_DEFINED ||
-           dev->class >> 8 == PCI_CLASS_NOT_DEFINED_VGA ||
-           dev->class >> 8 == PCI_CLASS_DISPLAY_VGA ||
-           dev->class >> 8 == PCI_CLASS_DISPLAY_XGA)
-       {
-               /*
-                * All of these (may) have I/O scattered all around
-                * and may not use i/o-base address registers at all.
-                * So we just have to always enable I/O to these
-                * devices.
-                */
-               cmd |= PCI_COMMAND_IO;
-       }
-
-       pci_write_config_word(dev, PCI_COMMAND, cmd | PCI_COMMAND_MASTER);
-
-       pci_write_config_byte(dev, PCI_LATENCY_TIMER, (disable_pci_burst) ? 0 : 32);
-
-       if (bus_info != NULL)
-               bus_info->conf_device(dev);     /* Machine dependent configuration. */
-
-       DBG_DEVS(("layout_dev: bus %d  slot 0x%x  VID 0x%x  DID 0x%x  class 0x%x\n",
-                 dev->bus->number, PCI_SLOT(dev->devfn), dev->vendor, dev->device, dev->class));
-}
-
-/*
- * static void layout_bus(struct pci_bus *bus)
- *
- * Layout memory and I/O for all devices on the given bus.
- *
- * Parameters:
- *
- * bus - bus.
- */
-
-static void __init layout_bus(struct pci_bus *bus)
-{
-       unsigned int bio, bmem;
-       struct pci_dev *dev;
-
-       DBG_DEVS(("layout_bus: starting bus %d\n", bus->number));
-
-       if (!bus->devices && !bus->children)
-               return;
-
-       /*
-        * Align the current bases on appropriate boundaries (4K for
-        * IO and 1MB for memory).
-        */
-
-       bio = io_base = ALIGN(io_base, 4*KB);
-       bmem = mem_base = ALIGN(mem_base, 1*MB);
-
-       /*
-        * PCI devices might have been setup by a PCI BIOS emulation
-        * running under TOS. In these cases there is a
-        * window during which two devices may have an overlapping
-        * address range. To avoid this causing trouble, we first
-        * turn off the I/O and memory address decoders for all PCI
-        * devices.  They'll be re-enabled only once all address
-        * decoders are programmed consistently.
-        */
-
-       DBG_DEVS(("layout_bus: disable_dev for bus %d\n", bus->number));
-
-       for (dev = bus->devices; dev; dev = dev->sibling)
-       {
-               if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) ||
-                   (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA))
-                       disable_dev(dev);
-       }
-
-       /*
-        * Allocate space to each device:
-        */
-
-       DBG_DEVS(("layout_bus: starting bus %d devices\n", bus->number));
-
-       for (dev = bus->devices; dev; dev = dev->sibling)
-       {
-               if ((dev->class >> 16 != PCI_BASE_CLASS_BRIDGE) ||
-                   (dev->class >> 8 == PCI_CLASS_BRIDGE_PCMCIA))
-                       layout_dev(dev);
-       }
-
-       DBG_DEVS(("layout_bus: bus %d finished\n", bus->number));
-}
-
-/*
- * static void pcibios_fixup(void)
- *
- * Layout memory and I/O of all devices on the PCI bus if 'pci_modify' is
- * true. This might be necessary because not every m68k machine with a PCI
- * bus has a PCI BIOS. This function should be called right after
- * pci_scan_bus() in pcibios_init().
- */
-
-static void __init pcibios_fixup(void)
-{
-       if (pci_modify)
-       {
-               /*
-                * Set base addresses for allocation of I/O and memory space.
-                */
-
-               io_base = bus_info->io_space.start + IO_ALLOC_OFFSET;
-               mem_base = bus_info->mem_space.start + MEM_ALLOC_OFFSET;
-
-               /*
-                * Scan the tree, allocating PCI memory and I/O space.
-                */
-
-               layout_bus(pci_bus_b(pci_root.next));
-       }
-
-       /*
-        * Fix interrupt assignments, etc.
-        */
-
-       bus_info->fixup(pci_modify);
-}
-
-/*
- * static void pcibios_claim_resources(struct pci_bus *bus)
- *
- * Claim all resources that are assigned to devices on the given bus.
- *
- * Parameters:
- *
- * bus - bus.
- */
-
-static void __init pcibios_claim_resources(struct pci_bus *bus)
-{
-       struct pci_dev *dev;
-       int i;
-
-       while (bus)
-       {
-               for (dev = bus->devices; (dev != NULL); dev = dev->sibling)
-               {
-                       for (i = 0; i < PCI_NUM_RESOURCES; i++)
-                       {
-                               struct resource *r = &dev->resource[i];
-                               struct resource *pr;
-                               struct pci_bus_info *bus_info = (struct pci_bus_info *) dev->sysdata;
-
-                               if ((r->start == 0) || (r->parent != NULL))
-                                       continue;
-#if 1
-                               if (r->flags & IORESOURCE_IO)
-                                       pr = &bus_info->io_space;
-                               else
-                                       pr = &bus_info->mem_space;
-#else
-                               if (r->flags & IORESOURCE_IO)
-                                       pr = &ioport_resource;
-                               else
-                                       pr = &iomem_resource;
-#endif
-                               if (request_resource(pr, r) < 0)
-                               {
-                                       printk(KERN_ERR "PCI: Address space collision on region %d of device %s\n", i, dev->name);
-                               }
-                       }
-               }
-
-               if (bus->children)
-                       pcibios_claim_resources(bus->children);
-
-               bus = bus->next;
-       }
-}
-
-/*
- * int pcibios_assign_resource(struct pci_dev *dev, int i)
- *
- * Assign a new address to a PCI resource.
- *
- * Parameters:
- *
- * dev - device.
- * i   - resource.
- *
- * Result: 0 if successful.
- */
-
-int __init pcibios_assign_resource(struct pci_dev *dev, int i)
-{
-       struct resource *r = &dev->resource[i];
-       struct resource *pr = pci_find_parent_resource(dev, r);
-       unsigned long size = r->end + 1;
-
-       if (!pr)
-               return -EINVAL;
-
-       if (r->flags & IORESOURCE_IO)
-       {
-               if (size > 0x100)
-                       return -EFBIG;
-
-               if (allocate_resource(pr, r, size, bus_info->io_space.start +
-                                     IO_ALLOC_OFFSET,  bus_info->io_space.end, 1024))
-                       return -EBUSY;
-       }
-       else
-       {
-               if (allocate_resource(pr, r, size, bus_info->mem_space.start +
-                                     MEM_ALLOC_OFFSET, bus_info->mem_space.end, size))
-                       return -EBUSY;
-       }
-
-       if (i < 6)
-               pci_write_config_dword(dev, PCI_BASE_ADDRESS_0 + 4 * i, r->start);
-
-       return 0;
-}
-
-void __init pcibios_fixup_bus(struct pci_bus *bus)
-{
-       struct pci_dev *dev;
-       void *sysdata;
-
-       sysdata = (bus->parent) ? bus->parent->sysdata : bus->sysdata;
-
-       for (dev = bus->devices; (dev != NULL); dev = dev->sibling)
-               dev->sysdata = sysdata;
-}
-
-void __init pcibios_init(void)
-{
-       printk("Linux/m68k PCI BIOS32 revision %x.%02x\n", MAJOR_REV, MINOR_REV);
-
-       bus_info = NULL;
-#ifdef CONFIG_HADES
-       if (MACH_IS_HADES)
-               bus_info = init_hades_pci();
-#endif
-       if (bus_info != NULL)
-       {
-               printk("PCI: Probing PCI hardware\n");
-               pci_scan_bus(0, bus_info->m68k_pci_ops, bus_info);
-               pcibios_fixup();
-               pcibios_claim_resources(pci_root);
-       }
-       else
-               printk("PCI: No PCI bus detected\n");
-}
-
-char * __init pcibios_setup(char *str)
-{
-       if (!strcmp(str, "nomodify"))
-       {
-               pci_modify = 0;
-               return NULL;
-       }
-       else if (!strcmp(str, "skipvga"))
-       {
-               skip_vga = 1;
-               return NULL;
-       }
-       else if (!strcmp(str, "noburst"))
-       {
-               disable_pci_burst = 1;
-               return NULL;
-       }
-
-       return str;
-}
-#endif /* CONFIG_PCI */
index 6f8c080dd9f9d24979f23adefb086810b7c2ae65..2bb4245404d836ca73e770ed24146f7c6c78e9b4 100644 (file)
@@ -66,8 +66,8 @@ void dma_free_coherent(struct device *dev, size_t size,
 }
 EXPORT_SYMBOL(dma_free_coherent);
 
-inline void dma_sync_single_for_device(struct device *dev, dma_addr_t handle, size_t size,
-                                      enum dma_data_direction dir)
+void dma_sync_single_for_device(struct device *dev, dma_addr_t handle,
+                               size_t size, enum dma_data_direction dir)
 {
        switch (dir) {
        case DMA_TO_DEVICE:
index ded7dd2f67b2803688965a49f0abb72faf1e0463..7e8a0d394e6184cbf63a5fb257befa4082ce0148 100644 (file)
@@ -429,8 +429,9 @@ int show_interrupts(struct seq_file *p, void *v)
        return 0;
 }
 
+#ifdef CONFIG_PROC_FS
 void init_irq_proc(void)
 {
        /* Insert /proc/irq driver here */
 }
-
+#endif
index 7888cdf91f5dafba1d157547d8ddb4b1a7f268a9..3042c2bc8c58490083ef4a2718c6a839c4e7e978 100644 (file)
@@ -78,7 +78,7 @@ unsigned long thread_saved_pc(struct task_struct *tsk)
 static void default_idle(void)
 {
        if (!need_resched())
-#if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES)
+#if defined(MACH_ATARI_ONLY)
                /* block out HSYNC on the atari (falcon) */
                __asm__("stop #0x2200" : : : "cc");
 #else
index 75b8340b254be08caa07f9e29eac3cbb5e5f0161..6d813de2baf183472f9a95379505e602508845c7 100644 (file)
@@ -883,8 +883,7 @@ void show_trace(unsigned long *stack)
                        if (i % 5 == 0)
                                printk("\n       ");
 #endif
-                       printk(" [<%08lx>]", addr);
-                       print_symbol(" %s\n", addr);
+                       printk(" [<%08lx>] %pS\n", addr, (void *)addr);
                        i++;
                }
        }
@@ -900,10 +899,8 @@ void show_registers(struct pt_regs *regs)
        int i;
 
        print_modules();
-       printk("PC: [<%08lx>]",regs->pc);
-       print_symbol(" %s", regs->pc);
-       printk("\nSR: %04x  SP: %p  a2: %08lx\n",
-              regs->sr, regs, regs->a2);
+       printk("PC: [<%08lx>] %pS\n", regs->pc, (void *)regs->pc);
+       printk("SR: %04x  SP: %p  a2: %08lx\n", regs->sr, regs, regs->a2);
        printk("d0: %08lx    d1: %08lx    d2: %08lx    d3: %08lx\n",
               regs->d0, regs->d1, regs->d2, regs->d3);
        printk("d4: %08lx    d5: %08lx    a0: %08lx    a1: %08lx\n",
index 99b0784c0552a094cb629f26ae3827e469d17a36..f846d4e3e5e1f23a179ec47e69bbb09488a0c3c8 100644 (file)
@@ -34,10 +34,10 @@ SECTIONS
        CONSTRUCTORS
        }
 
-  .bss : { *(.bss) }           /* BSS */
-
   . = ALIGN(16);
-  .data.cacheline_aligned : { *(.data.cacheline_aligned) } :data
+  .data.cacheline_aligned : { *(.data.cacheline_aligned) }
+
+  .bss : { *(.bss) }           /* BSS */
 
   _edata = .;                  /* End of data section */
 
@@ -48,7 +48,7 @@ SECTIONS
        _sinittext = .;
        INIT_TEXT
        _einittext = .;
-  }
+  } :data
   .init.data : { INIT_DATA }
   . = ALIGN(16);
   __setup_start = .;
@@ -74,6 +74,7 @@ SECTIONS
   .init.ramfs : { *(.init.ramfs) }
   __initramfs_end = .;
 #endif
+  NOTES
   . = ALIGN(8192);
   __init_end = .;
 
index 46b7d6035aabaab6a299f5c2cef9fee411c96bb4..df620ac2a296b7a7da77a87cf9e00c06ee0786e5 100644 (file)
@@ -66,8 +66,10 @@ static struct vm_struct *get_io_area(unsigned long size)
        for (p = &iolist; (tmp = *p) ; p = &tmp->next) {
                if (size + addr < (unsigned long)tmp->addr)
                        break;
-               if (addr > KMAP_END-size)
+               if (addr > KMAP_END-size) {
+                       kfree(area);
                        return NULL;
+               }
                addr = tmp->size + (unsigned long)tmp->addr;
        }
        area->addr = (void *)addr;
index 432a9f13b2ed6bc6955908096740c1154e3d4ee5..cea5e3e4e63646abf411aeb34be8172493214a34 100644 (file)
@@ -52,15 +52,15 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                /* Ensure clock and real-time-mode-register are accessible */
                rtc->ctrl = RTC_READ;
                memset(&wtime, 0, sizeof(struct rtc_time));
-               wtime.tm_sec =  BCD2BIN(rtc->bcd_sec);
-               wtime.tm_min =  BCD2BIN(rtc->bcd_min);
-               wtime.tm_hour = BCD2BIN(rtc->bcd_hr);
-               wtime.tm_mday =  BCD2BIN(rtc->bcd_dom);
-               wtime.tm_mon =  BCD2BIN(rtc->bcd_mth)-1;
-               wtime.tm_year = BCD2BIN(rtc->bcd_year);
+               wtime.tm_sec =  bcd2bin(rtc->bcd_sec);
+               wtime.tm_min =  bcd2bin(rtc->bcd_min);
+               wtime.tm_hour = bcd2bin(rtc->bcd_hr);
+               wtime.tm_mday =  bcd2bin(rtc->bcd_dom);
+               wtime.tm_mon =  bcd2bin(rtc->bcd_mth)-1;
+               wtime.tm_year = bcd2bin(rtc->bcd_year);
                if (wtime.tm_year < 70)
                        wtime.tm_year += 100;
-               wtime.tm_wday = BCD2BIN(rtc->bcd_dow)-1;
+               wtime.tm_wday = bcd2bin(rtc->bcd_dow)-1;
                rtc->ctrl = 0;
                local_irq_restore(flags);
                return copy_to_user(argp, &wtime, sizeof wtime) ?
@@ -104,12 +104,12 @@ static int rtc_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
                local_irq_save(flags);
                rtc->ctrl     = RTC_WRITE;
 
-               rtc->bcd_sec  = BIN2BCD(sec);
-               rtc->bcd_min  = BIN2BCD(min);
-               rtc->bcd_hr   = BIN2BCD(hrs);
-               rtc->bcd_dom  = BIN2BCD(day);
-               rtc->bcd_mth  = BIN2BCD(mon);
-               rtc->bcd_year = BIN2BCD(yrs%100);
+               rtc->bcd_sec  = bin2bcd(sec);
+               rtc->bcd_min  = bin2bcd(min);
+               rtc->bcd_hr   = bin2bcd(hrs);
+               rtc->bcd_dom  = bin2bcd(day);
+               rtc->bcd_mth  = bin2bcd(mon);
+               rtc->bcd_year = bin2bcd(yrs%100);
 
                rtc->ctrl     = 0;
                local_irq_restore(flags);
index be9de2f3dc48ee1da88283072e49a28890329122..9c7eefa3f98a133bd53d767b0edbf3f622993416 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/serial_reg.h>
 #include <linux/rtc.h>
 #include <linux/vt_kern.h>
+#include <linux/bcd.h>
 
 #include <asm/io.h>
 #include <asm/rtc.h>
@@ -216,17 +217,6 @@ int q40_parse_bootinfo(const struct bi_record *rec)
 }
 
 
-static inline unsigned char bcd2bin(unsigned char b)
-{
-       return (b >> 4) * 10 + (b & 15);
-}
-
-static inline unsigned char bin2bcd(unsigned char b)
-{
-       return (b / 10) * 16 + (b % 10);
-}
-
-
 static unsigned long q40_gettimeoffset(void)
 {
        return 5000 * (ql_ticks != 0);
index f5eaafb00d218ce9519545b3ddb1c2600bac9532..536a04aaf22f28b9de07fda6dd9420b1b31e3b3d 100644 (file)
@@ -47,23 +47,23 @@ int sun3x_hwclk(int set, struct rtc_time *t)
 
        if(set) {
                h->csr |= C_WRITE;
-               h->sec = BIN2BCD(t->tm_sec);
-               h->min = BIN2BCD(t->tm_min);
-               h->hour = BIN2BCD(t->tm_hour);
-               h->wday = BIN2BCD(t->tm_wday);
-               h->mday = BIN2BCD(t->tm_mday);
-               h->month = BIN2BCD(t->tm_mon);
-               h->year = BIN2BCD(t->tm_year);
+               h->sec = bin2bcd(t->tm_sec);
+               h->min = bin2bcd(t->tm_min);
+               h->hour = bin2bcd(t->tm_hour);
+               h->wday = bin2bcd(t->tm_wday);
+               h->mday = bin2bcd(t->tm_mday);
+               h->month = bin2bcd(t->tm_mon);
+               h->year = bin2bcd(t->tm_year);
                h->csr &= ~C_WRITE;
        } else {
                h->csr |= C_READ;
-               t->tm_sec = BCD2BIN(h->sec);
-               t->tm_min = BCD2BIN(h->min);
-               t->tm_hour = BCD2BIN(h->hour);
-               t->tm_wday = BCD2BIN(h->wday);
-               t->tm_mday = BCD2BIN(h->mday);
-               t->tm_mon = BCD2BIN(h->month);
-               t->tm_year = BCD2BIN(h->year);
+               t->tm_sec = bcd2bin(h->sec);
+               t->tm_min = bcd2bin(h->min);
+               t->tm_hour = bcd2bin(h->hour);
+               t->tm_wday = bcd2bin(h->wday);
+               t->tm_mday = bcd2bin(h->mday);
+               t->tm_mon = bcd2bin(h->month);
+               t->tm_year = bcd2bin(h->year);
                h->csr &= ~C_READ;
        }
 
index 73008f7bdc93708281e647889a7e3d6c6be87c41..9c93a5b36f2a2dfd14a84fcfea813fb8ed3634e8 100644 (file)
 #include <linux/stddef.h>
 #include <asm/processor.h>
 
-static __inline__ int ide_probe_legacy(void)
-{
-#ifdef CONFIG_PCI
-       struct pci_dev *dev;
-       /*
-        * This can be called on the ide_setup() path, super-early in
-        * boot.  But the down_read() will enable local interrupts,
-        * which can cause some machines to crash.  So here we detect
-        * and flag that situation and bail out early.
-        */
-       if (no_pci_devices())
-               return 0;
-       dev = pci_get_class(PCI_CLASS_BRIDGE_EISA << 8, NULL);
-       if (dev)
-               goto found;
-       dev = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL);
-       if (dev)
-               goto found;
-       return 0;
-found:
-       pci_dev_put(dev);
-       return 1;
-#elif defined(CONFIG_EISA) || defined(CONFIG_ISA)
-       return 1;
-#else
-       return 0;
-#endif
-}
-
 /* MIPS port and memory-mapped I/O string operations.  */
 static inline void __ide_flush_prologue(void)
 {
index 05191bbc68b8bef23926a60b28b461ca559e5502..0a23b5795b25a87c38b117e4bfc168dfc565c2d5 100644 (file)
@@ -223,11 +223,25 @@ static struct platform_device rtc_device = {
 static __init int add_rtc_cmos(void)
 {
 #ifdef CONFIG_PNP
-       if (!pnp_platform_devices)
-               platform_device_register(&rtc_device);
-#else
+       static const char *ids[] __initconst =
+           { "PNP0b00", "PNP0b01", "PNP0b02", };
+       struct pnp_dev *dev;
+       struct pnp_id *id;
+       int i;
+
+       pnp_for_each_dev(dev) {
+               for (id = dev->id; id; id = id->next) {
+                       for (i = 0; i < ARRAY_SIZE(ids); i++) {
+                               if (compare_pnp_id(id, ids[i]) != 0)
+                                       return 0;
+                       }
+               }
+       }
+#endif
+
        platform_device_register(&rtc_device);
-#endif /* CONFIG_PNP */
+       dev_info(&rtc_device.dev,
+                "registered platform RTC device (no PNP device found)\n");
        return 0;
 }
 device_initcall(add_rtc_cmos);
index a00359e8f7a8f06c14bfbff198e34d4bc5d5d5ea..9606d2bd1dd974a4766fed7748836e6cab5e46b8 100644 (file)
@@ -53,11 +53,6 @@ extern struct fd_ops no_fd_ops;
 struct fd_ops *fd_ops;
 #endif
 
-#if defined(CONFIG_BLK_DEV_IDE) || defined(CONFIG_BLK_DEV_IDE_MODULE)
-extern struct ide_ops no_ide_ops;
-struct ide_ops *ide_ops;
-#endif
-
 extern struct rtc_ops no_rtc_ops;
 struct rtc_ops *rtc_ops;
 
index 3c578ef78c4830f791039b83e2a44ab80d7538d8..24649ada08dfd353c8a9895df6773156520e66ea 100644 (file)
@@ -260,115 +260,3 @@ static int __init init_acpi_device_notify(void)
 }
 
 arch_initcall(init_acpi_device_notify);
-
-
-#if defined(CONFIG_RTC_DRV_CMOS) || defined(CONFIG_RTC_DRV_CMOS_MODULE)
-
-#ifdef CONFIG_PM
-static u32 rtc_handler(void *context)
-{
-       acpi_clear_event(ACPI_EVENT_RTC);
-       acpi_disable_event(ACPI_EVENT_RTC, 0);
-       return ACPI_INTERRUPT_HANDLED;
-}
-
-static inline void rtc_wake_setup(void)
-{
-       acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
-       /*
-        * After the RTC handler is installed, the Fixed_RTC event should
-        * be disabled. Only when the RTC alarm is set will it be enabled.
-        */
-       acpi_clear_event(ACPI_EVENT_RTC);
-       acpi_disable_event(ACPI_EVENT_RTC, 0);
-}
-
-static void rtc_wake_on(struct device *dev)
-{
-       acpi_clear_event(ACPI_EVENT_RTC);
-       acpi_enable_event(ACPI_EVENT_RTC, 0);
-}
-
-static void rtc_wake_off(struct device *dev)
-{
-       acpi_disable_event(ACPI_EVENT_RTC, 0);
-}
-#else
-#define rtc_wake_setup()       do{}while(0)
-#define rtc_wake_on            NULL
-#define rtc_wake_off           NULL
-#endif
-
-/* Every ACPI platform has a mc146818 compatible "cmos rtc".  Here we find
- * its device node and pass extra config data.  This helps its driver use
- * capabilities that the now-obsolete mc146818 didn't have, and informs it
- * that this board's RTC is wakeup-capable (per ACPI spec).
- */
-#include <linux/mc146818rtc.h>
-
-static struct cmos_rtc_board_info rtc_info;
-
-
-/* PNP devices are registered in a subsys_initcall();
- * ACPI specifies the PNP IDs to use.
- */
-#include <linux/pnp.h>
-
-static int __init pnp_match(struct device *dev, void *data)
-{
-       static const char *ids[] = { "PNP0b00", "PNP0b01", "PNP0b02", };
-       struct pnp_dev *pnp = to_pnp_dev(dev);
-       int i;
-
-       for (i = 0; i < ARRAY_SIZE(ids); i++) {
-               if (compare_pnp_id(pnp->id, ids[i]) != 0)
-                       return 1;
-       }
-       return 0;
-}
-
-static struct device *__init get_rtc_dev(void)
-{
-       return bus_find_device(&pnp_bus_type, NULL, NULL, pnp_match);
-}
-
-static int __init acpi_rtc_init(void)
-{
-       struct device *dev = get_rtc_dev();
-
-       if (acpi_disabled)
-               return 0;
-
-       if (dev) {
-               rtc_wake_setup();
-               rtc_info.wake_on = rtc_wake_on;
-               rtc_info.wake_off = rtc_wake_off;
-
-               /* workaround bug in some ACPI tables */
-               if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
-                       DBG("bogus FADT month_alarm\n");
-                       acpi_gbl_FADT.month_alarm = 0;
-               }
-
-               rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
-               rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
-               rtc_info.rtc_century = acpi_gbl_FADT.century;
-
-               /* NOTE:  S4_RTC_WAKE is NOT currently useful to Linux */
-               if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
-                       printk(PREFIX "RTC can wake from S4\n");
-
-
-               dev->platform_data = &rtc_info;
-
-               /* RTC always wakes from S1/S2/S3, and often S4/STD */
-               device_init_wakeup(dev, 1);
-
-               put_device(dev);
-       } else
-               DBG("RTC unavailable?\n");
-       return 0;
-}
-module_init(acpi_rtc_init);
-
-#endif
index 41b4361bbf6ed86788634223ce855734f79ada89..02b596b9cf6a55fd058381a4d7d09ae928c4ceba 100644 (file)
@@ -148,6 +148,64 @@ static struct ata_port_operations pcmcia_8bit_port_ops = {
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+
+struct pcmcia_config_check {
+       unsigned long ctl_base;
+       int skip_vcc;
+       int is_kme;
+};
+
+static int pcmcia_check_one_config(struct pcmcia_device *pdev,
+                                  cistpl_cftable_entry_t *cfg,
+                                  cistpl_cftable_entry_t *dflt,
+                                  unsigned int vcc,
+                                  void *priv_data)
+{
+       struct pcmcia_config_check *stk = priv_data;
+
+       /* Check for matching Vcc, unless we're desperate */
+       if (!stk->skip_vcc) {
+               if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+                       if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
+                               return -ENODEV;
+               } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+                       if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
+                               return -ENODEV;
+               }
+       }
+
+       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               pdev->io.BasePort1 = io->win[0].base;
+               pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               if (io->nwin == 2) {
+                       pdev->io.NumPorts1 = 8;
+                       pdev->io.BasePort2 = io->win[1].base;
+                       pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
+                       if (pcmcia_request_io(pdev, &pdev->io) != 0)
+                               return -ENODEV;
+                       stk->ctl_base = pdev->io.BasePort2;
+               } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
+                       pdev->io.NumPorts1 = io->win[0].len;
+                       pdev->io.NumPorts2 = 0;
+                       if (pcmcia_request_io(pdev, &pdev->io) != 0)
+                               return -ENODEV;
+                       stk->ctl_base = pdev->io.BasePort1 + 0x0e;
+               } else
+                       return -ENODEV;
+               /* If we've got this far, we're done */
+               return 0;
+       }
+       return -ENODEV;
+}
+
 /**
  *     pcmcia_init_one         -       attach a PCMCIA interface
  *     @pdev: pcmcia device
@@ -161,19 +219,11 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        struct ata_host *host;
        struct ata_port *ap;
        struct ata_pcmcia_info *info;
-       tuple_t tuple;
-       struct {
-               unsigned short buf[128];
-               cisparse_t parse;
-               config_info_t conf;
-               cistpl_cftable_entry_t dflt;
-       } *stk = NULL;
-       cistpl_cftable_entry_t *cfg;
-       int pass, last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM, p;
+       struct pcmcia_config_check *stk = NULL;
+       int last_ret = 0, last_fn = 0, is_kme = 0, ret = -ENOMEM, p;
        unsigned long io_base, ctl_base;
        void __iomem *io_addr, *ctl_addr;
        int n_ports = 1;
-
        struct ata_port_operations *ops = &pcmcia_port_ops;
 
        info = kzalloc(sizeof(*info), GFP_KERNEL);
@@ -193,96 +243,27 @@ static int pcmcia_init_one(struct pcmcia_device *pdev)
        pdev->conf.Attributes = CONF_ENABLE_IRQ;
        pdev->conf.IntType = INT_MEMORY_AND_IO;
 
-       /* Allocate resoure probing structures */
-
-       stk = kzalloc(sizeof(*stk), GFP_KERNEL);
-       if (!stk)
-               goto out1;
-
-       cfg = &stk->parse.cftable_entry;
-
-       /* Tuples we are walking */
-       tuple.TupleData = (cisdata_t *)&stk->buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-
        /* See if we have a manufacturer identifier. Use it to set is_kme for
           vendor quirks */
        is_kme = ((pdev->manf_id == MANFID_KME) &&
                  ((pdev->card_id == PRODID_KME_KXLC005_A) ||
                   (pdev->card_id == PRODID_KME_KXLC005_B)));
 
-       /* Not sure if this is right... look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(pdev, &stk->conf));
-/*     link->conf.Vcc = stk->conf.Vcc; */
-
-       pass = io_base = ctl_base = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       tuple.Attributes = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(pdev, &tuple));
-
-       /* Now munch the resources looking for a suitable set */
-       while (1) {
-               if (pcmcia_get_tuple_data(pdev, &tuple) != 0)
-                       goto next_entry;
-               if (pcmcia_parse_tuple(pdev, &tuple, &stk->parse) != 0)
-                       goto next_entry;
-               /* Check for matching Vcc, unless we're desperate */
-               if (!pass) {
-                       if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                               if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
-                                       goto next_entry;
-                       } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                               if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
-                                       goto next_entry;
-                       }
-               }
+       /* Allocate resoure probing structures */
 
-               if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       pdev->conf.Vpp = stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
-
-               if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
-                       pdev->conf.ConfigIndex = cfg->index;
-                       pdev->io.BasePort1 = io->win[0].base;
-                       pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       if (io->nwin == 2) {
-                               pdev->io.NumPorts1 = 8;
-                               pdev->io.BasePort2 = io->win[1].base;
-                               pdev->io.NumPorts2 = (is_kme) ? 2 : 1;
-                               if (pcmcia_request_io(pdev, &pdev->io) != 0)
-                                       goto next_entry;
-                               io_base = pdev->io.BasePort1;
-                               ctl_base = pdev->io.BasePort2;
-                       } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
-                               pdev->io.NumPorts1 = io->win[0].len;
-                               pdev->io.NumPorts2 = 0;
-                               if (pcmcia_request_io(pdev, &pdev->io) != 0)
-                                       goto next_entry;
-                               io_base = pdev->io.BasePort1;
-                               ctl_base = pdev->io.BasePort1 + 0x0e;
-                       } else
-                               goto next_entry;
-                       /* If we've got this far, we're done */
-                       break;
-               }
-next_entry:
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
-               if (pass) {
-                       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(pdev, &tuple));
-               } else if (pcmcia_get_next_tuple(pdev, &tuple) != 0) {
-                       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(pdev, &tuple));
-                       memset(&stk->dflt, 0, sizeof(stk->dflt));
-                       pass++;
-               }
-       }
+       stk = kzalloc(sizeof(*stk), GFP_KERNEL);
+       if (!stk)
+               goto out1;
+       stk->is_kme = is_kme;
+       stk->skip_vcc = io_base = ctl_base = 0;
 
+       if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk)) {
+               stk->skip_vcc = 1;
+               if (pcmcia_loop_config(pdev, pcmcia_check_one_config, stk))
+                       goto failed; /* No suitable config found */
+       }
+       io_base = pdev->io.BasePort1;
+       ctl_base = stk->ctl_base;
        CS_CHECK(RequestIRQ, pcmcia_request_irq(pdev, &pdev->irq));
        CS_CHECK(RequestConfiguration, pcmcia_request_configuration(pdev, &pdev->conf));
 
@@ -384,6 +365,7 @@ static struct pcmcia_device_id pcmcia_devices[] = {
        PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
        PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
        PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),        /* SanDisk CFA */
+       PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000),        /* Kingston */
        PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620),        /* TI emulated */
        PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000),        /* Toshiba */
        PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
@@ -404,9 +386,9 @@ static struct pcmcia_device_id pcmcia_devices[] = {
        PCMCIA_DEVICE_PROD_ID12("EXP   ", "CD-ROM", 0x0a5c52fd, 0x66536591),
        PCMCIA_DEVICE_PROD_ID12("EXP   ", "PnPIDE", 0x0a5c52fd, 0x0c694728),
        PCMCIA_DEVICE_PROD_ID12("FREECOM", "PCCARD-IDE", 0x5714cbf7, 0x48e0ab8e),
-       PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
        PCMCIA_DEVICE_PROD_ID12("HITACHI", "FLASH", 0xf4f43949, 0x9eb86aae),
        PCMCIA_DEVICE_PROD_ID12("HITACHI", "microdrive", 0xf4f43949, 0xa6d76178),
+       PCMCIA_DEVICE_PROD_ID12("Hyperstone", "Model1", 0x3d5b9ef5, 0xca6ab420),
        PCMCIA_DEVICE_PROD_ID12("IBM", "microdrive", 0xb569a6e5, 0xa6d76178),
        PCMCIA_DEVICE_PROD_ID12("IBM", "IBM17JSSFP20", 0xb569a6e5, 0xf2508753),
        PCMCIA_DEVICE_PROD_ID12("KINGSTON", "CF8GB", 0x2e6d1829, 0xacbe682e),
index 49f274197b16a7ece82403a4118dc26c2d38b514..432cf40182916366b71fad0b9c4f8e1131b2ef66 100644 (file)
@@ -1882,10 +1882,6 @@ static int __init atari_floppy_init (void)
                /* Amiga, Mac, ... don't have Atari-compatible floppy :-) */
                return -ENODEV;
 
-       if (MACH_IS_HADES)
-               /* Hades doesn't have Atari-compatible floppy */
-               return -ENODEV;
-
        if (register_blkdev(FLOPPY_MAJOR,"fd"))
                return -EBUSY;
 
index bcf57927b7a8ff7e9e377f03e798c37f650689f2..e6ee21d99d92ce42cd0b8091544363f9f4758cb5 100644 (file)
@@ -901,23 +901,23 @@ static int bluecard_config(struct pcmcia_device *link)
        for (n = 0; n < 0x400; n += 0x40) {
                link->io.BasePort1 = n ^ 0x300;
                i = pcmcia_request_io(link, &link->io);
-               if (i == CS_SUCCESS)
+               if (i == 0)
                        break;
        }
 
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIO, i);
                goto failed;
        }
 
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
                goto failed;
        }
index 27058477cc8b7722bdc901ec7edb21e1d503be27..2cbe70b66470eb7189a7232fa54e8c79d5db70fe 100644 (file)
@@ -678,101 +678,78 @@ static void bt3c_detach(struct pcmcia_device *link)
        kfree(info);
 }
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int bt3c_check_config(struct pcmcia_device *p_dev,
+                            cistpl_cftable_entry_t *cf,
+                            cistpl_cftable_entry_t *dflt,
+                            unsigned int vcc,
+                            void *priv_data)
 {
-       int i;
-
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
-               return i;
-
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       unsigned long try = (unsigned long) priv_data;
+
+       if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
+           (cf->io.win[0].base != 0)) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.IOAddrLines = (try == 0) ? 16 :
+                       cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
 }
 
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int bt3c_check_config_notpicky(struct pcmcia_device *p_dev,
+                                     cistpl_cftable_entry_t *cf,
+                                     cistpl_cftable_entry_t *dflt,
+                                     unsigned int vcc,
+                                     void *priv_data)
 {
-       if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       int j;
+
+       if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
+               for (j = 0; j < 5; j++) {
+                       p_dev->io.BasePort1 = base[j];
+                       p_dev->io.IOAddrLines = base[j] ? 16 : 3;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
 }
 
 static int bt3c_config(struct pcmcia_device *link)
 {
-       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        bt3c_info_t *info = link->priv;
-       tuple_t tuple;
-       u_short buf[256];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cf = &parse.cftable_entry;
-       int i, j, try;
-
-       /* First pass: look for a config entry that looks normal. */
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       /* Two tries: without IO aliases, then with aliases */
-       for (try = 0; try < 2; try++) {
-               i = first_tuple(link, &tuple, &parse);
-               while (i != CS_NO_MORE_ITEMS) {
-                       if (i != CS_SUCCESS)
-                               goto next_entry;
-                       if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                               link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-                       if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
-                               link->conf.ConfigIndex = cf->index;
-                               link->io.BasePort1 = cf->io.win[0].base;
-                               link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
-                               i = pcmcia_request_io(link, &link->io);
-                               if (i == CS_SUCCESS)
-                                       goto found_port;
-                       }
-next_entry:
-                       i = next_tuple(link, &tuple, &parse);
-               }
-       }
+       int i;
+       unsigned long try;
+
+       /* First pass: look for a config entry that looks normal.
+          Two tries: without IO aliases, then with aliases */
+       for (try = 0; try < 2; try++)
+               if (!pcmcia_loop_config(link, bt3c_check_config, (void *) try))
+                       goto found_port;
 
        /* Second pass: try to find an entry that isn't picky about
           its base address, then try to grab any standard serial port
           address, and finally try to get any free port. */
-       i = first_tuple(link, &tuple, &parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               if ((i == CS_SUCCESS) && (cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
-                       link->conf.ConfigIndex = cf->index;
-                       for (j = 0; j < 5; j++) {
-                               link->io.BasePort1 = base[j];
-                               link->io.IOAddrLines = base[j] ? 16 : 3;
-                               i = pcmcia_request_io(link, &link->io);
-                               if (i == CS_SUCCESS)
-                                       goto found_port;
-                       }
-               }
-               i = next_tuple(link, &tuple, &parse);
-       }
+       if (!pcmcia_loop_config(link, bt3c_check_config_notpicky, NULL))
+               goto found_port;
 
-found_port:
-       if (i != CS_SUCCESS) {
-               BT_ERR("No usable port range found");
-               cs_error(link, RequestIO, i);
-               goto failed;
-       }
+       BT_ERR("No usable port range found");
+       cs_error(link, RequestIO, -ENODEV);
+       goto failed;
 
+found_port:
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
                goto failed;
        }
index 68d1d258e6a4f5f4e8064a061d374ef1b632dca3..8e556b7ff9f63b3e1d95f99526304655df2c73ad 100644 (file)
@@ -607,102 +607,78 @@ static void btuart_detach(struct pcmcia_device *link)
        kfree(info);
 }
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int btuart_check_config(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cf,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-       int i;
-
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
-               return i;
-
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       int *try = priv_data;
+
+       if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) &&
+           (cf->io.win[0].base != 0)) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.IOAddrLines = (*try == 0) ? 16 :
+                       cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
 }
 
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int btuart_check_config_notpicky(struct pcmcia_device *p_dev,
+                                       cistpl_cftable_entry_t *cf,
+                                       cistpl_cftable_entry_t *dflt,
+                                       unsigned int vcc,
+                                       void *priv_data)
 {
-       if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       int j;
+
+       if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
+               for (j = 0; j < 5; j++) {
+                       p_dev->io.BasePort1 = base[j];
+                       p_dev->io.IOAddrLines = base[j] ? 16 : 3;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
 }
 
 static int btuart_config(struct pcmcia_device *link)
 {
-       static unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        btuart_info_t *info = link->priv;
-       tuple_t tuple;
-       u_short buf[256];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cf = &parse.cftable_entry;
-       int i, j, try;
-
-       /* First pass: look for a config entry that looks normal. */
-       tuple.TupleData = (cisdata_t *) buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       /* Two tries: without IO aliases, then with aliases */
-       for (try = 0; try < 2; try++) {
-               i = first_tuple(link, &tuple, &parse);
-               while (i != CS_NO_MORE_ITEMS) {
-                       if (i != CS_SUCCESS)
-                               goto next_entry;
-                       if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                               link->conf.Vpp = cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-                       if ((cf->io.nwin > 0) && (cf->io.win[0].len == 8) && (cf->io.win[0].base != 0)) {
-                               link->conf.ConfigIndex = cf->index;
-                               link->io.BasePort1 = cf->io.win[0].base;
-                               link->io.IOAddrLines = (try == 0) ? 16 : cf->io.flags & CISTPL_IO_LINES_MASK;
-                               i = pcmcia_request_io(link, &link->io);
-                               if (i == CS_SUCCESS)
-                                       goto found_port;
-                       }
-next_entry:
-                       i = next_tuple(link, &tuple, &parse);
-               }
-       }
+       int i;
+       int try;
+
+       /* First pass: look for a config entry that looks normal.
+          Two tries: without IO aliases, then with aliases */
+       for (try = 0; try < 2; try++)
+               if (!pcmcia_loop_config(link, btuart_check_config, &try))
+                       goto found_port;
 
        /* Second pass: try to find an entry that isn't picky about
           its base address, then try to grab any standard serial port
           address, and finally try to get any free port. */
-       i = first_tuple(link, &tuple, &parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               if ((i == CS_SUCCESS) && (cf->io.nwin > 0)
-                   && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
-                       link->conf.ConfigIndex = cf->index;
-                       for (j = 0; j < 5; j++) {
-                               link->io.BasePort1 = base[j];
-                               link->io.IOAddrLines = base[j] ? 16 : 3;
-                               i = pcmcia_request_io(link, &link->io);
-                               if (i == CS_SUCCESS)
-                                       goto found_port;
-                       }
-               }
-               i = next_tuple(link, &tuple, &parse);
-       }
+       if (!pcmcia_loop_config(link, btuart_check_config_notpicky, NULL))
+               goto found_port;
 
-found_port:
-       if (i != CS_SUCCESS) {
-               BT_ERR("No usable port range found");
-               cs_error(link, RequestIO, i);
-               goto failed;
-       }
+       BT_ERR("No usable port range found");
+       cs_error(link, RequestIO, -ENODEV);
+       goto failed;
 
+found_port:
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
                goto failed;
        }
index dae45cdf02b2db78db84531bd5b0a41243ad891b..e6e6b037695a2692e178deef1ce9bafd8b7bd227 100644 (file)
@@ -590,75 +590,40 @@ static void dtl1_detach(struct pcmcia_device *link)
        kfree(info);
 }
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
+static int dtl1_confcheck(struct pcmcia_device *p_dev,
+                         cistpl_cftable_entry_t *cf,
+                         cistpl_cftable_entry_t *dflt,
+                         unsigned int vcc,
+                         void *priv_data)
 {
-       int i;
-
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
-               return i;
-
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_first_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
-}
-
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
-{
-       if (pcmcia_get_next_tuple(handle, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       return get_tuple(handle, tuple, parse);
+       if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.NumPorts1 = cf->io.win[0].len;        /*yo */
+               p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
 }
 
 static int dtl1_config(struct pcmcia_device *link)
 {
        dtl1_info_t *info = link->priv;
-       tuple_t tuple;
-       u_short buf[256];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cf = &parse.cftable_entry;
        int i;
 
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-
        /* Look for a generic full-sized window */
        link->io.NumPorts1 = 8;
-       i = first_tuple(link, &tuple, &parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               if ((i == CS_SUCCESS) && (cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
-                       link->conf.ConfigIndex = cf->index;
-                       link->io.BasePort1 = cf->io.win[0].base;
-                       link->io.NumPorts1 = cf->io.win[0].len; /*yo */
-                       link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
-                       i = pcmcia_request_io(link, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-               i = next_tuple(link, &tuple, &parse);
-       }
-
-       if (i != CS_SUCCESS) {
-               cs_error(link, RequestIO, i);
+       if (!pcmcia_loop_config(link, dtl1_confcheck, NULL))
                goto failed;
-       }
 
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
                goto failed;
        }
index f070ae7bd91a1d905eab711a6ee8d013ae8f3eeb..1c5bf99895edda84f0571ff91851b828aa988f79 100644 (file)
@@ -1759,65 +1759,40 @@ static void cmm_cm4000_release(struct pcmcia_device * link)
 
 /*==== Interface to PCMCIA Layer =======================================*/
 
+static int cm4000_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cfg,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
+{
+       if (!cfg->io.nwin)
+               return -ENODEV;
+
+       /* Get the IOaddr */
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       p_dev->io.NumPorts1 = cfg->io.win[0].len;
+       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+       if (!(cfg->io.flags & CISTPL_IO_8BIT))
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+       if (!(cfg->io.flags & CISTPL_IO_16BIT))
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+       p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
+
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int cm4000_config(struct pcmcia_device * link, int devno)
 {
        struct cm4000_dev *dev;
-       tuple_t tuple;
-       cisparse_t parse;
-       u_char buf[64];
-       int fail_fn, fail_rc;
-       int rc;
 
        /* read the config-tuples */
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-
-       link->io.BasePort2 = 0;
-       link->io.NumPorts2 = 0;
-       link->io.Attributes2 = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       for (rc = pcmcia_get_first_tuple(link, &tuple);
-            rc == CS_SUCCESS; rc = pcmcia_get_next_tuple(link, &tuple)) {
-
-               rc = pcmcia_get_tuple_data(link, &tuple);
-               if (rc != CS_SUCCESS)
-                       continue;
-               rc = pcmcia_parse_tuple(link, &tuple, &parse);
-               if (rc != CS_SUCCESS)
-                       continue;
-
-               link->conf.ConfigIndex = parse.cftable_entry.index;
-
-               if (!parse.cftable_entry.io.nwin)
-                       continue;
-
-               /* Get the IOaddr */
-               link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-               link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
-               link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-               if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-               if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-               link->io.IOAddrLines = parse.cftable_entry.io.flags
-                   & CISTPL_IO_LINES_MASK;
-
-               rc = pcmcia_request_io(link, &link->io);
-               if (rc == CS_SUCCESS)
-                       break;  /* we are done */
-       }
-       if (rc != CS_SUCCESS)
+       if (pcmcia_loop_config(link, cm4000_config_check, NULL))
                goto cs_release;
 
        link->conf.IntType = 00000002;
 
-       if ((fail_rc =
-            pcmcia_request_configuration(link, &link->conf)) != CS_SUCCESS) {
-               fail_fn = RequestConfiguration;
+       if (pcmcia_request_configuration(link, &link->conf))
                goto cs_release;
-       }
 
        dev = link->priv;
        sprintf(dev->node.dev_name, DEVICE_NAME "%d", devno);
index 0b5934bef7a4301049f19c8d82393544742f4a84..2d7c906435b7be8a6b60e9e4e19ec2a727578304 100644 (file)
@@ -526,65 +526,49 @@ static void cm4040_reader_release(struct pcmcia_device *link)
        return;
 }
 
-static int reader_config(struct pcmcia_device *link, int devno)
+static int cm4040_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cfg,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-       struct reader_dev *dev;
-       tuple_t tuple;
-       cisparse_t parse;
-       u_char buf[64];
-       int fail_fn, fail_rc;
        int rc;
+       if (!cfg->io.nwin)
+               return -ENODEV;
+
+       /* Get the IOaddr */
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       p_dev->io.NumPorts1 = cfg->io.win[0].len;
+       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+       if (!(cfg->io.flags & CISTPL_IO_8BIT))
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+       if (!(cfg->io.flags & CISTPL_IO_16BIT))
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+       p_dev->io.IOAddrLines = cfg->io.flags & CISTPL_IO_LINES_MASK;
+
+       rc = pcmcia_request_io(p_dev, &p_dev->io);
+       dev_printk(KERN_INFO, &handle_to_dev(p_dev),
+                  "pcmcia_request_io returned 0x%x\n", rc);
+       return rc;
+}
+
 
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
+static int reader_config(struct pcmcia_device *link, int devno)
+{
+       struct reader_dev *dev;
+       int fail_rc;
 
        link->io.BasePort2 = 0;
        link->io.NumPorts2 = 0;
        link->io.Attributes2 = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       for (rc = pcmcia_get_first_tuple(link, &tuple);
-            rc == CS_SUCCESS;
-            rc = pcmcia_get_next_tuple(link, &tuple)) {
-               rc = pcmcia_get_tuple_data(link, &tuple);
-               if (rc != CS_SUCCESS)
-                       continue;
-               rc = pcmcia_parse_tuple(link, &tuple, &parse);
-               if (rc != CS_SUCCESS)
-                       continue;
-
-               link->conf.ConfigIndex = parse.cftable_entry.index;
-
-               if (!parse.cftable_entry.io.nwin)
-                       continue;
-
-               link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-               link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
-               link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-               if (!(parse.cftable_entry.io.flags & CISTPL_IO_8BIT))
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-               if (!(parse.cftable_entry.io.flags & CISTPL_IO_16BIT))
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-               link->io.IOAddrLines = parse.cftable_entry.io.flags
-                                               & CISTPL_IO_LINES_MASK;
-               rc = pcmcia_request_io(link, &link->io);
-
-               dev_printk(KERN_INFO, &handle_to_dev(link), "foo");
-               if (rc == CS_SUCCESS)
-                       break;
-               else
-                       dev_printk(KERN_INFO, &handle_to_dev(link),
-                                  "pcmcia_request_io failed 0x%x\n", rc);
-       }
-       if (rc != CS_SUCCESS)
+
+       if (pcmcia_loop_config(link, cm4040_config_check, NULL))
                goto cs_release;
 
        link->conf.IntType = 00000002;
 
-       if ((fail_rc = pcmcia_request_configuration(link,&link->conf))
-                                                               !=CS_SUCCESS) {
-               fail_fn = RequestConfiguration;
+       fail_rc = pcmcia_request_configuration(link, &link->conf);
+       if (fail_rc != 0) {
                dev_printk(KERN_INFO, &handle_to_dev(link),
                           "pcmcia_request_configuration failed 0x%x\n",
                           fail_rc);
index 5eca7a99afe6c3daf1c793f4c0990e5125a72862..5216fce0c62d57ce6d2947750ac7dc22f1b82f0e 100644 (file)
@@ -65,9 +65,9 @@ static void signalled_reboot_work(struct work_struct *work_reboot)
        struct ipw_dev *ipw = container_of(work_reboot, struct ipw_dev,
                        work_reboot);
        struct pcmcia_device *link = ipw->link;
-       int ret = pccard_reset_card(link->socket);
+       int ret = pcmcia_reset_card(link->socket);
 
-       if (ret != CS_SUCCESS)
+       if (ret != 0)
                cs_error(link, ResetCard, ret);
 }
 
@@ -83,7 +83,6 @@ static int config_ipwireless(struct ipw_dev *ipw)
 {
        struct pcmcia_device *link = ipw->link;
        int ret;
-       config_info_t conf;
        tuple_t tuple;
        unsigned short buf[64];
        cisparse_t parse;
@@ -105,7 +104,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
        while (ret == 0) {
                ret = pcmcia_get_tuple_data(link, &tuple);
 
-               if (ret != CS_SUCCESS) {
+               if (ret != 0) {
                        cs_error(link, GetTupleData, ret);
                        goto exit0;
                }
@@ -116,21 +115,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
 
        ret = pcmcia_get_first_tuple(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetFirstTuple, ret);
                goto exit0;
        }
 
        ret = pcmcia_get_tuple_data(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetTupleData, ret);
                goto exit0;
        }
 
-       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+       ret = pcmcia_parse_tuple(&tuple, &parse);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, ParseTuple, ret);
                goto exit0;
        }
@@ -152,21 +151,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
 
        ret = pcmcia_get_first_tuple(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetFirstTuple, ret);
                goto exit0;
        }
 
        ret = pcmcia_get_tuple_data(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetTupleData, ret);
                goto exit0;
        }
 
-       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+       ret = pcmcia_parse_tuple(&tuple, &parse);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetTupleData, ret);
                goto exit0;
        }
@@ -181,7 +180,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
 
        ret = pcmcia_request_io(link, &link->io);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, RequestIO, ret);
                goto exit0;
        }
@@ -195,21 +194,21 @@ static int config_ipwireless(struct ipw_dev *ipw)
 
        ret = pcmcia_get_first_tuple(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetFirstTuple, ret);
                goto exit1;
        }
 
        ret = pcmcia_get_tuple_data(link, &tuple);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, GetTupleData, ret);
                goto exit1;
        }
 
-       ret = pcmcia_parse_tuple(link, &tuple, &parse);
+       ret = pcmcia_parse_tuple(&tuple, &parse);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, ParseTuple, ret);
                goto exit1;
        }
@@ -227,7 +226,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                ret = pcmcia_request_window(&link, &ipw->request_common_memory,
                                &ipw->handle_common_memory);
 
-               if (ret != CS_SUCCESS) {
+               if (ret != 0) {
                        cs_error(link, RequestWindow, ret);
                        goto exit1;
                }
@@ -239,7 +238,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                ret = pcmcia_map_mem_page(ipw->handle_common_memory,
                                &memreq_common_memory);
 
-               if (ret != CS_SUCCESS) {
+               if (ret != 0) {
                        cs_error(link, MapMemPage, ret);
                        goto exit1;
                }
@@ -261,7 +260,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                ret = pcmcia_request_window(&link, &ipw->request_attr_memory,
                                &ipw->handle_attr_memory);
 
-               if (ret != CS_SUCCESS) {
+               if (ret != 0) {
                        cs_error(link, RequestWindow, ret);
                        goto exit2;
                }
@@ -272,7 +271,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
                ret = pcmcia_map_mem_page(ipw->handle_attr_memory,
                                &memreq_attr_memory);
 
-               if (ret != CS_SUCCESS) {
+               if (ret != 0) {
                        cs_error(link, MapMemPage, ret);
                        goto exit2;
                }
@@ -292,20 +291,11 @@ static int config_ipwireless(struct ipw_dev *ipw)
 
        ret = pcmcia_request_irq(link, &link->irq);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, RequestIRQ, ret);
                goto exit3;
        }
 
-       /* Look up current Vcc */
-
-       ret = pcmcia_get_configuration_info(link, &conf);
-
-       if (ret != CS_SUCCESS) {
-               cs_error(link, GetConfigurationInfo, ret);
-               goto exit4;
-       }
-
        printk(KERN_INFO IPWIRELESS_PCCARD_NAME ": Card type %s\n",
                        ipw->is_v2_card ? "V2/V3" : "V1");
        printk(KERN_INFO IPWIRELESS_PCCARD_NAME
@@ -341,7 +331,7 @@ static int config_ipwireless(struct ipw_dev *ipw)
         */
        ret = pcmcia_request_configuration(link, &link->conf);
 
-       if (ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, RequestConfiguration, ret);
                goto exit4;
        }
index c240562c218b735b985883528458272733294eff..9a626e50b793ba65ce21d269d64a3536546e970c 100644 (file)
@@ -601,7 +601,7 @@ static int mgslpc_config(struct pcmcia_device *link)
 
     cfg = &(parse.cftable_entry);
     CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-    CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
+    CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
 
     if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
     if (cfg->index == 0)
index 57029fefd64a65fec4bfbb0e69a1915e8aa4359a..a0f7ffb6808716679ed1bc6d4cefb088ad0ba972 100644 (file)
@@ -301,7 +301,7 @@ static void scrup(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
        d = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
        s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * (t + nr));
        scr_memmovew(d, s, (b - t - nr) * vc->vc_size_row);
-       scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_scrl_erase_char,
+       scr_memsetw(d + (b - t - nr) * vc->vc_cols, vc->vc_video_erase_char,
                    vc->vc_size_row * nr);
 }
 
@@ -319,7 +319,7 @@ static void scrdown(struct vc_data *vc, unsigned int t, unsigned int b, int nr)
        s = (unsigned short *)(vc->vc_origin + vc->vc_size_row * t);
        step = vc->vc_cols * nr;
        scr_memmovew(s + step, s, (b - t - nr) * vc->vc_size_row);
-       scr_memsetw(s, vc->vc_scrl_erase_char, 2 * step);
+       scr_memsetw(s, vc->vc_video_erase_char, 2 * step);
 }
 
 static void do_update_region(struct vc_data *vc, unsigned long start, int count)
@@ -434,7 +434,6 @@ static void update_attr(struct vc_data *vc)
                      vc->vc_blink, vc->vc_underline,
                      vc->vc_reverse ^ vc->vc_decscnm, vc->vc_italic);
        vc->vc_video_erase_char = (build_attr(vc, vc->vc_color, 1, vc->vc_blink, 0, vc->vc_decscnm, 0) << 8) | ' ';
-       vc->vc_scrl_erase_char = (build_attr(vc, vc->vc_def_color, 1, false, false, vc->vc_decscnm, false) << 8) | ' ';
 }
 
 /* Note: inverting the screen twice should revert to the original state */
index b50b5dac95b0f75a49d9da5aeae42e1db2d87a2c..6c6dd2facede2e33366ce4dcbb584edc4e3811f8 100644 (file)
@@ -54,38 +54,6 @@ menuconfig IDE
 
 if IDE
 
-config BLK_DEV_IDE
-       tristate "Enhanced IDE/MFM/RLL disk/cdrom/tape/floppy support"
-       ---help---
-         If you say Y here, you will use the full-featured IDE driver to
-         control up to ten ATA/IDE interfaces, each being able to serve a
-         "master" and a "slave" device, for a total of up to twenty ATA/IDE
-         disk/cdrom/tape/floppy drives.
-
-         Useful information about large (>540 MB) IDE disks, multiple
-         interfaces, what to do if ATA/IDE devices are not automatically
-         detected, sound card ATA/IDE ports, module support, and other
-         topics, is contained in <file:Documentation/ide/ide.txt>. For detailed
-         information about hard drives, consult the Disk-HOWTO and the
-         Multi-Disk-HOWTO, available from
-         <http://www.tldp.org/docs.html#howto>.
-
-         To fine-tune ATA/IDE drive/interface parameters for improved
-         performance, look for the hdparm package at
-         <ftp://ibiblio.org/pub/Linux/system/hardware/>.
-
-         To compile this driver as a module, choose M here and read
-         <file:Documentation/ide/ide.txt>. The module will be called ide-mod.
-         Do not compile this driver as a module if your root file system (the
-         one containing the directory /) is located on an IDE device.
-
-         If you have one or more IDE drives, say Y or M here. If your system
-         has no IDE drives, or if memory requirements are really tight, you
-         could say N here, and select the "Old hard disk driver" below
-         instead to save about 13 KB of memory in the kernel.
-
-if BLK_DEV_IDE
-
 comment "Please see Documentation/ide/ide.txt for help/info on IDE drives"
 
 config IDE_TIMINGS
@@ -348,7 +316,7 @@ config BLK_DEV_IDEPCI
 
 config IDEPCI_PCIBUS_ORDER
        bool "Probe IDE PCI devices in the PCI bus order (DEPRECATED)"
-       depends on BLK_DEV_IDE=y && BLK_DEV_IDEPCI
+       depends on IDE=y && BLK_DEV_IDEPCI
        default y
        help
          Probe IDE PCI devices in the order in which they appear on the
@@ -729,7 +697,7 @@ endif
 
 config BLK_DEV_IDE_PMAC
        tristate "PowerMac on-board IDE support"
-       depends on PPC_PMAC && IDE=y && BLK_DEV_IDE=y
+       depends on PPC_PMAC && IDE=y
        select IDE_TIMINGS
        help
          This driver provides support for the on-board IDE controller on
@@ -963,6 +931,4 @@ config BLK_DEV_IDEDMA
        def_bool BLK_DEV_IDEDMA_SFF || BLK_DEV_IDEDMA_PMAC || \
                 BLK_DEV_IDEDMA_ICS || BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
 
-endif
-
 endif # IDE
index 308b8a12f314b758ac28d3e8c44d67d8ec671d85..ceaf779054eac07246702bf789b0ffbc6a97b7b3 100644 (file)
@@ -5,24 +5,25 @@
 EXTRA_CFLAGS                           += -Idrivers/ide
 
 ide-core-y += ide.o ide-ioctls.o ide-io.o ide-iops.o ide-lib.o ide-probe.o \
-             ide-taskfile.o ide-pio-blacklist.o
+             ide-taskfile.o ide-park.o ide-pio-blacklist.o
 
 # core IDE code
 ide-core-$(CONFIG_IDE_TIMINGS)         += ide-timings.o
 ide-core-$(CONFIG_IDE_ATAPI)           += ide-atapi.o
 ide-core-$(CONFIG_BLK_DEV_IDEPCI)      += setup-pci.o
 ide-core-$(CONFIG_BLK_DEV_IDEDMA)      += ide-dma.o
+ide-core-$(CONFIG_BLK_DEV_IDEDMA_SFF)  += ide-dma-sff.o
 ide-core-$(CONFIG_IDE_PROC_FS)         += ide-proc.o
 ide-core-$(CONFIG_BLK_DEV_IDEACPI)     += ide-acpi.o
 
-obj-$(CONFIG_BLK_DEV_IDE)              += ide-core.o
+obj-$(CONFIG_IDE)                      += ide-core.o
 
 ifeq ($(CONFIG_IDE_ARM), y)
        ide-arm-core-y += arm/ide_arm.o
        obj-y += ide-arm-core.o
 endif
 
-obj-$(CONFIG_BLK_DEV_IDE)              += legacy/ pci/
+obj-$(CONFIG_IDE)                      += legacy/ pci/
 
 obj-$(CONFIG_IDEPCI_PCIBUS_ORDER)      += ide-scan-pci.o
 
@@ -31,15 +32,21 @@ ifeq ($(CONFIG_BLK_DEV_CMD640), y)
        obj-y += cmd640-core.o
 endif
 
-obj-$(CONFIG_BLK_DEV_IDE)              += ppc/
+obj-$(CONFIG_IDE)                      += ppc/
 obj-$(CONFIG_IDE_H8300)                        += h8300/
 obj-$(CONFIG_IDE_GENERIC)              += ide-generic.o
 obj-$(CONFIG_BLK_DEV_IDEPNP)           += ide-pnp.o
 
+ide-disk_mod-y += ide-disk.o ide-disk_ioctl.o
 ide-cd_mod-y += ide-cd.o ide-cd_ioctl.o ide-cd_verbose.o
 ide-floppy_mod-y += ide-floppy.o ide-floppy_ioctl.o
 
-obj-$(CONFIG_BLK_DEV_IDEDISK)          += ide-disk.o
+ifeq ($(CONFIG_IDE_PROC_FS), y)
+       ide-disk_mod-y += ide-disk_proc.o
+       ide-floppy_mod-y += ide-floppy_proc.o
+endif
+
+obj-$(CONFIG_BLK_DEV_IDEDISK)          += ide-disk_mod.o
 obj-$(CONFIG_BLK_DEV_IDECD)            += ide-cd_mod.o
 obj-$(CONFIG_BLK_DEV_IDEFLOPPY)                += ide-floppy_mod.o
 obj-$(CONFIG_BLK_DEV_IDETAPE)          += ide-tape.o
@@ -54,4 +61,4 @@ ifeq ($(CONFIG_BLK_DEV_PLATFORM), y)
        obj-y += ide-platform-core.o
 endif
 
-obj-$(CONFIG_BLK_DEV_IDE)              += arm/ mips/
+obj-$(CONFIG_IDE)                      += arm/ mips/
index 70f5b164828b0888681cca503c06298f5d59eda5..76bdc9a27f6f7ae91bbdd0ad4635fb169229a27c 100644 (file)
@@ -372,25 +372,6 @@ static int icside_dma_test_irq(ide_drive_t *drive)
                        ICS_ARCIN_V6_INTRSTAT_1)) & 1;
 }
 
-static void icside_dma_timeout(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-
-       printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
-
-       if (icside_dma_test_irq(drive))
-               return;
-
-       ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
-
-       icside_dma_end(drive);
-}
-
-static void icside_dma_lost_irq(ide_drive_t *drive)
-{
-       printk(KERN_ERR "%s: IRQ lost\n", drive->name);
-}
-
 static int icside_dma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
 {
        hwif->dmatable_cpu      = NULL;
@@ -406,8 +387,8 @@ static const struct ide_dma_ops icside_v6_dma_ops = {
        .dma_start              = icside_dma_start,
        .dma_end                = icside_dma_end,
        .dma_test_irq           = icside_dma_test_irq,
-       .dma_timeout            = icside_dma_timeout,
-       .dma_lost_irq           = icside_dma_lost_irq,
+       .dma_timeout            = ide_dma_timeout,
+       .dma_lost_irq           = ide_dma_lost_irq,
 };
 #else
 #define icside_v6_dma_ops NULL
index bde7a585f1987e3488e318982754143399a3709e..e2cdd2e9cdecc70d388be220b3128d19efaf9de2 100644 (file)
@@ -80,7 +80,7 @@ static void h8300_tf_load(ide_drive_t *drive, ide_task_t *task)
                outb(tf->lbah, io_ports->lbah_addr);
 
        if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
-               outb((tf->device & HIHI) | drive->select.all,
+               outb((tf->device & HIHI) | drive->select,
                     io_ports->device_addr);
 }
 
index 2427c380b3dcd88e44be8c2c3e66581532c7fd00..244a8a052ce85ff3b7bdbe6a28ab5a234b847359 100644 (file)
@@ -290,7 +290,7 @@ static int do_drive_get_GTF(ide_drive_t *drive,
        DEBPRINT("ENTER: %s at %s, port#: %d, hard_port#: %d\n",
                 hwif->name, dev->bus_id, port, hwif->channel);
 
-       if (!drive->present) {
+       if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0) {
                DEBPRINT("%s drive %d:%d not present\n",
                         hwif->name, hwif->channel, port);
                goto out;
@@ -420,8 +420,9 @@ static int do_drive_set_taskfiles(ide_drive_t *drive,
 
        DEBPRINT("ENTER: %s, hard_port#: %d\n", drive->name, drive->dn);
 
-       if (!drive->present)
+       if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                goto out;
+
        if (!gtf_count)         /* shouldn't be here */
                goto out;
 
@@ -660,7 +661,8 @@ void ide_acpi_set_state(ide_hwif_t *hwif, int on)
                if (!drive->acpidata->obj_handle)
                        drive->acpidata->obj_handle = ide_acpi_drive_get_handle(drive);
 
-               if (drive->acpidata->obj_handle && drive->present) {
+               if (drive->acpidata->obj_handle &&
+                   (drive->dev_flags & IDE_DFLAG_PRESENT)) {
                        acpi_bus_set_power(drive->acpidata->obj_handle,
                                on? ACPI_STATE_D0: ACPI_STATE_D3);
                }
@@ -720,7 +722,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
 
                memset(drive->acpidata, 0, sizeof(*drive->acpidata));
 
-               if (!drive->present)
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                        continue;
 
                err = taskfile_lib_get_identify(drive, drive->acpidata->idbuff);
@@ -745,7 +747,7 @@ void ide_acpi_port_init_devices(ide_hwif_t *hwif)
        for (i = 0; i < MAX_DRIVES; i++) {
                drive = &hwif->drives[i];
 
-               if (drive->present)
+               if (drive->dev_flags & IDE_DFLAG_PRESENT)
                        /* Execute ACPI startup code */
                        ide_acpi_exec_tfs(drive);
        }
index 608c5bade92939476d15a1c1f053584fde419e95..2e305714c209e8d9573a2aee1f490ece032b2580 100644 (file)
@@ -124,8 +124,8 @@ EXPORT_SYMBOL_GPL(ide_init_pc);
  * the current request, so that it will be processed immediately, on the next
  * pass through the driver.
  */
-void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
-                      struct ide_atapi_pc *pc, struct request *rq)
+static void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
+                             struct ide_atapi_pc *pc, struct request *rq)
 {
        blk_rq_init(NULL, rq);
        rq->cmd_type = REQ_TYPE_SPECIAL;
@@ -137,7 +137,6 @@ void ide_queue_pc_head(ide_drive_t *drive, struct gendisk *disk,
                rq->cmd[13] = REQ_IDETAPE_PC1;
        ide_do_drive_cmd(drive, rq);
 }
-EXPORT_SYMBOL_GPL(ide_queue_pc_head);
 
 /*
  * Add a special packet command request to the tail of the request queue,
@@ -203,25 +202,80 @@ int ide_set_media_lock(ide_drive_t *drive, struct gendisk *disk, int on)
 }
 EXPORT_SYMBOL_GPL(ide_set_media_lock);
 
-/* TODO: unify the code thus making some arguments go away */
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
-       ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
-       void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
-       void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
-       int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned, int))
+void ide_create_request_sense_cmd(ide_drive_t *drive, struct ide_atapi_pc *pc)
 {
+       ide_init_pc(pc);
+       pc->c[0] = REQUEST_SENSE;
+       if (drive->media == ide_floppy) {
+               pc->c[4] = 255;
+               pc->req_xfer = 18;
+       } else {
+               pc->c[4] = 20;
+               pc->req_xfer = 20;
+       }
+}
+EXPORT_SYMBOL_GPL(ide_create_request_sense_cmd);
+
+/*
+ * Called when an error was detected during the last packet command.
+ * We queue a request sense packet command in the head of the request list.
+ */
+void ide_retry_pc(ide_drive_t *drive, struct gendisk *disk)
+{
+       struct request *rq = &drive->request_sense_rq;
+       struct ide_atapi_pc *pc = &drive->request_sense_pc;
+
+       (void)ide_read_error(drive);
+       ide_create_request_sense_cmd(drive, pc);
+       if (drive->media == ide_tape)
+               set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
+       ide_queue_pc_head(drive, disk, pc, rq);
+}
+EXPORT_SYMBOL_GPL(ide_retry_pc);
+
+int ide_scsi_expiry(ide_drive_t *drive)
+{
+       struct ide_atapi_pc *pc = drive->pc;
+
+       debug_log("%s called for %lu at %lu\n", __func__,
+                 pc->scsi_cmd->serial_number, jiffies);
+
+       pc->flags |= PC_FLAG_TIMEDOUT;
+
+       return 0; /* we do not want the IDE subsystem to retry */
+}
+EXPORT_SYMBOL_GPL(ide_scsi_expiry);
+
+/*
+ * This is the usual interrupt handler which will be called during a packet
+ * command.  We will transfer some of the data (as requested by the drive)
+ * and will re-point interrupt handler to us.
+ */
+static ide_startstop_t ide_pc_intr(ide_drive_t *drive)
+{
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = hwif->hwgroup->rq;
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
        xfer_func_t *xferfunc;
-       unsigned int temp;
+       ide_expiry_t *expiry;
+       unsigned int timeout, temp;
        u16 bcount;
-       u8 stat, ireason, scsi = drive->scsi;
+       u8 stat, ireason, scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI), dsc = 0;
 
        debug_log("Enter %s - interrupt handler\n", __func__);
 
+       if (scsi) {
+               timeout = ide_scsi_get_timeout(pc);
+               expiry = ide_scsi_expiry;
+       } else {
+               timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
+                                                      : WAIT_TAPE_CMD;
+               expiry = NULL;
+       }
+
        if (pc->flags & PC_FLAG_TIMEDOUT) {
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, 0);
                return ide_stopped;
        }
 
@@ -238,8 +292,8 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
                        pc->flags |= PC_FLAG_DMA_ERROR;
                } else {
                        pc->xferred = pc->req_xfer;
-                       if (update_buffers)
-                               update_buffers(drive, pc);
+                       if (drive->pc_update_buffers)
+                               drive->pc_update_buffers(drive, pc);
                }
                debug_log("%s: DMA finished\n", drive->name);
        }
@@ -276,21 +330,19 @@ ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
                        debug_log("[cmd %x]: check condition\n", rq->cmd[0]);
 
                        /* Retry operation */
-                       retry_pc(drive);
+                       ide_retry_pc(drive, rq->rq_disk);
 
                        /* queued, but not started */
                        return ide_stopped;
                }
 cmd_finished:
                pc->error = 0;
-               if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) &&
-                   (stat & ATA_DSC) == 0) {
-                       dsc_handle(drive);
-                       return ide_stopped;
-               }
+
+               if ((pc->flags & PC_FLAG_WAIT_FOR_DSC) && (stat & ATA_DSC) == 0)
+                       dsc = 1;
 
                /* Command finished - Call the callback function */
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, dsc);
 
                return ide_stopped;
        }
@@ -336,7 +388,8 @@ cmd_finished:
                                        temp = 0;
                                if (temp) {
                                        if (pc->sg)
-                                               io_buffers(drive, pc, temp, 0);
+                                               drive->pc_io_buffers(drive, pc,
+                                                                    temp, 0);
                                        else
                                                tp_ops->input_data(drive, NULL,
                                                        pc->cur_pos, temp);
@@ -348,9 +401,7 @@ cmd_finished:
                                pc->xferred += temp;
                                pc->cur_pos += temp;
                                ide_pad_transfer(drive, 0, bcount - temp);
-                               ide_set_handler(drive, handler, timeout,
-                                               expiry);
-                               return ide_started;
+                               goto next_irq;
                        }
                        debug_log("The device wants to send us more data than "
                                  "expected - allowing transfer\n");
@@ -362,7 +413,7 @@ cmd_finished:
        if ((drive->media == ide_floppy && !scsi && !pc->buf) ||
            (drive->media == ide_tape && !scsi && pc->bh) ||
            (scsi && pc->sg)) {
-               int done = io_buffers(drive, pc, bcount,
+               int done = drive->pc_io_buffers(drive, pc, bcount,
                                  !!(pc->flags & PC_FLAG_WRITING));
 
                /* FIXME: don't do partial completions */
@@ -377,12 +428,11 @@ cmd_finished:
 
        debug_log("[cmd %x] transferred %d bytes on that intr.\n",
                  rq->cmd[0], bcount);
-
+next_irq:
        /* And set the interrupt handler again */
-       ide_set_handler(drive, handler, timeout, expiry);
+       ide_set_handler(drive, ide_pc_intr, timeout, expiry);
        return ide_started;
 }
-EXPORT_SYMBOL_GPL(ide_pc_intr);
 
 static u8 ide_read_ireason(ide_drive_t *drive)
 {
@@ -418,12 +468,22 @@ static u8 ide_wait_ireason(ide_drive_t *drive, u8 ireason)
        return ireason;
 }
 
-ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
-                               ide_handler_t *handler, unsigned int timeout,
-                               ide_expiry_t *expiry)
+static int ide_delayed_transfer_pc(ide_drive_t *drive)
 {
+       /* Send the actual packet */
+       drive->hwif->tp_ops->output_data(drive, NULL, drive->pc->c, 12);
+
+       /* Timeout for the packet command */
+       return WAIT_FLOPPY_CMD;
+}
+
+static ide_startstop_t ide_transfer_pc(ide_drive_t *drive)
+{
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
        struct request *rq = hwif->hwgroup->rq;
+       ide_expiry_t *expiry;
+       unsigned int timeout;
        ide_startstop_t startstop;
        u8 ireason;
 
@@ -434,7 +494,8 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
        }
 
        ireason = ide_read_ireason(drive);
-       if (drive->media == ide_tape && !drive->scsi)
+       if (drive->media == ide_tape &&
+           (drive->dev_flags & IDE_DFLAG_SCSI) == 0)
                ireason = ide_wait_ireason(drive, ireason);
 
        if ((ireason & ATAPI_COD) == 0 || (ireason & ATAPI_IO)) {
@@ -443,8 +504,27 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
                return ide_do_reset(drive);
        }
 
+       /*
+        * If necessary schedule the packet transfer to occur 'timeout'
+        * miliseconds later in ide_delayed_transfer_pc() after the device
+        * says it's ready for a packet.
+        */
+       if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
+               timeout = drive->pc_delay;
+               expiry = &ide_delayed_transfer_pc;
+       } else {
+               if (drive->dev_flags & IDE_DFLAG_SCSI) {
+                       timeout = ide_scsi_get_timeout(pc);
+                       expiry = ide_scsi_expiry;
+               } else {
+                       timeout = (drive->media == ide_floppy) ? WAIT_FLOPPY_CMD
+                                                              : WAIT_TAPE_CMD;
+                       expiry = NULL;
+               }
+       }
+
        /* Set the interrupt routine */
-       ide_set_handler(drive, handler, timeout, expiry);
+       ide_set_handler(drive, ide_pc_intr, timeout, expiry);
 
        /* Begin DMA, if necessary */
        if (pc->flags & PC_FLAG_DMA_OK) {
@@ -458,22 +538,22 @@ ide_startstop_t ide_transfer_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
 
        return ide_started;
 }
-EXPORT_SYMBOL_GPL(ide_transfer_pc);
 
-ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
-                            ide_handler_t *handler, unsigned int timeout,
+ide_startstop_t ide_issue_pc(ide_drive_t *drive, unsigned int timeout,
                             ide_expiry_t *expiry)
 {
+       struct ide_atapi_pc *pc = drive->pc;
        ide_hwif_t *hwif = drive->hwif;
+       u32 tf_flags;
        u16 bcount;
-       u8 dma = 0;
+       u8 scsi = !!(drive->dev_flags & IDE_DFLAG_SCSI);
 
        /* We haven't transferred any data yet */
        pc->xferred = 0;
        pc->cur_pos = pc->buf;
 
        /* Request to transfer the entire buffer at once */
-       if (drive->media == ide_tape && !drive->scsi)
+       if (drive->media == ide_tape && scsi == 0)
                bcount = pc->req_xfer;
        else
                bcount = min(pc->req_xfer, 63 * 1024);
@@ -483,28 +563,35 @@ ide_startstop_t ide_issue_pc(ide_drive_t *drive, struct ide_atapi_pc *pc,
                ide_dma_off(drive);
        }
 
-       if ((pc->flags & PC_FLAG_DMA_OK) && drive->using_dma) {
-               if (drive->scsi)
+       if ((pc->flags & PC_FLAG_DMA_OK) &&
+           (drive->dev_flags & IDE_DFLAG_USING_DMA)) {
+               if (scsi)
                        hwif->sg_mapped = 1;
-               dma = !hwif->dma_ops->dma_setup(drive);
-               if (drive->scsi)
+               drive->dma = !hwif->dma_ops->dma_setup(drive);
+               if (scsi)
                        hwif->sg_mapped = 0;
        }
 
-       if (!dma)
+       if (!drive->dma)
                pc->flags &= ~PC_FLAG_DMA_OK;
 
-       ide_pktcmd_tf_load(drive, drive->scsi ? 0 : IDE_TFLAG_OUT_DEVICE,
-                          bcount, dma);
+       if (scsi)
+               tf_flags = 0;
+       else if (drive->media == ide_cdrom || drive->media == ide_optical)
+               tf_flags = IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL;
+       else
+               tf_flags = IDE_TFLAG_OUT_DEVICE;
+
+       ide_pktcmd_tf_load(drive, tf_flags, bcount, drive->dma);
 
        /* Issue the packet command */
        if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
-               ide_execute_command(drive, ATA_CMD_PACKET, handler,
+               ide_execute_command(drive, ATA_CMD_PACKET, ide_transfer_pc,
                                    timeout, NULL);
                return ide_started;
        } else {
                ide_execute_pkt_cmd(drive);
-               return (*handler)(drive);
+               return ide_transfer_pc(drive);
        }
 }
 EXPORT_SYMBOL_GPL(ide_issue_pc);
index 465a92ca01794bd7c2bb2b7630a70c84d04b3776..3308b1cd3a335de2cf4da4867ec7ca2597649f5a 100644 (file)
@@ -23,6 +23,9 @@
  *     Documentation/ide/ChangeLog.ide-cd.1994-2004
  */
 
+#define DRV_NAME "ide-cd"
+#define PFX DRV_NAME ": "
+
 #define IDECD_VERSION "5.00"
 
 #include <linux/module.h>
 
 #include "ide-cd.h"
 
-static DEFINE_MUTEX(idecd_ref_mutex);
+#define IDECD_DEBUG_LOG                1
 
-#define to_ide_cd(obj) container_of(obj, struct cdrom_info, kref)
+#if IDECD_DEBUG_LOG
+#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
+#else
+#define ide_debug_log(lvl, fmt, args...) do {} while (0)
+#endif
 
-#define ide_cd_g(disk) \
-       container_of((disk)->private_data, struct cdrom_info, driver)
+static DEFINE_MUTEX(idecd_ref_mutex);
 
 static void ide_cd_release(struct kref *);
 
@@ -64,7 +70,7 @@ static struct cdrom_info *ide_cd_get(struct gendisk *disk)
        struct cdrom_info *cd = NULL;
 
        mutex_lock(&idecd_ref_mutex);
-       cd = ide_cd_g(disk);
+       cd = ide_drv_g(disk, cdrom_info);
        if (cd) {
                if (ide_device_get(cd->drive))
                        cd = NULL;
@@ -102,6 +108,9 @@ static int cdrom_log_sense(ide_drive_t *drive, struct request *rq,
 {
        int log = 0;
 
+       ide_debug_log(IDE_DBG_SENSE, "Call %s, sense_key: 0x%x\n", __func__,
+                     sense->sense_key);
+
        if (!sense || !rq || (rq->cmd_flags & REQ_QUIET))
                return 0;
 
@@ -150,6 +159,14 @@ static void cdrom_analyze_sense_data(ide_drive_t *drive,
        unsigned long bio_sectors;
        struct cdrom_info *info = drive->driver_data;
 
+       ide_debug_log(IDE_DBG_SENSE, "Call %s, error_code: 0x%x, "
+                       "sense_key: 0x%x\n", __func__, sense->error_code,
+                       sense->sense_key);
+
+       if (failed_command)
+               ide_debug_log(IDE_DBG_SENSE, "%s: failed cmd: 0x%x\n",
+                               __func__, failed_command->cmd[0]);
+
        if (!cdrom_log_sense(drive, failed_command, sense))
                return;
 
@@ -200,6 +217,8 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
        struct cdrom_info *info         = drive->driver_data;
        struct request *rq              = &info->request_sense_request;
 
+       ide_debug_log(IDE_DBG_SENSE, "Call %s\n", __func__);
+
        if (sense == NULL)
                sense = &info->sense_data;
 
@@ -219,6 +238,10 @@ static void cdrom_queue_request_sense(ide_drive_t *drive, void *sense,
        /* NOTE! Save the failed command in "rq->buffer" */
        rq->buffer = (void *) failed_command;
 
+       if (failed_command)
+               ide_debug_log(IDE_DBG_SENSE, "failed_cmd: 0x%x\n",
+                             failed_command->cmd[0]);
+
        ide_do_drive_cmd(drive, rq);
 }
 
@@ -227,6 +250,10 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
        struct request *rq = HWGROUP(drive)->rq;
        int nsectors = rq->hard_cur_sectors;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s, cmd: 0x%x, uptodate: 0x%x, "
+                     "nsectors: %d\n", __func__, rq->cmd[0], uptodate,
+                     nsectors);
+
        if (blk_sense_request(rq) && uptodate) {
                /*
                 * For REQ_TYPE_SENSE, "rq->buffer" points to the original
@@ -269,6 +296,9 @@ static void cdrom_end_request(ide_drive_t *drive, int uptodate)
        if (!nsectors)
                nsectors = 1;
 
+       ide_debug_log(IDE_DBG_FUNC, "Exit %s, uptodate: 0x%x, nsectors: %d\n",
+                     __func__, uptodate, nsectors);
+
        ide_end_request(drive, uptodate, nsectors);
 }
 
@@ -304,11 +334,15 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
        sense_key = err >> 4;
 
        if (rq == NULL) {
-               printk(KERN_ERR "%s: missing rq in %s\n",
+               printk(KERN_ERR PFX "%s: missing rq in %s\n",
                                drive->name, __func__);
                return 1;
        }
 
+       ide_debug_log(IDE_DBG_RQ, "%s: stat: 0x%x, good_stat: 0x%x, "
+                     "rq->cmd_type: 0x%x, err: 0x%x\n", __func__, stat,
+                     good_stat, rq->cmd_type, err);
+
        if (blk_sense_request(rq)) {
                /*
                 * We got an error trying to get sense info from the drive
@@ -374,7 +408,8 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                                cdrom_saw_media_change(drive);
 
                                /* fail the request */
-                               printk(KERN_ERR "%s: tray open\n", drive->name);
+                               printk(KERN_ERR PFX "%s: tray open\n",
+                                               drive->name);
                                do_end_request = 1;
                        } else {
                                struct cdrom_info *info = drive->driver_data;
@@ -460,7 +495,7 @@ static int cdrom_decode_status(ide_drive_t *drive, int good_stat, int *stat_ret)
                if (stat & ATA_ERR)
                        cdrom_queue_request_sense(drive, NULL, NULL);
        } else {
-               blk_dump_rq_flags(rq, "ide-cd: bad rq");
+               blk_dump_rq_flags(rq, PFX "bad rq");
                cdrom_end_request(drive, 0);
        }
 
@@ -488,6 +523,9 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
        struct request *rq = HWGROUP(drive)->rq;
        unsigned long wait = 0;
 
+       ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd[0]: 0x%x\n", __func__,
+                     rq->cmd[0]);
+
        /*
         * Some commands are *slow* and normally take a long time to complete.
         * Usually we can use the ATAPI "disconnect" to bypass this, but not all
@@ -504,7 +542,7 @@ static int cdrom_timer_expiry(ide_drive_t *drive)
                break;
        default:
                if (!(rq->cmd_flags & REQ_QUIET))
-                       printk(KERN_INFO "ide-cd: cmd 0x%x timed out\n",
+                       printk(KERN_INFO PFX "cmd 0x%x timed out\n",
                                         rq->cmd[0]);
                wait = 0;
                break;
@@ -524,20 +562,21 @@ static ide_startstop_t cdrom_start_packet_command(ide_drive_t *drive,
                                                  int xferlen,
                                                  ide_handler_t *handler)
 {
-       struct cdrom_info *info = drive->driver_data;
        ide_hwif_t *hwif = drive->hwif;
 
+       ide_debug_log(IDE_DBG_PC, "Call %s, xferlen: %d\n", __func__, xferlen);
+
        /* FIXME: for Virtual DMA we must check harder */
-       if (info->dma)
-               info->dma = !hwif->dma_ops->dma_setup(drive);
+       if (drive->dma)
+               drive->dma = !hwif->dma_ops->dma_setup(drive);
 
        /* set up the controller registers */
        ide_pktcmd_tf_load(drive, IDE_TFLAG_OUT_NSECT | IDE_TFLAG_OUT_LBAL,
-                          xferlen, info->dma);
+                          xferlen, drive->dma);
 
        if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
                /* waiting for CDB interrupt, not DMA yet. */
-               if (info->dma)
+               if (drive->dma)
                        drive->waiting_for_dma = 0;
 
                /* packet command */
@@ -564,9 +603,10 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
 {
        ide_hwif_t *hwif = drive->hwif;
        int cmd_len;
-       struct cdrom_info *info = drive->driver_data;
        ide_startstop_t startstop;
 
+       ide_debug_log(IDE_DBG_PC, "Call %s\n", __func__);
+
        if (drive->atapi_flags & IDE_AFLAG_DRQ_INTERRUPT) {
                /*
                 * Here we should have been called after receiving an interrupt
@@ -578,7 +618,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
                        return ide_stopped;
 
                /* ok, next interrupt will be DMA interrupt */
-               if (info->dma)
+               if (drive->dma)
                        drive->waiting_for_dma = 1;
        } else {
                /* otherwise, we must wait for DRQ to get set */
@@ -599,7 +639,7 @@ static ide_startstop_t cdrom_transfer_packet_command(ide_drive_t *drive,
        hwif->tp_ops->output_data(drive, NULL, rq->cmd, cmd_len);
 
        /* start the DMA if need be */
-       if (info->dma)
+       if (drive->dma)
                hwif->dma_ops->dma_start(drive);
 
        return ide_started;
@@ -615,6 +655,9 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
 {
        ide_hwif_t *hwif = drive->hwif;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s, ireason: 0x%x, rw: 0x%x\n",
+                     __func__, ireason, rw);
+
        /*
         * ireason == 0: the drive wants to receive data from us
         * ireason == 2: the drive is expecting to transfer data to us
@@ -624,7 +667,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
        else if (ireason == (rw << 1)) {
 
                /* whoops... */
-               printk(KERN_ERR "%s: %s: wrong transfer direction!\n",
+               printk(KERN_ERR PFX "%s: %s: wrong transfer direction!\n",
                                drive->name, __func__);
 
                ide_pad_transfer(drive, rw, len);
@@ -637,7 +680,7 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
                return 0;
        } else {
                /* drive wants a command packet, or invalid ireason... */
-               printk(KERN_ERR "%s: %s: bad interrupt reason 0x%02x\n",
+               printk(KERN_ERR PFX "%s: %s: bad interrupt reason 0x%02x\n",
                                drive->name, __func__, ireason);
        }
 
@@ -654,17 +697,19 @@ static int ide_cd_check_ireason(ide_drive_t *drive, struct request *rq,
  */
 static int ide_cd_check_transfer_size(ide_drive_t *drive, int len)
 {
+       ide_debug_log(IDE_DBG_FUNC, "Call %s, len: %d\n", __func__, len);
+
        if ((len % SECTOR_SIZE) == 0)
                return 0;
 
-       printk(KERN_ERR "%s: %s: Bad transfer size %d\n",
-                       drive->name, __func__, len);
+       printk(KERN_ERR PFX "%s: %s: Bad transfer size %d\n", drive->name,
+                       __func__, len);
 
        if (drive->atapi_flags & IDE_AFLAG_LIMIT_NFRAMES)
-               printk(KERN_ERR "  This drive is not supported by "
-                               "this version of the driver\n");
+               printk(KERN_ERR PFX "This drive is not supported by this "
+                               "version of the driver\n");
        else {
-               printk(KERN_ERR "  Trying to limit transfer sizes\n");
+               printk(KERN_ERR PFX "Trying to limit transfer sizes\n");
                drive->atapi_flags |= IDE_AFLAG_LIMIT_NFRAMES;
        }
 
@@ -676,6 +721,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *);
 static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
                                                 struct request *rq)
 {
+       ide_debug_log(IDE_DBG_RQ, "Call %s: rq->cmd_flags: 0x%x\n", __func__,
+                     rq->cmd_flags);
+
        if (rq_data_dir(rq) == READ) {
                unsigned short sectors_per_frame =
                        queue_hardsect_size(drive->queue) >> SECTOR_BITS;
@@ -695,7 +743,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
                        /* sanity check... */
                        if (rq->current_nr_sectors !=
                            bio_cur_sectors(rq->bio)) {
-                               printk(KERN_ERR "%s: %s: buffer botch (%u)\n",
+                               printk(KERN_ERR PFX "%s: %s: buffer botch (%u)\n",
                                                drive->name, __func__,
                                                rq->current_nr_sectors);
                                cdrom_end_request(drive, 0);
@@ -704,11 +752,7 @@ static ide_startstop_t ide_cd_prepare_rw_request(ide_drive_t *drive,
                        rq->current_nr_sectors += nskip;
                }
        }
-#if 0
-       else
-               /* the immediate bit */
-               rq->cmd[1] = 1 << 3;
-#endif
+
        /* set up the command */
        rq->timeout = ATAPI_WAIT_PC;
 
@@ -739,6 +783,8 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
        int stat;
        static int retry = 10;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        if (cdrom_decode_status(drive, 0, &stat))
                return ide_stopped;
 
@@ -746,7 +792,7 @@ static ide_startstop_t cdrom_seek_intr(ide_drive_t *drive)
 
        if (retry && time_after(jiffies, info->start_seek + IDECD_SEEK_TIMER)) {
                if (--retry == 0)
-                       drive->dsc_overlap = 0;
+                       drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
        }
        return ide_stopped;
 }
@@ -755,6 +801,8 @@ static void ide_cd_prepare_seek_request(ide_drive_t *drive, struct request *rq)
 {
        sector_t frame = rq->sector;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        sector_div(frame, queue_hardsect_size(drive->queue) >> SECTOR_BITS);
 
        memset(rq->cmd, 0, BLK_MAX_CDB);
@@ -775,8 +823,11 @@ static ide_startstop_t cdrom_start_seek_continuation(ide_drive_t *drive)
  * Fix up a possibly partially-processed request so that we can start it over
  * entirely, or even put it back on the request queue.
  */
-static void restore_request(struct request *rq)
+static void ide_cd_restore_request(ide_drive_t *drive, struct request *rq)
 {
+
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        if (rq->buffer != bio_data(rq->bio)) {
                sector_t n =
                        (rq->buffer - (char *)bio_data(rq->bio)) / SECTOR_SIZE;
@@ -795,8 +846,11 @@ static void restore_request(struct request *rq)
 /*
  * All other packet commands.
  */
-static void ide_cd_request_sense_fixup(struct request *rq)
+static void ide_cd_request_sense_fixup(ide_drive_t *drive, struct request *rq)
 {
+
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        /*
         * Some of the trailing request sense fields are optional,
         * and some drives don't send them.  Sigh.
@@ -822,6 +876,10 @@ int ide_cd_queue_pc(ide_drive_t *drive, const unsigned char *cmd,
        if (!sense)
                sense = &local_sense;
 
+       ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x, "
+                     "timeout: %d, cmd_flags: 0x%x\n", __func__, cmd[0], write,
+                     timeout, cmd_flags);
+
        /* start of retry loop */
        do {
                struct request *rq;
@@ -895,7 +953,6 @@ static int cdrom_newpc_intr_dummy_cb(struct request *rq)
 static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       struct cdrom_info *info = drive->driver_data;
        struct request *rq = HWGROUP(drive)->rq;
        xfer_func_t *xferfunc;
        ide_expiry_t *expiry = NULL;
@@ -905,13 +962,16 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
        u16 len;
        u8 ireason;
 
+       ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd[0]: 0x%x, write: 0x%x\n",
+                     __func__, rq->cmd[0], write);
+
        /* check for errors */
-       dma = info->dma;
+       dma = drive->dma;
        if (dma) {
-               info->dma = 0;
+               drive->dma = 0;
                dma_error = hwif->dma_ops->dma_end(drive);
                if (dma_error) {
-                       printk(KERN_ERR "%s: DMA %s error\n", drive->name,
+                       printk(KERN_ERR PFX "%s: DMA %s error\n", drive->name,
                                        write ? "write" : "read");
                        ide_dma_off(drive);
                }
@@ -937,6 +997,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
        if (thislen > len)
                thislen = len;
 
+       ide_debug_log(IDE_DBG_PC, "%s: DRQ: stat: 0x%x, thislen: %d\n",
+                     __func__, stat, thislen);
+
        /* If DRQ is clear, the command has completed. */
        if ((stat & ATA_DRQ) == 0) {
                if (blk_fs_request(rq)) {
@@ -946,7 +1009,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                         */
                        uptodate = 1;
                        if (rq->current_nr_sectors > 0) {
-                               printk(KERN_ERR "%s: %s: data underrun "
+                               printk(KERN_ERR PFX "%s: %s: data underrun "
                                                "(%d blocks)\n",
                                                drive->name, __func__,
                                                rq->current_nr_sectors);
@@ -957,7 +1020,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                        cdrom_end_request(drive, uptodate);
                        return ide_stopped;
                } else if (!blk_pc_request(rq)) {
-                       ide_cd_request_sense_fixup(rq);
+                       ide_cd_request_sense_fixup(drive, rq);
                        /* complain if we still have data left to transfer */
                        uptodate = rq->data_len ? 0 : 1;
                }
@@ -1000,6 +1063,9 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                xferfunc = hwif->tp_ops->input_data;
        }
 
+       ide_debug_log(IDE_DBG_PC, "%s: data transfer, rq->cmd_type: 0x%x, "
+                     "ireason: 0x%x\n", __func__, rq->cmd_type, ireason);
+
        /* transfer data */
        while (thislen > 0) {
                u8 *ptr = blk_fs_request(rq) ? NULL : rq->data;
@@ -1024,7 +1090,7 @@ static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive)
                                 */
                                ide_pad_transfer(drive, 0, thislen);
                        else {
-                               printk(KERN_ERR "%s: confused, missing data\n",
+                               printk(KERN_ERR PFX "%s: confused, missing data\n",
                                                drive->name);
                                blk_dump_rq_flags(rq, rq_data_dir(rq)
                                                  ? "cdrom_newpc_intr, write"
@@ -1111,6 +1177,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
        unsigned short sectors_per_frame =
                queue_hardsect_size(drive->queue) >> SECTOR_BITS;
 
+       ide_debug_log(IDE_DBG_RQ, "Call %s, write: 0x%x, secs_per_frame: %u\n",
+                     __func__, write, sectors_per_frame);
+
        if (write) {
                /* disk has become write protected */
                if (get_disk_ro(cd->disk)) {
@@ -1122,7 +1191,7 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
                 * We may be retrying this request after an error.  Fix up any
                 * weirdness which might be present in the request packet.
                 */
-               restore_request(rq);
+               ide_cd_restore_request(drive, rq);
        }
 
        /* use DMA, if possible / writes *must* be hardware frame aligned */
@@ -1132,9 +1201,9 @@ static ide_startstop_t cdrom_start_rw(ide_drive_t *drive, struct request *rq)
                        cdrom_end_request(drive, 0);
                        return ide_stopped;
                }
-               cd->dma = 0;
+               drive->dma = 0;
        } else
-               cd->dma = drive->using_dma;
+               drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
 
        if (write)
                cd->devinfo.media_written = 1;
@@ -1151,14 +1220,16 @@ static ide_startstop_t cdrom_do_newpc_cont(ide_drive_t *drive)
 
 static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
 {
-       struct cdrom_info *info = drive->driver_data;
+
+       ide_debug_log(IDE_DBG_PC, "Call %s, rq->cmd_type: 0x%x\n", __func__,
+                     rq->cmd_type);
 
        if (blk_pc_request(rq))
                rq->cmd_flags |= REQ_QUIET;
        else
                rq->cmd_flags &= ~REQ_FAILED;
 
-       info->dma = 0;
+       drive->dma = 0;
 
        /* sg request */
        if (rq->bio || ((rq->cmd_type == REQ_TYPE_ATA_PC) && rq->data_len)) {
@@ -1171,7 +1242,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
                else
                        buf = rq->data;
 
-               info->dma = drive->using_dma;
+               drive->dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
 
                /*
                 * check if dma is safe
@@ -1182,7 +1253,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
                alignment = queue_dma_alignment(q) | q->dma_pad_mask;
                if ((unsigned long)buf & alignment || rq->data_len & alignment
                    || object_is_on_stack(buf))
-                       info->dma = 0;
+                       drive->dma = 0;
        }
 }
 
@@ -1196,6 +1267,9 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
        ide_handler_t *fn;
        int xferlen;
 
+       ide_debug_log(IDE_DBG_RQ, "Call %s, rq->cmd_type: 0x%x, block: %llu\n",
+                     __func__, rq->cmd_type, (unsigned long long)block);
+
        if (blk_fs_request(rq)) {
                if (drive->atapi_flags & IDE_AFLAG_SEEKING) {
                        ide_hwif_t *hwif = drive->hwif;
@@ -1208,7 +1282,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
                                                        IDECD_SEEK_TIMER);
                                        return ide_stopped;
                                }
-                               printk(KERN_ERR "%s: DSC timeout\n",
+                               printk(KERN_ERR PFX "%s: DSC timeout\n",
                                                drive->name);
                        }
                        drive->atapi_flags &= ~IDE_AFLAG_SEEKING;
@@ -1216,11 +1290,11 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
                if (rq_data_dir(rq) == READ &&
                    IDE_LARGE_SEEK(info->last_block, block,
                            IDECD_SEEK_THRESHOLD) &&
-                   drive->dsc_overlap) {
+                   (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)) {
                        xferlen = 0;
                        fn = cdrom_start_seek_continuation;
 
-                       info->dma = 0;
+                       drive->dma = 0;
                        info->start_seek = jiffies;
 
                        ide_cd_prepare_seek_request(drive, rq);
@@ -1249,7 +1323,7 @@ static ide_startstop_t ide_cd_do_request(ide_drive_t *drive, struct request *rq,
                cdrom_end_request(drive, 1);
                return ide_stopped;
        } else {
-               blk_dump_rq_flags(rq, "ide-cd bad flags");
+               blk_dump_rq_flags(rq, DRV_NAME " bad flags");
                cdrom_end_request(drive, 0);
                return ide_stopped;
        }
@@ -1279,6 +1353,8 @@ int cdrom_check_status(ide_drive_t *drive, struct request_sense *sense)
        struct cdrom_device_info *cdi = &info->devinfo;
        unsigned char cmd[BLK_MAX_CDB];
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        memset(cmd, 0, BLK_MAX_CDB);
        cmd[0] = GPCMD_TEST_UNIT_READY;
 
@@ -1305,6 +1381,8 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
        unsigned len = sizeof(capbuf);
        u32 blocklen;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        memset(cmd, 0, BLK_MAX_CDB);
        cmd[0] = GPCMD_READ_CDVD_CAPACITY;
 
@@ -1324,10 +1402,10 @@ static int cdrom_read_capacity(ide_drive_t *drive, unsigned long *capacity,
        case 4096:
                break;
        default:
-               printk(KERN_ERR "%s: weird block size %u\n",
-                       drive->name, blocklen);
-               printk(KERN_ERR "%s: default to 2kb block size\n",
-                       drive->name);
+               printk(KERN_ERR PFX "%s: weird block size %u\n",
+                               drive->name, blocklen);
+               printk(KERN_ERR PFX "%s: default to 2kb block size\n",
+                               drive->name);
                blocklen = 2048;
                break;
        }
@@ -1343,6 +1421,8 @@ static int cdrom_read_tocentry(ide_drive_t *drive, int trackno, int msf_flag,
 {
        unsigned char cmd[BLK_MAX_CDB];
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        memset(cmd, 0, BLK_MAX_CDB);
 
        cmd[0] = GPCMD_READ_TOC_PMA_ATIP;
@@ -1371,11 +1451,13 @@ int ide_cd_read_toc(ide_drive_t *drive, struct request_sense *sense)
        long last_written;
        unsigned long sectors_per_frame = SECTORS_PER_FRAME;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        if (toc == NULL) {
                /* try to allocate space */
                toc = kmalloc(sizeof(struct atapi_toc), GFP_KERNEL);
                if (toc == NULL) {
-                       printk(KERN_ERR "%s: No cdrom TOC buffer!\n",
+                       printk(KERN_ERR PFX "%s: No cdrom TOC buffer!\n",
                                        drive->name);
                        return -ENOMEM;
                }
@@ -1531,6 +1613,8 @@ int ide_cdrom_get_capabilities(ide_drive_t *drive, u8 *buf)
        struct packet_command cgc;
        int stat, attempts = 3, size = ATAPI_CAPABILITIES_PAGE_SIZE;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        if ((drive->atapi_flags & IDE_AFLAG_FULL_CAPS_PAGE) == 0)
                size -= ATAPI_CAPABILITIES_PAGE_PAD_SIZE;
 
@@ -1549,6 +1633,8 @@ void ide_cdrom_update_speed(ide_drive_t *drive, u8 *buf)
        struct cdrom_info *cd = drive->driver_data;
        u16 curspeed, maxspeed;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        if (drive->atapi_flags & IDE_AFLAG_LE_SPEED_FIELDS) {
                curspeed = le16_to_cpup((__le16 *)&buf[8 + 14]);
                maxspeed = le16_to_cpup((__le16 *)&buf[8 + 8]);
@@ -1589,6 +1675,8 @@ static int ide_cdrom_register(ide_drive_t *drive, int nslots)
        struct cdrom_info *info = drive->driver_data;
        struct cdrom_device_info *devinfo = &info->devinfo;
 
+       ide_debug_log(IDE_DBG_PROBE, "Call %s, nslots: %d\n", __func__, nslots);
+
        devinfo->ops = &ide_cdrom_dops;
        devinfo->speed = info->current_speed;
        devinfo->capacity = nslots;
@@ -1610,13 +1698,17 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
        mechtype_t mechtype;
        int nslots = 1;
 
+       ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->media: 0x%x, "
+                     "drive->atapi_flags: 0x%lx\n", __func__, drive->media,
+                     drive->atapi_flags);
+
        cdi->mask = (CDC_CD_R | CDC_CD_RW | CDC_DVD | CDC_DVD_R |
                     CDC_DVD_RAM | CDC_SELECT_DISC | CDC_PLAY_AUDIO |
                     CDC_MO_DRIVE | CDC_RAM);
 
        if (drive->media == ide_optical) {
                cdi->mask &= ~(CDC_MO_DRIVE | CDC_RAM);
-               printk(KERN_ERR "%s: ATAPI magneto-optical drive\n",
+               printk(KERN_ERR PFX "%s: ATAPI magneto-optical drive\n",
                                drive->name);
                return nslots;
        }
@@ -1674,7 +1766,7 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
 
        ide_cdrom_update_speed(drive, buf);
 
-       printk(KERN_INFO "%s: ATAPI", drive->name);
+       printk(KERN_INFO PFX "%s: ATAPI", drive->name);
 
        /* don't print speed if the drive reported 0 */
        if (cd->max_speed)
@@ -1697,7 +1789,8 @@ static int ide_cdrom_probe_capabilities(ide_drive_t *drive)
        else
                printk(KERN_CONT " drive");
 
-       printk(KERN_CONT ", %dkB Cache\n", be16_to_cpup((__be16 *)&buf[8 + 12]));
+       printk(KERN_CONT ", %dkB Cache\n",
+                        be16_to_cpup((__be16 *)&buf[8 + 12]));
 
        return nslots;
 }
@@ -1809,7 +1902,7 @@ static ide_proc_entry_t idecd_proc[] = {
        { NULL, 0, NULL, NULL }
 };
 
-ide_devset_rw_field(dsc_overlap, dsc_overlap);
+ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
 
 static const struct ide_proc_devset idecd_settings[] = {
        IDE_PROC_DEVSET(dsc_overlap, 0, 1),
@@ -1884,6 +1977,8 @@ static int ide_cdrom_setup(ide_drive_t *drive)
        char *fw_rev = (char *)&id[ATA_ID_FW_REV];
        int nslots;
 
+       ide_debug_log(IDE_DBG_PROBE, "Call %s\n", __func__);
+
        blk_queue_prep_rq(drive->queue, ide_cdrom_prep_fn);
        blk_queue_dma_alignment(drive->queue, 31);
        blk_queue_update_dma_pad(drive->queue, 15);
@@ -1891,14 +1986,9 @@ static int ide_cdrom_setup(ide_drive_t *drive)
        if (!drive->queue->unplug_delay)
                drive->queue->unplug_delay = 1;
 
-       drive->special.all      = 0;
-
        drive->atapi_flags = IDE_AFLAG_MEDIA_CHANGED | IDE_AFLAG_NO_EJECT |
                       ide_cd_flags(id);
 
-       if ((id[ATA_ID_CONFIG] & 0x0060) == 0x20)
-               drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
-
        if ((drive->atapi_flags & IDE_AFLAG_VERTOS_300_SSD) &&
            fw_rev[4] == '1' && fw_rev[6] <= '2')
                drive->atapi_flags |= (IDE_AFLAG_TOCTRACKS_AS_BCD |
@@ -1915,10 +2005,13 @@ static int ide_cdrom_setup(ide_drive_t *drive)
        /* set correct block size */
        blk_queue_hardsect_size(drive->queue, CD_FRAMESIZE);
 
-       drive->dsc_overlap = (drive->next != drive);
+       if (drive->next != drive)
+               drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
 
        if (ide_cdrom_register(drive, nslots)) {
-               printk(KERN_ERR "%s: %s failed to register device with the"
+               printk(KERN_ERR PFX "%s: %s failed to register device with the"
                                " cdrom driver.\n", drive->name, __func__);
                cd->devinfo.handle = NULL;
                return 1;
@@ -1932,6 +2025,8 @@ static void ide_cd_remove(ide_drive_t *drive)
 {
        struct cdrom_info *info = drive->driver_data;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        ide_proc_unregister_driver(drive, info->driver);
 
        del_gendisk(info->disk);
@@ -1941,15 +2036,17 @@ static void ide_cd_remove(ide_drive_t *drive)
 
 static void ide_cd_release(struct kref *kref)
 {
-       struct cdrom_info *info = to_ide_cd(kref);
+       struct cdrom_info *info = to_ide_drv(kref, cdrom_info);
        struct cdrom_device_info *devinfo = &info->devinfo;
        ide_drive_t *drive = info->drive;
        struct gendisk *g = info->disk;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        kfree(info->toc);
        if (devinfo->handle == drive)
                unregister_cdrom(devinfo);
-       drive->dsc_overlap = 0;
+       drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
        drive->driver_data = NULL;
        blk_queue_prep_rq(drive->queue, NULL);
        g->private_data = NULL;
@@ -1968,7 +2065,6 @@ static ide_driver_t ide_cdrom_driver = {
        .probe                  = ide_cd_probe,
        .remove                 = ide_cd_remove,
        .version                = IDECD_VERSION,
-       .media                  = ide_cdrom,
        .do_request             = ide_cd_do_request,
        .end_request            = ide_end_request,
        .error                  = __ide_error,
@@ -1999,7 +2095,7 @@ static int idecd_open(struct inode *inode, struct file *file)
 static int idecd_release(struct inode *inode, struct file *file)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
-       struct cdrom_info *info = ide_cd_g(disk);
+       struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
 
        cdrom_release(&info->devinfo, file);
 
@@ -2051,7 +2147,7 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
        struct block_device *bdev = inode->i_bdev;
-       struct cdrom_info *info = ide_cd_g(bdev->bd_disk);
+       struct cdrom_info *info = ide_drv_g(bdev->bd_disk, cdrom_info);
        int err;
 
        switch (cmd) {
@@ -2072,13 +2168,13 @@ static int idecd_ioctl(struct inode *inode, struct file *file,
 
 static int idecd_media_changed(struct gendisk *disk)
 {
-       struct cdrom_info *info = ide_cd_g(disk);
+       struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
        return cdrom_media_changed(&info->devinfo);
 }
 
 static int idecd_revalidate_disk(struct gendisk *disk)
 {
-       struct cdrom_info *info = ide_cd_g(disk);
+       struct cdrom_info *info = ide_drv_g(disk, cdrom_info);
        struct request_sense sense;
 
        ide_cd_read_toc(info->drive, &sense);
@@ -2097,8 +2193,11 @@ static struct block_device_operations idecd_ops = {
 
 /* module options */
 static char *ignore;
-
 module_param(ignore, charp, 0400);
+
+static unsigned long debug_mask;
+module_param(debug_mask, ulong, 0644);
+
 MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
 
 static int ide_cd_probe(ide_drive_t *drive)
@@ -2107,6 +2206,10 @@ static int ide_cd_probe(ide_drive_t *drive)
        struct gendisk *g;
        struct request_sense sense;
 
+       ide_debug_log(IDE_DBG_PROBE, "Call %s, drive->driver_req: %s, "
+                     "drive->media: 0x%x\n", __func__, drive->driver_req,
+                     drive->media);
+
        if (!strstr("ide-cdrom", drive->driver_req))
                goto failed;
 
@@ -2116,14 +2219,17 @@ static int ide_cd_probe(ide_drive_t *drive)
        /* skip drives that we were told to ignore */
        if (ignore != NULL) {
                if (strstr(ignore, drive->name)) {
-                       printk(KERN_INFO "ide-cd: ignoring drive %s\n",
+                       printk(KERN_INFO PFX "ignoring drive %s\n",
                                         drive->name);
                        goto failed;
                }
        }
+
+       drive->debug_mask = debug_mask;
+
        info = kzalloc(sizeof(struct cdrom_info), GFP_KERNEL);
        if (info == NULL) {
-               printk(KERN_ERR "%s: Can't allocate a cdrom structure\n",
+               printk(KERN_ERR PFX "%s: Can't allocate a cdrom structure\n",
                                drive->name);
                goto failed;
        }
@@ -2171,6 +2277,7 @@ static void __exit ide_cdrom_exit(void)
 
 static int __init ide_cdrom_init(void)
 {
+       printk(KERN_INFO DRV_NAME " driver " IDECD_VERSION "\n");
        return driver_register(&ide_cdrom_driver.gen_driver);
 }
 
index 61a4599b77dbf3c37528799118c181960a5f5786..5882b9a9ea8b7becc8108872e996ab9f852af95d 100644 (file)
@@ -88,7 +88,6 @@ struct cdrom_info {
        struct request_sense sense_data;
 
        struct request request_sense_request;
-       int dma;
        unsigned long last_block;
        unsigned long start_seek;
 
index 01846f244b40156b3822bcb504f05f7c18b12bd5..3853bde8eedc3c291b8b676529563afccdcc2f0d 100644 (file)
 #define IDE_DISK_MINORS                0
 #endif
 
-struct ide_disk_obj {
-       ide_drive_t     *drive;
-       ide_driver_t    *driver;
-       struct gendisk  *disk;
-       struct kref     kref;
-       unsigned int    openers;        /* protected by BKL for now */
-};
+#include "ide-disk.h"
 
 static DEFINE_MUTEX(idedisk_ref_mutex);
 
 #define to_ide_disk(obj) container_of(obj, struct ide_disk_obj, kref)
 
-#define ide_disk_g(disk) \
-       container_of((disk)->private_data, struct ide_disk_obj, driver)
-
 static void ide_disk_release(struct kref *);
 
 static struct ide_disk_obj *ide_disk_get(struct gendisk *disk)
@@ -140,9 +131,9 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
                                        sector_t block)
 {
        ide_hwif_t *hwif        = HWIF(drive);
-       unsigned int dma        = drive->using_dma;
        u16 nsectors            = (u16)rq->nr_sectors;
-       u8 lba48                = (drive->addressing == 1) ? 1 : 0;
+       u8 lba48                = !!(drive->dev_flags & IDE_DFLAG_LBA48);
+       u8 dma                  = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
        ide_task_t              task;
        struct ide_taskfile     *tf = &task.tf;
        ide_startstop_t         rc;
@@ -162,7 +153,7 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
        memset(&task, 0, sizeof(task));
        task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
 
-       if (drive->select.b.lba) {
+       if (drive->dev_flags & IDE_DFLAG_LBA) {
                if (lba48) {
                        pr_debug("%s: LBA=0x%012llx\n", drive->name,
                                        (unsigned long long)block);
@@ -187,6 +178,8 @@ static ide_startstop_t __ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
                        tf->lbah   = block >>= 8;
                        tf->device = (block >> 8) & 0xf;
                }
+
+               tf->device |= ATA_LBA;
        } else {
                unsigned int sect, head, cyl, track;
 
@@ -237,7 +230,7 @@ static ide_startstop_t ide_do_rw_disk(ide_drive_t *drive, struct request *rq,
 {
        ide_hwif_t *hwif = HWIF(drive);
 
-       BUG_ON(drive->blocked);
+       BUG_ON(drive->dev_flags & IDE_DFLAG_BLOCKED);
 
        if (!blk_fs_request(rq)) {
                blk_dump_rq_flags(rq, "ide_do_rw_disk - bad command");
@@ -384,139 +377,39 @@ static void idedisk_check_hpa(ide_drive_t *drive)
 static void init_idedisk_capacity(ide_drive_t *drive)
 {
        u16 *id = drive->id;
-       /*
-        * If this drive supports the Host Protected Area feature set,
-        * then we may need to change our opinion about the drive's capacity.
-        */
-       int hpa = ata_id_hpa_enabled(id);
+       int lba;
 
        if (ata_id_lba48_enabled(id)) {
                /* drive speaks 48-bit LBA */
-               drive->select.b.lba = 1;
+               lba = 1;
                drive->capacity64 = ata_id_u64(id, ATA_ID_LBA_CAPACITY_2);
-               if (hpa)
-                       idedisk_check_hpa(drive);
        } else if (ata_id_has_lba(id) && ata_id_is_lba_capacity_ok(id)) {
                /* drive speaks 28-bit LBA */
-               drive->select.b.lba = 1;
+               lba = 1;
                drive->capacity64 = ata_id_u32(id, ATA_ID_LBA_CAPACITY);
-               if (hpa)
-                       idedisk_check_hpa(drive);
        } else {
                /* drive speaks boring old 28-bit CHS */
+               lba = 0;
                drive->capacity64 = drive->cyl * drive->head * drive->sect;
        }
-}
 
-static sector_t idedisk_capacity(ide_drive_t *drive)
-{
-       return drive->capacity64;
-}
+       if (lba) {
+               drive->dev_flags |= IDE_DFLAG_LBA;
 
-#ifdef CONFIG_IDE_PROC_FS
-static int smart_enable(ide_drive_t *drive)
-{
-       ide_task_t args;
-       struct ide_taskfile *tf = &args.tf;
-
-       memset(&args, 0, sizeof(ide_task_t));
-       tf->feature = ATA_SMART_ENABLE;
-       tf->lbam    = ATA_SMART_LBAM_PASS;
-       tf->lbah    = ATA_SMART_LBAH_PASS;
-       tf->command = ATA_CMD_SMART;
-       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       return ide_no_data_taskfile(drive, &args);
-}
-
-static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
-{
-       ide_task_t args;
-       struct ide_taskfile *tf = &args.tf;
-
-       memset(&args, 0, sizeof(ide_task_t));
-       tf->feature = sub_cmd;
-       tf->nsect   = 0x01;
-       tf->lbam    = ATA_SMART_LBAM_PASS;
-       tf->lbah    = ATA_SMART_LBAH_PASS;
-       tf->command = ATA_CMD_SMART;
-       args.tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       args.data_phase = TASKFILE_IN;
-       (void) smart_enable(drive);
-       return ide_raw_taskfile(drive, &args, buf, 1);
-}
-
-static int proc_idedisk_read_cache
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
-{
-       ide_drive_t     *drive = (ide_drive_t *) data;
-       char            *out = page;
-       int             len;
-
-       if (drive->id_read)
-               len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
-       else
-               len = sprintf(out, "(none)\n");
-
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
-}
-
-static int proc_idedisk_read_capacity
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
-{
-       ide_drive_t*drive = (ide_drive_t *)data;
-       int len;
-
-       len = sprintf(page, "%llu\n", (long long)idedisk_capacity(drive));
-
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
-}
-
-static int proc_idedisk_read_smart(char *page, char **start, off_t off,
-                                  int count, int *eof, void *data, u8 sub_cmd)
-{
-       ide_drive_t     *drive = (ide_drive_t *)data;
-       int             len = 0, i = 0;
-
-       if (get_smart_data(drive, page, sub_cmd) == 0) {
-               unsigned short *val = (unsigned short *) page;
-               char *out = (char *)val + SECTOR_SIZE;
-
-               page = out;
-               do {
-                       out += sprintf(out, "%04x%c", le16_to_cpu(*val),
-                                      (++i & 7) ? ' ' : '\n');
-                       val += 1;
-               } while (i < SECTOR_SIZE / 2);
-               len = out - page;
+               /*
+               * If this device supports the Host Protected Area feature set,
+               * then we may need to change our opinion about its capacity.
+               */
+               if (ata_id_hpa_enabled(id))
+                       idedisk_check_hpa(drive);
        }
-
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
 }
 
-static int proc_idedisk_read_sv
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
+sector_t ide_disk_capacity(ide_drive_t *drive)
 {
-       return proc_idedisk_read_smart(page, start, off, count, eof, data,
-                                      ATA_SMART_READ_VALUES);
-}
-
-static int proc_idedisk_read_st
-       (char *page, char **start, off_t off, int count, int *eof, void *data)
-{
-       return proc_idedisk_read_smart(page, start, off, count, eof, data,
-                                      ATA_SMART_READ_THRESHOLDS);
+       return drive->capacity64;
 }
 
-static ide_proc_entry_t idedisk_proc[] = {
-       { "cache",        S_IFREG|S_IRUGO, proc_idedisk_read_cache,    NULL },
-       { "capacity",     S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
-       { "geometry",     S_IFREG|S_IRUGO, proc_ide_read_geometry,     NULL },
-       { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv,       NULL },
-       { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st,   NULL },
-       { NULL, 0, NULL, NULL }
-};
-#endif /* CONFIG_IDE_PROC_FS */
-
 static void idedisk_prepare_flush(struct request_queue *q, struct request *rq)
 {
        ide_drive_t *drive = q->queuedata;
@@ -568,25 +461,43 @@ static int set_multcount(ide_drive_t *drive, int arg)
        return (drive->mult_count == arg) ? 0 : -EIO;
 }
 
-ide_devset_get(nowerr, nowerr);
+ide_devset_get_flag(nowerr, IDE_DFLAG_NOWERR);
 
 static int set_nowerr(ide_drive_t *drive, int arg)
 {
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       drive->nowerr = arg;
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_NOWERR;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_NOWERR;
+
        drive->bad_wstat = arg ? BAD_R_STAT : BAD_W_STAT;
+
        return 0;
 }
 
+static int ide_do_setfeature(ide_drive_t *drive, u8 feature, u8 nsect)
+{
+       ide_task_t task;
+
+       memset(&task, 0, sizeof(task));
+       task.tf.feature = feature;
+       task.tf.nsect   = nsect;
+       task.tf.command = ATA_CMD_SET_FEATURES;
+       task.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+
+       return ide_no_data_taskfile(drive, &task);
+}
+
 static void update_ordered(ide_drive_t *drive)
 {
        u16 *id = drive->id;
        unsigned ordered = QUEUE_ORDERED_NONE;
        prepare_flush_fn *prep_fn = NULL;
 
-       if (drive->wcache) {
+       if (drive->dev_flags & IDE_DFLAG_WCACHE) {
                unsigned long long capacity;
                int barrier;
                /*
@@ -597,9 +508,11 @@ static void update_ordered(ide_drive_t *drive)
                 * time we have trimmed the drive capacity if LBA48 is
                 * not available so we don't need to recheck that.
                 */
-               capacity = idedisk_capacity(drive);
-               barrier = ata_id_flush_enabled(id) && !drive->noflush &&
-                       (drive->addressing == 0 || capacity <= (1ULL << 28) ||
+               capacity = ide_disk_capacity(drive);
+               barrier = ata_id_flush_enabled(id) &&
+                       (drive->dev_flags & IDE_DFLAG_NOFLUSH) == 0 &&
+                       ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 ||
+                        capacity <= (1ULL << 28) ||
                         ata_id_flush_ext_enabled(id));
 
                printk(KERN_INFO "%s: cache flushes %ssupported\n",
@@ -615,25 +528,24 @@ static void update_ordered(ide_drive_t *drive)
        blk_queue_ordered(drive->queue, ordered, prep_fn);
 }
 
-ide_devset_get(wcache, wcache);
+ide_devset_get_flag(wcache, IDE_DFLAG_WCACHE);
 
 static int set_wcache(ide_drive_t *drive, int arg)
 {
-       ide_task_t args;
        int err = 1;
 
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
        if (ata_id_flush_enabled(drive->id)) {
-               memset(&args, 0, sizeof(ide_task_t));
-               args.tf.feature = arg ?
-                       SETFEATURES_WC_ON : SETFEATURES_WC_OFF;
-               args.tf.command = ATA_CMD_SET_FEATURES;
-               args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-               err = ide_no_data_taskfile(drive, &args);
-               if (err == 0)
-                       drive->wcache = arg;
+               err = ide_do_setfeature(drive,
+                       arg ? SETFEATURES_WC_ON : SETFEATURES_WC_OFF, 0);
+               if (err == 0) {
+                       if (arg)
+                               drive->dev_flags |= IDE_DFLAG_WCACHE;
+                       else
+                               drive->dev_flags &= ~IDE_DFLAG_WCACHE;
+               }
        }
 
        update_ordered(drive);
@@ -658,22 +570,18 @@ ide_devset_get(acoustic, acoustic);
 
 static int set_acoustic(ide_drive_t *drive, int arg)
 {
-       ide_task_t args;
-
        if (arg < 0 || arg > 254)
                return -EINVAL;
 
-       memset(&args, 0, sizeof(ide_task_t));
-       args.tf.feature = arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF;
-       args.tf.nsect   = arg;
-       args.tf.command = ATA_CMD_SET_FEATURES;
-       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
-       ide_no_data_taskfile(drive, &args);
+       ide_do_setfeature(drive,
+               arg ? SETFEATURES_AAM_ON : SETFEATURES_AAM_OFF, arg);
+
        drive->acoustic = arg;
+
        return 0;
 }
 
-ide_devset_get(addressing, addressing);
+ide_devset_get_flag(addressing, IDE_DFLAG_LBA48);
 
 /*
  * drive->addressing:
@@ -686,49 +594,27 @@ static int set_addressing(ide_drive_t *drive, int arg)
        if (arg < 0 || arg > 2)
                return -EINVAL;
 
-       drive->addressing =  0;
-
-       if (drive->hwif->host_flags & IDE_HFLAG_NO_LBA48)
-               return 0;
-
-       if (ata_id_lba48_enabled(drive->id) == 0)
+       if (arg && ((drive->hwif->host_flags & IDE_HFLAG_NO_LBA48) ||
+           ata_id_lba48_enabled(drive->id) == 0))
                return -EIO;
 
-       drive->addressing = arg;
+       if (arg == 2)
+               arg = 0;
+
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_LBA48;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_LBA48;
 
        return 0;
 }
 
-ide_devset_rw(acoustic, acoustic);
-ide_devset_rw(address, addressing);
-ide_devset_rw(multcount, multcount);
-ide_devset_rw(wcache, wcache);
-
-ide_devset_rw_sync(nowerr, nowerr);
+ide_ext_devset_rw(acoustic, acoustic);
+ide_ext_devset_rw(address, addressing);
+ide_ext_devset_rw(multcount, multcount);
+ide_ext_devset_rw(wcache, wcache);
 
-#ifdef CONFIG_IDE_PROC_FS
-ide_devset_rw_field(bios_cyl, bios_cyl);
-ide_devset_rw_field(bios_head, bios_head);
-ide_devset_rw_field(bios_sect, bios_sect);
-ide_devset_rw_field(failures, failures);
-ide_devset_rw_field(lun, lun);
-ide_devset_rw_field(max_failures, max_failures);
-
-static const struct ide_proc_devset idedisk_settings[] = {
-       IDE_PROC_DEVSET(acoustic,       0,   254),
-       IDE_PROC_DEVSET(address,        0,     2),
-       IDE_PROC_DEVSET(bios_cyl,       0, 65535),
-       IDE_PROC_DEVSET(bios_head,      0,   255),
-       IDE_PROC_DEVSET(bios_sect,      0,    63),
-       IDE_PROC_DEVSET(failures,       0, 65535),
-       IDE_PROC_DEVSET(lun,            0,     7),
-       IDE_PROC_DEVSET(max_failures,   0, 65535),
-       IDE_PROC_DEVSET(multcount,      0,    16),
-       IDE_PROC_DEVSET(nowerr,         0,     1),
-       IDE_PROC_DEVSET(wcache,         0,     1),
-       { 0 },
-};
-#endif
+ide_ext_devset_rw_sync(nowerr, nowerr);
 
 static void idedisk_setup(ide_drive_t *drive)
 {
@@ -740,20 +626,20 @@ static void idedisk_setup(ide_drive_t *drive)
 
        ide_proc_register_driver(drive, idkp->driver);
 
-       if (drive->id_read == 0)
+       if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0)
                return;
 
-       if (drive->removable) {
+       if (drive->dev_flags & IDE_DFLAG_REMOVABLE) {
                /*
                 * Removable disks (eg. SYQUEST); ignore 'WD' drives
                 */
                if (m[0] != 'W' || m[1] != 'D')
-                       drive->doorlocking = 1;
+                       drive->dev_flags |= IDE_DFLAG_DOORLOCKING;
        }
 
        (void)set_addressing(drive, 1);
 
-       if (drive->addressing == 1) {
+       if (drive->dev_flags & IDE_DFLAG_LBA48) {
                int max_s = 2048;
 
                if (max_s > hwif->rqsize)
@@ -769,7 +655,8 @@ static void idedisk_setup(ide_drive_t *drive)
        init_idedisk_capacity(drive);
 
        /* limit drive capacity to 137GB if LBA48 cannot be used */
-       if (drive->addressing == 0 && drive->capacity64 > 1ULL << 28) {
+       if ((drive->dev_flags & IDE_DFLAG_LBA48) == 0 &&
+           drive->capacity64 > 1ULL << 28) {
                printk(KERN_WARNING "%s: cannot use LBA48 - full capacity "
                       "%llu sectors (%llu MB)\n",
                       drive->name, (unsigned long long)drive->capacity64,
@@ -777,22 +664,23 @@ static void idedisk_setup(ide_drive_t *drive)
                drive->capacity64 = 1ULL << 28;
        }
 
-       if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) && drive->addressing) {
+       if ((hwif->host_flags & IDE_HFLAG_NO_LBA48_DMA) &&
+           (drive->dev_flags & IDE_DFLAG_LBA48)) {
                if (drive->capacity64 > 1ULL << 28) {
                        printk(KERN_INFO "%s: cannot use LBA48 DMA - PIO mode"
                                         " will be used for accessing sectors "
                                         "> %u\n", drive->name, 1 << 28);
                } else
-                       drive->addressing = 0;
+                       drive->dev_flags &= ~IDE_DFLAG_LBA48;
        }
 
        /*
         * if possible, give fdisk access to more of the drive,
         * by correcting bios_cyls:
         */
-       capacity = idedisk_capacity(drive);
+       capacity = ide_disk_capacity(drive);
 
-       if (!drive->forced_geom) {
+       if ((drive->dev_flags & IDE_DFLAG_FORCED_GEOM) == 0) {
                if (ata_id_lba48_enabled(drive->id)) {
                        /* compatibility */
                        drive->bios_sect = 63;
@@ -827,14 +715,15 @@ static void idedisk_setup(ide_drive_t *drive)
 
        /* write cache enabled? */
        if ((id[ATA_ID_CSFO] & 1) || ata_id_wcache_enabled(id))
-               drive->wcache = 1;
+               drive->dev_flags |= IDE_DFLAG_WCACHE;
 
        set_wcache(drive, 1);
 }
 
 static void ide_cacheflush_p(ide_drive_t *drive)
 {
-       if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0)
+       if (ata_id_flush_enabled(drive->id) == 0 ||
+           (drive->dev_flags & IDE_DFLAG_WCACHE) == 0)
                return;
 
        if (do_idedisk_flushcache(drive))
@@ -918,13 +807,12 @@ static ide_driver_t idedisk_driver = {
        .resume                 = ide_disk_resume,
        .shutdown               = ide_device_shutdown,
        .version                = IDEDISK_VERSION,
-       .media                  = ide_disk,
        .do_request             = ide_do_rw_disk,
        .end_request            = ide_end_request,
        .error                  = __ide_error,
 #ifdef CONFIG_IDE_PROC_FS
-       .proc                   = idedisk_proc,
-       .settings               = idedisk_settings,
+       .proc                   = ide_disk_proc,
+       .settings               = ide_disk_settings,
 #endif
 };
 
@@ -953,15 +841,16 @@ static int idedisk_open(struct inode *inode, struct file *filp)
 
        idkp->openers++;
 
-       if (drive->removable && idkp->openers == 1) {
+       if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
                check_disk_change(inode->i_bdev);
                /*
                 * Ignore the return code from door_lock,
                 * since the open() has already succeeded,
                 * and the door_lock is irrelevant at this point.
                 */
-               if (drive->doorlocking && idedisk_set_doorlock(drive, 1))
-                       drive->doorlocking = 0;
+               if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
+                   idedisk_set_doorlock(drive, 1))
+                       drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
        }
        return 0;
 }
@@ -975,9 +864,10 @@ static int idedisk_release(struct inode *inode, struct file *filp)
        if (idkp->openers == 1)
                ide_cacheflush_p(drive);
 
-       if (drive->removable && idkp->openers == 1) {
-               if (drive->doorlocking && idedisk_set_doorlock(drive, 0))
-                       drive->doorlocking = 0;
+       if ((drive->dev_flags & IDE_DFLAG_REMOVABLE) && idkp->openers == 1) {
+               if ((drive->dev_flags & IDE_DFLAG_DOORLOCKING) &&
+                   idedisk_set_doorlock(drive, 0))
+                       drive->dev_flags &= ~IDE_DFLAG_DOORLOCKING;
        }
 
        idkp->openers--;
@@ -998,48 +888,25 @@ static int idedisk_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
-{ HDIO_GET_ADDRESS,    HDIO_SET_ADDRESS,   &ide_devset_address   },
-{ HDIO_GET_MULTCOUNT,  HDIO_SET_MULTCOUNT, &ide_devset_multcount },
-{ HDIO_GET_NOWERR,     HDIO_SET_NOWERR,    &ide_devset_nowerr    },
-{ HDIO_GET_WCACHE,     HDIO_SET_WCACHE,    &ide_devset_wcache    },
-{ HDIO_GET_ACOUSTIC,   HDIO_SET_ACOUSTIC,  &ide_devset_acoustic  },
-{ 0 }
-};
-
-static int idedisk_ioctl(struct inode *inode, struct file *file,
-                       unsigned int cmd, unsigned long arg)
-{
-       struct block_device *bdev = inode->i_bdev;
-       struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
-       ide_drive_t *drive = idkp->drive;
-       int err;
-
-       err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
-       if (err != -EOPNOTSUPP)
-               return err;
-
-       return generic_ide_ioctl(drive, file, bdev, cmd, arg);
-}
-
 static int idedisk_media_changed(struct gendisk *disk)
 {
        struct ide_disk_obj *idkp = ide_disk_g(disk);
        ide_drive_t *drive = idkp->drive;
 
        /* do not scan partitions twice if this is a removable device */
-       if (drive->attach) {
-               drive->attach = 0;
+       if (drive->dev_flags & IDE_DFLAG_ATTACH) {
+               drive->dev_flags &= ~IDE_DFLAG_ATTACH;
                return 0;
        }
+
        /* if removable, always assume it was changed */
-       return drive->removable;
+       return !!(drive->dev_flags & IDE_DFLAG_REMOVABLE);
 }
 
 static int idedisk_revalidate_disk(struct gendisk *disk)
 {
        struct ide_disk_obj *idkp = ide_disk_g(disk);
-       set_capacity(disk, idedisk_capacity(idkp->drive));
+       set_capacity(disk, ide_disk_capacity(idkp->drive));
        return 0;
 }
 
@@ -1047,7 +914,7 @@ static struct block_device_operations idedisk_ops = {
        .owner                  = THIS_MODULE,
        .open                   = idedisk_open,
        .release                = idedisk_release,
-       .ioctl                  = idedisk_ioctl,
+       .ioctl                  = ide_disk_ioctl,
        .getgeo                 = idedisk_getgeo,
        .media_changed          = idedisk_media_changed,
        .revalidate_disk        = idedisk_revalidate_disk
@@ -1088,19 +955,20 @@ static int ide_disk_probe(ide_drive_t *drive)
        drive->driver_data = idkp;
 
        idedisk_setup(drive);
-       if ((!drive->head || drive->head > 16) && !drive->select.b.lba) {
+       if ((drive->dev_flags & IDE_DFLAG_LBA) == 0 &&
+           (drive->head == 0 || drive->head > 16)) {
                printk(KERN_ERR "%s: INVALID GEOMETRY: %d PHYSICAL HEADS?\n",
                        drive->name, drive->head);
-               drive->attach = 0;
+               drive->dev_flags &= ~IDE_DFLAG_ATTACH;
        } else
-               drive->attach = 1;
+               drive->dev_flags |= IDE_DFLAG_ATTACH;
 
        g->minors = IDE_DISK_MINORS;
        g->driverfs_dev = &drive->gendev;
        g->flags |= GENHD_FL_EXT_DEVT;
-       if (drive->removable)
-               g->flags |= GENHD_FL_REMOVABLE;
-       set_capacity(g, idedisk_capacity(drive));
+       if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
+               g->flags = GENHD_FL_REMOVABLE;
+       set_capacity(g, ide_disk_capacity(drive));
        g->fops = &idedisk_ops;
        add_disk(g);
        return 0;
@@ -1122,6 +990,7 @@ static int __init idedisk_init(void)
 }
 
 MODULE_ALIAS("ide:*m-disk*");
+MODULE_ALIAS("ide-disk");
 module_init(idedisk_init);
 module_exit(idedisk_exit);
 MODULE_LICENSE("GPL");
diff --git a/drivers/ide/ide-disk.h b/drivers/ide/ide-disk.h
new file mode 100644 (file)
index 0000000..a82fa43
--- /dev/null
@@ -0,0 +1,32 @@
+#ifndef __IDE_DISK_H
+#define __IDE_DISK_H
+
+struct ide_disk_obj {
+       ide_drive_t     *drive;
+       ide_driver_t    *driver;
+       struct gendisk  *disk;
+       struct kref     kref;
+       unsigned int    openers;        /* protected by BKL for now */
+};
+
+#define ide_disk_g(disk) \
+       container_of((disk)->private_data, struct ide_disk_obj, driver)
+
+/* ide-disk.c */
+sector_t ide_disk_capacity(ide_drive_t *);
+ide_decl_devset(address);
+ide_decl_devset(multcount);
+ide_decl_devset(nowerr);
+ide_decl_devset(wcache);
+ide_decl_devset(acoustic);
+
+/* ide-disk_ioctl.c */
+int ide_disk_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
+
+#ifdef CONFIG_IDE_PROC_FS
+/* ide-disk_proc.c */
+extern ide_proc_entry_t ide_disk_proc[];
+extern const struct ide_proc_devset ide_disk_settings[];
+#endif
+
+#endif /* __IDE_DISK_H */
diff --git a/drivers/ide/ide-disk_ioctl.c b/drivers/ide/ide-disk_ioctl.c
new file mode 100644 (file)
index 0000000..a6cf1a0
--- /dev/null
@@ -0,0 +1,29 @@
+#include <linux/kernel.h>
+#include <linux/ide.h>
+#include <linux/hdreg.h>
+
+#include "ide-disk.h"
+
+static const struct ide_ioctl_devset ide_disk_ioctl_settings[] = {
+{ HDIO_GET_ADDRESS,    HDIO_SET_ADDRESS,   &ide_devset_address   },
+{ HDIO_GET_MULTCOUNT,  HDIO_SET_MULTCOUNT, &ide_devset_multcount },
+{ HDIO_GET_NOWERR,     HDIO_SET_NOWERR,    &ide_devset_nowerr    },
+{ HDIO_GET_WCACHE,     HDIO_SET_WCACHE,    &ide_devset_wcache    },
+{ HDIO_GET_ACOUSTIC,   HDIO_SET_ACOUSTIC,  &ide_devset_acoustic  },
+{ 0 }
+};
+
+int ide_disk_ioctl(struct inode *inode, struct file *file,
+                  unsigned int cmd, unsigned long arg)
+{
+       struct block_device *bdev = inode->i_bdev;
+       struct ide_disk_obj *idkp = ide_disk_g(bdev->bd_disk);
+       ide_drive_t *drive = idkp->drive;
+       int err;
+
+       err = ide_setting_ioctl(drive, bdev, cmd, arg, ide_disk_ioctl_settings);
+       if (err != -EOPNOTSUPP)
+               return err;
+
+       return generic_ide_ioctl(drive, file, bdev, cmd, arg);
+}
diff --git a/drivers/ide/ide-disk_proc.c b/drivers/ide/ide-disk_proc.c
new file mode 100644 (file)
index 0000000..4724976
--- /dev/null
@@ -0,0 +1,129 @@
+#include <linux/kernel.h>
+#include <linux/ide.h>
+#include <linux/hdreg.h>
+
+#include "ide-disk.h"
+
+static int smart_enable(ide_drive_t *drive)
+{
+       ide_task_t args;
+       struct ide_taskfile *tf = &args.tf;
+
+       memset(&args, 0, sizeof(ide_task_t));
+       tf->feature = ATA_SMART_ENABLE;
+       tf->lbam    = ATA_SMART_LBAM_PASS;
+       tf->lbah    = ATA_SMART_LBAH_PASS;
+       tf->command = ATA_CMD_SMART;
+       args.tf_flags = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+       return ide_no_data_taskfile(drive, &args);
+}
+
+static int get_smart_data(ide_drive_t *drive, u8 *buf, u8 sub_cmd)
+{
+       ide_task_t args;
+       struct ide_taskfile *tf = &args.tf;
+
+       memset(&args, 0, sizeof(ide_task_t));
+       tf->feature = sub_cmd;
+       tf->nsect   = 0x01;
+       tf->lbam    = ATA_SMART_LBAM_PASS;
+       tf->lbah    = ATA_SMART_LBAH_PASS;
+       tf->command = ATA_CMD_SMART;
+       args.tf_flags   = IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+       args.data_phase = TASKFILE_IN;
+       (void) smart_enable(drive);
+       return ide_raw_taskfile(drive, &args, buf, 1);
+}
+
+static int proc_idedisk_read_cache
+       (char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+       ide_drive_t     *drive = (ide_drive_t *) data;
+       char            *out = page;
+       int             len;
+
+       if (drive->dev_flags & IDE_DFLAG_ID_READ)
+               len = sprintf(out, "%i\n", drive->id[ATA_ID_BUF_SIZE] / 2);
+       else
+               len = sprintf(out, "(none)\n");
+
+       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+}
+
+static int proc_idedisk_read_capacity
+       (char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+       ide_drive_t*drive = (ide_drive_t *)data;
+       int len;
+
+       len = sprintf(page, "%llu\n", (long long)ide_disk_capacity(drive));
+
+       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+}
+
+static int proc_idedisk_read_smart(char *page, char **start, off_t off,
+                                  int count, int *eof, void *data, u8 sub_cmd)
+{
+       ide_drive_t     *drive = (ide_drive_t *)data;
+       int             len = 0, i = 0;
+
+       if (get_smart_data(drive, page, sub_cmd) == 0) {
+               unsigned short *val = (unsigned short *) page;
+               char *out = (char *)val + SECTOR_SIZE;
+
+               page = out;
+               do {
+                       out += sprintf(out, "%04x%c", le16_to_cpu(*val),
+                                      (++i & 7) ? ' ' : '\n');
+                       val += 1;
+               } while (i < SECTOR_SIZE / 2);
+               len = out - page;
+       }
+
+       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+}
+
+static int proc_idedisk_read_sv
+       (char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+       return proc_idedisk_read_smart(page, start, off, count, eof, data,
+                                      ATA_SMART_READ_VALUES);
+}
+
+static int proc_idedisk_read_st
+       (char *page, char **start, off_t off, int count, int *eof, void *data)
+{
+       return proc_idedisk_read_smart(page, start, off, count, eof, data,
+                                      ATA_SMART_READ_THRESHOLDS);
+}
+
+ide_proc_entry_t ide_disk_proc[] = {
+       { "cache",        S_IFREG|S_IRUGO, proc_idedisk_read_cache,    NULL },
+       { "capacity",     S_IFREG|S_IRUGO, proc_idedisk_read_capacity, NULL },
+       { "geometry",     S_IFREG|S_IRUGO, proc_ide_read_geometry,     NULL },
+       { "smart_values", S_IFREG|S_IRUSR, proc_idedisk_read_sv,       NULL },
+       { "smart_thresholds", S_IFREG|S_IRUSR, proc_idedisk_read_st,   NULL },
+       { NULL, 0, NULL, NULL }
+};
+
+ide_devset_rw_field(bios_cyl, bios_cyl);
+ide_devset_rw_field(bios_head, bios_head);
+ide_devset_rw_field(bios_sect, bios_sect);
+ide_devset_rw_field(failures, failures);
+ide_devset_rw_field(lun, lun);
+ide_devset_rw_field(max_failures, max_failures);
+
+const struct ide_proc_devset ide_disk_settings[] = {
+       IDE_PROC_DEVSET(acoustic,       0,   254),
+       IDE_PROC_DEVSET(address,        0,     2),
+       IDE_PROC_DEVSET(bios_cyl,       0, 65535),
+       IDE_PROC_DEVSET(bios_head,      0,   255),
+       IDE_PROC_DEVSET(bios_sect,      0,    63),
+       IDE_PROC_DEVSET(failures,       0, 65535),
+       IDE_PROC_DEVSET(lun,            0,     7),
+       IDE_PROC_DEVSET(max_failures,   0, 65535),
+       IDE_PROC_DEVSET(multcount,      0,    16),
+       IDE_PROC_DEVSET(nowerr,         0,     1),
+       IDE_PROC_DEVSET(wcache,         0,     1),
+       { 0 },
+};
diff --git a/drivers/ide/ide-dma-sff.c b/drivers/ide/ide-dma-sff.c
new file mode 100644 (file)
index 0000000..0903782
--- /dev/null
@@ -0,0 +1,356 @@
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/ide.h>
+#include <linux/scatterlist.h>
+#include <linux/dma-mapping.h>
+#include <linux/io.h>
+
+/**
+ *     config_drive_for_dma    -       attempt to activate IDE DMA
+ *     @drive: the drive to place in DMA mode
+ *
+ *     If the drive supports at least mode 2 DMA or UDMA of any kind
+ *     then attempt to place it into DMA mode. Drives that are known to
+ *     support DMA but predate the DMA properties or that are known
+ *     to have DMA handling bugs are also set up appropriately based
+ *     on the good/bad drive lists.
+ */
+
+int config_drive_for_dma(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u16 *id = drive->id;
+
+       if (drive->media != ide_disk) {
+               if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
+                       return 0;
+       }
+
+       /*
+        * Enable DMA on any drive that has
+        * UltraDMA (mode 0/1/2/3/4/5/6) enabled
+        */
+       if ((id[ATA_ID_FIELD_VALID] & 4) &&
+           ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
+               return 1;
+
+       /*
+        * Enable DMA on any drive that has mode2 DMA
+        * (multi or single) enabled
+        */
+       if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
+               if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
+                   (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
+                       return 1;
+
+       /* Consult the list of known "good" drives */
+       if (ide_dma_good_drive(drive))
+               return 1;
+
+       return 0;
+}
+
+/**
+ *     ide_dma_host_set        -       Enable/disable DMA on a host
+ *     @drive: drive to control
+ *
+ *     Enable/disable DMA on an IDE controller following generic
+ *     bus-mastering IDE controller behaviour.
+ */
+
+void ide_dma_host_set(ide_drive_t *drive, int on)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u8 unit = drive->dn & 1;
+       u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
+
+       if (on)
+               dma_stat |= (1 << (5 + unit));
+       else
+               dma_stat &= ~(1 << (5 + unit));
+
+       if (hwif->host_flags & IDE_HFLAG_MMIO)
+               writeb(dma_stat,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
+       else
+               outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
+}
+EXPORT_SYMBOL_GPL(ide_dma_host_set);
+
+/**
+ *     ide_build_dmatable      -       build IDE DMA table
+ *
+ *     ide_build_dmatable() prepares a dma request. We map the command
+ *     to get the pci bus addresses of the buffers and then build up
+ *     the PRD table that the IDE layer wants to be fed.
+ *
+ *     Most chipsets correctly interpret a length of 0x0000 as 64KB,
+ *     but at least one (e.g. CS5530) misinterprets it as zero (!).
+ *     So we break the 64KB entry into two 32KB entries instead.
+ *
+ *     Returns the number of built PRD entries if all went okay,
+ *     returns 0 otherwise.
+ *
+ *     May also be invoked from trm290.c
+ */
+
+int ide_build_dmatable(ide_drive_t *drive, struct request *rq)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       __le32 *table = (__le32 *)hwif->dmatable_cpu;
+       unsigned int is_trm290  = (hwif->chipset == ide_trm290) ? 1 : 0;
+       unsigned int count = 0;
+       int i;
+       struct scatterlist *sg;
+
+       hwif->sg_nents = ide_build_sglist(drive, rq);
+       if (hwif->sg_nents == 0)
+               return 0;
+
+       for_each_sg(hwif->sg_table, sg, hwif->sg_nents, i) {
+               u32 cur_addr, cur_len, xcount, bcount;
+
+               cur_addr = sg_dma_address(sg);
+               cur_len = sg_dma_len(sg);
+
+               /*
+                * Fill in the dma table, without crossing any 64kB boundaries.
+                * Most hardware requires 16-bit alignment of all blocks,
+                * but the trm290 requires 32-bit alignment.
+                */
+
+               while (cur_len) {
+                       if (count++ >= PRD_ENTRIES)
+                               goto use_pio_instead;
+
+                       bcount = 0x10000 - (cur_addr & 0xffff);
+                       if (bcount > cur_len)
+                               bcount = cur_len;
+                       *table++ = cpu_to_le32(cur_addr);
+                       xcount = bcount & 0xffff;
+                       if (is_trm290)
+                               xcount = ((xcount >> 2) - 1) << 16;
+                       if (xcount == 0x0000) {
+                               if (count++ >= PRD_ENTRIES)
+                                       goto use_pio_instead;
+                               *table++ = cpu_to_le32(0x8000);
+                               *table++ = cpu_to_le32(cur_addr + 0x8000);
+                               xcount = 0x8000;
+                       }
+                       *table++ = cpu_to_le32(xcount);
+                       cur_addr += bcount;
+                       cur_len -= bcount;
+               }
+       }
+
+       if (count) {
+               if (!is_trm290)
+                       *--table |= cpu_to_le32(0x80000000);
+               return count;
+       }
+
+use_pio_instead:
+       printk(KERN_ERR "%s: %s\n", drive->name,
+               count ? "DMA table too small" : "empty DMA table?");
+
+       ide_destroy_dmatable(drive);
+
+       return 0; /* revert to PIO for this request */
+}
+EXPORT_SYMBOL_GPL(ide_build_dmatable);
+
+/**
+ *     ide_dma_setup   -       begin a DMA phase
+ *     @drive: target device
+ *
+ *     Build an IDE DMA PRD (IDE speak for scatter gather table)
+ *     and then set up the DMA transfer registers for a device
+ *     that follows generic IDE PCI DMA behaviour. Controllers can
+ *     override this function if they need to
+ *
+ *     Returns 0 on success. If a PIO fallback is required then 1
+ *     is returned.
+ */
+
+int ide_dma_setup(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       struct request *rq = hwif->hwgroup->rq;
+       unsigned int reading;
+       u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
+       u8 dma_stat;
+
+       if (rq_data_dir(rq))
+               reading = 0;
+       else
+               reading = 1 << 3;
+
+       /* fall back to pio! */
+       if (!ide_build_dmatable(drive, rq)) {
+               ide_map_sg(drive, rq);
+               return 1;
+       }
+
+       /* PRD table */
+       if (hwif->host_flags & IDE_HFLAG_MMIO)
+               writel(hwif->dmatable_dma,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
+       else
+               outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
+
+       /* specify r/w */
+       if (mmio)
+               writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
+       else
+               outb(reading, hwif->dma_base + ATA_DMA_CMD);
+
+       /* read DMA status for INTR & ERROR flags */
+       dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
+
+       /* clear INTR & ERROR flags */
+       if (mmio)
+               writeb(dma_stat | 6,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
+       else
+               outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
+
+       drive->waiting_for_dma = 1;
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ide_dma_setup);
+
+/**
+ *     dma_timer_expiry        -       handle a DMA timeout
+ *     @drive: Drive that timed out
+ *
+ *     An IDE DMA transfer timed out. In the event of an error we ask
+ *     the driver to resolve the problem, if a DMA transfer is still
+ *     in progress we continue to wait (arguably we need to add a
+ *     secondary 'I don't care what the drive thinks' timeout here)
+ *     Finally if we have an interrupt we let it complete the I/O.
+ *     But only one time - we clear expiry and if it's still not
+ *     completed after WAIT_CMD, we error and retry in PIO.
+ *     This can occur if an interrupt is lost or due to hang or bugs.
+ */
+
+static int dma_timer_expiry(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
+
+       printk(KERN_WARNING "%s: %s: DMA status (0x%02x)\n",
+               drive->name, __func__, dma_stat);
+
+       if ((dma_stat & 0x18) == 0x18)  /* BUSY Stupid Early Timer !! */
+               return WAIT_CMD;
+
+       hwif->hwgroup->expiry = NULL;   /* one free ride for now */
+
+       /* 1 dmaing, 2 error, 4 intr */
+       if (dma_stat & 2)       /* ERROR */
+               return -1;
+
+       if (dma_stat & 1)       /* DMAing */
+               return WAIT_CMD;
+
+       if (dma_stat & 4)       /* Got an Interrupt */
+               return WAIT_CMD;
+
+       return 0;       /* Status is unknown -- reset the bus */
+}
+
+void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
+{
+       /* issue cmd to drive */
+       ide_execute_command(drive, command, &ide_dma_intr, 2 * WAIT_CMD,
+                           dma_timer_expiry);
+}
+EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
+
+void ide_dma_start(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u8 dma_cmd;
+
+       /* Note that this is done *after* the cmd has
+        * been issued to the drive, as per the BM-IDE spec.
+        * The Promise Ultra33 doesn't work correctly when
+        * we do this part before issuing the drive cmd.
+        */
+       if (hwif->host_flags & IDE_HFLAG_MMIO) {
+               dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
+               /* start DMA */
+               writeb(dma_cmd | 1,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
+       } else {
+               dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
+               outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
+       }
+
+       wmb();
+}
+EXPORT_SYMBOL_GPL(ide_dma_start);
+
+/* returns 1 on error, 0 otherwise */
+int ide_dma_end(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
+       u8 dma_stat = 0, dma_cmd = 0;
+
+       drive->waiting_for_dma = 0;
+
+       if (mmio) {
+               /* get DMA command mode */
+               dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
+               /* stop DMA */
+               writeb(dma_cmd & ~1,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
+       } else {
+               dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
+               outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
+       }
+
+       /* get DMA status */
+       dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
+
+       if (mmio)
+               /* clear the INTR & ERROR bits */
+               writeb(dma_stat | 6,
+                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
+       else
+               outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
+
+       /* purge DMA mappings */
+       ide_destroy_dmatable(drive);
+       /* verify good DMA status */
+       wmb();
+       return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
+}
+EXPORT_SYMBOL_GPL(ide_dma_end);
+
+/* returns 1 if dma irq issued, 0 otherwise */
+int ide_dma_test_irq(ide_drive_t *drive)
+{
+       ide_hwif_t *hwif = drive->hwif;
+       u8 dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
+
+       /* return 1 if INTR asserted */
+       if ((dma_stat & 4) == 4)
+               return 1;
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(ide_dma_test_irq);
+
+const struct ide_dma_ops sff_dma_ops = {
+       .dma_host_set           = ide_dma_host_set,
+       .dma_setup              = ide_dma_setup,
+       .dma_exec_cmd           = ide_dma_exec_cmd,
+       .dma_start              = ide_dma_start,
+       .dma_end                = ide_dma_end,
+       .dma_test_irq           = ide_dma_test_irq,
+       .dma_timeout            = ide_dma_timeout,
+       .dma_lost_irq           = ide_dma_lost_irq,
+};
+EXPORT_SYMBOL_GPL(sff_dma_ops);
index ef2f1504c0d5b238a122d1bb309011a555d2cc70..fffd11717b2d169e3557c501db7c51780db5a4b1 100644 (file)
  * for supplying a Promise UDMA board & WD UDMA drive for this work!
  */
 
-#include <linux/module.h>
 #include <linux/types.h>
 #include <linux/kernel.h>
-#include <linux/timer.h>
-#include <linux/mm.h>
-#include <linux/interrupt.h>
-#include <linux/pci.h>
-#include <linux/init.h>
 #include <linux/ide.h>
-#include <linux/delay.h>
 #include <linux/scatterlist.h>
 #include <linux/dma-mapping.h>
 
-#include <asm/io.h>
-#include <asm/irq.h>
-
-static const struct drive_list_entry drive_whitelist [] = {
-
+static const struct drive_list_entry drive_whitelist[] = {
        { "Micropolis 2112A"    ,       NULL            },
        { "CONNER CTMA 4000"    ,       NULL            },
        { "CONNER CTT8000-A"    ,       NULL            },
@@ -53,8 +42,7 @@ static const struct drive_list_entry drive_whitelist [] = {
        { NULL                  ,       NULL            }
 };
 
-static const struct drive_list_entry drive_blacklist [] = {
-
+static const struct drive_list_entry drive_blacklist[] = {
        { "WDC AC11000H"        ,       NULL            },
        { "WDC AC22100H"        ,       NULL            },
        { "WDC AC32500H"        ,       NULL            },
@@ -94,11 +82,11 @@ static const struct drive_list_entry drive_blacklist [] = {
  *     ide_dma_intr    -       IDE DMA interrupt handler
  *     @drive: the drive the interrupt is for
  *
- *     Handle an interrupt completing a read/write DMA transfer on an 
+ *     Handle an interrupt completing a read/write DMA transfer on an
  *     IDE device
  */
-ide_startstop_t ide_dma_intr (ide_drive_t *drive)
+
+ide_startstop_t ide_dma_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        u8 stat = 0, dma_stat = 0;
@@ -108,20 +96,19 @@ ide_startstop_t ide_dma_intr (ide_drive_t *drive)
 
        if (OK_STAT(stat, DRIVE_READY, drive->bad_wstat | ATA_DRQ)) {
                if (!dma_stat) {
-                       struct request *rq = HWGROUP(drive)->rq;
+                       struct request *rq = hwif->hwgroup->rq;
 
                        task_end_request(drive, rq, stat);
                        return ide_stopped;
                }
-               printk(KERN_ERR "%s: dma_intr: bad DMA status (dma_stat=%x)\n", 
-                      drive->name, dma_stat);
+               printk(KERN_ERR "%s: %s: bad DMA status (0x%02x)\n",
+                       drive->name, __func__, dma_stat);
        }
        return ide_error(drive, "dma_intr", stat);
 }
-
 EXPORT_SYMBOL_GPL(ide_dma_intr);
 
-static int ide_dma_good_drive(ide_drive_t *drive)
+int ide_dma_good_drive(ide_drive_t *drive)
 {
        return ide_in_drive_list(drive->id, drive_whitelist);
 }
@@ -139,7 +126,7 @@ static int ide_dma_good_drive(ide_drive_t *drive)
 
 int ide_build_sglist(ide_drive_t *drive, struct request *rq)
 {
-       ide_hwif_t *hwif = HWIF(drive);
+       ide_hwif_t *hwif = drive->hwif;
        struct scatterlist *sg = hwif->sg_table;
 
        ide_map_sg(drive, rq);
@@ -152,106 +139,8 @@ int ide_build_sglist(ide_drive_t *drive, struct request *rq)
        return dma_map_sg(hwif->dev, sg, hwif->sg_nents,
                          hwif->sg_dma_direction);
 }
-
 EXPORT_SYMBOL_GPL(ide_build_sglist);
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
-/**
- *     ide_build_dmatable      -       build IDE DMA table
- *
- *     ide_build_dmatable() prepares a dma request. We map the command
- *     to get the pci bus addresses of the buffers and then build up
- *     the PRD table that the IDE layer wants to be fed. The code
- *     knows about the 64K wrap bug in the CS5530.
- *
- *     Returns the number of built PRD entries if all went okay,
- *     returns 0 otherwise.
- *
- *     May also be invoked from trm290.c
- */
-int ide_build_dmatable (ide_drive_t *drive, struct request *rq)
-{
-       ide_hwif_t *hwif        = HWIF(drive);
-       __le32 *table = (__le32 *)hwif->dmatable_cpu;
-       unsigned int is_trm290  = (hwif->chipset == ide_trm290) ? 1 : 0;
-       unsigned int count = 0;
-       int i;
-       struct scatterlist *sg;
-
-       hwif->sg_nents = i = ide_build_sglist(drive, rq);
-
-       if (!i)
-               return 0;
-
-       sg = hwif->sg_table;
-       while (i) {
-               u32 cur_addr;
-               u32 cur_len;
-
-               cur_addr = sg_dma_address(sg);
-               cur_len = sg_dma_len(sg);
-
-               /*
-                * Fill in the dma table, without crossing any 64kB boundaries.
-                * Most hardware requires 16-bit alignment of all blocks,
-                * but the trm290 requires 32-bit alignment.
-                */
-
-               while (cur_len) {
-                       if (count++ >= PRD_ENTRIES) {
-                               printk(KERN_ERR "%s: DMA table too small\n", drive->name);
-                               goto use_pio_instead;
-                       } else {
-                               u32 xcount, bcount = 0x10000 - (cur_addr & 0xffff);
-
-                               if (bcount > cur_len)
-                                       bcount = cur_len;
-                               *table++ = cpu_to_le32(cur_addr);
-                               xcount = bcount & 0xffff;
-                               if (is_trm290)
-                                       xcount = ((xcount >> 2) - 1) << 16;
-                               else if (xcount == 0x0000) {
-       /* 
-        * Most chipsets correctly interpret a length of 0x0000 as 64KB,
-        * but at least one (e.g. CS5530) misinterprets it as zero (!).
-        * So here we break the 64KB entry into two 32KB entries instead.
-        */
-                                       if (count++ >= PRD_ENTRIES) {
-                                               printk(KERN_ERR "%s: DMA table too small\n", drive->name);
-                                               goto use_pio_instead;
-                                       }
-                                       *table++ = cpu_to_le32(0x8000);
-                                       *table++ = cpu_to_le32(cur_addr + 0x8000);
-                                       xcount = 0x8000;
-                               }
-                               *table++ = cpu_to_le32(xcount);
-                               cur_addr += bcount;
-                               cur_len -= bcount;
-                       }
-               }
-
-               sg = sg_next(sg);
-               i--;
-       }
-
-       if (count) {
-               if (!is_trm290)
-                       *--table |= cpu_to_le32(0x80000000);
-               return count;
-       }
-
-       printk(KERN_ERR "%s: empty DMA table?\n", drive->name);
-
-use_pio_instead:
-       ide_destroy_dmatable(drive);
-
-       return 0; /* revert to PIO for this request */
-}
-
-EXPORT_SYMBOL_GPL(ide_build_dmatable);
-#endif
-
 /**
  *     ide_destroy_dmatable    -       clean up DMA mapping
  *     @drive: The drive to unmap
@@ -262,147 +151,30 @@ EXPORT_SYMBOL_GPL(ide_build_dmatable);
  *     an oops as only one mapping can be live for each target at a given
  *     time.
  */
-void ide_destroy_dmatable (ide_drive_t *drive)
+
+void ide_destroy_dmatable(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
 
        dma_unmap_sg(hwif->dev, hwif->sg_table, hwif->sg_nents,
                     hwif->sg_dma_direction);
 }
-
 EXPORT_SYMBOL_GPL(ide_destroy_dmatable);
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
-/**
- *     config_drive_for_dma    -       attempt to activate IDE DMA
- *     @drive: the drive to place in DMA mode
- *
- *     If the drive supports at least mode 2 DMA or UDMA of any kind
- *     then attempt to place it into DMA mode. Drives that are known to
- *     support DMA but predate the DMA properties or that are known
- *     to have DMA handling bugs are also set up appropriately based
- *     on the good/bad drive lists.
- */
-static int config_drive_for_dma (ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       u16 *id = drive->id;
-
-       if (drive->media != ide_disk) {
-               if (hwif->host_flags & IDE_HFLAG_NO_ATAPI_DMA)
-                       return 0;
-       }
-
-       /*
-        * Enable DMA on any drive that has
-        * UltraDMA (mode 0/1/2/3/4/5/6) enabled
-        */
-       if ((id[ATA_ID_FIELD_VALID] & 4) &&
-           ((id[ATA_ID_UDMA_MODES] >> 8) & 0x7f))
-               return 1;
-
-       /*
-        * Enable DMA on any drive that has mode2 DMA
-        * (multi or single) enabled
-        */
-       if (id[ATA_ID_FIELD_VALID] & 2) /* regular DMA */
-               if ((id[ATA_ID_MWDMA_MODES] & 0x404) == 0x404 ||
-                   (id[ATA_ID_SWDMA_MODES] & 0x404) == 0x404)
-                       return 1;
-
-       /* Consult the list of known "good" drives */
-       if (ide_dma_good_drive(drive))
-               return 1;
-
-       return 0;
-}
-
-/**
- *     dma_timer_expiry        -       handle a DMA timeout
- *     @drive: Drive that timed out
- *
- *     An IDE DMA transfer timed out. In the event of an error we ask
- *     the driver to resolve the problem, if a DMA transfer is still
- *     in progress we continue to wait (arguably we need to add a 
- *     secondary 'I don't care what the drive thinks' timeout here)
- *     Finally if we have an interrupt we let it complete the I/O.
- *     But only one time - we clear expiry and if it's still not
- *     completed after WAIT_CMD, we error and retry in PIO.
- *     This can occur if an interrupt is lost or due to hang or bugs.
- */
-static int dma_timer_expiry (ide_drive_t *drive)
-{
-       ide_hwif_t *hwif        = HWIF(drive);
-       u8 dma_stat             = hwif->tp_ops->read_sff_dma_status(hwif);
-
-       printk(KERN_WARNING "%s: dma_timer_expiry: dma status == 0x%02x\n",
-               drive->name, dma_stat);
-
-       if ((dma_stat & 0x18) == 0x18)  /* BUSY Stupid Early Timer !! */
-               return WAIT_CMD;
-
-       HWGROUP(drive)->expiry = NULL;  /* one free ride for now */
-
-       /* 1 dmaing, 2 error, 4 intr */
-       if (dma_stat & 2)       /* ERROR */
-               return -1;
-
-       if (dma_stat & 1)       /* DMAing */
-               return WAIT_CMD;
-
-       if (dma_stat & 4)       /* Got an Interrupt */
-               return WAIT_CMD;
-
-       return 0;       /* Status is unknown -- reset the bus */
-}
-
-/**
- *     ide_dma_host_set        -       Enable/disable DMA on a host
- *     @drive: drive to control
- *
- *     Enable/disable DMA on an IDE controller following generic
- *     bus-mastering IDE controller behaviour.
- */
-
-void ide_dma_host_set(ide_drive_t *drive, int on)
-{
-       ide_hwif_t *hwif        = HWIF(drive);
-       u8 unit                 = (drive->select.b.unit & 0x01);
-       u8 dma_stat             = hwif->tp_ops->read_sff_dma_status(hwif);
-
-       if (on)
-               dma_stat |= (1 << (5 + unit));
-       else
-               dma_stat &= ~(1 << (5 + unit));
-
-       if (hwif->host_flags & IDE_HFLAG_MMIO)
-               writeb(dma_stat,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
-       else
-               outb(dma_stat, hwif->dma_base + ATA_DMA_STATUS);
-}
-
-EXPORT_SYMBOL_GPL(ide_dma_host_set);
-#endif /* CONFIG_BLK_DEV_IDEDMA_SFF  */
-
 /**
  *     ide_dma_off_quietly     -       Generic DMA kill
  *     @drive: drive to control
  *
- *     Turn off the current DMA on this IDE controller. 
+ *     Turn off the current DMA on this IDE controller.
  */
 
 void ide_dma_off_quietly(ide_drive_t *drive)
 {
-       drive->using_dma = 0;
+       drive->dev_flags &= ~IDE_DFLAG_USING_DMA;
        ide_toggle_bounce(drive, 0);
 
        drive->hwif->dma_ops->dma_host_set(drive, 0);
 }
-
 EXPORT_SYMBOL(ide_dma_off_quietly);
 
 /**
@@ -418,7 +190,6 @@ void ide_dma_off(ide_drive_t *drive)
        printk(KERN_INFO "%s: DMA disabled\n", drive->name);
        ide_dma_off_quietly(drive);
 }
-
 EXPORT_SYMBOL(ide_dma_off);
 
 /**
@@ -430,167 +201,13 @@ EXPORT_SYMBOL(ide_dma_off);
 
 void ide_dma_on(ide_drive_t *drive)
 {
-       drive->using_dma = 1;
+       drive->dev_flags |= IDE_DFLAG_USING_DMA;
        ide_toggle_bounce(drive, 1);
 
        drive->hwif->dma_ops->dma_host_set(drive, 1);
 }
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
-/**
- *     ide_dma_setup   -       begin a DMA phase
- *     @drive: target device
- *
- *     Build an IDE DMA PRD (IDE speak for scatter gather table)
- *     and then set up the DMA transfer registers for a device
- *     that follows generic IDE PCI DMA behaviour. Controllers can
- *     override this function if they need to
- *
- *     Returns 0 on success. If a PIO fallback is required then 1
- *     is returned. 
- */
-
-int ide_dma_setup(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       struct request *rq = HWGROUP(drive)->rq;
-       unsigned int reading;
-       u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
-       u8 dma_stat;
-
-       if (rq_data_dir(rq))
-               reading = 0;
-       else
-               reading = 1 << 3;
-
-       /* fall back to pio! */
-       if (!ide_build_dmatable(drive, rq)) {
-               ide_map_sg(drive, rq);
-               return 1;
-       }
-
-       /* PRD table */
-       if (hwif->host_flags & IDE_HFLAG_MMIO)
-               writel(hwif->dmatable_dma,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_TABLE_OFS));
-       else
-               outl(hwif->dmatable_dma, hwif->dma_base + ATA_DMA_TABLE_OFS);
-
-       /* specify r/w */
-       if (mmio)
-               writeb(reading, (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
-       else
-               outb(reading, hwif->dma_base + ATA_DMA_CMD);
-
-       /* read DMA status for INTR & ERROR flags */
-       dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
-
-       /* clear INTR & ERROR flags */
-       if (mmio)
-               writeb(dma_stat | 6,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
-       else
-               outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
-
-       drive->waiting_for_dma = 1;
-       return 0;
-}
-
-EXPORT_SYMBOL_GPL(ide_dma_setup);
-
-void ide_dma_exec_cmd(ide_drive_t *drive, u8 command)
-{
-       /* issue cmd to drive */
-       ide_execute_command(drive, command, &ide_dma_intr, 2*WAIT_CMD, dma_timer_expiry);
-}
-EXPORT_SYMBOL_GPL(ide_dma_exec_cmd);
-
-void ide_dma_start(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       u8 dma_cmd;
-
-       /* Note that this is done *after* the cmd has
-        * been issued to the drive, as per the BM-IDE spec.
-        * The Promise Ultra33 doesn't work correctly when
-        * we do this part before issuing the drive cmd.
-        */
-       if (hwif->host_flags & IDE_HFLAG_MMIO) {
-               dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
-               /* start DMA */
-               writeb(dma_cmd | 1,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
-       } else {
-               dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
-               outb(dma_cmd | 1, hwif->dma_base + ATA_DMA_CMD);
-       }
-
-       hwif->dma = 1;
-       wmb();
-}
-
-EXPORT_SYMBOL_GPL(ide_dma_start);
-
-/* returns 1 on error, 0 otherwise */
-int __ide_dma_end (ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       u8 mmio = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
-       u8 dma_stat = 0, dma_cmd = 0;
-
-       drive->waiting_for_dma = 0;
-
-       if (mmio) {
-               /* get DMA command mode */
-               dma_cmd = readb((void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
-               /* stop DMA */
-               writeb(dma_cmd & ~1,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_CMD));
-       } else {
-               dma_cmd = inb(hwif->dma_base + ATA_DMA_CMD);
-               outb(dma_cmd & ~1, hwif->dma_base + ATA_DMA_CMD);
-       }
-
-       /* get DMA status */
-       dma_stat = hwif->tp_ops->read_sff_dma_status(hwif);
-
-       if (mmio)
-               /* clear the INTR & ERROR bits */
-               writeb(dma_stat | 6,
-                      (void __iomem *)(hwif->dma_base + ATA_DMA_STATUS));
-       else
-               outb(dma_stat | 6, hwif->dma_base + ATA_DMA_STATUS);
-
-       /* purge DMA mappings */
-       ide_destroy_dmatable(drive);
-       /* verify good DMA status */
-       hwif->dma = 0;
-       wmb();
-       return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
-}
-
-EXPORT_SYMBOL(__ide_dma_end);
-
-/* returns 1 if dma irq issued, 0 otherwise */
-int ide_dma_test_irq(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif        = HWIF(drive);
-       u8 dma_stat             = hwif->tp_ops->read_sff_dma_status(hwif);
-
-       /* return 1 if INTR asserted */
-       if ((dma_stat & 4) == 4)
-               return 1;
-       if (!drive->waiting_for_dma)
-               printk(KERN_WARNING "%s: (%s) called while not waiting\n",
-                       drive->name, __func__);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(ide_dma_test_irq);
-#else
-static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
-#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
-
-int __ide_dma_bad_drive (ide_drive_t *drive)
+int __ide_dma_bad_drive(ide_drive_t *drive)
 {
        u16 *id = drive->id;
 
@@ -602,7 +219,6 @@ int __ide_dma_bad_drive (ide_drive_t *drive)
        }
        return 0;
 }
-
 EXPORT_SYMBOL(__ide_dma_bad_drive);
 
 static const u8 xfer_mode_bases[] = {
@@ -618,7 +234,7 @@ static unsigned int ide_get_mode_mask(ide_drive_t *drive, u8 base, u8 req_mode)
        const struct ide_port_ops *port_ops = hwif->port_ops;
        unsigned int mask = 0;
 
-       switch(base) {
+       switch (base) {
        case XFER_UDMA_0:
                if ((id[ATA_ID_FIELD_VALID] & 4) == 0)
                        break;
@@ -719,7 +335,6 @@ u8 ide_find_dma_mode(ide_drive_t *drive, u8 req_mode)
 
        return mode;
 }
-
 EXPORT_SYMBOL_GPL(ide_find_dma_mode);
 
 static int ide_tune_dma(ide_drive_t *drive)
@@ -727,7 +342,8 @@ static int ide_tune_dma(ide_drive_t *drive)
        ide_hwif_t *hwif = drive->hwif;
        u8 speed;
 
-       if (drive->nodma || ata_id_has_dma(drive->id) == 0)
+       if (ata_id_has_dma(drive->id) == 0 ||
+           (drive->dev_flags & IDE_DFLAG_NODMA))
                return 0;
 
        /* consult the list of known "bad" drives */
@@ -827,66 +443,59 @@ void ide_check_dma_crc(ide_drive_t *drive)
                ide_dma_on(drive);
 }
 
-#ifdef CONFIG_BLK_DEV_IDEDMA_SFF
-void ide_dma_lost_irq (ide_drive_t *drive)
+void ide_dma_lost_irq(ide_drive_t *drive)
 {
-       printk("%s: DMA interrupt recovery\n", drive->name);
+       printk(KERN_ERR "%s: DMA interrupt recovery\n", drive->name);
 }
+EXPORT_SYMBOL_GPL(ide_dma_lost_irq);
 
-EXPORT_SYMBOL(ide_dma_lost_irq);
-
-void ide_dma_timeout (ide_drive_t *drive)
+void ide_dma_timeout(ide_drive_t *drive)
 {
-       ide_hwif_t *hwif = HWIF(drive);
+       ide_hwif_t *hwif = drive->hwif;
 
        printk(KERN_ERR "%s: timeout waiting for DMA\n", drive->name);
 
        if (hwif->dma_ops->dma_test_irq(drive))
                return;
 
+       ide_dump_status(drive, "DMA timeout", hwif->tp_ops->read_status(hwif));
+
        hwif->dma_ops->dma_end(drive);
 }
-
-EXPORT_SYMBOL(ide_dma_timeout);
+EXPORT_SYMBOL_GPL(ide_dma_timeout);
 
 void ide_release_dma_engine(ide_hwif_t *hwif)
 {
        if (hwif->dmatable_cpu) {
-               struct pci_dev *pdev = to_pci_dev(hwif->dev);
+               int prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
 
-               pci_free_consistent(pdev, PRD_ENTRIES * PRD_BYTES,
-                                   hwif->dmatable_cpu, hwif->dmatable_dma);
+               dma_free_coherent(hwif->dev, prd_size,
+                                 hwif->dmatable_cpu, hwif->dmatable_dma);
                hwif->dmatable_cpu = NULL;
        }
 }
+EXPORT_SYMBOL_GPL(ide_release_dma_engine);
 
 int ide_allocate_dma_engine(ide_hwif_t *hwif)
 {
-       struct pci_dev *pdev = to_pci_dev(hwif->dev);
+       int prd_size;
 
-       hwif->dmatable_cpu = pci_alloc_consistent(pdev,
-                                                 PRD_ENTRIES * PRD_BYTES,
-                                                 &hwif->dmatable_dma);
+       if (hwif->prd_max_nents == 0)
+               hwif->prd_max_nents = PRD_ENTRIES;
+       if (hwif->prd_ent_size == 0)
+               hwif->prd_ent_size = PRD_BYTES;
 
-       if (hwif->dmatable_cpu)
-               return 0;
+       prd_size = hwif->prd_max_nents * hwif->prd_ent_size;
 
-       printk(KERN_ERR "%s: -- Error, unable to allocate DMA table.\n",
+       hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev, prd_size,
+                                               &hwif->dmatable_dma,
+                                               GFP_ATOMIC);
+       if (hwif->dmatable_cpu == NULL) {
+               printk(KERN_ERR "%s: unable to allocate PRD table\n",
                        hwif->name);
+               return -ENOMEM;
+       }
 
-       return 1;
+       return 0;
 }
 EXPORT_SYMBOL_GPL(ide_allocate_dma_engine);
-
-const struct ide_dma_ops sff_dma_ops = {
-       .dma_host_set           = ide_dma_host_set,
-       .dma_setup              = ide_dma_setup,
-       .dma_exec_cmd           = ide_dma_exec_cmd,
-       .dma_start              = ide_dma_start,
-       .dma_end                = __ide_dma_end,
-       .dma_test_irq           = ide_dma_test_irq,
-       .dma_timeout            = ide_dma_timeout,
-       .dma_lost_irq           = ide_dma_lost_irq,
-};
-EXPORT_SYMBOL_GPL(sff_dma_ops);
-#endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
index d36f155470a49dfcafef2ee19dbb9a3835475c9b..cf0aa25470ee87368291dbf8614d2b67020315e9 100644 (file)
@@ -16,6 +16,7 @@
  */
 
 #define DRV_NAME "ide-floppy"
+#define PFX DRV_NAME ": "
 
 #define IDEFLOPPY_VERSION "1.00"
 
 
 #include "ide-floppy.h"
 
-/* define to see debug info */
-#define IDEFLOPPY_DEBUG_LOG            0
+/* module parameters */
+static unsigned long debug_mask;
+module_param(debug_mask, ulong, 0644);
 
-/* #define IDEFLOPPY_DEBUG(fmt, args...) printk(KERN_INFO fmt, ## args) */
-#define IDEFLOPPY_DEBUG(fmt, args...)
+/* define to see debug info */
+#define IDEFLOPPY_DEBUG_LOG    0
 
 #if IDEFLOPPY_DEBUG_LOG
-#define debug_log(fmt, args...) \
-       printk(KERN_INFO "ide-floppy: " fmt, ## args)
+#define ide_debug_log(lvl, fmt, args...) __ide_debug_log(lvl, fmt, args)
 #else
-#define debug_log(fmt, args...) do {} while (0)
+#define ide_debug_log(lvl, fmt, args...) do {} while (0)
 #endif
 
 /*
 #define CAPACITY_CURRENT       0x02
 #define CAPACITY_NO_CARTRIDGE  0x03
 
-#define IDEFLOPPY_TICKS_DELAY  HZ/20   /* default delay for ZIP 100 (50ms) */
+/*
+ * The following delay solves a problem with ATAPI Zip 100 drive where BSY bit
+ * was apparently being deasserted before the unit was ready to receive data.
+ */
+#define IDEFLOPPY_PC_DELAY     (HZ/20) /* default delay for ZIP 100 (50ms) */
 
 /* Error code returned in rq->errors to the higher part of the driver. */
 #define        IDEFLOPPY_ERROR_GENERAL         101
 
 static DEFINE_MUTEX(idefloppy_ref_mutex);
 
-#define to_ide_floppy(obj) container_of(obj, struct ide_floppy_obj, kref)
-
-#define ide_floppy_g(disk) \
-       container_of((disk)->private_data, struct ide_floppy_obj, driver)
-
 static void idefloppy_cleanup_obj(struct kref *);
 
 static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
@@ -92,7 +92,7 @@ static struct ide_floppy_obj *ide_floppy_get(struct gendisk *disk)
        struct ide_floppy_obj *floppy = NULL;
 
        mutex_lock(&idefloppy_ref_mutex);
-       floppy = ide_floppy_g(disk);
+       floppy = ide_drv_g(disk, ide_floppy_obj);
        if (floppy) {
                if (ide_device_get(floppy->drive))
                        floppy = NULL;
@@ -123,13 +123,21 @@ static int idefloppy_end_request(ide_drive_t *drive, int uptodate, int nsecs)
        struct request *rq = HWGROUP(drive)->rq;
        int error;
 
-       debug_log("Reached %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
 
        switch (uptodate) {
-       case 0: error = IDEFLOPPY_ERROR_GENERAL; break;
-       case 1: error = 0; break;
-       default: error = uptodate;
+       case 0:
+               error = IDEFLOPPY_ERROR_GENERAL;
+               break;
+
+       case 1:
+               error = 0;
+               break;
+
+       default:
+               error = uptodate;
        }
+
        if (error)
                floppy->failed_pc = NULL;
        /* Why does this happen? */
@@ -156,13 +164,13 @@ static void idefloppy_update_buffers(ide_drive_t *drive,
                idefloppy_end_request(drive, 1, 0);
 }
 
-static void ide_floppy_callback(ide_drive_t *drive)
+static void ide_floppy_callback(ide_drive_t *drive, int dsc)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
-       struct ide_atapi_pc *pc = floppy->pc;
+       struct ide_atapi_pc *pc = drive->pc;
        int uptodate = pc->error ? 0 : 1;
 
-       debug_log("Reached %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
 
        if (floppy->failed_pc == pc)
                floppy->failed_pc = NULL;
@@ -171,7 +179,7 @@ static void ide_floppy_callback(ide_drive_t *drive)
            (pc->rq && blk_pc_request(pc->rq)))
                uptodate = 1; /* FIXME */
        else if (pc->c[0] == GPCMD_REQUEST_SENSE) {
-               u8 *buf = floppy->pc->buf;
+               u8 *buf = pc->buf;
 
                if (!pc->error) {
                        floppy->sense_key = buf[2] & 0x0F;
@@ -181,99 +189,20 @@ static void ide_floppy_callback(ide_drive_t *drive)
                                (u16)get_unaligned((u16 *)&buf[16]) : 0x10000;
 
                        if (floppy->failed_pc)
-                               debug_log("pc = %x, ", floppy->failed_pc->c[0]);
+                               ide_debug_log(IDE_DBG_PC, "pc = %x, ",
+                                             floppy->failed_pc->c[0]);
 
-                       debug_log("sense key = %x, asc = %x, ascq = %x\n",
-                                 floppy->sense_key, floppy->asc, floppy->ascq);
+                       ide_debug_log(IDE_DBG_SENSE, "sense key = %x, asc = %x,"
+                                     "ascq = %x\n", floppy->sense_key,
+                                     floppy->asc, floppy->ascq);
                } else
-                       printk(KERN_ERR "Error in REQUEST SENSE itself - "
-                                       "Aborting request!\n");
+                       printk(KERN_ERR PFX "Error in REQUEST SENSE itself - "
+                              "Aborting request!\n");
        }
 
        idefloppy_end_request(drive, uptodate, 0);
 }
 
-void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *pc)
-{
-       ide_init_pc(pc);
-       pc->c[0] = GPCMD_REQUEST_SENSE;
-       pc->c[4] = 255;
-       pc->req_xfer = 18;
-}
-
-/*
- * Called when an error was detected during the last packet command. We queue a
- * request sense packet command in the head of the request list.
- */
-static void idefloppy_retry_pc(ide_drive_t *drive)
-{
-       struct ide_floppy_obj *floppy = drive->driver_data;
-       struct request *rq = &floppy->request_sense_rq;
-       struct ide_atapi_pc *pc = &floppy->request_sense_pc;
-
-       (void)ide_read_error(drive);
-       ide_floppy_create_request_sense_cmd(pc);
-       ide_queue_pc_head(drive, floppy->disk, pc, rq);
-}
-
-/* The usual interrupt handler called during a packet command. */
-static ide_startstop_t idefloppy_pc_intr(ide_drive_t *drive)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-
-       return ide_pc_intr(drive, floppy->pc, idefloppy_pc_intr,
-                          WAIT_FLOPPY_CMD, NULL, idefloppy_update_buffers,
-                          idefloppy_retry_pc, NULL, ide_io_buffers);
-}
-
-/*
- * What we have here is a classic case of a top half / bottom half interrupt
- * service routine. In interrupt mode, the device sends an interrupt to signal
- * that it is ready to receive a packet. However, we need to delay about 2-3
- * ticks before issuing the packet or we gets in trouble.
- */
-static int idefloppy_transfer_pc(ide_drive_t *drive)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-
-       /* Send the actual packet */
-       drive->hwif->tp_ops->output_data(drive, NULL, floppy->pc->c, 12);
-
-       /* Timeout for the packet command */
-       return WAIT_FLOPPY_CMD;
-}
-
-/*
- * Called as an interrupt (or directly). When the device says it's ready for a
- * packet, we schedule the packet transfer to occur about 2-3 ticks later in
- * transfer_pc.
- */
-static ide_startstop_t idefloppy_start_pc_transfer(ide_drive_t *drive)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-       struct ide_atapi_pc *pc = floppy->pc;
-       ide_expiry_t *expiry;
-       unsigned int timeout;
-
-       /*
-        * The following delay solves a problem with ATAPI Zip 100 drives
-        * where the Busy flag was apparently being deasserted before the
-        * unit was ready to receive data. This was happening on a
-        * 1200 MHz Athlon system. 10/26/01 25msec is too short,
-        * 40 and 50msec work well. idefloppy_pc_intr will not be actually
-        * used until after the packet is moved in about 50 msec.
-        */
-       if (drive->atapi_flags & IDE_AFLAG_ZIP_DRIVE) {
-               timeout = floppy->ticks;
-               expiry = &idefloppy_transfer_pc;
-       } else {
-               timeout = WAIT_FLOPPY_CMD;
-               expiry = NULL;
-       }
-
-       return ide_transfer_pc(drive, pc, idefloppy_pc_intr, timeout, expiry);
-}
-
 static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
                                    struct ide_atapi_pc *pc)
 {
@@ -283,7 +212,7 @@ static void ide_floppy_report_error(idefloppy_floppy_t *floppy,
            floppy->ascq      == 0x00)
                return;
 
-       printk(KERN_ERR "ide-floppy: %s: I/O error, pc = %2x, key = %2x, "
+       printk(KERN_ERR PFX "%s: I/O error, pc = %2x, key = %2x, "
                        "asc = %2x, ascq = %2x\n",
                        floppy->drive->name, pc->c[0], floppy->sense_key,
                        floppy->asc, floppy->ascq);
@@ -298,8 +227,9 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
        if (floppy->failed_pc == NULL &&
            pc->c[0] != GPCMD_REQUEST_SENSE)
                floppy->failed_pc = pc;
+
        /* Set the current packet command */
-       floppy->pc = pc;
+       drive->pc = pc;
 
        if (pc->retries > IDEFLOPPY_MAX_PC_RETRIES) {
                if (!(pc->flags & PC_FLAG_SUPPRESS_ERROR))
@@ -308,16 +238,15 @@ static ide_startstop_t idefloppy_issue_pc(ide_drive_t *drive,
                pc->error = IDEFLOPPY_ERROR_GENERAL;
 
                floppy->failed_pc = NULL;
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, 0);
                return ide_stopped;
        }
 
-       debug_log("Retry number - %d\n", pc->retries);
+       ide_debug_log(IDE_DBG_FUNC, "%s: Retry #%d\n", __func__, pc->retries);
 
        pc->retries++;
 
-       return ide_issue_pc(drive, pc, idefloppy_start_pc_transfer,
-                           WAIT_FLOPPY_CMD, NULL);
+       return ide_issue_pc(drive, WAIT_FLOPPY_CMD, NULL);
 }
 
 void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *pc)
@@ -347,23 +276,23 @@ void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *pc, u8 page_code)
                length += 32;
                break;
        default:
-               printk(KERN_ERR "ide-floppy: unsupported page code "
-                               "in create_mode_sense_cmd\n");
+               printk(KERN_ERR PFX "unsupported page code in %s\n", __func__);
        }
        put_unaligned(cpu_to_be16(length), (u16 *) &pc->c[7]);
        pc->req_xfer = length;
 }
 
-static void idefloppy_create_rw_cmd(idefloppy_floppy_t *floppy,
+static void idefloppy_create_rw_cmd(ide_drive_t *drive,
                                    struct ide_atapi_pc *pc, struct request *rq,
                                    unsigned long sector)
 {
+       idefloppy_floppy_t *floppy = drive->driver_data;
        int block = sector / floppy->bs_factor;
        int blocks = rq->nr_sectors / floppy->bs_factor;
        int cmd = rq_data_dir(rq);
 
-       debug_log("create_rw10_cmd: block == %d, blocks == %d\n",
-               block, blocks);
+       ide_debug_log(IDE_DBG_FUNC, "%s: block: %d, blocks: %d\n", __func__,
+                     block, blocks);
 
        ide_init_pc(pc);
        pc->c[0] = cmd == READ ? GPCMD_READ_10 : GPCMD_WRITE_10;
@@ -408,41 +337,42 @@ static ide_startstop_t idefloppy_do_request(ide_drive_t *drive,
        struct ide_atapi_pc *pc;
        unsigned long block = (unsigned long)block_s;
 
-       debug_log("%s: dev: %s, cmd: 0x%x, cmd_type: %x, errors: %d\n",
-                 __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
-                 rq->cmd[0], rq->cmd_type, rq->errors);
+       ide_debug_log(IDE_DBG_FUNC, "%s: dev: %s, cmd: 0x%x, cmd_type: %x, "
+                     "errors: %d\n",
+                     __func__, rq->rq_disk ? rq->rq_disk->disk_name : "?",
+                     rq->cmd[0], rq->cmd_type, rq->errors);
 
-       debug_log("%s: sector: %ld, nr_sectors: %ld, current_nr_sectors: %d\n",
-                 __func__, (long)rq->sector, rq->nr_sectors,
-                 rq->current_nr_sectors);
+       ide_debug_log(IDE_DBG_FUNC, "%s: sector: %ld, nr_sectors: %ld, "
+                     "current_nr_sectors: %d\n",
+                     __func__, (long)rq->sector, rq->nr_sectors,
+                     rq->current_nr_sectors);
 
        if (rq->errors >= ERROR_MAX) {
                if (floppy->failed_pc)
                        ide_floppy_report_error(floppy, floppy->failed_pc);
                else
-                       printk(KERN_ERR "ide-floppy: %s: I/O error\n",
-                               drive->name);
+                       printk(KERN_ERR PFX "%s: I/O error\n", drive->name);
+
                idefloppy_end_request(drive, 0, 0);
                return ide_stopped;
        }
        if (blk_fs_request(rq)) {
                if (((long)rq->sector % floppy->bs_factor) ||
                    (rq->nr_sectors % floppy->bs_factor)) {
-                       printk(KERN_ERR "%s: unsupported r/w request size\n",
-                                       drive->name);
+                       printk(KERN_ERR PFX "%s: unsupported r/w rq size\n",
+                               drive->name);
                        idefloppy_end_request(drive, 0, 0);
                        return ide_stopped;
                }
                pc = &floppy->queued_pc;
-               idefloppy_create_rw_cmd(floppy, pc, rq, block);
+               idefloppy_create_rw_cmd(drive, pc, rq, block);
        } else if (blk_special_request(rq)) {
                pc = (struct ide_atapi_pc *) rq->buffer;
        } else if (blk_pc_request(rq)) {
                pc = &floppy->queued_pc;
                idefloppy_blockpc_cmd(floppy, pc, rq);
        } else {
-               blk_dump_rq_flags(rq,
-                       "ide-floppy: unsupported command in queue");
+               blk_dump_rq_flags(rq, PFX "unsupported command in queue");
                idefloppy_end_request(drive, 0, 0);
                return ide_stopped;
        }
@@ -475,8 +405,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
        ide_floppy_create_mode_sense_cmd(&pc, IDEFLOPPY_FLEXIBLE_DISK_PAGE);
 
        if (ide_queue_pc_tail(drive, disk, &pc)) {
-               printk(KERN_ERR "ide-floppy: Can't get flexible disk page"
-                               " parameters\n");
+               printk(KERN_ERR PFX "Can't get flexible disk page params\n");
                return 1;
        }
 
@@ -499,7 +428,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
        capacity = cyls * heads * sectors * sector_size;
 
        if (memcmp(page, &floppy->flexible_disk_page, 32))
-               printk(KERN_INFO "%s: %dkB, %d/%d/%d CHS, %d kBps, "
+               printk(KERN_INFO PFX "%s: %dkB, %d/%d/%d CHS, %d kBps, "
                                "%d sector size, %d rpm\n",
                                drive->name, capacity / 1024, cyls, heads,
                                sectors, transfer_rate / 8, sector_size, rpm);
@@ -511,7 +440,7 @@ static int ide_floppy_get_flexible_disk_page(ide_drive_t *drive)
        lba_capacity = floppy->blocks * floppy->block_size;
 
        if (capacity < lba_capacity) {
-               printk(KERN_NOTICE "%s: The disk reports a capacity of %d "
+               printk(KERN_NOTICE PFX "%s: The disk reports a capacity of %d "
                        "bytes, but the drive only handles %d\n",
                        drive->name, lba_capacity, capacity);
                floppy->blocks = floppy->block_size ?
@@ -541,7 +470,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
 
        ide_floppy_create_read_capacity_cmd(&pc);
        if (ide_queue_pc_tail(drive, disk, &pc)) {
-               printk(KERN_ERR "ide-floppy: Can't get floppy parameters\n");
+               printk(KERN_ERR PFX "Can't get floppy parameters\n");
                return 1;
        }
        header_len = pc.buf[3];
@@ -554,8 +483,9 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                blocks = be32_to_cpup((__be32 *)&pc.buf[desc_start]);
                length = be16_to_cpup((__be16 *)&pc.buf[desc_start + 6]);
 
-               debug_log("Descriptor %d: %dkB, %d blocks, %d sector size\n",
-                               i, blocks * length / 1024, blocks, length);
+               ide_debug_log(IDE_DBG_PROBE, "Descriptor %d: %dkB, %d blocks, "
+                             "%d sector size\n",
+                             i, blocks * length / 1024, blocks, length);
 
                if (i)
                        continue;
@@ -575,23 +505,24 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                case CAPACITY_CURRENT:
                        /* Normal Zip/LS-120 disks */
                        if (memcmp(cap_desc, &floppy->cap_desc, 8))
-                               printk(KERN_INFO "%s: %dkB, %d blocks, %d "
-                                       "sector size\n", drive->name,
-                                       blocks * length / 1024, blocks, length);
+                               printk(KERN_INFO PFX "%s: %dkB, %d blocks, %d "
+                                      "sector size\n",
+                                      drive->name, blocks * length / 1024,
+                                      blocks, length);
                        memcpy(&floppy->cap_desc, cap_desc, 8);
 
                        if (!length || length % 512) {
-                               printk(KERN_NOTICE "%s: %d bytes block size "
-                                       "not supported\n", drive->name, length);
+                               printk(KERN_NOTICE PFX "%s: %d bytes block size"
+                                      not supported\n", drive->name, length);
                        } else {
                                floppy->blocks = blocks;
                                floppy->block_size = length;
                                floppy->bs_factor = length / 512;
                                if (floppy->bs_factor != 1)
-                                       printk(KERN_NOTICE "%s: warning: non "
-                                               "512 bytes block size not "
-                                               "fully supported\n",
-                                               drive->name);
+                                       printk(KERN_NOTICE PFX "%s: Warning: "
+                                              "non 512 bytes block size not "
+                                              "fully supported\n",
+                                              drive->name);
                                rc = 0;
                        }
                        break;
@@ -600,15 +531,16 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
                         * This is a KERN_ERR so it appears on screen
                         * for the user to see
                         */
-                       printk(KERN_ERR "%s: No disk in drive\n", drive->name);
+                       printk(KERN_ERR PFX "%s: No disk in drive\n",
+                              drive->name);
                        break;
                case CAPACITY_INVALID:
-                       printk(KERN_ERR "%s: Invalid capacity for disk "
+                       printk(KERN_ERR PFX "%s: Invalid capacity for disk "
                                "in drive\n", drive->name);
                        break;
                }
-               debug_log("Descriptor 0 Code: %d\n",
-                         pc.buf[desc_start + 4] & 0x03);
+               ide_debug_log(IDE_DBG_PROBE, "Descriptor 0 Code: %d\n",
+                             pc.buf[desc_start + 4] & 0x03);
        }
 
        /* Clik! disk does not support get_flexible_disk_page */
@@ -620,7 +552,7 @@ static int ide_floppy_get_capacity(ide_drive_t *drive)
        return rc;
 }
 
-static sector_t idefloppy_capacity(ide_drive_t *drive)
+sector_t ide_floppy_capacity(ide_drive_t *drive)
 {
        idefloppy_floppy_t *floppy = drive->driver_data;
        unsigned long capacity = floppy->blocks * floppy->bs_factor;
@@ -628,46 +560,14 @@ static sector_t idefloppy_capacity(ide_drive_t *drive)
        return capacity;
 }
 
-#ifdef CONFIG_IDE_PROC_FS
-ide_devset_rw_field(bios_cyl, bios_cyl);
-ide_devset_rw_field(bios_head, bios_head);
-ide_devset_rw_field(bios_sect, bios_sect);
-
-static int get_ticks(ide_drive_t *drive)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-       return floppy->ticks;
-}
-
-static int set_ticks(ide_drive_t *drive, int arg)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-       floppy->ticks = arg;
-       return 0;
-}
-
-IDE_DEVSET(ticks, DS_SYNC, get_ticks, set_ticks);
-
-static const struct ide_proc_devset idefloppy_settings[] = {
-       IDE_PROC_DEVSET(bios_cyl,  0, 1023),
-       IDE_PROC_DEVSET(bios_head, 0,  255),
-       IDE_PROC_DEVSET(bios_sect, 0,   63),
-       IDE_PROC_DEVSET(ticks,     0,  255),
-       { 0 },
-};
-#endif
-
 static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
 {
        u16 *id = drive->id;
-       u8 gcw[2];
-
-       *((u16 *)&gcw) = id[ATA_ID_CONFIG];
 
-       drive->pc_callback = ide_floppy_callback;
+       drive->pc_callback       = ide_floppy_callback;
+       drive->pc_update_buffers = idefloppy_update_buffers;
+       drive->pc_io_buffers     = ide_io_buffers;
 
-       if (((gcw[0] & 0x60) >> 5) == 1)
-               drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
        /*
         * We used to check revisions here. At this point however I'm giving up.
         * Just assume they are all broken, its easier.
@@ -680,7 +580,7 @@ static void idefloppy_setup(ide_drive_t *drive, idefloppy_floppy_t *floppy)
        if (!strncmp((char *)&id[ATA_ID_PROD], "IOMEGA ZIP 100 ATAPI", 20)) {
                drive->atapi_flags |= IDE_AFLAG_ZIP_DRIVE;
                /* This value will be visible in the /proc/ide/hdx/settings */
-               floppy->ticks = IDEFLOPPY_TICKS_DELAY;
+               drive->pc_delay = IDEFLOPPY_PC_DELAY;
                blk_queue_max_sectors(drive->queue, 64);
        }
 
@@ -714,7 +614,7 @@ static void ide_floppy_remove(ide_drive_t *drive)
 
 static void idefloppy_cleanup_obj(struct kref *kref)
 {
-       struct ide_floppy_obj *floppy = to_ide_floppy(kref);
+       struct ide_floppy_obj *floppy = to_ide_drv(kref, ide_floppy_obj);
        ide_drive_t *drive = floppy->drive;
        struct gendisk *g = floppy->disk;
 
@@ -724,24 +624,6 @@ static void idefloppy_cleanup_obj(struct kref *kref)
        kfree(floppy);
 }
 
-#ifdef CONFIG_IDE_PROC_FS
-static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
-               int count, int *eof, void *data)
-{
-       ide_drive_t*drive = (ide_drive_t *)data;
-       int len;
-
-       len = sprintf(page, "%llu\n", (long long)idefloppy_capacity(drive));
-       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
-}
-
-static ide_proc_entry_t idefloppy_proc[] = {
-       { "capacity",   S_IFREG|S_IRUGO, proc_idefloppy_read_capacity,  NULL },
-       { "geometry",   S_IFREG|S_IRUGO, proc_ide_read_geometry,        NULL },
-       { NULL, 0, NULL, NULL }
-};
-#endif /* CONFIG_IDE_PROC_FS */
-
 static int ide_floppy_probe(ide_drive_t *);
 
 static ide_driver_t idefloppy_driver = {
@@ -753,13 +635,12 @@ static ide_driver_t idefloppy_driver = {
        .probe                  = ide_floppy_probe,
        .remove                 = ide_floppy_remove,
        .version                = IDEFLOPPY_VERSION,
-       .media                  = ide_floppy,
        .do_request             = idefloppy_do_request,
        .end_request            = idefloppy_end_request,
        .error                  = __ide_error,
 #ifdef CONFIG_IDE_PROC_FS
-       .proc                   = idefloppy_proc,
-       .settings               = idefloppy_settings,
+       .proc                   = ide_floppy_proc,
+       .settings               = ide_floppy_settings,
 #endif
 };
 
@@ -770,14 +651,14 @@ static int idefloppy_open(struct inode *inode, struct file *filp)
        ide_drive_t *drive;
        int ret = 0;
 
-       debug_log("Reached %s\n", __func__);
-
        floppy = ide_floppy_get(disk);
        if (!floppy)
                return -ENXIO;
 
        drive = floppy->drive;
 
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
+
        floppy->openers++;
 
        if (floppy->openers == 1) {
@@ -822,10 +703,10 @@ out_put_floppy:
 static int idefloppy_release(struct inode *inode, struct file *filp)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
-       struct ide_floppy_obj *floppy = ide_floppy_g(disk);
+       struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
        ide_drive_t *drive = floppy->drive;
 
-       debug_log("Reached %s\n", __func__);
+       ide_debug_log(IDE_DBG_FUNC, "Call %s\n", __func__);
 
        if (floppy->openers == 1) {
                ide_set_media_lock(drive, disk, 0);
@@ -841,7 +722,8 @@ static int idefloppy_release(struct inode *inode, struct file *filp)
 
 static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
 {
-       struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
+       struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
+                                                    ide_floppy_obj);
        ide_drive_t *drive = floppy->drive;
 
        geo->heads = drive->bios_head;
@@ -850,64 +732,15 @@ static int idefloppy_getgeo(struct block_device *bdev, struct hd_geometry *geo)
        return 0;
 }
 
-static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
-                              unsigned long arg, unsigned int cmd)
-{
-       idefloppy_floppy_t *floppy = drive->driver_data;
-       struct gendisk *disk = floppy->disk;
-       int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
-
-       if (floppy->openers > 1)
-               return -EBUSY;
-
-       ide_set_media_lock(drive, disk, prevent);
-
-       if (cmd == CDROMEJECT)
-               ide_do_start_stop(drive, disk, 2);
-
-       return 0;
-}
-
-static int idefloppy_ioctl(struct inode *inode, struct file *file,
-                       unsigned int cmd, unsigned long arg)
-{
-       struct block_device *bdev = inode->i_bdev;
-       struct ide_floppy_obj *floppy = ide_floppy_g(bdev->bd_disk);
-       ide_drive_t *drive = floppy->drive;
-       struct ide_atapi_pc pc;
-       void __user *argp = (void __user *)arg;
-       int err;
-
-       if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
-               return ide_floppy_lockdoor(drive, &pc, arg, cmd);
-
-       err = ide_floppy_format_ioctl(drive, file, cmd, argp);
-       if (err != -ENOTTY)
-               return err;
-
-       /*
-        * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
-        * and CDROM_SEND_PACKET (legacy) ioctls
-        */
-       if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
-               err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
-                                       bdev->bd_disk, cmd, argp);
-
-       if (err == -ENOTTY)
-               err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
-
-       return err;
-}
-
 static int idefloppy_media_changed(struct gendisk *disk)
 {
-       struct ide_floppy_obj *floppy = ide_floppy_g(disk);
+       struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
        ide_drive_t *drive = floppy->drive;
        int ret;
 
        /* do not scan partitions twice if this is a removable device */
-       if (drive->attach) {
-               drive->attach = 0;
+       if (drive->dev_flags & IDE_DFLAG_ATTACH) {
+               drive->dev_flags &= ~IDE_DFLAG_ATTACH;
                return 0;
        }
        ret = !!(drive->atapi_flags & IDE_AFLAG_MEDIA_CHANGED);
@@ -917,8 +750,8 @@ static int idefloppy_media_changed(struct gendisk *disk)
 
 static int idefloppy_revalidate_disk(struct gendisk *disk)
 {
-       struct ide_floppy_obj *floppy = ide_floppy_g(disk);
-       set_capacity(disk, idefloppy_capacity(floppy->drive));
+       struct ide_floppy_obj *floppy = ide_drv_g(disk, ide_floppy_obj);
+       set_capacity(disk, ide_floppy_capacity(floppy->drive));
        return 0;
 }
 
@@ -926,7 +759,7 @@ static struct block_device_operations idefloppy_ops = {
        .owner                  = THIS_MODULE,
        .open                   = idefloppy_open,
        .release                = idefloppy_release,
-       .ioctl                  = idefloppy_ioctl,
+       .ioctl                  = ide_floppy_ioctl,
        .getgeo                 = idefloppy_getgeo,
        .media_changed          = idefloppy_media_changed,
        .revalidate_disk        = idefloppy_revalidate_disk
@@ -944,14 +777,14 @@ static int ide_floppy_probe(ide_drive_t *drive)
                goto failed;
 
        if (!ide_check_atapi_device(drive, DRV_NAME)) {
-               printk(KERN_ERR "ide-floppy: %s: not supported by this version"
-                               " of ide-floppy\n", drive->name);
+               printk(KERN_ERR PFX "%s: not supported by this version of "
+                      DRV_NAME "\n", drive->name);
                goto failed;
        }
        floppy = kzalloc(sizeof(idefloppy_floppy_t), GFP_KERNEL);
        if (!floppy) {
-               printk(KERN_ERR "ide-floppy: %s: Can't allocate a floppy"
-                               " structure\n", drive->name);
+               printk(KERN_ERR PFX "%s: Can't allocate a floppy structure\n",
+                      drive->name);
                goto failed;
        }
 
@@ -971,13 +804,16 @@ static int ide_floppy_probe(ide_drive_t *drive)
 
        drive->driver_data = floppy;
 
+       drive->debug_mask = debug_mask;
+
        idefloppy_setup(drive, floppy);
+       drive->dev_flags |= IDE_DFLAG_ATTACH;
 
        g->minors = 1 << PARTN_BITS;
        g->driverfs_dev = &drive->gendev;
-       g->flags = drive->removable ? GENHD_FL_REMOVABLE : 0;
+       if (drive->dev_flags & IDE_DFLAG_REMOVABLE)
+               g->flags = GENHD_FL_REMOVABLE;
        g->fops = &idefloppy_ops;
-       drive->attach = 1;
        add_disk(g);
        return 0;
 
@@ -994,7 +830,7 @@ static void __exit idefloppy_exit(void)
 
 static int __init idefloppy_init(void)
 {
-       printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
+       printk(KERN_INFO DRV_NAME " driver " IDEFLOPPY_VERSION "\n");
        return driver_register(&idefloppy_driver.gen_driver);
 }
 
index ecadc2bc322dc9904acb4507281db91d1138e9a7..17cf865e583d28edd7890b3e874bcd0cdec561ce 100644 (file)
@@ -13,20 +13,14 @@ typedef struct ide_floppy_obj {
        struct kref     kref;
        unsigned int    openers;        /* protected by BKL for now */
 
-       /* Current packet command */
-       struct ide_atapi_pc *pc;
        /* Last failed packet command */
        struct ide_atapi_pc *failed_pc;
        /* used for blk_{fs,pc}_request() requests */
        struct ide_atapi_pc queued_pc;
 
-       struct ide_atapi_pc request_sense_pc;
-       struct request request_sense_rq;
-
        /* Last error information */
        u8 sense_key, asc, ascq;
-       /* delay this long before sending packet command */
-       u8 ticks;
+
        int progress_indication;
 
        /* Device information */
@@ -54,10 +48,15 @@ typedef struct ide_floppy_obj {
 /* ide-floppy.c */
 void ide_floppy_create_mode_sense_cmd(struct ide_atapi_pc *, u8);
 void ide_floppy_create_read_capacity_cmd(struct ide_atapi_pc *);
-void ide_floppy_create_request_sense_cmd(struct ide_atapi_pc *);
+sector_t ide_floppy_capacity(ide_drive_t *);
 
 /* ide-floppy_ioctl.c */
-int ide_floppy_format_ioctl(ide_drive_t *, struct file *, unsigned int,
-                           void __user *);
+int ide_floppy_ioctl(struct inode *, struct file *, unsigned, unsigned long);
+
+#ifdef CONFIG_IDE_PROC_FS
+/* ide-floppy_proc.c */
+extern ide_proc_entry_t ide_floppy_proc[];
+extern const struct ide_proc_devset ide_floppy_settings[];
+#endif
 
 #endif /*__IDE_FLOPPY_H */
index 5ffc4512d14bbeb02cd6d853603e4564d27df9b5..a3a7a0809e2bdf5edba01c3c93c0f2b6cd467d8a 100644 (file)
@@ -195,7 +195,7 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
        int progress_indication = 0x10000;
 
        if (drive->atapi_flags & IDE_AFLAG_SRFP) {
-               ide_floppy_create_request_sense_cmd(&pc);
+               ide_create_request_sense_cmd(drive, &pc);
                if (ide_queue_pc_tail(drive, floppy->disk, &pc))
                        return -EIO;
 
@@ -223,8 +223,26 @@ static int ide_floppy_get_format_progress(ide_drive_t *drive, int __user *arg)
        return 0;
 }
 
-int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
-                           unsigned int cmd, void __user *argp)
+static int ide_floppy_lockdoor(ide_drive_t *drive, struct ide_atapi_pc *pc,
+                              unsigned long arg, unsigned int cmd)
+{
+       idefloppy_floppy_t *floppy = drive->driver_data;
+       struct gendisk *disk = floppy->disk;
+       int prevent = (arg && cmd != CDROMEJECT) ? 1 : 0;
+
+       if (floppy->openers > 1)
+               return -EBUSY;
+
+       ide_set_media_lock(drive, disk, prevent);
+
+       if (cmd == CDROMEJECT)
+               ide_do_start_stop(drive, disk, 2);
+
+       return 0;
+}
+
+static int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
+                                  unsigned int cmd, void __user *argp)
 {
        switch (cmd) {
        case IDEFLOPPY_IOCTL_FORMAT_SUPPORTED:
@@ -241,3 +259,35 @@ int ide_floppy_format_ioctl(ide_drive_t *drive, struct file *file,
                return -ENOTTY;
        }
 }
+
+int ide_floppy_ioctl(struct inode *inode, struct file *file,
+                   unsigned int cmd, unsigned long arg)
+{
+       struct block_device *bdev = inode->i_bdev;
+       struct ide_floppy_obj *floppy = ide_drv_g(bdev->bd_disk,
+                                                    ide_floppy_obj);
+       ide_drive_t *drive = floppy->drive;
+       struct ide_atapi_pc pc;
+       void __user *argp = (void __user *)arg;
+       int err;
+
+       if (cmd == CDROMEJECT || cmd == CDROM_LOCKDOOR)
+               return ide_floppy_lockdoor(drive, &pc, arg, cmd);
+
+       err = ide_floppy_format_ioctl(drive, file, cmd, argp);
+       if (err != -ENOTTY)
+               return err;
+
+       /*
+        * skip SCSI_IOCTL_SEND_COMMAND (deprecated)
+        * and CDROM_SEND_PACKET (legacy) ioctls
+        */
+       if (cmd != CDROM_SEND_PACKET && cmd != SCSI_IOCTL_SEND_COMMAND)
+               err = scsi_cmd_ioctl(file, bdev->bd_disk->queue,
+                                       bdev->bd_disk, cmd, argp);
+
+       if (err == -ENOTTY)
+               err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
+
+       return err;
+}
diff --git a/drivers/ide/ide-floppy_proc.c b/drivers/ide/ide-floppy_proc.c
new file mode 100644 (file)
index 0000000..76f0c6c
--- /dev/null
@@ -0,0 +1,33 @@
+#include <linux/kernel.h>
+#include <linux/ide.h>
+
+#include "ide-floppy.h"
+
+static int proc_idefloppy_read_capacity(char *page, char **start, off_t off,
+               int count, int *eof, void *data)
+{
+       ide_drive_t*drive = (ide_drive_t *)data;
+       int len;
+
+       len = sprintf(page, "%llu\n", (long long)ide_floppy_capacity(drive));
+       PROC_IDE_READ_RETURN(page, start, off, count, eof, len);
+}
+
+ide_proc_entry_t ide_floppy_proc[] = {
+       { "capacity",   S_IFREG|S_IRUGO, proc_idefloppy_read_capacity,  NULL },
+       { "geometry",   S_IFREG|S_IRUGO, proc_ide_read_geometry,        NULL },
+       { NULL, 0, NULL, NULL }
+};
+
+ide_devset_rw_field(bios_cyl, bios_cyl);
+ide_devset_rw_field(bios_head, bios_head);
+ide_devset_rw_field(bios_sect, bios_sect);
+ide_devset_rw_field(ticks, pc_delay);
+
+const struct ide_proc_devset ide_floppy_settings[] = {
+       IDE_PROC_DEVSET(bios_cyl,  0, 1023),
+       IDE_PROC_DEVSET(bios_head, 0,  255),
+       IDE_PROC_DEVSET(bios_sect, 0,   63),
+       IDE_PROC_DEVSET(ticks,     0,  255),
+       { 0 },
+};
index 0a3cb0c33ae579533ad33eb46c7d9cbfe3c74276..81a5282ce1eb06e74a93168e33cd94e9d5f1ac52 100644 (file)
@@ -137,15 +137,10 @@ static void ide_generic_check_pci_legacy_iobases(int *primary, int *secondary)
 
 static int __init ide_generic_init(void)
 {
-       hw_regs_t hw[MAX_HWIFS], *hws[MAX_HWIFS];
-       struct ide_host *host;
+       hw_regs_t hw, *hws[] = { &hw, NULL, NULL, NULL };
        unsigned long io_addr;
-       int i, rc, primary = 0, secondary = 0;
+       int i, rc = 0, primary = 0, secondary = 0;
 
-#ifdef CONFIG_MIPS
-       if (!ide_probe_legacy())
-               return -ENODEV;
-#endif
        ide_generic_check_pci_legacy_iobases(&primary, &secondary);
 
        if (!probe_mask) {
@@ -161,13 +156,9 @@ static int __init ide_generic_init(void)
                printk(KERN_INFO DRV_NAME ": enforcing probing of I/O ports "
                        "upon user request\n");
 
-       memset(hws, 0, sizeof(hw_regs_t *) * MAX_HWIFS);
-
        for (i = 0; i < ARRAY_SIZE(legacy_bases); i++) {
                io_addr = legacy_bases[i];
 
-               hws[i] = NULL;
-
                if ((probe_mask & (1 << i)) && io_addr) {
                        if (!request_region(io_addr, 8, DRV_NAME)) {
                                printk(KERN_ERR "%s: I/O resource 0x%lX-0x%lX "
@@ -184,45 +175,27 @@ static int __init ide_generic_init(void)
                                continue;
                        }
 
-                       memset(&hw[i], 0, sizeof(hw[i]));
-                       ide_std_init_ports(&hw[i], io_addr, io_addr + 0x206);
+                       memset(&hw, 0, sizeof(hw));
+                       ide_std_init_ports(&hw, io_addr, io_addr + 0x206);
 #ifdef CONFIG_IA64
-                       hw[i].irq = isa_irq_to_vector(legacy_irqs[i]);
+                       hw.irq = isa_irq_to_vector(legacy_irqs[i]);
 #else
-                       hw[i].irq = legacy_irqs[i];
+                       hw.irq = legacy_irqs[i];
 #endif
-                       hw[i].chipset = ide_generic;
+                       hw.chipset = ide_generic;
 
-                       hws[i] = &hw[i];
+                       rc = ide_host_add(NULL, hws, NULL);
+                       if (rc) {
+                               release_region(io_addr + 0x206, 1);
+                               release_region(io_addr, 8);
+                       }
                }
        }
 
-       host = ide_host_alloc_all(NULL, hws);
-       if (host == NULL) {
-               rc = -ENOMEM;
-               goto err;
-       }
-
-       rc = ide_host_register(host, NULL, hws);
-       if (rc)
-               goto err_free;
-
        if (ide_generic_sysfs_init())
                printk(KERN_ERR DRV_NAME ": failed to create ide_generic "
                                         "class\n");
 
-       return 0;
-err_free:
-       ide_host_free(host);
-err:
-       for (i = 0; i < MAX_HWIFS; i++) {
-               if (hws[i] == NULL)
-                       continue;
-
-               io_addr = hws[i]->io_ports.data_addr;
-               release_region(io_addr + 0x206, 1);
-               release_region(io_addr, 8);
-       }
        return rc;
 }
 
index 1c51949833be5ed17e71bde14a0fa8b55b0e47ee..77c6eaeacefafaf987f0d7500eb82f394e189284 100644 (file)
@@ -78,8 +78,9 @@ static int __ide_end_request(ide_drive_t *drive, struct request *rq,
         * decide whether to reenable DMA -- 3 is a random magic for now,
         * if we DMA timeout more than 3 times, just stay in PIO
         */
-       if (drive->state == DMA_PIO_RETRY && drive->retry_pio <= 3) {
-               drive->state = 0;
+       if ((drive->dev_flags & IDE_DFLAG_DMA_PIO_RETRY) &&
+           drive->retry_pio <= 3) {
+               drive->dev_flags &= ~IDE_DFLAG_DMA_PIO_RETRY;
                ide_dma_on(drive);
        }
 
@@ -131,21 +132,6 @@ int ide_end_request (ide_drive_t *drive, int uptodate, int nr_sectors)
 }
 EXPORT_SYMBOL(ide_end_request);
 
-/*
- * Power Management state machine. This one is rather trivial for now,
- * we should probably add more, like switching back to PIO on suspend
- * to help some BIOSes, re-do the door locking on resume, etc...
- */
-
-enum {
-       ide_pm_flush_cache      = ide_pm_state_start_suspend,
-       idedisk_pm_standby,
-
-       idedisk_pm_restore_pio  = ide_pm_state_start_resume,
-       idedisk_pm_idle,
-       ide_pm_restore_dma,
-};
-
 static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 stat, u8 error)
 {
        struct request_pm_state *pm = rq->data;
@@ -154,20 +140,20 @@ static void ide_complete_power_step(ide_drive_t *drive, struct request *rq, u8 s
                return;
 
        switch (pm->pm_step) {
-       case ide_pm_flush_cache:        /* Suspend step 1 (flush cache) complete */
+       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
                if (pm->pm_state == PM_EVENT_FREEZE)
-                       pm->pm_step = ide_pm_state_completed;
+                       pm->pm_step = IDE_PM_COMPLETED;
                else
-                       pm->pm_step = idedisk_pm_standby;
+                       pm->pm_step = IDE_PM_STANDBY;
                break;
-       case idedisk_pm_standby:        /* Suspend step 2 (standby) complete */
-               pm->pm_step = ide_pm_state_completed;
+       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
+               pm->pm_step = IDE_PM_COMPLETED;
                break;
-       case idedisk_pm_restore_pio:    /* Resume step 1 complete */
-               pm->pm_step = idedisk_pm_idle;
+       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
+               pm->pm_step = IDE_PM_IDLE;
                break;
-       case idedisk_pm_idle:           /* Resume step 2 (idle) complete */
-               pm->pm_step = ide_pm_restore_dma;
+       case IDE_PM_IDLE:               /* Resume step 2 (idle)*/
+               pm->pm_step = IDE_PM_RESTORE_DMA;
                break;
        }
 }
@@ -180,11 +166,12 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
        memset(args, 0, sizeof(*args));
 
        switch (pm->pm_step) {
-       case ide_pm_flush_cache:        /* Suspend step 1 (flush cache) */
+       case IDE_PM_FLUSH_CACHE:        /* Suspend step 1 (flush cache) */
                if (drive->media != ide_disk)
                        break;
                /* Not supported? Switch to next step now. */
-               if (!drive->wcache || ata_id_flush_enabled(drive->id) == 0) {
+               if (ata_id_flush_enabled(drive->id) == 0 ||
+                   (drive->dev_flags & IDE_DFLAG_WCACHE) == 0) {
                        ide_complete_power_step(drive, rq, 0, 0);
                        return ide_stopped;
                }
@@ -193,27 +180,23 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
                else
                        args->tf.command = ATA_CMD_FLUSH;
                goto out_do_tf;
-
-       case idedisk_pm_standby:        /* Suspend step 2 (standby) */
+       case IDE_PM_STANDBY:            /* Suspend step 2 (standby) */
                args->tf.command = ATA_CMD_STANDBYNOW1;
                goto out_do_tf;
-
-       case idedisk_pm_restore_pio:    /* Resume step 1 (restore PIO) */
+       case IDE_PM_RESTORE_PIO:        /* Resume step 1 (restore PIO) */
                ide_set_max_pio(drive);
                /*
-                * skip idedisk_pm_idle for ATAPI devices
+                * skip IDE_PM_IDLE for ATAPI devices
                 */
                if (drive->media != ide_disk)
-                       pm->pm_step = ide_pm_restore_dma;
+                       pm->pm_step = IDE_PM_RESTORE_DMA;
                else
                        ide_complete_power_step(drive, rq, 0, 0);
                return ide_stopped;
-
-       case idedisk_pm_idle:           /* Resume step 2 (idle) */
+       case IDE_PM_IDLE:               /* Resume step 2 (idle) */
                args->tf.command = ATA_CMD_IDLEIMMEDIATE;
                goto out_do_tf;
-
-       case ide_pm_restore_dma:        /* Resume step 3 (restore DMA) */
+       case IDE_PM_RESTORE_DMA:        /* Resume step 3 (restore DMA) */
                /*
                 * Right now, all we do is call ide_set_dma(drive),
                 * we could be smarter and check for current xfer_speed
@@ -222,12 +205,13 @@ static ide_startstop_t ide_start_power_step(ide_drive_t *drive, struct request *
                if (drive->hwif->dma_ops == NULL)
                        break;
                /*
-                * TODO: respect ->using_dma setting
+                * TODO: respect IDE_DFLAG_USING_DMA
                 */
                ide_set_dma(drive);
                break;
        }
-       pm->pm_step = ide_pm_state_completed;
+
+       pm->pm_step = IDE_PM_COMPLETED;
        return ide_stopped;
 
 out_do_tf:
@@ -287,7 +271,7 @@ static void ide_complete_pm_request (ide_drive_t *drive, struct request *rq)
        if (blk_pm_suspend_request(rq)) {
                blk_stop_queue(drive->queue);
        } else {
-               drive->blocked = 0;
+               drive->dev_flags &= ~IDE_DFLAG_BLOCKED;
                blk_start_queue(drive->queue);
        }
        HWGROUP(drive)->rq = NULL;
@@ -343,7 +327,7 @@ void ide_end_drive_cmd (ide_drive_t *drive, u8 stat, u8 err)
                        drive->name, rq->pm->pm_step, stat, err);
 #endif
                ide_complete_power_step(drive, rq, stat, err);
-               if (pm->pm_step == ide_pm_state_completed)
+               if (pm->pm_step == IDE_PM_COMPLETED)
                        ide_complete_pm_request(drive, rq);
                return;
        }
@@ -374,13 +358,14 @@ static ide_startstop_t ide_ata_error(ide_drive_t *drive, struct request *rq, u8
 {
        ide_hwif_t *hwif = drive->hwif;
 
-       if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) {
+       if ((stat & ATA_BUSY) ||
+           ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
                /* other bits are useless when BUSY */
                rq->errors |= ERROR_RESET;
        } else if (stat & ATA_ERR) {
                /* err has different meaning on cdrom and tape */
                if (err == ATA_ABORTED) {
-                       if (drive->select.b.lba &&
+                       if ((drive->dev_flags & IDE_DFLAG_LBA) &&
                            /* some newer drives don't support ATA_CMD_INIT_DEV_PARAMS */
                            hwif->tp_ops->read_status(hwif) == ATA_CMD_INIT_DEV_PARAMS)
                                return ide_stopped;
@@ -428,7 +413,8 @@ static ide_startstop_t ide_atapi_error(ide_drive_t *drive, struct request *rq, u
 {
        ide_hwif_t *hwif = drive->hwif;
 
-       if ((stat & ATA_BUSY) || ((stat & ATA_DF) && !drive->nowerr)) {
+       if ((stat & ATA_BUSY) ||
+           ((stat & ATA_DF) && (drive->dev_flags & IDE_DFLAG_NOWERR) == 0)) {
                /* other bits are useless when BUSY */
                rq->errors |= ERROR_RESET;
        } else {
@@ -509,7 +495,7 @@ static void ide_tf_set_specify_cmd(ide_drive_t *drive, struct ide_taskfile *tf)
        tf->lbal    = drive->sect;
        tf->lbam    = drive->cyl;
        tf->lbah    = drive->cyl >> 8;
-       tf->device  = ((drive->head - 1) | drive->select.all) & ~ATA_LBA;
+       tf->device  = (drive->head - 1) | drive->select;
        tf->command = ATA_CMD_INIT_DEV_PARAMS;
 }
 
@@ -557,30 +543,6 @@ static ide_startstop_t ide_disk_special(ide_drive_t *drive)
        return ide_started;
 }
 
-/*
- * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
- */
-static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
-{
-       switch (req_pio) {
-       case 202:
-       case 201:
-       case 200:
-       case 102:
-       case 101:
-       case 100:
-               return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
-       case 9:
-       case 8:
-               return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
-       case 7:
-       case 6:
-               return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
-       default:
-               return 0;
-       }
-}
-
 /**
  *     do_special              -       issue some special commands
  *     @drive: drive the command is for
@@ -598,45 +560,12 @@ static ide_startstop_t do_special (ide_drive_t *drive)
 #ifdef DEBUG
        printk("%s: do_special: 0x%02x\n", drive->name, s->all);
 #endif
-       if (s->b.set_tune) {
-               ide_hwif_t *hwif = drive->hwif;
-               const struct ide_port_ops *port_ops = hwif->port_ops;
-               u8 req_pio = drive->tune_req;
-
-               s->b.set_tune = 0;
-
-               if (set_pio_mode_abuse(drive->hwif, req_pio)) {
-                       /*
-                        * take ide_lock for drive->[no_]unmask/[no_]io_32bit
-                        */
-                       if (req_pio == 8 || req_pio == 9) {
-                               unsigned long flags;
-
-                               spin_lock_irqsave(&ide_lock, flags);
-                               port_ops->set_pio_mode(drive, req_pio);
-                               spin_unlock_irqrestore(&ide_lock, flags);
-                       } else
-                               port_ops->set_pio_mode(drive, req_pio);
-               } else {
-                       int keep_dma = drive->using_dma;
-
-                       ide_set_pio(drive, req_pio);
-
-                       if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
-                               if (keep_dma)
-                                       ide_dma_on(drive);
-                       }
-               }
-
-               return ide_stopped;
-       } else {
-               if (drive->media == ide_disk)
-                       return ide_disk_special(drive);
+       if (drive->media == ide_disk)
+               return ide_disk_special(drive);
 
-               s->all = 0;
-               drive->mult_req = 0;
-               return ide_stopped;
-       }
+       s->all = 0;
+       drive->mult_req = 0;
+       return ide_stopped;
 }
 
 void ide_map_sg(ide_drive_t *drive, struct request *rq)
@@ -726,10 +655,7 @@ int ide_devset_execute(ide_drive_t *drive, const struct ide_devset *setting,
        if (!(setting->flags & DS_SYNC))
                return setting->set(drive, arg);
 
-       rq = blk_get_request(q, READ, GFP_KERNEL);
-       if (!rq)
-               return -ENOMEM;
-
+       rq = blk_get_request(q, READ, __GFP_WAIT);
        rq->cmd_type = REQ_TYPE_SPECIAL;
        rq->cmd_len = 5;
        rq->cmd[0] = REQ_DEVSET_EXEC;
@@ -746,7 +672,32 @@ EXPORT_SYMBOL_GPL(ide_devset_execute);
 
 static ide_startstop_t ide_special_rq(ide_drive_t *drive, struct request *rq)
 {
-       switch (rq->cmd[0]) {
+       u8 cmd = rq->cmd[0];
+
+       if (cmd == REQ_PARK_HEADS || cmd == REQ_UNPARK_HEADS) {
+               ide_task_t task;
+               struct ide_taskfile *tf = &task.tf;
+
+               memset(&task, 0, sizeof(task));
+               if (cmd == REQ_PARK_HEADS) {
+                       drive->sleep = *(unsigned long *)rq->special;
+                       drive->dev_flags |= IDE_DFLAG_SLEEPING;
+                       tf->command = ATA_CMD_IDLEIMMEDIATE;
+                       tf->feature = 0x44;
+                       tf->lbal = 0x4c;
+                       tf->lbam = 0x4e;
+                       tf->lbah = 0x55;
+                       task.tf_flags |= IDE_TFLAG_CUSTOM_HANDLER;
+               } else          /* cmd == REQ_UNPARK_HEADS */
+                       tf->command = ATA_CMD_CHK_POWER;
+
+               task.tf_flags |= IDE_TFLAG_TF | IDE_TFLAG_DEVICE;
+               task.rq = rq;
+               drive->hwif->data_phase = task.data_phase = TASKFILE_NO_DATA;
+               return do_rw_taskfile(drive, &task);
+       }
+
+       switch (cmd) {
        case REQ_DEVSET_EXEC:
        {
                int err, (*setfunc)(ide_drive_t *, int) = rq->special;
@@ -773,11 +724,11 @@ static void ide_check_pm_state(ide_drive_t *drive, struct request *rq)
        struct request_pm_state *pm = rq->data;
 
        if (blk_pm_suspend_request(rq) &&
-           pm->pm_step == ide_pm_state_start_suspend)
+           pm->pm_step == IDE_PM_START_SUSPEND)
                /* Mark drive blocked when starting the suspend sequence. */
-               drive->blocked = 1;
+               drive->dev_flags |= IDE_DFLAG_BLOCKED;
        else if (blk_pm_resume_request(rq) &&
-                pm->pm_step == ide_pm_state_start_resume) {
+                pm->pm_step == IDE_PM_START_RESUME) {
                /* 
                 * The first thing we do on wakeup is to wait for BSY bit to
                 * go away (with a looong timeout) as a drive on this hwif may
@@ -857,7 +808,7 @@ static ide_startstop_t start_request (ide_drive_t *drive, struct request *rq)
 #endif
                        startstop = ide_start_power_step(drive, rq);
                        if (startstop == ide_stopped &&
-                           pm->pm_step == ide_pm_state_completed)
+                           pm->pm_step == IDE_PM_COMPLETED)
                                ide_complete_pm_request(drive, rq);
                        return startstop;
                } else if (!rq->rq_disk && blk_special_request(rq))
@@ -895,7 +846,7 @@ void ide_stall_queue (ide_drive_t *drive, unsigned long timeout)
        if (timeout > WAIT_WORSTCASE)
                timeout = WAIT_WORSTCASE;
        drive->sleep = timeout + jiffies;
-       drive->sleeping = 1;
+       drive->dev_flags |= IDE_DFLAG_SLEEPING;
 }
 
 EXPORT_SYMBOL(ide_stall_queue);
@@ -935,18 +886,23 @@ repeat:
        }
 
        do {
-               if ((!drive->sleeping || time_after_eq(jiffies, drive->sleep))
-                   && !elv_queue_empty(drive->queue)) {
-                       if (!best
-                        || (drive->sleeping && (!best->sleeping || time_before(drive->sleep, best->sleep)))
-                        || (!best->sleeping && time_before(WAKEUP(drive), WAKEUP(best))))
-                       {
+               u8 dev_s = !!(drive->dev_flags & IDE_DFLAG_SLEEPING);
+               u8 best_s = (best && !!(best->dev_flags & IDE_DFLAG_SLEEPING));
+
+               if ((dev_s == 0 || time_after_eq(jiffies, drive->sleep)) &&
+                   !elv_queue_empty(drive->queue)) {
+                       if (best == NULL ||
+                           (dev_s && (best_s == 0 || time_before(drive->sleep, best->sleep))) ||
+                           (best_s == 0 && time_before(WAKEUP(drive), WAKEUP(best)))) {
                                if (!blk_queue_plugged(drive->queue))
                                        best = drive;
                        }
                }
        } while ((drive = drive->next) != hwgroup->drive);
-       if (best && best->nice1 && !best->sleeping && best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
+
+       if (best && (best->dev_flags & IDE_DFLAG_NICE1) &&
+           (best->dev_flags & IDE_DFLAG_SLEEPING) == 0 &&
+           best != hwgroup->drive && best->service_time > WAIT_MIN_SLEEP) {
                long t = (signed long)(WAKEUP(best) - jiffies);
                if (t >= WAIT_MIN_SLEEP) {
                /*
@@ -955,7 +911,7 @@ repeat:
                 */
                        drive = best->next;
                        do {
-                               if (!drive->sleeping
+                               if ((drive->dev_flags & IDE_DFLAG_SLEEPING) == 0
                                 && time_before(jiffies - best->service_time, WAKEUP(drive))
                                 && time_before(WAKEUP(drive), jiffies + t))
                                {
@@ -1026,7 +982,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
                        hwgroup->rq = NULL;
                        drive = hwgroup->drive;
                        do {
-                               if (drive->sleeping && (!sleeping || time_before(drive->sleep, sleep))) {
+                               if ((drive->dev_flags & IDE_DFLAG_SLEEPING) &&
+                                   (sleeping == 0 ||
+                                    time_before(drive->sleep, sleep))) {
                                        sleeping = 1;
                                        sleep = drive->sleep;
                                }
@@ -1075,7 +1033,7 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
                }
                hwgroup->hwif = hwif;
                hwgroup->drive = drive;
-               drive->sleeping = 0;
+               drive->dev_flags &= ~(IDE_DFLAG_SLEEPING | IDE_DFLAG_PARKED);
                drive->service_start = jiffies;
 
                if (blk_queue_plugged(drive->queue)) {
@@ -1109,7 +1067,9 @@ static void ide_do_request (ide_hwgroup_t *hwgroup, int masked_irq)
                 * We count how many times we loop here to make sure we service
                 * all drives in the hwgroup without looping for ever
                 */
-               if (drive->blocked && !blk_pm_request(rq) && !(rq->cmd_flags & REQ_PREEMPT)) {
+               if ((drive->dev_flags & IDE_DFLAG_BLOCKED) &&
+                   blk_pm_request(rq) == 0 &&
+                   (rq->cmd_flags & REQ_PREEMPT) == 0) {
                        drive = drive->next ? drive->next : hwgroup->drive;
                        if (loops++ < 4 && !blk_queue_plugged(drive->queue))
                                goto again;
@@ -1182,8 +1142,8 @@ static ide_startstop_t ide_dma_timeout_retry(ide_drive_t *drive, int error)
         * a timeout -- we'll reenable after we finish this next request
         * (or rather the first chunk of it) in pio.
         */
+       drive->dev_flags |= IDE_DFLAG_DMA_PIO_RETRY;
        drive->retry_pio++;
-       drive->state = DMA_PIO_RETRY;
        ide_dma_off_quietly(drive);
 
        /*
@@ -1480,23 +1440,16 @@ irqreturn_t ide_intr (int irq, void *dev_id)
        del_timer(&hwgroup->timer);
        spin_unlock(&ide_lock);
 
-       /* Some controllers might set DMA INTR no matter DMA or PIO;
-        * bmdma status might need to be cleared even for
-        * PIO interrupts to prevent spurious/lost irq.
-        */
-       if (hwif->ide_dma_clear_irq && !(drive->waiting_for_dma))
-               /* ide_dma_end() needs bmdma status for error checking.
-                * So, skip clearing bmdma status here and leave it
-                * to ide_dma_end() if this is dma interrupt.
-                */
-               hwif->ide_dma_clear_irq(drive);
+       if (hwif->port_ops && hwif->port_ops->clear_irq)
+               hwif->port_ops->clear_irq(drive);
 
-       if (drive->unmask)
+       if (drive->dev_flags & IDE_DFLAG_UNMASK)
                local_irq_enable_in_hardirq();
+
        /* service this interrupt, may set handler for next interrupt */
        startstop = handler(drive);
-       spin_lock_irq(&ide_lock);
 
+       spin_lock_irq(&ide_lock);
        /*
         * Note that handler() may have set things up for another
         * interrupt to occur soon, but it cannot happen until
index cf01564901af245d976f0edcb6dd9d6c7ba75f97..a90945f4979287ca8d260d65c4fab2e144a846af 100644 (file)
@@ -62,7 +62,7 @@ static int ide_get_identity_ioctl(ide_drive_t *drive, unsigned int cmd,
        int size = (cmd == HDIO_GET_IDENTITY) ? (ATA_ID_WORDS * 2) : 142;
        int rc = 0;
 
-       if (drive->id_read == 0) {
+       if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
                rc = -ENOMSG;
                goto out;
        }
@@ -86,8 +86,10 @@ out:
 
 static int ide_get_nice_ioctl(ide_drive_t *drive, unsigned long arg)
 {
-       return put_user((drive->dsc_overlap << IDE_NICE_DSC_OVERLAP) |
-                       (drive->nice1 << IDE_NICE_1), (long __user *)arg);
+       return put_user((!!(drive->dev_flags & IDE_DFLAG_DSC_OVERLAP)
+                        << IDE_NICE_DSC_OVERLAP) |
+                       (!!(drive->dev_flags & IDE_DFLAG_NICE1)
+                        << IDE_NICE_1), (long __user *)arg);
 }
 
 static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
@@ -97,11 +99,18 @@ static int ide_set_nice_ioctl(ide_drive_t *drive, unsigned long arg)
 
        if (((arg >> IDE_NICE_DSC_OVERLAP) & 1) &&
            (drive->media == ide_disk || drive->media == ide_floppy ||
-            drive->scsi))
+            (drive->dev_flags & IDE_DFLAG_SCSI)))
                return -EPERM;
 
-       drive->dsc_overlap = (arg >> IDE_NICE_DSC_OVERLAP) & 1;
-       drive->nice1 = (arg >> IDE_NICE_1) & 1;
+       if ((arg >> IDE_NICE_DSC_OVERLAP) & 1)
+               drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
+
+       if ((arg >> IDE_NICE_1) & 1)
+               drive->dev_flags |= IDE_DFLAG_NICE1;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_NICE1;
 
        return 0;
 }
index 0a2fd3b37ac4b84ecbccc1fdb41efe9da708c268..b762deb2dacb34f408ff55d0104581593f117e5d 100644 (file)
@@ -181,7 +181,7 @@ void ide_tf_load(ide_drive_t *drive, ide_task_t *task)
                tf_outb(tf->lbah, io_ports->lbah_addr);
 
        if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
-               tf_outb((tf->device & HIHI) | drive->select.all,
+               tf_outb((tf->device & HIHI) | drive->select,
                         io_ports->device_addr);
 }
 EXPORT_SYMBOL_GPL(ide_tf_load);
@@ -647,7 +647,7 @@ u8 eighty_ninty_three (ide_drive_t *drive)
                return 1;
 
 no_80w:
-       if (drive->udma33_warned == 1)
+       if (drive->dev_flags & IDE_DFLAG_UDMA33_WARNED)
                return 0;
 
        printk(KERN_WARNING "%s: %s side 80-wire cable detection failed, "
@@ -655,7 +655,7 @@ no_80w:
                            drive->name,
                            hwif->cbl == ATA_CBL_PATA80 ? "drive" : "host");
 
-       drive->udma33_warned = 1;
+       drive->dev_flags |= IDE_DFLAG_UDMA33_WARNED;
 
        return 0;
 }
@@ -711,7 +711,7 @@ int ide_driveid_update(ide_drive_t *drive)
 
        kfree(id);
 
-       if (drive->using_dma && ide_id_dma_bug(drive))
+       if ((drive->dev_flags & IDE_DFLAG_USING_DMA) && ide_id_dma_bug(drive))
                ide_dma_off(drive);
 
        return 1;
@@ -790,7 +790,7 @@ int ide_config_drive_speed(ide_drive_t *drive, u8 speed)
 
  skip:
 #ifdef CONFIG_BLK_DEV_IDEDMA
-       if (speed >= XFER_SW_DMA_0 && drive->using_dma)
+       if (speed >= XFER_SW_DMA_0 && (drive->dev_flags & IDE_DFLAG_USING_DMA))
                hwif->dma_ops->dma_host_set(drive, 1);
        else if (hwif->dma_ops) /* check if host supports DMA */
                ide_dma_off_quietly(drive);
@@ -940,6 +940,25 @@ static ide_startstop_t atapi_reset_pollfunc (ide_drive_t *drive)
        return ide_stopped;
 }
 
+static void ide_reset_report_error(ide_hwif_t *hwif, u8 err)
+{
+       static const char *err_master_vals[] =
+               { NULL, "passed", "formatter device error",
+                 "sector buffer error", "ECC circuitry error",
+                 "controlling MPU error" };
+
+       u8 err_master = err & 0x7f;
+
+       printk(KERN_ERR "%s: reset: master: ", hwif->name);
+       if (err_master && err_master < 6)
+               printk(KERN_CONT "%s", err_master_vals[err_master]);
+       else
+               printk(KERN_CONT "error (0x%02x?)", err);
+       if (err & 0x80)
+               printk(KERN_CONT "; slave: failed");
+       printk(KERN_CONT "\n");
+}
+
 /*
  * reset_pollfunc() gets invoked to poll the interface for completion every 50ms
  * during an ide reset operation. If the drives have not yet responded,
@@ -975,31 +994,14 @@ static ide_startstop_t reset_pollfunc (ide_drive_t *drive)
                drive->failures++;
                err = -EIO;
        } else  {
-               printk("%s: reset: ", hwif->name);
                tmp = ide_read_error(drive);
 
                if (tmp == 1) {
-                       printk("success\n");
+                       printk(KERN_INFO "%s: reset: success\n", hwif->name);
                        drive->failures = 0;
                } else {
+                       ide_reset_report_error(hwif, tmp);
                        drive->failures++;
-                       printk("master: ");
-                       switch (tmp & 0x7f) {
-                               case 1: printk("passed");
-                                       break;
-                               case 2: printk("formatter device error");
-                                       break;
-                               case 3: printk("sector buffer error");
-                                       break;
-                               case 4: printk("ECC circuitry error");
-                                       break;
-                               case 5: printk("controlling MPU error");
-                                       break;
-                               default:printk("error (0x%02x?)", tmp);
-                       }
-                       if (tmp & 0x80)
-                               printk("; slave: failed");
-                       printk("\n");
                        err = -EIO;
                }
        }
@@ -1016,9 +1018,14 @@ static void ide_disk_pre_reset(ide_drive_t *drive)
        drive->special.all = 0;
        drive->special.b.set_geometry = legacy;
        drive->special.b.recalibrate  = legacy;
+
        drive->mult_count = 0;
-       if (!drive->keep_settings && !drive->using_dma)
+       drive->dev_flags &= ~IDE_DFLAG_PARKED;
+
+       if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0 &&
+           (drive->dev_flags & IDE_DFLAG_USING_DMA) == 0)
                drive->mult_req = 0;
+
        if (drive->mult_req != drive->mult_count)
                drive->special.b.set_multmode = 1;
 }
@@ -1030,18 +1037,18 @@ static void pre_reset(ide_drive_t *drive)
        if (drive->media == ide_disk)
                ide_disk_pre_reset(drive);
        else
-               drive->post_reset = 1;
+               drive->dev_flags |= IDE_DFLAG_POST_RESET;
 
-       if (drive->using_dma) {
+       if (drive->dev_flags & IDE_DFLAG_USING_DMA) {
                if (drive->crc_count)
                        ide_check_dma_crc(drive);
                else
                        ide_dma_off(drive);
        }
 
-       if (!drive->keep_settings) {
-               if (!drive->using_dma) {
-                       drive->unmask = 0;
+       if ((drive->dev_flags & IDE_DFLAG_KEEP_SETTINGS) == 0) {
+               if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0) {
+                       drive->dev_flags &= ~IDE_DFLAG_UNMASK;
                        drive->io_32bit = 0;
                }
                return;
@@ -1073,12 +1080,13 @@ static void pre_reset(ide_drive_t *drive)
 static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
 {
        unsigned int unit;
-       unsigned long flags;
+       unsigned long flags, timeout;
        ide_hwif_t *hwif;
        ide_hwgroup_t *hwgroup;
        struct ide_io_ports *io_ports;
        const struct ide_tp_ops *tp_ops;
        const struct ide_port_ops *port_ops;
+       DEFINE_WAIT(wait);
 
        spin_lock_irqsave(&ide_lock, flags);
        hwif = HWIF(drive);
@@ -1105,6 +1113,31 @@ static ide_startstop_t do_reset1 (ide_drive_t *drive, int do_not_try_atapi)
                return ide_started;
        }
 
+       /* We must not disturb devices in the IDE_DFLAG_PARKED state. */
+       do {
+               unsigned long now;
+
+               prepare_to_wait(&ide_park_wq, &wait, TASK_UNINTERRUPTIBLE);
+               timeout = jiffies;
+               for (unit = 0; unit < MAX_DRIVES; unit++) {
+                       ide_drive_t *tdrive = &hwif->drives[unit];
+
+                       if (tdrive->dev_flags & IDE_DFLAG_PRESENT &&
+                           tdrive->dev_flags & IDE_DFLAG_PARKED &&
+                           time_after(tdrive->sleep, timeout))
+                               timeout = tdrive->sleep;
+               }
+
+               now = jiffies;
+               if (time_before_eq(timeout, now))
+                       break;
+
+               spin_unlock_irqrestore(&ide_lock, flags);
+               timeout = schedule_timeout_uninterruptible(timeout - now);
+               spin_lock_irqsave(&ide_lock, flags);
+       } while (timeout);
+       finish_wait(&ide_park_wq, &wait);
+
        /*
         * First, reset any device state data we were maintaining
         * for any of the drives on this interface.
index ed426dd0fdd8a6747a744a64607c030ef0b6ed1e..9fc4cfb2a272bd6b89a112e72158eb6e1d656b9e 100644 (file)
@@ -317,7 +317,7 @@ static void ide_dump_sector(ide_drive_t *drive)
 {
        ide_task_t task;
        struct ide_taskfile *tf = &task.tf;
-       int lba48 = (drive->addressing == 1) ? 1 : 0;
+       u8 lba48 = !!(drive->dev_flags & IDE_DFLAG_LBA48);
 
        memset(&task, 0, sizeof(task));
        if (lba48)
diff --git a/drivers/ide/ide-park.c b/drivers/ide/ide-park.c
new file mode 100644 (file)
index 0000000..03b00e5
--- /dev/null
@@ -0,0 +1,121 @@
+#include <linux/kernel.h>
+#include <linux/ide.h>
+#include <linux/jiffies.h>
+#include <linux/blkdev.h>
+
+DECLARE_WAIT_QUEUE_HEAD(ide_park_wq);
+
+static void issue_park_cmd(ide_drive_t *drive, unsigned long timeout)
+{
+       struct request_queue *q = drive->queue;
+       struct request *rq;
+       int rc;
+
+       timeout += jiffies;
+       spin_lock_irq(&ide_lock);
+       if (drive->dev_flags & IDE_DFLAG_PARKED) {
+               ide_hwgroup_t *hwgroup = drive->hwif->hwgroup;
+               int reset_timer;
+
+               reset_timer = time_before(timeout, drive->sleep);
+               drive->sleep = timeout;
+               wake_up_all(&ide_park_wq);
+               if (reset_timer && hwgroup->sleeping &&
+                   del_timer(&hwgroup->timer)) {
+                       hwgroup->sleeping = 0;
+                       hwgroup->busy = 0;
+                       blk_start_queueing(q);
+               }
+               spin_unlock_irq(&ide_lock);
+               return;
+       }
+       spin_unlock_irq(&ide_lock);
+
+       rq = blk_get_request(q, READ, __GFP_WAIT);
+       rq->cmd[0] = REQ_PARK_HEADS;
+       rq->cmd_len = 1;
+       rq->cmd_type = REQ_TYPE_SPECIAL;
+       rq->special = &timeout;
+       rc = blk_execute_rq(q, NULL, rq, 1);
+       blk_put_request(rq);
+       if (rc)
+               goto out;
+
+       /*
+        * Make sure that *some* command is sent to the drive after the
+        * timeout has expired, so power management will be reenabled.
+        */
+       rq = blk_get_request(q, READ, GFP_NOWAIT);
+       if (unlikely(!rq))
+               goto out;
+
+       rq->cmd[0] = REQ_UNPARK_HEADS;
+       rq->cmd_len = 1;
+       rq->cmd_type = REQ_TYPE_SPECIAL;
+       elv_add_request(q, rq, ELEVATOR_INSERT_FRONT, 1);
+
+out:
+       return;
+}
+
+ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
+                     char *buf)
+{
+       ide_drive_t *drive = to_ide_device(dev);
+       unsigned long now;
+       unsigned int msecs;
+
+       if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
+               return -EOPNOTSUPP;
+
+       spin_lock_irq(&ide_lock);
+       now = jiffies;
+       if (drive->dev_flags & IDE_DFLAG_PARKED &&
+           time_after(drive->sleep, now))
+               msecs = jiffies_to_msecs(drive->sleep - now);
+       else
+               msecs = 0;
+       spin_unlock_irq(&ide_lock);
+
+       return snprintf(buf, 20, "%u\n", msecs);
+}
+
+ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t len)
+{
+#define MAX_PARK_TIMEOUT 30000
+       ide_drive_t *drive = to_ide_device(dev);
+       long int input;
+       int rc;
+
+       rc = strict_strtol(buf, 10, &input);
+       if (rc || input < -2)
+               return -EINVAL;
+       if (input > MAX_PARK_TIMEOUT) {
+               input = MAX_PARK_TIMEOUT;
+               rc = -EOVERFLOW;
+       }
+
+       mutex_lock(&ide_setting_mtx);
+       if (input >= 0) {
+               if (drive->dev_flags & IDE_DFLAG_NO_UNLOAD)
+                       rc = -EOPNOTSUPP;
+               else if (input || drive->dev_flags & IDE_DFLAG_PARKED)
+                       issue_park_cmd(drive, msecs_to_jiffies(input));
+       } else {
+               if (drive->media == ide_disk)
+                       switch (input) {
+                       case -1:
+                               drive->dev_flags &= ~IDE_DFLAG_NO_UNLOAD;
+                               break;
+                       case -2:
+                               drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
+                               break;
+                       }
+               else
+                       rc = -EOPNOTSUPP;
+       }
+       mutex_unlock(&ide_setting_mtx);
+
+       return rc ? rc : len;
+}
index 06575a12b63518d01f2de299be39fb97f814afbe..f27baa5f140e903cff37678d6be157be55f4decd 100644 (file)
@@ -121,7 +121,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
        /* read 512 bytes of id info */
        hwif->tp_ops->input_data(drive, NULL, id, SECTOR_SIZE);
 
-       drive->id_read = 1;
+       drive->dev_flags |= IDE_DFLAG_ID_READ;
+
        local_irq_enable();
 #ifdef DEBUG
        printk(KERN_INFO "%s: dumping identify data\n", drive->name);
@@ -153,8 +154,8 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
 
        printk(KERN_INFO "%s: %s, ", drive->name, m);
 
-       drive->present = 1;
-       drive->dead = 0;
+       drive->dev_flags |= IDE_DFLAG_PRESENT;
+       drive->dev_flags &= ~IDE_DFLAG_DEAD;
 
        /*
         * Check for an ATAPI device
@@ -172,14 +173,14 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
                                                printk(KERN_CONT "cdrom or floppy?, assuming ");
                                        if (drive->media != ide_cdrom) {
                                                printk(KERN_CONT "FLOPPY");
-                                               drive->removable = 1;
+                                               drive->dev_flags |= IDE_DFLAG_REMOVABLE;
                                                break;
                                        }
                                }
                                /* Early cdrom models used zero */
                                type = ide_cdrom;
                        case ide_cdrom:
-                               drive->removable = 1;
+                               drive->dev_flags |= IDE_DFLAG_REMOVABLE;
 #ifdef CONFIG_PPC
                                /* kludge for Apple PowerBook internal zip */
                                if (!strstr(m, "CD-ROM") && strstr(m, "ZIP")) {
@@ -195,7 +196,7 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
                                break;
                        case ide_optical:
                                printk(KERN_CONT "OPTICAL");
-                               drive->removable = 1;
+                               drive->dev_flags |= IDE_DFLAG_REMOVABLE;
                                break;
                        default:
                                printk(KERN_CONT "UNKNOWN (type %d)", type);
@@ -205,6 +206,10 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
                drive->media = type;
                /* an ATAPI device ignores DRDY */
                drive->ready_stat = 0;
+               if (ata_id_cdb_intr(id))
+                       drive->atapi_flags |= IDE_AFLAG_DRQ_INTERRUPT;
+               /* we don't do head unloading on ATAPI devices */
+               drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
                return;
        }
 
@@ -216,17 +221,20 @@ static inline void do_identify (ide_drive_t *drive, u8 cmd)
 
        /* CF devices are *not* removable in Linux definition of the term */
        if (is_cfa == 0 && (id[ATA_ID_CONFIG] & (1 << 7)))
-               drive->removable = 1;
+               drive->dev_flags |= IDE_DFLAG_REMOVABLE;
 
        drive->media = ide_disk;
 
+       if (!ata_id_has_unload(drive->id))
+               drive->dev_flags |= IDE_DFLAG_NO_UNLOAD;
+
        printk(KERN_CONT "%s DISK drive\n", is_cfa ? "CFA" : "ATA");
 
        return;
 
 err_misc:
        kfree(id);
-       drive->present = 0;
+       drive->dev_flags &= ~IDE_DFLAG_PRESENT;
        return;
 }
 
@@ -426,16 +434,15 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
        ide_hwif_t *hwif = HWIF(drive);
        const struct ide_tp_ops *tp_ops = hwif->tp_ops;
        int rc;
-       u8 stat;
+       u8 present = !!(drive->dev_flags & IDE_DFLAG_PRESENT), stat;
+
+       /* avoid waiting for inappropriate probes */
+       if (present && drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
+               return 4;
 
-       if (drive->present) {
-               /* avoid waiting for inappropriate probes */
-               if (drive->media != ide_disk && cmd == ATA_CMD_ID_ATA)
-                       return 4;
-       }
 #ifdef DEBUG
        printk(KERN_INFO "probing for %s: present=%d, media=%d, probetype=%s\n",
-               drive->name, drive->present, drive->media,
+               drive->name, present, drive->media,
                (cmd == ATA_CMD_ID_ATA) ? "ATA" : "ATAPI");
 #endif
 
@@ -446,8 +453,8 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
        SELECT_DRIVE(drive);
        msleep(50);
 
-       if (ide_read_device(drive) != drive->select.all && !drive->present) {
-               if (drive->select.b.unit != 0) {
+       if (ide_read_device(drive) != drive->select && present == 0) {
+               if (drive->dn & 1) {
                        /* exit with drive0 selected */
                        SELECT_DRIVE(&hwif->drives[0]);
                        /* allow ATA_BUSY to assert & clear */
@@ -460,7 +467,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
        stat = tp_ops->read_status(hwif);
 
        if (OK_STAT(stat, ATA_DRDY, ATA_BUSY) ||
-           drive->present || cmd == ATA_CMD_ID_ATAPI) {
+           present || cmd == ATA_CMD_ID_ATAPI) {
                /* send cmd and wait */
                if ((rc = try_to_identify(drive, cmd))) {
                        /* failed: try again */
@@ -493,7 +500,7 @@ static int do_probe (ide_drive_t *drive, u8 cmd)
                /* not present or maybe ATAPI */
                rc = 3;
        }
-       if (drive->select.b.unit != 0) {
+       if (drive->dn & 1) {
                /* exit with drive0 selected */
                SELECT_DRIVE(&hwif->drives[0]);
                msleep(50);
@@ -542,8 +549,8 @@ static void enable_nest (ide_drive_t *drive)
  *     and presents things to the user as needed.
  *
  *     Returns:        0  no device was found
- *                     1  device was found (note: drive->present might
- *                        still be 0)
+ *                     1  device was found
+ *                        (note: IDE_DFLAG_PRESENT might still be not set)
  */
  
 static inline u8 probe_for_drive (ide_drive_t *drive)
@@ -559,10 +566,10 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
         *      Also note that 0 everywhere means "can't do X"
         */
  
+       drive->dev_flags &= ~IDE_DFLAG_ID_READ;
+
        drive->id = kzalloc(SECTOR_SIZE, GFP_KERNEL);
-       drive->id_read = 0;
-       if(drive->id == NULL)
-       {
+       if (drive->id == NULL) {
                printk(KERN_ERR "ide: out of memory for id data.\n");
                return 0;
        }
@@ -571,14 +578,14 @@ static inline u8 probe_for_drive (ide_drive_t *drive)
        strcpy(m, "UNKNOWN");
 
        /* skip probing? */
-       if (!drive->noprobe) {
+       if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0) {
 retry:
                /* if !(success||timed-out) */
                if (do_probe(drive, ATA_CMD_ID_ATA) >= 2)
                        /* look for ATAPI device */
                        (void)do_probe(drive, ATA_CMD_ID_ATAPI);
 
-               if (!drive->present)
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                        /* drive not found */
                        return 0;
 
@@ -588,7 +595,7 @@ retry:
                }
 
                /* identification failed? */
-               if (!drive->id_read) {
+               if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
                        if (drive->media == ide_disk) {
                                printk(KERN_INFO "%s: non-IDE drive, CHS=%d/%d/%d\n",
                                        drive->name, drive->cyl,
@@ -598,15 +605,17 @@ retry:
                        } else {
                                /* nuke it */
                                printk(KERN_WARNING "%s: Unknown device on bus refused identification. Ignoring.\n", drive->name);
-                               drive->present = 0;
+                               drive->dev_flags &= ~IDE_DFLAG_PRESENT;
                        }
                }
                /* drive was found */
        }
-       if(!drive->present)
+
+       if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                return 0;
+
        /* The drive wasn't being helpful. Add generic info only */
-       if (drive->id_read == 0) {
+       if ((drive->dev_flags & IDE_DFLAG_ID_READ) == 0) {
                generic_id(drive);
                return 1;
        }
@@ -616,7 +625,7 @@ retry:
                ide_disk_init_mult_count(drive);
        }
 
-       return drive->present;
+       return !!(drive->dev_flags & IDE_DFLAG_PRESENT);
 }
 
 static void hwif_release_dev(struct device *dev)
@@ -707,7 +716,8 @@ static int ide_port_wait_ready(ide_hwif_t *hwif)
                ide_drive_t *drive = &hwif->drives[unit];
 
                /* Ignore disks that we will not probe for later. */
-               if (!drive->noprobe || drive->present) {
+               if ((drive->dev_flags & IDE_DFLAG_NOPROBE) == 0 ||
+                   (drive->dev_flags & IDE_DFLAG_PRESENT)) {
                        SELECT_DRIVE(drive);
                        hwif->tp_ops->set_irq(hwif, 1);
                        mdelay(2);
@@ -739,7 +749,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
 {
        ide_drive_t *dev0 = &dev1->hwif->drives[0];
 
-       if ((dev1->dn & 1) == 0 || dev0->present == 0)
+       if ((dev1->dn & 1) == 0 || (dev0->dev_flags & IDE_DFLAG_PRESENT) == 0)
                return;
 
        /* If the models don't match they are not the same product */
@@ -759,7 +769,7 @@ void ide_undecoded_slave(ide_drive_t *dev1)
        /* Appears to be an IDE flash adapter with decode bugs */
        printk(KERN_WARNING "ide-probe: ignoring undecoded slave\n");
 
-       dev1->present = 0;
+       dev1->dev_flags &= ~IDE_DFLAG_PRESENT;
 }
 
 EXPORT_SYMBOL_GPL(ide_undecoded_slave);
@@ -772,7 +782,8 @@ static int ide_probe_port(ide_hwif_t *hwif)
 
        BUG_ON(hwif->present);
 
-       if (hwif->drives[0].noprobe && hwif->drives[1].noprobe)
+       if ((hwif->drives[0].dev_flags & IDE_DFLAG_NOPROBE) &&
+           (hwif->drives[1].dev_flags & IDE_DFLAG_NOPROBE))
                return -EACCES;
 
        /*
@@ -794,9 +805,9 @@ static int ide_probe_port(ide_hwif_t *hwif)
         */
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
-               drive->dn = (hwif->channel ? 2 : 0) + unit;
+
                (void) probe_for_drive(drive);
-               if (drive->present)
+               if (drive->dev_flags & IDE_DFLAG_PRESENT)
                        rc = 0;
        }
 
@@ -820,17 +831,19 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        for (unit = 0; unit < MAX_DRIVES; unit++) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (drive->present && port_ops && port_ops->quirkproc)
-                       port_ops->quirkproc(drive);
+               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
+                       if (port_ops && port_ops->quirkproc)
+                               port_ops->quirkproc(drive);
+               }
        }
 
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (drive->present) {
+               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
                        ide_set_max_pio(drive);
 
-                       drive->nice1 = 1;
+                       drive->dev_flags |= IDE_DFLAG_NICE1;
 
                        if (hwif->dma_ops)
                                ide_set_dma(drive);
@@ -840,14 +853,14 @@ static void ide_port_tune_devices(ide_hwif_t *hwif)
        for (unit = 0; unit < MAX_DRIVES; ++unit) {
                ide_drive_t *drive = &hwif->drives[unit];
 
-               if (hwif->host_flags & IDE_HFLAG_NO_IO_32BIT)
-                       drive->no_io_32bit = 1;
+               if ((hwif->host_flags & IDE_HFLAG_NO_IO_32BIT) ||
+                   drive->id[ATA_ID_DWORD_IO])
+                       drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
                else
-                       drive->no_io_32bit = drive->id[ATA_ID_DWORD_IO] ? 1 : 0;
+                       drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
        }
 }
 
-#if MAX_HWIFS > 1
 /*
  * save_match() is used to simplify logic in init_irq() below.
  *
@@ -872,7 +885,6 @@ static void save_match(ide_hwif_t *hwif, ide_hwif_t *new, ide_hwif_t **match)
        if (!m || m->irq != hwif->irq) /* don't undo a prior perfect match */
                *match = new;
 }
-#endif /* MAX_HWIFS > 1 */
 
 /*
  * init request queue
@@ -951,26 +963,33 @@ static void ide_add_drive_to_hwgroup(ide_drive_t *drive)
  * - allocate the block device queue
  * - link drive into the hwgroup
  */
-static void ide_port_setup_devices(ide_hwif_t *hwif)
+static int ide_port_setup_devices(ide_hwif_t *hwif)
 {
-       int i;
+       int i, j = 0;
 
        mutex_lock(&ide_cfg_mtx);
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
 
-               if (!drive->present)
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                        continue;
 
                if (ide_init_queue(drive)) {
                        printk(KERN_ERR "ide: failed to init %s\n",
                                        drive->name);
+                       kfree(drive->id);
+                       drive->id = NULL;
+                       drive->dev_flags &= ~IDE_DFLAG_PRESENT;
                        continue;
                }
 
+               j++;
+
                ide_add_drive_to_hwgroup(drive);
        }
        mutex_unlock(&ide_cfg_mtx);
+
+       return j;
 }
 
 static ide_hwif_t *ide_ports[MAX_HWIFS];
@@ -1029,7 +1048,7 @@ static int init_irq (ide_hwif_t *hwif)
 
        mutex_lock(&ide_cfg_mtx);
        hwif->hwgroup = NULL;
-#if MAX_HWIFS > 1
+
        /*
         * Group up with any other hwifs that share our irq(s).
         */
@@ -1054,7 +1073,7 @@ static int init_irq (ide_hwif_t *hwif)
                        }
                }
        }
-#endif /* MAX_HWIFS > 1 */
+
        /*
         * If we are still without a hwgroup, then form a new one
         */
@@ -1153,12 +1172,13 @@ static struct kobject *ata_probe(dev_t dev, int *part, void *data)
        ide_hwif_t *hwif = data;
        int unit = *part >> PARTN_BITS;
        ide_drive_t *drive = &hwif->drives[unit];
-       if (!drive->present)
+
+       if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                return NULL;
 
        if (drive->media == ide_disk)
                request_module("ide-disk");
-       if (drive->scsi)
+       if (drive->dev_flags & IDE_DFLAG_SCSI)
                request_module("ide-scsi");
        if (drive->media == ide_cdrom || drive->media == ide_optical)
                request_module("ide-cd");
@@ -1205,7 +1225,7 @@ EXPORT_SYMBOL_GPL(ide_unregister_region);
 void ide_init_disk(struct gendisk *disk, ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       unsigned int unit = (drive->select.all >> 4) & 1;
+       unsigned int unit = drive->dn & 1;
 
        disk->major = hwif->major;
        disk->first_minor = unit << PARTN_BITS;
@@ -1248,7 +1268,7 @@ static void drive_release_dev (struct device *dev)
        ide_remove_drive_from_hwgroup(drive);
        kfree(drive->id);
        drive->id = NULL;
-       drive->present = 0;
+       drive->dev_flags &= ~IDE_DFLAG_PRESENT;
        /* Messed up locking ... */
        spin_unlock_irq(&ide_lock);
        blk_cleanup_queue(drive->queue);
@@ -1327,7 +1347,7 @@ static void hwif_register_devices(ide_hwif_t *hwif)
                struct device *dev = &drive->gendev;
                int ret;
 
-               if (!drive->present)
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                        continue;
 
                snprintf(dev->bus_id, BUS_ID_SIZE, "%u.%u", hwif->index, i);
@@ -1351,12 +1371,14 @@ static void ide_port_init_devices(ide_hwif_t *hwif)
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
 
+               drive->dn = i + hwif->channel * 2;
+
                if (hwif->host_flags & IDE_HFLAG_IO_32BIT)
                        drive->io_32bit = 1;
                if (hwif->host_flags & IDE_HFLAG_UNMASK_IRQS)
-                       drive->unmask = 1;
+                       drive->dev_flags |= IDE_DFLAG_UNMASK;
                if (hwif->host_flags & IDE_HFLAG_NO_UNMASK_IRQS)
-                       drive->no_unmask = 1;
+                       drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
 
                if (port_ops && port_ops->init_dev)
                        port_ops->init_dev(drive);
@@ -1513,19 +1535,14 @@ static int ide_find_port_slot(const struct ide_port_info *d)
         * ports 0x1f0/0x170 (the ide0/ide1 defaults).
         */
        mutex_lock(&ide_cfg_mtx);
-       if (MAX_HWIFS == 1) {
-               if (ide_indexes == 0 && i == 0)
-                       idx = 1;
+       if (bootable) {
+               if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
+                       idx = ffz(ide_indexes | i);
        } else {
-               if (bootable) {
-                       if ((ide_indexes | i) != (1 << MAX_HWIFS) - 1)
-                               idx = ffz(ide_indexes | i);
-               } else {
-                       if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
-                               idx = ffz(ide_indexes | 3);
-                       else if ((ide_indexes & 3) != 3)
-                               idx = ffz(ide_indexes);
-               }
+               if ((ide_indexes | 3) != (1 << MAX_HWIFS) - 1)
+                       idx = ffz(ide_indexes | 3);
+               else if ((ide_indexes & 3) != 3)
+                       idx = ffz(ide_indexes);
        }
        if (idx >= 0)
                ide_indexes |= (1 << idx);
@@ -1541,8 +1558,7 @@ static void ide_free_port_slot(int idx)
        mutex_unlock(&ide_cfg_mtx);
 }
 
-struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
-                                   hw_regs_t **hws)
+struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
 {
        struct ide_host *host;
        int i;
@@ -1551,7 +1567,7 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
        if (host == NULL)
                return NULL;
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                ide_hwif_t *hwif;
                int idx;
 
@@ -1593,18 +1609,6 @@ struct ide_host *ide_host_alloc_all(const struct ide_port_info *d,
 
        return host;
 }
-EXPORT_SYMBOL_GPL(ide_host_alloc_all);
-
-struct ide_host *ide_host_alloc(const struct ide_port_info *d, hw_regs_t **hws)
-{
-       hw_regs_t *hws_all[MAX_HWIFS];
-       int i;
-
-       for (i = 0; i < MAX_HWIFS; i++)
-               hws_all[i] = (i < 4) ? hws[i] : NULL;
-
-       return ide_host_alloc_all(d, hws_all);
-}
 EXPORT_SYMBOL_GPL(ide_host_alloc);
 
 int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
@@ -1613,7 +1617,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
        ide_hwif_t *hwif, *mate = NULL;
        int i, j = 0;
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL) {
@@ -1626,22 +1630,22 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
 
                if (d == NULL) {
                        mate = NULL;
-                       continue;
-               }
+               } else {
+                       if ((i & 1) && mate) {
+                               hwif->mate = mate;
+                               mate->mate = hwif;
+                       }
 
-               if ((i & 1) && mate) {
-                       hwif->mate = mate;
-                       mate->mate = hwif;
-               }
+                       mate = (i & 1) ? NULL : hwif;
 
-               mate = (i & 1) ? NULL : hwif;
+                       ide_init_port(hwif, i & 1, d);
+                       ide_port_cable_detect(hwif);
+               }
 
-               ide_init_port(hwif, i & 1, d);
-               ide_port_cable_detect(hwif);
                ide_port_init_devices(hwif);
        }
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL)
@@ -1658,7 +1662,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
                        ide_port_tune_devices(hwif);
        }
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL)
@@ -1671,10 +1675,13 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
                        continue;
                }
 
-               j++;
-
                if (hwif->present)
-                       ide_port_setup_devices(hwif);
+                       if (ide_port_setup_devices(hwif) == 0) {
+                               hwif->present = 0;
+                               continue;
+                       }
+
+               j++;
 
                ide_acpi_init(hwif);
 
@@ -1682,7 +1689,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
                        ide_acpi_port_init_devices(hwif);
        }
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL)
@@ -1695,7 +1702,7 @@ int ide_host_register(struct ide_host *host, const struct ide_port_info *d,
                        hwif_register_devices(hwif);
        }
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL)
@@ -1740,7 +1747,7 @@ void ide_host_free(struct ide_host *host)
        ide_hwif_t *hwif;
        int i;
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                hwif = host->ports[i];
 
                if (hwif == NULL)
@@ -1758,7 +1765,7 @@ void ide_host_remove(struct ide_host *host)
 {
        int i;
 
-       for (i = 0; i < MAX_HWIFS; i++) {
+       for (i = 0; i < MAX_HOST_PORTS; i++) {
                if (host->ports[i])
                        ide_unregister(host->ports[i]);
        }
index e7030a491463e126755784f9993db43083543aae..b26926487cc03f907e8e1798cdf6f0323027391e 100644 (file)
@@ -227,7 +227,7 @@ static int set_xfer_rate (ide_drive_t *drive, int arg)
 
 ide_devset_rw(current_speed, xfer_rate);
 ide_devset_rw_field(init_speed, init_speed);
-ide_devset_rw_field(nice1, nice1);
+ide_devset_rw_flag(nice1, IDE_DFLAG_NICE1);
 ide_devset_rw_field(number, dn);
 
 static const struct ide_proc_devset ide_generic_settings[] = {
@@ -622,9 +622,7 @@ void ide_proc_port_register_devices(ide_hwif_t *hwif)
        for (d = 0; d < MAX_DRIVES; d++) {
                ide_drive_t *drive = &hwif->drives[d];
 
-               if (!drive->present)
-                       continue;
-               if (drive->proc)
+               if ((drive->dev_flags & IDE_DFLAG_PRESENT) == 0 || drive->proc)
                        continue;
 
                drive->proc = proc_mkdir(drive->name, parent);
index f8c84df4a0bcf5e743cc2b341973488786602f29..25ac60f532730a0d19edfdf923f660f7c8b4e0dc 100644 (file)
@@ -172,23 +172,16 @@ typedef struct ide_tape_obj {
        struct kref     kref;
 
        /*
-        *      pc points to the current processed packet command.
-        *
         *      failed_pc points to the last failed packet command, or contains
         *      NULL if we do not need to retry any packet command. This is
         *      required since an additional packet command is needed before the
         *      retry, to get detailed information on what went wrong.
         */
-       /* Current packet command */
-       struct ide_atapi_pc *pc;
        /* Last failed packet command */
        struct ide_atapi_pc *failed_pc;
        /* used by REQ_IDETAPE_{READ,WRITE} requests */
        struct ide_atapi_pc queued_pc;
 
-       struct ide_atapi_pc request_sense_pc;
-       struct request request_sense_rq;
-
        /*
         * DSC polling variables.
         *
@@ -274,11 +267,6 @@ static DEFINE_MUTEX(idetape_ref_mutex);
 
 static struct class *idetape_sysfs_class;
 
-#define to_ide_tape(obj) container_of(obj, struct ide_tape_obj, kref)
-
-#define ide_tape_g(disk) \
-       container_of((disk)->private_data, struct ide_tape_obj, driver)
-
 static void ide_tape_release(struct kref *);
 
 static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
@@ -286,7 +274,7 @@ static struct ide_tape_obj *ide_tape_get(struct gendisk *disk)
        struct ide_tape_obj *tape = NULL;
 
        mutex_lock(&idetape_ref_mutex);
-       tape = ide_tape_g(disk);
+       tape = ide_drv_g(disk, ide_tape_obj);
        if (tape) {
                if (ide_device_get(tape->drive))
                        tape = NULL;
@@ -313,8 +301,6 @@ static void ide_tape_put(struct ide_tape_obj *tape)
  */
 static struct ide_tape_obj *idetape_devs[MAX_HWIFS * MAX_DRIVES];
 
-#define ide_tape_f(file) ((file)->private_data)
-
 static struct ide_tape_obj *ide_tape_chrdev_get(unsigned int i)
 {
        struct ide_tape_obj *tape = NULL;
@@ -522,14 +508,19 @@ static int idetape_end_request(ide_drive_t *drive, int uptodate, int nr_sects)
        return 0;
 }
 
-static void ide_tape_callback(ide_drive_t *drive)
+static void ide_tape_handle_dsc(ide_drive_t *);
+
+static void ide_tape_callback(ide_drive_t *drive, int dsc)
 {
        idetape_tape_t *tape = drive->driver_data;
-       struct ide_atapi_pc *pc = tape->pc;
+       struct ide_atapi_pc *pc = drive->pc;
        int uptodate = pc->error ? 0 : 1;
 
        debug_log(DBG_PROCS, "Enter %s\n", __func__);
 
+       if (dsc)
+               ide_tape_handle_dsc(drive);
+
        if (tape->failed_pc == pc)
                tape->failed_pc = NULL;
 
@@ -558,7 +549,7 @@ static void ide_tape_callback(ide_drive_t *drive)
                if (pc->error)
                        uptodate = pc->error;
        } else if (pc->c[0] == READ_POSITION && uptodate) {
-               u8 *readpos = tape->pc->buf;
+               u8 *readpos = pc->buf;
 
                debug_log(DBG_SENSE, "BOP - %s\n",
                                (readpos[0] & 0x80) ? "Yes" : "No");
@@ -583,31 +574,6 @@ static void ide_tape_callback(ide_drive_t *drive)
        idetape_end_request(drive, uptodate, 0);
 }
 
-static void idetape_create_request_sense_cmd(struct ide_atapi_pc *pc)
-{
-       ide_init_pc(pc);
-       pc->c[0] = REQUEST_SENSE;
-       pc->c[4] = 20;
-       pc->req_xfer = 20;
-}
-
-/*
- *     idetape_retry_pc is called when an error was detected during the
- *     last packet command. We queue a request sense packet command in
- *     the head of the request list.
- */
-static void idetape_retry_pc(ide_drive_t *drive)
-{
-       struct ide_tape_obj *tape = drive->driver_data;
-       struct request *rq = &tape->request_sense_rq;
-       struct ide_atapi_pc *pc = &tape->request_sense_pc;
-
-       (void)ide_read_error(drive);
-       idetape_create_request_sense_cmd(pc);
-       set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
-       ide_queue_pc_head(drive, tape->disk, pc, rq);
-}
-
 /*
  * Postpone the current request so that ide.c will be able to service requests
  * from another device on the same hwgroup while we are polling for DSC.
@@ -645,35 +611,19 @@ static int ide_tape_io_buffers(ide_drive_t *drive, struct ide_atapi_pc *pc,
        return bcount;
 }
 
-/*
- * This is the usual interrupt handler which will be called during a packet
- * command. We will transfer some of the data (as requested by the drive) and
- * will re-point interrupt handler to us. When data transfer is finished, we
- * will act according to the algorithm described before
- * idetape_issue_pc.
- */
-static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-
-       return ide_pc_intr(drive, tape->pc, idetape_pc_intr, WAIT_TAPE_CMD,
-                          NULL, idetape_update_buffers, idetape_retry_pc,
-                          ide_tape_handle_dsc, ide_tape_io_buffers);
-}
-
 /*
  * Packet Command Interface
  *
- * The current Packet Command is available in tape->pc, and will not change
+ * The current Packet Command is available in drive->pc, and will not change
  * until we finish handling it. Each packet command is associated with a
  * callback function that will be called when the command is finished.
  *
  * The handling will be done in three stages:
  *
  * 1. idetape_issue_pc will send the packet command to the drive, and will set
- * the interrupt handler to idetape_pc_intr.
+ * the interrupt handler to ide_pc_intr.
  *
- * 2. On each interrupt, idetape_pc_intr will be called. This step will be
+ * 2. On each interrupt, ide_pc_intr will be called. This step will be
  * repeated until the device signals us that no more interrupts will be issued.
  *
  * 3. ATAPI Tape media access commands have immediate status with a delayed
@@ -697,20 +647,13 @@ static ide_startstop_t idetape_pc_intr(ide_drive_t *drive)
  * again, the callback function will be called and then we will handle the next
  * request.
  */
-static ide_startstop_t idetape_transfer_pc(ide_drive_t *drive)
-{
-       idetape_tape_t *tape = drive->driver_data;
-
-       return ide_transfer_pc(drive, tape->pc, idetape_pc_intr,
-                              WAIT_TAPE_CMD, NULL);
-}
 
 static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
        idetape_tape_t *tape = drive->driver_data;
 
-       if (tape->pc->c[0] == REQUEST_SENSE &&
+       if (drive->pc->c[0] == REQUEST_SENSE &&
            pc->c[0] == REQUEST_SENSE) {
                printk(KERN_ERR "ide-tape: possible ide-tape.c bug - "
                        "Two request sense in serial were issued\n");
@@ -718,8 +661,9 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
 
        if (tape->failed_pc == NULL && pc->c[0] != REQUEST_SENSE)
                tape->failed_pc = pc;
+
        /* Set the current packet command */
-       tape->pc = pc;
+       drive->pc = pc;
 
        if (pc->retries > IDETAPE_MAX_PC_RETRIES ||
                (pc->flags & PC_FLAG_ABORT)) {
@@ -743,15 +687,14 @@ static ide_startstop_t idetape_issue_pc(ide_drive_t *drive,
                        pc->error = IDETAPE_ERROR_GENERAL;
                }
                tape->failed_pc = NULL;
-               drive->pc_callback(drive);
+               drive->pc_callback(drive, 0);
                return ide_stopped;
        }
        debug_log(DBG_SENSE, "Retry #%d, cmd = %02X\n", pc->retries, pc->c[0]);
 
        pc->retries++;
 
-       return ide_issue_pc(drive, pc, idetape_transfer_pc,
-                           WAIT_TAPE_CMD, NULL);
+       return ide_issue_pc(drive, WAIT_TAPE_CMD, NULL);
 }
 
 /* A mode sense command is used to "sense" tape parameters. */
@@ -785,7 +728,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        idetape_tape_t *tape = drive->driver_data;
-       struct ide_atapi_pc *pc = tape->pc;
+       struct ide_atapi_pc *pc = drive->pc;
        u8 stat;
 
        stat = hwif->tp_ops->read_status(hwif);
@@ -797,7 +740,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
                                printk(KERN_ERR "ide-tape: %s: I/O error, ",
                                                tape->name);
                        /* Retry operation */
-                       idetape_retry_pc(drive);
+                       ide_retry_pc(drive, tape->disk);
                        return ide_stopped;
                }
                pc->error = 0;
@@ -805,7 +748,7 @@ static ide_startstop_t idetape_media_access_finished(ide_drive_t *drive)
                pc->error = IDETAPE_ERROR_GENERAL;
                tape->failed_pc = NULL;
        }
-       drive->pc_callback(drive);
+       drive->pc_callback(drive, 0);
        return ide_stopped;
 }
 
@@ -862,7 +805,7 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
        }
 
        /* Retry a failed packet command */
-       if (tape->failed_pc && tape->pc->c[0] == REQUEST_SENSE) {
+       if (tape->failed_pc && drive->pc->c[0] == REQUEST_SENSE) {
                pc = tape->failed_pc;
                goto out;
        }
@@ -883,12 +826,13 @@ static ide_startstop_t idetape_do_request(ide_drive_t *drive,
         */
        stat = hwif->tp_ops->read_status(hwif);
 
-       if (!drive->dsc_overlap && !(rq->cmd[13] & REQ_IDETAPE_PC2))
+       if ((drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) == 0 &&
+           (rq->cmd[13] & REQ_IDETAPE_PC2) == 0)
                set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
 
-       if (drive->post_reset == 1) {
+       if (drive->dev_flags & IDE_DFLAG_POST_RESET) {
                set_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags);
-               drive->post_reset = 0;
+               drive->dev_flags &= ~IDE_DFLAG_POST_RESET;
        }
 
        if (!test_and_clear_bit(IDE_AFLAG_IGNORE_DSC, &drive->atapi_flags) &&
@@ -1411,7 +1355,7 @@ static int idetape_init_read(ide_drive_t *drive)
                 * No point in issuing this if DSC overlap isn't supported, some
                 * drives (Seagate STT3401A) will return an error.
                 */
-               if (drive->dsc_overlap) {
+               if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
                        bytes_read = idetape_queue_rw_tail(drive,
                                                        REQ_IDETAPE_READ, 0,
                                                        tape->merge_bh);
@@ -1592,7 +1536,7 @@ static int idetape_space_over_filemarks(ide_drive_t *drive, short mt_op,
 static ssize_t idetape_chrdev_read(struct file *file, char __user *buf,
                                   size_t count, loff_t *ppos)
 {
-       struct ide_tape_obj *tape = ide_tape_f(file);
+       struct ide_tape_obj *tape = file->private_data;
        ide_drive_t *drive = tape->drive;
        ssize_t bytes_read, temp, actually_read = 0, rc;
        ssize_t ret = 0;
@@ -1654,7 +1598,7 @@ finish:
 static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
                                     size_t count, loff_t *ppos)
 {
-       struct ide_tape_obj *tape = ide_tape_f(file);
+       struct ide_tape_obj *tape = file->private_data;
        ide_drive_t *drive = tape->drive;
        ssize_t actually_written = 0;
        ssize_t ret = 0;
@@ -1687,7 +1631,7 @@ static ssize_t idetape_chrdev_write(struct file *file, const char __user *buf,
                 * point in issuing this if DSC overlap isn't supported, some
                 * drives (Seagate STT3401A) will return an error.
                 */
-               if (drive->dsc_overlap) {
+               if (drive->dev_flags & IDE_DFLAG_DSC_OVERLAP) {
                        ssize_t retval = idetape_queue_rw_tail(drive,
                                                        REQ_IDETAPE_WRITE, 0,
                                                        tape->merge_bh);
@@ -1886,7 +1830,7 @@ static int idetape_mtioctop(ide_drive_t *drive, short mt_op, int mt_count)
 static int idetape_chrdev_ioctl(struct inode *inode, struct file *file,
                                unsigned int cmd, unsigned long arg)
 {
-       struct ide_tape_obj *tape = ide_tape_f(file);
+       struct ide_tape_obj *tape = file->private_data;
        ide_drive_t *drive = tape->drive;
        struct mtop mtop;
        struct mtget mtget;
@@ -2063,7 +2007,7 @@ static void idetape_write_release(ide_drive_t *drive, unsigned int minor)
 
 static int idetape_chrdev_release(struct inode *inode, struct file *filp)
 {
-       struct ide_tape_obj *tape = ide_tape_f(filp);
+       struct ide_tape_obj *tape = filp->private_data;
        ide_drive_t *drive = tape->drive;
        unsigned int minor = iminor(inode);
 
@@ -2202,7 +2146,7 @@ static int divf_tdsc(ide_drive_t *drive)  { return   HZ; }
 static int divf_buffer(ide_drive_t *drive)     { return    2; }
 static int divf_buffer_size(ide_drive_t *drive)        { return 1024; }
 
-ide_devset_rw_field(dsc_overlap, dsc_overlap);
+ide_devset_rw_flag(dsc_overlap, IDE_DFLAG_DSC_OVERLAP);
 
 ide_tape_devset_rw_field(debug_mask, debug_mask);
 ide_tape_devset_rw_field(tdsc, best_dsc_rw_freq);
@@ -2241,33 +2185,32 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
        unsigned long t;
        int speed;
        int buffer_size;
-       u8 gcw[2];
        u16 *ctl = (u16 *)&tape->caps[12];
 
-       drive->pc_callback = ide_tape_callback;
+       drive->pc_callback       = ide_tape_callback;
+       drive->pc_update_buffers = idetape_update_buffers;
+       drive->pc_io_buffers     = ide_tape_io_buffers;
 
        spin_lock_init(&tape->lock);
-       drive->dsc_overlap = 1;
+
+       drive->dev_flags |= IDE_DFLAG_DSC_OVERLAP;
+
        if (drive->hwif->host_flags & IDE_HFLAG_NO_DSC) {
                printk(KERN_INFO "ide-tape: %s: disabling DSC overlap\n",
                                 tape->name);
-               drive->dsc_overlap = 0;
+               drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
        }
+
        /* Seagate Travan drives do not support DSC overlap. */
        if (strstr((char *)&drive->id[ATA_ID_PROD], "Seagate STT3401"))
-               drive->dsc_overlap = 0;
+               drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
+
        tape->minor = minor;
        tape->name[0] = 'h';
        tape->name[1] = 't';
        tape->name[2] = '0' + minor;
        tape->chrdev_dir = IDETAPE_DIR_NONE;
 
-       *((u16 *)&gcw) = drive->id[ATA_ID_CONFIG];
-
-       /* Command packet DRQ type */
-       if (((gcw[0] & 0x60) >> 5) == 1)
-               set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
-
        idetape_get_inquiry_results(drive);
        idetape_get_mode_sense_results(drive);
        ide_tape_get_bsize_from_bdesc(drive);
@@ -2302,7 +2245,7 @@ static void idetape_setup(ide_drive_t *drive, idetape_tape_t *tape, int minor)
                (*(u16 *)&tape->caps[16] * 512) / tape->buffer_size,
                tape->buffer_size / 1024,
                tape->best_dsc_rw_freq * 1000 / HZ,
-               drive->using_dma ? ", DMA":"");
+               (drive->dev_flags & IDE_DFLAG_USING_DMA) ? ", DMA" : "");
 
        ide_proc_register_driver(drive, tape->driver);
 }
@@ -2320,13 +2263,13 @@ static void ide_tape_remove(ide_drive_t *drive)
 
 static void ide_tape_release(struct kref *kref)
 {
-       struct ide_tape_obj *tape = to_ide_tape(kref);
+       struct ide_tape_obj *tape = to_ide_drv(kref, ide_tape_obj);
        ide_drive_t *drive = tape->drive;
        struct gendisk *g = tape->disk;
 
        BUG_ON(tape->merge_bh_size);
 
-       drive->dsc_overlap = 0;
+       drive->dev_flags &= ~IDE_DFLAG_DSC_OVERLAP;
        drive->driver_data = NULL;
        device_destroy(idetape_sysfs_class, MKDEV(IDETAPE_MAJOR, tape->minor));
        device_destroy(idetape_sysfs_class,
@@ -2368,7 +2311,6 @@ static ide_driver_t idetape_driver = {
        .probe                  = ide_tape_probe,
        .remove                 = ide_tape_remove,
        .version                = IDETAPE_VERSION,
-       .media                  = ide_tape,
        .do_request             = idetape_do_request,
        .end_request            = idetape_end_request,
        .error                  = __ide_error,
@@ -2403,7 +2345,7 @@ static int idetape_open(struct inode *inode, struct file *filp)
 static int idetape_release(struct inode *inode, struct file *filp)
 {
        struct gendisk *disk = inode->i_bdev->bd_disk;
-       struct ide_tape_obj *tape = ide_tape_g(disk);
+       struct ide_tape_obj *tape = ide_drv_g(disk, ide_tape_obj);
 
        ide_tape_put(tape);
 
@@ -2414,7 +2356,7 @@ static int idetape_ioctl(struct inode *inode, struct file *file,
                        unsigned int cmd, unsigned long arg)
 {
        struct block_device *bdev = inode->i_bdev;
-       struct ide_tape_obj *tape = ide_tape_g(bdev->bd_disk);
+       struct ide_tape_obj *tape = ide_drv_g(bdev->bd_disk, ide_tape_obj);
        ide_drive_t *drive = tape->drive;
        int err = generic_ide_ioctl(drive, file, bdev, cmd, arg);
        if (err == -EINVAL)
@@ -2441,7 +2383,8 @@ static int ide_tape_probe(ide_drive_t *drive)
        if (drive->media != ide_tape)
                goto failed;
 
-       if (drive->id_read == 1 && !ide_check_atapi_device(drive, DRV_NAME)) {
+       if ((drive->dev_flags & IDE_DFLAG_ID_READ) &&
+           ide_check_atapi_device(drive, DRV_NAME) == 0) {
                printk(KERN_ERR "ide-tape: %s: not supported by this version of"
                                " the driver\n", drive->name);
                goto failed;
index 487b18b3ebae9036d2f794291eb5026f3c59ae0a..bf4fb9d8d176f2f91efa7a91a06d229f80f4d502 100644 (file)
@@ -53,9 +53,6 @@ int taskfile_lib_get_identify (ide_drive_t *drive, u8 *buf)
 }
 
 static ide_startstop_t task_no_data_intr(ide_drive_t *);
-static ide_startstop_t set_geometry_intr(ide_drive_t *);
-static ide_startstop_t recal_intr(ide_drive_t *);
-static ide_startstop_t set_multmode_intr(ide_drive_t *);
 static ide_startstop_t pre_task_out_intr(ide_drive_t *, struct request *);
 static ide_startstop_t task_in_intr(ide_drive_t *);
 
@@ -79,6 +76,8 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
        if (task->tf_flags & IDE_TFLAG_FLAGGED)
                task->tf_flags |= IDE_TFLAG_FLAGGED_SET_IN_FLAGS;
 
+       memcpy(&hwif->task, task, sizeof(*task));
+
        if ((task->tf_flags & IDE_TFLAG_DMA_PIO_FALLBACK) == 0) {
                ide_tf_dump(drive->name, tf);
                tp_ops->set_irq(hwif, 1);
@@ -99,24 +98,12 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
        case TASKFILE_NO_DATA:
                if (handler == NULL)
                        handler = task_no_data_intr;
-               if (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) {
-                       switch (tf->command) {
-                       case ATA_CMD_INIT_DEV_PARAMS:
-                               handler = set_geometry_intr;
-                               break;
-                       case ATA_CMD_RESTORE:
-                               handler = recal_intr;
-                               break;
-                       case ATA_CMD_SET_MULTI:
-                               handler = set_multmode_intr;
-                               break;
-                       }
-               }
                ide_execute_command(drive, tf->command, handler,
                                    WAIT_WORSTCASE, NULL);
                return ide_started;
        default:
-               if (drive->using_dma == 0 || dma_ops->dma_setup(drive))
+               if ((drive->dev_flags & IDE_DFLAG_USING_DMA) == 0 ||
+                   dma_ops->dma_setup(drive))
                        return ide_stopped;
                dma_ops->dma_exec_cmd(drive, tf->command);
                dma_ops->dma_start(drive);
@@ -126,33 +113,15 @@ ide_startstop_t do_rw_taskfile (ide_drive_t *drive, ide_task_t *task)
 EXPORT_SYMBOL_GPL(do_rw_taskfile);
 
 /*
- * set_multmode_intr() is invoked on completion of a ATA_CMD_SET_MULTI cmd.
- */
-static ide_startstop_t set_multmode_intr(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       u8 stat;
-
-       local_irq_enable_in_hardirq();
-       stat = hwif->tp_ops->read_status(hwif);
-
-       if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
-               drive->mult_count = drive->mult_req;
-       else {
-               drive->mult_req = drive->mult_count = 0;
-               drive->special.b.recalibrate = 1;
-               (void) ide_dump_status(drive, "set_multmode", stat);
-       }
-       return ide_stopped;
-}
-
-/*
- * set_geometry_intr() is invoked on completion of a ATA_CMD_INIT_DEV_PARAMS cmd.
+ * Handler for commands without a data phase
  */
-static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
+static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       int retries = 5;
+       ide_task_t *task = &hwif->task;
+       struct ide_taskfile *tf = &task->tf;
+       int custom = (task->tf_flags & IDE_TFLAG_CUSTOM_HANDLER) ? 1 : 0;
+       int retries = (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) ? 5 : 1;
        u8 stat;
 
        local_irq_enable_in_hardirq();
@@ -164,50 +133,36 @@ static ide_startstop_t set_geometry_intr(ide_drive_t *drive)
                udelay(10);
        };
 
-       if (OK_STAT(stat, ATA_DRDY, BAD_STAT))
-               return ide_stopped;
-
-       if (stat & (ATA_ERR | ATA_DRQ))
-               return ide_error(drive, "set_geometry_intr", stat);
-
-       ide_set_handler(drive, &set_geometry_intr, WAIT_WORSTCASE, NULL);
-       return ide_started;
-}
-
-/*
- * recal_intr() is invoked on completion of a ATA_CMD_RESTORE (recalibrate) cmd.
- */
-static ide_startstop_t recal_intr(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       u8 stat;
-
-       local_irq_enable_in_hardirq();
-       stat = hwif->tp_ops->read_status(hwif);
-
-       if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
-               return ide_error(drive, "recal_intr", stat);
-       return ide_stopped;
-}
-
-/*
- * Handler for commands without a data phase
- */
-static ide_startstop_t task_no_data_intr(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-       ide_task_t *args = hwif->hwgroup->rq->special;
-       u8 stat;
-
-       local_irq_enable_in_hardirq();
-       stat = hwif->tp_ops->read_status(hwif);
-
-       if (!OK_STAT(stat, ATA_DRDY, BAD_STAT))
+       if (!OK_STAT(stat, ATA_DRDY, BAD_STAT)) {
+               if (custom && tf->command == ATA_CMD_SET_MULTI) {
+                       drive->mult_req = drive->mult_count = 0;
+                       drive->special.b.recalibrate = 1;
+                       (void)ide_dump_status(drive, __func__, stat);
+                       return ide_stopped;
+               } else if (custom && tf->command == ATA_CMD_INIT_DEV_PARAMS) {
+                       if ((stat & (ATA_ERR | ATA_DRQ)) == 0) {
+                               ide_set_handler(drive, &task_no_data_intr,
+                                               WAIT_WORSTCASE, NULL);
+                               return ide_started;
+                       }
+               }
                return ide_error(drive, "task_no_data_intr", stat);
                /* calls ide_end_drive_cmd */
+       }
 
-       if (args)
+       if (!custom)
+               ide_end_drive_cmd(drive, stat, ide_read_error(drive));
+       else if (tf->command == ATA_CMD_IDLEIMMEDIATE) {
+               hwif->tp_ops->tf_read(drive, task);
+               if (tf->lbal != 0xc4) {
+                       printk(KERN_ERR "%s: head unload failed!\n",
+                              drive->name);
+                       ide_tf_dump(drive->name, tf);
+               } else
+                       drive->dev_flags |= IDE_DFLAG_PARKED;
                ide_end_drive_cmd(drive, stat, ide_read_error(drive));
+       } else if (tf->command == ATA_CMD_SET_MULTI)
+               drive->mult_count = drive->mult_req;
 
        return ide_stopped;
 }
@@ -469,13 +424,12 @@ static ide_startstop_t pre_task_out_intr(ide_drive_t *drive, struct request *rq)
        if (ide_wait_stat(&startstop, drive, ATA_DRQ,
                          drive->bad_wstat, WAIT_DRQ)) {
                printk(KERN_ERR "%s: no DRQ after issuing %sWRITE%s\n",
-                               drive->name,
-                               drive->hwif->data_phase ? "MULT" : "",
-                               drive->addressing ? "_EXT" : "");
+                       drive->name, drive->hwif->data_phase ? "MULT" : "",
+                       (drive->dev_flags & IDE_DFLAG_LBA48) ? "_EXT" : "");
                return startstop;
        }
 
-       if (!drive->unmask)
+       if ((drive->dev_flags & IDE_DFLAG_UNMASK) == 0)
                local_irq_disable();
 
        ide_set_handler(drive, &task_out_intr, WAIT_WORSTCASE, NULL);
@@ -591,7 +545,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
 
        args.tf_flags = IDE_TFLAG_IO_16BIT | IDE_TFLAG_DEVICE |
                        IDE_TFLAG_IN_TF;
-       if (drive->addressing == 1)
+       if (drive->dev_flags & IDE_DFLAG_LBA48)
                args.tf_flags |= (IDE_TFLAG_LBA48 | IDE_TFLAG_IN_HOB);
 
        if (req_task->out_flags.all) {
@@ -694,7 +648,7 @@ int ide_taskfile_ioctl (ide_drive_t *drive, unsigned int cmd, unsigned long arg)
        if ((args.tf_flags & IDE_TFLAG_FLAGGED_SET_IN_FLAGS) &&
            req_task->in_flags.all == 0) {
                req_task->in_flags.all = IDE_TASKFILE_STD_IN_FLAGS;
-               if (drive->addressing == 1)
+               if (drive->dev_flags & IDE_DFLAG_LBA48)
                        req_task->in_flags.all |= (IDE_HOB_STD_IN_FLAGS << 8);
        }
 
index 9dcf5aed92cbcd1f1bf390cef2678ef7f6d1afa2..04f8f13cb9d74d697f65f3c37bb03117b3bc0057 100644 (file)
@@ -114,7 +114,7 @@ static void ide_port_init_devices_data(ide_hwif_t *hwif)
                memset(drive, 0, sizeof(*drive));
 
                drive->media                    = ide_disk;
-               drive->select.all               = (unit<<4)|0xa0;
+               drive->select                   = (unit << 4) | ATA_DEVICE_OBS;
                drive->hwif                     = hwif;
                drive->ready_stat               = ATA_DRDY;
                drive->bad_wstat                = BAD_W_STAT;
@@ -138,7 +138,7 @@ static void __ide_port_unregister_devices(ide_hwif_t *hwif)
        for (i = 0; i < MAX_DRIVES; i++) {
                ide_drive_t *drive = &hwif->drives[i];
 
-               if (drive->present) {
+               if (drive->dev_flags & IDE_DFLAG_PRESENT) {
                        spin_unlock_irq(&ide_lock);
                        device_unregister(&drive->gendev);
                        wait_for_completion(&drive->gendev_rel_comp);
@@ -227,8 +227,7 @@ void ide_unregister(ide_hwif_t *hwif)
        kfree(hwif->sg_table);
        unregister_blkdev(hwif->major, hwif->name);
 
-       if (hwif->dma_base)
-               ide_release_dma_engine(hwif);
+       ide_release_dma_engine(hwif);
 
        mutex_unlock(&ide_cfg_mtx);
 }
@@ -254,7 +253,7 @@ ide_devset_get(io_32bit, io_32bit);
 
 static int set_io_32bit(ide_drive_t *drive, int arg)
 {
-       if (drive->no_io_32bit)
+       if (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT)
                return -EPERM;
 
        if (arg < 0 || arg > 1 + (SUPPORT_VLB_SYNC << 1))
@@ -265,19 +264,22 @@ static int set_io_32bit(ide_drive_t *drive, int arg)
        return 0;
 }
 
-ide_devset_get(ksettings, keep_settings);
+ide_devset_get_flag(ksettings, IDE_DFLAG_KEEP_SETTINGS);
 
 static int set_ksettings(ide_drive_t *drive, int arg)
 {
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       drive->keep_settings = arg;
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_KEEP_SETTINGS;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_KEEP_SETTINGS;
 
        return 0;
 }
 
-ide_devset_get(using_dma, using_dma);
+ide_devset_get_flag(using_dma, IDE_DFLAG_USING_DMA);
 
 static int set_using_dma(ide_drive_t *drive, int arg)
 {
@@ -311,9 +313,32 @@ out:
 #endif
 }
 
+/*
+ * handle HDIO_SET_PIO_MODE ioctl abusers here, eventually it will go away
+ */
+static int set_pio_mode_abuse(ide_hwif_t *hwif, u8 req_pio)
+{
+       switch (req_pio) {
+       case 202:
+       case 201:
+       case 200:
+       case 102:
+       case 101:
+       case 100:
+               return (hwif->host_flags & IDE_HFLAG_ABUSE_DMA_MODES) ? 1 : 0;
+       case 9:
+       case 8:
+               return (hwif->host_flags & IDE_HFLAG_ABUSE_PREFETCH) ? 1 : 0;
+       case 7:
+       case 6:
+               return (hwif->host_flags & IDE_HFLAG_ABUSE_FAST_DEVSEL) ? 1 : 0;
+       default:
+               return 0;
+       }
+}
+
 static int set_pio_mode(ide_drive_t *drive, int arg)
 {
-       struct request *rq;
        ide_hwif_t *hwif = drive->hwif;
        const struct ide_port_ops *port_ops = hwif->port_ops;
 
@@ -324,56 +349,65 @@ static int set_pio_mode(ide_drive_t *drive, int arg)
            (hwif->host_flags & IDE_HFLAG_NO_SET_MODE))
                return -ENOSYS;
 
-       if (drive->special.b.set_tune)
-               return -EBUSY;
+       if (set_pio_mode_abuse(drive->hwif, arg)) {
+               if (arg == 8 || arg == 9) {
+                       unsigned long flags;
 
-       rq = blk_get_request(drive->queue, READ, __GFP_WAIT);
-       rq->cmd_type = REQ_TYPE_ATA_TASKFILE;
+                       /* take lock for IDE_DFLAG_[NO_]UNMASK/[NO_]IO_32BIT */
+                       spin_lock_irqsave(&ide_lock, flags);
+                       port_ops->set_pio_mode(drive, arg);
+                       spin_unlock_irqrestore(&ide_lock, flags);
+               } else
+                       port_ops->set_pio_mode(drive, arg);
+       } else {
+               int keep_dma = !!(drive->dev_flags & IDE_DFLAG_USING_DMA);
 
-       drive->tune_req = (u8) arg;
-       drive->special.b.set_tune = 1;
+               ide_set_pio(drive, arg);
 
-       blk_execute_rq(drive->queue, NULL, rq, 0);
-       blk_put_request(rq);
+               if (hwif->host_flags & IDE_HFLAG_SET_PIO_MODE_KEEP_DMA) {
+                       if (keep_dma)
+                               ide_dma_on(drive);
+               }
+       }
 
        return 0;
 }
 
-ide_devset_get(unmaskirq, unmask);
+ide_devset_get_flag(unmaskirq, IDE_DFLAG_UNMASK);
 
 static int set_unmaskirq(ide_drive_t *drive, int arg)
 {
-       if (drive->no_unmask)
+       if (drive->dev_flags & IDE_DFLAG_NO_UNMASK)
                return -EPERM;
 
        if (arg < 0 || arg > 1)
                return -EINVAL;
 
-       drive->unmask = arg;
+       if (arg)
+               drive->dev_flags |= IDE_DFLAG_UNMASK;
+       else
+               drive->dev_flags &= ~IDE_DFLAG_UNMASK;
 
        return 0;
 }
 
-#define ide_gen_devset_rw(_name, _func) \
-__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
-
-ide_gen_devset_rw(io_32bit, io_32bit);
-ide_gen_devset_rw(keepsettings, ksettings);
-ide_gen_devset_rw(unmaskirq, unmaskirq);
-ide_gen_devset_rw(using_dma, using_dma);
-__IDE_DEVSET(pio_mode, 0, NULL, set_pio_mode);
+ide_ext_devset_rw_sync(io_32bit, io_32bit);
+ide_ext_devset_rw_sync(keepsettings, ksettings);
+ide_ext_devset_rw_sync(unmaskirq, unmaskirq);
+ide_ext_devset_rw_sync(using_dma, using_dma);
+__IDE_DEVSET(pio_mode, DS_SYNC, NULL, set_pio_mode);
 
 static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
 {
-       ide_drive_t *drive = dev->driver_data;
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
        ide_hwif_t *hwif = HWIF(drive);
        struct request *rq;
        struct request_pm_state rqpm;
        ide_task_t args;
        int ret;
 
-       /* Call ACPI _GTM only once */
-       if (!(drive->dn % 2))
+       /* call ACPI _GTM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL)
                ide_acpi_get_timing(hwif);
 
        memset(&rqpm, 0, sizeof(rqpm));
@@ -382,33 +416,32 @@ static int generic_ide_suspend(struct device *dev, pm_message_t mesg)
        rq->cmd_type = REQ_TYPE_PM_SUSPEND;
        rq->special = &args;
        rq->data = &rqpm;
-       rqpm.pm_step = ide_pm_state_start_suspend;
+       rqpm.pm_step = IDE_PM_START_SUSPEND;
        if (mesg.event == PM_EVENT_PRETHAW)
                mesg.event = PM_EVENT_FREEZE;
        rqpm.pm_state = mesg.event;
 
        ret = blk_execute_rq(drive->queue, NULL, rq, 0);
        blk_put_request(rq);
-       /* only call ACPI _PS3 after both drivers are suspended */
-       if (!ret && (((drive->dn % 2) && hwif->drives[0].present
-                && hwif->drives[1].present)
-                || !hwif->drives[0].present
-                || !hwif->drives[1].present))
+
+       /* call ACPI _PS3 only after both devices are suspended */
+       if (ret == 0 && ((drive->dn & 1) || pair == NULL))
                ide_acpi_set_state(hwif, 0);
+
        return ret;
 }
 
 static int generic_ide_resume(struct device *dev)
 {
-       ide_drive_t *drive = dev->driver_data;
+       ide_drive_t *drive = dev->driver_data, *pair = ide_get_pair_dev(drive);
        ide_hwif_t *hwif = HWIF(drive);
        struct request *rq;
        struct request_pm_state rqpm;
        ide_task_t args;
        int err;
 
-       /* Call ACPI _STM only once */
-       if (!(drive->dn % 2)) {
+       /* call ACPI _PS0 / _STM only once */
+       if ((drive->dn & 1) == 0 || pair == NULL) {
                ide_acpi_set_state(hwif, 1);
                ide_acpi_push_timing(hwif);
        }
@@ -422,7 +455,7 @@ static int generic_ide_resume(struct device *dev)
        rq->cmd_flags |= REQ_PREEMPT;
        rq->special = &args;
        rq->data = &rqpm;
-       rqpm.pm_step = ide_pm_state_start_resume;
+       rqpm.pm_step = IDE_PM_START_RESUME;
        rqpm.pm_state = PM_EVENT_ON;
 
        err = blk_execute_rq(drive->queue, NULL, rq, 1);
@@ -554,6 +587,7 @@ static struct device_attribute ide_dev_attrs[] = {
        __ATTR_RO(model),
        __ATTR_RO(firmware),
        __ATTR(serial, 0400, serial_show, NULL),
+       __ATTR(unload_heads, 0644, ide_park_show, ide_park_store),
        __ATTR_NULL
 };
 
@@ -708,22 +742,22 @@ static int ide_set_disk_chs(const char *str, struct kernel_param *kp)
 module_param_call(chs, ide_set_disk_chs, NULL, NULL, 0);
 MODULE_PARM_DESC(chs, "force device as a disk (using CHS)");
 
-static void ide_dev_apply_params(ide_drive_t *drive)
+static void ide_dev_apply_params(ide_drive_t *drive, u8 unit)
 {
-       int i = drive->hwif->index * MAX_DRIVES + drive->select.b.unit;
+       int i = drive->hwif->index * MAX_DRIVES + unit;
 
        if (ide_nodma & (1 << i)) {
                printk(KERN_INFO "ide: disallowing DMA for %s\n", drive->name);
-               drive->nodma = 1;
+               drive->dev_flags |= IDE_DFLAG_NODMA;
        }
        if (ide_noflush & (1 << i)) {
                printk(KERN_INFO "ide: disabling flush requests for %s\n",
                                 drive->name);
-               drive->noflush = 1;
+               drive->dev_flags |= IDE_DFLAG_NOFLUSH;
        }
        if (ide_noprobe & (1 << i)) {
                printk(KERN_INFO "ide: skipping probe for %s\n", drive->name);
-               drive->noprobe = 1;
+               drive->dev_flags |= IDE_DFLAG_NOPROBE;
        }
        if (ide_nowerr & (1 << i)) {
                printk(KERN_INFO "ide: ignoring the ATA_DF bit for %s\n",
@@ -732,7 +766,7 @@ static void ide_dev_apply_params(ide_drive_t *drive)
        }
        if (ide_cdroms & (1 << i)) {
                printk(KERN_INFO "ide: forcing %s as a CD-ROM\n", drive->name);
-               drive->present = 1;
+               drive->dev_flags |= IDE_DFLAG_PRESENT;
                drive->media = ide_cdrom;
                /* an ATAPI device ignores DRDY */
                drive->ready_stat = 0;
@@ -741,11 +775,12 @@ static void ide_dev_apply_params(ide_drive_t *drive)
                drive->cyl  = drive->bios_cyl  = ide_disks_chs[i].cyl;
                drive->head = drive->bios_head = ide_disks_chs[i].head;
                drive->sect = drive->bios_sect = ide_disks_chs[i].sect;
-               drive->forced_geom = 1;
+
                printk(KERN_INFO "ide: forcing %s as a disk (%d/%d/%d)\n",
                                 drive->name,
                                 drive->cyl, drive->head, drive->sect);
-               drive->present = 1;
+
+               drive->dev_flags |= IDE_DFLAG_FORCED_GEOM | IDE_DFLAG_PRESENT;
                drive->media = ide_disk;
                drive->ready_stat = ATA_DRDY;
        }
@@ -785,7 +820,7 @@ void ide_port_apply_params(ide_hwif_t *hwif)
        }
 
        for (i = 0; i < MAX_DRIVES; i++)
-               ide_dev_apply_params(&hwif->drives[i]);
+               ide_dev_apply_params(&hwif->drives[i], i);
 }
 
 /*
index 7276c96aaa2a88aa8bfd2279da17b21963cd7b9c..90da1f953ed080d0b0fb3ce38ff527398c42d00c 100644 (file)
@@ -131,7 +131,7 @@ static void ali14xx_set_pio_mode(ide_drive_t *drive, const u8 pio)
                drive->name, pio, time1, time2, param1, param2, param3, param4);
 
        /* stuff timing parameters into controller registers */
-       driveNum = (HWIF(drive)->index << 1) + drive->select.b.unit;
+       driveNum = (drive->hwif->index << 1) + (drive->dn & 1);
        spin_lock_irqsave(&ali14xx_lock, flags);
        outb_p(regOn, basePort);
        outReg(param1, regTab[driveNum].reg1);
index 5123ea291d075a332fe5f652957cb0de0d9744cc..c7e5c2246b79e1b29836055921e116daacafe102 100644 (file)
@@ -120,7 +120,8 @@ static void ht6560b_selectproc (ide_drive_t *drive)
         * Need to enforce prefetch sometimes because otherwise
         * it'll hang (hard).
         */
-       if (drive->media != ide_disk || !drive->present)
+       if (drive->media != ide_disk ||
+           (drive->dev_flags & IDE_DFLAG_PRESENT) == 0)
                select |= HT_PREFETCH_MODE;
 
        if (select != current_select || timing != current_timing) {
@@ -249,11 +250,11 @@ static void ht_set_prefetch(ide_drive_t *drive, u8 state)
         */
        if (state) {
                drive->drive_data |= t;   /* enable prefetch mode */
-               drive->no_unmask = 1;
-               drive->unmask = 0;
+               drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
+               drive->dev_flags &= ~IDE_DFLAG_UNMASK;
        } else {
                drive->drive_data &= ~t;  /* disable prefetch mode */
-               drive->no_unmask = 0;
+               drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
        }
 
        spin_unlock_irqrestore(&ht6560b_lock, flags);
index c76d55de6996413496ddc9c8d725f3feb633c860..9e85b1ec9607604178a6a99419b2449516027f5d 100644 (file)
@@ -14,7 +14,7 @@ MODULE_PARM_DESC(probe, "probe for generic IDE chipset with 4 drives/port");
 static void ide_4drives_init_dev(ide_drive_t *drive)
 {
        if (drive->hwif->channel)
-               drive->select.all ^= 0x20;
+               drive->select ^= 0x20;
 }
 
 static const struct ide_port_ops ide_4drives_port_ops = {
index ee6fc30d5e2bec793b93099a5068b7c5cccdaa4c..cb199c815b534234bbd115c0ea19df7fea3a48e9 100644 (file)
@@ -219,103 +219,91 @@ out_release:
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+struct pcmcia_config_check {
+       unsigned long ctl_base;
+       int skip_vcc;
+       int is_kme;
+};
+
+static int pcmcia_check_one_config(struct pcmcia_device *pdev,
+                                  cistpl_cftable_entry_t *cfg,
+                                  cistpl_cftable_entry_t *dflt,
+                                  unsigned int vcc,
+                                  void *priv_data)
+{
+       struct pcmcia_config_check *stk = priv_data;
+
+       /* Check for matching Vcc, unless we're desperate */
+       if (!stk->skip_vcc) {
+               if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+                       if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
+                               return -ENODEV;
+               } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+                       if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000)
+                               return -ENODEV;
+               }
+       }
+
+       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               pdev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               pdev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               pdev->conf.ConfigIndex = cfg->index;
+               pdev->io.BasePort1 = io->win[0].base;
+               pdev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       pdev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               if (io->nwin == 2) {
+                       pdev->io.NumPorts1 = 8;
+                       pdev->io.BasePort2 = io->win[1].base;
+                       pdev->io.NumPorts2 = (stk->is_kme) ? 2 : 1;
+                       if (pcmcia_request_io(pdev, &pdev->io) != 0)
+                               return -ENODEV;
+                       stk->ctl_base = pdev->io.BasePort2;
+               } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
+                       pdev->io.NumPorts1 = io->win[0].len;
+                       pdev->io.NumPorts2 = 0;
+                       if (pcmcia_request_io(pdev, &pdev->io) != 0)
+                               return -ENODEV;
+                       stk->ctl_base = pdev->io.BasePort1 + 0x0e;
+               } else
+                       return -ENODEV;
+               /* If we've got this far, we're done */
+               return 0;
+       }
+       return -ENODEV;
+}
+
 static int ide_config(struct pcmcia_device *link)
 {
     ide_info_t *info = link->priv;
-    tuple_t tuple;
-    struct {
-       u_short         buf[128];
-       cisparse_t      parse;
-       config_info_t   conf;
-       cistpl_cftable_entry_t dflt;
-    } *stk = NULL;
-    cistpl_cftable_entry_t *cfg;
-    int pass, last_ret = 0, last_fn = 0, is_kme = 0;
+    struct pcmcia_config_check *stk = NULL;
+    int last_ret = 0, last_fn = 0, is_kme = 0;
     unsigned long io_base, ctl_base;
     struct ide_host *host;
 
     DEBUG(0, "ide_config(0x%p)\n", link);
 
-    stk = kzalloc(sizeof(*stk), GFP_KERNEL);
-    if (!stk) goto err_mem;
-    cfg = &stk->parse.cftable_entry;
-
-    tuple.TupleData = (cisdata_t *)&stk->buf;
-    tuple.TupleOffset = 0;
-    tuple.TupleDataMax = 255;
-    tuple.Attributes = 0;
-
     is_kme = ((link->manf_id == MANFID_KME) &&
              ((link->card_id == PRODID_KME_KXLC005_A) ||
               (link->card_id == PRODID_KME_KXLC005_B)));
 
-    /* Not sure if this is right... look up the current Vcc */
-    CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &stk->conf));
-
-    pass = io_base = ctl_base = 0;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    tuple.Attributes = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (1) {
-       if (pcmcia_get_tuple_data(link, &tuple) != 0) goto next_entry;
-       if (pcmcia_parse_tuple(link, &tuple, &stk->parse) != 0) goto next_entry;
-
-       /* Check for matching Vcc, unless we're desperate */
-       if (!pass) {
-           if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
-               if (stk->conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000)
-                   goto next_entry;
-           } else if (stk->dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-               if (stk->conf.Vcc != stk->dflt.vcc.param[CISTPL_POWER_VNOM] / 10000)
-                   goto next_entry;
-           }
-       }
-
-       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-           link->conf.Vpp =
-               cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-       else if (stk->dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-           link->conf.Vpp =
-               stk->dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
-
-       if ((cfg->io.nwin > 0) || (stk->dflt.io.nwin > 0)) {
-           cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &stk->dflt.io;
-           link->conf.ConfigIndex = cfg->index;
-           link->io.BasePort1 = io->win[0].base;
-           link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-           if (!(io->flags & CISTPL_IO_16BIT))
-               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-           if (io->nwin == 2) {
-               link->io.NumPorts1 = 8;
-               link->io.BasePort2 = io->win[1].base;
-               link->io.NumPorts2 = (is_kme) ? 2 : 1;
-               if (pcmcia_request_io(link, &link->io) != 0)
-                       goto next_entry;
-               io_base = link->io.BasePort1;
-               ctl_base = link->io.BasePort2;
-           } else if ((io->nwin == 1) && (io->win[0].len >= 16)) {
-               link->io.NumPorts1 = io->win[0].len;
-               link->io.NumPorts2 = 0;
-               if (pcmcia_request_io(link, &link->io) != 0)
-                       goto next_entry;
-               io_base = link->io.BasePort1;
-               ctl_base = link->io.BasePort1 + 0x0e;
-           } else goto next_entry;
-           /* If we've got this far, we're done */
-           break;
-       }
-
-    next_entry:
-       if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-           memcpy(&stk->dflt, cfg, sizeof(stk->dflt));
-       if (pass) {
-           CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       } else if (pcmcia_get_next_tuple(link, &tuple) != 0) {
-           CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-           memset(&stk->dflt, 0, sizeof(stk->dflt));
-           pass++;
-       }
+    stk = kzalloc(sizeof(*stk), GFP_KERNEL);
+    if (!stk)
+           goto err_mem;
+    stk->is_kme = is_kme;
+    stk->skip_vcc = io_base = ctl_base = 0;
+
+    if (pcmcia_loop_config(link, pcmcia_check_one_config, stk)) {
+           stk->skip_vcc = 1;
+           if (pcmcia_loop_config(link, pcmcia_check_one_config, stk))
+                   goto failed; /* No suitable config found */
     }
+    io_base = link->io.BasePort1;
+    ctl_base = stk->ctl_base;
 
     CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
     CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
@@ -403,8 +391,10 @@ static struct pcmcia_device_id ide_ids[] = {
        PCMCIA_DEVICE_MANF_CARD(0x000a, 0x0000),        /* I-O Data CFA */
        PCMCIA_DEVICE_MANF_CARD(0x001c, 0x0001),        /* Mitsubishi CFA */
        PCMCIA_DEVICE_MANF_CARD(0x0032, 0x0704),
+       PCMCIA_DEVICE_MANF_CARD(0x0032, 0x2904),
        PCMCIA_DEVICE_MANF_CARD(0x0045, 0x0401),        /* SanDisk CFA */
        PCMCIA_DEVICE_MANF_CARD(0x004f, 0x0000),        /* Kingston */
+       PCMCIA_DEVICE_MANF_CARD(0x0097, 0x1620),        /* TI emulated */
        PCMCIA_DEVICE_MANF_CARD(0x0098, 0x0000),        /* Toshiba */
        PCMCIA_DEVICE_MANF_CARD(0x00a4, 0x002d),
        PCMCIA_DEVICE_MANF_CARD(0x00ce, 0x0000),        /* Samsung */
index ec408b3a7100ae9eb4492ca1dfcb74ddc888c790..bc27c7aba93612628eff92defc91baaef5657109 100644 (file)
@@ -305,7 +305,7 @@ static void __init qd6580_init_dev(ide_drive_t *drive)
        } else
                t2 = t1 = hwif->channel ? QD6580_DEF_DATA2 : QD6580_DEF_DATA;
 
-       drive->drive_data = drive->select.b.unit ? t2 : t1;
+       drive->drive_data = (drive->dn & 1) ? t2 : t1;
 }
 
 static const struct ide_port_ops qd6500_port_ops = {
index 11b7f61aae40f7a7d7ec8d29be48cd6c5ec78313..0ec8fd1e4dcb3ae37d3fb98966bc936f534fa0d0 100644 (file)
@@ -322,11 +322,7 @@ static int auide_dma_setup(ide_drive_t *drive)
 }
 
 static int auide_dma_test_irq(ide_drive_t *drive)
-{      
-       if (drive->waiting_for_dma == 0)
-               printk(KERN_WARNING "%s: ide_dma_test_irq \
-                                     called while not waiting\n", drive->name);
-
+{
        /* If dbdma didn't execute the STOP command yet, the
         * active bit is still set
         */
@@ -344,11 +340,6 @@ static void auide_dma_host_set(ide_drive_t *drive, int on)
 {
 }
 
-static void auide_dma_lost_irq(ide_drive_t *drive)
-{
-       printk(KERN_ERR "%s: IRQ lost\n", drive->name);
-}
-
 static void auide_ddma_tx_callback(int irq, void *param)
 {
        _auide_hwif *ahwif = (_auide_hwif*)param;
@@ -375,18 +366,6 @@ static void auide_init_dbdma_dev(dbdev_tab_t *dev, u32 dev_id, u32 tsize, u32 de
 }
 
 #ifdef CONFIG_BLK_DEV_IDE_AU1XXX_MDMA2_DBDMA
-static void auide_dma_timeout(ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = HWIF(drive);
-
-       printk(KERN_ERR "%s: DMA timeout occurred: ", drive->name);
-
-       if (auide_dma_test_irq(drive))
-               return;
-
-       auide_dma_end(drive);
-}
-
 static const struct ide_dma_ops au1xxx_dma_ops = {
        .dma_host_set           = auide_dma_host_set,
        .dma_setup              = auide_dma_setup,
@@ -394,8 +373,8 @@ static const struct ide_dma_ops au1xxx_dma_ops = {
        .dma_start              = auide_dma_start,
        .dma_end                = auide_dma_end,
        .dma_test_irq           = auide_dma_test_irq,
-       .dma_lost_irq           = auide_dma_lost_irq,
-       .dma_timeout            = auide_dma_timeout,
+       .dma_lost_irq           = ide_dma_lost_irq,
+       .dma_timeout            = ide_dma_timeout,
 };
 
 static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
@@ -448,10 +427,9 @@ static int auide_ddma_init(ide_hwif_t *hwif, const struct ide_port_info *d)
                                                             NUM_DESCRIPTORS);
        auide->rx_desc_head = (void*)au1xxx_dbdma_ring_alloc(auide->rx_chan,
                                                             NUM_DESCRIPTORS);
-       hwif->dmatable_cpu = dma_alloc_coherent(hwif->dev,
-                                               PRD_ENTRIES * PRD_BYTES,        /* 1 Page */
-                                               &hwif->dmatable_dma, GFP_KERNEL);
+
+       /* FIXME: check return value */
+       (void)ide_allocate_dma_engine(hwif);
        
        au1xxx_dbdma_start( auide->tx_chan );
        au1xxx_dbdma_start( auide->rx_chan );
index e7475ba559c74063543650816335a751864687ac..4142c698e0d3da9fda2db897edf8228fdd8bba12 100644 (file)
@@ -115,7 +115,7 @@ static void aec6260_set_mode(ide_drive_t *drive, const u8 speed)
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        struct ide_host *host   = pci_get_drvdata(dev);
        struct chipset_bus_clock_list_entry *bus_clock = host->host_priv;
-       u8 unit         = (drive->select.b.unit & 0x01);
+       u8 unit                 = drive->dn & 1;
        u8 tmp1 = 0, tmp2 = 0;
        u8 ultra = 0, drive_conf = 0, ultra_conf = 0;
        unsigned long flags;
@@ -302,7 +302,7 @@ static const struct pci_device_id aec62xx_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, aec62xx_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver aec62xx_pci_driver = {
        .name           = "AEC62xx_IDE",
        .id_table       = aec62xx_pci_tbl,
        .probe          = aec62xx_init_one,
@@ -313,12 +313,12 @@ static struct pci_driver driver = {
 
 static int __init aec62xx_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&aec62xx_pci_driver);
 }
 
 static void __exit aec62xx_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&aec62xx_pci_driver);
 }
 
 module_init(aec62xx_ide_init);
index 053c75263918d592c60a70024ee7ef47c564953d..daf9dce39e522226a83d5433179e414b1c8a4730 100644 (file)
@@ -77,8 +77,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
        int bus_speed = ide_pci_clk ? ide_pci_clk : 33;
        int port = hwif->channel ? 0x5c : 0x58;
        int portFIFO = hwif->channel ? 0x55 : 0x54;
-       u8 cd_dma_fifo = 0;
-       int unit = drive->select.b.unit & 1;
+       u8 cd_dma_fifo = 0, unit = drive->dn & 1;
 
        if ((s_clc = (s_time * bus_speed + 999) / 1000) >= 8)
                s_clc = 0;
@@ -112,7 +111,7 @@ static void ali_set_pio_mode(ide_drive_t *drive, const u8 pio)
        }
        
        pci_write_config_byte(dev, port, s_clc);
-       pci_write_config_byte(dev, port+drive->select.b.unit+2, (a_clc << 4) | r_clc);
+       pci_write_config_byte(dev, port + unit + 2, (a_clc << 4) | r_clc);
        local_irq_restore(flags);
 }
 
@@ -154,7 +153,7 @@ static void ali_set_dma_mode(ide_drive_t *drive, const u8 speed)
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
        u8 speed1               = speed;
-       u8 unit                 = (drive->select.b.unit & 0x01);
+       u8 unit                 = drive->dn & 1;
        u8 tmpbyte              = 0x00;
        int m5229_udma          = (hwif->channel) ? 0x57 : 0x56;
 
@@ -508,7 +507,7 @@ static const struct ide_dma_ops ali_dma_ops = {
        .dma_setup              = ali15x3_dma_setup,
        .dma_exec_cmd           = ide_dma_exec_cmd,
        .dma_start              = ide_dma_start,
-       .dma_end                = __ide_dma_end,
+       .dma_end                = ide_dma_end,
        .dma_test_irq           = ide_dma_test_irq,
        .dma_lost_irq           = ide_dma_lost_irq,
        .dma_timeout            = ide_dma_timeout,
@@ -576,7 +575,7 @@ static const struct pci_device_id alim15x3_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, alim15x3_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver alim15x3_pci_driver = {
        .name           = "ALI15x3_IDE",
        .id_table       = alim15x3_pci_tbl,
        .probe          = alim15x3_init_one,
@@ -587,12 +586,12 @@ static struct pci_driver driver = {
 
 static int __init ali15x3_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&alim15x3_pci_driver);
 }
 
 static void __exit ali15x3_ide_exit(void)
 {
-       return pci_unregister_driver(&driver);
+       return pci_unregister_driver(&alim15x3_pci_driver);
 }
 
 module_init(ali15x3_ide_init);
index 824471f91bf5f739047e4f962f53605e9c466dee..81ec73134edacfead9286aa479c0a73f1526de05 100644 (file)
@@ -92,7 +92,7 @@ static void amd_set_drive(ide_drive_t *drive, const u8 speed)
 
        ide_timing_compute(drive, speed, &t, T, UT);
 
-       if (peer->present) {
+       if (peer->dev_flags & IDE_DFLAG_PRESENT) {
                ide_timing_compute(peer, peer->current_speed, &p, T, UT);
                ide_timing_merge(&p, &t, &t, IDE_TIMING_8BIT);
        }
@@ -319,7 +319,7 @@ static const struct pci_device_id amd74xx_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, amd74xx_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver amd74xx_pci_driver = {
        .name           = "AMD_IDE",
        .id_table       = amd74xx_pci_tbl,
        .probe          = amd74xx_probe,
@@ -330,12 +330,12 @@ static struct pci_driver driver = {
 
 static int __init amd74xx_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&amd74xx_pci_driver);
 }
 
 static void __exit amd74xx_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&amd74xx_pci_driver);
 }
 
 module_init(amd74xx_ide_init);
index e4437034dd0820d237c9af8ecae7642374293234..b2735d28f5cc22019b88c8f159da1af91dccbb7e 100644 (file)
@@ -182,7 +182,7 @@ static const struct pci_device_id atiixp_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, atiixp_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver atiixp_pci_driver = {
        .name           = "ATIIXP_IDE",
        .id_table       = atiixp_pci_tbl,
        .probe          = atiixp_init_one,
@@ -193,12 +193,12 @@ static struct pci_driver driver = {
 
 static int __init atiixp_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&atiixp_pci_driver);
 }
 
 static void __exit atiixp_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&atiixp_pci_driver);
 }
 
 module_init(atiixp_ide_init);
index 7f39cdb414109ece635ba535e49eb5529a0f51f1..e4306647d00d6782e8db72d40d82827bb085044f 100644 (file)
@@ -378,13 +378,13 @@ static void __set_prefetch_mode(ide_drive_t *drive, int mode)
 {
        if (mode) {     /* want prefetch on? */
 #if CMD640_PREFETCH_MASKS
-               drive->no_unmask = 1;
-               drive->unmask = 0;
+               drive->dev_flags |= IDE_DFLAG_NO_UNMASK;
+               drive->dev_flags &= ~IDE_DFLAG_UNMASK;
 #endif
-               drive->no_io_32bit = 0;
+               drive->dev_flags &= ~IDE_DFLAG_NO_IO_32BIT;
        } else {
-               drive->no_unmask = 0;
-               drive->no_io_32bit = 1;
+               drive->dev_flags &= ~IDE_DFLAG_NO_UNMASK;
+               drive->dev_flags |= IDE_DFLAG_NO_IO_32BIT;
                drive->io_32bit = 0;
        }
 }
@@ -468,10 +468,10 @@ static void program_drive_counts(ide_drive_t *drive, unsigned int index)
         */
        if (index > 1) {
                ide_hwif_t *hwif = drive->hwif;
-               ide_drive_t *peer = &hwif->drives[!drive->select.b.unit];
+               ide_drive_t *peer = &hwif->drives[!(drive->dn & 1)];
                unsigned int mate = index ^ 1;
 
-               if (peer->present) {
+               if (peer->dev_flags & IDE_DFLAG_PRESENT) {
                        if (setup_count < setup_counts[mate])
                                setup_count = setup_counts[mate];
                        if (active_count < active_counts[mate])
@@ -607,7 +607,7 @@ static void cmd640_set_pio_mode(ide_drive_t *drive, const u8 pio)
 
 static void cmd640_init_dev(ide_drive_t *drive)
 {
-       unsigned int i = drive->hwif->channel * 2 + drive->select.b.unit;
+       unsigned int i = drive->hwif->channel * 2 + (drive->dn & 1);
 
 #ifdef CONFIG_BLK_DEV_CMD640_ENHANCED
        /*
@@ -626,7 +626,7 @@ static void cmd640_init_dev(ide_drive_t *drive)
         */
        check_prefetch(drive, i);
        printk(KERN_INFO DRV_NAME ": drive%d timings/prefetch(%s) preserved\n",
-                                 i, drive->no_io_32bit ? "off" : "on");
+               i, (drive->dev_flags & IDE_DFLAG_NO_IO_32BIT) ? "off" : "on");
 #endif /* CONFIG_BLK_DEV_CMD640_ENHANCED */
 }
 
index 456dee18b660fa94dc72c85877fa598f511c79ca..935385c77e062d12e6ad6061942dfcdd5cbbdd8d 100644 (file)
@@ -228,7 +228,7 @@ static int cmd648_dma_end(ide_drive_t *drive)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        unsigned long base      = hwif->dma_base - (hwif->channel * 8);
-       int err                 = __ide_dma_end(drive);
+       int err                 = ide_dma_end(drive);
        u8  irq_mask            = hwif->channel ? MRDMODE_INTR_CH1 :
                                                  MRDMODE_INTR_CH0;
        u8  mrdmode             = inb(base + 1);
@@ -248,7 +248,7 @@ static int cmd64x_dma_end(ide_drive_t *drive)
        u8  irq_mask            = hwif->channel ? ARTTIM23_INTR_CH1 :
                                                  CFR_INTR_CH0;
        u8  irq_stat            = 0;
-       int err                 = __ide_dma_end(drive);
+       int err                 = ide_dma_end(drive);
 
        (void) pci_read_config_byte(dev, irq_reg, &irq_stat);
        /* clear the interrupt bit */
@@ -505,7 +505,7 @@ static const struct pci_device_id cmd64x_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cmd64x_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver cmd64x_pci_driver = {
        .name           = "CMD64x_IDE",
        .id_table       = cmd64x_pci_tbl,
        .probe          = cmd64x_init_one,
@@ -516,12 +516,12 @@ static struct pci_driver driver = {
 
 static int __init cmd64x_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&cmd64x_pci_driver);
 }
 
 static void __exit cmd64x_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&cmd64x_pci_driver);
 }
 
 module_init(cmd64x_ide_init);
index d6341f7c4144b15e08b78372637f5e582266c968..5efb467f8fa0009fa257e9e6a41de1afa3e3f630 100644 (file)
@@ -145,7 +145,7 @@ static const struct pci_device_id cs5520_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cs5520_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver cs5520_pci_driver = {
        .name           = "Cyrix_IDE",
        .id_table       = cs5520_pci_tbl,
        .probe          = cs5520_init_one,
@@ -155,7 +155,7 @@ static struct pci_driver driver = {
 
 static int __init cs5520_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&cs5520_pci_driver);
 }
 
 module_init(cs5520_ide_init);
index da42fa7e9f979ea5d5eed4731d473f96a1d95929..53f079cc00afc010f2cf62b643fe98432feceea8 100644 (file)
@@ -267,7 +267,7 @@ static const struct pci_device_id cs5530_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cs5530_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver cs5530_pci_driver = {
        .name           = "CS5530 IDE",
        .id_table       = cs5530_pci_tbl,
        .probe          = cs5530_init_one,
@@ -278,12 +278,12 @@ static struct pci_driver driver = {
 
 static int __init cs5530_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&cs5530_pci_driver);
 }
 
 static void __exit cs5530_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&cs5530_pci_driver);
 }
 
 module_init(cs5530_ide_init);
index 1e5bc59ea2fb03074fa9729501660f0e7b33bfcd..983d957a01894a2b207eda57cc6a350430cd3307 100644 (file)
@@ -76,7 +76,7 @@ static unsigned int cs5535_udma_timings[5] =
 static void cs5535_set_speed(ide_drive_t *drive, const u8 speed)
 {
        u32 reg = 0, dummy;
-       int unit = drive->select.b.unit;
+       u8 unit = drive->dn & 1;
 
        /* Set the PIO timings */
        if (speed < XFER_SW_DMA_0) {
@@ -192,7 +192,7 @@ static const struct pci_device_id cs5535_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, cs5535_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver cs5535_pci_driver = {
        .name           = "CS5535_IDE",
        .id_table       = cs5535_pci_tbl,
        .probe          = cs5535_init_one,
@@ -203,12 +203,12 @@ static struct pci_driver driver = {
 
 static int __init cs5535_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&cs5535_pci_driver);
 }
 
 static void __exit cs5535_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&cs5535_pci_driver);
 }
 
 module_init(cs5535_ide_init);
index 69820e9224d138978a32e8ddc879fe325117633e..5297f07d293300da38f9c1a3f1db7af41068aca1 100644 (file)
 
 #define DRV_NAME "cy82c693"
 
-/* the current version */
-#define CY82_VERSION   "CY82C693U driver v0.34 99-13-12 Andreas S. Krebs (akrebs@altavista.net)"
-
 /*
  *     The following are used to debug the driver.
  */
-#define CY82C693_DEBUG_LOGS    0
 #define CY82C693_DEBUG_INFO    0
 
-/* define CY82C693_SETDMA_CLOCK to set DMA Controller Clock Speed to ATCLK */
-#undef CY82C693_SETDMA_CLOCK
-
 /*
  *     NOTE: the value for busmaster timeout is tricky and I got it by
  *     trial and error!  By using a to low value will cause DMA timeouts
@@ -89,7 +82,6 @@
 #define CY82_INDEX_PORT                0x22
 #define CY82_DATA_PORT         0x23
 
-#define CY82_INDEX_CTRLREG1    0x01
 #define CY82_INDEX_CHANNEL0    0x30
 #define CY82_INDEX_CHANNEL1    0x31
 #define CY82_INDEX_TIMEOUT     0x32
@@ -179,17 +171,6 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
 
        index = hwif->channel ? CY82_INDEX_CHANNEL1 : CY82_INDEX_CHANNEL0;
 
-#if CY82C693_DEBUG_LOGS
-       /* for debug let's show the previous values */
-
-       outb(index, CY82_INDEX_PORT);
-       data = inb(CY82_DATA_PORT);
-
-       printk(KERN_INFO "%s (ch=%d, dev=%d): DMA mode is %d (single=%d)\n",
-               drive->name, HWIF(drive)->channel, drive->select.b.unit,
-               (data&0x3), ((data>>2)&1));
-#endif /* CY82C693_DEBUG_LOGS */
-
        data = (mode & 3) | (single << 2);
 
        outb(index, CY82_INDEX_PORT);
@@ -197,8 +178,7 @@ static void cy82c693_set_dma_mode(ide_drive_t *drive, const u8 mode)
 
 #if CY82C693_DEBUG_INFO
        printk(KERN_INFO "%s (ch=%d, dev=%d): set DMA mode to %d (single=%d)\n",
-               drive->name, HWIF(drive)->channel, drive->select.b.unit,
-               mode & 3, single);
+               drive->name, hwif->channel, drive->dn & 1, mode & 3, single);
 #endif /* CY82C693_DEBUG_INFO */
 
        /*
@@ -239,50 +219,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
                }
        }
 
-#if CY82C693_DEBUG_LOGS
-       /* for debug let's show the register values */
-
-       if (drive->select.b.unit == 0) {
-               /*
-                * get master drive registers
-                * address setup control register
-                * is 32 bit !!!
-                */
-               pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
-               addrCtrl &= 0x0F;
-
-               /* now let's get the remaining registers */
-               pci_read_config_byte(dev, CY82_IDE_MASTER_IOR, &pclk.time_16r);
-               pci_read_config_byte(dev, CY82_IDE_MASTER_IOW, &pclk.time_16w);
-               pci_read_config_byte(dev, CY82_IDE_MASTER_8BIT, &pclk.time_8);
-       } else {
-               /*
-                * set slave drive registers
-                * address setup control register
-                * is 32 bit !!!
-                */
-               pci_read_config_dword(dev, CY82_IDE_ADDRSETUP, &addrCtrl);
-
-               addrCtrl &= 0xF0;
-               addrCtrl >>= 4;
-
-               /* now let's get the remaining registers */
-               pci_read_config_byte(dev, CY82_IDE_SLAVE_IOR, &pclk.time_16r);
-               pci_read_config_byte(dev, CY82_IDE_SLAVE_IOW, &pclk.time_16w);
-               pci_read_config_byte(dev, CY82_IDE_SLAVE_8BIT, &pclk.time_8);
-       }
-
-       printk(KERN_INFO "%s (ch=%d, dev=%d): PIO timing is "
-               "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
-               drive->name, hwif->channel, drive->select.b.unit,
-               addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
-#endif /* CY82C693_DEBUG_LOGS */
-
        /* let's calc the values for this PIO mode */
        compute_clocks(pio, &pclk);
 
        /* now let's write  the clocks registers */
-       if (drive->select.b.unit == 0) {
+       if ((drive->dn & 1) == 0) {
                /*
                 * set master drive
                 * address setup control register
@@ -324,63 +265,11 @@ static void cy82c693_set_pio_mode(ide_drive_t *drive, const u8 pio)
 #if CY82C693_DEBUG_INFO
        printk(KERN_INFO "%s (ch=%d, dev=%d): set PIO timing to "
                "(addr=0x%X, ior=0x%X, iow=0x%X, 8bit=0x%X)\n",
-               drive->name, hwif->channel, drive->select.b.unit,
+               drive->name, hwif->channel, drive->dn & 1,
                addrCtrl, pclk.time_16r, pclk.time_16w, pclk.time_8);
 #endif /* CY82C693_DEBUG_INFO */
 }
 
-/*
- * this function is called during init and is used to setup the cy82c693 chip
- */
-static unsigned int init_chipset_cy82c693(struct pci_dev *dev)
-{
-       if (PCI_FUNC(dev->devfn) != 1)
-               return 0;
-
-#ifdef CY82C693_SETDMA_CLOCK
-       u8 data = 0;
-#endif /* CY82C693_SETDMA_CLOCK */
-
-       /* write info about this verion of the driver */
-       printk(KERN_INFO CY82_VERSION "\n");
-
-#ifdef CY82C693_SETDMA_CLOCK
-       /* okay let's set the DMA clock speed */
-
-       outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
-       data = inb(CY82_DATA_PORT);
-
-#if CY82C693_DEBUG_INFO
-       printk(KERN_INFO DRV_NAME ": Peripheral Configuration Register: 0x%X\n",
-               data);
-#endif /* CY82C693_DEBUG_INFO */
-
-       /*
-        * for some reason sometimes the DMA controller
-        * speed is set to ATCLK/2 ???? - we fix this here
-        *
-        * note: i don't know what causes this strange behaviour,
-        *       but even changing the dma speed doesn't solve it :-(
-        *       the ide performance is still only half the normal speed
-        *
-        *       if anybody knows what goes wrong with my machine, please
-        *       let me know - ASK
-        */
-
-       data |= 0x03;
-
-       outb(CY82_INDEX_CTRLREG1, CY82_INDEX_PORT);
-       outb(data, CY82_DATA_PORT);
-
-#if CY82C693_DEBUG_INFO
-       printk(KERN_INFO ": New Peripheral Configuration Register: 0x%X\n",
-               data);
-#endif /* CY82C693_DEBUG_INFO */
-
-#endif /* CY82C693_SETDMA_CLOCK */
-       return 0;
-}
-
 static void __devinit init_iops_cy82c693(ide_hwif_t *hwif)
 {
        static ide_hwif_t *primary;
@@ -401,7 +290,6 @@ static const struct ide_port_ops cy82c693_port_ops = {
 
 static const struct ide_port_info cy82c693_chipset __devinitdata = {
        .name           = DRV_NAME,
-       .init_chipset   = init_chipset_cy82c693,
        .init_iops      = init_iops_cy82c693,
        .port_ops       = &cy82c693_port_ops,
        .chipset        = ide_cy82c693,
@@ -443,7 +331,7 @@ static const struct pci_device_id cy82c693_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, cy82c693_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver cy82c693_pci_driver = {
        .name           = "Cypress_IDE",
        .id_table       = cy82c693_pci_tbl,
        .probe          = cy82c693_init_one,
@@ -454,12 +342,12 @@ static struct pci_driver driver = {
 
 static int __init cy82c693_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&cy82c693_pci_driver);
 }
 
 static void __exit cy82c693_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&cy82c693_pci_driver);
 }
 
 module_init(cy82c693_ide_init);
index 83b63b365e51659ea6c6f934465e3076600c248b..8689a706f537186e46549d2253b51c5c66c3b3a6 100644 (file)
@@ -117,7 +117,7 @@ static struct pci_device_id delkin_cb_pci_tbl[] __devinitdata = {
 };
 MODULE_DEVICE_TABLE(pci, delkin_cb_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver delkin_cb_pci_driver = {
        .name           = "Delkin-ASKA-Workbit Cardbus IDE",
        .id_table       = delkin_cb_pci_tbl,
        .probe          = delkin_cb_probe,
@@ -126,12 +126,12 @@ static struct pci_driver driver = {
 
 static int __init delkin_cb_init(void)
 {
-       return pci_register_driver(&driver);
+       return pci_register_driver(&delkin_cb_pci_driver);
 }
 
 static void __exit delkin_cb_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&delkin_cb_pci_driver);
 }
 
 module_init(delkin_cb_init);
index 092b238cb250d81d914f8118f587b8d019fcda1d..474f96a7c076a317bd29d72be1f3b181b0b50686 100644 (file)
@@ -166,7 +166,7 @@ static const struct pci_device_id generic_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, generic_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver generic_pci_driver = {
        .name           = "PCI_IDE",
        .id_table       = generic_pci_tbl,
        .probe          = generic_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
 
 static int __init generic_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&generic_pci_driver);
 }
 
 static void __exit generic_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&generic_pci_driver);
 }
 
 module_init(generic_ide_init);
index 644de29f8fe4a9f3ba2732abbc48968ae4a9195d..fb1a3aa57f073681dac953440ecdf9c803d54296 100644 (file)
@@ -166,7 +166,7 @@ static const struct pci_device_id hpt34x_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, hpt34x_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver hpt34x_pci_driver = {
        .name           = "HPT34x_IDE",
        .id_table       = hpt34x_pci_tbl,
        .probe          = hpt34x_init_one,
@@ -177,12 +177,12 @@ static struct pci_driver driver = {
 
 static int __init hpt34x_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&hpt34x_pci_driver);
 }
 
 static void __exit hpt34x_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&hpt34x_pci_driver);
 }
 
 module_init(hpt34x_ide_init);
index a194022b6a61b39260169d275278cdd5f1cc119b..9cf171cb9376b5265e07f87dfe88cb3a346bdc3f 100644 (file)
@@ -835,7 +835,7 @@ static int hpt370_dma_end(ide_drive_t *drive)
                if (dma_stat & 0x01)
                        hpt370_irq_timeout(drive);
        }
-       return __ide_dma_end(drive);
+       return ide_dma_end(drive);
 }
 
 static void hpt370_dma_timeout(ide_drive_t *drive)
@@ -863,9 +863,6 @@ static int hpt374_dma_test_irq(ide_drive_t *drive)
        if (dma_stat & 4)
                return 1;
 
-       if (!drive->waiting_for_dma)
-               printk(KERN_WARNING "%s: (%s) called while not waiting\n",
-                               drive->name, __func__);
        return 0;
 }
 
@@ -880,7 +877,7 @@ static int hpt374_dma_end(ide_drive_t *drive)
        pci_read_config_byte(dev, mcr_addr, &mcr);
        if (bwsr & mask)
                pci_write_config_byte(dev, mcr_addr, mcr | 0x30);
-       return __ide_dma_end(drive);
+       return ide_dma_end(drive);
 }
 
 /**
@@ -1456,7 +1453,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
        .dma_setup              = ide_dma_setup,
        .dma_exec_cmd           = ide_dma_exec_cmd,
        .dma_start              = ide_dma_start,
-       .dma_end                = __ide_dma_end,
+       .dma_end                = ide_dma_end,
        .dma_test_irq           = ide_dma_test_irq,
        .dma_lost_irq           = hpt366_dma_lost_irq,
        .dma_timeout            = ide_dma_timeout,
@@ -1622,7 +1619,7 @@ static const struct pci_device_id hpt366_pci_tbl[] __devinitconst = {
 };
 MODULE_DEVICE_TABLE(pci, hpt366_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver hpt366_pci_driver = {
        .name           = "HPT366_IDE",
        .id_table       = hpt366_pci_tbl,
        .probe          = hpt366_init_one,
@@ -1633,12 +1630,12 @@ static struct pci_driver driver = {
 
 static int __init hpt366_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&hpt366_pci_driver);
 }
 
 static void __exit hpt366_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&hpt366_pci_driver);
 }
 
 module_init(hpt366_ide_init);
index 0954ccd08d6fe718d37dc0fa48bfaa093611c635..7c2feeb3c5ec2f691821ec17e1dddcaec5df9189 100644 (file)
@@ -189,7 +189,7 @@ static const struct pci_device_id it8213_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, it8213_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver it8213_pci_driver = {
        .name           = "ITE8213_IDE",
        .id_table       = it8213_pci_tbl,
        .probe          = it8213_init_one,
@@ -200,12 +200,12 @@ static struct pci_driver driver = {
 
 static int __init it8213_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&it8213_pci_driver);
 }
 
 static void __exit it8213_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&it8213_pci_driver);
 }
 
 module_init(it8213_ide_init);
index 46edd083b3488b4c4ae6da9d31391aeb7c9461b2..995e18bb3139c55cde7bd06f4f7369c6ec3a9e70 100644 (file)
@@ -138,8 +138,7 @@ static void it821x_program_udma(ide_drive_t *drive, u16 timing)
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
        int channel = hwif->channel;
-       int unit = drive->select.b.unit;
-       u8 conf;
+       u8 unit = drive->dn & 1, conf;
 
        /* Program UDMA timing bits */
        if(itdev->clock_mode == ATA_66)
@@ -168,13 +167,11 @@ static void it821x_clock_strategy(ide_drive_t *drive)
        ide_hwif_t *hwif = drive->hwif;
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
+       ide_drive_t *pair;
+       int clock, altclock, sel = 0;
+       u8 unit = drive->dn & 1, v;
 
-       u8 unit = drive->select.b.unit;
-       ide_drive_t *pair = &hwif->drives[1-unit];
-
-       int clock, altclock;
-       u8 v;
-       int sel = 0;
+       pair = &hwif->drives[1 - unit];
 
        if(itdev->want[0][0] > itdev->want[1][0]) {
                clock = itdev->want[0][1];
@@ -240,16 +237,17 @@ static void it821x_clock_strategy(ide_drive_t *drive)
 
 static void it821x_set_pio_mode(ide_drive_t *drive, const u8 pio)
 {
-       ide_hwif_t *hwif        = drive->hwif;
+       ide_hwif_t *hwif = drive->hwif;
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
-       int unit = drive->select.b.unit;
-       ide_drive_t *pair = &hwif->drives[1 - unit];
-       u8 set_pio = pio;
+       ide_drive_t *pair;
+       u8 unit = drive->dn & 1, set_pio = pio;
 
        /* Spec says 89 ref driver uses 88 */
        static u16 pio_timings[]= { 0xAA88, 0xA382, 0xA181, 0x3332, 0x3121 };
        static u8 pio_want[]    = { ATA_66, ATA_66, ATA_66, ATA_66, ATA_ANY };
 
+       pair = &hwif->drives[1 - unit];
+
        /*
         * Compute the best PIO mode we can for a given device. We must
         * pick a speed that does not cause problems with the other device
@@ -286,9 +284,7 @@ static void it821x_tune_mwdma (ide_drive_t *drive, byte mode_wanted)
        ide_hwif_t *hwif = drive->hwif;
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        struct it821x_dev *itdev = (void *)ide_get_hwifdata(hwif);
-       int unit = drive->select.b.unit;
-       int channel = hwif->channel;
-       u8 conf;
+       u8 unit = drive->dn & 1, channel = hwif->channel, conf;
 
        static u16 dma[]        = { 0x8866, 0x3222, 0x3121 };
        static u8 mwdma_want[]  = { ATA_ANY, ATA_66, ATA_ANY };
@@ -325,9 +321,7 @@ static void it821x_tune_udma (ide_drive_t *drive, byte mode_wanted)
        ide_hwif_t *hwif = drive->hwif;
        struct pci_dev *dev = to_pci_dev(hwif->dev);
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
-       int unit = drive->select.b.unit;
-       int channel = hwif->channel;
-       u8 conf;
+       u8 unit = drive->dn & 1, channel = hwif->channel, conf;
 
        static u16 udma[]       = { 0x4433, 0x4231, 0x3121, 0x2121, 0x1111, 0x2211, 0x1111 };
        static u8 udma_want[]   = { ATA_ANY, ATA_50, ATA_ANY, ATA_66, ATA_66, ATA_50, ATA_66 };
@@ -369,7 +363,8 @@ static void it821x_dma_start(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
-       int unit = drive->select.b.unit;
+       u8 unit = drive->dn & 1;
+
        if(itdev->mwdma[unit] != MWDMA_OFF)
                it821x_program(drive, itdev->mwdma[unit]);
        else if(itdev->udma[unit] != UDMA_OFF && itdev->timing10)
@@ -389,9 +384,10 @@ static void it821x_dma_start(ide_drive_t *drive)
 static int it821x_dma_end(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = drive->hwif;
-       int unit = drive->select.b.unit;
        struct it821x_dev *itdev = ide_get_hwifdata(hwif);
-       int ret = __ide_dma_end(drive);
+       int ret = ide_dma_end(drive);
+       u8 unit = drive->dn & 1;
+
        if(itdev->mwdma[unit] != MWDMA_OFF)
                it821x_program(drive, itdev->pio[unit]);
        return ret;
@@ -454,7 +450,7 @@ static void it821x_quirkproc(ide_drive_t *drive)
                 *      IRQ mask as we may well be in PIO (eg rev 0x10)
                 *      for now and we know unmasking is safe on this chipset.
                 */
-               drive->unmask = 1;
+               drive->dev_flags |= IDE_DFLAG_UNMASK;
        } else {
        /*
         *      Perform fixups on smart mode. We need to "lose" some
@@ -680,7 +676,7 @@ static const struct pci_device_id it821x_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, it821x_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver it821x_pci_driver = {
        .name           = "ITE821x IDE",
        .id_table       = it821x_pci_tbl,
        .probe          = it821x_init_one,
@@ -691,12 +687,12 @@ static struct pci_driver driver = {
 
 static int __init it821x_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&it821x_pci_driver);
 }
 
 static void __exit it821x_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&it821x_pci_driver);
 }
 
 module_init(it821x_ide_init);
index acd647110648628d045e8e6cbf75e7b9faa28c7e..9a68433cf46d38e041c4f5bf9f5a8e1e6927656f 100644 (file)
@@ -149,7 +149,7 @@ static struct pci_device_id jmicron_pci_tbl[] = {
 
 MODULE_DEVICE_TABLE(pci, jmicron_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver jmicron_pci_driver = {
        .name           = "JMicron IDE",
        .id_table       = jmicron_pci_tbl,
        .probe          = jmicron_init_one,
@@ -160,12 +160,12 @@ static struct pci_driver driver = {
 
 static int __init jmicron_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&jmicron_pci_driver);
 }
 
 static void __exit jmicron_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&jmicron_pci_driver);
 }
 
 module_init(jmicron_ide_init);
index 53bd645736d965b73eeee8f8ffaeacc12a193cce..13789060f407fd7dc1ff860d40a989e026e1a8ae 100644 (file)
@@ -137,7 +137,7 @@ static void __devinit superio_init_iops(struct hwif_s *hwif)
 static unsigned int ns87415_count = 0, ns87415_control[MAX_HWIFS] = { 0 };
 
 /*
- * This routine either enables/disables (according to drive->present)
+ * This routine either enables/disables (according to IDE_DFLAG_PRESENT)
  * the IRQ associated with the port (HWIF(drive)),
  * and selects either PIO or DMA handshaking for the next I/O operation.
  */
@@ -153,11 +153,15 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
 
        /* Adjust IRQ enable bit */
        bit = 1 << (8 + hwif->channel);
-       new = drive->present ? (new & ~bit) : (new | bit);
+
+       if (drive->dev_flags & IDE_DFLAG_PRESENT)
+               new &= ~bit;
+       else
+               new |= bit;
 
        /* Select PIO or DMA, DMA may only be selected for one drive/channel. */
-       bit   = 1 << (20 + drive->select.b.unit       + (hwif->channel << 1));
-       other = 1 << (20 + (1 - drive->select.b.unit) + (hwif->channel << 1));
+       bit   = 1 << (20 + (drive->dn & 1) + (hwif->channel << 1));
+       other = 1 << (20 + (1 - (drive->dn & 1)) + (hwif->channel << 1));
        new = use_dma ? ((new & ~other) | bit) : (new & ~bit);
 
        if (new != *old) {
@@ -187,7 +191,8 @@ static void ns87415_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
 
 static void ns87415_selectproc (ide_drive_t *drive)
 {
-       ns87415_prepare_drive (drive, drive->using_dma);
+       ns87415_prepare_drive(drive,
+                             !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
 }
 
 static int ns87415_dma_end(ide_drive_t *drive)
@@ -334,7 +339,7 @@ static const struct pci_device_id ns87415_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, ns87415_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver ns87415_pci_driver = {
        .name           = "NS87415_IDE",
        .id_table       = ns87415_pci_tbl,
        .probe          = ns87415_init_one,
@@ -345,12 +350,12 @@ static struct pci_driver driver = {
 
 static int __init ns87415_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&ns87415_pci_driver);
 }
 
 static void __exit ns87415_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&ns87415_pci_driver);
 }
 
 module_init(ns87415_ide_init);
index 3de11ddcf863f1e1295c1f47d45fd3a6bef33e23..6048eda3cd613711f05fa44226857bb66faff51c 100644 (file)
@@ -179,7 +179,7 @@ static void opti621_set_pio_mode(ide_drive_t *drive, const u8 pio)
        misc = addr_timings[clk][addr_pio];
 
        /* select Index-0/1 for Register-A/B */
-       write_reg(drive->select.b.unit, MISC_REG);
+       write_reg(drive->dn & 1, MISC_REG);
        /* set read cycle timings */
        write_reg(tim, READ_REG);
        /* set write cycle timings */
@@ -220,7 +220,7 @@ static const struct pci_device_id opti621_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, opti621_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver opti621_pci_driver = {
        .name           = "Opti621_IDE",
        .id_table       = opti621_pci_tbl,
        .probe          = opti621_init_one,
@@ -231,12 +231,12 @@ static struct pci_driver driver = {
 
 static int __init opti621_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&opti621_pci_driver);
 }
 
 static void __exit opti621_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&opti621_pci_driver);
 }
 
 module_init(opti621_ide_init);
index 9fc59962553b32fd5f4f72c32ec378d9fb09fe55..211ae46e3e0ca2101d0cf5bb1d8d7039422e95df 100644 (file)
@@ -561,7 +561,7 @@ static const struct pci_device_id pdc202new_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, pdc202new_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver pdc202new_pci_driver = {
        .name           = "Promise_IDE",
        .id_table       = pdc202new_pci_tbl,
        .probe          = pdc202new_init_one,
@@ -572,12 +572,12 @@ static struct pci_driver driver = {
 
 static int __init pdc202new_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&pdc202new_pci_driver);
 }
 
 static void __exit pdc202new_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&pdc202new_pci_driver);
 }
 
 module_init(pdc202new_ide_init);
index cb6d2a00c514a5624e5e4fa2caf1b0c938b7ab36..799557c25eefede0c583680ccf5fbb39d91510ca 100644 (file)
@@ -168,7 +168,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
 {
        if (drive->current_speed > XFER_UDMA_2)
                pdc_old_enable_66MHz_clock(drive->hwif);
-       if (drive->media != ide_disk || drive->addressing == 1) {
+       if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
                struct request *rq      = HWGROUP(drive)->rq;
                ide_hwif_t *hwif        = HWIF(drive);
                unsigned long high_16   = hwif->extra_base - 16;
@@ -188,7 +188,7 @@ static void pdc202xx_dma_start(ide_drive_t *drive)
 
 static int pdc202xx_dma_end(ide_drive_t *drive)
 {
-       if (drive->media != ide_disk || drive->addressing == 1) {
+       if (drive->media != ide_disk || (drive->dev_flags & IDE_DFLAG_LBA48)) {
                ide_hwif_t *hwif        = HWIF(drive);
                unsigned long high_16   = hwif->extra_base - 16;
                unsigned long atapi_reg = high_16 + (hwif->channel ? 0x24 : 0x20);
@@ -200,7 +200,7 @@ static int pdc202xx_dma_end(ide_drive_t *drive)
        }
        if (drive->current_speed > XFER_UDMA_2)
                pdc_old_disable_66MHz_clock(drive->hwif);
-       return __ide_dma_end(drive);
+       return ide_dma_end(drive);
 }
 
 static int pdc202xx_dma_test_irq(ide_drive_t *drive)
@@ -333,7 +333,7 @@ static const struct ide_dma_ops pdc20246_dma_ops = {
        .dma_setup              = ide_dma_setup,
        .dma_exec_cmd           = ide_dma_exec_cmd,
        .dma_start              = ide_dma_start,
-       .dma_end                = __ide_dma_end,
+       .dma_end                = ide_dma_end,
        .dma_test_irq           = pdc202xx_dma_test_irq,
        .dma_lost_irq           = pdc202xx_dma_lost_irq,
        .dma_timeout            = pdc202xx_dma_timeout,
@@ -426,7 +426,7 @@ static const struct pci_device_id pdc202xx_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, pdc202xx_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver pdc202xx_pci_driver = {
        .name           = "Promise_Old_IDE",
        .id_table       = pdc202xx_pci_tbl,
        .probe          = pdc202xx_init_one,
@@ -437,12 +437,12 @@ static struct pci_driver driver = {
 
 static int __init pdc202xx_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&pdc202xx_pci_driver);
 }
 
 static void __exit pdc202xx_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&pdc202xx_pci_driver);
 }
 
 module_init(pdc202xx_ide_init);
index a06c03f8e29539da2567dcb8563392d6078bec5a..d63f9fdca76bce87e37f4c6604ade546be5f6ab7 100644 (file)
@@ -215,17 +215,26 @@ static unsigned int init_chipset_ich(struct pci_dev *dev)
 }
 
 /**
- *     piix_dma_clear_irq      -       clear BMDMA status
- *     @drive: IDE drive to clear
+ *     ich_clear_irq   -       clear BMDMA status
+ *     @drive: IDE drive
  *
- *     Called from ide_intr() for PIO interrupts
- *     to clear BMDMA status as needed by ICHx
+ *     ICHx contollers set DMA INTR no matter DMA or PIO.
+ *     BMDMA status might need to be cleared even for
+ *     PIO interrupts to prevent spurious/lost IRQ.
  */
-static void piix_dma_clear_irq(ide_drive_t *drive)
+static void ich_clear_irq(ide_drive_t *drive)
 {
        ide_hwif_t *hwif = HWIF(drive);
        u8 dma_stat;
 
+       /*
+        * ide_dma_end() needs BMDMA status for error checking.
+        * So, skip clearing BMDMA status here and leave it
+        * to ide_dma_end() if this is DMA interrupt.
+        */
+       if (drive->waiting_for_dma || hwif->dma_base == 0)
+               return;
+
        /* clear the INTR & ERROR bits */
        dma_stat = inb(hwif->dma_base + ATA_DMA_STATUS);
        /* Should we force the bit as well ? */
@@ -249,6 +258,7 @@ static const struct ich_laptop ich_laptop[] = {
        { 0x27DF, 0x1025, 0x0110 },     /* ICH7 on Acer 3682WLMi */
        { 0x27DF, 0x1043, 0x1267 },     /* ICH7 on Asus W5F */
        { 0x27DF, 0x103C, 0x30A1 },     /* ICH7 on HP Compaq nc2400 */
+       { 0x27DF, 0x1071, 0xD221 },     /* ICH7 on Hercules EC-900 */
        { 0x24CA, 0x1025, 0x0061 },     /* ICH4 on Acer Aspire 2023WLMi */
        { 0x2653, 0x1043, 0x82D8 },     /* ICH6M on Asus Eee 701 */
        /* end marker */
@@ -293,21 +303,19 @@ static void __devinit init_hwif_piix(ide_hwif_t *hwif)
                hwif->ultra_mask = hwif->mwdma_mask = hwif->swdma_mask = 0;
 }
 
-static void __devinit init_hwif_ich(ide_hwif_t *hwif)
-{
-       init_hwif_piix(hwif);
-
-       /* ICHx need to clear the BMDMA status for all interrupts */
-       if (hwif->dma_base)
-               hwif->ide_dma_clear_irq = &piix_dma_clear_irq;
-}
-
 static const struct ide_port_ops piix_port_ops = {
        .set_pio_mode           = piix_set_pio_mode,
        .set_dma_mode           = piix_set_dma_mode,
        .cable_detect           = piix_cable_detect,
 };
 
+static const struct ide_port_ops ich_port_ops = {
+       .set_pio_mode           = piix_set_pio_mode,
+       .set_dma_mode           = piix_set_dma_mode,
+       .clear_irq              = ich_clear_irq,
+       .cable_detect           = piix_cable_detect,
+};
+
 #ifndef CONFIG_IA64
  #define IDE_HFLAGS_PIIX IDE_HFLAG_LEGACY_IRQS
 #else
@@ -331,9 +339,9 @@ static const struct ide_port_ops piix_port_ops = {
        { \
                .name           = DRV_NAME, \
                .init_chipset   = init_chipset_ich, \
-               .init_hwif      = init_hwif_ich, \
+               .init_hwif      = init_hwif_piix, \
                .enablebits     = {{0x41,0x80,0x80}, {0x43,0x80,0x80}}, \
-               .port_ops       = &piix_port_ops, \
+               .port_ops       = &ich_port_ops, \
                .host_flags     = IDE_HFLAGS_PIIX, \
                .pio_mask       = ATA_PIO4, \
                .swdma_mask     = ATA_SWDMA2_ONLY, \
@@ -444,7 +452,7 @@ static const struct pci_device_id piix_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, piix_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver piix_pci_driver = {
        .name           = "PIIX_IDE",
        .id_table       = piix_pci_tbl,
        .probe          = piix_init_one,
@@ -456,12 +464,12 @@ static struct pci_driver driver = {
 static int __init piix_ide_init(void)
 {
        piix_check_450nx();
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&piix_pci_driver);
 }
 
 static void __exit piix_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&piix_pci_driver);
 }
 
 module_init(piix_ide_init);
index c117a068761be47c585c6e259826a658d9c62613..7daf0135cbac678a0e22dcda2c388ceebf843f9b 100644 (file)
@@ -59,7 +59,7 @@ static const struct pci_device_id rz1000_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, rz1000_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver rz1000_pci_driver = {
        .name           = "RZ1000_IDE",
        .id_table       = rz1000_pci_tbl,
        .probe          = rz1000_init_one,
@@ -68,12 +68,12 @@ static struct pci_driver driver = {
 
 static int __init rz1000_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&rz1000_pci_driver);
 }
 
 static void __exit rz1000_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&rz1000_pci_driver);
 }
 
 module_init(rz1000_ide_init);
index bdc1fed412604a72b0d206c3a9179d5f8253b2af..f1a8758e3a99f7d8b6953782c4150c35fefb8097 100644 (file)
@@ -126,7 +126,6 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
 {
        ide_hwif_t              *hwif = HWIF(drive);
        struct pci_dev          *dev = to_pci_dev(hwif->dev);
-       int                     unit = drive->select.b.unit;
        unsigned int            reg, timings;
        unsigned short          pci_clock;
        unsigned int            basereg = hwif->channel ? 0x50 : 0x40;
@@ -155,7 +154,7 @@ static void sc1200_set_dma_mode(ide_drive_t *drive, const u8 mode)
        else
                timings = mwdma_timing[pci_clock][mode - XFER_MW_DMA_0];
 
-       if (unit == 0) {                        /* are we configuring drive0? */
+       if ((drive->dn & 1) == 0) {
                pci_read_config_dword(dev, basereg + 4, &reg);
                timings |= reg & 0x80000000;    /* preserve PIO format bit */
                pci_write_config_dword(dev, basereg + 4, timings);
@@ -216,7 +215,8 @@ static void sc1200_set_pio_mode(ide_drive_t *drive, const u8 pio)
        if (mode != -1) {
                printk("SC1200: %s: changing (U)DMA mode\n", drive->name);
                ide_dma_off_quietly(drive);
-               if (ide_set_dma_mode(drive, mode) == 0 && drive->using_dma)
+               if (ide_set_dma_mode(drive, mode) == 0 &&
+                   (drive->dev_flags & IDE_DFLAG_USING_DMA))
                        hwif->dma_ops->dma_host_set(drive, 1);
                return;
        }
@@ -328,7 +328,7 @@ static const struct pci_device_id sc1200_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, sc1200_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver sc1200_pci_driver = {
        .name           = "SC1200_IDE",
        .id_table       = sc1200_pci_tbl,
        .probe          = sc1200_init_one,
@@ -341,12 +341,12 @@ static struct pci_driver driver = {
 
 static int __init sc1200_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&sc1200_pci_driver);
 }
 
 static void __exit sc1200_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&sc1200_pci_driver);
 }
 
 module_init(sc1200_ide_init);
index e92a874b31dfa07bc7334f6795bacac3927e1258..9ce1d8059921932de41938cc874412088b75b4ee 100644 (file)
@@ -291,7 +291,7 @@ static void scc_set_dma_mode(ide_drive_t *drive, const u8 speed)
 static void scc_dma_host_set(ide_drive_t *drive, int on)
 {
        ide_hwif_t *hwif = drive->hwif;
-       u8 unit = (drive->select.b.unit & 0x01);
+       u8 unit = drive->dn & 1;
        u8 dma_stat = scc_ide_inb(hwif->dma_base + 4);
 
        if (on)
@@ -353,7 +353,6 @@ static void scc_dma_start(ide_drive_t *drive)
 
        /* start DMA */
        scc_ide_outb(dma_cmd | 1, hwif->dma_base);
-       hwif->dma = 1;
        wmb();
 }
 
@@ -374,7 +373,6 @@ static int __scc_dma_end(ide_drive_t *drive)
        /* purge DMA mappings */
        ide_destroy_dmatable(drive);
        /* verify good DMA status */
-       hwif->dma = 0;
        wmb();
        return (dma_stat & 7) != 4 ? (0x10 | dma_stat) : 0;
 }
@@ -511,9 +509,6 @@ static int scc_dma_test_irq(ide_drive_t *drive)
        if (int_stat & INTSTS_IOIRQS)
                return 1;
 
-       if (!drive->waiting_for_dma)
-               printk(KERN_WARNING "%s: (%s) called while not waiting\n",
-                       drive->name, __func__);
        return 0;
 }
 
@@ -710,7 +705,7 @@ static void scc_tf_load(ide_drive_t *drive, ide_task_t *task)
                scc_ide_outb(tf->lbah, io_ports->lbah_addr);
 
        if (task->tf_flags & IDE_TFLAG_OUT_DEVICE)
-               scc_ide_outb((tf->device & HIHI) | drive->select.all,
+               scc_ide_outb((tf->device & HIHI) | drive->select,
                             io_ports->device_addr);
 }
 
@@ -826,6 +821,12 @@ static void __devinit init_iops_scc(ide_hwif_t *hwif)
        init_mmio_iops_scc(hwif);
 }
 
+static int __devinit scc_init_dma(ide_hwif_t *hwif,
+                                 const struct ide_port_info *d)
+{
+       return ide_allocate_dma_engine(hwif);
+}
+
 static u8 scc_cable_detect(ide_hwif_t *hwif)
 {
        return ATA_CBL_PATA80;
@@ -890,6 +891,7 @@ static const struct ide_dma_ops scc_dma_ops = {
   {                                                    \
       .name            = name_str,                     \
       .init_iops       = init_iops_scc,                \
+      .init_dma                = scc_init_dma,                 \
       .init_hwif       = init_hwif_scc,                \
       .tp_ops          = &scc_tp_ops,          \
       .port_ops                = &scc_port_ops,                \
@@ -927,13 +929,6 @@ static void __devexit scc_remove(struct pci_dev *dev)
 {
        struct scc_ports *ports = pci_get_drvdata(dev);
        struct ide_host *host = ports->host;
-       ide_hwif_t *hwif = host->ports[0];
-
-       if (hwif->dmatable_cpu) {
-               pci_free_consistent(dev, PRD_ENTRIES * PRD_BYTES,
-                                   hwif->dmatable_cpu, hwif->dmatable_dma);
-               hwif->dmatable_cpu = NULL;
-       }
 
        ide_host_remove(host);
 
@@ -949,7 +944,7 @@ static const struct pci_device_id scc_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, scc_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver scc_pci_driver = {
        .name = "SCC IDE",
        .id_table = scc_pci_tbl,
        .probe = scc_init_one,
@@ -958,14 +953,14 @@ static struct pci_driver driver = {
 
 static int scc_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&scc_pci_driver);
 }
 
 module_init(scc_ide_init);
 /* -- No exit code?
 static void scc_ide_exit(void)
 {
-       ide_pci_unregister_driver(&driver);
+       ide_pci_unregister_driver(&scc_pci_driver);
 }
 module_exit(scc_ide_exit);
  */
index 3dff2aea317e88ae261d5050b9b0ae3c1023dd7e..437bc919dafd8ae52d58e169ce4a2e373ca355b9 100644 (file)
@@ -153,7 +153,7 @@ static void svwks_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
-       u8 unit                 = (drive->select.b.unit & 0x01);
+       u8 unit                 = drive->dn & 1;
 
        u8 ultra_enable  = 0, ultra_timing = 0, dma_timing = 0;
 
@@ -443,7 +443,7 @@ static const struct pci_device_id svwks_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, svwks_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver svwks_pci_driver = {
        .name           = "Serverworks_IDE",
        .id_table       = svwks_pci_tbl,
        .probe          = svwks_init_one,
@@ -454,12 +454,12 @@ static struct pci_driver driver = {
 
 static int __init svwks_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&svwks_pci_driver);
 }
 
 static void __exit svwks_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&svwks_pci_driver);
 }
 
 module_init(svwks_ide_init);
index 1017fb4f63173d2891313c636f221c6c4d295d4d..dd634541ce361a62a4789484cdf89fe6a85584f3 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2003-2006 Silicon Graphics, Inc.  All Rights Reserved.
+ * Copyright (C) 2008 MontaVista Software, Inc.
  *
  * This program is free software; you can redistribute it and/or modify it
  * under the terms of version 2 of the GNU General Public License
@@ -150,7 +151,7 @@ sgiioc4_clearirq(ide_drive_t * drive)
                int count = 0;
 
                stat = sgiioc4_read_status(hwif);
-               while ((stat & 0x80) && (count++ < 100)) {
+               while ((stat & ATA_BUSY) && (count++ < 100)) {
                        udelay(1);
                        stat = sgiioc4_read_status(hwif);
                }
@@ -310,7 +311,7 @@ static u8 sgiioc4_read_status(ide_hwif_t *hwif)
        u8 reg = (u8) readb((void __iomem *) port);
 
        if ((port & 0xFFF) == 0x11C) {  /* Status register of IOC4 */
-               if (reg & 0x51) {       /* Not busy...check for interrupt */
+               if (!(reg & ATA_BUSY)) { /* Not busy... check for interrupt */
                        unsigned long other_ir = port - 0x110;
                        unsigned int intr_reg = (u32) readl((void __iomem *) other_ir);
 
@@ -338,35 +339,31 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
        if (dma_base == 0)
                return -1;
 
-       printk(KERN_INFO "%s: BM-DMA at 0x%04lx-0x%04lx\n", hwif->name,
-              dma_base, dma_base + num_ports - 1);
+       printk(KERN_INFO "    %s: MMIO-DMA\n", hwif->name);
 
-       if (!request_mem_region(dma_base, num_ports, hwif->name)) {
-               printk(KERN_ERR
-                      "%s(%s) -- ERROR, Addresses 0x%p to 0x%p "
-                      "ALREADY in use\n",
-                      __func__, hwif->name, (void *) dma_base,
-                      (void *) dma_base + num_ports - 1);
+       if (request_mem_region(dma_base, num_ports, hwif->name) == NULL) {
+               printk(KERN_ERR "%s(%s) -- ERROR: addresses 0x%08lx to 0x%08lx "
+                      "already in use\n", __func__, hwif->name,
+                      dma_base, dma_base + num_ports - 1);
                return -1;
        }
 
        virt_dma_base = ioremap(dma_base, num_ports);
        if (virt_dma_base == NULL) {
-               printk(KERN_ERR
-                      "%s(%s) -- ERROR, Unable to map addresses 0x%lx to 0x%lx\n",
-                      __func__, hwif->name, dma_base, dma_base + num_ports - 1);
+               printk(KERN_ERR "%s(%s) -- ERROR: unable to map addresses "
+                      "0x%lx to 0x%lx\n", __func__, hwif->name,
+                      dma_base, dma_base + num_ports - 1);
                goto dma_remap_failure;
        }
        hwif->dma_base = (unsigned long) virt_dma_base;
 
-       hwif->dmatable_cpu = pci_alloc_consistent(dev,
-                                         IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
-                                         &hwif->dmatable_dma);
+       hwif->sg_max_nents = IOC4_PRD_ENTRIES;
 
-       if (!hwif->dmatable_cpu)
-               goto dma_pci_alloc_failure;
+       hwif->prd_max_nents = IOC4_PRD_ENTRIES;
+       hwif->prd_ent_size = IOC4_PRD_BYTES;
 
-       hwif->sg_max_nents = IOC4_PRD_ENTRIES;
+       if (ide_allocate_dma_engine(hwif))
+               goto dma_pci_alloc_failure;
 
        pad = pci_alloc_consistent(dev, IOC4_IDE_CACHELINE_SIZE,
                                   (dma_addr_t *)&hwif->extra_base);
@@ -375,13 +372,11 @@ ide_dma_sgiioc4(ide_hwif_t *hwif, const struct ide_port_info *d)
                return 0;
        }
 
-       pci_free_consistent(dev, IOC4_PRD_ENTRIES * IOC4_PRD_BYTES,
-                           hwif->dmatable_cpu, hwif->dmatable_dma);
-       printk(KERN_INFO
-              "%s() -- Error! Unable to allocate DMA Maps for drive %s\n",
+       ide_release_dma_engine(hwif);
+
+       printk(KERN_ERR "%s(%s) -- ERROR: Unable to allocate DMA maps\n",
               __func__, hwif->name);
-       printk(KERN_INFO
-              "Changing from DMA to PIO mode for Drive %s\n", hwif->name);
+       printk(KERN_INFO "%s: changing from DMA to PIO mode", hwif->name);
 
 dma_pci_alloc_failure:
        iounmap(virt_dma_base);
@@ -617,14 +612,12 @@ sgiioc4_ide_setup_pci_device(struct pci_dev *dev)
        irqport = (unsigned long) virt_base + IOC4_INTR_OFFSET;
 
        cmd_phys_base = bar0 + IOC4_CMD_OFFSET;
-       if (!request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
-           DRV_NAME)) {
-               printk(KERN_ERR
-                       "%s %s: -- ERROR, Addresses "
-                       "0x%p to 0x%p ALREADY in use\n",
-                      DRV_NAME, pci_name(dev), (void *)cmd_phys_base,
-                      (void *) cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
-               return -ENOMEM;
+       if (request_mem_region(cmd_phys_base, IOC4_CMD_CTL_BLK_SIZE,
+                              DRV_NAME) == NULL) {
+               printk(KERN_ERR "%s %s -- ERROR: addresses 0x%08lx to 0x%08lx "
+                      "already in use\n", DRV_NAME, pci_name(dev),
+                      cmd_phys_base, cmd_phys_base + IOC4_CMD_CTL_BLK_SIZE);
+               return -EBUSY;
        }
 
        /* Initialize the IO registers */
index 174a873b4c6405229e48eb2714998cf9bef8ce69..eb4faf92c5719ceb3c95c2f23b8e40bf3a96d9db 100644 (file)
@@ -116,13 +116,14 @@ static inline unsigned long siimage_seldev(ide_drive_t *drive, int r)
 {
        ide_hwif_t *hwif        = HWIF(drive);
        unsigned long base      = (unsigned long)hwif->hwif_data;
+       u8 unit                 = drive->dn & 1;
 
        base += 0xA0 + r;
        if (hwif->host_flags & IDE_HFLAG_MMIO)
                base += hwif->channel << 6;
        else
                base += hwif->channel << 4;
-       base |= drive->select.b.unit << drive->select.b.unit;
+       base |= unit << unit;
        return base;
 }
 
@@ -255,7 +256,7 @@ static void sil_set_pio_mode(ide_drive_t *drive, u8 pio)
        u8 addr_mask            = hwif->channel ? (mmio ? 0xF4 : 0x84)
                                                : (mmio ? 0xB4 : 0x80);
        u8 mode                 = 0;
-       u8 unit                 = drive->select.b.unit;
+       u8 unit                 = drive->dn & 1;
 
        /* trim *taskfile* PIO to the slowest of the master/slave */
        if (pair) {
@@ -301,9 +302,9 @@ static void sil_set_dma_mode(ide_drive_t *drive, const u8 speed)
 
        ide_hwif_t *hwif        = HWIF(drive);
        struct pci_dev *dev     = to_pci_dev(hwif->dev);
-       u16 ultra = 0, multi    = 0;
-       u8 mode = 0, unit       = drive->select.b.unit;
        unsigned long base      = (unsigned long)hwif->hwif_data;
+       u16 ultra = 0, multi    = 0;
+       u8 mode = 0, unit       = drive->dn & 1;
        u8 mmio                 = (hwif->host_flags & IDE_HFLAG_MMIO) ? 1 : 0;
        u8 scsc = 0, addr_mask  = hwif->channel ? (mmio ? 0xF4 : 0x84)
                                                : (mmio ? 0xB4 : 0x80);
@@ -712,7 +713,7 @@ static const struct ide_dma_ops sil_dma_ops = {
        .dma_setup              = ide_dma_setup,
        .dma_exec_cmd           = ide_dma_exec_cmd,
        .dma_start              = ide_dma_start,
-       .dma_end                = __ide_dma_end,
+       .dma_end                = ide_dma_end,
        .dma_test_irq           = siimage_dma_test_irq,
        .dma_timeout            = ide_dma_timeout,
        .dma_lost_irq           = ide_dma_lost_irq,
@@ -829,7 +830,7 @@ static const struct pci_device_id siimage_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, siimage_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver siimage_pci_driver = {
        .name           = "SiI_IDE",
        .id_table       = siimage_pci_tbl,
        .probe          = siimage_init_one,
@@ -840,12 +841,12 @@ static struct pci_driver driver = {
 
 static int __init siimage_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&siimage_pci_driver);
 }
 
 static void __exit siimage_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&siimage_pci_driver);
 }
 
 module_init(siimage_ide_init);
index 734dd41f1f679c649fc635d169f511eb7661518b..ad32e18c5ba368abbc8f5925181845c78b262df3 100644 (file)
@@ -605,7 +605,7 @@ static const struct pci_device_id sis5513_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, sis5513_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver sis5513_pci_driver = {
        .name           = "SIS_IDE",
        .id_table       = sis5513_pci_tbl,
        .probe          = sis5513_init_one,
@@ -616,12 +616,12 @@ static struct pci_driver driver = {
 
 static int __init sis5513_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&sis5513_pci_driver);
 }
 
 static void __exit sis5513_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&sis5513_pci_driver);
 }
 
 module_init(sis5513_ide_init);
index 37a6b7bdc0403ac78ef95b89a1a31217c191aa08..84dc33602ff86277bcc69c39484befda8fca018c 100644 (file)
@@ -207,7 +207,7 @@ static int sl82c105_dma_end(ide_drive_t *drive)
 
        DBG(("%s(drive:%s)\n", __func__, drive->name));
 
-       ret = __ide_dma_end(drive);
+       ret = ide_dma_end(drive);
 
        pci_write_config_word(dev, reg, drive->drive_data);
 
@@ -345,7 +345,7 @@ static const struct pci_device_id sl82c105_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, sl82c105_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver sl82c105_pci_driver = {
        .name           = "W82C105_IDE",
        .id_table       = sl82c105_pci_tbl,
        .probe          = sl82c105_init_one,
@@ -356,12 +356,12 @@ static struct pci_driver driver = {
 
 static int __init sl82c105_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&sl82c105_pci_driver);
 }
 
 static void __exit sl82c105_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&sl82c105_pci_driver);
 }
 
 module_init(sl82c105_ide_init);
index a9551a13ac5717f014ea6fb0c27c2a7ac6bb1cff..0f759e4ed7799779e4492790b58ebf2147d1dcc5 100644 (file)
@@ -154,7 +154,7 @@ static const struct pci_device_id slc90e66_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, slc90e66_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver slc90e66_pci_driver = {
        .name           = "SLC90e66_IDE",
        .id_table       = slc90e66_pci_tbl,
        .probe          = slc90e66_init_one,
@@ -165,12 +165,12 @@ static struct pci_driver driver = {
 
 static int __init slc90e66_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&slc90e66_pci_driver);
 }
 
 static void __exit slc90e66_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&slc90e66_pci_driver);
 }
 
 module_init(slc90e66_ide_init);
index 927277c54ec9609d542605234761efa58a7cbce2..93e2cce4b296f5a55c50f32d5f0a4fe9f9133ff5 100644 (file)
@@ -186,7 +186,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
        .dma_setup              = ide_dma_setup,
        .dma_exec_cmd           = ide_dma_exec_cmd,
        .dma_start              = tc86c001_dma_start,
-       .dma_end                = __ide_dma_end,
+       .dma_end                = ide_dma_end,
        .dma_test_irq           = ide_dma_test_irq,
        .dma_lost_irq           = ide_dma_lost_irq,
        .dma_timeout            = ide_dma_timeout,
@@ -245,7 +245,7 @@ static const struct pci_device_id tc86c001_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, tc86c001_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver tc86c001_pci_driver = {
        .name           = "TC86C001",
        .id_table       = tc86c001_pci_tbl,
        .probe          = tc86c001_init_one,
@@ -254,12 +254,12 @@ static struct pci_driver driver = {
 
 static int __init tc86c001_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&tc86c001_pci_driver);
 }
 
 static void __exit tc86c001_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&tc86c001_pci_driver);
 }
 
 module_init(tc86c001_ide_init);
index be8715dcee05ec735c35c8b88eb2493f0305736e..b6ff40336aa993c5960bc4754cb0dec40793ee32 100644 (file)
@@ -38,13 +38,12 @@ static void triflex_set_mode(ide_drive_t *drive, const u8 speed)
 {
        ide_hwif_t *hwif = HWIF(drive);
        struct pci_dev *dev = to_pci_dev(hwif->dev);
-       u8 channel_offset = hwif->channel ? 0x74 : 0x70;
-       u16 timing = 0;
        u32 triflex_timings = 0;
-       u8 unit = (drive->select.b.unit & 0x01);
-       
+       u16 timing = 0;
+       u8 channel_offset = hwif->channel ? 0x74 : 0x70, unit = drive->dn & 1;
+
        pci_read_config_dword(dev, channel_offset, &triflex_timings);
-       
+
        switch(speed) {
                case XFER_MW_DMA_2:
                        timing = 0x0103; 
@@ -114,7 +113,7 @@ static const struct pci_device_id triflex_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, triflex_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver triflex_pci_driver = {
        .name           = "TRIFLEX_IDE",
        .id_table       = triflex_pci_tbl,
        .probe          = triflex_init_one,
@@ -125,12 +124,12 @@ static struct pci_driver driver = {
 
 static int __init triflex_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&triflex_pci_driver);
 }
 
 static void __exit triflex_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&triflex_pci_driver);
 }
 
 module_init(triflex_ide_init);
index 4dfbc6a68b5b371827b8ab355caae6941baffde7..75ea6152656663b6673c536e7903e4d2eb6bafda 100644 (file)
@@ -161,7 +161,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
        }
 
        /* enable IRQ if not probing */
-       if (drive->present) {
+       if (drive->dev_flags & IDE_DFLAG_PRESENT) {
                reg = inw(hwif->config_data + 3);
                reg &= 0x13;
                reg &= ~(1 << hwif->channel);
@@ -173,7 +173,7 @@ static void trm290_prepare_drive (ide_drive_t *drive, unsigned int use_dma)
 
 static void trm290_selectproc (ide_drive_t *drive)
 {
-       trm290_prepare_drive(drive, drive->using_dma);
+       trm290_prepare_drive(drive, !!(drive->dev_flags & IDE_DFLAG_USING_DMA));
 }
 
 static void trm290_dma_exec_cmd(ide_drive_t *drive, u8 command)
@@ -350,7 +350,7 @@ static const struct pci_device_id trm290_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, trm290_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver trm290_pci_driver = {
        .name           = "TRM290_IDE",
        .id_table       = trm290_pci_tbl,
        .probe          = trm290_init_one,
@@ -359,12 +359,12 @@ static struct pci_driver driver = {
 
 static int __init trm290_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&trm290_pci_driver);
 }
 
 static void __exit trm290_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&trm290_pci_driver);
 }
 
 module_init(trm290_ide_init);
index acacdaab69c2345a817b2b048bd19733ee10a072..2a812d3207e97d55be27c5f1363af67f96b90bdb 100644 (file)
@@ -487,7 +487,7 @@ static const struct pci_device_id via_pci_tbl[] = {
 };
 MODULE_DEVICE_TABLE(pci, via_pci_tbl);
 
-static struct pci_driver driver = {
+static struct pci_driver via_pci_driver = {
        .name           = "VIA_IDE",
        .id_table       = via_pci_tbl,
        .probe          = via_init_one,
@@ -498,12 +498,12 @@ static struct pci_driver driver = {
 
 static int __init via_ide_init(void)
 {
-       return ide_pci_register_driver(&driver);
+       return ide_pci_register_driver(&via_pci_driver);
 }
 
 static void __exit via_ide_exit(void)
 {
-       pci_unregister_driver(&driver);
+       pci_unregister_driver(&via_pci_driver);
 }
 
 module_init(via_ide_init);
index c3432da78d5227b46f106ac995af650ac7d2c0fd..2e19d6298536f2fb94d3e0a8a1b5fd08877f3734 100644 (file)
@@ -430,10 +430,7 @@ pmac_ide_selectproc(ide_drive_t *drive)
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
 
-       if (pmif == NULL)
-               return;
-
-       if (drive->select.b.unit & 0x01)
+       if (drive->dn & 1)
                writel(pmif->timings[1], PMAC_IDE_REG(IDE_TIMING_CONFIG));
        else
                writel(pmif->timings[0], PMAC_IDE_REG(IDE_TIMING_CONFIG));
@@ -452,10 +449,7 @@ pmac_ide_kauai_selectproc(ide_drive_t *drive)
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
 
-       if (pmif == NULL)
-               return;
-
-       if (drive->select.b.unit & 0x01) {
+       if (drive->dn & 1) {
                writel(pmif->timings[1], PMAC_IDE_REG(IDE_KAUAI_PIO_CONFIG));
                writel(pmif->timings[3], PMAC_IDE_REG(IDE_KAUAI_ULTRA_CONFIG));
        } else {
@@ -475,9 +469,6 @@ pmac_ide_do_update_timings(ide_drive_t *drive)
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
 
-       if (pmif == NULL)
-               return;
-
        if (pmif->kind == controller_sh_ata6 ||
            pmif->kind == controller_un_ata6 ||
            pmif->kind == controller_k2_ata6)
@@ -524,11 +515,8 @@ pmac_ide_set_pio_mode(ide_drive_t *drive, const u8 pio)
        unsigned accessTime, recTime;
        unsigned int cycle_time;
 
-       if (pmif == NULL)
-               return;
-               
        /* which drive is it ? */
-       timings = &pmif->timings[drive->select.b.unit & 0x01];
+       timings = &pmif->timings[drive->dn & 1];
        t = *timings;
 
        cycle_time = ide_pio_cycle_time(drive, pio);
@@ -805,9 +793,9 @@ static void pmac_ide_set_dma_mode(ide_drive_t *drive, const u8 speed)
        ide_hwif_t *hwif = drive->hwif;
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
-       int unit = (drive->select.b.unit & 0x01);
        int ret = 0;
        u32 *timings, *timings2, tl[2];
+       u8 unit = drive->dn & 1;
 
        timings = &pmif->timings[unit];
        timings2 = &pmif->timings[unit+2];
@@ -966,11 +954,11 @@ static void pmac_ide_init_dev(ide_drive_t *drive)
        if (pmif->mediabay) {
 #ifdef CONFIG_PMAC_MEDIABAY
                if (check_media_bay_by_base(pmif->regbase, MB_CD) == 0) {
-                       drive->noprobe = 0;
+                       drive->dev_flags &= ~IDE_DFLAG_NOPROBE;
                        return;
                }
 #endif
-               drive->noprobe = 1;
+               drive->dev_flags |= IDE_DFLAG_NOPROBE;
        }
 }
 
@@ -1535,18 +1523,6 @@ use_pio_instead:
        return 0; /* revert to PIO for this request */
 }
 
-/* Teardown mappings after DMA has completed.  */
-static void
-pmac_ide_destroy_dmatable (ide_drive_t *drive)
-{
-       ide_hwif_t *hwif = drive->hwif;
-
-       if (hwif->sg_nents) {
-               ide_destroy_dmatable(drive);
-               hwif->sg_nents = 0;
-       }
-}
-
 /*
  * Prepare a DMA transfer. We build the DMA table, adjust the timings for
  * a read on KeyLargo ATA/66 and mark us as waiting for DMA completion
@@ -1558,12 +1534,7 @@ pmac_ide_dma_setup(ide_drive_t *drive)
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
        struct request *rq = HWGROUP(drive)->rq;
-       u8 unit = (drive->select.b.unit & 0x01);
-       u8 ata4;
-
-       if (pmif == NULL)
-               return 1;
-       ata4 = (pmif->kind == controller_kl_ata4);      
+       u8 unit = drive->dn & 1, ata4 = (pmif->kind == controller_kl_ata4);
 
        if (!pmac_ide_build_dmatable(drive, rq)) {
                ide_map_sg(drive, rq);
@@ -1617,17 +1588,15 @@ pmac_ide_dma_end (ide_drive_t *drive)
        ide_hwif_t *hwif = drive->hwif;
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
-       volatile struct dbdma_regs __iomem *dma;
+       volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
        u32 dstat;
-       
-       if (pmif == NULL)
-               return 0;
-       dma = pmif->dma_regs;
 
        drive->waiting_for_dma = 0;
        dstat = readl(&dma->status);
        writel(((RUN|WAKE|DEAD) << 16), &dma->control);
-       pmac_ide_destroy_dmatable(drive);
+
+       ide_destroy_dmatable(drive);
+
        /* verify good dma status. we don't check for ACTIVE beeing 0. We should...
         * in theory, but with ATAPI decices doing buffer underruns, that would
         * cause us to disable DMA, which isn't what we want
@@ -1647,13 +1616,9 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
        ide_hwif_t *hwif = drive->hwif;
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
-       volatile struct dbdma_regs __iomem *dma;
+       volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
        unsigned long status, timeout;
 
-       if (pmif == NULL)
-               return 0;
-       dma = pmif->dma_regs;
-
        /* We have to things to deal with here:
         * 
         * - The dbdma won't stop if the command was started
@@ -1672,9 +1637,6 @@ pmac_ide_dma_test_irq (ide_drive_t *drive)
        status = readl(&dma->status);
        if (!(status & ACTIVE))
                return 1;
-       if (!drive->waiting_for_dma)
-               printk(KERN_WARNING "ide%d, ide_dma_test_irq \
-                       called while not waiting\n", HWIF(drive)->index);
 
        /* If dbdma didn't execute the STOP command yet, the
         * active bit is still set. We consider that we aren't
@@ -1709,14 +1671,9 @@ pmac_ide_dma_lost_irq (ide_drive_t *drive)
        ide_hwif_t *hwif = drive->hwif;
        pmac_ide_hwif_t *pmif =
                (pmac_ide_hwif_t *)dev_get_drvdata(hwif->gendev.parent);
-       volatile struct dbdma_regs __iomem *dma;
-       unsigned long status;
-
-       if (pmif == NULL)
-               return;
-       dma = pmif->dma_regs;
+       volatile struct dbdma_regs __iomem *dma = pmif->dma_regs;
+       unsigned long status = readl(&dma->status);
 
-       status = readl(&dma->status);
        printk(KERN_ERR "ide-pmac lost interrupt, dma status: %lx\n", status);
 }
 
index daa9d4220331b06e68b9100caad9c5e98065a48f..82ec6b1b646782276363f769bc73e96226237459 100644 (file)
@@ -458,35 +458,35 @@ static int hp_sdc_rtc_proc_output (char *buf)
                p += sprintf(p, "i8042 rtc\t: READ FAILED!\n");
        } else {
                p += sprintf(p, "i8042 rtc\t: %ld.%02d seconds\n", 
-                            tv.tv_sec, tv.tv_usec/1000);
+                            tv.tv_sec, (int)tv.tv_usec/1000);
        }
 
        if (hp_sdc_rtc_read_fhs(&tv)) {
                p += sprintf(p, "handshake\t: READ FAILED!\n");
        } else {
                p += sprintf(p, "handshake\t: %ld.%02d seconds\n", 
-                            tv.tv_sec, tv.tv_usec/1000);
+                            tv.tv_sec, (int)tv.tv_usec/1000);
        }
 
        if (hp_sdc_rtc_read_mt(&tv)) {
                p += sprintf(p, "alarm\t\t: READ FAILED!\n");
        } else {
                p += sprintf(p, "alarm\t\t: %ld.%02d seconds\n", 
-                            tv.tv_sec, tv.tv_usec/1000);
+                            tv.tv_sec, (int)tv.tv_usec/1000);
        }
 
        if (hp_sdc_rtc_read_dt(&tv)) {
                p += sprintf(p, "delay\t\t: READ FAILED!\n");
        } else {
                p += sprintf(p, "delay\t\t: %ld.%02d seconds\n", 
-                            tv.tv_sec, tv.tv_usec/1000);
+                            tv.tv_sec, (int)tv.tv_usec/1000);
        }
 
        if (hp_sdc_rtc_read_ct(&tv)) {
                p += sprintf(p, "periodic\t: READ FAILED!\n");
        } else {
                p += sprintf(p, "periodic\t: %ld.%02d seconds\n", 
-                            tv.tv_sec, tv.tv_usec/1000);
+                            tv.tv_sec, (int)tv.tv_usec/1000);
        }
 
         p += sprintf(p,
index 0d395979b2d19c2a35ddb31e6d8c915c363fcfd9..bfe49243f38bf571d5d99e2f36c3d42b569ea6f3 100644 (file)
@@ -323,7 +323,7 @@ static void hp_sdc_tasklet(unsigned long foo)
                         * it back to the application. and be less verbose.
                         */
                        printk(KERN_WARNING PREFIX "read timeout (%ius)!\n",
-                              tv.tv_usec - hp_sdc.rtv.tv_usec);
+                              (int)(tv.tv_usec - hp_sdc.rtv.tv_usec));
                        curr->idx += hp_sdc.rqty;
                        hp_sdc.rqty = 0;
                        tmp = curr->seq[curr->actidx];
index a5b941c327f71477eecda3edb0f9b4c02acd4dda..c72565520e418cdad31796d9f310f4f103636117 100644 (file)
@@ -154,83 +154,50 @@ static void avmcs_detach(struct pcmcia_device *link)
     
 ======================================================================*/
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
+static int avmcs_configcheck(struct pcmcia_device *p_dev,
+                            cistpl_cftable_entry_t *cf,
+                            cistpl_cftable_entry_t *dflt,
+                            unsigned int vcc,
+                            void *priv_data)
 {
-    int i = pcmcia_get_tuple_data(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_first_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
-
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_next_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
+       if (cf->io.nwin <= 0)
+               return -ENODEV;
+
+       p_dev->io.BasePort1 = cf->io.win[0].base;
+       p_dev->io.NumPorts1 = cf->io.win[0].len;
+       p_dev->io.NumPorts2 = 0;
+       printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
+              p_dev->io.BasePort1,
+              p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
+       return pcmcia_request_io(p_dev, &p_dev->io);
 }
 
 static int avmcs_config(struct pcmcia_device *link)
 {
-    tuple_t tuple;
-    cisparse_t parse;
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
     local_info_t *dev;
     int i;
-    u_char buf[64];
     char devname[128];
     int cardtype;
     int (*addcard)(unsigned int port, unsigned irq);
 
     dev = link->priv;
 
-    do {
-       devname[0] = 0;
-       if (link->prod_id[1])
-               strlcpy(devname, link->prod_id[1], sizeof(devname));
+    devname[0] = 0;
+    if (link->prod_id[1])
+           strlcpy(devname, link->prod_id[1], sizeof(devname));
 
-       /*
-         * find IO port
-         */
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       i = first_tuple(link, &tuple, &parse);
-       while (i == CS_SUCCESS) {
-           if (cf->io.nwin > 0) {
-               link->conf.ConfigIndex = cf->index;
-               link->io.BasePort1 = cf->io.win[0].base;
-               link->io.NumPorts1 = cf->io.win[0].len;
-               link->io.NumPorts2 = 0;
-                printk(KERN_INFO "avm_cs: testing i/o %#x-%#x\n",
-                       link->io.BasePort1,
-                       link->io.BasePort1+link->io.NumPorts1-1);
-               i = pcmcia_request_io(link, &link->io);
-               if (i == CS_SUCCESS) goto found_port;
-           }
-           i = next_tuple(link, &tuple, &parse);
-       }
-
-found_port:
-       if (i != CS_SUCCESS) {
-           cs_error(link, RequestIO, i);
-           break;
-       }
+    /*
+     * find IO port
+     */
+    if (pcmcia_loop_config(link, avmcs_configcheck, NULL))
+           return -ENODEV;
 
+    do {
        /*
         * allocate an interrupt line
         */
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
            cs_error(link, RequestIRQ, i);
            /* undo */
            pcmcia_disable_device(link);
@@ -241,7 +208,7 @@ found_port:
          * configure the PCMCIA socket
          */
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
            cs_error(link, RequestConfiguration, i);
            pcmcia_disable_device(link);
            break;
index fc6cc2c065b807ac72c44992bb885a1d92e6ec0d..23560c897ec361d59526ffa1d36fad6264ddadcb 100644 (file)
@@ -174,38 +174,29 @@ static void avma1cs_detach(struct pcmcia_device *link)
     
 ======================================================================*/
 
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
+static int avma1cs_configcheck(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cf,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-    int i = pcmcia_get_tuple_data(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return pcmcia_parse_tuple(handle, tuple, parse);
+       if (cf->io.nwin <= 0)
+               return -ENODEV;
+
+       p_dev->io.BasePort1 = cf->io.win[0].base;
+       p_dev->io.NumPorts1 = cf->io.win[0].len;
+       p_dev->io.NumPorts2 = 0;
+       printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
+              p_dev->io.BasePort1,
+              p_dev->io.BasePort1+p_dev->io.NumPorts1-1);
+       return pcmcia_request_io(p_dev, &p_dev->io);
 }
 
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_first_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
-
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                    cisparse_t *parse)
-{
-    int i = pcmcia_get_next_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
 
 static int avma1cs_config(struct pcmcia_device *link)
 {
-    tuple_t tuple;
-    cisparse_t parse;
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
     local_info_t *dev;
     int i;
-    u_char buf[64];
     char devname[128];
     IsdnCard_t icard;
     int busy = 0;
@@ -214,45 +205,19 @@ static int avma1cs_config(struct pcmcia_device *link)
 
     DEBUG(0, "avma1cs_config(0x%p)\n", link);
 
-    do {
-       devname[0] = 0;
-       if (link->prod_id[1])
-               strlcpy(devname, link->prod_id[1], sizeof(devname));
+    devname[0] = 0;
+    if (link->prod_id[1])
+           strlcpy(devname, link->prod_id[1], sizeof(devname));
 
-       /*
-         * find IO port
-         */
-       tuple.TupleData = (cisdata_t *)buf;
-       tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-       tuple.Attributes = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       i = first_tuple(link, &tuple, &parse);
-       while (i == CS_SUCCESS) {
-           if (cf->io.nwin > 0) {
-               link->conf.ConfigIndex = cf->index;
-               link->io.BasePort1 = cf->io.win[0].base;
-               link->io.NumPorts1 = cf->io.win[0].len;
-               link->io.NumPorts2 = 0;
-               printk(KERN_INFO "avma1_cs: testing i/o %#x-%#x\n",
-                       link->io.BasePort1,
-                       link->io.BasePort1+link->io.NumPorts1 - 1);
-               i = pcmcia_request_io(link, &link->io);
-               if (i == CS_SUCCESS) goto found_port;
-           }
-           i = next_tuple(link, &tuple, &parse);
-       }
+    if (pcmcia_loop_config(link, avma1cs_configcheck, NULL))
+           return -ENODEV;
 
-found_port:
-       if (i != CS_SUCCESS) {
-           cs_error(link, RequestIO, i);
-           break;
-       }
-       
+    do {
        /*
         * allocate an interrupt line
         */
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
            cs_error(link, RequestIRQ, i);
            /* undo */
            pcmcia_disable_device(link);
@@ -263,7 +228,7 @@ found_port:
         * configure the PCMCIA socket
         */
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
            cs_error(link, RequestConfiguration, i);
            pcmcia_disable_device(link);
            break;
index db7e64424afe02fca1896c1b1edefdced2e2ac72..f4d0fe29bcf8b1a855a69fa1c1395a4bd9ee863d 100644 (file)
@@ -203,82 +203,55 @@ static void elsa_cs_detach(struct pcmcia_device *link)
     device available to the system.
 
 ======================================================================*/
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
-{
-    int i = pcmcia_get_tuple_data(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
-{
-    int i = pcmcia_get_first_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
 
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
+static int elsa_cs_configcheck(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cf,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-    int i = pcmcia_get_next_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
+       int j;
+
+       if ((cf->io.nwin > 0) && cf->io.win[0].base) {
+               printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       } else {
+               printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
+               for (j = 0x2f0; j > 0x100; j -= 0x10) {
+                       p_dev->io.BasePort1 = j;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
 }
 
 static int elsa_cs_config(struct pcmcia_device *link)
 {
-    tuple_t tuple;
-    cisparse_t parse;
     local_info_t *dev;
-    int i, j, last_fn;
-    u_short buf[128];
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
+    int i, last_fn;
     IsdnCard_t icard;
 
     DEBUG(0, "elsa_config(0x%p)\n", link);
     dev = link->priv;
 
-    tuple.TupleData = (cisdata_t *)buf;
-    tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-    tuple.Attributes = 0;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    i = first_tuple(link, &tuple, &parse);
-    while (i == CS_SUCCESS) {
-        if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
-            printk(KERN_INFO "(elsa_cs: looks like the 96 model)\n");
-            link->conf.ConfigIndex = cf->index;
-            link->io.BasePort1 = cf->io.win[0].base;
-            i = pcmcia_request_io(link, &link->io);
-            if (i == CS_SUCCESS) break;
-        } else {
-          printk(KERN_INFO "(elsa_cs: looks like the 97 model)\n");
-          link->conf.ConfigIndex = cf->index;
-          for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
-            link->io.BasePort1 = j;
-            i = pcmcia_request_io(link, &link->io);
-            if (i == CS_SUCCESS) break;
-          }
-          break;
-        }
-        i = next_tuple(link, &tuple, &parse);
-    }
-
-    if (i != CS_SUCCESS) {
+    i = pcmcia_loop_config(link, elsa_cs_configcheck, NULL);
+    if (i != 0) {
        last_fn = RequestIO;
        goto cs_failed;
     }
 
     i = pcmcia_request_irq(link, &link->irq);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
         link->irq.AssignedIRQ = 0;
        last_fn = RequestIRQ;
         goto cs_failed;
     }
 
     i = pcmcia_request_configuration(link, &link->conf);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
       last_fn = RequestConfiguration;
       goto cs_failed;
     }
index 439cb530def8833a7c1e17f9e363d3d8341b3518..9a3c9f5e4fe82b5e132bc426592e603b243a091b 100644 (file)
@@ -217,101 +217,61 @@ static void sedlbauer_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
-static int sedlbauer_config(struct pcmcia_device *link)
+static int sedlbauer_config_check(struct pcmcia_device *p_dev,
+                                 cistpl_cftable_entry_t *cfg,
+                                 cistpl_cftable_entry_t *dflt,
+                                 unsigned int vcc,
+                                 void *priv_data)
 {
-    local_info_t *dev = link->priv;
-    tuple_t tuple;
-    cisparse_t parse;
-    int last_fn, last_ret;
-    u8 buf[64];
-    config_info_t conf;
-    win_req_t req;
-    memreq_t map;
-    IsdnCard_t  icard;
-
-    DEBUG(0, "sedlbauer_config(0x%p)\n", link);
-
-    tuple.Attributes = 0;
-    tuple.TupleData = buf;
-    tuple.TupleDataMax = sizeof(buf);
-    tuple.TupleOffset = 0;
+       win_req_t *req = priv_data;
 
-    CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
+       if (cfg->index == 0)
+               return -ENODEV;
 
-    /*
-      In this loop, we scan the CIS for configuration table entries,
-      each of which describes a valid card configuration, including
-      voltage, IO window, memory window, and interrupt settings.
-
-      We make no assumptions about the card to be configured: we use
-      just the information available in the CIS.  In an ideal world,
-      this would work for any PCMCIA card, but it requires a complete
-      and accurate CIS.  In practice, a driver usually "knows" most of
-      these things without consulting the CIS, and most client drivers
-      will only use the CIS to fill in implementation-defined details.
-    */
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (1) {
-       cistpl_cftable_entry_t dflt = { 0 };
-       cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-           goto next_entry;
-
-       if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-       if (cfg->index == 0) goto next_entry;
-       link->conf.ConfigIndex = cfg->index;
-       
        /* Does this card need audio output? */
        if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-           link->conf.Attributes |= CONF_ENABLE_SPKR;
-           link->conf.Status = CCSR_AUDIO_ENA;
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
        }
-       
+
        /* Use power settings for Vcc and Vpp if present */
        /*  Note that the CIS values need to be rescaled */
        if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
-           if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
-               goto next_entry;
-       } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
-           if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000)
-               goto next_entry;
+               if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
+                       return -ENODEV;
+       } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
+               if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
+                       return -ENODEV;
        }
-           
+
        if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
-           link->conf.Vpp =
-               cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
-       else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
-           link->conf.Vpp =
-               dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-       
+               p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+       else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
+
        /* Do we need to allocate an interrupt? */
-       if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-           link->conf.Attributes |= CONF_ENABLE_IRQ;
-       
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
        /* IO window settings */
-       link->io.NumPorts1 = link->io.NumPorts2 = 0;
-       if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-           cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-           link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-           if (!(io->flags & CISTPL_IO_8BIT))
-               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-           if (!(io->flags & CISTPL_IO_16BIT))
-               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-/* new in dummy.cs 2001/01/28 MN 
-            link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-*/
-           link->io.BasePort1 = io->win[0].base;
-           link->io.NumPorts1 = io->win[0].len;
-           if (io->nwin > 1) {
-               link->io.Attributes2 = link->io.Attributes1;
-               link->io.BasePort2 = io->win[1].base;
-               link->io.NumPorts2 = io->win[1].len;
-           }
-           /* This reserves IO space but doesn't actually enable it */
-           if (pcmcia_request_io(link, &link->io) != 0)
-               goto next_entry;
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+               /* This reserves IO space but doesn't actually enable it */
+               if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
+                       return -ENODEV;
        }
 
        /*
@@ -325,30 +285,54 @@ static int sedlbauer_config(struct pcmcia_device *link)
          needs to be mapped to virtual space with ioremap() before it
          is used.
        */
-       if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
-           cistpl_mem_t *mem =
-               (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
-           req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
-           req.Attributes |= WIN_ENABLE;
-           req.Base = mem->win[0].host_addr;
-           req.Size = mem->win[0].len;
-/* new in dummy.cs 2001/01/28 MN 
-            if (req.Size < 0x1000)
-                req.Size = 0x1000;
-*/
-           req.AccessSpeed = 0;
-           if (pcmcia_request_window(&link, &req, &link->win) != 0)
-               goto next_entry;
-           map.Page = 0; map.CardOffset = mem->win[0].card_addr;
-           if (pcmcia_map_mem_page(link->win, &map) != 0)
-               goto next_entry;
+       if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
+               cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
+               memreq_t map;
+               req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
+               req->Attributes |= WIN_ENABLE;
+               req->Base = mem->win[0].host_addr;
+               req->Size = mem->win[0].len;
+               req->AccessSpeed = 0;
+               if (pcmcia_request_window(&p_dev, req, &p_dev->win) != 0)
+                       return -ENODEV;
+               map.Page = 0;
+               map.CardOffset = mem->win[0].card_addr;
+               if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
+                       return -ENODEV;
        }
-       /* If we got this far, we're cool! */
-       break;
+       return 0;
+}
 
-    next_entry:
-       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-    }
+
+
+static int sedlbauer_config(struct pcmcia_device *link)
+{
+    local_info_t *dev = link->priv;
+    win_req_t *req;
+    int last_fn, last_ret;
+    IsdnCard_t  icard;
+
+    DEBUG(0, "sedlbauer_config(0x%p)\n", link);
+
+    req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
+    if (!req)
+           return -ENOMEM;
+
+    /*
+      In this loop, we scan the CIS for configuration table entries,
+      each of which describes a valid card configuration, including
+      voltage, IO window, memory window, and interrupt settings.
+
+      We make no assumptions about the card to be configured: we use
+      just the information available in the CIS.  In an ideal world,
+      this would work for any PCMCIA card, but it requires a complete
+      and accurate CIS.  In practice, a driver usually "knows" most of
+      these things without consulting the CIS, and most client drivers
+      will only use the CIS to fill in implementation-defined details.
+    */
+    last_ret = pcmcia_loop_config(link, sedlbauer_config_check, req);
+    if (last_ret)
+           goto failed;
 
     /*
        Allocate an interrupt line.  Note that this does not assign a
@@ -387,8 +371,8 @@ static int sedlbauer_config(struct pcmcia_device *link)
        printk(" & 0x%04x-0x%04x", link->io.BasePort2,
               link->io.BasePort2+link->io.NumPorts2-1);
     if (link->win)
-       printk(", mem 0x%06lx-0x%06lx", req.Base,
-              req.Base+req.Size-1);
+       printk(", mem 0x%06lx-0x%06lx", req->Base,
+              req->Base+req->Size-1);
     printk("\n");
 
     icard.para[0] = link->irq.AssignedIRQ;
@@ -409,6 +393,7 @@ static int sedlbauer_config(struct pcmcia_device *link)
 
 cs_failed:
     cs_error(link, last_fn, last_ret);
+failed:
     sedlbauer_release(link);
     return -ENODEV;
 
index ab4bd455450eef1a7b6f5c39968b9416ac4bc459..623d111544d43dfe7859eef6ca14c82533c64a8c 100644 (file)
@@ -193,82 +193,55 @@ static void teles_detach(struct pcmcia_device *link)
     device available to the system.
 
 ======================================================================*/
-static int get_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
-{
-    int i = pcmcia_get_tuple_data(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
-{
-    int i = pcmcia_get_first_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
-}
 
-static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
-                     cisparse_t *parse)
+static int teles_cs_configcheck(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cf,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
 {
-    int i = pcmcia_get_next_tuple(handle, tuple);
-    if (i != CS_SUCCESS) return i;
-    return get_tuple(handle, tuple, parse);
+       int j;
+
+       if ((cf->io.nwin > 0) && cf->io.win[0].base) {
+               printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       } else {
+               printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
+               for (j = 0x2f0; j > 0x100; j -= 0x10) {
+                       p_dev->io.BasePort1 = j;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
 }
 
 static int teles_cs_config(struct pcmcia_device *link)
 {
-    tuple_t tuple;
-    cisparse_t parse;
     local_info_t *dev;
-    int i, j, last_fn;
-    u_short buf[128];
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
+    int i, last_fn;
     IsdnCard_t icard;
 
     DEBUG(0, "teles_config(0x%p)\n", link);
     dev = link->priv;
 
-    tuple.TupleData = (cisdata_t *)buf;
-    tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-    tuple.Attributes = 0;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    i = first_tuple(link, &tuple, &parse);
-    while (i == CS_SUCCESS) {
-        if ( (cf->io.nwin > 0) && cf->io.win[0].base) {
-            printk(KERN_INFO "(teles_cs: looks like the 96 model)\n");
-            link->conf.ConfigIndex = cf->index;
-            link->io.BasePort1 = cf->io.win[0].base;
-            i = pcmcia_request_io(link, &link->io);
-            if (i == CS_SUCCESS) break;
-        } else {
-          printk(KERN_INFO "(teles_cs: looks like the 97 model)\n");
-          link->conf.ConfigIndex = cf->index;
-          for (i = 0, j = 0x2f0; j > 0x100; j -= 0x10) {
-            link->io.BasePort1 = j;
-            i = pcmcia_request_io(link, &link->io);
-            if (i == CS_SUCCESS) break;
-          }
-          break;
-        }
-        i = next_tuple(link, &tuple, &parse);
-    }
-
-    if (i != CS_SUCCESS) {
+    i = pcmcia_loop_config(link, teles_cs_configcheck, NULL);
+    if (i != 0) {
        last_fn = RequestIO;
        goto cs_failed;
     }
 
     i = pcmcia_request_irq(link, &link->irq);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
         link->irq.AssignedIRQ = 0;
        last_fn = RequestIRQ;
         goto cs_failed;
     }
 
     i = pcmcia_request_configuration(link, &link->conf);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
       last_fn = RequestConfiguration;
       goto cs_failed;
     }
index e92b1ba4b45eb836d83ef101564c76311644ed2e..c2f51cc507608bada189220168178d05b34f908a 100644 (file)
@@ -452,10 +452,10 @@ one_member:
                        if (finddsp->features.pcm_id == dsp->features.pcm_id) {
                                if (finddsp->pcm_slot_rx >= 0 &&
                                    finddsp->pcm_slot_rx < sizeof(freeslots))
-                                       freeslots[finddsp->pcm_slot_tx] = 0;
+                                       freeslots[finddsp->pcm_slot_rx] = 0;
                                if (finddsp->pcm_slot_tx >= 0 &&
                                    finddsp->pcm_slot_tx < sizeof(freeslots))
-                                       freeslots[finddsp->pcm_slot_rx] = 0;
+                                       freeslots[finddsp->pcm_slot_tx] = 0;
                        }
                }
                i = 0;
index e7462924b5050fb70cad3ddfd9f607368d61e774..875fabe16e368c32b87f1a2e697accf45369eac6 100644 (file)
@@ -61,7 +61,7 @@ mISDN_open(struct inode *ino, struct file *filep)
        init_waitqueue_head(&dev->wait);
        filep->private_data = dev;
        __module_get(THIS_MODULE);
-       return 0;
+       return nonseekable_open(ino, filep);
 }
 
 static int
index 07d92c11b5d8d935887f0b8361626faaf1abfd46..2281b5098e95455cd1a6d60af7354f7728888185 100644 (file)
@@ -30,6 +30,20 @@ config BLK_DEV_MD
 
          If unsure, say N.
 
+config MD_AUTODETECT
+       bool "Autodetect RAID arrays during kernel boot"
+       depends on BLK_DEV_MD=y
+       default y
+       ---help---
+         If you say Y here, then the kernel will try to autodetect raid
+         arrays as part of its boot process. 
+
+         If you don't use raid and say Y, this autodetection can cause 
+         a several-second delay in the boot time due to various
+         synchronisation steps that are part of this step.
+
+         If unsure, say Y.
+
 config MD_LINEAR
        tristate "Linear (append) mode"
        depends on BLK_DEV_MD
index 8fa91f846d591bcd35d544d87aec42edbbfc5b96..4952aeb5dd80583ba34c4bff94ee319ddf1a4731 100644 (file)
@@ -103,6 +103,56 @@ IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE] = {
 
 EXPORT_SYMBOL_GPL(ir_codes_avermedia_dvbt);
 
+/* Mauro Carvalho Chehab <mchehab@infradead.org> */
+IR_KEYTAB_TYPE ir_codes_avermedia_m135a[IR_KEYTAB_SIZE] = {
+       [0x00] = KEY_POWER2,
+       [0x2e] = KEY_DOT,               /* '.' */
+       [0x01] = KEY_MODE,              /* TV/FM */
+
+       [0x05] = KEY_1,
+       [0x06] = KEY_2,
+       [0x07] = KEY_3,
+       [0x09] = KEY_4,
+       [0x0a] = KEY_5,
+       [0x0b] = KEY_6,
+       [0x0d] = KEY_7,
+       [0x0e] = KEY_8,
+       [0x0f] = KEY_9,
+       [0x11] = KEY_0,
+
+       [0x13] = KEY_RIGHT,             /* -> */
+       [0x12] = KEY_LEFT,              /* <- */
+
+       [0x17] = KEY_SLEEP,             /* Capturar Imagem */
+       [0x10] = KEY_SHUFFLE,           /* Amostra */
+
+       /* FIXME: The keys bellow aren't ok */
+
+       [0x43] = KEY_CHANNELUP,
+       [0x42] = KEY_CHANNELDOWN,
+       [0x1f] = KEY_VOLUMEUP,
+       [0x1e] = KEY_VOLUMEDOWN,
+       [0x0c] = KEY_ENTER,
+
+       [0x14] = KEY_MUTE,
+       [0x08] = KEY_AUDIO,
+
+       [0x03] = KEY_TEXT,
+       [0x04] = KEY_EPG,
+       [0x2b] = KEY_TV2,               /* TV2 */
+
+       [0x1d] = KEY_RED,
+       [0x1c] = KEY_YELLOW,
+       [0x41] = KEY_GREEN,
+       [0x40] = KEY_BLUE,
+
+       [0x1a] = KEY_PLAYPAUSE,
+       [0x19] = KEY_RECORD,
+       [0x18] = KEY_PLAY,
+       [0x1b] = KEY_STOP,
+};
+EXPORT_SYMBOL_GPL(ir_codes_avermedia_m135a);
+
 /* Attila Kondoros <attila.kondoros@chello.hu> */
 IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE] = {
 
@@ -467,7 +517,8 @@ EXPORT_SYMBOL_GPL(ir_codes_adstech_dvb_t_pci);
 
 /* ---------------------------------------------------------------------- */
 
-/* MSI TV@nywhere remote */
+/* MSI TV@nywhere MASTER remote */
+
 IR_KEYTAB_TYPE ir_codes_msi_tvanywhere[IR_KEYTAB_SIZE] = {
        /* Keys 0 to 9 */
        [ 0x00 ] = KEY_0,
@@ -501,6 +552,95 @@ EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere);
 
 /* ---------------------------------------------------------------------- */
 
+/*
+  Keycodes for remote on the MSI TV@nywhere Plus. The controller IC on the card
+  is marked "KS003". The controller is I2C at address 0x30, but does not seem
+  to respond to probes until a read is performed from a valid device.
+  I don't know why...
+
+  Note: This remote may be of similar or identical design to the
+  Pixelview remote (?).  The raw codes and duplicate button codes
+  appear to be the same.
+
+  Henry Wong <henry@stuffedcow.net>
+  Some changes to formatting and keycodes by Mark Schultz <n9xmj@yahoo.com>
+
+*/
+
+IR_KEYTAB_TYPE ir_codes_msi_tvanywhere_plus[IR_KEYTAB_SIZE] = {
+
+/*  ---- Remote Button Layout ----
+
+    POWER   SOURCE  SCAN    MUTE
+    TV/FM   1       2       3
+    |>      4       5       6
+    <|      7       8       9
+    ^^UP    0       +       RECALL
+    vvDN    RECORD  STOP    PLAY
+
+       MINIMIZE          ZOOM
+
+                 CH+
+      VOL-                   VOL+
+                 CH-
+
+       SNAPSHOT           MTS
+
+     <<      FUNC    >>     RESET
+*/
+
+       [0x01] = KEY_KP1,             /* 1 */
+       [0x0b] = KEY_KP2,             /* 2 */
+       [0x1b] = KEY_KP3,             /* 3 */
+       [0x05] = KEY_KP4,             /* 4 */
+       [0x09] = KEY_KP5,             /* 5 */
+       [0x15] = KEY_KP6,             /* 6 */
+       [0x06] = KEY_KP7,             /* 7 */
+       [0x0a] = KEY_KP8,             /* 8 */
+       [0x12] = KEY_KP9,             /* 9 */
+       [0x02] = KEY_KP0,             /* 0 */
+       [0x10] = KEY_KPPLUS,          /* + */
+       [0x13] = KEY_AGAIN,           /* Recall */
+
+       [0x1e] = KEY_POWER,           /* Power */
+       [0x07] = KEY_TUNER,           /* Source */
+       [0x1c] = KEY_SEARCH,          /* Scan */
+       [0x18] = KEY_MUTE,            /* Mute */
+
+       [0x03] = KEY_RADIO,           /* TV/FM */
+       /* The next four keys are duplicates that appear to send the
+          same IR code as Ch+, Ch-, >>, and << .  The raw code assigned
+          to them is the actual code + 0x20 - they will never be
+          detected as such unless some way is discovered to distinguish
+          these buttons from those that have the same code. */
+       [0x3f] = KEY_RIGHT,           /* |> and Ch+ */
+       [0x37] = KEY_LEFT,            /* <| and Ch- */
+       [0x2c] = KEY_UP,              /* ^^Up and >> */
+       [0x24] = KEY_DOWN,            /* vvDn and << */
+
+       [0x00] = KEY_RECORD,          /* Record */
+       [0x08] = KEY_STOP,            /* Stop */
+       [0x11] = KEY_PLAY,            /* Play */
+
+       [0x0f] = KEY_CLOSE,           /* Minimize */
+       [0x19] = KEY_ZOOM,            /* Zoom */
+       [0x1a] = KEY_SHUFFLE,         /* Snapshot */
+       [0x0d] = KEY_LANGUAGE,        /* MTS */
+
+       [0x14] = KEY_VOLUMEDOWN,      /* Vol- */
+       [0x16] = KEY_VOLUMEUP,        /* Vol+ */
+       [0x17] = KEY_CHANNELDOWN,     /* Ch- */
+       [0x1f] = KEY_CHANNELUP,       /* Ch+ */
+
+       [0x04] = KEY_REWIND,          /* << */
+       [0x0e] = KEY_MENU,            /* Function */
+       [0x0c] = KEY_FASTFORWARD,     /* >> */
+       [0x1d] = KEY_RESTART,         /* Reset */
+};
+EXPORT_SYMBOL_GPL(ir_codes_msi_tvanywhere_plus);
+
+/* ---------------------------------------------------------------------- */
+
 /* Cinergy 1400 DVB-T */
 IR_KEYTAB_TYPE ir_codes_cinergy_1400[IR_KEYTAB_SIZE] = {
        [ 0x01 ] = KEY_POWER,
@@ -1792,12 +1932,61 @@ IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE] = {
        [ 0x41 ] = KEY_GREEN,           /* AP2 */
        [ 0x47 ] = KEY_YELLOW,          /* AP3 */
        [ 0x57 ] = KEY_BLUE,            /* AP4 */
-
-
 };
-
 EXPORT_SYMBOL_GPL(ir_codes_encore_enltv);
 
+/* Encore ENLTV2-FM  - silver plastic - "Wand Media" written at the botton
+    Mauro Carvalho Chehab <mchehab@infradead.org> */
+IR_KEYTAB_TYPE ir_codes_encore_enltv2[IR_KEYTAB_SIZE] = {
+       [0x4c] = KEY_POWER2,
+       [0x4a] = KEY_TUNER,
+       [0x40] = KEY_1,
+       [0x60] = KEY_2,
+       [0x50] = KEY_3,
+       [0x70] = KEY_4,
+       [0x48] = KEY_5,
+       [0x68] = KEY_6,
+       [0x58] = KEY_7,
+       [0x78] = KEY_8,
+       [0x44] = KEY_9,
+       [0x54] = KEY_0,
+
+       [0x64] = KEY_LAST,              /* +100 */
+       [0x4e] = KEY_AGAIN,             /* Recall */
+
+       [0x6c] = KEY_SWITCHVIDEOMODE,   /* Video Source */
+       [0x5e] = KEY_MENU,
+       [0x56] = KEY_SCREEN,
+       [0x7a] = KEY_SETUP,
+
+       [0x46] = KEY_MUTE,
+       [0x5c] = KEY_MODE,              /* Stereo */
+       [0x74] = KEY_INFO,
+       [0x7c] = KEY_CLEAR,
+
+       [0x55] = KEY_UP,
+       [0x49] = KEY_DOWN,
+       [0x7e] = KEY_LEFT,
+       [0x59] = KEY_RIGHT,
+       [0x6a] = KEY_ENTER,
+
+       [0x42] = KEY_VOLUMEUP,
+       [0x62] = KEY_VOLUMEDOWN,
+       [0x52] = KEY_CHANNELUP,
+       [0x72] = KEY_CHANNELDOWN,
+
+       [0x41] = KEY_RECORD,
+       [0x51] = KEY_SHUFFLE,   /* Snapshot */
+       [0x75] = KEY_TIME,      /* Timeshift */
+       [0x71] = KEY_TV2,       /* PIP */
+
+       [0x45] = KEY_REWIND,
+       [0x6f] = KEY_PAUSE,
+       [0x7d] = KEY_FORWARD,
+       [0x79] = KEY_STOP,
+};
+EXPORT_SYMBOL_GPL(ir_codes_encore_enltv2);
+
 /* for the Technotrend 1500 bundled remotes (grey and black): */
 IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE] = {
        [ 0x01 ] = KEY_POWER,
@@ -2239,3 +2428,86 @@ IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE] = {
        [0x2a] = KEY_MENU,
 };
 EXPORT_SYMBOL_GPL(ir_codes_avermedia_a16d);
+
+/* Encore ENLTV-FM v5.3
+   Mauro Carvalho Chehab <mchehab@infradead.org>
+ */
+IR_KEYTAB_TYPE ir_codes_encore_enltv_fm53[IR_KEYTAB_SIZE] = {
+       [0x10] = KEY_POWER2,
+       [0x06] = KEY_MUTE,
+
+       [0x09] = KEY_1,
+       [0x1d] = KEY_2,
+       [0x1f] = KEY_3,
+       [0x19] = KEY_4,
+       [0x1b] = KEY_5,
+       [0x11] = KEY_6,
+       [0x17] = KEY_7,
+       [0x12] = KEY_8,
+       [0x16] = KEY_9,
+       [0x48] = KEY_0,
+
+       [0x04] = KEY_LIST,              /* -/-- */
+       [0x40] = KEY_LAST,              /* recall */
+
+       [0x02] = KEY_MODE,              /* TV/AV */
+       [0x05] = KEY_SHUFFLE,           /* SNAPSHOT */
+
+       [0x4c] = KEY_CHANNELUP,         /* UP */
+       [0x00] = KEY_CHANNELDOWN,       /* DOWN */
+       [0x0d] = KEY_VOLUMEUP,          /* RIGHT */
+       [0x15] = KEY_VOLUMEDOWN,        /* LEFT */
+       [0x49] = KEY_ENTER,             /* OK */
+
+       [0x54] = KEY_RECORD,
+       [0x4d] = KEY_PLAY,              /* pause */
+
+       [0x1e] = KEY_UP,                /* video setting */
+       [0x0e] = KEY_RIGHT,             /* <- */
+       [0x1a] = KEY_LEFT,              /* -> */
+
+       [0x0a] = KEY_DOWN,              /* video default */
+       [0x0c] = KEY_ZOOM,              /* hide pannel */
+       [0x47] = KEY_SLEEP,             /* shutdown */
+};
+EXPORT_SYMBOL_GPL(ir_codes_encore_enltv_fm53);
+
+/* Zogis Real Audio 220 - 32 keys IR */
+IR_KEYTAB_TYPE ir_codes_real_audio_220_32_keys[IR_KEYTAB_SIZE] = {
+       [0x1c] = KEY_RADIO,
+       [0x12] = KEY_POWER2,
+
+       [0x01] = KEY_1,
+       [0x02] = KEY_2,
+       [0x03] = KEY_3,
+       [0x04] = KEY_4,
+       [0x05] = KEY_5,
+       [0x06] = KEY_6,
+       [0x07] = KEY_7,
+       [0x08] = KEY_8,
+       [0x09] = KEY_9,
+       [0x00] = KEY_0,
+
+       [0x0c] = KEY_VOLUMEUP,
+       [0x18] = KEY_VOLUMEDOWN,
+       [0x0b] = KEY_CHANNELUP,
+       [0x15] = KEY_CHANNELDOWN,
+       [0x16] = KEY_ENTER,
+
+       [0x11] = KEY_LIST,              /* Source */
+       [0x0d] = KEY_AUDIO,             /* stereo */
+
+       [0x0f] = KEY_PREVIOUS,          /* Prev */
+       [0x1b] = KEY_PAUSE,             /* Timeshift */
+       [0x1a] = KEY_NEXT,              /* Next */
+
+       [0x0e] = KEY_STOP,
+       [0x1f] = KEY_PLAY,
+       [0x1e] = KEY_PLAYPAUSE,         /* Pause */
+
+       [0x1d] = KEY_RECORD,
+       [0x13] = KEY_MUTE,
+       [0x19] = KEY_SHUFFLE,           /* Snapshot */
+
+};
+EXPORT_SYMBOL_GPL(ir_codes_real_audio_220_32_keys);
index d01965e96927b2477530ed666d86001eb68be946..d599d360da3fafcbcd26d72c19419683f1f2c4cb 100644 (file)
@@ -234,7 +234,7 @@ void saa7146_pgtable_free(struct pci_dev *pci, struct saa7146_pgtable *pt)
 int saa7146_pgtable_alloc(struct pci_dev *pci, struct saa7146_pgtable *pt)
 {
        __le32       *cpu;
-       dma_addr_t   dma_addr;
+       dma_addr_t   dma_addr = 0;
 
        cpu = pci_alloc_consistent(pci, PAGE_SIZE, &dma_addr);
        if (NULL == cpu) {
index cf6a817d50594a21f76721f1c386b1b2d798418c..5b34c134aa25147dc118a3cc44a3ba49365166f6 100644 (file)
@@ -533,7 +533,7 @@ int saa7146_register_device(struct video_device **vid, struct saa7146_dev* dev,
        memcpy(vfd, &device_template, sizeof(struct video_device));
        strlcpy(vfd->name, name, sizeof(vfd->name));
        vfd->release = video_device_release;
-       vfd->priv = dev;
+       video_set_drvdata(vfd, dev);
 
        // fixme: -1 should be an insmod parameter *for the extension* (like "video_nr");
        if (video_register_device(vfd, type, -1) < 0) {
index 1305b0e63ce5a6b268c5203eb035393d746407a3..12206d75dd4ee968d96213ebe31f75b55fb14ba5 100644 (file)
@@ -170,6 +170,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
        b[0] = REG_LO1B1;
        b[1] = 0xFF;
 
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
+
        mt2060_writeregs(priv,b,2);
 
        freq = params->frequency / 1000; // Hz -> kHz
@@ -233,6 +236,9 @@ static int mt2060_set_params(struct dvb_frontend *fe, struct dvb_frontend_parame
                i++;
        } while (i<10);
 
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
+
        return ret;
 }
 
@@ -296,13 +302,35 @@ static int mt2060_get_bandwidth(struct dvb_frontend *fe, u32 *bandwidth)
 static int mt2060_init(struct dvb_frontend *fe)
 {
        struct mt2060_priv *priv = fe->tuner_priv;
-       return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x33);
+       int ret;
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
+
+       ret = mt2060_writereg(priv, REG_VGAG,
+                             (priv->cfg->clock_out << 6) | 0x33);
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
+
+       return ret;
 }
 
 static int mt2060_sleep(struct dvb_frontend *fe)
 {
        struct mt2060_priv *priv = fe->tuner_priv;
-       return mt2060_writereg(priv, REG_VGAG, (priv->cfg->clock_out << 6) | 0x30);
+       int ret;
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
+
+       ret = mt2060_writereg(priv, REG_VGAG,
+                             (priv->cfg->clock_out << 6) | 0x30);
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
+
+       return ret;
 }
 
 static int mt2060_release(struct dvb_frontend *fe)
@@ -344,6 +372,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
        priv->i2c      = i2c;
        priv->if1_freq = if1;
 
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1); /* open i2c_gate */
+
        if (mt2060_readreg(priv,REG_PART_REV,&id) != 0) {
                kfree(priv);
                return NULL;
@@ -360,6 +391,9 @@ struct dvb_frontend * mt2060_attach(struct dvb_frontend *fe, struct i2c_adapter
 
        mt2060_calibrate(priv);
 
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0); /* close i2c_gate */
+
        return fe;
 }
 EXPORT_SYMBOL(mt2060_attach);
index cb25e43502fe5922d69a163c69172a1a32a7ae21..64379f2bf2370eaf221d33aea24a7c946ab75f5a 100644 (file)
@@ -979,7 +979,6 @@ struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
        switch (instance) {
        case 0:
                goto fail;
-               break;
        case 1:
                /* new tuner instance */
                state->config = cfg;
index 93063c6fbbf634e42aac29b3502de2b66104e232..1b48b5d0bf1ef7a708a92131d120684c98750b43 100644 (file)
@@ -1155,7 +1155,6 @@ struct dvb_frontend *tda18271_attach(struct dvb_frontend *fe, u8 addr,
        switch (instance) {
        case 0:
                goto fail;
-               break;
        case 1:
                /* new tuner instance */
                priv->gate = (cfg) ? cfg->gate : TDA18271_GATE_AUTO;
index 8555d9cf9051031f7643675b4487e65461553d1b..4a74f65e759aad5bc622ed7178cd13f1e2416f0c 100644 (file)
@@ -447,17 +447,19 @@ static void tda827xa_lna_gain(struct dvb_frontend *fe, int high,
                        else
                                arg = 0;
                }
-               if (priv->cfg->tuner_callback)
-                       priv->cfg->tuner_callback(priv->i2c_adap->algo_data,
-                                                               gp_func, arg);
+               if (fe->callback)
+                       fe->callback(priv->i2c_adap->algo_data,
+                                    DVB_FRONTEND_COMPONENT_TUNER,
+                                    gp_func, arg);
                buf[1] = high ? 0 : 1;
                if (priv->cfg->config == 2)
                        buf[1] = high ? 1 : 0;
                i2c_transfer(priv->i2c_adap, &msg, 1);
                break;
        case 3: /* switch with GPIO of saa713x */
-               if (priv->cfg->tuner_callback)
-                       priv->cfg->tuner_callback(priv->i2c_adap->algo_data, 0, high);
+               if (fe->callback)
+                       fe->callback(priv->i2c_adap->algo_data,
+                                    DVB_FRONTEND_COMPONENT_TUNER, 0, high);
                break;
        }
 }
index 7850a9a1dc8f42a04a0e2c19496b894aeb8611a6..7d72ce0a0c2df925263fcfce42d5561990aa7745 100644 (file)
@@ -36,7 +36,6 @@ struct tda827x_config
        /* interface to tda829x driver */
        unsigned int config;
        int          switch_addr;
-       int (*tuner_callback) (void *dev, int command, int arg);
 
        void (*agcf)(struct dvb_frontend *fe);
 };
index 91204d3f282dfc5de1c02c7c9b9ad6c62959ff13..c112bdd4e0f04a89a7ffe60fdaa143e6721339f8 100644 (file)
@@ -672,10 +672,8 @@ struct dvb_frontend *tda829x_attach(struct dvb_frontend *fe,
        priv->i2c_props.addr     = i2c_addr;
        priv->i2c_props.adap     = i2c_adap;
        priv->i2c_props.name     = "tda829x";
-       if (cfg) {
+       if (cfg)
                priv->cfg.config         = cfg->lna_cfg;
-               priv->cfg.tuner_callback = cfg->tuner_callback;
-       }
 
        if (tda8290_probe(&priv->i2c_props) == 0) {
                priv->ver = TDA8290;
index aa074f3f0c07f247db9e74a6fe4e636488ad0d47..7e288b26fcc3c5f0a9665a8159027c1d8dbd73c7 100644 (file)
@@ -22,7 +22,6 @@
 
 struct tda829x_config {
        unsigned int lna_cfg;
-       int (*tuner_callback) (void *dev, int command, int arg);
 
        unsigned int probe_tuner:1;
 #define TDA829X_PROBE_TUNER 0
index 72abf0b73486d19c3e69e4330b0213f1d963a9f3..ff1788cc5d48ef6068a9759dd61061388e299445 100644 (file)
@@ -686,7 +686,6 @@ struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
        case 0:
                mutex_unlock(&tda9887_list_mutex);
                return NULL;
-               break;
        case 1:
                fe->analog_demod_priv = priv;
                priv->mode = T_STANDBY;
index aa773a658a2a3e3c0d7caae7cb2d3b783ff8b10d..2a1aac1cc7552d33ec72e55073d873d72e323ce7 100644 (file)
@@ -142,6 +142,7 @@ static inline int tuner_stereo(const int type, const int status)
        case TUNER_PHILIPS_FM1236_MK3:
        case TUNER_PHILIPS_FM1256_IH3:
        case TUNER_LG_NTSC_TAPE:
+       case TUNER_TCL_MF02GIP_5N:
                return ((status & TUNER_SIGNAL) == TUNER_STEREO_MK3);
        default:
                return status & TUNER_STEREO;
@@ -494,6 +495,7 @@ static int simple_radio_bandswitch(struct dvb_frontend *fe, u8 *buffer)
        case TUNER_PHILIPS_FMD1216ME_MK3:
        case TUNER_LG_NTSC_TAPE:
        case TUNER_PHILIPS_FM1256_IH3:
+       case TUNER_TCL_MF02GIP_5N:
                buffer[3] = 0x19;
                break;
        case TUNER_TNF_5335MF:
@@ -1038,7 +1040,6 @@ struct dvb_frontend *simple_tuner_attach(struct dvb_frontend *fe,
        case 0:
                mutex_unlock(&tuner_simple_list_mutex);
                return NULL;
-               break;
        case 1:
                fe->tuner_priv = priv;
 
index 10dddca8b5d1817ede0be39bab500c2841c5ea4e..04961a1f44be66145f929dbc1f5cb2599371c41e 100644 (file)
@@ -1216,6 +1216,23 @@ static struct tuner_params tuner_samsung_tcpg_6121p30a_params[] = {
        },
 };
 
+/* ------------ TUNER_TCL_MF02GIP-5N-E - TCL MF02GIP-5N ------------ */
+
+static struct tuner_range tuner_tcl_mf02gip_5n_ntsc_ranges[] = {
+       { 16 * 172.00 /*MHz*/, 0x8e, 0x01, },
+       { 16 * 448.00 /*MHz*/, 0x8e, 0x02, },
+       { 16 * 999.99        , 0x8e, 0x04, },
+};
+
+static struct tuner_params tuner_tcl_mf02gip_5n_params[] = {
+       {
+               .type   = TUNER_PARAM_TYPE_NTSC,
+               .ranges = tuner_tcl_mf02gip_5n_ntsc_ranges,
+               .count  = ARRAY_SIZE(tuner_tcl_mf02gip_5n_ntsc_ranges),
+               .cb_first_if_lower_freq = 1,
+       },
+};
+
 /* --------------------------------------------------------------------- */
 
 struct tunertype tuners[] = {
@@ -1641,6 +1658,11 @@ struct tunertype tuners[] = {
                .name   = "Xceive 5000 tuner",
                /* see xc5000.c for details */
        },
+       [TUNER_TCL_MF02GIP_5N] = { /* TCL tuner MF02GIP-5N-E */
+               .name   = "TCL tuner MF02GIP-5N-E",
+               .params = tuner_tcl_mf02gip_5n_params,
+               .count  = ARRAY_SIZE(tuner_tcl_mf02gip_5n_params),
+       },
 };
 EXPORT_SYMBOL(tuners);
 
index 4dd1d2421cc529fde892a6204b02dd725d25f277..b65e6803e6c64983d07f4d6c7a00d1e2fefbb96e 100644 (file)
@@ -71,9 +71,6 @@ struct firmware_properties {
 struct xc2028_data {
        struct list_head        hybrid_tuner_instance_list;
        struct tuner_i2c_props  i2c_props;
-       int                     (*tuner_callback) (void *dev,
-                                                  int command, int arg);
-       void                    *video_dev;
        __u32                   frequency;
 
        struct firmware_description *firm;
@@ -492,6 +489,23 @@ ret:
        return i;
 }
 
+static inline int do_tuner_callback(struct dvb_frontend *fe, int cmd, int arg)
+{
+       struct xc2028_data *priv = fe->tuner_priv;
+
+       /* analog side (tuner-core) uses i2c_adap->algo_data.
+        * digital side is not guaranteed to have algo_data defined.
+        *
+        * digital side will always have fe->dvb defined.
+        * analog side (tuner-core) doesn't (yet) define fe->dvb.
+        */
+
+       return (!fe->callback) ? -EINVAL :
+               fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
+                               fe->dvb->priv : priv->i2c_props.adap->algo_data,
+                            DVB_FRONTEND_COMPONENT_TUNER, cmd, arg);
+}
+
 static int load_firmware(struct dvb_frontend *fe, unsigned int type,
                         v4l2_std_id *id)
 {
@@ -530,8 +544,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
 
                if (!size) {
                        /* Special callback command received */
-                       rc = priv->tuner_callback(priv->video_dev,
-                                                 XC2028_TUNER_RESET, 0);
+                       rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
                        if (rc < 0) {
                                tuner_err("Error at RESET code %d\n",
                                           (*p) & 0x7f);
@@ -542,8 +555,7 @@ static int load_firmware(struct dvb_frontend *fe, unsigned int type,
                if (size >= 0xff00) {
                        switch (size) {
                        case 0xff00:
-                               rc = priv->tuner_callback(priv->video_dev,
-                                                       XC2028_RESET_CLK, 0);
+                               rc = do_tuner_callback(fe, XC2028_RESET_CLK, 0);
                                if (rc < 0) {
                                        tuner_err("Error at RESET code %d\n",
                                                  (*p) & 0x7f);
@@ -715,8 +727,7 @@ retry:
        memset(&priv->cur_fw, 0, sizeof(priv->cur_fw));
 
        /* Reset is needed before loading firmware */
-       rc = priv->tuner_callback(priv->video_dev,
-                                 XC2028_TUNER_RESET, 0);
+       rc = do_tuner_callback(fe, XC2028_TUNER_RESET, 0);
        if (rc < 0)
                goto fail;
 
@@ -933,7 +944,7 @@ static int generic_set_freq(struct dvb_frontend *fe, u32 freq /* in HZ */,
           The reset CLK is needed only with tm6000.
           Driver should work fine even if this fails.
         */
-       priv->tuner_callback(priv->video_dev, XC2028_RESET_CLK, 1);
+       do_tuner_callback(fe, XC2028_RESET_CLK, 1);
 
        msleep(10);
 
@@ -1002,11 +1013,6 @@ static int xc2028_set_params(struct dvb_frontend *fe,
 
        tuner_dbg("%s called\n", __func__);
 
-       if (priv->ctrl.d2633)
-               type |= D2633;
-       else
-               type |= D2620;
-
        switch(fe->ops.info.type) {
        case FE_OFDM:
                bw = p->u.ofdm.bandwidth;
@@ -1021,10 +1027,8 @@ static int xc2028_set_params(struct dvb_frontend *fe,
                break;
        case FE_ATSC:
                bw = BANDWIDTH_6_MHZ;
-               /* The only ATSC firmware (at least on v2.7) is D2633,
-                  so overrides ctrl->d2633 */
-               type |= ATSC| D2633;
-               type &= ~D2620;
+               /* The only ATSC firmware (at least on v2.7) is D2633 */
+               type |= ATSC | D2633;
                break;
        /* DVB-S is not supported */
        default:
@@ -1057,6 +1061,28 @@ static int xc2028_set_params(struct dvb_frontend *fe,
                tuner_err("error: bandwidth not supported.\n");
        };
 
+       /*
+         Selects between D2633 or D2620 firmware.
+         It doesn't make sense for ATSC, since it should be D2633 on all cases
+        */
+       if (fe->ops.info.type != FE_ATSC) {
+               switch (priv->ctrl.type) {
+               case XC2028_D2633:
+                       type |= D2633;
+                       break;
+               case XC2028_D2620:
+                       type |= D2620;
+                       break;
+               case XC2028_AUTO:
+               default:
+                       /* Zarlink seems to need D2633 */
+                       if (priv->ctrl.demod == XC3028_FE_ZARLINK456)
+                               type |= D2633;
+                       else
+                               type |= D2620;
+               }
+       }
+
        /* All S-code tables need a 200kHz shift */
        if (priv->ctrl.demod)
                demod = priv->ctrl.demod + 200;
@@ -1177,20 +1203,10 @@ struct dvb_frontend *xc2028_attach(struct dvb_frontend *fe,
                break;
        case 1:
                /* new tuner instance */
-               priv->tuner_callback = cfg->callback;
                priv->ctrl.max_len = 13;
 
                mutex_init(&priv->lock);
 
-               /* analog side (tuner-core) uses i2c_adap->algo_data.
-                * digital side is not guaranteed to have algo_data defined.
-                *
-                * digital side will always have fe->dvb defined.
-                * analog side (tuner-core) doesn't (yet) define fe->dvb.
-                */
-               priv->video_dev = ((fe->dvb) && (fe->dvb->priv)) ?
-                                  fe->dvb->priv : cfg->i2c_adap->algo_data;
-
                fe->tuner_priv = priv;
                break;
        case 2:
index 2c5b6282b569203d8551cbcb23ff4e727318d756..19de7928a74eb75b5a01177a633acdf7e7768559 100644 (file)
 #define        XC3028_FE_ZARLINK456    4560
 #define        XC3028_FE_CHINA         5200
 
+enum firmware_type {
+       XC2028_AUTO = 0,        /* By default, auto-detects */
+       XC2028_D2633,
+       XC2028_D2620,
+};
+
 struct xc2028_ctrl {
        char                    *fname;
        int                     max_len;
        unsigned int            scode_table;
        unsigned int            mts   :1;
-       unsigned int            d2633 :1;
        unsigned int            input1:1;
        unsigned int            vhfbw7:1;
        unsigned int            uhfbw8:1;
        unsigned int            demod;
+       enum firmware_type      type:2;
 };
 
 struct xc2028_config {
        struct i2c_adapter *i2c_adap;
        u8                 i2c_addr;
-       void               *video_dev;
        struct xc2028_ctrl *ctrl;
-       int                (*callback) (void *dev, int command, int arg);
 };
 
 /* xc2028 commands for callback */
index dcddfa803a75597b00d97e40f734203a4fdc8952..f9c2bb917f54b5fe701268e527464491d2b19784 100644 (file)
@@ -30,7 +30,7 @@
 #include "dvb_frontend.h"
 
 #include "xc5000.h"
-#include "xc5000_priv.h"
+#include "tuner-i2c.h"
 
 static int debug;
 module_param(debug, int, 0644);
@@ -40,12 +40,26 @@ static int xc5000_load_fw_on_attach;
 module_param_named(init_fw, xc5000_load_fw_on_attach, int, 0644);
 MODULE_PARM_DESC(init_fw, "Load firmware during driver initialization.");
 
+static DEFINE_MUTEX(xc5000_list_mutex);
+static LIST_HEAD(hybrid_tuner_instance_list);
+
 #define dprintk(level,fmt, arg...) if (debug >= level) \
        printk(KERN_INFO "%s: " fmt, "xc5000", ## arg)
 
 #define XC5000_DEFAULT_FIRMWARE "dvb-fe-xc5000-1.1.fw"
 #define XC5000_DEFAULT_FIRMWARE_SIZE 12332
 
+struct xc5000_priv {
+       struct tuner_i2c_props i2c_props;
+       struct list_head hybrid_tuner_instance_list;
+
+       u32 if_khz;
+       u32 freq_hz;
+       u32 bandwidth;
+       u8  video_standard;
+       u8  rf_mode;
+};
+
 /* Misc Defines */
 #define MAX_TV_STANDARD                        23
 #define XC_MAX_I2C_WRITE_LENGTH                64
@@ -216,9 +230,12 @@ static void xc5000_TunerReset(struct dvb_frontend *fe)
 
        dprintk(1, "%s()\n", __func__);
 
-       if (priv->cfg->tuner_callback) {
-               ret = priv->cfg->tuner_callback(priv->devptr,
-                                               XC5000_TUNER_RESET, 0);
+       if (fe->callback) {
+               ret = fe->callback(((fe->dvb) && (fe->dvb->priv)) ?
+                                          fe->dvb->priv :
+                                          priv->i2c_props.adap->algo_data,
+                                          DVB_FRONTEND_COMPONENT_TUNER,
+                                          XC5000_TUNER_RESET, 0);
                if (ret)
                        printk(KERN_ERR "xc5000: reset failed\n");
        } else
@@ -509,13 +526,13 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
        u8 buf[2] = { reg >> 8, reg & 0xff };
        u8 bval[2] = { 0, 0 };
        struct i2c_msg msg[2] = {
-               { .addr = priv->cfg->i2c_address,
+               { .addr = priv->i2c_props.addr,
                        .flags = 0, .buf = &buf[0], .len = 2 },
-               { .addr = priv->cfg->i2c_address,
+               { .addr = priv->i2c_props.addr,
                        .flags = I2C_M_RD, .buf = &bval[0], .len = 2 },
        };
 
-       if (i2c_transfer(priv->i2c, msg, 2) != 2) {
+       if (i2c_transfer(priv->i2c_props.adap, msg, 2) != 2) {
                printk(KERN_WARNING "xc5000: I2C read failed\n");
                return -EREMOTEIO;
        }
@@ -526,10 +543,10 @@ static int xc5000_readreg(struct xc5000_priv *priv, u16 reg, u16 *val)
 
 static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
 {
-       struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
+       struct i2c_msg msg = { .addr = priv->i2c_props.addr,
                .flags = 0, .buf = buf, .len = len };
 
-       if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+       if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
                printk(KERN_ERR "xc5000: I2C write failed (len=%i)\n",
                        (int)len);
                return -EREMOTEIO;
@@ -539,10 +556,10 @@ static int xc5000_writeregs(struct xc5000_priv *priv, u8 *buf, u8 len)
 
 static int xc5000_readregs(struct xc5000_priv *priv, u8 *buf, u8 len)
 {
-       struct i2c_msg msg = { .addr = priv->cfg->i2c_address,
+       struct i2c_msg msg = { .addr = priv->i2c_props.addr,
                .flags = I2C_M_RD, .buf = buf, .len = len };
 
-       if (i2c_transfer(priv->i2c, &msg, 1) != 1) {
+       if (i2c_transfer(priv->i2c_props.adap, &msg, 1) != 1) {
                printk(KERN_ERR "xc5000 I2C read failed (len=%i)\n",(int)len);
                return -EREMOTEIO;
        }
@@ -559,7 +576,7 @@ static int xc5000_fwupload(struct dvb_frontend* fe)
        printk(KERN_INFO "xc5000: waiting for firmware upload (%s)...\n",
                XC5000_DEFAULT_FIRMWARE);
 
-       ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c->dev);
+       ret = request_firmware(&fw, XC5000_DEFAULT_FIRMWARE, &priv->i2c_props.adap->dev);
        if (ret) {
                printk(KERN_ERR "xc5000: Upload failed. (file not found?)\n");
                ret = XC_RESULT_RESET_FAILURE;
@@ -675,10 +692,10 @@ static int xc5000_set_params(struct dvb_frontend *fe,
                return -EREMOTEIO;
        }
 
-       ret = xc_set_IF_frequency(priv, priv->cfg->if_khz);
+       ret = xc_set_IF_frequency(priv, priv->if_khz);
        if (ret != XC_RESULT_SUCCESS) {
                printk(KERN_ERR "xc5000: xc_Set_IF_frequency(%d) failed\n",
-                       priv->cfg->if_khz);
+                      priv->if_khz);
                return -EIO;
        }
 
@@ -897,9 +914,19 @@ static int xc5000_init(struct dvb_frontend *fe)
 
 static int xc5000_release(struct dvb_frontend *fe)
 {
+       struct xc5000_priv *priv = fe->tuner_priv;
+
        dprintk(1, "%s()\n", __func__);
-       kfree(fe->tuner_priv);
+
+       mutex_lock(&xc5000_list_mutex);
+
+       if (priv)
+               hybrid_tuner_release_state(priv);
+
+       mutex_unlock(&xc5000_list_mutex);
+
        fe->tuner_priv = NULL;
+
        return 0;
 }
 
@@ -924,29 +951,43 @@ static const struct dvb_tuner_ops xc5000_tuner_ops = {
 
 struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
                                   struct i2c_adapter *i2c,
-                                  struct xc5000_config *cfg, void *devptr)
+                                  struct xc5000_config *cfg)
 {
        struct xc5000_priv *priv = NULL;
+       int instance;
        u16 id = 0;
 
-       dprintk(1, "%s()\n", __func__);
+       dprintk(1, "%s(%d-%04x)\n", __func__,
+               i2c ? i2c_adapter_id(i2c) : -1,
+               cfg ? cfg->i2c_address : -1);
 
-       priv = kzalloc(sizeof(struct xc5000_priv), GFP_KERNEL);
-       if (priv == NULL)
-               return NULL;
+       mutex_lock(&xc5000_list_mutex);
 
-       priv->cfg = cfg;
-       priv->bandwidth = BANDWIDTH_6_MHZ;
-       priv->i2c = i2c;
-       priv->devptr = devptr;
+       instance = hybrid_tuner_request_state(struct xc5000_priv, priv,
+                                             hybrid_tuner_instance_list,
+                                             i2c, cfg->i2c_address, "xc5000");
+       switch (instance) {
+       case 0:
+               goto fail;
+               break;
+       case 1:
+               /* new tuner instance */
+               priv->bandwidth = BANDWIDTH_6_MHZ;
+               priv->if_khz = cfg->if_khz;
+
+               fe->tuner_priv = priv;
+               break;
+       default:
+               /* existing tuner instance */
+               fe->tuner_priv = priv;
+               break;
+       }
 
        /* Check if firmware has been loaded. It is possible that another
           instance of the driver has loaded the firmware.
         */
-       if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0) {
-               kfree(priv);
-               return NULL;
-       }
+       if (xc5000_readreg(priv, XREG_PRODUCT_ID, &id) != 0)
+               goto fail;
 
        switch(id) {
        case XC_PRODUCT_ID_FW_LOADED:
@@ -967,19 +1008,23 @@ struct dvb_frontend *xc5000_attach(struct dvb_frontend *fe,
                printk(KERN_ERR
                        "xc5000: Device not found at addr 0x%02x (0x%x)\n",
                        cfg->i2c_address, id);
-               kfree(priv);
-               return NULL;
+               goto fail;
        }
 
+       mutex_unlock(&xc5000_list_mutex);
+
        memcpy(&fe->ops.tuner_ops, &xc5000_tuner_ops,
                sizeof(struct dvb_tuner_ops));
 
-       fe->tuner_priv = priv;
-
        if (xc5000_load_fw_on_attach)
                xc5000_init(fe);
 
        return fe;
+fail:
+       mutex_unlock(&xc5000_list_mutex);
+
+       xc5000_release(fe);
+       return NULL;
 }
 EXPORT_SYMBOL(xc5000_attach);
 
index 5389f740945ae82133bf3f53d07872a13d7b59e6..cf1a558e0e7f73c40cd8525f559563496bcef82f 100644 (file)
@@ -30,8 +30,6 @@ struct i2c_adapter;
 struct xc5000_config {
        u8   i2c_address;
        u32  if_khz;
-
-       int  (*tuner_callback) (void *priv, int command, int arg);
 };
 
 /* xc5000 callback command */
@@ -49,13 +47,11 @@ struct xc5000_config {
     (defined(CONFIG_MEDIA_TUNER_XC5000_MODULE) && defined(MODULE))
 extern struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
                                          struct i2c_adapter *i2c,
-                                         struct xc5000_config *cfg,
-                                         void *devptr);
+                                         struct xc5000_config *cfg);
 #else
 static inline struct dvb_frontend* xc5000_attach(struct dvb_frontend *fe,
                                                 struct i2c_adapter *i2c,
-                                                struct xc5000_config *cfg,
-                                                void *devptr)
+                                                struct xc5000_config *cfg)
 {
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
diff --git a/drivers/media/common/tuners/xc5000_priv.h b/drivers/media/common/tuners/xc5000_priv.h
deleted file mode 100644 (file)
index b2a0074..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- *  Driver for Xceive XC5000 "QAM/8VSB single chip tuner"
- *
- *  Copyright (c) 2007 Steven Toth <stoth@linuxtv.org>
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2 of the License, or
- *  (at your option) any later version.
- *
- *  This program is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- *
- *  GNU General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef XC5000_PRIV_H
-#define XC5000_PRIV_H
-
-struct xc5000_priv {
-       struct xc5000_config *cfg;
-       struct i2c_adapter   *i2c;
-
-       u32 freq_hz;
-       u32 bandwidth;
-       u8  video_standard;
-       u8  rf_mode;
-
-       void *devptr;
-};
-
-#endif
index 8bc1445bd33bda02d7c4d1bc6e5413aa375b51a7..0bcd852576d686a2b556b05e72467d687d49181d 100644 (file)
@@ -20,7 +20,6 @@ comment "Supported USB Adapters"
 source "drivers/media/dvb/dvb-usb/Kconfig"
 source "drivers/media/dvb/ttusb-budget/Kconfig"
 source "drivers/media/dvb/ttusb-dec/Kconfig"
-source "drivers/media/dvb/cinergyT2/Kconfig"
 source "drivers/media/dvb/siano/Kconfig"
 
 comment "Supported FlexCopII (B2C2) Adapters"
@@ -35,6 +34,10 @@ comment "Supported Pluto2 Adapters"
        depends on DVB_CORE && PCI && I2C
 source "drivers/media/dvb/pluto2/Kconfig"
 
+comment "Supported SDMC DM1105 Adapters"
+       depends on DVB_CORE && PCI && I2C
+source "drivers/media/dvb/dm1105/Kconfig"
+
 comment "Supported DVB Frontends"
        depends on DVB_CORE
 source "drivers/media/dvb/frontends/Kconfig"
index d6ba4d19520189b1606d7bedc595c26283e75518..f91e9eb15e52effa8e9f15d1e0e2e4573beeae59 100644 (file)
@@ -2,4 +2,4 @@
 # Makefile for the kernel multimedia device drivers.
 #
 
-obj-y        := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ cinergyT2/ dvb-usb/ pluto2/ siano/
+obj-y        := dvb-core/ frontends/ ttpci/ ttusb-dec/ ttusb-budget/ b2c2/ bt8xx/ dvb-usb/ pluto2/ siano/ dm1105/
index a91ed28f03a41d815f9edc2f32b7805535cf8ce1..26f0011a507813a0564b741ba7040a7c579fe8fc 100644 (file)
@@ -10,7 +10,7 @@
 int flexcop_dma_allocate(struct pci_dev *pdev, struct flexcop_dma *dma, u32 size)
 {
        u8 *tcpu;
-       dma_addr_t tdma;
+       dma_addr_t tdma = 0;
 
        if (size % 2) {
                err("dma buffersize has to be even.");
index 6afbfbbef0ce304885826365df8a40735c9a5ee7..48762a2b9e42e340c63f94534a171052e5b7f103 100644 (file)
@@ -702,7 +702,7 @@ static void frontend_init(struct dvb_bt8xx_card *card, u32 type)
        }
 
        if (card->fe == NULL)
-               printk("dvb-bt8xx: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+               printk("dvb-bt8xx: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       card->bt->dev->vendor,
                       card->bt->dev->device,
                       card->bt->dev->subsystem_vendor,
diff --git a/drivers/media/dvb/cinergyT2/Kconfig b/drivers/media/dvb/cinergyT2/Kconfig
deleted file mode 100644 (file)
index c03513b..0000000
+++ /dev/null
@@ -1,85 +0,0 @@
-config DVB_CINERGYT2
-       tristate "Terratec CinergyT2/qanu USB2 DVB-T receiver"
-       depends on DVB_CORE && USB && INPUT
-       help
-         Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers
-
-         Say Y if you own such a device and want to use it.
-
-
-config DVB_CINERGYT2_TUNING
-       bool "sophisticated fine-tuning for CinergyT2 cards"
-       depends on DVB_CINERGYT2
-       help
-         Here you can fine-tune some parameters of the CinergyT2 driver.
-
-         Normally you don't need to touch this, but in exotic setups you
-         may fine-tune your setup and adjust e.g. DMA buffer sizes for
-         a particular application.
-
-
-config DVB_CINERGYT2_STREAM_URB_COUNT
-       int "Number of queued USB Request Blocks for Highspeed Stream Transfers"
-       depends on DVB_CINERGYT2_TUNING
-       default "32"
-       help
-         USB Request Blocks for Highspeed Stream transfers are scheduled in
-         a queue for the Host Controller.
-
-         Usually the default value is a safe choice.
-
-         You may increase this number if you are using this device in a
-         Server Environment with many high-traffic USB Highspeed devices
-         sharing the same USB bus.
-
-
-config DVB_CINERGYT2_STREAM_BUF_SIZE
-       int "Size of URB Stream Buffers for Highspeed Transfers"
-       depends on DVB_CINERGYT2_TUNING
-       default "512"
-       help
-         Should be a multiple of native buffer size of 512 bytes.
-         Default value is a safe choice.
-
-         You may increase this number if you are using this device in a
-         Server Environment with many high-traffic USB Highspeed devices
-         sharing the same USB bus.
-
-
-config DVB_CINERGYT2_QUERY_INTERVAL
-       int "Status update interval [milliseconds]"
-       depends on DVB_CINERGYT2_TUNING
-       default "250"
-       help
-         This is the interval for status readouts from the demodulator.
-         You may try lower values if you need more responsive signal quality
-         measurements.
-
-         Please keep in mind that these updates cause traffic on the tuner
-         control bus and thus may or may not affect reception sensitivity.
-
-         The default value should be a safe choice for common applications.
-
-
-config DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
-       bool "Register the onboard IR Remote Control Receiver as Input Device"
-       depends on DVB_CINERGYT2_TUNING
-       default y
-       help
-         Enable this option if you want to use the onboard Infrared Remote
-         Control Receiver as Linux-Input device.
-
-         Right now only the keycode table for the default Remote Control
-         delivered with the device is supported, please see the driver
-         source code to find out how to add support for other controls.
-
-
-config DVB_CINERGYT2_RC_QUERY_INTERVAL
-       int "Infrared Remote Controller update interval [milliseconds]"
-       depends on DVB_CINERGYT2_TUNING && DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
-       default "50"
-       help
-         If you have a very fast-repeating remote control you can try lower
-         values, for normal consumer receivers the default value should be
-         a safe choice.
-
diff --git a/drivers/media/dvb/cinergyT2/Makefile b/drivers/media/dvb/cinergyT2/Makefile
deleted file mode 100644 (file)
index d762d8c..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-obj-$(CONFIG_DVB_CINERGYT2) += cinergyT2.o
-
-EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/
diff --git a/drivers/media/dvb/cinergyT2/cinergyT2.c b/drivers/media/dvb/cinergyT2/cinergyT2.c
deleted file mode 100644 (file)
index a824f37..0000000
+++ /dev/null
@@ -1,1105 +0,0 @@
-/*
- * TerraTec Cinergy T²/qanu USB2 DVB-T adapter.
- *
- * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
- *                 Holger Waechtler <holger@qanu.de>
- *
- *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- */
-
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/slab.h>
-#include <linux/usb.h>
-#include <linux/input.h>
-#include <linux/dvb/frontend.h>
-#include <linux/mutex.h>
-#include <linux/mm.h>
-#include <asm/io.h>
-
-#include "dmxdev.h"
-#include "dvb_demux.h"
-#include "dvb_net.h"
-
-#ifdef CONFIG_DVB_CINERGYT2_TUNING
-       #define STREAM_URB_COUNT (CONFIG_DVB_CINERGYT2_STREAM_URB_COUNT)
-       #define STREAM_BUF_SIZE (CONFIG_DVB_CINERGYT2_STREAM_BUF_SIZE)
-       #define QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_QUERY_INTERVAL)
-       #ifdef CONFIG_DVB_CINERGYT2_ENABLE_RC_INPUT_DEVICE
-               #define RC_QUERY_INTERVAL (CONFIG_DVB_CINERGYT2_RC_QUERY_INTERVAL)
-               #define ENABLE_RC (1)
-       #endif
-#else
-       #define STREAM_URB_COUNT (32)
-       #define STREAM_BUF_SIZE (512)   /* bytes */
-       #define ENABLE_RC (1)
-       #define RC_QUERY_INTERVAL (50)  /* milliseconds */
-       #define QUERY_INTERVAL (333)    /* milliseconds */
-#endif
-
-#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
-
-static int debug;
-module_param_named(debug, debug, int, 0644);
-MODULE_PARM_DESC(debug, "Turn on/off debugging (default:off).");
-
-DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
-
-#define dprintk(level, args...)                                                \
-do {                                                                   \
-       if ((debug & level)) {                                          \
-               printk("%s: %s(): ", KBUILD_MODNAME,                    \
-                      __func__);                                       \
-               printk(args); }                                         \
-} while (0)
-
-enum cinergyt2_ep1_cmd {
-       CINERGYT2_EP1_PID_TABLE_RESET           = 0x01,
-       CINERGYT2_EP1_PID_SETUP                 = 0x02,
-       CINERGYT2_EP1_CONTROL_STREAM_TRANSFER   = 0x03,
-       CINERGYT2_EP1_SET_TUNER_PARAMETERS      = 0x04,
-       CINERGYT2_EP1_GET_TUNER_STATUS          = 0x05,
-       CINERGYT2_EP1_START_SCAN                = 0x06,
-       CINERGYT2_EP1_CONTINUE_SCAN             = 0x07,
-       CINERGYT2_EP1_GET_RC_EVENTS             = 0x08,
-       CINERGYT2_EP1_SLEEP_MODE                = 0x09
-};
-
-struct dvbt_set_parameters_msg {
-       uint8_t cmd;
-       __le32 freq;
-       uint8_t bandwidth;
-       __le16 tps;
-       uint8_t flags;
-} __attribute__((packed));
-
-struct dvbt_get_status_msg {
-       __le32 freq;
-       uint8_t bandwidth;
-       __le16 tps;
-       uint8_t flags;
-       __le16 gain;
-       uint8_t snr;
-       __le32 viterbi_error_rate;
-       __le32 rs_error_rate;
-       __le32 uncorrected_block_count;
-       uint8_t lock_bits;
-       uint8_t prev_lock_bits;
-} __attribute__((packed));
-
-static struct dvb_frontend_info cinergyt2_fe_info = {
-       .name = DRIVER_NAME,
-       .type = FE_OFDM,
-       .frequency_min = 174000000,
-       .frequency_max = 862000000,
-       .frequency_stepsize = 166667,
-       .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 |
-               FE_CAN_FEC_3_4 | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
-               FE_CAN_FEC_AUTO |
-               FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
-               FE_CAN_TRANSMISSION_MODE_AUTO | FE_CAN_GUARD_INTERVAL_AUTO |
-               FE_CAN_HIERARCHY_AUTO | FE_CAN_RECOVER | FE_CAN_MUTE_TS
-};
-
-struct cinergyt2 {
-       struct dvb_demux demux;
-       struct usb_device *udev;
-       struct mutex sem;
-       struct mutex wq_sem;
-       struct dvb_adapter adapter;
-       struct dvb_device *fedev;
-       struct dmxdev dmxdev;
-       struct dvb_net dvbnet;
-
-       int streaming;
-       int sleeping;
-
-       struct dvbt_set_parameters_msg param;
-       struct dvbt_get_status_msg status;
-       struct delayed_work query_work;
-
-       wait_queue_head_t poll_wq;
-       int pending_fe_events;
-       int disconnect_pending;
-       unsigned int uncorrected_block_count;
-       atomic_t inuse;
-
-       void *streambuf;
-       dma_addr_t streambuf_dmahandle;
-       struct urb *stream_urb [STREAM_URB_COUNT];
-
-#ifdef ENABLE_RC
-       struct input_dev *rc_input_dev;
-       char phys[64];
-       struct delayed_work rc_query_work;
-       int rc_input_event;
-       __le32 rc_last_code;
-       unsigned long last_event_jiffies;
-#endif
-};
-
-enum {
-       CINERGYT2_RC_EVENT_TYPE_NONE = 0x00,
-       CINERGYT2_RC_EVENT_TYPE_NEC  = 0x01,
-       CINERGYT2_RC_EVENT_TYPE_RC5  = 0x02
-};
-
-struct cinergyt2_rc_event {
-       char type;
-       __le32 value;
-} __attribute__((packed));
-
-static const uint32_t rc_keys[] = {
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xfe01eb04,     KEY_POWER,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xfd02eb04,     KEY_1,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xfc03eb04,     KEY_2,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xfb04eb04,     KEY_3,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xfa05eb04,     KEY_4,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf906eb04,     KEY_5,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf807eb04,     KEY_6,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf708eb04,     KEY_7,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf609eb04,     KEY_8,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf50aeb04,     KEY_9,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf30ceb04,     KEY_0,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf40beb04,     KEY_VIDEO,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf20deb04,     KEY_REFRESH,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf10eeb04,     KEY_SELECT,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xf00feb04,     KEY_EPG,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xef10eb04,     KEY_UP,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xeb14eb04,     KEY_DOWN,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xee11eb04,     KEY_LEFT,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xec13eb04,     KEY_RIGHT,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xed12eb04,     KEY_OK,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xea15eb04,     KEY_TEXT,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe916eb04,     KEY_INFO,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe817eb04,     KEY_RED,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe718eb04,     KEY_GREEN,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe619eb04,     KEY_YELLOW,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe51aeb04,     KEY_BLUE,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe31ceb04,     KEY_VOLUMEUP,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe11eeb04,     KEY_VOLUMEDOWN,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe21deb04,     KEY_MUTE,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe41beb04,     KEY_CHANNELUP,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xe01feb04,     KEY_CHANNELDOWN,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xbf40eb04,     KEY_PAUSE,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xb34ceb04,     KEY_PLAY,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xa758eb04,     KEY_RECORD,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xab54eb04,     KEY_PREVIOUS,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xb748eb04,     KEY_STOP,
-       CINERGYT2_RC_EVENT_TYPE_NEC,    0xa35ceb04,     KEY_NEXT
-};
-
-static int cinergyt2_command (struct cinergyt2 *cinergyt2,
-                             char *send_buf, int send_buf_len,
-                             char *recv_buf, int recv_buf_len)
-{
-       int actual_len;
-       char dummy;
-       int ret;
-
-       ret = usb_bulk_msg(cinergyt2->udev, usb_sndbulkpipe(cinergyt2->udev, 1),
-                          send_buf, send_buf_len, &actual_len, 1000);
-
-       if (ret)
-               dprintk(1, "usb_bulk_msg (send) failed, err %i\n", ret);
-
-       if (!recv_buf)
-               recv_buf = &dummy;
-
-       ret = usb_bulk_msg(cinergyt2->udev, usb_rcvbulkpipe(cinergyt2->udev, 1),
-                          recv_buf, recv_buf_len, &actual_len, 1000);
-
-       if (ret)
-               dprintk(1, "usb_bulk_msg (read) failed, err %i\n", ret);
-
-       return ret ? ret : actual_len;
-}
-
-static void cinergyt2_control_stream_transfer (struct cinergyt2 *cinergyt2, int enable)
-{
-       char buf [] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
-       cinergyt2_command(cinergyt2, buf, sizeof(buf), NULL, 0);
-}
-
-static void cinergyt2_sleep (struct cinergyt2 *cinergyt2, int sleep)
-{
-       char buf [] = { CINERGYT2_EP1_SLEEP_MODE, sleep ? 1 : 0 };
-       cinergyt2_command(cinergyt2, buf, sizeof(buf), NULL, 0);
-       cinergyt2->sleeping = sleep;
-}
-
-static void cinergyt2_stream_irq (struct urb *urb);
-
-static int cinergyt2_submit_stream_urb (struct cinergyt2 *cinergyt2, struct urb *urb)
-{
-       int err;
-
-       usb_fill_bulk_urb(urb,
-                         cinergyt2->udev,
-                         usb_rcvbulkpipe(cinergyt2->udev, 0x2),
-                         urb->transfer_buffer,
-                         STREAM_BUF_SIZE,
-                         cinergyt2_stream_irq,
-                         cinergyt2);
-
-       if ((err = usb_submit_urb(urb, GFP_ATOMIC)))
-               dprintk(1, "urb submission failed (err = %i)!\n", err);
-
-       return err;
-}
-
-static void cinergyt2_stream_irq (struct urb *urb)
-{
-       struct cinergyt2 *cinergyt2 = urb->context;
-
-       if (urb->actual_length > 0)
-               dvb_dmx_swfilter(&cinergyt2->demux,
-                                urb->transfer_buffer, urb->actual_length);
-
-       if (cinergyt2->streaming)
-               cinergyt2_submit_stream_urb(cinergyt2, urb);
-}
-
-static void cinergyt2_free_stream_urbs (struct cinergyt2 *cinergyt2)
-{
-       int i;
-
-       for (i=0; i<STREAM_URB_COUNT; i++)
-               usb_free_urb(cinergyt2->stream_urb[i]);
-
-       usb_buffer_free(cinergyt2->udev, STREAM_URB_COUNT*STREAM_BUF_SIZE,
-                           cinergyt2->streambuf, cinergyt2->streambuf_dmahandle);
-}
-
-static int cinergyt2_alloc_stream_urbs (struct cinergyt2 *cinergyt2)
-{
-       int i;
-
-       cinergyt2->streambuf = usb_buffer_alloc(cinergyt2->udev, STREAM_URB_COUNT*STREAM_BUF_SIZE,
-                                             GFP_KERNEL, &cinergyt2->streambuf_dmahandle);
-       if (!cinergyt2->streambuf) {
-               dprintk(1, "failed to alloc consistent stream memory area, bailing out!\n");
-               return -ENOMEM;
-       }
-
-       memset(cinergyt2->streambuf, 0, STREAM_URB_COUNT*STREAM_BUF_SIZE);
-
-       for (i=0; i<STREAM_URB_COUNT; i++) {
-               struct urb *urb;
-
-               if (!(urb = usb_alloc_urb(0, GFP_ATOMIC))) {
-                       dprintk(1, "failed to alloc consistent stream urbs, bailing out!\n");
-                       cinergyt2_free_stream_urbs(cinergyt2);
-                       return -ENOMEM;
-               }
-
-               urb->transfer_buffer = cinergyt2->streambuf + i * STREAM_BUF_SIZE;
-               urb->transfer_buffer_length = STREAM_BUF_SIZE;
-
-               cinergyt2->stream_urb[i] = urb;
-       }
-
-       return 0;
-}
-
-static void cinergyt2_stop_stream_xfer (struct cinergyt2 *cinergyt2)
-{
-       int i;
-
-       cinergyt2_control_stream_transfer(cinergyt2, 0);
-
-       for (i=0; i<STREAM_URB_COUNT; i++)
-               usb_kill_urb(cinergyt2->stream_urb[i]);
-}
-
-static int cinergyt2_start_stream_xfer (struct cinergyt2 *cinergyt2)
-{
-       int i, err;
-
-       for (i=0; i<STREAM_URB_COUNT; i++) {
-               if ((err = cinergyt2_submit_stream_urb(cinergyt2, cinergyt2->stream_urb[i]))) {
-                       cinergyt2_stop_stream_xfer(cinergyt2);
-                       dprintk(1, "failed urb submission (%i: err = %i)!\n", i, err);
-                       return err;
-               }
-       }
-
-       cinergyt2_control_stream_transfer(cinergyt2, 1);
-       return 0;
-}
-
-static int cinergyt2_start_feed(struct dvb_demux_feed *dvbdmxfeed)
-{
-       struct dvb_demux *demux = dvbdmxfeed->demux;
-       struct cinergyt2 *cinergyt2 = demux->priv;
-
-       if (cinergyt2->disconnect_pending)
-               return -EAGAIN;
-       if (mutex_lock_interruptible(&cinergyt2->sem))
-               return -ERESTARTSYS;
-
-       if (cinergyt2->streaming == 0)
-               cinergyt2_start_stream_xfer(cinergyt2);
-
-       cinergyt2->streaming++;
-       mutex_unlock(&cinergyt2->sem);
-       return 0;
-}
-
-static int cinergyt2_stop_feed(struct dvb_demux_feed *dvbdmxfeed)
-{
-       struct dvb_demux *demux = dvbdmxfeed->demux;
-       struct cinergyt2 *cinergyt2 = demux->priv;
-
-       if (cinergyt2->disconnect_pending)
-               return -EAGAIN;
-       if (mutex_lock_interruptible(&cinergyt2->sem))
-               return -ERESTARTSYS;
-
-       if (--cinergyt2->streaming == 0)
-               cinergyt2_stop_stream_xfer(cinergyt2);
-
-       mutex_unlock(&cinergyt2->sem);
-       return 0;
-}
-
-/**
- *  convert linux-dvb frontend parameter set into TPS.
- *  See ETSI ETS-300744, section 4.6.2, table 9 for details.
- *
- *  This function is probably reusable and may better get placed in a support
- *  library.
- *
- *  We replace errornous fields by default TPS fields (the ones with value 0).
- */
-static uint16_t compute_tps (struct dvb_frontend_parameters *p)
-{
-       struct dvb_ofdm_parameters *op = &p->u.ofdm;
-       uint16_t tps = 0;
-
-       switch (op->code_rate_HP) {
-               case FEC_2_3:
-                       tps |= (1 << 7);
-                       break;
-               case FEC_3_4:
-                       tps |= (2 << 7);
-                       break;
-               case FEC_5_6:
-                       tps |= (3 << 7);
-                       break;
-               case FEC_7_8:
-                       tps |= (4 << 7);
-                       break;
-               case FEC_1_2:
-               case FEC_AUTO:
-               default:
-                       /* tps |= (0 << 7) */;
-       }
-
-       switch (op->code_rate_LP) {
-               case FEC_2_3:
-                       tps |= (1 << 4);
-                       break;
-               case FEC_3_4:
-                       tps |= (2 << 4);
-                       break;
-               case FEC_5_6:
-                       tps |= (3 << 4);
-                       break;
-               case FEC_7_8:
-                       tps |= (4 << 4);
-                       break;
-               case FEC_1_2:
-               case FEC_AUTO:
-               default:
-                       /* tps |= (0 << 4) */;
-       }
-
-       switch (op->constellation) {
-               case QAM_16:
-                       tps |= (1 << 13);
-                       break;
-               case QAM_64:
-                       tps |= (2 << 13);
-                       break;
-               case QPSK:
-               default:
-                       /* tps |= (0 << 13) */;
-       }
-
-       switch (op->transmission_mode) {
-               case TRANSMISSION_MODE_8K:
-                       tps |= (1 << 0);
-                       break;
-               case TRANSMISSION_MODE_2K:
-               default:
-                       /* tps |= (0 << 0) */;
-       }
-
-       switch (op->guard_interval) {
-               case GUARD_INTERVAL_1_16:
-                       tps |= (1 << 2);
-                       break;
-               case GUARD_INTERVAL_1_8:
-                       tps |= (2 << 2);
-                       break;
-               case GUARD_INTERVAL_1_4:
-                       tps |= (3 << 2);
-                       break;
-               case GUARD_INTERVAL_1_32:
-               default:
-                       /* tps |= (0 << 2) */;
-       }
-
-       switch (op->hierarchy_information) {
-               case HIERARCHY_1:
-                       tps |= (1 << 10);
-                       break;
-               case HIERARCHY_2:
-                       tps |= (2 << 10);
-                       break;
-               case HIERARCHY_4:
-                       tps |= (3 << 10);
-                       break;
-               case HIERARCHY_NONE:
-               default:
-                       /* tps |= (0 << 10) */;
-       }
-
-       return tps;
-}
-
-static int cinergyt2_open (struct inode *inode, struct file *file)
-{
-       struct dvb_device *dvbdev = file->private_data;
-       struct cinergyt2 *cinergyt2 = dvbdev->priv;
-       int err = -EAGAIN;
-
-       if (cinergyt2->disconnect_pending)
-               goto out;
-       err = mutex_lock_interruptible(&cinergyt2->wq_sem);
-       if (err)
-               goto out;
-
-       err = mutex_lock_interruptible(&cinergyt2->sem);
-       if (err)
-               goto out_unlock1;
-
-       if ((err = dvb_generic_open(inode, file)))
-               goto out_unlock2;
-
-       if ((file->f_flags & O_ACCMODE) != O_RDONLY) {
-               cinergyt2_sleep(cinergyt2, 0);
-               schedule_delayed_work(&cinergyt2->query_work, HZ/2);
-       }
-
-       atomic_inc(&cinergyt2->inuse);
-
-out_unlock2:
-       mutex_unlock(&cinergyt2->sem);
-out_unlock1:
-       mutex_unlock(&cinergyt2->wq_sem);
-out:
-       return err;
-}
-
-static void cinergyt2_unregister(struct cinergyt2 *cinergyt2)
-{
-       dvb_net_release(&cinergyt2->dvbnet);
-       dvb_dmxdev_release(&cinergyt2->dmxdev);
-       dvb_dmx_release(&cinergyt2->demux);
-       dvb_unregister_device(cinergyt2->fedev);
-       dvb_unregister_adapter(&cinergyt2->adapter);
-
-       cinergyt2_free_stream_urbs(cinergyt2);
-       kfree(cinergyt2);
-}
-
-static int cinergyt2_release (struct inode *inode, struct file *file)
-{
-       struct dvb_device *dvbdev = file->private_data;
-       struct cinergyt2 *cinergyt2 = dvbdev->priv;
-
-       mutex_lock(&cinergyt2->wq_sem);
-
-       if (!cinergyt2->disconnect_pending && (file->f_flags & O_ACCMODE) != O_RDONLY) {
-               cancel_rearming_delayed_work(&cinergyt2->query_work);
-
-               mutex_lock(&cinergyt2->sem);
-               cinergyt2_sleep(cinergyt2, 1);
-               mutex_unlock(&cinergyt2->sem);
-       }
-
-       mutex_unlock(&cinergyt2->wq_sem);
-
-       if (atomic_dec_and_test(&cinergyt2->inuse) && cinergyt2->disconnect_pending) {
-               warn("delayed unregister in release");
-               cinergyt2_unregister(cinergyt2);
-       }
-
-       return dvb_generic_release(inode, file);
-}
-
-static unsigned int cinergyt2_poll (struct file *file, struct poll_table_struct *wait)
-{
-       struct dvb_device *dvbdev = file->private_data;
-       struct cinergyt2 *cinergyt2 = dvbdev->priv;
-       unsigned int mask = 0;
-
-       if (cinergyt2->disconnect_pending)
-               return -EAGAIN;
-       if (mutex_lock_interruptible(&cinergyt2->sem))
-               return -ERESTARTSYS;
-
-       poll_wait(file, &cinergyt2->poll_wq, wait);
-
-       if (cinergyt2->pending_fe_events != 0)
-               mask |= (POLLIN | POLLRDNORM | POLLPRI);
-
-       mutex_unlock(&cinergyt2->sem);
-
-       return mask;
-}
-
-
-static int cinergyt2_ioctl (struct inode *inode, struct file *file,
-                    unsigned cmd, unsigned long arg)
-{
-       struct dvb_device *dvbdev = file->private_data;
-       struct cinergyt2 *cinergyt2 = dvbdev->priv;
-       struct dvbt_get_status_msg *stat = &cinergyt2->status;
-       fe_status_t status = 0;
-
-       switch (cmd) {
-       case FE_GET_INFO:
-               return copy_to_user((void __user*) arg, &cinergyt2_fe_info,
-                                   sizeof(struct dvb_frontend_info));
-
-       case FE_READ_STATUS:
-               if (0xffff - le16_to_cpu(stat->gain) > 30)
-                       status |= FE_HAS_SIGNAL;
-               if (stat->lock_bits & (1 << 6))
-                       status |= FE_HAS_LOCK;
-               if (stat->lock_bits & (1 << 5))
-                       status |= FE_HAS_SYNC;
-               if (stat->lock_bits & (1 << 4))
-                       status |= FE_HAS_CARRIER;
-               if (stat->lock_bits & (1 << 1))
-                       status |= FE_HAS_VITERBI;
-
-               return copy_to_user((void  __user*) arg, &status, sizeof(status));
-
-       case FE_READ_BER:
-               return put_user(le32_to_cpu(stat->viterbi_error_rate),
-                               (__u32 __user *) arg);
-
-       case FE_READ_SIGNAL_STRENGTH:
-               return put_user(0xffff - le16_to_cpu(stat->gain),
-                               (__u16 __user *) arg);
-
-       case FE_READ_SNR:
-               return put_user((stat->snr << 8) | stat->snr,
-                               (__u16 __user *) arg);
-
-       case FE_READ_UNCORRECTED_BLOCKS:
-       {
-               uint32_t unc_count;
-
-               if (mutex_lock_interruptible(&cinergyt2->sem))
-                       return -ERESTARTSYS;
-               unc_count = cinergyt2->uncorrected_block_count;
-               cinergyt2->uncorrected_block_count = 0;
-               mutex_unlock(&cinergyt2->sem);
-
-               /* UNC are already converted to host byte order... */
-               return put_user(unc_count,(__u32 __user *) arg);
-       }
-       case FE_SET_FRONTEND:
-       {
-               struct dvbt_set_parameters_msg *param = &cinergyt2->param;
-               struct dvb_frontend_parameters p;
-               int err;
-
-               if ((file->f_flags & O_ACCMODE) == O_RDONLY)
-                       return -EPERM;
-
-               if (copy_from_user(&p, (void  __user*) arg, sizeof(p)))
-                       return -EFAULT;
-
-               if (cinergyt2->disconnect_pending)
-                       return -EAGAIN;
-               if (mutex_lock_interruptible(&cinergyt2->sem))
-                       return -ERESTARTSYS;
-
-               param->cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
-               param->tps = cpu_to_le16(compute_tps(&p));
-               param->freq = cpu_to_le32(p.frequency / 1000);
-               param->bandwidth = 8 - p.u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
-
-               stat->lock_bits = 0;
-               cinergyt2->pending_fe_events++;
-               wake_up_interruptible(&cinergyt2->poll_wq);
-
-               err = cinergyt2_command(cinergyt2,
-                                       (char *) param, sizeof(*param),
-                                       NULL, 0);
-
-               mutex_unlock(&cinergyt2->sem);
-
-               return (err < 0) ? err : 0;
-       }
-
-       case FE_GET_FRONTEND:
-               /**
-                *  trivial to implement (see struct dvbt_get_status_msg).
-                *  equivalent to FE_READ ioctls, but needs
-                *  TPS -> linux-dvb parameter set conversion. Feel free
-                *  to implement this and send us a patch if you need this
-                *  functionality.
-                */
-               break;
-
-       case FE_GET_EVENT:
-       {
-               /**
-                *  for now we only fill the status field. the parameters
-                *  are trivial to fill as soon FE_GET_FRONTEND is done.
-                */
-               struct dvb_frontend_event __user *e = (void __user *) arg;
-               if (cinergyt2->pending_fe_events == 0) {
-                       if (file->f_flags & O_NONBLOCK)
-                               return -EWOULDBLOCK;
-                       wait_event_interruptible(cinergyt2->poll_wq,
-                                                cinergyt2->pending_fe_events > 0);
-               }
-               cinergyt2->pending_fe_events = 0;
-               return cinergyt2_ioctl(inode, file, FE_READ_STATUS,
-                                       (unsigned long) &e->status);
-       }
-
-       default:
-               ;
-       }
-
-       return -EINVAL;
-}
-
-static int cinergyt2_mmap(struct file *file, struct vm_area_struct *vma)
-{
-       struct dvb_device *dvbdev = file->private_data;
-       struct cinergyt2 *cinergyt2 = dvbdev->priv;
-       int ret = 0;
-
-       lock_kernel();
-
-       if (vma->vm_flags & (VM_WRITE | VM_EXEC)) {
-               ret = -EPERM;
-               goto bailout;
-       }
-
-       if (vma->vm_end > vma->vm_start + STREAM_URB_COUNT * STREAM_BUF_SIZE) {
-               ret = -EINVAL;
-               goto bailout;
-       }
-
-       vma->vm_flags |= (VM_IO | VM_DONTCOPY);
-       vma->vm_file = file;
-
-       ret = remap_pfn_range(vma, vma->vm_start,
-                             virt_to_phys(cinergyt2->streambuf) >> PAGE_SHIFT,
-                             vma->vm_end - vma->vm_start,
-                             vma->vm_page_prot) ? -EAGAIN : 0;
-bailout:
-       unlock_kernel();
-       return ret;
-}
-
-static struct file_operations cinergyt2_fops = {
-       .owner          = THIS_MODULE,
-       .ioctl          = cinergyt2_ioctl,
-       .poll           = cinergyt2_poll,
-       .open           = cinergyt2_open,
-       .release        = cinergyt2_release,
-       .mmap           = cinergyt2_mmap
-};
-
-static struct dvb_device cinergyt2_fe_template = {
-       .users = ~0,
-       .writers = 1,
-       .readers = (~0)-1,
-       .fops = &cinergyt2_fops
-};
-
-#ifdef ENABLE_RC
-
-static void cinergyt2_query_rc (struct work_struct *work)
-{
-       struct cinergyt2 *cinergyt2 =
-               container_of(work, struct cinergyt2, rc_query_work.work);
-       char buf[1] = { CINERGYT2_EP1_GET_RC_EVENTS };
-       struct cinergyt2_rc_event rc_events[12];
-       int n, len, i;
-
-       if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
-               return;
-
-       len = cinergyt2_command(cinergyt2, buf, sizeof(buf),
-                               (char *) rc_events, sizeof(rc_events));
-       if (len < 0)
-               goto out;
-       if (len == 0) {
-               if (time_after(jiffies, cinergyt2->last_event_jiffies +
-                              msecs_to_jiffies(150))) {
-                       /* stop key repeat */
-                       if (cinergyt2->rc_input_event != KEY_MAX) {
-                               dprintk(1, "rc_input_event=%d Up\n", cinergyt2->rc_input_event);
-                               input_report_key(cinergyt2->rc_input_dev,
-                                                cinergyt2->rc_input_event, 0);
-                               input_sync(cinergyt2->rc_input_dev);
-                               cinergyt2->rc_input_event = KEY_MAX;
-                       }
-                       cinergyt2->rc_last_code = cpu_to_le32(~0);
-               }
-               goto out;
-       }
-       cinergyt2->last_event_jiffies = jiffies;
-
-       for (n = 0; n < (len / sizeof(rc_events[0])); n++) {
-               dprintk(1, "rc_events[%d].value = %x, type=%x\n",
-                       n, le32_to_cpu(rc_events[n].value), rc_events[n].type);
-
-               if (rc_events[n].type == CINERGYT2_RC_EVENT_TYPE_NEC &&
-                   rc_events[n].value == cpu_to_le32(~0)) {
-                       /* keyrepeat bit -> just repeat last rc_input_event */
-               } else {
-                       cinergyt2->rc_input_event = KEY_MAX;
-                       for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3) {
-                               if (rc_keys[i + 0] == rc_events[n].type &&
-                                   rc_keys[i + 1] == le32_to_cpu(rc_events[n].value)) {
-                                       cinergyt2->rc_input_event = rc_keys[i + 2];
-                                       break;
-                               }
-                       }
-               }
-
-               if (cinergyt2->rc_input_event != KEY_MAX) {
-                       if (rc_events[n].value == cinergyt2->rc_last_code &&
-                           cinergyt2->rc_last_code != cpu_to_le32(~0)) {
-                               /* emit a key-up so the double event is recognized */
-                               dprintk(1, "rc_input_event=%d UP\n", cinergyt2->rc_input_event);
-                               input_report_key(cinergyt2->rc_input_dev,
-                                                cinergyt2->rc_input_event, 0);
-                       }
-                       dprintk(1, "rc_input_event=%d\n", cinergyt2->rc_input_event);
-                       input_report_key(cinergyt2->rc_input_dev,
-                                        cinergyt2->rc_input_event, 1);
-                       input_sync(cinergyt2->rc_input_dev);
-                       cinergyt2->rc_last_code = rc_events[n].value;
-               }
-       }
-
-out:
-       schedule_delayed_work(&cinergyt2->rc_query_work,
-                             msecs_to_jiffies(RC_QUERY_INTERVAL));
-
-       mutex_unlock(&cinergyt2->sem);
-}
-
-static int cinergyt2_register_rc(struct cinergyt2 *cinergyt2)
-{
-       struct input_dev *input_dev;
-       int i;
-       int err;
-
-       input_dev = input_allocate_device();
-       if (!input_dev)
-               return -ENOMEM;
-
-       usb_make_path(cinergyt2->udev, cinergyt2->phys, sizeof(cinergyt2->phys));
-       strlcat(cinergyt2->phys, "/input0", sizeof(cinergyt2->phys));
-       cinergyt2->rc_input_event = KEY_MAX;
-       cinergyt2->rc_last_code = cpu_to_le32(~0);
-       INIT_DELAYED_WORK(&cinergyt2->rc_query_work, cinergyt2_query_rc);
-
-       input_dev->name = DRIVER_NAME " remote control";
-       input_dev->phys = cinergyt2->phys;
-       input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
-       for (i = 0; i < ARRAY_SIZE(rc_keys); i += 3)
-               set_bit(rc_keys[i + 2], input_dev->keybit);
-       input_dev->keycodesize = 0;
-       input_dev->keycodemax = 0;
-       input_dev->id.bustype = BUS_USB;
-       input_dev->id.vendor = le16_to_cpu(cinergyt2->udev->descriptor.idVendor);
-       input_dev->id.product = le16_to_cpu(cinergyt2->udev->descriptor.idProduct);
-       input_dev->id.version = 1;
-       input_dev->dev.parent = &cinergyt2->udev->dev;
-
-       err = input_register_device(input_dev);
-       if (err) {
-               input_free_device(input_dev);
-               return err;
-       }
-
-       cinergyt2->rc_input_dev = input_dev;
-       schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
-
-       return 0;
-}
-
-static void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2)
-{
-       cancel_rearming_delayed_work(&cinergyt2->rc_query_work);
-       input_unregister_device(cinergyt2->rc_input_dev);
-}
-
-static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2)
-{
-       cancel_rearming_delayed_work(&cinergyt2->rc_query_work);
-}
-
-static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2)
-{
-       schedule_delayed_work(&cinergyt2->rc_query_work, HZ/2);
-}
-
-#else
-
-static inline int cinergyt2_register_rc(struct cinergyt2 *cinergyt2) { return 0; }
-static inline void cinergyt2_unregister_rc(struct cinergyt2 *cinergyt2) { }
-static inline void cinergyt2_suspend_rc(struct cinergyt2 *cinergyt2) { }
-static inline void cinergyt2_resume_rc(struct cinergyt2 *cinergyt2) { }
-
-#endif /* ENABLE_RC */
-
-static void cinergyt2_query (struct work_struct *work)
-{
-       struct cinergyt2 *cinergyt2 =
-               container_of(work, struct cinergyt2, query_work.work);
-       char cmd [] = { CINERGYT2_EP1_GET_TUNER_STATUS };
-       struct dvbt_get_status_msg *s = &cinergyt2->status;
-       uint8_t lock_bits;
-
-       if (cinergyt2->disconnect_pending || mutex_lock_interruptible(&cinergyt2->sem))
-               return;
-
-       lock_bits = s->lock_bits;
-
-       cinergyt2_command(cinergyt2, cmd, sizeof(cmd), (char *) s, sizeof(*s));
-
-       cinergyt2->uncorrected_block_count +=
-               le32_to_cpu(s->uncorrected_block_count);
-
-       if (lock_bits != s->lock_bits) {
-               wake_up_interruptible(&cinergyt2->poll_wq);
-               cinergyt2->pending_fe_events++;
-       }
-
-       schedule_delayed_work(&cinergyt2->query_work,
-                             msecs_to_jiffies(QUERY_INTERVAL));
-
-       mutex_unlock(&cinergyt2->sem);
-}
-
-static int cinergyt2_probe (struct usb_interface *intf,
-                 const struct usb_device_id *id)
-{
-       struct cinergyt2 *cinergyt2;
-       int err;
-
-       if (!(cinergyt2 = kzalloc (sizeof(struct cinergyt2), GFP_KERNEL))) {
-               dprintk(1, "out of memory?!?\n");
-               return -ENOMEM;
-       }
-
-       usb_set_intfdata (intf, (void *) cinergyt2);
-
-       mutex_init(&cinergyt2->sem);
-       mutex_init(&cinergyt2->wq_sem);
-       init_waitqueue_head (&cinergyt2->poll_wq);
-       INIT_DELAYED_WORK(&cinergyt2->query_work, cinergyt2_query);
-
-       cinergyt2->udev = interface_to_usbdev(intf);
-       cinergyt2->param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
-
-       if (cinergyt2_alloc_stream_urbs (cinergyt2) < 0) {
-               dprintk(1, "unable to allocate stream urbs\n");
-               kfree(cinergyt2);
-               return -ENOMEM;
-       }
-
-       err = dvb_register_adapter(&cinergyt2->adapter, DRIVER_NAME,
-                                  THIS_MODULE, &cinergyt2->udev->dev,
-                                  adapter_nr);
-       if (err < 0) {
-               kfree(cinergyt2);
-               return err;
-       }
-
-       cinergyt2->demux.priv = cinergyt2;
-       cinergyt2->demux.filternum = 256;
-       cinergyt2->demux.feednum = 256;
-       cinergyt2->demux.start_feed = cinergyt2_start_feed;
-       cinergyt2->demux.stop_feed = cinergyt2_stop_feed;
-       cinergyt2->demux.dmx.capabilities = DMX_TS_FILTERING |
-                                           DMX_SECTION_FILTERING |
-                                           DMX_MEMORY_BASED_FILTERING;
-
-       if ((err = dvb_dmx_init(&cinergyt2->demux)) < 0) {
-               dprintk(1, "dvb_dmx_init() failed (err = %d)\n", err);
-               goto bailout;
-       }
-
-       cinergyt2->dmxdev.filternum = cinergyt2->demux.filternum;
-       cinergyt2->dmxdev.demux = &cinergyt2->demux.dmx;
-       cinergyt2->dmxdev.capabilities = 0;
-
-       if ((err = dvb_dmxdev_init(&cinergyt2->dmxdev, &cinergyt2->adapter)) < 0) {
-               dprintk(1, "dvb_dmxdev_init() failed (err = %d)\n", err);
-               goto bailout;
-       }
-
-       if (dvb_net_init(&cinergyt2->adapter, &cinergyt2->dvbnet, &cinergyt2->demux.dmx))
-               dprintk(1, "dvb_net_init() failed!\n");
-
-       dvb_register_device(&cinergyt2->adapter, &cinergyt2->fedev,
-                           &cinergyt2_fe_template, cinergyt2,
-                           DVB_DEVICE_FRONTEND);
-
-       err = cinergyt2_register_rc(cinergyt2);
-       if (err)
-               goto bailout;
-
-       return 0;
-
-bailout:
-       dvb_net_release(&cinergyt2->dvbnet);
-       dvb_dmxdev_release(&cinergyt2->dmxdev);
-       dvb_dmx_release(&cinergyt2->demux);
-       dvb_unregister_adapter(&cinergyt2->adapter);
-       cinergyt2_free_stream_urbs(cinergyt2);
-       kfree(cinergyt2);
-       return -ENOMEM;
-}
-
-static void cinergyt2_disconnect (struct usb_interface *intf)
-{
-       struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
-
-       cinergyt2_unregister_rc(cinergyt2);
-       cancel_rearming_delayed_work(&cinergyt2->query_work);
-       wake_up_interruptible(&cinergyt2->poll_wq);
-
-       cinergyt2->demux.dmx.close(&cinergyt2->demux.dmx);
-       cinergyt2->disconnect_pending = 1;
-
-       if (!atomic_read(&cinergyt2->inuse))
-               cinergyt2_unregister(cinergyt2);
-}
-
-static int cinergyt2_suspend (struct usb_interface *intf, pm_message_t state)
-{
-       struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
-
-       if (cinergyt2->disconnect_pending)
-               return -EAGAIN;
-       if (mutex_lock_interruptible(&cinergyt2->wq_sem))
-               return -ERESTARTSYS;
-
-       cinergyt2_suspend_rc(cinergyt2);
-       cancel_rearming_delayed_work(&cinergyt2->query_work);
-
-       mutex_lock(&cinergyt2->sem);
-       if (cinergyt2->streaming)
-               cinergyt2_stop_stream_xfer(cinergyt2);
-       cinergyt2_sleep(cinergyt2, 1);
-       mutex_unlock(&cinergyt2->sem);
-
-       mutex_unlock(&cinergyt2->wq_sem);
-
-       return 0;
-}
-
-static int cinergyt2_resume (struct usb_interface *intf)
-{
-       struct cinergyt2 *cinergyt2 = usb_get_intfdata (intf);
-       struct dvbt_set_parameters_msg *param = &cinergyt2->param;
-       int err = -EAGAIN;
-
-       if (cinergyt2->disconnect_pending)
-               goto out;
-       err = mutex_lock_interruptible(&cinergyt2->wq_sem);
-       if (err)
-               goto out;
-
-       err = mutex_lock_interruptible(&cinergyt2->sem);
-       if (err)
-               goto out_unlock1;
-
-       if (!cinergyt2->sleeping) {
-               cinergyt2_sleep(cinergyt2, 0);
-               cinergyt2_command(cinergyt2, (char *) param, sizeof(*param), NULL, 0);
-               if (cinergyt2->streaming)
-                       cinergyt2_start_stream_xfer(cinergyt2);
-               schedule_delayed_work(&cinergyt2->query_work, HZ/2);
-       }
-
-       cinergyt2_resume_rc(cinergyt2);
-
-       mutex_unlock(&cinergyt2->sem);
-out_unlock1:
-       mutex_unlock(&cinergyt2->wq_sem);
-out:
-       return err;
-}
-
-static const struct usb_device_id cinergyt2_table [] __devinitdata = {
-       { USB_DEVICE(0x0ccd, 0x0038) },
-       { 0 }
-};
-
-MODULE_DEVICE_TABLE(usb, cinergyt2_table);
-
-static struct usb_driver cinergyt2_driver = {
-       .name   = "cinergyT2",
-       .probe  = cinergyt2_probe,
-       .disconnect     = cinergyt2_disconnect,
-       .suspend        = cinergyt2_suspend,
-       .resume         = cinergyt2_resume,
-       .id_table       = cinergyt2_table
-};
-
-static int __init cinergyt2_init (void)
-{
-       int err;
-
-       if ((err = usb_register(&cinergyt2_driver)) < 0)
-               dprintk(1, "usb_register() failed! (err %i)\n", err);
-
-       return err;
-}
-
-static void __exit cinergyt2_exit (void)
-{
-       usb_deregister(&cinergyt2_driver);
-}
-
-module_init (cinergyt2_init);
-module_exit (cinergyt2_exit);
-
-MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Holger Waechtler, Daniel Mack");
diff --git a/drivers/media/dvb/dm1105/Kconfig b/drivers/media/dvb/dm1105/Kconfig
new file mode 100644 (file)
index 0000000..1332301
--- /dev/null
@@ -0,0 +1,18 @@
+config DVB_DM1105
+       tristate "SDMC DM1105 based PCI cards"
+       depends on DVB_CORE && PCI && I2C
+       select DVB_PLL if !DVB_FE_CUSTOMISE
+       select DVB_STV0299 if !DVB_FE_CUSTOMISE
+       select DVB_STV0288 if !DVB_FE_CUSTOMISE
+       select DVB_STB6000 if !DVB_FE_CUSTOMISE
+       select DVB_CX24116 if !DVB_FE_CUSTOMISE
+       select DVB_SI21XX if !DVB_FE_CUSTOMISE
+       help
+         Support for cards based on the SDMC DM1105 PCI chip like
+         DvbWorld 2002
+
+         Since these cards have no MPEG decoder onboard, they transmit
+         only compressed MPEG data over the PCI bus, so you need
+         an external software decoder to watch TV on your computer.
+
+         Say Y or M if you own such a device and want to use it.
diff --git a/drivers/media/dvb/dm1105/Makefile b/drivers/media/dvb/dm1105/Makefile
new file mode 100644 (file)
index 0000000..8ac28b0
--- /dev/null
@@ -0,0 +1,3 @@
+obj-$(CONFIG_DVB_DM1105) += dm1105.o
+
+EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends
diff --git a/drivers/media/dvb/dm1105/dm1105.c b/drivers/media/dvb/dm1105/dm1105.c
new file mode 100644 (file)
index 0000000..f732144
--- /dev/null
@@ -0,0 +1,911 @@
+/*
+ * dm1105.c - driver for DVB cards based on SDMC DM1105 PCI chip
+ *
+ * Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/version.h>
+#include <linux/i2c.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/proc_fs.h>
+#include <linux/pci.h>
+#include <linux/dma-mapping.h>
+#include <linux/input.h>
+#include <media/ir-common.h>
+
+#include "demux.h"
+#include "dmxdev.h"
+#include "dvb_demux.h"
+#include "dvb_frontend.h"
+#include "dvb_net.h"
+#include "dvbdev.h"
+#include "dvb-pll.h"
+
+#include "stv0299.h"
+#include "stv0288.h"
+#include "stb6000.h"
+#include "si21xx.h"
+#include "cx24116.h"
+#include "z0194a.h"
+
+/* ----------------------------------------------- */
+/*
+ * PCI ID's
+ */
+#ifndef PCI_VENDOR_ID_TRIGEM
+#define PCI_VENDOR_ID_TRIGEM   0x109f
+#endif
+#ifndef PCI_DEVICE_ID_DM1105
+#define PCI_DEVICE_ID_DM1105   0x036f
+#endif
+#ifndef PCI_DEVICE_ID_DW2002
+#define PCI_DEVICE_ID_DW2002   0x2002
+#endif
+#ifndef PCI_DEVICE_ID_DW2004
+#define PCI_DEVICE_ID_DW2004   0x2004
+#endif
+/* ----------------------------------------------- */
+/* sdmc dm1105 registers */
+
+/* TS Control */
+#define DM1105_TSCTR                           0x00
+#define DM1105_DTALENTH                                0x04
+
+/* GPIO Interface */
+#define DM1105_GPIOVAL                         0x08
+#define DM1105_GPIOCTR                         0x0c
+
+/* PID serial number */
+#define DM1105_PIDN                            0x10
+
+/* Odd-even secret key select */
+#define DM1105_CWSEL                           0x14
+
+/* Host Command Interface */
+#define DM1105_HOST_CTR                                0x18
+#define DM1105_HOST_AD                         0x1c
+
+/* PCI Interface */
+#define DM1105_CR                              0x30
+#define DM1105_RST                             0x34
+#define DM1105_STADR                           0x38
+#define DM1105_RLEN                            0x3c
+#define DM1105_WRP                             0x40
+#define DM1105_INTCNT                          0x44
+#define DM1105_INTMAK                          0x48
+#define DM1105_INTSTS                          0x4c
+
+/* CW Value */
+#define DM1105_ODD                             0x50
+#define DM1105_EVEN                            0x58
+
+/* PID Value */
+#define DM1105_PID                             0x60
+
+/* IR Control */
+#define DM1105_IRCTR                           0x64
+#define DM1105_IRMODE                          0x68
+#define DM1105_SYSTEMCODE                      0x6c
+#define DM1105_IRCODE                          0x70
+
+/* Unknown Values */
+#define DM1105_ENCRYPT                         0x74
+#define DM1105_VER                             0x7c
+
+/* I2C Interface */
+#define DM1105_I2CCTR                          0x80
+#define DM1105_I2CSTS                          0x81
+#define DM1105_I2CDAT                          0x82
+#define DM1105_I2C_RA                          0x83
+/* ----------------------------------------------- */
+/* Interrupt Mask Bits */
+
+#define INTMAK_TSIRQM                          0x01
+#define INTMAK_HIRQM                           0x04
+#define INTMAK_IRM                             0x08
+#define INTMAK_ALLMASK                         (INTMAK_TSIRQM | \
+                                               INTMAK_HIRQM | \
+                                               INTMAK_IRM)
+#define INTMAK_NONEMASK                                0x00
+
+/* Interrupt Status Bits */
+#define INTSTS_TSIRQ                           0x01
+#define INTSTS_HIRQ                            0x04
+#define INTSTS_IR                              0x08
+
+/* IR Control Bits */
+#define DM1105_IR_EN                           0x01
+#define DM1105_SYS_CHK                         0x02
+#define DM1105_REP_FLG                         0x08
+
+/* EEPROM addr */
+#define IIC_24C01_addr                         0xa0
+/* Max board count */
+#define DM1105_MAX                             0x04
+
+#define DRIVER_NAME                            "dm1105"
+
+#define DM1105_DMA_PACKETS                     47
+#define DM1105_DMA_PACKET_LENGTH               (128*4)
+#define DM1105_DMA_BYTES                       (128 * 4 * DM1105_DMA_PACKETS)
+
+/* GPIO's for LNB power control */
+#define DM1105_LNB_MASK                                0x00000000
+#define DM1105_LNB_13V                         0x00010100
+#define DM1105_LNB_18V                         0x00000100
+
+static int ir_debug;
+module_param(ir_debug, int, 0644);
+MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static u16 ir_codes_dm1105_nec[128] = {
+       [0x0a] = KEY_Q,         /*power*/
+       [0x0c] = KEY_M,         /*mute*/
+       [0x11] = KEY_1,
+       [0x12] = KEY_2,
+       [0x13] = KEY_3,
+       [0x14] = KEY_4,
+       [0x15] = KEY_5,
+       [0x16] = KEY_6,
+       [0x17] = KEY_7,
+       [0x18] = KEY_8,
+       [0x19] = KEY_9,
+       [0x10] = KEY_0,
+       [0x1c] = KEY_PAGEUP,    /*ch+*/
+       [0x0f] = KEY_PAGEDOWN,  /*ch-*/
+       [0x1a] = KEY_O,         /*vol+*/
+       [0x0e] = KEY_Z,         /*vol-*/
+       [0x04] = KEY_R,         /*rec*/
+       [0x09] = KEY_D,         /*fav*/
+       [0x08] = KEY_BACKSPACE, /*rewind*/
+       [0x07] = KEY_A,         /*fast*/
+       [0x0b] = KEY_P,         /*pause*/
+       [0x02] = KEY_ESC,       /*cancel*/
+       [0x03] = KEY_G,         /*tab*/
+       [0x00] = KEY_UP,        /*up*/
+       [0x1f] = KEY_ENTER,     /*ok*/
+       [0x01] = KEY_DOWN,      /*down*/
+       [0x05] = KEY_C,         /*cap*/
+       [0x06] = KEY_S,         /*stop*/
+       [0x40] = KEY_F,         /*full*/
+       [0x1e] = KEY_W,         /*tvmode*/
+       [0x1b] = KEY_B,         /*recall*/
+};
+
+/* infrared remote control */
+struct infrared {
+       u16     key_map[128];
+       struct input_dev        *input_dev;
+       char                    input_phys[32];
+       struct tasklet_struct   ir_tasklet;
+       u32                     ir_command;
+};
+
+struct dm1105dvb {
+       /* pci */
+       struct pci_dev *pdev;
+       u8 __iomem *io_mem;
+
+       /* ir */
+       struct infrared ir;
+
+       /* dvb */
+       struct dmx_frontend hw_frontend;
+       struct dmx_frontend mem_frontend;
+       struct dmxdev dmxdev;
+       struct dvb_adapter dvb_adapter;
+       struct dvb_demux demux;
+       struct dvb_frontend *fe;
+       struct dvb_net dvbnet;
+       unsigned int full_ts_users;
+
+       /* i2c */
+       struct i2c_adapter i2c_adap;
+
+       /* dma */
+       dma_addr_t dma_addr;
+       unsigned char *ts_buf;
+       u32 wrp;
+       u32 buffer_size;
+       unsigned int    PacketErrorCount;
+       unsigned int dmarst;
+       spinlock_t lock;
+
+};
+
+#define dm_io_mem(reg) ((unsigned long)(&dm1105dvb->io_mem[reg]))
+
+static struct dm1105dvb *dm1105dvb_local;
+
+static int dm1105_i2c_xfer(struct i2c_adapter *i2c_adap,
+                           struct i2c_msg *msgs, int num)
+{
+       struct dm1105dvb *dm1105dvb ;
+
+       int addr, rc, i, j, k, len, byte, data;
+       u8 status;
+
+       dm1105dvb = i2c_adap->algo_data;
+       for (i = 0; i < num; i++) {
+               outb(0x00, dm_io_mem(DM1105_I2CCTR));
+               if (msgs[i].flags & I2C_M_RD) {
+                       /* read bytes */
+                       addr  = msgs[i].addr << 1;
+                       addr |= 1;
+                       outb(addr, dm_io_mem(DM1105_I2CDAT));
+                       for (byte = 0; byte < msgs[i].len; byte++)
+                               outb(0, dm_io_mem(DM1105_I2CDAT + byte + 1));
+
+                       outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
+                       for (j = 0; j < 55; j++) {
+                               mdelay(10);
+                               status = inb(dm_io_mem(DM1105_I2CSTS));
+                               if ((status & 0xc0) == 0x40)
+                                       break;
+                       }
+                       if (j >= 55)
+                               return -1;
+
+                       for (byte = 0; byte < msgs[i].len; byte++) {
+                               rc = inb(dm_io_mem(DM1105_I2CDAT + byte + 1));
+                               if (rc < 0)
+                                       goto err;
+                               msgs[i].buf[byte] = rc;
+                       }
+               } else {
+                       if ((msgs[i].buf[0] == 0xf7) && (msgs[i].addr == 0x55)) {
+                               /* prepaired for cx24116 firmware */
+                               /* Write in small blocks */
+                               len = msgs[i].len - 1;
+                               k = 1;
+                               do {
+                                       outb(msgs[i].addr << 1, dm_io_mem(DM1105_I2CDAT));
+                                       outb(0xf7, dm_io_mem(DM1105_I2CDAT + 1));
+                                       for (byte = 0; byte < (len > 48 ? 48 : len); byte++) {
+                                               data = msgs[i].buf[k+byte];
+                                               outb(data, dm_io_mem(DM1105_I2CDAT + byte + 2));
+                                       }
+                                       outb(0x82 + (len > 48 ? 48 : len), dm_io_mem(DM1105_I2CCTR));
+                                       for (j = 0; j < 25; j++) {
+                                               mdelay(10);
+                                               status = inb(dm_io_mem(DM1105_I2CSTS));
+                                               if ((status & 0xc0) == 0x40)
+                                                       break;
+                                       }
+
+                                       if (j >= 25)
+                                               return -1;
+
+                                       k += 48;
+                                       len -= 48;
+                               } while (len > 0);
+                       } else {
+                               /* write bytes */
+                               outb(msgs[i].addr<<1, dm_io_mem(DM1105_I2CDAT));
+                               for (byte = 0; byte < msgs[i].len; byte++) {
+                                       data = msgs[i].buf[byte];
+                                       outb(data, dm_io_mem(DM1105_I2CDAT + byte + 1));
+                               }
+                               outb(0x81 + msgs[i].len, dm_io_mem(DM1105_I2CCTR));
+                               for (j = 0; j < 25; j++) {
+                                       mdelay(10);
+                                       status = inb(dm_io_mem(DM1105_I2CSTS));
+                                       if ((status & 0xc0) == 0x40)
+                                               break;
+                               }
+
+                               if (j >= 25)
+                                       return -1;
+                       }
+               }
+       }
+       return num;
+ err:
+       return rc;
+}
+
+static u32 functionality(struct i2c_adapter *adap)
+{
+       return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm dm1105_algo = {
+       .master_xfer   = dm1105_i2c_xfer,
+       .functionality = functionality,
+};
+
+static inline struct dm1105dvb *feed_to_dm1105dvb(struct dvb_demux_feed *feed)
+{
+       return container_of(feed->demux, struct dm1105dvb, demux);
+}
+
+static inline struct dm1105dvb *frontend_to_dm1105dvb(struct dvb_frontend *fe)
+{
+       return container_of(fe->dvb, struct dm1105dvb, dvb_adapter);
+}
+
+static int dm1105dvb_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
+{
+       struct dm1105dvb *dm1105dvb = frontend_to_dm1105dvb(fe);
+
+               if (voltage == SEC_VOLTAGE_18) {
+                       outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
+                       outl(DM1105_LNB_18V, dm_io_mem(DM1105_GPIOVAL));
+               } else  {
+               /*LNB ON-13V by default!*/
+                       outl(DM1105_LNB_MASK, dm_io_mem(DM1105_GPIOCTR));
+                       outl(DM1105_LNB_13V, dm_io_mem(DM1105_GPIOVAL));
+               }
+
+       return 0;
+}
+
+static void dm1105dvb_set_dma_addr(struct dm1105dvb *dm1105dvb)
+{
+       outl(cpu_to_le32(dm1105dvb->dma_addr), dm_io_mem(DM1105_STADR));
+}
+
+static int __devinit dm1105dvb_dma_map(struct dm1105dvb *dm1105dvb)
+{
+       dm1105dvb->ts_buf = pci_alloc_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, &dm1105dvb->dma_addr);
+
+       return pci_dma_mapping_error(dm1105dvb->pdev, dm1105dvb->dma_addr);
+}
+
+static void dm1105dvb_dma_unmap(struct dm1105dvb *dm1105dvb)
+{
+       pci_free_consistent(dm1105dvb->pdev, 6*DM1105_DMA_BYTES, dm1105dvb->ts_buf, dm1105dvb->dma_addr);
+}
+
+static void __devinit dm1105dvb_enable_irqs(struct dm1105dvb *dm1105dvb)
+{
+       outb(INTMAK_ALLMASK, dm_io_mem(DM1105_INTMAK));
+       outb(1, dm_io_mem(DM1105_CR));
+}
+
+static void dm1105dvb_disable_irqs(struct dm1105dvb *dm1105dvb)
+{
+       outb(INTMAK_IRM, dm_io_mem(DM1105_INTMAK));
+       outb(0, dm_io_mem(DM1105_CR));
+}
+
+static int dm1105dvb_start_feed(struct dvb_demux_feed *f)
+{
+       struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
+
+       if (dm1105dvb->full_ts_users++ == 0)
+               dm1105dvb_enable_irqs(dm1105dvb);
+
+       return 0;
+}
+
+static int dm1105dvb_stop_feed(struct dvb_demux_feed *f)
+{
+       struct dm1105dvb *dm1105dvb = feed_to_dm1105dvb(f);
+
+       if (--dm1105dvb->full_ts_users == 0)
+               dm1105dvb_disable_irqs(dm1105dvb);
+
+       return 0;
+}
+
+/* ir tasklet */
+static void dm1105_emit_key(unsigned long parm)
+{
+       struct infrared *ir = (struct infrared *) parm;
+       u32 ircom = ir->ir_command;
+       u8 data;
+       u16 keycode;
+
+       data = (ircom >> 8) & 0x7f;
+
+       input_event(ir->input_dev, EV_MSC, MSC_RAW, (0x0000f8 << 16) | data);
+       input_event(ir->input_dev, EV_MSC, MSC_SCAN, data);
+       keycode = ir->key_map[data];
+
+       if (!keycode)
+               return;
+
+       input_event(ir->input_dev, EV_KEY, keycode, 1);
+       input_sync(ir->input_dev);
+       input_event(ir->input_dev, EV_KEY, keycode, 0);
+       input_sync(ir->input_dev);
+
+}
+
+static irqreturn_t dm1105dvb_irq(int irq, void *dev_id)
+{
+       struct dm1105dvb *dm1105dvb = dev_id;
+       unsigned int piece;
+       unsigned int nbpackets;
+       u32 command;
+       u32 nextwrp;
+       u32 oldwrp;
+
+       /* Read-Write INSTS Ack's Interrupt for DM1105 chip 16.03.2008 */
+       unsigned int intsts = inb(dm_io_mem(DM1105_INTSTS));
+       outb(intsts, dm_io_mem(DM1105_INTSTS));
+
+       switch (intsts) {
+       case INTSTS_TSIRQ:
+       case (INTSTS_TSIRQ | INTSTS_IR):
+               nextwrp = inl(dm_io_mem(DM1105_WRP)) -
+                       inl(dm_io_mem(DM1105_STADR)) ;
+               oldwrp = dm1105dvb->wrp;
+               spin_lock(&dm1105dvb->lock);
+               if (!((dm1105dvb->ts_buf[oldwrp] == 0x47) &&
+                               (dm1105dvb->ts_buf[oldwrp + 188] == 0x47) &&
+                               (dm1105dvb->ts_buf[oldwrp + 188 * 2] == 0x47))) {
+                       dm1105dvb->PacketErrorCount++;
+                       /* bad packet found */
+                       if ((dm1105dvb->PacketErrorCount >= 2) &&
+                                       (dm1105dvb->dmarst == 0)) {
+                               outb(1, dm_io_mem(DM1105_RST));
+                               dm1105dvb->wrp = 0;
+                               dm1105dvb->PacketErrorCount = 0;
+                               dm1105dvb->dmarst = 0;
+                               spin_unlock(&dm1105dvb->lock);
+                               return IRQ_HANDLED;
+                       }
+               }
+               if (nextwrp < oldwrp) {
+                       piece = dm1105dvb->buffer_size - oldwrp;
+                       memcpy(dm1105dvb->ts_buf + dm1105dvb->buffer_size, dm1105dvb->ts_buf, nextwrp);
+                       nbpackets = (piece + nextwrp)/188;
+               } else  {
+                       nbpackets = (nextwrp - oldwrp)/188;
+               }
+               dvb_dmx_swfilter_packets(&dm1105dvb->demux, &dm1105dvb->ts_buf[oldwrp], nbpackets);
+               dm1105dvb->wrp = nextwrp;
+               spin_unlock(&dm1105dvb->lock);
+               break;
+       case INTSTS_IR:
+               command = inl(dm_io_mem(DM1105_IRCODE));
+               if (ir_debug)
+                       printk("dm1105: received byte 0x%04x\n", command);
+
+               dm1105dvb->ir.ir_command = command;
+               tasklet_schedule(&dm1105dvb->ir.ir_tasklet);
+               break;
+       }
+       return IRQ_HANDLED;
+
+
+}
+
+/* register with input layer */
+static void input_register_keys(struct infrared *ir)
+{
+       int i;
+
+       memset(ir->input_dev->keybit, 0, sizeof(ir->input_dev->keybit));
+
+       for (i = 0; i < ARRAY_SIZE(ir->key_map); i++)
+                       set_bit(ir->key_map[i], ir->input_dev->keybit);
+
+       ir->input_dev->keycode = ir->key_map;
+       ir->input_dev->keycodesize = sizeof(ir->key_map[0]);
+       ir->input_dev->keycodemax = ARRAY_SIZE(ir->key_map);
+}
+
+int __devinit dm1105_ir_init(struct dm1105dvb *dm1105)
+{
+       struct input_dev *input_dev;
+       int err;
+
+       dm1105dvb_local = dm1105;
+
+       input_dev = input_allocate_device();
+       if (!input_dev)
+               return -ENOMEM;
+
+       dm1105->ir.input_dev = input_dev;
+       snprintf(dm1105->ir.input_phys, sizeof(dm1105->ir.input_phys),
+               "pci-%s/ir0", pci_name(dm1105->pdev));
+
+       input_dev->evbit[0] = BIT(EV_KEY);
+       input_dev->name = "DVB on-card IR receiver";
+
+       input_dev->phys = dm1105->ir.input_phys;
+       input_dev->id.bustype = BUS_PCI;
+       input_dev->id.version = 2;
+       if (dm1105->pdev->subsystem_vendor) {
+               input_dev->id.vendor = dm1105->pdev->subsystem_vendor;
+               input_dev->id.product = dm1105->pdev->subsystem_device;
+       } else {
+               input_dev->id.vendor = dm1105->pdev->vendor;
+               input_dev->id.product = dm1105->pdev->device;
+       }
+       input_dev->dev.parent = &dm1105->pdev->dev;
+       /* initial keymap */
+       memcpy(dm1105->ir.key_map, ir_codes_dm1105_nec, sizeof dm1105->ir.key_map);
+       input_register_keys(&dm1105->ir);
+       err = input_register_device(input_dev);
+       if (err) {
+               input_free_device(input_dev);
+               return err;
+       }
+
+       tasklet_init(&dm1105->ir.ir_tasklet, dm1105_emit_key, (unsigned long) &dm1105->ir);
+
+       return 0;
+}
+
+
+void __devexit dm1105_ir_exit(struct dm1105dvb *dm1105)
+{
+       tasklet_kill(&dm1105->ir.ir_tasklet);
+       input_unregister_device(dm1105->ir.input_dev);
+
+}
+
+static int __devinit dm1105dvb_hw_init(struct dm1105dvb *dm1105dvb)
+{
+       dm1105dvb_disable_irqs(dm1105dvb);
+
+       outb(0, dm_io_mem(DM1105_HOST_CTR));
+
+       /*DATALEN 188,*/
+       outb(188, dm_io_mem(DM1105_DTALENTH));
+       /*TS_STRT TS_VALP MSBFIRST TS_MODE ALPAS TSPES*/
+       outw(0xc10a, dm_io_mem(DM1105_TSCTR));
+
+       /* map DMA and set address */
+       dm1105dvb_dma_map(dm1105dvb);
+       dm1105dvb_set_dma_addr(dm1105dvb);
+       /* big buffer */
+       outl(5*DM1105_DMA_BYTES, dm_io_mem(DM1105_RLEN));
+       outb(47, dm_io_mem(DM1105_INTCNT));
+
+       /* IR NEC mode enable */
+       outb((DM1105_IR_EN | DM1105_SYS_CHK), dm_io_mem(DM1105_IRCTR));
+       outb(0, dm_io_mem(DM1105_IRMODE));
+       outw(0, dm_io_mem(DM1105_SYSTEMCODE));
+
+       return 0;
+}
+
+static void dm1105dvb_hw_exit(struct dm1105dvb *dm1105dvb)
+{
+       dm1105dvb_disable_irqs(dm1105dvb);
+
+       /* IR disable */
+       outb(0, dm_io_mem(DM1105_IRCTR));
+       outb(INTMAK_NONEMASK, dm_io_mem(DM1105_INTMAK));
+
+       dm1105dvb_dma_unmap(dm1105dvb);
+}
+
+static struct stv0288_config earda_config = {
+       .demod_address = 0x68,
+       .min_delay_ms = 100,
+};
+
+static struct si21xx_config serit_config = {
+       .demod_address = 0x68,
+       .min_delay_ms = 100,
+
+};
+
+static struct cx24116_config serit_sp2633_config = {
+       .demod_address = 0x55,
+};
+
+static int __devinit frontend_init(struct dm1105dvb *dm1105dvb)
+{
+       int ret;
+
+       switch (dm1105dvb->pdev->subsystem_device) {
+       case PCI_DEVICE_ID_DW2002:
+               dm1105dvb->fe = dvb_attach(
+                       stv0299_attach, &sharp_z0194a_config,
+                       &dm1105dvb->i2c_adap);
+
+               if (dm1105dvb->fe) {
+                       dm1105dvb->fe->ops.set_voltage =
+                                                       dm1105dvb_set_voltage;
+                       dvb_attach(dvb_pll_attach, dm1105dvb->fe, 0x60,
+                                       &dm1105dvb->i2c_adap, DVB_PLL_OPERA1);
+               }
+
+               if (!dm1105dvb->fe) {
+                       dm1105dvb->fe = dvb_attach(
+                               stv0288_attach, &earda_config,
+                               &dm1105dvb->i2c_adap);
+                       if (dm1105dvb->fe) {
+                               dm1105dvb->fe->ops.set_voltage =
+                                                       dm1105dvb_set_voltage;
+                               dvb_attach(stb6000_attach, dm1105dvb->fe, 0x61,
+                                               &dm1105dvb->i2c_adap);
+                       }
+               }
+
+               if (!dm1105dvb->fe) {
+                       dm1105dvb->fe = dvb_attach(
+                               si21xx_attach, &serit_config,
+                               &dm1105dvb->i2c_adap);
+                       if (dm1105dvb->fe)
+                               dm1105dvb->fe->ops.set_voltage =
+                                                       dm1105dvb_set_voltage;
+               }
+               break;
+       case PCI_DEVICE_ID_DW2004:
+               dm1105dvb->fe = dvb_attach(
+                       cx24116_attach, &serit_sp2633_config,
+                       &dm1105dvb->i2c_adap);
+               if (dm1105dvb->fe)
+                       dm1105dvb->fe->ops.set_voltage = dm1105dvb_set_voltage;
+               break;
+       }
+
+       if (!dm1105dvb->fe) {
+               dev_err(&dm1105dvb->pdev->dev, "could not attach frontend\n");
+               return -ENODEV;
+       }
+
+       ret = dvb_register_frontend(&dm1105dvb->dvb_adapter, dm1105dvb->fe);
+       if (ret < 0) {
+               if (dm1105dvb->fe->ops.release)
+                       dm1105dvb->fe->ops.release(dm1105dvb->fe);
+               dm1105dvb->fe = NULL;
+               return ret;
+       }
+
+       return 0;
+}
+
+static void __devinit dm1105dvb_read_mac(struct dm1105dvb *dm1105dvb, u8 *mac)
+{
+       static u8 command[1] = { 0x28 };
+
+       struct i2c_msg msg[] = {
+               { .addr = IIC_24C01_addr >> 1, .flags = 0,
+                               .buf = command, .len = 1 },
+               { .addr = IIC_24C01_addr >> 1, .flags = I2C_M_RD,
+                               .buf = mac, .len = 6 },
+       };
+
+       dm1105_i2c_xfer(&dm1105dvb->i2c_adap, msg , 2);
+       dev_info(&dm1105dvb->pdev->dev, "MAC %02x:%02x:%02x:%02x:%02x:%02x\n",
+                       mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
+}
+
+static int __devinit dm1105_probe(struct pci_dev *pdev,
+                                 const struct pci_device_id *ent)
+{
+       struct dm1105dvb *dm1105dvb;
+       struct dvb_adapter *dvb_adapter;
+       struct dvb_demux *dvbdemux;
+       struct dmx_demux *dmx;
+       int ret = -ENOMEM;
+
+       dm1105dvb = kzalloc(sizeof(struct dm1105dvb), GFP_KERNEL);
+       if (!dm1105dvb)
+               goto out;
+
+       dm1105dvb->pdev = pdev;
+       dm1105dvb->buffer_size = 5 * DM1105_DMA_BYTES;
+       dm1105dvb->PacketErrorCount = 0;
+       dm1105dvb->dmarst = 0;
+
+       ret = pci_enable_device(pdev);
+       if (ret < 0)
+               goto err_kfree;
+
+       ret = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
+       if (ret < 0)
+               goto err_pci_disable_device;
+
+       pci_set_master(pdev);
+
+       ret = pci_request_regions(pdev, DRIVER_NAME);
+       if (ret < 0)
+               goto err_pci_disable_device;
+
+       dm1105dvb->io_mem = pci_iomap(pdev, 0, pci_resource_len(pdev, 0));
+       if (!dm1105dvb->io_mem) {
+               ret = -EIO;
+               goto err_pci_release_regions;
+       }
+
+       spin_lock_init(&dm1105dvb->lock);
+       pci_set_drvdata(pdev, dm1105dvb);
+
+       ret = request_irq(pdev->irq, dm1105dvb_irq, IRQF_SHARED, DRIVER_NAME, dm1105dvb);
+       if (ret < 0)
+               goto err_pci_iounmap;
+
+       ret = dm1105dvb_hw_init(dm1105dvb);
+       if (ret < 0)
+               goto err_free_irq;
+
+       /* i2c */
+       i2c_set_adapdata(&dm1105dvb->i2c_adap, dm1105dvb);
+       strcpy(dm1105dvb->i2c_adap.name, DRIVER_NAME);
+       dm1105dvb->i2c_adap.owner = THIS_MODULE;
+       dm1105dvb->i2c_adap.class = I2C_CLASS_TV_DIGITAL;
+       dm1105dvb->i2c_adap.dev.parent = &pdev->dev;
+       dm1105dvb->i2c_adap.algo = &dm1105_algo;
+       dm1105dvb->i2c_adap.algo_data = dm1105dvb;
+       ret = i2c_add_adapter(&dm1105dvb->i2c_adap);
+
+       if (ret < 0)
+               goto err_dm1105dvb_hw_exit;
+
+       /* dvb */
+       ret = dvb_register_adapter(&dm1105dvb->dvb_adapter, DRIVER_NAME,
+                                       THIS_MODULE, &pdev->dev, adapter_nr);
+       if (ret < 0)
+               goto err_i2c_del_adapter;
+
+       dvb_adapter = &dm1105dvb->dvb_adapter;
+
+       dm1105dvb_read_mac(dm1105dvb, dvb_adapter->proposed_mac);
+
+       dvbdemux = &dm1105dvb->demux;
+       dvbdemux->filternum = 256;
+       dvbdemux->feednum = 256;
+       dvbdemux->start_feed = dm1105dvb_start_feed;
+       dvbdemux->stop_feed = dm1105dvb_stop_feed;
+       dvbdemux->dmx.capabilities = (DMX_TS_FILTERING |
+                       DMX_SECTION_FILTERING | DMX_MEMORY_BASED_FILTERING);
+       ret = dvb_dmx_init(dvbdemux);
+       if (ret < 0)
+               goto err_dvb_unregister_adapter;
+
+       dmx = &dvbdemux->dmx;
+       dm1105dvb->dmxdev.filternum = 256;
+       dm1105dvb->dmxdev.demux = dmx;
+       dm1105dvb->dmxdev.capabilities = 0;
+
+       ret = dvb_dmxdev_init(&dm1105dvb->dmxdev, dvb_adapter);
+       if (ret < 0)
+               goto err_dvb_dmx_release;
+
+       dm1105dvb->hw_frontend.source = DMX_FRONTEND_0;
+
+       ret = dmx->add_frontend(dmx, &dm1105dvb->hw_frontend);
+       if (ret < 0)
+               goto err_dvb_dmxdev_release;
+
+       dm1105dvb->mem_frontend.source = DMX_MEMORY_FE;
+
+       ret = dmx->add_frontend(dmx, &dm1105dvb->mem_frontend);
+       if (ret < 0)
+               goto err_remove_hw_frontend;
+
+       ret = dmx->connect_frontend(dmx, &dm1105dvb->hw_frontend);
+       if (ret < 0)
+               goto err_remove_mem_frontend;
+
+       ret = frontend_init(dm1105dvb);
+       if (ret < 0)
+               goto err_disconnect_frontend;
+
+       dvb_net_init(dvb_adapter, &dm1105dvb->dvbnet, dmx);
+       dm1105_ir_init(dm1105dvb);
+out:
+       return ret;
+
+err_disconnect_frontend:
+       dmx->disconnect_frontend(dmx);
+err_remove_mem_frontend:
+       dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
+err_remove_hw_frontend:
+       dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
+err_dvb_dmxdev_release:
+       dvb_dmxdev_release(&dm1105dvb->dmxdev);
+err_dvb_dmx_release:
+       dvb_dmx_release(dvbdemux);
+err_dvb_unregister_adapter:
+       dvb_unregister_adapter(dvb_adapter);
+err_i2c_del_adapter:
+       i2c_del_adapter(&dm1105dvb->i2c_adap);
+err_dm1105dvb_hw_exit:
+       dm1105dvb_hw_exit(dm1105dvb);
+err_free_irq:
+       free_irq(pdev->irq, dm1105dvb);
+err_pci_iounmap:
+       pci_iounmap(pdev, dm1105dvb->io_mem);
+err_pci_release_regions:
+       pci_release_regions(pdev);
+err_pci_disable_device:
+       pci_disable_device(pdev);
+err_kfree:
+       pci_set_drvdata(pdev, NULL);
+       kfree(dm1105dvb);
+       goto out;
+}
+
+static void __devexit dm1105_remove(struct pci_dev *pdev)
+{
+       struct dm1105dvb *dm1105dvb = pci_get_drvdata(pdev);
+       struct dvb_adapter *dvb_adapter = &dm1105dvb->dvb_adapter;
+       struct dvb_demux *dvbdemux = &dm1105dvb->demux;
+       struct dmx_demux *dmx = &dvbdemux->dmx;
+
+       dm1105_ir_exit(dm1105dvb);
+       dmx->close(dmx);
+       dvb_net_release(&dm1105dvb->dvbnet);
+       if (dm1105dvb->fe)
+               dvb_unregister_frontend(dm1105dvb->fe);
+
+       dmx->disconnect_frontend(dmx);
+       dmx->remove_frontend(dmx, &dm1105dvb->mem_frontend);
+       dmx->remove_frontend(dmx, &dm1105dvb->hw_frontend);
+       dvb_dmxdev_release(&dm1105dvb->dmxdev);
+       dvb_dmx_release(dvbdemux);
+       dvb_unregister_adapter(dvb_adapter);
+       if (&dm1105dvb->i2c_adap)
+               i2c_del_adapter(&dm1105dvb->i2c_adap);
+
+       dm1105dvb_hw_exit(dm1105dvb);
+       synchronize_irq(pdev->irq);
+       free_irq(pdev->irq, dm1105dvb);
+       pci_iounmap(pdev, dm1105dvb->io_mem);
+       pci_release_regions(pdev);
+       pci_disable_device(pdev);
+       pci_set_drvdata(pdev, NULL);
+       kfree(dm1105dvb);
+}
+
+static struct pci_device_id dm1105_id_table[] __devinitdata = {
+       {
+               .vendor = PCI_VENDOR_ID_TRIGEM,
+               .device = PCI_DEVICE_ID_DM1105,
+               .subvendor = PCI_ANY_ID,
+               .subdevice = PCI_DEVICE_ID_DW2002,
+       }, {
+               .vendor = PCI_VENDOR_ID_TRIGEM,
+               .device = PCI_DEVICE_ID_DM1105,
+               .subvendor = PCI_ANY_ID,
+               .subdevice = PCI_DEVICE_ID_DW2004,
+       }, {
+               /* empty */
+       },
+};
+
+MODULE_DEVICE_TABLE(pci, dm1105_id_table);
+
+static struct pci_driver dm1105_driver = {
+       .name = DRIVER_NAME,
+       .id_table = dm1105_id_table,
+       .probe = dm1105_probe,
+       .remove = __devexit_p(dm1105_remove),
+};
+
+static int __init dm1105_init(void)
+{
+       return pci_register_driver(&dm1105_driver);
+}
+
+static void __exit dm1105_exit(void)
+{
+       pci_unregister_driver(&dm1105_driver);
+}
+
+module_init(dm1105_init);
+module_exit(dm1105_exit);
+
+MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
+MODULE_DESCRIPTION("SDMC DM1105 DVB driver");
+MODULE_LICENSE("GPL");
index 3526e3ee9487747788e00ac66b0c978af36a3ad2..f170e822fadce9016eeba24330d23101cbb01927 100644 (file)
@@ -40,6 +40,7 @@
 
 #include "dvb_frontend.h"
 #include "dvbdev.h"
+#include <linux/dvb/version.h>
 
 static int dvb_frontend_debug;
 static int dvb_shutdown_timeout;
@@ -755,6 +756,539 @@ static int dvb_frontend_check_parameters(struct dvb_frontend *fe,
        return 0;
 }
 
+struct dtv_cmds_h dtv_cmds[] = {
+       [DTV_TUNE] = {
+               .name   = "DTV_TUNE",
+               .cmd    = DTV_TUNE,
+               .set    = 1,
+       },
+       [DTV_CLEAR] = {
+               .name   = "DTV_CLEAR",
+               .cmd    = DTV_CLEAR,
+               .set    = 1,
+       },
+
+       /* Set */
+       [DTV_FREQUENCY] = {
+               .name   = "DTV_FREQUENCY",
+               .cmd    = DTV_FREQUENCY,
+               .set    = 1,
+       },
+       [DTV_BANDWIDTH_HZ] = {
+               .name   = "DTV_BANDWIDTH_HZ",
+               .cmd    = DTV_BANDWIDTH_HZ,
+               .set    = 1,
+       },
+       [DTV_MODULATION] = {
+               .name   = "DTV_MODULATION",
+               .cmd    = DTV_MODULATION,
+               .set    = 1,
+       },
+       [DTV_INVERSION] = {
+               .name   = "DTV_INVERSION",
+               .cmd    = DTV_INVERSION,
+               .set    = 1,
+       },
+       [DTV_DISEQC_MASTER] = {
+               .name   = "DTV_DISEQC_MASTER",
+               .cmd    = DTV_DISEQC_MASTER,
+               .set    = 1,
+               .buffer = 1,
+       },
+       [DTV_SYMBOL_RATE] = {
+               .name   = "DTV_SYMBOL_RATE",
+               .cmd    = DTV_SYMBOL_RATE,
+               .set    = 1,
+       },
+       [DTV_INNER_FEC] = {
+               .name   = "DTV_INNER_FEC",
+               .cmd    = DTV_INNER_FEC,
+               .set    = 1,
+       },
+       [DTV_VOLTAGE] = {
+               .name   = "DTV_VOLTAGE",
+               .cmd    = DTV_VOLTAGE,
+               .set    = 1,
+       },
+       [DTV_TONE] = {
+               .name   = "DTV_TONE",
+               .cmd    = DTV_TONE,
+               .set    = 1,
+       },
+       [DTV_PILOT] = {
+               .name   = "DTV_PILOT",
+               .cmd    = DTV_PILOT,
+               .set    = 1,
+       },
+       [DTV_ROLLOFF] = {
+               .name   = "DTV_ROLLOFF",
+               .cmd    = DTV_ROLLOFF,
+               .set    = 1,
+       },
+       [DTV_DELIVERY_SYSTEM] = {
+               .name   = "DTV_DELIVERY_SYSTEM",
+               .cmd    = DTV_DELIVERY_SYSTEM,
+               .set    = 1,
+       },
+       [DTV_HIERARCHY] = {
+               .name   = "DTV_HIERARCHY",
+               .cmd    = DTV_HIERARCHY,
+               .set    = 1,
+       },
+       [DTV_CODE_RATE_HP] = {
+               .name   = "DTV_CODE_RATE_HP",
+               .cmd    = DTV_CODE_RATE_HP,
+               .set    = 1,
+       },
+       [DTV_CODE_RATE_LP] = {
+               .name   = "DTV_CODE_RATE_LP",
+               .cmd    = DTV_CODE_RATE_LP,
+               .set    = 1,
+       },
+       [DTV_GUARD_INTERVAL] = {
+               .name   = "DTV_GUARD_INTERVAL",
+               .cmd    = DTV_GUARD_INTERVAL,
+               .set    = 1,
+       },
+       [DTV_TRANSMISSION_MODE] = {
+               .name   = "DTV_TRANSMISSION_MODE",
+               .cmd    = DTV_TRANSMISSION_MODE,
+               .set    = 1,
+       },
+       /* Get */
+       [DTV_DISEQC_SLAVE_REPLY] = {
+               .name   = "DTV_DISEQC_SLAVE_REPLY",
+               .cmd    = DTV_DISEQC_SLAVE_REPLY,
+               .set    = 0,
+               .buffer = 1,
+       },
+       [DTV_API_VERSION] = {
+               .name   = "DTV_API_VERSION",
+               .cmd    = DTV_API_VERSION,
+               .set    = 0,
+       },
+       [DTV_CODE_RATE_HP] = {
+               .name   = "DTV_CODE_RATE_HP",
+               .cmd    = DTV_CODE_RATE_HP,
+               .set    = 0,
+       },
+       [DTV_CODE_RATE_LP] = {
+               .name   = "DTV_CODE_RATE_LP",
+               .cmd    = DTV_CODE_RATE_LP,
+               .set    = 0,
+       },
+       [DTV_GUARD_INTERVAL] = {
+               .name   = "DTV_GUARD_INTERVAL",
+               .cmd    = DTV_GUARD_INTERVAL,
+               .set    = 0,
+       },
+       [DTV_TRANSMISSION_MODE] = {
+               .name   = "DTV_TRANSMISSION_MODE",
+               .cmd    = DTV_TRANSMISSION_MODE,
+               .set    = 0,
+       },
+       [DTV_HIERARCHY] = {
+               .name   = "DTV_HIERARCHY",
+               .cmd    = DTV_HIERARCHY,
+               .set    = 0,
+       },
+};
+
+void dtv_property_dump(struct dtv_property *tvp)
+{
+       int i;
+
+       if (tvp->cmd <= 0 || tvp->cmd > DTV_MAX_COMMAND) {
+               printk("%s: tvp.cmd = 0x%08x (undefined/unknown/invalid)\n",
+                       __func__, tvp->cmd);
+               return;
+       }
+
+       printk("%s() tvp.cmd    = 0x%08x (%s)\n"
+               ,__FUNCTION__
+               ,tvp->cmd
+               ,dtv_cmds[ tvp->cmd ].name);
+
+       if(dtv_cmds[ tvp->cmd ].buffer) {
+
+               printk("%s() tvp.u.buffer.len = 0x%02x\n"
+                       ,__FUNCTION__
+                       ,tvp->u.buffer.len);
+
+               for(i = 0; i < tvp->u.buffer.len; i++)
+                       printk("%s() tvp.u.buffer.data[0x%02x] = 0x%02x\n"
+                               ,__FUNCTION__
+                               ,i
+                               ,tvp->u.buffer.data[i]);
+
+       } else
+               printk("%s() tvp.u.data = 0x%08x\n", __FUNCTION__, tvp->u.data);
+}
+
+int is_legacy_delivery_system(fe_delivery_system_t s)
+{
+       if((s == SYS_UNDEFINED) || (s == SYS_DVBC_ANNEX_AC) ||
+               (s == SYS_DVBC_ANNEX_B) || (s == SYS_DVBT) || (s == SYS_DVBS))
+               return 1;
+
+       return 0;
+}
+
+/* Synchronise the legacy tuning parameters into the cache, so that demodulator
+ * drivers can use a single set_frontend tuning function, regardless of whether
+ * it's being used for the legacy or new API, reducing code and complexity.
+ */
+void dtv_property_cache_sync(struct dvb_frontend *fe, struct dvb_frontend_parameters *p)
+{
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+       printk("%s()\n", __FUNCTION__);
+
+       c->frequency = p->frequency;
+       c->inversion = p->inversion;
+
+       switch (fe->ops.info.type) {
+       case FE_QPSK:
+               c->modulation = QPSK;   /* implied for DVB-S in legacy API */
+               c->rolloff = ROLLOFF_35;/* implied for DVB-S */
+               c->symbol_rate = p->u.qpsk.symbol_rate;
+               c->fec_inner = p->u.qpsk.fec_inner;
+               c->delivery_system = SYS_DVBS;
+               break;
+       case FE_QAM:
+               c->symbol_rate = p->u.qam.symbol_rate;
+               c->fec_inner = p->u.qam.fec_inner;
+               c->modulation = p->u.qam.modulation;
+               c->delivery_system = SYS_DVBC_ANNEX_AC;
+               break;
+       case FE_OFDM:
+               if (p->u.ofdm.bandwidth == BANDWIDTH_6_MHZ)
+                       c->bandwidth_hz = 6000000;
+               else if (p->u.ofdm.bandwidth == BANDWIDTH_7_MHZ)
+                       c->bandwidth_hz = 7000000;
+               else if (p->u.ofdm.bandwidth == BANDWIDTH_8_MHZ)
+                       c->bandwidth_hz = 8000000;
+               else
+                       /* Including BANDWIDTH_AUTO */
+                       c->bandwidth_hz = 0;
+               c->code_rate_HP = p->u.ofdm.code_rate_HP;
+               c->code_rate_LP = p->u.ofdm.code_rate_LP;
+               c->modulation = p->u.ofdm.constellation;
+               c->transmission_mode = p->u.ofdm.transmission_mode;
+               c->guard_interval = p->u.ofdm.guard_interval;
+               c->hierarchy = p->u.ofdm.hierarchy_information;
+               c->delivery_system = SYS_DVBT;
+               break;
+       case FE_ATSC:
+               c->modulation = p->u.vsb.modulation;
+               if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
+                       c->delivery_system = SYS_ATSC;
+               else
+                       c->delivery_system = SYS_DVBC_ANNEX_B;
+               break;
+       }
+}
+
+/* Ensure the cached values are set correctly in the frontend
+ * legacy tuning structures, for the advanced tuning API.
+ */
+void dtv_property_legacy_params_sync(struct dvb_frontend *fe)
+{
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct dvb_frontend_private *fepriv = fe->frontend_priv;
+       struct dvb_frontend_parameters *p = &fepriv->parameters;
+
+       printk("%s()\n", __FUNCTION__);
+
+       p->frequency = c->frequency;
+       p->inversion = c->inversion;
+
+       switch (fe->ops.info.type) {
+       case FE_QPSK:
+               printk("%s() Preparing QPSK req\n", __FUNCTION__);
+               p->u.qpsk.symbol_rate = c->symbol_rate;
+               p->u.qpsk.fec_inner = c->fec_inner;
+               c->delivery_system = SYS_DVBS;
+               break;
+       case FE_QAM:
+               printk("%s() Preparing QAM req\n", __FUNCTION__);
+               p->u.qam.symbol_rate = c->symbol_rate;
+               p->u.qam.fec_inner = c->fec_inner;
+               p->u.qam.modulation = c->modulation;
+               c->delivery_system = SYS_DVBC_ANNEX_AC;
+               break;
+       case FE_OFDM:
+               printk("%s() Preparing OFDM req\n", __FUNCTION__);
+               if (c->bandwidth_hz == 6000000)
+                       p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
+               else if (c->bandwidth_hz == 7000000)
+                       p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
+               else if (c->bandwidth_hz == 8000000)
+                       p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
+               else
+                       p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
+               p->u.ofdm.code_rate_HP = c->code_rate_HP;
+               p->u.ofdm.code_rate_LP = c->code_rate_LP;
+               p->u.ofdm.constellation = c->modulation;
+               p->u.ofdm.transmission_mode = c->transmission_mode;
+               p->u.ofdm.guard_interval = c->guard_interval;
+               p->u.ofdm.hierarchy_information = c->hierarchy;
+               c->delivery_system = SYS_DVBT;
+               break;
+       case FE_ATSC:
+               printk("%s() Preparing VSB req\n", __FUNCTION__);
+               p->u.vsb.modulation = c->modulation;
+               if ((c->modulation == VSB_8) || (c->modulation == VSB_16))
+                       c->delivery_system = SYS_ATSC;
+               else
+                       c->delivery_system = SYS_DVBC_ANNEX_B;
+               break;
+       }
+}
+
+/* Ensure the cached values are set correctly in the frontend
+ * legacy tuning structures, for the legacy tuning API.
+ */
+void dtv_property_adv_params_sync(struct dvb_frontend *fe)
+{
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct dvb_frontend_private *fepriv = fe->frontend_priv;
+       struct dvb_frontend_parameters *p = &fepriv->parameters;
+
+       printk("%s()\n", __FUNCTION__);
+
+       p->frequency = c->frequency;
+       p->inversion = c->inversion;
+
+       switch(c->modulation) {
+       case PSK_8:
+       case APSK_16:
+       case QPSK:
+               p->u.qpsk.symbol_rate = c->symbol_rate;
+               p->u.qpsk.fec_inner = c->fec_inner;
+               break;
+       default:
+               break;
+       }
+
+       if(c->delivery_system == SYS_ISDBT) {
+               /* Fake out a generic DVB-T request so we pass validation in the ioctl */
+               p->frequency = c->frequency;
+               p->inversion = INVERSION_AUTO;
+               p->u.ofdm.constellation = QAM_AUTO;
+               p->u.ofdm.code_rate_HP = FEC_AUTO;
+               p->u.ofdm.code_rate_LP = FEC_AUTO;
+               p->u.ofdm.bandwidth = BANDWIDTH_AUTO;
+               p->u.ofdm.transmission_mode = TRANSMISSION_MODE_AUTO;
+               p->u.ofdm.guard_interval = GUARD_INTERVAL_AUTO;
+               p->u.ofdm.hierarchy_information = HIERARCHY_AUTO;
+       }
+}
+
+void dtv_property_cache_submit(struct dvb_frontend *fe)
+{
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+       printk("%s()\n", __FUNCTION__);
+
+       /* For legacy delivery systems we don't need the delivery_system to
+        * be specified, but we populate the older structures from the cache
+        * so we can call set_frontend on older drivers.
+        */
+       if(is_legacy_delivery_system(c->delivery_system)) {
+
+               printk("%s() legacy, modulation = %d\n", __FUNCTION__, c->modulation);
+               dtv_property_legacy_params_sync(fe);
+
+       } else {
+               printk("%s() adv, modulation = %d\n", __FUNCTION__, c->modulation);
+
+               /* For advanced delivery systems / modulation types ...
+                * we seed the lecacy dvb_frontend_parameters structure
+                * so that the sanity checking code later in the IOCTL processing
+                * can validate our basic frequency ranges, symbolrates, modulation
+                * etc.
+                */
+               dtv_property_adv_params_sync(fe);
+       }
+}
+
+static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
+                       unsigned int cmd, void *parg);
+static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
+                       unsigned int cmd, void *parg);
+
+int dtv_property_process_get(struct dvb_frontend *fe, struct dtv_property *tvp,
+       struct inode *inode, struct file *file)
+{
+       int r = 0;
+
+       printk("%s()\n", __FUNCTION__);
+
+       dtv_property_dump(tvp);
+
+       /* Allow the frontend to validate incoming properties */
+       if (fe->ops.get_property)
+               r = fe->ops.get_property(fe, tvp);
+
+       if (r < 0)
+               return r;
+
+       switch(tvp->cmd) {
+       case DTV_FREQUENCY:
+               tvp->u.data = fe->dtv_property_cache.frequency;
+               break;
+       case DTV_MODULATION:
+               tvp->u.data = fe->dtv_property_cache.modulation;
+               break;
+       case DTV_BANDWIDTH_HZ:
+               tvp->u.data = fe->dtv_property_cache.bandwidth_hz;
+               break;
+       case DTV_INVERSION:
+               tvp->u.data = fe->dtv_property_cache.inversion;
+               break;
+       case DTV_SYMBOL_RATE:
+               tvp->u.data = fe->dtv_property_cache.symbol_rate;
+               break;
+       case DTV_INNER_FEC:
+               tvp->u.data = fe->dtv_property_cache.fec_inner;
+               break;
+       case DTV_PILOT:
+               tvp->u.data = fe->dtv_property_cache.pilot;
+               break;
+       case DTV_ROLLOFF:
+               tvp->u.data = fe->dtv_property_cache.rolloff;
+               break;
+       case DTV_DELIVERY_SYSTEM:
+               tvp->u.data = fe->dtv_property_cache.delivery_system;
+               break;
+       case DTV_VOLTAGE:
+               tvp->u.data = fe->dtv_property_cache.voltage;
+               break;
+       case DTV_TONE:
+               tvp->u.data = fe->dtv_property_cache.sectone;
+               break;
+       case DTV_API_VERSION:
+               tvp->u.data = (DVB_API_VERSION << 8) | DVB_API_VERSION_MINOR;
+               break;
+       case DTV_CODE_RATE_HP:
+               tvp->u.data = fe->dtv_property_cache.code_rate_HP;
+               break;
+       case DTV_CODE_RATE_LP:
+               tvp->u.data = fe->dtv_property_cache.code_rate_LP;
+               break;
+       case DTV_GUARD_INTERVAL:
+               tvp->u.data = fe->dtv_property_cache.guard_interval;
+               break;
+       case DTV_TRANSMISSION_MODE:
+               tvp->u.data = fe->dtv_property_cache.transmission_mode;
+               break;
+       case DTV_HIERARCHY:
+               tvp->u.data = fe->dtv_property_cache.hierarchy;
+               break;
+       default:
+               r = -1;
+       }
+
+       return r;
+}
+
+int dtv_property_process_set(struct dvb_frontend *fe, struct dtv_property *tvp,
+       struct inode *inode, struct file *file)
+{
+       int r = 0;
+       struct dvb_frontend_private *fepriv = fe->frontend_priv;
+       printk("%s()\n", __FUNCTION__);
+       dtv_property_dump(tvp);
+
+       /* Allow the frontend to validate incoming properties */
+       if (fe->ops.set_property)
+               r = fe->ops.set_property(fe, tvp);
+
+       if (r < 0)
+               return r;
+
+       switch(tvp->cmd) {
+       case DTV_CLEAR:
+               /* Reset a cache of data specific to the frontend here. This does
+                * not effect hardware.
+                */
+               printk("%s() Flushing property cache\n", __FUNCTION__);
+               memset(&fe->dtv_property_cache, 0, sizeof(struct dtv_frontend_properties));
+               fe->dtv_property_cache.state = tvp->cmd;
+               fe->dtv_property_cache.delivery_system = SYS_UNDEFINED;
+               break;
+       case DTV_TUNE:
+               /* interpret the cache of data, build either a traditional frontend
+                * tunerequest so we can pass validation in the FE_SET_FRONTEND
+                * ioctl.
+                */
+               fe->dtv_property_cache.state = tvp->cmd;
+               printk("%s() Finalised property cache\n", __FUNCTION__);
+               dtv_property_cache_submit(fe);
+
+               r |= dvb_frontend_ioctl_legacy(inode, file, FE_SET_FRONTEND,
+                       &fepriv->parameters);
+               break;
+       case DTV_FREQUENCY:
+               fe->dtv_property_cache.frequency = tvp->u.data;
+               break;
+       case DTV_MODULATION:
+               fe->dtv_property_cache.modulation = tvp->u.data;
+               break;
+       case DTV_BANDWIDTH_HZ:
+               fe->dtv_property_cache.bandwidth_hz = tvp->u.data;
+               break;
+       case DTV_INVERSION:
+               fe->dtv_property_cache.inversion = tvp->u.data;
+               break;
+       case DTV_SYMBOL_RATE:
+               fe->dtv_property_cache.symbol_rate = tvp->u.data;
+               break;
+       case DTV_INNER_FEC:
+               fe->dtv_property_cache.fec_inner = tvp->u.data;
+               break;
+       case DTV_PILOT:
+               fe->dtv_property_cache.pilot = tvp->u.data;
+               break;
+       case DTV_ROLLOFF:
+               fe->dtv_property_cache.rolloff = tvp->u.data;
+               break;
+       case DTV_DELIVERY_SYSTEM:
+               fe->dtv_property_cache.delivery_system = tvp->u.data;
+               break;
+       case DTV_VOLTAGE:
+               fe->dtv_property_cache.voltage = tvp->u.data;
+               r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_VOLTAGE,
+                       (void *)fe->dtv_property_cache.voltage);
+               break;
+       case DTV_TONE:
+               fe->dtv_property_cache.sectone = tvp->u.data;
+               r = dvb_frontend_ioctl_legacy(inode, file, FE_SET_TONE,
+                       (void *)fe->dtv_property_cache.sectone);
+               break;
+       case DTV_CODE_RATE_HP:
+               fe->dtv_property_cache.code_rate_HP = tvp->u.data;
+               break;
+       case DTV_CODE_RATE_LP:
+               fe->dtv_property_cache.code_rate_LP = tvp->u.data;
+               break;
+       case DTV_GUARD_INTERVAL:
+               fe->dtv_property_cache.guard_interval = tvp->u.data;
+               break;
+       case DTV_TRANSMISSION_MODE:
+               fe->dtv_property_cache.transmission_mode = tvp->u.data;
+               break;
+       case DTV_HIERARCHY:
+               fe->dtv_property_cache.hierarchy = tvp->u.data;
+               break;
+       default:
+               r = -1;
+       }
+
+       return r;
+}
+
 static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
                        unsigned int cmd, void *parg)
 {
@@ -776,6 +1310,116 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
        if (down_interruptible (&fepriv->sem))
                return -ERESTARTSYS;
 
+       if ((cmd == FE_SET_PROPERTY) || (cmd == FE_GET_PROPERTY))
+               err = dvb_frontend_ioctl_properties(inode, file, cmd, parg);
+       else {
+               fe->dtv_property_cache.state = DTV_UNDEFINED;
+               err = dvb_frontend_ioctl_legacy(inode, file, cmd, parg);
+       }
+
+       up(&fepriv->sem);
+       return err;
+}
+
+static int dvb_frontend_ioctl_properties(struct inode *inode, struct file *file,
+                       unsigned int cmd, void *parg)
+{
+       struct dvb_device *dvbdev = file->private_data;
+       struct dvb_frontend *fe = dvbdev->priv;
+       int err = 0;
+
+       struct dtv_properties *tvps = NULL;
+       struct dtv_property *tvp = NULL;
+       int i;
+
+       dprintk("%s\n", __func__);
+
+       if(cmd == FE_SET_PROPERTY) {
+               printk("%s() FE_SET_PROPERTY\n", __FUNCTION__);
+
+               tvps = (struct dtv_properties __user *)parg;
+
+               printk("%s() properties.num = %d\n", __FUNCTION__, tvps->num);
+               printk("%s() properties.props = %p\n", __FUNCTION__, tvps->props);
+
+               /* Put an arbitrary limit on the number of messages that can
+                * be sent at once */
+               if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
+                       return -EINVAL;
+
+               tvp = (struct dtv_property *) kmalloc(tvps->num *
+                       sizeof(struct dtv_property), GFP_KERNEL);
+               if (!tvp) {
+                       err = -ENOMEM;
+                       goto out;
+               }
+
+               if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
+                       err = -EFAULT;
+                       goto out;
+               }
+
+               for (i = 0; i < tvps->num; i++) {
+                       (tvp + i)->result = dtv_property_process_set(fe, tvp + i, inode, file);
+                       err |= (tvp + i)->result;
+               }
+
+               if(fe->dtv_property_cache.state == DTV_TUNE) {
+                       printk("%s() Property cache is full, tuning\n", __FUNCTION__);
+               }
+
+       } else
+       if(cmd == FE_GET_PROPERTY) {
+               printk("%s() FE_GET_PROPERTY\n", __FUNCTION__);
+
+               tvps = (struct dtv_properties __user *)parg;
+
+               printk("%s() properties.num = %d\n", __FUNCTION__, tvps->num);
+               printk("%s() properties.props = %p\n", __FUNCTION__, tvps->props);
+
+               /* Put an arbitrary limit on the number of messages that can
+                * be sent at once */
+               if ((tvps->num == 0) || (tvps->num > DTV_IOCTL_MAX_MSGS))
+                       return -EINVAL;
+
+               tvp = (struct dtv_property *) kmalloc(tvps->num *
+                       sizeof(struct dtv_property), GFP_KERNEL);
+               if (!tvp) {
+                       err = -ENOMEM;
+                       goto out;
+               }
+
+               if (copy_from_user(tvp, tvps->props, tvps->num * sizeof(struct dtv_property))) {
+                       err = -EFAULT;
+                       goto out;
+               }
+
+               for (i = 0; i < tvps->num; i++) {
+                       (tvp + i)->result = dtv_property_process_get(fe, tvp + i, inode, file);
+                       err |= (tvp + i)->result;
+               }
+
+               if (copy_to_user(tvps->props, tvp, tvps->num * sizeof(struct dtv_property))) {
+                       err = -EFAULT;
+                       goto out;
+               }
+
+       } else
+               err = -EOPNOTSUPP;
+
+out:
+       kfree(tvp);
+       return err;
+}
+
+static int dvb_frontend_ioctl_legacy(struct inode *inode, struct file *file,
+                       unsigned int cmd, void *parg)
+{
+       struct dvb_device *dvbdev = file->private_data;
+       struct dvb_frontend *fe = dvbdev->priv;
+       struct dvb_frontend_private *fepriv = fe->frontend_priv;
+       int err = -EOPNOTSUPP;
+
        switch (cmd) {
        case FE_GET_INFO: {
                struct dvb_frontend_info* info = parg;
@@ -942,13 +1586,21 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
        case FE_SET_FRONTEND: {
                struct dvb_frontend_tune_settings fetunesettings;
 
-               if (dvb_frontend_check_parameters(fe, parg) < 0) {
-                       err = -EINVAL;
-                       break;
-               }
+               if(fe->dtv_property_cache.state == DTV_TUNE) {
+                       if (dvb_frontend_check_parameters(fe, &fepriv->parameters) < 0) {
+                               err = -EINVAL;
+                               break;
+                       }
+               } else {
+                       if (dvb_frontend_check_parameters(fe, parg) < 0) {
+                               err = -EINVAL;
+                               break;
+                       }
 
-               memcpy (&fepriv->parameters, parg,
-                       sizeof (struct dvb_frontend_parameters));
+                       memcpy (&fepriv->parameters, parg,
+                               sizeof (struct dvb_frontend_parameters));
+                       dtv_property_cache_sync(fe, &fepriv->parameters);
+               }
 
                memset(&fetunesettings, 0, sizeof(struct dvb_frontend_tune_settings));
                memcpy(&fetunesettings.parameters, parg,
@@ -1027,10 +1679,10 @@ static int dvb_frontend_ioctl(struct inode *inode, struct file *file,
                break;
        };
 
-       up (&fepriv->sem);
        return err;
 }
 
+
 static unsigned int dvb_frontend_poll(struct file *file, struct poll_table_struct *wait)
 {
        struct dvb_device *dvbdev = file->private_data;
index aa4133f0bd1911d093b4e386aba4ab0c965f6ba8..3055301ff3cab3da0ee4a8ef555b9aa09c4a459d 100644 (file)
@@ -169,6 +169,9 @@ struct dvb_frontend_ops {
 
        struct dvb_tuner_ops tuner_ops;
        struct analog_demod_ops analog_ops;
+
+       int (*set_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
+       int (*get_property)(struct dvb_frontend* fe, struct dtv_property* tvp);
 };
 
 #define MAX_EVENT 8
@@ -182,6 +185,32 @@ struct dvb_fe_events {
        struct mutex              mtx;
 };
 
+struct dtv_frontend_properties {
+
+       /* Cache State */
+       u32                     state;
+
+       u32                     frequency;
+       fe_modulation_t         modulation;
+
+       fe_sec_voltage_t        voltage;
+       fe_sec_tone_mode_t      sectone;
+       fe_spectral_inversion_t inversion;
+       fe_code_rate_t          fec_inner;
+       fe_transmit_mode_t      transmission_mode;
+       u32                     bandwidth_hz;   /* 0 = AUTO */
+       fe_guard_interval_t     guard_interval;
+       fe_hierarchy_t          hierarchy;
+       u32                     symbol_rate;
+       fe_code_rate_t          code_rate_HP;
+       fe_code_rate_t          code_rate_LP;
+
+       fe_pilot_t              pilot;
+       fe_rolloff_t            rolloff;
+
+       fe_delivery_system_t    delivery_system;
+};
+
 struct dvb_frontend {
        struct dvb_frontend_ops ops;
        struct dvb_adapter *dvb;
@@ -190,6 +219,9 @@ struct dvb_frontend {
        void *frontend_priv;
        void *sec_priv;
        void *analog_demod_priv;
+       struct dtv_frontend_properties dtv_property_cache;
+#define DVB_FRONTEND_COMPONENT_TUNER 0
+       int (*callback)(void *adapter_priv, int component, int cmd, int arg);
 };
 
 extern int dvb_register_frontend(struct dvb_adapter *dvb,
index e84152b7576d731940fc957b22c77b0e42f67a4f..3c13bcfa6385719e6f1388a4682e9e0c767dd1ea 100644 (file)
@@ -72,9 +72,11 @@ config DVB_USB_DIB0700
        select DVB_DIB7000P
        select DVB_DIB7000M
        select DVB_DIB3000MC
+       select DVB_S5H1411 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_MT2060 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_MT2266 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_XC5000 if !DVB_FE_CUSTOMIZE
        select DVB_TUNER_DIB0070
        help
          Support for USB2.0/1.1 DVB receivers based on the DiB0700 USB bridge. The
@@ -108,6 +110,8 @@ config DVB_USB_CXUSB
        select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE
+       select DVB_DIB7000P if !DVB_FE_CUSTOMISE
+       select DVB_TUNER_DIB0070 if !DVB_FE_CUSTOMISE
        help
          Say Y here to support the Conexant USB2.0 hybrid reference design.
          Currently, only DVB and ATSC modes are supported, analog mode
@@ -245,12 +249,25 @@ config DVB_USB_AF9005_REMOTE
          Afatech AF9005 based receiver.
 
 config DVB_USB_DW2102
-       tristate "DvbWorld 2102 DVB-S USB2.0 receiver"
+       tristate "DvbWorld DVB-S/S2 USB2.0 support"
        depends on DVB_USB
-       select DVB_STV0299 if !DVB_FE_CUSTOMISE
        select DVB_PLL if !DVB_FE_CUSTOMISE
+       select DVB_STV0299 if !DVB_FE_CUSTOMISE
+       select DVB_STV0288 if !DVB_FE_CUSTOMISE
+       select DVB_STB6000 if !DVB_FE_CUSTOMISE
+       select DVB_CX24116 if !DVB_FE_CUSTOMISE
+       select DVB_SI21XX if !DVB_FE_CUSTOMISE
        help
-          Say Y here to support the DvbWorld 2102 DVB-S USB2.0 receiver.
+         Say Y here to support the DvbWorld DVB-S/S2 USB2.0 receivers
+         and the TeVii S650.
+
+config         DVB_USB_CINERGY_T2
+       tristate "Terratec CinergyT2/qanu USB 2.0 DVB-T receiver"
+       depends on DVB_USB
+       help
+         Support for "TerraTec CinergyT2" USB2.0 Highspeed DVB Receivers
+
+         Say Y if you own such a device and want to use it.
 
 config DVB_USB_ANYSEE
        tristate "Anysee DVB-T/C USB2.0 support"
@@ -262,3 +279,22 @@ config DVB_USB_ANYSEE
        help
          Say Y here to support the Anysee E30, Anysee E30 Plus or
          Anysee E30 C Plus DVB USB2.0 receiver.
+
+config DVB_USB_DTV5100
+       tristate "AME DTV-5100 USB2.0 DVB-T support"
+       depends on DVB_USB
+       select MEDIA_TUNER_QT1010 if !DVB_FE_CUSTOMISE
+       help
+         Say Y here to support the AME DTV-5100 USB2.0 DVB-T receiver.
+
+config DVB_USB_AF9015
+       tristate "Afatech AF9015 DVB-T USB2.0 support"
+       depends on DVB_USB && EXPERIMENTAL
+       select DVB_AF9013
+       select DVB_PLL              if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_MT2060   if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_QT1010   if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMISE
+       select MEDIA_TUNER_MXL5005S if !DVB_FE_CUSTOMISE
+       help
+         Say Y here to support the Afatech AF9015 based DVB-T USB2.0 receiver
index e206f1ea0027c9804789525fa9a558c3bcaf6be1..3122b7cc2c239b74514339398d29ccd2fbb5809e 100644 (file)
@@ -67,6 +67,16 @@ obj-$(CONFIG_DVB_USB_ANYSEE) += dvb-usb-anysee.o
 dvb-usb-dw2102-objs = dw2102.o
 obj-$(CONFIG_DVB_USB_DW2102) += dvb-usb-dw2102.o
 
+dvb-usb-dtv5100-objs = dtv5100.o
+obj-$(CONFIG_DVB_USB_DTV5100) += dvb-usb-dtv5100.o
+
+dvb-usb-af9015-objs = af9015.o
+obj-$(CONFIG_DVB_USB_AF9015) += dvb-usb-af9015.o
+
+dvb-usb-cinergyT2-objs = cinergyT2-core.o cinergyT2-fe.o
+obj-$(CONFIG_DVB_USB_CINERGY_T2) += dvb-usb-cinergyT2.o
+
+
 EXTRA_CFLAGS += -Idrivers/media/dvb/dvb-core/ -Idrivers/media/dvb/frontends/
 # due to tuner-xc3028
 EXTRA_CFLAGS += -Idrivers/media/common/tuners
index ff00c0e8f4a1ce34c28000c481af51012852c260..7c596f926764376d8ebfdd24c5f7f8f9f576d4e0 100644 (file)
@@ -25,7 +25,7 @@
  */
 #include "af9005.h"
 /* debug */
-int dvb_usb_af9005_remote_debug;
+static int dvb_usb_af9005_remote_debug;
 module_param_named(debug, dvb_usb_af9005_remote_debug, int, 0644);
 MODULE_PARM_DESC(debug,
                 "enable (1) or disable (0) debug messages."
index 6eeaae51b1ca585ec9ad9962f58d8ea19aa29b15..4d69045426ddd3e7c394f3486849ab1c6c8e9543 100644 (file)
@@ -14,7 +14,7 @@ typedef struct {
        u8 val;
 } RegDesc;
 
-RegDesc script[] = {
+static RegDesc script[] = {
        {0xa180, 0x0, 0x8, 0xa},
        {0xa181, 0x0, 0x8, 0xd7},
        {0xa182, 0x0, 0x8, 0xa3},
index cfe71feefcad27a8e64598316a366bda99ae8985..ca5a0a4d2a47c9ba9bc21ce4ce2173665eac66b4 100644 (file)
@@ -35,17 +35,17 @@ module_param_named(led, dvb_usb_af9005_led, bool, 0644);
 MODULE_PARM_DESC(led, "enable led (default: 1).");
 
 /* eeprom dump */
-int dvb_usb_af9005_dump_eeprom = 0;
+static int dvb_usb_af9005_dump_eeprom;
 module_param_named(dump_eeprom, dvb_usb_af9005_dump_eeprom, int, 0);
 MODULE_PARM_DESC(dump_eeprom, "dump contents of the eeprom.");
 
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 /* remote control decoder */
-int (*rc_decode) (struct dvb_usb_device * d, u8 * data, int len, u32 * event,
-                 int *state);
-void *rc_keys;
-int *rc_keys_size;
+static int (*rc_decode) (struct dvb_usb_device *d, u8 *data, int len,
+               u32 *event, int *state);
+static void *rc_keys;
+static int *rc_keys_size;
 
 u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
 
@@ -54,8 +54,8 @@ struct af9005_device_state {
        int led_state;
 };
 
-int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 * wbuf, u16 wlen,
-                         u8 * rbuf, u16 rlen, int delay_ms)
+static int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 *wbuf, u16 wlen,
+                         u8 *rbuf, u16 rlen, int delay_ms)
 {
        int actlen, ret = -ENOMEM;
 
@@ -98,12 +98,7 @@ int af9005_usb_generic_rw(struct dvb_usb_device *d, u8 * wbuf, u16 wlen,
        return ret;
 }
 
-int af9005_usb_generic_write(struct dvb_usb_device *d, u8 * buf, u16 len)
-{
-       return af9005_usb_generic_rw(d, buf, len, NULL, 0, 0);
-}
-
-int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
+static int af9005_generic_read_write(struct dvb_usb_device *d, u16 reg,
                              int readwrite, int type, u8 * values, int len)
 {
        struct af9005_device_state *st = d->priv;
@@ -765,7 +760,7 @@ static int af9005_boot_packet(struct usb_device *udev, int type, u8 * reply)
        return 0;
 }
 
-int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
+static int af9005_download_firmware(struct usb_device *udev, const struct firmware *fw)
 {
        int i, packets, ret, act_len;
 
diff --git a/drivers/media/dvb/dvb-usb/af9015.c b/drivers/media/dvb/dvb-usb/af9015.c
new file mode 100644 (file)
index 0000000..cb0829c
--- /dev/null
@@ -0,0 +1,1474 @@
+/*
+ * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
+ *
+ * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
+ *
+ * Thanks to Afatech who kindly provided information.
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "af9015.h"
+#include "af9013.h"
+#include "mt2060.h"
+#include "qt1010.h"
+#include "tda18271.h"
+#include "mxl5005s.h"
+#if 0
+#include "mc44s80x.h"
+#endif
+
+int dvb_usb_af9015_debug;
+module_param_named(debug, dvb_usb_af9015_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
+int dvb_usb_af9015_remote;
+module_param_named(remote, dvb_usb_af9015_remote, int, 0644);
+MODULE_PARM_DESC(remote, "select remote");
+int dvb_usb_af9015_dual_mode;
+module_param_named(dual_mode, dvb_usb_af9015_dual_mode, int, 0644);
+MODULE_PARM_DESC(dual_mode, "enable dual mode");
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static DEFINE_MUTEX(af9015_usb_mutex);
+
+static struct af9015_config af9015_config;
+static struct dvb_usb_device_properties af9015_properties[2];
+int af9015_properties_count = ARRAY_SIZE(af9015_properties);
+
+static struct af9013_config af9015_af9013_config[] = {
+       {
+               .demod_address = AF9015_I2C_DEMOD,
+               .output_mode = AF9013_OUTPUT_MODE_USB,
+               .api_version = { 0, 1, 9, 0 },
+               .gpio[0] = AF9013_GPIO_HI,
+               .gpio[3] = AF9013_GPIO_TUNER_ON,
+
+       }, {
+               .output_mode = AF9013_OUTPUT_MODE_SERIAL,
+               .api_version = { 0, 1, 9, 0 },
+               .gpio[0] = AF9013_GPIO_TUNER_ON,
+               .gpio[1] = AF9013_GPIO_LO,
+       }
+};
+
+static int af9015_rw_udev(struct usb_device *udev, struct req_t *req)
+{
+       int act_len, ret;
+       u8 buf[64];
+       u8 write = 1;
+       u8 msg_len = 8;
+       static u8 seq; /* packet sequence number */
+
+       if (mutex_lock_interruptible(&af9015_usb_mutex) < 0)
+               return -EAGAIN;
+
+       buf[0] = req->cmd;
+       buf[1] = seq++;
+       buf[2] = req->i2c_addr;
+       buf[3] = req->addr >> 8;
+       buf[4] = req->addr & 0xff;
+       buf[5] = req->mbox;
+       buf[6] = req->addr_len;
+       buf[7] = req->data_len;
+
+       switch (req->cmd) {
+       case GET_CONFIG:
+       case BOOT:
+       case READ_MEMORY:
+       case RECONNECT_USB:
+       case GET_IR_CODE:
+               write = 0;
+               break;
+       case READ_I2C:
+               write = 0;
+               buf[2] |= 0x01; /* set I2C direction */
+       case WRITE_I2C:
+               buf[0] = READ_WRITE_I2C;
+               break;
+       case WRITE_MEMORY:
+               if (((req->addr & 0xff00) == 0xff00) ||
+                   ((req->addr & 0xae00) == 0xae00))
+                       buf[0] = WRITE_VIRTUAL_MEMORY;
+       case WRITE_VIRTUAL_MEMORY:
+       case COPY_FIRMWARE:
+       case DOWNLOAD_FIRMWARE:
+               break;
+       default:
+               err("unknown command:%d", req->cmd);
+               ret = -1;
+               goto error_unlock;
+       }
+
+       /* write requested */
+       if (write) {
+               memcpy(&buf[8], req->data, req->data_len);
+               msg_len += req->data_len;
+       }
+       deb_xfer(">>> ");
+       debug_dump(buf, msg_len, deb_xfer);
+
+       /* send req */
+       ret = usb_bulk_msg(udev, usb_sndbulkpipe(udev, 0x02), buf, msg_len,
+       &act_len, AF9015_USB_TIMEOUT);
+       if (ret)
+               err("bulk message failed:%d (%d/%d)", ret, msg_len, act_len);
+       else
+               if (act_len != msg_len)
+                       ret = -1; /* all data is not send */
+       if (ret)
+               goto error_unlock;
+
+       /* no ack for those packets */
+       if (req->cmd == DOWNLOAD_FIRMWARE || req->cmd == RECONNECT_USB)
+               goto exit_unlock;
+
+       /* receive ack and data if read req */
+       msg_len = 1 + 1 + req->data_len;  /* seq + status + data len */
+       ret = usb_bulk_msg(udev, usb_rcvbulkpipe(udev, 0x81), buf, msg_len,
+                          &act_len, AF9015_USB_TIMEOUT);
+       if (ret) {
+               err("recv bulk message failed:%d", ret);
+               ret = -1;
+               goto error_unlock;
+       }
+
+       deb_xfer("<<< ");
+       debug_dump(buf, act_len, deb_xfer);
+
+       /* remote controller query status is 1 if remote code is not received */
+       if (req->cmd == GET_IR_CODE && buf[1] == 1) {
+               buf[1] = 0; /* clear command "error" status */
+               memset(&buf[2], 0, req->data_len);
+               buf[3] = 1; /* no remote code received mark */
+       }
+
+       /* check status */
+       if (buf[1]) {
+               err("command failed:%d", buf[1]);
+               ret = -1;
+               goto error_unlock;
+       }
+
+       /* read request, copy returned data to return buf */
+       if (!write)
+               memcpy(req->data, &buf[2], req->data_len);
+
+error_unlock:
+exit_unlock:
+       mutex_unlock(&af9015_usb_mutex);
+
+       return ret;
+}
+
+static int af9015_ctrl_msg(struct dvb_usb_device *d, struct req_t *req)
+{
+       return af9015_rw_udev(d->udev, req);
+}
+
+static int af9015_write_regs(struct dvb_usb_device *d, u16 addr, u8 *val,
+       u8 len)
+{
+       struct req_t req = {WRITE_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, len,
+               val};
+       return af9015_ctrl_msg(d, &req);
+}
+
+static int af9015_write_reg(struct dvb_usb_device *d, u16 addr, u8 val)
+{
+       return af9015_write_regs(d, addr, &val, 1);
+}
+
+static int af9015_read_reg(struct dvb_usb_device *d, u16 addr, u8 *val)
+{
+       struct req_t req = {READ_MEMORY, AF9015_I2C_DEMOD, addr, 0, 0, 1, val};
+       return af9015_ctrl_msg(d, &req);
+}
+
+static int af9015_write_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
+       u8 val)
+{
+       struct req_t req = {WRITE_I2C, addr, reg, 1, 1, 1, &val};
+
+       if (addr == af9015_af9013_config[0].demod_address ||
+           addr == af9015_af9013_config[1].demod_address)
+               req.addr_len = 3;
+
+       return af9015_ctrl_msg(d, &req);
+}
+
+static int af9015_read_reg_i2c(struct dvb_usb_device *d, u8 addr, u16 reg,
+       u8 *val)
+{
+       struct req_t req = {READ_I2C, addr, reg, 0, 1, 1, val};
+
+       if (addr == af9015_af9013_config[0].demod_address ||
+           addr == af9015_af9013_config[1].demod_address)
+               req.addr_len = 3;
+
+       return af9015_ctrl_msg(d, &req);
+}
+
+static int af9015_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
+       int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int ret = 0, i = 0;
+       u16 addr;
+       u8 mbox, addr_len;
+       struct req_t req;
+
+/* TODO: implement bus lock
+
+The bus lock is needed because there is two tuners both using same I2C-address.
+Due to that the only way to select correct tuner is use demodulator I2C-gate.
+
+................................................
+. AF9015 includes integrated AF9013 demodulator.
+. ____________                   ____________  .                ____________
+.|     uC     |                 |   demod    | .               |    tuner   |
+.|------------|                 |------------| .               |------------|
+.|   AF9015   |                 |  AF9013/5  | .               |   MXL5003  |
+.|            |--+----I2C-------|-----/ -----|-.-----I2C-------|            |
+.|            |  |              | addr 0x38  | .               |  addr 0xc6 |
+.|____________|  |              |____________| .               |____________|
+.................|..............................
+                |               ____________                   ____________
+                |              |   demod    |                 |    tuner   |
+                |              |------------|                 |------------|
+                |              |   AF9013   |                 |   MXL5003  |
+                +----I2C-------|-----/ -----|-------I2C-------|            |
+                               | addr 0x3a  |                 |  addr 0xc6 |
+                               |____________|                 |____________|
+*/
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       while (i < num) {
+               if (msg[i].addr == af9015_af9013_config[0].demod_address ||
+                   msg[i].addr == af9015_af9013_config[1].demod_address) {
+                       addr = msg[i].buf[0] << 8;
+                       addr += msg[i].buf[1];
+                       mbox = msg[i].buf[2];
+                       addr_len = 3;
+               } else {
+                       addr = msg[i].buf[0];
+                       addr_len = 1;
+                       mbox = 0;
+               }
+
+               if (num > i + 1 && (msg[i+1].flags & I2C_M_RD)) {
+                       if (msg[i].addr ==
+                               af9015_af9013_config[0].demod_address)
+                               req.cmd = READ_MEMORY;
+                       else
+                               req.cmd = READ_I2C;
+                       req.i2c_addr = msg[i].addr;
+                       req.addr = addr;
+                       req.mbox = mbox;
+                       req.addr_len = addr_len;
+                       req.data_len = msg[i+1].len;
+                       req.data = &msg[i+1].buf[0];
+                       ret = af9015_ctrl_msg(d, &req);
+                       i += 2;
+               } else {
+                       if (msg[i].addr ==
+                               af9015_af9013_config[0].demod_address)
+                               req.cmd = WRITE_MEMORY;
+                       else
+                               req.cmd = WRITE_I2C;
+                       req.i2c_addr = msg[i].addr;
+                       req.addr = addr;
+                       req.mbox = mbox;
+                       req.addr_len = addr_len;
+                       req.data_len = msg[i].len-addr_len;
+                       req.data = &msg[i].buf[addr_len];
+                       ret = af9015_ctrl_msg(d, &req);
+                       i += 1;
+               }
+               if (ret)
+                       goto error;
+
+       }
+       ret = i;
+
+error:
+       mutex_unlock(&d->i2c_mutex);
+
+       return ret;
+}
+
+static u32 af9015_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm af9015_i2c_algo = {
+       .master_xfer = af9015_i2c_xfer,
+       .functionality = af9015_i2c_func,
+};
+
+static int af9015_do_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit, u8 op)
+{
+       int ret;
+       u8 val, mask = 0x01;
+
+       ret = af9015_read_reg(d, addr, &val);
+       if (ret)
+               return ret;
+
+       mask <<= bit;
+       if (op) {
+               /* set bit */
+               val |= mask;
+       } else {
+               /* clear bit */
+               mask ^= 0xff;
+               val &= mask;
+       }
+
+       return af9015_write_reg(d, addr, val);
+}
+
+static int af9015_set_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
+{
+       return af9015_do_reg_bit(d, addr, bit, 1);
+}
+
+static int af9015_clear_reg_bit(struct dvb_usb_device *d, u16 addr, u8 bit)
+{
+       return af9015_do_reg_bit(d, addr, bit, 0);
+}
+
+static int af9015_init_endpoint(struct dvb_usb_device *d)
+{
+       int ret;
+       u16 frame_size;
+       u8  packet_size;
+       deb_info("%s: USB speed:%d\n", __func__, d->udev->speed);
+
+#define TS_PACKET_SIZE            188
+
+#define TS_USB20_PACKET_COUNT     348
+#define TS_USB20_FRAME_SIZE       (TS_PACKET_SIZE*TS_USB20_PACKET_COUNT)
+
+#define TS_USB11_PACKET_COUNT      21
+#define TS_USB11_FRAME_SIZE       (TS_PACKET_SIZE*TS_USB11_PACKET_COUNT)
+
+#define TS_USB20_MAX_PACKET_SIZE  512
+#define TS_USB11_MAX_PACKET_SIZE   64
+
+       if (d->udev->speed == USB_SPEED_FULL) {
+               frame_size = TS_USB11_FRAME_SIZE/4;
+               packet_size = TS_USB11_MAX_PACKET_SIZE/4;
+       } else {
+               frame_size = TS_USB20_FRAME_SIZE/4;
+               packet_size = TS_USB20_MAX_PACKET_SIZE/4;
+       }
+
+       ret = af9015_set_reg_bit(d, 0xd507, 2); /* assert EP4 reset */
+       if (ret)
+               goto error;
+       ret = af9015_set_reg_bit(d, 0xd50b, 1); /* assert EP5 reset */
+       if (ret)
+               goto error;
+       ret = af9015_clear_reg_bit(d, 0xdd11, 5); /* disable EP4 */
+       if (ret)
+               goto error;
+       ret = af9015_clear_reg_bit(d, 0xdd11, 6); /* disable EP5 */
+       if (ret)
+               goto error;
+       ret = af9015_set_reg_bit(d, 0xdd11, 5); /* enable EP4 */
+       if (ret)
+               goto error;
+       if (af9015_config.dual_mode) {
+               ret = af9015_set_reg_bit(d, 0xdd11, 6); /* enable EP5 */
+               if (ret)
+                       goto error;
+       }
+       ret = af9015_clear_reg_bit(d, 0xdd13, 5); /* disable EP4 NAK */
+       if (ret)
+               goto error;
+       if (af9015_config.dual_mode) {
+               ret = af9015_clear_reg_bit(d, 0xdd13, 6); /* disable EP5 NAK */
+               if (ret)
+                       goto error;
+       }
+       /* EP4 xfer length */
+       ret = af9015_write_reg(d, 0xdd88, frame_size & 0xff);
+       if (ret)
+               goto error;
+       ret = af9015_write_reg(d, 0xdd89, frame_size >> 8);
+       if (ret)
+               goto error;
+       /* EP5 xfer length */
+       ret = af9015_write_reg(d, 0xdd8a, frame_size & 0xff);
+       if (ret)
+               goto error;
+       ret = af9015_write_reg(d, 0xdd8b, frame_size >> 8);
+       if (ret)
+               goto error;
+       ret = af9015_write_reg(d, 0xdd0c, packet_size); /* EP4 packet size */
+       if (ret)
+               goto error;
+       ret = af9015_write_reg(d, 0xdd0d, packet_size); /* EP5 packet size */
+       if (ret)
+               goto error;
+       ret = af9015_clear_reg_bit(d, 0xd507, 2); /* negate EP4 reset */
+       if (ret)
+               goto error;
+       if (af9015_config.dual_mode) {
+               ret = af9015_clear_reg_bit(d, 0xd50b, 1); /* negate EP5 reset */
+               if (ret)
+                       goto error;
+       }
+
+       /* enable / disable mp2if2 */
+       if (af9015_config.dual_mode)
+               ret = af9015_set_reg_bit(d, 0xd50b, 0);
+       else
+               ret = af9015_clear_reg_bit(d, 0xd50b, 0);
+error:
+       if (ret)
+               err("endpoint init failed:%d", ret);
+       return ret;
+}
+
+static int af9015_copy_firmware(struct dvb_usb_device *d)
+{
+       int ret;
+       u8 fw_params[4];
+       u8 val, i;
+       struct req_t req = {COPY_FIRMWARE, 0, 0x5100, 0, 0, sizeof(fw_params),
+               fw_params };
+       deb_info("%s:\n", __func__);
+
+       fw_params[0] = af9015_config.firmware_size >> 8;
+       fw_params[1] = af9015_config.firmware_size & 0xff;
+       fw_params[2] = af9015_config.firmware_checksum >> 8;
+       fw_params[3] = af9015_config.firmware_checksum & 0xff;
+
+       /* wait 2nd demodulator ready */
+       msleep(100);
+
+       ret = af9015_read_reg_i2c(d, 0x3a, 0x98be, &val);
+       if (ret)
+               goto error;
+       else
+               deb_info("%s: firmware status:%02x\n", __func__, val);
+
+       if (val == 0x0c) /* fw is running, no need for download */
+               goto exit;
+
+       /* set I2C master clock to fast (to speed up firmware copy) */
+       ret = af9015_write_reg(d, 0xd416, 0x04); /* 0x04 * 400ns */
+       if (ret)
+               goto error;
+
+       msleep(50);
+
+       /* copy firmware */
+       ret = af9015_ctrl_msg(d, &req);
+       if (ret)
+               err("firmware copy cmd failed:%d", ret);
+       deb_info("%s: firmware copy done\n", __func__);
+
+       /* set I2C master clock back to normal */
+       ret = af9015_write_reg(d, 0xd416, 0x14); /* 0x14 * 400ns */
+       if (ret)
+               goto error;
+
+       /* request boot firmware */
+       ret = af9015_write_reg_i2c(d, af9015_af9013_config[1].demod_address,
+               0xe205, 1);
+       deb_info("%s: firmware boot cmd status:%d\n", __func__, ret);
+       if (ret)
+               goto error;
+
+       for (i = 0; i < 15; i++) {
+               msleep(100);
+
+               /* check firmware status */
+               ret = af9015_read_reg_i2c(d,
+                       af9015_af9013_config[1].demod_address, 0x98be, &val);
+               deb_info("%s: firmware status cmd status:%d fw status:%02x\n",
+                       __func__, ret, val);
+               if (ret)
+                       goto error;
+
+               if (val == 0x0c || val == 0x04) /* success or fail */
+                       break;
+       }
+
+       if (val == 0x04) {
+               err("firmware did not run");
+               ret = -1;
+       } else if (val != 0x0c) {
+               err("firmware boot timeout");
+               ret = -1;
+       }
+
+error:
+exit:
+       return ret;
+}
+
+/* dump eeprom */
+static int af9015_eeprom_dump(struct dvb_usb_device *d)
+{
+       char buf[52], buf2[4];
+       u8 reg, val;
+
+       for (reg = 0; ; reg++) {
+               if (reg % 16 == 0) {
+                       if (reg)
+                               deb_info("%s\n", buf);
+                       sprintf(buf, "%02x: ", reg);
+               }
+               if (af9015_read_reg_i2c(d, AF9015_I2C_EEPROM, reg, &val) == 0)
+                       sprintf(buf2, "%02x ", val);
+               else
+                       strcpy(buf2, "-- ");
+               strcat(buf, buf2);
+               if (reg == 0xff)
+                       break;
+       }
+       deb_info("%s\n", buf);
+       return 0;
+}
+
+int af9015_download_ir_table(struct dvb_usb_device *d)
+{
+       int i, packets = 0, ret;
+       u16 addr = 0x9a56; /* ir-table start address */
+       struct req_t req = {WRITE_MEMORY, 0, 0, 0, 0, 1, NULL};
+       u8 *data = NULL;
+       deb_info("%s:\n", __func__);
+
+       data = af9015_config.ir_table;
+       packets = af9015_config.ir_table_size;
+
+       /* no remote */
+       if (!packets)
+               goto exit;
+
+       /* load remote ir-table */
+       for (i = 0; i < packets; i++) {
+               req.addr = addr + i;
+               req.data = &data[i];
+               ret = af9015_ctrl_msg(d, &req);
+               if (ret) {
+                       err("ir-table download failed at packet %d with " \
+                               "code %d", i, ret);
+                       return ret;
+               }
+       }
+
+exit:
+       return 0;
+}
+
+static int af9015_init(struct dvb_usb_device *d)
+{
+       int ret;
+       deb_info("%s:\n", __func__);
+
+       ret = af9015_init_endpoint(d);
+       if (ret)
+               goto error;
+
+       ret = af9015_download_ir_table(d);
+       if (ret)
+               goto error;
+
+error:
+       return ret;
+}
+
+static int af9015_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
+{
+       int ret;
+       deb_info("%s: onoff:%d\n", __func__, onoff);
+
+       if (onoff)
+               ret = af9015_set_reg_bit(adap->dev, 0xd503, 0);
+       else
+               ret = af9015_clear_reg_bit(adap->dev, 0xd503, 0);
+
+       return ret;
+}
+
+static int af9015_pid_filter(struct dvb_usb_adapter *adap, int index, u16 pid,
+       int onoff)
+{
+       int ret;
+       u8 idx;
+
+       deb_info("%s: set pid filter, index %d, pid %x, onoff %d\n",
+               __func__, index, pid, onoff);
+
+       ret = af9015_write_reg(adap->dev, 0xd505, (pid & 0xff));
+       if (ret)
+               goto error;
+
+       ret = af9015_write_reg(adap->dev, 0xd506, (pid >> 8));
+       if (ret)
+               goto error;
+
+       idx = ((index & 0x1f) | (1 << 5));
+       ret = af9015_write_reg(adap->dev, 0xd504, idx);
+
+error:
+       return ret;
+}
+
+static int af9015_download_firmware(struct usb_device *udev,
+       const struct firmware *fw)
+{
+       int i, len, packets, remainder, ret;
+       struct req_t req = {DOWNLOAD_FIRMWARE, 0, 0, 0, 0, 0, NULL};
+       u16 addr = 0x5100; /* firmware start address */
+       u16 checksum = 0;
+
+       deb_info("%s:\n", __func__);
+
+       /* calc checksum */
+       for (i = 0; i < fw->size; i++)
+               checksum += fw->data[i];
+
+       af9015_config.firmware_size = fw->size;
+       af9015_config.firmware_checksum = checksum;
+
+       #define FW_PACKET_MAX_DATA  55
+
+       packets = fw->size / FW_PACKET_MAX_DATA;
+       remainder = fw->size % FW_PACKET_MAX_DATA;
+       len = FW_PACKET_MAX_DATA;
+       for (i = 0; i <= packets; i++) {
+               if (i == packets)  /* set size of the last packet */
+                       len = remainder;
+
+               req.data_len = len;
+               req.data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
+               req.addr = addr;
+               addr += FW_PACKET_MAX_DATA;
+
+               ret = af9015_rw_udev(udev, &req);
+               if (ret) {
+                       err("firmware download failed at packet %d with " \
+                               "code %d", i, ret);
+                       goto error;
+               }
+       }
+
+       /* firmware loaded, request boot */
+       req.cmd = BOOT;
+       ret = af9015_rw_udev(udev, &req);
+       if (ret) {
+               err("firmware boot failed:%d", ret);
+               goto error;
+       }
+
+       /* firmware is running, reconnect device in the usb bus */
+       req.cmd = RECONNECT_USB;
+       ret = af9015_rw_udev(udev, &req);
+       if (ret)
+               err("reconnect failed: %d", ret);
+
+error:
+       return ret;
+}
+
+static int af9015_read_config(struct usb_device *udev)
+{
+       int ret;
+       u8 val, i, offset = 0;
+       struct req_t req = {READ_I2C, AF9015_I2C_EEPROM, 0, 0, 1, 1, &val};
+       char manufacturer[10];
+
+       /* IR remote controller */
+       req.addr = AF9015_EEPROM_IR_MODE;
+       ret = af9015_rw_udev(udev, &req);
+       if (ret)
+               goto error;
+       deb_info("%s: IR mode:%d\n", __func__, val);
+       for (i = 0; i < af9015_properties_count; i++) {
+               if (val == AF9015_IR_MODE_DISABLED || val == 0x04) {
+                       af9015_properties[i].rc_key_map = NULL;
+                       af9015_properties[i].rc_key_map_size  = 0;
+               } else if (dvb_usb_af9015_remote) {
+                       /* load remote defined as module param */
+                       switch (dvb_usb_af9015_remote) {
+                       case AF9015_REMOTE_A_LINK_DTU_M:
+                               af9015_properties[i].rc_key_map =
+                                 af9015_rc_keys_a_link;
+                               af9015_properties[i].rc_key_map_size =
+                                 ARRAY_SIZE(af9015_rc_keys_a_link);
+                               af9015_config.ir_table = af9015_ir_table_a_link;
+                               af9015_config.ir_table_size =
+                                 ARRAY_SIZE(af9015_ir_table_a_link);
+                               break;
+                       case AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3:
+                               af9015_properties[i].rc_key_map =
+                                 af9015_rc_keys_msi;
+                               af9015_properties[i].rc_key_map_size =
+                                 ARRAY_SIZE(af9015_rc_keys_msi);
+                               af9015_config.ir_table = af9015_ir_table_msi;
+                               af9015_config.ir_table_size =
+                                 ARRAY_SIZE(af9015_ir_table_msi);
+                               break;
+                       case AF9015_REMOTE_MYGICTV_U718:
+                               af9015_properties[i].rc_key_map =
+                                 af9015_rc_keys_mygictv;
+                               af9015_properties[i].rc_key_map_size =
+                                 ARRAY_SIZE(af9015_rc_keys_mygictv);
+                               af9015_config.ir_table =
+                                 af9015_ir_table_mygictv;
+                               af9015_config.ir_table_size =
+                                 ARRAY_SIZE(af9015_ir_table_mygictv);
+                               break;
+                       }
+               } else {
+                       switch (udev->descriptor.idVendor) {
+                       case USB_VID_LEADTEK:
+                               af9015_properties[i].rc_key_map =
+                                 af9015_rc_keys_leadtek;
+                               af9015_properties[i].rc_key_map_size =
+                                 ARRAY_SIZE(af9015_rc_keys_leadtek);
+                               af9015_config.ir_table =
+                                 af9015_ir_table_leadtek;
+                               af9015_config.ir_table_size =
+                                 ARRAY_SIZE(af9015_ir_table_leadtek);
+                               break;
+                       case USB_VID_VISIONPLUS:
+                               if (udev->descriptor.idProduct ==
+                               USB_PID_AZUREWAVE_AD_TU700) {
+                                       af9015_properties[i].rc_key_map =
+                                         af9015_rc_keys_twinhan;
+                                       af9015_properties[i].rc_key_map_size =
+                                         ARRAY_SIZE(af9015_rc_keys_twinhan);
+                                       af9015_config.ir_table =
+                                         af9015_ir_table_twinhan;
+                                       af9015_config.ir_table_size =
+                                         ARRAY_SIZE(af9015_ir_table_twinhan);
+                               }
+                               break;
+                       case USB_VID_KWORLD_2:
+                               /* TODO: use correct rc keys */
+                               af9015_properties[i].rc_key_map =
+                                 af9015_rc_keys_twinhan;
+                               af9015_properties[i].rc_key_map_size =
+                                 ARRAY_SIZE(af9015_rc_keys_twinhan);
+                               af9015_config.ir_table = af9015_ir_table_kworld;
+                               af9015_config.ir_table_size =
+                                 ARRAY_SIZE(af9015_ir_table_kworld);
+                               break;
+                       /* Check USB manufacturer and product strings and try
+                          to determine correct remote in case of chip vendor
+                          reference IDs are used. */
+                       case USB_VID_AFATECH:
+                               memset(manufacturer, 0, sizeof(manufacturer));
+                               usb_string(udev, udev->descriptor.iManufacturer,
+                                       manufacturer, sizeof(manufacturer));
+                               if (!strcmp("Geniatech", manufacturer)) {
+                                       /* iManufacturer 1 Geniatech
+                                          iProduct      2 AF9015 */
+                                       af9015_properties[i].rc_key_map =
+                                         af9015_rc_keys_mygictv;
+                                       af9015_properties[i].rc_key_map_size =
+                                         ARRAY_SIZE(af9015_rc_keys_mygictv);
+                                       af9015_config.ir_table =
+                                         af9015_ir_table_mygictv;
+                                       af9015_config.ir_table_size =
+                                         ARRAY_SIZE(af9015_ir_table_mygictv);
+                               } else if (!strcmp("MSI", manufacturer)) {
+                                       /* iManufacturer 1 MSI
+                                          iProduct      2 MSI K-VOX */
+                                       af9015_properties[i].rc_key_map =
+                                         af9015_rc_keys_msi;
+                                       af9015_properties[i].rc_key_map_size =
+                                         ARRAY_SIZE(af9015_rc_keys_msi);
+                                       af9015_config.ir_table =
+                                         af9015_ir_table_msi;
+                                       af9015_config.ir_table_size =
+                                         ARRAY_SIZE(af9015_ir_table_msi);
+                               }
+                               break;
+                       }
+               }
+       }
+
+       /* TS mode - one or two receivers */
+       req.addr = AF9015_EEPROM_TS_MODE;
+       ret = af9015_rw_udev(udev, &req);
+       if (ret)
+               goto error;
+       af9015_config.dual_mode = val;
+       deb_info("%s: TS mode:%d\n", __func__, af9015_config.dual_mode);
+       /* disable dual mode by default because it is buggy */
+       if (!dvb_usb_af9015_dual_mode)
+               af9015_config.dual_mode = 0;
+
+       /* set buffer size according to USB port speed */
+       for (i = 0; i < af9015_properties_count; i++) {
+               /* USB1.1 set smaller buffersize and disable 2nd adapter */
+               if (udev->speed == USB_SPEED_FULL) {
+                       af9015_properties[i].adapter->stream.u.bulk.buffersize =
+                               TS_USB11_MAX_PACKET_SIZE;
+                       /* disable 2nd adapter because we don't have
+                          PID-filters */
+                       af9015_config.dual_mode = 0;
+               } else {
+                       af9015_properties[i].adapter->stream.u.bulk.buffersize =
+                               TS_USB20_MAX_PACKET_SIZE;
+               }
+       }
+
+       if (af9015_config.dual_mode) {
+               /* read 2nd demodulator I2C address */
+               req.addr = AF9015_EEPROM_DEMOD2_I2C;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               af9015_af9013_config[1].demod_address = val;
+
+               /* enable 2nd adapter */
+               for (i = 0; i < af9015_properties_count; i++)
+                       af9015_properties[i].num_adapters = 2;
+
+       } else {
+                /* disable 2nd adapter */
+               for (i = 0; i < af9015_properties_count; i++)
+                       af9015_properties[i].num_adapters = 1;
+       }
+
+       for (i = 0; i < af9015_properties[0].num_adapters; i++) {
+               if (i == 1)
+                       offset = AF9015_EEPROM_OFFSET;
+               /* xtal */
+               req.addr = AF9015_EEPROM_XTAL_TYPE1 + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               switch (val) {
+               case 0:
+                       af9015_af9013_config[i].adc_clock = 28800;
+                       break;
+               case 1:
+                       af9015_af9013_config[i].adc_clock = 20480;
+                       break;
+               case 2:
+                       af9015_af9013_config[i].adc_clock = 28000;
+                       break;
+               case 3:
+                       af9015_af9013_config[i].adc_clock = 25000;
+                       break;
+               };
+               deb_info("%s: [%d] xtal:%d set adc_clock:%d\n", __func__, i,
+                       val, af9015_af9013_config[i].adc_clock);
+
+               /* tuner IF */
+               req.addr = AF9015_EEPROM_IF1H + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               af9015_af9013_config[i].tuner_if = val << 8;
+               req.addr = AF9015_EEPROM_IF1L + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               af9015_af9013_config[i].tuner_if += val;
+               deb_info("%s: [%d] IF1:%d\n", __func__, i,
+                       af9015_af9013_config[0].tuner_if);
+
+               /* MT2060 IF1 */
+               req.addr = AF9015_EEPROM_MT2060_IF1H  + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               af9015_config.mt2060_if1[i] = val << 8;
+               req.addr = AF9015_EEPROM_MT2060_IF1L + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               af9015_config.mt2060_if1[i] += val;
+               deb_info("%s: [%d] MT2060 IF1:%d\n", __func__, i,
+                       af9015_config.mt2060_if1[i]);
+
+               /* tuner */
+               req.addr =  AF9015_EEPROM_TUNER_ID1 + offset;
+               ret = af9015_rw_udev(udev, &req);
+               if (ret)
+                       goto error;
+               switch (val) {
+               case AF9013_TUNER_ENV77H11D5:
+               case AF9013_TUNER_MT2060:
+               case AF9013_TUNER_MC44S803:
+               case AF9013_TUNER_QT1010:
+               case AF9013_TUNER_UNKNOWN:
+               case AF9013_TUNER_MT2060_2:
+               case AF9013_TUNER_TDA18271:
+               case AF9013_TUNER_QT1010A:
+                       af9015_af9013_config[i].rf_spec_inv = 1;
+                       break;
+               case AF9013_TUNER_MXL5003D:
+               case AF9013_TUNER_MXL5005D:
+               case AF9013_TUNER_MXL5005R:
+                       af9015_af9013_config[i].rf_spec_inv = 0;
+                       break;
+               default:
+                       warn("tuner id:%d not supported, please report!", val);
+                       return -ENODEV;
+               };
+
+               af9015_af9013_config[i].tuner = val;
+               deb_info("%s: [%d] tuner id:%d\n", __func__, i, val);
+       }
+
+error:
+       if (ret)
+               err("eeprom read failed:%d", ret);
+
+       return ret;
+}
+
+static int af9015_identify_state(struct usb_device *udev,
+                                struct dvb_usb_device_properties *props,
+                                struct dvb_usb_device_description **desc,
+                                int *cold)
+{
+       int ret;
+       u8 reply;
+       struct req_t req = {GET_CONFIG, 0, 0, 0, 0, 1, &reply};
+
+       ret = af9015_rw_udev(udev, &req);
+       if (ret)
+               return ret;
+
+       deb_info("%s: reply:%02x\n", __func__, reply);
+       if (reply == 0x02)
+               *cold = 0;
+       else
+               *cold = 1;
+
+       return ret;
+}
+
+static int af9015_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+       u8 buf[8];
+       struct req_t req = {GET_IR_CODE, 0, 0, 0, 0, sizeof(buf), buf};
+       struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
+       int i, ret;
+
+       memset(buf, 0, sizeof(buf));
+
+       ret = af9015_ctrl_msg(d, &req);
+       if (ret)
+               return ret;
+
+       *event = 0;
+       *state = REMOTE_NO_KEY_PRESSED;
+
+       for (i = 0; i < d->props.rc_key_map_size; i++) {
+               if (!buf[1] && keymap[i].custom == buf[0] &&
+                   keymap[i].data == buf[2]) {
+                       *event = keymap[i].event;
+                       *state = REMOTE_KEY_PRESSED;
+                       break;
+               }
+       }
+       if (!buf[1])
+               deb_rc("%s: %02x %02x %02x %02x %02x %02x %02x %02x\n",
+                       __func__, buf[0], buf[1], buf[2], buf[3], buf[4],
+                       buf[5], buf[6], buf[7]);
+
+       return 0;
+}
+
+/* init 2nd I2C adapter */
+int af9015_i2c_init(struct dvb_usb_device *d)
+{
+       int ret;
+       struct af9015_state *state = d->priv;
+       deb_info("%s:\n", __func__);
+
+       strncpy(state->i2c_adap.name, d->desc->name,
+               sizeof(state->i2c_adap.name));
+#ifdef I2C_ADAP_CLASS_TV_DIGITAL
+       state->i2c_adap.class = I2C_ADAP_CLASS_TV_DIGITAL,
+#else
+       state->i2c_adap.class = I2C_CLASS_TV_DIGITAL,
+#endif
+       state->i2c_adap.algo      = d->props.i2c_algo;
+       state->i2c_adap.algo_data = NULL;
+       state->i2c_adap.dev.parent = &d->udev->dev;
+
+       i2c_set_adapdata(&state->i2c_adap, d);
+
+       ret = i2c_add_adapter(&state->i2c_adap);
+       if (ret < 0)
+               err("could not add i2c adapter");
+
+       return ret;
+}
+
+static int af9015_af9013_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       int ret;
+       struct af9015_state *state = adap->dev->priv;
+       struct i2c_adapter *i2c_adap;
+
+       if (adap->id == 0) {
+               /* select I2C adapter */
+               i2c_adap = &adap->dev->i2c_adap;
+
+               deb_info("%s: init I2C\n", __func__);
+               ret = af9015_i2c_init(adap->dev);
+
+               /* dump eeprom (debug) */
+               ret = af9015_eeprom_dump(adap->dev);
+               if (ret)
+                       return ret;
+       } else {
+               /* select I2C adapter */
+               i2c_adap = &state->i2c_adap;
+
+               /* copy firmware to 2nd demodulator */
+               if (af9015_config.dual_mode) {
+                       ret = af9015_copy_firmware(adap->dev);
+                       if (ret) {
+                               err("firmware copy to 2nd frontend " \
+                                       "failed, will disable it");
+                               af9015_config.dual_mode = 0;
+                               return -ENODEV;
+                       }
+               } else {
+                       return -ENODEV;
+               }
+       }
+
+       /* attach demodulator */
+       adap->fe = dvb_attach(af9013_attach, &af9015_af9013_config[adap->id],
+               i2c_adap);
+
+       return adap->fe == NULL ? -ENODEV : 0;
+}
+
+static struct mt2060_config af9015_mt2060_config = {
+       .i2c_address = 0xc0,
+       .clock_out = 0,
+};
+
+static struct qt1010_config af9015_qt1010_config = {
+       .i2c_address = 0xc4,
+};
+
+static struct tda18271_config af9015_tda18271_config = {
+       .gate = TDA18271_GATE_DIGITAL,
+       .small_i2c = 1,
+};
+
+static struct mxl5005s_config af9015_mxl5003_config = {
+       .i2c_address     = 0xc6,
+       .if_freq         = IF_FREQ_4570000HZ,
+       .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
+       .agc_mode        = MXL_SINGLE_AGC,
+       .tracking_filter = MXL_TF_DEFAULT,
+       .rssi_enable     = MXL_RSSI_ENABLE,
+       .cap_select      = MXL_CAP_SEL_ENABLE,
+       .div_out         = MXL_DIV_OUT_4,
+       .clock_out       = MXL_CLOCK_OUT_DISABLE,
+       .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
+       .top             = MXL5005S_TOP_25P2,
+       .mod_mode        = MXL_DIGITAL_MODE,
+       .if_mode         = MXL_ZERO_IF,
+       .AgcMasterByte   = 0x00,
+};
+
+static struct mxl5005s_config af9015_mxl5005_config = {
+       .i2c_address     = 0xc6,
+       .if_freq         = IF_FREQ_4570000HZ,
+       .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
+       .agc_mode        = MXL_SINGLE_AGC,
+       .tracking_filter = MXL_TF_OFF,
+       .rssi_enable     = MXL_RSSI_ENABLE,
+       .cap_select      = MXL_CAP_SEL_ENABLE,
+       .div_out         = MXL_DIV_OUT_4,
+       .clock_out       = MXL_CLOCK_OUT_DISABLE,
+       .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
+       .top             = MXL5005S_TOP_25P2,
+       .mod_mode        = MXL_DIGITAL_MODE,
+       .if_mode         = MXL_ZERO_IF,
+       .AgcMasterByte   = 0x00,
+};
+
+static int af9015_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       struct af9015_state *state = adap->dev->priv;
+       struct i2c_adapter *i2c_adap;
+       int ret;
+       deb_info("%s: \n", __func__);
+
+       /* select I2C adapter */
+       if (adap->id == 0)
+               i2c_adap = &adap->dev->i2c_adap;
+       else
+               i2c_adap = &state->i2c_adap;
+
+       switch (af9015_af9013_config[adap->id].tuner) {
+       case AF9013_TUNER_MT2060:
+       case AF9013_TUNER_MT2060_2:
+               ret = dvb_attach(mt2060_attach, adap->fe, i2c_adap,
+                       &af9015_mt2060_config,
+                       af9015_config.mt2060_if1[adap->id])
+                       == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_QT1010:
+       case AF9013_TUNER_QT1010A:
+               ret = dvb_attach(qt1010_attach, adap->fe, i2c_adap,
+                       &af9015_qt1010_config) == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_TDA18271:
+               ret = dvb_attach(tda18271_attach, adap->fe, 0xc0, i2c_adap,
+                       &af9015_tda18271_config) == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_MXL5003D:
+               ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
+                       &af9015_mxl5003_config) == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_MXL5005D:
+       case AF9013_TUNER_MXL5005R:
+               ret = dvb_attach(mxl5005s_attach, adap->fe, i2c_adap,
+                       &af9015_mxl5005_config) == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_ENV77H11D5:
+               ret = dvb_attach(dvb_pll_attach, adap->fe, 0xc0, i2c_adap,
+                       DVB_PLL_TDA665X) == NULL ? -ENODEV : 0;
+               break;
+       case AF9013_TUNER_MC44S803:
+#if 0
+               ret = dvb_attach(mc44s80x_attach, adap->fe, i2c_adap)
+                       == NULL ? -ENODEV : 0;
+#else
+               ret = -ENODEV;
+               info("Freescale MC44S803 tuner found but no driver for that" \
+                       "tuner. Look at the Linuxtv.org for tuner driver" \
+                       "status.");
+#endif
+               break;
+       case AF9013_TUNER_UNKNOWN:
+       default:
+               ret = -ENODEV;
+               err("Unknown tuner id:%d",
+                       af9015_af9013_config[adap->id].tuner);
+       }
+       return ret;
+}
+
+static struct usb_device_id af9015_usb_table[] = {
+/*  0 */{USB_DEVICE(USB_VID_AFATECH,   USB_PID_AFATECH_AF9015_9015)},
+       {USB_DEVICE(USB_VID_AFATECH,   USB_PID_AFATECH_AF9015_9016)},
+       {USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_GOLD)},
+       {USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV71E)},
+       {USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_KWORLD_399U)},
+/*  5 */{USB_DEVICE(USB_VID_VISIONPLUS,
+               USB_PID_TINYTWIN)},
+       {USB_DEVICE(USB_VID_VISIONPLUS,
+               USB_PID_AZUREWAVE_AD_TU700)},
+       {USB_DEVICE(USB_VID_TERRATEC,  USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2)},
+       {USB_DEVICE(USB_VID_KWORLD_2,  USB_PID_KWORLD_PC160_2T)},
+       {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X)},
+/* 10 */{USB_DEVICE(USB_VID_XTENSIONS, USB_PID_XTENSIONS_XD_380)},
+       {USB_DEVICE(USB_VID_MSI_2,     USB_PID_MSI_DIGIVOX_DUO)},
+       {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_X_2)},
+       {USB_DEVICE(USB_VID_TELESTAR,  USB_PID_TELESTAR_STARSTICK_2)},
+       {USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_A309)},
+/* 15 */{USB_DEVICE(USB_VID_MSI_2,     USB_PID_MSI_DIGI_VOX_MINI_III)},
+       {0},
+};
+MODULE_DEVICE_TABLE(usb, af9015_usb_table);
+
+static struct dvb_usb_device_properties af9015_properties[] = {
+       {
+               .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+               .usb_ctrl = DEVICE_SPECIFIC,
+               .download_firmware = af9015_download_firmware,
+               .firmware = "dvb-usb-af9015.fw",
+
+               .size_of_priv = sizeof(struct af9015_state), \
+
+               .num_adapters = 2,
+               .adapter = {
+                       {
+                               .caps = DVB_USB_ADAP_HAS_PID_FILTER |
+                               DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
+
+                               .pid_filter_count = 32,
+                               .pid_filter       = af9015_pid_filter,
+                               .pid_filter_ctrl  = af9015_pid_filter_ctrl,
+
+                               .frontend_attach =
+                                       af9015_af9013_frontend_attach,
+                               .tuner_attach    = af9015_tuner_attach,
+                               .stream = {
+                                       .type = USB_BULK,
+                                       .count = 6,
+                                       .endpoint = 0x84,
+                               },
+                       },
+                       {
+                               .frontend_attach =
+                                       af9015_af9013_frontend_attach,
+                               .tuner_attach    = af9015_tuner_attach,
+                               .stream = {
+                                       .type = USB_BULK,
+                                       .count = 6,
+                                       .endpoint = 0x85,
+                               },
+                       }
+               },
+
+               .identify_state = af9015_identify_state,
+
+               .rc_query         = af9015_rc_query,
+               .rc_interval      = 150,
+
+               .i2c_algo = &af9015_i2c_algo,
+
+               .num_device_descs = 9,
+               .devices = {
+                       {
+                               .name = "Afatech AF9015 DVB-T USB2.0 stick",
+                               .cold_ids = {&af9015_usb_table[0],
+                                            &af9015_usb_table[1], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "Leadtek WinFast DTV Dongle Gold",
+                               .cold_ids = {&af9015_usb_table[2], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "Pinnacle PCTV 71e",
+                               .cold_ids = {&af9015_usb_table[3], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "KWorld PlusTV Dual DVB-T Stick " \
+                                       "(DVB-T 399U)",
+                               .cold_ids = {&af9015_usb_table[4], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "DigitalNow TinyTwin DVB-T Receiver",
+                               .cold_ids = {&af9015_usb_table[5], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "TwinHan AzureWave AD-TU700(704J)",
+                               .cold_ids = {&af9015_usb_table[6], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "TerraTec Cinergy T USB XE",
+                               .cold_ids = {&af9015_usb_table[7], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "KWorld PlusTV Dual DVB-T PCI " \
+                                       "(DVB-T PC160-2T)",
+                               .cold_ids = {&af9015_usb_table[8], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "AVerMedia AVerTV DVB-T Volar X",
+                               .cold_ids = {&af9015_usb_table[9], NULL},
+                               .warm_ids = {NULL},
+                       },
+               }
+       }, {
+               .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+               .usb_ctrl = DEVICE_SPECIFIC,
+               .download_firmware = af9015_download_firmware,
+               .firmware = "dvb-usb-af9015.fw",
+
+               .size_of_priv = sizeof(struct af9015_state), \
+
+               .num_adapters = 2,
+               .adapter = {
+                       {
+                               .caps = DVB_USB_ADAP_HAS_PID_FILTER |
+                               DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
+
+                               .pid_filter_count = 32,
+                               .pid_filter       = af9015_pid_filter,
+                               .pid_filter_ctrl  = af9015_pid_filter_ctrl,
+
+                               .frontend_attach =
+                                       af9015_af9013_frontend_attach,
+                               .tuner_attach    = af9015_tuner_attach,
+                               .stream = {
+                                       .type = USB_BULK,
+                                       .count = 6,
+                                       .endpoint = 0x84,
+                               },
+                       },
+                       {
+                               .frontend_attach =
+                                       af9015_af9013_frontend_attach,
+                               .tuner_attach    = af9015_tuner_attach,
+                               .stream = {
+                                       .type = USB_BULK,
+                                       .count = 6,
+                                       .endpoint = 0x85,
+                               },
+                       }
+               },
+
+               .identify_state = af9015_identify_state,
+
+               .rc_query         = af9015_rc_query,
+               .rc_interval      = 150,
+
+               .i2c_algo = &af9015_i2c_algo,
+
+               .num_device_descs = 6,
+               .devices = {
+                       {
+                               .name = "Xtensions XD-380",
+                               .cold_ids = {&af9015_usb_table[10], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "MSI DIGIVOX Duo",
+                               .cold_ids = {&af9015_usb_table[11], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "Fujitsu-Siemens Slim Mobile USB DVB-T",
+                               .cold_ids = {&af9015_usb_table[12], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "Telestar Starstick 2",
+                               .cold_ids = {&af9015_usb_table[13], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "AVerMedia A309",
+                               .cold_ids = {&af9015_usb_table[14], NULL},
+                               .warm_ids = {NULL},
+                       },
+                       {
+                               .name = "MSI Digi VOX mini III",
+                               .cold_ids = {&af9015_usb_table[15], NULL},
+                               .warm_ids = {NULL},
+                       },
+               }
+       }
+};
+
+static int af9015_usb_probe(struct usb_interface *intf,
+                           const struct usb_device_id *id)
+{
+       int ret = 0;
+       struct dvb_usb_device *d = NULL;
+       struct usb_device *udev = interface_to_usbdev(intf);
+       u8 i;
+
+       deb_info("%s: interface:%d\n", __func__,
+               intf->cur_altsetting->desc.bInterfaceNumber);
+
+       /* interface 0 is used by DVB-T receiver and
+          interface 1 is for remote controller (HID) */
+       if (intf->cur_altsetting->desc.bInterfaceNumber == 0) {
+               ret = af9015_read_config(udev);
+               if (ret)
+                       return ret;
+
+               for (i = 0; i < af9015_properties_count; i++) {
+                       ret = dvb_usb_device_init(intf, &af9015_properties[i],
+                               THIS_MODULE, &d, adapter_nr);
+                       if (!ret)
+                               break;
+                       if (ret != -ENODEV)
+                               return ret;
+               }
+               if (ret)
+                       return ret;
+
+               if (d)
+                       ret = af9015_init(d);
+       }
+
+       return ret;
+}
+
+void af9015_i2c_exit(struct dvb_usb_device *d)
+{
+       struct af9015_state *state = d->priv;
+       deb_info("%s: \n", __func__);
+
+       /* remove 2nd I2C adapter */
+       if (d->state & DVB_USB_STATE_I2C)
+               i2c_del_adapter(&state->i2c_adap);
+}
+
+static void af9015_usb_device_exit(struct usb_interface *intf)
+{
+       struct dvb_usb_device *d = usb_get_intfdata(intf);
+       deb_info("%s: \n", __func__);
+
+       /* remove 2nd I2C adapter */
+       if (d != NULL && d->desc != NULL)
+               af9015_i2c_exit(d);
+
+       dvb_usb_device_exit(intf);
+}
+
+/* usb specific object needed to register this driver with the usb subsystem */
+static struct usb_driver af9015_usb_driver = {
+       .name = "dvb_usb_af9015",
+       .probe = af9015_usb_probe,
+       .disconnect = af9015_usb_device_exit,
+       .id_table = af9015_usb_table,
+};
+
+/* module stuff */
+static int __init af9015_usb_module_init(void)
+{
+       int ret;
+       ret = usb_register(&af9015_usb_driver);
+       if (ret)
+               err("module init failed:%d", ret);
+
+       return ret;
+}
+
+static void __exit af9015_usb_module_exit(void)
+{
+       /* deregister this driver from the USB subsystem */
+       usb_deregister(&af9015_usb_driver);
+}
+
+module_init(af9015_usb_module_init);
+module_exit(af9015_usb_module_exit);
+
+MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
+MODULE_DESCRIPTION("Driver for Afatech AF9015 DVB-T");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/af9015.h b/drivers/media/dvb/dvb-usb/af9015.h
new file mode 100644 (file)
index 0000000..882e8a4
--- /dev/null
@@ -0,0 +1,524 @@
+/*
+ * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
+ *
+ * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
+ *
+ * Thanks to Afatech who kindly provided information.
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _DVB_USB_AF9015_H_
+#define _DVB_USB_AF9015_H_
+
+#define DVB_USB_LOG_PREFIX "af9015"
+#include "dvb-usb.h"
+
+extern int dvb_usb_af9015_debug;
+#define deb_info(args...) dprintk(dvb_usb_af9015_debug, 0x01, args)
+#define deb_rc(args...)   dprintk(dvb_usb_af9015_debug, 0x02, args)
+#define deb_xfer(args...) dprintk(dvb_usb_af9015_debug, 0x04, args)
+#define deb_reg(args...)  dprintk(dvb_usb_af9015_debug, 0x08, args)
+#define deb_i2c(args...)  dprintk(dvb_usb_af9015_debug, 0x10, args)
+#define deb_fw(args...)   dprintk(dvb_usb_af9015_debug, 0x20, args)
+
+#define AF9015_I2C_EEPROM  0xa0
+#define AF9015_I2C_DEMOD   0x38
+#define AF9015_USB_TIMEOUT 2000
+
+/* EEPROM locations */
+#define AF9015_EEPROM_IR_MODE        0x18
+#define AF9015_EEPROM_IR_REMOTE_TYPE 0x34
+#define AF9015_EEPROM_TS_MODE        0x31
+#define AF9015_EEPROM_DEMOD2_I2C     0x32
+
+#define AF9015_EEPROM_SAW_BW1        0x35
+#define AF9015_EEPROM_XTAL_TYPE1     0x36
+#define AF9015_EEPROM_SPEC_INV1      0x37
+#define AF9015_EEPROM_IF1L           0x38
+#define AF9015_EEPROM_IF1H           0x39
+#define AF9015_EEPROM_MT2060_IF1L    0x3a
+#define AF9015_EEPROM_MT2060_IF1H    0x3b
+#define AF9015_EEPROM_TUNER_ID1      0x3c
+
+#define AF9015_EEPROM_SAW_BW2        0x45
+#define AF9015_EEPROM_XTAL_TYPE2     0x46
+#define AF9015_EEPROM_SPEC_INV2      0x47
+#define AF9015_EEPROM_IF2L           0x48
+#define AF9015_EEPROM_IF2H           0x49
+#define AF9015_EEPROM_MT2060_IF2L    0x4a
+#define AF9015_EEPROM_MT2060_IF2H    0x4b
+#define AF9015_EEPROM_TUNER_ID2      0x4c
+
+#define AF9015_EEPROM_OFFSET (AF9015_EEPROM_SAW_BW2 - AF9015_EEPROM_SAW_BW1)
+
+#define AF9015_GPIO_ON (1 << 0)
+#define AF9015_GPIO_EN (1 << 1)
+#define AF9015_GPIO_O  (1 << 2)
+#define AF9015_GPIO_I  (1 << 3)
+
+#define AF9015_GPIO_TUNER_ON  (AF9015_GPIO_ON|AF9015_GPIO_EN)
+#define AF9015_GPIO_TUNER_OFF (AF9015_GPIO_ON|AF9015_GPIO_EN|AF9015_GPIO_O)
+
+struct req_t {
+       u8  cmd;       /* [0] */
+       /*  seq */     /* [1] */
+       u8  i2c_addr;  /* [2] */
+       u16 addr;      /* [3|4] */
+       u8  mbox;      /* [5] */
+       u8  addr_len;  /* [6] */
+       u8  data_len;  /* [7] */
+       u8  *data;
+};
+
+enum af9015_cmd {
+       GET_CONFIG           = 0x10,
+       DOWNLOAD_FIRMWARE    = 0x11,
+       BOOT                 = 0x13,
+       READ_MEMORY          = 0x20,
+       WRITE_MEMORY         = 0x21,
+       READ_WRITE_I2C       = 0x22,
+       COPY_FIRMWARE        = 0x23,
+       RECONNECT_USB        = 0x5a,
+       WRITE_VIRTUAL_MEMORY = 0x26,
+       GET_IR_CODE          = 0x27,
+       READ_I2C,
+       WRITE_I2C,
+};
+
+enum af9015_ir_mode {
+       AF9015_IR_MODE_DISABLED = 0,
+       AF9015_IR_MODE_HID,
+       AF9015_IR_MODE_RLC,
+       AF9015_IR_MODE_RC6,
+};
+
+struct af9015_state {
+       struct i2c_adapter i2c_adap; /* I2C adapter for 2nd FE */
+};
+
+struct af9015_config {
+       u8  dual_mode:1;
+       u16 mt2060_if1[2];
+       u16 firmware_size;
+       u16 firmware_checksum;
+       u8  *ir_table;
+       u16 ir_table_size;
+};
+
+enum af9015_remote {
+       AF9015_REMOTE_NONE                    = 0,
+       AF9015_REMOTE_A_LINK_DTU_M,
+       AF9015_REMOTE_MSI_DIGIVOX_MINI_II_V3,
+       AF9015_REMOTE_MYGICTV_U718,
+};
+
+/* Leadtek WinFast DTV Dongle Gold */
+static struct dvb_usb_rc_key af9015_rc_keys_leadtek[] = {
+       { 0x00, 0x1e, KEY_1 },
+       { 0x00, 0x1f, KEY_2 },
+       { 0x00, 0x20, KEY_3 },
+       { 0x00, 0x21, KEY_4 },
+       { 0x00, 0x22, KEY_5 },
+       { 0x00, 0x23, KEY_6 },
+       { 0x00, 0x24, KEY_7 },
+       { 0x00, 0x25, KEY_8 },
+       { 0x00, 0x26, KEY_9 },
+       { 0x00, 0x27, KEY_0 },
+       { 0x00, 0x28, KEY_ENTER },
+       { 0x00, 0x4f, KEY_VOLUMEUP },
+       { 0x00, 0x50, KEY_VOLUMEDOWN },
+       { 0x00, 0x51, KEY_CHANNELDOWN },
+       { 0x00, 0x52, KEY_CHANNELUP },
+};
+
+static u8 af9015_ir_table_leadtek[] = {
+       0x03, 0xfc, 0x00, 0xff, 0x1a, 0x01, 0x00,
+       0x03, 0xfc, 0x56, 0xa9, 0x00, 0x00, 0x00,
+       0x03, 0xfc, 0x4b, 0xb4, 0x00, 0x00, 0x00,
+       0x03, 0xfc, 0x4c, 0xb3, 0xb2, 0x04, 0x00,
+       0x03, 0xfc, 0x4d, 0xb2, 0x00, 0x00, 0x00,
+       0x03, 0xfc, 0x4e, 0xb1, 0x00, 0x00, 0x00,
+       0x03, 0xfc, 0x1f, 0xe0, 0x3d, 0x00, 0x00,
+       0x03, 0xfc, 0x40, 0xbf, 0x13, 0x01, 0x00,
+       0x03, 0xfc, 0x14, 0xeb, 0x10, 0x00, 0x00,
+       0x03, 0xfc, 0x49, 0xb6, 0x05, 0x01, 0x00,
+       0x03, 0xfc, 0x50, 0xaf, 0x29, 0x00, 0x00,
+       0x03, 0xfc, 0x0c, 0xf3, 0x52, 0x00, 0x00,
+       0x03, 0xfc, 0x03, 0xfc, 0x09, 0x00, 0x00,
+       0x03, 0xfc, 0x08, 0xf7, 0x50, 0x00, 0x00,
+       0x03, 0xfc, 0x13, 0xec, 0x28, 0x00, 0x00,
+       0x03, 0xfc, 0x04, 0xfb, 0x4f, 0x00, 0x00,
+       0x03, 0xfc, 0x4f, 0xb0, 0x0f, 0x01, 0x00,
+       0x03, 0xfc, 0x10, 0xef, 0x51, 0x00, 0x00,
+       0x03, 0xfc, 0x51, 0xae, 0x3f, 0x00, 0x00,
+       0x03, 0xfc, 0x42, 0xbd, 0x13, 0x00, 0x00,
+       0x03, 0xfc, 0x43, 0xbc, 0x00, 0x00, 0x00,
+       0x03, 0xfc, 0x44, 0xbb, 0x11, 0x00, 0x00,
+       0x03, 0xfc, 0x52, 0xad, 0x19, 0x00, 0x00,
+       0x03, 0xfc, 0x54, 0xab, 0x05, 0x00, 0x00,
+       0x03, 0xfc, 0x46, 0xb9, 0x29, 0x00, 0x00,
+       0x03, 0xfc, 0x55, 0xaa, 0x2b, 0x00, 0x00,
+       0x03, 0xfc, 0x53, 0xac, 0x41, 0x00, 0x00,
+       0x03, 0xfc, 0x05, 0xfa, 0x1e, 0x00, 0x00,
+       0x03, 0xfc, 0x06, 0xf9, 0x1f, 0x00, 0x00,
+       0x03, 0xfc, 0x07, 0xf8, 0x20, 0x00, 0x00,
+       0x03, 0xfc, 0x1e, 0xe1, 0x19, 0x00, 0x00,
+       0x03, 0xfc, 0x09, 0xf6, 0x21, 0x00, 0x00,
+       0x03, 0xfc, 0x0a, 0xf5, 0x22, 0x00, 0x00,
+       0x03, 0xfc, 0x0b, 0xf4, 0x23, 0x00, 0x00,
+       0x03, 0xfc, 0x1b, 0xe4, 0x16, 0x00, 0x00,
+       0x03, 0xfc, 0x0d, 0xf2, 0x24, 0x00, 0x00,
+       0x03, 0xfc, 0x0e, 0xf1, 0x25, 0x00, 0x00,
+       0x03, 0xfc, 0x0f, 0xf0, 0x26, 0x00, 0x00,
+       0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00,
+       0x03, 0xfc, 0x41, 0xbe, 0x37, 0x00, 0x00,
+       0x03, 0xfc, 0x12, 0xed, 0x27, 0x00, 0x00,
+       0x03, 0xfc, 0x11, 0xee, 0x2a, 0x00, 0x00,
+       0x03, 0xfc, 0x48, 0xb7, 0x2c, 0x00, 0x00,
+       0x03, 0xfc, 0x4a, 0xb5, 0x3c, 0x00, 0x00,
+       0x03, 0xfc, 0x47, 0xb8, 0x15, 0x01, 0x00,
+       0x03, 0xfc, 0x45, 0xba, 0x0b, 0x01, 0x00,
+       0x03, 0xfc, 0x5e, 0xa1, 0x43, 0x00, 0x00,
+       0x03, 0xfc, 0x5a, 0xa5, 0x42, 0x00, 0x00,
+       0x03, 0xfc, 0x5b, 0xa4, 0x4b, 0x00, 0x00,
+       0x03, 0xfc, 0x5f, 0xa0, 0x4e, 0x00, 0x00,
+};
+
+/* TwinHan AzureWave AD-TU700(704J) */
+static struct dvb_usb_rc_key af9015_rc_keys_twinhan[] = {
+       { 0x05, 0x3f, KEY_POWER },
+       { 0x00, 0x19, KEY_FAVORITES },    /* Favorite List */
+       { 0x00, 0x04, KEY_TEXT },         /* Teletext */
+       { 0x00, 0x0e, KEY_POWER },
+       { 0x00, 0x0e, KEY_INFO },         /* Preview */
+       { 0x00, 0x08, KEY_EPG },          /* Info/EPG */
+       { 0x00, 0x0f, KEY_LIST },         /* Record List */
+       { 0x00, 0x1e, KEY_1 },
+       { 0x00, 0x1f, KEY_2 },
+       { 0x00, 0x20, KEY_3 },
+       { 0x00, 0x21, KEY_4 },
+       { 0x00, 0x22, KEY_5 },
+       { 0x00, 0x23, KEY_6 },
+       { 0x00, 0x24, KEY_7 },
+       { 0x00, 0x25, KEY_8 },
+       { 0x00, 0x26, KEY_9 },
+       { 0x00, 0x27, KEY_0 },
+       { 0x00, 0x29, KEY_CANCEL },       /* Cancel */
+       { 0x00, 0x4c, KEY_CLEAR },        /* Clear */
+       { 0x00, 0x2a, KEY_BACK },         /* Back */
+       { 0x00, 0x2b, KEY_TAB },          /* Tab */
+       { 0x00, 0x52, KEY_UP },           /* up arrow */
+       { 0x00, 0x51, KEY_DOWN },         /* down arrow */
+       { 0x00, 0x4f, KEY_RIGHT },        /* right arrow */
+       { 0x00, 0x50, KEY_LEFT },         /* left arrow */
+       { 0x00, 0x28, KEY_ENTER },        /* Enter / ok */
+       { 0x02, 0x52, KEY_VOLUMEUP },
+       { 0x02, 0x51, KEY_VOLUMEDOWN },
+       { 0x00, 0x4e, KEY_CHANNELDOWN },
+       { 0x00, 0x4b, KEY_CHANNELUP },
+       { 0x00, 0x4a, KEY_RECORD },
+       { 0x01, 0x11, KEY_PLAY },
+       { 0x00, 0x17, KEY_PAUSE },
+       { 0x00, 0x0c, KEY_REWIND },       /* FR << */
+       { 0x00, 0x11, KEY_FASTFORWARD },  /* FF >> */
+       { 0x01, 0x15, KEY_PREVIOUS },     /* Replay */
+       { 0x01, 0x0e, KEY_NEXT },         /* Skip */
+       { 0x00, 0x13, KEY_CAMERA },       /* Capture */
+       { 0x01, 0x0f, KEY_LANGUAGE },     /* SAP */
+       { 0x01, 0x13, KEY_TV2 },          /* PIP */
+       { 0x00, 0x1d, KEY_ZOOM },         /* Full Screen */
+       { 0x01, 0x17, KEY_SUBTITLE },     /* Subtitle / CC */
+       { 0x00, 0x10, KEY_MUTE },
+       { 0x01, 0x19, KEY_AUDIO },        /* L/R */ /* TODO better event */
+       { 0x01, 0x16, KEY_SLEEP },        /* Hibernate */
+       { 0x01, 0x16, KEY_SWITCHVIDEOMODE },
+                                         /* A/V */ /* TODO does not work */
+       { 0x00, 0x06, KEY_AGAIN },        /* Recall */
+       { 0x01, 0x16, KEY_KPPLUS },       /* Zoom+ */ /* TODO does not work */
+       { 0x01, 0x16, KEY_KPMINUS },      /* Zoom- */ /* TODO does not work */
+       { 0x02, 0x15, KEY_RED },
+       { 0x02, 0x0a, KEY_GREEN },
+       { 0x02, 0x1c, KEY_YELLOW },
+       { 0x02, 0x05, KEY_BLUE },
+};
+
+static u8 af9015_ir_table_twinhan[] = {
+       0x00, 0xff, 0x16, 0xe9, 0x3f, 0x05, 0x00,
+       0x00, 0xff, 0x07, 0xf8, 0x16, 0x01, 0x00,
+       0x00, 0xff, 0x14, 0xeb, 0x11, 0x01, 0x00,
+       0x00, 0xff, 0x1a, 0xe5, 0x4d, 0x00, 0x00,
+       0x00, 0xff, 0x4c, 0xb3, 0x17, 0x00, 0x00,
+       0x00, 0xff, 0x12, 0xed, 0x11, 0x00, 0x00,
+       0x00, 0xff, 0x40, 0xbf, 0x0c, 0x00, 0x00,
+       0x00, 0xff, 0x11, 0xee, 0x4a, 0x00, 0x00,
+       0x00, 0xff, 0x54, 0xab, 0x13, 0x00, 0x00,
+       0x00, 0xff, 0x41, 0xbe, 0x15, 0x01, 0x00,
+       0x00, 0xff, 0x42, 0xbd, 0x0e, 0x01, 0x00,
+       0x00, 0xff, 0x43, 0xbc, 0x17, 0x01, 0x00,
+       0x00, 0xff, 0x50, 0xaf, 0x0f, 0x01, 0x00,
+       0x00, 0xff, 0x4d, 0xb2, 0x1d, 0x00, 0x00,
+       0x00, 0xff, 0x47, 0xb8, 0x13, 0x01, 0x00,
+       0x00, 0xff, 0x05, 0xfa, 0x4b, 0x00, 0x00,
+       0x00, 0xff, 0x02, 0xfd, 0x4e, 0x00, 0x00,
+       0x00, 0xff, 0x0e, 0xf1, 0x06, 0x00, 0x00,
+       0x00, 0xff, 0x1e, 0xe1, 0x52, 0x02, 0x00,
+       0x00, 0xff, 0x0a, 0xf5, 0x51, 0x02, 0x00,
+       0x00, 0xff, 0x10, 0xef, 0x10, 0x00, 0x00,
+       0x00, 0xff, 0x49, 0xb6, 0x19, 0x01, 0x00,
+       0x00, 0xff, 0x15, 0xea, 0x27, 0x00, 0x00,
+       0x00, 0xff, 0x03, 0xfc, 0x1e, 0x00, 0x00,
+       0x00, 0xff, 0x01, 0xfe, 0x1f, 0x00, 0x00,
+       0x00, 0xff, 0x06, 0xf9, 0x20, 0x00, 0x00,
+       0x00, 0xff, 0x09, 0xf6, 0x21, 0x00, 0x00,
+       0x00, 0xff, 0x1d, 0xe2, 0x22, 0x00, 0x00,
+       0x00, 0xff, 0x1f, 0xe0, 0x23, 0x00, 0x00,
+       0x00, 0xff, 0x0d, 0xf2, 0x24, 0x00, 0x00,
+       0x00, 0xff, 0x19, 0xe6, 0x25, 0x00, 0x00,
+       0x00, 0xff, 0x1b, 0xe4, 0x26, 0x00, 0x00,
+       0x00, 0xff, 0x00, 0xff, 0x2b, 0x00, 0x00,
+       0x00, 0xff, 0x4a, 0xb5, 0x4c, 0x00, 0x00,
+       0x00, 0xff, 0x4b, 0xb4, 0x52, 0x00, 0x00,
+       0x00, 0xff, 0x51, 0xae, 0x51, 0x00, 0x00,
+       0x00, 0xff, 0x52, 0xad, 0x4f, 0x00, 0x00,
+       0x00, 0xff, 0x4e, 0xb1, 0x50, 0x00, 0x00,
+       0x00, 0xff, 0x0c, 0xf3, 0x29, 0x00, 0x00,
+       0x00, 0xff, 0x4f, 0xb0, 0x28, 0x00, 0x00,
+       0x00, 0xff, 0x13, 0xec, 0x2a, 0x00, 0x00,
+       0x00, 0xff, 0x17, 0xe8, 0x19, 0x00, 0x00,
+       0x00, 0xff, 0x04, 0xfb, 0x0f, 0x00, 0x00,
+       0x00, 0xff, 0x48, 0xb7, 0x0e, 0x00, 0x00,
+       0x00, 0xff, 0x0f, 0xf0, 0x04, 0x00, 0x00,
+       0x00, 0xff, 0x1c, 0xe3, 0x08, 0x00, 0x00,
+       0x00, 0xff, 0x18, 0xe7, 0x15, 0x02, 0x00,
+       0x00, 0xff, 0x53, 0xac, 0x0a, 0x02, 0x00,
+       0x00, 0xff, 0x5e, 0xa1, 0x1c, 0x02, 0x00,
+       0x00, 0xff, 0x5f, 0xa0, 0x05, 0x02, 0x00,
+};
+
+/* A-Link DTU(m) */
+static struct dvb_usb_rc_key af9015_rc_keys_a_link[] = {
+       { 0x00, 0x1e, KEY_1 },
+       { 0x00, 0x1f, KEY_2 },
+       { 0x00, 0x20, KEY_3 },
+       { 0x00, 0x21, KEY_4 },
+       { 0x00, 0x22, KEY_5 },
+       { 0x00, 0x23, KEY_6 },
+       { 0x00, 0x24, KEY_7 },
+       { 0x00, 0x25, KEY_8 },
+       { 0x00, 0x26, KEY_9 },
+       { 0x00, 0x27, KEY_0 },
+       { 0x00, 0x2e, KEY_CHANNELUP },
+       { 0x00, 0x2d, KEY_CHANNELDOWN },
+       { 0x04, 0x28, KEY_ZOOM },
+       { 0x00, 0x41, KEY_MUTE },
+       { 0x00, 0x42, KEY_VOLUMEDOWN },
+       { 0x00, 0x43, KEY_VOLUMEUP },
+       { 0x00, 0x44, KEY_GOTO },         /* jump */
+       { 0x05, 0x45, KEY_POWER },
+};
+
+static u8 af9015_ir_table_a_link[] = {
+       0x08, 0xf7, 0x12, 0xed, 0x45, 0x05, 0x00, /* power */
+       0x08, 0xf7, 0x1a, 0xe5, 0x41, 0x00, 0x00, /* mute */
+       0x08, 0xf7, 0x01, 0xfe, 0x1e, 0x00, 0x00, /* 1 */
+       0x08, 0xf7, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
+       0x08, 0xf7, 0x03, 0xfc, 0x24, 0x00, 0x00, /* 7 */
+       0x08, 0xf7, 0x05, 0xfa, 0x28, 0x04, 0x00, /* zoom */
+       0x08, 0xf7, 0x00, 0xff, 0x43, 0x00, 0x00, /* volume up */
+       0x08, 0xf7, 0x16, 0xe9, 0x42, 0x00, 0x00, /* volume down */
+       0x08, 0xf7, 0x0f, 0xf0, 0x1f, 0x00, 0x00, /* 2 */
+       0x08, 0xf7, 0x0d, 0xf2, 0x22, 0x00, 0x00, /* 5 */
+       0x08, 0xf7, 0x1b, 0xe4, 0x25, 0x00, 0x00, /* 8 */
+       0x08, 0xf7, 0x06, 0xf9, 0x27, 0x00, 0x00, /* 0 */
+       0x08, 0xf7, 0x14, 0xeb, 0x2e, 0x00, 0x00, /* channel up */
+       0x08, 0xf7, 0x1d, 0xe2, 0x2d, 0x00, 0x00, /* channel down */
+       0x08, 0xf7, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
+       0x08, 0xf7, 0x18, 0xe7, 0x23, 0x00, 0x00, /* 6 */
+       0x08, 0xf7, 0x04, 0xfb, 0x26, 0x00, 0x00, /* 9 */
+       0x08, 0xf7, 0x07, 0xf8, 0x44, 0x00, 0x00, /* jump */
+};
+
+/* MSI DIGIVOX mini II V3.0 */
+static struct dvb_usb_rc_key af9015_rc_keys_msi[] = {
+       { 0x00, 0x1e, KEY_1 },
+       { 0x00, 0x1f, KEY_2 },
+       { 0x00, 0x20, KEY_3 },
+       { 0x00, 0x21, KEY_4 },
+       { 0x00, 0x22, KEY_5 },
+       { 0x00, 0x23, KEY_6 },
+       { 0x00, 0x24, KEY_7 },
+       { 0x00, 0x25, KEY_8 },
+       { 0x00, 0x26, KEY_9 },
+       { 0x00, 0x27, KEY_0 },
+       { 0x03, 0x0f, KEY_CHANNELUP },
+       { 0x03, 0x0e, KEY_CHANNELDOWN },
+       { 0x00, 0x42, KEY_VOLUMEDOWN },
+       { 0x00, 0x43, KEY_VOLUMEUP },
+       { 0x05, 0x45, KEY_POWER },
+       { 0x00, 0x52, KEY_UP },           /* up */
+       { 0x00, 0x51, KEY_DOWN },         /* down */
+       { 0x00, 0x28, KEY_ENTER },
+};
+
+static u8 af9015_ir_table_msi[] = {
+       0x03, 0xfc, 0x17, 0xe8, 0x45, 0x05, 0x00, /* power */
+       0x03, 0xfc, 0x0d, 0xf2, 0x51, 0x00, 0x00, /* down */
+       0x03, 0xfc, 0x03, 0xfc, 0x52, 0x00, 0x00, /* up */
+       0x03, 0xfc, 0x1a, 0xe5, 0x1e, 0x00, 0x00, /* 1 */
+       0x03, 0xfc, 0x02, 0xfd, 0x1f, 0x00, 0x00, /* 2 */
+       0x03, 0xfc, 0x04, 0xfb, 0x20, 0x00, 0x00, /* 3 */
+       0x03, 0xfc, 0x1c, 0xe3, 0x21, 0x00, 0x00, /* 4 */
+       0x03, 0xfc, 0x08, 0xf7, 0x22, 0x00, 0x00, /* 5 */
+       0x03, 0xfc, 0x1d, 0xe2, 0x23, 0x00, 0x00, /* 6 */
+       0x03, 0xfc, 0x11, 0xee, 0x24, 0x00, 0x00, /* 7 */
+       0x03, 0xfc, 0x0b, 0xf4, 0x25, 0x00, 0x00, /* 8 */
+       0x03, 0xfc, 0x10, 0xef, 0x26, 0x00, 0x00, /* 9 */
+       0x03, 0xfc, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
+       0x03, 0xfc, 0x14, 0xeb, 0x43, 0x00, 0x00, /* volume up */
+       0x03, 0xfc, 0x1f, 0xe0, 0x42, 0x00, 0x00, /* volume down */
+       0x03, 0xfc, 0x15, 0xea, 0x0f, 0x03, 0x00, /* channel up */
+       0x03, 0xfc, 0x05, 0xfa, 0x0e, 0x03, 0x00, /* channel down */
+       0x03, 0xfc, 0x16, 0xe9, 0x28, 0x00, 0x00, /* enter */
+};
+
+/* MYGICTV U718 */
+static struct dvb_usb_rc_key af9015_rc_keys_mygictv[] = {
+       { 0x00, 0x3d, KEY_SWITCHVIDEOMODE },
+                                         /* TV / AV */
+       { 0x05, 0x45, KEY_POWER },
+       { 0x00, 0x1e, KEY_1 },
+       { 0x00, 0x1f, KEY_2 },
+       { 0x00, 0x20, KEY_3 },
+       { 0x00, 0x21, KEY_4 },
+       { 0x00, 0x22, KEY_5 },
+       { 0x00, 0x23, KEY_6 },
+       { 0x00, 0x24, KEY_7 },
+       { 0x00, 0x25, KEY_8 },
+       { 0x00, 0x26, KEY_9 },
+       { 0x00, 0x27, KEY_0 },
+       { 0x00, 0x41, KEY_MUTE },
+       { 0x00, 0x2a, KEY_ESC },          /* Esc */
+       { 0x00, 0x2e, KEY_CHANNELUP },
+       { 0x00, 0x2d, KEY_CHANNELDOWN },
+       { 0x00, 0x42, KEY_VOLUMEDOWN },
+       { 0x00, 0x43, KEY_VOLUMEUP },
+       { 0x00, 0x52, KEY_UP },           /* up arrow */
+       { 0x00, 0x51, KEY_DOWN },         /* down arrow */
+       { 0x00, 0x4f, KEY_RIGHT },        /* right arrow */
+       { 0x00, 0x50, KEY_LEFT },         /* left arrow */
+       { 0x00, 0x28, KEY_ENTER },        /* ok */
+       { 0x01, 0x15, KEY_RECORD },
+       { 0x03, 0x13, KEY_PLAY },
+       { 0x01, 0x13, KEY_PAUSE },
+       { 0x01, 0x16, KEY_STOP },
+       { 0x03, 0x07, KEY_REWIND },       /* FR << */
+       { 0x03, 0x09, KEY_FASTFORWARD },  /* FF >> */
+       { 0x00, 0x3b, KEY_TIME },         /* TimeShift */
+       { 0x00, 0x3e, KEY_CAMERA },       /* Snapshot */
+       { 0x03, 0x16, KEY_CYCLEWINDOWS }, /* yellow, min / max */
+       { 0x00, 0x00, KEY_ZOOM },         /* 'select' (?) */
+       { 0x03, 0x16, KEY_SHUFFLE },      /* Shuffle */
+       { 0x03, 0x45, KEY_POWER },
+};
+
+static u8 af9015_ir_table_mygictv[] = {
+       0x02, 0xbd, 0x0c, 0xf3, 0x3d, 0x00, 0x00, /* TV / AV */
+       0x02, 0xbd, 0x14, 0xeb, 0x45, 0x05, 0x00, /* power */
+       0x02, 0xbd, 0x00, 0xff, 0x1e, 0x00, 0x00, /* 1 */
+       0x02, 0xbd, 0x01, 0xfe, 0x1f, 0x00, 0x00, /* 2 */
+       0x02, 0xbd, 0x02, 0xfd, 0x20, 0x00, 0x00, /* 3 */
+       0x02, 0xbd, 0x03, 0xfc, 0x21, 0x00, 0x00, /* 4 */
+       0x02, 0xbd, 0x04, 0xfb, 0x22, 0x00, 0x00, /* 5 */
+       0x02, 0xbd, 0x05, 0xfa, 0x23, 0x00, 0x00, /* 6 */
+       0x02, 0xbd, 0x06, 0xf9, 0x24, 0x00, 0x00, /* 7 */
+       0x02, 0xbd, 0x07, 0xf8, 0x25, 0x00, 0x00, /* 8 */
+       0x02, 0xbd, 0x08, 0xf7, 0x26, 0x00, 0x00, /* 9 */
+       0x02, 0xbd, 0x09, 0xf6, 0x27, 0x00, 0x00, /* 0 */
+       0x02, 0xbd, 0x0a, 0xf5, 0x41, 0x00, 0x00, /* mute */
+       0x02, 0xbd, 0x1c, 0xe3, 0x2a, 0x00, 0x00, /* esc */
+       0x02, 0xbd, 0x1f, 0xe0, 0x43, 0x00, 0x00, /* volume up */
+       0x02, 0xbd, 0x12, 0xed, 0x52, 0x00, 0x00, /* up arrow */
+       0x02, 0xbd, 0x11, 0xee, 0x50, 0x00, 0x00, /* left arrow */
+       0x02, 0xbd, 0x15, 0xea, 0x28, 0x00, 0x00, /* ok */
+       0x02, 0xbd, 0x10, 0xef, 0x4f, 0x00, 0x00, /* right arrow */
+       0x02, 0xbd, 0x13, 0xec, 0x51, 0x00, 0x00, /* down arrow */
+       0x02, 0xbd, 0x0e, 0xf1, 0x42, 0x00, 0x00, /* volume down */
+       0x02, 0xbd, 0x19, 0xe6, 0x15, 0x01, 0x00, /* record */
+       0x02, 0xbd, 0x1e, 0xe1, 0x13, 0x03, 0x00, /* play */
+       0x02, 0xbd, 0x16, 0xe9, 0x16, 0x01, 0x00, /* stop */
+       0x02, 0xbd, 0x0b, 0xf4, 0x28, 0x04, 0x00, /* yellow, min / max */
+       0x02, 0xbd, 0x0f, 0xf0, 0x3b, 0x00, 0x00, /* time shift */
+       0x02, 0xbd, 0x18, 0xe7, 0x2e, 0x00, 0x00, /* channel up */
+       0x02, 0xbd, 0x1a, 0xe5, 0x2d, 0x00, 0x00, /* channel down */
+       0x02, 0xbd, 0x17, 0xe8, 0x3e, 0x00, 0x00, /* snapshot */
+       0x02, 0xbd, 0x40, 0xbf, 0x13, 0x01, 0x00, /* pause */
+       0x02, 0xbd, 0x41, 0xbe, 0x09, 0x03, 0x00, /* FF >> */
+       0x02, 0xbd, 0x42, 0xbd, 0x07, 0x03, 0x00, /* FR << */
+       0x02, 0xbd, 0x43, 0xbc, 0x00, 0x00, 0x00, /* 'select' (?) */
+       0x02, 0xbd, 0x44, 0xbb, 0x16, 0x03, 0x00, /* shuffle */
+       0x02, 0xbd, 0x45, 0xba, 0x45, 0x03, 0x00, /* power */
+};
+
+/* KWorld PlusTV Dual DVB-T Stick (DVB-T 399U) */
+static u8 af9015_ir_table_kworld[] = {
+       0x86, 0x6b, 0x0c, 0xf3, 0x2e, 0x07, 0x00,
+       0x86, 0x6b, 0x16, 0xe9, 0x2d, 0x07, 0x00,
+       0x86, 0x6b, 0x1d, 0xe2, 0x37, 0x07, 0x00,
+       0x86, 0x6b, 0x00, 0xff, 0x1e, 0x07, 0x00,
+       0x86, 0x6b, 0x01, 0xfe, 0x1f, 0x07, 0x00,
+       0x86, 0x6b, 0x02, 0xfd, 0x20, 0x07, 0x00,
+       0x86, 0x6b, 0x03, 0xfc, 0x21, 0x07, 0x00,
+       0x86, 0x6b, 0x04, 0xfb, 0x22, 0x07, 0x00,
+       0x86, 0x6b, 0x05, 0xfa, 0x23, 0x07, 0x00,
+       0x86, 0x6b, 0x06, 0xf9, 0x24, 0x07, 0x00,
+       0x86, 0x6b, 0x07, 0xf8, 0x25, 0x07, 0x00,
+       0x86, 0x6b, 0x08, 0xf7, 0x26, 0x07, 0x00,
+       0x86, 0x6b, 0x09, 0xf6, 0x4d, 0x07, 0x00,
+       0x86, 0x6b, 0x0a, 0xf5, 0x4e, 0x07, 0x00,
+       0x86, 0x6b, 0x14, 0xeb, 0x4f, 0x07, 0x00,
+       0x86, 0x6b, 0x1e, 0xe1, 0x50, 0x07, 0x00,
+       0x86, 0x6b, 0x17, 0xe8, 0x52, 0x07, 0x00,
+       0x86, 0x6b, 0x1f, 0xe0, 0x51, 0x07, 0x00,
+       0x86, 0x6b, 0x0e, 0xf1, 0x0b, 0x07, 0x00,
+       0x86, 0x6b, 0x20, 0xdf, 0x0c, 0x07, 0x00,
+       0x86, 0x6b, 0x42, 0xbd, 0x0d, 0x07, 0x00,
+       0x86, 0x6b, 0x0b, 0xf4, 0x0e, 0x07, 0x00,
+       0x86, 0x6b, 0x43, 0xbc, 0x0f, 0x07, 0x00,
+       0x86, 0x6b, 0x10, 0xef, 0x10, 0x07, 0x00,
+       0x86, 0x6b, 0x21, 0xde, 0x11, 0x07, 0x00,
+       0x86, 0x6b, 0x13, 0xec, 0x12, 0x07, 0x00,
+       0x86, 0x6b, 0x11, 0xee, 0x13, 0x07, 0x00,
+       0x86, 0x6b, 0x12, 0xed, 0x14, 0x07, 0x00,
+       0x86, 0x6b, 0x19, 0xe6, 0x15, 0x07, 0x00,
+       0x86, 0x6b, 0x1a, 0xe5, 0x16, 0x07, 0x00,
+       0x86, 0x6b, 0x1b, 0xe4, 0x17, 0x07, 0x00,
+       0x86, 0x6b, 0x4b, 0xb4, 0x18, 0x07, 0x00,
+       0x86, 0x6b, 0x40, 0xbf, 0x19, 0x07, 0x00,
+       0x86, 0x6b, 0x44, 0xbb, 0x1a, 0x07, 0x00,
+       0x86, 0x6b, 0x41, 0xbe, 0x1b, 0x07, 0x00,
+       0x86, 0x6b, 0x22, 0xdd, 0x1c, 0x07, 0x00,
+       0x86, 0x6b, 0x15, 0xea, 0x1d, 0x07, 0x00,
+       0x86, 0x6b, 0x0f, 0xf0, 0x3f, 0x07, 0x00,
+       0x86, 0x6b, 0x1c, 0xe3, 0x40, 0x07, 0x00,
+       0x86, 0x6b, 0x4a, 0xb5, 0x41, 0x07, 0x00,
+       0x86, 0x6b, 0x48, 0xb7, 0x42, 0x07, 0x00,
+       0x86, 0x6b, 0x49, 0xb6, 0x43, 0x07, 0x00,
+       0x86, 0x6b, 0x18, 0xe7, 0x44, 0x07, 0x00,
+       0x86, 0x6b, 0x23, 0xdc, 0x45, 0x07, 0x00,
+};
+
+#endif
index 2f408d2e1ef349be29c3ae6ba97ee09df9b49bc5..c786359fba03fea99bbceb52a1d15bee5e8684ad 100644 (file)
@@ -41,6 +41,9 @@
 static int dvb_usb_anysee_debug;
 module_param_named(debug, dvb_usb_anysee_debug, int, 0644);
 MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
+int dvb_usb_anysee_delsys;
+module_param_named(delsys, dvb_usb_anysee_delsys, int, 0644);
+MODULE_PARM_DESC(delsys, "select delivery mode (0=DVB-C, 1=DVB-T)");
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static struct mutex anysee_usb_mutex;
@@ -178,14 +181,14 @@ static int anysee_master_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
                        inc = 1;
                }
                if (ret)
-                       return ret;
+                       break;
 
                i += inc;
        }
 
        mutex_unlock(&d->i2c_mutex);
 
-       return i;
+       return ret ? ret : i;
 }
 
 static u32 anysee_i2c_func(struct i2c_adapter *adapter)
@@ -272,9 +275,11 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
              model      demod     hw  firmware
           1. E30        MT352     02  0.2.1
           2. E30        ZL10353   02  0.2.1
-          3. E30 Plus   ZL10353   06  0.1.0
-          4. E30C Plus  TDA10023  0a  0.1.0    rev 0.2
-          4. E30C Plus  TDA10023  0f  0.1.2    rev 0.4
+          3. E30 Combo  ZL10353   0f  0.1.2    DVB-T/C combo
+          4. E30 Plus   ZL10353   06  0.1.0
+          5. E30C Plus  TDA10023  0a  0.1.0    rev 0.2
+             E30C Plus  TDA10023  0f  0.1.2    rev 0.4
+             E30 Combo  TDA10023  0f  0.1.2    DVB-T/C combo
        */
 
        /* Zarlink MT352 DVB-T demod inside of Samsung DNOS404ZH102A NIM */
@@ -293,6 +298,21 @@ static int anysee_frontend_attach(struct dvb_usb_adapter *adap)
                return 0;
        }
 
+       /* for E30 Combo Plus DVB-T demodulator */
+       if (dvb_usb_anysee_delsys) {
+               ret = anysee_write_reg(adap->dev, 0xb0, 0x01);
+               if (ret)
+                       return ret;
+
+               /* Zarlink ZL10353 DVB-T demod */
+               adap->fe = dvb_attach(zl10353_attach, &anysee_zl10353_config,
+                                     &adap->dev->i2c_adap);
+               if (adap->fe != NULL) {
+                       state->tuner = DVB_PLL_SAMSUNG_DTOS403IH102A;
+                       return 0;
+               }
+       }
+
        /* connect demod on IO port D for TDA10023 & ZL10353 */
        ret = anysee_write_reg(adap->dev, 0xb0, 0x25);
        if (ret)
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-core.c b/drivers/media/dvb/dvb-usb/cinergyT2-core.c
new file mode 100644 (file)
index 0000000..3ac9f74
--- /dev/null
@@ -0,0 +1,268 @@
+/*
+ * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
+ *
+ * Based on the dvb-usb-framework code and the
+ * original Terratec Cinergy T2 driver by:
+ *
+ * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
+ *                 Holger Waechtler <holger@qanu.de>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "cinergyT2.h"
+
+
+/* debug */
+int dvb_usb_cinergyt2_debug;
+int disable_remote;
+
+module_param_named(debug, dvb_usb_cinergyt2_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info, xfer=2, rc=4 "
+               "(or-able)).");
+
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+struct cinergyt2_state {
+       u8 rc_counter;
+};
+
+/* We are missing a release hook with usb_device data */
+struct dvb_usb_device *cinergyt2_usb_device;
+
+static struct dvb_usb_device_properties cinergyt2_properties;
+
+static int cinergyt2_streaming_ctrl(struct dvb_usb_adapter *adap, int enable)
+{
+       char buf[] = { CINERGYT2_EP1_CONTROL_STREAM_TRANSFER, enable ? 1 : 0 };
+       char result[64];
+       return dvb_usb_generic_rw(adap->dev, buf, sizeof(buf), result,
+                               sizeof(result), 0);
+}
+
+static int cinergyt2_power_ctrl(struct dvb_usb_device *d, int enable)
+{
+       char buf[] = { CINERGYT2_EP1_SLEEP_MODE, enable ? 0 : 1 };
+       char state[3];
+       return dvb_usb_generic_rw(d, buf, sizeof(buf), state, sizeof(state), 0);
+}
+
+static int cinergyt2_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       char query[] = { CINERGYT2_EP1_GET_FIRMWARE_VERSION };
+       char state[3];
+       int ret;
+
+       adap->fe = cinergyt2_fe_attach(adap->dev);
+
+       ret = dvb_usb_generic_rw(adap->dev, query, sizeof(query), state,
+                               sizeof(state), 0);
+       if (ret < 0) {
+               deb_rc("cinergyt2_power_ctrl() Failed to retrieve sleep "
+                       "state info\n");
+       }
+
+       /* Copy this pointer as we are gonna need it in the release phase */
+       cinergyt2_usb_device = adap->dev;
+
+       return 0;
+}
+
+static struct dvb_usb_rc_key cinergyt2_rc_keys[] = {
+       { 0x04, 0x01,   KEY_POWER },
+       { 0x04, 0x02,   KEY_1 },
+       { 0x04, 0x03,   KEY_2 },
+       { 0x04, 0x04,   KEY_3 },
+       { 0x04, 0x05,   KEY_4 },
+       { 0x04, 0x06,   KEY_5 },
+       { 0x04, 0x07,   KEY_6 },
+       { 0x04, 0x08,   KEY_7 },
+       { 0x04, 0x09,   KEY_8 },
+       { 0x04, 0x0a,   KEY_9 },
+       { 0x04, 0x0c,   KEY_0 },
+       { 0x04, 0x0b,   KEY_VIDEO },
+       { 0x04, 0x0d,   KEY_REFRESH },
+       { 0x04, 0x0e,   KEY_SELECT },
+       { 0x04, 0x0f,   KEY_EPG },
+       { 0x04, 0x10,   KEY_UP },
+       { 0x04, 0x14,   KEY_DOWN },
+       { 0x04, 0x11,   KEY_LEFT },
+       { 0x04, 0x13,   KEY_RIGHT },
+       { 0x04, 0x12,   KEY_OK },
+       { 0x04, 0x15,   KEY_TEXT },
+       { 0x04, 0x16,   KEY_INFO },
+       { 0x04, 0x17,   KEY_RED },
+       { 0x04, 0x18,   KEY_GREEN },
+       { 0x04, 0x19,   KEY_YELLOW },
+       { 0x04, 0x1a,   KEY_BLUE },
+       { 0x04, 0x1c,   KEY_VOLUMEUP },
+       { 0x04, 0x1e,   KEY_VOLUMEDOWN },
+       { 0x04, 0x1d,   KEY_MUTE },
+       { 0x04, 0x1b,   KEY_CHANNELUP },
+       { 0x04, 0x1f,   KEY_CHANNELDOWN },
+       { 0x04, 0x40,   KEY_PAUSE },
+       { 0x04, 0x4c,   KEY_PLAY },
+       { 0x04, 0x58,   KEY_RECORD },
+       { 0x04, 0x54,   KEY_PREVIOUS },
+       { 0x04, 0x48,   KEY_STOP },
+       { 0x04, 0x5c,   KEY_NEXT }
+};
+
+/* Number of keypresses to ignore before detect repeating */
+#define RC_REPEAT_DELAY 3
+
+static int repeatable_keys[] = {
+       KEY_UP,
+       KEY_DOWN,
+       KEY_LEFT,
+       KEY_RIGHT,
+       KEY_VOLUMEUP,
+       KEY_VOLUMEDOWN,
+       KEY_CHANNELUP,
+       KEY_CHANNELDOWN
+};
+
+static int cinergyt2_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
+{
+       struct cinergyt2_state *st = d->priv;
+       u8 key[5] = {0, 0, 0, 0, 0}, cmd = CINERGYT2_EP1_GET_RC_EVENTS;
+       int i;
+
+       *state = REMOTE_NO_KEY_PRESSED;
+
+       dvb_usb_generic_rw(d, &cmd, 1, key, sizeof(key), 0);
+       if (key[4] == 0xff) {
+               /* key repeat */
+               st->rc_counter++;
+               if (st->rc_counter > RC_REPEAT_DELAY) {
+                       for (i = 0; i < ARRAY_SIZE(repeatable_keys); i++) {
+                               if (d->last_event == repeatable_keys[i]) {
+                                       *state = REMOTE_KEY_REPEAT;
+                                       *event = d->last_event;
+                                       deb_rc("repeat key, event %x\n",
+                                                  *event);
+                                       return 0;
+                               }
+                       }
+                       deb_rc("repeated key (non repeatable)\n");
+               }
+               return 0;
+       }
+
+       /* hack to pass checksum on the custom field */
+       key[2] = ~key[1];
+       dvb_usb_nec_rc_key_to_event(d, key, event, state);
+       if (key[0] != 0) {
+               if (*event != d->last_event)
+                       st->rc_counter = 0;
+
+               deb_rc("key: %x %x %x %x %x\n",
+                      key[0], key[1], key[2], key[3], key[4]);
+       }
+       return 0;
+}
+
+static int cinergyt2_usb_probe(struct usb_interface *intf,
+                               const struct usb_device_id *id)
+{
+       return dvb_usb_device_init(intf, &cinergyt2_properties,
+                                       THIS_MODULE, NULL, adapter_nr);
+}
+
+
+static struct usb_device_id cinergyt2_usb_table[] = {
+       { USB_DEVICE(USB_VID_TERRATEC, 0x0038) },
+       { 0 }
+};
+
+MODULE_DEVICE_TABLE(usb, cinergyt2_usb_table);
+
+static struct dvb_usb_device_properties cinergyt2_properties = {
+       .size_of_priv = sizeof(struct cinergyt2_state),
+       .num_adapters = 1,
+       .adapter = {
+               {
+                       .streaming_ctrl   = cinergyt2_streaming_ctrl,
+                       .frontend_attach  = cinergyt2_frontend_attach,
+
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 5,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 512,
+                                       }
+                               }
+                       },
+               }
+       },
+
+       .power_ctrl       = cinergyt2_power_ctrl,
+
+       .rc_interval      = 50,
+       .rc_key_map       = cinergyt2_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(cinergyt2_rc_keys),
+       .rc_query         = cinergyt2_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 1,
+
+       .num_device_descs = 1,
+       .devices = {
+               { .name = "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver",
+                 .cold_ids = {NULL},
+                 .warm_ids = { &cinergyt2_usb_table[0], NULL },
+               },
+               { NULL },
+       }
+};
+
+
+static struct usb_driver cinergyt2_driver = {
+       .name           = "cinergyT2",
+       .probe          = cinergyt2_usb_probe,
+       .disconnect     = dvb_usb_device_exit,
+       .id_table       = cinergyt2_usb_table
+};
+
+static int __init cinergyt2_usb_init(void)
+{
+       int err;
+
+       err = usb_register(&cinergyt2_driver);
+       if (err) {
+               err("usb_register() failed! (err %i)\n", err);
+               return err;
+       }
+       return 0;
+}
+
+static void __exit cinergyt2_usb_exit(void)
+{
+       usb_deregister(&cinergyt2_driver);
+}
+
+module_init(cinergyt2_usb_init);
+module_exit(cinergyt2_usb_exit);
+
+MODULE_DESCRIPTION("Terratec Cinergy T2 DVB-T driver");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Tomi Orava");
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2-fe.c b/drivers/media/dvb/dvb-usb/cinergyT2-fe.c
new file mode 100644 (file)
index 0000000..649f25c
--- /dev/null
@@ -0,0 +1,351 @@
+/*
+ * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
+ *
+ * Based on the dvb-usb-framework code and the
+ * original Terratec Cinergy T2 driver by:
+ *
+ * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
+ *                  Holger Waechtler <holger@qanu.de>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include "cinergyT2.h"
+
+
+/**
+ *  convert linux-dvb frontend parameter set into TPS.
+ *  See ETSI ETS-300744, section 4.6.2, table 9 for details.
+ *
+ *  This function is probably reusable and may better get placed in a support
+ *  library.
+ *
+ *  We replace errornous fields by default TPS fields (the ones with value 0).
+ */
+
+static uint16_t compute_tps(struct dvb_frontend_parameters *p)
+{
+       struct dvb_ofdm_parameters *op = &p->u.ofdm;
+       uint16_t tps = 0;
+
+       switch (op->code_rate_HP) {
+       case FEC_2_3:
+               tps |= (1 << 7);
+               break;
+       case FEC_3_4:
+               tps |= (2 << 7);
+               break;
+       case FEC_5_6:
+               tps |= (3 << 7);
+               break;
+       case FEC_7_8:
+               tps |= (4 << 7);
+               break;
+       case FEC_1_2:
+       case FEC_AUTO:
+       default:
+               /* tps |= (0 << 7) */;
+       }
+
+       switch (op->code_rate_LP) {
+       case FEC_2_3:
+               tps |= (1 << 4);
+               break;
+       case FEC_3_4:
+               tps |= (2 << 4);
+               break;
+       case FEC_5_6:
+               tps |= (3 << 4);
+               break;
+       case FEC_7_8:
+               tps |= (4 << 4);
+               break;
+       case FEC_1_2:
+       case FEC_AUTO:
+       default:
+               /* tps |= (0 << 4) */;
+       }
+
+       switch (op->constellation) {
+       case QAM_16:
+               tps |= (1 << 13);
+               break;
+       case QAM_64:
+               tps |= (2 << 13);
+               break;
+       case QPSK:
+       default:
+               /* tps |= (0 << 13) */;
+       }
+
+       switch (op->transmission_mode) {
+       case TRANSMISSION_MODE_8K:
+               tps |= (1 << 0);
+               break;
+       case TRANSMISSION_MODE_2K:
+       default:
+               /* tps |= (0 << 0) */;
+       }
+
+       switch (op->guard_interval) {
+       case GUARD_INTERVAL_1_16:
+               tps |= (1 << 2);
+               break;
+       case GUARD_INTERVAL_1_8:
+               tps |= (2 << 2);
+               break;
+       case GUARD_INTERVAL_1_4:
+               tps |= (3 << 2);
+               break;
+       case GUARD_INTERVAL_1_32:
+       default:
+               /* tps |= (0 << 2) */;
+       }
+
+       switch (op->hierarchy_information) {
+       case HIERARCHY_1:
+               tps |= (1 << 10);
+               break;
+       case HIERARCHY_2:
+               tps |= (2 << 10);
+               break;
+       case HIERARCHY_4:
+               tps |= (3 << 10);
+               break;
+       case HIERARCHY_NONE:
+       default:
+               /* tps |= (0 << 10) */;
+       }
+
+       return tps;
+}
+
+struct cinergyt2_fe_state {
+       struct dvb_frontend fe;
+       struct dvb_usb_device *d;
+};
+
+static int cinergyt2_fe_read_status(struct dvb_frontend *fe,
+                                       fe_status_t *status)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_get_status_msg result;
+       u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+       int ret;
+
+       ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&result,
+                       sizeof(result), 0);
+       if (ret < 0)
+               return ret;
+
+       *status = 0;
+
+       if (0xffff - le16_to_cpu(result.gain) > 30)
+               *status |= FE_HAS_SIGNAL;
+       if (result.lock_bits & (1 << 6))
+               *status |= FE_HAS_LOCK;
+       if (result.lock_bits & (1 << 5))
+               *status |= FE_HAS_SYNC;
+       if (result.lock_bits & (1 << 4))
+               *status |= FE_HAS_CARRIER;
+       if (result.lock_bits & (1 << 1))
+               *status |= FE_HAS_VITERBI;
+
+       if ((*status & (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC)) !=
+                       (FE_HAS_CARRIER | FE_HAS_VITERBI | FE_HAS_SYNC))
+               *status &= ~FE_HAS_LOCK;
+
+       return 0;
+}
+
+static int cinergyt2_fe_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_get_status_msg status;
+       char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+       int ret;
+
+       ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
+                               sizeof(status), 0);
+       if (ret < 0)
+               return ret;
+
+       *ber = le32_to_cpu(status.viterbi_error_rate);
+       return 0;
+}
+
+static int cinergyt2_fe_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_get_status_msg status;
+       u8 cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+       int ret;
+
+       ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (u8 *)&status,
+                               sizeof(status), 0);
+       if (ret < 0) {
+               err("cinergyt2_fe_read_unc_blocks() Failed! (Error=%d)\n",
+                       ret);
+               return ret;
+       }
+       *unc = le32_to_cpu(status.uncorrected_block_count);
+       return 0;
+}
+
+static int cinergyt2_fe_read_signal_strength(struct dvb_frontend *fe,
+                                               u16 *strength)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_get_status_msg status;
+       char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+       int ret;
+
+       ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
+                               sizeof(status), 0);
+       if (ret < 0) {
+               err("cinergyt2_fe_read_signal_strength() Failed!"
+                       " (Error=%d)\n", ret);
+               return ret;
+       }
+       *strength = (0xffff - le16_to_cpu(status.gain));
+       return 0;
+}
+
+static int cinergyt2_fe_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_get_status_msg status;
+       char cmd[] = { CINERGYT2_EP1_GET_TUNER_STATUS };
+       int ret;
+
+       ret = dvb_usb_generic_rw(state->d, cmd, sizeof(cmd), (char *)&status,
+                               sizeof(status), 0);
+       if (ret < 0) {
+               err("cinergyt2_fe_read_snr() Failed! (Error=%d)\n", ret);
+               return ret;
+       }
+       *snr = (status.snr << 8) | status.snr;
+       return 0;
+}
+
+static int cinergyt2_fe_init(struct dvb_frontend *fe)
+{
+       return 0;
+}
+
+static int cinergyt2_fe_sleep(struct dvb_frontend *fe)
+{
+       deb_info("cinergyt2_fe_sleep() Called\n");
+       return 0;
+}
+
+static int cinergyt2_fe_get_tune_settings(struct dvb_frontend *fe,
+                               struct dvb_frontend_tune_settings *tune)
+{
+       tune->min_delay_ms = 800;
+       return 0;
+}
+
+static int cinergyt2_fe_set_frontend(struct dvb_frontend *fe,
+                                 struct dvb_frontend_parameters *fep)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       struct dvbt_set_parameters_msg param;
+       char result[2];
+       int err;
+
+       param.cmd = CINERGYT2_EP1_SET_TUNER_PARAMETERS;
+       param.tps = cpu_to_le16(compute_tps(fep));
+       param.freq = cpu_to_le32(fep->frequency / 1000);
+       param.bandwidth = 8 - fep->u.ofdm.bandwidth - BANDWIDTH_8_MHZ;
+
+       err = dvb_usb_generic_rw(state->d,
+                       (char *)&param, sizeof(param),
+                       result, sizeof(result), 0);
+       if (err < 0)
+               err("cinergyt2_fe_set_frontend() Failed! err=%d\n", err);
+
+       return (err < 0) ? err : 0;
+}
+
+static int cinergyt2_fe_get_frontend(struct dvb_frontend *fe,
+                                 struct dvb_frontend_parameters *fep)
+{
+       return 0;
+}
+
+static void cinergyt2_fe_release(struct dvb_frontend *fe)
+{
+       struct cinergyt2_fe_state *state = fe->demodulator_priv;
+       if (state != NULL)
+               kfree(state);
+}
+
+static struct dvb_frontend_ops cinergyt2_fe_ops;
+
+struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d)
+{
+       struct cinergyt2_fe_state *s = kzalloc(sizeof(
+                                       struct cinergyt2_fe_state), GFP_KERNEL);
+       if (s == NULL)
+               return NULL;
+
+       s->d = d;
+       memcpy(&s->fe.ops, &cinergyt2_fe_ops, sizeof(struct dvb_frontend_ops));
+       s->fe.demodulator_priv = s;
+       return &s->fe;
+}
+
+
+static struct dvb_frontend_ops cinergyt2_fe_ops = {
+       .info = {
+               .name                   = DRIVER_NAME,
+               .type                   = FE_OFDM,
+               .frequency_min          = 174000000,
+               .frequency_max          = 862000000,
+               .frequency_stepsize     = 166667,
+               .caps = FE_CAN_INVERSION_AUTO | FE_CAN_FEC_1_2
+                       | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4
+                       | FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8
+                       | FE_CAN_FEC_AUTO | FE_CAN_QPSK
+                       | FE_CAN_QAM_16 | FE_CAN_QAM_64
+                       | FE_CAN_QAM_AUTO
+                       | FE_CAN_TRANSMISSION_MODE_AUTO
+                       | FE_CAN_GUARD_INTERVAL_AUTO
+                       | FE_CAN_HIERARCHY_AUTO
+                       | FE_CAN_RECOVER
+                       | FE_CAN_MUTE_TS
+       },
+
+       .release                = cinergyt2_fe_release,
+
+       .init                   = cinergyt2_fe_init,
+       .sleep                  = cinergyt2_fe_sleep,
+
+       .set_frontend           = cinergyt2_fe_set_frontend,
+       .get_frontend           = cinergyt2_fe_get_frontend,
+       .get_tune_settings      = cinergyt2_fe_get_tune_settings,
+
+       .read_status            = cinergyt2_fe_read_status,
+       .read_ber               = cinergyt2_fe_read_ber,
+       .read_signal_strength   = cinergyt2_fe_read_signal_strength,
+       .read_snr               = cinergyt2_fe_read_snr,
+       .read_ucblocks          = cinergyt2_fe_read_unc_blocks,
+};
diff --git a/drivers/media/dvb/dvb-usb/cinergyT2.h b/drivers/media/dvb/dvb-usb/cinergyT2.h
new file mode 100644 (file)
index 0000000..11d79eb
--- /dev/null
@@ -0,0 +1,95 @@
+/*
+ * TerraTec Cinergy T2/qanu USB2 DVB-T adapter.
+ *
+ * Copyright (C) 2007 Tomi Orava (tomimo@ncircle.nullnet.fi)
+ *
+ * Based on the dvb-usb-framework code and the
+ * original Terratec Cinergy T2 driver by:
+ *
+ * Copyright (C) 2004 Daniel Mack <daniel@qanu.de> and
+ *                  Holger Waechtler <holger@qanu.de>
+ *
+ *  Protocol Spec published on http://qanu.de/specs/terratec_cinergyT2.pdf
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License,  or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not,  write to the Free Software
+ * Foundation,  Inc.,  675 Mass Ave,  Cambridge,  MA 02139,  USA.
+ *
+ */
+
+#ifndef _DVB_USB_CINERGYT2_H_
+#define _DVB_USB_CINERGYT2_H_
+
+#include <linux/usb/input.h>
+
+#define DVB_USB_LOG_PREFIX "cinergyT2"
+#include "dvb-usb.h"
+
+#define DRIVER_NAME "TerraTec/qanu USB2.0 Highspeed DVB-T Receiver"
+
+extern int dvb_usb_cinergyt2_debug;
+
+#define deb_info(args...)  dprintk(dvb_usb_cinergyt2_debug,  0x001, args)
+#define deb_xfer(args...)  dprintk(dvb_usb_cinergyt2_debug,  0x002, args)
+#define deb_pll(args...)   dprintk(dvb_usb_cinergyt2_debug,  0x004, args)
+#define deb_ts(args...)    dprintk(dvb_usb_cinergyt2_debug,  0x008, args)
+#define deb_err(args...)   dprintk(dvb_usb_cinergyt2_debug,  0x010, args)
+#define deb_rc(args...)    dprintk(dvb_usb_cinergyt2_debug,  0x020, args)
+#define deb_fw(args...)    dprintk(dvb_usb_cinergyt2_debug,  0x040, args)
+#define deb_mem(args...)   dprintk(dvb_usb_cinergyt2_debug,  0x080, args)
+#define deb_uxfer(args...) dprintk(dvb_usb_cinergyt2_debug,  0x100, args)
+
+
+
+enum cinergyt2_ep1_cmd {
+       CINERGYT2_EP1_PID_TABLE_RESET           = 0x01,
+       CINERGYT2_EP1_PID_SETUP                 = 0x02,
+       CINERGYT2_EP1_CONTROL_STREAM_TRANSFER   = 0x03,
+       CINERGYT2_EP1_SET_TUNER_PARAMETERS      = 0x04,
+       CINERGYT2_EP1_GET_TUNER_STATUS          = 0x05,
+       CINERGYT2_EP1_START_SCAN                = 0x06,
+       CINERGYT2_EP1_CONTINUE_SCAN             = 0x07,
+       CINERGYT2_EP1_GET_RC_EVENTS             = 0x08,
+       CINERGYT2_EP1_SLEEP_MODE                = 0x09,
+       CINERGYT2_EP1_GET_FIRMWARE_VERSION      = 0x0A
+};
+
+
+struct dvbt_get_status_msg {
+       uint32_t freq;
+       uint8_t bandwidth;
+       uint16_t tps;
+       uint8_t flags;
+       uint16_t gain;
+       uint8_t snr;
+       uint32_t viterbi_error_rate;
+       uint32_t rs_error_rate;
+       uint32_t uncorrected_block_count;
+       uint8_t lock_bits;
+       uint8_t prev_lock_bits;
+} __attribute__((packed));
+
+
+struct dvbt_set_parameters_msg {
+       uint8_t cmd;
+       uint32_t freq;
+       uint8_t bandwidth;
+       uint16_t tps;
+       uint8_t flags;
+} __attribute__((packed));
+
+
+extern struct dvb_frontend *cinergyt2_fe_attach(struct dvb_usb_device *d);
+
+#endif /* _DVB_USB_CINERGYT2_H_ */
+
index 563400277a426a5455e0d9036fdb5d608a0e416e..406d7fba369d6b702e5db34fef48fd133e89c2da 100644 (file)
@@ -36,6 +36,9 @@
 #include "tuner-xc2028.h"
 #include "tuner-simple.h"
 #include "mxl5005s.h"
+#include "dib7000p.h"
+#include "dib0070.h"
+#include "lgs8gl5.h"
 
 /* debug */
 static int dvb_usb_cxusb_debug;
@@ -109,6 +112,25 @@ static void cxusb_nano2_led(struct dvb_usb_device *d, int onoff)
        cxusb_bluebird_gpio_rw(d, 0x40, onoff ? 0 : 0x40);
 }
 
+static int cxusb_d680_dmb_gpio_tuner(struct dvb_usb_device *d,
+               u8 addr, int onoff)
+{
+       u8  o[2] = {addr, onoff};
+       u8  i;
+       int rc;
+
+       rc = cxusb_ctrl_msg(d, CMD_GPIO_WRITE, o, 2, &i, 1);
+
+       if (rc < 0)
+               return rc;
+       if (i == 0x01)
+               return 0;
+       else {
+               deb_info("gpio_write failed.\n");
+               return -EIO;
+       }
+}
+
 /* I2C */
 static int cxusb_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                          int num)
@@ -262,6 +284,20 @@ static int cxusb_nano2_power_ctrl(struct dvb_usb_device *d, int onoff)
        return rc;
 }
 
+static int cxusb_d680_dmb_power_ctrl(struct dvb_usb_device *d, int onoff)
+{
+       int ret;
+       u8  b;
+       ret = cxusb_power_ctrl(d, onoff);
+       if (!onoff)
+               return ret;
+
+       msleep(128);
+       cxusb_ctrl_msg(d, CMD_DIGITAL, NULL, 0, &b, 1);
+       msleep(100);
+       return ret;
+}
+
 static int cxusb_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 {
        u8 buf[2] = { 0x03, 0x00 };
@@ -283,6 +319,67 @@ static int cxusb_aver_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
        return 0;
 }
 
+static void cxusb_d680_dmb_drain_message(struct dvb_usb_device *d)
+{
+       int       ep = d->props.generic_bulk_ctrl_endpoint;
+       const int timeout = 100;
+       const int junk_len = 32;
+       u8        *junk;
+       int       rd_count;
+
+       /* Discard remaining data in video pipe */
+       junk = kmalloc(junk_len, GFP_KERNEL);
+       if (!junk)
+               return;
+       while (1) {
+               if (usb_bulk_msg(d->udev,
+                       usb_rcvbulkpipe(d->udev, ep),
+                       junk, junk_len, &rd_count, timeout) < 0)
+                       break;
+               if (!rd_count)
+                       break;
+       }
+       kfree(junk);
+}
+
+static void cxusb_d680_dmb_drain_video(struct dvb_usb_device *d)
+{
+       struct usb_data_stream_properties *p = &d->props.adapter[0].stream;
+       const int timeout = 100;
+       const int junk_len = p->u.bulk.buffersize;
+       u8        *junk;
+       int       rd_count;
+
+       /* Discard remaining data in video pipe */
+       junk = kmalloc(junk_len, GFP_KERNEL);
+       if (!junk)
+               return;
+       while (1) {
+               if (usb_bulk_msg(d->udev,
+                       usb_rcvbulkpipe(d->udev, p->endpoint),
+                       junk, junk_len, &rd_count, timeout) < 0)
+                       break;
+               if (!rd_count)
+                       break;
+       }
+       kfree(junk);
+}
+
+static int cxusb_d680_dmb_streaming_ctrl(
+               struct dvb_usb_adapter *adap, int onoff)
+{
+       if (onoff) {
+               u8 buf[2] = { 0x03, 0x00 };
+               cxusb_d680_dmb_drain_video(adap->dev);
+               return cxusb_ctrl_msg(adap->dev, CMD_STREAMING_ON,
+                       buf, sizeof(buf), NULL, 0);
+       } else {
+               int ret = cxusb_ctrl_msg(adap->dev,
+                       CMD_STREAMING_OFF, NULL, 0, NULL, 0);
+               return ret;
+       }
+}
+
 static int cxusb_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
        struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
@@ -335,6 +432,32 @@ static int cxusb_bluebird2_rc_query(struct dvb_usb_device *d, u32 *event,
        return 0;
 }
 
+static int cxusb_d680_dmb_rc_query(struct dvb_usb_device *d, u32 *event,
+               int *state)
+{
+       struct dvb_usb_rc_key *keymap = d->props.rc_key_map;
+       u8 ircode[2];
+       int i;
+
+       *event = 0;
+       *state = REMOTE_NO_KEY_PRESSED;
+
+       if (cxusb_ctrl_msg(d, 0x10, NULL, 0, ircode, 2) < 0)
+               return 0;
+
+       for (i = 0; i < d->props.rc_key_map_size; i++) {
+               if (keymap[i].custom == ircode[0] &&
+                   keymap[i].data == ircode[1]) {
+                       *event = keymap[i].event;
+                       *state = REMOTE_KEY_PRESSED;
+
+                       return 0;
+               }
+       }
+
+       return 0;
+}
+
 static struct dvb_usb_rc_key dvico_mce_rc_keys[] = {
        { 0xfe, 0x02, KEY_TV },
        { 0xfe, 0x0e, KEY_MP3 },
@@ -422,6 +545,44 @@ static struct dvb_usb_rc_key dvico_portable_rc_keys[] = {
        { 0xfc, 0x00, KEY_UNKNOWN },    /* HD */
 };
 
+static struct dvb_usb_rc_key d680_dmb_rc_keys[] = {
+       { 0x00, 0x38, KEY_UNKNOWN },    /* TV/AV */
+       { 0x08, 0x0c, KEY_ZOOM },
+       { 0x08, 0x00, KEY_0 },
+       { 0x00, 0x01, KEY_1 },
+       { 0x08, 0x02, KEY_2 },
+       { 0x00, 0x03, KEY_3 },
+       { 0x08, 0x04, KEY_4 },
+       { 0x00, 0x05, KEY_5 },
+       { 0x08, 0x06, KEY_6 },
+       { 0x00, 0x07, KEY_7 },
+       { 0x08, 0x08, KEY_8 },
+       { 0x00, 0x09, KEY_9 },
+       { 0x00, 0x0a, KEY_MUTE },
+       { 0x08, 0x29, KEY_BACK },
+       { 0x00, 0x12, KEY_CHANNELUP },
+       { 0x08, 0x13, KEY_CHANNELDOWN },
+       { 0x00, 0x2b, KEY_VOLUMEUP },
+       { 0x08, 0x2c, KEY_VOLUMEDOWN },
+       { 0x00, 0x20, KEY_UP },
+       { 0x08, 0x21, KEY_DOWN },
+       { 0x00, 0x11, KEY_LEFT },
+       { 0x08, 0x10, KEY_RIGHT },
+       { 0x00, 0x0d, KEY_OK },
+       { 0x08, 0x1f, KEY_RECORD },
+       { 0x00, 0x17, KEY_PLAYPAUSE },
+       { 0x08, 0x16, KEY_PLAYPAUSE },
+       { 0x00, 0x0b, KEY_STOP },
+       { 0x08, 0x27, KEY_FASTFORWARD },
+       { 0x00, 0x26, KEY_REWIND },
+       { 0x08, 0x1e, KEY_UNKNOWN },    /* Time Shift */
+       { 0x00, 0x0e, KEY_UNKNOWN },    /* Snapshot */
+       { 0x08, 0x2d, KEY_UNKNOWN },    /* Mouse Cursor */
+       { 0x00, 0x0f, KEY_UNKNOWN },    /* Minimize/Maximize */
+       { 0x08, 0x14, KEY_UNKNOWN },    /* Shuffle */
+       { 0x00, 0x25, KEY_POWER },
+};
+
 static int cxusb_dee1601_demod_init(struct dvb_frontend* fe)
 {
        static u8 clock_config []  = { CLOCK_CTL,  0x38, 0x28 };
@@ -527,6 +688,24 @@ static struct mxl5005s_config aver_a868r_tuner = {
        .AgcMasterByte   = 0x00,
 };
 
+/* FIXME: needs tweaking */
+static struct mxl5005s_config d680_dmb_tuner = {
+       .i2c_address     = 0x63,
+       .if_freq         = 36125000UL,
+       .xtal_freq       = CRYSTAL_FREQ_16000000HZ,
+       .agc_mode        = MXL_SINGLE_AGC,
+       .tracking_filter = MXL_TF_C,
+       .rssi_enable     = MXL_RSSI_ENABLE,
+       .cap_select      = MXL_CAP_SEL_ENABLE,
+       .div_out         = MXL_DIV_OUT_4,
+       .clock_out       = MXL_CLOCK_OUT_DISABLE,
+       .output_load     = MXL5005S_IF_OUTPUT_LOAD_200_OHM,
+       .top             = MXL5005S_TOP_25P2,
+       .mod_mode        = MXL_DIGITAL_MODE,
+       .if_mode         = MXL_ZERO_IF,
+       .AgcMasterByte   = 0x00,
+};
+
 /* Callbacks for DVB USB */
 static int cxusb_fmd1216me_tuner_attach(struct dvb_usb_adapter *adap)
 {
@@ -563,7 +742,8 @@ static int cxusb_lgh064f_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
-static int dvico_bluebird_xc2028_callback(void *ptr, int command, int arg)
+static int dvico_bluebird_xc2028_callback(void *ptr, int component,
+                                         int command, int arg)
 {
        struct dvb_usb_adapter *adap = ptr;
        struct dvb_usb_device *d = adap->dev;
@@ -591,14 +771,16 @@ static int cxusb_dvico_xc3028_tuner_attach(struct dvb_usb_adapter *adap)
        struct xc2028_config      cfg = {
                .i2c_adap  = &adap->dev->i2c_adap,
                .i2c_addr  = 0x61,
-               .callback  = dvico_bluebird_xc2028_callback,
        };
        static struct xc2028_ctrl ctl = {
-               .fname       = "xc3028-v27.fw",
+               .fname       = XC2028_DEFAULT_FIRMWARE,
                .max_len     = 64,
                .demod       = XC3028_FE_ZARLINK456,
        };
 
+       /* FIXME: generalize & move to common area */
+       adap->fe->callback = dvico_bluebird_xc2028_callback;
+
        fe = dvb_attach(xc2028_attach, adap->fe, &cfg);
        if (fe == NULL || fe->ops.tuner_ops.set_config == NULL)
                return -EIO;
@@ -615,6 +797,14 @@ static int cxusb_mxl5003s_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
+static int cxusb_d680_dmb_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       struct dvb_frontend *fe;
+       fe = dvb_attach(mxl5005s_attach, adap->fe,
+                       &adap->dev->i2c_adap, &d680_dmb_tuner);
+       return (fe == NULL) ? -EIO : 0;
+}
+
 static int cxusb_cx22702_frontend_attach(struct dvb_usb_adapter *adap)
 {
        u8 b;
@@ -726,6 +916,159 @@ no_IR:
        return 0;
 }
 
+static struct dibx000_agc_config dib7070_agc_config = {
+       .band_caps = BAND_UHF | BAND_VHF | BAND_LBAND | BAND_SBAND,
+
+       /*
+        * P_agc_use_sd_mod1=0, P_agc_use_sd_mod2=0, P_agc_freq_pwm_div=5,
+        * P_agc_inv_pwm1=0, P_agc_inv_pwm2=0, P_agc_inh_dc_rv_est=0,
+        * P_agc_time_est=3, P_agc_freeze=0, P_agc_nb_est=5, P_agc_write=0
+        */
+       .setup = (0 << 15) | (0 << 14) | (5 << 11) | (0 << 10) | (0 << 9) |
+                (0 << 8) | (3 << 5) | (0 << 4) | (5 << 1) | (0 << 0),
+       .inv_gain = 600,
+       .time_stabiliz = 10,
+       .alpha_level = 0,
+       .thlock = 118,
+       .wbd_inv = 0,
+       .wbd_ref = 3530,
+       .wbd_sel = 1,
+       .wbd_alpha = 5,
+       .agc1_max = 65535,
+       .agc1_min = 0,
+       .agc2_max = 65535,
+       .agc2_min = 0,
+       .agc1_pt1 = 0,
+       .agc1_pt2 = 40,
+       .agc1_pt3 = 183,
+       .agc1_slope1 = 206,
+       .agc1_slope2 = 255,
+       .agc2_pt1 = 72,
+       .agc2_pt2 = 152,
+       .agc2_slope1 = 88,
+       .agc2_slope2 = 90,
+       .alpha_mant = 17,
+       .alpha_exp = 27,
+       .beta_mant = 23,
+       .beta_exp = 51,
+       .perform_agc_softsplit = 0,
+};
+
+static struct dibx000_bandwidth_config dib7070_bw_config_12_mhz = {
+       .internal = 60000,
+       .sampling = 15000,
+       .pll_prediv = 1,
+       .pll_ratio = 20,
+       .pll_range = 3,
+       .pll_reset = 1,
+       .pll_bypass = 0,
+       .enable_refdiv = 0,
+       .bypclk_div = 0,
+       .IO_CLK_en_core = 1,
+       .ADClkSrc = 1,
+       .modulo = 2,
+       /* refsel, sel, freq_15k */
+       .sad_cfg = (3 << 14) | (1 << 12) | (524 << 0),
+       .ifreq = (0 << 25) | 0,
+       .timf = 20452225,
+       .xtal_hz = 12000000,
+};
+
+static struct dib7000p_config cxusb_dualdig4_rev2_config = {
+       .output_mode = OUTMODE_MPEG2_PAR_GATED_CLK,
+       .output_mpeg2_in_188_bytes = 1,
+
+       .agc_config_count = 1,
+       .agc = &dib7070_agc_config,
+       .bw  = &dib7070_bw_config_12_mhz,
+       .tuner_is_baseband = 1,
+       .spur_protect = 1,
+
+       .gpio_dir = 0xfcef,
+       .gpio_val = 0x0110,
+
+       .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
+
+       .hostbus_diversity = 1,
+};
+
+static int cxusb_dualdig4_rev2_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
+               err("set interface failed");
+
+       cxusb_ctrl_msg(adap->dev, CMD_DIGITAL, NULL, 0, NULL, 0);
+
+       cxusb_bluebird_gpio_pulse(adap->dev, 0x02, 1);
+
+       dib7000p_i2c_enumeration(&adap->dev->i2c_adap, 1, 18,
+                                &cxusb_dualdig4_rev2_config);
+
+       adap->fe = dvb_attach(dib7000p_attach, &adap->dev->i2c_adap, 0x80,
+                             &cxusb_dualdig4_rev2_config);
+       if (adap->fe == NULL)
+               return -EIO;
+
+       return 0;
+}
+
+static int dib7070_tuner_reset(struct dvb_frontend *fe, int onoff)
+{
+       return dib7000p_set_gpio(fe, 8, 0, !onoff);
+}
+
+static int dib7070_tuner_sleep(struct dvb_frontend *fe, int onoff)
+{
+       return 0;
+}
+
+static struct dib0070_config dib7070p_dib0070_config = {
+       .i2c_address = DEFAULT_DIB0070_I2C_ADDRESS,
+       .reset = dib7070_tuner_reset,
+       .sleep = dib7070_tuner_sleep,
+       .clock_khz = 12000,
+};
+
+struct dib0700_adapter_state {
+       int (*set_param_save) (struct dvb_frontend *,
+                              struct dvb_frontend_parameters *);
+};
+
+static int dib7070_set_param_override(struct dvb_frontend *fe,
+                                     struct dvb_frontend_parameters *fep)
+{
+       struct dvb_usb_adapter *adap = fe->dvb->priv;
+       struct dib0700_adapter_state *state = adap->priv;
+
+       u16 offset;
+       u8 band = BAND_OF_FREQUENCY(fep->frequency/1000);
+       switch (band) {
+       case BAND_VHF: offset = 950; break;
+       default:
+       case BAND_UHF: offset = 550; break;
+       }
+
+       dib7000p_set_wbd_ref(fe, offset + dib0070_wbd_offset(fe));
+
+       return state->set_param_save(fe, fep);
+}
+
+static int cxusb_dualdig4_rev2_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       struct dib0700_adapter_state *st = adap->priv;
+       struct i2c_adapter *tun_i2c =
+               dib7000p_get_i2c_master(adap->fe,
+                                       DIBX000_I2C_INTERFACE_TUNER, 1);
+
+       if (dvb_attach(dib0070_attach, adap->fe, tun_i2c,
+           &dib7070p_dib0070_config) == NULL)
+               return -ENODEV;
+
+       st->set_param_save = adap->fe->ops.tuner_ops.set_params;
+       adap->fe->ops.tuner_ops.set_params = dib7070_set_param_override;
+       return 0;
+}
+
 static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
 {
        if (usb_set_interface(adap->dev->udev, 0, 1) < 0)
@@ -751,6 +1094,54 @@ static int cxusb_nano2_frontend_attach(struct dvb_usb_adapter *adap)
        return -EIO;
 }
 
+static struct lgs8gl5_config lgs8gl5_cfg = {
+       .demod_address = 0x19,
+};
+
+static int cxusb_d680_dmb_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       struct dvb_usb_device *d = adap->dev;
+       int n;
+
+       /* Select required USB configuration */
+       if (usb_set_interface(d->udev, 0, 0) < 0)
+               err("set interface failed");
+
+       /* Unblock all USB pipes */
+       usb_clear_halt(d->udev,
+               usb_sndbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
+       usb_clear_halt(d->udev,
+               usb_rcvbulkpipe(d->udev, d->props.generic_bulk_ctrl_endpoint));
+       usb_clear_halt(d->udev,
+               usb_rcvbulkpipe(d->udev, d->props.adapter[0].stream.endpoint));
+
+       /* Drain USB pipes to avoid hang after reboot */
+       for (n = 0;  n < 5;  n++) {
+               cxusb_d680_dmb_drain_message(d);
+               cxusb_d680_dmb_drain_video(d);
+               msleep(200);
+       }
+
+       /* Reset the tuner */
+       if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 0) < 0) {
+               err("clear tuner gpio failed");
+               return -EIO;
+       }
+       msleep(100);
+       if (cxusb_d680_dmb_gpio_tuner(d, 0x07, 1) < 0) {
+               err("set tuner gpio failed");
+               return -EIO;
+       }
+       msleep(100);
+
+       /* Attach frontend */
+       adap->fe = dvb_attach(lgs8gl5_attach, &lgs8gl5_cfg, &d->i2c_adap);
+       if (adap->fe == NULL)
+               return -EIO;
+
+       return 0;
+}
+
 /*
  * DViCO has shipped two devices with the same USB ID, but only one of them
  * needs a firmware download.  Check the device class details to see if they
@@ -826,9 +1217,11 @@ static struct dvb_usb_device_properties cxusb_bluebird_dee1601_properties;
 static struct dvb_usb_device_properties cxusb_bluebird_lgz201_properties;
 static struct dvb_usb_device_properties cxusb_bluebird_dtt7579_properties;
 static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_properties;
+static struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties;
 static struct dvb_usb_device_properties cxusb_bluebird_nano2_properties;
 static struct dvb_usb_device_properties cxusb_bluebird_nano2_needsfirmware_properties;
 static struct dvb_usb_device_properties cxusb_aver_a868r_properties;
+static struct dvb_usb_device_properties cxusb_d680_dmb_properties;
 
 static int cxusb_probe(struct usb_interface *intf,
                       const struct usb_device_id *id)
@@ -852,6 +1245,11 @@ static int cxusb_probe(struct usb_interface *intf,
                                     THIS_MODULE, NULL, adapter_nr) ||
            0 == dvb_usb_device_init(intf, &cxusb_aver_a868r_properties,
                                     THIS_MODULE, NULL, adapter_nr) ||
+           0 == dvb_usb_device_init(intf,
+                                    &cxusb_bluebird_dualdig4_rev2_properties,
+                                    THIS_MODULE, NULL, adapter_nr) ||
+           0 == dvb_usb_device_init(intf, &cxusb_d680_dmb_properties,
+                                    THIS_MODULE, NULL, adapter_nr) ||
            0)
                return 0;
 
@@ -876,6 +1274,8 @@ static struct usb_device_id cxusb_table [] = {
        { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2) },
        { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM) },
        { USB_DEVICE(USB_VID_AVERMEDIA, USB_PID_AVERMEDIA_VOLAR_A868R) },
+       { USB_DEVICE(USB_VID_DVICO, USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2) },
+       { USB_DEVICE(USB_VID_CONEXANT, USB_PID_CONEXANT_D680_DMB) },
        {}              /* Terminating entry */
 };
 MODULE_DEVICE_TABLE (usb, cxusb_table);
@@ -1321,6 +1721,104 @@ static struct dvb_usb_device_properties cxusb_aver_a868r_properties = {
        }
 };
 
+static
+struct dvb_usb_device_properties cxusb_bluebird_dualdig4_rev2_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+       .usb_ctrl         = CYPRESS_FX2,
+
+       .size_of_priv     = sizeof(struct cxusb_state),
+
+       .num_adapters = 1,
+       .adapter = {
+               {
+                       .streaming_ctrl  = cxusb_streaming_ctrl,
+                       .frontend_attach = cxusb_dualdig4_rev2_frontend_attach,
+                       .tuner_attach    = cxusb_dualdig4_rev2_tuner_attach,
+                       .size_of_priv    = sizeof(struct dib0700_adapter_state),
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 7,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 4096,
+                                       }
+                               }
+                       },
+               },
+       },
+
+       .power_ctrl       = cxusb_bluebird_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
+
+       .rc_interval      = 100,
+       .rc_key_map       = dvico_mce_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(dvico_mce_rc_keys),
+       .rc_query         = cxusb_rc_query,
+
+       .num_device_descs = 1,
+       .devices = {
+               {   "DViCO FusionHDTV DVB-T Dual Digital 4 (rev 2)",
+                       { NULL },
+                       { &cxusb_table[17], NULL },
+               },
+       }
+};
+
+static struct dvb_usb_device_properties cxusb_d680_dmb_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+
+       .usb_ctrl         = CYPRESS_FX2,
+
+       .size_of_priv     = sizeof(struct cxusb_state),
+
+       .num_adapters = 1,
+       .adapter = {
+               {
+                       .streaming_ctrl   = cxusb_d680_dmb_streaming_ctrl,
+                       .frontend_attach  = cxusb_d680_dmb_frontend_attach,
+                       .tuner_attach     = cxusb_d680_dmb_tuner_attach,
+
+                       /* parameter for the MPEG2-data transfer */
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 5,
+                               .endpoint = 0x02,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 8192,
+                                       }
+                               }
+                       },
+               },
+       },
+
+       .power_ctrl       = cxusb_d680_dmb_power_ctrl,
+
+       .i2c_algo         = &cxusb_i2c_algo,
+
+       .generic_bulk_ctrl_endpoint = 0x01,
+
+       .rc_interval      = 100,
+       .rc_key_map       = d680_dmb_rc_keys,
+       .rc_key_map_size  = ARRAY_SIZE(d680_dmb_rc_keys),
+       .rc_query         = cxusb_d680_dmb_rc_query,
+
+       .num_device_descs = 1,
+       .devices = {
+               {
+                       "Conexant DMB-TH Stick",
+                       { NULL },
+                       { &cxusb_table[18], NULL },
+               },
+       }
+};
+
 static struct usb_driver cxusb_driver = {
        .name           = "dvb_usb_cxusb",
        .probe          = cxusb_probe,
index 66d4dc6ba46fe8a78a9d597f3d45bdb6e6c5cf01..739193943c17ccbabe5c6af9c1b4a1e3d77c4cc8 100644 (file)
@@ -31,6 +31,8 @@ extern int dvb_usb_dib0700_debug;
        // 2 Byte: MPEG2 mode:  4MSB(1 = Master Mode, 0 = Slave Mode) 4LSB(Channel 1 = bit0, Channel 2 = bit1)
        // 2 Byte: Analog mode: 4MSB(0 = 625 lines, 1 = 525 lines)    4LSB(     "                "           )
 #define REQUEST_SET_RC       0x11
+#define REQUEST_NEW_I2C_READ 0x12
+#define REQUEST_NEW_I2C_WRITE 0x13
 #define REQUEST_GET_VERSION  0x15
 
 struct dib0700_state {
@@ -39,6 +41,8 @@ struct dib0700_state {
        u8 rc_toggle;
        u8 rc_counter;
        u8 is_dib7000pc;
+       u8 fw_use_new_i2c_api;
+       u8 disable_streaming_master_mode;
 };
 
 extern int dib0700_set_gpio(struct dvb_usb_device *, enum dib07x0_gpios gpio, u8 gpio_dir, u8 gpio_val);
index 595a04696c87af2590588bf87013a44b8e44aa7c..dd53cee3896de0d3857569ce08af9d39bc9d308d 100644 (file)
@@ -82,9 +82,98 @@ int dib0700_set_gpio(struct dvb_usb_device *d, enum dib07x0_gpios gpio, u8 gpio_
 }
 
 /*
- * I2C master xfer function
+ * I2C master xfer function (supported in 1.20 firmware)
  */
-static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num)
+static int dib0700_i2c_xfer_new(struct i2c_adapter *adap, struct i2c_msg *msg,
+                               int num)
+{
+       /* The new i2c firmware messages are more reliable and in particular
+          properly support i2c read calls not preceded by a write */
+
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       uint8_t bus_mode = 1;  /* 0=eeprom bus, 1=frontend bus */
+       uint8_t gen_mode = 0; /* 0=master i2c, 1=gpio i2c */
+       uint8_t en_start = 0;
+       uint8_t en_stop = 0;
+       uint8_t buf[255]; /* TBV: malloc ? */
+       int result, i;
+
+       /* Ensure nobody else hits the i2c bus while we're sending our
+          sequence of messages, (such as the remote control thread) */
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       for (i = 0; i < num; i++) {
+               if (i == 0) {
+                       /* First message in the transaction */
+                       en_start = 1;
+               } else if (!(msg[i].flags & I2C_M_NOSTART)) {
+                       /* Device supports repeated-start */
+                       en_start = 1;
+               } else {
+                       /* Not the first packet and device doesn't support
+                          repeated start */
+                       en_start = 0;
+               }
+               if (i == (num - 1)) {
+                       /* Last message in the transaction */
+                       en_stop = 1;
+               }
+
+               if (msg[i].flags & I2C_M_RD) {
+                       /* Read request */
+                       u16 index, value;
+                       uint8_t i2c_dest;
+
+                       i2c_dest = (msg[i].addr << 1);
+                       value = ((en_start << 7) | (en_stop << 6) |
+                                (msg[i].len & 0x3F)) << 8 | i2c_dest;
+                       /* I2C ctrl + FE bus; */
+                       index = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
+
+                       result = usb_control_msg(d->udev,
+                                                usb_rcvctrlpipe(d->udev, 0),
+                                                REQUEST_NEW_I2C_READ,
+                                                USB_TYPE_VENDOR | USB_DIR_IN,
+                                                value, index, msg[i].buf,
+                                                msg[i].len,
+                                                USB_CTRL_GET_TIMEOUT);
+                       if (result < 0) {
+                               err("i2c read error (status = %d)\n", result);
+                               break;
+                       }
+               } else {
+                       /* Write request */
+                       buf[0] = REQUEST_NEW_I2C_WRITE;
+                       buf[1] = (msg[i].addr << 1);
+                       buf[2] = (en_start << 7) | (en_stop << 6) |
+                               (msg[i].len & 0x3F);
+                       /* I2C ctrl + FE bus; */
+                       buf[3] = ((gen_mode<<6)&0xC0) | ((bus_mode<<4)&0x30);
+                       /* The Actual i2c payload */
+                       memcpy(&buf[4], msg[i].buf, msg[i].len);
+
+                       result = usb_control_msg(d->udev,
+                                                usb_sndctrlpipe(d->udev, 0),
+                                                REQUEST_NEW_I2C_WRITE,
+                                                USB_TYPE_VENDOR | USB_DIR_OUT,
+                                                0, 0, buf, msg[i].len + 4,
+                                                USB_CTRL_GET_TIMEOUT);
+                       if (result < 0) {
+                               err("i2c write error (status = %d)\n", result);
+                               break;
+                       }
+               }
+       }
+       mutex_unlock(&d->i2c_mutex);
+       return i;
+}
+
+/*
+ * I2C master xfer function (pre-1.20 firmware)
+ */
+static int dib0700_i2c_xfer_legacy(struct i2c_adapter *adap,
+                                  struct i2c_msg *msg, int num)
 {
        struct dvb_usb_device *d = i2c_get_adapdata(adap);
        int i,len;
@@ -124,6 +213,21 @@ static int dib0700_i2c_xfer(struct i2c_adapter *adap,struct i2c_msg *msg,int num
        return i;
 }
 
+static int dib0700_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msg,
+                           int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       struct dib0700_state *st = d->priv;
+
+       if (st->fw_use_new_i2c_api == 1) {
+               /* User running at least fw 1.20 */
+               return dib0700_i2c_xfer_new(adap, msg, num);
+       } else {
+               /* Use legacy calls */
+               return dib0700_i2c_xfer_legacy(adap, msg, num);
+       }
+}
+
 static u32 dib0700_i2c_func(struct i2c_adapter *adapter)
 {
        return I2C_FUNC_I2C;
@@ -246,7 +350,12 @@ int dib0700_streaming_ctrl(struct dvb_usb_adapter *adap, int onoff)
 
        b[0] = REQUEST_ENABLE_VIDEO;
        b[1] = (onoff << 4) | 0x00; /* this bit gives a kind of command, rather than enabling something or not */
-       b[2] = (0x01 << 4); /* Master mode */
+
+       if (st->disable_streaming_master_mode == 1)
+               b[2] = 0x00;
+       else
+               b[2] = (0x01 << 4); /* Master mode */
+
        b[3] = 0x00;
 
        deb_info("modifying (%d) streaming state for %d\n", onoff, adap->id);
index 6c0e5c5f4362fbed72c8ccdd3d10c7a0098bf056..0cfccc24b1907acad9d4db7ea6f3d77b5a6e7a1a 100644 (file)
@@ -14,6 +14,8 @@
 #include "mt2060.h"
 #include "mt2266.h"
 #include "tuner-xc2028.h"
+#include "xc5000.h"
+#include "s5h1411.h"
 #include "dib0070.h"
 
 static int force_lna_activation;
@@ -366,7 +368,8 @@ static struct dib7000p_config stk7700ph_dib7700_xc3028_config = {
        .gpio_pwm_pos = DIB7000P_GPIO_DEFAULT_PWM_POS,
 };
 
-static int stk7700ph_xc3028_callback(void *ptr, int command, int arg)
+static int stk7700ph_xc3028_callback(void *ptr, int component,
+                                    int command, int arg)
 {
        struct dvb_usb_adapter *adap = ptr;
 
@@ -394,7 +397,6 @@ static struct xc2028_ctrl stk7700ph_xc3028_ctrl = {
 
 static struct xc2028_config stk7700ph_xc3028_config = {
        .i2c_addr = 0x61,
-       .callback = stk7700ph_xc3028_callback,
        .ctrl = &stk7700ph_xc3028_ctrl,
 };
 
@@ -435,7 +437,9 @@ static int stk7700ph_tuner_attach(struct dvb_usb_adapter *adap)
                DIBX000_I2C_INTERFACE_TUNER, 1);
 
        stk7700ph_xc3028_config.i2c_adap = tun_i2c;
-       stk7700ph_xc3028_config.video_dev = adap;
+
+       /* FIXME: generalize & move to common area */
+       adap->fe->callback = stk7700ph_xc3028_callback;
 
        return dvb_attach(xc2028_attach, adap->fe, &stk7700ph_xc3028_config)
                == NULL ? -ENODEV : 0;
@@ -677,6 +681,43 @@ static struct dvb_usb_rc_key dib0700_rc_keys[] = {
        { 0x01, 0x7d, KEY_VOLUMEDOWN },
        { 0x02, 0x42, KEY_CHANNELUP },
        { 0x00, 0x7d, KEY_CHANNELDOWN },
+
+       /* Key codes for Nova-TD "credit card" remote control. */
+       { 0x1d, 0x00, KEY_0 },
+       { 0x1d, 0x01, KEY_1 },
+       { 0x1d, 0x02, KEY_2 },
+       { 0x1d, 0x03, KEY_3 },
+       { 0x1d, 0x04, KEY_4 },
+       { 0x1d, 0x05, KEY_5 },
+       { 0x1d, 0x06, KEY_6 },
+       { 0x1d, 0x07, KEY_7 },
+       { 0x1d, 0x08, KEY_8 },
+       { 0x1d, 0x09, KEY_9 },
+       { 0x1d, 0x0a, KEY_TEXT },
+       { 0x1d, 0x0d, KEY_MENU },
+       { 0x1d, 0x0f, KEY_MUTE },
+       { 0x1d, 0x10, KEY_VOLUMEUP },
+       { 0x1d, 0x11, KEY_VOLUMEDOWN },
+       { 0x1d, 0x12, KEY_CHANNEL },
+       { 0x1d, 0x14, KEY_UP },
+       { 0x1d, 0x15, KEY_DOWN },
+       { 0x1d, 0x16, KEY_LEFT },
+       { 0x1d, 0x17, KEY_RIGHT },
+       { 0x1d, 0x1c, KEY_TV },
+       { 0x1d, 0x1e, KEY_NEXT },
+       { 0x1d, 0x1f, KEY_BACK },
+       { 0x1d, 0x20, KEY_CHANNELUP },
+       { 0x1d, 0x21, KEY_CHANNELDOWN },
+       { 0x1d, 0x24, KEY_LAST },
+       { 0x1d, 0x25, KEY_OK },
+       { 0x1d, 0x30, KEY_PAUSE },
+       { 0x1d, 0x32, KEY_REWIND },
+       { 0x1d, 0x34, KEY_FASTFORWARD },
+       { 0x1d, 0x35, KEY_PLAY },
+       { 0x1d, 0x36, KEY_STOP },
+       { 0x1d, 0x37, KEY_RECORD },
+       { 0x1d, 0x3b, KEY_GOTO },
+       { 0x1d, 0x3d, KEY_POWER },
 };
 
 /* STK7700P: Hauppauge Nova-T Stick, AVerMedia Volar */
@@ -1078,6 +1119,97 @@ static int stk7070pd_frontend_attach1(struct dvb_usb_adapter *adap)
        return adap->fe == NULL ? -ENODEV : 0;
 }
 
+/* S5H1411 */
+static struct s5h1411_config pinnacle_801e_config = {
+       .output_mode   = S5H1411_PARALLEL_OUTPUT,
+       .gpio          = S5H1411_GPIO_OFF,
+       .mpeg_timing   = S5H1411_MPEGTIMING_NONCONTINOUS_NONINVERTING_CLOCK,
+       .qam_if        = S5H1411_IF_44000,
+       .vsb_if        = S5H1411_IF_44000,
+       .inversion     = S5H1411_INVERSION_OFF,
+       .status_mode   = S5H1411_DEMODLOCKING
+};
+
+/* Pinnacle PCTV HD Pro 801e GPIOs map:
+   GPIO0  - currently unknown
+   GPIO1  - xc5000 tuner reset
+   GPIO2  - CX25843 sleep
+   GPIO3  - currently unknown
+   GPIO4  - currently unknown
+   GPIO6  - currently unknown
+   GPIO7  - currently unknown
+   GPIO9  - currently unknown
+   GPIO10 - CX25843 reset
+ */
+static int s5h1411_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       struct dib0700_state *st = adap->dev->priv;
+
+       /* Make use of the new i2c functions from FW 1.20 */
+       st->fw_use_new_i2c_api = 1;
+
+       /* The s5h1411 requires the dib0700 to not be in master mode */
+       st->disable_streaming_master_mode = 1;
+
+       /* All msleep values taken from Windows USB trace */
+       dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 0);
+       dib0700_set_gpio(adap->dev, GPIO3, GPIO_OUT, 0);
+       dib0700_set_gpio(adap->dev, GPIO6, GPIO_OUT, 1);
+       msleep(400);
+       dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 0);
+       msleep(60);
+       dib0700_set_gpio(adap->dev, GPIO10, GPIO_OUT, 1);
+       msleep(30);
+       dib0700_set_gpio(adap->dev, GPIO0, GPIO_OUT, 1);
+       dib0700_set_gpio(adap->dev, GPIO9, GPIO_OUT, 1);
+       dib0700_set_gpio(adap->dev, GPIO4, GPIO_OUT, 1);
+       dib0700_set_gpio(adap->dev, GPIO7, GPIO_OUT, 1);
+       dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 0);
+       msleep(30);
+
+       /* Put the CX25843 to sleep for now since we're in digital mode */
+       dib0700_set_gpio(adap->dev, GPIO2, GPIO_OUT, 1);
+
+       /* GPIOs are initialized, do the attach */
+       adap->fe = dvb_attach(s5h1411_attach, &pinnacle_801e_config,
+                             &adap->dev->i2c_adap);
+       return adap->fe == NULL ? -ENODEV : 0;
+}
+
+static int dib0700_xc5000_tuner_callback(void *priv, int component,
+                                        int command, int arg)
+{
+       struct dvb_usb_adapter *adap = priv;
+
+       if (command == XC5000_TUNER_RESET) {
+               /* Reset the tuner */
+               dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 0);
+               msleep(330); /* from Windows USB trace */
+               dib0700_set_gpio(adap->dev, GPIO1, GPIO_OUT, 1);
+               msleep(330); /* from Windows USB trace */
+       } else {
+               err("xc5000: unknown tuner callback command: %d\n", command);
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static struct xc5000_config s5h1411_xc5000_tunerconfig = {
+       .i2c_address      = 0x64,
+       .if_khz           = 5380,
+};
+
+static int xc5000_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       /* FIXME: generalize & move to common area */
+       adap->fe->callback = dib0700_xc5000_tuner_callback;
+
+       return dvb_attach(xc5000_attach, adap->fe, &adap->dev->i2c_adap,
+                         &s5h1411_xc5000_tunerconfig)
+               == NULL ? -ENODEV : 0;
+}
+
 /* DVB-USB and USB stuff follows */
 struct usb_device_id dib0700_usb_id_table[] = {
 /* 0 */        { USB_DEVICE(USB_VID_DIBCOM,    USB_PID_DIBCOM_STK7700P) },
@@ -1119,6 +1251,11 @@ struct usb_device_id dib0700_usb_id_table[] = {
        { USB_DEVICE(USB_VID_LEADTEK,   USB_PID_WINFAST_DTV_DONGLE_STK7700P_2) },
 /* 35 */{ USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_TD_STICK_52009) },
        { USB_DEVICE(USB_VID_HAUPPAUGE, USB_PID_HAUPPAUGE_NOVA_T_500_3) },
+       { USB_DEVICE(USB_VID_GIGABYTE,  USB_PID_GIGABYTE_U8000) },
+       { USB_DEVICE(USB_VID_YUAN,      USB_PID_YUAN_STK7700PH) },
+       { USB_DEVICE(USB_VID_ASUS,      USB_PID_ASUS_U3000H) },
+/* 40 */{ USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E) },
+       { USB_DEVICE(USB_VID_PINNACLE,  USB_PID_PINNACLE_PCTV801E_SE) },
        { 0 }           /* Terminating entry */
 };
 MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
@@ -1126,7 +1263,7 @@ MODULE_DEVICE_TABLE(usb, dib0700_usb_id_table);
 #define DIB0700_DEFAULT_DEVICE_PROPERTIES \
        .caps              = DVB_USB_IS_AN_I2C_ADAPTER, \
        .usb_ctrl          = DEVICE_SPECIFIC, \
-       .firmware          = "dvb-usb-dib0700-1.10.fw", \
+       .firmware          = "dvb-usb-dib0700-1.20.fw", \
        .download_firmware = dib0700_download_firmware, \
        .no_reconnect      = 1, \
        .size_of_priv      = sizeof(struct dib0700_state), \
@@ -1293,7 +1430,12 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                { &dib0700_usb_id_table[31], NULL },
                                { NULL },
                        }
-               }
+               },
+
+               .rc_interval      = DEFAULT_RC_INTERVAL,
+               .rc_key_map       = dib0700_rc_keys,
+               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_query         = dib0700_rc_query
        }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
 
                .num_adapters = 1,
@@ -1408,7 +1550,7 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                        },
                },
 
-               .num_device_descs = 3,
+               .num_device_descs = 5,
                .devices = {
                        {   "Terratec Cinergy HT USB XE",
                                { &dib0700_usb_id_table[27], NULL },
@@ -1422,6 +1564,47 @@ struct dvb_usb_device_properties dib0700_devices[] = {
                                { &dib0700_usb_id_table[32], NULL },
                                { NULL },
                        },
+                       {   "Gigabyte U8000-RH",
+                               { &dib0700_usb_id_table[37], NULL },
+                               { NULL },
+                       },
+                       {   "YUAN High-Tech STK7700PH",
+                               { &dib0700_usb_id_table[38], NULL },
+                               { NULL },
+                       },
+                       {   "Asus My Cinema-U3000Hybrid",
+                               { &dib0700_usb_id_table[39], NULL },
+                               { NULL },
+                       },
+               },
+               .rc_interval      = DEFAULT_RC_INTERVAL,
+               .rc_key_map       = dib0700_rc_keys,
+               .rc_key_map_size  = ARRAY_SIZE(dib0700_rc_keys),
+               .rc_query         = dib0700_rc_query
+       }, { DIB0700_DEFAULT_DEVICE_PROPERTIES,
+               .num_adapters = 1,
+               .adapter = {
+                       {
+                               .frontend_attach  = s5h1411_frontend_attach,
+                               .tuner_attach     = xc5000_tuner_attach,
+
+                               DIB0700_DEFAULT_STREAMING_CONFIG(0x02),
+
+                               .size_of_priv = sizeof(struct
+                                               dib0700_adapter_state),
+                       },
+               },
+
+               .num_device_descs = 2,
+               .devices = {
+                       {   "Pinnacle PCTV HD Pro USB Stick",
+                               { &dib0700_usb_id_table[40], NULL },
+                               { NULL },
+                       },
+                       {   "Pinnacle PCTV HD USB Stick",
+                               { &dib0700_usb_id_table[41], NULL },
+                               { NULL },
+                       },
                },
                .rc_interval      = DEFAULT_RC_INTERVAL,
                .rc_key_map       = dib0700_rc_keys,
diff --git a/drivers/media/dvb/dvb-usb/dtv5100.c b/drivers/media/dvb/dvb-usb/dtv5100.c
new file mode 100644 (file)
index 0000000..078ce92
--- /dev/null
@@ -0,0 +1,240 @@
+/*
+ * DVB USB Linux driver for AME DTV-5100 USB2.0 DVB-T
+ *
+ * Copyright (C) 2008  Antoine Jacquet <royale@zerezo.com>
+ * http://royale.zerezo.com/dtv5100/
+ *
+ * Inspired by gl861.c and au6610.c drivers
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#include "dtv5100.h"
+#include "zl10353.h"
+#include "qt1010.h"
+
+/* debug */
+static int dvb_usb_dtv5100_debug;
+module_param_named(debug, dvb_usb_dtv5100_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level" DVB_USB_DEBUG_STATUS);
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
+static int dtv5100_i2c_msg(struct dvb_usb_device *d, u8 addr,
+                          u8 *wbuf, u16 wlen, u8 *rbuf, u16 rlen)
+{
+       u8 request;
+       u8 type;
+       u16 value;
+       u16 index;
+
+       switch (wlen) {
+       case 1:
+               /* write { reg }, read { value } */
+               request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_READ :
+                                                       DTV5100_TUNER_READ);
+               type = USB_TYPE_VENDOR | USB_DIR_IN;
+               value = 0;
+               break;
+       case 2:
+               /* write { reg, value } */
+               request = (addr == DTV5100_DEMOD_ADDR ? DTV5100_DEMOD_WRITE :
+                                                       DTV5100_TUNER_WRITE);
+               type = USB_TYPE_VENDOR | USB_DIR_OUT;
+               value = wbuf[1];
+               break;
+       default:
+               warn("wlen = %x, aborting.", wlen);
+               return -EINVAL;
+       }
+       index = (addr << 8) + wbuf[0];
+
+       msleep(1); /* avoid I2C errors */
+       return usb_control_msg(d->udev, usb_rcvctrlpipe(d->udev, 0), request,
+                              type, value, index, rbuf, rlen,
+                              DTV5100_USB_TIMEOUT);
+}
+
+/* I2C */
+static int dtv5100_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
+                           int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int i;
+
+       if (num > 2)
+               return -EINVAL;
+
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       for (i = 0; i < num; i++) {
+               /* write/read request */
+               if (i+1 < num && (msg[i+1].flags & I2C_M_RD)) {
+                       if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,
+                                           msg[i].len, msg[i+1].buf,
+                                           msg[i+1].len) < 0)
+                               break;
+                       i++;
+               } else if (dtv5100_i2c_msg(d, msg[i].addr, msg[i].buf,
+                                          msg[i].len, NULL, 0) < 0)
+                               break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return i;
+}
+
+static u32 dtv5100_i2c_func(struct i2c_adapter *adapter)
+{
+       return I2C_FUNC_I2C;
+}
+
+static struct i2c_algorithm dtv5100_i2c_algo = {
+       .master_xfer   = dtv5100_i2c_xfer,
+       .functionality = dtv5100_i2c_func,
+};
+
+/* Callbacks for DVB USB */
+static struct zl10353_config dtv5100_zl10353_config = {
+       .demod_address = DTV5100_DEMOD_ADDR,
+       .no_tuner = 1,
+       .parallel_ts = 1,
+};
+
+static int dtv5100_frontend_attach(struct dvb_usb_adapter *adap)
+{
+       adap->fe = dvb_attach(zl10353_attach, &dtv5100_zl10353_config,
+                             &adap->dev->i2c_adap);
+       if (adap->fe == NULL)
+               return -EIO;
+
+       /* disable i2c gate, or it won't work... is this safe? */
+       adap->fe->ops.i2c_gate_ctrl = NULL;
+
+       return 0;
+}
+
+static struct qt1010_config dtv5100_qt1010_config = {
+       .i2c_address = DTV5100_TUNER_ADDR
+};
+
+static int dtv5100_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       return dvb_attach(qt1010_attach,
+                         adap->fe, &adap->dev->i2c_adap,
+                         &dtv5100_qt1010_config) == NULL ? -ENODEV : 0;
+}
+
+/* DVB USB Driver stuff */
+static struct dvb_usb_device_properties dtv5100_properties;
+
+static int dtv5100_probe(struct usb_interface *intf,
+                        const struct usb_device_id *id)
+{
+       int i, ret;
+       struct usb_device *udev = interface_to_usbdev(intf);
+
+       /* initialize non qt1010/zl10353 part? */
+       for (i = 0; dtv5100_init[i].request; i++) {
+               ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+                                     dtv5100_init[i].request,
+                                     USB_TYPE_VENDOR | USB_DIR_OUT,
+                                     dtv5100_init[i].value,
+                                     dtv5100_init[i].index, NULL, 0,
+                                     DTV5100_USB_TIMEOUT);
+               if (ret)
+                       return ret;
+       }
+
+       ret = dvb_usb_device_init(intf, &dtv5100_properties,
+                                 THIS_MODULE, NULL, adapter_nr);
+       if (ret)
+               return ret;
+
+       return 0;
+}
+
+static struct usb_device_id dtv5100_table[] = {
+       { USB_DEVICE(0x06be, 0xa232) },
+       { }             /* Terminating entry */
+};
+MODULE_DEVICE_TABLE(usb, dtv5100_table);
+
+static struct dvb_usb_device_properties dtv5100_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+       .usb_ctrl = DEVICE_SPECIFIC,
+
+       .size_of_priv = 0,
+
+       .num_adapters = 1,
+       .adapter = {{
+               .frontend_attach = dtv5100_frontend_attach,
+               .tuner_attach    = dtv5100_tuner_attach,
+
+               .stream = {
+                       .type = USB_BULK,
+                       .count = 8,
+                       .endpoint = 0x82,
+                       .u = {
+                               .bulk = {
+                                       .buffersize = 4096,
+                               }
+                       }
+               },
+       } },
+
+       .i2c_algo = &dtv5100_i2c_algo,
+
+       .num_device_descs = 1,
+       .devices = {
+               {
+                       .name = "AME DTV-5100 USB2.0 DVB-T",
+                       .cold_ids = { NULL },
+                       .warm_ids = { &dtv5100_table[0], NULL },
+               },
+       }
+};
+
+static struct usb_driver dtv5100_driver = {
+       .name           = "dvb_usb_dtv5100",
+       .probe          = dtv5100_probe,
+       .disconnect     = dvb_usb_device_exit,
+       .id_table       = dtv5100_table,
+};
+
+/* module stuff */
+static int __init dtv5100_module_init(void)
+{
+       int ret;
+
+       ret = usb_register(&dtv5100_driver);
+       if (ret)
+               err("usb_register failed. Error number %d", ret);
+
+       return ret;
+}
+
+static void __exit dtv5100_module_exit(void)
+{
+       /* deregister this driver from the USB subsystem */
+       usb_deregister(&dtv5100_driver);
+}
+
+module_init(dtv5100_module_init);
+module_exit(dtv5100_module_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/dvb-usb/dtv5100.h b/drivers/media/dvb/dvb-usb/dtv5100.h
new file mode 100644 (file)
index 0000000..93e96e0
--- /dev/null
@@ -0,0 +1,51 @@
+/*
+ * DVB USB Linux driver for AME DTV-5100 USB2.0 DVB-T
+ *
+ * Copyright (C) 2008  Antoine Jacquet <royale@zerezo.com>
+ * http://royale.zerezo.com/dtv5100/
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ */
+
+#ifndef _DVB_USB_DTV5100_H_
+#define _DVB_USB_DTV5100_H_
+
+#define DVB_USB_LOG_PREFIX "dtv5100"
+#include "dvb-usb.h"
+
+#define DTV5100_USB_TIMEOUT 500
+
+#define DTV5100_DEMOD_ADDR     0x00
+#define DTV5100_DEMOD_WRITE    0xc0
+#define DTV5100_DEMOD_READ     0xc1
+
+#define DTV5100_TUNER_ADDR     0xc4
+#define DTV5100_TUNER_WRITE    0xc7
+#define DTV5100_TUNER_READ     0xc8
+
+#define DRIVER_AUTHOR "Antoine Jacquet, http://royale.zerezo.com/"
+#define DRIVER_DESC "AME DTV-5100 USB2.0 DVB-T"
+
+static struct {
+       u8 request;
+       u8 value;
+       u16 index;
+} dtv5100_init[] = {
+       { 0x000000c5, 0x00000000, 0x00000001 },
+       { 0x000000c5, 0x00000001, 0x00000001 },
+       { }             /* Terminating entry */
+};
+
+#endif
index 03dfb9f2fe30eacd73aadbcf01b8aa9c5230ccd5..7380b94b3b36065af00051e7f5f965fb18f3afc1 100644 (file)
@@ -22,6 +22,7 @@
 #define USB_VID_AVERMEDIA                      0x07ca
 #define USB_VID_COMPRO                         0x185b
 #define USB_VID_COMPRO_UNK                     0x145f
+#define USB_VID_CONEXANT                       0x0572
 #define USB_VID_CYPRESS                                0x04b4
 #define USB_VID_DIBCOM                         0x10b8
 #define USB_VID_DPOSH                          0x1498
 #define USB_VID_HAUPPAUGE                      0x2040
 #define USB_VID_HYPER_PALTEK                   0x1025
 #define USB_VID_KWORLD                         0xeb2a
+#define USB_VID_KWORLD_2                       0x1b80
 #define USB_VID_KYE                            0x0458
 #define USB_VID_LEADTEK                                0x0413
 #define USB_VID_LITEON                         0x04ca
 #define USB_VID_MEDION                         0x1660
 #define USB_VID_MIGLIA                         0x18f3
 #define USB_VID_MSI                            0x0db0
+#define USB_VID_MSI_2                          0x1462
 #define USB_VID_OPERA1                         0x695c
 #define USB_VID_PINNACLE                       0x2304
 #define USB_VID_TECHNOTREND                    0x0b48
 #define USB_VID_TERRATEC                       0x0ccd
+#define USB_VID_TELESTAR                       0x10b9
 #define USB_VID_VISIONPLUS                     0x13d3
 #define USB_VID_TWINHAN                                0x1822
 #define USB_VID_ULTIMA_ELECTRONIC              0x05d8
 #define USB_VID_WIDEVIEW                       0x14aa
 #define USB_VID_GIGABYTE                       0x1044
 #define USB_VID_YUAN                           0x1164
-
+#define USB_VID_XTENSIONS                      0x1ae7
 
 /* Product IDs */
 #define USB_PID_ADSTECH_USB2_COLD                      0xa333
 #define USB_PID_ADSTECH_USB2_WARM                      0xa334
 #define USB_PID_AFATECH_AF9005                         0x9020
+#define USB_PID_AFATECH_AF9015_9015                    0x9015
+#define USB_PID_AFATECH_AF9015_9016                    0x9016
 #define USB_VID_ALINK_DTU                              0xf170
 #define USB_PID_ANSONIC_DVBT_USB                       0x6000
 #define USB_PID_ANYSEE                                 0x861f
+#define USB_PID_AZUREWAVE_AD_TU700                     0x3237
 #define USB_PID_AVERMEDIA_DVBT_USB_COLD                        0x0001
 #define USB_PID_AVERMEDIA_DVBT_USB_WARM                        0x0002
 #define USB_PID_AVERMEDIA_DVBT_USB2_COLD               0xa800
@@ -69,6 +76,7 @@
 #define USB_PID_COMPRO_DVBU2000_UNK_WARM               0x010d
 #define USB_PID_COMPRO_VIDEOMATE_U500                  0x1e78
 #define USB_PID_COMPRO_VIDEOMATE_U500_PC               0x1e80
+#define USB_PID_CONEXANT_D680_DMB                      0x86d6
 #define USB_PID_DIBCOM_HOOK_DEFAULT                    0x0064
 #define USB_PID_DIBCOM_HOOK_DEFAULT_REENUM             0x0065
 #define USB_PID_DIBCOM_MOD3000_COLD                    0x0bb8
 #define USB_PID_UNIWILL_STK7700P                       0x6003
 #define USB_PID_GRANDTEC_DVBT_USB_COLD                 0x0fa0
 #define USB_PID_GRANDTEC_DVBT_USB_WARM                 0x0fa1
+#define USB_PID_KWORLD_399U                            0xe399
+#define USB_PID_KWORLD_PC160_2T                                0xc160
 #define USB_PID_KWORLD_VSTREAM_COLD                    0x17de
 #define USB_PID_KWORLD_VSTREAM_WARM                    0x17df
 #define USB_PID_TERRATEC_CINERGY_T_USB_XE              0x0055
+#define USB_PID_TERRATEC_CINERGY_T_USB_XE_REV2         0x0069
 #define USB_PID_TWINHAN_VP7041_COLD                    0x3201
 #define USB_PID_TWINHAN_VP7041_WARM                    0x3202
 #define USB_PID_TWINHAN_VP7020_COLD                    0x3203
 #define USB_PID_TWINHAN_VP7045_WARM                    0x3206
 #define USB_PID_TWINHAN_VP7021_COLD                    0x3207
 #define USB_PID_TWINHAN_VP7021_WARM                    0x3208
+#define USB_PID_TINYTWIN                               0x3226
 #define USB_PID_DNTV_TINYUSB2_COLD                     0x3223
 #define USB_PID_DNTV_TINYUSB2_WARM                     0x3224
 #define USB_PID_ULTIMA_TVBOX_COLD                      0x8105
 #define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R       0x0039
 #define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_ATSC  0x1039
 #define USB_PID_AVERMEDIA_HYBRID_ULTRA_USB_M039R_DVBT  0x2039
+#define USB_PID_AVERMEDIA_VOLAR_X                      0xa815
+#define USB_PID_AVERMEDIA_VOLAR_X_2                    0x8150
+#define USB_PID_AVERMEDIA_A309                         0xa309
 #define USB_PID_TECHNOTREND_CONNECT_S2400               0x3006
 #define USB_PID_TERRATEC_CINERGY_DT_XS_DIVERSITY       0x005a
 #define USB_PID_TERRATEC_CINERGY_HT_USB_XE             0x0058
 #define USB_PID_PINNACLE_PCTV2000E                     0x022c
 #define USB_PID_PINNACLE_PCTV_DVB_T_FLASH              0x0228
 #define USB_PID_PINNACLE_PCTV_DUAL_DIVERSITY_DVB_T     0x0229
+#define USB_PID_PINNACLE_PCTV71E                       0x022b
 #define USB_PID_PINNACLE_PCTV72E                       0x0236
 #define USB_PID_PINNACLE_PCTV73E                       0x0237
+#define USB_PID_PINNACLE_PCTV801E                      0x023a
+#define USB_PID_PINNACLE_PCTV801E_SE                   0x023b
 #define USB_PID_PCTV_200E                              0x020e
 #define USB_PID_PCTV_400E                              0x020f
 #define USB_PID_PCTV_450E                              0x0222
 #define USB_PID_DVICO_BLUEBIRD_DUAL_2_COLD             0xdb58
 #define USB_PID_DVICO_BLUEBIRD_DUAL_2_WARM             0xdb59
 #define USB_PID_DVICO_BLUEBIRD_DUAL_4                  0xdb78
+#define USB_PID_DVICO_BLUEBIRD_DUAL_4_REV_2            0xdb98
 #define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2            0xdb70
 #define USB_PID_DVICO_BLUEBIRD_DVB_T_NANO_2_NFW_WARM   0xdb71
 #define USB_PID_DIGITALNOW_BLUEBIRD_DUAL_1_COLD                0xdb54
 #define USB_PID_WINFAST_DTV_DONGLE_WARM                        0x6026
 #define USB_PID_WINFAST_DTV_DONGLE_STK7700P            0x6f00
 #define USB_PID_WINFAST_DTV_DONGLE_STK7700P_2          0x6f01
+#define USB_PID_WINFAST_DTV_DONGLE_GOLD                        0x6029
 #define USB_PID_GENPIX_8PSK_REV_1_COLD                 0x0200
 #define USB_PID_GENPIX_8PSK_REV_1_WARM                 0x0201
 #define USB_PID_GENPIX_8PSK_REV_2                      0x0202
 #define USB_PID_GENPIX_SKYWALKER_CW3K                  0x0204
 #define USB_PID_SIGMATEK_DVB_110                       0x6610
 #define USB_PID_MSI_DIGI_VOX_MINI_II                   0x1513
+#define USB_PID_MSI_DIGIVOX_DUO                                0x8801
 #define USB_PID_OPERA1_COLD                            0x2830
 #define USB_PID_OPERA1_WARM                            0x3829
 #define USB_PID_LIFEVIEW_TV_WALKER_TWIN_COLD           0x0514
 #define USB_PID_LIFEVIEW_TV_WALKER_TWIN_WARM           0x0513
 #define USB_PID_GIGABYTE_U7000                         0x7001
+#define USB_PID_GIGABYTE_U8000                         0x7002
 #define USB_PID_ASUS_U3000                             0x171f
+#define USB_PID_ASUS_U3000H                            0x1736
 #define USB_PID_ASUS_U3100                             0x173f
 #define USB_PID_YUAN_EC372S                            0x1edc
+#define USB_PID_YUAN_STK7700PH                         0x1f08
 #define USB_PID_DW2102                                 0x2102
+#define USB_PID_XTENSIONS_XD_380                       0x0381
+#define USB_PID_TELESTAR_STARSTICK_2                   0x8000
+#define USB_PID_MSI_DIGI_VOX_MINI_III                   0x8807
 
 #endif
index a4d898b44e55c40eb9cf5b7cccfdfe496cdcfa62..ca53df61caa8fbc9d7e3b84c2a27c2b1bace533e 100644 (file)
@@ -1,4 +1,5 @@
-/* DVB USB framework compliant Linux driver for the DVBWorld DVB-S 2102 Card
+/* DVB USB framework compliant Linux driver for the
+*      DVBWorld DVB-S 2101, 2102, DVB-S2 2104 Card
 *
 * Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
 *
 */
 #include <linux/version.h>
 #include "dw2102.h"
+#include "si21xx.h"
 #include "stv0299.h"
 #include "z0194a.h"
+#include "stv0288.h"
+#include "stb6000.h"
+#include "eds1547.h"
+#include "cx24116.h"
 
 #ifndef USB_PID_DW2102
 #define USB_PID_DW2102 0x2102
 #endif
 
-#define DW2102_READ_MSG 0
-#define DW2102_WRITE_MSG 1
+#ifndef USB_PID_DW2104
+#define USB_PID_DW2104 0x2104
+#endif
+
+#define DW210X_READ_MSG 0
+#define DW210X_WRITE_MSG 1
 
 #define REG_1F_SYMBOLRATE_BYTE0 0x1f
 #define REG_20_SYMBOLRATE_BYTE1 0x20
 #define REG_21_SYMBOLRATE_BYTE2 0x21
-
+/* on my own*/
 #define DW2102_VOLTAGE_CTRL (0x1800)
 #define DW2102_RC_QUERY (0x1a00)
 
-struct dw2102_state {
+struct dw210x_state {
        u32 last_key_pressed;
 };
-struct dw2102_rc_keys {
+struct dw210x_rc_keys {
        u32 keycode;
        u32 event;
 };
 
+/* debug */
+static int dvb_usb_dw2102_debug;
+module_param_named(debug, dvb_usb_dw2102_debug, int, 0644);
+MODULE_PARM_DESC(debug, "set debugging level (1=info 2=xfer (or-able))." DVB_USB_DEBUG_STATUS);
+
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
-static int dw2102_op_rw(struct usb_device *dev, u8 request, u16 value,
-               u8 *data, u16 len, int flags)
+static int dw210x_op_rw(struct usb_device *dev, u8 request, u16 value,
+                       u16 index, u8 * data, u16 len, int flags)
 {
        int ret;
        u8 u8buf[len];
 
-       unsigned int pipe = (flags == DW2102_READ_MSG) ?
-               usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
-       u8 request_type = (flags == DW2102_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
+       unsigned int pipe = (flags == DW210X_READ_MSG) ?
+                               usb_rcvctrlpipe(dev, 0) : usb_sndctrlpipe(dev, 0);
+       u8 request_type = (flags == DW210X_READ_MSG) ? USB_DIR_IN : USB_DIR_OUT;
 
-       if (flags == DW2102_WRITE_MSG)
+       if (flags == DW210X_WRITE_MSG)
                memcpy(u8buf, data, len);
-       ret = usb_control_msg(dev, pipe, request,
-               request_type | USB_TYPE_VENDOR, value, 0 , u8buf, len, 2000);
+       ret = usb_control_msg(dev, pipe, request, request_type | USB_TYPE_VENDOR,
+                               value, index , u8buf, len, 2000);
 
-       if (flags == DW2102_READ_MSG)
+       if (flags == DW210X_READ_MSG)
                memcpy(data, u8buf, len);
        return ret;
 }
 
 /* I2C */
-
 static int dw2102_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[],
                int num)
 {
 struct dvb_usb_device *d = i2c_get_adapdata(adap);
        int i = 0, ret = 0;
        u8 buf6[] = {0x2c, 0x05, 0xc0, 0, 0, 0, 0};
-       u8 request;
        u16 value;
 
        if (!d)
@@ -76,14 +89,12 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
        switch (num) {
        case 2:
                /* read stv0299 register */
-               request = 0xb5;
                value = msg[0].buf[0];/* register */
                for (i = 0; i < msg[1].len; i++) {
                        value = value + i;
-                       ret = dw2102_op_rw(d->udev, 0xb5,
-                               value, buf6, 2, DW2102_READ_MSG);
+                       ret = dw210x_op_rw(d->udev, 0xb5, value, 0,
+                                       buf6, 2, DW210X_READ_MSG);
                        msg[1].buf[i] = buf6[0];
-
                }
                break;
        case 1:
@@ -93,8 +104,8 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
                        buf6[0] = 0x2a;
                        buf6[1] = msg[0].buf[0];
                        buf6[2] = msg[0].buf[1];
-                       ret = dw2102_op_rw(d->udev, 0xb2,
-                               0, buf6, 3, DW2102_WRITE_MSG);
+                       ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                       buf6, 3, DW210X_WRITE_MSG);
                        break;
                case 0x60:
                        if (msg[0].flags == 0) {
@@ -106,26 +117,26 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
                                buf6[4] = msg[0].buf[1];
                                buf6[5] = msg[0].buf[2];
                                buf6[6] = msg[0].buf[3];
-                               ret = dw2102_op_rw(d->udev, 0xb2,
-                               0, buf6, 7, DW2102_WRITE_MSG);
+                               ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                               buf6, 7, DW210X_WRITE_MSG);
                        } else {
-                       /* write to tuner pll */
-                               ret = dw2102_op_rw(d->udev, 0xb5,
-                               0, buf6, 1, DW2102_READ_MSG);
+                       /* read from tuner */
+                               ret = dw210x_op_rw(d->udev, 0xb5, 0, 0,
+                                               buf6, 1, DW210X_READ_MSG);
                                msg[0].buf[0] = buf6[0];
                        }
                        break;
                case (DW2102_RC_QUERY):
-                       ret  = dw2102_op_rw(d->udev, 0xb8,
-                               0, buf6, 2, DW2102_READ_MSG);
+                       ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
+                                       buf6, 2, DW210X_READ_MSG);
                        msg[0].buf[0] = buf6[0];
                        msg[0].buf[1] = buf6[1];
                        break;
                case (DW2102_VOLTAGE_CTRL):
                        buf6[0] = 0x30;
                        buf6[1] = msg[0].buf[0];
-                       ret = dw2102_op_rw(d->udev, 0xb2,
-                               0, buf6, 2, DW2102_WRITE_MSG);
+                       ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                       buf6, 2, DW210X_WRITE_MSG);
                        break;
                }
 
@@ -136,17 +147,265 @@ struct dvb_usb_device *d = i2c_get_adapdata(adap);
        return num;
 }
 
-static u32 dw2102_i2c_func(struct i2c_adapter *adapter)
+static int dw2102_serit_i2c_transfer(struct i2c_adapter *adap,
+                                               struct i2c_msg msg[], int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int ret = 0;
+       u8 buf6[] = {0, 0, 0, 0, 0, 0, 0};
+
+       if (!d)
+               return -ENODEV;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       switch (num) {
+       case 2:
+               /* read si2109 register by number */
+               buf6[0] = 0xd0;
+               buf6[1] = msg[0].len;
+               buf6[2] = msg[0].buf[0];
+               ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                               buf6, msg[0].len + 2, DW210X_WRITE_MSG);
+               /* read si2109 register */
+               ret = dw210x_op_rw(d->udev, 0xc3, 0xd0, 0,
+                               buf6, msg[1].len + 2, DW210X_READ_MSG);
+               memcpy(msg[1].buf, buf6 + 2, msg[1].len);
+
+               break;
+       case 1:
+               switch (msg[0].addr) {
+               case 0x68:
+                       /* write to si2109 register */
+                       buf6[0] = 0xd0;
+                       buf6[1] = msg[0].len;
+                       memcpy(buf6 + 2, msg[0].buf, msg[0].len);
+                       ret = dw210x_op_rw(d->udev, 0xc2, 0, 0, buf6,
+                                       msg[0].len + 2, DW210X_WRITE_MSG);
+                       break;
+               case(DW2102_RC_QUERY):
+                       ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
+                                       buf6, 2, DW210X_READ_MSG);
+                       msg[0].buf[0] = buf6[0];
+                       msg[0].buf[1] = buf6[1];
+                       break;
+               case(DW2102_VOLTAGE_CTRL):
+                       buf6[0] = 0x30;
+                       buf6[1] = msg[0].buf[0];
+                       ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                       buf6, 2, DW210X_WRITE_MSG);
+                       break;
+               }
+               break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return num;
+}
+static int dw2102_earda_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int ret = 0;
+
+       if (!d)
+               return -ENODEV;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       switch (num) {
+       case 2: {
+               /* read */
+               /* first write first register number */
+               u8 ibuf [msg[1].len + 2], obuf[3];
+               obuf[0] = 0xd0;
+               obuf[1] = msg[0].len;
+               obuf[2] = msg[0].buf[0];
+               ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                               obuf, msg[0].len + 2, DW210X_WRITE_MSG);
+               /* second read registers */
+               ret = dw210x_op_rw(d->udev, 0xc3, 0xd1 , 0,
+                               ibuf, msg[1].len + 2, DW210X_READ_MSG);
+               memcpy(msg[1].buf, ibuf + 2, msg[1].len);
+
+               break;
+       }
+       case 1:
+               switch (msg[0].addr) {
+               case 0x68: {
+                       /* write to register */
+                       u8 obuf[msg[0].len + 2];
+                       obuf[0] = 0xd0;
+                       obuf[1] = msg[0].len;
+                       memcpy(obuf + 2, msg[0].buf, msg[0].len);
+                       ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                                       obuf, msg[0].len + 2, DW210X_WRITE_MSG);
+                       break;
+               }
+               case 0x61: {
+                       /* write to tuner */
+                       u8 obuf[msg[0].len + 2];
+                       obuf[0] = 0xc2;
+                       obuf[1] = msg[0].len;
+                       memcpy(obuf + 2, msg[0].buf, msg[0].len);
+                       ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                                       obuf, msg[0].len + 2, DW210X_WRITE_MSG);
+                       break;
+               }
+               case(DW2102_RC_QUERY): {
+                       u8 ibuf[2];
+                       ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
+                                       ibuf, 2, DW210X_READ_MSG);
+                       memcpy(msg[0].buf, ibuf , 2);
+                       break;
+               }
+               case(DW2102_VOLTAGE_CTRL): {
+                       u8 obuf[2];
+                       obuf[0] = 0x30;
+                       obuf[1] = msg[0].buf[0];
+                       ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                       obuf, 2, DW210X_WRITE_MSG);
+                       break;
+               }
+               }
+
+               break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return num;
+}
+
+static int dw2104_i2c_transfer(struct i2c_adapter *adap, struct i2c_msg msg[], int num)
+{
+       struct dvb_usb_device *d = i2c_get_adapdata(adap);
+       int ret = 0;
+       int len, i;
+
+       if (!d)
+               return -ENODEV;
+       if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
+               return -EAGAIN;
+
+       switch (num) {
+       case 2: {
+               /* read */
+               /* first write first register number */
+               u8 ibuf [msg[1].len + 2], obuf[3];
+               obuf[0] = 0xaa;
+               obuf[1] = msg[0].len;
+               obuf[2] = msg[0].buf[0];
+               ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                               obuf, msg[0].len + 2, DW210X_WRITE_MSG);
+               /* second read registers */
+               ret = dw210x_op_rw(d->udev, 0xc3, 0xab , 0,
+                               ibuf, msg[1].len + 2, DW210X_READ_MSG);
+               memcpy(msg[1].buf, ibuf + 2, msg[1].len);
+
+               break;
+       }
+       case 1:
+               switch (msg[0].addr) {
+               case 0x55: {
+                       if (msg[0].buf[0] == 0xf7) {
+                               /* firmware */
+                               /* Write in small blocks */
+                               u8 obuf[19];
+                               obuf[0] = 0xaa;
+                               obuf[1] = 0x11;
+                               obuf[2] = 0xf7;
+                               len = msg[0].len - 1;
+                               i = 1;
+                               do {
+                                       memcpy(obuf + 3, msg[0].buf + i, (len > 16 ? 16 : len));
+                                       ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                                               obuf, (len > 16 ? 16 : len) + 3, DW210X_WRITE_MSG);
+                                       i += 16;
+                                       len -= 16;
+                               } while (len > 0);
+                       } else {
+                               /* write to register */
+                               u8 obuf[msg[0].len + 2];
+                               obuf[0] = 0xaa;
+                               obuf[1] = msg[0].len;
+                               memcpy(obuf + 2, msg[0].buf, msg[0].len);
+                               ret = dw210x_op_rw(d->udev, 0xc2, 0, 0,
+                                               obuf, msg[0].len + 2, DW210X_WRITE_MSG);
+                       }
+                       break;
+               }
+               case(DW2102_RC_QUERY): {
+                       u8 ibuf[2];
+                       ret  = dw210x_op_rw(d->udev, 0xb8, 0, 0,
+                                       ibuf, 2, DW210X_READ_MSG);
+                       memcpy(msg[0].buf, ibuf , 2);
+                       break;
+               }
+               case(DW2102_VOLTAGE_CTRL): {
+                       u8 obuf[2];
+                       obuf[0] = 0x30;
+                       obuf[1] = msg[0].buf[0];
+                       ret = dw210x_op_rw(d->udev, 0xb2, 0, 0,
+                                       obuf, 2, DW210X_WRITE_MSG);
+                       break;
+               }
+               }
+
+               break;
+       }
+
+       mutex_unlock(&d->i2c_mutex);
+       return num;
+}
+
+static u32 dw210x_i2c_func(struct i2c_adapter *adapter)
 {
        return I2C_FUNC_I2C;
 }
 
 static struct i2c_algorithm dw2102_i2c_algo = {
        .master_xfer = dw2102_i2c_transfer,
-       .functionality = dw2102_i2c_func,
+       .functionality = dw210x_i2c_func,
+};
+
+static struct i2c_algorithm dw2102_serit_i2c_algo = {
+       .master_xfer = dw2102_serit_i2c_transfer,
+       .functionality = dw210x_i2c_func,
+};
+
+static struct i2c_algorithm dw2102_earda_i2c_algo = {
+       .master_xfer = dw2102_earda_i2c_transfer,
+       .functionality = dw210x_i2c_func,
+};
+
+static struct i2c_algorithm dw2104_i2c_algo = {
+       .master_xfer = dw2104_i2c_transfer,
+       .functionality = dw210x_i2c_func,
 };
 
-static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
+static int dw210x_read_mac_address(struct dvb_usb_device *d, u8 mac[6])
+{
+       int i;
+       u8 ibuf[] = {0, 0};
+       u8 eeprom[256], eepromline[16];
+
+       for (i = 0; i < 256; i++) {
+               if (dw210x_op_rw(d->udev, 0xb6, 0xa0 , i, ibuf, 2, DW210X_READ_MSG) < 0) {
+                       err("read eeprom failed.");
+                       return -1;
+               } else {
+                       eepromline[i%16] = ibuf[0];
+                       eeprom[i] = ibuf[0];
+               }
+               if ((i % 16) == 15) {
+                       deb_xfer("%02x: ", i - 15);
+                       debug_dump(eepromline, 16, deb_xfer);
+               }
+       }
+       memcpy(mac, eeprom + 8, 6);
+       return 0;
+};
+
+static int dw210x_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
 {
        static u8 command_13v[1] = {0x00};
        static u8 command_18v[1] = {0x01};
@@ -163,18 +422,66 @@ static int dw2102_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t voltage)
        return 0;
 }
 
-static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
+static struct cx24116_config dw2104_config = {
+       .demod_address = 0x55,
+       .mpg_clk_pos_pol = 0x01,
+};
+
+static struct si21xx_config serit_sp1511lhb_config = {
+       .demod_address = 0x68,
+       .min_delay_ms = 100,
+
+};
+
+static int dw2104_frontend_attach(struct dvb_usb_adapter *d)
 {
-       d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
-               &d->dev->i2c_adap);
-       if (d->fe != NULL) {
-               d->fe->ops.set_voltage = dw2102_set_voltage;
-               info("Attached stv0299!\n");
+       if ((d->fe = dvb_attach(cx24116_attach, &dw2104_config,
+                       &d->dev->i2c_adap)) != NULL) {
+               d->fe->ops.set_voltage = dw210x_set_voltage;
+               info("Attached cx24116!\n");
                return 0;
        }
        return -EIO;
 }
 
+static struct dvb_usb_device_properties dw2102_properties;
+
+static int dw2102_frontend_attach(struct dvb_usb_adapter *d)
+{
+       if (dw2102_properties.i2c_algo == &dw2102_serit_i2c_algo) {
+               /*dw2102_properties.adapter->tuner_attach = NULL;*/
+               d->fe = dvb_attach(si21xx_attach, &serit_sp1511lhb_config,
+                                       &d->dev->i2c_adap);
+               if (d->fe != NULL) {
+                       d->fe->ops.set_voltage = dw210x_set_voltage;
+                       info("Attached si21xx!\n");
+                       return 0;
+               }
+       }
+       if (dw2102_properties.i2c_algo == &dw2102_earda_i2c_algo) {
+               /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
+               d->fe = dvb_attach(stv0288_attach, &earda_config,
+                                       &d->dev->i2c_adap);
+               if (d->fe != NULL) {
+                       d->fe->ops.set_voltage = dw210x_set_voltage;
+                       info("Attached stv0288!\n");
+                       return 0;
+               }
+       }
+
+       if (dw2102_properties.i2c_algo == &dw2102_i2c_algo) {
+               /*dw2102_properties.adapter->tuner_attach = dw2102_tuner_attach;*/
+               d->fe = dvb_attach(stv0299_attach, &sharp_z0194a_config,
+                                       &d->dev->i2c_adap);
+               if (d->fe != NULL) {
+                       d->fe->ops.set_voltage = dw210x_set_voltage;
+                       info("Attached stv0299!\n");
+                       return 0;
+               }
+       }
+       return -EIO;
+}
+
 static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
 {
        dvb_attach(dvb_pll_attach, adap->fe, 0x60,
@@ -182,7 +489,15 @@ static int dw2102_tuner_attach(struct dvb_usb_adapter *adap)
        return 0;
 }
 
-static struct dvb_usb_rc_key dw2102_rc_keys[] = {
+static int dw2102_earda_tuner_attach(struct dvb_usb_adapter *adap)
+{
+       dvb_attach(stb6000_attach, adap->fe, 0x61,
+               &adap->dev->i2c_adap);
+
+       return 0;
+}
+
+static struct dvb_usb_rc_key dw210x_rc_keys[] = {
        { 0xf8, 0x0a, KEY_Q },          /*power*/
        { 0xf8, 0x0c, KEY_M },          /*mute*/
        { 0xf8, 0x11, KEY_1 },
@@ -221,7 +536,7 @@ static struct dvb_usb_rc_key dw2102_rc_keys[] = {
 
 static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 {
-       struct dw2102_state *st = d->priv;
+       struct dw210x_state *st = d->priv;
        u8 key[2];
        struct i2c_msg msg[] = {
                {.addr = DW2102_RC_QUERY, .flags = I2C_M_RD, .buf = key,
@@ -231,12 +546,12 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 
        *state = REMOTE_NO_KEY_PRESSED;
        if (dw2102_i2c_transfer(&d->i2c_adap, msg, 1) == 1) {
-               for (i = 0; i < ARRAY_SIZE(dw2102_rc_keys); i++) {
-                       if (dw2102_rc_keys[i].data == msg[0].buf[0]) {
+               for (i = 0; i < ARRAY_SIZE(dw210x_rc_keys); i++) {
+                       if (dw210x_rc_keys[i].data == msg[0].buf[0]) {
                                *state = REMOTE_KEY_PRESSED;
-                               *event = dw2102_rc_keys[i].event;
+                               *event = dw210x_rc_keys[i].event;
                                st->last_key_pressed =
-                                       dw2102_rc_keys[i].event;
+                                       dw210x_rc_keys[i].event;
                                break;
                        }
                st->last_key_pressed = 0;
@@ -249,6 +564,8 @@ static int dw2102_rc_query(struct dvb_usb_device *d, u32 *event, int *state)
 static struct usb_device_id dw2102_table[] = {
        {USB_DEVICE(USB_VID_CYPRESS, USB_PID_DW2102)},
        {USB_DEVICE(USB_VID_CYPRESS, 0x2101)},
+       {USB_DEVICE(USB_VID_CYPRESS, 0x2104)},
+       {USB_DEVICE(0x9022, 0xd650)},
        { }
 };
 
@@ -260,7 +577,7 @@ static int dw2102_load_firmware(struct usb_device *dev,
        u8 *b, *p;
        int ret = 0, i;
        u8 reset;
-       u8 reset16 [] = {0, 0, 0, 0, 0, 0, 0};
+       u8 reset16[] = {0, 0, 0, 0, 0, 0, 0};
        const struct firmware *fw;
        const char *filename = "dvb-usb-dw2101.fw";
        switch (dev->descriptor.idProduct) {
@@ -273,25 +590,23 @@ static int dw2102_load_firmware(struct usb_device *dev,
                        return ret;
                }
                break;
-       case USB_PID_DW2102:
+       default:
                fw = frmwr;
                break;
        }
-       info("start downloading DW2102 firmware");
+       info("start downloading DW210X firmware");
        p = kmalloc(fw->size, GFP_KERNEL);
        reset = 1;
        /*stop the CPU*/
-       dw2102_op_rw(dev, 0xa0, 0x7f92, &reset, 1, DW2102_WRITE_MSG);
-       dw2102_op_rw(dev, 0xa0, 0xe600, &reset, 1, DW2102_WRITE_MSG);
+       dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1, DW210X_WRITE_MSG);
+       dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1, DW210X_WRITE_MSG);
 
        if (p != NULL) {
                memcpy(p, fw->data, fw->size);
                for (i = 0; i < fw->size; i += 0x40) {
                        b = (u8 *) p + i;
-                       if (dw2102_op_rw
-                               (dev, 0xa0, i, b , 0x40,
-                                       DW2102_WRITE_MSG) != 0x40
-                               ) {
+                       if (dw210x_op_rw(dev, 0xa0, i, 0, b , 0x40,
+                                       DW210X_WRITE_MSG) != 0x40) {
                                err("error while transferring firmware");
                                ret = -EINVAL;
                                break;
@@ -299,43 +614,66 @@ static int dw2102_load_firmware(struct usb_device *dev,
                }
                /* restart the CPU */
                reset = 0;
-               if (ret || dw2102_op_rw
-                       (dev, 0xa0, 0x7f92, &reset, 1,
-                       DW2102_WRITE_MSG) != 1) {
+               if (ret || dw210x_op_rw(dev, 0xa0, 0x7f92, 0, &reset, 1,
+                                       DW210X_WRITE_MSG) != 1) {
                        err("could not restart the USB controller CPU.");
                        ret = -EINVAL;
                }
-               if (ret || dw2102_op_rw
-                       (dev, 0xa0, 0xe600, &reset, 1,
-                       DW2102_WRITE_MSG) != 1) {
+               if (ret || dw210x_op_rw(dev, 0xa0, 0xe600, 0, &reset, 1,
+                                       DW210X_WRITE_MSG) != 1) {
                        err("could not restart the USB controller CPU.");
                        ret = -EINVAL;
                }
                /* init registers */
                switch (dev->descriptor.idProduct) {
-               case USB_PID_DW2102:
-                       dw2102_op_rw
-                               (dev, 0xbf, 0x0040, &reset, 0,
-                               DW2102_WRITE_MSG);
-                       dw2102_op_rw
-                               (dev, 0xb9, 0x0000, &reset16[0], 2,
-                               DW2102_READ_MSG);
+               case USB_PID_DW2104:
+               case 0xd650:
+                       reset = 1;
+                       dw210x_op_rw(dev, 0xc4, 0x0000, 0, &reset, 1,
+                                       DW210X_WRITE_MSG);
+                       reset = 0;
+                       dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
+                                       DW210X_WRITE_MSG);
                        break;
+               case USB_PID_DW2102:
+                       dw210x_op_rw(dev, 0xbf, 0x0040, 0, &reset, 0,
+                                       DW210X_WRITE_MSG);
+                       dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
+                                       DW210X_READ_MSG);
+                       /* check STV0299 frontend  */
+                       dw210x_op_rw(dev, 0xb5, 0, 0, &reset16[0], 2,
+                                       DW210X_READ_MSG);
+                       if (reset16[0] == 0xa1) {
+                               dw2102_properties.i2c_algo = &dw2102_i2c_algo;
+                               dw2102_properties.adapter->tuner_attach = &dw2102_tuner_attach;
+                               break;
+                       } else {
+                               /* check STV0288 frontend  */
+                               reset16[0] = 0xd0;
+                               reset16[1] = 1;
+                               reset16[2] = 0;
+                               dw210x_op_rw(dev, 0xc2, 0, 0, &reset16[0], 3,
+                                               DW210X_WRITE_MSG);
+                               dw210x_op_rw(dev, 0xc3, 0xd1, 0, &reset16[0], 3,
+                                               DW210X_READ_MSG);
+                               if (reset16[2] == 0x11) {
+                                       dw2102_properties.i2c_algo = &dw2102_earda_i2c_algo;
+                                       dw2102_properties.adapter->tuner_attach = &dw2102_earda_tuner_attach;
+                                       break;
+                               }
+                       }
                case 0x2101:
-                       dw2102_op_rw
-                               (dev, 0xbc, 0x0030, &reset16[0], 2,
-                               DW2102_READ_MSG);
-                       dw2102_op_rw
-                               (dev, 0xba, 0x0000, &reset16[0], 7,
-                               DW2102_READ_MSG);
-                       dw2102_op_rw
-                               (dev, 0xba, 0x0000, &reset16[0], 7,
-                               DW2102_READ_MSG);
-                       dw2102_op_rw
-                               (dev, 0xb9, 0x0000, &reset16[0], 2,
-                               DW2102_READ_MSG);
+                       dw210x_op_rw(dev, 0xbc, 0x0030, 0, &reset16[0], 2,
+                                       DW210X_READ_MSG);
+                       dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
+                                       DW210X_READ_MSG);
+                       dw210x_op_rw(dev, 0xba, 0x0000, 0, &reset16[0], 7,
+                                       DW210X_READ_MSG);
+                       dw210x_op_rw(dev, 0xb9, 0x0000, 0, &reset16[0], 2,
+                                       DW210X_READ_MSG);
                        break;
                }
+               msleep(100);
                kfree(p);
        }
        return ret;
@@ -345,12 +683,12 @@ static struct dvb_usb_device_properties dw2102_properties = {
        .caps = DVB_USB_IS_AN_I2C_ADAPTER,
        .usb_ctrl = DEVICE_SPECIFIC,
        .firmware = "dvb-usb-dw2102.fw",
-       .size_of_priv = sizeof(struct dw2102_state),
+       .size_of_priv = sizeof(struct dw210x_state),
        .no_reconnect = 1,
 
-       .i2c_algo = &dw2102_i2c_algo,
-       .rc_key_map = dw2102_rc_keys,
-       .rc_key_map_size = ARRAY_SIZE(dw2102_rc_keys),
+       .i2c_algo = &dw2102_serit_i2c_algo,
+       .rc_key_map = dw210x_rc_keys,
+       .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
        .rc_interval = 150,
        .rc_query = dw2102_rc_query,
 
@@ -358,11 +696,12 @@ static struct dvb_usb_device_properties dw2102_properties = {
        /* parameter for the MPEG2-data transfer */
        .num_adapters = 1,
        .download_firmware = dw2102_load_firmware,
-       .adapter = {
+       .read_mac_address = dw210x_read_mac_address,
+               .adapter = {
                {
                        .frontend_attach = dw2102_frontend_attach,
                        .streaming_ctrl = NULL,
-                       .tuner_attach = dw2102_tuner_attach,
+                       .tuner_attach = NULL,
                        .stream = {
                                .type = USB_BULK,
                                .count = 8,
@@ -388,11 +727,64 @@ static struct dvb_usb_device_properties dw2102_properties = {
        }
 };
 
+static struct dvb_usb_device_properties dw2104_properties = {
+       .caps = DVB_USB_IS_AN_I2C_ADAPTER,
+       .usb_ctrl = DEVICE_SPECIFIC,
+       .firmware = "dvb-usb-dw2104.fw",
+       .size_of_priv = sizeof(struct dw210x_state),
+       .no_reconnect = 1,
+
+       .i2c_algo = &dw2104_i2c_algo,
+       .rc_key_map = dw210x_rc_keys,
+       .rc_key_map_size = ARRAY_SIZE(dw210x_rc_keys),
+       .rc_interval = 150,
+       .rc_query = dw2102_rc_query,
+
+       .generic_bulk_ctrl_endpoint = 0x81,
+       /* parameter for the MPEG2-data transfer */
+       .num_adapters = 1,
+       .download_firmware = dw2102_load_firmware,
+       .read_mac_address = dw210x_read_mac_address,
+       .adapter = {
+               {
+                       .frontend_attach = dw2104_frontend_attach,
+                       .streaming_ctrl = NULL,
+                       /*.tuner_attach = dw2104_tuner_attach,*/
+                       .stream = {
+                               .type = USB_BULK,
+                               .count = 8,
+                               .endpoint = 0x82,
+                               .u = {
+                                       .bulk = {
+                                               .buffersize = 4096,
+                                       }
+                               }
+                       },
+               }
+       },
+       .num_device_descs = 2,
+       .devices = {
+               { "DVBWorld DW2104 USB2.0",
+                       {&dw2102_table[2], NULL},
+                       {NULL},
+               },
+               { "TeVii S650 USB2.0",
+                       {&dw2102_table[3], NULL},
+                       {NULL},
+               },
+       }
+};
+
 static int dw2102_probe(struct usb_interface *intf,
                const struct usb_device_id *id)
 {
-       return dvb_usb_device_init(intf, &dw2102_properties,
-               THIS_MODULE, NULL, adapter_nr);
+       if (0 == dvb_usb_device_init(intf, &dw2102_properties,
+                       THIS_MODULE, NULL, adapter_nr) ||
+           0 == dvb_usb_device_init(intf, &dw2104_properties,
+                       THIS_MODULE, NULL, adapter_nr)) {
+               return 0;
+       }
+       return -ENODEV;
 }
 
 static struct usb_driver dw2102_driver = {
@@ -420,6 +812,6 @@ module_init(dw2102_module_init);
 module_exit(dw2102_module_exit);
 
 MODULE_AUTHOR("Igor M. Liplianin (c) liplianin@me.by");
-MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101 2102 USB2.0 device");
+MODULE_DESCRIPTION("Driver for DVBWorld DVB-S 2101, 2102, DVB-S2 2104 USB2.0 device");
 MODULE_VERSION("0.1");
 MODULE_LICENSE("GPL");
index 7a310f906837c9fdbe24ef822a9fea9f2fc51e2d..e3370734e95a2d625e736a8718de9d671ab759e1 100644 (file)
@@ -4,6 +4,5 @@
 #define DVB_USB_LOG_PREFIX "dw2102"
 #include "dvb-usb.h"
 
-extern int dvb_usb_dw2102_debug;
 #define deb_xfer(args...) dprintk(dvb_usb_dw2102_debug, 0x02, args)
 #endif
index 7dbb4a223c99829d0dbf88abf94d72ad5529ed6e..96b93e21a84bdbb6ddeb9ea2e3635b50ca0da149 100644 (file)
@@ -43,6 +43,20 @@ config DVB_S5H1420
        help
          A DVB-S tuner module. Say Y when you want to support this frontend.
 
+config DVB_STV0288
+       tristate "ST STV0288 based"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         A DVB-S tuner module. Say Y when you want to support this frontend.
+
+config DVB_STB6000
+       tristate "ST STB6000 silicon tuner"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+         help
+         A DVB-S silicon tuner module. Say Y when you want to support this tuner.
+
 config DVB_STV0299
        tristate "ST STV0299 based"
        depends on DVB_CORE && I2C
@@ -92,6 +106,20 @@ config DVB_TUA6100
        help
          A DVB-S PLL chip.
 
+config DVB_CX24116
+       tristate "Conexant CX24116 based"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         A DVB-S/S2 tuner module. Say Y when you want to support this frontend.
+
+config DVB_SI21XX
+       tristate "Silicon Labs SI21XX based"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         A DVB-S tuner module. Say Y when you want to support this frontend.
+
 comment "DVB-T (terrestrial) frontends"
        depends on DVB_CORE
 
@@ -385,4 +413,23 @@ config DVB_ISL6421
        help
          An SEC control chip.
 
+config DVB_LGS8GL5
+       tristate "Silicon Legend LGS-8GL5 demodulator (OFDM)"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         A DMB-TH tuner module. Say Y when you want to support this frontend.
+
+comment "Tools to develop new frontends"
+
+config DVB_DUMMY_FE
+       tristate "Dummy frontend driver"
+       default n
+
+config DVB_AF9013
+       tristate "Afatech AF9013 demodulator"
+       depends on DVB_CORE && I2C
+       default m if DVB_FE_CUSTOMISE
+       help
+         Say Y when you want to support this frontend.
 endmenu
index 028da55611c02cbad0c1b20404ad7326de2066e0..aba79f4a63a7217475079e694cb9fc4fbb052d34 100644 (file)
@@ -48,3 +48,10 @@ obj-$(CONFIG_DVB_TUNER_ITD1000) += itd1000.o
 obj-$(CONFIG_DVB_AU8522) += au8522.o
 obj-$(CONFIG_DVB_TDA10048) += tda10048.o
 obj-$(CONFIG_DVB_S5H1411) += s5h1411.o
+obj-$(CONFIG_DVB_LGS8GL5) += lgs8gl5.o
+obj-$(CONFIG_DVB_DUMMY_FE) += dvb_dummy_fe.o
+obj-$(CONFIG_DVB_AF9013) += af9013.o
+obj-$(CONFIG_DVB_CX24116) += cx24116.o
+obj-$(CONFIG_DVB_SI21XX) += si21xx.o
+obj-$(CONFIG_DVB_STV0288) += stv0288.o
+obj-$(CONFIG_DVB_STB6000) += stb6000.o
diff --git a/drivers/media/dvb/frontends/af9013.c b/drivers/media/dvb/frontends/af9013.c
new file mode 100644 (file)
index 0000000..21c1060
--- /dev/null
@@ -0,0 +1,1685 @@
+/*
+ * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
+ *
+ * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
+ *
+ * Thanks to Afatech who kindly provided information.
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/firmware.h>
+
+#include "dvb_frontend.h"
+#include "af9013_priv.h"
+#include "af9013.h"
+
+int af9013_debug;
+
+struct af9013_state {
+       struct i2c_adapter *i2c;
+       struct dvb_frontend frontend;
+
+       struct af9013_config config;
+
+       u16 signal_strength;
+       u32 ber;
+       u32 ucblocks;
+       u16 snr;
+       u32 frequency;
+       unsigned long next_statistics_check;
+};
+
+static u8 regmask[8] = { 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff };
+
+static int af9013_write_regs(struct af9013_state *state, u8 mbox, u16 reg,
+       u8 *val, u8 len)
+{
+       u8 buf[3+len];
+       struct i2c_msg msg = {
+               .addr = state->config.demod_address,
+               .flags = 0,
+               .len = sizeof(buf),
+               .buf = buf };
+
+       buf[0] = reg >> 8;
+       buf[1] = reg & 0xff;
+       buf[2] = mbox;
+       memcpy(&buf[3], val, len);
+
+       if (i2c_transfer(state->i2c, &msg, 1) != 1) {
+               warn("I2C write failed reg:%04x len:%d", reg, len);
+               return -EREMOTEIO;
+       }
+       return 0;
+}
+
+static int af9013_write_ofdm_regs(struct af9013_state *state, u16 reg, u8 *val,
+       u8 len)
+{
+       u8 mbox = (1 << 0)|(1 << 1)|((len - 1) << 2)|(0 << 6)|(0 << 7);
+       return af9013_write_regs(state, mbox, reg, val, len);
+}
+
+static int af9013_write_ofsm_regs(struct af9013_state *state, u16 reg, u8 *val,
+       u8 len)
+{
+       u8 mbox = (1 << 0)|(1 << 1)|((len - 1) << 2)|(1 << 6)|(1 << 7);
+       return af9013_write_regs(state, mbox, reg, val, len);
+}
+
+/* write single register */
+static int af9013_write_reg(struct af9013_state *state, u16 reg, u8 val)
+{
+       return af9013_write_ofdm_regs(state, reg, &val, 1);
+}
+
+/* read single register */
+static int af9013_read_reg(struct af9013_state *state, u16 reg, u8 *val)
+{
+       u8 obuf[3] = { reg >> 8, reg & 0xff, 0 };
+       u8 ibuf[1];
+       struct i2c_msg msg[2] = {
+               {
+                       .addr = state->config.demod_address,
+                       .flags = 0,
+                       .len = sizeof(obuf),
+                       .buf = obuf
+               }, {
+                       .addr = state->config.demod_address,
+                       .flags = I2C_M_RD,
+                       .len = sizeof(ibuf),
+                       .buf = ibuf
+               }
+       };
+
+       if (i2c_transfer(state->i2c, msg, 2) != 2) {
+               warn("I2C read failed reg:%04x", reg);
+               return -EREMOTEIO;
+       }
+       *val = ibuf[0];
+       return 0;
+}
+
+static int af9013_write_reg_bits(struct af9013_state *state, u16 reg, u8 pos,
+       u8 len, u8 val)
+{
+       int ret;
+       u8 tmp, mask;
+
+       ret = af9013_read_reg(state, reg, &tmp);
+       if (ret)
+               return ret;
+
+       mask = regmask[len - 1] << pos;
+       tmp = (tmp & ~mask) | ((val << pos) & mask);
+
+       return af9013_write_reg(state, reg, tmp);
+}
+
+static int af9013_read_reg_bits(struct af9013_state *state, u16 reg, u8 pos,
+       u8 len, u8 *val)
+{
+       int ret;
+       u8 tmp;
+
+       ret = af9013_read_reg(state, reg, &tmp);
+       if (ret)
+               return ret;
+       *val = (tmp >> pos) & regmask[len - 1];
+       return 0;
+}
+
+static int af9013_set_gpio(struct af9013_state *state, u8 gpio, u8 gpioval)
+{
+       int ret;
+       u8 pos;
+       u16 addr;
+       deb_info("%s: gpio:%d gpioval:%02x\n", __func__, gpio, gpioval);
+
+/* GPIO0 & GPIO1 0xd735
+   GPIO2 & GPIO3 0xd736 */
+
+       switch (gpio) {
+       case 0:
+       case 1:
+               addr = 0xd735;
+               break;
+       case 2:
+       case 3:
+               addr = 0xd736;
+               break;
+
+       default:
+               err("invalid gpio:%d\n", gpio);
+               ret = -EINVAL;
+               goto error;
+       };
+
+       switch (gpio) {
+       case 0:
+       case 2:
+               pos = 0;
+               break;
+       case 1:
+       case 3:
+       default:
+               pos = 4;
+               break;
+       };
+
+       ret = af9013_write_reg_bits(state, addr, pos, 4, gpioval);
+
+error:
+       return ret;
+}
+
+static u32 af913_div(u32 a, u32 b, u32 x)
+{
+       u32 r = 0, c = 0, i;
+       deb_info("%s: a:%d b:%d x:%d\n", __func__, a, b, x);
+
+       if (a > b) {
+               c = a / b;
+               a = a - c * b;
+       }
+
+       for (i = 0; i < x; i++) {
+               if (a >= b) {
+                       r += 1;
+                       a -= b;
+               }
+               a <<= 1;
+               r <<= 1;
+       }
+       r = (c << (u32)x) + r;
+
+       deb_info("%s: a:%d b:%d x:%d r:%d r:%x\n", __func__, a, b, x, r, r);
+       return r;
+}
+
+static int af9013_set_coeff(struct af9013_state *state, fe_bandwidth_t bw)
+{
+       int ret = 0;
+       u8 i = 0;
+       u8 buf[24];
+       u32 ns_coeff1_2048nu;
+       u32 ns_coeff1_8191nu;
+       u32 ns_coeff1_8192nu;
+       u32 ns_coeff1_8193nu;
+       u32 ns_coeff2_2k;
+       u32 ns_coeff2_8k;
+
+       deb_info("%s: adc_clock:%d bw:%d\n", __func__,
+               state->config.adc_clock, bw);
+
+       switch (state->config.adc_clock) {
+       case 28800: /* 28.800 MHz */
+               switch (bw) {
+               case BANDWIDTH_6_MHZ:
+                       ns_coeff1_2048nu = 0x01e79e7a;
+                       ns_coeff1_8191nu = 0x0079eb6e;
+                       ns_coeff1_8192nu = 0x0079e79e;
+                       ns_coeff1_8193nu = 0x0079e3cf;
+                       ns_coeff2_2k     = 0x00f3cf3d;
+                       ns_coeff2_8k     = 0x003cf3cf;
+                       break;
+               case BANDWIDTH_7_MHZ:
+                       ns_coeff1_2048nu = 0x0238e38e;
+                       ns_coeff1_8191nu = 0x008e3d55;
+                       ns_coeff1_8192nu = 0x008e38e4;
+                       ns_coeff1_8193nu = 0x008e3472;
+                       ns_coeff2_2k     = 0x011c71c7;
+                       ns_coeff2_8k     = 0x00471c72;
+                       break;
+               case BANDWIDTH_8_MHZ:
+                       ns_coeff1_2048nu = 0x028a28a3;
+                       ns_coeff1_8191nu = 0x00a28f3d;
+                       ns_coeff1_8192nu = 0x00a28a29;
+                       ns_coeff1_8193nu = 0x00a28514;
+                       ns_coeff2_2k     = 0x01451451;
+                       ns_coeff2_8k     = 0x00514514;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               break;
+       case 20480: /* 20.480 MHz */
+               switch (bw) {
+               case BANDWIDTH_6_MHZ:
+                       ns_coeff1_2048nu = 0x02adb6dc;
+                       ns_coeff1_8191nu = 0x00ab7313;
+                       ns_coeff1_8192nu = 0x00ab6db7;
+                       ns_coeff1_8193nu = 0x00ab685c;
+                       ns_coeff2_2k     = 0x0156db6e;
+                       ns_coeff2_8k     = 0x0055b6dc;
+                       break;
+               case BANDWIDTH_7_MHZ:
+                       ns_coeff1_2048nu = 0x03200001;
+                       ns_coeff1_8191nu = 0x00c80640;
+                       ns_coeff1_8192nu = 0x00c80000;
+                       ns_coeff1_8193nu = 0x00c7f9c0;
+                       ns_coeff2_2k     = 0x01900000;
+                       ns_coeff2_8k     = 0x00640000;
+                       break;
+               case BANDWIDTH_8_MHZ:
+                       ns_coeff1_2048nu = 0x03924926;
+                       ns_coeff1_8191nu = 0x00e4996e;
+                       ns_coeff1_8192nu = 0x00e49249;
+                       ns_coeff1_8193nu = 0x00e48b25;
+                       ns_coeff2_2k     = 0x01c92493;
+                       ns_coeff2_8k     = 0x00724925;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               break;
+       case 28000: /* 28.000 MHz */
+               switch (bw) {
+               case BANDWIDTH_6_MHZ:
+                       ns_coeff1_2048nu = 0x01f58d10;
+                       ns_coeff1_8191nu = 0x007d672f;
+                       ns_coeff1_8192nu = 0x007d6344;
+                       ns_coeff1_8193nu = 0x007d5f59;
+                       ns_coeff2_2k     = 0x00fac688;
+                       ns_coeff2_8k     = 0x003eb1a2;
+                       break;
+               case BANDWIDTH_7_MHZ:
+                       ns_coeff1_2048nu = 0x02492492;
+                       ns_coeff1_8191nu = 0x00924db7;
+                       ns_coeff1_8192nu = 0x00924925;
+                       ns_coeff1_8193nu = 0x00924492;
+                       ns_coeff2_2k     = 0x01249249;
+                       ns_coeff2_8k     = 0x00492492;
+                       break;
+               case BANDWIDTH_8_MHZ:
+                       ns_coeff1_2048nu = 0x029cbc15;
+                       ns_coeff1_8191nu = 0x00a7343f;
+                       ns_coeff1_8192nu = 0x00a72f05;
+                       ns_coeff1_8193nu = 0x00a729cc;
+                       ns_coeff2_2k     = 0x014e5e0a;
+                       ns_coeff2_8k     = 0x00539783;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               break;
+       case 25000: /* 25.000 MHz */
+               switch (bw) {
+               case BANDWIDTH_6_MHZ:
+                       ns_coeff1_2048nu = 0x0231bcb5;
+                       ns_coeff1_8191nu = 0x008c7391;
+                       ns_coeff1_8192nu = 0x008c6f2d;
+                       ns_coeff1_8193nu = 0x008c6aca;
+                       ns_coeff2_2k     = 0x0118de5b;
+                       ns_coeff2_8k     = 0x00463797;
+                       break;
+               case BANDWIDTH_7_MHZ:
+                       ns_coeff1_2048nu = 0x028f5c29;
+                       ns_coeff1_8191nu = 0x00a3dc29;
+                       ns_coeff1_8192nu = 0x00a3d70a;
+                       ns_coeff1_8193nu = 0x00a3d1ec;
+                       ns_coeff2_2k     = 0x0147ae14;
+                       ns_coeff2_8k     = 0x0051eb85;
+                       break;
+               case BANDWIDTH_8_MHZ:
+                       ns_coeff1_2048nu = 0x02ecfb9d;
+                       ns_coeff1_8191nu = 0x00bb44c1;
+                       ns_coeff1_8192nu = 0x00bb3ee7;
+                       ns_coeff1_8193nu = 0x00bb390d;
+                       ns_coeff2_2k     = 0x01767dce;
+                       ns_coeff2_8k     = 0x005d9f74;
+                       break;
+               default:
+                       ret = -EINVAL;
+               }
+               break;
+       default:
+               err("invalid xtal");
+               return -EINVAL;
+       }
+       if (ret) {
+               err("invalid bandwidth");
+               return ret;
+       }
+
+       buf[i++] = (u8) ((ns_coeff1_2048nu & 0x03000000) >> 24);
+       buf[i++] = (u8) ((ns_coeff1_2048nu & 0x00ff0000) >> 16);
+       buf[i++] = (u8) ((ns_coeff1_2048nu & 0x0000ff00) >> 8);
+       buf[i++] = (u8) ((ns_coeff1_2048nu & 0x000000ff));
+       buf[i++] = (u8) ((ns_coeff2_2k     & 0x01c00000) >> 22);
+       buf[i++] = (u8) ((ns_coeff2_2k     & 0x003fc000) >> 14);
+       buf[i++] = (u8) ((ns_coeff2_2k     & 0x00003fc0) >> 6);
+       buf[i++] = (u8) ((ns_coeff2_2k     & 0x0000003f));
+       buf[i++] = (u8) ((ns_coeff1_8191nu & 0x03000000) >> 24);
+       buf[i++] = (u8) ((ns_coeff1_8191nu & 0x00ffc000) >> 16);
+       buf[i++] = (u8) ((ns_coeff1_8191nu & 0x0000ff00) >> 8);
+       buf[i++] = (u8) ((ns_coeff1_8191nu & 0x000000ff));
+       buf[i++] = (u8) ((ns_coeff1_8192nu & 0x03000000) >> 24);
+       buf[i++] = (u8) ((ns_coeff1_8192nu & 0x00ffc000) >> 16);
+       buf[i++] = (u8) ((ns_coeff1_8192nu & 0x0000ff00) >> 8);
+       buf[i++] = (u8) ((ns_coeff1_8192nu & 0x000000ff));
+       buf[i++] = (u8) ((ns_coeff1_8193nu & 0x03000000) >> 24);
+       buf[i++] = (u8) ((ns_coeff1_8193nu & 0x00ffc000) >> 16);
+       buf[i++] = (u8) ((ns_coeff1_8193nu & 0x0000ff00) >> 8);
+       buf[i++] = (u8) ((ns_coeff1_8193nu & 0x000000ff));
+       buf[i++] = (u8) ((ns_coeff2_8k     & 0x01c00000) >> 22);
+       buf[i++] = (u8) ((ns_coeff2_8k     & 0x003fc000) >> 14);
+       buf[i++] = (u8) ((ns_coeff2_8k     & 0x00003fc0) >> 6);
+       buf[i++] = (u8) ((ns_coeff2_8k     & 0x0000003f));
+
+       deb_info("%s: coeff:", __func__);
+       debug_dump(buf, sizeof(buf), deb_info);
+
+       /* program */
+       for (i = 0; i < sizeof(buf); i++) {
+               ret = af9013_write_reg(state, 0xae00 + i, buf[i]);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
+static int af9013_set_adc_ctrl(struct af9013_state *state)
+{
+       int ret;
+       u8 buf[3], tmp, i;
+       u32 adc_cw;
+
+       deb_info("%s: adc_clock:%d\n", __func__, state->config.adc_clock);
+
+       /* adc frequency type */
+       switch (state->config.adc_clock) {
+       case 28800: /* 28.800 MHz */
+               tmp = 0;
+               break;
+       case 20480: /* 20.480 MHz */
+               tmp = 1;
+               break;
+       case 28000: /* 28.000 MHz */
+               tmp = 2;
+               break;
+       case 25000: /* 25.000 MHz */
+               tmp = 3;
+               break;
+       default:
+               err("invalid xtal");
+               return -EINVAL;
+       }
+
+       adc_cw = af913_div(state->config.adc_clock*1000, 1000000ul, 19ul);
+
+       buf[0] = (u8) ((adc_cw & 0x000000ff));
+       buf[1] = (u8) ((adc_cw & 0x0000ff00) >> 8);
+       buf[2] = (u8) ((adc_cw & 0x00ff0000) >> 16);
+
+       deb_info("%s: adc_cw:", __func__);
+       debug_dump(buf, sizeof(buf), deb_info);
+
+       /* program */
+       for (i = 0; i < sizeof(buf); i++) {
+               ret = af9013_write_reg(state, 0xd180 + i, buf[i]);
+               if (ret)
+                       goto error;
+       }
+       ret = af9013_write_reg_bits(state, 0x9bd2, 0, 4, tmp);
+error:
+       return ret;
+}
+
+static int af9013_set_freq_ctrl(struct af9013_state *state, fe_bandwidth_t bw)
+{
+       int ret;
+       u16 addr;
+       u8 buf[3], i, j;
+       u32 adc_freq, freq_cw;
+       s8 bfs_spec_inv;
+       int if_sample_freq;
+
+       for (j = 0; j < 3; j++) {
+               if (j == 0) {
+                       addr = 0xd140; /* fcw normal */
+                       bfs_spec_inv = state->config.rf_spec_inv ? -1 : 1;
+               } else if (j == 1) {
+                       addr = 0x9be7; /* fcw dummy ram */
+                       bfs_spec_inv = state->config.rf_spec_inv ? -1 : 1;
+               } else {
+                       addr = 0x9bea; /* fcw inverted */
+                       bfs_spec_inv = state->config.rf_spec_inv ? 1 : -1;
+               }
+
+               adc_freq       = state->config.adc_clock * 1000;
+               if_sample_freq = state->config.tuner_if * 1000;
+
+               /* TDA18271 uses different sampling freq for every bw */
+               if (state->config.tuner == AF9013_TUNER_TDA18271) {
+                       switch (bw) {
+                       case BANDWIDTH_6_MHZ:
+                               if_sample_freq = 3300000; /* 3.3 MHz */
+                               break;
+                       case BANDWIDTH_7_MHZ:
+                               if_sample_freq = 3800000; /* 3.8 MHz */
+                               break;
+                       case BANDWIDTH_8_MHZ:
+                       default:
+                               if_sample_freq = 4300000; /* 4.3 MHz */
+                               break;
+                       }
+               }
+
+               while (if_sample_freq > (adc_freq / 2))
+                       if_sample_freq = if_sample_freq - adc_freq;
+
+               if (if_sample_freq >= 0)
+                       bfs_spec_inv = bfs_spec_inv * (-1);
+               else
+                       if_sample_freq = if_sample_freq * (-1);
+
+               freq_cw = af913_div(if_sample_freq, adc_freq, 23ul);
+
+               if (bfs_spec_inv == -1)
+                       freq_cw = 0x00800000 - freq_cw;
+
+               buf[0] = (u8) ((freq_cw & 0x000000ff));
+               buf[1] = (u8) ((freq_cw & 0x0000ff00) >> 8);
+               buf[2] = (u8) ((freq_cw & 0x007f0000) >> 16);
+
+
+               deb_info("%s: freq_cw:", __func__);
+               debug_dump(buf, sizeof(buf), deb_info);
+
+               /* program */
+               for (i = 0; i < sizeof(buf); i++) {
+                       ret = af9013_write_reg(state, addr++, buf[i]);
+                       if (ret)
+                               goto error;
+               }
+       }
+error:
+       return ret;
+}
+
+static int af9013_set_ofdm_params(struct af9013_state *state,
+       struct dvb_ofdm_parameters *params, u8 *auto_mode)
+{
+       int ret;
+       u8 i, buf[3] = {0, 0, 0};
+       *auto_mode = 0; /* set if parameters are requested to auto set */
+
+       switch (params->transmission_mode) {
+       case TRANSMISSION_MODE_AUTO:
+               *auto_mode = 1;
+       case TRANSMISSION_MODE_2K:
+               break;
+       case TRANSMISSION_MODE_8K:
+               buf[0] |= (1 << 0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (params->guard_interval) {
+       case GUARD_INTERVAL_AUTO:
+               *auto_mode = 1;
+       case GUARD_INTERVAL_1_32:
+               break;
+       case GUARD_INTERVAL_1_16:
+               buf[0] |= (1 << 2);
+               break;
+       case GUARD_INTERVAL_1_8:
+               buf[0] |= (2 << 2);
+               break;
+       case GUARD_INTERVAL_1_4:
+               buf[0] |= (3 << 2);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (params->hierarchy_information) {
+       case HIERARCHY_AUTO:
+               *auto_mode = 1;
+       case HIERARCHY_NONE:
+               break;
+       case HIERARCHY_1:
+               buf[0] |= (1 << 4);
+               break;
+       case HIERARCHY_2:
+               buf[0] |= (2 << 4);
+               break;
+       case HIERARCHY_4:
+               buf[0] |= (3 << 4);
+               break;
+       default:
+               return -EINVAL;
+       };
+
+       switch (params->constellation) {
+       case QAM_AUTO:
+               *auto_mode = 1;
+       case QPSK:
+               break;
+       case QAM_16:
+               buf[1] |= (1 << 6);
+               break;
+       case QAM_64:
+               buf[1] |= (2 << 6);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* Use HP. How and which case we can switch to LP? */
+       buf[1] |= (1 << 4);
+
+       switch (params->code_rate_HP) {
+       case FEC_AUTO:
+               *auto_mode = 1;
+       case FEC_1_2:
+               break;
+       case FEC_2_3:
+               buf[2] |= (1 << 0);
+               break;
+       case FEC_3_4:
+               buf[2] |= (2 << 0);
+               break;
+       case FEC_5_6:
+               buf[2] |= (3 << 0);
+               break;
+       case FEC_7_8:
+               buf[2] |= (4 << 0);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (params->code_rate_LP) {
+       case FEC_AUTO:
+       /* if HIERARCHY_NONE and FEC_NONE then LP FEC is set to FEC_AUTO
+          by dvb_frontend.c for compatibility */
+               if (params->hierarchy_information != HIERARCHY_NONE)
+                       *auto_mode = 1;
+       case FEC_1_2:
+               break;
+       case FEC_2_3:
+               buf[2] |= (1 << 3);
+               break;
+       case FEC_3_4:
+               buf[2] |= (2 << 3);
+               break;
+       case FEC_5_6:
+               buf[2] |= (3 << 3);
+               break;
+       case FEC_7_8:
+               buf[2] |= (4 << 3);
+               break;
+       case FEC_NONE:
+               if (params->hierarchy_information == HIERARCHY_AUTO)
+                       break;
+       default:
+               return -EINVAL;
+       }
+
+       switch (params->bandwidth) {
+       case BANDWIDTH_6_MHZ:
+               break;
+       case BANDWIDTH_7_MHZ:
+               buf[1] |= (1 << 2);
+               break;
+       case BANDWIDTH_8_MHZ:
+               buf[1] |= (2 << 2);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* program */
+       for (i = 0; i < sizeof(buf); i++) {
+               ret = af9013_write_reg(state, 0xd3c0 + i, buf[i]);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+
+static int af9013_reset(struct af9013_state *state, u8 sleep)
+{
+       int ret;
+       u8 tmp, i;
+       deb_info("%s\n", __func__);
+
+       /* enable OFDM reset */
+       ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 1);
+       if (ret)
+               goto error;
+
+       /* start reset mechanism */
+       ret = af9013_write_reg(state, 0xaeff, 1);
+       if (ret)
+               goto error;
+
+       /* reset is done when bit 1 is set */
+       for (i = 0; i < 150; i++) {
+               ret = af9013_read_reg_bits(state, 0xd417, 1, 1, &tmp);
+               if (ret)
+                       goto error;
+               if (tmp)
+                       break; /* reset done */
+               msleep(10);
+       }
+       if (!tmp)
+               return -ETIMEDOUT;
+
+       /* don't clear reset when going to sleep */
+       if (!sleep) {
+               /* clear OFDM reset */
+               ret = af9013_write_reg_bits(state, 0xd417, 1, 1, 0);
+               if (ret)
+                       goto error;
+
+               /* disable OFDM reset */
+               ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 0);
+       }
+error:
+       return ret;
+}
+
+static int af9013_power_ctrl(struct af9013_state *state, u8 onoff)
+{
+       int ret;
+       deb_info("%s: onoff:%d\n", __func__, onoff);
+
+       if (onoff) {
+               /* power on */
+               ret = af9013_write_reg_bits(state, 0xd73a, 3, 1, 0);
+               if (ret)
+                       goto error;
+               ret = af9013_write_reg_bits(state, 0xd417, 1, 1, 0);
+               if (ret)
+                       goto error;
+               ret = af9013_write_reg_bits(state, 0xd417, 4, 1, 0);
+       } else {
+               /* power off */
+               ret = af9013_reset(state, 1);
+               if (ret)
+                       goto error;
+               ret = af9013_write_reg_bits(state, 0xd73a, 3, 1, 1);
+       }
+error:
+       return ret;
+}
+
+static int af9013_lock_led(struct af9013_state *state, u8 onoff)
+{
+       deb_info("%s: onoff:%d\n", __func__, onoff);
+
+       return af9013_write_reg_bits(state, 0xd730, 0, 1, onoff);
+}
+
+static int af9013_set_frontend(struct dvb_frontend *fe,
+       struct dvb_frontend_parameters *params)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       u8 auto_mode; /* auto set TPS */
+
+       deb_info("%s: freq:%d bw:%d\n", __func__, params->frequency,
+               params->u.ofdm.bandwidth);
+
+       state->frequency = params->frequency;
+
+       /* program CFOE coefficients */
+       ret = af9013_set_coeff(state, params->u.ofdm.bandwidth);
+       if (ret)
+               goto error;
+
+       /* program frequency control */
+       ret = af9013_set_freq_ctrl(state, params->u.ofdm.bandwidth);
+       if (ret)
+               goto error;
+
+       /* clear TPS lock flag (inverted flag) */
+       ret = af9013_write_reg_bits(state, 0xd330, 3, 1, 1);
+       if (ret)
+               goto error;
+
+       /* clear MPEG2 lock flag */
+       ret = af9013_write_reg_bits(state, 0xd507, 6, 1, 0);
+       if (ret)
+               goto error;
+
+       /* empty channel function */
+       ret = af9013_write_reg_bits(state, 0x9bfe, 0, 1, 0);
+       if (ret)
+               goto error;
+
+       /* empty DVB-T channel function */
+       ret = af9013_write_reg_bits(state, 0x9bc2, 0, 1, 0);
+       if (ret)
+               goto error;
+
+       /* program tuner */
+       if (fe->ops.tuner_ops.set_params)
+               fe->ops.tuner_ops.set_params(fe, params);
+
+       /* program TPS and bandwidth, check if auto mode needed */
+       ret = af9013_set_ofdm_params(state, &params->u.ofdm, &auto_mode);
+       if (ret)
+               goto error;
+
+       if (auto_mode) {
+               /* clear easy mode flag */
+               ret = af9013_write_reg(state, 0xaefd, 0);
+               deb_info("%s: auto TPS\n", __func__);
+       } else {
+               /* set easy mode flag */
+               ret = af9013_write_reg(state, 0xaefd, 1);
+               if (ret)
+                       goto error;
+               ret = af9013_write_reg(state, 0xaefe, 0);
+               deb_info("%s: manual TPS\n", __func__);
+       }
+       if (ret)
+               goto error;
+
+       /* everything is set, lets try to receive channel - OFSM GO! */
+       ret = af9013_write_reg(state, 0xffff, 0);
+       if (ret)
+               goto error;
+
+error:
+       return ret;
+}
+
+static int af9013_get_frontend(struct dvb_frontend *fe,
+       struct dvb_frontend_parameters *p)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       u8 i, buf[3];
+       deb_info("%s\n", __func__);
+
+       /* read TPS registers */
+       for (i = 0; i < 3; i++) {
+               ret = af9013_read_reg(state, 0xd3c0 + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+
+       switch ((buf[1] >> 6) & 3) {
+       case 0:
+               p->u.ofdm.constellation = QPSK;
+               break;
+       case 1:
+               p->u.ofdm.constellation = QAM_16;
+               break;
+       case 2:
+               p->u.ofdm.constellation = QAM_64;
+               break;
+       }
+
+       switch ((buf[0] >> 0) & 3) {
+       case 0:
+               p->u.ofdm.transmission_mode = TRANSMISSION_MODE_2K;
+               break;
+       case 1:
+               p->u.ofdm.transmission_mode = TRANSMISSION_MODE_8K;
+       }
+
+       switch ((buf[0] >> 2) & 3) {
+       case 0:
+               p->u.ofdm.guard_interval = GUARD_INTERVAL_1_32;
+               break;
+       case 1:
+               p->u.ofdm.guard_interval = GUARD_INTERVAL_1_16;
+               break;
+       case 2:
+               p->u.ofdm.guard_interval = GUARD_INTERVAL_1_8;
+               break;
+       case 3:
+               p->u.ofdm.guard_interval = GUARD_INTERVAL_1_4;
+               break;
+       }
+
+       switch ((buf[0] >> 4) & 7) {
+       case 0:
+               p->u.ofdm.hierarchy_information = HIERARCHY_NONE;
+               break;
+       case 1:
+               p->u.ofdm.hierarchy_information = HIERARCHY_1;
+               break;
+       case 2:
+               p->u.ofdm.hierarchy_information = HIERARCHY_2;
+               break;
+       case 3:
+               p->u.ofdm.hierarchy_information = HIERARCHY_4;
+               break;
+       }
+
+       switch ((buf[2] >> 0) & 7) {
+       case 0:
+               p->u.ofdm.code_rate_HP = FEC_1_2;
+               break;
+       case 1:
+               p->u.ofdm.code_rate_HP = FEC_2_3;
+               break;
+       case 2:
+               p->u.ofdm.code_rate_HP = FEC_3_4;
+               break;
+       case 3:
+               p->u.ofdm.code_rate_HP = FEC_5_6;
+               break;
+       case 4:
+               p->u.ofdm.code_rate_HP = FEC_7_8;
+               break;
+       }
+
+       switch ((buf[2] >> 3) & 7) {
+       case 0:
+               p->u.ofdm.code_rate_LP = FEC_1_2;
+               break;
+       case 1:
+               p->u.ofdm.code_rate_LP = FEC_2_3;
+               break;
+       case 2:
+               p->u.ofdm.code_rate_LP = FEC_3_4;
+               break;
+       case 3:
+               p->u.ofdm.code_rate_LP = FEC_5_6;
+               break;
+       case 4:
+               p->u.ofdm.code_rate_LP = FEC_7_8;
+               break;
+       }
+
+       switch ((buf[1] >> 2) & 3) {
+       case 0:
+               p->u.ofdm.bandwidth = BANDWIDTH_6_MHZ;
+               break;
+       case 1:
+               p->u.ofdm.bandwidth = BANDWIDTH_7_MHZ;
+               break;
+       case 2:
+               p->u.ofdm.bandwidth = BANDWIDTH_8_MHZ;
+               break;
+       }
+
+       p->inversion = INVERSION_AUTO;
+       p->frequency = state->frequency;
+
+error:
+       return ret;
+}
+
+static int af9013_update_ber_unc(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       u8 buf[3], i;
+       u32 error_bit_count = 0;
+       u32 total_bit_count = 0;
+       u32 abort_packet_count = 0;
+
+       state->ber = 0;
+
+       /* check if error bit count is ready */
+       ret = af9013_read_reg_bits(state, 0xd391, 4, 1, &buf[0]);
+       if (ret)
+               goto error;
+       if (!buf[0])
+               goto exit;
+
+       /* get RSD packet abort count */
+       for (i = 0; i < 2; i++) {
+               ret = af9013_read_reg(state, 0xd38a + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+       abort_packet_count = (buf[1] << 8) + buf[0];
+
+       /* get error bit count */
+       for (i = 0; i < 3; i++) {
+               ret = af9013_read_reg(state, 0xd387 + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+       error_bit_count = (buf[2] << 16) + (buf[1] << 8) + buf[0];
+       error_bit_count = error_bit_count - abort_packet_count * 8 * 8;
+
+       /* get used RSD counting period (10000 RSD packets used) */
+       for (i = 0; i < 2; i++) {
+               ret = af9013_read_reg(state, 0xd385 + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+       total_bit_count = (buf[1] << 8) + buf[0];
+       total_bit_count = total_bit_count - abort_packet_count;
+       total_bit_count = total_bit_count * 204 * 8;
+
+       if (total_bit_count)
+               state->ber = error_bit_count * 1000000000 / total_bit_count;
+
+       state->ucblocks += abort_packet_count;
+
+       deb_info("%s: err bits:%d total bits:%d abort count:%d\n", __func__,
+               error_bit_count, total_bit_count, abort_packet_count);
+
+       /* set BER counting range */
+       ret = af9013_write_reg(state, 0xd385, 10000 & 0xff);
+       if (ret)
+               goto error;
+       ret = af9013_write_reg(state, 0xd386, 10000 >> 8);
+       if (ret)
+               goto error;
+       /* reset and start BER counter */
+       ret = af9013_write_reg_bits(state, 0xd391, 4, 1, 1);
+       if (ret)
+               goto error;
+
+exit:
+error:
+       return ret;
+}
+
+static int af9013_update_snr(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       u8 buf[3], i, len;
+       u32 quant = 0;
+       struct snr_table *snr_table;
+
+       /* check if quantizer ready (for snr) */
+       ret = af9013_read_reg_bits(state, 0xd2e1, 3, 1, &buf[0]);
+       if (ret)
+               goto error;
+       if (buf[0]) {
+               /* quantizer ready - read it */
+               for (i = 0; i < 3; i++) {
+                       ret = af9013_read_reg(state, 0xd2e3 + i, &buf[i]);
+                       if (ret)
+                               goto error;
+               }
+               quant = (buf[2] << 16) + (buf[1] << 8) + buf[0];
+
+               /* read current constellation */
+               ret = af9013_read_reg(state, 0xd3c1, &buf[0]);
+               if (ret)
+                       goto error;
+
+               switch ((buf[0] >> 6) & 3) {
+               case 0:
+                       len = ARRAY_SIZE(qpsk_snr_table);
+                       snr_table = qpsk_snr_table;
+                       break;
+               case 1:
+                       len = ARRAY_SIZE(qam16_snr_table);
+                       snr_table = qam16_snr_table;
+                       break;
+               case 2:
+                       len = ARRAY_SIZE(qam64_snr_table);
+                       snr_table = qam64_snr_table;
+                       break;
+               default:
+                       len = 0;
+                       break;
+               }
+
+               if (len) {
+                       for (i = 0; i < len; i++) {
+                               if (quant < snr_table[i].val) {
+                                       state->snr = snr_table[i].snr * 10;
+                                       break;
+                               }
+                       }
+               }
+
+               /* set quantizer super frame count */
+               ret = af9013_write_reg(state, 0xd2e2, 1);
+               if (ret)
+                       goto error;
+
+               /* check quantizer availability */
+               for (i = 0; i < 10; i++) {
+                       msleep(10);
+                       ret = af9013_read_reg_bits(state, 0xd2e6, 0, 1,
+                               &buf[0]);
+                       if (ret)
+                               goto error;
+                       if (!buf[0])
+                               break;
+               }
+
+               /* reset quantizer */
+               ret = af9013_write_reg_bits(state, 0xd2e1, 3, 1, 1);
+               if (ret)
+                       goto error;
+       }
+
+error:
+       return ret;
+}
+
+static int af9013_update_signal_strength(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       u8 tmp0;
+       u8 rf_gain, rf_50, rf_80, if_gain, if_50, if_80;
+       int signal_strength;
+
+       deb_info("%s\n", __func__);
+
+       state->signal_strength = 0;
+
+       ret = af9013_read_reg_bits(state, 0x9bee, 0, 1, &tmp0);
+       if (ret)
+               goto error;
+       if (tmp0) {
+               ret = af9013_read_reg(state, 0x9bbd, &rf_50);
+               if (ret)
+                       goto error;
+               ret = af9013_read_reg(state, 0x9bd0, &rf_80);
+               if (ret)
+                       goto error;
+               ret = af9013_read_reg(state, 0x9be2, &if_50);
+               if (ret)
+                       goto error;
+               ret = af9013_read_reg(state, 0x9be4, &if_80);
+               if (ret)
+                       goto error;
+               ret = af9013_read_reg(state, 0xd07c, &rf_gain);
+               if (ret)
+                       goto error;
+               ret = af9013_read_reg(state, 0xd07d, &if_gain);
+               if (ret)
+                       goto error;
+               signal_strength = (0xffff / (9 * (rf_50 + if_50) - \
+                       11 * (rf_80 + if_80))) * (10 * (rf_gain + if_gain) - \
+                       11 * (rf_80 + if_80));
+               if (signal_strength < 0)
+                       signal_strength = 0;
+               else if (signal_strength > 0xffff)
+                       signal_strength = 0xffff;
+
+               state->signal_strength = signal_strength;
+       }
+
+error:
+       return ret;
+}
+
+static int af9013_update_statistics(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+
+       if (time_before(jiffies, state->next_statistics_check))
+               return 0;
+
+       /* set minimum statistic update interval */
+       state->next_statistics_check = jiffies + msecs_to_jiffies(1200);
+
+       ret = af9013_update_signal_strength(fe);
+       if (ret)
+               goto error;
+       ret = af9013_update_snr(fe);
+       if (ret)
+               goto error;
+       ret = af9013_update_ber_unc(fe);
+       if (ret)
+               goto error;
+
+error:
+       return ret;
+}
+
+static int af9013_get_tune_settings(struct dvb_frontend *fe,
+       struct dvb_frontend_tune_settings *fesettings)
+{
+       fesettings->min_delay_ms = 800;
+       fesettings->step_size = 0;
+       fesettings->max_drift = 0;
+
+       return 0;
+}
+
+static int af9013_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret = 0;
+       u8 tmp;
+       *status = 0;
+
+       /* TPS lock */
+       ret = af9013_read_reg_bits(state, 0xd330, 3, 1, &tmp);
+       if (ret)
+               goto error;
+       if (tmp)
+               *status |= FE_HAS_VITERBI | FE_HAS_CARRIER | FE_HAS_SIGNAL;
+
+       /* MPEG2 lock */
+       ret = af9013_read_reg_bits(state, 0xd507, 6, 1, &tmp);
+       if (ret)
+               goto error;
+       if (tmp)
+               *status |= FE_HAS_SYNC | FE_HAS_LOCK;
+
+       if (!*status & FE_HAS_SIGNAL) {
+               /* AGC lock */
+               ret = af9013_read_reg_bits(state, 0xd1a0, 6, 1, &tmp);
+               if (ret)
+                       goto error;
+               if (tmp)
+                       *status |= FE_HAS_SIGNAL;
+       }
+
+       if (!*status & FE_HAS_CARRIER) {
+               /* CFO lock */
+               ret = af9013_read_reg_bits(state, 0xd333, 7, 1, &tmp);
+               if (ret)
+                       goto error;
+               if (tmp)
+                       *status |= FE_HAS_CARRIER;
+       }
+
+       if (!*status & FE_HAS_CARRIER) {
+               /* SFOE lock */
+               ret = af9013_read_reg_bits(state, 0xd334, 6, 1, &tmp);
+               if (ret)
+                       goto error;
+               if (tmp)
+                       *status |= FE_HAS_CARRIER;
+       }
+
+       ret = af9013_update_statistics(fe);
+
+error:
+       return ret;
+}
+
+
+static int af9013_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       ret = af9013_update_statistics(fe);
+       *ber = state->ber;
+       return ret;
+}
+
+static int af9013_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       ret = af9013_update_statistics(fe);
+       *strength = state->signal_strength;
+       return ret;
+}
+
+static int af9013_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       ret = af9013_update_statistics(fe);
+       *snr = state->snr;
+       return ret;
+}
+
+static int af9013_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       ret = af9013_update_statistics(fe);
+       *ucblocks = state->ucblocks;
+       return ret;
+}
+
+static int af9013_sleep(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret;
+       deb_info("%s\n", __func__);
+
+       ret = af9013_lock_led(state, 0);
+       if (ret)
+               goto error;
+
+       ret = af9013_power_ctrl(state, 0);
+error:
+       return ret;
+}
+
+static int af9013_init(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       int ret, i, len;
+       u8 tmp0, tmp1;
+       struct regdesc *init;
+       deb_info("%s\n", __func__);
+
+       /* reset OFDM */
+       ret = af9013_reset(state, 0);
+       if (ret)
+               goto error;
+
+       /* power on */
+       ret = af9013_power_ctrl(state, 1);
+       if (ret)
+               goto error;
+
+       /* enable ADC */
+       ret = af9013_write_reg(state, 0xd73a, 0xa4);
+       if (ret)
+               goto error;
+
+       /* write API version to firmware */
+       for (i = 0; i < sizeof(state->config.api_version); i++) {
+               ret = af9013_write_reg(state, 0x9bf2 + i,
+                       state->config.api_version[i]);
+               if (ret)
+                       goto error;
+       }
+
+       /* program ADC control */
+       ret = af9013_set_adc_ctrl(state);
+       if (ret)
+               goto error;
+
+       /* set I2C master clock */
+       ret = af9013_write_reg(state, 0xd416, 0x14);
+       if (ret)
+               goto error;
+
+       /* set 16 embx */
+       ret = af9013_write_reg_bits(state, 0xd700, 1, 1, 1);
+       if (ret)
+               goto error;
+
+       /* set no trigger */
+       ret = af9013_write_reg_bits(state, 0xd700, 2, 1, 0);
+       if (ret)
+               goto error;
+
+       /* set read-update bit for constellation */
+       ret = af9013_write_reg_bits(state, 0xd371, 1, 1, 1);
+       if (ret)
+               goto error;
+
+       /* enable FEC monitor */
+       ret = af9013_write_reg_bits(state, 0xd392, 1, 1, 1);
+       if (ret)
+               goto error;
+
+       /* load OFSM settings */
+       deb_info("%s: load ofsm settings\n", __func__);
+       len = ARRAY_SIZE(ofsm_init);
+       init = ofsm_init;
+       for (i = 0; i < len; i++) {
+               ret = af9013_write_reg_bits(state, init[i].addr, init[i].pos,
+                       init[i].len, init[i].val);
+               if (ret)
+                       goto error;
+       }
+
+       /* load tuner specific settings */
+       deb_info("%s: load tuner specific settings\n", __func__);
+       switch (state->config.tuner) {
+       case AF9013_TUNER_MXL5003D:
+               len = ARRAY_SIZE(tuner_init_mxl5003d);
+               init = tuner_init_mxl5003d;
+               break;
+       case AF9013_TUNER_MXL5005D:
+       case AF9013_TUNER_MXL5005R:
+               len = ARRAY_SIZE(tuner_init_mxl5005);
+               init = tuner_init_mxl5005;
+               break;
+       case AF9013_TUNER_ENV77H11D5:
+               len = ARRAY_SIZE(tuner_init_env77h11d5);
+               init = tuner_init_env77h11d5;
+               break;
+       case AF9013_TUNER_MT2060:
+               len = ARRAY_SIZE(tuner_init_mt2060);
+               init = tuner_init_mt2060;
+               break;
+       case AF9013_TUNER_MC44S803:
+               len = ARRAY_SIZE(tuner_init_mc44s803);
+               init = tuner_init_mc44s803;
+               break;
+       case AF9013_TUNER_QT1010:
+       case AF9013_TUNER_QT1010A:
+               len = ARRAY_SIZE(tuner_init_qt1010);
+               init = tuner_init_qt1010;
+               break;
+       case AF9013_TUNER_MT2060_2:
+               len = ARRAY_SIZE(tuner_init_mt2060_2);
+               init = tuner_init_mt2060_2;
+               break;
+       case AF9013_TUNER_TDA18271:
+               len = ARRAY_SIZE(tuner_init_tda18271);
+               init = tuner_init_tda18271;
+               break;
+       case AF9013_TUNER_UNKNOWN:
+       default:
+               len = ARRAY_SIZE(tuner_init_unknown);
+               init = tuner_init_unknown;
+               break;
+       }
+
+       for (i = 0; i < len; i++) {
+               ret = af9013_write_reg_bits(state, init[i].addr, init[i].pos,
+                       init[i].len, init[i].val);
+               if (ret)
+                       goto error;
+       }
+
+       /* set TS mode */
+       deb_info("%s: setting ts mode\n", __func__);
+       tmp0 = 0; /* parallel mode */
+       tmp1 = 0; /* serial mode */
+       switch (state->config.output_mode) {
+       case AF9013_OUTPUT_MODE_PARALLEL:
+               tmp0 = 1;
+               break;
+       case AF9013_OUTPUT_MODE_SERIAL:
+               tmp1 = 1;
+               break;
+       case AF9013_OUTPUT_MODE_USB:
+               /* usb mode for AF9015 */
+       default:
+               break;
+       }
+       ret = af9013_write_reg_bits(state, 0xd500, 1, 1, tmp0); /* parallel */
+       if (ret)
+               goto error;
+       ret = af9013_write_reg_bits(state, 0xd500, 2, 1, tmp1); /* serial */
+       if (ret)
+               goto error;
+
+       /* enable lock led */
+       ret = af9013_lock_led(state, 1);
+       if (ret)
+               goto error;
+
+error:
+       return ret;
+}
+
+static struct dvb_frontend_ops af9013_ops;
+
+static int af9013_download_firmware(struct af9013_state *state)
+{
+       int i, len, packets, remainder, ret;
+       const struct firmware *fw;
+       u16 addr = 0x5100; /* firmware start address */
+       u16 checksum = 0;
+       u8 val;
+       u8 fw_params[4];
+       u8 *data;
+       u8 *fw_file = AF9013_DEFAULT_FIRMWARE;
+
+       msleep(100);
+       /* check whether firmware is already running */
+       ret = af9013_read_reg(state, 0x98be, &val);
+       if (ret)
+               goto error;
+       else
+               deb_info("%s: firmware status:%02x\n", __func__, val);
+
+       if (val == 0x0c) /* fw is running, no need for download */
+               goto exit;
+
+       info("found a '%s' in cold state, will try to load a firmware",
+               af9013_ops.info.name);
+
+       /* request the firmware, this will block and timeout */
+       ret = request_firmware(&fw, fw_file,  &state->i2c->dev);
+       if (ret) {
+               err("did not find the firmware file. (%s) "
+                       "Please see linux/Documentation/dvb/ for more details" \
+                       " on firmware-problems. (%d)",
+                       fw_file, ret);
+               goto error;
+       }
+
+       info("downloading firmware from file '%s'", fw_file);
+
+       /* calc checksum */
+       for (i = 0; i < fw->size; i++)
+               checksum += fw->data[i];
+
+       fw_params[0] = checksum >> 8;
+       fw_params[1] = checksum & 0xff;
+       fw_params[2] = fw->size >> 8;
+       fw_params[3] = fw->size & 0xff;
+
+       /* write fw checksum & size */
+       ret = af9013_write_ofsm_regs(state, 0x50fc,
+               fw_params, sizeof(fw_params));
+       if (ret)
+               goto error_release;
+
+       #define FW_PACKET_MAX_DATA  16
+
+       packets = fw->size / FW_PACKET_MAX_DATA;
+       remainder = fw->size % FW_PACKET_MAX_DATA;
+       len = FW_PACKET_MAX_DATA;
+       for (i = 0; i <= packets; i++) {
+               if (i == packets)  /* set size of the last packet */
+                       len = remainder;
+
+               data = (u8 *)(fw->data + i * FW_PACKET_MAX_DATA);
+               ret = af9013_write_ofsm_regs(state, addr, data, len);
+               addr += FW_PACKET_MAX_DATA;
+
+               if (ret) {
+                       err("firmware download failed at %d with %d", i, ret);
+                       goto error_release;
+               }
+       }
+
+       /* request boot firmware */
+       ret = af9013_write_reg(state, 0xe205, 1);
+       if (ret)
+               goto error_release;
+
+       for (i = 0; i < 15; i++) {
+               msleep(100);
+
+               /* check firmware status */
+               ret = af9013_read_reg(state, 0x98be, &val);
+               if (ret)
+                       goto error_release;
+
+               deb_info("%s: firmware status:%02x\n", __func__, val);
+
+               if (val == 0x0c || val == 0x04) /* success or fail */
+                       break;
+       }
+
+       if (val == 0x04) {
+               err("firmware did not run");
+               ret = -1;
+       } else if (val != 0x0c) {
+               err("firmware boot timeout");
+               ret = -1;
+       }
+
+error_release:
+       release_firmware(fw);
+error:
+exit:
+       if (!ret)
+               info("found a '%s' in warm state.", af9013_ops.info.name);
+       return ret;
+}
+
+static int af9013_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
+{
+       int ret;
+       struct af9013_state *state = fe->demodulator_priv;
+       deb_info("%s: enable:%d\n", __func__, enable);
+
+       if (state->config.output_mode == AF9013_OUTPUT_MODE_USB)
+               ret = af9013_write_reg_bits(state, 0xd417, 3, 1, enable);
+       else
+               ret = af9013_write_reg_bits(state, 0xd607, 2, 1, enable);
+
+       return ret;
+}
+
+static void af9013_release(struct dvb_frontend *fe)
+{
+       struct af9013_state *state = fe->demodulator_priv;
+       kfree(state);
+}
+
+static struct dvb_frontend_ops af9013_ops;
+
+struct dvb_frontend *af9013_attach(const struct af9013_config *config,
+       struct i2c_adapter *i2c)
+{
+       int ret;
+       struct af9013_state *state = NULL;
+       u8 buf[3], i;
+
+       /* allocate memory for the internal state */
+       state = kzalloc(sizeof(struct af9013_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error;
+
+       /* setup the state */
+       state->i2c = i2c;
+       memcpy(&state->config, config, sizeof(struct af9013_config));
+
+       /* chip version */
+       ret = af9013_read_reg_bits(state, 0xd733, 4, 4, &buf[2]);
+       if (ret)
+               goto error;
+
+       /* ROM version */
+       for (i = 0; i < 2; i++) {
+               ret = af9013_read_reg(state, 0x116b + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+       deb_info("%s: chip version:%d ROM version:%d.%d\n", __func__,
+               buf[2], buf[0], buf[1]);
+
+       /* download firmware */
+       if (state->config.output_mode != AF9013_OUTPUT_MODE_USB) {
+               ret = af9013_download_firmware(state);
+               if (ret)
+                       goto error;
+       }
+
+       /* firmware version */
+       for (i = 0; i < 3; i++) {
+               ret = af9013_read_reg(state, 0x5103 + i, &buf[i]);
+               if (ret)
+                       goto error;
+       }
+       info("firmware version:%d.%d.%d", buf[0], buf[1], buf[2]);
+
+       /* settings for mp2if */
+       if (state->config.output_mode == AF9013_OUTPUT_MODE_USB) {
+               /* AF9015 split PSB to 1.5k + 0.5k */
+               ret = af9013_write_reg_bits(state, 0xd50b, 2, 1, 1);
+       } else {
+               /* AF9013 change the output bit to data7 */
+               ret = af9013_write_reg_bits(state, 0xd500, 3, 1, 1);
+               if (ret)
+                       goto error;
+               /* AF9013 set mpeg to full speed */
+               ret = af9013_write_reg_bits(state, 0xd502, 4, 1, 1);
+       }
+       if (ret)
+               goto error;
+       ret = af9013_write_reg_bits(state, 0xd520, 4, 1, 1);
+       if (ret)
+               goto error;
+
+       /* set GPIOs */
+       for (i = 0; i < sizeof(state->config.gpio); i++) {
+               ret = af9013_set_gpio(state, i, state->config.gpio[i]);
+               if (ret)
+                       goto error;
+       }
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &af9013_ops,
+               sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+
+       return &state->frontend;
+error:
+       kfree(state);
+       return NULL;
+}
+EXPORT_SYMBOL(af9013_attach);
+
+static struct dvb_frontend_ops af9013_ops = {
+       .info = {
+               .name = "Afatech AF9013 DVB-T",
+               .type = FE_OFDM,
+               .frequency_min = 174000000,
+               .frequency_max = 862000000,
+               .frequency_stepsize = 250000,
+               .frequency_tolerance = 0,
+               .caps =
+                       FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+                       FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
+                       FE_CAN_QPSK | FE_CAN_QAM_16 |
+                       FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
+                       FE_CAN_TRANSMISSION_MODE_AUTO |
+                       FE_CAN_GUARD_INTERVAL_AUTO |
+                       FE_CAN_HIERARCHY_AUTO |
+                       FE_CAN_RECOVER |
+                       FE_CAN_MUTE_TS
+       },
+
+       .release = af9013_release,
+       .init = af9013_init,
+       .sleep = af9013_sleep,
+       .i2c_gate_ctrl = af9013_i2c_gate_ctrl,
+
+       .set_frontend = af9013_set_frontend,
+       .get_frontend = af9013_get_frontend,
+
+       .get_tune_settings = af9013_get_tune_settings,
+
+       .read_status = af9013_read_status,
+       .read_ber = af9013_read_ber,
+       .read_signal_strength = af9013_read_signal_strength,
+       .read_snr = af9013_read_snr,
+       .read_ucblocks = af9013_read_ucblocks,
+};
+
+module_param_named(debug, af9013_debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
+MODULE_DESCRIPTION("Afatech AF9013 DVB-T demodulator driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/af9013.h b/drivers/media/dvb/frontends/af9013.h
new file mode 100644 (file)
index 0000000..28b90c9
--- /dev/null
@@ -0,0 +1,107 @@
+/*
+ * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
+ *
+ * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
+ *
+ * Thanks to Afatech who kindly provided information.
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _AF9013_H_
+#define _AF9013_H_
+
+#include <linux/dvb/frontend.h>
+
+enum af9013_ts_mode {
+       AF9013_OUTPUT_MODE_PARALLEL,
+       AF9013_OUTPUT_MODE_SERIAL,
+       AF9013_OUTPUT_MODE_USB, /* only for AF9015 */
+};
+
+enum af9013_tuner {
+       AF9013_TUNER_MXL5003D   =   3, /* MaxLinear */
+       AF9013_TUNER_MXL5005D   =  13, /* MaxLinear */
+       AF9013_TUNER_MXL5005R   =  30, /* MaxLinear */
+       AF9013_TUNER_ENV77H11D5 = 129, /* Panasonic */
+       AF9013_TUNER_MT2060     = 130, /* Microtune */
+       AF9013_TUNER_MC44S803   = 133, /* Freescale */
+       AF9013_TUNER_QT1010     = 134, /* Quantek */
+       AF9013_TUNER_UNKNOWN    = 140, /* for can tuners ? */
+       AF9013_TUNER_MT2060_2   = 147, /* Microtune */
+       AF9013_TUNER_TDA18271   = 156, /* NXP */
+       AF9013_TUNER_QT1010A    = 162, /* Quantek */
+};
+
+/* AF9013/5 GPIOs (mostly guessed)
+   demod#1-gpio#0 - set demod#2 i2c-addr for dual devices
+   demod#1-gpio#1 - xtal setting (?)
+   demod#1-gpio#3 - tuner#1
+   demod#2-gpio#0 - tuner#2
+   demod#2-gpio#1 - xtal setting (?)
+*/
+#define AF9013_GPIO_ON (1 << 0)
+#define AF9013_GPIO_EN (1 << 1)
+#define AF9013_GPIO_O  (1 << 2)
+#define AF9013_GPIO_I  (1 << 3)
+
+#define AF9013_GPIO_LO (AF9013_GPIO_ON|AF9013_GPIO_EN)
+#define AF9013_GPIO_HI (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O)
+
+#define AF9013_GPIO_TUNER_ON  (AF9013_GPIO_ON|AF9013_GPIO_EN)
+#define AF9013_GPIO_TUNER_OFF (AF9013_GPIO_ON|AF9013_GPIO_EN|AF9013_GPIO_O)
+
+struct af9013_config {
+       /* demodulator's I2C address */
+       u8 demod_address;
+
+       /* frequencies in kHz */
+       u32 adc_clock;
+
+       /* tuner ID */
+       u8 tuner;
+
+       /* tuner IF */
+       u16 tuner_if;
+
+       /* TS data output mode */
+       u8 output_mode:2;
+
+       /* RF spectrum inversion */
+       u8 rf_spec_inv:1;
+
+       /* API version */
+       u8 api_version[4];
+
+       /* GPIOs */
+       u8 gpio[4];
+};
+
+
+#if defined(CONFIG_DVB_AF9013) || \
+       (defined(CONFIG_DVB_AF9013_MODULE) && defined(MODULE))
+extern struct dvb_frontend *af9013_attach(const struct af9013_config *config,
+       struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *af9013_attach(
+const struct af9013_config *config, struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_AF9013 */
+
+#endif /* _AF9013_H_ */
diff --git a/drivers/media/dvb/frontends/af9013_priv.h b/drivers/media/dvb/frontends/af9013_priv.h
new file mode 100644 (file)
index 0000000..163e251
--- /dev/null
@@ -0,0 +1,869 @@
+/*
+ * DVB USB Linux driver for Afatech AF9015 DVB-T USB2.0 receiver
+ *
+ * Copyright (C) 2007 Antti Palosaari <crope@iki.fi>
+ *
+ * Thanks to Afatech who kindly provided information.
+ *
+ *    This program is free software; you can redistribute it and/or modify
+ *    it under the terms of the GNU General Public License as published by
+ *    the Free Software Foundation; either version 2 of the License, or
+ *    (at your option) any later version.
+ *
+ *    This program is distributed in the hope that it will be useful,
+ *    but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *    GNU General Public License for more details.
+ *
+ *    You should have received a copy of the GNU General Public License
+ *    along with this program; if not, write to the Free Software
+ *    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ */
+
+#ifndef _AF9013_PRIV_
+#define _AF9013_PRIV_
+
+#define LOG_PREFIX "af9013"
+extern int af9013_debug;
+
+#define dprintk(var, level, args...) \
+           do { if ((var & level)) printk(args); } while (0)
+
+#define debug_dump(b, l, func) {\
+       int loop_; \
+       for (loop_ = 0; loop_ < l; loop_++) \
+               func("%02x ", b[loop_]); \
+       func("\n");\
+}
+
+#define deb_info(args...) dprintk(af9013_debug, 0x01, args)
+
+#undef err
+#define err(f, arg...)  printk(KERN_ERR     LOG_PREFIX": " f "\n" , ## arg)
+#undef info
+#define info(f, arg...) printk(KERN_INFO    LOG_PREFIX": " f "\n" , ## arg)
+#undef warn
+#define warn(f, arg...) printk(KERN_WARNING LOG_PREFIX": " f "\n" , ## arg)
+
+#define AF9013_DEFAULT_FIRMWARE     "dvb-fe-af9013.fw"
+
+struct regdesc {
+       u16 addr;
+       u8  pos:4;
+       u8  len:4;
+       u8  val;
+};
+
+struct snr_table {
+       u32 val;
+       u8 snr;
+};
+
+/* QPSK SNR lookup table */
+static struct snr_table qpsk_snr_table[] = {
+       { 0x0b4771,  0 },
+       { 0x0c1aed,  1 },
+       { 0x0d0d27,  2 },
+       { 0x0e4d19,  3 },
+       { 0x0e5da8,  4 },
+       { 0x107097,  5 },
+       { 0x116975,  6 },
+       { 0x1252d9,  7 },
+       { 0x131fa4,  8 },
+       { 0x13d5e1,  9 },
+       { 0x148e53, 10 },
+       { 0x15358b, 11 },
+       { 0x15dd29, 12 },
+       { 0x168112, 13 },
+       { 0x170b61, 14 },
+       { 0xffffff, 15 },
+};
+
+/* QAM16 SNR lookup table */
+static struct snr_table qam16_snr_table[] = {
+       { 0x05eb62,  5 },
+       { 0x05fecf,  6 },
+       { 0x060b80,  7 },
+       { 0x062501,  8 },
+       { 0x064865,  9 },
+       { 0x069604, 10 },
+       { 0x06f356, 11 },
+       { 0x07706a, 12 },
+       { 0x0804d3, 13 },
+       { 0x089d1a, 14 },
+       { 0x093e3d, 15 },
+       { 0x09e35d, 16 },
+       { 0x0a7c3c, 17 },
+       { 0x0afaf8, 18 },
+       { 0x0b719d, 19 },
+       { 0xffffff, 20 },
+};
+
+/* QAM64 SNR lookup table */
+static struct snr_table qam64_snr_table[] = {
+       { 0x03109b, 12 },
+       { 0x0310d4, 13 },
+       { 0x031920, 14 },
+       { 0x0322d0, 15 },
+       { 0x0339fc, 16 },
+       { 0x0364a1, 17 },
+       { 0x038bcc, 18 },
+       { 0x03c7d3, 19 },
+       { 0x0408cc, 20 },
+       { 0x043bed, 21 },
+       { 0x048061, 22 },
+       { 0x04be95, 23 },
+       { 0x04fa7d, 24 },
+       { 0x052405, 25 },
+       { 0x05570d, 26 },
+       { 0xffffff, 27 },
+};
+
+static struct regdesc ofsm_init[] = {
+       { 0xd73a, 0, 8, 0xa1 },
+       { 0xd73b, 0, 8, 0x1f },
+       { 0xd73c, 4, 4, 0x0a },
+       { 0xd732, 3, 1, 0x00 },
+       { 0xd731, 4, 2, 0x03 },
+       { 0xd73d, 7, 1, 0x01 },
+       { 0xd740, 0, 1, 0x00 },
+       { 0xd740, 1, 1, 0x00 },
+       { 0xd740, 2, 1, 0x00 },
+       { 0xd740, 3, 1, 0x01 },
+       { 0xd3c1, 4, 1, 0x01 },
+       { 0xd3a2, 0, 8, 0x00 },
+       { 0xd3a3, 0, 8, 0x04 },
+       { 0xd305, 0, 8, 0x32 },
+       { 0xd306, 0, 8, 0x10 },
+       { 0xd304, 0, 8, 0x04 },
+       { 0x9112, 0, 1, 0x01 },
+       { 0x911d, 0, 1, 0x01 },
+       { 0x911a, 0, 1, 0x01 },
+       { 0x911b, 0, 1, 0x01 },
+       { 0x9bce, 0, 4, 0x02 },
+       { 0x9116, 0, 1, 0x01 },
+       { 0x9bd1, 0, 1, 0x01 },
+       { 0xd2e0, 0, 8, 0xd0 },
+       { 0xd2e9, 0, 4, 0x0d },
+       { 0xd38c, 0, 8, 0xfc },
+       { 0xd38d, 0, 8, 0x00 },
+       { 0xd38e, 0, 8, 0x7e },
+       { 0xd38f, 0, 8, 0x00 },
+       { 0xd390, 0, 8, 0x2f },
+       { 0xd145, 4, 1, 0x01 },
+       { 0xd1a9, 4, 1, 0x01 },
+       { 0xd158, 5, 3, 0x01 },
+       { 0xd159, 0, 6, 0x06 },
+       { 0xd167, 0, 8, 0x00 },
+       { 0xd168, 0, 4, 0x07 },
+       { 0xd1c3, 5, 3, 0x00 },
+       { 0xd1c4, 0, 6, 0x00 },
+       { 0xd1c5, 0, 7, 0x10 },
+       { 0xd1c6, 0, 3, 0x02 },
+       { 0xd080, 2, 5, 0x03 },
+       { 0xd081, 4, 4, 0x09 },
+       { 0xd098, 4, 4, 0x0f },
+       { 0xd098, 0, 4, 0x03 },
+       { 0xdbc0, 3, 1, 0x01 },
+       { 0xdbc0, 4, 1, 0x01 },
+       { 0xdbc7, 0, 8, 0x08 },
+       { 0xdbc8, 4, 4, 0x00 },
+       { 0xdbc9, 0, 5, 0x01 },
+       { 0xd280, 0, 8, 0xe0 },
+       { 0xd281, 0, 8, 0xff },
+       { 0xd282, 0, 8, 0xff },
+       { 0xd283, 0, 8, 0xc3 },
+       { 0xd284, 0, 8, 0xff },
+       { 0xd285, 0, 4, 0x01 },
+       { 0xd0f0, 0, 7, 0x1a },
+       { 0xd0f1, 4, 1, 0x01 },
+       { 0xd0f2, 0, 8, 0x0c },
+       { 0xd103, 0, 4, 0x08 },
+       { 0xd0f8, 0, 7, 0x20 },
+       { 0xd111, 5, 1, 0x00 },
+       { 0xd111, 6, 1, 0x00 },
+       { 0x910b, 0, 8, 0x0a },
+       { 0x9115, 0, 8, 0x02 },
+       { 0x910c, 0, 8, 0x02 },
+       { 0x910d, 0, 8, 0x08 },
+       { 0x910e, 0, 8, 0x0a },
+       { 0x9bf6, 0, 8, 0x06 },
+       { 0x9bf8, 0, 8, 0x02 },
+       { 0x9bf7, 0, 8, 0x05 },
+       { 0x9bf9, 0, 8, 0x0f },
+       { 0x9bfc, 0, 8, 0x13 },
+       { 0x9bd3, 0, 8, 0xff },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+};
+
+/* Panasonic ENV77H11D5 tuner init
+   AF9013_TUNER_ENV77H11D5 = 129 */
+static struct regdesc tuner_init_env77h11d5[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x03 },
+       { 0x9bbe, 0, 8, 0x01 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x00 },
+       { 0x9be3, 0, 8, 0x00 },
+       { 0xd015, 0, 8, 0x50 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0xdf },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x44 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0xeb },
+       { 0xd00d, 0, 2, 0x02 },
+       { 0xd00a, 0, 8, 0xf4 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bba, 0, 8, 0xf9 },
+       { 0x9bc3, 0, 8, 0xdf },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0xeb },
+       { 0x9bc6, 0, 8, 0x02 },
+       { 0x9bc9, 0, 8, 0x52 },
+       { 0xd011, 0, 8, 0x3c },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0xf7 },
+       { 0xd014, 0, 2, 0x02 },
+       { 0xd040, 0, 8, 0x0b },
+       { 0xd041, 0, 2, 0x02 },
+       { 0xd042, 0, 8, 0x4d },
+       { 0xd043, 0, 2, 0x00 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+};
+
+/* Microtune MT2060 tuner init
+   AF9013_TUNER_MT2060     = 130 */
+static struct regdesc tuner_init_mt2060[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x07 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x00 },
+       { 0x9be3, 0, 8, 0x00 },
+       { 0x9bbe, 0, 1, 0x00 },
+       { 0x9bcc, 0, 1, 0x00 },
+       { 0x9bb9, 0, 8, 0x75 },
+       { 0x9bcd, 0, 8, 0x24 },
+       { 0x9bff, 0, 8, 0x30 },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0x0f },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x32 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0x36 },
+       { 0xd00d, 0, 2, 0x03 },
+       { 0xd00a, 0, 8, 0x35 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x07 },
+       { 0x9bc8, 0, 8, 0x90 },
+       { 0x9bc3, 0, 8, 0x0f },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x36 },
+       { 0x9bc6, 0, 8, 0x03 },
+       { 0x9bba, 0, 8, 0xc9 },
+       { 0x9bc9, 0, 8, 0x79 },
+       { 0xd011, 0, 8, 0x10 },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0x45 },
+       { 0xd014, 0, 2, 0x03 },
+       { 0xd040, 0, 8, 0x98 },
+       { 0xd041, 0, 2, 0x00 },
+       { 0xd042, 0, 8, 0xcf },
+       { 0xd043, 0, 2, 0x03 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+       { 0x9bd0, 0, 8, 0xcc },
+       { 0x9be4, 0, 8, 0xa0 },
+       { 0x9bbd, 0, 8, 0x8e },
+       { 0x9be2, 0, 8, 0x4d },
+       { 0x9bee, 0, 1, 0x01 },
+};
+
+/* Microtune MT2060 tuner init
+   AF9013_TUNER_MT2060_2   = 147 */
+static struct regdesc tuner_init_mt2060_2[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x06 },
+       { 0x9bbe, 0, 8, 0x01 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0x0f },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x32 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0x36 },
+       { 0xd00d, 0, 2, 0x03 },
+       { 0xd00a, 0, 8, 0x35 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x07 },
+       { 0x9bc8, 0, 8, 0x90 },
+       { 0x9bc3, 0, 8, 0x0f },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x36 },
+       { 0x9bc6, 0, 8, 0x03 },
+       { 0x9bba, 0, 8, 0xc9 },
+       { 0x9bc9, 0, 8, 0x79 },
+       { 0xd011, 0, 8, 0x10 },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0x45 },
+       { 0xd014, 0, 2, 0x03 },
+       { 0xd040, 0, 8, 0x98 },
+       { 0xd041, 0, 2, 0x00 },
+       { 0xd042, 0, 8, 0xcf },
+       { 0xd043, 0, 2, 0x03 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 8, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x96 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0xd045, 7, 1, 0x00 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+};
+
+/* MaxLinear MXL5003 tuner init
+   AF9013_TUNER_MXL5003D   =   3 */
+static struct regdesc tuner_init_mxl5003d[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x09 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x00 },
+       { 0x9be3, 0, 8, 0x00 },
+       { 0x9bfc, 0, 8, 0x0f },
+       { 0x9bf6, 0, 8, 0x01 },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0xd015, 0, 8, 0x33 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x40 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0x0f },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x6c },
+       { 0xd007, 0, 2, 0x00 },
+       { 0xd00c, 0, 8, 0x3d },
+       { 0xd00d, 0, 2, 0x00 },
+       { 0xd00a, 0, 8, 0x45 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x07 },
+       { 0x9bc8, 0, 8, 0x52 },
+       { 0x9bc3, 0, 8, 0x0f },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x3d },
+       { 0x9bc6, 0, 8, 0x00 },
+       { 0x9bba, 0, 8, 0xa2 },
+       { 0x9bc9, 0, 8, 0xa0 },
+       { 0xd011, 0, 8, 0x56 },
+       { 0xd012, 0, 2, 0x00 },
+       { 0xd013, 0, 8, 0x50 },
+       { 0xd014, 0, 2, 0x00 },
+       { 0xd040, 0, 8, 0x56 },
+       { 0xd041, 0, 2, 0x00 },
+       { 0xd042, 0, 8, 0x50 },
+       { 0xd043, 0, 2, 0x00 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 8, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+};
+
+/* MaxLinear MXL5005 tuner init
+   AF9013_TUNER_MXL5005D   =  13
+   AF9013_TUNER_MXL5005R   =  30 */
+static struct regdesc tuner_init_mxl5005[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x07 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x01 },
+       { 0x9be3, 0, 8, 0x01 },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+       { 0x9bb9, 0, 8, 0x00 },
+       { 0x9bcd, 0, 8, 0x28 },
+       { 0x9bff, 0, 8, 0x24 },
+       { 0xd015, 0, 8, 0x40 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x40 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0x0f },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x73 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0xfa },
+       { 0xd00d, 0, 2, 0x01 },
+       { 0xd00a, 0, 8, 0xff },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x23 },
+       { 0x9bc8, 0, 8, 0x55 },
+       { 0x9bc3, 0, 8, 0x01 },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0xfa },
+       { 0x9bc6, 0, 8, 0x01 },
+       { 0x9bba, 0, 8, 0xff },
+       { 0x9bc9, 0, 8, 0xff },
+       { 0x9bd3, 0, 8, 0x95 },
+       { 0xd011, 0, 8, 0x70 },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0xfb },
+       { 0xd014, 0, 2, 0x01 },
+       { 0xd040, 0, 8, 0x70 },
+       { 0xd041, 0, 2, 0x01 },
+       { 0xd042, 0, 8, 0xfb },
+       { 0xd043, 0, 2, 0x01 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+       { 0x9bd0, 0, 8, 0x93 },
+       { 0x9be4, 0, 8, 0xfe },
+       { 0x9bbd, 0, 8, 0x63 },
+       { 0x9be2, 0, 8, 0xfe },
+       { 0x9bee, 0, 1, 0x01 },
+};
+
+/* Quantek QT1010 tuner init
+   AF9013_TUNER_QT1010     = 134
+   AF9013_TUNER_QT1010A    = 162 */
+static struct regdesc tuner_init_qt1010[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x09 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x01 },
+       { 0x9be3, 0, 8, 0x01 },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+       { 0x9bb9, 0, 8, 0x00 },
+       { 0x9bcd, 0, 8, 0x28 },
+       { 0x9bff, 0, 8, 0x20 },
+       { 0xd008, 0, 8, 0x0f },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x99 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0x0f },
+       { 0xd00d, 0, 2, 0x02 },
+       { 0xd00a, 0, 8, 0x50 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x00 },
+       { 0x9bc8, 0, 8, 0x00 },
+       { 0x9bc3, 0, 8, 0x0f },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x0f },
+       { 0x9bc6, 0, 8, 0x02 },
+       { 0x9bba, 0, 8, 0xc5 },
+       { 0x9bc9, 0, 8, 0xff },
+       { 0xd011, 0, 8, 0x58 },
+       { 0xd012, 0, 2, 0x02 },
+       { 0xd013, 0, 8, 0x89 },
+       { 0xd014, 0, 2, 0x01 },
+       { 0xd040, 0, 8, 0x58 },
+       { 0xd041, 0, 2, 0x02 },
+       { 0xd042, 0, 8, 0x89 },
+       { 0xd043, 0, 2, 0x01 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+       { 0x9bd0, 0, 8, 0xcd },
+       { 0x9be4, 0, 8, 0xbb },
+       { 0x9bbd, 0, 8, 0x93 },
+       { 0x9be2, 0, 8, 0x80 },
+       { 0x9bee, 0, 1, 0x01 },
+};
+
+/* Freescale MC44S803 tuner init
+   AF9013_TUNER_MC44S803   = 133 */
+static struct regdesc tuner_init_mc44s803[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x06 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x00 },
+       { 0x9be3, 0, 8, 0x00 },
+       { 0x9bf6, 0, 8, 0x01 },
+       { 0x9bf8, 0, 8, 0x02 },
+       { 0x9bf9, 0, 8, 0x02 },
+       { 0x9bfc, 0, 8, 0x1f },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+       { 0x9bb9, 0, 8, 0x00 },
+       { 0x9bcd, 0, 8, 0x24 },
+       { 0x9bff, 0, 8, 0x24 },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0x01 },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x7b },
+       { 0xd007, 0, 2, 0x00 },
+       { 0xd00c, 0, 8, 0x7c },
+       { 0xd00d, 0, 2, 0x02 },
+       { 0xd00a, 0, 8, 0xfe },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bc7, 0, 8, 0x08 },
+       { 0x9bc8, 0, 8, 0x9a },
+       { 0x9bc3, 0, 8, 0x01 },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x7c },
+       { 0x9bc6, 0, 8, 0x02 },
+       { 0x9bba, 0, 8, 0xfc },
+       { 0x9bc9, 0, 8, 0xaa },
+       { 0xd011, 0, 8, 0x6b },
+       { 0xd012, 0, 2, 0x00 },
+       { 0xd013, 0, 8, 0x88 },
+       { 0xd014, 0, 2, 0x02 },
+       { 0xd040, 0, 8, 0x6b },
+       { 0xd041, 0, 2, 0x00 },
+       { 0xd042, 0, 8, 0x7c },
+       { 0xd043, 0, 2, 0x02 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+       { 0x9bd0, 0, 8, 0x9e },
+       { 0x9be4, 0, 8, 0xff },
+       { 0x9bbd, 0, 8, 0x9e },
+       { 0x9be2, 0, 8, 0x25 },
+       { 0x9bee, 0, 1, 0x01 },
+       { 0xd73b, 3, 1, 0x00 },
+};
+
+/* unknown, probably for tin can tuner, tuner init
+   AF9013_TUNER_UNKNOWN   = 140 */
+static struct regdesc tuner_init_unknown[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x02 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x01 },
+       { 0x9be3, 0, 8, 0x01 },
+       { 0xd1a0, 1, 1, 0x00 },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+       { 0x9bb9, 0, 8, 0x00 },
+       { 0x9bcd, 0, 8, 0x18 },
+       { 0x9bff, 0, 8, 0x2c },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0xdf },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x44 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0x00 },
+       { 0xd00d, 0, 2, 0x02 },
+       { 0xd00a, 0, 8, 0xf6 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bba, 0, 8, 0xf9 },
+       { 0x9bc8, 0, 8, 0xaa },
+       { 0x9bc3, 0, 8, 0xdf },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x00 },
+       { 0x9bc6, 0, 8, 0x02 },
+       { 0x9bc9, 0, 8, 0xf0 },
+       { 0xd011, 0, 8, 0x3c },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0xf7 },
+       { 0xd014, 0, 2, 0x02 },
+       { 0xd040, 0, 8, 0x0b },
+       { 0xd041, 0, 2, 0x02 },
+       { 0xd042, 0, 8, 0x4d },
+       { 0xd043, 0, 2, 0x00 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+};
+
+/* NXP TDA18271 tuner init
+   AF9013_TUNER_TDA18271   = 156 */
+static struct regdesc tuner_init_tda18271[] = {
+       { 0x9bd5, 0, 8, 0x01 },
+       { 0x9bd6, 0, 8, 0x04 },
+       { 0xd1a0, 1, 1, 0x01 },
+       { 0xd000, 0, 1, 0x01 },
+       { 0xd000, 1, 1, 0x00 },
+       { 0xd001, 1, 1, 0x01 },
+       { 0xd001, 0, 1, 0x00 },
+       { 0xd001, 5, 1, 0x00 },
+       { 0xd002, 0, 5, 0x19 },
+       { 0xd003, 0, 5, 0x1a },
+       { 0xd004, 0, 5, 0x19 },
+       { 0xd005, 0, 5, 0x1a },
+       { 0xd00e, 0, 5, 0x10 },
+       { 0xd00f, 0, 3, 0x04 },
+       { 0xd00f, 3, 3, 0x05 },
+       { 0xd010, 0, 3, 0x04 },
+       { 0xd010, 3, 3, 0x05 },
+       { 0xd016, 4, 4, 0x03 },
+       { 0xd01f, 0, 6, 0x0a },
+       { 0xd020, 0, 6, 0x0a },
+       { 0x9bda, 0, 8, 0x01 },
+       { 0x9be3, 0, 8, 0x01 },
+       { 0xd1a0, 1, 1, 0x00 },
+       { 0x9bbe, 0, 1, 0x01 },
+       { 0x9bcc, 0, 1, 0x01 },
+       { 0x9bb9, 0, 8, 0x00 },
+       { 0x9bcd, 0, 8, 0x18 },
+       { 0x9bff, 0, 8, 0x2c },
+       { 0xd015, 0, 8, 0x46 },
+       { 0xd016, 0, 1, 0x00 },
+       { 0xd044, 0, 8, 0x46 },
+       { 0xd045, 0, 1, 0x00 },
+       { 0xd008, 0, 8, 0xdf },
+       { 0xd009, 0, 2, 0x02 },
+       { 0xd006, 0, 8, 0x44 },
+       { 0xd007, 0, 2, 0x01 },
+       { 0xd00c, 0, 8, 0x00 },
+       { 0xd00d, 0, 2, 0x02 },
+       { 0xd00a, 0, 8, 0xf6 },
+       { 0xd00b, 0, 2, 0x01 },
+       { 0x9bba, 0, 8, 0xf9 },
+       { 0x9bc8, 0, 8, 0xaa },
+       { 0x9bc3, 0, 8, 0xdf },
+       { 0x9bc4, 0, 8, 0x02 },
+       { 0x9bc5, 0, 8, 0x00 },
+       { 0x9bc6, 0, 8, 0x02 },
+       { 0x9bc9, 0, 8, 0xf0 },
+       { 0xd011, 0, 8, 0x3c },
+       { 0xd012, 0, 2, 0x01 },
+       { 0xd013, 0, 8, 0xf7 },
+       { 0xd014, 0, 2, 0x02 },
+       { 0xd040, 0, 8, 0x0b },
+       { 0xd041, 0, 2, 0x02 },
+       { 0xd042, 0, 8, 0x4d },
+       { 0xd043, 0, 2, 0x00 },
+       { 0xd045, 1, 1, 0x00 },
+       { 0x9bcf, 0, 1, 0x01 },
+       { 0xd045, 2, 1, 0x01 },
+       { 0xd04f, 0, 8, 0x9a },
+       { 0xd050, 0, 1, 0x01 },
+       { 0xd051, 0, 8, 0x5a },
+       { 0xd052, 0, 1, 0x01 },
+       { 0xd053, 0, 8, 0x50 },
+       { 0xd054, 0, 8, 0x46 },
+       { 0x9bd7, 0, 8, 0x0a },
+       { 0x9bd8, 0, 8, 0x14 },
+       { 0x9bd9, 0, 8, 0x08 },
+       { 0x9bd0, 0, 8, 0xa8 },
+       { 0x9be4, 0, 8, 0x7f },
+       { 0x9bbd, 0, 8, 0xa8 },
+       { 0x9be2, 0, 8, 0x20 },
+       { 0x9bee, 0, 1, 0x01 },
+};
+
+#endif /* _AF9013_PRIV_ */
index 0b82cc2a1e161c7603e900ab6bff8d4ffc9effee..eabf9a68e7ec36362ec3aab2c46f076ebfa54273 100644 (file)
@@ -40,6 +40,8 @@ struct au8522_state {
        u32 current_frequency;
        fe_modulation_t current_modulation;
 
+       u32 fe_status;
+       unsigned int led_state;
 };
 
 static int debug;
@@ -538,11 +540,98 @@ static int au8522_init(struct dvb_frontend *fe)
        return 0;
 }
 
+static int au8522_led_gpio_enable(struct au8522_state *state, int onoff)
+{
+       struct au8522_led_config *led_config = state->config->led_cfg;
+       u8 val;
+
+       /* bail out if we cant control an LED */
+       if (!led_config || !led_config->gpio_output ||
+           !led_config->gpio_output_enable || !led_config->gpio_output_disable)
+               return 0;
+
+       val = au8522_readreg(state, 0x4000 |
+                            (led_config->gpio_output & ~0xc000));
+       if (onoff) {
+               /* enable GPIO output */
+               val &= ~((led_config->gpio_output_enable >> 8) & 0xff);
+               val |=  (led_config->gpio_output_enable & 0xff);
+       } else {
+               /* disable GPIO output */
+               val &= ~((led_config->gpio_output_disable >> 8) & 0xff);
+               val |=  (led_config->gpio_output_disable & 0xff);
+       }
+       return au8522_writereg(state, 0x8000 |
+                              (led_config->gpio_output & ~0xc000), val);
+}
+
+/* led = 0 | off
+ * led = 1 | signal ok
+ * led = 2 | signal strong
+ * led < 0 | only light led if leds are currently off
+ */
+static int au8522_led_ctrl(struct au8522_state *state, int led)
+{
+       struct au8522_led_config *led_config = state->config->led_cfg;
+       int i, ret = 0;
+
+       /* bail out if we cant control an LED */
+       if (!led_config || !led_config->gpio_leds ||
+           !led_config->num_led_states || !led_config->led_states)
+               return 0;
+
+       if (led < 0) {
+               /* if LED is already lit, then leave it as-is */
+               if (state->led_state)
+                       return 0;
+               else
+                       led *= -1;
+       }
+
+       /* toggle LED if changing state */
+       if (state->led_state != led) {
+               u8 val;
+
+               dprintk("%s: %d\n", __func__, led);
+
+               au8522_led_gpio_enable(state, 1);
+
+               val = au8522_readreg(state, 0x4000 |
+                                    (led_config->gpio_leds & ~0xc000));
+
+               /* start with all leds off */
+               for (i = 0; i < led_config->num_led_states; i++)
+                       val &= ~led_config->led_states[i];
+
+               /* set selected LED state */
+               if (led < led_config->num_led_states)
+                       val |= led_config->led_states[led];
+               else if (led_config->num_led_states)
+                       val |=
+                       led_config->led_states[led_config->num_led_states - 1];
+
+               ret = au8522_writereg(state, 0x8000 |
+                                     (led_config->gpio_leds & ~0xc000), val);
+               if (ret < 0)
+                       return ret;
+
+               state->led_state = led;
+
+               if (led == 0)
+                       au8522_led_gpio_enable(state, 0);
+       }
+
+       return 0;
+}
+
 static int au8522_sleep(struct dvb_frontend *fe)
 {
        struct au8522_state *state = fe->demodulator_priv;
        dprintk("%s()\n", __func__);
 
+       /* turn off led */
+       au8522_led_ctrl(state, 0);
+
        state->current_frequency = 0;
 
        return 0;
@@ -592,12 +681,53 @@ static int au8522_read_status(struct dvb_frontend *fe, fe_status_t *status)
                        *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
                break;
        }
+       state->fe_status = *status;
+
+       if (*status & FE_HAS_LOCK)
+               /* turn on LED, if it isn't on already */
+               au8522_led_ctrl(state, -1);
+       else
+               /* turn off LED */
+               au8522_led_ctrl(state, 0);
 
        dprintk("%s() status 0x%08x\n", __func__, *status);
 
        return 0;
 }
 
+static int au8522_led_status(struct au8522_state *state, const u16 *snr)
+{
+       struct au8522_led_config *led_config = state->config->led_cfg;
+       int led;
+       u16 strong;
+
+       /* bail out if we cant control an LED */
+       if (!led_config)
+               return 0;
+
+       if (0 == (state->fe_status & FE_HAS_LOCK))
+               return au8522_led_ctrl(state, 0);
+       else if (state->current_modulation == QAM_256)
+               strong = led_config->qam256_strong;
+       else if (state->current_modulation == QAM_64)
+               strong = led_config->qam64_strong;
+       else /* (state->current_modulation == VSB_8) */
+               strong = led_config->vsb8_strong;
+
+       if (*snr >= strong)
+               led = 2;
+       else
+               led = 1;
+
+       if ((state->led_state) &&
+           (((strong < *snr) ? (*snr - strong) : (strong - *snr)) <= 10))
+               /* snr didn't change enough to bother
+                * changing the color of the led */
+               return 0;
+
+       return au8522_led_ctrl(state, led);
+}
+
 static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
        struct au8522_state *state = fe->demodulator_priv;
@@ -621,6 +751,9 @@ static int au8522_read_snr(struct dvb_frontend *fe, u16 *snr)
                                            au8522_readreg(state, 0x4311),
                                            snr);
 
+       if (state->config->led_cfg)
+               au8522_led_status(state, snr);
+
        return ret;
 }
 
index 595915ade8c3681b5158e0ed0bf56da36ab25d4f..7b94f554a09344d02c9bb97122783fe4ca39947b 100644 (file)
@@ -30,6 +30,21 @@ enum au8522_if_freq {
        AU8522_IF_3_25MHZ,
 };
 
+struct au8522_led_config {
+       u16 vsb8_strong;
+       u16 qam64_strong;
+       u16 qam256_strong;
+
+       u16 gpio_output;
+       /* unset hi bits, set low bits */
+       u16 gpio_output_enable;
+       u16 gpio_output_disable;
+
+       u16 gpio_leds;
+       u8 *led_states;
+       unsigned int num_led_states;
+};
+
 struct au8522_config {
        /* the demodulator's i2c address */
        u8 demod_address;
@@ -39,6 +54,8 @@ struct au8522_config {
 #define AU8522_DEMODLOCKING 1
        u8 status_mode;
 
+       struct au8522_led_config *led_cfg;
+
        enum au8522_if_freq vsb_if;
        enum au8522_if_freq qam_if;
 };
index 1792adb23c4d527d89bbb4bd859e01ea4732e854..fdcceee91f3ac44cc1000201f3ebca32f7e46c0e 100644 (file)
@@ -33,12 +33,17 @@ struct cx24110_config
        u8 demod_address;
 };
 
-static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val) {
-       int r = 0;
-       u8 buf[] = {(u8) (val>>24), (u8) (val>>16), (u8) (val>>8)};
+static inline int cx24110_pll_write(struct dvb_frontend *fe, u32 val)
+{
+       u8 buf[] = {
+               (u8)((val >> 24) & 0xff),
+               (u8)((val >> 16) & 0xff),
+               (u8)((val >> 8) & 0xff)
+       };
+
        if (fe->ops.write)
-               r = fe->ops.write(fe, buf, 3);
-       return r;
+               return fe->ops.write(fe, buf, 3);
+       return 0;
 }
 
 #if defined(CONFIG_DVB_CX24110) || (defined(CONFIG_DVB_CX24110_MODULE) && defined(MODULE))
diff --git a/drivers/media/dvb/frontends/cx24116.c b/drivers/media/dvb/frontends/cx24116.c
new file mode 100644 (file)
index 0000000..deb36f4
--- /dev/null
@@ -0,0 +1,1423 @@
+/*
+    Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver
+
+    Copyright (C) 2006-2008 Steven Toth <stoth@hauppauge.com>
+    Copyright (C) 2006-2007 Georg Acher
+    Copyright (C) 2007-2008 Darron Broad
+       March 2007
+           Fixed some bugs.
+           Added diseqc support.
+           Added corrected signal strength support.
+       August 2007
+           Sync with legacy version.
+           Some clean ups.
+    Copyright (C) 2008 Igor Liplianin
+       September, 9th 2008
+           Fixed locking on high symbol rates (>30000).
+           Implement MPEG initialization parameter.
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#include <linux/slab.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/firmware.h>
+
+#include "dvb_frontend.h"
+#include "cx24116.h"
+
+static int debug = 0;
+#define dprintk(args...) \
+       do { \
+               if (debug) printk ("cx24116: " args); \
+       } while (0)
+
+#define CX24116_DEFAULT_FIRMWARE "dvb-fe-cx24116.fw"
+#define CX24116_SEARCH_RANGE_KHZ 5000
+
+/* known registers */
+#define CX24116_REG_COMMAND (0x00)      /* command args 0x00..0x1e */
+#define CX24116_REG_EXECUTE (0x1f)      /* execute command */
+#define CX24116_REG_MAILBOX (0x96)      /* FW or multipurpose mailbox? */
+#define CX24116_REG_RESET   (0x20)      /* reset status > 0     */
+#define CX24116_REG_SIGNAL  (0x9e)      /* signal low           */
+#define CX24116_REG_SSTATUS (0x9d)      /* signal high / status */
+#define CX24116_REG_QUALITY8 (0xa3)
+#define CX24116_REG_QSTATUS (0xbc)
+#define CX24116_REG_QUALITY0 (0xd5)
+#define CX24116_REG_BER0    (0xc9)
+#define CX24116_REG_BER8    (0xc8)
+#define CX24116_REG_BER16   (0xc7)
+#define CX24116_REG_BER24   (0xc6)
+#define CX24116_REG_UCB0    (0xcb)
+#define CX24116_REG_UCB8    (0xca)
+#define CX24116_REG_CLKDIV  (0xf3)
+#define CX24116_REG_RATEDIV (0xf9)
+#define CX24116_REG_FECSTATUS (0x9c)    /* configured fec (not tuned) or actual FEC (tuned) 1=1/2 2=2/3 etc */
+
+/* FECSTATUS bits */
+#define CX24116_FEC_FECMASK   (0x1f)    /* mask to determine configured fec (not tuned) or actual fec (tuned) */
+#define CX24116_FEC_DVBS      (0x20)    /* Select DVB-S demodulator, else DVB-S2 */
+#define CX24116_FEC_UNKNOWN   (0x40)    /* Unknown/unused */
+#define CX24116_FEC_PILOT     (0x80)    /* Pilot mode requested when tuning else always reset when tuned */
+
+/* arg buffer size */
+#define CX24116_ARGLEN (0x1e)
+
+/* rolloff */
+#define CX24116_ROLLOFF_020 (0x00)
+#define CX24116_ROLLOFF_025 (0x01)
+#define CX24116_ROLLOFF_035 (0x02)
+
+/* pilot bit */
+#define CX24116_PILOT_OFF (0x00)
+#define CX24116_PILOT_ON (0x40)
+
+/* signal status */
+#define CX24116_HAS_SIGNAL   (0x01)
+#define CX24116_HAS_CARRIER  (0x02)
+#define CX24116_HAS_VITERBI  (0x04)
+#define CX24116_HAS_SYNCLOCK (0x08)
+#define CX24116_HAS_UNKNOWN1 (0x10)
+#define CX24116_HAS_UNKNOWN2 (0x20)
+#define CX24116_STATUS_MASK  (0x3f)
+#define CX24116_SIGNAL_MASK  (0xc0)
+
+#define CX24116_DISEQC_TONEOFF   (0)    /* toneburst never sent */
+#define CX24116_DISEQC_TONECACHE (1)    /* toneburst cached     */
+#define CX24116_DISEQC_MESGCACHE (2)    /* message cached       */
+
+/* arg offset for DiSEqC */
+#define CX24116_DISEQC_BURST  (1)
+#define CX24116_DISEQC_ARG2_2 (2)   /* unknown value=2 */
+#define CX24116_DISEQC_ARG3_0 (3)   /* unknown value=0 */
+#define CX24116_DISEQC_ARG4_0 (4)   /* unknown value=0 */
+#define CX24116_DISEQC_MSGLEN (5)
+#define CX24116_DISEQC_MSGOFS (6)
+
+/* DiSEqC burst */
+#define CX24116_DISEQC_MINI_A (0)
+#define CX24116_DISEQC_MINI_B (1)
+
+/* DiSEqC tone burst */
+static int toneburst = 1;
+
+/* SNR measurements */
+static int esno_snr = 0;
+
+enum cmds
+{
+       CMD_SET_VCO     = 0x10,
+       CMD_TUNEREQUEST = 0x11,
+       CMD_MPEGCONFIG  = 0x13,
+       CMD_TUNERINIT   = 0x14,
+       CMD_BANDWIDTH   = 0x15,
+       CMD_GETAGC      = 0x19,
+       CMD_LNBCONFIG   = 0x20,
+       CMD_LNBSEND     = 0x21, /* Formerly CMD_SEND_DISEQC */
+       CMD_SET_TONEPRE = 0x22,
+       CMD_SET_TONE    = 0x23,
+       CMD_UPDFWVERS   = 0x35,
+       CMD_TUNERSLEEP  = 0x36,
+       CMD_AGCCONTROL  = 0x3b, /* Unknown */
+};
+
+/* The Demod/Tuner can't easily provide these, we cache them */
+struct cx24116_tuning
+{
+       u32 frequency;
+       u32 symbol_rate;
+       fe_spectral_inversion_t inversion;
+       fe_code_rate_t fec;
+
+       fe_modulation_t modulation;
+       fe_pilot_t pilot;
+       fe_rolloff_t rolloff;
+
+       /* Demod values */
+       u8 fec_val;
+       u8 fec_mask;
+       u8 inversion_val;
+       u8 pilot_val;
+       u8 rolloff_val;
+};
+
+/* Basic commands that are sent to the firmware */
+struct cx24116_cmd
+{
+       u8 len;
+       u8 args[CX24116_ARGLEN];
+};
+
+struct cx24116_state
+{
+       struct i2c_adapter* i2c;
+       const struct cx24116_config* config;
+
+       struct dvb_frontend frontend;
+
+       struct cx24116_tuning dcur;
+       struct cx24116_tuning dnxt;
+
+       u8 skip_fw_load;
+       u8 burst;
+       struct cx24116_cmd dsec_cmd;
+};
+
+static int cx24116_writereg(struct cx24116_state* state, int reg, int data)
+{
+       u8 buf[] = { reg, data };
+       struct i2c_msg msg = { .addr = state->config->demod_address,
+               .flags = 0, .buf = buf, .len = 2 };
+       int err;
+
+       if (debug>1)
+               printk("cx24116: %s: write reg 0x%02x, value 0x%02x\n",
+                                               __func__,reg, data);
+
+       if ((err = i2c_transfer(state->i2c, &msg, 1)) != 1) {
+               printk("%s: writereg error(err == %i, reg == 0x%02x,"
+                        " value == 0x%02x)\n", __func__, err, reg, data);
+               return -EREMOTEIO;
+       }
+
+       return 0;
+}
+
+/* Bulk byte writes to a single I2C address, for 32k firmware load */
+static int cx24116_writeregN(struct cx24116_state* state, int reg, u8 *data, u16 len)
+{
+       int ret = -EREMOTEIO;
+       struct i2c_msg msg;
+       u8 *buf;
+
+       buf = kmalloc(len + 1, GFP_KERNEL);
+       if (buf == NULL) {
+               printk("Unable to kmalloc\n");
+               ret = -ENOMEM;
+               goto error;
+       }
+
+       *(buf) = reg;
+       memcpy(buf + 1, data, len);
+
+       msg.addr = state->config->demod_address;
+       msg.flags = 0;
+       msg.buf = buf;
+       msg.len = len + 1;
+
+       if (debug>1)
+               printk("cx24116: %s:  write regN 0x%02x, len = %d\n",
+                                               __func__,reg, len);
+
+       if ((ret = i2c_transfer(state->i2c, &msg, 1)) != 1) {
+               printk("%s: writereg error(err == %i, reg == 0x%02x\n",
+                        __func__, ret, reg);
+               ret = -EREMOTEIO;
+       }
+
+error:
+       kfree(buf);
+
+       return ret;
+}
+
+static int cx24116_readreg(struct cx24116_state* state, u8 reg)
+{
+       int ret;
+       u8 b0[] = { reg };
+       u8 b1[] = { 0 };
+       struct i2c_msg msg[] = {
+               { .addr = state->config->demod_address, .flags = 0, .buf = b0, .len = 1 },
+               { .addr = state->config->demod_address, .flags = I2C_M_RD, .buf = b1, .len = 1 }
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 2);
+
+       if (ret != 2) {
+               printk("%s: reg=0x%x (error=%d)\n", __func__, reg, ret);
+               return ret;
+       }
+
+       if (debug>1)
+               printk("cx24116: read reg 0x%02x, value 0x%02x\n",reg, b1[0]);
+
+       return b1[0];
+}
+
+static int cx24116_set_inversion(struct cx24116_state* state, fe_spectral_inversion_t inversion)
+{
+       dprintk("%s(%d)\n", __func__, inversion);
+
+       switch (inversion) {
+       case INVERSION_OFF:
+               state->dnxt.inversion_val = 0x00;
+               break;
+       case INVERSION_ON:
+               state->dnxt.inversion_val = 0x04;
+               break;
+       case INVERSION_AUTO:
+               state->dnxt.inversion_val = 0x0C;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       state->dnxt.inversion = inversion;
+
+       return 0;
+}
+
+/*
+ * modfec (modulation and FEC)
+ * ===========================
+ *
+ * MOD          FEC             mask/val    standard
+ * ----         --------        ----------- --------
+ * QPSK         FEC_1_2         0x02 0x02+X DVB-S
+ * QPSK         FEC_2_3         0x04 0x02+X DVB-S
+ * QPSK         FEC_3_4         0x08 0x02+X DVB-S
+ * QPSK         FEC_4_5         0x10 0x02+X DVB-S (?)
+ * QPSK         FEC_5_6         0x20 0x02+X DVB-S
+ * QPSK         FEC_6_7         0x40 0x02+X DVB-S
+ * QPSK         FEC_7_8         0x80 0x02+X DVB-S
+ * QPSK         FEC_8_9         0x01 0x02+X DVB-S (?) (NOT SUPPORTED?)
+ * QPSK         AUTO            0xff 0x02+X DVB-S
+ *
+ * For DVB-S high byte probably represents FEC
+ * and low byte selects the modulator. The high
+ * byte is search range mask. Bit 5 may turn
+ * on DVB-S and remaining bits represent some
+ * kind of calibration (how/what i do not know).
+ *
+ * Eg.(2/3) szap "Zone Horror"
+ *
+ * mask/val = 0x04, 0x20
+ * status 1f | signal c3c0 | snr a333 | ber 00000098 | unc 00000000 | FE_HAS_LOCK
+ *
+ * mask/val = 0x04, 0x30
+ * status 1f | signal c3c0 | snr a333 | ber 00000000 | unc 00000000 | FE_HAS_LOCK
+ *
+ * After tuning FECSTATUS contains actual FEC
+ * in use numbered 1 through to 8 for 1/2 .. 2/3 etc
+ *
+ * NBC=NOT/NON BACKWARD COMPATIBLE WITH DVB-S (DVB-S2 only)
+ *
+ * NBC-QPSK     FEC_1_2         0x00, 0x04      DVB-S2
+ * NBC-QPSK     FEC_3_5         0x00, 0x05      DVB-S2
+ * NBC-QPSK     FEC_2_3         0x00, 0x06      DVB-S2
+ * NBC-QPSK     FEC_3_4         0x00, 0x07      DVB-S2
+ * NBC-QPSK     FEC_4_5         0x00, 0x08      DVB-S2
+ * NBC-QPSK     FEC_5_6         0x00, 0x09      DVB-S2
+ * NBC-QPSK     FEC_8_9         0x00, 0x0a      DVB-S2
+ * NBC-QPSK     FEC_9_10        0x00, 0x0b      DVB-S2
+ *
+ * NBC-8PSK     FEC_3_5         0x00, 0x0c      DVB-S2
+ * NBC-8PSK     FEC_2_3         0x00, 0x0d      DVB-S2
+ * NBC-8PSK     FEC_3_4         0x00, 0x0e      DVB-S2
+ * NBC-8PSK     FEC_5_6         0x00, 0x0f      DVB-S2
+ * NBC-8PSK     FEC_8_9         0x00, 0x10      DVB-S2
+ * NBC-8PSK     FEC_9_10        0x00, 0x11      DVB-S2
+ *
+ * For DVB-S2 low bytes selects both modulator
+ * and FEC. High byte is meaningless here. To
+ * set pilot, bit 6 (0x40) is set. When inspecting
+ * FECSTATUS bit 7 (0x80) represents the pilot
+ * selection whilst not tuned. When tuned, actual FEC
+ * in use is found in FECSTATUS as per above. Pilot
+ * value is reset.
+ */
+
+/* A table of modulation, fec and configuration bytes for the demod.
+ * Not all S2 mmodulation schemes are support and not all rates with
+ * a scheme are support. Especially, no auto detect when in S2 mode.
+ */
+struct cx24116_modfec {
+       fe_delivery_system_t delivery_system;
+       fe_modulation_t modulation;
+       fe_code_rate_t fec;
+       u8 mask;        /* In DVBS mode this is used to autodetect */
+       u8 val;         /* Passed to the firmware to indicate mode selection */
+} CX24116_MODFEC_MODES[] = {
+ /* QPSK. For unknown rates we set hardware to auto detect 0xfe 0x30 */
+
+ /*mod   fec       mask  val */
+ { SYS_DVBS, QPSK, FEC_NONE, 0xfe, 0x30 },
+ { SYS_DVBS, QPSK, FEC_1_2,  0x02, 0x2e }, /* 00000010 00101110 */
+ { SYS_DVBS, QPSK, FEC_2_3,  0x04, 0x2f }, /* 00000100 00101111 */
+ { SYS_DVBS, QPSK, FEC_3_4,  0x08, 0x30 }, /* 00001000 00110000 */
+ { SYS_DVBS, QPSK, FEC_4_5,  0xfe, 0x30 }, /* 000?0000 ?        */
+ { SYS_DVBS, QPSK, FEC_5_6,  0x20, 0x31 }, /* 00100000 00110001 */
+ { SYS_DVBS, QPSK, FEC_6_7,  0xfe, 0x30 }, /* 0?000000 ?        */
+ { SYS_DVBS, QPSK, FEC_7_8,  0x80, 0x32 }, /* 10000000 00110010 */
+ { SYS_DVBS, QPSK, FEC_8_9,  0xfe, 0x30 }, /* 0000000? ?        */
+ { SYS_DVBS, QPSK, FEC_AUTO, 0xfe, 0x30 },
+ /* NBC-QPSK */
+ { SYS_DVBS2, QPSK, FEC_1_2,  0x00, 0x04 },
+ { SYS_DVBS2, QPSK, FEC_3_5,  0x00, 0x05 },
+ { SYS_DVBS2, QPSK, FEC_2_3,  0x00, 0x06 },
+ { SYS_DVBS2, QPSK, FEC_3_4,  0x00, 0x07 },
+ { SYS_DVBS2, QPSK, FEC_4_5,  0x00, 0x08 },
+ { SYS_DVBS2, QPSK, FEC_5_6,  0x00, 0x09 },
+ { SYS_DVBS2, QPSK, FEC_8_9,  0x00, 0x0a },
+ { SYS_DVBS2, QPSK, FEC_9_10, 0x00, 0x0b },
+ /* 8PSK */
+ { SYS_DVBS2, PSK_8, FEC_3_5,  0x00, 0x0c },
+ { SYS_DVBS2, PSK_8, FEC_2_3,  0x00, 0x0d },
+ { SYS_DVBS2, PSK_8, FEC_3_4,  0x00, 0x0e },
+ { SYS_DVBS2, PSK_8, FEC_5_6,  0x00, 0x0f },
+ { SYS_DVBS2, PSK_8, FEC_8_9,  0x00, 0x10 },
+ { SYS_DVBS2, PSK_8, FEC_9_10, 0x00, 0x11 },
+ /*
+  * `val' can be found in the FECSTATUS register when tuning.
+  * FECSTATUS will give the actual FEC in use if tuning was successful.
+  */
+};
+
+static int cx24116_lookup_fecmod(struct cx24116_state* state,
+       fe_modulation_t m, fe_code_rate_t f)
+{
+       int i, ret = -EOPNOTSUPP;
+
+       dprintk("%s(0x%02x,0x%02x)\n", __func__, m, f);
+
+       for(i=0 ; i < sizeof(CX24116_MODFEC_MODES) / sizeof(struct cx24116_modfec) ; i++)
+       {
+               if( (m == CX24116_MODFEC_MODES[i].modulation) &&
+                       (f == CX24116_MODFEC_MODES[i].fec) )
+                       {
+                               ret = i;
+                               break;
+                       }
+       }
+
+       return ret;
+}
+
+static int cx24116_set_fec(struct cx24116_state* state, fe_modulation_t mod, fe_code_rate_t fec)
+{
+       int ret = 0;
+
+       dprintk("%s(0x%02x,0x%02x)\n", __func__, mod, fec);
+
+       ret = cx24116_lookup_fecmod(state, mod, fec);
+
+       if(ret < 0)
+               return ret;
+
+       state->dnxt.fec = fec;
+       state->dnxt.fec_val = CX24116_MODFEC_MODES[ret].val;
+       state->dnxt.fec_mask = CX24116_MODFEC_MODES[ret].mask;
+       dprintk("%s() mask/val = 0x%02x/0x%02x\n", __func__,
+               state->dnxt.fec_mask, state->dnxt.fec_val);
+
+       return 0;
+}
+
+static int cx24116_set_symbolrate(struct cx24116_state* state, u32 rate)
+{
+       dprintk("%s(%d)\n", __func__, rate);
+
+       /*  check if symbol rate is within limits */
+       if ((rate > state->frontend.ops.info.symbol_rate_max) ||
+           (rate < state->frontend.ops.info.symbol_rate_min)) {
+               dprintk("%s() unsupported symbol_rate = %d\n", __func__, rate);
+               return -EOPNOTSUPP;
+       }
+
+       state->dnxt.symbol_rate = rate;
+       dprintk("%s() symbol_rate = %d\n", __func__, rate);
+
+       return 0;
+}
+
+static int cx24116_load_firmware (struct dvb_frontend* fe, const struct firmware *fw);
+
+static int cx24116_firmware_ondemand(struct dvb_frontend* fe)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       const struct firmware *fw;
+       int ret = 0;
+
+       dprintk("%s()\n",__func__);
+
+       if (cx24116_readreg(state, 0x20) > 0)
+       {
+
+               if (state->skip_fw_load)
+                       return 0;
+
+               /* Load firmware */
+               /* request the firmware, this will block until someone uploads it */
+               printk("%s: Waiting for firmware upload (%s)...\n", __func__, CX24116_DEFAULT_FIRMWARE);
+               ret = request_firmware(&fw, CX24116_DEFAULT_FIRMWARE, &state->i2c->dev);
+               printk("%s: Waiting for firmware upload(2)...\n", __func__);
+               if (ret) {
+                       printk("%s: No firmware uploaded (timeout or file not found?)\n", __func__);
+                       return ret;
+               }
+
+               /* Make sure we don't recurse back through here during loading */
+               state->skip_fw_load = 1;
+
+               ret = cx24116_load_firmware(fe, fw);
+               if (ret)
+                       printk("%s: Writing firmware to device failed\n", __func__);
+
+               release_firmware(fw);
+
+               printk("%s: Firmware upload %s\n", __func__, ret == 0 ? "complete" : "failed");
+
+               /* Ensure firmware is always loaded if required */
+               state->skip_fw_load = 0;
+       }
+
+       return ret;
+}
+
+/* Take a basic firmware command structure, format it and forward it for processing */
+static int cx24116_cmd_execute(struct dvb_frontend* fe, struct cx24116_cmd *cmd)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       int i, ret;
+
+       dprintk("%s()\n", __func__);
+
+       /* Load the firmware if required */
+       if ( (ret = cx24116_firmware_ondemand(fe)) != 0)
+       {
+               printk("%s(): Unable initialise the firmware\n", __func__);
+               return ret;
+       }
+
+       /* Write the command */
+       for(i = 0; i < cmd->len ; i++)
+       {
+               dprintk("%s: 0x%02x == 0x%02x\n", __func__, i, cmd->args[i]);
+               cx24116_writereg(state, i, cmd->args[i]);
+       }
+
+       /* Start execution and wait for cmd to terminate */
+       cx24116_writereg(state, CX24116_REG_EXECUTE, 0x01);
+       while( cx24116_readreg(state, CX24116_REG_EXECUTE) )
+       {
+               msleep(10);
+               if(i++ > 64)
+               {
+                       /* Avoid looping forever if the firmware does no respond */
+                       printk("%s() Firmware not responding\n", __func__);
+                       return -EREMOTEIO;
+               }
+       }
+       return 0;
+}
+
+static int cx24116_load_firmware (struct dvb_frontend* fe, const struct firmware *fw)
+{
+       struct cx24116_state* state = fe->demodulator_priv;
+       struct cx24116_cmd cmd;
+       int i, ret;
+       unsigned char vers[4];
+
+       dprintk("%s\n", __func__);
+       dprintk("Firmware is %zu bytes (%02x %02x .. %02x %02x)\n"
+                       ,fw->size
+                       ,fw->data[0]
+                       ,fw->data[1]
+                       ,fw->data[ fw->size-2 ]
+                       ,fw->data[ fw->size-1 ]
+                       );
+
+       /* Toggle 88x SRST pin to reset demod */
+       if (state->config->reset_device)
+               state->config->reset_device(fe);
+
+       /* Begin the firmware load process */
+       /* Prepare the demod, load the firmware, cleanup after load */
+
+       /* Init PLL */
+       cx24116_writereg(state, 0xE5, 0x00);
+       cx24116_writereg(state, 0xF1, 0x08);
+       cx24116_writereg(state, 0xF2, 0x13);
+
+       /* Start PLL */
+       cx24116_writereg(state, 0xe0, 0x03);
+       cx24116_writereg(state, 0xe0, 0x00);
+
+       /* Unknown */
+       cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);
+       cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);
+
+       /* Unknown */
+       cx24116_writereg(state, 0xF0, 0x03);
+       cx24116_writereg(state, 0xF4, 0x81);
+       cx24116_writereg(state, 0xF5, 0x00);
+       cx24116_writereg(state, 0xF6, 0x00);
+
+       /* write the entire firmware as one transaction */
+       cx24116_writeregN(state, 0xF7, fw->data, fw->size);
+
+       cx24116_writereg(state, 0xF4, 0x10);
+       cx24116_writereg(state, 0xF0, 0x00);
+       cx24116_writereg(state, 0xF8, 0x06);
+
+       /* Firmware CMD 10: VCO config */
+       cmd.args[0x00] = CMD_SET_VCO;
+       cmd.args[0x01] = 0x05;
+       cmd.args[0x02] = 0xdc;
+       cmd.args[0x03] = 0xda;
+       cmd.args[0x04] = 0xae;
+       cmd.args[0x05] = 0xaa;
+       cmd.args[0x06] = 0x04;
+       cmd.args[0x07] = 0x9d;
+       cmd.args[0x08] = 0xfc;
+       cmd.args[0x09] = 0x06;
+       cmd.len= 0x0a;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       cx24116_writereg(state, CX24116_REG_SSTATUS, 0x00);
+
+       /* Firmware CMD 14: Tuner config */
+       cmd.args[0x00] = CMD_TUNERINIT;
+       cmd.args[0x01] = 0x00;
+       cmd.args[0x02] = 0x00;
+       cmd.len= 0x03;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       cx24116_writereg(state, 0xe5, 0x00);
+
+       /* Firmware CMD 13: MPEG config */
+       cmd.args[0x00] = CMD_MPEGCONFIG;
+       cmd.args[0x01] = 0x01;
+       cmd.args[0x02] = 0x75;
+       cmd.args[0x03] = 0x00;
+       if (state->config->mpg_clk_pos_pol)
+               cmd.args[0x04] = state->config->mpg_clk_pos_pol;
+       else
+               cmd.args[0x04] = 0x02;
+       cmd.args[0x05] = 0x00;
+       cmd.len= 0x06;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       /* Firmware CMD 35: Get firmware version */
+       cmd.args[0x00] = CMD_UPDFWVERS;
+       cmd.len= 0x02;
+       for(i=0; i<4; i++) {
+               cmd.args[0x01] = i;
+               ret = cx24116_cmd_execute(fe, &cmd);
+               if (ret != 0)
+                       return ret;
+               vers[i]= cx24116_readreg(state, CX24116_REG_MAILBOX);
+       }
+       printk("%s: FW version %i.%i.%i.%i\n", __func__,
+               vers[0], vers[1], vers[2], vers[3]);
+
+       return 0;
+}
+
+static int cx24116_set_voltage(struct dvb_frontend* fe, fe_sec_voltage_t voltage)
+{
+       /* The isl6421 module will override this function in the fops. */
+       dprintk("%s() This should never appear if the isl6421 module is loaded correctly\n",__func__);
+
+       return -EOPNOTSUPP;
+}
+
+static int cx24116_read_status(struct dvb_frontend* fe, fe_status_t* status)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+
+       int lock = cx24116_readreg(state, CX24116_REG_SSTATUS);
+
+       dprintk("%s: status = 0x%02x\n", __func__, lock);
+
+       *status = 0;
+
+       if (lock & CX24116_HAS_SIGNAL)
+               *status |= FE_HAS_SIGNAL;
+       if (lock & CX24116_HAS_CARRIER)
+               *status |= FE_HAS_CARRIER;
+       if (lock & CX24116_HAS_VITERBI)
+               *status |= FE_HAS_VITERBI;
+       if (lock & CX24116_HAS_SYNCLOCK)
+               *status |= FE_HAS_SYNC | FE_HAS_LOCK;
+
+       return 0;
+}
+
+static int cx24116_read_ber(struct dvb_frontend* fe, u32* ber)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+
+       dprintk("%s()\n", __func__);
+
+       *ber =  ( cx24116_readreg(state, CX24116_REG_BER24) << 24 ) |
+               ( cx24116_readreg(state, CX24116_REG_BER16) << 16 ) |
+               ( cx24116_readreg(state, CX24116_REG_BER8 ) << 8  ) |
+                 cx24116_readreg(state, CX24116_REG_BER0 );
+
+       return 0;
+}
+
+/* TODO Determine function and scale appropriately */
+static int cx24116_read_signal_strength(struct dvb_frontend* fe, u16* signal_strength)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       struct cx24116_cmd cmd;
+       int ret;
+       u16 sig_reading;
+
+       dprintk("%s()\n", __func__);
+
+       /* Firmware CMD 19: Get AGC */
+       cmd.args[0x00] = CMD_GETAGC;
+       cmd.len= 0x01;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       sig_reading = ( cx24116_readreg(state, CX24116_REG_SSTATUS) & CX24116_SIGNAL_MASK ) |
+               ( cx24116_readreg(state, CX24116_REG_SIGNAL) << 6 );
+       *signal_strength= 0 - sig_reading;
+
+       dprintk("%s: raw / cooked = 0x%04x / 0x%04x\n", __func__, sig_reading, *signal_strength);
+
+       return 0;
+}
+
+/* SNR (0..100)% = (sig & 0xf0) * 10 + (sig & 0x0f) * 10 / 16 */
+static int cx24116_read_snr_pct(struct dvb_frontend* fe, u16* snr)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       u8 snr_reading;
+       static const u32 snr_tab[] = { /* 10 x Table (rounded up) */
+               0x00000,0x0199A,0x03333,0x04ccD,0x06667,
+                       0x08000,0x0999A,0x0b333,0x0cccD,0x0e667,
+               0x10000,0x1199A,0x13333,0x14ccD,0x16667,0x18000 };
+
+       dprintk("%s()\n", __func__);
+
+       snr_reading = cx24116_readreg(state, CX24116_REG_QUALITY0);
+
+       if(snr_reading >= 0xa0 /* 100% */)
+               *snr = 0xffff;
+       else
+               *snr = snr_tab [ ( snr_reading & 0xf0 )   >> 4 ] +
+                       ( snr_tab [ ( snr_reading & 0x0f ) ] >> 4 );
+
+       dprintk("%s: raw / cooked = 0x%02x / 0x%04x\n", __func__,
+               snr_reading, *snr);
+
+       return 0;
+}
+
+/* The reelbox patches show the value in the registers represents
+ * ESNO, from 0->30db (values 0->300). We provide this value by
+ * default.
+ */
+static int cx24116_read_snr_esno(struct dvb_frontend* fe, u16* snr)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+
+       dprintk("%s()\n", __func__);
+
+       *snr = cx24116_readreg(state, CX24116_REG_QUALITY8) << 8 |
+               cx24116_readreg(state, CX24116_REG_QUALITY0);
+
+       dprintk("%s: raw 0x%04x\n", __func__, *snr);
+
+       return 0;
+}
+
+static int cx24116_read_snr(struct dvb_frontend* fe, u16* snr)
+{
+       if (esno_snr == 1)
+               return cx24116_read_snr_esno(fe, snr);
+       else
+               return cx24116_read_snr_pct(fe, snr);
+}
+
+static int cx24116_read_ucblocks(struct dvb_frontend* fe, u32* ucblocks)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+
+       dprintk("%s()\n", __func__);
+
+       *ucblocks = ( cx24116_readreg(state, CX24116_REG_UCB8) << 8 ) |
+               cx24116_readreg(state, CX24116_REG_UCB0);
+
+       return 0;
+}
+
+/* Overwrite the current tuning params, we are about to tune */
+static void cx24116_clone_params(struct dvb_frontend* fe)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       memcpy(&state->dcur, &state->dnxt, sizeof(state->dcur));
+}
+
+/* Wait for LNB */
+static int cx24116_wait_for_lnb(struct dvb_frontend* fe)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       int i;
+
+       dprintk("%s() qstatus = 0x%02x\n", __func__,
+               cx24116_readreg(state, CX24116_REG_QSTATUS));
+
+       /* Wait for up to 300 ms */
+       for(i = 0; i < 30 ; i++) {
+               if (cx24116_readreg(state, CX24116_REG_QSTATUS) & 0x20)
+                       return 0;
+               msleep(10);
+       }
+
+       dprintk("%s(): LNB not ready\n", __func__);
+
+       return -ETIMEDOUT; /* -EBUSY ? */
+}
+
+static int cx24116_set_tone(struct dvb_frontend* fe, fe_sec_tone_mode_t tone)
+{
+       struct cx24116_cmd cmd;
+       int ret;
+
+       dprintk("%s(%d)\n", __func__, tone);
+       if ( (tone != SEC_TONE_ON) && (tone != SEC_TONE_OFF) ) {
+               printk("%s: Invalid, tone=%d\n", __func__, tone);
+               return -EINVAL;
+       }
+
+       /* Wait for LNB ready */
+       ret = cx24116_wait_for_lnb(fe);
+       if(ret != 0)
+               return ret;
+
+       /* Min delay time after DiSEqC send */
+       msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */
+
+       /* This is always done before the tone is set */
+       cmd.args[0x00] = CMD_SET_TONEPRE;
+       cmd.args[0x01] = 0x00;
+       cmd.len= 0x02;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       /* Now we set the tone */
+       cmd.args[0x00] = CMD_SET_TONE;
+       cmd.args[0x01] = 0x00;
+       cmd.args[0x02] = 0x00;
+
+       switch (tone) {
+       case SEC_TONE_ON:
+               dprintk("%s: setting tone on\n", __func__);
+               cmd.args[0x03] = 0x01;
+               break;
+       case SEC_TONE_OFF:
+               dprintk("%s: setting tone off\n",__func__);
+               cmd.args[0x03] = 0x00;
+               break;
+       }
+       cmd.len= 0x04;
+
+       /* Min delay time before DiSEqC send */
+       msleep(15); /* XXX determine is FW does this, see send_diseqc/burst */
+
+       return cx24116_cmd_execute(fe, &cmd);
+}
+
+/* Initialise DiSEqC */
+static int cx24116_diseqc_init(struct dvb_frontend* fe)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       struct cx24116_cmd cmd;
+       int ret;
+
+       /* Firmware CMD 20: LNB/DiSEqC config */
+       cmd.args[0x00] = CMD_LNBCONFIG;
+       cmd.args[0x01] = 0x00;
+       cmd.args[0x02] = 0x10;
+       cmd.args[0x03] = 0x00;
+       cmd.args[0x04] = 0x8f;
+       cmd.args[0x05] = 0x28;
+       cmd.args[0x06] = (toneburst == CX24116_DISEQC_TONEOFF) ? 0x00 : 0x01;
+       cmd.args[0x07] = 0x01;
+       cmd.len= 0x08;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       /* Prepare a DiSEqC command */
+       state->dsec_cmd.args[0x00] = CMD_LNBSEND;
+
+       /* DiSEqC burst */
+       state->dsec_cmd.args[CX24116_DISEQC_BURST]  = CX24116_DISEQC_MINI_A;
+
+       /* Unknown */
+       state->dsec_cmd.args[CX24116_DISEQC_ARG2_2] = 0x02;
+       state->dsec_cmd.args[CX24116_DISEQC_ARG3_0] = 0x00;
+       state->dsec_cmd.args[CX24116_DISEQC_ARG4_0] = 0x00; /* Continuation flag? */
+
+       /* DiSEqC message length */
+       state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = 0x00;
+
+       /* Command length */
+       state->dsec_cmd.len= CX24116_DISEQC_MSGOFS;
+
+       return 0;
+}
+
+/* Send DiSEqC message with derived burst (hack) || previous burst */
+static int cx24116_send_diseqc_msg(struct dvb_frontend* fe, struct dvb_diseqc_master_cmd *d)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       int i, ret;
+
+       /* Dump DiSEqC message */
+       if (debug) {
+               printk("cx24116: %s(", __func__);
+               for(i = 0 ; i < d->msg_len ;) {
+                       printk("0x%02x", d->msg[i]);
+                       if(++i < d->msg_len)
+                               printk(", ");
+                       }
+               printk(") toneburst=%d\n", toneburst);
+       }
+
+       /* Validate length */
+       if(d->msg_len > (CX24116_ARGLEN - CX24116_DISEQC_MSGOFS))
+               return -EINVAL;
+
+       /* DiSEqC message */
+       for (i = 0; i < d->msg_len; i++)
+               state->dsec_cmd.args[CX24116_DISEQC_MSGOFS + i] = d->msg[i];
+
+       /* DiSEqC message length */
+       state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] = d->msg_len;
+
+       /* Command length */
+       state->dsec_cmd.len= CX24116_DISEQC_MSGOFS + state->dsec_cmd.args[CX24116_DISEQC_MSGLEN];
+
+       /* DiSEqC toneburst */
+       if(toneburst == CX24116_DISEQC_MESGCACHE)
+               /* Message is cached */
+               return 0;
+
+       else if(toneburst == CX24116_DISEQC_TONEOFF)
+               /* Message is sent without burst */
+               state->dsec_cmd.args[CX24116_DISEQC_BURST] = 0;
+
+       else if(toneburst == CX24116_DISEQC_TONECACHE) {
+               /*
+                * Message is sent with derived else cached burst
+                *
+                * WRITE PORT GROUP COMMAND 38
+                *
+                * 0/A/A: E0 10 38 F0..F3
+                * 1/B/B: E0 10 38 F4..F7
+                * 2/C/A: E0 10 38 F8..FB
+                * 3/D/B: E0 10 38 FC..FF
+                *
+                * databyte[3]= 8421:8421
+                *              ABCD:WXYZ
+                *              CLR :SET
+                *
+                *              WX= PORT SELECT 0..3    (X=TONEBURST)
+                *              Y = VOLTAGE             (0=13V, 1=18V)
+                *              Z = BAND                (0=LOW, 1=HIGH(22K))
+                */
+               if(d->msg_len >= 4 && d->msg[2] == 0x38)
+                       state->dsec_cmd.args[CX24116_DISEQC_BURST] = ((d->msg[3] & 4) >> 2);
+               if(debug)
+                       dprintk("%s burst=%d\n", __func__, state->dsec_cmd.args[CX24116_DISEQC_BURST]);
+       }
+
+       /* Wait for LNB ready */
+       ret = cx24116_wait_for_lnb(fe);
+       if(ret != 0)
+               return ret;
+
+       /* Wait for voltage/min repeat delay */
+       msleep(100);
+
+       /* Command */
+       ret = cx24116_cmd_execute(fe, &state->dsec_cmd);
+       if(ret != 0)
+               return ret;
+       /*
+        * Wait for send
+        *
+        * Eutelsat spec:
+        * >15ms delay          + (XXX determine if FW does this, see set_tone)
+        *  13.5ms per byte     +
+        * >15ms delay          +
+        *  12.5ms burst        +
+        * >15ms delay            (XXX determine if FW does this, see set_tone)
+        */
+       msleep( (state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) + ((toneburst == CX24116_DISEQC_TONEOFF) ? 30 : 60) );
+
+       return 0;
+}
+
+/* Send DiSEqC burst */
+static int cx24116_diseqc_send_burst(struct dvb_frontend* fe, fe_sec_mini_cmd_t burst)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       int ret;
+
+       dprintk("%s(%d) toneburst=%d\n",__func__, burst, toneburst);
+
+       /* DiSEqC burst */
+       if (burst == SEC_MINI_A)
+               state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_A;
+       else if(burst == SEC_MINI_B)
+               state->dsec_cmd.args[CX24116_DISEQC_BURST] = CX24116_DISEQC_MINI_B;
+       else
+               return -EINVAL;
+
+       /* DiSEqC toneburst */
+       if(toneburst != CX24116_DISEQC_MESGCACHE)
+               /* Burst is cached */
+               return 0;
+
+       /* Burst is to be sent with cached message */
+
+       /* Wait for LNB ready */
+       ret = cx24116_wait_for_lnb(fe);
+       if(ret != 0)
+               return ret;
+
+       /* Wait for voltage/min repeat delay */
+       msleep(100);
+
+       /* Command */
+       ret = cx24116_cmd_execute(fe, &state->dsec_cmd);
+       if(ret != 0)
+               return ret;
+
+       /*
+        * Wait for send
+        *
+        * Eutelsat spec:
+        * >15ms delay          + (XXX determine if FW does this, see set_tone)
+        *  13.5ms per byte     +
+        * >15ms delay          +
+        *  12.5ms burst        +
+        * >15ms delay            (XXX determine if FW does this, see set_tone)
+        */
+       msleep( (state->dsec_cmd.args[CX24116_DISEQC_MSGLEN] << 4) + 60 );
+
+       return 0;
+}
+
+static void cx24116_release(struct dvb_frontend* fe)
+{
+       struct cx24116_state* state = fe->demodulator_priv;
+       dprintk("%s\n",__func__);
+       kfree(state);
+}
+
+static struct dvb_frontend_ops cx24116_ops;
+
+struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
+                                   struct i2c_adapter* i2c)
+{
+       struct cx24116_state* state = NULL;
+       int ret;
+
+       dprintk("%s\n",__func__);
+
+       /* allocate memory for the internal state */
+       state = kmalloc(sizeof(struct cx24116_state), GFP_KERNEL);
+       if (state == NULL) {
+               printk("Unable to kmalloc\n");
+               goto error1;
+       }
+
+       /* setup the state */
+       memset(state, 0, sizeof(struct cx24116_state));
+
+       state->config = config;
+       state->i2c = i2c;
+
+       /* check if the demod is present */
+       ret = (cx24116_readreg(state, 0xFF) << 8) | cx24116_readreg(state, 0xFE);
+       if (ret != 0x0501) {
+               printk("Invalid probe, probably not a CX24116 device\n");
+               goto error2;
+       }
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &cx24116_ops, sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+       return &state->frontend;
+
+error2: kfree(state);
+error1: return NULL;
+}
+/*
+ * Initialise or wake up device
+ *
+ * Power config will reset and load initial firmware if required
+ */
+static int cx24116_initfe(struct dvb_frontend* fe)
+{
+       struct cx24116_state* state = fe->demodulator_priv;
+       struct cx24116_cmd cmd;
+       int ret;
+
+       dprintk("%s()\n",__func__);
+
+       /* Power on */
+       cx24116_writereg(state, 0xe0, 0);
+       cx24116_writereg(state, 0xe1, 0);
+       cx24116_writereg(state, 0xea, 0);
+
+       /* Firmware CMD 36: Power config */
+       cmd.args[0x00] = CMD_TUNERSLEEP;
+       cmd.args[0x01] = 0;
+       cmd.len= 0x02;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if(ret != 0)
+               return ret;
+
+       return cx24116_diseqc_init(fe);
+}
+
+/*
+ * Put device to sleep
+ */
+static int cx24116_sleep(struct dvb_frontend* fe)
+{
+       struct cx24116_state* state = fe->demodulator_priv;
+       struct cx24116_cmd cmd;
+       int ret;
+
+       dprintk("%s()\n",__func__);
+
+       /* Firmware CMD 36: Power config */
+       cmd.args[0x00] = CMD_TUNERSLEEP;
+       cmd.args[0x01] = 1;
+       cmd.len= 0x02;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if(ret != 0)
+               return ret;
+
+       /* Power off (Shutdown clocks) */
+       cx24116_writereg(state, 0xea, 0xff);
+       cx24116_writereg(state, 0xe1, 1);
+       cx24116_writereg(state, 0xe0, 1);
+
+       return 0;
+}
+
+static int cx24116_set_property(struct dvb_frontend *fe, struct dtv_property* tvp)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+static int cx24116_get_property(struct dvb_frontend *fe, struct dtv_property* tvp)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+/* dvb-core told us to tune, the tv property cache will be complete,
+ * it's safe for is to pull values and use them for tuning purposes.
+ */
+static int cx24116_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
+{
+       struct cx24116_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+       struct cx24116_cmd cmd;
+       fe_status_t tunerstat;
+       int i, status, ret, retune;
+
+       dprintk("%s()\n",__func__);
+
+       switch(c->delivery_system) {
+               case SYS_DVBS:
+                       dprintk("%s: DVB-S delivery system selected\n",__func__);
+
+                       /* Only QPSK is supported for DVB-S */
+                       if(c->modulation != QPSK) {
+                               dprintk("%s: unsupported modulation selected (%d)\n",
+                                       __func__, c->modulation);
+                               return -EOPNOTSUPP;
+                       }
+
+                       /* Pilot doesn't exist in DVB-S, turn bit off */
+                       state->dnxt.pilot_val = CX24116_PILOT_OFF;
+                       retune = 1;
+
+                       /* DVB-S only supports 0.35 */
+                       if(c->rolloff != ROLLOFF_35) {
+                               dprintk("%s: unsupported rolloff selected (%d)\n",
+                                       __func__, c->rolloff);
+                               return -EOPNOTSUPP;
+                       }
+                       state->dnxt.rolloff_val = CX24116_ROLLOFF_035;
+                       break;
+
+               case SYS_DVBS2:
+                       dprintk("%s: DVB-S2 delivery system selected\n",__func__);
+
+                       /*
+                        * NBC 8PSK/QPSK with DVB-S is supported for DVB-S2,
+                        * but not hardware auto detection
+                        */
+                       if(c->modulation != PSK_8 && c->modulation != QPSK) {
+                               dprintk("%s: unsupported modulation selected (%d)\n",
+                                       __func__, c->modulation);
+                               return -EOPNOTSUPP;
+                       }
+
+                       switch(c->pilot) {
+                               case PILOT_AUTO:        /* Not supported but emulated */
+                                       retune = 2;     /* Fall-through */
+                               case PILOT_OFF:
+                                       state->dnxt.pilot_val = CX24116_PILOT_OFF;
+                                       break;
+                               case PILOT_ON:
+                                       state->dnxt.pilot_val = CX24116_PILOT_ON;
+                                       break;
+                               default:
+                                       dprintk("%s: unsupported pilot mode selected (%d)\n",
+                                               __func__, c->pilot);
+                                       return -EOPNOTSUPP;
+                       }
+
+                       switch(c->rolloff) {
+                               case ROLLOFF_20:
+                                       state->dnxt.rolloff_val= CX24116_ROLLOFF_020;
+                                       break;
+                               case ROLLOFF_25:
+                                       state->dnxt.rolloff_val= CX24116_ROLLOFF_025;
+                                       break;
+                               case ROLLOFF_35:
+                                       state->dnxt.rolloff_val= CX24116_ROLLOFF_035;
+                                       break;
+                               case ROLLOFF_AUTO:      /* Rolloff must be explicit */
+                               default:
+                                       dprintk("%s: unsupported rolloff selected (%d)\n",
+                                               __func__, c->rolloff);
+                                       return -EOPNOTSUPP;
+                       }
+                       break;
+
+               default:
+                       dprintk("%s: unsupported delivery system selected (%d)\n",
+                               __func__, c->delivery_system);
+                       return -EOPNOTSUPP;
+       }
+       state->dnxt.modulation = c->modulation;
+       state->dnxt.frequency = c->frequency;
+       state->dnxt.pilot = c->pilot;
+       state->dnxt.rolloff = c->rolloff;
+
+       if ((ret = cx24116_set_inversion(state, c->inversion)) !=  0)
+               return ret;
+
+       /* FEC_NONE/AUTO for DVB-S2 is not supported and detected here */
+       if ((ret = cx24116_set_fec(state, c->modulation, c->fec_inner)) !=  0)
+               return ret;
+
+       if ((ret = cx24116_set_symbolrate(state, c->symbol_rate)) !=  0)
+               return ret;
+
+       /* discard the 'current' tuning parameters and prepare to tune */
+       cx24116_clone_params(fe);
+
+       dprintk("%s:   modulation  = %d\n", __func__, state->dcur.modulation);
+       dprintk("%s:   frequency   = %d\n", __func__, state->dcur.frequency);
+       dprintk("%s:   pilot       = %d (val = 0x%02x)\n", __func__,
+               state->dcur.pilot, state->dcur.pilot_val);
+       dprintk("%s:   retune      = %d\n", __func__, retune);
+       dprintk("%s:   rolloff     = %d (val = 0x%02x)\n", __func__,
+               state->dcur.rolloff, state->dcur.rolloff_val);
+       dprintk("%s:   symbol_rate = %d\n", __func__, state->dcur.symbol_rate);
+       dprintk("%s:   FEC         = %d (mask/val = 0x%02x/0x%02x)\n", __func__,
+               state->dcur.fec, state->dcur.fec_mask, state->dcur.fec_val);
+       dprintk("%s:   Inversion   = %d (val = 0x%02x)\n", __func__,
+               state->dcur.inversion, state->dcur.inversion_val);
+
+       /* This is also done in advise/acquire on HVR4000 but not on LITE */
+       if (state->config->set_ts_params)
+               state->config->set_ts_params(fe, 0);
+
+       /* Set/Reset B/W */
+       cmd.args[0x00] = CMD_BANDWIDTH;
+       cmd.args[0x01] = 0x01;
+       cmd.len= 0x02;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       /* Prepare a tune request */
+       cmd.args[0x00] = CMD_TUNEREQUEST;
+
+       /* Frequency */
+       cmd.args[0x01] = (state->dcur.frequency & 0xff0000) >> 16;
+       cmd.args[0x02] = (state->dcur.frequency & 0x00ff00) >> 8;
+       cmd.args[0x03] = (state->dcur.frequency & 0x0000ff);
+
+       /* Symbol Rate */
+       cmd.args[0x04] = ((state->dcur.symbol_rate / 1000) & 0xff00) >> 8;
+       cmd.args[0x05] = ((state->dcur.symbol_rate / 1000) & 0x00ff);
+
+       /* Automatic Inversion */
+       cmd.args[0x06] = state->dcur.inversion_val;
+
+       /* Modulation / FEC / Pilot */
+       cmd.args[0x07] = state->dcur.fec_val | state->dcur.pilot_val;
+
+       cmd.args[0x08] = CX24116_SEARCH_RANGE_KHZ >> 8;
+       cmd.args[0x09] = CX24116_SEARCH_RANGE_KHZ & 0xff;
+       cmd.args[0x0a] = 0x00;
+       cmd.args[0x0b] = 0x00;
+       cmd.args[0x0c] = state->dcur.rolloff_val;
+       cmd.args[0x0d] = state->dcur.fec_mask;
+
+       if (state->dcur.symbol_rate > 30000000) {
+               cmd.args[0x0e] = 0x04;
+               cmd.args[0x0f] = 0x00;
+               cmd.args[0x10] = 0x01;
+               cmd.args[0x11] = 0x77;
+               cmd.args[0x12] = 0x36;
+               cx24116_writereg(state, CX24116_REG_CLKDIV, 0x44);
+               cx24116_writereg(state, CX24116_REG_RATEDIV, 0x01);
+       } else {
+               cmd.args[0x0e] = 0x06;
+               cmd.args[0x0f] = 0x00;
+               cmd.args[0x10] = 0x00;
+               cmd.args[0x11] = 0xFA;
+               cmd.args[0x12] = 0x24;
+               cx24116_writereg(state, CX24116_REG_CLKDIV, 0x46);
+               cx24116_writereg(state, CX24116_REG_RATEDIV, 0x00);
+       }
+
+       cmd.len= 0x13;
+
+       /* We need to support pilot and non-pilot tuning in the
+        * driver automatically. This is a workaround for because
+        * the demod does not support autodetect.
+        */
+       do {
+               /* Reset status register */
+               status = cx24116_readreg(state, CX24116_REG_SSTATUS) & CX24116_SIGNAL_MASK;
+               cx24116_writereg(state, CX24116_REG_SSTATUS, status);
+
+               /* Tune */
+               ret = cx24116_cmd_execute(fe, &cmd);
+               if( ret != 0 )
+                       break;
+
+               /*
+                * Wait for up to 500 ms before retrying
+                *
+                * If we are able to tune then generally it occurs within 100ms.
+                * If it takes longer, try a different toneburst setting.
+                */
+               for(i = 0; i < 50 ; i++) {
+                       cx24116_read_status(fe, &tunerstat);
+                       status = tunerstat & (FE_HAS_SIGNAL | FE_HAS_SYNC);
+                       if(status == (FE_HAS_SIGNAL | FE_HAS_SYNC)) {
+                               dprintk("%s: Tuned\n",__func__);
+                               goto tuned;
+                       }
+                       msleep(10);
+               }
+
+               dprintk("%s: Not tuned\n",__func__);
+
+               /* Toggle pilot bit when in auto-pilot */
+               if(state->dcur.pilot == PILOT_AUTO)
+                       cmd.args[0x07] ^= CX24116_PILOT_ON;
+       }
+       while(--retune);
+
+tuned:  /* Set/Reset B/W */
+       cmd.args[0x00] = CMD_BANDWIDTH;
+       cmd.args[0x01] = 0x00;
+       cmd.len= 0x02;
+       ret = cx24116_cmd_execute(fe, &cmd);
+       if (ret != 0)
+               return ret;
+
+       return ret;
+}
+
+static struct dvb_frontend_ops cx24116_ops = {
+
+       .info = {
+               .name = "Conexant CX24116/CX24118",
+               .type = FE_QPSK,
+               .frequency_min = 950000,
+               .frequency_max = 2150000,
+               .frequency_stepsize = 1011, /* kHz for QPSK frontends */
+               .frequency_tolerance = 5000,
+               .symbol_rate_min = 1000000,
+               .symbol_rate_max = 45000000,
+               .caps = FE_CAN_INVERSION_AUTO |
+                       FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+                       FE_CAN_FEC_4_5 | FE_CAN_FEC_5_6 | FE_CAN_FEC_6_7 |
+                       FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
+                       FE_CAN_QPSK | FE_CAN_RECOVER
+       },
+
+       .release = cx24116_release,
+
+       .init = cx24116_initfe,
+       .sleep = cx24116_sleep,
+       .read_status = cx24116_read_status,
+       .read_ber = cx24116_read_ber,
+       .read_signal_strength = cx24116_read_signal_strength,
+       .read_snr = cx24116_read_snr,
+       .read_ucblocks = cx24116_read_ucblocks,
+       .set_tone = cx24116_set_tone,
+       .set_voltage = cx24116_set_voltage,
+       .diseqc_send_master_cmd = cx24116_send_diseqc_msg,
+       .diseqc_send_burst = cx24116_diseqc_send_burst,
+
+       .set_property = cx24116_set_property,
+       .get_property = cx24116_get_property,
+       .set_frontend = cx24116_set_frontend,
+};
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
+
+module_param(toneburst, int, 0644);
+MODULE_PARM_DESC(toneburst, "DiSEqC toneburst 0=OFF, 1=TONE CACHE, 2=MESSAGE CACHE (default:1)");
+
+module_param(esno_snr, int, 0644);
+MODULE_PARM_DESC(debug, "SNR return units, 0=PERCENTAGE 0-100, 1=ESNO(db * 10) (default:0)");
+
+MODULE_DESCRIPTION("DVB Frontend module for Conexant cx24116/cx24118 hardware");
+MODULE_AUTHOR("Steven Toth");
+MODULE_LICENSE("GPL");
+
+EXPORT_SYMBOL(cx24116_attach);
diff --git a/drivers/media/dvb/frontends/cx24116.h b/drivers/media/dvb/frontends/cx24116.h
new file mode 100644 (file)
index 0000000..8dbcec2
--- /dev/null
@@ -0,0 +1,53 @@
+/*
+    Conexant cx24116/cx24118 - DVBS/S2 Satellite demod/tuner driver
+
+    Copyright (C) 2006 Steven Toth <stoth@linuxtv.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+*/
+
+#ifndef CX24116_H
+#define CX24116_H
+
+#include <linux/dvb/frontend.h>
+
+struct cx24116_config
+{
+       /* the demodulator's i2c address */
+       u8 demod_address;
+
+       /* Need to set device param for start_dma */
+       int (*set_ts_params)(struct dvb_frontend* fe, int is_punctured);
+
+       /* Need to reset device during firmware loading */
+       int (*reset_device)(struct dvb_frontend* fe);
+
+       /* Need to set MPEG parameters */
+       u8 mpg_clk_pos_pol:0x02;
+};
+
+#if defined(CONFIG_DVB_CX24116) || defined(CONFIG_DVB_CX24116_MODULE)
+extern struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
+                                          struct i2c_adapter* i2c);
+#else
+static inline struct dvb_frontend* cx24116_attach(const struct cx24116_config* config,
+                                                 struct i2c_adapter* i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
+       return NULL;
+}
+#endif // CONFIG_DVB_CX24116
+
+#endif /* CX24116_H */
index 3eedfdf505bc5d49f6551268dc966544bc17fa83..21f2c5161af4887c2a8e7ff9dc7b4c98762f01f7 100644 (file)
@@ -41,6 +41,7 @@ struct dib0070_config {
 extern struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
                                           struct i2c_adapter *i2c,
                                           struct dib0070_config *cfg);
+extern u16 dib0070_wbd_offset(struct dvb_frontend *);
 #else
 static inline struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
                                                  struct i2c_adapter *i2c,
@@ -49,9 +50,14 @@ static inline struct dvb_frontend *dib0070_attach(struct dvb_frontend *fe,
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
 }
+
+static inline u16 dib0070_wbd_offset(struct dvb_frontend *fe)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return -ENODEV;
+}
 #endif
 
 extern void dib0070_ctrl_agc_filter(struct dvb_frontend *, uint8_t open);
-extern u16 dib0070_wbd_offset(struct dvb_frontend *);
 
 #endif
index 5f1375e30dfc25e3bff127b8bf6ebbf4ef2e420e..0109720353bd475e6458c347ea42dfca0663d3de 100644 (file)
@@ -1284,7 +1284,10 @@ struct i2c_adapter * dib7000m_get_i2c_master(struct dvb_frontend *demod, enum di
 }
 EXPORT_SYMBOL(dib7000m_get_i2c_master);
 
-int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000m_config cfg[])
+#if 0
+/* used with some prototype boards */
+int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods,
+               u8 default_addr, struct dib7000m_config cfg[])
 {
        struct dib7000m_state st = { .i2c_adap = i2c };
        int k = 0;
@@ -1329,6 +1332,7 @@ int dib7000m_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 defau
        return 0;
 }
 EXPORT_SYMBOL(dib7000m_i2c_enumeration);
+#endif
 
 static struct dvb_frontend_ops dib7000m_ops;
 struct dvb_frontend * dib7000m_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr, struct dib7000m_config *cfg)
index 1a0142e0d74166a5576d11f27f4159403fcd78f0..8217e5b38f47064e464942ff3b75fa3b8e8ce53c 100644 (file)
@@ -1333,7 +1333,8 @@ struct dvb_frontend * dib7000p_attach(struct i2c_adapter *i2c_adap, u8 i2c_addr,
        /* Ensure the output mode remains at the previous default if it's
         * not specifically set by the caller.
         */
-       if (st->cfg.output_mode != OUTMODE_MPEG2_SERIAL)
+       if ((st->cfg.output_mode != OUTMODE_MPEG2_SERIAL) &&
+           (st->cfg.output_mode != OUTMODE_MPEG2_PAR_GATED_CLK))
                st->cfg.output_mode = OUTMODE_MPEG2_FIFO;
 
        demod                   = &st->demod;
index 07c4d12ed5b7846bf3e9589cd2236fe49668fa9f..3e81268571276f895e2c1d6075d2ba44209953f7 100644 (file)
@@ -41,6 +41,14 @@ struct dib7000p_config {
 extern struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
                                            u8 i2c_addr,
                                            struct dib7000p_config *cfg);
+extern struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *,
+                                                  enum dibx000_i2c_interface,
+                                                  int);
+extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
+                                   int no_of_demods, u8 default_addr,
+                                   struct dib7000p_config cfg[]);
+extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
+extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
 #else
 static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
                                                   u8 i2c_addr,
@@ -49,13 +57,36 @@ static inline struct dvb_frontend *dib7000p_attach(struct i2c_adapter *i2c_adap,
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
 }
-#endif
 
-extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c, int no_of_demods, u8 default_addr, struct dib7000p_config cfg[]);
+static inline
+struct i2c_adapter *dib7000p_get_i2c_master(struct dvb_frontend *fe,
+                                           enum dibx000_i2c_interface i, int x)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+
+extern int dib7000p_i2c_enumeration(struct i2c_adapter *i2c,
+                                   int no_of_demods, u8 default_addr,
+                                   struct dib7000p_config cfg[])
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return -ENODEV;
+}
+
+extern int dib7000p_set_gpio(struct dvb_frontend *fe, u8 num, u8 dir, u8 val)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return -ENODEV;
+}
+
+extern int dib7000p_set_wbd_ref(struct dvb_frontend *fe, u16 value)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return -ENODEV;
+}
+#endif
 
-extern struct i2c_adapter * dib7000p_get_i2c_master(struct dvb_frontend *, enum dibx000_i2c_interface, int);
 extern int dib7000pc_detection(struct i2c_adapter *i2c_adap);
-extern int dib7000p_set_gpio(struct dvb_frontend *, u8 num, u8 dir, u8 val);
-extern int dib7000p_set_wbd_ref(struct dvb_frontend *, u16 value);
 
 #endif
index 3cbed874a6f8346b28e63e74ac004dc59f29bc1a..b9ca5c8d2dd9400814f64566a24952b541126a0a 100644 (file)
@@ -38,35 +38,32 @@ static const char mod_name[] = "drx397xD";
 #define F_SET_0D0h     1
 #define F_SET_0D4h     2
 
-typedef enum fw_ix {
+enum fw_ix {
 #define _FW_ENTRY(a, b)                b
 #include "drx397xD_fw.h"
-} fw_ix_t;
+};
 
 /* chip specifics */
 struct drx397xD_state {
        struct i2c_adapter *i2c;
        struct dvb_frontend frontend;
        struct drx397xD_config config;
-       fw_ix_t chip_rev;
+       enum fw_ix chip_rev;
        int flags;
        u32 bandwidth_parm;     /* internal bandwidth conversions */
        u32 f_osc;              /* w90: actual osc frequency [Hz] */
 };
 
-/*******************************************************************************
- * Firmware
- ******************************************************************************/
-
+/* Firmware */
 static const char *blob_name[] = {
 #define _BLOB_ENTRY(a, b)              a
 #include "drx397xD_fw.h"
 };
 
-typedef enum blob_ix {
+enum blob_ix {
 #define _BLOB_ENTRY(a, b)              b
 #include "drx397xD_fw.h"
-} blob_ix_t;
+};
 
 static struct {
        const char *name;
@@ -85,7 +82,7 @@ static struct {
 };
 
 /* use only with writer lock aquired */
-static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix)
+static void _drx_release_fw(struct drx397xD_state *s, enum fw_ix ix)
 {
        memset(&fw[ix].data[0], 0, sizeof(fw[0].data));
        if (fw[ix].file)
@@ -94,9 +91,9 @@ static void _drx_release_fw(struct drx397xD_state *s, fw_ix_t ix)
 
 static void drx_release_fw(struct drx397xD_state *s)
 {
-       fw_ix_t ix = s->chip_rev;
+       enum fw_ix ix = s->chip_rev;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        write_lock(&fw[ix].lock);
        if (fw[ix].refcnt) {
@@ -107,13 +104,13 @@ static void drx_release_fw(struct drx397xD_state *s)
        write_unlock(&fw[ix].lock);
 }
 
-static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix)
+static int drx_load_fw(struct drx397xD_state *s, enum fw_ix ix)
 {
        const u8 *data;
        size_t size, len;
        int i = 0, j, rc = -EINVAL;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        if (ix < 0 || ix >= ARRAY_SIZE(fw))
                return -EINVAL;
@@ -175,32 +172,34 @@ static int drx_load_fw(struct drx397xD_state *s, fw_ix_t ix)
                        goto exit_corrupt;
                }
        } while (i < size);
-      exit_corrupt:
+
+exit_corrupt:
        printk(KERN_ERR "%s: Firmware is corrupt\n", mod_name);
-      exit_err:
+exit_err:
        _drx_release_fw(s, ix);
        fw[ix].refcnt--;
-      exit_ok:
+exit_ok:
        fw[ix].refcnt++;
        write_unlock(&fw[ix].lock);
+
        return rc;
 }
 
-/*******************************************************************************
- * i2c bus IO
- ******************************************************************************/
-
-static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
+/* i2c bus IO */
+static int write_fw(struct drx397xD_state *s, enum blob_ix ix)
 {
-       struct i2c_msg msg = {.addr = s->config.demod_address,.flags = 0 };
        const u8 *data;
        int len, rc = 0, i = 0;
+       struct i2c_msg msg = {
+               .addr = s->config.demod_address,
+               .flags = 0
+       };
 
        if (ix < 0 || ix >= ARRAY_SIZE(blob_name)) {
-               pr_debug("%s drx_fw_ix_t out of range\n", __FUNCTION__);
+               pr_debug("%s drx_fw_ix_t out of range\n", __func__);
                return -EINVAL;
        }
-       pr_debug("%s %s\n", __FUNCTION__, blob_name[ix]);
+       pr_debug("%s %s\n", __func__, blob_name[ix]);
 
        read_lock(&fw[s->chip_rev].lock);
        data = fw[s->chip_rev].data[ix];
@@ -229,33 +228,33 @@ static int write_fw(struct drx397xD_state *s, blob_ix_t ix)
                        goto exit_rc;
                }
        }
-      exit_rc:
+exit_rc:
        read_unlock(&fw[s->chip_rev].lock);
+
        return 0;
 }
 
 /* Function is not endian safe, use the RD16 wrapper below */
-static int _read16(struct drx397xD_state *s, u32 i2c_adr)
+static int _read16(struct drx397xD_state *s, __le32 i2c_adr)
 {
        int rc;
        u8 a[4];
-       u16 v;
+       __le16 v;
        struct i2c_msg msg[2] = {
                {
-                .addr = s->config.demod_address,
-                .flags = 0,
-                .buf = a,
-                .len = sizeof(a)
-                }
-               , {
-                  .addr = s->config.demod_address,
-                  .flags = I2C_M_RD,
-                  .buf = (u8 *) & v,
-                  .len = sizeof(v)
-                  }
+                       .addr = s->config.demod_address,
+                       .flags = 0,
+                       .buf = a,
+                       .len = sizeof(a)
+               }, {
+                       .addr = s->config.demod_address,
+                       .flags = I2C_M_RD,
+                       .buf = (u8 *)&v,
+                       .len = sizeof(v)
+               }
        };
 
-       *(u32 *) a = i2c_adr;
+       *(__le32 *) a = i2c_adr;
 
        rc = i2c_transfer(s->i2c, msg, 2);
        if (rc != 2)
@@ -265,7 +264,7 @@ static int _read16(struct drx397xD_state *s, u32 i2c_adr)
 }
 
 /* Function is not endian safe, use the WR16.. wrappers below */
-static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val)
+static int _write16(struct drx397xD_state *s, __le32 i2c_adr, __le16 val)
 {
        u8 a[6];
        int rc;
@@ -276,28 +275,28 @@ static int _write16(struct drx397xD_state *s, u32 i2c_adr, u16 val)
                .len = sizeof(a)
        };
 
-       *(u32 *) a = i2c_adr;
-       *(u16 *) & a[4] = val;
+       *(__le32 *)a = i2c_adr;
+       *(__le16 *)&a[4] = val;
 
        rc = i2c_transfer(s->i2c, &msg, 1);
        if (rc != 1)
                return -EIO;
+
        return 0;
 }
 
-#define WR16(ss,adr, val) \
+#define WR16(ss, adr, val) \
                _write16(ss, I2C_ADR_C0(adr), cpu_to_le16(val))
-#define WR16_E0(ss,adr, val) \
+#define WR16_E0(ss, adr, val) \
                _write16(ss, I2C_ADR_E0(adr), cpu_to_le16(val))
-#define RD16(ss,adr) \
+#define RD16(ss, adr) \
                _read16(ss, I2C_ADR_C0(adr))
 
-#define EXIT_RC( cmd ) if ( (rc = (cmd)) < 0) goto exit_rc
-
-/*******************************************************************************
- * Tuner callback
- ******************************************************************************/
+#define EXIT_RC(cmd)   \
+       if ((rc = (cmd)) < 0)   \
+               goto exit_rc
 
+/* Tuner callback */
 static int PLL_Set(struct drx397xD_state *s,
                   struct dvb_frontend_parameters *fep, int *df_tuner)
 {
@@ -305,7 +304,7 @@ static int PLL_Set(struct drx397xD_state *s,
        u32 f_tuner, f = fep->frequency;
        int rc;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        if ((f > s->frontend.ops.tuner_ops.info.frequency_max) ||
            (f < s->frontend.ops.tuner_ops.info.frequency_min))
@@ -325,28 +324,26 @@ static int PLL_Set(struct drx397xD_state *s,
                return rc;
 
        *df_tuner = f_tuner - f;
-       pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __FUNCTION__, f,
+       pr_debug("%s requested %d [Hz] tuner %d [Hz]\n", __func__, f,
                 f_tuner);
 
        return 0;
 }
 
-/*******************************************************************************
- * Demodulator helper functions
- ******************************************************************************/
-
+/* Demodulator helper functions */
 static int SC_WaitForReady(struct drx397xD_state *s)
 {
        int cnt = 1000;
        int rc;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        while (cnt--) {
                rc = RD16(s, 0x820043);
                if (rc == 0)
                        return 0;
        }
+
        return -1;
 }
 
@@ -354,13 +351,14 @@ static int SC_SendCommand(struct drx397xD_state *s, int cmd)
 {
        int rc;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        WR16(s, 0x820043, cmd);
        SC_WaitForReady(s);
        rc = RD16(s, 0x820042);
        if ((rc & 0xffff) == 0xffff)
                return -1;
+
        return 0;
 }
 
@@ -368,7 +366,7 @@ static int HI_Command(struct drx397xD_state *s, u16 cmd)
 {
        int rc, cnt = 1000;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        rc = WR16(s, 0x420032, cmd);
        if (rc < 0)
@@ -383,22 +381,24 @@ static int HI_Command(struct drx397xD_state *s, u16 cmd)
                if (rc < 0)
                        return rc;
        } while (--cnt);
+
        return rc;
 }
 
 static int HI_CfgCommand(struct drx397xD_state *s)
 {
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        WR16(s, 0x420033, 0x3973);
-       WR16(s, 0x420034, s->config.w50);       // code 4, log 4
-       WR16(s, 0x420035, s->config.w52);       // code 15,  log 9
+       WR16(s, 0x420034, s->config.w50);       /* code 4, log 4 */
+       WR16(s, 0x420035, s->config.w52);       /* code 15,  log 9 */
        WR16(s, 0x420036, s->config.demod_address << 1);
-       WR16(s, 0x420037, s->config.w56);       // code (set_i2c ??  initX 1 ), log 1
-//      WR16(s, 0x420033, 0x3973);
+       WR16(s, 0x420037, s->config.w56);       /* code (set_i2c ??  initX 1 ), log 1 */
+       /* WR16(s, 0x420033, 0x3973); */
        if ((s->config.w56 & 8) == 0)
                return HI_Command(s, 3);
+
        return WR16(s, 0x420032, 0x3);
 }
 
@@ -419,7 +419,7 @@ static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
        u16 w0C = agc->w0C;
        int quot, rem, i, rc = -EINVAL;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        if (agc->w04 > 0x3ff)
                goto exit_rc;
@@ -468,7 +468,7 @@ static int SetCfgIfAgc(struct drx397xD_state *s, struct drx397xD_CfgIfAgc *agc)
        i = slowIncrDecLUT_15272[rem / 28];
        EXIT_RC(WR16(s, 0x0c2002b, i));
        rc = WR16(s, 0x0c2002c, i);
-      exit_rc:
+exit_rc:
        return rc;
 }
 
@@ -478,7 +478,7 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
        u16 w06 = agc->w06;
        int rc = -1;
 
-       pr_debug("%s %d 0x%x 0x%x\n", __FUNCTION__, agc->d00, w04, w06);
+       pr_debug("%s %d 0x%x 0x%x\n", __func__, agc->d00, w04, w06);
 
        if (w04 > 0x3ff)
                goto exit_rc;
@@ -498,7 +498,7 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
                rc &= ~2;
                break;
        case 0:
-               // loc_8000659
+               /* loc_8000659 */
                s->config.w9C &= ~2;
                EXIT_RC(WR16(s, 0x0c20015, s->config.w9C));
                EXIT_RC(RD16(s, 0x0c20010));
@@ -522,7 +522,8 @@ static int SetCfgRfAgc(struct drx397xD_state *s, struct drx397xD_CfgRfAgc *agc)
                rc |= 2;
        }
        rc = WR16(s, 0x0c20013, rc);
-      exit_rc:
+
+exit_rc:
        return rc;
 }
 
@@ -554,7 +555,7 @@ static int CorrectSysClockDeviation(struct drx397xD_state *s)
        int lockstat;
        u32 clk, clk_limit;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        if (s->config.d5C == 0) {
                EXIT_RC(WR16(s, 0x08200e8, 0x010));
@@ -598,11 +599,12 @@ static int CorrectSysClockDeviation(struct drx397xD_state *s)
 
        if (clk - s->config.f_osc * 1000 + clk_limit <= 2 * clk_limit) {
                s->f_osc = clk;
-               pr_debug("%s: osc %d %d [Hz]\n", __FUNCTION__,
+               pr_debug("%s: osc %d %d [Hz]\n", __func__,
                         s->config.f_osc * 1000, clk - s->config.f_osc * 1000);
        }
        rc = WR16(s, 0x08200e8, 0);
-      exit_rc:
+
+exit_rc:
        return rc;
 }
 
@@ -610,7 +612,7 @@ static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
 {
        int rc, si, bp;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        si = s->config.wA0;
        if (s->config.w98 == 0) {
@@ -620,17 +622,17 @@ static int ConfigureMPEGOutput(struct drx397xD_state *s, int type)
                si &= ~1;
                bp = 0x200;
        }
-       if (s->config.w9A == 0) {
+       if (s->config.w9A == 0)
                si |= 0x80;
-       } else {
+       else
                si &= ~0x80;
-       }
 
        EXIT_RC(WR16(s, 0x2150045, 0));
        EXIT_RC(WR16(s, 0x2150010, si));
        EXIT_RC(WR16(s, 0x2150011, bp));
        rc = WR16(s, 0x2150012, (type == 0 ? 0xfff : 0));
-      exit_rc:
+
+exit_rc:
        return rc;
 }
 
@@ -646,7 +648,7 @@ static int drx_tune(struct drx397xD_state *s,
 
        int rc, df_tuner;
        int a, b, c, d;
-       pr_debug("%s %d\n", __FUNCTION__, s->config.d60);
+       pr_debug("%s %d\n", __func__, s->config.d60);
 
        if (s->config.d60 != 2)
                goto set_tuner;
@@ -658,7 +660,7 @@ static int drx_tune(struct drx397xD_state *s,
        rc = ConfigureMPEGOutput(s, 0);
        if (rc < 0)
                goto set_tuner;
-      set_tuner:
+set_tuner:
 
        rc = PLL_Set(s, fep, &df_tuner);
        if (rc < 0) {
@@ -835,16 +837,16 @@ static int drx_tune(struct drx397xD_state *s,
                rc = WR16(s, 0x2010012, 0);
                if (rc < 0)
                        goto exit_rc;
-               //              QPSK    QAM16   QAM64
-               ebx = 0x19f;    //                 62
-               ebp = 0x1fb;    //                 15
-               v20 = 0x16a;    //  62
-               v1E = 0x195;    //         62
-               v16 = 0x1bb;    //  15
-               v14 = 0x1ef;    //         15
-               v12 = 5;        //  16
-               v10 = 5;        //         16
-               v0E = 5;        //                 16
+                               /* QPSK    QAM16  QAM64 */
+               ebx = 0x19f;    /*                 62   */
+               ebp = 0x1fb;    /*                 15   */
+               v20 = 0x16a;    /*  62                  */
+               v1E = 0x195;    /*         62           */
+               v16 = 0x1bb;    /*  15                  */
+               v14 = 0x1ef;    /*         15           */
+               v12 = 5;        /*  16                  */
+               v10 = 5;        /*         16           */
+               v0E = 5;        /*                 16   */
        }
 
        switch (fep->u.ofdm.constellation) {
@@ -997,17 +999,17 @@ static int drx_tune(struct drx397xD_state *s,
        case BANDWIDTH_8_MHZ:   /* 0 */
        case BANDWIDTH_AUTO:
                rc = WR16(s, 0x0c2003f, 0x32);
-               s->bandwidth_parm = ebx = 0x8b8249;     // 9142857
+               s->bandwidth_parm = ebx = 0x8b8249;
                edx = 0;
                break;
        case BANDWIDTH_7_MHZ:
                rc = WR16(s, 0x0c2003f, 0x3b);
-               s->bandwidth_parm = ebx = 0x7a1200;     // 8000000
+               s->bandwidth_parm = ebx = 0x7a1200;
                edx = 0x4807;
                break;
        case BANDWIDTH_6_MHZ:
                rc = WR16(s, 0x0c2003f, 0x47);
-               s->bandwidth_parm = ebx = 0x68a1b6;     // 6857142
+               s->bandwidth_parm = ebx = 0x68a1b6;
                edx = 0x0f07;
                break;
        };
@@ -1060,8 +1062,6 @@ static int drx_tune(struct drx397xD_state *s,
        WR16(s, 0x0820040, 1);
        SC_SendCommand(s, 1);
 
-//      rc = WR16(s, 0x2150000, 1);
-//      if (rc < 0) goto exit_rc;
 
        rc = WR16(s, 0x2150000, 2);
        rc = WR16(s, 0x2150016, a);
@@ -1069,7 +1069,8 @@ static int drx_tune(struct drx397xD_state *s,
        rc = WR16(s, 0x2150036, 0);
        rc = WR16(s, 0x2150000, 1);
        s->config.d60 = 2;
-      exit_rc:
+
+exit_rc:
        return rc;
 }
 
@@ -1082,7 +1083,7 @@ static int drx397x_init(struct dvb_frontend *fe)
        struct drx397xD_state *s = fe->demodulator_priv;
        int rc;
 
-       pr_debug("%s\n", __FUNCTION__);
+       pr_debug("%s\n", __func__);
 
        s->config.rfagc.d00 = 2;        /* 0x7c */
        s->config.rfagc.w04 = 0;
@@ -1102,18 +1103,18 @@ static int drx397x_init(struct dvb_frontend *fe)
 
        /* HI_CfgCommand */
        s->config.w50 = 4;
-       s->config.w52 = 9;      // 0xf;
+       s->config.w52 = 9;
 
-       s->config.f_if = 42800000;      /* d14: intermediate frequency [Hz]     */
-       s->config.f_osc = 48000;        /* s66 : oscillator frequency [kHz]     */
-       s->config.w92 = 12000;  // 20000;
+       s->config.f_if = 42800000;      /* d14: intermediate frequency [Hz] */
+       s->config.f_osc = 48000;        /* s66 : oscillator frequency [kHz] */
+       s->config.w92 = 12000;
 
        s->config.w9C = 0x000e;
        s->config.w9E = 0x0000;
 
        /* ConfigureMPEGOutput params */
        s->config.wA0 = 4;
-       s->config.w98 = 1;      // 0;
+       s->config.w98 = 1;
        s->config.w9A = 1;
 
        /* get chip revision */
@@ -1248,7 +1249,7 @@ static int drx397x_init(struct dvb_frontend *fe)
                rc = WR16(s, 0x0c20012, 1);
        }
 
-      write_DRXD_InitFE_1:
+write_DRXD_InitFE_1:
 
        rc = write_fw(s, DRXD_InitFE_1);
        if (rc < 0)
@@ -1311,7 +1312,8 @@ static int drx397x_init(struct dvb_frontend *fe)
        s->config.d5C = 0;
        s->config.d60 = 1;
        s->config.d48 = 1;
-      error:
+
+error:
        return rc;
 }
 
@@ -1326,7 +1328,8 @@ static int drx397x_set_frontend(struct dvb_frontend *fe,
 {
        struct drx397xD_state *s = fe->demodulator_priv;
 
-       s->config.s20d24 = 1;   // 0;
+       s->config.s20d24 = 1;
+
        return drx_tune(s, params);
 }
 
@@ -1337,18 +1340,16 @@ static int drx397x_get_tune_settings(struct dvb_frontend *fe,
        fe_tune_settings->min_delay_ms = 10000;
        fe_tune_settings->step_size = 0;
        fe_tune_settings->max_drift = 0;
+
        return 0;
 }
 
-static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
+static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t *status)
 {
        struct drx397xD_state *s = fe->demodulator_priv;
        int lockstat;
 
        GetLockStatus(s, &lockstat);
-       /* TODO */
-//      if (lockstat & 1)
-//      CorrectSysClockDeviation(s);
 
        *status = 0;
        if (lockstat & 2) {
@@ -1356,9 +1357,8 @@ static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
                ConfigureMPEGOutput(s, 1);
                *status = FE_HAS_LOCK | FE_HAS_SYNC | FE_HAS_VITERBI;
        }
-       if (lockstat & 4) {
+       if (lockstat & 4)
                *status |= FE_HAS_CARRIER | FE_HAS_SIGNAL;
-       }
 
        return 0;
 }
@@ -1366,16 +1366,18 @@ static int drx397x_read_status(struct dvb_frontend *fe, fe_status_t * status)
 static int drx397x_read_ber(struct dvb_frontend *fe, unsigned int *ber)
 {
        *ber = 0;
+
        return 0;
 }
 
-static int drx397x_read_snr(struct dvb_frontend *fe, u16 * snr)
+static int drx397x_read_snr(struct dvb_frontend *fe, u16 *snr)
 {
        *snr = 0;
+
        return 0;
 }
 
-static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
+static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
 {
        struct drx397xD_state *s = fe->demodulator_priv;
        int rc;
@@ -1401,6 +1403,7 @@ static int drx397x_read_signal_strength(struct dvb_frontend *fe, u16 * strength)
         * The following does the same but with less rounding errors:
         */
        *strength = ~(7720 + (rc * 30744 >> 10));
+
        return 0;
 }
 
@@ -1408,6 +1411,7 @@ static int drx397x_read_ucblocks(struct dvb_frontend *fe,
                                 unsigned int *ucblocks)
 {
        *ucblocks = 0;
+
        return 0;
 }
 
@@ -1436,22 +1440,22 @@ static struct dvb_frontend_ops drx397x_ops = {
                 .frequency_max         = 855250000,
                 .frequency_stepsize    = 166667,
                 .frequency_tolerance   = 0,
-                .caps =                                        /* 0x0C01B2EAE */
-                        FE_CAN_FEC_1_2                 |       // = 0x2,
-                        FE_CAN_FEC_2_3                 |       // = 0x4,
-                        FE_CAN_FEC_3_4                 |       // = 0x8,
-                        FE_CAN_FEC_5_6                 |       // = 0x20,
-                        FE_CAN_FEC_7_8                 |       // = 0x80,
-                        FE_CAN_FEC_AUTO                |       // = 0x200,
-                        FE_CAN_QPSK                    |       // = 0x400,
-                        FE_CAN_QAM_16                  |       // = 0x800,
-                        FE_CAN_QAM_64                  |       // = 0x2000,
-                        FE_CAN_QAM_AUTO                |       // = 0x10000,
-                        FE_CAN_TRANSMISSION_MODE_AUTO  |       // = 0x20000,
-                        FE_CAN_GUARD_INTERVAL_AUTO     |       // = 0x80000,
-                        FE_CAN_HIERARCHY_AUTO          |       // = 0x100000,
-                        FE_CAN_RECOVER                 |       // = 0x40000000,
-                        FE_CAN_MUTE_TS                         // = 0x80000000
+                .caps =                                  /* 0x0C01B2EAE */
+                        FE_CAN_FEC_1_2                 | /* = 0x2, */
+                        FE_CAN_FEC_2_3                 | /* = 0x4, */
+                        FE_CAN_FEC_3_4                 | /* = 0x8, */
+                        FE_CAN_FEC_5_6                 | /* = 0x20, */
+                        FE_CAN_FEC_7_8                 | /* = 0x80, */
+                        FE_CAN_FEC_AUTO                | /* = 0x200, */
+                        FE_CAN_QPSK                    | /* = 0x400, */
+                        FE_CAN_QAM_16                  | /* = 0x800, */
+                        FE_CAN_QAM_64                  | /* = 0x2000, */
+                        FE_CAN_QAM_AUTO                | /* = 0x10000, */
+                        FE_CAN_TRANSMISSION_MODE_AUTO  | /* = 0x20000, */
+                        FE_CAN_GUARD_INTERVAL_AUTO     | /* = 0x80000, */
+                        FE_CAN_HIERARCHY_AUTO          | /* = 0x100000, */
+                        FE_CAN_RECOVER                 | /* = 0x40000000, */
+                        FE_CAN_MUTE_TS                   /* = 0x80000000 */
         },
 
        .release = drx397x_release,
@@ -1472,33 +1476,35 @@ static struct dvb_frontend_ops drx397x_ops = {
 struct dvb_frontend *drx397xD_attach(const struct drx397xD_config *config,
                                     struct i2c_adapter *i2c)
 {
-       struct drx397xD_state *s = NULL;
+       struct drx397xD_state *state;
 
        /* allocate memory for the internal state */
-       s = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
-       if (s == NULL)
+       state = kzalloc(sizeof(struct drx397xD_state), GFP_KERNEL);
+       if (!state)
                goto error;
 
        /* setup the state */
-       s->i2c = i2c;
-       memcpy(&s->config, config, sizeof(struct drx397xD_config));
+       state->i2c = i2c;
+       memcpy(&state->config, config, sizeof(struct drx397xD_config));
 
        /* check if the demod is there */
-       if (RD16(s, 0x2410019) < 0)
+       if (RD16(state, 0x2410019) < 0)
                goto error;
 
        /* create dvb_frontend */
-       memcpy(&s->frontend.ops, &drx397x_ops, sizeof(struct dvb_frontend_ops));
-       s->frontend.demodulator_priv = s;
+       memcpy(&state->frontend.ops, &drx397x_ops,
+                       sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+
+       return &state->frontend;
+error:
+       kfree(state);
 
-       return &s->frontend;
-      error:
-       kfree(s);
        return NULL;
 }
+EXPORT_SYMBOL(drx397xD_attach);
 
 MODULE_DESCRIPTION("Micronas DRX397xD DVB-T Frontend");
 MODULE_AUTHOR("Henk Vergonet");
 MODULE_LICENSE("GPL");
 
-EXPORT_SYMBOL(drx397xD_attach);
index ddc7a07971b73473c4c9fd428f9a038a2768fe0c..ba05d17290c633e51fdc30e0dc0055d9702affeb 100644 (file)
@@ -28,7 +28,7 @@
 #define DRX_F_OFFSET   36000000
 
 #define I2C_ADR_C0(x) \
-(      (u32)cpu_to_le32( \
+(      cpu_to_le32( \
                (u32)( \
                        (((u32)(x) & (u32)0x000000ffUL)      ) | \
                        (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
@@ -38,7 +38,7 @@
 )
 
 #define I2C_ADR_E0(x) \
-(      (u32)cpu_to_le32( \
+(      cpu_to_le32( \
                (u32)( \
                        (((u32)(x) & (u32)0x000000ffUL)      ) | \
                        (((u32)(x) & (u32)0x0000ff00UL) << 16) | \
@@ -122,7 +122,7 @@ extern struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config
 static inline struct dvb_frontend* drx397xD_attach(const struct drx397xD_config *config,
                                           struct i2c_adapter *i2c)
 {
-       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __FUNCTION__);
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
 }
 #endif /* CONFIG_DVB_DRX397XD */
index fed09dfb2b7c64eb2c90b5ebd9ec64a913512b47..db8a937cc63008dbabe4a1225810f03e80916d31 100644 (file)
@@ -75,9 +75,10 @@ static int dvb_dummy_fe_get_frontend(struct dvb_frontend* fe, struct dvb_fronten
 
 static int dvb_dummy_fe_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_parameters *p)
 {
-       if (fe->ops->tuner_ops->set_params) {
-               fe->ops->tuner_ops->set_params(fe, p);
-               if (fe->ops->i2c_gate_ctrl) fe->ops->i2c_gate_ctrl(fe, 0);
+       if (fe->ops.tuner_ops.set_params) {
+               fe->ops.tuner_ops.set_params(fe, p);
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 0);
        }
 
        return 0;
@@ -131,7 +132,7 @@ error:
 
 static struct dvb_frontend_ops dvb_dummy_fe_qpsk_ops;
 
-struct dvb_frontend* dvb_dummy_fe_qpsk_attach()
+struct dvb_frontend *dvb_dummy_fe_qpsk_attach(void)
 {
        struct dvb_dummy_fe_state* state = NULL;
 
@@ -151,7 +152,7 @@ error:
 
 static struct dvb_frontend_ops dvb_dummy_fe_qam_ops;
 
-struct dvb_frontend* dvb_dummy_fe_qam_attach()
+struct dvb_frontend *dvb_dummy_fe_qam_attach(void)
 {
        struct dvb_dummy_fe_state* state = NULL;
 
diff --git a/drivers/media/dvb/frontends/eds1547.h b/drivers/media/dvb/frontends/eds1547.h
new file mode 100644 (file)
index 0000000..fa79b7c
--- /dev/null
@@ -0,0 +1,133 @@
+/* eds1547.h Earda EDS-1547 tuner support
+*
+* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+*
+*      This program is free software; you can redistribute it and/or modify it
+*      under the terms of the GNU General Public License as published by the
+*      Free Software Foundation, version 2.
+*
+* see Documentation/dvb/README.dvb-usb for more information
+*/
+
+#ifndef EDS1547
+#define EDS1547
+
+static u8 stv0288_earda_inittab[] = {
+       0x01, 0x57,
+       0x02, 0x20,
+       0x03, 0x8e,
+       0x04, 0x8e,
+       0x05, 0x12,
+       0x06, 0x00,
+       0x07, 0x00,
+       0x09, 0x00,
+       0x0a, 0x04,
+       0x0b, 0x00,
+       0x0c, 0x00,
+       0x0d, 0x00,
+       0x0e, 0xd4,
+       0x0f, 0x30,
+       0x11, 0x44,
+       0x12, 0x03,
+       0x13, 0x48,
+       0x14, 0x84,
+       0x15, 0x45,
+       0x16, 0xb7,
+       0x17, 0x9c,
+       0x18, 0x00,
+       0x19, 0xa6,
+       0x1a, 0x88,
+       0x1b, 0x8f,
+       0x1c, 0xf0,
+       0x20, 0x0b,
+       0x21, 0x54,
+       0x22, 0x00,
+       0x23, 0x00,
+       0x2b, 0xff,
+       0x2c, 0xf7,
+       0x30, 0x00,
+       0x31, 0x1e,
+       0x32, 0x14,
+       0x33, 0x0f,
+       0x34, 0x09,
+       0x35, 0x0c,
+       0x36, 0x05,
+       0x37, 0x2f,
+       0x38, 0x16,
+       0x39, 0xbd,
+       0x3a, 0x00,
+       0x3b, 0x13,
+       0x3c, 0x11,
+       0x3d, 0x30,
+       0x40, 0x63,
+       0x41, 0x04,
+       0x42, 0x60,
+       0x43, 0x00,
+       0x44, 0x00,
+       0x45, 0x00,
+       0x46, 0x00,
+       0x47, 0x00,
+       0x4a, 0x00,
+       0x50, 0x10,
+       0x51, 0x36,
+       0x52, 0x09,
+       0x53, 0x94,
+       0x54, 0x62,
+       0x55, 0x29,
+       0x56, 0x64,
+       0x57, 0x2b,
+       0x58, 0x54,
+       0x59, 0x86,
+       0x5a, 0x00,
+       0x5b, 0x9b,
+       0x5c, 0x08,
+       0x5d, 0x7f,
+       0x5e, 0x00,
+       0x5f, 0xff,
+       0x70, 0x00,
+       0x71, 0x00,
+       0x72, 0x00,
+       0x74, 0x00,
+       0x75, 0x00,
+       0x76, 0x00,
+       0x81, 0x00,
+       0x82, 0x3f,
+       0x83, 0x3f,
+       0x84, 0x00,
+       0x85, 0x00,
+       0x88, 0x00,
+       0x89, 0x00,
+       0x8a, 0x00,
+       0x8b, 0x00,
+       0x8c, 0x00,
+       0x90, 0x00,
+       0x91, 0x00,
+       0x92, 0x00,
+       0x93, 0x00,
+       0x94, 0x1c,
+       0x97, 0x00,
+       0xa0, 0x48,
+       0xa1, 0x00,
+       0xb0, 0xb8,
+       0xb1, 0x3a,
+       0xb2, 0x10,
+       0xb3, 0x82,
+       0xb4, 0x80,
+       0xb5, 0x82,
+       0xb6, 0x82,
+       0xb7, 0x82,
+       0xb8, 0x20,
+       0xb9, 0x00,
+       0xf0, 0x00,
+       0xf1, 0x00,
+       0xf2, 0xc0,
+       0xff,0xff,
+};
+
+static struct stv0288_config earda_config = {
+       .demod_address = 0x68,
+       .min_delay_ms = 100,
+       .inittab = stv0288_earda_inittab,
+};
+
+#endif
diff --git a/drivers/media/dvb/frontends/lgs8gl5.c b/drivers/media/dvb/frontends/lgs8gl5.c
new file mode 100644 (file)
index 0000000..855852f
--- /dev/null
@@ -0,0 +1,454 @@
+/*
+    Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
+
+    Copyright (C) 2008 Sirius International (Hong Kong) Limited
+       Timothy Lee <timothy.lee@siriushk.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include "dvb_frontend.h"
+#include "lgs8gl5.h"
+
+
+#define REG_RESET              0x02
+#define REG_RESET_OFF                  0x01
+#define REG_03                 0x03
+#define REG_04                 0x04
+#define REG_07                 0x07
+#define REG_09                 0x09
+#define REG_0A                 0x0a
+#define REG_0B                 0x0b
+#define REG_0C                 0x0c
+#define REG_37                 0x37
+#define REG_STRENGTH           0x4b
+#define REG_STRENGTH_MASK              0x7f
+#define REG_STRENGTH_CARRIER           0x80
+#define REG_INVERSION          0x7c
+#define REG_INVERSION_ON               0x80
+#define REG_7D                 0x7d
+#define REG_7E                 0x7e
+#define REG_A2                 0xa2
+#define REG_STATUS             0xa4
+#define REG_STATUS_SYNC                0x04
+#define REG_STATUS_LOCK                0x01
+
+
+struct lgs8gl5_state {
+       struct i2c_adapter *i2c;
+       const struct lgs8gl5_config *config;
+       struct dvb_frontend frontend;
+};
+
+
+static int debug;
+#define dprintk(args...) \
+       do { \
+               if (debug) \
+                       printk(KERN_DEBUG "lgs8gl5: " args); \
+       } while (0)
+
+
+/* Writes into demod's register */
+static int
+lgs8gl5_write_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
+{
+       int ret;
+       u8 buf[] = {reg, data};
+       struct i2c_msg msg = {
+               .addr  = state->config->demod_address,
+               .flags = 0,
+               .buf   = buf,
+               .len   = 2
+       };
+
+       ret = i2c_transfer(state->i2c, &msg, 1);
+       if (ret != 1)
+               dprintk("%s: error (reg=0x%02x, val=0x%02x, ret=%i)\n",
+                       __func__, reg, data, ret);
+       return (ret != 1) ? -1 : 0;
+}
+
+
+/* Reads from demod's register */
+static int
+lgs8gl5_read_reg(struct lgs8gl5_state *state, u8 reg)
+{
+       int ret;
+       u8 b0[] = {reg};
+       u8 b1[] = {0};
+       struct i2c_msg msg[2] = {
+               {
+                       .addr  = state->config->demod_address,
+                       .flags = 0,
+                       .buf   = b0,
+                       .len   = 1
+               },
+               {
+                       .addr  = state->config->demod_address,
+                       .flags = I2C_M_RD,
+                       .buf   = b1,
+                       .len   = 1
+               }
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 2);
+       if (ret != 2)
+               return -EIO;
+
+       return b1[0];
+}
+
+
+static int
+lgs8gl5_update_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
+{
+       lgs8gl5_read_reg(state, reg);
+       lgs8gl5_write_reg(state, reg, data);
+       return 0;
+}
+
+
+/* Writes into alternate device's register */
+/* TODO:  Find out what that device is for! */
+static int
+lgs8gl5_update_alt_reg(struct lgs8gl5_state *state, u8 reg, u8 data)
+{
+       int ret;
+       u8 b0[] = {reg};
+       u8 b1[] = {0};
+       u8 b2[] = {reg, data};
+       struct i2c_msg msg[3] = {
+               {
+                       .addr  = state->config->demod_address + 2,
+                       .flags = 0,
+                       .buf   = b0,
+                       .len   = 1
+               },
+               {
+                       .addr  = state->config->demod_address + 2,
+                       .flags = I2C_M_RD,
+                       .buf   = b1,
+                       .len   = 1
+               },
+               {
+                       .addr  = state->config->demod_address + 2,
+                       .flags = 0,
+                       .buf   = b2,
+                       .len   = 2
+               },
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 3);
+       return (ret != 3) ? -1 : 0;
+}
+
+
+static void
+lgs8gl5_soft_reset(struct lgs8gl5_state *state)
+{
+       u8 val;
+
+       dprintk("%s\n", __func__);
+
+       val = lgs8gl5_read_reg(state, REG_RESET);
+       lgs8gl5_write_reg(state, REG_RESET, val & ~REG_RESET_OFF);
+       lgs8gl5_write_reg(state, REG_RESET, val | REG_RESET_OFF);
+       msleep(5);
+}
+
+
+/* Starts demodulation */
+static void
+lgs8gl5_start_demod(struct lgs8gl5_state *state)
+{
+       u8  val;
+       int n;
+
+       dprintk("%s\n", __func__);
+
+       lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
+       lgs8gl5_soft_reset(state);
+       lgs8gl5_update_reg(state, REG_07, 0x10);
+       lgs8gl5_update_reg(state, REG_07, 0x10);
+       lgs8gl5_write_reg(state, REG_09, 0x0e);
+       lgs8gl5_write_reg(state, REG_0A, 0xe5);
+       lgs8gl5_write_reg(state, REG_0B, 0x35);
+       lgs8gl5_write_reg(state, REG_0C, 0x30);
+
+       lgs8gl5_update_reg(state, REG_03, 0x00);
+       lgs8gl5_update_reg(state, REG_7E, 0x01);
+       lgs8gl5_update_alt_reg(state, 0xc5, 0x00);
+       lgs8gl5_update_reg(state, REG_04, 0x02);
+       lgs8gl5_update_reg(state, REG_37, 0x01);
+       lgs8gl5_soft_reset(state);
+
+       /* Wait for carrier */
+       for (n = 0;  n < 10;  n++) {
+               val = lgs8gl5_read_reg(state, REG_STRENGTH);
+               dprintk("Wait for carrier[%d] 0x%02X\n", n, val);
+               if (val & REG_STRENGTH_CARRIER)
+                       break;
+               msleep(4);
+       }
+       if (!(val & REG_STRENGTH_CARRIER))
+               return;
+
+       /* Wait for lock */
+       for (n = 0;  n < 20;  n++) {
+               val = lgs8gl5_read_reg(state, REG_STATUS);
+               dprintk("Wait for lock[%d] 0x%02X\n", n, val);
+               if (val & REG_STATUS_LOCK)
+                       break;
+               msleep(12);
+       }
+       if (!(val & REG_STATUS_LOCK))
+               return;
+
+       lgs8gl5_write_reg(state, REG_7D, lgs8gl5_read_reg(state, REG_A2));
+       lgs8gl5_soft_reset(state);
+}
+
+
+static int
+lgs8gl5_init(struct dvb_frontend *fe)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       lgs8gl5_update_alt_reg(state, 0xc2, 0x28);
+       lgs8gl5_soft_reset(state);
+       lgs8gl5_update_reg(state, REG_07, 0x10);
+       lgs8gl5_update_reg(state, REG_07, 0x10);
+       lgs8gl5_write_reg(state, REG_09, 0x0e);
+       lgs8gl5_write_reg(state, REG_0A, 0xe5);
+       lgs8gl5_write_reg(state, REG_0B, 0x35);
+       lgs8gl5_write_reg(state, REG_0C, 0x30);
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+       u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
+       u8 flags = lgs8gl5_read_reg(state, REG_STATUS);
+
+       *status = 0;
+
+       if ((level & REG_STRENGTH_MASK) > 0)
+               *status |= FE_HAS_SIGNAL;
+       if (level & REG_STRENGTH_CARRIER)
+               *status |= FE_HAS_CARRIER;
+       if (flags & REG_STATUS_SYNC)
+               *status |= FE_HAS_SYNC;
+       if (flags & REG_STATUS_LOCK)
+               *status |= FE_HAS_LOCK;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       *ber = 0;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_read_signal_strength(struct dvb_frontend *fe, u16 *signal_strength)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+       u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
+       *signal_strength = (level & REG_STRENGTH_MASK) << 8;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+       u8 level = lgs8gl5_read_reg(state, REG_STRENGTH);
+       *snr = (level & REG_STRENGTH_MASK) << 8;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       *ucblocks = 0;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_set_frontend(struct dvb_frontend *fe,
+               struct dvb_frontend_parameters *p)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ)
+               return -EINVAL;
+
+       if (fe->ops.tuner_ops.set_params) {
+               fe->ops.tuner_ops.set_params(fe, p);
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 0);
+       }
+
+       /* lgs8gl5_set_inversion(state, p->inversion); */
+
+       lgs8gl5_start_demod(state);
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_get_frontend(struct dvb_frontend *fe,
+               struct dvb_frontend_parameters *p)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+       u8 inv = lgs8gl5_read_reg(state, REG_INVERSION);
+       struct dvb_ofdm_parameters *o = &p->u.ofdm;
+
+       p->inversion = (inv & REG_INVERSION_ON) ? INVERSION_ON : INVERSION_OFF;
+
+       o->code_rate_HP = FEC_1_2;
+       o->code_rate_LP = FEC_7_8;
+       o->guard_interval = GUARD_INTERVAL_1_32;
+       o->transmission_mode = TRANSMISSION_MODE_2K;
+       o->constellation = QAM_64;
+       o->hierarchy_information = HIERARCHY_NONE;
+       o->bandwidth = BANDWIDTH_8_MHZ;
+
+       return 0;
+}
+
+
+static int
+lgs8gl5_get_tune_settings(struct dvb_frontend *fe,
+               struct dvb_frontend_tune_settings *fesettings)
+{
+       fesettings->min_delay_ms = 240;
+       fesettings->step_size    = 0;
+       fesettings->max_drift    = 0;
+       return 0;
+}
+
+
+static void
+lgs8gl5_release(struct dvb_frontend *fe)
+{
+       struct lgs8gl5_state *state = fe->demodulator_priv;
+       kfree(state);
+}
+
+
+static struct dvb_frontend_ops lgs8gl5_ops;
+
+
+struct dvb_frontend*
+lgs8gl5_attach(const struct lgs8gl5_config *config, struct i2c_adapter *i2c)
+{
+       struct lgs8gl5_state *state = NULL;
+
+       dprintk("%s\n", __func__);
+
+       /* Allocate memory for the internal state */
+       state = kmalloc(sizeof(struct lgs8gl5_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error;
+
+       /* Setup the state */
+       state->config = config;
+       state->i2c    = i2c;
+
+       /* Check if the demod is there */
+       if (lgs8gl5_read_reg(state, REG_RESET) < 0)
+               goto error;
+
+       /* Create dvb_frontend */
+       memcpy(&state->frontend.ops, &lgs8gl5_ops,
+               sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+       return &state->frontend;
+
+error:
+       kfree(state);
+       return NULL;
+}
+EXPORT_SYMBOL(lgs8gl5_attach);
+
+
+static struct dvb_frontend_ops lgs8gl5_ops = {
+       .info = {
+               .name                   = "Legend Silicon LGS-8GL5 DMB-TH",
+               .type                   = FE_OFDM,
+               .frequency_min          = 474000000,
+               .frequency_max          = 858000000,
+               .frequency_stepsize     = 10000,
+               .frequency_tolerance    = 0,
+               .caps = FE_CAN_FEC_AUTO |
+                       FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_32 |
+                       FE_CAN_QAM_64 | FE_CAN_QAM_AUTO |
+                       FE_CAN_TRANSMISSION_MODE_AUTO |
+                       FE_CAN_BANDWIDTH_AUTO |
+                       FE_CAN_GUARD_INTERVAL_AUTO |
+                       FE_CAN_HIERARCHY_AUTO |
+                       FE_CAN_RECOVER
+       },
+
+       .release = lgs8gl5_release,
+
+       .init = lgs8gl5_init,
+
+       .set_frontend = lgs8gl5_set_frontend,
+       .get_frontend = lgs8gl5_get_frontend,
+       .get_tune_settings = lgs8gl5_get_tune_settings,
+
+       .read_status = lgs8gl5_read_status,
+       .read_ber = lgs8gl5_read_ber,
+       .read_signal_strength = lgs8gl5_read_signal_strength,
+       .read_snr = lgs8gl5_read_snr,
+       .read_ucblocks = lgs8gl5_read_ucblocks,
+};
+
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_DESCRIPTION("Legend Silicon LGS-8GL5 DMB-TH Demodulator driver");
+MODULE_AUTHOR("Timothy Lee");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/lgs8gl5.h b/drivers/media/dvb/frontends/lgs8gl5.h
new file mode 100644 (file)
index 0000000..d141767
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+    Legend Silicon LGS-8GL5 DMB-TH OFDM demodulator driver
+
+    Copyright (C) 2008 Sirius International (Hong Kong) Limited
+       Timothy Lee <timothy.lee@siriushk.com>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef LGS8GL5_H
+#define LGS8GL5_H
+
+#include <linux/dvb/frontend.h>
+
+struct lgs8gl5_config {
+       /* the demodulator's i2c address */
+       u8 demod_address;
+};
+
+#if defined(CONFIG_DVB_LGS8GL5) || \
+       (defined(CONFIG_DVB_LGS8GL5_MODULE) && defined(MODULE))
+extern struct dvb_frontend *lgs8gl5_attach(
+       const struct lgs8gl5_config *config, struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *lgs8gl5_attach(
+       const struct lgs8gl5_config *config, struct i2c_adapter *i2c) {
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_LGS8GL5 */
+
+#endif /* LGS8GL5_H */
index af298358e822e4048cf7b03c312cf5abb73e7312..a8429ebfa8a2e6da67208e926d5644f74e583a02 100644 (file)
@@ -80,7 +80,7 @@ static int i2c_writebytes (struct nxt200x_state* state, u8 addr, u8 *buf, u8 len
        return 0;
 }
 
-static u8 i2c_readbytes (struct nxt200x_state* state, u8 addr, u8* buf, u8 len)
+static int i2c_readbytes(struct nxt200x_state *state, u8 addr, u8 *buf, u8 len)
 {
        int err;
        struct i2c_msg msg = { .addr = addr, .flags = I2C_M_RD, .buf = buf, .len = len };
@@ -111,7 +111,7 @@ static int nxt200x_writebytes (struct nxt200x_state* state, u8 reg,
        return 0;
 }
 
-static u8 nxt200x_readbytes (struct nxt200x_state* state, u8 reg, u8* buf, u8 len)
+static int nxt200x_readbytes(struct nxt200x_state *state, u8 reg, u8 *buf, u8 len)
 {
        u8 reg2 [] = { reg };
 
index 6afe12aaca4e53d6ab417279c5c143e69d271c72..16cf2fdd5d7d1c6a14189a5b56312a4b4acb3f99 100644 (file)
@@ -88,7 +88,7 @@ static int i2c_writebytes (struct or51211_state* state, u8 reg, const u8 *buf,
        return 0;
 }
 
-static u8 i2c_readbytes (struct or51211_state* state, u8 reg, u8* buf, int len)
+static int i2c_readbytes(struct or51211_state *state, u8 reg, u8 *buf, int len)
 {
        int err;
        struct i2c_msg msg;
diff --git a/drivers/media/dvb/frontends/si21xx.c b/drivers/media/dvb/frontends/si21xx.c
new file mode 100644 (file)
index 0000000..3ddbe69
--- /dev/null
@@ -0,0 +1,974 @@
+/* DVB compliant Linux driver for the DVB-S si2109/2110 demodulator
+*
+* Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+*
+*      This program is free software; you can redistribute it and/or modify
+*      it under the terms of the GNU General Public License as published by
+*      the Free Software Foundation; either version 2 of the License, or
+*      (at your option) any later version.
+*
+*/
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <asm/div64.h>
+
+#include "dvb_frontend.h"
+#include "si21xx.h"
+
+#define        REVISION_REG                    0x00
+#define        SYSTEM_MODE_REG                 0x01
+#define        TS_CTRL_REG_1                   0x02
+#define        TS_CTRL_REG_2                   0x03
+#define        PIN_CTRL_REG_1                  0x04
+#define        PIN_CTRL_REG_2                  0x05
+#define        LOCK_STATUS_REG_1               0x0f
+#define        LOCK_STATUS_REG_2               0x10
+#define        ACQ_STATUS_REG                  0x11
+#define        ACQ_CTRL_REG_1                  0x13
+#define        ACQ_CTRL_REG_2                  0x14
+#define        PLL_DIVISOR_REG                 0x15
+#define        COARSE_TUNE_REG                 0x16
+#define        FINE_TUNE_REG_L                 0x17
+#define        FINE_TUNE_REG_H                 0x18
+
+#define        ANALOG_AGC_POWER_LEVEL_REG      0x28
+#define        CFO_ESTIMATOR_CTRL_REG_1        0x29
+#define        CFO_ESTIMATOR_CTRL_REG_2        0x2a
+#define        CFO_ESTIMATOR_CTRL_REG_3        0x2b
+
+#define        SYM_RATE_ESTIMATE_REG_L         0x31
+#define        SYM_RATE_ESTIMATE_REG_M         0x32
+#define        SYM_RATE_ESTIMATE_REG_H         0x33
+
+#define        CFO_ESTIMATOR_OFFSET_REG_L      0x36
+#define        CFO_ESTIMATOR_OFFSET_REG_H      0x37
+#define        CFO_ERROR_REG_L                 0x38
+#define        CFO_ERROR_REG_H                 0x39
+#define        SYM_RATE_ESTIMATOR_CTRL_REG     0x3a
+
+#define        SYM_RATE_REG_L                  0x3f
+#define        SYM_RATE_REG_M                  0x40
+#define        SYM_RATE_REG_H                  0x41
+#define        SYM_RATE_ESTIMATOR_MAXIMUM_REG  0x42
+#define        SYM_RATE_ESTIMATOR_MINIMUM_REG  0x43
+
+#define        C_N_ESTIMATOR_CTRL_REG          0x7c
+#define        C_N_ESTIMATOR_THRSHLD_REG       0x7d
+#define        C_N_ESTIMATOR_LEVEL_REG_L       0x7e
+#define        C_N_ESTIMATOR_LEVEL_REG_H       0x7f
+
+#define        BLIND_SCAN_CTRL_REG             0x80
+
+#define        LSA_CTRL_REG_1                  0x8D
+#define        SPCTRM_TILT_CORR_THRSHLD_REG    0x8f
+#define        ONE_DB_BNDWDTH_THRSHLD_REG      0x90
+#define        TWO_DB_BNDWDTH_THRSHLD_REG      0x91
+#define        THREE_DB_BNDWDTH_THRSHLD_REG    0x92
+#define        INBAND_POWER_THRSHLD_REG        0x93
+#define        REF_NOISE_LVL_MRGN_THRSHLD_REG  0x94
+
+#define        VIT_SRCH_CTRL_REG_1             0xa0
+#define        VIT_SRCH_CTRL_REG_2             0xa1
+#define        VIT_SRCH_CTRL_REG_3             0xa2
+#define        VIT_SRCH_STATUS_REG             0xa3
+#define        VITERBI_BER_COUNT_REG_L         0xab
+#define        REED_SOLOMON_CTRL_REG           0xb0
+#define        REED_SOLOMON_ERROR_COUNT_REG_L  0xb1
+#define        PRBS_CTRL_REG                   0xb5
+
+#define        LNB_CTRL_REG_1                  0xc0
+#define        LNB_CTRL_REG_2                  0xc1
+#define        LNB_CTRL_REG_3                  0xc2
+#define        LNB_CTRL_REG_4                  0xc3
+#define        LNB_CTRL_STATUS_REG             0xc4
+#define        LNB_FIFO_REGS_0                 0xc5
+#define        LNB_FIFO_REGS_1                 0xc6
+#define        LNB_FIFO_REGS_2                 0xc7
+#define        LNB_FIFO_REGS_3                 0xc8
+#define        LNB_FIFO_REGS_4                 0xc9
+#define        LNB_FIFO_REGS_5                 0xca
+#define        LNB_SUPPLY_CTRL_REG_1           0xcb
+#define        LNB_SUPPLY_CTRL_REG_2           0xcc
+#define        LNB_SUPPLY_CTRL_REG_3           0xcd
+#define        LNB_SUPPLY_CTRL_REG_4           0xce
+#define        LNB_SUPPLY_STATUS_REG           0xcf
+
+#define FALSE  0
+#define TRUE   1
+#define FAIL   -1
+#define PASS   0
+
+#define ALLOWABLE_FS_COUNT     10
+#define STATUS_BER             0
+#define STATUS_UCBLOCKS                1
+
+static int debug;
+#define dprintk(args...) \
+       do { \
+               if (debug) \
+                       printk(KERN_DEBUG "si21xx: " args); \
+       } while (0)
+
+enum {
+       ACTIVE_HIGH,
+       ACTIVE_LOW
+};
+enum {
+       BYTE_WIDE,
+       BIT_WIDE
+};
+enum {
+       CLK_GAPPED_MODE,
+       CLK_CONTINUOUS_MODE
+};
+enum {
+       RISING_EDGE,
+       FALLING_EDGE
+};
+enum {
+       MSB_FIRST,
+       LSB_FIRST
+};
+enum {
+       SERIAL,
+       PARALLEL
+};
+
+struct si21xx_state {
+       struct i2c_adapter *i2c;
+       const struct si21xx_config *config;
+       struct dvb_frontend frontend;
+       u8 initialised:1;
+       int errmode;
+       int fs;                 /*Sampling rate of the ADC in MHz*/
+};
+
+/*     register default initialization */
+static u8 serit_sp1511lhb_inittab[] = {
+       0x01, 0x28,     /* set i2c_inc_disable */
+       0x20, 0x03,
+       0x27, 0x20,
+       0xe0, 0x45,
+       0xe1, 0x08,
+       0xfe, 0x01,
+       0x01, 0x28,
+       0x89, 0x09,
+       0x04, 0x80,
+       0x05, 0x01,
+       0x06, 0x00,
+       0x20, 0x03,
+       0x24, 0x88,
+       0x29, 0x09,
+       0x2a, 0x0f,
+       0x2c, 0x10,
+       0x2d, 0x19,
+       0x2e, 0x08,
+       0x2f, 0x10,
+       0x30, 0x19,
+       0x34, 0x20,
+       0x35, 0x03,
+       0x45, 0x02,
+       0x46, 0x45,
+       0x47, 0xd0,
+       0x48, 0x00,
+       0x49, 0x40,
+       0x4a, 0x03,
+       0x4c, 0xfd,
+       0x4f, 0x2e,
+       0x50, 0x2e,
+       0x51, 0x10,
+       0x52, 0x10,
+       0x56, 0x92,
+       0x59, 0x00,
+       0x5a, 0x2d,
+       0x5b, 0x33,
+       0x5c, 0x1f,
+       0x5f, 0x76,
+       0x62, 0xc0,
+       0x63, 0xc0,
+       0x64, 0xf3,
+       0x65, 0xf3,
+       0x79, 0x40,
+       0x6a, 0x40,
+       0x6b, 0x0a,
+       0x6c, 0x80,
+       0x6d, 0x27,
+       0x71, 0x06,
+       0x75, 0x60,
+       0x78, 0x00,
+       0x79, 0xb5,
+       0x7c, 0x05,
+       0x7d, 0x1a,
+       0x87, 0x55,
+       0x88, 0x72,
+       0x8f, 0x08,
+       0x90, 0xe0,
+       0x94, 0x40,
+       0xa0, 0x3f,
+       0xa1, 0xc0,
+       0xa4, 0xcc,
+       0xa5, 0x66,
+       0xa6, 0x66,
+       0xa7, 0x7b,
+       0xa8, 0x7b,
+       0xa9, 0x7b,
+       0xaa, 0x9a,
+       0xed, 0x04,
+       0xad, 0x00,
+       0xae, 0x03,
+       0xcc, 0xab,
+       0x01, 0x08,
+       0xff, 0xff
+};
+
+/*     low level read/writes */
+static int si21_writeregs(struct si21xx_state *state, u8 reg1,
+                                                       u8 *data, int len)
+{
+       int ret;
+       u8 buf[60];/* = { reg1, data };*/
+       struct i2c_msg msg = {
+                               .addr = state->config->demod_address,
+                               .flags = 0,
+                               .buf = buf,
+                               .len = len + 1
+       };
+
+       msg.buf[0] =  reg1;
+       memcpy(msg.buf + 1, data, len);
+
+       ret = i2c_transfer(state->i2c, &msg, 1);
+
+       if (ret != 1)
+               dprintk("%s: writereg error (reg1 == 0x%02x, data == 0x%02x, "
+                       "ret == %i)\n", __func__, reg1, data[0], ret);
+
+       return (ret != 1) ? -EREMOTEIO : 0;
+}
+
+static int si21_writereg(struct si21xx_state *state, u8 reg, u8 data)
+{
+       int ret;
+       u8 buf[] = { reg, data };
+       struct i2c_msg msg = {
+                               .addr = state->config->demod_address,
+                               .flags = 0,
+                               .buf = buf,
+                               .len = 2
+       };
+
+       ret = i2c_transfer(state->i2c, &msg, 1);
+
+       if (ret != 1)
+               dprintk("%s: writereg error (reg == 0x%02x, data == 0x%02x, "
+                       "ret == %i)\n", __func__, reg, data, ret);
+
+       return (ret != 1) ? -EREMOTEIO : 0;
+}
+
+static int si21_write(struct dvb_frontend *fe, u8 *buf, int len)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       if (len != 2)
+               return -EINVAL;
+
+       return si21_writereg(state, buf[0], buf[1]);
+}
+
+static u8 si21_readreg(struct si21xx_state *state, u8 reg)
+{
+       int ret;
+       u8 b0[] = { reg };
+       u8 b1[] = { 0 };
+       struct i2c_msg msg[] = {
+               {
+                       .addr = state->config->demod_address,
+                       .flags = 0,
+                       .buf = b0,
+                       .len = 1
+               }, {
+                       .addr = state->config->demod_address,
+                       .flags = I2C_M_RD,
+                       .buf = b1,
+                       .len = 1
+               }
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 2);
+
+       if (ret != 2)
+               dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
+                       __func__, reg, ret);
+
+       return b1[0];
+}
+
+static int si21_readregs(struct si21xx_state *state, u8 reg1, u8 *b, u8 len)
+{
+       int ret;
+       struct i2c_msg msg[] = {
+               {
+                       .addr = state->config->demod_address,
+                       .flags = 0,
+                       .buf = &reg1,
+                       .len = 1
+               }, {
+                       .addr = state->config->demod_address,
+                       .flags = I2C_M_RD,
+                       .buf = b,
+                       .len = len
+               }
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 2);
+
+       if (ret != 2)
+               dprintk("%s: readreg error (ret == %i)\n", __func__, ret);
+
+       return ret == 2 ? 0 : -1;
+}
+
+static int si21xx_wait_diseqc_idle(struct si21xx_state *state, int timeout)
+{
+       unsigned long start = jiffies;
+
+       dprintk("%s\n", __func__);
+
+       while ((si21_readreg(state, LNB_CTRL_REG_1) & 0x8) == 8) {
+               if (jiffies - start > timeout) {
+                       dprintk("%s: timeout!!\n", __func__);
+                       return -ETIMEDOUT;
+               }
+               msleep(10);
+       };
+
+       return 0;
+}
+
+static int si21xx_set_symbolrate(struct dvb_frontend *fe, u32 srate)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u32 sym_rate, data_rate;
+       int i;
+       u8 sym_rate_bytes[3];
+
+       dprintk("%s : srate = %i\n", __func__ , srate);
+
+       if ((srate < 1000000) || (srate > 45000000))
+               return -EINVAL;
+
+       data_rate = srate;
+       sym_rate = 0;
+
+       for (i = 0; i < 4; ++i) {
+               sym_rate /= 100;
+               sym_rate = sym_rate + ((data_rate % 100) * 0x800000) /
+                                                               state->fs;
+               data_rate /= 100;
+       }
+       for (i = 0; i < 3; ++i)
+               sym_rate_bytes[i] = (u8)((sym_rate >> (i * 8)) & 0xff);
+
+       si21_writeregs(state, SYM_RATE_REG_L, sym_rate_bytes, 0x03);
+
+       return 0;
+}
+
+static int si21xx_send_diseqc_msg(struct dvb_frontend *fe,
+                                       struct dvb_diseqc_master_cmd *m)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 lnb_status;
+       u8 LNB_CTRL_1;
+       int status;
+
+       dprintk("%s\n", __func__);
+
+       status = PASS;
+       LNB_CTRL_1 = 0;
+
+       status |= si21_readregs(state, LNB_CTRL_STATUS_REG, &lnb_status, 0x01);
+       status |= si21_readregs(state, LNB_CTRL_REG_1, &lnb_status, 0x01);
+
+       /*fill the FIFO*/
+       status |= si21_writeregs(state, LNB_FIFO_REGS_0, m->msg, m->msg_len);
+
+       LNB_CTRL_1 = (lnb_status & 0x70);
+       LNB_CTRL_1 |= m->msg_len;
+
+       LNB_CTRL_1 |= 0x80;     /* begin LNB signaling */
+
+       status |= si21_writeregs(state, LNB_CTRL_REG_1, &LNB_CTRL_1, 0x01);
+
+       return status;
+}
+
+static int si21xx_send_diseqc_burst(struct dvb_frontend *fe,
+                                               fe_sec_mini_cmd_t burst)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 val;
+
+       dprintk("%s\n", __func__);
+
+       if (si21xx_wait_diseqc_idle(state, 100) < 0)
+               return -ETIMEDOUT;
+
+       val = (0x80 | si21_readreg(state, 0xc1));
+       if (si21_writereg(state, LNB_CTRL_REG_1,
+                       burst == SEC_MINI_A ? (val & ~0x10) : (val | 0x10)))
+               return -EREMOTEIO;
+
+       if (si21xx_wait_diseqc_idle(state, 100) < 0)
+               return -ETIMEDOUT;
+
+       if (si21_writereg(state, LNB_CTRL_REG_1, val))
+               return -EREMOTEIO;
+
+       return 0;
+}
+/*     30.06.2008 */
+static int si21xx_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 val;
+
+       dprintk("%s\n", __func__);
+       val = (0x80 | si21_readreg(state, LNB_CTRL_REG_1));
+
+       switch (tone) {
+       case SEC_TONE_ON:
+               return si21_writereg(state, LNB_CTRL_REG_1, val | 0x20);
+
+       case SEC_TONE_OFF:
+               return si21_writereg(state, LNB_CTRL_REG_1, (val & ~0x20));
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static int si21xx_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       u8 val;
+       dprintk("%s: %s\n", __func__,
+               volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
+               volt == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
+
+
+       val = (0x80 | si21_readreg(state, LNB_CTRL_REG_1));
+
+       switch (volt) {
+       case SEC_VOLTAGE_18:
+               return si21_writereg(state, LNB_CTRL_REG_1, val | 0x40);
+               break;
+       case SEC_VOLTAGE_13:
+               return si21_writereg(state, LNB_CTRL_REG_1, (val & ~0x40));
+               break;
+       default:
+               return -EINVAL;
+       };
+}
+
+static int si21xx_init(struct dvb_frontend *fe)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       int i;
+       int status = 0;
+       u8 reg1;
+       u8 val;
+       u8 reg2[2];
+
+       dprintk("%s\n", __func__);
+
+       for (i = 0; ; i += 2) {
+               reg1 = serit_sp1511lhb_inittab[i];
+               val = serit_sp1511lhb_inittab[i+1];
+               if (reg1 == 0xff && val == 0xff)
+                       break;
+               si21_writeregs(state, reg1, &val, 1);
+       }
+
+       /*DVB QPSK SYSTEM MODE REG*/
+       reg1 = 0x08;
+       si21_writeregs(state, SYSTEM_MODE_REG, &reg1, 0x01);
+
+       /*transport stream config*/
+       /*
+       mode = PARALLEL;
+       sdata_form = LSB_FIRST;
+       clk_edge = FALLING_EDGE;
+       clk_mode = CLK_GAPPED_MODE;
+       strt_len = BYTE_WIDE;
+       sync_pol = ACTIVE_HIGH;
+       val_pol = ACTIVE_HIGH;
+       err_pol = ACTIVE_HIGH;
+       sclk_rate = 0x00;
+       parity = 0x00 ;
+       data_delay = 0x00;
+       clk_delay = 0x00;
+       pclk_smooth = 0x00;
+       */
+       reg2[0] =
+               PARALLEL + (LSB_FIRST << 1)
+               + (FALLING_EDGE << 2) + (CLK_GAPPED_MODE << 3)
+               + (BYTE_WIDE << 4) + (ACTIVE_HIGH << 5)
+               + (ACTIVE_HIGH << 6) + (ACTIVE_HIGH << 7);
+
+       reg2[1] = 0;
+       /*      sclk_rate + (parity << 2)
+               + (data_delay << 3) + (clk_delay << 4)
+               + (pclk_smooth << 5);
+       */
+       status |= si21_writeregs(state, TS_CTRL_REG_1, reg2, 0x02);
+       if (status != 0)
+               dprintk(" %s : TS Set Error\n", __func__);
+
+       return 0;
+
+}
+
+static int si21_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 regs_read[2];
+       u8 reg_read;
+       u8 i;
+       u8 lock;
+       u8 signal = si21_readreg(state, ANALOG_AGC_POWER_LEVEL_REG);
+
+       si21_readregs(state, LOCK_STATUS_REG_1, regs_read, 0x02);
+       reg_read = 0;
+
+       for (i = 0; i < 7; ++i)
+               reg_read |= ((regs_read[0] >> i) & 0x01) << (6 - i);
+
+       lock = ((reg_read & 0x7f) | (regs_read[1] & 0x80));
+
+       dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, lock);
+       *status = 0;
+
+       if (signal > 10)
+               *status |= FE_HAS_SIGNAL;
+
+       if (lock & 0x2)
+               *status |= FE_HAS_CARRIER;
+
+       if (lock & 0x20)
+               *status |= FE_HAS_VITERBI;
+
+       if (lock & 0x40)
+               *status |= FE_HAS_SYNC;
+
+       if ((lock & 0x7b) == 0x7b)
+               *status |= FE_HAS_LOCK;
+
+       return 0;
+}
+
+static int si21_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       /*status = si21_readreg(state, ANALOG_AGC_POWER_LEVEL_REG,
+                                               (u8*)agclevel, 0x01);*/
+
+       u16 signal = (3 * si21_readreg(state, 0x27) *
+                                       si21_readreg(state, 0x28));
+
+       dprintk("%s : AGCPWR: 0x%02x%02x, signal=0x%04x\n", __func__,
+               si21_readreg(state, 0x27),
+               si21_readreg(state, 0x28), (int) signal);
+
+       signal  <<= 4;
+       *strength = signal;
+
+       return 0;
+}
+
+static int si21_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       if (state->errmode != STATUS_BER)
+               return 0;
+
+       *ber = (si21_readreg(state, 0x1d) << 8) |
+                               si21_readreg(state, 0x1e);
+
+       return 0;
+}
+
+static int si21_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       s32 xsnr = 0xffff - ((si21_readreg(state, 0x24) << 8) |
+                                       si21_readreg(state, 0x25));
+       xsnr = 3 * (xsnr - 0xa100);
+       *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;
+
+       dprintk("%s\n", __func__);
+
+       return 0;
+}
+
+static int si21_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       if (state->errmode != STATUS_UCBLOCKS)
+               *ucblocks = 0;
+       else
+               *ucblocks = (si21_readreg(state, 0x1d) << 8) |
+                                       si21_readreg(state, 0x1e);
+
+       return 0;
+}
+
+/*     initiates a channel acquisition sequence
+       using the specified symbol rate and code rate */
+static int si21xx_setacquire(struct dvb_frontend *fe, int symbrate,
+                                               fe_code_rate_t crate)
+{
+
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 coderates[] = {
+                               0x0, 0x01, 0x02, 0x04, 0x00,
+                               0x8, 0x10, 0x20, 0x00, 0x3f
+       };
+
+       u8 coderate_ptr;
+       int status;
+       u8 start_acq = 0x80;
+       u8 reg, regs[3];
+
+       dprintk("%s\n", __func__);
+
+       status = PASS;
+       coderate_ptr = coderates[crate];
+
+       si21xx_set_symbolrate(fe, symbrate);
+
+       /* write code rates to use in the Viterbi search */
+       status |= si21_writeregs(state,
+                               VIT_SRCH_CTRL_REG_1,
+                               &coderate_ptr, 0x01);
+
+       /* clear acq_start bit */
+       status |= si21_readregs(state, ACQ_CTRL_REG_2, &reg, 0x01);
+       reg &= ~start_acq;
+       status |= si21_writeregs(state, ACQ_CTRL_REG_2, &reg, 0x01);
+
+       /* use new Carrier Frequency Offset Estimator (QuickLock) */
+       regs[0] = 0xCB;
+       regs[1] = 0x40;
+       regs[2] = 0xCB;
+
+       status |= si21_writeregs(state,
+                               TWO_DB_BNDWDTH_THRSHLD_REG,
+                               &regs[0], 0x03);
+       reg = 0x56;
+       status |= si21_writeregs(state,
+                               LSA_CTRL_REG_1, &reg, 1);
+       reg = 0x05;
+       status |= si21_writeregs(state,
+                               BLIND_SCAN_CTRL_REG, &reg, 1);
+       /* start automatic acq */
+       status |= si21_writeregs(state,
+                               ACQ_CTRL_REG_2, &start_acq, 0x01);
+
+       return status;
+}
+
+static int si21xx_set_property(struct dvb_frontend *fe, struct dtv_property *p)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+static int si21xx_get_property(struct dvb_frontend *fe, struct dtv_property *p)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+static int si21xx_set_frontend(struct dvb_frontend *fe,
+                                       struct dvb_frontend_parameters *dfp)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+       /* freq         Channel carrier frequency in KHz (i.e. 1550000 KHz)
+        datarate       Channel symbol rate in Sps (i.e. 22500000 Sps)*/
+
+       /* in MHz */
+       unsigned char coarse_tune_freq;
+       int fine_tune_freq;
+       unsigned char sample_rate = 0;
+       /* boolean */
+       unsigned int inband_interferer_ind;
+
+       /* INTERMEDIATE VALUES */
+       int icoarse_tune_freq; /* MHz */
+       int ifine_tune_freq; /* MHz */
+       unsigned int band_high;
+       unsigned int band_low;
+       unsigned int x1;
+       unsigned int x2;
+       int i;
+       unsigned int inband_interferer_div2[ALLOWABLE_FS_COUNT] = {
+                       FALSE, FALSE, FALSE, FALSE, FALSE,
+                       FALSE, FALSE, FALSE, FALSE, FALSE
+       };
+       unsigned int inband_interferer_div4[ALLOWABLE_FS_COUNT] = {
+                       FALSE, FALSE, FALSE, FALSE, FALSE,
+                       FALSE, FALSE, FALSE, FALSE, FALSE
+       };
+
+       int status;
+
+       /* allowable sample rates for ADC in MHz */
+       int afs[ALLOWABLE_FS_COUNT] = { 200, 192, 193, 194, 195,
+                                       196, 204, 205, 206, 207
+       };
+       /* in MHz */
+       int if_limit_high;
+       int if_limit_low;
+       int lnb_lo;
+       int lnb_uncertanity;
+
+       int rf_freq;
+       int data_rate;
+       unsigned char regs[4];
+
+       dprintk("%s : FE_SET_FRONTEND\n", __func__);
+
+       if (c->delivery_system != SYS_DVBS) {
+                       dprintk("%s: unsupported delivery system selected (%d)\n",
+                               __func__, c->delivery_system);
+                       return -EOPNOTSUPP;
+       }
+
+       for (i = 0; i < ALLOWABLE_FS_COUNT; ++i)
+               inband_interferer_div2[i] = inband_interferer_div4[i] = FALSE;
+
+       if_limit_high = -700000;
+       if_limit_low = -100000;
+       /* in MHz */
+       lnb_lo = 0;
+       lnb_uncertanity = 0;
+
+       rf_freq = 10 * c->frequency ;
+       data_rate = c->symbol_rate / 100;
+
+       status = PASS;
+
+       band_low = (rf_freq - lnb_lo) - ((lnb_uncertanity * 200)
+                                       + (data_rate * 135)) / 200;
+
+       band_high = (rf_freq - lnb_lo) + ((lnb_uncertanity * 200)
+                                       + (data_rate * 135)) / 200;
+
+
+       icoarse_tune_freq = 100000 *
+                               (((rf_freq - lnb_lo) -
+                                       (if_limit_low + if_limit_high) / 2)
+                                                               / 100000);
+
+       ifine_tune_freq = (rf_freq - lnb_lo) - icoarse_tune_freq ;
+
+       for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
+               x1 = ((rf_freq - lnb_lo) / (afs[i] * 2500)) *
+                                       (afs[i] * 2500) + afs[i] * 2500;
+
+               x2 = ((rf_freq - lnb_lo) / (afs[i] * 2500)) *
+                                                       (afs[i] * 2500);
+
+               if (((band_low < x1) && (x1 < band_high)) ||
+                                       ((band_low < x2) && (x2 < band_high)))
+                                       inband_interferer_div4[i] = TRUE;
+
+       }
+
+       for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
+               x1 = ((rf_freq - lnb_lo) / (afs[i] * 5000)) *
+                                       (afs[i] * 5000) + afs[i] * 5000;
+
+               x2 = ((rf_freq - lnb_lo) / (afs[i] * 5000)) *
+                                       (afs[i] * 5000);
+
+               if (((band_low < x1) && (x1 < band_high)) ||
+                                       ((band_low < x2) && (x2 < band_high)))
+                                       inband_interferer_div2[i] = TRUE;
+       }
+
+       inband_interferer_ind = TRUE;
+       for (i = 0; i < ALLOWABLE_FS_COUNT; ++i)
+               inband_interferer_ind &= inband_interferer_div2[i] |
+                                               inband_interferer_div4[i];
+
+       if (inband_interferer_ind) {
+               for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
+                       if (inband_interferer_div2[i] == FALSE) {
+                               sample_rate = (u8) afs[i];
+                               break;
+                       }
+               }
+       } else {
+               for (i = 0; i < ALLOWABLE_FS_COUNT; ++i) {
+                       if ((inband_interferer_div2[i] |
+                                       inband_interferer_div4[i]) == FALSE) {
+                               sample_rate = (u8) afs[i];
+                               break;
+                       }
+               }
+
+       }
+
+       if (sample_rate > 207 || sample_rate < 192)
+               sample_rate = 200;
+
+       fine_tune_freq = ((0x4000 * (ifine_tune_freq / 10)) /
+                                       ((sample_rate) * 1000));
+
+       coarse_tune_freq = (u8)(icoarse_tune_freq / 100000);
+
+       regs[0] = sample_rate;
+       regs[1] = coarse_tune_freq;
+       regs[2] = fine_tune_freq & 0xFF;
+       regs[3] = fine_tune_freq >> 8 & 0xFF;
+
+       status |= si21_writeregs(state, PLL_DIVISOR_REG, &regs[0], 0x04);
+
+       state->fs = sample_rate;/*ADC MHz*/
+       si21xx_setacquire(fe, c->symbol_rate, c->fec_inner);
+
+       return 0;
+}
+
+static int si21xx_sleep(struct dvb_frontend *fe)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+       u8 regdata;
+
+       dprintk("%s\n", __func__);
+
+       si21_readregs(state, SYSTEM_MODE_REG, &regdata, 0x01);
+       regdata |= 1 << 6;
+       si21_writeregs(state, SYSTEM_MODE_REG, &regdata, 0x01);
+       state->initialised = 0;
+
+       return 0;
+}
+
+static void si21xx_release(struct dvb_frontend *fe)
+{
+       struct si21xx_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       kfree(state);
+}
+
+static struct dvb_frontend_ops si21xx_ops = {
+
+       .info = {
+               .name                   = "SL SI21XX DVB-S",
+               .type                   = FE_QPSK,
+               .frequency_min          = 950000,
+               .frequency_max          = 2150000,
+               .frequency_stepsize     = 125,   /* kHz for QPSK frontends */
+               .frequency_tolerance    = 0,
+               .symbol_rate_min        = 1000000,
+               .symbol_rate_max        = 45000000,
+               .symbol_rate_tolerance  = 500,  /* ppm */
+               .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+               FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
+               FE_CAN_QPSK |
+               FE_CAN_FEC_AUTO
+       },
+
+       .release = si21xx_release,
+       .init = si21xx_init,
+       .sleep = si21xx_sleep,
+       .write = si21_write,
+       .read_status = si21_read_status,
+       .read_ber = si21_read_ber,
+       .read_signal_strength = si21_read_signal_strength,
+       .read_snr = si21_read_snr,
+       .read_ucblocks = si21_read_ucblocks,
+       .diseqc_send_master_cmd = si21xx_send_diseqc_msg,
+       .diseqc_send_burst = si21xx_send_diseqc_burst,
+       .set_tone = si21xx_set_tone,
+       .set_voltage = si21xx_set_voltage,
+
+       .set_property = si21xx_set_property,
+       .get_property = si21xx_get_property,
+       .set_frontend = si21xx_set_frontend,
+};
+
+struct dvb_frontend *si21xx_attach(const struct si21xx_config *config,
+                                               struct i2c_adapter *i2c)
+{
+       struct si21xx_state *state = NULL;
+       int id;
+
+       dprintk("%s\n", __func__);
+
+       /* allocate memory for the internal state */
+       state = kmalloc(sizeof(struct si21xx_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error;
+
+       /* setup the state */
+       state->config = config;
+       state->i2c = i2c;
+       state->initialised = 0;
+       state->errmode = STATUS_BER;
+
+       /* check if the demod is there */
+       id = si21_readreg(state, SYSTEM_MODE_REG);
+       si21_writereg(state, SYSTEM_MODE_REG, id | 0x40); /* standby off */
+       msleep(200);
+       id = si21_readreg(state, 0x00);
+
+       /* register 0x00 contains:
+               0x34 for SI2107
+               0x24 for SI2108
+               0x14 for SI2109
+               0x04 for SI2110
+       */
+       if (id != 0x04 && id != 0x14)
+               goto error;
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &si21xx_ops,
+                                       sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+       return &state->frontend;
+
+error:
+       kfree(state);
+       return NULL;
+}
+EXPORT_SYMBOL(si21xx_attach);
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_DESCRIPTION("SL SI21XX DVB Demodulator driver");
+MODULE_AUTHOR("Igor M. Liplianin");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/si21xx.h b/drivers/media/dvb/frontends/si21xx.h
new file mode 100644 (file)
index 0000000..141b5b8
--- /dev/null
@@ -0,0 +1,37 @@
+#ifndef SI21XX_H
+#define SI21XX_H
+
+#include <linux/dvb/frontend.h>
+#include "dvb_frontend.h"
+
+struct si21xx_config {
+       /* the demodulator's i2c address */
+       u8 demod_address;
+
+       /* minimum delay before retuning */
+       int min_delay_ms;
+};
+
+#if defined(CONFIG_DVB_SI21XX) || \
+               (defined(CONFIG_DVB_SI21XX_MODULE) && defined(MODULE))
+extern struct dvb_frontend *si21xx_attach(const struct si21xx_config *config,
+                                               struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *si21xx_attach(
+               const struct si21xx_config *config, struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif
+
+static inline int si21xx_writeregister(struct dvb_frontend *fe, u8 reg, u8 val)
+{
+       int r = 0;
+       u8 buf[] = {reg, val};
+       if (fe->ops.write)
+               r = fe->ops.write(fe, buf, 2);
+       return r;
+}
+
+#endif
index 4543609e181619aae2b7746855e88c346112901a..559509ab4dabfc2f4376bb0b46d58315defb74fd 100644 (file)
@@ -337,7 +337,8 @@ static int sp887x_setup_frontend_parameters (struct dvb_frontend* fe,
                                             struct dvb_frontend_parameters *p)
 {
        struct sp887x_state* state = fe->demodulator_priv;
-       int actual_freq, err;
+       unsigned actual_freq;
+       int err;
        u16 val, reg0xc05;
 
        if (p->u.ofdm.bandwidth != BANDWIDTH_8_MHZ &&
diff --git a/drivers/media/dvb/frontends/stb6000.c b/drivers/media/dvb/frontends/stb6000.c
new file mode 100644 (file)
index 0000000..0e2cb0d
--- /dev/null
@@ -0,0 +1,255 @@
+  /*
+     Driver for ST STB6000 DVBS Silicon tuner
+
+     Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 2 of the License, or
+     (at your option) any later version.
+
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+
+     GNU General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+  */
+
+#include <linux/module.h>
+#include <linux/dvb/frontend.h>
+#include <asm/types.h>
+
+#include "stb6000.h"
+
+static int debug;
+#define dprintk(args...) \
+       do { \
+               if (debug) \
+                       printk(KERN_DEBUG "stb6000: " args); \
+       } while (0)
+
+struct stb6000_priv {
+       /* i2c details */
+       int i2c_address;
+       struct i2c_adapter *i2c;
+       u32 frequency;
+};
+
+static int stb6000_release(struct dvb_frontend *fe)
+{
+       kfree(fe->tuner_priv);
+       fe->tuner_priv = NULL;
+       return 0;
+}
+
+static int stb6000_sleep(struct dvb_frontend *fe)
+{
+       struct stb6000_priv *priv = fe->tuner_priv;
+       int ret;
+       u8 buf[] = { 10, 0 };
+       struct i2c_msg msg = {
+               .addr = priv->i2c_address,
+               .flags = 0,
+               .buf = buf,
+               .len = 2
+       };
+
+       dprintk("%s:\n", __func__);
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1);
+
+       ret = i2c_transfer(priv->i2c, &msg, 1);
+       if (ret != 1)
+               dprintk("%s: i2c error\n", __func__);
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0);
+
+       return (ret == 1) ? 0 : ret;
+}
+
+static int stb6000_set_params(struct dvb_frontend *fe,
+                               struct dvb_frontend_parameters *params)
+{
+       struct stb6000_priv *priv = fe->tuner_priv;
+       unsigned int n, m;
+       int ret;
+       u32 freq_mhz;
+       int bandwidth;
+       u8 buf[12];
+       struct i2c_msg msg = {
+               .addr = priv->i2c_address,
+               .flags = 0,
+               .buf = buf,
+               .len = 12
+       };
+
+       dprintk("%s:\n", __func__);
+
+       freq_mhz = params->frequency / 1000;
+       bandwidth = params->u.qpsk.symbol_rate / 1000000;
+
+       if (bandwidth > 31)
+               bandwidth = 31;
+
+       if ((freq_mhz > 949) && (freq_mhz < 2151)) {
+               buf[0] = 0x01;
+               buf[1] = 0xac;
+               if (freq_mhz < 1950)
+                       buf[1] = 0xaa;
+               if (freq_mhz < 1800)
+                       buf[1] = 0xa8;
+               if (freq_mhz < 1650)
+                       buf[1] = 0xa6;
+               if (freq_mhz < 1530)
+                       buf[1] = 0xa5;
+               if (freq_mhz < 1470)
+                       buf[1] = 0xa4;
+               if (freq_mhz < 1370)
+                       buf[1] = 0xa2;
+               if (freq_mhz < 1300)
+                       buf[1] = 0xa1;
+               if (freq_mhz < 1200)
+                       buf[1] = 0xa0;
+               if (freq_mhz < 1075)
+                       buf[1] = 0xbc;
+               if (freq_mhz < 1000)
+                       buf[1] = 0xba;
+               if (freq_mhz < 1075) {
+                       n = freq_mhz / 8; /* vco=lo*4 */
+                       m = 2;
+               } else {
+                       n = freq_mhz / 16; /* vco=lo*2 */
+                       m = 1;
+               }
+               buf[2] = n >> 1;
+               buf[3] = (unsigned char)(((n & 1) << 7) |
+                                       (m * freq_mhz - n * 16) | 0x60);
+               buf[4] = 0x04;
+               buf[5] = 0x0e;
+
+               buf[6] = (unsigned char)(bandwidth);
+
+               buf[7] = 0xd8;
+               buf[8] = 0xd0;
+               buf[9] = 0x50;
+               buf[10] = 0xeb;
+               buf[11] = 0x4f;
+
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 1);
+
+               ret = i2c_transfer(priv->i2c, &msg, 1);
+               if (ret != 1)
+                       dprintk("%s: i2c error\n", __func__);
+
+               udelay(10);
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 0);
+
+               buf[0] = 0x07;
+               buf[1] = 0xdf;
+               buf[2] = 0xd0;
+               buf[3] = 0x50;
+               buf[4] = 0xfb;
+               msg.len = 5;
+
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 1);
+
+               ret = i2c_transfer(priv->i2c, &msg, 1);
+               if (ret != 1)
+                       dprintk("%s: i2c error\n", __func__);
+
+               udelay(10);
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 0);
+
+               priv->frequency = freq_mhz * 1000;
+
+               return (ret == 1) ? 0 : ret;
+       }
+       return -1;
+}
+
+static int stb6000_get_frequency(struct dvb_frontend *fe, u32 *frequency)
+{
+       struct stb6000_priv *priv = fe->tuner_priv;
+       *frequency = priv->frequency;
+       return 0;
+}
+
+static struct dvb_tuner_ops stb6000_tuner_ops = {
+       .info = {
+               .name = "ST STB6000",
+               .frequency_min = 950000,
+               .frequency_max = 2150000
+       },
+       .release = stb6000_release,
+       .sleep = stb6000_sleep,
+       .set_params = stb6000_set_params,
+       .get_frequency = stb6000_get_frequency,
+};
+
+struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
+                                               struct i2c_adapter *i2c)
+{
+       struct stb6000_priv *priv = NULL;
+       u8 b0[] = { 0 };
+       u8 b1[] = { 0, 0 };
+       struct i2c_msg msg[2] = {
+               {
+                       .addr = addr,
+                       .flags = 0,
+                       .buf = b0,
+                       .len = 0
+               }, {
+                       .addr = addr,
+                       .flags = I2C_M_RD,
+                       .buf = b1,
+                       .len = 2
+               }
+       };
+       int ret;
+
+       dprintk("%s:\n", __func__);
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1);
+
+       /* is some i2c device here ? */
+       ret = i2c_transfer(i2c, msg, 2);
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 0);
+
+       if (ret != 2)
+               return NULL;
+
+       priv = kzalloc(sizeof(struct stb6000_priv), GFP_KERNEL);
+       if (priv == NULL)
+               return NULL;
+
+       priv->i2c_address = addr;
+       priv->i2c = i2c;
+
+       memcpy(&fe->ops.tuner_ops, &stb6000_tuner_ops,
+                               sizeof(struct dvb_tuner_ops));
+
+       fe->tuner_priv = priv;
+
+       return fe;
+}
+EXPORT_SYMBOL(stb6000_attach);
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_DESCRIPTION("DVB STB6000 driver");
+MODULE_AUTHOR("Igor M. Liplianin <liplianin@me.by>");
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb/frontends/stb6000.h b/drivers/media/dvb/frontends/stb6000.h
new file mode 100644 (file)
index 0000000..7be479c
--- /dev/null
@@ -0,0 +1,51 @@
+  /*
+     Driver for ST stb6000 DVBS Silicon tuner
+
+     Copyright (C) 2008 Igor M. Liplianin (liplianin@me.by)
+
+     This program is free software; you can redistribute it and/or modify
+     it under the terms of the GNU General Public License as published by
+     the Free Software Foundation; either version 2 of the License, or
+     (at your option) any later version.
+
+     This program is distributed in the hope that it will be useful,
+     but WITHOUT ANY WARRANTY; without even the implied warranty of
+     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+
+     GNU General Public License for more details.
+
+     You should have received a copy of the GNU General Public License
+     along with this program; if not, write to the Free Software
+     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+  */
+
+#ifndef __DVB_STB6000_H__
+#define __DVB_STB6000_H__
+
+#include <linux/i2c.h>
+#include "dvb_frontend.h"
+
+/**
+ * Attach a stb6000 tuner to the supplied frontend structure.
+ *
+ * @param fe Frontend to attach to.
+ * @param addr i2c address of the tuner.
+ * @param i2c i2c adapter to use.
+ * @return FE pointer on success, NULL on failure.
+ */
+#if defined(CONFIG_DVB_STB6000) || (defined(CONFIG_DVB_STB6000_MODULE) \
+                                                       && defined(MODULE))
+extern struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe, int addr,
+                                          struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *stb6000_attach(struct dvb_frontend *fe,
+                                                 int addr,
+                                                 struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_STB6000 */
+
+#endif /* __DVB_STB6000_H__ */
diff --git a/drivers/media/dvb/frontends/stv0288.c b/drivers/media/dvb/frontends/stv0288.c
new file mode 100644 (file)
index 0000000..ff1194d
--- /dev/null
@@ -0,0 +1,618 @@
+/*
+       Driver for ST STV0288 demodulator
+       Copyright (C) 2006 Georg Acher, BayCom GmbH, acher (at) baycom (dot) de
+               for Reel Multimedia
+       Copyright (C) 2008 TurboSight.com, Bob Liu <bob@turbosight.com>
+       Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
+               Removed stb6000 specific tuner code and revised some
+               procedures.
+
+       This program is free software; you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation; either version 2 of the License, or
+       (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <asm/div64.h>
+
+#include "dvb_frontend.h"
+#include "stv0288.h"
+
+struct stv0288_state {
+       struct i2c_adapter *i2c;
+       const struct stv0288_config *config;
+       struct dvb_frontend frontend;
+
+       u8 initialised:1;
+       u32 tuner_frequency;
+       u32 symbol_rate;
+       fe_code_rate_t fec_inner;
+       int errmode;
+};
+
+#define STATUS_BER 0
+#define STATUS_UCBLOCKS 1
+
+static int debug;
+static int debug_legacy_dish_switch;
+#define dprintk(args...) \
+       do { \
+               if (debug) \
+                       printk(KERN_DEBUG "stv0288: " args); \
+       } while (0)
+
+
+static int stv0288_writeregI(struct stv0288_state *state, u8 reg, u8 data)
+{
+       int ret;
+       u8 buf[] = { reg, data };
+       struct i2c_msg msg = {
+               .addr = state->config->demod_address,
+               .flags = 0,
+               .buf = buf,
+               .len = 2
+       };
+
+       ret = i2c_transfer(state->i2c, &msg, 1);
+
+       if (ret != 1)
+               dprintk("%s: writereg error (reg == 0x%02x, val == 0x%02x, "
+                       "ret == %i)\n", __func__, reg, data, ret);
+
+       return (ret != 1) ? -EREMOTEIO : 0;
+}
+
+static int stv0288_write(struct dvb_frontend *fe, u8 *buf, int len)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       if (len != 2)
+               return -EINVAL;
+
+       return stv0288_writeregI(state, buf[0], buf[1]);
+}
+
+static u8 stv0288_readreg(struct stv0288_state *state, u8 reg)
+{
+       int ret;
+       u8 b0[] = { reg };
+       u8 b1[] = { 0 };
+       struct i2c_msg msg[] = {
+               {
+                       .addr = state->config->demod_address,
+                       .flags = 0,
+                       .buf = b0,
+                       .len = 1
+               }, {
+                       .addr = state->config->demod_address,
+                       .flags = I2C_M_RD,
+                       .buf = b1,
+                       .len = 1
+               }
+       };
+
+       ret = i2c_transfer(state->i2c, msg, 2);
+
+       if (ret != 2)
+               dprintk("%s: readreg error (reg == 0x%02x, ret == %i)\n",
+                               __func__, reg, ret);
+
+       return b1[0];
+}
+
+static int stv0288_set_symbolrate(struct dvb_frontend *fe, u32 srate)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+       unsigned int temp;
+       unsigned char b[3];
+
+       if ((srate < 1000000) || (srate > 45000000))
+               return -EINVAL;
+
+       temp = (unsigned int)srate / 1000;
+
+               temp = temp * 32768;
+               temp = temp / 25;
+               temp = temp / 125;
+               b[0] = (unsigned char)((temp >> 12) & 0xff);
+               b[1] = (unsigned char)((temp >> 4) & 0xff);
+               b[2] = (unsigned char)((temp << 4) & 0xf0);
+               stv0288_writeregI(state, 0x28, 0x80); /* SFRH */
+               stv0288_writeregI(state, 0x29, 0); /* SFRM */
+               stv0288_writeregI(state, 0x2a, 0); /* SFRL */
+
+               stv0288_writeregI(state, 0x28, b[0]);
+               stv0288_writeregI(state, 0x29, b[1]);
+               stv0288_writeregI(state, 0x2a, b[2]);
+               dprintk("stv0288: stv0288_set_symbolrate\n");
+
+       return 0;
+}
+
+static int stv0288_send_diseqc_msg(struct dvb_frontend *fe,
+                                   struct dvb_diseqc_master_cmd *m)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       int i;
+
+       dprintk("%s\n", __func__);
+
+       stv0288_writeregI(state, 0x09, 0);
+       msleep(30);
+       stv0288_writeregI(state, 0x05, 0x16);
+
+       for (i = 0; i < m->msg_len; i++) {
+               if (stv0288_writeregI(state, 0x06, m->msg[i]))
+                       return -EREMOTEIO;
+               msleep(12);
+       }
+
+       return 0;
+}
+
+static int stv0288_send_diseqc_burst(struct dvb_frontend *fe,
+                                               fe_sec_mini_cmd_t burst)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       dprintk("%s\n", __func__);
+
+       if (stv0288_writeregI(state, 0x05, 0x16))/* burst mode */
+               return -EREMOTEIO;
+
+       if (stv0288_writeregI(state, 0x06, burst == SEC_MINI_A ? 0x00 : 0xff))
+               return -EREMOTEIO;
+
+       if (stv0288_writeregI(state, 0x06, 0x12))
+               return -EREMOTEIO;
+
+       return 0;
+}
+
+static int stv0288_set_tone(struct dvb_frontend *fe, fe_sec_tone_mode_t tone)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       switch (tone) {
+       case SEC_TONE_ON:
+               if (stv0288_writeregI(state, 0x05, 0x10))/* burst mode */
+                       return -EREMOTEIO;
+               return stv0288_writeregI(state, 0x06, 0xff);
+
+       case SEC_TONE_OFF:
+               if (stv0288_writeregI(state, 0x05, 0x13))/* burst mode */
+                       return -EREMOTEIO;
+               return stv0288_writeregI(state, 0x06, 0x00);
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static u8 stv0288_inittab[] = {
+       0x01, 0x15,
+       0x02, 0x20,
+       0x09, 0x0,
+       0x0a, 0x4,
+       0x0b, 0x0,
+       0x0c, 0x0,
+       0x0d, 0x0,
+       0x0e, 0xd4,
+       0x0f, 0x30,
+       0x11, 0x80,
+       0x12, 0x03,
+       0x13, 0x48,
+       0x14, 0x84,
+       0x15, 0x45,
+       0x16, 0xb7,
+       0x17, 0x9c,
+       0x18, 0x0,
+       0x19, 0xa6,
+       0x1a, 0x88,
+       0x1b, 0x8f,
+       0x1c, 0xf0,
+       0x20, 0x0b,
+       0x21, 0x54,
+       0x22, 0x0,
+       0x23, 0x0,
+       0x2b, 0xff,
+       0x2c, 0xf7,
+       0x30, 0x0,
+       0x31, 0x1e,
+       0x32, 0x14,
+       0x33, 0x0f,
+       0x34, 0x09,
+       0x35, 0x0c,
+       0x36, 0x05,
+       0x37, 0x2f,
+       0x38, 0x16,
+       0x39, 0xbe,
+       0x3a, 0x0,
+       0x3b, 0x13,
+       0x3c, 0x11,
+       0x3d, 0x30,
+       0x40, 0x63,
+       0x41, 0x04,
+       0x42, 0x60,
+       0x43, 0x00,
+       0x44, 0x00,
+       0x45, 0x00,
+       0x46, 0x00,
+       0x47, 0x00,
+       0x4a, 0x00,
+       0x50, 0x10,
+       0x51, 0x38,
+       0x52, 0x21,
+       0x58, 0x54,
+       0x59, 0x86,
+       0x5a, 0x0,
+       0x5b, 0x9b,
+       0x5c, 0x08,
+       0x5d, 0x7f,
+       0x5e, 0x0,
+       0x5f, 0xff,
+       0x70, 0x0,
+       0x71, 0x0,
+       0x72, 0x0,
+       0x74, 0x0,
+       0x75, 0x0,
+       0x76, 0x0,
+       0x81, 0x0,
+       0x82, 0x3f,
+       0x83, 0x3f,
+       0x84, 0x0,
+       0x85, 0x0,
+       0x88, 0x0,
+       0x89, 0x0,
+       0x8a, 0x0,
+       0x8b, 0x0,
+       0x8c, 0x0,
+       0x90, 0x0,
+       0x91, 0x0,
+       0x92, 0x0,
+       0x93, 0x0,
+       0x94, 0x1c,
+       0x97, 0x0,
+       0xa0, 0x48,
+       0xa1, 0x0,
+       0xb0, 0xb8,
+       0xb1, 0x3a,
+       0xb2, 0x10,
+       0xb3, 0x82,
+       0xb4, 0x80,
+       0xb5, 0x82,
+       0xb6, 0x82,
+       0xb7, 0x82,
+       0xb8, 0x20,
+       0xb9, 0x0,
+       0xf0, 0x0,
+       0xf1, 0x0,
+       0xf2, 0xc0,
+       0x51, 0x36,
+       0x52, 0x09,
+       0x53, 0x94,
+       0x54, 0x62,
+       0x55, 0x29,
+       0x56, 0x64,
+       0x57, 0x2b,
+       0xff, 0xff,
+};
+
+static int stv0288_set_voltage(struct dvb_frontend *fe, fe_sec_voltage_t volt)
+{
+       dprintk("%s: %s\n", __func__,
+               volt == SEC_VOLTAGE_13 ? "SEC_VOLTAGE_13" :
+               volt == SEC_VOLTAGE_18 ? "SEC_VOLTAGE_18" : "??");
+
+       return 0;
+}
+
+static int stv0288_init(struct dvb_frontend *fe)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+       int i;
+       u8 reg;
+       u8 val;
+
+       dprintk("stv0288: init chip\n");
+       stv0288_writeregI(state, 0x41, 0x04);
+       msleep(50);
+
+       /* we have default inittab */
+       if (state->config->inittab == NULL) {
+               for (i = 0; !(stv0288_inittab[i] == 0xff &&
+                               stv0288_inittab[i + 1] == 0xff); i += 2)
+                       stv0288_writeregI(state, stv0288_inittab[i],
+                                       stv0288_inittab[i + 1]);
+       } else {
+               for (i = 0; ; i += 2)  {
+                       reg = state->config->inittab[i];
+                       val = state->config->inittab[i+1];
+                       if (reg == 0xff && val == 0xff)
+                               break;
+                       stv0288_writeregI(state, reg, val);
+               }
+       }
+       return 0;
+}
+
+static int stv0288_read_status(struct dvb_frontend *fe, fe_status_t *status)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       u8 sync = stv0288_readreg(state, 0x24);
+       if (sync == 255)
+               sync = 0;
+
+       dprintk("%s : FE_READ_STATUS : VSTATUS: 0x%02x\n", __func__, sync);
+
+       *status = 0;
+
+       if ((sync & 0x08) == 0x08) {
+               *status |= FE_HAS_LOCK;
+               dprintk("stv0288 has locked\n");
+       }
+
+       return 0;
+}
+
+static int stv0288_read_ber(struct dvb_frontend *fe, u32 *ber)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       if (state->errmode != STATUS_BER)
+               return 0;
+       *ber = (stv0288_readreg(state, 0x26) << 8) |
+                                       stv0288_readreg(state, 0x27);
+       dprintk("stv0288_read_ber %d\n", *ber);
+
+       return 0;
+}
+
+
+static int stv0288_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       s32 signal =  0xffff - ((stv0288_readreg(state, 0x10) << 8));
+
+
+       signal = signal * 5 / 4;
+       *strength = (signal > 0xffff) ? 0xffff : (signal < 0) ? 0 : signal;
+       dprintk("stv0288_read_signal_strength %d\n", *strength);
+
+       return 0;
+}
+static int stv0288_sleep(struct dvb_frontend *fe)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       stv0288_writeregI(state, 0x41, 0x84);
+       state->initialised = 0;
+
+       return 0;
+}
+static int stv0288_read_snr(struct dvb_frontend *fe, u16 *snr)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       s32 xsnr = 0xffff - ((stv0288_readreg(state, 0x2d) << 8)
+                          | stv0288_readreg(state, 0x2e));
+       xsnr = 3 * (xsnr - 0xa100);
+       *snr = (xsnr > 0xffff) ? 0xffff : (xsnr < 0) ? 0 : xsnr;
+       dprintk("stv0288_read_snr %d\n", *snr);
+
+       return 0;
+}
+
+static int stv0288_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       if (state->errmode != STATUS_BER)
+               return 0;
+       *ucblocks = (stv0288_readreg(state, 0x26) << 8) |
+                                       stv0288_readreg(state, 0x27);
+       dprintk("stv0288_read_ber %d\n", *ucblocks);
+
+       return 0;
+}
+
+static int stv0288_set_property(struct dvb_frontend *fe, struct dtv_property *p)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+static int stv0288_get_property(struct dvb_frontend *fe, struct dtv_property *p)
+{
+       dprintk("%s(..)\n", __func__);
+       return 0;
+}
+
+static int stv0288_set_frontend(struct dvb_frontend *fe,
+                                       struct dvb_frontend_parameters *dfp)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+       struct dtv_frontend_properties *c = &fe->dtv_property_cache;
+
+       char tm;
+       unsigned char tda[3];
+
+       dprintk("%s : FE_SET_FRONTEND\n", __func__);
+
+       if (c->delivery_system != SYS_DVBS) {
+                       dprintk("%s: unsupported delivery "
+                               "system selected (%d)\n",
+                               __func__, c->delivery_system);
+                       return -EOPNOTSUPP;
+       }
+
+       if (state->config->set_ts_params)
+               state->config->set_ts_params(fe, 0);
+
+       /* only frequency & symbol_rate are used for tuner*/
+       dfp->frequency = c->frequency;
+       dfp->u.qpsk.symbol_rate = c->symbol_rate;
+       if (fe->ops.tuner_ops.set_params) {
+               fe->ops.tuner_ops.set_params(fe, dfp);
+               if (fe->ops.i2c_gate_ctrl)
+                       fe->ops.i2c_gate_ctrl(fe, 0);
+       }
+
+       udelay(10);
+       stv0288_set_symbolrate(fe, c->symbol_rate);
+       /* Carrier lock control register */
+       stv0288_writeregI(state, 0x15, 0xc5);
+
+       tda[0] = 0x2b; /* CFRM */
+       tda[2] = 0x0; /* CFRL */
+       for (tm = -6; tm < 7;) {
+               /* Viterbi status */
+               if (stv0288_readreg(state, 0x24) & 0x80)
+                       break;
+
+               tda[2] += 40;
+               if (tda[2] < 40)
+                       tm++;
+               tda[1] = (unsigned char)tm;
+               stv0288_writeregI(state, 0x2b, tda[1]);
+               stv0288_writeregI(state, 0x2c, tda[2]);
+               udelay(30);
+       }
+
+       state->tuner_frequency = c->frequency;
+       state->fec_inner = FEC_AUTO;
+       state->symbol_rate = c->symbol_rate;
+
+       return 0;
+}
+
+static int stv0288_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+
+       if (enable)
+               stv0288_writeregI(state, 0x01, 0xb5);
+       else
+               stv0288_writeregI(state, 0x01, 0x35);
+
+       udelay(1);
+
+       return 0;
+}
+
+static void stv0288_release(struct dvb_frontend *fe)
+{
+       struct stv0288_state *state = fe->demodulator_priv;
+       kfree(state);
+}
+
+static struct dvb_frontend_ops stv0288_ops = {
+
+       .info = {
+               .name                   = "ST STV0288 DVB-S",
+               .type                   = FE_QPSK,
+               .frequency_min          = 950000,
+               .frequency_max          = 2150000,
+               .frequency_stepsize     = 1000,  /* kHz for QPSK frontends */
+               .frequency_tolerance    = 0,
+               .symbol_rate_min        = 1000000,
+               .symbol_rate_max        = 45000000,
+               .symbol_rate_tolerance  = 500,  /* ppm */
+               .caps = FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
+                     FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 |
+                     FE_CAN_QPSK |
+                     FE_CAN_FEC_AUTO
+       },
+
+       .release = stv0288_release,
+       .init = stv0288_init,
+       .sleep = stv0288_sleep,
+       .write = stv0288_write,
+       .i2c_gate_ctrl = stv0288_i2c_gate_ctrl,
+       .read_status = stv0288_read_status,
+       .read_ber = stv0288_read_ber,
+       .read_signal_strength = stv0288_read_signal_strength,
+       .read_snr = stv0288_read_snr,
+       .read_ucblocks = stv0288_read_ucblocks,
+       .diseqc_send_master_cmd = stv0288_send_diseqc_msg,
+       .diseqc_send_burst = stv0288_send_diseqc_burst,
+       .set_tone = stv0288_set_tone,
+       .set_voltage = stv0288_set_voltage,
+
+       .set_property = stv0288_set_property,
+       .get_property = stv0288_get_property,
+       .set_frontend = stv0288_set_frontend,
+};
+
+struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
+                                   struct i2c_adapter *i2c)
+{
+       struct stv0288_state *state = NULL;
+       int id;
+
+       /* allocate memory for the internal state */
+       state = kmalloc(sizeof(struct stv0288_state), GFP_KERNEL);
+       if (state == NULL)
+               goto error;
+
+       /* setup the state */
+       state->config = config;
+       state->i2c = i2c;
+       state->initialised = 0;
+       state->tuner_frequency = 0;
+       state->symbol_rate = 0;
+       state->fec_inner = 0;
+       state->errmode = STATUS_BER;
+
+       stv0288_writeregI(state, 0x41, 0x04);
+       msleep(200);
+       id = stv0288_readreg(state, 0x00);
+       dprintk("stv0288 id %x\n", id);
+
+       /* register 0x00 contains 0x11 for STV0288  */
+       if (id != 0x11)
+               goto error;
+
+       /* create dvb_frontend */
+       memcpy(&state->frontend.ops, &stv0288_ops,
+                       sizeof(struct dvb_frontend_ops));
+       state->frontend.demodulator_priv = state;
+       return &state->frontend;
+
+error:
+       kfree(state);
+
+       return NULL;
+}
+EXPORT_SYMBOL(stv0288_attach);
+
+module_param(debug_legacy_dish_switch, int, 0444);
+MODULE_PARM_DESC(debug_legacy_dish_switch,
+               "Enable timing analysis for Dish Network legacy switches");
+
+module_param(debug, int, 0644);
+MODULE_PARM_DESC(debug, "Turn on/off frontend debugging (default:off).");
+
+MODULE_DESCRIPTION("ST STV0288 DVB Demodulator driver");
+MODULE_AUTHOR("Georg Acher, Bob Liu, Igor liplianin");
+MODULE_LICENSE("GPL");
+
diff --git a/drivers/media/dvb/frontends/stv0288.h b/drivers/media/dvb/frontends/stv0288.h
new file mode 100644 (file)
index 0000000..f2b53db
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+       Driver for ST STV0288 demodulator
+
+       Copyright (C) 2006 Georg Acher, BayCom GmbH, acher (at) baycom (dot) de
+               for Reel Multimedia
+       Copyright (C) 2008 TurboSight.com, <bob@turbosight.com>
+       Copyright (C) 2008 Igor M. Liplianin <liplianin@me.by>
+               Removed stb6000 specific tuner code and revised some
+               procedures.
+
+       This program is free software; you can redistribute it and/or modify
+       it under the terms of the GNU General Public License as published by
+       the Free Software Foundation; either version 2 of the License, or
+       (at your option) any later version.
+
+       This program is distributed in the hope that it will be useful,
+       but WITHOUT ANY WARRANTY; without even the implied warranty of
+       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+       GNU General Public License for more details.
+
+       You should have received a copy of the GNU General Public License
+       along with this program; if not, write to the Free Software
+       Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+
+*/
+
+#ifndef STV0288_H
+#define STV0288_H
+
+#include <linux/dvb/frontend.h>
+#include "dvb_frontend.h"
+
+struct stv0288_config {
+       /* the demodulator's i2c address */
+       u8 demod_address;
+
+       u8* inittab;
+
+       /* minimum delay before retuning */
+       int min_delay_ms;
+
+       int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
+};
+
+#if defined(CONFIG_DVB_STV0288) || (defined(CONFIG_DVB_STV0288_MODULE) && \
+                                                       defined(MODULE))
+extern struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
+                                          struct i2c_adapter *i2c);
+#else
+static inline struct dvb_frontend *stv0288_attach(const struct stv0288_config *config,
+                                          struct i2c_adapter *i2c)
+{
+       printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
+       return NULL;
+}
+#endif /* CONFIG_DVB_STV0288 */
+
+static inline int stv0288_writereg(struct dvb_frontend *fe, u8 reg, u8 val)
+{
+       int r = 0;
+       u8 buf[] = { reg, val };
+       if (fe->ops.write)
+               r = fe->ops.write(fe, buf, 2);
+       return r;
+}
+
+#endif /* STV0288_H */
index 35435bef8e7992af4e1e8648a8c408b0f2d62f18..6c1cb1973c6e09c90010a7ec0167a9e50ae5b23e 100644 (file)
@@ -559,6 +559,8 @@ static int stv0299_set_frontend(struct dvb_frontend* fe, struct dvb_frontend_par
        int invval = 0;
 
        dprintk ("%s : FE_SET_FRONTEND\n", __func__);
+       if (state->config->set_ts_params)
+               state->config->set_ts_params(fe, 0);
 
        // set the inversion
        if (p->inversion == INVERSION_OFF) invval = 0;
index 3282f43022f5da37d2681e34a20c235e94828176..0fd96e22b650abec41ab65692770a8238d7c43c9 100644 (file)
@@ -89,15 +89,18 @@ struct stv0299_config
        int min_delay_ms;
 
        /* Set the symbol rate */
-       int (*set_symbol_rate)(struct dvb_frontend* fe, u32 srate, u32 ratio);
+       int (*set_symbol_rate)(struct dvb_frontend *fe, u32 srate, u32 ratio);
+
+       /* Set device param to start dma */
+       int (*set_ts_params)(struct dvb_frontend *fe, int is_punctured);
 };
 
 #if defined(CONFIG_DVB_STV0299) || (defined(CONFIG_DVB_STV0299_MODULE) && defined(MODULE))
-extern struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
-                                          struct i2c_adapteri2c);
+extern struct dvb_frontend *stv0299_attach(const struct stv0299_config *config,
+                                          struct i2c_adapter *i2c);
 #else
-static inline struct dvb_frontend* stv0299_attach(const struct stv0299_config* config,
-                                          struct i2c_adapteri2c)
+static inline struct dvb_frontend *stv0299_attach(const struct stv0299_config *config,
+                                          struct i2c_adapter *i2c)
 {
        printk(KERN_WARNING "%s: driver disabled by Kconfig\n", __func__);
        return NULL;
diff --git a/drivers/media/dvb/frontends/tdhd1.h b/drivers/media/dvb/frontends/tdhd1.h
new file mode 100644 (file)
index 0000000..51f1706
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * tdhd1.h - ALPS TDHD1-204A tuner support
+ *
+ * Copyright (C) 2008 Oliver Endriss <o.endriss@gmx.de>
+ *
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Or, point your browser to http://www.gnu.org/copyleft/gpl.html
+ *
+ *
+ * The project's page is at http://www.linuxtv.org
+ */
+
+#ifndef TDHD1_H
+#define TDHD1_H
+
+#include "tda1004x.h"
+
+static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name);
+
+static struct tda1004x_config alps_tdhd1_204a_config = {
+       .demod_address = 0x8,
+       .invert = 1,
+       .invert_oclk = 0,
+       .xtal_freq = TDA10046_XTAL_4M,
+       .agc_config = TDA10046_AGC_DEFAULT,
+       .if_freq = TDA10046_FREQ_3617,
+       .request_firmware = alps_tdhd1_204_request_firmware
+};
+
+static int alps_tdhd1_204a_tuner_set_params(struct dvb_frontend *fe, struct dvb_frontend_parameters *params)
+{
+       struct i2c_adapter *i2c = fe->tuner_priv;
+       u8 data[4];
+       struct i2c_msg msg = { .addr = 0x61, .flags = 0, .buf = data, .len = sizeof(data) };
+       u32 div;
+
+       div = (params->frequency + 36166666) / 166666;
+
+       data[0] = (div >> 8) & 0x7f;
+       data[1] = div & 0xff;
+       data[2] = 0x85;
+
+       if (params->frequency >= 174000000 && params->frequency <= 230000000)
+               data[3] = 0x02;
+       else if (params->frequency >= 470000000 && params->frequency <= 823000000)
+               data[3] = 0x0C;
+       else if (params->frequency > 823000000 && params->frequency <= 862000000)
+               data[3] = 0x8C;
+       else
+               return -EINVAL;
+
+       if (fe->ops.i2c_gate_ctrl)
+               fe->ops.i2c_gate_ctrl(fe, 1);
+       if (i2c_transfer(i2c, &msg, 1) != 1)
+               return -EIO;
+
+       return 0;
+}
+
+#endif /* TDHD1_H */
index 41b5a988b619fb8016485a7e50e512c1a66b9356..867027ceab3e71d29ce43b3944104043670eeb99 100644 (file)
@@ -86,6 +86,7 @@ config DVB_BUDGET
        select DVB_TDA10086 if !DVB_FE_CUSTOMISE
        select DVB_TDA826X if !DVB_FE_CUSTOMISE
        select DVB_LNBP21 if !DVB_FE_CUSTOMISE
+       select DVB_TDA1004X if !DVB_FE_CUSTOMISE
        help
          Support for simple SAA7146 based DVB cards (so called Budget-
          or Nova-PCI cards) without onboard MPEG2 decoder, and without
index 0777e8f9544ba66d63402a7f7bc5facd2a73c08c..c7c770c2898825c8a06c65400b880ea817c90cdc 100644 (file)
@@ -88,6 +88,7 @@ static int budgetpatch;
 static int wss_cfg_4_3 = 0x4008;
 static int wss_cfg_16_9 = 0x0007;
 static int tv_standard;
+static int full_ts;
 
 module_param_named(debug, av7110_debug, int, 0644);
 MODULE_PARM_DESC(debug, "debug level (bitmask, default 0)");
@@ -106,6 +107,8 @@ module_param(volume, int, 0444);
 MODULE_PARM_DESC(volume, "initial volume: default 255 (range 0-255)");
 module_param(budgetpatch, int, 0444);
 MODULE_PARM_DESC(budgetpatch, "use budget-patch hardware modification: default 0 (0 no, 1 autodetect, 2 always)");
+module_param(full_ts, int, 0444);
+MODULE_PARM_DESC(full_ts, "enable code for full-ts hardware modification: 0 disable (default), 1 enable");
 module_param(wss_cfg_4_3, int, 0444);
 MODULE_PARM_DESC(wss_cfg_4_3, "WSS 4:3 - default 0x4008 - bit 15: disable, 14: burst mode, 13..0: wss data");
 module_param(wss_cfg_16_9, int, 0444);
@@ -116,6 +119,8 @@ MODULE_PARM_DESC(tv_standard, "TV standard: 0 PAL (default), 1 NTSC");
 DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 
 static void restart_feeds(struct av7110 *av7110);
+static int budget_start_feed(struct dvb_demux_feed *feed);
+static int budget_stop_feed(struct dvb_demux_feed *feed);
 
 static int av7110_num;
 
@@ -376,9 +381,9 @@ static inline void start_debi_dma(struct av7110 *av7110, int dir,
                irdebi(av7110, DEBISWAB, addr, 0, len);
 }
 
-static void debiirq(unsigned long data)
+static void debiirq(unsigned long cookie)
 {
-       struct av7110 *av7110 = (struct av7110 *) data;
+       struct av7110 *av7110 = (struct av7110 *)cookie;
        int type = av7110->debitype;
        int handle = (type >> 8) & 0x1f;
        unsigned int xfer = 0;
@@ -487,9 +492,9 @@ debi_done:
 }
 
 /* irq from av7110 firmware writing the mailbox register in the DPRAM */
-static void gpioirq(unsigned long data)
+static void gpioirq(unsigned long cookie)
 {
-       struct av7110 *av7110 = (struct av7110 *) data;
+       struct av7110 *av7110 = (struct av7110 *)cookie;
        u32 rxbuf, txbuf;
        int len;
 
@@ -806,6 +811,9 @@ static int StartHWFilter(struct dvb_demux_filter *dvbdmxfilter)
 
        dprintk(4, "%p\n", av7110);
 
+       if (av7110->full_ts)
+               return 0;
+
        if (dvbdmxfilter->type == DMX_TYPE_SEC) {
                if (hw_sections) {
                        buf[4] = (dvbdmxfilter->filter.filter_value[0] << 8) |
@@ -854,6 +862,9 @@ static int StopHWFilter(struct dvb_demux_filter *dvbdmxfilter)
 
        dprintk(4, "%p\n", av7110);
 
+       if (av7110->full_ts)
+               return 0;
+
        handle = dvbdmxfilter->hw_handle;
        if (handle >= 32) {
                printk("%s tried to stop invalid filter %04x, filter type = %x\n",
@@ -913,7 +924,7 @@ static int dvb_feed_start_pid(struct dvb_demux_feed *dvbdmxfeed)
                                return ret;
                }
 
-       if ((dvbdmxfeed->ts_type & TS_PACKET)) {
+       if ((dvbdmxfeed->ts_type & TS_PACKET) && !av7110->full_ts) {
                if (dvbdmxfeed->pes_type == 0 && !(dvbdmx->pids[0] & 0x8000))
                        ret = av7110_av_start_record(av7110, RP_AUDIO, dvbdmxfeed);
                if (dvbdmxfeed->pes_type == 1 && !(dvbdmx->pids[1] & 0x8000))
@@ -974,7 +985,7 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
        if (!demux->dmx.frontend)
                return -EINVAL;
 
-       if (feed->pid > 0x1fff)
+       if (!av7110->full_ts && feed->pid > 0x1fff)
                return -EINVAL;
 
        if (feed->type == DMX_TYPE_TS) {
@@ -1003,7 +1014,12 @@ static int av7110_start_feed(struct dvb_demux_feed *feed)
                }
        }
 
-       else if (feed->type == DMX_TYPE_SEC) {
+       if (av7110->full_ts) {
+               budget_start_feed(feed);
+               return ret;
+       }
+
+       if (feed->type == DMX_TYPE_SEC) {
                int i;
 
                for (i = 0; i < demux->filternum; i++) {
@@ -1050,7 +1066,12 @@ static int av7110_stop_feed(struct dvb_demux_feed *feed)
                                ret = StopHWFilter(feed->filter);
        }
 
-       if (!ret && feed->type == DMX_TYPE_SEC) {
+       if (av7110->full_ts) {
+               budget_stop_feed(feed);
+               return ret;
+       }
+
+       if (feed->type == DMX_TYPE_SEC) {
                for (i = 0; i<demux->filternum; i++) {
                        if (demux->filter[i].state == DMX_STATE_GO &&
                            demux->filter[i].filter.parent == &feed->feed.sec) {
@@ -1074,6 +1095,7 @@ static void restart_feeds(struct av7110 *av7110)
        struct dvb_demux *dvbdmx = &av7110->demux;
        struct dvb_demux_feed *feed;
        int mode;
+       int feeding;
        int i, j;
 
        dprintk(4, "%p\n", av7110);
@@ -1082,6 +1104,8 @@ static void restart_feeds(struct av7110 *av7110)
        av7110->playing = 0;
        av7110->rec_mode = 0;
 
+       feeding = av7110->feeding1; /* full_ts mod */
+
        for (i = 0; i < dvbdmx->feednum; i++) {
                feed = &dvbdmx->feed[i];
                if (feed->state == DMX_STATE_GO) {
@@ -1099,6 +1123,8 @@ static void restart_feeds(struct av7110 *av7110)
                }
        }
 
+       av7110->feeding1 = feeding; /* full_ts mod */
+
        if (mode)
                av7110_av_start_play(av7110, mode);
 }
@@ -1197,8 +1223,9 @@ static int start_ts_capture(struct av7110 *budget)
 
        if (budget->feeding1)
                return ++budget->feeding1;
-       memset(budget->grabbing, 0x00, TS_HEIGHT * TS_WIDTH);
+       memset(budget->grabbing, 0x00, TS_BUFLEN);
        budget->ttbp = 0;
+       SAA7146_ISR_CLEAR(budget->dev, MASK_10);  /* VPE */
        SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
        saa7146_write(budget->dev, MC1, (MASK_04 | MASK_20)); /* DMA3 on */
        return ++budget->feeding1;
@@ -1233,18 +1260,14 @@ static int budget_stop_feed(struct dvb_demux_feed *feed)
        return status;
 }
 
-static void vpeirq(unsigned long data)
+static void vpeirq(unsigned long cookie)
 {
-       struct av7110 *budget = (struct av7110 *) data;
+       struct av7110 *budget = (struct av7110 *)cookie;
        u8 *mem = (u8 *) (budget->grabbing);
        u32 olddma = budget->ttbp;
        u32 newdma = saa7146_read(budget->dev, PCI_VDP3);
+       struct dvb_demux *demux = budget->full_ts ? &budget->demux : &budget->demux1;
 
-       if (!budgetpatch) {
-               printk("av7110.c: vpeirq() called while budgetpatch disabled!"
-                      " check saa7146 IER register\n");
-               BUG();
-       }
        /* nearest lower position divisible by 188 */
        newdma -= newdma % 188;
 
@@ -1268,11 +1291,11 @@ static void vpeirq(unsigned long data)
 
        if (newdma > olddma)
                /* no wraparound, dump olddma..newdma */
-               dvb_dmx_swfilter_packets(&budget->demux1, mem + olddma, (newdma - olddma) / 188);
+               dvb_dmx_swfilter_packets(demux, mem + olddma, (newdma - olddma) / 188);
        else {
                /* wraparound, dump olddma..buflen and 0..newdma */
-               dvb_dmx_swfilter_packets(&budget->demux1, mem + olddma, (TS_BUFLEN - olddma) / 188);
-               dvb_dmx_swfilter_packets(&budget->demux1, mem, newdma / 188);
+               dvb_dmx_swfilter_packets(demux, mem + olddma, (TS_BUFLEN - olddma) / 188);
+               dvb_dmx_swfilter_packets(demux, mem, newdma / 188);
        }
 }
 
@@ -1294,8 +1317,8 @@ static int av7110_register(struct av7110 *av7110)
        for (i = 0; i < 32; i++)
                av7110->handle2filter[i] = NULL;
 
-       dvbdemux->filternum = 32;
-       dvbdemux->feednum = 32;
+       dvbdemux->filternum = (av7110->full_ts) ? 256 : 32;
+       dvbdemux->feednum = (av7110->full_ts) ? 256 : 32;
        dvbdemux->start_feed = av7110_start_feed;
        dvbdemux->stop_feed = av7110_stop_feed;
        dvbdemux->write_to_decoder = av7110_write_to_decoder;
@@ -1305,7 +1328,7 @@ static int av7110_register(struct av7110 *av7110)
        dvb_dmx_init(&av7110->demux);
        av7110->demux.dmx.get_stc = dvb_get_stc;
 
-       av7110->dmxdev.filternum = 32;
+       av7110->dmxdev.filternum = (av7110->full_ts) ? 256 : 32;
        av7110->dmxdev.demux = &dvbdemux->dmx;
        av7110->dmxdev.capabilities = 0;
 
@@ -1422,7 +1445,6 @@ int i2c_writereg(struct av7110 *av7110, u8 id, u8 reg, u8 val)
        return i2c_transfer(&av7110->i2c_adap, &msgs, 1);
 }
 
-#if 0
 u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg)
 {
        u8 mm1[] = {0x00};
@@ -1439,7 +1461,6 @@ u8 i2c_readreg(struct av7110 *av7110, u8 id, u8 reg)
 
        return mm2[0];
 }
-#endif
 
 /****************************************************************************
  * INITIALIZATION
@@ -2256,7 +2277,7 @@ static int frontend_init(struct av7110 *av7110)
        if (!av7110->fe) {
                /* FIXME: propagate the failure code from the lower layers */
                ret = -ENOMEM;
-               printk("dvb-ttpci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+               printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       av7110->dev->pci->vendor,
                       av7110->dev->pci->device,
                       av7110->dev->pci->subsystem_vendor,
@@ -2484,7 +2505,47 @@ static int __devinit av7110_attach(struct saa7146_dev* dev,
                               av7110->dvb_adapter.proposed_mac);
        ret = -ENOMEM;
 
-       if (budgetpatch) {
+       /* full-ts mod? */
+       if (full_ts)
+               av7110->full_ts = true;
+
+       /* check for full-ts flag in eeprom */
+       if (i2c_readreg(av7110, 0xaa, 0) == 0x4f && i2c_readreg(av7110, 0xaa, 1) == 0x45) {
+               u8 flags = i2c_readreg(av7110, 0xaa, 2);
+               if (flags != 0xff && (flags & 0x01))
+                       av7110->full_ts = true;
+       }
+
+       if (av7110->full_ts) {
+               printk(KERN_INFO "dvb-ttpci: full-ts mode enabled for saa7146 port B\n");
+               spin_lock_init(&av7110->feedlock1);
+               av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
+                                                                &av7110->pt);
+               if (!av7110->grabbing)
+                       goto err_i2c_del_3;
+
+               saa7146_write(dev, DD1_STREAM_B, 0x00000000);
+               saa7146_write(dev, MC2, (MASK_10 | MASK_26));
+
+               saa7146_write(dev, DD1_INIT, 0x00000600);
+               saa7146_write(dev, MC2, (MASK_09 | MASK_25 | MASK_10 | MASK_26));
+
+               saa7146_write(dev, BRS_CTRL, 0x60000000);
+               saa7146_write(dev, MC2, MASK_08 | MASK_24);
+
+               /* dma3 */
+               saa7146_write(dev, PCI_BT_V1, 0x001c0000 | (saa7146_read(dev, PCI_BT_V1) & ~0x001f0000));
+               saa7146_write(dev, BASE_ODD3, 0);
+               saa7146_write(dev, BASE_EVEN3, 0);
+               saa7146_write(dev, PROT_ADDR3, TS_WIDTH * TS_HEIGHT);
+               saa7146_write(dev, PITCH3, TS_WIDTH);
+               saa7146_write(dev, BASE_PAGE3, av7110->pt.dma | ME1 | 0x90);
+               saa7146_write(dev, NUM_LINE_BYTE3, (TS_HEIGHT << 16) | TS_WIDTH);
+               saa7146_write(dev, MC2, MASK_04 | MASK_20);
+
+               tasklet_init(&av7110->vpe_tasklet, vpeirq, (unsigned long) av7110);
+
+       } else if (budgetpatch) {
                spin_lock_init(&av7110->feedlock1);
                av7110->grabbing = saa7146_vmalloc_build_pgtable(pdev, length,
                                                                 &av7110->pt);
@@ -2710,11 +2771,13 @@ static int __devexit av7110_detach(struct saa7146_dev* saa)
 #if defined(CONFIG_INPUT_EVDEV) || defined(CONFIG_INPUT_EVDEV_MODULE)
        av7110_ir_exit(av7110);
 #endif
-       if (budgetpatch) {
-               /* Disable RPS1 */
-               saa7146_write(saa, MC1, MASK_29);
-               /* VSYNC LOW (inactive) */
-               saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
+       if (budgetpatch || av7110->full_ts) {
+               if (budgetpatch) {
+                       /* Disable RPS1 */
+                       saa7146_write(saa, MC1, MASK_29);
+                       /* VSYNC LOW (inactive) */
+                       saa7146_setgpio(saa, 3, SAA7146_GPIO_OUTLO);
+               }
                saa7146_write(saa, MC1, MASK_20);       /* DMA3 off */
                SAA7146_IER_DISABLE(saa, MASK_10);
                SAA7146_ISR_CLEAR(saa, MASK_10);
@@ -2794,7 +2857,7 @@ static void av7110_irq(struct saa7146_dev* dev, u32 *isr)
                tasklet_schedule(&av7110->gpio_tasklet);
        }
 
-       if ((*isr & MASK_10) && budgetpatch)
+       if (*isr & MASK_10)
                tasklet_schedule(&av7110->vpe_tasklet);
 }
 
index 55f23ddcb994e259fa56fe45f646019bf7e916da..d85b8512ac307cb2bfa59f3d695036a1a6a35515 100644 (file)
@@ -192,6 +192,7 @@ struct av7110 {
        unsigned char           *grabbing;
        struct saa7146_pgtable  pt;
        struct tasklet_struct   vpe_tasklet;
+       bool                    full_ts;
 
        int                     fe_synced;
        struct mutex            pid_mutex;
index 184647ad1c7c041fb5aa890c4b9cadbb6c979571..bdc62acf2099ea431f5303f1336d6e2a78902bba 100644 (file)
@@ -788,6 +788,9 @@ int av7110_write_to_decoder(struct dvb_demux_feed *feed, const u8 *buf, size_t l
 
        dprintk(2, "av7110:%p, \n", av7110);
 
+       if (av7110->full_ts && demux->dmx.frontend->source != DMX_MEMORY_FE)
+               return 0;
+
        switch (feed->pes_type) {
        case 0:
                if (av7110->audiostate.stream_source == AUDIO_SOURCE_MEMORY)
index b7d1f2f18d3a45e1939b61e69ea1dd9ff6448cc9..1032ea77837e356766cb27aaa2bb3f3295688b84 100644 (file)
@@ -57,6 +57,8 @@
 #define SLOTSTATUS_READY        8
 #define SLOTSTATUS_OCCUPIED     (SLOTSTATUS_PRESENT|SLOTSTATUS_RESET|SLOTSTATUS_READY)
 
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
 struct budget_av {
        struct budget budget;
        struct video_device *vd;
@@ -1049,7 +1051,7 @@ static void frontend_init(struct budget_av *budget_av)
 
        if (fe == NULL) {
                printk(KERN_ERR "budget-av: A frontend driver was not found "
-                               "for device %04x/%04x subsystem %04x/%04x\n",
+                               "for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       saa->pci->vendor,
                       saa->pci->device,
                       saa->pci->subsystem_vendor,
@@ -1127,7 +1129,9 @@ static int budget_av_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 
        dev->ext_priv = budget_av;
 
-       if ((err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE))) {
+       err = ttpci_budget_init(&budget_av->budget, dev, info, THIS_MODULE,
+                               adapter_nr);
+       if (err) {
                kfree(budget_av);
                return err;
        }
index 060e7c7853266f9a2ae6fd514748a6e10b67182c..0a5aad45435d2c0bb37209b8fb2341513f38e21e 100644 (file)
@@ -92,6 +92,8 @@ static int ir_debug;
 module_param(ir_debug, int, 0644);
 MODULE_PARM_DESC(ir_debug, "enable debugging information for IR decoding");
 
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
 struct budget_ci_ir {
        struct input_dev *dev;
        struct tasklet_struct msp430_irq_tasklet;
@@ -1153,7 +1155,7 @@ static void frontend_init(struct budget_ci *budget_ci)
        }
 
        if (budget_ci->budget.dvb_frontend == NULL) {
-               printk("budget-ci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+               printk("budget-ci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       budget_ci->budget.dev->pci->vendor,
                       budget_ci->budget.dev->pci->device,
                       budget_ci->budget.dev->pci->subsystem_vendor,
@@ -1183,7 +1185,8 @@ static int budget_ci_attach(struct saa7146_dev *dev, struct saa7146_pci_extensio
 
        dev->ext_priv = budget_ci;
 
-       err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE);
+       err = ttpci_budget_init(&budget_ci->budget, dev, info, THIS_MODULE,
+                               adapter_nr);
        if (err)
                goto out2;
 
index 6f4ddb643fee12482ae84ab0f76939a4fd91999c..ba18e56d5f11295bb8bb79b9ce7d4e5d4a608b4b 100644 (file)
@@ -57,8 +57,6 @@ module_param_named(bufsize, dma_buffer_size, int, 0444);
 MODULE_PARM_DESC(debug, "Turn on/off budget debugging (default:off).");
 MODULE_PARM_DESC(bufsize, "DMA buffer size in KB, default: 188, min: 188, max: 1410 (Activy: 564)");
 
-DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
-
 /****************************************************************************
  * TT budget / WinTV Nova
  ****************************************************************************/
@@ -411,7 +409,7 @@ static void budget_unregister(struct budget *budget)
 
 int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
                      struct saa7146_pci_extension_data *info,
-                     struct module *owner)
+                     struct module *owner, short *adapter_nums)
 {
        int ret = 0;
        struct budget_info *bi = info->ext_priv;
@@ -474,7 +472,7 @@ int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
        printk("%s: dma buffer size %u\n", budget->dev->name, budget->buffer_size);
 
        ret = dvb_register_adapter(&budget->dvb_adapter, budget->card->name,
-                                  owner, &budget->dev->pci->dev, adapter_nr);
+                                  owner, &budget->dev->pci->dev, adapter_nums);
        if (ret < 0)
                return ret;
 
index aa5ed4ef19f24cfcf68eb8282cb369317c9478d3..60136688a9a4c07dd104fe58ee641b46afd5000c 100644 (file)
@@ -39,6 +39,8 @@
 
 #include "bsru6.h"
 
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
 #define budget_patch budget
 
 static struct saa7146_extension budget_extension;
@@ -360,7 +362,7 @@ static void frontend_init(struct budget_patch* budget)
        }
 
        if (budget->dvb_frontend == NULL) {
-               printk("dvb-ttpci: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+               printk("dvb-ttpci: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       budget->dev->pci->vendor,
                       budget->dev->pci->device,
                       budget->dev->pci->subsystem_vendor,
@@ -592,8 +594,9 @@ static int budget_patch_attach (struct saa7146_dev* dev, struct saa7146_pci_exte
 
        dprintk(2, "budget: %p\n", budget);
 
-       if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
-               kfree (budget);
+       err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
+       if (err) {
+               kfree(budget);
                return err;
        }
 
index f0068996ac07eb907e4042ed01be74e5c0bdd462..1638e1d9f538011e49a193b6ce52dbf86464d274 100644 (file)
 #include "lnbp21.h"
 #include "bsru6.h"
 #include "bsbe1.h"
+#include "tdhd1.h"
 
 static int diseqc_method;
 module_param(diseqc_method, int, 0444);
 MODULE_PARM_DESC(diseqc_method, "Select DiSEqC method for subsystem id 13c2:1003, 0: default, 1: more reliable (for newer revisions only)");
 
+DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
+
 static void Set22K (struct budget *budget, int state)
 {
        struct saa7146_dev *dev=budget->dev;
@@ -390,6 +393,13 @@ static struct stv0299_config alps_bsbe1_config_activy = {
        .set_symbol_rate = alps_bsbe1_set_symbol_rate,
 };
 
+static int alps_tdhd1_204_request_firmware(struct dvb_frontend *fe, const struct firmware **fw, char *name)
+{
+       struct budget *budget = (struct budget *)fe->dvb->priv;
+
+       return request_firmware(fw, name, &budget->dev->pci->dev);
+}
+
 
 static int i2c_readreg(struct i2c_adapter *i2c, u8 adr, u8 reg)
 {
@@ -511,6 +521,14 @@ static void frontend_init(struct budget *budget)
                }
                break;
 
+       case 0x5f60: /* Fujitsu Siemens Activy Budget-T PCI rev AL (tda10046/ALPS TDHD1-204A) */
+               budget->dvb_frontend = dvb_attach(tda10046_attach, &alps_tdhd1_204a_config, &budget->i2c_adap);
+               if (budget->dvb_frontend) {
+                       budget->dvb_frontend->ops.tuner_ops.set_params = alps_tdhd1_204a_tuner_set_params;
+                       budget->dvb_frontend->tuner_priv = &budget->i2c_adap;
+               }
+               break;
+
        case 0x5f61: /* Fujitsu Siemens Activy Budget-T PCI rev GR (L64781/Grundig 29504-401(tsa5060)) */
                budget->dvb_frontend = dvb_attach(l64781_attach, &grundig_29504_401_config_activy, &budget->i2c_adap);
                if (budget->dvb_frontend) {
@@ -550,7 +568,7 @@ static void frontend_init(struct budget *budget)
        }
 
        if (budget->dvb_frontend == NULL) {
-               printk("budget: A frontend driver was not found for device %04x/%04x subsystem %04x/%04x\n",
+               printk("budget: A frontend driver was not found for device [%04x:%04x] subsystem [%04x:%04x]\n",
                       budget->dev->pci->vendor,
                       budget->dev->pci->device,
                       budget->dev->pci->subsystem_vendor,
@@ -582,7 +600,8 @@ static int budget_attach (struct saa7146_dev* dev, struct saa7146_pci_extension_
 
        dev->ext_priv = budget;
 
-       if ((err = ttpci_budget_init (budget, dev, info, THIS_MODULE))) {
+       err = ttpci_budget_init(budget, dev, info, THIS_MODULE, adapter_nr);
+       if (err) {
                printk("==> failed\n");
                kfree (budget);
                return err;
@@ -624,6 +643,7 @@ MAKE_BUDGET_INFO(ttbs1401, "TT-Budget-S-1401 PCI", BUDGET_TT);
 MAKE_BUDGET_INFO(fsacs0, "Fujitsu Siemens Activy Budget-S PCI (rev GR/grundig frontend)", BUDGET_FS_ACTIVY);
 MAKE_BUDGET_INFO(fsacs1, "Fujitsu Siemens Activy Budget-S PCI (rev AL/alps frontend)", BUDGET_FS_ACTIVY);
 MAKE_BUDGET_INFO(fsact,         "Fujitsu Siemens Activy Budget-T PCI (rev GR/Grundig frontend)", BUDGET_FS_ACTIVY);
+MAKE_BUDGET_INFO(fsact1, "Fujitsu Siemens Activy Budget-T PCI (rev AL/ALPS TDHD1-204A)", BUDGET_FS_ACTIVY);
 
 static struct pci_device_id pci_tbl[] = {
        MAKE_EXTENSION_PCI(ttbs,  0x13c2, 0x1003),
@@ -634,6 +654,7 @@ static struct pci_device_id pci_tbl[] = {
        MAKE_EXTENSION_PCI(ttbs1401, 0x13c2, 0x1018),
        MAKE_EXTENSION_PCI(fsacs1,0x1131, 0x4f60),
        MAKE_EXTENSION_PCI(fsacs0,0x1131, 0x4f61),
+       MAKE_EXTENSION_PCI(fsact1, 0x1131, 0x5f60),
        MAKE_EXTENSION_PCI(fsact, 0x1131, 0x5f61),
        {
                .vendor    = 0,
index dd450b739bff9bb21d56c2bc8d2dae3d6c4dab54..86435bf162601661381d33f323d1e0176cac4774 100644 (file)
@@ -109,7 +109,7 @@ static struct saa7146_pci_extension_data x_var = { \
 
 extern int ttpci_budget_init(struct budget *budget, struct saa7146_dev *dev,
                             struct saa7146_pci_extension_data *info,
-                            struct module *owner);
+                            struct module *owner, short *adapter_nums);
 extern void ttpci_budget_init_hooks(struct budget *budget);
 extern int ttpci_budget_deinit(struct budget *budget);
 extern void ttpci_budget_irq10_handler(struct saa7146_dev *dev, u32 * isr);
index e6c9cd2e3b94514784a4ee423553e2f94987ca35..66ab0c6e9783da4f8a99cca3699c3a32dd51ec58 100644 (file)
@@ -1614,7 +1614,7 @@ static void frontend_init(struct ttusb* ttusb)
        }
 
        if (ttusb->fe == NULL) {
-               printk("dvb-ttusb-budget: A frontend driver was not found for device %04x/%04x\n",
+               printk("dvb-ttusb-budget: A frontend driver was not found for device [%04x:%04x]\n",
                       le16_to_cpu(ttusb->dev->descriptor.idVendor),
                       le16_to_cpu(ttusb->dev->descriptor.idProduct));
        } else {
index de5829b863fd26edd62923cf6168bf9e883bb6ef..ab33fec8a19fbcef75855786f5dadc44c2bf721f 100644 (file)
@@ -1665,7 +1665,7 @@ static int ttusb_dec_probe(struct usb_interface *intf,
        }
 
        if (dec->fe == NULL) {
-               printk("dvb-ttusb-dec: A frontend driver was not found for device %04x/%04x\n",
+               printk("dvb-ttusb-dec: A frontend driver was not found for device [%04x:%04x]\n",
                       le16_to_cpu(dec->udev->descriptor.idVendor),
                       le16_to_cpu(dec->udev->descriptor.idProduct));
        } else {
index 443af24097f34118fe51c66aa7bb80aa12d17c1f..21260aad1e54684a46c82248dc0bee8681327c21 100644 (file)
@@ -38,7 +38,17 @@ struct ttusbdecfe_state {
 };
 
 
-static int ttusbdecfe_read_status(struct dvb_frontend* fe, fe_status_t* status)
+static int ttusbdecfe_dvbs_read_status(struct dvb_frontend *fe,
+       fe_status_t *status)
+{
+       *status = FE_HAS_SIGNAL | FE_HAS_VITERBI |
+               FE_HAS_SYNC | FE_HAS_CARRIER | FE_HAS_LOCK;
+       return 0;
+}
+
+
+static int ttusbdecfe_dvbt_read_status(struct dvb_frontend *fe,
+       fe_status_t *status)
 {
        struct ttusbdecfe_state* state = fe->demodulator_priv;
        u8 b[] = { 0x00, 0x00, 0x00, 0x00,
@@ -251,7 +261,7 @@ static struct dvb_frontend_ops ttusbdecfe_dvbt_ops = {
 
        .get_tune_settings = ttusbdecfe_dvbt_get_tune_settings,
 
-       .read_status = ttusbdecfe_read_status,
+       .read_status = ttusbdecfe_dvbt_read_status,
 };
 
 static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
@@ -273,7 +283,7 @@ static struct dvb_frontend_ops ttusbdecfe_dvbs_ops = {
 
        .set_frontend = ttusbdecfe_dvbs_set_frontend,
 
-       .read_status = ttusbdecfe_read_status,
+       .read_status = ttusbdecfe_dvbs_read_status,
 
        .diseqc_send_master_cmd = ttusbdecfe_dvbs_diseqc_send_master_cmd,
        .set_voltage = ttusbdecfe_dvbs_set_voltage,
index 1b41b3f77cf95c2b6f28394cf1eb378a2fefe0ec..e51d707e58d35aa7acc905cc0f017f07584be16b 100644 (file)
@@ -361,4 +361,16 @@ config USB_SI470X
          To compile this driver as a module, choose M here: the
          module will be called radio-silabs.
 
+config USB_MR800
+       tristate "AverMedia MR 800 USB FM radio support"
+       depends on USB && VIDEO_V4L2
+       ---help---
+         Say Y here if you want to connect this type of radio to your
+         computer's USB port. Note that the audio is not digital, and
+         you must connect the line out connector to a sound card or a
+         set of speakers.
+
+         To compile this driver as a module, choose M here: the
+         module will be called radio-mr800.
+
 endif # RADIO_ADAPTERS
index 7ca71ab96b43021d5edd3080f118b7fe2f072f44..240ec63cdafc490c88612dbc091742cfe714ff32 100644 (file)
@@ -18,5 +18,6 @@ obj-$(CONFIG_RADIO_TRUST) += radio-trust.o
 obj-$(CONFIG_RADIO_MAESTRO) += radio-maestro.o
 obj-$(CONFIG_USB_DSBR) += dsbr100.o
 obj-$(CONFIG_USB_SI470X) += radio-si470x.o
+obj-$(CONFIG_USB_MR800) += radio-mr800.o
 
 EXTRA_CFLAGS += -Isound
index 70c65a745923f088b96e2e8d0da59e3f7865ef25..66783fffe4c1c34dc0e57e9b32feb775c8da3fc2 100644 (file)
@@ -274,7 +274,7 @@ static int vidioc_querycap(struct file *file, void *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                struct v4l2_tuner *v)
 {
-       struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -306,7 +306,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        radio->curfreq = f->frequency;
        if (dsbr100_setfreq(radio, radio->curfreq)==-1)
@@ -317,7 +317,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = radio->curfreq;
@@ -342,7 +342,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -355,16 +355,20 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct dsbr100_device *radio = video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
                if (ctrl->value) {
-                       if (dsbr100_stop(radio)==-1)
+                       if (dsbr100_stop(radio) == -1) {
                                warn("Radio did not respond properly");
+                               return -EBUSY;
+                       }
                } else {
-                       if (dsbr100_start(radio)==-1)
+                       if (dsbr100_start(radio) == -1) {
                                warn("Radio did not respond properly");
+                               return -EBUSY;
+                       }
                }
                return 0;
        }
@@ -405,23 +409,26 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static int usb_dsbr100_open(struct inode *inode, struct file *file)
 {
-       struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
+       lock_kernel();
        radio->users = 1;
        radio->muted = 1;
 
        if (dsbr100_start(radio)<0) {
                warn("Radio did not start up properly");
                radio->users = 0;
+               unlock_kernel();
                return -EIO;
        }
        dsbr100_setfreq(radio, radio->curfreq);
+       unlock_kernel();
        return 0;
 }
 
 static int usb_dsbr100_close(struct inode *inode, struct file *file)
 {
-       struct dsbr100_device *radio=video_get_drvdata(video_devdata(file));
+       struct dsbr100_device *radio = video_drvdata(file);
 
        if (!radio)
                return -ENODEV;
@@ -507,7 +514,8 @@ static int usb_dsbr100_probe(struct usb_interface *intf,
 static int __init dsbr100_init(void)
 {
        int retval = usb_register(&usb_dsbr100_driver);
-       info(DRIVER_VERSION ":" DRIVER_DESC);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
        return retval;
 }
 
index 1f064f4b32df6945c0d20262471784ddb94f7204..9305e958fc665399e5dd7454d9b56f5939d76709 100644 (file)
@@ -51,6 +51,7 @@ static struct mutex lock;
 
 struct rt_device
 {
+       unsigned long in_use;
        int port;
        int curvol;
        unsigned long curfreq;
@@ -245,8 +246,7 @@ static int vidioc_querycap(struct file *file, void  *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -273,8 +273,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        rt->curfreq = f->frequency;
        rt_setfreq(rt, rt->curfreq);
@@ -284,8 +283,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = rt->curfreq;
@@ -310,8 +308,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -327,8 +324,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -378,10 +374,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct rt_device rtrack_unit;
 
+static int rtrack_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &rtrack_unit.in_use) ? -EBUSY : 0;
+}
+
+static int rtrack_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &rtrack_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations rtrack_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = rtrack_exclusive_open,
+       .release        = rtrack_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -408,6 +415,7 @@ static struct video_device rtrack_radio = {
        .name           = "RadioTrack radio",
        .fops           = &rtrack_fops,
        .ioctl_ops      = &rtrack_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init rtrack_init(void)
@@ -424,7 +432,7 @@ static int __init rtrack_init(void)
                return -EBUSY;
        }
 
-       rtrack_radio.priv=&rtrack_unit;
+       video_set_drvdata(&rtrack_radio, &rtrack_unit);
 
        if (video_register_device(&rtrack_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                release_region(io, 2);
index 628c689e3ffe1779c422bdbc11883207a15d7c9e..d78489573230c259086711245d35775af57ed94a 100644 (file)
@@ -70,6 +70,7 @@ static struct mutex lock;
 
 struct az_device
 {
+       unsigned long in_use;
        int curvol;
        unsigned long curfreq;
        int stereo;
@@ -195,8 +196,7 @@ static int vidioc_querycap (struct file *file, void  *priv,
 static int vidioc_g_tuner (struct file *file, void *priv,
                                struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct az_device *az = dev->priv;
+       struct az_device *az = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -264,8 +264,7 @@ static int vidioc_s_audio (struct file *file, void *priv,
 static int vidioc_s_frequency (struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct az_device *az = dev->priv;
+       struct az_device *az = video_drvdata(file);
 
        az->curfreq = f->frequency;
        az_setfreq(az, az->curfreq);
@@ -275,8 +274,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
 static int vidioc_g_frequency (struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct az_device *az = dev->priv;
+       struct az_device *az = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = az->curfreq;
@@ -302,8 +300,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
 static int vidioc_g_ctrl (struct file *file, void *priv,
                            struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct az_device *az = dev->priv;
+       struct az_device *az = video_drvdata(file);
 
        switch (ctrl->id) {
                case V4L2_CID_AUDIO_MUTE:
@@ -322,8 +319,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
 static int vidioc_s_ctrl (struct file *file, void *priv,
                            struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct az_device *az = dev->priv;
+       struct az_device *az = video_drvdata(file);
 
        switch (ctrl->id) {
                case V4L2_CID_AUDIO_MUTE:
@@ -342,10 +338,21 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
 
 static struct az_device aztech_unit;
 
+static int aztech_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &aztech_unit.in_use) ? -EBUSY : 0;
+}
+
+static int aztech_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &aztech_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations aztech_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = aztech_exclusive_open,
+       .release        = aztech_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -369,9 +376,10 @@ static const struct v4l2_ioctl_ops aztech_ioctl_ops = {
 };
 
 static struct video_device aztech_radio = {
-       .name               = "Aztech radio",
-       .fops               = &aztech_fops,
-       .ioctl_ops          = &aztech_ioctl_ops,
+       .name           = "Aztech radio",
+       .fops           = &aztech_fops,
+       .ioctl_ops      = &aztech_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 module_param_named(debug,aztech_radio.debug, int, 0644);
@@ -392,7 +400,7 @@ static int __init aztech_init(void)
        }
 
        mutex_init(&lock);
-       aztech_radio.priv=&aztech_unit;
+       video_set_drvdata(&aztech_radio, &aztech_unit);
 
        if (video_register_device(&aztech_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                release_region(io,2);
index 04c3698d32e4b77e3b28f81d104b0dcbe23dfe59..0490a1fa999db04d63a21def52448396b00dfa55 100644 (file)
@@ -589,6 +589,7 @@ static struct video_device cadet_radio = {
        .name           = "Cadet radio",
        .fops           = &cadet_fops,
        .ioctl_ops      = &cadet_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 #ifdef CONFIG_PNP
index 5cd7f032298d28e1af01a35342b9f332f8e9faa7..e15bee6d7cfcb874fedab31a35730af81a75b19b 100644 (file)
@@ -100,9 +100,8 @@ struct gemtek_pci_card {
        u8  mute;
 };
 
-static const char rcsid[] = "$Id: radio-gemtek-pci.c,v 1.1 2001/07/23 08:08:16 ted Exp ted $";
-
 static int nr_radio = -1;
+static unsigned long in_use;
 
 static inline u8 gemtek_pci_out( u16 value, u32 port )
 {
@@ -205,8 +204,7 @@ static int vidioc_querycap(struct file *file, void *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_pci_card *card = dev->priv;
+       struct gemtek_pci_card *card = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -233,8 +231,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_pci_card *card = dev->priv;
+       struct gemtek_pci_card *card = video_drvdata(file);
 
        if ( (f->frequency < GEMTEK_PCI_RANGE_LOW) ||
                        (f->frequency > GEMTEK_PCI_RANGE_HIGH) )
@@ -248,8 +245,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_pci_card *card = dev->priv;
+       struct gemtek_pci_card *card = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = card->current_frequency;
@@ -273,8 +269,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_pci_card *card = dev->priv;
+       struct gemtek_pci_card *card = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -293,8 +288,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_pci_card *card = dev->priv;
+       struct gemtek_pci_card *card = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -364,10 +358,21 @@ MODULE_DEVICE_TABLE( pci, gemtek_pci_id );
 
 static int mx = 1;
 
+static int gemtek_pci_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
+}
+
+static int gemtek_pci_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &in_use);
+       return 0;
+}
+
 static const struct file_operations gemtek_pci_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = gemtek_pci_exclusive_open,
+       .release        = gemtek_pci_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -391,9 +396,10 @@ static const struct v4l2_ioctl_ops gemtek_pci_ioctl_ops = {
 };
 
 static struct video_device vdev_template = {
-       .name          = "Gemtek PCI Radio",
-       .fops          = &gemtek_pci_fops,
-       .ioctl_ops     = &gemtek_pci_ioctl_ops,
+       .name           = "Gemtek PCI Radio",
+       .fops           = &gemtek_pci_fops,
+       .ioctl_ops      = &gemtek_pci_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci_device_id *pci_id )
@@ -431,7 +437,7 @@ static int __devinit gemtek_pci_probe( struct pci_dev *pci_dev, const struct pci
        }
 
        card->videodev = devradio;
-       devradio->priv = card;
+       video_set_drvdata(devradio, card);
        gemtek_pci_mute( card );
 
        printk( KERN_INFO "Gemtek PCI Radio (rev. %d) found at 0x%04x-0x%04x.\n",
index 0a0f956bb308387dc7c9334f150bef5b855448b9..d131a5d381287b0069d4e83dad2615feb115adf7 100644 (file)
@@ -57,6 +57,7 @@ static int shutdown   = 1;
 static int keepmuted   = 1;
 static int initmute    = 1;
 static int radio_nr    = -1;
+static unsigned long in_use;
 
 module_param(io, int, 0444);
 MODULE_PARM_DESC(io, "Force I/O port for the GemTek Radio card if automatic "
@@ -393,10 +394,21 @@ static struct v4l2_queryctrl radio_qctrl[] = {
        }
 };
 
+static int gemtek_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
+}
+
+static int gemtek_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &in_use);
+       return 0;
+}
+
 static const struct file_operations gemtek_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = gemtek_exclusive_open,
+       .release        = gemtek_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -447,8 +459,7 @@ static int vidioc_s_tuner(struct file *file, void *priv, struct v4l2_tuner *v)
 static int vidioc_s_frequency(struct file *file, void *priv,
                              struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_device *rt = dev->priv;
+       struct gemtek_device *rt = video_drvdata(file);
 
        gemtek_setfreq(rt, f->frequency);
 
@@ -458,8 +469,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                              struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_device *rt = dev->priv;
+       struct gemtek_device *rt = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = rt->lastfreq;
@@ -483,8 +493,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_device *rt = dev->priv;
+       struct gemtek_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -503,8 +512,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                         struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct gemtek_device *rt = dev->priv;
+       struct gemtek_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -569,9 +577,10 @@ static const struct v4l2_ioctl_ops gemtek_ioctl_ops = {
 };
 
 static struct video_device gemtek_radio = {
-       .name                   = "GemTek Radio card",
-       .fops                   = &gemtek_fops,
-       .ioctl_ops              = &gemtek_ioctl_ops,
+       .name           = "GemTek Radio card",
+       .fops           = &gemtek_fops,
+       .ioctl_ops      = &gemtek_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 /*
@@ -610,7 +619,7 @@ static int __init gemtek_init(void)
                return -EINVAL;
        }
 
-       gemtek_radio.priv = &gemtek_unit;
+       video_set_drvdata(&gemtek_radio, &gemtek_unit);
 
        if (video_register_device(&gemtek_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                release_region(io, 1);
index 9ef0a763eeb72a54570324a7b3112a549cdfdcb6..4bf4d007bcfa2b62db846c29f3c035831c5f0433 100644 (file)
@@ -75,7 +75,21 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 static int radio_nr = -1;
 module_param(radio_nr, int, 0);
 
+static unsigned long in_use;
+
 static int maestro_probe(struct pci_dev *pdev, const struct pci_device_id *ent);
+
+static int maestro_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
+}
+
+static int maestro_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &in_use);
+       return 0;
+}
+
 static void maestro_remove(struct pci_dev *pdev);
 
 static struct pci_device_id maestro_r_pci_tbl[] = {
@@ -98,8 +112,8 @@ static struct pci_driver maestro_r_driver = {
 
 static const struct file_operations maestro_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = maestro_exclusive_open,
+       .release        = maestro_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -196,8 +210,7 @@ static int vidioc_querycap(struct file *file, void  *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card = video_get_drvdata(dev);
+       struct radio_device *card = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -229,8 +242,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card = video_get_drvdata(dev);
+       struct radio_device *card = video_drvdata(file);
 
        if (f->frequency < FREQ_LO || f->frequency > FREQ_HI)
                return -EINVAL;
@@ -241,8 +253,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card = video_get_drvdata(dev);
+       struct radio_device *card = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = BITS2FREQ(radio_bits_get(card));
@@ -267,8 +278,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card = video_get_drvdata(dev);
+       struct radio_device *card = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -281,8 +291,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card = video_get_drvdata(dev);
+       struct radio_device *card = video_drvdata(file);
        register u16 io = card->io;
        register u16 omask = inw(io + IO_MASK);
 
@@ -374,6 +383,7 @@ static struct video_device maestro_radio = {
        .name           = "Maestro radio",
        .fops           = &maestro_fops,
        .ioctl_ops      = &maestro_ioctl_ops,
+       .release        = video_device_release,
 };
 
 static int __devinit maestro_probe(struct pci_dev *pdev,
index 0cc6fcb041fd9773c56088ed50de1406f8030a27..c777a17b00bc21c986b08b756080a995eeeb990e 100644 (file)
@@ -85,6 +85,7 @@ static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16 ;
 static int radio_nr = -1;
 module_param(radio_nr, int, 0);
 
+static unsigned long in_use;
 
 #define FREQ_LO                 50*16000
 #define FREQ_HI                150*16000
@@ -99,10 +100,21 @@ module_param(radio_nr, int, 0);
 #define BITS2FREQ(x)   ((x) * FREQ_STEP - FREQ_IF)
 
 
+static int maxiradio_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
+}
+
+static int maxiradio_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &in_use);
+       return 0;
+}
+
 static const struct file_operations maxiradio_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = maxiradio_exclusive_open,
+       .release        = maxiradio_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -219,8 +231,7 @@ static int vidioc_querycap (struct file *file, void  *priv,
 static int vidioc_g_tuner (struct file *file, void *priv,
                           struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card=dev->priv;
+       struct radio_device *card = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -290,8 +301,7 @@ static int vidioc_s_audio (struct file *file, void *priv,
 static int vidioc_s_frequency (struct file *file, void *priv,
                               struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card=dev->priv;
+       struct radio_device *card = video_drvdata(file);
 
        if (f->frequency < FREQ_LO || f->frequency > FREQ_HI) {
                dprintk(1, "radio freq (%d.%02d MHz) out of range (%d-%d)\n",
@@ -312,8 +322,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
 static int vidioc_g_frequency (struct file *file, void *priv,
                               struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card=dev->priv;
+       struct radio_device *card = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = card->freq;
@@ -343,8 +352,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
 static int vidioc_g_ctrl (struct file *file, void *priv,
                            struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card=dev->priv;
+       struct radio_device *card = video_drvdata(file);
 
        switch (ctrl->id) {
                case V4L2_CID_AUDIO_MUTE:
@@ -358,8 +366,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
 static int vidioc_s_ctrl (struct file *file, void *priv,
                          struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct radio_device *card=dev->priv;
+       struct radio_device *card = video_drvdata(file);
 
        switch (ctrl->id) {
                case V4L2_CID_AUDIO_MUTE:
@@ -390,9 +397,10 @@ static const struct v4l2_ioctl_ops maxiradio_ioctl_ops = {
 };
 
 static struct video_device maxiradio_radio = {
-       .name               = "Maxi Radio FM2000 radio",
-       .fops               = &maxiradio_fops,
-       .ioctl_ops          = &maxiradio_ioctl_ops,
+       .name           = "Maxi Radio FM2000 radio",
+       .fops           = &maxiradio_fops,
+       .ioctl_ops      = &maxiradio_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_device_id *ent)
@@ -408,7 +416,7 @@ static int __devinit maxiradio_init_one(struct pci_dev *pdev, const struct pci_d
 
        radio_unit.io = pci_resource_start(pdev, 0);
        mutex_init(&radio_unit.lock);
-       maxiradio_radio.priv = &radio_unit;
+       video_set_drvdata(&maxiradio_radio, &radio_unit);
 
        if (video_register_device(&maxiradio_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                printk("radio-maxiradio: can't register device!");
diff --git a/drivers/media/radio/radio-mr800.c b/drivers/media/radio/radio-mr800.c
new file mode 100644 (file)
index 0000000..a33717c
--- /dev/null
@@ -0,0 +1,628 @@
+/*
+ * A driver for the AverMedia MR 800 USB FM radio. This device plugs
+ * into both the USB and an analog audio input, so this thing
+ * only deals with initialization and frequency setting, the
+ * audio data has to be handled by a sound driver.
+ *
+ * Copyright (c) 2008 Alexey Klimov <klimov.linux@gmail.com>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+/*
+ * Big thanks to authors of dsbr100.c and radio-si470x.c
+ *
+ * When work was looked pretty good, i discover this:
+ * http://av-usbradio.sourceforge.net/index.php
+ * http://sourceforge.net/projects/av-usbradio/
+ * Latest release of theirs project was in 2005.
+ * Probably, this driver could be improved trough using their
+ * achievements (specifications given).
+ * So, we have smth to begin with.
+ *
+ * History:
+ * Version 0.01:       First working version.
+ *                     It's required to blacklist AverMedia USB Radio
+ *                     in usbhid/hid-quirks.c
+ *
+ * Many things to do:
+ *     - Correct power managment of device (suspend & resume)
+ *     - Make x86 independance (little-endian and big-endian stuff)
+ *     - Add code for scanning and smooth tuning
+ *     - Checked and add stereo&mono stuff
+ *     - Add code for sensitivity value
+ *     - Correct mistakes
+ *     - In Japan another FREQ_MIN and FREQ_MAX
+ */
+
+/* kernel includes */
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/input.h>
+#include <linux/videodev2.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+#include <linux/usb.h>
+#include <linux/version.h>     /* for KERNEL_VERSION MACRO */
+
+/* driver and module definitions */
+#define DRIVER_AUTHOR "Alexey Klimov <klimov.linux@gmail.com>"
+#define DRIVER_DESC "AverMedia MR 800 USB FM radio driver"
+#define DRIVER_VERSION "0.01"
+#define RADIO_VERSION KERNEL_VERSION(0, 0, 1)
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+
+#define USB_AMRADIO_VENDOR 0x07ca
+#define USB_AMRADIO_PRODUCT 0xb800
+
+/* Probably USB_TIMEOUT should be modified in module parameter */
+#define BUFFER_LENGTH 8
+#define USB_TIMEOUT 500
+
+/* Frequency limits in MHz -- these are European values.  For Japanese
+devices, that would be 76 and 91.  */
+#define FREQ_MIN  87.5
+#define FREQ_MAX 108.0
+#define FREQ_MUL 16000
+
+/* module parameter */
+static int radio_nr = -1;
+module_param(radio_nr, int, 0);
+MODULE_PARM_DESC(radio_nr, "Radio Nr");
+
+static struct v4l2_queryctrl radio_qctrl[] = {
+       {
+               .id            = V4L2_CID_AUDIO_MUTE,
+               .name          = "Mute",
+               .minimum       = 0,
+               .maximum       = 1,
+               .step          = 1,
+               .default_value = 1,
+               .type          = V4L2_CTRL_TYPE_BOOLEAN,
+       },
+/* HINT: the disabled controls are only here to satify kradio and such apps */
+       {       .id             = V4L2_CID_AUDIO_VOLUME,
+               .flags          = V4L2_CTRL_FLAG_DISABLED,
+       },
+       {
+               .id             = V4L2_CID_AUDIO_BALANCE,
+               .flags          = V4L2_CTRL_FLAG_DISABLED,
+       },
+       {
+               .id             = V4L2_CID_AUDIO_BASS,
+               .flags          = V4L2_CTRL_FLAG_DISABLED,
+       },
+       {
+               .id             = V4L2_CID_AUDIO_TREBLE,
+               .flags          = V4L2_CTRL_FLAG_DISABLED,
+       },
+       {
+               .id             = V4L2_CID_AUDIO_LOUDNESS,
+               .flags          = V4L2_CTRL_FLAG_DISABLED,
+       },
+};
+
+static int usb_amradio_probe(struct usb_interface *intf,
+                            const struct usb_device_id *id);
+static void usb_amradio_disconnect(struct usb_interface *intf);
+static int usb_amradio_open(struct inode *inode, struct file *file);
+static int usb_amradio_close(struct inode *inode, struct file *file);
+static int usb_amradio_suspend(struct usb_interface *intf,
+                               pm_message_t message);
+static int usb_amradio_resume(struct usb_interface *intf);
+
+/* Data for one (physical) device */
+struct amradio_device {
+       /* reference to USB and video device */
+       struct usb_device *usbdev;
+       struct video_device *videodev;
+
+       unsigned char *buffer;
+       struct mutex lock;      /* buffer locking */
+       int curfreq;
+       int stereo;
+       int users;
+       int removed;
+       int muted;
+};
+
+/* USB Device ID List */
+static struct usb_device_id usb_amradio_device_table[] = {
+       {USB_DEVICE_AND_INTERFACE_INFO(USB_AMRADIO_VENDOR, USB_AMRADIO_PRODUCT,
+                                                       USB_CLASS_HID, 0, 0) },
+       { }                                             /* Terminating entry */
+};
+
+MODULE_DEVICE_TABLE(usb, usb_amradio_device_table);
+
+/* USB subsystem interface */
+static struct usb_driver usb_amradio_driver = {
+       .name                   = "radio-mr800",
+       .probe                  = usb_amradio_probe,
+       .disconnect             = usb_amradio_disconnect,
+       .suspend                = usb_amradio_suspend,
+       .resume                 = usb_amradio_resume,
+       .reset_resume           = usb_amradio_resume,
+       .id_table               = usb_amradio_device_table,
+       .supports_autosuspend   = 1,
+};
+
+/* switch on radio. Send 8 bytes to device. */
+static int amradio_start(struct amradio_device *radio)
+{
+       int retval;
+       int size;
+
+       mutex_lock(&radio->lock);
+
+       radio->buffer[0] = 0x00;
+       radio->buffer[1] = 0x55;
+       radio->buffer[2] = 0xaa;
+       radio->buffer[3] = 0x00;
+       radio->buffer[4] = 0xab;
+       radio->buffer[5] = 0x00;
+       radio->buffer[6] = 0x00;
+       radio->buffer[7] = 0x00;
+
+       retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
+               (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
+
+       if (retval) {
+               mutex_unlock(&radio->lock);
+               return retval;
+       }
+
+       mutex_unlock(&radio->lock);
+
+       radio->muted = 0;
+
+       return retval;
+}
+
+/* switch off radio */
+static int amradio_stop(struct amradio_device *radio)
+{
+       int retval;
+       int size;
+
+       mutex_lock(&radio->lock);
+
+       radio->buffer[0] = 0x00;
+       radio->buffer[1] = 0x55;
+       radio->buffer[2] = 0xaa;
+       radio->buffer[3] = 0x00;
+       radio->buffer[4] = 0xab;
+       radio->buffer[5] = 0x01;
+       radio->buffer[6] = 0x00;
+       radio->buffer[7] = 0x00;
+
+       retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
+               (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
+
+       if (retval) {
+               mutex_unlock(&radio->lock);
+               return retval;
+       }
+
+       mutex_unlock(&radio->lock);
+
+       radio->muted = 1;
+
+       return retval;
+}
+
+/* set a frequency, freq is defined by v4l's TUNER_LOW, i.e. 1/16th kHz */
+static int amradio_setfreq(struct amradio_device *radio, int freq)
+{
+       int retval;
+       int size;
+       unsigned short freq_send = 0x13 + (freq >> 3) / 25;
+
+       mutex_lock(&radio->lock);
+
+       radio->buffer[0] = 0x00;
+       radio->buffer[1] = 0x55;
+       radio->buffer[2] = 0xaa;
+       radio->buffer[3] = 0x03;
+       radio->buffer[4] = 0xa4;
+       radio->buffer[5] = 0x00;
+       radio->buffer[6] = 0x00;
+       radio->buffer[7] = 0x08;
+
+       retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
+               (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
+
+       if (retval) {
+               mutex_unlock(&radio->lock);
+               return retval;
+       }
+
+       /* frequency is calculated from freq_send and placed in first 2 bytes */
+       radio->buffer[0] = (freq_send >> 8) & 0xff;
+       radio->buffer[1] = freq_send & 0xff;
+       radio->buffer[2] = 0x01;
+       radio->buffer[3] = 0x00;
+       radio->buffer[4] = 0x00;
+       /* 5 and 6 bytes of buffer already = 0x00 */
+       radio->buffer[7] = 0x00;
+
+       retval = usb_bulk_msg(radio->usbdev, usb_sndintpipe(radio->usbdev, 2),
+               (void *) (radio->buffer), BUFFER_LENGTH, &size, USB_TIMEOUT);
+
+       if (retval) {
+               mutex_unlock(&radio->lock);
+               return retval;
+       }
+
+       mutex_unlock(&radio->lock);
+
+       radio->stereo = 0;
+
+       return retval;
+}
+
+/* USB subsystem interface begins here */
+
+/* handle unplugging of the device, release data structures
+if nothing keeps us from doing it.  If something is still
+keeping us busy, the release callback of v4l will take care
+of releasing it. */
+static void usb_amradio_disconnect(struct usb_interface *intf)
+{
+       struct amradio_device *radio = usb_get_intfdata(intf);
+
+       usb_set_intfdata(intf, NULL);
+
+       if (radio) {
+               video_unregister_device(radio->videodev);
+               radio->videodev = NULL;
+               if (radio->users) {
+                       kfree(radio->buffer);
+                       kfree(radio);
+               } else {
+                       radio->removed = 1;
+               }
+       }
+}
+
+/* vidioc_querycap - query device capabilities */
+static int vidioc_querycap(struct file *file, void *priv,
+                                       struct v4l2_capability *v)
+{
+       strlcpy(v->driver, "radio-mr800", sizeof(v->driver));
+       strlcpy(v->card, "AverMedia MR 800 USB FM Radio", sizeof(v->card));
+       sprintf(v->bus_info, "USB");
+       v->version = RADIO_VERSION;
+       v->capabilities = V4L2_CAP_TUNER;
+       return 0;
+}
+
+/* vidioc_g_tuner - get tuner attributes */
+static int vidioc_g_tuner(struct file *file, void *priv,
+                               struct v4l2_tuner *v)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       if (v->index > 0)
+               return -EINVAL;
+
+/* TODO: Add function which look is signal stereo or not
+ *     amradio_getstat(radio);
+ */
+       radio->stereo = -1;
+       strcpy(v->name, "FM");
+       v->type = V4L2_TUNER_RADIO;
+       v->rangelow = FREQ_MIN * FREQ_MUL;
+       v->rangehigh = FREQ_MAX * FREQ_MUL;
+       v->rxsubchans = V4L2_TUNER_SUB_MONO | V4L2_TUNER_SUB_STEREO;
+       v->capability = V4L2_TUNER_CAP_LOW;
+       if (radio->stereo)
+               v->audmode = V4L2_TUNER_MODE_STEREO;
+       else
+               v->audmode = V4L2_TUNER_MODE_MONO;
+       v->signal = 0xffff;     /* Can't get the signal strength, sad.. */
+       v->afc = 0; /* Don't know what is this */
+       return 0;
+}
+
+/* vidioc_s_tuner - set tuner attributes */
+static int vidioc_s_tuner(struct file *file, void *priv,
+                               struct v4l2_tuner *v)
+{
+       if (v->index > 0)
+               return -EINVAL;
+       return 0;
+}
+
+/* vidioc_s_frequency - set tuner radio frequency */
+static int vidioc_s_frequency(struct file *file, void *priv,
+                               struct v4l2_frequency *f)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       radio->curfreq = f->frequency;
+       if (amradio_setfreq(radio, radio->curfreq) < 0)
+               warn("Set frequency failed");
+       return 0;
+}
+
+/* vidioc_g_frequency - get tuner radio frequency */
+static int vidioc_g_frequency(struct file *file, void *priv,
+                               struct v4l2_frequency *f)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       f->type = V4L2_TUNER_RADIO;
+       f->frequency = radio->curfreq;
+       return 0;
+}
+
+/* vidioc_queryctrl - enumerate control items */
+static int vidioc_queryctrl(struct file *file, void *priv,
+                               struct v4l2_queryctrl *qc)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(radio_qctrl); i++) {
+               if (qc->id && qc->id == radio_qctrl[i].id) {
+                       memcpy(qc, &(radio_qctrl[i]),
+                                               sizeof(*qc));
+                       return 0;
+               }
+       }
+       return -EINVAL;
+}
+
+/* vidioc_g_ctrl - get the value of a control */
+static int vidioc_g_ctrl(struct file *file, void *priv,
+                               struct v4l2_control *ctrl)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               ctrl->value = radio->muted;
+               return 0;
+       }
+       return -EINVAL;
+}
+
+/* vidioc_s_ctrl - set the value of a control */
+static int vidioc_s_ctrl(struct file *file, void *priv,
+                               struct v4l2_control *ctrl)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       switch (ctrl->id) {
+       case V4L2_CID_AUDIO_MUTE:
+               if (ctrl->value) {
+                       if (amradio_stop(radio) < 0) {
+                               warn("amradio_stop() failed");
+                               return -1;
+                       }
+               } else {
+                       if (amradio_start(radio) < 0) {
+                               warn("amradio_start() failed");
+                               return -1;
+                       }
+               }
+               return 0;
+       }
+       return -EINVAL;
+}
+
+/* vidioc_g_audio - get audio attributes */
+static int vidioc_g_audio(struct file *file, void *priv,
+                               struct v4l2_audio *a)
+{
+       if (a->index > 1)
+               return -EINVAL;
+
+       strcpy(a->name, "Radio");
+       a->capability = V4L2_AUDCAP_STEREO;
+       return 0;
+}
+
+/* vidioc_s_audio - set audio attributes  */
+static int vidioc_s_audio(struct file *file, void *priv,
+                                       struct v4l2_audio *a)
+{
+       if (a->index != 0)
+               return -EINVAL;
+       return 0;
+}
+
+/* vidioc_g_input - get input */
+static int vidioc_g_input(struct file *filp, void *priv, unsigned int *i)
+{
+       *i = 0;
+       return 0;
+}
+
+/* vidioc_s_input - set input */
+static int vidioc_s_input(struct file *filp, void *priv, unsigned int i)
+{
+       if (i != 0)
+               return -EINVAL;
+       return 0;
+}
+
+/* open device - amradio_start() and amradio_setfreq() */
+static int usb_amradio_open(struct inode *inode, struct file *file)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       radio->users = 1;
+       radio->muted = 1;
+
+       if (amradio_start(radio) < 0) {
+               warn("Radio did not start up properly");
+               radio->users = 0;
+               return -EIO;
+       }
+       if (amradio_setfreq(radio, radio->curfreq) < 0)
+               warn("Set frequency failed");
+       return 0;
+}
+
+/*close device - free driver structures */
+static int usb_amradio_close(struct inode *inode, struct file *file)
+{
+       struct amradio_device *radio = video_get_drvdata(video_devdata(file));
+
+       if (!radio)
+               return -ENODEV;
+       radio->users = 0;
+       if (radio->removed) {
+               kfree(radio->buffer);
+               kfree(radio);
+       }
+       return 0;
+}
+
+/* Suspend device - stop device. Need to be checked and fixed */
+static int usb_amradio_suspend(struct usb_interface *intf, pm_message_t message)
+{
+       struct amradio_device *radio = usb_get_intfdata(intf);
+
+       if (amradio_stop(radio) < 0)
+               warn("amradio_stop() failed");
+
+       info("radio-mr800: Going into suspend..");
+
+       return 0;
+}
+
+/* Resume device - start device. Need to be checked and fixed */
+static int usb_amradio_resume(struct usb_interface *intf)
+{
+       struct amradio_device *radio = usb_get_intfdata(intf);
+
+       if (amradio_start(radio) < 0)
+               warn("amradio_start() failed");
+
+       info("radio-mr800: Coming out of suspend..");
+
+       return 0;
+}
+
+/* File system interface */
+static const struct file_operations usb_amradio_fops = {
+       .owner          = THIS_MODULE,
+       .open           = usb_amradio_open,
+       .release        = usb_amradio_close,
+       .ioctl          = video_ioctl2,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = v4l_compat_ioctl32,
+#endif
+       .llseek         = no_llseek,
+};
+
+static const struct v4l2_ioctl_ops usb_amradio_ioctl_ops = {
+       .vidioc_querycap    = vidioc_querycap,
+       .vidioc_g_tuner     = vidioc_g_tuner,
+       .vidioc_s_tuner     = vidioc_s_tuner,
+       .vidioc_g_frequency = vidioc_g_frequency,
+       .vidioc_s_frequency = vidioc_s_frequency,
+       .vidioc_queryctrl   = vidioc_queryctrl,
+       .vidioc_g_ctrl      = vidioc_g_ctrl,
+       .vidioc_s_ctrl      = vidioc_s_ctrl,
+       .vidioc_g_audio     = vidioc_g_audio,
+       .vidioc_s_audio     = vidioc_s_audio,
+       .vidioc_g_input     = vidioc_g_input,
+       .vidioc_s_input     = vidioc_s_input,
+};
+
+/* V4L2 interface */
+static struct video_device amradio_videodev_template = {
+       .name           = "AverMedia MR 800 USB FM Radio",
+       .fops           = &usb_amradio_fops,
+       .ioctl_ops      = &usb_amradio_ioctl_ops,
+       .release        = video_device_release,
+};
+
+/* check if the device is present and register with v4l and
+usb if it is */
+static int usb_amradio_probe(struct usb_interface *intf,
+                               const struct usb_device_id *id)
+{
+       struct amradio_device *radio;
+
+       radio = kmalloc(sizeof(struct amradio_device), GFP_KERNEL);
+
+       if (!(radio))
+               return -ENOMEM;
+
+       radio->buffer = kmalloc(BUFFER_LENGTH, GFP_KERNEL);
+
+       if (!(radio->buffer)) {
+               kfree(radio);
+               return -ENOMEM;
+       }
+
+       radio->videodev = video_device_alloc();
+
+       if (!(radio->videodev)) {
+               kfree(radio->buffer);
+               kfree(radio);
+               return -ENOMEM;
+       }
+
+       memcpy(radio->videodev, &amradio_videodev_template,
+               sizeof(amradio_videodev_template));
+
+       radio->removed = 0;
+       radio->users = 0;
+       radio->usbdev = interface_to_usbdev(intf);
+       radio->curfreq = 95.16 * FREQ_MUL;
+
+       mutex_init(&radio->lock);
+
+       video_set_drvdata(radio->videodev, radio);
+       if (video_register_device(radio->videodev, VFL_TYPE_RADIO, radio_nr)) {
+               warn("Could not register video device");
+               video_device_release(radio->videodev);
+               kfree(radio->buffer);
+               kfree(radio);
+               return -EIO;
+       }
+
+       usb_set_intfdata(intf, radio);
+       return 0;
+}
+
+static int __init amradio_init(void)
+{
+       int retval = usb_register(&usb_amradio_driver);
+
+       info(DRIVER_VERSION " " DRIVER_DESC);
+       if (retval)
+               err("usb_register failed. Error number %d", retval);
+       return retval;
+}
+
+static void __exit amradio_exit(void)
+{
+       usb_deregister(&usb_amradio_driver);
+}
+
+module_init(amradio_init);
+module_exit(amradio_exit);
+
index 6d820e2481e7cc0e9e8b1d02a93f974289e35ce5..a67079777419571e875100f6d488e9c0178d939c 100644 (file)
@@ -52,6 +52,7 @@ static spinlock_t lock;
 
 struct rt_device
 {
+       unsigned long in_use;
        int port;
        unsigned long curfreq;
        int muted;
@@ -153,8 +154,7 @@ static int rt_getsigstr(struct rt_device *dev)
 static int vidioc_g_tuner(struct file *file, void *priv,
                                struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -173,8 +173,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        rt->curfreq = f->frequency;
        rt_setfreq(rt, rt->curfreq);
@@ -184,8 +183,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = rt->curfreq;
@@ -210,8 +208,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -230,8 +227,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct rt_device *rt = dev->priv;
+       struct rt_device *rt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -284,10 +280,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct rt_device rtrack2_unit;
 
+static int rtrack2_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &rtrack2_unit.in_use) ? -EBUSY : 0;
+}
+
+static int rtrack2_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &rtrack2_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations rtrack2_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = rtrack2_exclusive_open,
+       .release        = rtrack2_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -314,6 +321,7 @@ static struct video_device rtrack2_radio = {
        .name           = "RadioTrack II radio",
        .fops           = &rtrack2_fops,
        .ioctl_ops      = &rtrack2_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init rtrack2_init(void)
@@ -329,7 +337,7 @@ static int __init rtrack2_init(void)
                return -EBUSY;
        }
 
-       rtrack2_radio.priv=&rtrack2_unit;
+       video_set_drvdata(&rtrack2_radio, &rtrack2_unit);
 
        spin_lock_init(&lock);
        if (video_register_device(&rtrack2_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
index 0d478f54a90770810198a3e14551ac287b807353..329c90bddadd953836b25cd10dd9668bf2e99329 100644 (file)
@@ -45,6 +45,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 
 struct fmi_device
 {
+       unsigned long in_use;
        int port;
        int curvol; /* 1 or 0 */
        unsigned long curfreq; /* freq in kHz */
@@ -146,8 +147,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
        int mult;
-       struct video_device *dev = video_devdata(file);
-       struct fmi_device *fmi = dev->priv;
+       struct fmi_device *fmi = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -175,8 +175,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmi_device *fmi = dev->priv;
+       struct fmi_device *fmi = video_drvdata(file);
 
        if (!(fmi->flags & V4L2_TUNER_CAP_LOW))
                f->frequency *= 1000;
@@ -193,8 +192,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmi_device *fmi = dev->priv;
+       struct fmi_device *fmi = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = fmi->curfreq;
@@ -221,8 +219,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmi_device *fmi = dev->priv;
+       struct fmi_device *fmi = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -235,8 +232,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmi_device *fmi = dev->priv;
+       struct fmi_device *fmi = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -284,10 +280,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct fmi_device fmi_unit;
 
+static int fmi_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &fmi_unit.in_use) ? -EBUSY : 0;
+}
+
+static int fmi_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &fmi_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations fmi_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = fmi_exclusive_open,
+       .release        = fmi_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -314,6 +321,7 @@ static struct video_device fmi_radio = {
        .name           = "SF16FMx radio",
        .fops           = &fmi_fops,
        .ioctl_ops      = &fmi_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 /* ladis: this is my card. does any other types exist? */
@@ -373,7 +381,7 @@ static int __init fmi_init(void)
        fmi_unit.curvol = 0;
        fmi_unit.curfreq = 0;
        fmi_unit.flags = V4L2_TUNER_CAP_LOW;
-       fmi_radio.priv = &fmi_unit;
+       video_set_drvdata(&fmi_radio, &fmi_unit);
 
        mutex_init(&lock);
 
index 6290553d24beef56cf55ecfbe55aab32ae0ad620..b1f47c322e02637e58b2117a3c7df2e51656dd76 100644 (file)
@@ -64,6 +64,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 /* this should be static vars for module size */
 struct fmr2_device
 {
+       unsigned long in_use;
        int port;
        int curvol; /* 0-15 */
        int mute;
@@ -229,8 +230,7 @@ static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
        int mult;
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -262,8 +262,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        if (!(fmr2->flags & V4L2_TUNER_CAP_LOW))
                f->frequency *= 1000;
@@ -286,8 +285,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = fmr2->curfreq;
@@ -313,8 +311,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -330,8 +327,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct fmr2_device *fmr2 = dev->priv;
+       struct fmr2_device *fmr2 = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -400,10 +396,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct fmr2_device fmr2_unit;
 
+static int fmr2_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &fmr2_unit.in_use) ? -EBUSY : 0;
+}
+
+static int fmr2_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &fmr2_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations fmr2_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = fmr2_exclusive_open,
+       .release        = fmr2_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -430,6 +437,7 @@ static struct video_device fmr2_radio = {
        .name           = "SF16FMR2 radio",
        .fops           = &fmr2_fops,
        .ioctl_ops      = &fmr2_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init fmr2_init(void)
@@ -441,7 +449,7 @@ static int __init fmr2_init(void)
        fmr2_unit.stereo = 1;
        fmr2_unit.flags = V4L2_TUNER_CAP_LOW;
        fmr2_unit.card_type = 0;
-       fmr2_radio.priv = &fmr2_unit;
+       video_set_drvdata(&fmr2_radio, &fmr2_unit);
 
        mutex_init(&lock);
 
index 16c7ef20265c4c34e3782baead264700797923dd..f6cedcd3ab97b82b532b16a03137eb0fd5c7e75f 100644 (file)
@@ -986,7 +986,7 @@ static void si470x_work(struct work_struct *work)
 static ssize_t si470x_fops_read(struct file *file, char __user *buf,
                size_t count, loff_t *ppos)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
        unsigned int block_count = 0;
 
@@ -1047,7 +1047,7 @@ done:
 static unsigned int si470x_fops_poll(struct file *file,
                struct poll_table_struct *pts)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* switch on rds reception */
@@ -1071,9 +1071,10 @@ static unsigned int si470x_fops_poll(struct file *file,
  */
 static int si470x_fops_open(struct inode *inode, struct file *file)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval;
 
+       lock_kernel();
        radio->users++;
 
        retval = usb_autopm_get_interface(radio->intf);
@@ -1090,6 +1091,7 @@ static int si470x_fops_open(struct inode *inode, struct file *file)
        }
 
 done:
+       unlock_kernel();
        return retval;
 }
 
@@ -1099,7 +1101,7 @@ done:
  */
 static int si470x_fops_release(struct inode *inode, struct file *file)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety check */
@@ -1282,7 +1284,7 @@ done:
 static int si470x_vidioc_g_ctrl(struct file *file, void *priv,
                struct v4l2_control *ctrl)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1318,7 +1320,7 @@ done:
 static int si470x_vidioc_s_ctrl(struct file *file, void *priv,
                struct v4l2_control *ctrl)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1405,7 +1407,7 @@ done:
 static int si470x_vidioc_g_tuner(struct file *file, void *priv,
                struct v4l2_tuner *tuner)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1471,7 +1473,7 @@ done:
 static int si470x_vidioc_s_tuner(struct file *file, void *priv,
                struct v4l2_tuner *tuner)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1505,7 +1507,7 @@ done:
 static int si470x_vidioc_g_frequency(struct file *file, void *priv,
                struct v4l2_frequency *freq)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1534,7 +1536,7 @@ done:
 static int si470x_vidioc_s_frequency(struct file *file, void *priv,
                struct v4l2_frequency *freq)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
@@ -1563,7 +1565,7 @@ done:
 static int si470x_vidioc_s_hw_freq_seek(struct file *file, void *priv,
                struct v4l2_hw_freq_seek *seek)
 {
-       struct si470x_device *radio = video_get_drvdata(video_devdata(file));
+       struct si470x_device *radio = video_drvdata(file);
        int retval = 0;
 
        /* safety checks */
index 0876fecc5f275de8bf61bf1ab5d3713c90349c0f..0abb186a9473e5661dd1a117e83acdc9fe034a98 100644 (file)
@@ -79,6 +79,7 @@ static spinlock_t lock;
 
 struct tt_device
 {
+       unsigned long in_use;
        int port;
        int curvol;
        unsigned long curfreq;
@@ -220,8 +221,7 @@ static int vidioc_querycap(struct file *file, void *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct tt_device *tt = dev->priv;
+       struct tt_device *tt = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -248,8 +248,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct tt_device *tt = dev->priv;
+       struct tt_device *tt = video_drvdata(file);
 
        tt->curfreq = f->frequency;
        tt_setfreq(tt, tt->curfreq);
@@ -259,8 +258,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct tt_device *tt = dev->priv;
+       struct tt_device *tt = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = tt->curfreq;
@@ -285,8 +283,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct tt_device *tt = dev->priv;
+       struct tt_device *tt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -305,8 +302,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct tt_device *tt = dev->priv;
+       struct tt_device *tt = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -356,10 +352,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct tt_device terratec_unit;
 
+static int terratec_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &terratec_unit.in_use) ? -EBUSY : 0;
+}
+
+static int terratec_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &terratec_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations terratec_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = terratec_exclusive_open,
+       .release        = terratec_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -386,6 +393,7 @@ static struct video_device terratec_radio = {
        .name           = "TerraTec ActiveRadio",
        .fops           = &terratec_fops,
        .ioctl_ops      = &terratec_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init terratec_init(void)
@@ -401,7 +409,7 @@ static int __init terratec_init(void)
                return -EBUSY;
        }
 
-       terratec_radio.priv=&terratec_unit;
+       video_set_drvdata(&terratec_radio, &terratec_unit);
 
        spin_lock_init(&lock);
 
index 193161956253422121f906d46729013c114716a4..e7b111fcd105b6fc79a3a11c922d6edf2a0542e1 100644 (file)
@@ -78,6 +78,7 @@ static __u16 curtreble;
 static unsigned long curfreq;
 static int curstereo;
 static int curmute;
+static unsigned long in_use;
 
 /* i2c addresses */
 #define TDA7318_ADDR 0x88
@@ -336,10 +337,21 @@ static int vidioc_s_audio(struct file *file, void *priv,
        return 0;
 }
 
+static int trust_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &in_use) ? -EBUSY : 0;
+}
+
+static int trust_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &in_use);
+       return 0;
+}
+
 static const struct file_operations trust_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = trust_exclusive_open,
+       .release        = trust_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -366,6 +378,7 @@ static struct video_device trust_radio = {
        .name           = "Trust FM Radio",
        .fops           = &trust_fops,
        .ioctl_ops      = &trust_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init trust_init(void)
index f8d62cfea7745d28cdda0c5be81667e4fb571c09..952ec35a8415129100ae56564ee2e956facbccd7 100644 (file)
@@ -79,7 +79,7 @@ static struct v4l2_queryctrl radio_qctrl[] = {
 #endif
 
 struct typhoon_device {
-       int users;
+       unsigned long in_use;
        int iobase;
        int curvol;
        int muted;
@@ -223,8 +223,7 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct typhoon_device *typhoon = dev->priv;
+       struct typhoon_device *typhoon = video_drvdata(file);
 
        typhoon->curfreq = f->frequency;
        typhoon_setfreq(typhoon, typhoon->curfreq);
@@ -234,8 +233,7 @@ static int vidioc_s_frequency(struct file *file, void *priv,
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct typhoon_device *typhoon = dev->priv;
+       struct typhoon_device *typhoon = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = typhoon->curfreq;
@@ -261,8 +259,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct typhoon_device *typhoon = dev->priv;
+       struct typhoon_device *typhoon = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -278,8 +275,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl (struct file *file, void *priv,
                                        struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct typhoon_device *typhoon = dev->priv;
+       struct typhoon_device *typhoon = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -334,10 +330,21 @@ static struct typhoon_device typhoon_unit =
        .mutefreq       = CONFIG_RADIO_TYPHOON_MUTEFREQ,
 };
 
+static int typhoon_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &typhoon_unit.in_use) ? -EBUSY : 0;
+}
+
+static int typhoon_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &typhoon_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations typhoon_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = typhoon_exclusive_open,
+       .release        = typhoon_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -364,6 +371,7 @@ static struct video_device typhoon_radio = {
        .name           = "Typhoon Radio",
        .fops           = &typhoon_fops,
        .ioctl_ops      = &typhoon_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 #ifdef CONFIG_RADIO_TYPHOON_PROC_FS
@@ -446,9 +454,8 @@ static int __init typhoon_init(void)
                return -EBUSY;
        }
 
-       typhoon_radio.priv = &typhoon_unit;
-       if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) == -1)
-       {
+       video_set_drvdata(&typhoon_radio, &typhoon_unit);
+       if (video_register_device(&typhoon_radio, VFL_TYPE_RADIO, radio_nr) < 0) {
                release_region(io, 8);
                return -EINVAL;
        }
index 51d57ed3b3e12a5db805f09cb93acc9c39560e7c..15b10bad679660efa22b59bc3d70f161841c07f0 100644 (file)
@@ -69,6 +69,7 @@ static int io = CONFIG_RADIO_ZOLTRIX_PORT;
 static int radio_nr = -1;
 
 struct zol_device {
+       unsigned long in_use;
        int port;
        int curvol;
        unsigned long curfreq;
@@ -122,8 +123,11 @@ static int zol_setfreq(struct zol_device *dev, unsigned long freq)
        unsigned int stereo = dev->stereo;
        int i;
 
-       if (freq == 0)
-               return 1;
+       if (freq == 0) {
+               printk(KERN_WARNING "zoltrix: received zero freq. Failed to set.\n");
+               return -EINVAL;
+       }
+
        m = (freq / 160 - 8800) * 2;
        f = (unsigned long long) m + 0x4d1c;
 
@@ -245,8 +249,7 @@ static int vidioc_querycap(struct file *file, void  *priv,
 static int vidioc_g_tuner(struct file *file, void *priv,
                                        struct v4l2_tuner *v)
 {
-       struct video_device *dev = video_devdata(file);
-       struct zol_device *zol = dev->priv;
+       struct zol_device *zol = video_drvdata(file);
 
        if (v->index > 0)
                return -EINVAL;
@@ -276,19 +279,20 @@ static int vidioc_s_tuner(struct file *file, void *priv,
 static int vidioc_s_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct zol_device *zol = dev->priv;
+       struct zol_device *zol = video_drvdata(file);
 
        zol->curfreq = f->frequency;
-       zol_setfreq(zol, zol->curfreq);
+       if (zol_setfreq(zol, zol->curfreq) != 0) {
+               printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
+               return -EINVAL;
+       }
        return 0;
 }
 
 static int vidioc_g_frequency(struct file *file, void *priv,
                                        struct v4l2_frequency *f)
 {
-       struct video_device *dev = video_devdata(file);
-       struct zol_device *zol = dev->priv;
+       struct zol_device *zol = video_drvdata(file);
 
        f->type = V4L2_TUNER_RADIO;
        f->frequency = zol->curfreq;
@@ -313,8 +317,7 @@ static int vidioc_queryctrl(struct file *file, void *priv,
 static int vidioc_g_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct zol_device *zol = dev->priv;
+       struct zol_device *zol = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -330,8 +333,7 @@ static int vidioc_g_ctrl(struct file *file, void *priv,
 static int vidioc_s_ctrl(struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct zol_device *zol = dev->priv;
+       struct zol_device *zol = video_drvdata(file);
 
        switch (ctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
@@ -347,7 +349,10 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
                return 0;
        }
        zol->stereo = 1;
-       zol_setfreq(zol, zol->curfreq);
+       if (zol_setfreq(zol, zol->curfreq) != 0) {
+               printk(KERN_WARNING "zoltrix: Set frequency failed.\n");
+               return -EINVAL;
+       }
 #if 0
 /* FIXME: Implement stereo/mono switch on V4L2 */
                        if (v->mode & VIDEO_SOUND_STEREO) {
@@ -396,11 +401,22 @@ static int vidioc_s_audio(struct file *file, void *priv,
 
 static struct zol_device zoltrix_unit;
 
+static int zoltrix_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &zoltrix_unit.in_use) ? -EBUSY : 0;
+}
+
+static int zoltrix_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &zoltrix_unit.in_use);
+       return 0;
+}
+
 static const struct file_operations zoltrix_fops =
 {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = zoltrix_exclusive_open,
+       .release        = zoltrix_exclusive_release,
        .ioctl          = video_ioctl2,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -427,6 +443,7 @@ static struct video_device zoltrix_radio = {
        .name           = "Zoltrix Radio Plus",
        .fops           = &zoltrix_fops,
        .ioctl_ops      = &zoltrix_ioctl_ops,
+       .release        = video_device_release_empty,
 };
 
 static int __init zoltrix_init(void)
@@ -440,7 +457,7 @@ static int __init zoltrix_init(void)
                return -ENXIO;
        }
 
-       zoltrix_radio.priv = &zoltrix_unit;
+       video_set_drvdata(&zoltrix_radio, &zoltrix_unit);
        if (!request_region(io, 2, "zoltrix")) {
                printk(KERN_ERR "zoltrix: port 0x%x already in use\n", io);
                return -EBUSY;
index 3e9e0dcd217ecfaf278cdef11f6cb8cb18f666a2..47102c2c8250fc51df410059ba5b52c24ea5f510 100644 (file)
@@ -34,6 +34,7 @@ config VIDEOBUF_DVB
        select VIDEOBUF_GEN
 
 config VIDEO_BTCX
+       depends on PCI
        tristate
 
 config VIDEO_IR
@@ -71,6 +72,15 @@ config VIDEO_ADV_DEBUG
          V4L devices.
          In doubt, say N.
 
+config VIDEO_FIXED_MINOR_RANGES
+       bool "Enable old-style fixed minor ranges for video devices"
+       default n
+       ---help---
+         Say Y here to enable the old-style fixed-range minor assignments.
+         Only useful if you rely on the old behavior and use mknod instead of udev.
+
+         When in doubt, say N.
+
 config VIDEO_HELPER_CHIPS_AUTO
        bool "Autoselect pertinent encoders/decoders and other helper chips"
        default y
@@ -578,13 +588,6 @@ config VIDEO_SAA5249
          To compile this driver as a module, choose M here: the
          module will be called saa5249.
 
-config TUNER_3036
-       tristate "SAB3036 tuner"
-       depends on I2C && VIDEO_V4L1
-       help
-         Say Y here to include support for Philips SAB3036 compatible tuners.
-         If in doubt, say N.
-
 config VIDEO_VINO
        tristate "SGI Vino Video For Linux (EXPERIMENTAL)"
        depends on I2C && SGI_IP22 && EXPERIMENTAL && VIDEO_V4L2
@@ -602,79 +605,7 @@ config VIDEO_STRADIS
          driver for PCI.  There is a product page at
          <http://www.stradis.com/>.
 
-config VIDEO_ZORAN
-       tristate "Zoran ZR36057/36067 Video For Linux"
-       depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS
-       help
-         Say Y for support for MJPEG capture cards based on the Zoran
-         36057/36067 PCI controller chipset. This includes the Iomega
-         Buz, Pinnacle DC10+ and the Linux Media Labs LML33. There is
-         a driver homepage at <http://mjpeg.sf.net/driver-zoran/>. For
-         more information, check <file:Documentation/video4linux/Zoran>.
-
-         To compile this driver as a module, choose M here: the
-         module will be called zr36067.
-
-config VIDEO_ZORAN_DC30
-       tristate "Pinnacle/Miro DC30(+) support"
-       depends on VIDEO_ZORAN
-       select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_VPX3220 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback
-         card. This also supports really old DC10 cards based on the
-         zr36050 MJPEG codec and zr36016 VFE.
-
-config VIDEO_ZORAN_ZR36060
-       tristate "Zoran ZR36060"
-       depends on VIDEO_ZORAN
-       help
-         Say Y to support Zoran boards based on 36060 chips.
-         This includes Iomega Buz, Pinnacle DC10, Linux media Labs 33
-         and 33 R10 and AverMedia 6 boards.
-
-config VIDEO_ZORAN_BUZ
-       tristate "Iomega Buz support"
-       depends on VIDEO_ZORAN_ZR36060
-       select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         Support for the Iomega Buz MJPEG capture/playback card.
-
-config VIDEO_ZORAN_DC10
-       tristate "Pinnacle/Miro DC10(+) support"
-       depends on VIDEO_ZORAN_ZR36060
-       select VIDEO_SAA7110 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback
-         card.
-
-config VIDEO_ZORAN_LML33
-       tristate "Linux Media Labs LML33 support"
-       depends on VIDEO_ZORAN_ZR36060
-       select VIDEO_BT819 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         Support for the Linux Media Labs LML33 MJPEG capture/playback
-         card.
-
-config VIDEO_ZORAN_LML33R10
-       tristate "Linux Media Labs LML33R10 support"
-       depends on VIDEO_ZORAN_ZR36060
-       select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         support for the Linux Media Labs LML33R10 MJPEG capture/playback
-         card.
-
-config VIDEO_ZORAN_AVS6EYES
-       tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
-       depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1
-       select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
-       select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
-       help
-         Support for the AverMedia 6 Eyes video surveillance card.
+source "drivers/media/video/zoran/Kconfig"
 
 config VIDEO_MEYE
        tristate "Sony Vaio Picturebook Motion Eye Video For Linux"
@@ -697,7 +628,7 @@ config VIDEO_MXB
        depends on PCI && VIDEO_V4L1 && I2C
        select VIDEO_SAA7146_VV
        select VIDEO_TUNER
-       select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_SAA7115 if VIDEO_HELPER_CHIPS_AUTO
        select VIDEO_TDA9840 if VIDEO_HELPER_CHIPS_AUTO
        select VIDEO_TEA6415C if VIDEO_HELPER_CHIPS_AUTO
        select VIDEO_TEA6420 if VIDEO_HELPER_CHIPS_AUTO
@@ -708,21 +639,6 @@ config VIDEO_MXB
          To compile this driver as a module, choose M here: the
          module will be called mxb.
 
-config VIDEO_DPC
-       tristate "Philips-Semiconductors 'dpc7146 demonstration board'"
-       depends on PCI && VIDEO_V4L1 && I2C
-       select VIDEO_SAA7146_VV
-       select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
-       ---help---
-         This is a video4linux driver for the 'dpc7146 demonstration
-         board' by Philips-Semiconductors. It's the reference design
-         for SAA7146 bases boards, so if you have some unsupported
-         saa7146 based, analog video card, chances are good that it
-         will work with this skeleton driver.
-
-         To compile this driver as a module, choose M here: the
-         module will be called dpc7146.
-
 config VIDEO_HEXIUM_ORION
        tristate "Hexium HV-PCI6 and Orion frame grabber"
        depends on PCI && VIDEO_V4L2 && I2C
@@ -784,6 +700,70 @@ config VIDEO_CAFE_CCIC
          CMOS camera controller.  This is the controller found on first-
          generation OLPC systems.
 
+config SOC_CAMERA
+       tristate "SoC camera support"
+       depends on VIDEO_V4L2 && HAS_DMA
+       select VIDEOBUF_GEN
+       help
+         SoC Camera is a common API to several cameras, not connecting
+         over a bus like PCI or USB. For example some i2c camera connected
+         directly to the data bus of an SoC.
+
+config SOC_CAMERA_MT9M001
+       tristate "mt9m001 support"
+       depends on SOC_CAMERA && I2C
+       select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
+       help
+         This driver supports MT9M001 cameras from Micron, monochrome
+         and colour models.
+
+config MT9M001_PCA9536_SWITCH
+       bool "pca9536 datawidth switch for mt9m001"
+       depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
+       help
+         Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
+         extender to switch between 8 and 10 bit datawidth modes
+
+config SOC_CAMERA_MT9M111
+       tristate "mt9m111 support"
+       depends on SOC_CAMERA && I2C
+       help
+         This driver supports MT9M111 cameras from Micron
+
+config SOC_CAMERA_MT9V022
+       tristate "mt9v022 support"
+       depends on SOC_CAMERA && I2C
+       select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
+       help
+         This driver supports MT9V022 cameras from Micron
+
+config MT9V022_PCA9536_SWITCH
+       bool "pca9536 datawidth switch for mt9v022"
+       depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
+       help
+         Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
+         extender to switch between 8 and 10 bit datawidth modes
+
+config SOC_CAMERA_PLATFORM
+       tristate "platform camera support"
+       depends on SOC_CAMERA
+       help
+         This is a generic SoC camera platform driver, useful for testing
+
+config VIDEO_PXA27x
+       tristate "PXA27x Quick Capture Interface driver"
+       depends on VIDEO_DEV && PXA27x && SOC_CAMERA
+       select VIDEOBUF_DMA_SG
+       ---help---
+         This is a v4l2 driver for the PXA27x Quick Capture Interface
+
+config VIDEO_SH_MOBILE_CEU
+       tristate "SuperH Mobile CEU Interface driver"
+       depends on VIDEO_DEV && SOC_CAMERA && HAS_DMA
+       select VIDEOBUF_DMA_CONTIG
+       ---help---
+         This is a v4l2 driver for the SuperH Mobile CEU Interface
+
 #
 # USB Multimedia device configuration
 #
@@ -822,8 +802,7 @@ config VIDEO_OVCAMCHIP
 
 config USB_W9968CF
        tristate "USB W996[87]CF JPEG Dual Mode Camera support"
-       depends on VIDEO_V4L1 && I2C
-       select VIDEO_OVCAMCHIP
+       depends on VIDEO_V4L1 && I2C && VIDEO_OVCAMCHIP
        ---help---
          Say Y here if you want support for cameras based on OV681 or
          Winbond W9967CF/W9968CF JPEG USB Dual Mode Camera Chips.
@@ -914,64 +893,4 @@ config USB_S2255
 
 endif # V4L_USB_DRIVERS
 
-config SOC_CAMERA
-       tristate "SoC camera support"
-       depends on VIDEO_V4L2 && HAS_DMA
-       select VIDEOBUF_GEN
-       help
-         SoC Camera is a common API to several cameras, not connecting
-         over a bus like PCI or USB. For example some i2c camera connected
-         directly to the data bus of an SoC.
-
-config SOC_CAMERA_MT9M001
-       tristate "mt9m001 support"
-       depends on SOC_CAMERA && I2C
-       select GPIO_PCA953X if MT9M001_PCA9536_SWITCH
-       help
-         This driver supports MT9M001 cameras from Micron, monochrome
-         and colour models.
-
-config MT9M001_PCA9536_SWITCH
-       bool "pca9536 datawidth switch for mt9m001"
-       depends on SOC_CAMERA_MT9M001 && GENERIC_GPIO
-       help
-         Select this if your MT9M001 camera uses a PCA9536 I2C GPIO
-         extender to switch between 8 and 10 bit datawidth modes
-
-config SOC_CAMERA_MT9V022
-       tristate "mt9v022 support"
-       depends on SOC_CAMERA && I2C
-       select GPIO_PCA953X if MT9V022_PCA9536_SWITCH
-       help
-         This driver supports MT9V022 cameras from Micron
-
-config MT9V022_PCA9536_SWITCH
-       bool "pca9536 datawidth switch for mt9v022"
-       depends on SOC_CAMERA_MT9V022 && GENERIC_GPIO
-       help
-         Select this if your MT9V022 camera uses a PCA9536 I2C GPIO
-         extender to switch between 8 and 10 bit datawidth modes
-
-config SOC_CAMERA_PLATFORM
-       tristate "platform camera support"
-       depends on SOC_CAMERA
-       help
-         This is a generic SoC camera platform driver, useful for testing
-
-config VIDEO_PXA27x
-       tristate "PXA27x Quick Capture Interface driver"
-       depends on VIDEO_DEV && PXA27x
-       select SOC_CAMERA
-       select VIDEOBUF_DMA_SG
-       ---help---
-         This is a v4l2 driver for the PXA27x Quick Capture Interface
-
-config VIDEO_SH_MOBILE_CEU
-       tristate "SuperH Mobile CEU Interface driver"
-       depends on VIDEO_DEV && HAS_DMA
-       select SOC_CAMERA
-       select VIDEOBUF_DMA_CONTIG
-       ---help---
-         This is a v4l2 driver for the SuperH Mobile CEU Interface
-
 endif # VIDEO_CAPTURE_DRIVERS
index ef7c8d3ffb18bba4e3930668285a30883fc1fc10..16962f3aa15767f09d71ffaa492e2d6f3db562c4 100644 (file)
@@ -2,8 +2,6 @@
 # Makefile for the video capture/playback device drivers.
 #
 
-zr36067-objs   :=      zoran_procfs.o zoran_device.o \
-                       zoran_driver.o zoran_card.o
 tuner-objs     :=      tuner-core.o
 
 msp3400-objs   :=      msp3400-driver.o msp3400-kthreads.o
@@ -54,9 +52,7 @@ obj-$(CONFIG_VIDEO_BT856) += bt856.o
 obj-$(CONFIG_VIDEO_BT866) += bt866.o
 obj-$(CONFIG_VIDEO_KS0127) += ks0127.o
 
-obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
-obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
-obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
+obj-$(CONFIG_VIDEO_ZORAN) += zoran/
 
 obj-$(CONFIG_VIDEO_PMS) += pms.o
 obj-$(CONFIG_VIDEO_VINO) += vino.o indycam.o
@@ -84,8 +80,6 @@ obj-$(CONFIG_VIDEO_CPIA2) += cpia2/
 obj-$(CONFIG_VIDEO_MXB) += mxb.o
 obj-$(CONFIG_VIDEO_HEXIUM_ORION) += hexium_orion.o
 obj-$(CONFIG_VIDEO_HEXIUM_GEMINI) += hexium_gemini.o
-obj-$(CONFIG_VIDEO_DPC) += dpc7146.o
-obj-$(CONFIG_TUNER_3036) += tuner-3036.o
 
 obj-$(CONFIG_VIDEOBUF_GEN) += videobuf-core.o
 obj-$(CONFIG_VIDEOBUF_DMA_SG) += videobuf-dma-sg.o
@@ -137,6 +131,7 @@ obj-$(CONFIG_VIDEO_PXA27x)  += pxa_camera.o
 obj-$(CONFIG_VIDEO_SH_MOBILE_CEU)      += sh_mobile_ceu_camera.o
 obj-$(CONFIG_SOC_CAMERA)       += soc_camera.o
 obj-$(CONFIG_SOC_CAMERA_MT9M001)       += mt9m001.o
+obj-$(CONFIG_SOC_CAMERA_MT9M111)       += mt9m111.o
 obj-$(CONFIG_SOC_CAMERA_MT9V022)       += mt9v022.o
 obj-$(CONFIG_SOC_CAMERA_PLATFORM)      += soc_camera_platform.o
 
index 9e436ad3d34b64b9d695346b238eae9438a329e9..218754b4906a7a4fee61b7840dc4b8ed1db92ad4 100644 (file)
@@ -116,6 +116,7 @@ struct ar_device {
        int width, height;
        int frame_bytes, line_bytes;
        wait_queue_head_t wait;
+       unsigned long in_use;
        struct mutex lock;
 };
 
@@ -269,7 +270,7 @@ static inline void wait_for_vertical_sync(int exp_line)
 static ssize_t ar_read(struct file *file, char *buf, size_t count, loff_t *ppos)
 {
        struct video_device *v = video_devdata(file);
-       struct ar_device *ar = v->priv;
+       struct ar_device *ar = video_get_drvdata(v);
        long ret = ar->frame_bytes;             /* return read bytes */
        unsigned long arvcr1 = 0;
        unsigned long flags;
@@ -399,7 +400,7 @@ static int ar_do_ioctl(struct inode *inode, struct file *file,
                       unsigned int cmd, void *arg)
 {
        struct video_device *dev = video_devdata(file);
-       struct ar_device *ar = dev->priv;
+       struct ar_device *ar = video_get_drvdata(dev);
 
        DEBUG(1, "ar_ioctl()\n");
        switch(cmd) {
@@ -625,7 +626,7 @@ static void ar_interrupt(int irq, void *dev)
  */
 static int ar_initialize(struct video_device *dev)
 {
-       struct ar_device *ar = dev->priv;
+       struct ar_device *ar = video_get_drvdata(dev);
        unsigned long cr = 0;
        int i,found=0;
 
@@ -732,7 +733,7 @@ static int ar_initialize(struct video_device *dev)
 
 void ar_release(struct video_device *vfd)
 {
-       struct ar_device *ar = vfd->priv;
+       struct ar_device *ar = video_get_drvdata(vfd);
        mutex_lock(&ar->lock);
        video_device_release(vfd);
 }
@@ -742,10 +743,23 @@ void ar_release(struct video_device *vfd)
  * Video4Linux Module functions
  *
  ****************************************************************************/
+static struct ar_device ardev;
+
+static int ar_exclusive_open(struct inode *inode, struct file *file)
+{
+       return test_and_set_bit(0, &ardev.in_use) ? -EBUSY : 0;
+}
+
+static int ar_exclusive_release(struct inode *inode, struct file *file)
+{
+       clear_bit(0, &ardev.in_use);
+       return 0;
+}
+
 static const struct file_operations ar_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = ar_exclusive_open,
+       .release        = ar_exclusive_release,
        .read           = ar_read,
        .ioctl          = ar_ioctl,
 #ifdef CONFIG_COMPAT
@@ -762,7 +776,6 @@ static struct video_device ar_template = {
 };
 
 #define ALIGN4(x)      ((((int)(x)) & 0x3) == 0)
-static struct ar_device ardev;
 
 static int __init ar_init(void)
 {
@@ -802,7 +815,7 @@ static int __init ar_init(void)
                return -ENOMEM;
        }
        memcpy(ar->vdev, &ar_template, sizeof(ar_template));
-       ar->vdev->priv = ar;
+       video_set_drvdata(ar->vdev, ar);
 
        if (vga) {
                ar->width       = AR_WIDTH_VGA;
index ed48908a90340666f0726a77fc8b59c48e3e758f..5f07a8a072b64ed119c7c7b39e760c7bd985ea8e 100644 (file)
@@ -46,7 +46,7 @@ struct au0828_board au0828_boards[] = {
 /* Tuner callback function for au0828 boards. Currently only needed
  * for HVR1500Q, which has an xc5000 tuner.
  */
-int au0828_tuner_callback(void *priv, int command, int arg)
+int au0828_tuner_callback(void *priv, int component, int command, int arg)
 {
        struct au0828_dev *dev = priv;
 
index ba94be7e0ac1cdc65fb767d28cb8466e85cf9767..f0fcdb4769d73697e8d8a4ac9381854f2b9208f0 100644 (file)
@@ -36,11 +36,39 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
 #define _AU0828_BULKPIPE 0x83
 #define _BULKPIPESIZE 0xe522
 
+static u8 hauppauge_hvr950q_led_states[] = {
+       0x00, /* off */
+       0x02, /* yellow */
+       0x04, /* green */
+};
+
+static struct au8522_led_config hauppauge_hvr950q_led_cfg = {
+       .gpio_output = 0x00e0,
+       .gpio_output_enable  = 0x6006,
+       .gpio_output_disable = 0x0660,
+
+       .gpio_leds = 0x00e2,
+       .led_states  = hauppauge_hvr950q_led_states,
+       .num_led_states = sizeof(hauppauge_hvr950q_led_states),
+
+       .vsb8_strong   = 20 /* dB */ * 10,
+       .qam64_strong  = 25 /* dB */ * 10,
+       .qam256_strong = 32 /* dB */ * 10,
+};
+
 static struct au8522_config hauppauge_hvr950q_config = {
        .demod_address = 0x8e >> 1,
        .status_mode   = AU8522_DEMODLOCKING,
        .qam_if        = AU8522_IF_6MHZ,
        .vsb_if        = AU8522_IF_6MHZ,
+       .led_cfg       = &hauppauge_hvr950q_led_cfg,
+};
+
+static struct au8522_config fusionhdtv7usb_config = {
+       .demod_address = 0x8e >> 1,
+       .status_mode   = AU8522_DEMODLOCKING,
+       .qam_if        = AU8522_IF_6MHZ,
+       .vsb_if        = AU8522_IF_6MHZ,
 };
 
 static struct au8522_config hauppauge_woodbury_config = {
@@ -53,7 +81,6 @@ static struct au8522_config hauppauge_woodbury_config = {
 static struct xc5000_config hauppauge_hvr950q_tunerconfig = {
        .i2c_address      = 0x61,
        .if_khz           = 6000,
-       .tuner_callback   = au0828_tuner_callback
 };
 
 static struct mxl5007t_config mxl5007t_hvr950q_config = {
@@ -353,14 +380,12 @@ int au0828_dvb_register(struct au0828_dev *dev)
        switch (dev->board) {
        case AU0828_BOARD_HAUPPAUGE_HVR850:
        case AU0828_BOARD_HAUPPAUGE_HVR950Q:
-       case AU0828_BOARD_DVICO_FUSIONHDTV7:
                dvb->frontend = dvb_attach(au8522_attach,
                                &hauppauge_hvr950q_config,
                                &dev->i2c_adap);
                if (dvb->frontend != NULL)
-                       dvb_attach(xc5000_attach, dvb->frontend,
-                               &dev->i2c_adap,
-                               &hauppauge_hvr950q_tunerconfig, dev);
+                       dvb_attach(xc5000_attach, dvb->frontend, &dev->i2c_adap,
+                                  &hauppauge_hvr950q_tunerconfig);
                break;
        case AU0828_BOARD_HAUPPAUGE_HVR950Q_MXL:
                dvb->frontend = dvb_attach(au8522_attach,
@@ -380,6 +405,16 @@ int au0828_dvb_register(struct au0828_dev *dev)
                                   0x60, &dev->i2c_adap,
                                   &hauppauge_woodbury_tunerconfig);
                break;
+       case AU0828_BOARD_DVICO_FUSIONHDTV7:
+               dvb->frontend = dvb_attach(au8522_attach,
+                               &fusionhdtv7usb_config,
+                               &dev->i2c_adap);
+               if (dvb->frontend != NULL) {
+                       dvb_attach(xc5000_attach, dvb->frontend,
+                               &dev->i2c_adap,
+                               &hauppauge_hvr950q_tunerconfig);
+               }
+               break;
        default:
                printk(KERN_WARNING "The frontend of your DVB/ATSC card "
                       "isn't supported yet\n");
@@ -390,6 +425,8 @@ int au0828_dvb_register(struct au0828_dev *dev)
                       __func__);
                return -1;
        }
+       /* define general-purpose callback pointer */
+       dvb->frontend->callback = au0828_tuner_callback;
 
        /* register everything */
        ret = dvb_register(dev);
index 4f10ff300135fcedec9f9c5d5362bc2b7ec0cb65..9d6a1161dc98f3801bdee3cf614c88696f7b7e5f 100644 (file)
@@ -103,7 +103,8 @@ extern int au0828_debug;
 extern struct au0828_board au0828_boards[];
 extern struct usb_device_id au0828_usb_id_table[];
 extern void au0828_gpio_setup(struct au0828_dev *dev);
-extern int au0828_tuner_callback(void *priv, int command, int arg);
+extern int au0828_tuner_callback(void *priv, int component,
+                                int command, int arg);
 extern void au0828_card_setup(struct au0828_dev *dev);
 
 /* ----------------------------------------------------------- */
index 98ee2d8feb34ecbcb5282112e1b49a0e7b5957f6..ab2ce4d7b5de0dc3d822dd9b97d23f1bd358d807 100644 (file)
@@ -68,8 +68,8 @@ MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
 /* ----------------------------------------------------------------------- */
 
-#define REG_OFFSET     0xDA
-#define BT856_NR_REG   6
+#define BT856_REG_OFFSET       0xDA
+#define BT856_NR_REG           6
 
 struct bt856 {
        unsigned char reg[BT856_NR_REG];
@@ -89,7 +89,7 @@ bt856_write (struct i2c_client *client,
 {
        struct bt856 *encoder = i2c_get_clientdata(client);
 
-       encoder->reg[reg - REG_OFFSET] = value;
+       encoder->reg[reg - BT856_REG_OFFSET] = value;
        return i2c_smbus_write_byte_data(client, reg, value);
 }
 
@@ -103,7 +103,7 @@ bt856_setbit (struct i2c_client *client,
 
        return bt856_write(client, reg,
                           (encoder->
-                           reg[reg - REG_OFFSET] & ~(1 << bit)) |
+                           reg[reg - BT856_REG_OFFSET] & ~(1 << bit)) |
                            (value ? (1 << bit) : 0));
 }
 
index 6081edc362df4fb8adad2d87794cc2ba8990bb21..13742b0bbe3e10d61fa4970a445dd749a3702850 100644 (file)
@@ -305,7 +305,7 @@ static struct CARD {
        { 0x00261822, BTTV_BOARD_TWINHAN_DST,   "DNTV Live! Mini "},
        { 0xd200dbc0, BTTV_BOARD_DVICO_FUSIONHDTV_2,    "DViCO FusionHDTV 2" },
        { 0x763c008a, BTTV_BOARD_GEOVISION_GV600,       "GeoVision GV-600" },
-
+       { 0x18011000, BTTV_BOARD_ENLTV_FM_2,    "Encore ENL TV-FM-2" },
        { 0, -1, NULL }
 };
 
@@ -3037,6 +3037,31 @@ struct tvcard bttv_tvcards[] = {
                .has_radio      = 1,
                .has_remote     = 1,
        },
+       [BTTV_BOARD_ENLTV_FM_2] = {
+               /* Encore TV Tuner Pro ENL TV-FM-2
+                  Mauro Carvalho Chehab <mchehab@infradead.org */
+               .name           = "Encore ENL TV-FM-2",
+               .video_inputs   = 3,
+               .audio_inputs   = 1,
+               .tuner          = 0,
+               .svhs           = 2,
+               /* bit 6          -> IR disabled
+                  bit 18/17 = 00 -> mute
+                              01 -> enable external audio input
+                              10 -> internal audio input (mono?)
+                              11 -> internal audio input
+                */
+               .gpiomask       = 0x060040,
+               .muxsel         = { 2, 3, 3 },
+               .gpiomux        = { 0x60000, 0x60000, 0x20000, 0x20000 },
+               .gpiomute       = 0,
+               .tuner_type     = TUNER_TCL_MF02GIP_5N,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .pll            = PLL_28,
+               .has_radio      = 1,
+               .has_remote     = 1,
+       }
 };
 
 static const unsigned int bttv_num_tvcards = ARRAY_SIZE(bttv_tvcards);
index 933eaef41eadd4b3be9e404924d22fb316c1bd70..5858bf5ff41c3da1392bb21d337d13713bf56c45 100644 (file)
@@ -76,9 +76,9 @@ static unsigned int gbuffers = 8;
 static unsigned int gbufsize = 0x208000;
 static unsigned int reset_crop = 1;
 
-static int video_nr = -1;
-static int radio_nr = -1;
-static int vbi_nr = -1;
+static int video_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
+static int radio_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
+static int vbi_nr[BTTV_MAX] = { [0 ... (BTTV_MAX-1)] = -1 };
 static int debug_latency;
 
 static unsigned int fdsr;
@@ -108,9 +108,6 @@ module_param(irq_debug,         int, 0644);
 module_param(debug_latency,     int, 0644);
 
 module_param(fdsr,              int, 0444);
-module_param(video_nr,          int, 0444);
-module_param(radio_nr,          int, 0444);
-module_param(vbi_nr,            int, 0444);
 module_param(gbuffers,          int, 0444);
 module_param(gbufsize,          int, 0444);
 module_param(reset_crop,        int, 0444);
@@ -130,7 +127,10 @@ module_param(uv_ratio,          int, 0444);
 module_param(full_luma_range,   int, 0444);
 module_param(coring,            int, 0444);
 
-module_param_array(radio, int, NULL, 0444);
+module_param_array(radio,       int, NULL, 0444);
+module_param_array(video_nr,    int, NULL, 0444);
+module_param_array(radio_nr,    int, NULL, 0444);
+module_param_array(vbi_nr,      int, NULL, 0444);
 
 MODULE_PARM_DESC(radio,"The TV card supports radio, default is 0 (no)");
 MODULE_PARM_DESC(bigendian,"byte order of the framebuffer, default is native endian");
@@ -152,6 +152,9 @@ MODULE_PARM_DESC(irq_iswitch,"switch inputs in irq handler");
 MODULE_PARM_DESC(uv_ratio,"ratio between u and v gains, default is 50");
 MODULE_PARM_DESC(full_luma_range,"use the full luma range, default is 0 (no)");
 MODULE_PARM_DESC(coring,"set the luma coring level, default is 0 (no)");
+MODULE_PARM_DESC(video_nr, "video device numbers");
+MODULE_PARM_DESC(vbi_nr, "vbi device numbers");
+MODULE_PARM_DESC(radio_nr, "radio device numbers");
 
 MODULE_DESCRIPTION("bttv - v4l/v4l2 driver module for bt848/878 based cards");
 MODULE_AUTHOR("Ralph Metzler & Marcus Metzler & Gerd Knorr");
@@ -1367,7 +1370,7 @@ static void init_irqreg(struct bttv *btv)
                        (btv->gpioirq ? BT848_INT_GPINT : 0) |
                        BT848_INT_SCERR |
                        (fdsr ? BT848_INT_FDSR : 0) |
-                       BT848_INT_RISCI|BT848_INT_OCERR|BT848_INT_VPRES|
+                       BT848_INT_RISCI | BT848_INT_OCERR |
                        BT848_INT_FMTCHG|BT848_INT_HLOCK|
                        BT848_INT_I2CDONE,
                        BT848_INT_MASK);
@@ -2661,18 +2664,6 @@ static int bttv_querycap(struct file *file, void  *priv,
        return 0;
 }
 
-static int bttv_enum_fmt_vbi_cap(struct file *file, void  *priv,
-                               struct v4l2_fmtdesc *f)
-{
-       if (0 != f->index)
-               return -EINVAL;
-
-       f->pixelformat = V4L2_PIX_FMT_GREY;
-       strcpy(f->description, "vbi data");
-
-       return 0;
-}
-
 static int bttv_enum_fmt_cap_ovr(struct v4l2_fmtdesc *f)
 {
        int index = -1, i;
@@ -3227,6 +3218,7 @@ static int bttv_open(struct inode *inode, struct file *file)
 
        dprintk(KERN_DEBUG "bttv: open minor=%d\n",minor);
 
+       lock_kernel();
        for (i = 0; i < bttv_num; i++) {
                if (bttvs[i].video_dev &&
                    bttvs[i].video_dev->minor == minor) {
@@ -3241,16 +3233,20 @@ static int bttv_open(struct inode *inode, struct file *file)
                        break;
                }
        }
-       if (NULL == btv)
+       if (NULL == btv) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        dprintk(KERN_DEBUG "bttv%d: open called (type=%s)\n",
                btv->c.nr,v4l2_type_names[type]);
 
        /* allocate per filehandle data */
        fh = kmalloc(sizeof(*fh),GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
        file->private_data = fh;
        *fh = btv->init;
        fh->type = type;
@@ -3270,6 +3266,7 @@ static int bttv_open(struct inode *inode, struct file *file)
                            sizeof(struct bttv_buffer),
                            fh);
        set_tvnorm(btv,btv->tvnorm);
+       set_input(btv, btv->input, btv->tvnorm);
 
        btv->users++;
 
@@ -3290,6 +3287,7 @@ static int bttv_open(struct inode *inode, struct file *file)
        bttv_vbi_fmt_reset(&fh->vbi_fmt, btv->tvnorm);
 
        bttv_field_count(btv);
+       unlock_kernel();
        return 0;
 }
 
@@ -3330,6 +3328,10 @@ static int bttv_release(struct inode *inode, struct file *file)
 
        btv->users--;
        bttv_field_count(btv);
+
+       if (!btv->users)
+               audio_mute(btv, 1);
+
        return 0;
 }
 
@@ -3367,7 +3369,6 @@ static const struct v4l2_ioctl_ops bttv_ioctl_ops = {
        .vidioc_g_fmt_vid_overlay       = bttv_g_fmt_vid_overlay,
        .vidioc_try_fmt_vid_overlay     = bttv_try_fmt_vid_overlay,
        .vidioc_s_fmt_vid_overlay       = bttv_s_fmt_vid_overlay,
-       .vidioc_enum_fmt_vbi_cap        = bttv_enum_fmt_vbi_cap,
        .vidioc_g_fmt_vbi_cap           = bttv_g_fmt_vbi_cap,
        .vidioc_try_fmt_vbi_cap         = bttv_try_fmt_vbi_cap,
        .vidioc_s_fmt_vbi_cap           = bttv_s_fmt_vbi_cap,
@@ -3430,21 +3431,26 @@ static int radio_open(struct inode *inode, struct file *file)
 
        dprintk("bttv: open minor=%d\n",minor);
 
+       lock_kernel();
        for (i = 0; i < bttv_num; i++) {
                if (bttvs[i].radio_dev && bttvs[i].radio_dev->minor == minor) {
                        btv = &bttvs[i];
                        break;
                }
        }
-       if (NULL == btv)
+       if (NULL == btv) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        dprintk("bttv%d: open called (radio)\n",btv->c.nr);
 
        /* allocate per filehandle data */
        fh = kmalloc(sizeof(*fh), GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
        file->private_data = fh;
        *fh = btv->init;
        v4l2_prio_open(&btv->prio, &fh->prio);
@@ -3457,6 +3463,7 @@ static int radio_open(struct inode *inode, struct file *file)
        audio_input(btv,TVAUDIO_INPUT_RADIO);
 
        mutex_unlock(&btv->lock);
+       unlock_kernel();
        return 0;
 }
 
@@ -4235,7 +4242,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
 
        if (NULL == btv->video_dev)
                goto err;
-       if (video_register_device(btv->video_dev,VFL_TYPE_GRABBER,video_nr)<0)
+       if (video_register_device(btv->video_dev, VFL_TYPE_GRABBER,
+                                 video_nr[btv->c.nr]) < 0)
                goto err;
        printk(KERN_INFO "bttv%d: registered device video%d\n",
               btv->c.nr,btv->video_dev->minor & 0x1f);
@@ -4251,7 +4259,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
 
        if (NULL == btv->vbi_dev)
                goto err;
-       if (video_register_device(btv->vbi_dev,VFL_TYPE_VBI,vbi_nr)<0)
+       if (video_register_device(btv->vbi_dev, VFL_TYPE_VBI,
+                                 vbi_nr[btv->c.nr]) < 0)
                goto err;
        printk(KERN_INFO "bttv%d: registered device vbi%d\n",
               btv->c.nr,btv->vbi_dev->minor & 0x1f);
@@ -4262,7 +4271,8 @@ static int __devinit bttv_register_video(struct bttv *btv)
        btv->radio_dev = vdev_init(btv, &radio_template, "radio");
        if (NULL == btv->radio_dev)
                goto err;
-       if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,radio_nr)<0)
+       if (video_register_device(btv->radio_dev, VFL_TYPE_RADIO,
+                                 radio_nr[btv->c.nr]) < 0)
                goto err;
        printk(KERN_INFO "bttv%d: registered device radio%d\n",
               btv->c.nr,btv->radio_dev->minor & 0x1f);
index a38af98f4cae9e33ad4f47cd1873407a47c34dab..2f289d981fe62d3b3b2fba62ccc824e3d303935d 100644 (file)
@@ -28,8 +28,8 @@
 #include "bttvp.h"
 
 
-static int debug;
-module_param(debug, int, 0644);    /* debug level (0,1,2) */
+static int ir_debug;
+module_param(ir_debug, int, 0644);
 static int repeat_delay = 500;
 module_param(repeat_delay, int, 0644);
 static int repeat_period = 33;
@@ -40,6 +40,12 @@ module_param(ir_rc5_remote_gap, int, 0644);
 static int ir_rc5_key_timeout = 200;
 module_param(ir_rc5_key_timeout, int, 0644);
 
+#undef dprintk
+#define dprintk(arg...) do {   \
+       if (ir_debug >= 1)      \
+               printk(arg);    \
+} while (0)
+
 #define DEVNAME "bttv-input"
 
 /* ---------------------------------------------------------------------- */
@@ -79,6 +85,45 @@ static void ir_handle_key(struct bttv *btv)
 
 }
 
+static void ir_enltv_handle_key(struct bttv *btv)
+{
+       struct card_ir *ir = btv->remote;
+       u32 gpio, data, keyup;
+
+       /* read gpio value */
+       gpio = bttv_gpio_read(&btv->c);
+
+       /* extract data */
+       data = ir_extract_bits(gpio, ir->mask_keycode);
+
+       /* Check if it is keyup */
+       keyup = (gpio & ir->mask_keyup) ? 1 << 31 : 0;
+
+       if ((ir->last_gpio & 0x7f) != data) {
+               dprintk(KERN_INFO DEVNAME ": gpio=0x%x code=%d | %s\n",
+                       gpio, data,
+                       (gpio & ir->mask_keyup) ? " up" : "up/down");
+
+               ir_input_keydown(ir->dev, &ir->ir, data, data);
+               if (keyup)
+                       ir_input_nokey(ir->dev, &ir->ir);
+       } else {
+               if ((ir->last_gpio & 1 << 31) == keyup)
+                       return;
+
+               dprintk(KERN_INFO DEVNAME ":(cnt) gpio=0x%x code=%d | %s\n",
+                       gpio, data,
+                       (gpio & ir->mask_keyup) ? " up" : "down");
+
+               if (keyup)
+                       ir_input_nokey(ir->dev, &ir->ir);
+               else
+                       ir_input_keydown(ir->dev, &ir->ir, data, data);
+       }
+
+       ir->last_gpio = data | keyup;
+}
+
 void bttv_input_irq(struct bttv *btv)
 {
        struct card_ir *ir = btv->remote;
@@ -92,7 +137,10 @@ static void bttv_input_timer(unsigned long data)
        struct bttv *btv = (struct bttv*)data;
        struct card_ir *ir = btv->remote;
 
-       ir_handle_key(btv);
+       if (btv->c.type == BTTV_BOARD_ENLTV_FM_2)
+               ir_enltv_handle_key(btv);
+       else
+               ir_handle_key(btv);
        mod_timer(&ir->timer, jiffies + msecs_to_jiffies(ir->polling));
 }
 
@@ -284,6 +332,14 @@ int bttv_input_init(struct bttv *btv)
                ir->mask_keyup   = 0x006000;
                ir->polling      = 50; /* ms */
                break;
+       case BTTV_BOARD_ENLTV_FM_2:
+               ir_codes         = ir_codes_encore_enltv2;
+               ir->mask_keycode = 0x00fd00;
+               ir->mask_keyup   = 0x000080;
+               ir->polling      = 1; /* ms */
+               ir->last_gpio    = ir_extract_bits(bttv_gpio_read(&btv->c),
+                                                  ir->mask_keycode);
+               break;
        }
        if (NULL == ir_codes) {
                dprintk(KERN_INFO "Ooops: IR config error [card=%d]\n", btv->c.type);
index 6d93d16c96e4609cb899da64f4fc12364705cb52..46cb90e0985b2ad7bbe8193da8291d16eaf6a38b 100644 (file)
 #define BTTV_BOARD_TYPHOON_TVTUNERPCI     0x95
 #define BTTV_BOARD_GEOVISION_GV600        0x96
 #define BTTV_BOARD_KOZUMI_KTV_01C          0x97
-
+#define BTTV_BOARD_ENLTV_FM_2             0x98
 
 /* more card-specific defines */
 #define PT2254_L_CHANNEL 0x10
index 3324ab38f58c3b395f617e00c9a9c4bd957ff820..ac1b2687a20d7feca68b8ebce0758b0c5e29411c 100644 (file)
@@ -64,7 +64,7 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
                       unsigned int size)
 {
        __le32 *cpu;
-       dma_addr_t dma;
+       dma_addr_t dma = 0;
 
        if (NULL != risc->cpu && risc->size < size)
                btcx_riscmem_free(pci,risc);
index 6e39e253ce5361a5d99644e7b93d96474759b966..ace4ff9ea023b69732568db94093fbf3396682ae 100644 (file)
@@ -495,7 +495,7 @@ static void qc_set(struct qcam_device *q)
                val2 = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
                    q->transfer_scale;
        }
-       val = (val + val2 - 1) / val2;
+       val = DIV_ROUND_UP(val, val2);
        qc_command(q, 0x13);
        qc_command(q, val);
 
@@ -651,7 +651,7 @@ static long qc_capture(struct qcam_device * q, char __user *buf, unsigned long l
        transperline = q->width * q->bpp;
        divisor = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
            q->transfer_scale;
-       transperline = (transperline + divisor - 1) / divisor;
+       transperline = DIV_ROUND_UP(transperline, divisor);
 
        for (i = 0, yield = yieldlines; i < linestotrans; i++)
        {
@@ -894,10 +894,27 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
        return len;
 }
 
+static int qcam_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct video_device *dev = video_devdata(file);
+       struct qcam_device *qcam = (struct qcam_device *)dev;
+
+       return test_and_set_bit(0, &qcam->in_use) ? -EBUSY : 0;
+}
+
+static int qcam_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct video_device *dev = video_devdata(file);
+       struct qcam_device *qcam = (struct qcam_device *)dev;
+
+       clear_bit(0, &qcam->in_use);
+       return 0;
+}
+
 static const struct file_operations qcam_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = qcam_exclusive_open,
+       .release        = qcam_exclusive_release,
        .ioctl          = qcam_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -909,6 +926,7 @@ static struct video_device qcam_template=
 {
        .name           = "Connectix Quickcam",
        .fops           = &qcam_fops,
+       .release        = video_device_release_empty,
 };
 
 #define MAX_CAMS 4
index 6701dafbc0da82deca9579837464c94e3db426e0..8a60c5de09350a842dda12cae7a910d83161d35e 100644 (file)
@@ -65,4 +65,5 @@ struct qcam_device {
        int top, left;
        int status;
        unsigned int saved_bits;
+       unsigned long in_use;
 };
index 7f6c6b4bec10e7f3470d8452e1ee71b9cd90ab0e..17aa0adb346703938b650c8c8164e3789eab5f88 100644 (file)
@@ -51,6 +51,7 @@ struct qcam_device {
        int contrast, brightness, whitebal;
        int top, left;
        unsigned int bidirectional;
+       unsigned long in_use;
        struct mutex lock;
 };
 
@@ -687,11 +688,28 @@ static ssize_t qcam_read(struct file *file, char __user *buf,
        return len;
 }
 
+static int qcam_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct video_device *dev = video_devdata(file);
+       struct qcam_device *qcam = (struct qcam_device *)dev;
+
+       return test_and_set_bit(0, &qcam->in_use) ? -EBUSY : 0;
+}
+
+static int qcam_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct video_device *dev = video_devdata(file);
+       struct qcam_device *qcam = (struct qcam_device *)dev;
+
+       clear_bit(0, &qcam->in_use);
+       return 0;
+}
+
 /* video device template */
 static const struct file_operations qcam_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = qcam_exclusive_open,
+       .release        = qcam_exclusive_release,
        .ioctl          = qcam_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -704,6 +722,7 @@ static struct video_device qcam_template=
 {
        .name           = "Colour QuickCam",
        .fops           = &qcam_fops,
+       .release        = video_device_release_empty,
 };
 
 /* Initialize the QuickCam driver control structure. */
index 08efbe7254ff428d51e5bb734715754f1acdb2f6..fc9497bdd322f008c6673ada3c7468be051c3706 100644 (file)
@@ -1476,9 +1476,12 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
 {
        struct cafe_camera *cam;
 
+       lock_kernel();
        cam = cafe_find_dev(iminor(inode));
-       if (cam == NULL)
+       if (cam == NULL) {
+               unlock_kernel();
                return -ENODEV;
+       }
        filp->private_data = cam;
 
        mutex_lock(&cam->s_mutex);
@@ -1490,6 +1493,7 @@ static int cafe_v4l_open(struct inode *inode, struct file *filp)
        }
        (cam->users)++;
        mutex_unlock(&cam->s_mutex);
+       unlock_kernel();
        return 0;
 }
 
index a661800b0e69fdefec154a23b69462fc448da2c1..c325e926de8a310f09eb15b3e0548a51d67e2e96 100644 (file)
@@ -3155,7 +3155,7 @@ static void put_cam(struct cpia_camera_ops* ops)
 static int cpia_open(struct inode *inode, struct file *file)
 {
        struct video_device *dev = video_devdata(file);
-       struct cam_data *cam = dev->priv;
+       struct cam_data *cam = video_get_drvdata(dev);
        int err;
 
        if (!cam) {
@@ -3202,7 +3202,7 @@ static int cpia_open(struct inode *inode, struct file *file)
 
        /* Set ownership of /proc/cpia/videoX to current user */
        if(cam->proc_entry)
-               cam->proc_entry->uid = current->uid;
+               cam->proc_entry->uid = current_uid();
 
        /* set mark for loading first frame uncompressed */
        cam->first_frame = 1;
@@ -3232,7 +3232,7 @@ static int cpia_open(struct inode *inode, struct file *file)
 static int cpia_close(struct inode *inode, struct file *file)
 {
        struct  video_device *dev = file->private_data;
-       struct cam_data *cam = dev->priv;
+       struct cam_data *cam = video_get_drvdata(dev);
 
        if (cam->ops) {
                /* Return ownership of /proc/cpia/videoX to root */
@@ -3284,7 +3284,7 @@ static ssize_t cpia_read(struct file *file, char __user *buf,
                         size_t count, loff_t *ppos)
 {
        struct video_device *dev = file->private_data;
-       struct cam_data *cam = dev->priv;
+       struct cam_data *cam = video_get_drvdata(dev);
        int err;
 
        /* make this _really_ smp and multithread-safe */
@@ -3341,7 +3341,7 @@ static int cpia_do_ioctl(struct inode *inode, struct file *file,
                         unsigned int ioctlnr, void *arg)
 {
        struct video_device *dev = file->private_data;
-       struct cam_data *cam = dev->priv;
+       struct cam_data *cam = video_get_drvdata(dev);
        int retval = 0;
 
        if (!cam || !cam->ops)
@@ -3739,7 +3739,7 @@ static int cpia_mmap(struct file *file, struct vm_area_struct *vma)
        unsigned long start = vma->vm_start;
        unsigned long size  = vma->vm_end - vma->vm_start;
        unsigned long page, pos;
-       struct cam_data *cam = dev->priv;
+       struct cam_data *cam = video_get_drvdata(dev);
        int retval;
 
        if (!cam || !cam->ops)
@@ -3801,6 +3801,7 @@ static const struct file_operations cpia_fops = {
 static struct video_device cpia_template = {
        .name           = "CPiA Camera",
        .fops           = &cpia_fops,
+       .release        = video_device_release_empty,
 };
 
 /* initialise cam_data structure  */
@@ -3928,7 +3929,7 @@ static void init_camera_struct(struct cam_data *cam,
        cam->proc_entry = NULL;
 
        memcpy(&cam->vdev, &cpia_template, sizeof(cpia_template));
-       cam->vdev.priv = cam;
+       video_set_drvdata(&cam->vdev, cam);
 
        cam->curframe = 0;
        for (i = 0; i < FRAME_NUM; i++) {
index af8b9ec8e3587bd64ff37cf2c29a4df1fe5118fa..7e791b6923f986913095339ec5392d420fcc88a0 100644 (file)
@@ -1537,7 +1537,7 @@ static int config_sensor_500(struct camera_data *cam,
  *
  *  This sets all user changeable properties to the values in cam->params.
  *****************************************************************************/
-int set_all_properties(struct camera_data *cam)
+static int set_all_properties(struct camera_data *cam)
 {
        /**
         * Don't set target_kb here, it will be set later.
@@ -1588,7 +1588,7 @@ void cpia2_save_camera_state(struct camera_data *cam)
  *  get_color_params
  *
  *****************************************************************************/
-void get_color_params(struct camera_data *cam)
+static void get_color_params(struct camera_data *cam)
 {
        cpia2_do_command(cam, CPIA2_CMD_GET_VP_BRIGHTNESS, TRANSFER_READ, 0);
        cpia2_do_command(cam, CPIA2_CMD_GET_VP_SATURATION, TRANSFER_READ, 0);
@@ -1881,7 +1881,7 @@ void cpia2_set_saturation(struct camera_data *cam, unsigned char value)
  *  wake_system
  *
  *****************************************************************************/
-void wake_system(struct camera_data *cam)
+static void wake_system(struct camera_data *cam)
 {
        cpia2_do_command(cam, CPIA2_CMD_SET_WAKEUP, TRANSFER_WRITE, 0);
 }
@@ -1892,7 +1892,7 @@ void wake_system(struct camera_data *cam)
  *
  *  Valid for STV500 sensor only
  *****************************************************************************/
-void set_lowlight_boost(struct camera_data *cam)
+static void set_lowlight_boost(struct camera_data *cam)
 {
        struct cpia2_command cmd;
 
@@ -2169,7 +2169,7 @@ void cpia2_dbg_dump_registers(struct camera_data *cam)
  *
  *  Sets all values to the defaults
  *****************************************************************************/
-void reset_camera_struct(struct camera_data *cam)
+static void reset_camera_struct(struct camera_data *cam)
 {
        /***
         * The following parameter values are the defaults from the register map.
index a8a199047cbde4c448dbfb736beedbb78d3c4e08..73511a542077b40c9c7ff32e795fc15789a557b9 100644 (file)
@@ -478,7 +478,7 @@ int cpia2_usb_change_streaming_alternate(struct camera_data *cam,
  * set_alternate
  *
  *****************************************************************************/
-int set_alternate(struct camera_data *cam, unsigned int alt)
+static int set_alternate(struct camera_data *cam, unsigned int alt)
 {
        int ret = 0;
 
index eb9f15cd4c45c9884170fb9599e99f6544e4e288..897e8d1a5c3c0a08cadc5dfa470767c90095573d 100644 (file)
@@ -241,8 +241,7 @@ static struct v4l2_queryctrl controls[] = {
  *****************************************************************************/
 static int cpia2_open(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct camera_data *cam = video_get_drvdata(dev);
+       struct camera_data *cam = video_drvdata(file);
        int retval = 0;
 
        if (!cam) {
@@ -357,8 +356,7 @@ static int cpia2_close(struct inode *inode, struct file *file)
 static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
                              loff_t *off)
 {
-       struct video_device *dev = video_devdata(file);
-       struct camera_data *cam = video_get_drvdata(dev);
+       struct camera_data *cam = video_drvdata(file);
        int noblock = file->f_flags&O_NONBLOCK;
 
        struct cpia2_fh *fh = file->private_data;
@@ -382,9 +380,7 @@ static ssize_t cpia2_v4l_read(struct file *file, char __user *buf, size_t count,
  *****************************************************************************/
 static unsigned int cpia2_v4l_poll(struct file *filp, struct poll_table_struct *wait)
 {
-       struct video_device *dev = video_devdata(filp);
-       struct camera_data *cam = video_get_drvdata(dev);
-
+       struct camera_data *cam = video_drvdata(filp);
        struct cpia2_fh *fh = filp->private_data;
 
        if(!cam)
@@ -1579,8 +1575,7 @@ static int ioctl_dqbuf(void *arg,struct camera_data *cam, struct file *file)
 static int cpia2_do_ioctl(struct inode *inode, struct file *file,
                          unsigned int ioctl_nr, void *arg)
 {
-       struct video_device *dev = video_devdata(file);
-       struct camera_data *cam = video_get_drvdata(dev);
+       struct camera_data *cam = video_drvdata(file);
        int retval = 0;
 
        if (!cam)
@@ -1860,9 +1855,8 @@ static int cpia2_ioctl(struct inode *inode, struct file *file,
  *****************************************************************************/
 static int cpia2_mmap(struct file *file, struct vm_area_struct *area)
 {
+       struct camera_data *cam = video_drvdata(file);
        int retval;
-       struct video_device *dev = video_devdata(file);
-       struct camera_data *cam = video_get_drvdata(dev);
 
        /* Priority check */
        struct cpia2_fh *fh = file->private_data;
index b23d2e26120f7f80cf6ad66113cf346700fea432..f7bf0edf93f9dbf9beceac7fddf5f2a07f79dbf7 100644 (file)
@@ -2,7 +2,7 @@ cx18-objs    := cx18-driver.o cx18-cards.o cx18-i2c.o cx18-firmware.o cx18-gpio.
        cx18-queue.o cx18-streams.o cx18-fileops.o cx18-ioctl.o cx18-controls.o \
        cx18-mailbox.o cx18-vbi.o cx18-audio.o cx18-video.o cx18-irq.o \
        cx18-av-core.o cx18-av-audio.o cx18-av-firmware.o cx18-av-vbi.o cx18-scb.o \
-       cx18-dvb.o
+       cx18-dvb.o cx18-io.o
 
 obj-$(CONFIG_VIDEO_CX18) += cx18.o
 
index 6d5b94fc70879eec06835a8c958481019a3440bf..57beddf0af4df2d3936c69c3044d60c200ca67c2 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-i2c.h"
 #include "cx18-cards.h"
 #include "cx18-audio.h"
@@ -60,10 +61,10 @@ int cx18_audio_set_io(struct cx18 *cx)
        if (err)
                return err;
 
-       val = read_reg(CX18_AUDIO_ENABLE) & ~0x30;
+       val = cx18_read_reg(cx, CX18_AUDIO_ENABLE) & ~0x30;
        val |= (audio_input > CX18_AV_AUDIO_SERIAL2) ? 0x20 :
                                        (audio_input << 4);
-       write_reg(val | 0xb00, CX18_AUDIO_ENABLE);
+       cx18_write_reg(cx, val | 0xb00, CX18_AUDIO_ENABLE);
        cx18_vapi(cx, CX18_APU_RESETAI, 1, 0);
        return 0;
 }
index 3b0a2c450605e84415289a1cc21e667f0ba7b531..73f5141a42d1270608f4017787230e52a49752c0 100644 (file)
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 
 int cx18_av_write(struct cx18 *cx, u16 addr, u8 value)
 {
-       u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3));
+       u32 reg = 0xc40000 + (addr & ~3);
        u32 mask = 0xff;
        int shift = (addr & 3) * 8;
+       u32 x = cx18_read_reg(cx, reg);
 
        x = (x & ~(mask << shift)) | ((u32)value << shift);
-       writel(x, cx->reg_mem + 0xc40000 + (addr & ~3));
+       cx18_write_reg(cx, x, reg);
        return 0;
 }
 
 int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value)
 {
-       writel(value, cx->reg_mem + 0xc40000 + addr);
+       cx18_write_reg(cx, value, 0xc40000 + addr);
+       return 0;
+}
+
+int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value)
+{
+       cx18_write_reg_noretry(cx, value, 0xc40000 + addr);
        return 0;
 }
 
 u8 cx18_av_read(struct cx18 *cx, u16 addr)
 {
-       u32 x = readl(cx->reg_mem + 0xc40000 + (addr & ~3));
+       u32 x = cx18_read_reg(cx, 0xc40000 + (addr & ~3));
        int shift = (addr & 3) * 8;
 
        return (x >> shift) & 0xff;
@@ -50,7 +58,12 @@ u8 cx18_av_read(struct cx18 *cx, u16 addr)
 
 u32 cx18_av_read4(struct cx18 *cx, u16 addr)
 {
-       return readl(cx->reg_mem + 0xc40000 + addr);
+       return cx18_read_reg(cx, 0xc40000 + addr);
+}
+
+u32 cx18_av_read4_noretry(struct cx18 *cx, u16 addr)
+{
+       return cx18_read_reg_noretry(cx, 0xc40000 + addr);
 }
 
 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned and_mask,
index eb61fa1e0965bbbcebccbcc0ee86ec4b9939ed55..b67d8df20cc66a7533a34e93c95982a91ac6accb 100644 (file)
@@ -301,8 +301,10 @@ struct cx18_av_state {
 /* cx18_av-core.c                                                         */
 int cx18_av_write(struct cx18 *cx, u16 addr, u8 value);
 int cx18_av_write4(struct cx18 *cx, u16 addr, u32 value);
+int cx18_av_write4_noretry(struct cx18 *cx, u16 addr, u32 value);
 u8 cx18_av_read(struct cx18 *cx, u16 addr);
 u32 cx18_av_read4(struct cx18 *cx, u16 addr);
+u32 cx18_av_read4_noretry(struct cx18 *cx, u16 addr);
 int cx18_av_and_or(struct cx18 *cx, u16 addr, unsigned mask, u8 value);
 int cx18_av_and_or4(struct cx18 *cx, u16 addr, u32 mask, u32 value);
 int cx18_av_cmd(struct cx18 *cx, unsigned int cmd, void *arg);
index e996a4e3123a3a01a2cae74a152d6131f79e594a..522a035b2e8fb5c065e334ad3fc2482af654c000 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include <linux/firmware.h>
 
 #define CX18_AUDIO_ENABLE 0xc72014
@@ -49,7 +50,7 @@ int cx18_av_loadfw(struct cx18 *cx)
                cx18_av_write4(cx, 0x8100, 0x00010000);
 
                /* Put the 8051 in reset and enable firmware upload */
-               cx18_av_write4(cx, CXADEC_DL_CTL, 0x0F000000);
+               cx18_av_write4_noretry(cx, CXADEC_DL_CTL, 0x0F000000);
 
                ptr = fw->data;
                size = fw->size;
@@ -58,22 +59,28 @@ int cx18_av_loadfw(struct cx18 *cx)
                        u32 dl_control = 0x0F000000 | i | ((u32)ptr[i] << 16);
                        u32 value = 0;
                        int retries2;
+                       int unrec_err = 0;
 
-                       for (retries2 = 0; retries2 < 5; retries2++) {
-                               cx18_av_write4(cx, CXADEC_DL_CTL, dl_control);
+                       for (retries2 = 0; retries2 < CX18_MAX_MMIO_RETRIES;
+                            retries2++) {
+                               cx18_av_write4_noretry(cx, CXADEC_DL_CTL,
+                                                      dl_control);
                                udelay(10);
-                               value = cx18_av_read4(cx, CXADEC_DL_CTL);
+                               value = cx18_av_read4_noretry(cx,
+                                                             CXADEC_DL_CTL);
                                if (value == dl_control)
                                        break;
                                /* Check if we can correct the byte by changing
                                   the address.  We can only write the lower
                                   address byte of the address. */
                                if ((value & 0x3F00) != (dl_control & 0x3F00)) {
-                                       retries2 = 5;
+                                       unrec_err = 1;
                                        break;
                                }
                        }
-                       if (retries2 >= 5)
+                       cx18_log_write_retries(cx, retries2,
+                                       cx->reg_mem + 0xc40000 + CXADEC_DL_CTL);
+                       if (unrec_err || retries2 >= CX18_MAX_MMIO_RETRIES)
                                break;
                }
                if (i == size)
@@ -119,10 +126,10 @@ int cx18_av_loadfw(struct cx18 *cx)
           have a name in the spec. */
        cx18_av_write4(cx, 0x09CC, 1);
 
-       v = read_reg(CX18_AUDIO_ENABLE);
-       /* If bit 11 is 1 */
+       v = cx18_read_reg(cx, CX18_AUDIO_ENABLE);
+       /* If bit 11 is 1, clear bit 10 */
        if (v & 0x800)
-               write_reg(v & 0xFFFFFBFF, CX18_AUDIO_ENABLE); /* Clear bit 10 */
+               cx18_write_reg(cx, v & 0xFFFFFBFF, CX18_AUDIO_ENABLE);
 
        /* Enable WW auto audio standard detection */
        v = cx18_av_read4(cx, CXADEC_STD_DET_CTL);
index 3cb9734ec07bf7f6314f84590430ce3ee93b7432..5efe01ebe9db368e258f8716525223d3ee1425c6 100644 (file)
@@ -292,12 +292,111 @@ static const struct cx18_card cx18_card_cnxt_raptor_pal = {
 
 /* ------------------------------------------------------------------------- */
 
+/* Toshiba Qosmio laptop internal DVB-T/Analog Hybrid Tuner */
+
+static const struct cx18_card_pci_info cx18_pci_toshiba_qosmio_dvbt[] = {
+       { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_TOSHIBA, 0x0110 },
+       { 0, 0, 0 }
+};
+
+static const struct cx18_card cx18_card_toshiba_qosmio_dvbt = {
+       .type = CX18_CARD_TOSHIBA_QOSMIO_DVBT,
+       .name = "Toshiba Qosmio DVB-T/Analog",
+       .comment = "Experimenters and photos needed for device to work well.\n"
+                 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
+       .v4l2_capabilities = CX18_CAP_ENCODER,
+       .hw_audio_ctrl = CX18_HW_CX23418,
+       .hw_all = CX18_HW_TUNER,
+       .video_inputs = {
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE6 },
+               { CX18_CARD_INPUT_SVIDEO1,    1,
+                       CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE1 },
+       },
+       .audio_inputs = {
+               { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
+               { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 1 },
+       },
+       .tuners = {
+               { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
+       },
+       .ddr = {
+               .chip_config = 0x202,
+               .refresh = 0x3bb,
+               .timing1 = 0x33320a63,
+               .timing2 = 0x0a,
+               .tune_lane = 0,
+               .initial_emrs = 0x42,
+       },
+       .xceive_pin = 15,
+       .pci_list = cx18_pci_toshiba_qosmio_dvbt,
+       .i2c = &cx18_i2c_std,
+};
+
+/* ------------------------------------------------------------------------- */
+
+/* Leadtek WinFast PVR2100 */
+
+static const struct cx18_card_pci_info cx18_pci_leadtek_pvr2100[] = {
+       { PCI_DEVICE_ID_CX23418, CX18_PCI_ID_LEADTEK, 0x6f27 },
+       { 0, 0, 0 }
+};
+
+static const struct cx18_card cx18_card_leadtek_pvr2100 = {
+       .type = CX18_CARD_LEADTEK_PVR2100,
+       .name = "Leadtek WinFast PVR2100",
+       .comment = "Experimenters and photos needed for device to work well.\n"
+                 "\tTo help, mail the ivtv-devel list (www.ivtvdriver.org).\n",
+       .v4l2_capabilities = CX18_CAP_ENCODER,
+       .hw_audio_ctrl = CX18_HW_CX23418,
+       .hw_muxer = CX18_HW_GPIO,
+       .hw_all = CX18_HW_TUNER | CX18_HW_GPIO,
+       .video_inputs = {
+               { CX18_CARD_INPUT_VID_TUNER,  0, CX18_AV_COMPOSITE2 },
+               { CX18_CARD_INPUT_SVIDEO1,    1,
+                       CX18_AV_SVIDEO_LUMA3 | CX18_AV_SVIDEO_CHROMA4 },
+               { CX18_CARD_INPUT_COMPOSITE1, 1, CX18_AV_COMPOSITE7 },
+       },
+       .audio_inputs = {
+               { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5,        0 },
+               { CX18_CARD_INPUT_LINE_IN1,  CX18_AV_AUDIO_SERIAL1, 1 },
+       },
+       .tuners = {
+               /* XC3028 tuner */
+               { .std = V4L2_STD_ALL, .tuner = TUNER_XC2028 },
+       },
+       .radio_input = { CX18_CARD_INPUT_AUD_TUNER, CX18_AV_AUDIO5, 2 },
+       .ddr = {
+               /*
+                * Pointer to proper DDR config values provided by
+                * Terry Wu <terrywu at leadtek.com.tw>
+                */
+               .chip_config = 0x303,
+               .refresh = 0x3bb,
+               .timing1 = 0x24220e83,
+               .timing2 = 0x1f,
+               .tune_lane = 0,
+               .initial_emrs = 0x2,
+       },
+       .gpio_init.initial_value = 0x6,
+       .gpio_init.direction = 0x7,
+       .gpio_audio_input = { .mask   = 0x7,
+                             .tuner  = 0x6, .linein = 0x2, .radio  = 0x2 },
+       .xceive_pin = 15,
+       .pci_list = cx18_pci_leadtek_pvr2100,
+       .i2c = &cx18_i2c_std,
+};
+
+/* ------------------------------------------------------------------------- */
+
 static const struct cx18_card *cx18_card_list[] = {
        &cx18_card_hvr1600_esmt,
        &cx18_card_hvr1600_samsung,
        &cx18_card_h900,
        &cx18_card_mpc718,
        &cx18_card_cnxt_raptor_pal,
+       &cx18_card_toshiba_qosmio_dvbt,
+       &cx18_card_leadtek_pvr2100,
 };
 
 const struct cx18_card *cx18_get_card(u16 index)
index bd18afebbf860565292b212bde83361486761d8e..085121c2b47f3844aa07e60b21f7b5e4843437b6 100644 (file)
@@ -4,6 +4,7 @@
  *  Derived from ivtv-driver.c
  *
  *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
+ *  Copyright (C) 2008  Andy Walls <awalls@radix.net>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-version.h"
 #include "cx18-cards.h"
 #include "cx18-i2c.h"
@@ -73,10 +75,14 @@ static int radio[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
                                     -1, -1, -1, -1, -1, -1, -1, -1,
                                     -1, -1, -1, -1, -1, -1, -1, -1,
                                     -1, -1, -1, -1, -1, -1, -1, -1 };
-
+static int mmio_ndelay[CX18_MAX_CARDS] = { -1, -1, -1, -1, -1, -1, -1, -1,
+                                          -1, -1, -1, -1, -1, -1, -1, -1,
+                                          -1, -1, -1, -1, -1, -1, -1, -1,
+                                          -1, -1, -1, -1, -1, -1, -1, -1 };
 static unsigned cardtype_c = 1;
 static unsigned tuner_c = 1;
 static unsigned radio_c = 1;
+static unsigned mmio_ndelay_c = 1;
 static char pal[] = "--";
 static char secam[] = "--";
 static char ntsc[] = "-";
@@ -90,15 +96,18 @@ static int enc_pcm_buffers = CX18_DEFAULT_ENC_PCM_BUFFERS;
 
 static int cx18_pci_latency = 1;
 
+int cx18_retry_mmio = 1;
 int cx18_debug;
 
 module_param_array(tuner, int, &tuner_c, 0644);
 module_param_array(radio, bool, &radio_c, 0644);
 module_param_array(cardtype, int, &cardtype_c, 0644);
+module_param_array(mmio_ndelay, int, &mmio_ndelay_c, 0644);
 module_param_string(pal, pal, sizeof(pal), 0644);
 module_param_string(secam, secam, sizeof(secam), 0644);
 module_param_string(ntsc, ntsc, sizeof(ntsc), 0644);
 module_param_named(debug, cx18_debug, int, 0644);
+module_param_named(retry_mmio, cx18_retry_mmio, int, 0644);
 module_param(cx18_pci_latency, int, 0644);
 module_param(cx18_first_minor, int, 0644);
 
@@ -121,6 +130,8 @@ MODULE_PARM_DESC(cardtype,
                 "\t\t\t 3 = Compro VideoMate H900\n"
                 "\t\t\t 4 = Yuan MPC718\n"
                 "\t\t\t 5 = Conexant Raptor PAL/SECAM\n"
+                "\t\t\t 6 = Toshiba Qosmio DVB-T/Analog\n"
+                "\t\t\t 7 = Leadtek WinFast PVR2100\n"
                 "\t\t\t 0 = Autodetect (default)\n"
                 "\t\t\t-1 = Ignore this card\n\t\t");
 MODULE_PARM_DESC(pal, "Set PAL standard: B, G, H, D, K, I, M, N, Nc, 60");
@@ -140,6 +151,14 @@ MODULE_PARM_DESC(debug,
 MODULE_PARM_DESC(cx18_pci_latency,
                 "Change the PCI latency to 64 if lower: 0 = No, 1 = Yes,\n"
                 "\t\t\tDefault: Yes");
+MODULE_PARM_DESC(retry_mmio,
+                "Check and retry memory mapped IO accesses\n"
+                "\t\t\tDefault: 1 [Yes]");
+MODULE_PARM_DESC(mmio_ndelay,
+                "Delay (ns) for each CX23418 memory mapped IO access.\n"
+                "\t\t\tTry larger values that are close to a multiple of the\n"
+                "\t\t\tPCI clock period, 30.3 ns, if your card doesn't work.\n"
+                "\t\t\tDefault: " __stringify(CX18_DEFAULT_MMIO_NDELAY));
 MODULE_PARM_DESC(enc_mpg_buffers,
                 "Encoder MPG Buffers (in MB)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_MPG_BUFFERS));
@@ -156,7 +175,7 @@ MODULE_PARM_DESC(enc_pcm_buffers,
                 "Encoder PCM buffers (in MB)\n"
                 "\t\t\tDefault: " __stringify(CX18_DEFAULT_ENC_PCM_BUFFERS));
 
-MODULE_PARM_DESC(cx18_first_minor, "Set minor assigned to first card");
+MODULE_PARM_DESC(cx18_first_minor, "Set kernel number assigned to first card");
 
 MODULE_AUTHOR("Hans Verkuil");
 MODULE_DESCRIPTION("CX23418 driver");
@@ -356,6 +375,11 @@ static void cx18_process_options(struct cx18 *cx)
        cx->options.tuner = tuner[cx->num];
        cx->options.radio = radio[cx->num];
 
+       if (mmio_ndelay[cx->num] < 0)
+               cx->options.mmio_ndelay = CX18_DEFAULT_MMIO_NDELAY;
+       else
+               cx->options.mmio_ndelay = mmio_ndelay[cx->num];
+
        cx->std = cx18_parse_std(cx);
        if (cx->options.cardtype == -1) {
                CX18_INFO("Ignore card\n");
@@ -395,9 +419,9 @@ done:
 
        if (cx->card == NULL) {
                cx->card = cx18_get_card(CX18_CARD_HVR_1600_ESMT);
-               CX18_ERR("Unknown card: vendor/device: %04x/%04x\n",
+               CX18_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
                     cx->dev->vendor, cx->dev->device);
-               CX18_ERR("              subsystem vendor/device: %04x/%04x\n",
+               CX18_ERR("              subsystem vendor/device: [%04x:%04x]\n",
                     cx->dev->subsystem_vendor, cx->dev->subsystem_device);
                CX18_ERR("Defaulting to %s card\n", cx->card->name);
                CX18_ERR("Please mail the vendor/device and subsystem vendor/device IDs and what kind of\n");
@@ -511,9 +535,9 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev,
                return -EIO;
        }
 
-       /* Check for bus mastering */
+       /* Enable bus mastering and memory mapped IO for the CX23418 */
        pci_read_config_word(dev, PCI_COMMAND, &cmd);
-       cmd |= PCI_COMMAND_IO | PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
+       cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
        pci_write_config_word(dev, PCI_COMMAND, cmd);
 
        pci_read_config_byte(dev, PCI_CLASS_REVISION, &cx->card_rev);
@@ -525,11 +549,6 @@ static int cx18_setup_pci(struct cx18 *cx, struct pci_dev *dev,
                pci_write_config_byte(dev, PCI_LATENCY_TIMER, 64);
                pci_read_config_byte(dev, PCI_LATENCY_TIMER, &pci_latency);
        }
-       /* This config space value relates to DMA latencies. The
-          default value 0x8080 is too low however and will lead
-          to DMA errors. 0xffff is the max value which solves
-          these problems. */
-       pci_write_config_dword(dev, 0x40, 0xffff);
 
        CX18_DEBUG_INFO("cx%d (rev %d) at %02x:%02x.%x, "
                   "irq: %d, latency: %d, memory: 0x%lx\n",
@@ -656,7 +675,7 @@ static int __devinit cx18_probe(struct pci_dev *dev,
                goto free_mem;
        }
        cx->reg_mem = cx->enc_mem + CX18_REG_OFFSET;
-       devtype = read_reg(0xC72028);
+       devtype = cx18_read_reg(cx, 0xC72028);
        switch (devtype & 0xff000000) {
        case 0xff000000:
                CX18_INFO("cx23418 revision %08x (A)\n", devtype);
@@ -815,6 +834,7 @@ err:
        if (retval == 0)
                retval = -ENODEV;
        CX18_ERR("Error %d on initialization\n", retval);
+       cx18_log_statistics(cx);
 
        kfree(cx18_cards[cx18_cards_active]);
        cx18_cards[cx18_cards_active] = NULL;
@@ -902,8 +922,8 @@ static void cx18_remove(struct pci_dev *pci_dev)
                cx18_stop_all_captures(cx);
 
        /* Interrupts */
-       sw1_irq_disable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
-       sw2_irq_disable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
+       cx18_sw1_irq_disable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
+       cx18_sw2_irq_disable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
 
        cx18_halt_firmware(cx);
 
@@ -919,6 +939,7 @@ static void cx18_remove(struct pci_dev *pci_dev)
 
        pci_disable_device(cx->dev);
 
+       cx18_log_statistics(cx);
        CX18_INFO("Removed %s, card #%d\n", cx->card_name, cx->num);
 }
 
@@ -938,7 +959,7 @@ static int module_start(void)
 
        /* Validate parameters */
        if (cx18_first_minor < 0 || cx18_first_minor >= CX18_MAX_CARDS) {
-               printk(KERN_ERR "cx18:  Exiting, ivtv_first_minor must be between 0 and %d\n",
+               printk(KERN_ERR "cx18:  Exiting, cx18_first_minor must be between 0 and %d\n",
                     CX18_MAX_CARDS - 1);
                return -1;
        }
index 4801bc7fb5b224336c2cd4ba609df9fde7368bb6..fa8be0731a3f70ee3d6ca40a6301af86d7930a86 100644 (file)
@@ -38,7 +38,6 @@
 #include <linux/i2c-algo-bit.h>
 #include <linux/list.h>
 #include <linux/unistd.h>
-#include <linux/byteorder/swab.h>
 #include <linux/pagemap.h>
 #include <linux/workqueue.h>
 #include <linux/mutex.h>
@@ -64,6 +63,9 @@
 #  error "This driver requires kernel PCI support."
 #endif
 
+/* Default delay to throttle mmio access to the CX23418 */
+#define CX18_DEFAULT_MMIO_NDELAY 0 /* 0 ns = 0 PCI clock(s) / 33 MHz */
+
 #define CX18_MEM_OFFSET        0x00000000
 #define CX18_MEM_SIZE  0x04000000
 #define CX18_REG_OFFSET        0x02000000
@@ -77,7 +79,9 @@
 #define CX18_CARD_COMPRO_H900        2 /* Compro VideoMate H900 */
 #define CX18_CARD_YUAN_MPC718        3 /* Yuan MPC718 */
 #define CX18_CARD_CNXT_RAPTOR_PAL     4        /* Conexant Raptor PAL */
-#define CX18_CARD_LAST                       4
+#define CX18_CARD_TOSHIBA_QOSMIO_DVBT 5 /* Toshiba Qosmio Interal DVB-T/Analog*/
+#define CX18_CARD_LEADTEK_PVR2100     6 /* Leadtek WinFast PVR2100 */
+#define CX18_CARD_LAST                       6
 
 #define CX18_ENC_STREAM_TYPE_MPG  0
 #define CX18_ENC_STREAM_TYPE_TS   1
 #define CX18_PCI_ID_COMPRO             0x185b
 #define CX18_PCI_ID_YUAN               0x12ab
 #define CX18_PCI_ID_CONEXANT           0x14f1
+#define CX18_PCI_ID_TOSHIBA            0x1179
+#define CX18_PCI_ID_LEADTEK            0x107D
 
 /* ======================================================================== */
 /* ========================== START USER SETTABLE DMA VARIABLES =========== */
 
 #define CX18_MAX_PGM_INDEX (400)
 
+extern int cx18_retry_mmio;    /* enable check & retry of mmio accesses */
 extern int cx18_debug;
 
 
@@ -177,6 +184,7 @@ struct cx18_options {
        int cardtype;           /* force card type on load */
        int tuner;              /* set tuner on load */
        int radio;              /* enable/disable radio */
+       unsigned long mmio_ndelay; /* delay in ns after every PCI mmio access */
 };
 
 /* per-buffer bit flags */
@@ -216,8 +224,7 @@ struct cx18_buffer {
 
 struct cx18_queue {
        struct list_head list;
-       u32 buffers;
-       u32 length;
+       atomic_t buffers;
        u32 bytesused;
 };
 
@@ -237,6 +244,8 @@ struct cx18_dvb {
 struct cx18;    /* forward reference */
 struct cx18_scb; /* forward reference */
 
+#define CX18_INVALID_TASK_HANDLE 0xffffffff
+
 struct cx18_stream {
        /* These first four fields are always set, even if the stream
           is not actually created. */
@@ -259,7 +268,6 @@ struct cx18_stream {
        /* Buffer Stats */
        u32 buffers;
        u32 buf_size;
-       u32 buffers_stolen;
 
        /* Buffer Queues */
        struct cx18_queue q_free;       /* free buffers */
@@ -341,6 +349,13 @@ struct cx18_i2c_algo_callback_data {
        int bus_index;   /* 0 or 1 for the cx23418's 1st or 2nd I2C bus */
 };
 
+#define CX18_MAX_MMIO_RETRIES 10
+
+struct cx18_mmio_stats {
+       atomic_t retried_write[CX18_MAX_MMIO_RETRIES+1];
+       atomic_t retried_read[CX18_MAX_MMIO_RETRIES+1];
+};
+
 /* Struct to hold info about cx18 cards */
 struct cx18 {
        int num;                /* board number, -1 during init! */
@@ -430,6 +445,9 @@ struct cx18 {
        u32 gpio_val;
        struct mutex gpio_lock;
 
+       /* Statistics */
+       struct cx18_mmio_stats mmio_stats;
+
        /* v4l2 and User settings */
 
        /* codec settings */
@@ -458,47 +476,4 @@ void cx18_read_eeprom(struct cx18 *cx, struct tveeprom *tv);
 /* First-open initialization: load firmware, etc. */
 int cx18_init_on_first_open(struct cx18 *cx);
 
-/* This is a PCI post thing, where if the pci register is not read, then
-   the write doesn't always take effect right away. By reading back the
-   register any pending PCI writes will be performed (in order), and so
-   you can be sure that the writes are guaranteed to be done.
-
-   Rarely needed, only in some timing sensitive cases.
-   Apparently if this is not done some motherboards seem
-   to kill the firmware and get into the broken state until computer is
-   rebooted. */
-#define write_sync(val, reg) \
-       do { writel(val, reg); readl(reg); } while (0)
-
-#define read_reg(reg) readl(cx->reg_mem + (reg))
-#define write_reg(val, reg) writel(val, cx->reg_mem + (reg))
-#define write_reg_sync(val, reg) \
-       do { write_reg(val, reg); read_reg(reg); } while (0)
-
-#define read_enc(addr) readl(cx->enc_mem + (u32)(addr))
-#define write_enc(val, addr) writel(val, cx->enc_mem + (u32)(addr))
-#define write_enc_sync(val, addr) \
-       do { write_enc(val, addr); read_enc(addr); } while (0)
-
-#define sw1_irq_enable(val) do { \
-       write_reg(val, SW1_INT_STATUS); \
-       write_reg(read_reg(SW1_INT_ENABLE_PCI) | (val), SW1_INT_ENABLE_PCI); \
-} while (0)
-
-#define sw1_irq_disable(val) \
-       write_reg(read_reg(SW1_INT_ENABLE_PCI) & ~(val), SW1_INT_ENABLE_PCI);
-
-#define sw2_irq_enable(val) do { \
-       write_reg(val, SW2_INT_STATUS); \
-       write_reg(read_reg(SW2_INT_ENABLE_PCI) | (val), SW2_INT_ENABLE_PCI); \
-} while (0)
-
-#define sw2_irq_disable(val) \
-       write_reg(read_reg(SW2_INT_ENABLE_PCI) & ~(val), SW2_INT_ENABLE_PCI);
-
-#define setup_page(addr) do { \
-    u32 val = read_reg(0xD000F8) & ~0x1f00; \
-    write_reg(val | (((addr) >> 17) & 0x1f00), 0xD000F8); \
-} while (0)
-
 #endif /* CX18_DRIVER_H */
index 1e420a804fc96ddf24c3632b83e136d8755dc163..afc694e7bdb297f672944c3ba66b828aae6b16ad 100644 (file)
@@ -21,6 +21,7 @@
 
 #include "cx18-version.h"
 #include "cx18-dvb.h"
+#include "cx18-io.h"
 #include "cx18-streams.h"
 #include "cx18-cards.h"
 #include "s5h1409.h"
@@ -87,13 +88,13 @@ static int cx18_dvb_start_feed(struct dvb_demux_feed *feed)
        switch (cx->card->type) {
        case CX18_CARD_HVR_1600_ESMT:
        case CX18_CARD_HVR_1600_SAMSUNG:
-               v = read_reg(CX18_REG_DMUX_NUM_PORT_0_CONTROL);
+               v = cx18_read_reg(cx, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
                v |= 0x00400000; /* Serial Mode */
                v |= 0x00002000; /* Data Length - Byte */
                v |= 0x00010000; /* Error - Polarity */
                v |= 0x00020000; /* Error - Passthru */
                v |= 0x000c0000; /* Error - Ignore */
-               write_reg(v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
+               cx18_write_reg(cx, v, CX18_REG_DMUX_NUM_PORT_0_CONTROL);
                break;
 
        default:
index 1e537fe04a2372196254aa35e6846131f136c02e..5f9089907544c091f1e276eee7601a81a946ca77 100644 (file)
@@ -132,6 +132,7 @@ static void cx18_dualwatch(struct cx18 *cx)
        u16 new_stereo_mode;
        const u16 stereo_mask = 0x0300;
        const u16 dual = 0x0200;
+       u32 h;
 
        new_stereo_mode = cx->params.audio_properties & stereo_mask;
        memset(&vt, 0, sizeof(vt));
@@ -143,13 +144,21 @@ static void cx18_dualwatch(struct cx18 *cx)
        if (new_stereo_mode == cx->dualwatch_stereo_mode)
                return;
 
-       new_bitmap = new_stereo_mode | (cx->params.audio_properties & ~stereo_mask);
+       new_bitmap = new_stereo_mode
+                       | (cx->params.audio_properties & ~stereo_mask);
 
-       CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. new audio_bitmask=0x%ux\n",
-                          cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
+       CX18_DEBUG_INFO("dualwatch: change stereo flag from 0x%x to 0x%x. "
+                       "new audio_bitmask=0x%ux\n",
+                       cx->dualwatch_stereo_mode, new_stereo_mode, new_bitmap);
 
-       if (cx18_vapi(cx, CX18_CPU_SET_AUDIO_PARAMETERS, 2,
-                               cx18_find_handle(cx), new_bitmap) == 0) {
+       h = cx18_find_handle(cx);
+       if (h == CX18_INVALID_TASK_HANDLE) {
+               CX18_DEBUG_INFO("dualwatch: can't find valid task handle\n");
+               return;
+       }
+
+       if (cx18_vapi(cx,
+                     CX18_CPU_SET_AUDIO_PARAMETERS, 2, h, new_bitmap) == 0) {
                cx->dualwatch_stereo_mode = new_stereo_mode;
                return;
        }
@@ -223,7 +232,7 @@ static struct cx18_buffer *cx18_get_buffer(struct cx18_stream *s, int non_block,
                prepare_to_wait(&s->waitq, &wait, TASK_INTERRUPTIBLE);
                /* New buffers might have become available before we were added
                   to the waitqueue */
-               if (!s->q_full.buffers)
+               if (!atomic_read(&s->q_full.buffers))
                        schedule();
                finish_wait(&s->waitq, &wait);
                if (signal_pending(current)) {
@@ -509,7 +518,7 @@ unsigned int cx18_v4l2_enc_poll(struct file *filp, poll_table *wait)
        CX18_DEBUG_HI_FILE("Encoder poll\n");
        poll_wait(filp, &s->waitq, wait);
 
-       if (s->q_full.length || s->q_io.length)
+       if (atomic_read(&s->q_full.buffers) || atomic_read(&s->q_io.buffers))
                return POLLIN | POLLRDNORM;
        if (eof)
                return POLLHUP;
@@ -695,20 +704,28 @@ int cx18_v4l2_open(struct inode *inode, struct file *filp)
 
 void cx18_mute(struct cx18 *cx)
 {
-       if (atomic_read(&cx->ana_capturing))
-               cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2,
-                               cx18_find_handle(cx), 1);
+       u32 h;
+       if (atomic_read(&cx->ana_capturing)) {
+               h = cx18_find_handle(cx);
+               if (h != CX18_INVALID_TASK_HANDLE)
+                       cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, h, 1);
+               else
+                       CX18_ERR("Can't find valid task handle for mute\n");
+       }
        CX18_DEBUG_INFO("Mute\n");
 }
 
 void cx18_unmute(struct cx18 *cx)
 {
+       u32 h;
        if (atomic_read(&cx->ana_capturing)) {
-               cx18_msleep_timeout(100, 0);
-               cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2,
-                               cx18_find_handle(cx), 12);
-               cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2,
-                               cx18_find_handle(cx), 0);
+               h = cx18_find_handle(cx);
+               if (h != CX18_INVALID_TASK_HANDLE) {
+                       cx18_msleep_timeout(100, 0);
+                       cx18_vapi(cx, CX18_CPU_SET_MISC_PARAMETERS, 2, h, 12);
+                       cx18_vapi(cx, CX18_CPU_SET_AUDIO_MUTE, 2, h, 0);
+               } else
+                       CX18_ERR("Can't find valid task handle for unmute\n");
        }
        CX18_DEBUG_INFO("Unmute\n");
 }
index 78fadd2ada5d72a4a1d45708ebe352e03cb099d0..51534428cd00c9dbe1b231516ccf2df078bc9f16 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-scb.h"
 #include "cx18-irq.h"
 #include "cx18-firmware.h"
@@ -113,11 +114,11 @@ static int load_cpu_fw_direct(const char *fn, u8 __iomem *mem, struct cx18 *cx)
        src = (const u32 *)fw->data;
 
        for (i = 0; i < fw->size; i += 4096) {
-               setup_page(i);
+               cx18_setup_page(cx, i);
                for (j = i; j < fw->size && j < i + 4096; j += 4) {
                        /* no need for endianness conversion on the ppc */
-                       __raw_writel(*src, dst);
-                       if (__raw_readl(dst) != *src) {
+                       cx18_raw_writel(cx, *src, dst);
+                       if (cx18_raw_readl(cx, dst) != *src) {
                                CX18_ERR("Mismatch at offset %x\n", i);
                                release_firmware(fw);
                                return -EIO;
@@ -170,12 +171,15 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
                if (offset + seghdr.size > sz)
                        break;
                for (i = 0; i < seghdr.size; i += 4096) {
-                       setup_page(offset + i);
+                       cx18_setup_page(cx, offset + i);
                        for (j = i; j < seghdr.size && j < i + 4096; j += 4) {
                                /* no need for endianness conversion on the ppc */
-                               __raw_writel(src[(offset + j) / 4], dst + seghdr.addr + j);
-                               if (__raw_readl(dst + seghdr.addr + j) != src[(offset + j) / 4]) {
-                                       CX18_ERR("Mismatch at offset %x\n", offset + j);
+                               cx18_raw_writel(cx, src[(offset + j) / 4],
+                                               dst + seghdr.addr + j);
+                               if (cx18_raw_readl(cx, dst + seghdr.addr + j)
+                                   != src[(offset + j) / 4]) {
+                                       CX18_ERR("Mismatch at offset %x\n",
+                                                offset + j);
                                        release_firmware(fw);
                                        return -EIO;
                                }
@@ -189,43 +193,45 @@ static int load_apu_fw_direct(const char *fn, u8 __iomem *dst, struct cx18 *cx)
        size = fw->size;
        release_firmware(fw);
        /* Clear bit0 for APU to start from 0 */
-       write_reg(read_reg(0xc72030) & ~1, 0xc72030);
+       cx18_write_reg(cx, cx18_read_reg(cx, 0xc72030) & ~1, 0xc72030);
        return size;
 }
 
 void cx18_halt_firmware(struct cx18 *cx)
 {
        CX18_DEBUG_INFO("Preparing for firmware halt.\n");
-       write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
-       write_reg(0x00020002, CX18_ADEC_CONTROL);
+       cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
+       cx18_write_reg(cx, 0x00020002, CX18_ADEC_CONTROL);
 }
 
 void cx18_init_power(struct cx18 *cx, int lowpwr)
 {
        /* power-down Spare and AOM PLLs */
        /* power-up fast, slow and mpeg PLLs */
-       write_reg(0x00000008, CX18_PLL_POWER_DOWN);
+       cx18_write_reg(cx, 0x00000008, CX18_PLL_POWER_DOWN);
 
        /* ADEC out of sleep */
-       write_reg(0x00020000, CX18_ADEC_CONTROL);
+       cx18_write_reg(cx, 0x00020000, CX18_ADEC_CONTROL);
 
        /* The fast clock is at 200/245 MHz */
-       write_reg(lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT);
-       write_reg(lowpwr ? 0x1EFBF37 : 0x038E3D7, CX18_FAST_CLOCK_PLL_FRAC);
+       cx18_write_reg(cx, lowpwr ? 0xD : 0x11, CX18_FAST_CLOCK_PLL_INT);
+       cx18_write_reg(cx, lowpwr ? 0x1EFBF37 : 0x038E3D7,
+                                               CX18_FAST_CLOCK_PLL_FRAC);
 
-       write_reg(2, CX18_FAST_CLOCK_PLL_POST);
-       write_reg(1, CX18_FAST_CLOCK_PLL_PRESCALE);
-       write_reg(4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH);
+       cx18_write_reg(cx, 2, CX18_FAST_CLOCK_PLL_POST);
+       cx18_write_reg(cx, 1, CX18_FAST_CLOCK_PLL_PRESCALE);
+       cx18_write_reg(cx, 4, CX18_FAST_CLOCK_PLL_ADJUST_BANDWIDTH);
 
        /* set slow clock to 125/120 MHz */
-       write_reg(lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT);
-       write_reg(lowpwr ? 0xEBAF05 : 0x18618A8, CX18_SLOW_CLOCK_PLL_FRAC);
-       write_reg(4, CX18_SLOW_CLOCK_PLL_POST);
+       cx18_write_reg(cx, lowpwr ? 0x11 : 0x10, CX18_SLOW_CLOCK_PLL_INT);
+       cx18_write_reg(cx, lowpwr ? 0xEBAF05 : 0x18618A8,
+                                               CX18_SLOW_CLOCK_PLL_FRAC);
+       cx18_write_reg(cx, 4, CX18_SLOW_CLOCK_PLL_POST);
 
        /* mpeg clock pll 54MHz */
-       write_reg(0xF, CX18_MPEG_CLOCK_PLL_INT);
-       write_reg(0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC);
-       write_reg(8, CX18_MPEG_CLOCK_PLL_POST);
+       cx18_write_reg(cx, 0xF, CX18_MPEG_CLOCK_PLL_INT);
+       cx18_write_reg(cx, 0x2BCFEF, CX18_MPEG_CLOCK_PLL_FRAC);
+       cx18_write_reg(cx, 8, CX18_MPEG_CLOCK_PLL_POST);
 
        /* Defaults */
        /* APU = SC or SC/2 = 125/62.5 */
@@ -242,81 +248,84 @@ void cx18_init_power(struct cx18 *cx, int lowpwr)
        /* VFC = disabled */
        /* USB = disabled */
 
-       write_reg(lowpwr ? 0xFFFF0020 : 0x00060004, CX18_CLOCK_SELECT1);
-       write_reg(lowpwr ? 0xFFFF0004 : 0x00060006, CX18_CLOCK_SELECT2);
+       cx18_write_reg(cx, lowpwr ? 0xFFFF0020 : 0x00060004,
+                                                       CX18_CLOCK_SELECT1);
+       cx18_write_reg(cx, lowpwr ? 0xFFFF0004 : 0x00060006,
+                                                       CX18_CLOCK_SELECT2);
 
-       write_reg(0xFFFF0002, CX18_HALF_CLOCK_SELECT1);
-       write_reg(0xFFFF0104, CX18_HALF_CLOCK_SELECT2);
+       cx18_write_reg(cx, 0xFFFF0002, CX18_HALF_CLOCK_SELECT1);
+       cx18_write_reg(cx, 0xFFFF0104, CX18_HALF_CLOCK_SELECT2);
 
-       write_reg(0xFFFF9026, CX18_CLOCK_ENABLE1);
-       write_reg(0xFFFF3105, CX18_CLOCK_ENABLE2);
+       cx18_write_reg(cx, 0xFFFF9026, CX18_CLOCK_ENABLE1);
+       cx18_write_reg(cx, 0xFFFF3105, CX18_CLOCK_ENABLE2);
 }
 
 void cx18_init_memory(struct cx18 *cx)
 {
        cx18_msleep_timeout(10, 0);
-       write_reg(0x10000, CX18_DDR_SOFT_RESET);
+       cx18_write_reg(cx, 0x10000, CX18_DDR_SOFT_RESET);
        cx18_msleep_timeout(10, 0);
 
-       write_reg(cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG);
+       cx18_write_reg(cx, cx->card->ddr.chip_config, CX18_DDR_CHIP_CONFIG);
 
        cx18_msleep_timeout(10, 0);
 
-       write_reg(cx->card->ddr.refresh, CX18_DDR_REFRESH);
-       write_reg(cx->card->ddr.timing1, CX18_DDR_TIMING1);
-       write_reg(cx->card->ddr.timing2, CX18_DDR_TIMING2);
+       cx18_write_reg(cx, cx->card->ddr.refresh, CX18_DDR_REFRESH);
+       cx18_write_reg(cx, cx->card->ddr.timing1, CX18_DDR_TIMING1);
+       cx18_write_reg(cx, cx->card->ddr.timing2, CX18_DDR_TIMING2);
 
        cx18_msleep_timeout(10, 0);
 
        /* Initialize DQS pad time */
-       write_reg(cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE);
-       write_reg(cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS);
+       cx18_write_reg(cx, cx->card->ddr.tune_lane, CX18_DDR_TUNE_LANE);
+       cx18_write_reg(cx, cx->card->ddr.initial_emrs, CX18_DDR_INITIAL_EMRS);
 
        cx18_msleep_timeout(10, 0);
 
-       write_reg(0x20000, CX18_DDR_SOFT_RESET);
+       cx18_write_reg(cx, 0x20000, CX18_DDR_SOFT_RESET);
        cx18_msleep_timeout(10, 0);
 
        /* use power-down mode when idle */
-       write_reg(0x00000010, CX18_DDR_POWER_REG);
-
-       write_reg(0x10001, CX18_REG_BUS_TIMEOUT_EN);
-
-       write_reg(0x48, CX18_DDR_MB_PER_ROW_7);
-       write_reg(0xE0000, CX18_DDR_BASE_63_ADDR);
-
-       write_reg(0x00000101, CX18_WMB_CLIENT02);  /* AO */
-       write_reg(0x00000101, CX18_WMB_CLIENT09);  /* AI2 */
-       write_reg(0x00000101, CX18_WMB_CLIENT05);  /* VIM1 */
-       write_reg(0x00000101, CX18_WMB_CLIENT06);  /* AI1 */
-       write_reg(0x00000101, CX18_WMB_CLIENT07);  /* 3D comb */
-       write_reg(0x00000101, CX18_WMB_CLIENT10);  /* ME */
-       write_reg(0x00000101, CX18_WMB_CLIENT12);  /* ENC */
-       write_reg(0x00000101, CX18_WMB_CLIENT13);  /* PK */
-       write_reg(0x00000101, CX18_WMB_CLIENT11);  /* RC */
-       write_reg(0x00000101, CX18_WMB_CLIENT14);  /* AVO */
+       cx18_write_reg(cx, 0x00000010, CX18_DDR_POWER_REG);
+
+       cx18_write_reg(cx, 0x10001, CX18_REG_BUS_TIMEOUT_EN);
+
+       cx18_write_reg(cx, 0x48, CX18_DDR_MB_PER_ROW_7);
+       cx18_write_reg(cx, 0xE0000, CX18_DDR_BASE_63_ADDR);
+
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT02);  /* AO */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT09);  /* AI2 */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT05);  /* VIM1 */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT06);  /* AI1 */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT07);  /* 3D comb */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT10);  /* ME */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT12);  /* ENC */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT13);  /* PK */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT11);  /* RC */
+       cx18_write_reg(cx, 0x00000101, CX18_WMB_CLIENT14);  /* AVO */
 }
 
 int cx18_firmware_init(struct cx18 *cx)
 {
        /* Allow chip to control CLKRUN */
-       write_reg(0x5, CX18_DSP0_INTERRUPT_MASK);
+       cx18_write_reg(cx, 0x5, CX18_DSP0_INTERRUPT_MASK);
 
-       write_reg(0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
+       cx18_write_reg(cx, 0x000F000F, CX18_PROC_SOFT_RESET); /* stop the fw */
 
        cx18_msleep_timeout(1, 0);
 
-       sw1_irq_enable(IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
-       sw2_irq_enable(IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
+       cx18_sw1_irq_enable(cx, IRQ_CPU_TO_EPU | IRQ_APU_TO_EPU);
+       cx18_sw2_irq_enable(cx, IRQ_CPU_TO_EPU_ACK | IRQ_APU_TO_EPU_ACK);
 
        /* Only if the processor is not running */
-       if (read_reg(CX18_PROC_SOFT_RESET) & 8) {
+       if (cx18_read_reg(cx, CX18_PROC_SOFT_RESET) & 8) {
                int sz = load_apu_fw_direct("v4l-cx23418-apu.fw",
                               cx->enc_mem, cx);
 
-               write_enc(0xE51FF004, 0);
-               write_enc(0xa00000, 4);  /* todo: not hardcoded */
-               write_reg(0x00010000, CX18_PROC_SOFT_RESET); /* Start APU */
+               cx18_write_enc(cx, 0xE51FF004, 0);
+               cx18_write_enc(cx, 0xa00000, 4);  /* todo: not hardcoded */
+               /* Start APU */
+               cx18_write_reg(cx, 0x00010000, CX18_PROC_SOFT_RESET);
                cx18_msleep_timeout(500, 0);
 
                sz = sz <= 0 ? sz : load_cpu_fw_direct("v4l-cx23418-cpu.fw",
@@ -326,9 +335,10 @@ int cx18_firmware_init(struct cx18 *cx)
                        int retries = 0;
 
                        /* start the CPU */
-                       write_reg(0x00080000, CX18_PROC_SOFT_RESET);
+                       cx18_write_reg(cx, 0x00080000, CX18_PROC_SOFT_RESET);
                        while (retries++ < 50) { /* Loop for max 500mS */
-                               if ((read_reg(CX18_PROC_SOFT_RESET) & 1) == 0)
+                               if ((cx18_read_reg(cx, CX18_PROC_SOFT_RESET)
+                                    & 1) == 0)
                                        break;
                                cx18_msleep_timeout(10, 0);
                        }
@@ -342,6 +352,6 @@ int cx18_firmware_init(struct cx18 *cx)
                        return -EIO;
        }
        /* initialize GPIO */
-       write_reg(0x14001400, 0xC78110);
+       cx18_write_reg(cx, 0x14001400, 0xC78110);
        return 0;
 }
index 3d495dba4983d1662b2c2973ca97a1bb87b0ec54..0e560421989e4bb69f124a0ce28047d7c10665a3 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-cards.h"
 #include "cx18-gpio.h"
 #include "tuner-xc2028.h"
@@ -49,11 +50,11 @@ static void gpio_write(struct cx18 *cx)
        u32 dir = cx->gpio_dir;
        u32 val = cx->gpio_val;
 
-       write_reg((dir & 0xffff) << 16, CX18_REG_GPIO_DIR1);
-       write_reg(((dir & 0xffff) << 16) | (val & 0xffff),
+       cx18_write_reg(cx, (dir & 0xffff) << 16, CX18_REG_GPIO_DIR1);
+       cx18_write_reg(cx, ((dir & 0xffff) << 16) | (val & 0xffff),
                        CX18_REG_GPIO_OUT1);
-       write_reg(dir & 0xffff0000, CX18_REG_GPIO_DIR2);
-       write_reg_sync((dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
+       cx18_write_reg(cx, dir & 0xffff0000, CX18_REG_GPIO_DIR2);
+       cx18_write_reg_sync(cx, (dir & 0xffff0000) | ((val & 0xffff0000) >> 16),
                        CX18_REG_GPIO_OUT2);
 }
 
@@ -141,15 +142,17 @@ void cx18_gpio_init(struct cx18 *cx)
        }
 
        CX18_DEBUG_INFO("GPIO initial dir: %08x/%08x out: %08x/%08x\n",
-                  read_reg(CX18_REG_GPIO_DIR1), read_reg(CX18_REG_GPIO_DIR2),
-                  read_reg(CX18_REG_GPIO_OUT1), read_reg(CX18_REG_GPIO_OUT2));
+                       cx18_read_reg(cx, CX18_REG_GPIO_DIR1),
+                       cx18_read_reg(cx, CX18_REG_GPIO_DIR2),
+                       cx18_read_reg(cx, CX18_REG_GPIO_OUT1),
+                       cx18_read_reg(cx, CX18_REG_GPIO_OUT2));
 
        gpio_write(cx);
        mutex_unlock(&cx->gpio_lock);
 }
 
 /* Xceive tuner reset function */
-int cx18_reset_tuner_gpio(void *dev, int cmd, int value)
+int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value)
 {
        struct i2c_algo_bit_data *algo = dev;
        struct cx18_i2c_algo_callback_data *cb_data = algo->data;
index 22cd7ddf8554ba36dc6c8f1e97772ec17bb679d6..beb7424b9944f928b7239be5a162d9114486b112 100644 (file)
@@ -23,5 +23,5 @@
 void cx18_gpio_init(struct cx18 *cx);
 void cx18_reset_i2c_slaves_gpio(struct cx18 *cx);
 void cx18_reset_ir_gpio(void *data);
-int cx18_reset_tuner_gpio(void *dev, int cmd, int value);
+int cx18_reset_tuner_gpio(void *dev, int component, int cmd, int value);
 int cx18_gpio(struct cx18 *cx, unsigned int command, void *arg);
index 6023ba3bd3a63d79d967fdbb86a2fa67611a391c..aa09e557b195ceef2d2e0bfc506e1a59412e8c80 100644 (file)
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-cards.h"
 #include "cx18-gpio.h"
 #include "cx18-av-core.h"
 #include "cx18-i2c.h"
 
-#include <media/ir-kbd-i2c.h>
-
 #define CX18_REG_I2C_1_WR   0xf15000
 #define CX18_REG_I2C_1_RD   0xf15008
 #define CX18_REG_I2C_2_WR   0xf25100
@@ -158,12 +157,12 @@ static void cx18_setscl(void *data, int state)
        struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx;
        int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
        u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR;
-       u32 r = read_reg(addr);
+       u32 r = cx18_read_reg(cx, addr);
 
        if (state)
-               write_reg_sync(r | SETSCL_BIT, addr);
+               cx18_write_reg_sync(cx, r | SETSCL_BIT, addr);
        else
-               write_reg_sync(r & ~SETSCL_BIT, addr);
+               cx18_write_reg_sync(cx, r & ~SETSCL_BIT, addr);
 }
 
 static void cx18_setsda(void *data, int state)
@@ -171,12 +170,12 @@ static void cx18_setsda(void *data, int state)
        struct cx18 *cx = ((struct cx18_i2c_algo_callback_data *)data)->cx;
        int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
        u32 addr = bus_index ? CX18_REG_I2C_2_WR : CX18_REG_I2C_1_WR;
-       u32 r = read_reg(addr);
+       u32 r = cx18_read_reg(cx, addr);
 
        if (state)
-               write_reg_sync(r | SETSDL_BIT, addr);
+               cx18_write_reg_sync(cx, r | SETSDL_BIT, addr);
        else
-               write_reg_sync(r & ~SETSDL_BIT, addr);
+               cx18_write_reg_sync(cx, r & ~SETSDL_BIT, addr);
 }
 
 static int cx18_getscl(void *data)
@@ -185,7 +184,7 @@ static int cx18_getscl(void *data)
        int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
        u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD;
 
-       return read_reg(addr) & GETSCL_BIT;
+       return cx18_read_reg(cx, addr) & GETSCL_BIT;
 }
 
 static int cx18_getsda(void *data)
@@ -194,7 +193,7 @@ static int cx18_getsda(void *data)
        int bus_index = ((struct cx18_i2c_algo_callback_data *)data)->bus_index;
        u32 addr = bus_index ? CX18_REG_I2C_2_RD : CX18_REG_I2C_1_RD;
 
-       return read_reg(addr) & GETSDL_BIT;
+       return cx18_read_reg(cx, addr) & GETSDL_BIT;
 }
 
 /* template for i2c-bit-algo */
@@ -394,29 +393,33 @@ int init_cx18_i2c(struct cx18 *cx)
                cx->i2c_adap[i].dev.parent = &cx->dev->dev;
        }
 
-       if (read_reg(CX18_REG_I2C_2_WR) != 0x0003c02f) {
+       if (cx18_read_reg(cx, CX18_REG_I2C_2_WR) != 0x0003c02f) {
                /* Reset/Unreset I2C hardware block */
-               write_reg(0x10000000, 0xc71004); /* Clock select 220MHz */
-               write_reg_sync(0x10001000, 0xc71024); /* Clock Enable */
+               /* Clock select 220MHz */
+               cx18_write_reg(cx, 0x10000000, 0xc71004);
+               /* Clock Enable */
+               cx18_write_reg_sync(cx, 0x10001000, 0xc71024);
        }
        /* courtesy of Steven Toth <stoth@hauppauge.com> */
-       write_reg_sync(0x00c00000, 0xc7001c);
+       cx18_write_reg_sync(cx, 0x00c00000, 0xc7001c);
        mdelay(10);
-       write_reg_sync(0x00c000c0, 0xc7001c);
+       cx18_write_reg_sync(cx, 0x00c000c0, 0xc7001c);
        mdelay(10);
-       write_reg_sync(0x00c00000, 0xc7001c);
+       cx18_write_reg_sync(cx, 0x00c00000, 0xc7001c);
        mdelay(10);
 
-       write_reg_sync(0x00c00000, 0xc730c8); /* Set to edge-triggered intrs. */
-       write_reg_sync(0x00c00000, 0xc730c4); /* Clear any stale intrs */
+       /* Set to edge-triggered intrs. */
+       cx18_write_reg_sync(cx, 0x00c00000, 0xc730c8);
+       /* Clear any stale intrs */
+       cx18_write_reg_sync(cx, 0x00c00000, 0xc730c4);
 
        /* Hw I2C1 Clock Freq ~100kHz */
-       write_reg_sync(0x00021c0f & ~4, CX18_REG_I2C_1_WR);
+       cx18_write_reg_sync(cx, 0x00021c0f & ~4, CX18_REG_I2C_1_WR);
        cx18_setscl(&cx->i2c_algo_cb_data[0], 1);
        cx18_setsda(&cx->i2c_algo_cb_data[0], 1);
 
        /* Hw I2C2 Clock Freq ~100kHz */
-       write_reg_sync(0x00021c0f & ~4, CX18_REG_I2C_2_WR);
+       cx18_write_reg_sync(cx, 0x00021c0f & ~4, CX18_REG_I2C_2_WR);
        cx18_setscl(&cx->i2c_algo_cb_data[1], 1);
        cx18_setsda(&cx->i2c_algo_cb_data[1], 1);
 
@@ -430,8 +433,10 @@ void exit_cx18_i2c(struct cx18 *cx)
 {
        int i;
        CX18_DEBUG_I2C("i2c exit\n");
-       write_reg(read_reg(CX18_REG_I2C_1_WR) | 4, CX18_REG_I2C_1_WR);
-       write_reg(read_reg(CX18_REG_I2C_2_WR) | 4, CX18_REG_I2C_2_WR);
+       cx18_write_reg(cx, cx18_read_reg(cx, CX18_REG_I2C_1_WR) | 4,
+                                                       CX18_REG_I2C_1_WR);
+       cx18_write_reg(cx, cx18_read_reg(cx, CX18_REG_I2C_2_WR) | 4,
+                                                       CX18_REG_I2C_2_WR);
 
        for (i = 0; i < 2; i++) {
                i2c_del_adapter(&cx->i2c_adap[i]);
diff --git a/drivers/media/video/cx18/cx18-io.c b/drivers/media/video/cx18/cx18-io.c
new file mode 100644 (file)
index 0000000..700ab94
--- /dev/null
@@ -0,0 +1,254 @@
+/*
+ *  cx18 driver PCI memory mapped IO access routines
+ *
+ *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
+ *  Copyright (C) 2008  Andy Walls <awalls@radix.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ *  02111-1307  USA
+ */
+
+#include "cx18-driver.h"
+#include "cx18-io.h"
+#include "cx18-irq.h"
+
+void cx18_log_statistics(struct cx18 *cx)
+{
+       int i;
+
+       if (!(cx18_debug & CX18_DBGFLG_INFO))
+               return;
+
+       for (i = 0; i <= CX18_MAX_MMIO_RETRIES; i++)
+               CX18_DEBUG_INFO("retried_write[%d] = %d\n", i,
+                               atomic_read(&cx->mmio_stats.retried_write[i]));
+       for (i = 0; i <= CX18_MAX_MMIO_RETRIES; i++)
+               CX18_DEBUG_INFO("retried_read[%d] = %d\n", i,
+                               atomic_read(&cx->mmio_stats.retried_read[i]));
+       return;
+}
+
+void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       int i;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               cx18_raw_writel_noretry(cx, val, addr);
+               if (val == cx18_raw_readl_noretry(cx, addr))
+                       break;
+       }
+       cx18_log_write_retries(cx, i, addr);
+}
+
+u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr)
+{
+       int i;
+       u32 val;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               val = cx18_raw_readl_noretry(cx, addr);
+               if (val != 0xffffffff) /* PCI bus read error */
+                       break;
+       }
+       cx18_log_read_retries(cx, i, addr);
+       return val;
+}
+
+u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr)
+{
+       int i;
+       u16 val;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               val = cx18_raw_readw_noretry(cx, addr);
+               if (val != 0xffff) /* PCI bus read error */
+                       break;
+       }
+       cx18_log_read_retries(cx, i, addr);
+       return val;
+}
+
+void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       int i;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               cx18_writel_noretry(cx, val, addr);
+               if (val == cx18_readl_noretry(cx, addr))
+                       break;
+       }
+       cx18_log_write_retries(cx, i, addr);
+}
+
+void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr)
+{
+       int i;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               cx18_writew_noretry(cx, val, addr);
+               if (val == cx18_readw_noretry(cx, addr))
+                       break;
+       }
+       cx18_log_write_retries(cx, i, addr);
+}
+
+void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr)
+{
+       int i;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               cx18_writeb_noretry(cx, val, addr);
+               if (val == cx18_readb_noretry(cx, addr))
+                       break;
+       }
+       cx18_log_write_retries(cx, i, addr);
+}
+
+u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr)
+{
+       int i;
+       u32 val;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               val = cx18_readl_noretry(cx, addr);
+               if (val != 0xffffffff) /* PCI bus read error */
+                       break;
+       }
+       cx18_log_read_retries(cx, i, addr);
+       return val;
+}
+
+u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr)
+{
+       int i;
+       u16 val;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               val = cx18_readw_noretry(cx, addr);
+               if (val != 0xffff) /* PCI bus read error */
+                       break;
+       }
+       cx18_log_read_retries(cx, i, addr);
+       return val;
+}
+
+u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr)
+{
+       int i;
+       u8 val;
+       for (i = 0; i < CX18_MAX_MMIO_RETRIES; i++) {
+               val = cx18_readb_noretry(cx, addr);
+               if (val != 0xff) /* PCI bus read error */
+                       break;
+       }
+       cx18_log_read_retries(cx, i, addr);
+       return val;
+}
+
+void cx18_memcpy_fromio(struct cx18 *cx, void *to,
+                       const void __iomem *from, unsigned int len)
+{
+       const u8 __iomem *src = from;
+       u8 *dst = to;
+
+       /* Align reads on the CX23418's addresses */
+       if ((len > 0) && ((unsigned long) src & 1)) {
+               *dst = cx18_readb(cx, src);
+               len--;
+               dst++;
+               src++;
+       }
+       if ((len > 1) && ((unsigned long) src & 2)) {
+               *((u16 *)dst) = cx18_raw_readw(cx, src);
+               len -= 2;
+               dst += 2;
+               src += 2;
+       }
+       while (len > 3) {
+               *((u32 *)dst) = cx18_raw_readl(cx, src);
+               len -= 4;
+               dst += 4;
+               src += 4;
+       }
+       if (len > 1) {
+               *((u16 *)dst) = cx18_raw_readw(cx, src);
+               len -= 2;
+               dst += 2;
+               src += 2;
+       }
+       if (len > 0)
+               *dst = cx18_readb(cx, src);
+}
+
+void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count)
+{
+       u8 __iomem *dst = addr;
+       u16 val2 = val | (val << 8);
+       u32 val4 = val2 | (val2 << 16);
+
+       /* Align writes on the CX23418's addresses */
+       if ((count > 0) && ((unsigned long)dst & 1)) {
+               cx18_writeb(cx, (u8) val, dst);
+               count--;
+               dst++;
+       }
+       if ((count > 1) && ((unsigned long)dst & 2)) {
+               cx18_writew(cx, val2, dst);
+               count -= 2;
+               dst += 2;
+       }
+       while (count > 3) {
+               cx18_writel(cx, val4, dst);
+               count -= 4;
+               dst += 4;
+       }
+       if (count > 1) {
+               cx18_writew(cx, val2, dst);
+               count -= 2;
+               dst += 2;
+       }
+       if (count > 0)
+               cx18_writeb(cx, (u8) val, dst);
+}
+
+void cx18_sw1_irq_enable(struct cx18 *cx, u32 val)
+{
+       u32 r;
+       cx18_write_reg(cx, val, SW1_INT_STATUS);
+       r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
+       cx18_write_reg(cx, r | val, SW1_INT_ENABLE_PCI);
+}
+
+void cx18_sw1_irq_disable(struct cx18 *cx, u32 val)
+{
+       u32 r;
+       r = cx18_read_reg(cx, SW1_INT_ENABLE_PCI);
+       cx18_write_reg(cx, r & ~val, SW1_INT_ENABLE_PCI);
+}
+
+void cx18_sw2_irq_enable(struct cx18 *cx, u32 val)
+{
+       u32 r;
+       cx18_write_reg(cx, val, SW2_INT_STATUS);
+       r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
+       cx18_write_reg(cx, r | val, SW2_INT_ENABLE_PCI);
+}
+
+void cx18_sw2_irq_disable(struct cx18 *cx, u32 val)
+{
+       u32 r;
+       r = cx18_read_reg(cx, SW2_INT_ENABLE_PCI);
+       cx18_write_reg(cx, r & ~val, SW2_INT_ENABLE_PCI);
+}
+
+void cx18_setup_page(struct cx18 *cx, u32 addr)
+{
+       u32 val;
+       val = cx18_read_reg(cx, 0xD000F8);
+       val = (val & ~0x1f00) | ((addr >> 17) & 0x1f00);
+       cx18_write_reg(cx, val, 0xD000F8);
+}
diff --git a/drivers/media/video/cx18/cx18-io.h b/drivers/media/video/cx18/cx18-io.h
new file mode 100644 (file)
index 0000000..197d4fb
--- /dev/null
@@ -0,0 +1,378 @@
+/*
+ *  cx18 driver PCI memory mapped IO access routines
+ *
+ *  Copyright (C) 2007  Hans Verkuil <hverkuil@xs4all.nl>
+ *  Copyright (C) 2008  Andy Walls <awalls@radix.net>
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ *  02111-1307  USA
+ */
+
+#ifndef CX18_IO_H
+#define CX18_IO_H
+
+#include "cx18-driver.h"
+
+static inline void cx18_io_delay(struct cx18 *cx)
+{
+       if (cx->options.mmio_ndelay)
+               ndelay(cx->options.mmio_ndelay);
+}
+
+/*
+ * Readback and retry of MMIO access for reliability:
+ * The concept was suggested by Steve Toth <stoth@linuxtv.org>.
+ * The implmentation is the fault of Andy Walls <awalls@radix.net>.
+ */
+
+/* Statistics gathering */
+static inline
+void cx18_log_write_retries(struct cx18 *cx, int i, const void *addr)
+{
+       if (i > CX18_MAX_MMIO_RETRIES)
+               i = CX18_MAX_MMIO_RETRIES;
+       atomic_inc(&cx->mmio_stats.retried_write[i]);
+       return;
+}
+
+static inline
+void cx18_log_read_retries(struct cx18 *cx, int i, const void *addr)
+{
+       if (i > CX18_MAX_MMIO_RETRIES)
+               i = CX18_MAX_MMIO_RETRIES;
+       atomic_inc(&cx->mmio_stats.retried_read[i]);
+       return;
+}
+
+void cx18_log_statistics(struct cx18 *cx);
+
+/* Non byteswapping memory mapped IO */
+static inline
+void cx18_raw_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       __raw_writel(val, addr);
+       cx18_io_delay(cx);
+}
+
+void cx18_raw_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
+
+static inline void cx18_raw_writel(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               cx18_raw_writel_retry(cx, val, addr);
+       else
+               cx18_raw_writel_noretry(cx, val, addr);
+}
+
+
+static inline
+u32 cx18_raw_readl_noretry(struct cx18 *cx, const void __iomem *addr)
+{
+       u32 ret = __raw_readl(addr);
+       cx18_io_delay(cx);
+       return ret;
+}
+
+u32 cx18_raw_readl_retry(struct cx18 *cx, const void __iomem *addr);
+
+static inline u32 cx18_raw_readl(struct cx18 *cx, const void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_raw_readl_retry(cx, addr);
+
+       return cx18_raw_readl_noretry(cx, addr);
+}
+
+
+static inline
+u16 cx18_raw_readw_noretry(struct cx18 *cx, const void __iomem *addr)
+{
+       u16 ret = __raw_readw(addr);
+       cx18_io_delay(cx);
+       return ret;
+}
+
+u16 cx18_raw_readw_retry(struct cx18 *cx, const void __iomem *addr);
+
+static inline u16 cx18_raw_readw(struct cx18 *cx, const void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_raw_readw_retry(cx, addr);
+
+       return cx18_raw_readw_noretry(cx, addr);
+}
+
+
+/* Normal memory mapped IO */
+static inline
+void cx18_writel_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       writel(val, addr);
+       cx18_io_delay(cx);
+}
+
+void cx18_writel_retry(struct cx18 *cx, u32 val, void __iomem *addr);
+
+static inline void cx18_writel(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               cx18_writel_retry(cx, val, addr);
+       else
+               cx18_writel_noretry(cx, val, addr);
+}
+
+
+static inline
+void cx18_writew_noretry(struct cx18 *cx, u16 val, void __iomem *addr)
+{
+       writew(val, addr);
+       cx18_io_delay(cx);
+}
+
+void cx18_writew_retry(struct cx18 *cx, u16 val, void __iomem *addr);
+
+static inline void cx18_writew(struct cx18 *cx, u16 val, void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               cx18_writew_retry(cx, val, addr);
+       else
+               cx18_writew_noretry(cx, val, addr);
+}
+
+
+static inline
+void cx18_writeb_noretry(struct cx18 *cx, u8 val, void __iomem *addr)
+{
+       writeb(val, addr);
+       cx18_io_delay(cx);
+}
+
+void cx18_writeb_retry(struct cx18 *cx, u8 val, void __iomem *addr);
+
+static inline void cx18_writeb(struct cx18 *cx, u8 val, void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               cx18_writeb_retry(cx, val, addr);
+       else
+               cx18_writeb_noretry(cx, val, addr);
+}
+
+
+static inline u32 cx18_readl_noretry(struct cx18 *cx, const void __iomem *addr)
+{
+       u32 ret = readl(addr);
+       cx18_io_delay(cx);
+       return ret;
+}
+
+u32 cx18_readl_retry(struct cx18 *cx, const void __iomem *addr);
+
+static inline u32 cx18_readl(struct cx18 *cx, const void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_readl_retry(cx, addr);
+
+       return cx18_readl_noretry(cx, addr);
+}
+
+
+static inline u16 cx18_readw_noretry(struct cx18 *cx, const void __iomem *addr)
+{
+       u16 ret = readw(addr);
+       cx18_io_delay(cx);
+       return ret;
+}
+
+u16 cx18_readw_retry(struct cx18 *cx, const void __iomem *addr);
+
+static inline u16 cx18_readw(struct cx18 *cx, const void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_readw_retry(cx, addr);
+
+       return cx18_readw_noretry(cx, addr);
+}
+
+
+static inline u8 cx18_readb_noretry(struct cx18 *cx, const void __iomem *addr)
+{
+       u8 ret = readb(addr);
+       cx18_io_delay(cx);
+       return ret;
+}
+
+u8 cx18_readb_retry(struct cx18 *cx, const void __iomem *addr);
+
+static inline u8 cx18_readb(struct cx18 *cx, const void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_readb_retry(cx, addr);
+
+       return cx18_readb_noretry(cx, addr);
+}
+
+
+static inline
+u32 cx18_write_sync_noretry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       cx18_writel_noretry(cx, val, addr);
+       return cx18_readl_noretry(cx, addr);
+}
+
+static inline
+u32 cx18_write_sync_retry(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       cx18_writel_retry(cx, val, addr);
+       return cx18_readl_retry(cx, addr);
+}
+
+static inline u32 cx18_write_sync(struct cx18 *cx, u32 val, void __iomem *addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_write_sync_retry(cx, val, addr);
+
+       return cx18_write_sync_noretry(cx, val, addr);
+}
+
+
+void cx18_memcpy_fromio(struct cx18 *cx, void *to,
+                       const void __iomem *from, unsigned int len);
+void cx18_memset_io(struct cx18 *cx, void __iomem *addr, int val, size_t count);
+
+
+/* Access "register" region of CX23418 memory mapped I/O */
+static inline void cx18_write_reg_noretry(struct cx18 *cx, u32 val, u32 reg)
+{
+       cx18_writel_noretry(cx, val, cx->reg_mem + reg);
+}
+
+static inline void cx18_write_reg_retry(struct cx18 *cx, u32 val, u32 reg)
+{
+       cx18_writel_retry(cx, val, cx->reg_mem + reg);
+}
+
+static inline void cx18_write_reg(struct cx18 *cx, u32 val, u32 reg)
+{
+       if (cx18_retry_mmio)
+               cx18_write_reg_retry(cx, val, reg);
+       else
+               cx18_write_reg_noretry(cx, val, reg);
+}
+
+
+static inline u32 cx18_read_reg_noretry(struct cx18 *cx, u32 reg)
+{
+       return cx18_readl_noretry(cx, cx->reg_mem + reg);
+}
+
+static inline u32 cx18_read_reg_retry(struct cx18 *cx, u32 reg)
+{
+       return cx18_readl_retry(cx, cx->reg_mem + reg);
+}
+
+static inline u32 cx18_read_reg(struct cx18 *cx, u32 reg)
+{
+       if (cx18_retry_mmio)
+               return cx18_read_reg_retry(cx, reg);
+
+       return cx18_read_reg_noretry(cx, reg);
+}
+
+
+static inline u32 cx18_write_reg_sync_noretry(struct cx18 *cx, u32 val, u32 reg)
+{
+       return cx18_write_sync_noretry(cx, val, cx->reg_mem + reg);
+}
+
+static inline u32 cx18_write_reg_sync_retry(struct cx18 *cx, u32 val, u32 reg)
+{
+       return cx18_write_sync_retry(cx, val, cx->reg_mem + reg);
+}
+
+static inline u32 cx18_write_reg_sync(struct cx18 *cx, u32 val, u32 reg)
+{
+       if (cx18_retry_mmio)
+               return cx18_write_reg_sync_retry(cx, val, reg);
+
+       return cx18_write_reg_sync_noretry(cx, val, reg);
+}
+
+
+/* Access "encoder memory" region of CX23418 memory mapped I/O */
+static inline void cx18_write_enc_noretry(struct cx18 *cx, u32 val, u32 addr)
+{
+       cx18_writel_noretry(cx, val, cx->enc_mem + addr);
+}
+
+static inline void cx18_write_enc_retry(struct cx18 *cx, u32 val, u32 addr)
+{
+       cx18_writel_retry(cx, val, cx->enc_mem + addr);
+}
+
+static inline void cx18_write_enc(struct cx18 *cx, u32 val, u32 addr)
+{
+       if (cx18_retry_mmio)
+               cx18_write_enc_retry(cx, val, addr);
+       else
+               cx18_write_enc_noretry(cx, val, addr);
+}
+
+
+static inline u32 cx18_read_enc_noretry(struct cx18 *cx, u32 addr)
+{
+       return cx18_readl_noretry(cx, cx->enc_mem + addr);
+}
+
+static inline u32 cx18_read_enc_retry(struct cx18 *cx, u32 addr)
+{
+       return cx18_readl_retry(cx, cx->enc_mem + addr);
+}
+
+static inline u32 cx18_read_enc(struct cx18 *cx, u32 addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_read_enc_retry(cx, addr);
+
+       return cx18_read_enc_noretry(cx, addr);
+}
+
+static inline
+u32 cx18_write_enc_sync_noretry(struct cx18 *cx, u32 val, u32 addr)
+{
+       return cx18_write_sync_noretry(cx, val, cx->enc_mem + addr);
+}
+
+static inline
+u32 cx18_write_enc_sync_retry(struct cx18 *cx, u32 val, u32 addr)
+{
+       return cx18_write_sync_retry(cx, val, cx->enc_mem + addr);
+}
+
+static inline
+u32 cx18_write_enc_sync(struct cx18 *cx, u32 val, u32 addr)
+{
+       if (cx18_retry_mmio)
+               return cx18_write_enc_sync_retry(cx, val, addr);
+
+       return cx18_write_enc_sync_noretry(cx, val, addr);
+}
+
+void cx18_sw1_irq_enable(struct cx18 *cx, u32 val);
+void cx18_sw1_irq_disable(struct cx18 *cx, u32 val);
+void cx18_sw2_irq_enable(struct cx18 *cx, u32 val);
+void cx18_sw2_irq_disable(struct cx18 *cx, u32 val);
+void cx18_setup_page(struct cx18 *cx, u32 addr);
+
+#endif /* CX18_IO_H */
index a7f839631d6a6a5c2932385e956b6716b8059309..f0ca50f5fddeb3d290d1567f8d27a4e9d1378230 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-version.h"
 #include "cx18-mailbox.h"
 #include "cx18-i2c.h"
@@ -170,7 +171,6 @@ static int cx18_try_fmt_vid_cap(struct file *file, void *fh,
 {
        struct cx18_open_id *id = fh;
        struct cx18 *cx = id->cx;
-
        int w = fmt->fmt.pix.width;
        int h = fmt->fmt.pix.height;
 
@@ -202,8 +202,7 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
        struct cx18_open_id *id = fh;
        struct cx18 *cx = id->cx;
        int ret;
-       int w = fmt->fmt.pix.width;
-       int h = fmt->fmt.pix.height;
+       int w, h;
 
        ret = v4l2_prio_check(&cx->prio, &id->prio);
        if (ret)
@@ -212,6 +211,8 @@ static int cx18_s_fmt_vid_cap(struct file *file, void *fh,
        ret = cx18_try_fmt_vid_cap(file, fh, fmt);
        if (ret)
                return ret;
+       w = fmt->fmt.pix.width;
+       h = fmt->fmt.pix.height;
 
        if (cx->params.width == w && cx->params.height == h)
                return 0;
@@ -286,9 +287,9 @@ static int cx18_cxc(struct cx18 *cx, unsigned int cmd, void *arg)
 
        spin_lock_irqsave(&cx18_cards_lock, flags);
        if (cmd == VIDIOC_DBG_G_REGISTER)
-               regs->val = read_enc(regs->reg);
+               regs->val = cx18_read_enc(cx, regs->reg);
        else
-               write_enc(regs->val, regs->reg);
+               cx18_write_enc(cx, regs->val, regs->reg);
        spin_unlock_irqrestore(&cx18_cards_lock, flags);
        return 0;
 }
@@ -345,7 +346,7 @@ static int cx18_querycap(struct file *file, void *fh,
 
        strlcpy(vcap->driver, CX18_DRIVER_NAME, sizeof(vcap->driver));
        strlcpy(vcap->card, cx->card_name, sizeof(vcap->card));
-       strlcpy(vcap->bus_info, pci_name(cx->dev), sizeof(vcap->bus_info));
+       snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(cx->dev));
        vcap->version = CX18_DRIVER_VERSION;        /* version */
        vcap->capabilities = cx->v4l2_cap;          /* capabilities */
        return 0;
@@ -622,6 +623,7 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
 {
        struct cx18_open_id *id = fh;
        struct cx18 *cx = id->cx;
+       u32 h;
 
        switch (enc->cmd) {
        case V4L2_ENC_CMD_START:
@@ -643,8 +645,14 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
                        return -EPERM;
                if (test_and_set_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
                        return 0;
+               h = cx18_find_handle(cx);
+               if (h == CX18_INVALID_TASK_HANDLE) {
+                       CX18_ERR("Can't find valid task handle for "
+                                "V4L2_ENC_CMD_PAUSE\n");
+                       return -EBADFD;
+               }
                cx18_mute(cx);
-               cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, cx18_find_handle(cx));
+               cx18_vapi(cx, CX18_CPU_CAPTURE_PAUSE, 1, h);
                break;
 
        case V4L2_ENC_CMD_RESUME:
@@ -654,7 +662,13 @@ static int cx18_encoder_cmd(struct file *file, void *fh,
                        return -EPERM;
                if (!test_and_clear_bit(CX18_F_I_ENC_PAUSED, &cx->i_flags))
                        return 0;
-               cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, cx18_find_handle(cx));
+               h = cx18_find_handle(cx);
+               if (h == CX18_INVALID_TASK_HANDLE) {
+                       CX18_ERR("Can't find valid task handle for "
+                                "V4L2_ENC_CMD_RESUME\n");
+                       return -EBADFD;
+               }
+               cx18_vapi(cx, CX18_CPU_CAPTURE_RESUME, 1, h);
                cx18_unmute(cx);
                break;
 
@@ -731,12 +745,14 @@ static int cx18_log_status(struct file *file, void *fh)
                        continue;
                CX18_INFO("Stream %s: status 0x%04lx, %d%% of %d KiB (%d buffers) in use\n",
                          s->name, s->s_flags,
-                         (s->buffers - s->q_free.buffers) * 100 / s->buffers,
+                         (s->buffers - atomic_read(&s->q_free.buffers))
+                               * 100 / s->buffers,
                          (s->buffers * s->buf_size) / 1024, s->buffers);
        }
        CX18_INFO("Read MPEG/VBI: %lld/%lld bytes\n",
                        (long long)cx->mpg_data_received,
                        (long long)cx->vbi_data_inserted);
+       cx18_log_statistics(cx);
        CX18_INFO("==================  END STATUS CARD #%d  ==================\n", cx->num);
        return 0;
 }
index ab218315c84bb384fd71865392254c54fe9f9fbb..360330f5463f9ce985d4e835d84d9b5e12536b6d 100644 (file)
@@ -20,6 +20,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-firmware.h"
 #include "cx18-fileops.h"
 #include "cx18-queue.h"
@@ -48,8 +49,8 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
                        break;
        }
        if (i == CX18_MAX_STREAMS) {
-               CX18_WARN("DMA done for unknown handle %d for stream %s\n",
-                       handle, s->name);
+               CX18_WARN("Got DMA done notification for unknown/inactive"
+                         " handle %d\n", handle);
                mb->error = CXERR_NOT_OPEN;
                mb->cmd = 0;
                cx18_mb_ack(cx, mb);
@@ -60,8 +61,8 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
        if (mb->args[2] != 1)
                CX18_WARN("Ack struct = %d for %s\n",
                        mb->args[2], s->name);
-       id = read_enc(off);
-       buf = cx18_queue_get_buf_irq(s, id, read_enc(off + 4));
+       id = cx18_read_enc(cx, off);
+       buf = cx18_queue_get_buf_irq(s, id, cx18_read_enc(cx, off + 4));
        CX18_DEBUG_HI_DMA("DMA DONE for %s (buffer %d)\n", s->name, id);
        if (buf) {
                cx18_buf_sync_for_cpu(s, buf);
@@ -81,7 +82,7 @@ static void epu_dma_done(struct cx18 *cx, struct cx18_mailbox *mb)
                        set_bit(CX18_F_B_NEED_BUF_SWAP, &buf->b_flags);
        } else {
                CX18_WARN("Could not find buf %d for stream %s\n",
-                               read_enc(off), s->name);
+                               cx18_read_enc(cx, off), s->name);
        }
        mb->error = 0;
        mb->cmd = 0;
@@ -97,8 +98,8 @@ static void epu_debug(struct cx18 *cx, struct cx18_mailbox *mb)
        char *p;
 
        if (mb->args[1]) {
-               setup_page(mb->args[1]);
-               memcpy_fromio(str, cx->enc_mem + mb->args[1], 252);
+               cx18_setup_page(cx, mb->args[1]);
+               cx18_memcpy_fromio(cx, str, cx->enc_mem + mb->args[1], 252);
                str[252] = 0;
        }
        cx18_mb_ack(cx, mb);
@@ -113,7 +114,7 @@ static void hpu_cmd(struct cx18 *cx, u32 sw1)
        struct cx18_mailbox mb;
 
        if (sw1 & IRQ_CPU_TO_EPU) {
-               memcpy_fromio(&mb, &cx->scb->cpu2epu_mb, sizeof(mb));
+               cx18_memcpy_fromio(cx, &mb, &cx->scb->cpu2epu_mb, sizeof(mb));
                mb.error = 0;
 
                switch (mb.cmd) {
@@ -141,16 +142,16 @@ irqreturn_t cx18_irq_handler(int irq, void *dev_id)
 
        spin_lock(&cx->dma_reg_lock);
 
-       hw2_mask = read_reg(HW2_INT_MASK5_PCI);
-       hw2 = read_reg(HW2_INT_CLR_STATUS) & hw2_mask;
-       sw2_mask = read_reg(SW2_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU_ACK;
-       sw2 = read_reg(SW2_INT_STATUS) & sw2_mask;
-       sw1_mask = read_reg(SW1_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU;
-       sw1 = read_reg(SW1_INT_STATUS) & sw1_mask;
+       hw2_mask = cx18_read_reg(cx, HW2_INT_MASK5_PCI);
+       hw2 = cx18_read_reg(cx, HW2_INT_CLR_STATUS) & hw2_mask;
+       sw2_mask = cx18_read_reg(cx, SW2_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU_ACK;
+       sw2 = cx18_read_reg(cx, SW2_INT_STATUS) & sw2_mask;
+       sw1_mask = cx18_read_reg(cx, SW1_INT_ENABLE_PCI) | IRQ_EPU_TO_HPU;
+       sw1 = cx18_read_reg(cx, SW1_INT_STATUS) & sw1_mask;
 
-       write_reg(sw2&sw2_mask, SW2_INT_STATUS);
-       write_reg(sw1&sw1_mask, SW1_INT_STATUS);
-       write_reg(hw2&hw2_mask, HW2_INT_CLR_STATUS);
+       cx18_write_reg(cx, sw2&sw2_mask, SW2_INT_STATUS);
+       cx18_write_reg(cx, sw1&sw1_mask, SW1_INT_STATUS);
+       cx18_write_reg(cx, hw2&hw2_mask, HW2_INT_CLR_STATUS);
 
        if (sw1 || sw2 || hw2)
                CX18_DEBUG_HI_IRQ("SW1: %x  SW2: %x  HW2: %x\n", sw1, sw2, hw2);
@@ -161,15 +162,15 @@ irqreturn_t cx18_irq_handler(int irq, void *dev_id)
        */
 
        if (sw2) {
-               if (sw2 & (readl(&cx->scb->cpu2hpu_irq_ack) |
-                          readl(&cx->scb->cpu2epu_irq_ack)))
+               if (sw2 & (cx18_readl(cx, &cx->scb->cpu2hpu_irq_ack) |
+                          cx18_readl(cx, &cx->scb->cpu2epu_irq_ack)))
                        wake_up(&cx->mb_cpu_waitq);
-               if (sw2 & (readl(&cx->scb->apu2hpu_irq_ack) |
-                          readl(&cx->scb->apu2epu_irq_ack)))
+               if (sw2 & (cx18_readl(cx, &cx->scb->apu2hpu_irq_ack) |
+                          cx18_readl(cx, &cx->scb->apu2epu_irq_ack)))
                        wake_up(&cx->mb_apu_waitq);
-               if (sw2 & readl(&cx->scb->epu2hpu_irq_ack))
+               if (sw2 & cx18_readl(cx, &cx->scb->epu2hpu_irq_ack))
                        wake_up(&cx->mb_epu_waitq);
-               if (sw2 & readl(&cx->scb->hpu2epu_irq_ack))
+               if (sw2 & cx18_readl(cx, &cx->scb->hpu2epu_irq_ack))
                        wake_up(&cx->mb_hpu_waitq);
        }
 
index 93177514e846e8c5ab73ce485976ac8b424e773f..9d18dd22de76e9f1866fb27264159fb5b9798bce 100644 (file)
@@ -22,6 +22,7 @@
 #include <stdarg.h>
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-scb.h"
 #include "cx18-irq.h"
 #include "cx18-mailbox.h"
@@ -82,6 +83,7 @@ static const struct cx18_api_info api_info[] = {
        API_ENTRY(CPU, CX18_CPU_DE_SET_MDL_ACK,                 0),
        API_ENTRY(CPU, CX18_CPU_DE_SET_MDL,                     API_FAST),
        API_ENTRY(CPU, CX18_APU_RESETAI,                        API_FAST),
+       API_ENTRY(CPU, CX18_CPU_DE_RELEASE_MDL,                 0),
        API_ENTRY(0, 0,                                         0),
 };
 
@@ -105,20 +107,20 @@ static struct cx18_mailbox __iomem *cx18_mb_is_complete(struct cx18 *cx, int rpu
        switch (rpu) {
        case APU:
                mb = &cx->scb->epu2apu_mb;
-               *state = readl(&cx->scb->apu_state);
-               *irq = readl(&cx->scb->epu2apu_irq);
+               *state = cx18_readl(cx, &cx->scb->apu_state);
+               *irq = cx18_readl(cx, &cx->scb->epu2apu_irq);
                break;
 
        case CPU:
                mb = &cx->scb->epu2cpu_mb;
-               *state = readl(&cx->scb->cpu_state);
-               *irq = readl(&cx->scb->epu2cpu_irq);
+               *state = cx18_readl(cx, &cx->scb->cpu_state);
+               *irq = cx18_readl(cx, &cx->scb->epu2cpu_irq);
                break;
 
        case HPU:
                mb = &cx->scb->epu2hpu_mb;
-               *state = readl(&cx->scb->hpu_state);
-               *irq = readl(&cx->scb->epu2hpu_irq);
+               *state = cx18_readl(cx, &cx->scb->hpu_state);
+               *irq = cx18_readl(cx, &cx->scb->epu2hpu_irq);
                break;
        }
 
@@ -126,8 +128,8 @@ static struct cx18_mailbox __iomem *cx18_mb_is_complete(struct cx18 *cx, int rpu
                return mb;
 
        do {
-               *req = readl(&mb->request);
-               ack = readl(&mb->ack);
+               *req = cx18_readl(cx, &mb->request);
+               ack = cx18_readl(cx, &mb->ack);
                wait_count++;
        } while (*req != ack && wait_count < 600);
 
@@ -172,9 +174,9 @@ long cx18_mb_ack(struct cx18 *cx, const struct cx18_mailbox *mb)
                return -EINVAL;
        }
 
-       setup_page(SCB_OFFSET);
-       write_sync(mb->request, &ack_mb->ack);
-       write_reg(ack_irq, SW2_INT_SET);
+       cx18_setup_page(cx, SCB_OFFSET);
+       cx18_write_sync(cx, mb->request, &ack_mb->ack);
+       cx18_write_reg(cx, ack_irq, SW2_INT_SET);
        return 0;
 }
 
@@ -199,7 +201,7 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
                CX18_DEBUG_HI_API("%s\n", info->name);
        else
                CX18_DEBUG_API("%s\n", info->name);
-       setup_page(SCB_OFFSET);
+       cx18_setup_page(cx, SCB_OFFSET);
        mb = cx18_mb_is_complete(cx, info->rpu, &state, &irq, &req);
 
        if (mb == NULL) {
@@ -208,11 +210,11 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
        }
 
        oldreq = req - 1;
-       writel(cmd, &mb->cmd);
+       cx18_writel(cx, cmd, &mb->cmd);
        for (i = 0; i < args; i++)
-               writel(data[i], &mb->args[i]);
-       writel(0, &mb->error);
-       writel(req, &mb->request);
+               cx18_writel(cx, data[i], &mb->args[i]);
+       cx18_writel(cx, 0, &mb->error);
+       cx18_writel(cx, req, &mb->request);
 
        switch (info->rpu) {
        case APU: waitq = &cx->mb_apu_waitq; break;
@@ -223,9 +225,10 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
        }
        if (info->flags & API_FAST)
                timeout /= 2;
-       write_reg(irq, SW1_INT_SET);
+       cx18_write_reg(cx, irq, SW1_INT_SET);
 
-       while (!sig && readl(&mb->ack) != readl(&mb->request) && cnt < 660) {
+       while (!sig && cx18_readl(cx, &mb->ack) != cx18_readl(cx, &mb->request)
+              && cnt < 660) {
                if (cnt > 200 && !in_atomic())
                        sig = cx18_msleep_timeout(10, 1);
                cnt++;
@@ -233,13 +236,13 @@ static int cx18_api_call(struct cx18 *cx, u32 cmd, int args, u32 data[])
        if (sig)
                return -EINTR;
        if (cnt == 660) {
-               writel(oldreq, &mb->request);
+               cx18_writel(cx, oldreq, &mb->request);
                CX18_ERR("mb %s failed\n", info->name);
                return -EINVAL;
        }
        for (i = 0; i < MAX_MB_ARGUMENTS; i++)
-               data[i] = readl(&mb->args[i]);
-       err = readl(&mb->error);
+               data[i] = cx18_readl(cx, &mb->args[i]);
+       err = cx18_readl(cx, &mb->error);
        if (!in_atomic() && (info->flags & API_SLOW))
                cx18_msleep_timeout(300, 0);
        if (err)
index dbe792ac30015d68c760a1d42b2731f7a043042e..a33ba04a2686aa3ec73d0d705ddc1aa1bb3abad8 100644 (file)
@@ -37,8 +37,7 @@ void cx18_buf_swap(struct cx18_buffer *buf)
 void cx18_queue_init(struct cx18_queue *q)
 {
        INIT_LIST_HEAD(&q->list);
-       q->buffers = 0;
-       q->length = 0;
+       atomic_set(&q->buffers, 0);
        q->bytesused = 0;
 }
 
@@ -55,8 +54,7 @@ void cx18_enqueue(struct cx18_stream *s, struct cx18_buffer *buf,
        }
        spin_lock_irqsave(&s->qlock, flags);
        list_add_tail(&buf->list, &q->list);
-       q->buffers++;
-       q->length += s->buf_size;
+       atomic_inc(&q->buffers);
        q->bytesused += buf->bytesused - buf->readpos;
        spin_unlock_irqrestore(&s->qlock, flags);
 }
@@ -70,8 +68,7 @@ struct cx18_buffer *cx18_dequeue(struct cx18_stream *s, struct cx18_queue *q)
        if (!list_empty(&q->list)) {
                buf = list_entry(q->list.next, struct cx18_buffer, list);
                list_del_init(q->list.next);
-               q->buffers--;
-               q->length -= s->buf_size;
+               atomic_dec(&q->buffers);
                q->bytesused -= buf->bytesused - buf->readpos;
        }
        spin_unlock_irqrestore(&s->qlock, flags);
@@ -95,10 +92,8 @@ struct cx18_buffer *cx18_queue_get_buf_irq(struct cx18_stream *s, u32 id,
                /* the transport buffers are handled differently,
                   they are not moved to the full queue */
                if (s->type != CX18_ENC_STREAM_TYPE_TS) {
-                       s->q_free.buffers--;
-                       s->q_free.length -= s->buf_size;
-                       s->q_full.buffers++;
-                       s->q_full.length += s->buf_size;
+                       atomic_dec(&s->q_free.buffers);
+                       atomic_inc(&s->q_full.buffers);
                        s->q_full.bytesused += buf->bytesused;
                        list_move_tail(&buf->list, &s->q_full.list);
                }
@@ -124,8 +119,7 @@ static void cx18_queue_flush(struct cx18_stream *s, struct cx18_queue *q)
                buf = list_entry(q->list.next, struct cx18_buffer, list);
                list_move_tail(q->list.next, &s->q_free.list);
                buf->bytesused = buf->readpos = buf->b_flags = 0;
-               s->q_free.buffers++;
-               s->q_free.length += s->buf_size;
+               atomic_inc(&s->q_free.buffers);
        }
        cx18_queue_init(q);
        spin_unlock_irqrestore(&s->qlock, flags);
index 30bc803e30da5b31460fe04e374f3c716ce64b3f..f56d3772aa675bdb60464fc14ff3f4052ea7cb0b 100644 (file)
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-scb.h"
 
 void cx18_init_scb(struct cx18 *cx)
 {
-       setup_page(SCB_OFFSET);
-       memset_io(cx->scb, 0, 0x10000);
+       cx18_setup_page(cx, SCB_OFFSET);
+       cx18_memset_io(cx, cx->scb, 0, 0x10000);
 
-       writel(IRQ_APU_TO_CPU,     &cx->scb->apu2cpu_irq);
-       writel(IRQ_CPU_TO_APU_ACK, &cx->scb->cpu2apu_irq_ack);
-       writel(IRQ_HPU_TO_CPU,     &cx->scb->hpu2cpu_irq);
-       writel(IRQ_CPU_TO_HPU_ACK, &cx->scb->cpu2hpu_irq_ack);
-       writel(IRQ_PPU_TO_CPU,     &cx->scb->ppu2cpu_irq);
-       writel(IRQ_CPU_TO_PPU_ACK, &cx->scb->cpu2ppu_irq_ack);
-       writel(IRQ_EPU_TO_CPU,     &cx->scb->epu2cpu_irq);
-       writel(IRQ_CPU_TO_EPU_ACK, &cx->scb->cpu2epu_irq_ack);
+       cx18_writel(cx, IRQ_APU_TO_CPU,     &cx->scb->apu2cpu_irq);
+       cx18_writel(cx, IRQ_CPU_TO_APU_ACK, &cx->scb->cpu2apu_irq_ack);
+       cx18_writel(cx, IRQ_HPU_TO_CPU,     &cx->scb->hpu2cpu_irq);
+       cx18_writel(cx, IRQ_CPU_TO_HPU_ACK, &cx->scb->cpu2hpu_irq_ack);
+       cx18_writel(cx, IRQ_PPU_TO_CPU,     &cx->scb->ppu2cpu_irq);
+       cx18_writel(cx, IRQ_CPU_TO_PPU_ACK, &cx->scb->cpu2ppu_irq_ack);
+       cx18_writel(cx, IRQ_EPU_TO_CPU,     &cx->scb->epu2cpu_irq);
+       cx18_writel(cx, IRQ_CPU_TO_EPU_ACK, &cx->scb->cpu2epu_irq_ack);
 
-       writel(IRQ_CPU_TO_APU,     &cx->scb->cpu2apu_irq);
-       writel(IRQ_APU_TO_CPU_ACK, &cx->scb->apu2cpu_irq_ack);
-       writel(IRQ_HPU_TO_APU,     &cx->scb->hpu2apu_irq);
-       writel(IRQ_APU_TO_HPU_ACK, &cx->scb->apu2hpu_irq_ack);
-       writel(IRQ_PPU_TO_APU,     &cx->scb->ppu2apu_irq);
-       writel(IRQ_APU_TO_PPU_ACK, &cx->scb->apu2ppu_irq_ack);
-       writel(IRQ_EPU_TO_APU,     &cx->scb->epu2apu_irq);
-       writel(IRQ_APU_TO_EPU_ACK, &cx->scb->apu2epu_irq_ack);
+       cx18_writel(cx, IRQ_CPU_TO_APU,     &cx->scb->cpu2apu_irq);
+       cx18_writel(cx, IRQ_APU_TO_CPU_ACK, &cx->scb->apu2cpu_irq_ack);
+       cx18_writel(cx, IRQ_HPU_TO_APU,     &cx->scb->hpu2apu_irq);
+       cx18_writel(cx, IRQ_APU_TO_HPU_ACK, &cx->scb->apu2hpu_irq_ack);
+       cx18_writel(cx, IRQ_PPU_TO_APU,     &cx->scb->ppu2apu_irq);
+       cx18_writel(cx, IRQ_APU_TO_PPU_ACK, &cx->scb->apu2ppu_irq_ack);
+       cx18_writel(cx, IRQ_EPU_TO_APU,     &cx->scb->epu2apu_irq);
+       cx18_writel(cx, IRQ_APU_TO_EPU_ACK, &cx->scb->apu2epu_irq_ack);
 
-       writel(IRQ_CPU_TO_HPU,     &cx->scb->cpu2hpu_irq);
-       writel(IRQ_HPU_TO_CPU_ACK, &cx->scb->hpu2cpu_irq_ack);
-       writel(IRQ_APU_TO_HPU,     &cx->scb->apu2hpu_irq);
-       writel(IRQ_HPU_TO_APU_ACK, &cx->scb->hpu2apu_irq_ack);
-       writel(IRQ_PPU_TO_HPU,     &cx->scb->ppu2hpu_irq);
-       writel(IRQ_HPU_TO_PPU_ACK, &cx->scb->hpu2ppu_irq_ack);
-       writel(IRQ_EPU_TO_HPU,     &cx->scb->epu2hpu_irq);
-       writel(IRQ_HPU_TO_EPU_ACK, &cx->scb->hpu2epu_irq_ack);
+       cx18_writel(cx, IRQ_CPU_TO_HPU,     &cx->scb->cpu2hpu_irq);
+       cx18_writel(cx, IRQ_HPU_TO_CPU_ACK, &cx->scb->hpu2cpu_irq_ack);
+       cx18_writel(cx, IRQ_APU_TO_HPU,     &cx->scb->apu2hpu_irq);
+       cx18_writel(cx, IRQ_HPU_TO_APU_ACK, &cx->scb->hpu2apu_irq_ack);
+       cx18_writel(cx, IRQ_PPU_TO_HPU,     &cx->scb->ppu2hpu_irq);
+       cx18_writel(cx, IRQ_HPU_TO_PPU_ACK, &cx->scb->hpu2ppu_irq_ack);
+       cx18_writel(cx, IRQ_EPU_TO_HPU,     &cx->scb->epu2hpu_irq);
+       cx18_writel(cx, IRQ_HPU_TO_EPU_ACK, &cx->scb->hpu2epu_irq_ack);
 
-       writel(IRQ_CPU_TO_PPU,     &cx->scb->cpu2ppu_irq);
-       writel(IRQ_PPU_TO_CPU_ACK, &cx->scb->ppu2cpu_irq_ack);
-       writel(IRQ_APU_TO_PPU,     &cx->scb->apu2ppu_irq);
-       writel(IRQ_PPU_TO_APU_ACK, &cx->scb->ppu2apu_irq_ack);
-       writel(IRQ_HPU_TO_PPU,     &cx->scb->hpu2ppu_irq);
-       writel(IRQ_PPU_TO_HPU_ACK, &cx->scb->ppu2hpu_irq_ack);
-       writel(IRQ_EPU_TO_PPU,     &cx->scb->epu2ppu_irq);
-       writel(IRQ_PPU_TO_EPU_ACK, &cx->scb->ppu2epu_irq_ack);
+       cx18_writel(cx, IRQ_CPU_TO_PPU,     &cx->scb->cpu2ppu_irq);
+       cx18_writel(cx, IRQ_PPU_TO_CPU_ACK, &cx->scb->ppu2cpu_irq_ack);
+       cx18_writel(cx, IRQ_APU_TO_PPU,     &cx->scb->apu2ppu_irq);
+       cx18_writel(cx, IRQ_PPU_TO_APU_ACK, &cx->scb->ppu2apu_irq_ack);
+       cx18_writel(cx, IRQ_HPU_TO_PPU,     &cx->scb->hpu2ppu_irq);
+       cx18_writel(cx, IRQ_PPU_TO_HPU_ACK, &cx->scb->ppu2hpu_irq_ack);
+       cx18_writel(cx, IRQ_EPU_TO_PPU,     &cx->scb->epu2ppu_irq);
+       cx18_writel(cx, IRQ_PPU_TO_EPU_ACK, &cx->scb->ppu2epu_irq_ack);
 
-       writel(IRQ_CPU_TO_EPU,     &cx->scb->cpu2epu_irq);
-       writel(IRQ_EPU_TO_CPU_ACK, &cx->scb->epu2cpu_irq_ack);
-       writel(IRQ_APU_TO_EPU,     &cx->scb->apu2epu_irq);
-       writel(IRQ_EPU_TO_APU_ACK, &cx->scb->epu2apu_irq_ack);
-       writel(IRQ_HPU_TO_EPU,     &cx->scb->hpu2epu_irq);
-       writel(IRQ_EPU_TO_HPU_ACK, &cx->scb->epu2hpu_irq_ack);
-       writel(IRQ_PPU_TO_EPU,     &cx->scb->ppu2epu_irq);
-       writel(IRQ_EPU_TO_PPU_ACK, &cx->scb->epu2ppu_irq_ack);
+       cx18_writel(cx, IRQ_CPU_TO_EPU,     &cx->scb->cpu2epu_irq);
+       cx18_writel(cx, IRQ_EPU_TO_CPU_ACK, &cx->scb->epu2cpu_irq_ack);
+       cx18_writel(cx, IRQ_APU_TO_EPU,     &cx->scb->apu2epu_irq);
+       cx18_writel(cx, IRQ_EPU_TO_APU_ACK, &cx->scb->epu2apu_irq_ack);
+       cx18_writel(cx, IRQ_HPU_TO_EPU,     &cx->scb->hpu2epu_irq);
+       cx18_writel(cx, IRQ_EPU_TO_HPU_ACK, &cx->scb->epu2hpu_irq_ack);
+       cx18_writel(cx, IRQ_PPU_TO_EPU,     &cx->scb->ppu2epu_irq);
+       cx18_writel(cx, IRQ_EPU_TO_PPU_ACK, &cx->scb->epu2ppu_irq_ack);
 
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2cpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2cpu_mb),
                        &cx->scb->apu2cpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2cpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2cpu_mb),
                        &cx->scb->hpu2cpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2cpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2cpu_mb),
                        &cx->scb->ppu2cpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2cpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2cpu_mb),
                        &cx->scb->epu2cpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2apu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2apu_mb),
                        &cx->scb->cpu2apu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2apu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2apu_mb),
                        &cx->scb->hpu2apu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2apu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2apu_mb),
                        &cx->scb->ppu2apu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2apu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2apu_mb),
                        &cx->scb->epu2apu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2hpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2hpu_mb),
                        &cx->scb->cpu2hpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2hpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2hpu_mb),
                        &cx->scb->apu2hpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2hpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2hpu_mb),
                        &cx->scb->ppu2hpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2hpu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2hpu_mb),
                        &cx->scb->epu2hpu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2ppu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2ppu_mb),
                        &cx->scb->cpu2ppu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2ppu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2ppu_mb),
                        &cx->scb->apu2ppu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2ppu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2ppu_mb),
                        &cx->scb->hpu2ppu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, epu2ppu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, epu2ppu_mb),
                        &cx->scb->epu2ppu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu2epu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu2epu_mb),
                        &cx->scb->cpu2epu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, apu2epu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, apu2epu_mb),
                        &cx->scb->apu2epu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, hpu2epu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, hpu2epu_mb),
                        &cx->scb->hpu2epu_mb_offset);
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, ppu2epu_mb),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, ppu2epu_mb),
                        &cx->scb->ppu2epu_mb_offset);
 
-       writel(SCB_OFFSET + offsetof(struct cx18_scb, cpu_state),
+       cx18_writel(cx, SCB_OFFSET + offsetof(struct cx18_scb, cpu_state),
                        &cx->scb->ipc_offset);
 
-       writel(1, &cx->scb->hpu_state);
-       writel(1, &cx->scb->epu_state);
+       cx18_writel(cx, 1, &cx->scb->hpu_state);
+       cx18_writel(cx, 1, &cx->scb->epu_state);
 }
index 0da57f583bf75a90207b6b82bd5b762f95c742c6..0c8e7542cf6044ec86fbe8e0c6eb8931240c8e25 100644 (file)
@@ -22,6 +22,7 @@
  */
 
 #include "cx18-driver.h"
+#include "cx18-io.h"
 #include "cx18-fileops.h"
 #include "cx18-mailbox.h"
 #include "cx18-i2c.h"
@@ -56,7 +57,7 @@ static struct file_operations cx18_v4l2_enc_fops = {
 static struct {
        const char *name;
        int vfl_type;
-       int minor_offset;
+       int num_offset;
        int dma;
        enum v4l2_buf_type buf_type;
        struct file_operations *fops;
@@ -119,7 +120,7 @@ static void cx18_stream_init(struct cx18 *cx, int type)
        s->cx = cx;
        s->type = type;
        s->name = cx18_stream_info[type].name;
-       s->handle = 0xffffffff;
+       s->handle = CX18_INVALID_TASK_HANDLE;
 
        s->dma = cx18_stream_info[type].dma;
        s->buf_size = cx->stream_buf_size[type];
@@ -143,8 +144,8 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
 {
        struct cx18_stream *s = &cx->streams[type];
        u32 cap = cx->v4l2_cap;
-       int minor_offset = cx18_stream_info[type].minor_offset;
-       int minor;
+       int num_offset = cx18_stream_info[type].num_offset;
+       int num = cx->num + cx18_first_minor + num_offset;
 
        /* These four fields are always initialized. If v4l2dev == NULL, then
           this stream is not in use. In that case no other fields but these
@@ -163,9 +164,6 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
            !(cap & (V4L2_CAP_VBI_CAPTURE | V4L2_CAP_SLICED_VBI_CAPTURE)))
                return 0;
 
-       /* card number + user defined offset + device offset */
-       minor = cx->num + cx18_first_minor + minor_offset;
-
        /* User explicitly selected 0 buffers for these streams, so don't
           create them. */
        if (cx18_stream_info[type].dma != PCI_DMA_NONE &&
@@ -176,7 +174,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
 
        cx18_stream_init(cx, type);
 
-       if (minor_offset == -1)
+       if (num_offset == -1)
                return 0;
 
        /* allocate and initialize the v4l2 video device structure */
@@ -190,7 +188,7 @@ static int cx18_prep_dev(struct cx18 *cx, int type)
        snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "cx18-%d",
                        cx->num);
 
-       s->v4l2dev->minor = minor;
+       s->v4l2dev->num = num;
        s->v4l2dev->parent = &cx->dev->dev;
        s->v4l2dev->fops = cx18_stream_info[type].fops;
        s->v4l2dev->release = video_device_release;
@@ -226,7 +224,7 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
 {
        struct cx18_stream *s = &cx->streams[type];
        int vfl_type = cx18_stream_info[type].vfl_type;
-       int minor;
+       int num;
 
        /* TODO: Shouldn't this be a VFL_TYPE_TRANSPORT or something?
         * We need a VFL_TYPE_TS defined.
@@ -244,38 +242,44 @@ static int cx18_reg_dev(struct cx18 *cx, int type)
        if (s->v4l2dev == NULL)
                return 0;
 
-       minor = s->v4l2dev->minor;
+       num = s->v4l2dev->num;
+       /* card number + user defined offset + device offset */
+       if (type != CX18_ENC_STREAM_TYPE_MPG) {
+               struct cx18_stream *s_mpg = &cx->streams[CX18_ENC_STREAM_TYPE_MPG];
+
+               if (s_mpg->v4l2dev)
+                       num = s_mpg->v4l2dev->num + cx18_stream_info[type].num_offset;
+       }
 
        /* Register device. First try the desired minor, then any free one. */
-       if (video_register_device(s->v4l2dev, vfl_type, minor) &&
-                       video_register_device(s->v4l2dev, vfl_type, -1)) {
-               CX18_ERR("Couldn't register v4l2 device for %s minor %d\n",
-                       s->name, minor);
+       if (video_register_device(s->v4l2dev, vfl_type, num)) {
+               CX18_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
+                       s->name, num);
                video_device_release(s->v4l2dev);
                s->v4l2dev = NULL;
                return -ENOMEM;
        }
-       minor = s->v4l2dev->minor;
+       num = s->v4l2dev->num;
 
        switch (vfl_type) {
        case VFL_TYPE_GRABBER:
                CX18_INFO("Registered device video%d for %s (%d MB)\n",
-                       minor, s->name, cx->options.megabytes[type]);
+                       num, s->name, cx->options.megabytes[type]);
                break;
 
        case VFL_TYPE_RADIO:
                CX18_INFO("Registered device radio%d for %s\n",
-                       minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
+                       num, s->name);
                break;
 
        case VFL_TYPE_VBI:
                if (cx->options.megabytes[type])
                        CX18_INFO("Registered device vbi%d for %s (%d MB)\n",
-                               minor - MINOR_VFL_TYPE_VBI_MIN,
+                               num,
                                s->name, cx->options.megabytes[type]);
                else
                        CX18_INFO("Registered device vbi%d for %s\n",
-                               minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
+                               num, s->name);
                break;
        }
 
@@ -432,7 +436,6 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
        default:
                return -EINVAL;
        }
-       s->buffers_stolen = 0;
 
        /* mute/unmute video */
        cx18_vapi(cx, CX18_CPU_SET_VIDEO_MUTE, 2,
@@ -470,7 +473,7 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
 
        if (atomic_read(&cx->tot_capturing) == 0) {
                clear_bit(CX18_F_I_EOS, &cx->i_flags);
-               write_reg(7, CX18_DSP0_INTERRUPT_MASK);
+               cx18_write_reg(cx, 7, CX18_DSP0_INTERRUPT_MASK);
        }
 
        cx18_vapi(cx, CX18_CPU_DE_SET_MDL_ACK, 3, s->handle,
@@ -480,8 +483,9 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
        list_for_each(p, &s->q_free.list) {
                struct cx18_buffer *buf = list_entry(p, struct cx18_buffer, list);
 
-               writel(buf->dma_handle, &cx->scb->cpu_mdl[buf->id].paddr);
-               writel(s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
+               cx18_writel(cx, buf->dma_handle,
+                                       &cx->scb->cpu_mdl[buf->id].paddr);
+               cx18_writel(cx, s->buf_size, &cx->scb->cpu_mdl[buf->id].length);
                cx18_vapi(cx, CX18_CPU_DE_SET_MDL, 5, s->handle,
                        (void __iomem *)&cx->scb->cpu_mdl[buf->id] - cx->enc_mem,
                        1, buf->id, s->buf_size);
@@ -489,7 +493,14 @@ int cx18_start_v4l2_encode_stream(struct cx18_stream *s)
        /* begin_capture */
        if (cx18_vapi(cx, CX18_CPU_CAPTURE_START, 1, s->handle)) {
                CX18_DEBUG_WARN("Error starting capture!\n");
+               /* Ensure we're really not capturing before releasing MDLs */
+               if (s->type == CX18_ENC_STREAM_TYPE_MPG)
+                       cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 2, s->handle, 1);
+               else
+                       cx18_vapi(cx, CX18_CPU_CAPTURE_STOP, 1, s->handle);
+               cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
                cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
+               /* FIXME - clean-up DSP0_INT mask, i_flags, s_flags, etc. */
                return -EINVAL;
        }
 
@@ -541,6 +552,9 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
                CX18_INFO("ignoring gop_end: not (yet?) supported by the firmware\n");
        }
 
+       /* Tell the CX23418 it can't use our buffers anymore */
+       cx18_vapi(cx, CX18_CPU_DE_RELEASE_MDL, 1, s->handle);
+
        if (s->type != CX18_ENC_STREAM_TYPE_TS)
                atomic_dec(&cx->ana_capturing);
        atomic_dec(&cx->tot_capturing);
@@ -549,12 +563,12 @@ int cx18_stop_v4l2_encode_stream(struct cx18_stream *s, int gop_end)
        clear_bit(CX18_F_S_STREAMING, &s->s_flags);
 
        cx18_vapi(cx, CX18_DESTROY_TASK, 1, s->handle);
-       s->handle = 0xffffffff;
+       s->handle = CX18_INVALID_TASK_HANDLE;
 
        if (atomic_read(&cx->tot_capturing) > 0)
                return 0;
 
-       write_reg(5, CX18_DSP0_INTERRUPT_MASK);
+       cx18_write_reg(cx, 5, CX18_DSP0_INTERRUPT_MASK);
        wake_up(&s->waitq);
 
        return 0;
@@ -568,8 +582,8 @@ u32 cx18_find_handle(struct cx18 *cx)
        for (i = 0; i < CX18_MAX_STREAMS; i++) {
                struct cx18_stream *s = &cx->streams[i];
 
-               if (s->v4l2dev && s->handle)
+               if (s->v4l2dev && (s->handle != CX18_INVALID_TASK_HANDLE))
                        return s->handle;
        }
-       return 0;
+       return CX18_INVALID_TASK_HANDLE;
 }
index d5c7a6f968dda201b154d4d2d06563b8ca1bd44b..9f6be2d457fb727cc26f8bb0720729f2f7bd2677 100644 (file)
@@ -25,7 +25,7 @@
 #define CX18_DRIVER_NAME "cx18"
 #define CX18_DRIVER_VERSION_MAJOR 1
 #define CX18_DRIVER_VERSION_MINOR 0
-#define CX18_DRIVER_VERSION_PATCHLEVEL 0
+#define CX18_DRIVER_VERSION_PATCHLEVEL 1
 
 #define CX18_VERSION __stringify(CX18_DRIVER_VERSION_MAJOR) "." __stringify(CX18_DRIVER_VERSION_MINOR) "." __stringify(CX18_DRIVER_VERSION_PATCHLEVEL)
 #define CX18_DRIVER_VERSION KERNEL_VERSION(CX18_DRIVER_VERSION_MAJOR, \
index e7ed053059a8fdb4dc28a7cf5a7057b86e89971e..668f968d7761846cb17ae5d046f9154ca68be08f 100644 (file)
    Descriptor Lists to the driver
    IN[0] - Task handle. Handle of the task to start
    ReturnCode - One of the ERR_DE_... */
-/* #define CX18_CPU_DE_ReleaseMDL               (CPU_CMD_MASK_DE | 0x0006) */
+#define CX18_CPU_DE_RELEASE_MDL                (CPU_CMD_MASK_DE | 0x0006)
 
 /* Description: This command signals the cpu that the dat buffer has been
    consumed and ready for re-use.
index 22847a0444f59d051acd3e3d68bcbc2ad6852c50..cbbe47fb87b7a7c6a836f0fee5e2422cb6e41a95 100644 (file)
@@ -508,7 +508,10 @@ int cx2341x_ctrl_query(const struct cx2341x_mpeg_params *params,
                /* this setting is read-only for the cx2341x since the
                   V4L2_CID_MPEG_STREAM_TYPE really determines the
                   MPEG-1/2 setting */
-               err = v4l2_ctrl_query_fill_std(qctrl);
+               err = v4l2_ctrl_query_fill(qctrl,
+                                          V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
+                                          V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
+                                          V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
                if (err == 0)
                        qctrl->flags |= V4L2_CTRL_FLAG_READ_ONLY;
                return err;
index e60bd31b51a359cbc98857383cc76be0cfa0bc51..8c1b7fa47a41cc36f35d3f4c763ff65c190e792c 100644 (file)
@@ -15,6 +15,7 @@ config VIDEO_CX23885
        select DVB_S5H1409 if !DVB_FE_CUSTOMISE
        select DVB_S5H1411 if !DVB_FE_CUSTOMISE
        select DVB_LGDT330X if !DVB_FE_CUSTOMISE
+       select DVB_ZL10353 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_XC2028 if !DVB_FE_CUSTOMIZE
        select MEDIA_TUNER_TDA8290 if !DVB_FE_CUSTOMIZE
        select MEDIA_TUNER_TDA18271 if !DVB_FE_CUSTOMIZE
index 7b0e8c01692efab12f289c2fc3f843cdff733548..395c11fa47ceb486206eaf37f44145644762bc31 100644 (file)
@@ -36,7 +36,6 @@
 #include <media/cx2341x.h>
 
 #include "cx23885.h"
-#include "media/cx2341x.h"
 
 #define CX23885_FIRM_IMAGE_SIZE 376836
 #define CX23885_FIRM_IMAGE_NAME "v4l-cx23885-enc.fw"
@@ -632,7 +631,7 @@ int mc417_memory_read(struct cx23885_dev *dev, u32 address, u32 *value)
 /* ------------------------------------------------------------------ */
 
 /* MPEG encoder API */
-char *cmd_to_str(int cmd)
+static char *cmd_to_str(int cmd)
 {
        switch (cmd) {
        case CX2341X_ENC_PING_FW:
@@ -1583,6 +1582,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
 
        dprintk(2, "%s()\n", __func__);
 
+       lock_kernel();
        list_for_each(list, &cx23885_devlist) {
                h = list_entry(list, struct cx23885_dev, devlist);
                if (h->v4l_device->minor == minor) {
@@ -1591,13 +1591,17 @@ static int mpeg_open(struct inode *inode, struct file *file)
                }
        }
 
-       if (dev == NULL)
+       if (dev == NULL) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh), GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
 
        file->private_data = fh;
        fh->dev      = dev;
@@ -1608,6 +1612,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
                            V4L2_FIELD_INTERLACED,
                            sizeof(struct cx23885_buffer),
                            fh);
+       unlock_kernel();
 
        return 0;
 }
index c36d3f632104a22c37b408805f056ccddec936c8..2cda15f829fdda6fb434b60f78e8b9e78cff22f7 100644 (file)
@@ -26,6 +26,7 @@
 #include <media/cx25840.h>
 
 #include "cx23885.h"
+#include "tuner-xc2028.h"
 
 /* ------------------------------------------------------------------ */
 /* board config info                                                  */
@@ -148,6 +149,15 @@ struct cx23885_board cx23885_boards[] = {
                .portb          = CX23885_MPEG_DVB,
                .portc          = CX23885_MPEG_DVB,
        },
+       [CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP] = {
+               .name           = "DViCO FusionHDTV DVB-T Dual Express",
+               .portb          = CX23885_MPEG_DVB,
+               .portc          = CX23885_MPEG_DVB,
+       },
+       [CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H] = {
+               .name           = "Leadtek Winfast PxDVR3200 H",
+               .portc          = CX23885_MPEG_DVB,
+       },
 };
 const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
 
@@ -219,6 +229,14 @@ struct cx23885_subid cx23885_subids[] = {
                .subvendor = 0x18ac,
                .subdevice = 0xd618,
                .card      = CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP,
+       },{
+               .subvendor = 0x18ac,
+               .subdevice = 0xdb78,
+               .card      = CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP,
+       }, {
+               .subvendor = 0x107d,
+               .subdevice = 0x6681,
+               .card      = CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H,
        },
 };
 const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -319,15 +337,15 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
                        dev->name, tv.model);
 }
 
-/* Tuner callback function for cx23885 boards. Currently only needed
- * for HVR1500Q, which has an xc5000 tuner.
- */
-int cx23885_tuner_callback(void *priv, int command, int arg)
+int cx23885_tuner_callback(void *priv, int component, int command, int arg)
 {
-       struct cx23885_i2c *bus = priv;
-       struct cx23885_dev *dev = bus->dev;
+       struct cx23885_tsport *port = priv;
+       struct cx23885_dev *dev = port->dev;
        u32 bitmask = 0;
 
+       if (command == XC2028_RESET_CLK)
+               return 0;
+
        if (command != 0) {
                printk(KERN_ERR "%s(): Unknown command 0x%x.\n",
                        __func__, command);
@@ -335,21 +353,21 @@ int cx23885_tuner_callback(void *priv, int command, int arg)
        }
 
        switch(dev->board) {
+       case CX23885_BOARD_HAUPPAUGE_HVR1400:
+       case CX23885_BOARD_HAUPPAUGE_HVR1500:
        case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
-               /* Tuner Reset Command from xc5000 */
-               if (command == 0)
-                       bitmask = 0x04;
+       case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+               /* Tuner Reset Command */
+               bitmask = 0x04;
                break;
        case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
-               if (command == 0) {
-
-                       /* Two identical tuners on two different i2c buses,
-                        * we need to reset the correct gpio. */
-                       if (bus->nr == 0)
-                               bitmask = 0x01;
-                       else if (bus->nr == 1)
-                               bitmask = 0x04;
-               }
+       case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
+               /* Two identical tuners on two different i2c buses,
+                * we need to reset the correct gpio. */
+               if (port->nr == 0)
+                       bitmask = 0x01;
+               else if (port->nr == 1)
+                       bitmask = 0x04;
                break;
        }
 
@@ -465,6 +483,32 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
                mdelay(20);
                cx_set(GP0_IO, 0x000f000f);
                break;
+       case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
+               /* GPIO-0 portb xc3028 reset */
+               /* GPIO-1 portb zl10353 reset */
+               /* GPIO-2 portc xc3028 reset */
+               /* GPIO-3 portc zl10353 reset */
+
+               /* Put the parts into reset and back */
+               cx_set(GP0_IO, 0x000f0000);
+               mdelay(20);
+               cx_clear(GP0_IO, 0x0000000f);
+               mdelay(20);
+               cx_set(GP0_IO, 0x000f000f);
+               break;
+       case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+               /* GPIO-2  xc3028 tuner reset */
+
+               /* The following GPIO's are on the internal AVCore (cx25840) */
+               /* GPIO-?  zl10353 demod reset */
+
+               /* Put the parts into reset and back */
+               cx_set(GP0_IO, 0x00040000);
+               mdelay(20);
+               cx_clear(GP0_IO, 0x00000004);
+               mdelay(20);
+               cx_set(GP0_IO, 0x00040004);
+               break;
        }
 }
 
@@ -479,6 +523,9 @@ int cx23885_ir_init(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1400:
                /* FIXME: Implement me */
                break;
+       case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
+               request_module("ir-kbd-i2c");
+               break;
        }
 
        return 0;
@@ -516,6 +563,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
 
        switch (dev->board) {
        case CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP:
+       case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP:
                ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
                ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
                ts2->src_sel_val   = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
@@ -548,6 +596,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1200:
        case CX23885_BOARD_HAUPPAUGE_HVR1700:
        case CX23885_BOARD_HAUPPAUGE_HVR1400:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
        default:
                ts2->gen_ctrl_val  = 0xc; /* Serial bus + punctured clock */
                ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
@@ -561,6 +610,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
        case CX23885_BOARD_HAUPPAUGE_HVR1800:
        case CX23885_BOARD_HAUPPAUGE_HVR1800lp:
        case CX23885_BOARD_HAUPPAUGE_HVR1700:
+       case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
                request_module("cx25840");
                break;
        }
index 25fb09938744b67fdcece9661983e827daeda1db..beb3e61669a3373af706781717081aedf4dfa489 100644 (file)
@@ -1442,7 +1442,7 @@ void cx23885_cancel_buffers(struct cx23885_tsport *port)
        struct cx23885_dev *dev = port->dev;
        struct cx23885_dmaqueue *q = &port->mpegq;
 
-       dprintk(1, "%s()\n", __FUNCTION__);
+       dprintk(1, "%s()\n", __func__);
        del_timer_sync(&q->timeout);
        cx23885_stop_dma(port);
        do_cancel_buffers(port, "cancel", 0);
index 291b9d008da87f17897390b09cbcbf785201d5a1..24bd18327aa0f50b924bdf69527a5e373937c7fb 100644 (file)
@@ -42,6 +42,7 @@
 #include "tuner-simple.h"
 #include "dib7000p.h"
 #include "dibx000_common.h"
+#include "zl10353.h"
 
 static unsigned int debug;
 
@@ -188,13 +189,11 @@ static struct s5h1411_config dvico_s5h1411_config = {
 static struct xc5000_config hauppauge_hvr1500q_tunerconfig = {
        .i2c_address      = 0x61,
        .if_khz           = 5380,
-       .tuner_callback   = cx23885_tuner_callback
 };
 
 static struct xc5000_config dvico_xc5000_tunerconfig = {
        .i2c_address      = 0x64,
        .if_khz           = 5380,
-       .tuner_callback   = cx23885_tuner_callback
 };
 
 static struct tda829x_config tda829x_no_probe = {
@@ -303,35 +302,11 @@ static struct dib7000p_config hauppauge_hvr1400_dib7000_config = {
        .output_mode = OUTMODE_MPEG2_SERIAL,
 };
 
-static int cx23885_hvr1500_xc3028_callback(void *ptr, int command, int arg)
-{
-       struct cx23885_tsport *port = ptr;
-       struct cx23885_dev *dev = port->dev;
-
-       switch (command) {
-       case XC2028_TUNER_RESET:
-               /* Send the tuner in then out of reset */
-               /* GPIO-2 xc3028 tuner */
-               dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
-
-               cx_set(GP0_IO, 0x00040000);
-               cx_clear(GP0_IO, 0x00000004);
-               msleep(5);
-
-               cx_set(GP0_IO, 0x00040004);
-               msleep(5);
-               break;
-       case XC2028_RESET_CLK:
-               dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
-               break;
-       default:
-               dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
-                       command, arg);
-               return -EINVAL;
-       }
-
-       return 0;
-}
+static struct zl10353_config dvico_fusionhdtv_xc3028 = {
+       .demod_address = 0x0f,
+       .if2           = 45600,
+       .no_tuner      = 1,
+};
 
 static int dvb_register(struct cx23885_tsport *port)
 {
@@ -413,8 +388,8 @@ static int dvb_register(struct cx23885_tsport *port)
                                                &dev->i2c_bus[0].i2c_adap);
                if (port->dvb.frontend != NULL)
                        dvb_attach(xc5000_attach, port->dvb.frontend,
-                               &i2c_bus->i2c_adap,
-                               &hauppauge_hvr1500q_tunerconfig, i2c_bus);
+                                  &i2c_bus->i2c_adap,
+                                  &hauppauge_hvr1500q_tunerconfig);
                break;
        case CX23885_BOARD_HAUPPAUGE_HVR1500:
                i2c_bus = &dev->i2c_bus[1];
@@ -426,10 +401,9 @@ static int dvb_register(struct cx23885_tsport *port)
                        struct xc2028_config cfg = {
                                .i2c_adap  = &i2c_bus->i2c_adap,
                                .i2c_addr  = 0x61,
-                               .callback  = cx23885_hvr1500_xc3028_callback,
                        };
                        static struct xc2028_ctrl ctl = {
-                               .fname       = "xc3028-v27.fw",
+                               .fname       = XC2028_DEFAULT_FIRMWARE,
                                .max_len     = 64,
                                .scode_table = XC3028_FE_OREN538,
                        };
@@ -465,13 +439,13 @@ static int dvb_register(struct cx23885_tsport *port)
                        struct xc2028_config cfg = {
                                .i2c_adap  = &dev->i2c_bus[1].i2c_adap,
                                .i2c_addr  = 0x64,
-                               .callback  = cx23885_hvr1500_xc3028_callback,
                        };
                        static struct xc2028_ctrl ctl = {
-                               .fname   = "xc3028L-v36.fw",
+                               .fname   = XC3028L_DEFAULT_FIRMWARE,
                                .max_len = 64,
                                .demod   = 5000,
-                               .d2633   = 1
+                               /* This is true for all demods with v36 firmware? */
+                               .type    = XC2028_D2633,
                        };
 
                        fe = dvb_attach(xc2028_attach,
@@ -492,8 +466,57 @@ static int dvb_register(struct cx23885_tsport *port)
                                                        &i2c_bus->i2c_adap);
                if (port->dvb.frontend != NULL)
                        dvb_attach(xc5000_attach, port->dvb.frontend,
-                               &i2c_bus->i2c_adap,
-                               &dvico_xc5000_tunerconfig, i2c_bus);
+                                  &i2c_bus->i2c_adap,
+                                  &dvico_xc5000_tunerconfig);
+               break;
+       case CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP: {
+               i2c_bus = &dev->i2c_bus[port->nr - 1];
+
+               port->dvb.frontend = dvb_attach(zl10353_attach,
+                                              &dvico_fusionhdtv_xc3028,
+                                              &i2c_bus->i2c_adap);
+               if (port->dvb.frontend != NULL) {
+                       struct dvb_frontend      *fe;
+                       struct xc2028_config      cfg = {
+                               .i2c_adap  = &i2c_bus->i2c_adap,
+                               .i2c_addr  = 0x61,
+                       };
+                       static struct xc2028_ctrl ctl = {
+                               .fname       = XC2028_DEFAULT_FIRMWARE,
+                               .max_len     = 64,
+                               .demod       = XC3028_FE_ZARLINK456,
+                       };
+
+                       fe = dvb_attach(xc2028_attach, port->dvb.frontend,
+                                       &cfg);
+                       if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
+                               fe->ops.tuner_ops.set_config(fe, &ctl);
+               }
+               break;
+       }
+       case CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H:
+               i2c_bus = &dev->i2c_bus[0];
+
+               port->dvb.frontend = dvb_attach(zl10353_attach,
+                       &dvico_fusionhdtv_xc3028,
+                       &i2c_bus->i2c_adap);
+               if (port->dvb.frontend != NULL) {
+                       struct dvb_frontend      *fe;
+                       struct xc2028_config      cfg = {
+                               .i2c_adap  = &dev->i2c_bus[1].i2c_adap,
+                               .i2c_addr  = 0x61,
+                       };
+                       static struct xc2028_ctrl ctl = {
+                               .fname       = XC2028_DEFAULT_FIRMWARE,
+                               .max_len     = 64,
+                               .demod       = XC3028_FE_ZARLINK456,
+                       };
+
+                       fe = dvb_attach(xc2028_attach, port->dvb.frontend,
+                               &cfg);
+                       if (fe != NULL && fe->ops.tuner_ops.set_config != NULL)
+                               fe->ops.tuner_ops.set_config(fe, &ctl);
+               }
                break;
        default:
                printk("%s: The frontend of your DVB/ATSC card isn't supported yet\n",
@@ -504,6 +527,8 @@ static int dvb_register(struct cx23885_tsport *port)
                printk("%s: frontend initialization failed\n", dev->name);
                return -1;
        }
+       /* define general-purpose callback pointer */
+       port->dvb.frontend->callback = cx23885_tuner_callback;
 
        /* Put the analog decoder in standby to keep it quiet */
        cx23885_call_i2c_clients(i2c_bus, TUNER_SET_STANDBY, NULL);
index 35e61cd112fc8c09be763df9b14eca51ff26e2ad..5b297f0323b6485a5099a255d9bf8511414db848 100644 (file)
@@ -85,18 +85,8 @@ static int cx23885_start_vbi_dma(struct cx23885_dev    *dev,
        return 0;
 }
 
-int cx23885_stop_vbi_dma(struct cx23885_dev *dev)
-{
-       /* stop dma */
-       cx_clear(VID_A_DMA_CTL, 0x00000022);
-
-       /* disable irqs */
-       cx_clear(PCI_INT_MSK, 0x000001);
-       cx_clear(VID_A_INT_MSK, 0x00000022);
-       return 0;
-}
 
-int cx23885_restart_vbi_queue(struct cx23885_dev    *dev,
+static int cx23885_restart_vbi_queue(struct cx23885_dev    *dev,
                             struct cx23885_dmaqueue *q)
 {
        struct cx23885_buffer *buf;
index 6047c78d84bf5c2b26576e734e73e04f2724eb6c..f75ed1c9b71a28ec3f5791d80139f00c2605e2b0 100644 (file)
@@ -244,7 +244,7 @@ static struct cx23885_ctrl cx23885_ctls[] = {
 };
 static const int CX23885_CTLS = ARRAY_SIZE(cx23885_ctls);
 
-const u32 cx23885_user_ctrls[] = {
+static const u32 cx23885_user_ctrls[] = {
        V4L2_CID_USER_CLASS,
        V4L2_CID_BRIGHTNESS,
        V4L2_CID_CONTRAST,
@@ -254,14 +254,13 @@ const u32 cx23885_user_ctrls[] = {
        V4L2_CID_AUDIO_MUTE,
        0
 };
-EXPORT_SYMBOL(cx23885_user_ctrls);
 
 static const u32 *ctrl_classes[] = {
        cx23885_user_ctrls,
        NULL
 };
 
-void cx23885_video_wakeup(struct cx23885_dev *dev,
+static void cx23885_video_wakeup(struct cx23885_dev *dev,
                 struct cx23885_dmaqueue *q, u32 count)
 {
        struct cx23885_buffer *buf;
@@ -296,7 +295,7 @@ void cx23885_video_wakeup(struct cx23885_dev *dev,
                        __func__, bc);
 }
 
-int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
+static int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
 {
        dprintk(1, "%s(norm = 0x%08x) name: [%s]\n",
                __func__,
@@ -314,7 +313,7 @@ int cx23885_set_tvnorm(struct cx23885_dev *dev, v4l2_std_id norm)
        return 0;
 }
 
-struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
+static struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
                                    struct pci_dev *pci,
                                    struct video_device *template,
                                    char *type)
@@ -334,7 +333,7 @@ struct video_device *cx23885_vdev_init(struct cx23885_dev *dev,
        return vfd;
 }
 
-int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
+static int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
 {
        int i;
 
@@ -351,7 +350,6 @@ int cx23885_ctrl_query(struct v4l2_queryctrl *qctrl)
        *qctrl = cx23885_ctls[i].v;
        return 0;
 }
-EXPORT_SYMBOL(cx23885_ctrl_query);
 
 /* ------------------------------------------------------------------- */
 /* resource management                                                 */
@@ -402,7 +400,7 @@ static void res_free(struct cx23885_dev *dev, struct cx23885_fh *fh,
        mutex_unlock(&dev->lock);
 }
 
-int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
+static int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
 {
        struct v4l2_routing route;
        memset(&route, 0, sizeof(route));
@@ -422,10 +420,9 @@ int cx23885_video_mux(struct cx23885_dev *dev, unsigned int input)
 
        return 0;
 }
-EXPORT_SYMBOL(cx23885_video_mux);
 
 /* ------------------------------------------------------------------ */
-int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
+static int cx23885_set_scale(struct cx23885_dev *dev, unsigned int width,
        unsigned int height, enum v4l2_field field)
 {
        dprintk(1, "%s()\n", __func__);
@@ -731,6 +728,7 @@ static int video_open(struct inode *inode, struct file *file)
        enum v4l2_buf_type type = 0;
        int radio = 0;
 
+       lock_kernel();
        list_for_each(list, &cx23885_devlist) {
                h = list_entry(list, struct cx23885_dev, devlist);
                if (h->video_dev->minor == minor) {
@@ -748,16 +746,20 @@ static int video_open(struct inode *inode, struct file *file)
                        dev   = h;
                }
        }
-       if (NULL == dev)
+       if (NULL == dev) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        dprintk(1, "open minor=%d radio=%d type=%s\n",
                minor, radio, v4l2_type_names[type]);
 
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh), GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
        file->private_data = fh;
        fh->dev      = dev;
        fh->radio    = radio;
@@ -775,6 +777,7 @@ static int video_open(struct inode *inode, struct file *file)
 
        dprintk(1, "post videobuf_queue_init()\n");
 
+       unlock_kernel();
 
        return 0;
 }
@@ -884,21 +887,19 @@ static int video_mmap(struct file *file, struct vm_area_struct *vma)
 /* ------------------------------------------------------------------ */
 /* VIDEO CTRL IOCTLS                                                  */
 
-int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
+static int cx23885_get_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
 {
        dprintk(1, "%s() calling cx25840(VIDIOC_G_CTRL)\n", __func__);
        cx23885_call_i2c_clients(&dev->i2c_bus[2], VIDIOC_G_CTRL, ctl);
        return 0;
 }
-EXPORT_SYMBOL(cx23885_get_control);
 
-int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
+static int cx23885_set_control(struct cx23885_dev *dev, struct v4l2_control *ctl)
 {
        dprintk(1, "%s() calling cx25840(VIDIOC_S_CTRL)"
                " (disabled - no action)\n", __func__);
        return 0;
 }
-EXPORT_SYMBOL(cx23885_set_control);
 
 static void init_controls(struct cx23885_dev *dev)
 {
@@ -1146,7 +1147,7 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
        return 0;
 }
 
-int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
+static int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
 {
        static const char *iname[] = {
                [CX23885_VMUX_COMPOSITE1] = "Composite1",
@@ -1179,7 +1180,6 @@ int cx23885_enum_input(struct cx23885_dev *dev, struct v4l2_input *i)
                i->std = CX23885_NORMS;
        return 0;
 }
-EXPORT_SYMBOL(cx23885_enum_input);
 
 static int vidioc_enum_input(struct file *file, void *priv,
                                struct v4l2_input *i)
@@ -1288,7 +1288,7 @@ static int vidioc_g_frequency(struct file *file, void *priv,
        return 0;
 }
 
-int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
+static int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
 {
        if (unlikely(UNSET == dev->tuner_type))
                return -EINVAL;
@@ -1307,7 +1307,6 @@ int cx23885_set_freq(struct cx23885_dev *dev, struct v4l2_frequency *f)
 
        return 0;
 }
-EXPORT_SYMBOL(cx23885_set_freq);
 
 static int vidioc_s_frequency(struct file *file, void *priv,
                                struct v4l2_frequency *f)
index e23d97c071e05d49c2ad15dafc10cc33e15d636a..ba4e0aaed4633985dabe58919afef9dddfb9b228 100644 (file)
@@ -64,6 +64,8 @@
 #define CX23885_BOARD_HAUPPAUGE_HVR1700        8
 #define CX23885_BOARD_HAUPPAUGE_HVR1400        9
 #define CX23885_BOARD_DVICO_FUSIONHDTV_7_DUAL_EXP 10
+#define CX23885_BOARD_DVICO_FUSIONHDTV_DVB_T_DUAL_EXP 11
+#define CX23885_BOARD_LEADTEK_WINFAST_PXDVR3200_H 12
 
 /* Currently unsupported by the driver: PAL/H, NTSC/Kr, SECAM B/G/H/LC */
 #define CX23885_NORMS (\
@@ -409,7 +411,7 @@ extern const unsigned int cx23885_bcount;
 extern struct cx23885_subid cx23885_subids[];
 extern const unsigned int cx23885_idcount;
 
-extern int cx23885_tuner_callback(void *priv, int command, int arg);
+extern int cx23885_tuner_callback(void *priv, int component, int command, int arg);
 extern void cx23885_card_list(struct cx23885_dev *dev);
 extern int  cx23885_ir_init(struct cx23885_dev *dev);
 extern void cx23885_gpio_setup(struct cx23885_dev *dev);
index 69f2bbdbb929b1a9c41dad93cdfa97caca0d9122..58e6ef1c28a093d849b88f7111f5120a27b9b6aa 100644 (file)
@@ -141,10 +141,11 @@ int cx25840_vbi(struct i2c_client *client, unsigned int cmd, void *arg)
                u8 lcr[24];
 
                fmt = arg;
-               if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE)
+               if (fmt->type != V4L2_BUF_TYPE_SLICED_VBI_CAPTURE &&
+                   fmt->type != V4L2_BUF_TYPE_VBI_CAPTURE)
                        return -EINVAL;
                svbi = &fmt->fmt.sliced;
-               if (svbi->service_set == 0) {
+               if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
                        /* raw VBI */
                        memset(svbi, 0, sizeof(*svbi));
 
index 9dd7bdf659b96a066d05dee8d6f87d0dcc4e85ed..0b9e5fac6239f5783e0f42e24f8eb9d1c700dfed 100644 (file)
@@ -58,6 +58,10 @@ config VIDEO_CX88_DVB
        select DVB_ISL6421 if !DVB_FE_CUSTOMISE
        select MEDIA_TUNER_SIMPLE if !DVB_FE_CUSTOMISE
        select DVB_S5H1411 if !DVB_FE_CUSTOMISE
+       select DVB_CX24116 if !DVB_FE_CUSTOMISE
+       select DVB_STV0299 if !DVB_FE_CUSTOMISE
+       select DVB_STV0288 if !DVB_FE_CUSTOMISE
+       select DVB_STB6000 if !DVB_FE_CUSTOMISE
        ---help---
          This adds support for DVB/ATSC cards based on the
          Conexant 2388x chip.
index 9a1374a38ec75a315463c02e83f5c6ad113b6fb4..e71369754305cdfe21cab45990120115079aafa7 100644 (file)
@@ -1057,12 +1057,15 @@ static int mpeg_open(struct inode *inode, struct file *file)
        struct cx8802_driver *drv = NULL;
        int err;
 
+       lock_kernel();
        dev = cx8802_get_device(inode);
 
        dprintk( 1, "%s\n", __func__);
 
-       if (dev == NULL)
+       if (dev == NULL) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        /* Make sure we can acquire the hardware */
        drv = cx8802_get_driver(dev, CX88_MPEG_BLACKBIRD);
@@ -1070,6 +1073,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
                err = drv->request_acquire(drv);
                if(err != 0) {
                        dprintk(1,"%s: Unable to acquire hardware, %d\n", __func__, err);
+                       unlock_kernel();
                        return err;
                }
        }
@@ -1077,6 +1081,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
        if (blackbird_initialize_codec(dev) < 0) {
                if (drv)
                        drv->request_release(drv);
+               unlock_kernel();
                return -EINVAL;
        }
        dprintk(1,"open minor=%d\n",minor);
@@ -1086,6 +1091,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
        if (NULL == fh) {
                if (drv)
                        drv->request_release(drv);
+               unlock_kernel();
                return -ENOMEM;
        }
        file->private_data = fh;
@@ -1101,6 +1107,7 @@ static int mpeg_open(struct inode *inode, struct file *file)
        /* FIXME: locking against other video device */
        cx88_set_scale(dev->core, dev->width, dev->height,
                        fh->mpegq.field);
+       unlock_kernel();
 
        return 0;
 }
index de199a206a152bdc7e9a9fa381f2c623fd76a775..5da04e811ca20b3941b086e73566c91d081d27e6 100644 (file)
@@ -1349,27 +1349,30 @@ static const struct cx88_board cx88_boards[] = {
                .radio_addr     = ADDR_UNSET,
                .tda9887_conf   = TDA9887_PRESENT,
                .audio_chip     = V4L2_IDENT_WM8775,
+               /*
+                * gpio0 as reported by Mike Crash <mike AT mikecrash.com>
+                */
                .input          = {{
                        .type   = CX88_VMUX_TELEVISION,
                        .vmux   = 0,
-                       .gpio0  = 0xe780,
+                       .gpio0  = 0xef88,
                        .audioroute = 1,
                },{
                        .type   = CX88_VMUX_COMPOSITE1,
                        .vmux   = 1,
-                       .gpio0  = 0xe780,
+                       .gpio0  = 0xef88,
                        .audioroute = 2,
                },{
                        .type   = CX88_VMUX_SVIDEO,
                        .vmux   = 2,
-                       .gpio0  = 0xe780,
+                       .gpio0  = 0xef88,
                        .audioroute = 2,
                }},
                /* fixme: Add radio support */
                .mpeg           = CX88_MPEG_DVB | CX88_MPEG_BLACKBIRD,
                .radio = {
                        .type   = CX88_RADIO,
-                       .gpio0  = 0xe780,
+                       .gpio0  = 0xef88,
                },
        },
        [CX88_BOARD_ADSTECH_PTV_390] = {
@@ -1446,15 +1449,26 @@ static const struct cx88_board cx88_boards[] = {
                .name           = "Pinnacle Hybrid PCTV",
                .tuner_type     = TUNER_XC2028,
                .tuner_addr     = 0x61,
+               .radio_type     = TUNER_XC2028,
+               .radio_addr     = 0x61,
                .input          = { {
                        .type   = CX88_VMUX_TELEVISION,
                        .vmux   = 0,
+                       .gpio0  = 0x004ff,
+                       .gpio1  = 0x010ff,
+                       .gpio2  = 0x00001,
                }, {
                        .type   = CX88_VMUX_COMPOSITE1,
                        .vmux   = 1,
+                       .gpio0  = 0x004fb,
+                       .gpio1  = 0x010ef,
+                       .audioroute = 1,
                }, {
                        .type   = CX88_VMUX_SVIDEO,
                        .vmux   = 2,
+                       .gpio0  = 0x004fb,
+                       .gpio1  = 0x010ef,
+                       .audioroute = 1,
                } },
                .radio = {
                        .type   = CX88_RADIO,
@@ -1462,6 +1476,7 @@ static const struct cx88_board cx88_boards[] = {
                        .gpio1  = 0x010ff,
                        .gpio2  = 0x0ff,
                },
+               .mpeg           = CX88_MPEG_DVB,
        },
        [CX88_BOARD_WINFAST_TV2000_XP_GLOBAL] = {
                .name           = "Winfast TV2000 XP Global",
@@ -1566,9 +1581,9 @@ static const struct cx88_board cx88_boards[] = {
        },
        [CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO] = {
                .name           = "DViCO FusionHDTV DVB-T PRO",
-               .tuner_type     = TUNER_ABSENT, /* XXX: Has XC3028 */
+               .tuner_type     = TUNER_XC2028,
+               .tuner_addr     = 0x61,
                .radio_type     = UNSET,
-               .tuner_addr     = ADDR_UNSET,
                .radio_addr     = ADDR_UNSET,
                .input          = { {
                        .type   = CX88_VMUX_COMPOSITE1,
@@ -1625,6 +1640,36 @@ static const struct cx88_board cx88_boards[] = {
                        .gpio2 = 0x0cfb,
                },
        },
+       [CX88_BOARD_PROLINK_PV_GLOBAL_XTREME] = {
+               .name           = "Prolink Pixelview Global Extreme",
+               .tuner_type     = TUNER_XC2028,
+               .tuner_addr     = 0x61,
+               .input          = { {
+                       .type   = CX88_VMUX_TELEVISION,
+                       .vmux   = 0,
+                       .gpio0 = 0x04fb,
+                       .gpio1 = 0x04080,
+                       .gpio2 = 0x0cf7,
+               }, {
+                       .type   = CX88_VMUX_COMPOSITE1,
+                       .vmux   = 1,
+                       .gpio0 = 0x04fb,
+                       .gpio1 = 0x04080,
+                       .gpio2 = 0x0cfb,
+               }, {
+                       .type   = CX88_VMUX_SVIDEO,
+                       .vmux   = 2,
+                       .gpio0 = 0x04fb,
+                       .gpio1 = 0x04080,
+                       .gpio2 = 0x0cfb,
+               } },
+               .radio = {
+                       .type   = CX88_RADIO,
+                       .gpio0 = 0x04ff,
+                       .gpio1 = 0x04080,
+                       .gpio2 = 0x0cf7,
+               },
+       },
        /* Both radio, analog and ATSC work with this board.
           However, for analog to work, s5h1409 gate should be open,
           otherwise, tuner-xc3028 won't be detected.
@@ -1664,6 +1709,131 @@ static const struct cx88_board cx88_boards[] = {
                },
                .mpeg           = CX88_MPEG_DVB,
        },
+       [CX88_BOARD_HAUPPAUGE_HVR4000] = {
+               .name           = "Hauppauge WinTV-HVR4000 DVB-S/S2/T/Hybrid",
+               .tuner_type     = TUNER_PHILIPS_FMD1216ME_MK3,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .tda9887_conf   = TDA9887_PRESENT,
+               /*
+                * GPIO0 (WINTV2000)
+                *
+                * Analogue     SAT     DVB-T
+                * Antenna      0xc4bf  0xc4bb
+                * Composite    0xc4bf  0xc4bb
+                * S-Video      0xc4bf  0xc4bb
+                * Composite1   0xc4ff  0xc4fb
+                * S-Video1     0xc4ff  0xc4fb
+                *
+                * BIT  VALUE   FUNCTION GP{x}_IO
+                * 0    1       I:?
+                * 1    1       I:?
+                * 2    1       O:DVB-T DEMOD ENABLE LOW/ANALOG DEMOD ENABLE HIGH
+                * 3    1       I:?
+                * 4    1       I:?
+                * 5    1       I:?
+                * 6    0       O:INPUT SELECTOR 0=INTERNAL 1=EXPANSION
+                * 7    1       O:DVB-T DEMOD RESET LOW
+                *
+                * BIT  VALUE   FUNCTION GP{x}_OE
+                * 8    0       I
+                * 9    0       I
+                * a    1       O
+                * b    0       I
+                * c    0       I
+                * d    0       I
+                * e    1       O
+                * f    1       O
+                */
+               .input          = {{
+                       .type   = CX88_VMUX_TELEVISION,
+                       .vmux   = 0,
+                       .gpio0  = 0xc4bf,
+               }, {
+                       .type   = CX88_VMUX_COMPOSITE1,
+                       .vmux   = 1,
+                       .gpio0  = 0xc4bf,
+               }, {
+                       .type   = CX88_VMUX_SVIDEO,
+                       .vmux   = 2,
+                       .gpio0  = 0xc4bf,
+               } },
+               /* fixme: Add radio support */
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_HAUPPAUGE_HVR4000LITE] = {
+               .name           = "Hauppauge WinTV-HVR4000(Lite) DVB-S/S2",
+               .tuner_type     = UNSET,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 0,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_TEVII_S420] = {
+               .name           = "TeVii S420 DVB-S",
+               .tuner_type     = UNSET,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 0,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_TEVII_S460] = {
+               .name           = "TeVii S460 DVB-S/S2",
+               .tuner_type     = UNSET,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 0,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_OMICOM_SS4_PCI] = {
+               .name           = "Omicom SS4 DVB-S/S2 PCI",
+               .tuner_type     = UNSET,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 0,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_TBS_8920] = {
+               .name           = "TBS 8920 DVB-S/S2",
+               .tuner_type     = TUNER_ABSENT,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 1,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
+       [CX88_BOARD_PROF_7300] = {
+               .name           = "PROF 7300 DVB-S/S2",
+               .tuner_type     = UNSET,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .input          = {{
+                       .type   = CX88_VMUX_DVB,
+                       .vmux   = 0,
+               } },
+               .mpeg           = CX88_MPEG_DVB,
+       },
 };
 
 /* ------------------------------------------------------------------ */
@@ -2009,10 +2179,54 @@ static const struct cx88_subid cx88_subids[] = {
                .subvendor = 0x1554,
                .subdevice = 0x4935,
                .card      = CX88_BOARD_PROLINK_PV_8000GT,
+       }, {
+               .subvendor = 0x1554,
+               .subdevice = 0x4976,
+               .card      = CX88_BOARD_PROLINK_PV_GLOBAL_XTREME,
        }, {
                .subvendor = 0x17de,
                .subdevice = 0x08c1,
                .card      = CX88_BOARD_KWORLD_ATSC_120,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x6900,
+               .card      = CX88_BOARD_HAUPPAUGE_HVR4000,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x6904,
+               .card      = CX88_BOARD_HAUPPAUGE_HVR4000,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x6902,
+               .card      = CX88_BOARD_HAUPPAUGE_HVR4000,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x6905,
+               .card      = CX88_BOARD_HAUPPAUGE_HVR4000LITE,
+       }, {
+               .subvendor = 0x0070,
+               .subdevice = 0x6906,
+               .card      = CX88_BOARD_HAUPPAUGE_HVR4000LITE,
+       }, {
+               .subvendor = 0xd420,
+               .subdevice = 0x9022,
+               .card      = CX88_BOARD_TEVII_S420,
+       }, {
+               .subvendor = 0xd460,
+               .subdevice = 0x9022,
+               .card      = CX88_BOARD_TEVII_S460,
+       }, {
+               .subvendor = 0xA044,
+               .subdevice = 0x2011,
+               .card      = CX88_BOARD_OMICOM_SS4_PCI,
+       }, {
+               .subvendor = 0x8920,
+               .subdevice = 0x8888,
+               .card      = CX88_BOARD_TBS_8920,
+       }, {
+               .subvendor = 0xB033,
+               .subdevice = 0x3033,
+               .card      = CX88_BOARD_PROF_7300,
        },
 };
 
@@ -2065,6 +2279,13 @@ static void hauppauge_eeprom(struct cx88_core *core, u8 *eeprom_data)
        case 14669: /* WinTV-HVR3000 (OEM, no IR, no b/panel video - Low profile) */
        case 28552: /* WinTV-PVR 'Roslyn' (No IR) */
        case 34519: /* WinTV-PCI-FM */
+       case 69009:
+               /* WinTV-HVR4000 (DVBS/S2/T, Video and IR, back panel inputs) */
+       case 69100: /* WinTV-HVR4000LITE (DVBS/S2, IR) */
+       case 69500: /* WinTV-HVR4000LITE (DVBS/S2, No IR) */
+       case 69559:
+               /* WinTV-HVR4000 (DVBS/S2/T, Video no IR, back panel inputs) */
+       case 69569: /* WinTV-HVR4000 (DVBS/S2/T, Video no IR) */
        case 90002: /* Nova-T-PCI (9002) */
        case 92001: /* Nova-S-Plus (Video and IR) */
        case 92002: /* Nova-S-Plus (Video and IR) */
@@ -2149,9 +2370,21 @@ static int cx88_dvico_xc2028_callback(struct cx88_core *core,
 {
        switch (command) {
        case XC2028_TUNER_RESET:
-               cx_write(MO_GP0_IO, 0x101000);
-               mdelay(5);
-               cx_set(MO_GP0_IO, 0x101010);
+               switch (core->boardnr) {
+               case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
+                       /* GPIO-4 xc3028 tuner */
+
+                       cx_set(MO_GP0_IO, 0x00001000);
+                       cx_clear(MO_GP0_IO, 0x00000010);
+                       msleep(100);
+                       cx_set(MO_GP0_IO, 0x00000010);
+                       msleep(100);
+                       break;
+               default:
+                       cx_write(MO_GP0_IO, 0x101000);
+                       mdelay(5);
+                       cx_set(MO_GP0_IO, 0x101010);
+               }
                break;
        default:
                return -EINVAL;
@@ -2258,8 +2491,10 @@ static int cx88_xc2028_tuner_callback(struct cx88_core *core,
                return cx88_xc3028_geniatech_tuner_callback(core,
                                                        command, arg);
        case CX88_BOARD_PROLINK_PV_8000GT:
+       case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
                return cx88_pv_8000gt_callback(core, command, arg);
        case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
+       case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
                return cx88_dvico_xc2028_callback(core, command, arg);
        }
 
@@ -2327,7 +2562,7 @@ static int cx88_xc5000_tuner_callback(struct cx88_core *core,
        return 0; /* Should never be here */
 }
 
-int cx88_tuner_callback(void *priv, int command, int arg)
+int cx88_tuner_callback(void *priv, int component, int command, int arg)
 {
        struct i2c_algo_bit_data *i2c_algo = priv;
        struct cx88_core *core;
@@ -2344,6 +2579,9 @@ int cx88_tuner_callback(void *priv, int command, int arg)
                return -EINVAL;
        }
 
+       if (component != DVB_FRONTEND_COMPONENT_TUNER)
+               return -EINVAL;
+
        switch (core->board.tuner_type) {
                case TUNER_XC2028:
                        info_printk(core, "Calling XC2028/3028 callback\n");
@@ -2392,16 +2630,22 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
 {
        switch (core->boardnr) {
        case CX88_BOARD_HAUPPAUGE_HVR1300:
-               /* Bring the 702 demod up before i2c scanning/attach or devices are hidden */
-               /* We leave here with the 702 on the bus */
-               cx_write(MO_GP0_IO, 0x0000e780);
+               /*
+                * Bring the 702 demod up before i2c scanning/attach or devices are hidden
+                * We leave here with the 702 on the bus
+                *
+                * "reset the IR receiver on GPIO[3]"
+                * Reported by Mike Crash <mike AT mikecrash.com>
+                */
+               cx_write(MO_GP0_IO, 0x0000ef88);
                udelay(1000);
-               cx_clear(MO_GP0_IO, 0x00000080);
+               cx_clear(MO_GP0_IO, 0x00000088);
                udelay(50);
-               cx_set(MO_GP0_IO, 0x00000080); /* 702 out of reset */
+               cx_set(MO_GP0_IO, 0x00000088); /* 702 out of reset */
                udelay(1000);
                break;
 
+       case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
        case CX88_BOARD_PROLINK_PV_8000GT:
                cx_write(MO_GP2_IO, 0xcf7);
                mdelay(50);
@@ -2411,10 +2655,18 @@ static void cx88_card_setup_pre_i2c(struct cx88_core *core)
                msleep(10);
                break;
 
-        case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
+       case CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD:
                /* Enable the xc5000 tuner */
                cx_set(MO_GP0_IO, 0x00001010);
                break;
+
+       case CX88_BOARD_HAUPPAUGE_HVR3000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
+               /* Init GPIO */
+               cx_write(MO_GP0_IO, core->board.input[0].gpio0);
+               udelay(1000);
+               break;
        }
 }
 
@@ -2435,17 +2687,22 @@ void cx88_setup_xc3028(struct cx88_core *core, struct xc2028_ctrl *ctl)
                        core->i2c_algo.udelay = 16;
                break;
        case CX88_BOARD_DVICO_FUSIONHDTV_DVB_T_PRO:
-               ctl->scode_table = XC3028_FE_ZARLINK456;
+               ctl->demod = XC3028_FE_ZARLINK456;
                break;
        case CX88_BOARD_KWORLD_ATSC_120:
        case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
                ctl->demod = XC3028_FE_OREN538;
                break;
+       case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
        case CX88_BOARD_PROLINK_PV_8000GT:
                /*
-                * This board uses non-MTS firmware
+                * Those boards uses non-MTS firmware
                 */
                break;
+       case CX88_BOARD_PINNACLE_HYBRID_PCTV:
+               ctl->demod = XC3028_FE_ZARLINK456;
+               ctl->mts = 1;
+               break;
        default:
                ctl->demod = XC3028_FE_OREN538;
                ctl->mts = 1;
@@ -2489,6 +2746,8 @@ static void cx88_card_setup(struct cx88_core *core)
        case CX88_BOARD_HAUPPAUGE_HVR1100LP:
        case CX88_BOARD_HAUPPAUGE_HVR3000:
        case CX88_BOARD_HAUPPAUGE_HVR1300:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
                if (0 == core->i2c_rc)
                        hauppauge_eeprom(core, eeprom);
                break;
@@ -2570,7 +2829,18 @@ static void cx88_card_setup(struct cx88_core *core)
                tea5767_cfg.priv  = &ctl;
 
                cx88_call_i2c_clients(core, TUNER_SET_CONFIG, &tea5767_cfg);
+               break;
        }
+       case  CX88_BOARD_TEVII_S420:
+       case  CX88_BOARD_TEVII_S460:
+       case  CX88_BOARD_OMICOM_SS4_PCI:
+       case  CX88_BOARD_TBS_8920:
+       case  CX88_BOARD_PROF_7300:
+               cx_write(MO_SRST_IO, 0);
+               msleep(100);
+               cx_write(MO_SRST_IO, 1);
+               msleep(100);
+               break;
        } /*end switch() */
 
 
index d96173ff1dbac4a0096f854cdb0cc8008d4b8f7e..344ed2626e597e3a47c0e0307ee1f5001bae92da 100644 (file)
 #include "tuner-simple.h"
 #include "tda9887.h"
 #include "s5h1411.h"
+#include "stv0299.h"
+#include "z0194a.h"
+#include "stv0288.h"
+#include "stb6000.h"
+#include "cx24116.h"
 
 MODULE_DESCRIPTION("driver for cx2388x based DVB cards");
 MODULE_AUTHOR("Chris Pascoe <c.pascoe@itee.uq.edu.au>");
@@ -375,37 +380,28 @@ static int geniatech_dvbs_set_voltage(struct dvb_frontend *fe,
        return 0;
 }
 
-static int cx88_pci_nano_callback(void *ptr, int command, int arg)
+static int tevii_dvbs_set_voltage(struct dvb_frontend *fe,
+                                     fe_sec_voltage_t voltage)
 {
-       struct cx88_core *core = ptr;
-
-       switch (command) {
-       case XC2028_TUNER_RESET:
-               /* Send the tuner in then out of reset */
-               dprintk(1, "%s: XC2028_TUNER_RESET %d\n", __func__, arg);
-
-               switch (core->boardnr) {
-               case CX88_BOARD_DVICO_FUSIONHDTV_5_PCI_NANO:
-                       /* GPIO-4 xc3028 tuner */
-
-                       cx_set(MO_GP0_IO, 0x00001000);
-                       cx_clear(MO_GP0_IO, 0x00000010);
-                       msleep(100);
-                       cx_set(MO_GP0_IO, 0x00000010);
-                       msleep(100);
-                       break;
-               }
+       struct cx8802_dev *dev= fe->dvb->priv;
+       struct cx88_core *core = dev->core;
 
-               break;
-       case XC2028_RESET_CLK:
-               dprintk(1, "%s: XC2028_RESET_CLK %d\n", __func__, arg);
-               break;
-       default:
-               dprintk(1, "%s: unknown command %d, arg %d\n", __func__,
-                       command, arg);
-               return -EINVAL;
+       switch (voltage) {
+               case SEC_VOLTAGE_13:
+                       printk("LNB Voltage SEC_VOLTAGE_13\n");
+                       cx_write(MO_GP0_IO, 0x00006040);
+                       break;
+               case SEC_VOLTAGE_18:
+                       printk("LNB Voltage SEC_VOLTAGE_18\n");
+                       cx_write(MO_GP0_IO, 0x00006060);
+                       break;
+               case SEC_VOLTAGE_OFF:
+                       printk("LNB Voltage SEC_VOLTAGE_off\n");
+                       break;
        }
 
+       if (core->prev_set_voltage)
+               return core->prev_set_voltage(fe, voltage);
        return 0;
 }
 
@@ -456,7 +452,12 @@ static struct s5h1409_config kworld_atsc_120_config = {
 static struct xc5000_config pinnacle_pctv_hd_800i_tuner_config = {
        .i2c_address    = 0x64,
        .if_khz         = 5380,
-       .tuner_callback = cx88_tuner_callback,
+};
+
+static struct zl10353_config cx88_pinnacle_hybrid_pctv = {
+       .demod_address = (0x1e >> 1),
+       .no_tuner      = 1,
+       .if2           = 45600,
 };
 
 static struct zl10353_config cx88_geniatech_x8000_mt = {
@@ -477,7 +478,6 @@ static struct s5h1411_config dvico_fusionhdtv7_config = {
 static struct xc5000_config dvico_fusionhdtv7_tuner_config = {
        .i2c_address    = 0xc2 >> 1,
        .if_khz         = 5380,
-       .tuner_callback = cx88_tuner_callback,
 };
 
 static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
@@ -488,7 +488,6 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
                .i2c_adap  = &dev->core->i2c_adap,
                .i2c_addr  = addr,
                .ctrl      = &ctl,
-               .callback  = cx88_tuner_callback,
        };
 
        if (!dev->dvb.frontend) {
@@ -518,6 +517,60 @@ static int attach_xc3028(u8 addr, struct cx8802_dev *dev)
        return 0;
 }
 
+static int cx24116_set_ts_param(struct dvb_frontend *fe,
+       int is_punctured)
+{
+       struct cx8802_dev *dev = fe->dvb->priv;
+       dev->ts_gen_cntrl = 0x2;
+
+       return 0;
+}
+
+static int cx24116_reset_device(struct dvb_frontend *fe)
+{
+       struct cx8802_dev *dev = fe->dvb->priv;
+       struct cx88_core *core = dev->core;
+
+       /* Reset the part */
+       cx_write(MO_SRST_IO, 0);
+       msleep(10);
+       cx_write(MO_SRST_IO, 1);
+       msleep(10);
+
+       return 0;
+}
+
+static struct cx24116_config hauppauge_hvr4000_config = {
+       .demod_address          = 0x05,
+       .set_ts_params          = cx24116_set_ts_param,
+       .reset_device           = cx24116_reset_device,
+};
+
+static struct cx24116_config tevii_s460_config = {
+       .demod_address = 0x55,
+       .set_ts_params = cx24116_set_ts_param,
+       .reset_device  = cx24116_reset_device,
+};
+
+static struct stv0299_config tevii_tuner_sharp_config = {
+       .demod_address = 0x68,
+       .inittab = sharp_z0194a__inittab,
+       .mclk = 88000000UL,
+       .invert = 1,
+       .skip_reinit = 0,
+       .lock_output = 1,
+       .volt13_op0_op1 = STV0299_VOLT13_OP1,
+       .min_delay_ms = 100,
+       .set_symbol_rate = sharp_z0194a__set_symbol_rate,
+       .set_ts_params = cx24116_set_ts_param,
+};
+
+static struct stv0288_config tevii_tuner_earda_config = {
+       .demod_address = 0x68,
+       .min_delay_ms = 100,
+       .set_ts_params = cx24116_set_ts_param,
+};
+
 static int dvb_register(struct cx8802_dev *dev)
 {
        struct cx88_core *core = dev->core;
@@ -786,7 +839,7 @@ static int dvb_register(struct cx8802_dev *dev)
                                               &core->i2c_adap);
                if (dev->dvb.frontend) {
                        if (!dvb_attach(isl6421_attach, dev->dvb.frontend,
-                                       &core->i2c_adap, 0x08, 0x00, 0x00))
+                                       &core->i2c_adap, 0x08, ISL6421_DCL, 0x00))
                                goto frontend_detach;
                }
                break;
@@ -813,13 +866,9 @@ static int dvb_register(struct cx8802_dev *dev)
                                               &pinnacle_pctv_hd_800i_config,
                                               &core->i2c_adap);
                if (dev->dvb.frontend != NULL) {
-                       /* tuner_config.video_dev must point to
-                        * i2c_adap.algo_data
-                        */
                        if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
                                        &core->i2c_adap,
-                                       &pinnacle_pctv_hd_800i_tuner_config,
-                                       core->i2c_adap.algo_data))
+                                       &pinnacle_pctv_hd_800i_tuner_config))
                                goto frontend_detach;
                }
                break;
@@ -832,10 +881,9 @@ static int dvb_register(struct cx8802_dev *dev)
                        struct xc2028_config cfg = {
                                .i2c_adap  = &core->i2c_adap,
                                .i2c_addr  = 0x61,
-                               .callback  = cx88_pci_nano_callback,
                        };
                        static struct xc2028_ctrl ctl = {
-                               .fname       = "xc3028-v27.fw",
+                               .fname       = XC2028_DEFAULT_FIRMWARE,
                                .max_len     = 64,
                                .scode_table = XC3028_FE_OREN538,
                        };
@@ -848,10 +896,13 @@ static int dvb_register(struct cx8802_dev *dev)
                break;
         case CX88_BOARD_PINNACLE_HYBRID_PCTV:
                dev->dvb.frontend = dvb_attach(zl10353_attach,
-                                              &cx88_geniatech_x8000_mt,
+                                              &cx88_pinnacle_hybrid_pctv,
                                               &core->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0)
-                       goto frontend_detach;
+               if (dev->dvb.frontend) {
+                       dev->dvb.frontend->ops.i2c_gate_ctrl = NULL;
+                       if (attach_xc3028(0x61, dev) < 0)
+                               goto frontend_detach;
+               }
                break;
         case CX88_BOARD_GENIATECH_X8000_MT:
                dev->ts_gen_cntrl = 0x00;
@@ -874,16 +925,69 @@ static int dvb_register(struct cx8802_dev *dev)
                                               &dvico_fusionhdtv7_config,
                                               &core->i2c_adap);
                if (dev->dvb.frontend != NULL) {
-                       /* tuner_config.video_dev must point to
-                        * i2c_adap.algo_data
-                        */
                        if (!dvb_attach(xc5000_attach, dev->dvb.frontend,
                                        &core->i2c_adap,
-                                       &dvico_fusionhdtv7_tuner_config,
-                                       core->i2c_adap.algo_data))
+                                       &dvico_fusionhdtv7_tuner_config))
                                goto frontend_detach;
                }
                break;
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
+               /* Support for DVB-S only, not DVB-T support */
+               dev->dvb.frontend = dvb_attach(cx24116_attach,
+                       &hauppauge_hvr4000_config,
+                       &dev->core->i2c_adap);
+               if (dev->dvb.frontend) {
+                       dvb_attach(isl6421_attach, dev->dvb.frontend,
+                               &dev->core->i2c_adap,
+                               0x08, ISL6421_DCL, 0x00);
+               }
+               break;
+       case CX88_BOARD_TEVII_S420:
+               dev->dvb.frontend = dvb_attach(stv0299_attach,
+                                               &tevii_tuner_sharp_config,
+                                               &core->i2c_adap);
+               if (dev->dvb.frontend != NULL) {
+                       if (!dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x60,
+                                       &core->i2c_adap, DVB_PLL_OPERA1))
+                               goto frontend_detach;
+                       core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
+                       dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
+
+               } else {
+                       dev->dvb.frontend = dvb_attach(stv0288_attach,
+                                                           &tevii_tuner_earda_config,
+                                                           &core->i2c_adap);
+                               if (dev->dvb.frontend != NULL) {
+                                       if (!dvb_attach(stb6000_attach, dev->dvb.frontend, 0x61,
+                                               &core->i2c_adap))
+                                       goto frontend_detach;
+                               core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
+                               dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
+
+                       }
+               }
+               break;
+       case CX88_BOARD_TEVII_S460:
+               dev->dvb.frontend = dvb_attach(cx24116_attach,
+                                              &tevii_s460_config,
+                                              &core->i2c_adap);
+               if (dev->dvb.frontend != NULL) {
+                       core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
+                       dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
+               }
+               break;
+       case CX88_BOARD_OMICOM_SS4_PCI:
+       case CX88_BOARD_TBS_8920:
+       case CX88_BOARD_PROF_7300:
+               dev->dvb.frontend = dvb_attach(cx24116_attach,
+                                              &hauppauge_hvr4000_config,
+                                              &core->i2c_adap);
+               if (dev->dvb.frontend != NULL) {
+                       core->prev_set_voltage = dev->dvb.frontend->ops.set_voltage;
+                       dev->dvb.frontend->ops.set_voltage = tevii_dvbs_set_voltage;
+               }
+               break;
        default:
                printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card isn't supported yet\n",
                       core->name);
@@ -895,6 +999,8 @@ static int dvb_register(struct cx8802_dev *dev)
                       core->name);
                return -EINVAL;
        }
+       /* define general-purpose callback pointer */
+       dev->dvb.frontend->callback = cx88_tuner_callback;
 
        /* Ensure all frontends negotiate bus access */
        dev->dvb.frontend->ops.ts_bus_ctrl = cx88_dvb_bus_ctrl;
index d7406a994f094942924b3726e3b41ba31ac1f19b..8e74d64fdcd2e5324e38af6db7002341154e3d8d 100644 (file)
@@ -201,7 +201,23 @@ int cx88_i2c_init(struct cx88_core *core, struct pci_dev *pci)
 
        core->i2c_rc = i2c_bit_add_bus(&core->i2c_adap);
        if (0 == core->i2c_rc) {
+               static u8 tuner_data[] =
+                       { 0x0b, 0xdc, 0x86, 0x52 };
+               static struct i2c_msg tuner_msg =
+                       { .flags = 0, .addr = 0xc2 >> 1, .buf = tuner_data, .len = 4 };
+
                dprintk(1, "i2c register ok\n");
+               switch( core->boardnr ) {
+                       case CX88_BOARD_HAUPPAUGE_HVR1300:
+                       case CX88_BOARD_HAUPPAUGE_HVR3000:
+                       case CX88_BOARD_HAUPPAUGE_HVR4000:
+                               printk("%s: i2c init: enabling analog demod on HVR1300/3000/4000 tuner\n",
+                                       core->name);
+                               i2c_transfer(core->i2c_client.adapter, &tuner_msg, 1);
+                               break;
+                       default:
+                               break;
+               }
                if (i2c_scan)
                        do_i2c_scan(core->name,&core->i2c_client);
        } else
index 53526d997a4e97923231ead7736fa2f9c9c089cf..8683d104de72a4113587bff03440d38749ce048b 100644 (file)
@@ -224,6 +224,8 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
        case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
        case CX88_BOARD_HAUPPAUGE_HVR1100:
        case CX88_BOARD_HAUPPAUGE_HVR3000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
                ir_codes = ir_codes_hauppauge_new;
                ir_type = IR_TYPE_RC5;
                ir->sampling = 1;
@@ -259,6 +261,7 @@ int cx88_ir_init(struct cx88_core *core, struct pci_dev *pci)
                ir->polling = 1; /* ms */
                break;
        case CX88_BOARD_PROLINK_PV_8000GT:
+       case CX88_BOARD_PROLINK_PV_GLOBAL_XTREME:
                ir_codes = ir_codes_pixelview_new;
                ir->gpio_addr = MO_GP1_IO;
                ir->mask_keycode = 0x3f;
@@ -392,7 +395,7 @@ void cx88_ir_irq(struct cx88_core *core)
 {
        struct cx88_IR *ir = core->ir;
        u32 samples, ircode;
-       int i;
+       int i, start, range, toggle, dev, code;
 
        if (NULL == ir)
                return;
@@ -461,6 +464,34 @@ void cx88_ir_irq(struct cx88_core *core)
        case CX88_BOARD_HAUPPAUGE_NOVASPLUS_S1:
        case CX88_BOARD_HAUPPAUGE_HVR1100:
        case CX88_BOARD_HAUPPAUGE_HVR3000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000:
+       case CX88_BOARD_HAUPPAUGE_HVR4000LITE:
+               ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
+               ir_dprintk("biphase decoded: %x\n", ircode);
+               /*
+                * RC5 has an extension bit which adds a new range
+                * of available codes, this is detected here. Also
+                * hauppauge remotes (black/silver) always use
+                * specific device ids. If we do not filter the
+                * device ids then messages destined for devices
+                * such as TVs (id=0) will get through to the
+                * device causing mis-fired events.
+                */
+               /* split rc5 data block ... */
+               start = (ircode & 0x2000) >> 13;
+               range = (ircode & 0x1000) >> 12;
+               toggle= (ircode & 0x0800) >> 11;
+               dev   = (ircode & 0x07c0) >> 6;
+               code  = (ircode & 0x003f) | ((range << 6) ^ 0x0040);
+               if( start != 1)
+                       /* no key pressed */
+                       break;
+               if ( dev != 0x1e && dev != 0x1f )
+                       /* not a hauppauge remote */
+                       break;
+               ir_input_keydown(ir->input, &ir->ir, code, ircode);
+               ir->release = jiffies + msecs_to_jiffies(120);
+               break;
        case CX88_BOARD_PINNACLE_PCTV_HD_800i:
                ircode = ir_decode_biphase(ir->samples, ir->scount, 5, 7);
                ir_dprintk("biphase decoded: %x\n", ircode);
index ef4d56ea00278bf4183ac932fd7f46edda8b1618..be45955dff686ebb38d598c8fb7e86d62ef6ca2f 100644 (file)
@@ -773,6 +773,7 @@ static int video_open(struct inode *inode, struct file *file)
        enum v4l2_buf_type type = 0;
        int radio = 0;
 
+       lock_kernel();
        list_for_each_entry(h, &cx8800_devlist, devlist) {
                if (h->video_dev->minor == minor) {
                        dev  = h;
@@ -788,8 +789,10 @@ static int video_open(struct inode *inode, struct file *file)
                        dev   = h;
                }
        }
-       if (NULL == dev)
+       if (NULL == dev) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        core = dev->core;
 
@@ -798,8 +801,10 @@ static int video_open(struct inode *inode, struct file *file)
 
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh),GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
        file->private_data = fh;
        fh->dev      = dev;
        fh->radio    = radio;
@@ -832,6 +837,9 @@ static int video_open(struct inode *inode, struct file *file)
                cx88_set_stereo(core,V4L2_TUNER_MODE_STEREO,1);
                cx88_call_i2c_clients(core,AUDC_SET_RADIO,NULL);
        }
+       unlock_kernel();
+
+       atomic_inc(&core->users);
 
        return 0;
 }
@@ -920,7 +928,8 @@ static int video_release(struct inode *inode, struct file *file)
        file->private_data = NULL;
        kfree(fh);
 
-       cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
+       if(atomic_dec_and_test(&dev->core->users))
+               cx88_call_i2c_clients (dev->core, TUNER_SET_STANDBY, NULL);
 
        return 0;
 }
index 54fe650947115e490c6334ff489451e5f98576ca..dbf01b8b57a52876b0cfe7ae67f4e3665f6c0a1d 100644 (file)
@@ -221,6 +221,14 @@ extern struct sram_channel cx88_sram_channels[];
 #define CX88_BOARD_DVICO_FUSIONHDTV_7_GOLD 65
 #define CX88_BOARD_PROLINK_PV_8000GT       66
 #define CX88_BOARD_KWORLD_ATSC_120         67
+#define CX88_BOARD_HAUPPAUGE_HVR4000       68
+#define CX88_BOARD_HAUPPAUGE_HVR4000LITE   69
+#define CX88_BOARD_TEVII_S460              70
+#define CX88_BOARD_OMICOM_SS4_PCI          71
+#define CX88_BOARD_TBS_8920                72
+#define CX88_BOARD_TEVII_S420              73
+#define CX88_BOARD_PROLINK_PV_GLOBAL_XTREME 74
+#define CX88_BOARD_PROF_7300               75
 
 enum cx88_itype {
        CX88_VMUX_COMPOSITE1 = 1,
@@ -342,6 +350,7 @@ struct cx88_core {
        struct mutex               lock;
        /* various v4l controls */
        u32                        freq;
+       atomic_t                   users;
 
        /* cx88-video needs to access cx8802 for hybrid tuner pll access. */
        struct cx8802_dev          *dvbdev;
@@ -601,7 +610,7 @@ extern void cx88_call_i2c_clients(struct cx88_core *core,
 /* ----------------------------------------------------------- */
 /* cx88-cards.c                                                */
 
-extern int cx88_tuner_callback(void *dev, int command, int arg);
+extern int cx88_tuner_callback(void *dev, int component, int command, int arg);
 extern int cx88_get_resources(const struct cx88_core *core,
                              struct pci_dev *pci);
 extern struct cx88_core *cx88_core_create(struct pci_dev *pci, int nr);
index 79faedf585217f0e5cda3ac6902ce567dc9918c7..3aa538afcc0b3ab2343c2c29833cfe02621370f3 100644 (file)
@@ -866,7 +866,8 @@ static int __init dabusb_init (void)
 
        dbg("dabusb_init: driver registered");
 
-       info(DRIVER_VERSION ":" DRIVER_DESC);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
 
 out:
        return retval;
diff --git a/drivers/media/video/dpc7146.c b/drivers/media/video/dpc7146.c
deleted file mode 100644 (file)
index 88d6df7..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
-    dpc7146.c - v4l2 driver for the dpc7146 demonstration board
-
-    Copyright (C) 2000-2003 Michael Hunold <michael@mihu.de>
-
-    This program is free software; you can redistribute it and/or modify
-    it under the terms of the GNU General Public License as published by
-    the Free Software Foundation; either version 2 of the License, or
-    (at your option) any later version.
-
-    This program is distributed in the hope that it will be useful,
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-    GNU General Public License for more details.
-
-    You should have received a copy of the GNU General Public License
-    along with this program; if not, write to the Free Software
-    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-*/
-
-#define DEBUG_VARIABLE debug
-
-#include <media/saa7146_vv.h>
-#include <linux/video_decoder.h>       /* for saa7111a */
-
-#define I2C_SAA7111A            0x24
-
-/* All unused bytes are reserverd. */
-#define SAA711X_CHIP_VERSION            0x00
-#define SAA711X_ANALOG_INPUT_CONTROL_1  0x02
-#define SAA711X_ANALOG_INPUT_CONTROL_2  0x03
-#define SAA711X_ANALOG_INPUT_CONTROL_3  0x04
-#define SAA711X_ANALOG_INPUT_CONTROL_4  0x05
-#define SAA711X_HORIZONTAL_SYNC_START   0x06
-#define SAA711X_HORIZONTAL_SYNC_STOP    0x07
-#define SAA711X_SYNC_CONTROL            0x08
-#define SAA711X_LUMINANCE_CONTROL       0x09
-#define SAA711X_LUMINANCE_BRIGHTNESS    0x0A
-#define SAA711X_LUMINANCE_CONTRAST      0x0B
-#define SAA711X_CHROMA_SATURATION       0x0C
-#define SAA711X_CHROMA_HUE_CONTROL      0x0D
-#define SAA711X_CHROMA_CONTROL          0x0E
-#define SAA711X_FORMAT_DELAY_CONTROL    0x10
-#define SAA711X_OUTPUT_CONTROL_1        0x11
-#define SAA711X_OUTPUT_CONTROL_2        0x12
-#define SAA711X_OUTPUT_CONTROL_3        0x13
-#define SAA711X_V_GATE_1_START          0x15
-#define SAA711X_V_GATE_1_STOP           0x16
-#define SAA711X_V_GATE_1_MSB            0x17
-#define SAA711X_TEXT_SLICER_STATUS      0x1A
-#define SAA711X_DECODED_BYTES_OF_TS_1   0x1B
-#define SAA711X_DECODED_BYTES_OF_TS_2   0x1C
-#define SAA711X_STATUS_BYTE             0x1F
-
-#define DPC_BOARD_CAN_DO_VBI(dev)   (dev->revision != 0)
-
-static int debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "debug verbosity");
-
-static int dpc_num;
-
-#define DPC_INPUTS     2
-static struct v4l2_input dpc_inputs[DPC_INPUTS] = {
-       { 0, "Port A",  V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
-       { 1, "Port B",  V4L2_INPUT_TYPE_CAMERA, 2, 0, V4L2_STD_PAL_BG|V4L2_STD_NTSC_M, 0 },
-};
-
-#define DPC_AUDIOS     0
-
-static struct saa7146_extension_ioctls ioctls[] = {
-       { VIDIOC_G_INPUT,       SAA7146_EXCLUSIVE },
-       { VIDIOC_S_INPUT,       SAA7146_EXCLUSIVE },
-       { VIDIOC_ENUMINPUT,     SAA7146_EXCLUSIVE },
-       { VIDIOC_S_STD,         SAA7146_AFTER },
-       { 0,                    0 }
-};
-
-struct dpc
-{
-       struct video_device     *video_dev;
-       struct video_device     *vbi_dev;
-
-       struct i2c_adapter      i2c_adapter;
-       struct i2c_client       *saa7111a;
-
-       int cur_input;  /* current input */
-};
-
-static int dpc_check_clients(struct device *dev, void *data)
-{
-       struct dpc* dpc = data;
-       struct i2c_client *client = i2c_verify_client(dev);
-
-       if( !client )
-               return 0;
-
-       if( I2C_SAA7111A == client->addr )
-               dpc->saa7111a = client;
-
-       return 0;
-}
-
-/* fixme: add vbi stuff here */
-static int dpc_probe(struct saa7146_dev* dev)
-{
-       struct dpc* dpc = NULL;
-
-       dpc = kzalloc(sizeof(struct dpc), GFP_KERNEL);
-       if( NULL == dpc ) {
-               printk("dpc_v4l2.o: dpc_probe: not enough kernel memory.\n");
-               return -ENOMEM;
-       }
-
-       /* FIXME: enable i2c-port pins, video-port-pins
-          video port pins should be enabled here ?! */
-       saa7146_write(dev, MC1, (MASK_08 | MASK_24 | MASK_10 | MASK_26));
-
-       dpc->i2c_adapter = (struct i2c_adapter) {
-               .class = I2C_CLASS_TV_ANALOG,
-               .name = "dpc7146",
-       };
-       saa7146_i2c_adapter_prepare(dev, &dpc->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
-       if(i2c_add_adapter(&dpc->i2c_adapter) < 0) {
-               DEB_S(("cannot register i2c-device. skipping.\n"));
-               kfree(dpc);
-               return -EFAULT;
-       }
-
-       /* loop through all i2c-devices on the bus and look who is there */
-       device_for_each_child(&dpc->i2c_adapter.dev, dpc, dpc_check_clients);
-
-       /* check if all devices are present */
-       if (!dpc->saa7111a) {
-               DEB_D(("dpc_v4l2.o: dpc_attach failed for this device.\n"));
-               i2c_del_adapter(&dpc->i2c_adapter);
-               kfree(dpc);
-               return -ENODEV;
-       }
-
-       /* all devices are present, probe was successful */
-       DEB_D(("dpc_v4l2.o: dpc_probe succeeded for this device.\n"));
-
-       /* we store the pointer in our private data field */
-       dev->ext_priv = dpc;
-
-       return 0;
-}
-
-/* bring hardware to a sane state. this has to be done, just in case someone
-   wants to capture from this device before it has been properly initialized.
-   the capture engine would badly fail, because no valid signal arrives on the
-   saa7146, thus leading to timeouts and stuff. */
-static int dpc_init_done(struct saa7146_dev* dev)
-{
-       struct dpc* dpc = (struct dpc*)dev->ext_priv;
-
-       DEB_D(("dpc_v4l2.o: dpc_init_done called.\n"));
-
-       /* initialize the helper ics to useful values */
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x00, 0x11);
-
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x02, 0xc0);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x03, 0x30);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x04, 0x00);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x05, 0x00);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x06, 0xde);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x07, 0xad);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x08, 0xa8);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x09, 0x00);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x0a, 0x80);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x0b, 0x47);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x0c, 0x40);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x0d, 0x00);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x0e, 0x03);
-
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x10, 0xd0);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x11, 0x1c);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x12, 0xc1);
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x13, 0x30);
-
-       i2c_smbus_write_byte_data(dpc->saa7111a, 0x1f, 0x81);
-
-       return 0;
-}
-
-static struct saa7146_ext_vv vv_data;
-
-/* this function only gets called when the probing was successful */
-static int dpc_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data *info)
-{
-       struct dpc* dpc = (struct dpc*)dev->ext_priv;
-
-       DEB_D(("dpc_v4l2.o: dpc_attach called.\n"));
-
-       /* checking for i2c-devices can be omitted here, because we
-          already did this in "dpc_vl42_probe" */
-
-       saa7146_vv_init(dev,&vv_data);
-       if( 0 != saa7146_register_device(&dpc->video_dev, dev, "dpc", VFL_TYPE_GRABBER)) {
-               ERR(("cannot register capture v4l2 device. skipping.\n"));
-               return -1;
-       }
-
-       /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
-       if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
-               if( 0 != saa7146_register_device(&dpc->vbi_dev, dev, "dpc", VFL_TYPE_VBI)) {
-                       ERR(("cannot register vbi v4l2 device. skipping.\n"));
-               }
-       }
-
-       i2c_use_client(dpc->saa7111a);
-
-       printk("dpc: found 'dpc7146 demonstration board'-%d.\n",dpc_num);
-       dpc_num++;
-
-       /* the rest */
-       dpc->cur_input = 0;
-       dpc_init_done(dev);
-
-       return 0;
-}
-
-static int dpc_detach(struct saa7146_dev* dev)
-{
-       struct dpc* dpc = (struct dpc*)dev->ext_priv;
-
-       DEB_EE(("dev:%p\n",dev));
-
-       i2c_release_client(dpc->saa7111a);
-
-       saa7146_unregister_device(&dpc->video_dev,dev);
-       if( 0 != DPC_BOARD_CAN_DO_VBI(dev)) {
-               saa7146_unregister_device(&dpc->vbi_dev,dev);
-       }
-       saa7146_vv_release(dev);
-
-       dpc_num--;
-
-       i2c_del_adapter(&dpc->i2c_adapter);
-       kfree(dpc);
-       return 0;
-}
-
-#ifdef axa
-int dpc_vbi_bypass(struct saa7146_dev* dev)
-{
-       struct dpc* dpc = (struct dpc*)dev->ext_priv;
-
-       int i = 1;
-
-       /* switch bypass in saa7111a */
-       if ( 0 != dpc->saa7111a->driver->command(dpc->saa7111a,SAA711X_VBI_BYPASS, &i)) {
-               printk("dpc_v4l2.o: VBI_BYPASS: could not address saa7111a.\n");
-               return -1;
-       }
-
-       return 0;
-}
-#endif
-
-static int dpc_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
-{
-       struct saa7146_dev *dev = fh->dev;
-       struct dpc* dpc = (struct dpc*)dev->ext_priv;
-/*
-       struct saa7146_vv *vv = dev->vv_data;
-*/
-       switch(cmd)
-       {
-       case VIDIOC_ENUMINPUT:
-       {
-               struct v4l2_input *i = arg;
-               DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
-
-               if( i->index < 0 || i->index >= DPC_INPUTS) {
-                       return -EINVAL;
-               }
-
-               memcpy(i, &dpc_inputs[i->index], sizeof(struct v4l2_input));
-
-               DEB_D(("dpc_v4l2.o: v4l2_ioctl: VIDIOC_ENUMINPUT %d.\n",i->index));
-               return 0;
-       }
-       case VIDIOC_G_INPUT:
-       {
-               int *input = (int *)arg;
-               *input = dpc->cur_input;
-
-               DEB_D(("dpc_v4l2.o: VIDIOC_G_INPUT: %d\n",*input));
-               return 0;
-       }
-       case VIDIOC_S_INPUT:
-       {
-               int     input = *(int *)arg;
-
-               if (input < 0 || input >= DPC_INPUTS) {
-                       return -EINVAL;
-               }
-
-               dpc->cur_input = input;
-
-               /* fixme: switch input here, switch audio, too! */
-//             saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
-               printk("dpc_v4l2.o: VIDIOC_S_INPUT: fixme switch input.\n");
-
-               return 0;
-       }
-       default:
-/*
-               DEB_D(("dpc_v4l2.o: v4l2_ioctl does not handle this ioctl.\n"));
-*/
-               return -ENOIOCTLCMD;
-       }
-       return 0;
-}
-
-static int std_callback(struct saa7146_dev* dev, struct saa7146_standard *std)
-{
-       return 0;
-}
-
-static struct saa7146_standard standard[] = {
-       {
-               .name   = "PAL",        .id     = V4L2_STD_PAL,
-               .v_offset       = 0x17, .v_field        = 288,
-               .h_offset       = 0x14, .h_pixels       = 680,
-               .v_max_out      = 576,  .h_max_out      = 768,
-       }, {
-               .name   = "NTSC",       .id     = V4L2_STD_NTSC,
-               .v_offset       = 0x16, .v_field        = 240,
-               .h_offset       = 0x06, .h_pixels       = 708,
-               .v_max_out      = 480,  .h_max_out      = 640,
-       }, {
-               .name   = "SECAM",      .id     = V4L2_STD_SECAM,
-               .v_offset       = 0x14, .v_field        = 288,
-               .h_offset       = 0x14, .h_pixels       = 720,
-               .v_max_out      = 576,  .h_max_out      = 768,
-       }
-};
-
-static struct saa7146_extension extension;
-
-static struct saa7146_pci_extension_data dpc = {
-       .ext_priv = "Multimedia eXtension Board",
-       .ext = &extension,
-};
-
-static struct pci_device_id pci_tbl[] = {
-       {
-               .vendor    = PCI_VENDOR_ID_PHILIPS,
-               .device    = PCI_DEVICE_ID_PHILIPS_SAA7146,
-               .subvendor = 0x0000,
-               .subdevice = 0x0000,
-               .driver_data = (unsigned long)&dpc,
-       }, {
-               .vendor = 0,
-       }
-};
-
-MODULE_DEVICE_TABLE(pci, pci_tbl);
-
-static struct saa7146_ext_vv vv_data = {
-       .inputs         = DPC_INPUTS,
-       .capabilities   = V4L2_CAP_VBI_CAPTURE,
-       .stds           = &standard[0],
-       .num_stds       = sizeof(standard)/sizeof(struct saa7146_standard),
-       .std_callback   = &std_callback,
-       .ioctls         = &ioctls[0],
-       .ioctl          = dpc_ioctl,
-};
-
-static struct saa7146_extension extension = {
-       .name           = "dpc7146 demonstration board",
-       .flags          = SAA7146_USE_I2C_IRQ,
-
-       .pci_tbl        = &pci_tbl[0],
-       .module         = THIS_MODULE,
-
-       .probe          = dpc_probe,
-       .attach         = dpc_attach,
-       .detach         = dpc_detach,
-
-       .irq_mask       = 0,
-       .irq_func       = NULL,
-};
-
-static int __init dpc_init_module(void)
-{
-       if( 0 != saa7146_register_extension(&extension)) {
-               DEB_S(("failed to register extension.\n"));
-               return -ENODEV;
-       }
-
-       return 0;
-}
-
-static void __exit dpc_cleanup_module(void)
-{
-       saa7146_unregister_extension(&extension);
-}
-
-module_init(dpc_init_module);
-module_exit(dpc_cleanup_module);
-
-MODULE_DESCRIPTION("video4linux-2 driver for the 'dpc7146 demonstration board'");
-MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
-MODULE_LICENSE("GPL");
index de943cf6c169aa58eb5eb319cab4f0909a2fe27d..d65d0572403bbd29f77675bcaf995284e0cdd466 100644 (file)
@@ -1101,7 +1101,7 @@ struct usb_device_id em28xx_id_table [] = {
        { USB_DEVICE(0xeb1a, 0x2820),
                        .driver_info = EM2820_BOARD_UNKNOWN },
        { USB_DEVICE(0xeb1a, 0x2821),
-                       .driver_info = EM2820_BOARD_UNKNOWN },
+                       .driver_info = EM2820_BOARD_PROLINK_PLAYTV_USB2 },
        { USB_DEVICE(0xeb1a, 0x2860),
                        .driver_info = EM2820_BOARD_UNKNOWN },
        { USB_DEVICE(0xeb1a, 0x2861),
@@ -1271,7 +1271,7 @@ static struct em28xx_hash_table em28xx_i2c_hash[] = {
        {0x1ba50080, EM2860_BOARD_POINTNIX_INTRAORAL_CAMERA, TUNER_ABSENT},
 };
 
-int em28xx_tuner_callback(void *ptr, int command, int arg)
+int em28xx_tuner_callback(void *ptr, int component, int command, int arg)
 {
        int rc = 0;
        struct em28xx *dev = ptr;
index d2b1a1a52689f57fe5d9b423887d0c169818f347..c99e2383b7ec994cf92532bd2135812ecdda822d 100644 (file)
@@ -249,7 +249,6 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
        memset(&cfg, 0, sizeof(cfg));
        cfg.i2c_adap  = &dev->i2c_adap;
        cfg.i2c_addr  = addr;
-       cfg.callback  = em28xx_tuner_callback;
 
        if (!dev->dvb->frontend) {
                printk(KERN_ERR "%s/2: dvb frontend not attached. "
@@ -274,7 +273,7 @@ static int attach_xc3028(u8 addr, struct em28xx *dev)
 
 /* ------------------------------------------------------------------ */
 
-int register_dvb(struct em28xx_dvb *dvb,
+static int register_dvb(struct em28xx_dvb *dvb,
                 struct module *module,
                 struct em28xx *dev,
                 struct device *device)
@@ -422,6 +421,8 @@ static int dvb_init(struct em28xx *dev)
                }
                break;
        case EM2880_BOARD_HAUPPAUGE_WINTV_HVR_900:
+       case EM2880_BOARD_TERRATEC_HYBRID_XS:
+       case EM2880_BOARD_KWORLD_DVB_310U:
                dvb->frontend = dvb_attach(zl10353_attach,
                                           &em28xx_zl10353_with_xc3028,
                                           &dev->i2c_adap);
@@ -443,24 +444,6 @@ static int dvb_init(struct em28xx *dev)
                }
                break;
 #endif
-       case EM2880_BOARD_TERRATEC_HYBRID_XS:
-               dvb->frontend = dvb_attach(zl10353_attach,
-                                               &em28xx_zl10353_with_xc3028,
-                                               &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
-                        result = -EINVAL;
-                       goto out_free;
-               }
-               break;
-       case EM2880_BOARD_KWORLD_DVB_310U:
-               dvb->frontend = dvb_attach(zl10353_attach,
-                                               &em28xx_zl10353_with_xc3028,
-                                               &dev->i2c_adap);
-               if (attach_xc3028(0x61, dev) < 0) {
-                       result = -EINVAL;
-                       goto out_free;
-               }
-               break;
        default:
                printk(KERN_ERR "%s/2: The frontend of your DVB/ATSC card"
                                " isn't supported yet\n",
@@ -474,6 +457,8 @@ static int dvb_init(struct em28xx *dev)
                result = -EINVAL;
                goto out_free;
        }
+       /* define general-purpose callback pointer */
+       dvb->frontend->callback = em28xx_tuner_callback;
 
        /* register everything */
        result = register_dvb(dvb, THIS_MODULE, dev, &dev->udev->dev);
index 97853384c9436f0d198d668bb3cdca789125e5ae..3bab56b997fc391033b47e262f6d72855d11e15b 100644 (file)
@@ -143,10 +143,11 @@ static int em2800_i2c_check_for_device(struct em28xx *dev, unsigned char addr)
        }
        for (write_timeout = EM2800_I2C_WRITE_TIMEOUT; write_timeout > 0;
             write_timeout -= 5) {
-               unsigned msg = dev->em28xx_read_reg(dev, 0x5);
-               if (msg == 0x94)
+               unsigned reg = dev->em28xx_read_reg(dev, 0x5);
+
+               if (reg == 0x94)
                        return -ENODEV;
-               else if (msg == 0x84)
+               else if (reg == 0x84)
                        return 0;
                msleep(5);
        }
@@ -335,8 +336,11 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
 
        /* Check if board has eeprom */
        err = i2c_master_recv(&dev->i2c_client, &buf, 0);
-       if (err < 0)
-               return -1;
+       if (err < 0) {
+               em28xx_errdev("%s: i2c_master_recv failed! err [%d]\n",
+                       __func__, err);
+               return err;
+       }
 
        buf = 0;
 
@@ -344,7 +348,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
        if (err != 1) {
                printk(KERN_INFO "%s: Huh, no eeprom present (err=%d)?\n",
                       dev->name, err);
-               return -1;
+               return err;
        }
        while (size > 0) {
                if (size > 16)
@@ -357,7 +361,7 @@ static int em28xx_i2c_eeprom(struct em28xx *dev, unsigned char *eedata, int len)
                        printk(KERN_WARNING
                               "%s: i2c eeprom read error (err=%d)\n",
                               dev->name, err);
-                       return -1;
+                       return err;
                }
                size -= block;
                p += block;
@@ -585,18 +589,31 @@ void em28xx_i2c_call_clients(struct em28xx *dev, unsigned int cmd, void *arg)
  */
 int em28xx_i2c_register(struct em28xx *dev)
 {
+       int retval;
+
        BUG_ON(!dev->em28xx_write_regs || !dev->em28xx_read_reg);
        BUG_ON(!dev->em28xx_write_regs_req || !dev->em28xx_read_reg_req);
        dev->i2c_adap = em28xx_adap_template;
        dev->i2c_adap.dev.parent = &dev->udev->dev;
        strcpy(dev->i2c_adap.name, dev->name);
        dev->i2c_adap.algo_data = dev;
-       i2c_add_adapter(&dev->i2c_adap);
+
+       retval = i2c_add_adapter(&dev->i2c_adap);
+       if (retval < 0) {
+               em28xx_errdev("%s: i2c_add_adapter failed! retval [%d]\n",
+                       __func__, retval);
+               return retval;
+       }
 
        dev->i2c_client = em28xx_client_template;
        dev->i2c_client.adapter = &dev->i2c_adap;
 
-       em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
+       retval = em28xx_i2c_eeprom(dev, dev->eedata, sizeof(dev->eedata));
+       if (retval < 0) {
+               em28xx_errdev("%s: em28xx_i2_eeprom failed! retval [%d]\n",
+                       __func__, retval);
+               return retval;
+       }
 
        if (i2c_scan)
                em28xx_do_i2c_scan(dev);
index 49ab0629702e289bb2a8360a00c0703e3d60f694..c53649e5315b0a815cd09633578dfcea263b41cd 100644 (file)
@@ -513,10 +513,17 @@ static struct videobuf_queue_ops em28xx_video_qops = {
  */
 static int em28xx_config(struct em28xx *dev)
 {
+       int retval;
 
        /* Sets I2C speed to 100 KHz */
-       if (!dev->is_em2800)
-               em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
+       if (!dev->is_em2800) {
+               retval = em28xx_write_regs_req(dev, 0x00, 0x06, "\x40", 1);
+               if (retval < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req failed! retval [%d]\n",
+                               __func__, retval);
+                       return retval;
+               }
+       }
 
        /* enable vbi capturing */
 
@@ -1512,6 +1519,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
        struct em28xx_fh *fh;
        enum v4l2_buf_type fh_type = 0;
 
+       lock_kernel();
        list_for_each_entry(h, &em28xx_devlist, devlist) {
                if (h->vdev->minor == minor) {
                        dev  = h;
@@ -1527,8 +1535,10 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
                        dev   = h;
                }
        }
-       if (NULL == dev)
+       if (NULL == dev) {
+               unlock_kernel();
                return -ENODEV;
+       }
 
        em28xx_videodbg("open minor=%d type=%s users=%d\n",
                                minor, v4l2_type_names[fh_type], dev->users);
@@ -1537,6 +1547,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
        fh = kzalloc(sizeof(struct em28xx_fh), GFP_KERNEL);
        if (!fh) {
                em28xx_errdev("em28xx-video.c: Out of memory?!\n");
+               unlock_kernel();
                return -ENOMEM;
        }
        mutex_lock(&dev->lock);
@@ -1573,6 +1584,7 @@ static int em28xx_v4l2_open(struct inode *inode, struct file *filp)
                        sizeof(struct em28xx_buffer), fh);
 
        mutex_unlock(&dev->lock);
+       unlock_kernel();
 
        return errCode;
 }
@@ -1588,8 +1600,7 @@ static void em28xx_release_resources(struct em28xx *dev)
        /*FIXME: I2C IR should be disconnected */
 
        em28xx_info("V4L2 devices /dev/video%d and /dev/vbi%d deregistered\n",
-                               dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
-                               dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
+                               dev->vdev->num, dev->vbi_dev->num);
        list_del(&dev->devlist);
        if (dev->sbutton_input_dev)
                em28xx_deregister_snapshot_button(dev);
@@ -1948,13 +1959,23 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        }
 
        /* register i2c bus */
-       em28xx_i2c_register(dev);
+       errCode = em28xx_i2c_register(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_i2c_register - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        /* Do board specific init and eeprom reading */
        em28xx_card_setup(dev);
 
        /* Configure audio */
-       em28xx_audio_analog_set(dev);
+       errCode = em28xx_audio_analog_set(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_audio_analog_set - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        /* configure the device */
        em28xx_config_i2c(dev);
@@ -1974,6 +1995,11 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
        dev->ctl_input = 2;
 
        errCode = em28xx_config(dev);
+       if (errCode < 0) {
+               em28xx_errdev("%s: em28xx_config - errCode [%d]!\n",
+                       __func__, errCode);
+               return errCode;
+       }
 
        list_add_tail(&dev->devlist, &em28xx_devlist);
 
@@ -2026,17 +2052,27 @@ static int em28xx_init_dev(struct em28xx **devhandle, struct usb_device *udev,
 
        if (dev->has_msp34xx) {
                /* Send a reset to other chips via gpio */
-               em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
+               errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xf7", 1);
+               if (errCode < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(1) failed! errCode [%d]\n",
+                               __func__, errCode);
+                       return errCode;
+               }
                msleep(3);
-               em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
+
+               errCode = em28xx_write_regs_req(dev, 0x00, 0x08, "\xff", 1);
+               if (errCode < 0) {
+                       em28xx_errdev("%s: em28xx_write_regs_req - msp34xx(2) failed! errCode [%d]\n",
+                               __func__, errCode);
+                       return errCode;
+               }
                msleep(3);
        }
 
        video_mux(dev, 0);
 
        em28xx_info("V4L2 device registered as /dev/video%d and /dev/vbi%d\n",
-                               dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN,
-                               dev->vbi_dev->minor-MINOR_VFL_TYPE_VBI_MIN);
+                               dev->vdev->num, dev->vbi_dev->num);
 
        mutex_lock(&em28xx_extension_devlist_lock);
        if (!list_empty(&em28xx_extension_devlist)) {
@@ -2236,7 +2272,7 @@ static void em28xx_usb_disconnect(struct usb_interface *interface)
                em28xx_warn
                    ("device /dev/video%d is open! Deregistration and memory "
                     "deallocation are deferred on close.\n",
-                               dev->vdev->minor-MINOR_VFL_TYPE_GRABBER_MIN);
+                               dev->vdev->num);
 
                dev->state |= DEV_MISCONFIGURED;
                em28xx_uninit_isoc(dev);
index 9a3310748685c9c3ec63c84522272b463d491287..82781178e0a3e23c7514a09bf6600c02d658ae36 100644 (file)
@@ -411,8 +411,8 @@ struct em28xx {
        /* frame properties */
        int width;              /* current frame width */
        int height;             /* current frame height */
-       int hscale;             /* horizontal scale factor (see datasheet) */
-       int vscale;             /* vertical scale factor (see datasheet) */
+       unsigned hscale;        /* horizontal scale factor (see datasheet) */
+       unsigned vscale;        /* vertical scale factor (see datasheet) */
        int interlaced;         /* 1=interlace fileds, 0=just top fileds */
        unsigned int video_bytesread;   /* Number of bytes read */
 
@@ -528,7 +528,7 @@ extern struct em28xx_board em28xx_boards[];
 extern struct usb_device_id em28xx_id_table[];
 extern const unsigned int em28xx_bcount;
 void em28xx_set_ir(struct em28xx *dev, struct IR_i2c *ir);
-int em28xx_tuner_callback(void *ptr, int command, int arg);
+int em28xx_tuner_callback(void *ptr, int component, int command, int arg);
 
 /* Provided by em28xx-input.c */
 /* TODO: Check if the standard get_key handlers on ir-common can be used */
index 8db2a05bf9c542544b3a3bf9bc1c4fdd5cc217bf..7a85c41b0eea3b592ccc7554707421a40d70aaa3 100644 (file)
@@ -1214,7 +1214,7 @@ static int et61x251_open(struct inode* inode, struct file* filp)
        if (!down_read_trylock(&et61x251_dev_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        if (wait_for_completion_interruptible(&cam->probe)) {
                up_read(&et61x251_dev_lock);
@@ -1297,7 +1297,7 @@ static int et61x251_release(struct inode* inode, struct file* filp)
 
        down_write(&et61x251_dev_lock);
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        et61x251_stop_transfer(cam);
        et61x251_release_buffers(cam);
@@ -1318,7 +1318,7 @@ static ssize_t
 et61x251_read(struct file* filp, char __user * buf,
              size_t count, loff_t* f_pos)
 {
-       struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
+       struct et61x251_device *cam = video_drvdata(filp);
        struct et61x251_frame_t* f, * i;
        unsigned long lock_flags;
        long timeout;
@@ -1426,7 +1426,7 @@ exit:
 
 static unsigned int et61x251_poll(struct file *filp, poll_table *wait)
 {
-       struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
+       struct et61x251_device *cam = video_drvdata(filp);
        struct et61x251_frame_t* f;
        unsigned long lock_flags;
        unsigned int mask = 0;
@@ -1502,7 +1502,7 @@ static struct vm_operations_struct et61x251_vm_ops = {
 
 static int et61x251_mmap(struct file* filp, struct vm_area_struct *vma)
 {
-       struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
+       struct et61x251_device *cam = video_drvdata(filp);
        unsigned long size = vma->vm_end - vma->vm_start,
                      start = vma->vm_start;
        void *pos;
@@ -2395,7 +2395,7 @@ et61x251_vidioc_s_parm(struct et61x251_device* cam, void __user * arg)
 static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
                               unsigned int cmd, void __user * arg)
 {
-       struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
+       struct et61x251_device *cam = video_drvdata(filp);
 
        switch (cmd) {
 
@@ -2490,7 +2490,7 @@ static int et61x251_ioctl_v4l2(struct inode* inode, struct file* filp,
 static int et61x251_ioctl(struct inode* inode, struct file* filp,
                         unsigned int cmd, unsigned long arg)
 {
-       struct et61x251_device* cam = video_get_drvdata(video_devdata(filp));
+       struct et61x251_device *cam = video_drvdata(filp);
        int err = 0;
 
        if (mutex_lock_interruptible(&cam->fileop_mutex))
index 42b90742b40be6b4abc42d0f89d1928d5c4625c0..4d0817471c9f6a5c6bd11f6d5c3ef21710e205ab 100644 (file)
-config USB_GSPCA
-       tristate "USB GSPCA driver"
+menuconfig USB_GSPCA
+       tristate "GSPCA based webcams"
        depends on VIDEO_V4L2
+       default m
        ---help---
-         Say Y here if you want support for various USB webcams.
+       Say Y here if you want to enable selecting webcams based
+       on the GSPCA framework.
 
-         See <file:Documentation/video4linux/gspca.txt> for more info.
+       See <file:Documentation/video4linux/gspca.txt> for more info.
 
-         This driver uses the Video For Linux API. You must say Y or M to
-         "Video For Linux" to use this driver.
+       This driver uses the Video For Linux API. You must say Y or M to
+       "Video For Linux" to use this driver.
 
-         To compile this driver as modules, choose M here: the
-         modules will be called gspca_xxxx.
+       To compile this driver as modules, choose M here: the
+       modules will be called gspca_main.
+
+
+if USB_GSPCA && VIDEO_V4L2
+
+source "drivers/media/video/gspca/m5602/Kconfig"
+
+config USB_GSPCA_CONEX
+       tristate "Conexant Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the Conexant chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_conex.
+
+config USB_GSPCA_ETOMS
+       tristate "Etoms USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the Etoms chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_etoms.
+
+config USB_GSPCA_FINEPIX
+       tristate "Fujifilm FinePix USB V4L2 driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the FinePix chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_finepix.
+
+config USB_GSPCA_MARS
+       tristate "Mars USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the Mars chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_mars.
+
+config USB_GSPCA_OV519
+       tristate "OV519 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the OV519 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_ov519.
+
+config USB_GSPCA_PAC207
+       tristate "Pixart PAC207 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the PAC207 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_pac207.
+
+config USB_GSPCA_PAC7311
+       tristate "Pixart PAC7311 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the PAC7311 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_pac7311.
+
+config USB_GSPCA_SONIXB
+       tristate "SN9C102 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SONIXB chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_sonixb.
+
+config USB_GSPCA_SONIXJ
+       tristate "SONIX JPEG USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SONIXJ chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_sonixj
+
+config USB_GSPCA_SPCA500
+       tristate "SPCA500 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA500 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca500.
+
+config USB_GSPCA_SPCA501
+       tristate "SPCA501 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA501 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca501.
+
+config USB_GSPCA_SPCA505
+       tristate "SPCA505 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA505 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca505.
+
+config USB_GSPCA_SPCA506
+       tristate "SPCA506 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA506 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca506.
+
+config USB_GSPCA_SPCA508
+       tristate "SPCA508 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA508 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca508.
+
+config USB_GSPCA_SPCA561
+       tristate "SPCA561 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the SPCA561 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca561.
+
+config USB_GSPCA_STK014
+       tristate "Syntek DV4000 (STK014) USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the STK014 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_stk014.
+
+config USB_GSPCA_SUNPLUS
+       tristate "SUNPLUS USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the Sunplus
+       SPCA504(abc) SPCA533 SPCA536 chips.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_spca5xx.
+
+config USB_GSPCA_T613
+       tristate "T613 (JPEG Compliance) USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the T613 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_t613.
+
+config USB_GSPCA_TV8532
+       tristate "TV8532 USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the TV8531 chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_tv8532.
+
+config USB_GSPCA_VC032X
+       tristate "VC032X USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the VC032X chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_vc032x.
+
+config USB_GSPCA_ZC3XX
+       tristate "VC3xx USB Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+       Say Y here if you want support for cameras based on the ZC3XX chip.
+
+       To compile this driver as a module, choose M here: the
+       module will be called gspca_zc3xx.
+
+endif
index e68a8965297a70d7cff5ba6fb33ea83a32d4ee96..22734f5a6c3216b52cd0fb867832da939ced7bf6 100644 (file)
@@ -1,29 +1,48 @@
-obj-$(CONFIG_USB_GSPCA)        += gspca_main.o \
-       gspca_conex.o gspca_etoms.o gspca_mars.o \
-       gspca_ov519.o gspca_pac207.o gspca_pac7311.o \
-       gspca_sonixb.o gspca_sonixj.o gspca_spca500.o gspca_spca501.o \
-       gspca_spca505.o gspca_spca506.o gspca_spca508.o gspca_spca561.o \
-       gspca_sunplus.o gspca_stk014.o gspca_t613.o gspca_tv8532.o \
-       gspca_vc032x.o gspca_zc3xx.o
+obj-$(CONFIG_USB_GSPCA)                += gspca_main.o
+obj-$(CONFIG_USB_GSPCA_CONEX)  += gspca_conex.o
+obj-$(CONFIG_USB_GSPCA_ETOMS)  += gspca_etoms.o
+obj-$(CONFIG_USB_GSPCA_FINEPIX)        += gspca_finepix.o
+obj-$(CONFIG_USB_GSPCA_MARS)   += gspca_mars.o
+obj-$(CONFIG_USB_GSPCA_OV519)  += gspca_ov519.o
+obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o
+obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o
+obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o
+obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o
+obj-$(CONFIG_USB_GSPCA_SPCA500) += gspca_spca500.o
+obj-$(CONFIG_USB_GSPCA_SPCA501) += gspca_spca501.o
+obj-$(CONFIG_USB_GSPCA_SPCA505) += gspca_spca505.o
+obj-$(CONFIG_USB_GSPCA_SPCA506) += gspca_spca506.o
+obj-$(CONFIG_USB_GSPCA_SPCA508) += gspca_spca508.o
+obj-$(CONFIG_USB_GSPCA_SPCA561) += gspca_spca561.o
+obj-$(CONFIG_USB_GSPCA_SUNPLUS) += gspca_sunplus.o
+obj-$(CONFIG_USB_GSPCA_STK014) += gspca_stk014.o
+obj-$(CONFIG_USB_GSPCA_T613)   += gspca_t613.o
+obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o
+obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o
+obj-$(CONFIG_USB_GSPCA_ZC3XX)  += gspca_zc3xx.o
+
+gspca_main-objs                        := gspca.o
+gspca_conex-objs               := conex.o
+gspca_etoms-objs               := etoms.o
+gspca_finepix-objs             := finepix.o
+gspca_mars-objs                        := mars.o
+gspca_ov519-objs               := ov519.o
+gspca_pac207-objs              := pac207.o
+gspca_pac7311-objs             := pac7311.o
+gspca_sonixb-objs              := sonixb.o
+gspca_sonixj-objs              := sonixj.o
+gspca_spca500-objs             := spca500.o
+gspca_spca501-objs             := spca501.o
+gspca_spca505-objs             := spca505.o
+gspca_spca506-objs             := spca506.o
+gspca_spca508-objs             := spca508.o
+gspca_spca561-objs             := spca561.o
+gspca_stk014-objs              := stk014.o
+gspca_sunplus-objs             := sunplus.o
+gspca_t613-objs                        := t613.o
+gspca_tv8532-objs              := tv8532.o
+gspca_vc032x-objs              := vc032x.o
+gspca_zc3xx-objs               := zc3xx.o
+
+obj-$(CONFIG_USB_M5602)                += m5602/
 
-gspca_main-objs := gspca.o
-gspca_conex-objs := conex.o
-gspca_etoms-objs := etoms.o
-gspca_mars-objs := mars.o
-gspca_ov519-objs := ov519.o
-gspca_pac207-objs := pac207.o
-gspca_pac7311-objs := pac7311.o
-gspca_sonixb-objs := sonixb.o
-gspca_sonixj-objs := sonixj.o
-gspca_spca500-objs := spca500.o
-gspca_spca501-objs := spca501.o
-gspca_spca505-objs := spca505.o
-gspca_spca506-objs := spca506.o
-gspca_spca508-objs := spca508.o
-gspca_spca561-objs := spca561.o
-gspca_stk014-objs := stk014.o
-gspca_sunplus-objs := sunplus.o
-gspca_t613-objs := t613.o
-gspca_tv8532-objs := tv8532.o
-gspca_vc032x-objs := vc032x.o
-gspca_zc3xx-objs := zc3xx.o
index 4d9f4cc255a9540fe13e1fb36806f36cd7af6f7e..a9d51ba7c57ce7f79f736f3e1cf462afeea75ac3 100644 (file)
@@ -837,12 +837,13 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        cx11646_initsize(gspca_dev);
        cx11646_fw(gspca_dev);
        cx_sensor(gspca_dev);
        cx11646_jpeg(gspca_dev);
+       return 0;
 }
 
 static void sd_stop0(struct gspca_dev *gspca_dev)
index 4ff0e386914baf87d37482f0abdb7611c66720a2..3be30b420a26fea30eb09674c82798152f0519b2 100644 (file)
@@ -691,7 +691,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -704,6 +704,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
        reg_w_val(gspca_dev, ET_RESET_ALL, 0x08);
        et_video(gspca_dev, 1);         /* video on */
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
diff --git a/drivers/media/video/gspca/finepix.c b/drivers/media/video/gspca/finepix.c
new file mode 100644 (file)
index 0000000..65d3cbf
--- /dev/null
@@ -0,0 +1,466 @@
+/*
+ * Fujifilm Finepix subdriver
+ *
+ * Copyright (C) 2008 Frank Zago
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#define MODULE_NAME "finepix"
+
+#include "gspca.h"
+
+MODULE_AUTHOR("Frank Zago <frank@zago.net>");
+MODULE_DESCRIPTION("Fujifilm FinePix USB V4L2 driver");
+MODULE_LICENSE("GPL");
+
+/* Default timeout, in ms */
+#define FPIX_TIMEOUT (HZ / 10)
+
+/* Maximum transfer size to use. The windows driver reads by chunks of
+ * 0x2000 bytes, so do the same. Note: reading more seems to work
+ * too. */
+#define FPIX_MAX_TRANSFER 0x2000
+
+/* Structure to hold all of our device specific stuff */
+struct usb_fpix {
+       struct gspca_dev gspca_dev;     /* !! must be the first item */
+
+       /*
+        * USB stuff
+        */
+       struct usb_ctrlrequest ctrlreq;
+       struct urb *control_urb;
+       struct timer_list bulk_timer;
+
+       enum {
+               FPIX_NOP,       /* inactive, else streaming */
+               FPIX_RESET,     /* must reset */
+               FPIX_REQ_FRAME, /* requesting a frame */
+               FPIX_READ_FRAME,        /* reading frame */
+       } state;
+
+       /*
+        * Driver stuff
+        */
+       struct delayed_work wqe;
+       struct completion can_close;
+       int streaming;
+};
+
+/* Delay after which claim the next frame. If the delay is too small,
+ * the camera will return old frames. On the 4800Z, 20ms is bad, 25ms
+ * will fail every 4 or 5 frames, but 30ms is perfect. */
+#define NEXT_FRAME_DELAY  (((HZ * 30) + 999) / 1000)
+
+#define dev_new_state(new_state) {                             \
+               PDEBUG(D_STREAM, "new state from %d to %d at %s:%d",    \
+                       dev->state, new_state, __func__, __LINE__);     \
+               dev->state = new_state;                                 \
+}
+
+/* These cameras only support 320x200. */
+static struct v4l2_pix_format fpix_mode[1] = {
+       { 320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE,
+               .bytesperline = 320,
+               .sizeimage = 320 * 240 * 3 / 8 + 590,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 0}
+};
+
+/* Reads part of a frame */
+static void read_frame_part(struct usb_fpix *dev)
+{
+       int ret;
+
+       PDEBUG(D_STREAM, "read_frame_part");
+
+       /* Reads part of a frame */
+       ret = usb_submit_urb(dev->gspca_dev.urb[0], GFP_ATOMIC);
+       if (ret) {
+               dev_new_state(FPIX_RESET);
+               schedule_delayed_work(&dev->wqe, 1);
+               PDEBUG(D_STREAM, "usb_submit_urb failed with %d",
+                       ret);
+       } else {
+               /* Sometimes we never get a callback, so use a timer.
+                * Is this masking a bug somewhere else? */
+               dev->bulk_timer.expires = jiffies + msecs_to_jiffies(150);
+               add_timer(&dev->bulk_timer);
+       }
+}
+
+/* Callback for URBs. */
+static void urb_callback(struct urb *urb)
+{
+       struct gspca_dev *gspca_dev = urb->context;
+       struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
+
+       PDEBUG(D_PACK,
+               "enter urb_callback - status=%d, length=%d",
+               urb->status, urb->actual_length);
+
+       if (dev->state == FPIX_READ_FRAME)
+               del_timer(&dev->bulk_timer);
+
+       if (urb->status != 0) {
+               /* We kill a stuck urb every 50 frames on average, so don't
+                * display a log message for that. */
+               if (urb->status != -ECONNRESET)
+                       PDEBUG(D_STREAM, "bad URB status %d", urb->status);
+               dev_new_state(FPIX_RESET);
+               schedule_delayed_work(&dev->wqe, 1);
+       }
+
+       switch (dev->state) {
+       case FPIX_REQ_FRAME:
+               dev_new_state(FPIX_READ_FRAME);
+               read_frame_part(dev);
+               break;
+
+       case FPIX_READ_FRAME: {
+               unsigned char *data = urb->transfer_buffer;
+               struct gspca_frame *frame;
+
+               frame = gspca_get_i_frame(&dev->gspca_dev);
+               if (frame == NULL)
+                       gspca_dev->last_packet_type = DISCARD_PACKET;
+               if (urb->actual_length < FPIX_MAX_TRANSFER ||
+                       (data[urb->actual_length-2] == 0xff &&
+                               data[urb->actual_length-1] == 0xd9)) {
+
+                       /* If the result is less than what was asked
+                        * for, then it's the end of the
+                        * frame. Sometime the jpeg is not complete,
+                        * but there's nothing we can do. We also end
+                        * here if the the jpeg ends right at the end
+                        * of the frame. */
+                       if (frame)
+                               gspca_frame_add(gspca_dev, LAST_PACKET,
+                                               frame,
+                                               data, urb->actual_length);
+                       dev_new_state(FPIX_REQ_FRAME);
+                       schedule_delayed_work(&dev->wqe, NEXT_FRAME_DELAY);
+               } else {
+
+                       /* got a partial image */
+                       if (frame)
+                               gspca_frame_add(gspca_dev,
+                                               gspca_dev->last_packet_type
+                                                               == LAST_PACKET
+                                               ? FIRST_PACKET : INTER_PACKET,
+                                               frame,
+                                       data, urb->actual_length);
+                       read_frame_part(dev);
+               }
+               break;
+           }
+
+       case FPIX_NOP:
+       case FPIX_RESET:
+               PDEBUG(D_STREAM, "invalid state %d", dev->state);
+               break;
+       }
+}
+
+/* Request a new frame */
+static void request_frame(struct usb_fpix *dev)
+{
+       int ret;
+       struct gspca_dev *gspca_dev = &dev->gspca_dev;
+
+       /* Setup command packet */
+       memset(gspca_dev->usb_buf, 0, 12);
+       gspca_dev->usb_buf[0] = 0xd3;
+       gspca_dev->usb_buf[7] = 0x01;
+
+       /* Request a frame */
+       dev->ctrlreq.bRequestType =
+               USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE;
+       dev->ctrlreq.bRequest = USB_REQ_GET_STATUS;
+       dev->ctrlreq.wValue = 0;
+       dev->ctrlreq.wIndex = 0;
+       dev->ctrlreq.wLength = cpu_to_le16(12);
+
+       usb_fill_control_urb(dev->control_urb,
+                            gspca_dev->dev,
+                            usb_sndctrlpipe(gspca_dev->dev, 0),
+                            (unsigned char *) &dev->ctrlreq,
+                            gspca_dev->usb_buf,
+                            12, urb_callback, gspca_dev);
+
+       ret = usb_submit_urb(dev->control_urb, GFP_ATOMIC);
+       if (ret) {
+               dev_new_state(FPIX_RESET);
+               schedule_delayed_work(&dev->wqe, 1);
+               PDEBUG(D_STREAM, "usb_submit_urb failed with %d", ret);
+       }
+}
+
+/*--------------------------------------------------------------------------*/
+
+/* State machine. */
+static void fpix_sm(struct work_struct *work)
+{
+       struct usb_fpix *dev = container_of(work, struct usb_fpix, wqe.work);
+
+       PDEBUG(D_STREAM, "fpix_sm state %d", dev->state);
+
+       /* verify that the device wasn't unplugged */
+       if (!dev->gspca_dev.present) {
+               PDEBUG(D_STREAM, "device is gone");
+               dev_new_state(FPIX_NOP);
+               complete(&dev->can_close);
+               return;
+       }
+
+       if (!dev->streaming) {
+               PDEBUG(D_STREAM, "stopping state machine");
+               dev_new_state(FPIX_NOP);
+               complete(&dev->can_close);
+               return;
+       }
+
+       switch (dev->state) {
+       case FPIX_RESET:
+               dev_new_state(FPIX_REQ_FRAME);
+               schedule_delayed_work(&dev->wqe, HZ / 10);
+               break;
+
+       case FPIX_REQ_FRAME:
+               /* get an image */
+               request_frame(dev);
+               break;
+
+       case FPIX_NOP:
+       case FPIX_READ_FRAME:
+               PDEBUG(D_STREAM, "invalid state %d", dev->state);
+               break;
+       }
+}
+
+/* this function is called at probe time */
+static int sd_config(struct gspca_dev *gspca_dev,
+               const struct usb_device_id *id)
+{
+       struct cam *cam = &gspca_dev->cam;
+
+       cam->cam_mode = fpix_mode;
+       cam->nmodes = 1;
+       cam->epaddr = 0x01;     /* todo: correct for all cams? */
+       cam->bulk_size = FPIX_MAX_TRANSFER;
+
+/*     gspca_dev->nbalt = 1;    * use bulk transfer */
+       return 0;
+}
+
+/* Stop streaming and free the ressources allocated by sd_start. */
+static void sd_stopN(struct gspca_dev *gspca_dev)
+{
+       struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
+
+       dev->streaming = 0;
+
+       /* Stop the state machine */
+       if (dev->state != FPIX_NOP)
+               wait_for_completion(&dev->can_close);
+
+       usb_free_urb(dev->control_urb);
+       dev->control_urb = NULL;
+}
+
+/* Kill an URB that hasn't completed. */
+static void timeout_kill(unsigned long data)
+{
+       struct urb *urb = (struct urb *) data;
+
+       usb_unlink_urb(urb);
+}
+
+/* this function is called at probe and resume time */
+static int sd_init(struct gspca_dev *gspca_dev)
+{
+       struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
+
+       INIT_DELAYED_WORK(&dev->wqe, fpix_sm);
+
+       init_timer(&dev->bulk_timer);
+       dev->bulk_timer.function = timeout_kill;
+
+       return 0;
+}
+
+static int sd_start(struct gspca_dev *gspca_dev)
+{
+       struct usb_fpix *dev = (struct usb_fpix *) gspca_dev;
+       int ret;
+       int size_ret;
+
+       /* Reset bulk in endpoint */
+       usb_clear_halt(gspca_dev->dev, gspca_dev->cam.epaddr);
+
+       /* Init the device */
+       memset(gspca_dev->usb_buf, 0, 12);
+       gspca_dev->usb_buf[0] = 0xc6;
+       gspca_dev->usb_buf[8] = 0x20;
+
+       ret = usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       USB_REQ_GET_STATUS,
+                       USB_DIR_OUT | USB_TYPE_CLASS |
+                       USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
+                       12, FPIX_TIMEOUT);
+
+       if (ret != 12) {
+               PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
+               ret = -EIO;
+               goto error;
+       }
+
+       /* Read the result of the command. Ignore the result, for it
+        * varies with the device. */
+       ret = usb_bulk_msg(gspca_dev->dev,
+                       usb_rcvbulkpipe(gspca_dev->dev,
+                                       gspca_dev->cam.epaddr),
+                       gspca_dev->usb_buf, FPIX_MAX_TRANSFER, &size_ret,
+                       FPIX_TIMEOUT);
+       if (ret != 0) {
+               PDEBUG(D_STREAM, "usb_bulk_msg failed (%d)", ret);
+               ret = -EIO;
+               goto error;
+       }
+
+       /* Request a frame, but don't read it */
+       memset(gspca_dev->usb_buf, 0, 12);
+       gspca_dev->usb_buf[0] = 0xd3;
+       gspca_dev->usb_buf[7] = 0x01;
+
+       ret = usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       USB_REQ_GET_STATUS,
+                       USB_DIR_OUT | USB_TYPE_CLASS |
+                       USB_RECIP_INTERFACE, 0, 0, gspca_dev->usb_buf,
+                       12, FPIX_TIMEOUT);
+       if (ret != 12) {
+               PDEBUG(D_STREAM, "usb_control_msg failed (%d)", ret);
+               ret = -EIO;
+               goto error;
+       }
+
+       /* Again, reset bulk in endpoint */
+       usb_clear_halt(gspca_dev->dev, gspca_dev->cam.epaddr);
+
+       /* Allocate a control URB */
+       dev->control_urb = usb_alloc_urb(0, GFP_KERNEL);
+       if (!dev->control_urb) {
+               PDEBUG(D_STREAM, "No free urbs available");
+               ret = -EIO;
+               goto error;
+       }
+
+       /* Various initializations. */
+       init_completion(&dev->can_close);
+       dev->bulk_timer.data = (unsigned long)dev->gspca_dev.urb[0];
+       dev->gspca_dev.urb[0]->complete = urb_callback;
+       dev->streaming = 1;
+
+       /* Schedule a frame request. */
+       dev_new_state(FPIX_REQ_FRAME);
+       schedule_delayed_work(&dev->wqe, 1);
+
+       return 0;
+
+error:
+       /* Free the ressources */
+       sd_stopN(gspca_dev);
+       return ret;
+}
+
+/* Table of supported USB devices */
+static const __devinitdata struct usb_device_id device_table[] = {
+       {USB_DEVICE(0x04cb, 0x0104)},
+       {USB_DEVICE(0x04cb, 0x0109)},
+       {USB_DEVICE(0x04cb, 0x010b)},
+       {USB_DEVICE(0x04cb, 0x010f)},
+       {USB_DEVICE(0x04cb, 0x0111)},
+       {USB_DEVICE(0x04cb, 0x0113)},
+       {USB_DEVICE(0x04cb, 0x0115)},
+       {USB_DEVICE(0x04cb, 0x0117)},
+       {USB_DEVICE(0x04cb, 0x0119)},
+       {USB_DEVICE(0x04cb, 0x011b)},
+       {USB_DEVICE(0x04cb, 0x011d)},
+       {USB_DEVICE(0x04cb, 0x0121)},
+       {USB_DEVICE(0x04cb, 0x0123)},
+       {USB_DEVICE(0x04cb, 0x0125)},
+       {USB_DEVICE(0x04cb, 0x0127)},
+       {USB_DEVICE(0x04cb, 0x0129)},
+       {USB_DEVICE(0x04cb, 0x012b)},
+       {USB_DEVICE(0x04cb, 0x012d)},
+       {USB_DEVICE(0x04cb, 0x012f)},
+       {USB_DEVICE(0x04cb, 0x0131)},
+       {USB_DEVICE(0x04cb, 0x013b)},
+       {USB_DEVICE(0x04cb, 0x013d)},
+       {USB_DEVICE(0x04cb, 0x013f)},
+       {}
+};
+
+MODULE_DEVICE_TABLE(usb, device_table);
+
+/* sub-driver description */
+static const struct sd_desc sd_desc = {
+       .name = MODULE_NAME,
+       .config = sd_config,
+       .init = sd_init,
+       .start = sd_start,
+       .stopN = sd_stopN,
+};
+
+/* -- device connect -- */
+static int sd_probe(struct usb_interface *intf,
+               const struct usb_device_id *id)
+{
+       return gspca_dev_probe(intf, id,
+                       &sd_desc,
+                       sizeof(struct usb_fpix),
+                       THIS_MODULE);
+}
+
+static struct usb_driver sd_driver = {
+       .name = MODULE_NAME,
+       .id_table = device_table,
+       .probe = sd_probe,
+       .disconnect = gspca_disconnect,
+#ifdef CONFIG_PM
+       .suspend = gspca_suspend,
+       .resume = gspca_resume,
+#endif
+};
+
+/* -- module insert / remove -- */
+static int __init sd_mod_init(void)
+{
+       if (usb_register(&sd_driver) < 0)
+               return -1;
+       PDEBUG(D_PROBE, "registered");
+       return 0;
+}
+static void __exit sd_mod_exit(void)
+{
+       usb_deregister(&sd_driver);
+       PDEBUG(D_PROBE, "deregistered");
+}
+
+module_init(sd_mod_init);
+module_exit(sd_mod_exit);
index ac95c55887df4b38eb1cd8c4478538c53e042aef..c21af312ee7c496782a792fd1f29a33946a6277c 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/string.h>
 #include <linux/pagemap.h>
 #include <linux/io.h>
+#include <linux/kref.h>
 #include <asm/page.h>
 #include <linux/uaccess.h>
 #include <linux/jiffies.h>
@@ -43,7 +44,7 @@ MODULE_AUTHOR("Jean-Francois Moine <http://moinejf.free.fr>");
 MODULE_DESCRIPTION("GSPCA USB Camera Driver");
 MODULE_LICENSE("GPL");
 
-#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 2, 0)
+#define DRIVER_VERSION_NUMBER  KERNEL_VERSION(2, 3, 0)
 
 static int video_nr = -1;
 
@@ -102,6 +103,22 @@ static struct vm_operations_struct gspca_vm_ops = {
        .close          = gspca_vm_close,
 };
 
+/* get the current input frame buffer */
+struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev)
+{
+       struct gspca_frame *frame;
+       int i;
+
+       i = gspca_dev->fr_i;
+       i = gspca_dev->fr_queue[i];
+       frame = &gspca_dev->frame[i];
+       if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
+                               != V4L2_BUF_FLAG_QUEUED)
+               return NULL;
+       return frame;
+}
+EXPORT_SYMBOL(gspca_get_i_frame);
+
 /*
  * fill a video frame from an URB and resubmit
  */
@@ -110,7 +127,7 @@ static void fill_frame(struct gspca_dev *gspca_dev,
 {
        struct gspca_frame *frame;
        __u8 *data;             /* address of data in the iso message */
-       int i, j, len, st;
+       int i, len, st;
        cam_pkt_op pkt_scan;
 
        if (urb->status != 0) {
@@ -124,11 +141,8 @@ static void fill_frame(struct gspca_dev *gspca_dev,
        for (i = 0; i < urb->number_of_packets; i++) {
 
                /* check the availability of the frame buffer */
-               j = gspca_dev->fr_i;
-               j = gspca_dev->fr_queue[j];
-               frame = &gspca_dev->frame[j];
-               if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS)
-                                       != V4L2_BUF_FLAG_QUEUED) {
+               frame = gspca_get_i_frame(gspca_dev);
+               if (!frame) {
                        gspca_dev->last_packet_type = DISCARD_PACKET;
                        break;
                }
@@ -177,6 +191,39 @@ static void isoc_irq(struct urb *urb
        fill_frame(gspca_dev, urb);
 }
 
+/*
+ * bulk message interrupt from the USB device
+ */
+static void bulk_irq(struct urb *urb
+)
+{
+       struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context;
+       struct gspca_frame *frame;
+
+       PDEBUG(D_PACK, "bulk irq");
+       if (!gspca_dev->streaming)
+               return;
+       if (urb->status != 0 && urb->status != -ECONNRESET) {
+#ifdef CONFIG_PM
+               if (!gspca_dev->frozen)
+#endif
+                       PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status);
+               return;         /* disconnection ? */
+       }
+
+       /* check the availability of the frame buffer */
+       frame = gspca_get_i_frame(gspca_dev);
+       if (!frame) {
+               gspca_dev->last_packet_type = DISCARD_PACKET;
+       } else {
+               PDEBUG(D_PACK, "packet l:%d", urb->actual_length);
+               gspca_dev->sd_desc->pkt_scan(gspca_dev,
+                                       frame,
+                                       urb->transfer_buffer,
+                                       urb->actual_length);
+       }
+}
+
 /*
  * add data to the current frame
  *
@@ -190,7 +237,7 @@ static void isoc_irq(struct urb *urb
  * On LAST_PACKET, a new frame is returned.
  */
 struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
-                                   int packet_type,
+                                   enum gspca_packet_type packet_type,
                                    struct gspca_frame *frame,
                                    const __u8 *data,
                                    int len)
@@ -232,7 +279,7 @@ struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
        }
        gspca_dev->last_packet_type = packet_type;
 
-       /* if last packet, wake the application and advance in the queue */
+       /* if last packet, wake up the application and advance in the queue */
        if (packet_type == LAST_PACKET) {
                frame->v4l2_buf.bytesused = frame->data_end - frame->data;
                frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_QUEUED;
@@ -270,7 +317,6 @@ static void *rvmalloc(unsigned long size)
        void *mem;
        unsigned long adr;
 
-/*     size = PAGE_ALIGN(size);        (already done) */
        mem = vmalloc_32(size);
        if (mem != NULL) {
                adr = (unsigned long) mem;
@@ -374,10 +420,11 @@ static void destroy_urbs(struct gspca_dev *gspca_dev)
 }
 
 /*
- * search an input isochronous endpoint in an alternate setting
+ * look for an input transfer endpoint in an alternate setting
  */
-static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
-                                         __u8 epaddr)
+static struct usb_host_endpoint *alt_xfer(struct usb_host_interface *alt,
+                                         __u8 epaddr,
+                                         __u8 xfer)
 {
        struct usb_host_endpoint *ep;
        int i, attr;
@@ -388,7 +435,7 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
                if (ep->desc.bEndpointAddress == epaddr) {
                        attr = ep->desc.bmAttributes
                                                & USB_ENDPOINT_XFERTYPE_MASK;
-                       if (attr == USB_ENDPOINT_XFER_ISOC)
+                       if (attr == xfer)
                                return ep;
                        break;
                }
@@ -397,14 +444,14 @@ static struct usb_host_endpoint *alt_isoc(struct usb_host_interface *alt,
 }
 
 /*
- * search an input isochronous endpoint
+ * look for an input (isoc or bulk) endpoint
  *
  * The endpoint is defined by the subdriver.
  * Use only the first isoc (some Zoran - 0x0572:0x0001 - have two such ep).
  * This routine may be called many times when the bandwidth is too small
  * (the bandwidth is checked on urb submit).
  */
-static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
+static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev)
 {
        struct usb_interface *intf;
        struct usb_host_endpoint *ep;
@@ -413,28 +460,41 @@ static struct usb_host_endpoint *get_isoc_ep(struct gspca_dev *gspca_dev)
        intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface);
        ep = NULL;
        i = gspca_dev->alt;                     /* previous alt setting */
+
+       /* try isoc */
        while (--i > 0) {                       /* alt 0 is unusable */
-               ep = alt_isoc(&intf->altsetting[i], gspca_dev->cam.epaddr);
+               ep = alt_xfer(&intf->altsetting[i],
+                               gspca_dev->cam.epaddr,
+                               USB_ENDPOINT_XFER_ISOC);
                if (ep)
                        break;
        }
+
+       /* if no isoc, try bulk */
        if (ep == NULL) {
-               err("no ISOC endpoint found");
-               return NULL;
+               ep = alt_xfer(&intf->altsetting[0],
+                               gspca_dev->cam.epaddr,
+                               USB_ENDPOINT_XFER_BULK);
+               if (ep == NULL) {
+                       err("no transfer endpoint found");
+                       return NULL;
+               }
        }
-       PDEBUG(D_STREAM, "use ISOC alt %d ep 0x%02x",
+       PDEBUG(D_STREAM, "use alt %d ep 0x%02x",
                        i, ep->desc.bEndpointAddress);
-       ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
-       if (ret < 0) {
-               err("set interface err %d", ret);
-               return NULL;
+       if (i > 0) {
+               ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i);
+               if (ret < 0) {
+                       err("set interface err %d", ret);
+                       return NULL;
+               }
        }
        gspca_dev->alt = i;             /* memorize the current alt setting */
        return ep;
 }
 
 /*
- * create the isochronous URBs
+ * create the URBs for image transfer
  */
 static int create_urbs(struct gspca_dev *gspca_dev,
                        struct usb_host_endpoint *ep)
@@ -445,15 +505,27 @@ static int create_urbs(struct gspca_dev *gspca_dev,
        /* calculate the packet size and the number of packets */
        psize = le16_to_cpu(ep->desc.wMaxPacketSize);
 
-       /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */
-       psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
-       npkt = ISO_MAX_SIZE / psize;
-       if (npkt > ISO_MAX_PKT)
-               npkt = ISO_MAX_PKT;
-       bsize = psize * npkt;
-       PDEBUG(D_STREAM,
-               "isoc %d pkts size %d (bsize:%d)", npkt, psize, bsize);
-       nurbs = DEF_NURBS;
+       if (gspca_dev->alt != 0) {              /* isoc */
+
+               /* See paragraph 5.9 / table 5-11 of the usb 2.0 spec. */
+               psize = (psize & 0x07ff) * (1 + ((psize >> 11) & 3));
+               npkt = ISO_MAX_SIZE / psize;
+               if (npkt > ISO_MAX_PKT)
+                       npkt = ISO_MAX_PKT;
+               bsize = psize * npkt;
+               PDEBUG(D_STREAM,
+                       "isoc %d pkts size %d = bsize:%d",
+                       npkt, psize, bsize);
+               nurbs = DEF_NURBS;
+       } else {                                /* bulk */
+               npkt = 0;
+               bsize = gspca_dev->cam. bulk_size;
+               if (bsize == 0)
+                       bsize = psize;
+               PDEBUG(D_STREAM, "bulk bsize:%d", bsize);
+               nurbs = 1;
+       }
+
        gspca_dev->nurbs = nurbs;
        for (n = 0; n < nurbs; n++) {
                urb = usb_alloc_urb(npkt, GFP_KERNEL);
@@ -476,17 +548,24 @@ static int create_urbs(struct gspca_dev *gspca_dev,
                gspca_dev->urb[n] = urb;
                urb->dev = gspca_dev->dev;
                urb->context = gspca_dev;
-               urb->pipe = usb_rcvisocpipe(gspca_dev->dev,
-                                           ep->desc.bEndpointAddress);
-               urb->transfer_flags = URB_ISO_ASAP
-                                       | URB_NO_TRANSFER_DMA_MAP;
-               urb->interval = ep->desc.bInterval;
-               urb->complete = isoc_irq;
-               urb->number_of_packets = npkt;
                urb->transfer_buffer_length = bsize;
-               for (i = 0; i < npkt; i++) {
-                       urb->iso_frame_desc[i].length = psize;
-                       urb->iso_frame_desc[i].offset = psize * i;
+               if (npkt != 0) {                /* ISOC */
+                       urb->pipe = usb_rcvisocpipe(gspca_dev->dev,
+                                                   ep->desc.bEndpointAddress);
+                       urb->transfer_flags = URB_ISO_ASAP
+                                       | URB_NO_TRANSFER_DMA_MAP;
+                       urb->interval = ep->desc.bInterval;
+                       urb->complete = isoc_irq;
+                       urb->number_of_packets = npkt;
+                       for (i = 0; i < npkt; i++) {
+                               urb->iso_frame_desc[i].length = psize;
+                               urb->iso_frame_desc[i].offset = psize * i;
+                       }
+               } else {                /* bulk */
+                       urb->pipe = usb_rcvbulkpipe(gspca_dev->dev,
+                                               ep->desc.bEndpointAddress),
+                       urb->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
+                       urb->complete = bulk_irq;
                }
        }
        return 0;
@@ -508,7 +587,7 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
        gspca_dev->alt = gspca_dev->nbalt;
        for (;;) {
                PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt);
-               ep = get_isoc_ep(gspca_dev);
+               ep = get_ep(gspca_dev);
                if (ep == NULL) {
                        ret = -EIO;
                        goto out;
@@ -518,10 +597,18 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev)
                        goto out;
 
                /* start the cam */
-               gspca_dev->sd_desc->start(gspca_dev);
+               ret = gspca_dev->sd_desc->start(gspca_dev);
+               if (ret < 0) {
+                       destroy_urbs(gspca_dev);
+                       goto out;
+               }
                gspca_dev->streaming = 1;
                atomic_set(&gspca_dev->nevent, 0);
 
+               /* bulk transfers are started by the subdriver */
+               if (gspca_dev->alt == 0)
+                       break;
+
                /* submit the URBs */
                for (n = 0; n < gspca_dev->nurbs; n++) {
                        ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL);
@@ -553,7 +640,7 @@ static int gspca_set_alt0(struct gspca_dev *gspca_dev)
        return ret;
 }
 
-/* Note both the queue and the usb lock should be hold when calling this */
+/* Note: both the queue and the usb locks should be held when calling this */
 static void gspca_stream_off(struct gspca_dev *gspca_dev)
 {
        gspca_dev->streaming = 0;
@@ -759,6 +846,16 @@ out:
        return ret;
 }
 
+static void gspca_delete(struct kref *kref)
+{
+       struct gspca_dev *gspca_dev = container_of(kref, struct gspca_dev, kref);
+
+       PDEBUG(D_STREAM, "device deleted");
+
+       kfree(gspca_dev->usb_buf);
+       kfree(gspca_dev);
+}
+
 static int dev_open(struct inode *inode, struct file *file)
 {
        struct gspca_dev *gspca_dev;
@@ -778,13 +875,19 @@ static int dev_open(struct inode *inode, struct file *file)
                goto out;
        }
        gspca_dev->users++;
+
+       /* one more user */
+       kref_get(&gspca_dev->kref);
+
        file->private_data = gspca_dev;
 #ifdef GSPCA_DEBUG
        /* activate the v4l2 debug */
        if (gspca_debug & D_V4L2)
-               gspca_dev->vdev.debug |= 3;
+               gspca_dev->vdev.debug |= V4L2_DEBUG_IOCTL
+                                       | V4L2_DEBUG_IOCTL_ARG;
        else
-               gspca_dev->vdev.debug &= ~3;
+               gspca_dev->vdev.debug &= ~(V4L2_DEBUG_IOCTL
+                                       | V4L2_DEBUG_IOCTL_ARG);
 #endif
        ret = 0;
 out:
@@ -818,7 +921,11 @@ static int dev_close(struct inode *inode, struct file *file)
        }
        file->private_data = NULL;
        mutex_unlock(&gspca_dev->queue_lock);
+
        PDEBUG(D_STREAM, "close done");
+
+       kref_put(&gspca_dev->kref, gspca_delete);
+
        return 0;
 }
 
@@ -829,7 +936,6 @@ static int vidioc_querycap(struct file *file, void  *priv,
 
        memset(cap, 0, sizeof *cap);
        strncpy(cap->driver, gspca_dev->sd_desc->name, sizeof cap->driver);
-/*     strncpy(cap->card, gspca_dev->cam.dev_name, sizeof cap->card); */
        if (gspca_dev->dev->product != NULL) {
                strncpy(cap->card, gspca_dev->dev->product,
                        sizeof cap->card);
@@ -1463,7 +1569,6 @@ static int vidioc_qbuf(struct file *file, void *priv,
        }
 
        frame->v4l2_buf.flags |= V4L2_BUF_FLAG_QUEUED;
-/*     frame->v4l2_buf.flags &= ~V4L2_BUF_FLAG_DONE; */
 
        if (frame->v4l2_buf.memory == V4L2_MEMORY_USERPTR) {
                frame->v4l2_buf.m.userptr = v4l2_buf->m.userptr;
@@ -1610,7 +1715,7 @@ static ssize_t dev_read(struct file *file, char __user *data,
                }
 
                /* if the process slept for more than 1 second,
-                * get anewer frame */
+                * get a newer frame */
                frame = &gspca_dev->frame[v4l2_buf.index];
                if (--n < 0)
                        break;                  /* avoid infinite loop */
@@ -1728,21 +1833,21 @@ int gspca_dev_probe(struct usb_interface *intf,
        if (dev_size < sizeof *gspca_dev)
                dev_size = sizeof *gspca_dev;
        gspca_dev = kzalloc(dev_size, GFP_KERNEL);
-       if (gspca_dev == NULL) {
+       if (!gspca_dev) {
                err("couldn't kzalloc gspca struct");
-               return -EIO;
+               return -ENOMEM;
        }
+       kref_init(&gspca_dev->kref);
        gspca_dev->usb_buf = kmalloc(USB_BUF_SZ, GFP_KERNEL);
        if (!gspca_dev->usb_buf) {
                err("out of memory");
-               ret = -EIO;
+               ret = -ENOMEM;
                goto out;
        }
        gspca_dev->dev = dev;
        gspca_dev->iface = interface->bInterfaceNumber;
        gspca_dev->nbalt = intf->num_altsetting;
        gspca_dev->sd_desc = sd_desc;
-/*     gspca_dev->users = 0;                   (done by kzalloc) */
        gspca_dev->nbufread = 2;
 
        /* configure the subdriver and initialize the USB device */
@@ -1781,8 +1886,7 @@ int gspca_dev_probe(struct usb_interface *intf,
        PDEBUG(D_PROBE, "probe ok");
        return 0;
 out:
-       kfree(gspca_dev->usb_buf);
-       kfree(gspca_dev);
+       kref_put(&gspca_dev->kref, gspca_delete);
        return ret;
 }
 EXPORT_SYMBOL(gspca_dev_probe);
@@ -1797,25 +1901,16 @@ void gspca_disconnect(struct usb_interface *intf)
 {
        struct gspca_dev *gspca_dev = usb_get_intfdata(intf);
 
-       if (!gspca_dev)
-               return;
-       gspca_dev->present = 0;
-       mutex_lock(&gspca_dev->queue_lock);
-       mutex_lock(&gspca_dev->usb_lock);
-       gspca_dev->streaming = 0;
-       destroy_urbs(gspca_dev);
-       mutex_unlock(&gspca_dev->usb_lock);
-       mutex_unlock(&gspca_dev->queue_lock);
-       while (gspca_dev->users != 0) {         /* wait until fully closed */
-               atomic_inc(&gspca_dev->nevent);
-               wake_up_interruptible(&gspca_dev->wq);  /* wake processes */
-               schedule();
-       }
+       usb_set_intfdata(intf, NULL);
+
 /* We don't want people trying to open up the device */
        video_unregister_device(&gspca_dev->vdev);
-/* Free the memory */
-       kfree(gspca_dev->usb_buf);
-       kfree(gspca_dev);
+
+       gspca_dev->present = 0;
+       gspca_dev->streaming = 0;
+
+       kref_put(&gspca_dev->kref, gspca_delete);
+
        PDEBUG(D_PROBE, "disconnect complete");
 }
 EXPORT_SYMBOL(gspca_disconnect);
index c17625cff9ba2dbf35003ab4220363441fe6585d..4779dd0b06da0145eeee191f4e0e2d3fe198446a 100644 (file)
@@ -49,13 +49,14 @@ extern int gspca_debug;
        } while (0)
 
 #define GSPCA_MAX_FRAMES 16    /* maximum number of video frame buffers */
-/* ISOC transfers */
-#define MAX_NURBS 16           /* max number of URBs */
+/* image transfers */
+#define MAX_NURBS            /* max number of URBs */
 #define ISO_MAX_PKT 32         /* max number of packets in an ISOC transfer */
 #define ISO_MAX_SIZE 0x8000    /* max size of one URB buffer (32 Kb) */
 
 /* device information - set at probe time */
 struct cam {
+       int bulk_size;          /* buffer size when image transfer by bulk */
        struct v4l2_pix_format *cam_mode;       /* size nmodes */
        char nmodes;
        __u8 epaddr;
@@ -93,7 +94,7 @@ struct sd_desc {
 /* mandatory operations */
        cam_cf_op config;       /* called on probe */
        cam_op init;            /* called on probe and resume */
-       cam_v_op start;         /* called on stream on */
+       cam_op start;           /* called on stream on */
        cam_pkt_op pkt_scan;
 /* optional operations */
        cam_v_op stopN;         /* called on stream off - main alt */
@@ -105,10 +106,12 @@ struct sd_desc {
 };
 
 /* packet types when moving from iso buf to frame buf */
-#define DISCARD_PACKET 0
-#define FIRST_PACKET   1
-#define INTER_PACKET   2
-#define LAST_PACKET    3
+enum gspca_packet_type {
+       DISCARD_PACKET,
+       FIRST_PACKET,
+       INTER_PACKET,
+       LAST_PACKET
+};
 
 struct gspca_frame {
        __u8 *data;                     /* frame buffer */
@@ -121,6 +124,7 @@ struct gspca_dev {
        struct video_device vdev;       /* !! must be the first item */
        struct file_operations fops;
        struct usb_device *dev;
+       struct kref kref;
        struct file *capt_file;         /* file doing video capture */
 
        struct cam cam;                         /* device information */
@@ -173,10 +177,11 @@ int gspca_dev_probe(struct usb_interface *intf,
                struct module *module);
 void gspca_disconnect(struct usb_interface *intf);
 struct gspca_frame *gspca_frame_add(struct gspca_dev *gspca_dev,
-                                   int packet_type,
+                                   enum gspca_packet_type packet_type,
                                    struct gspca_frame *frame,
                                    const __u8 *data,
                                    int len);
+struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev);
 #ifdef CONFIG_PM
 int gspca_suspend(struct usb_interface *intf, pm_message_t message);
 int gspca_resume(struct usb_interface *intf);
diff --git a/drivers/media/video/gspca/m5602/Kconfig b/drivers/media/video/gspca/m5602/Kconfig
new file mode 100644 (file)
index 0000000..5a69016
--- /dev/null
@@ -0,0 +1,11 @@
+config USB_M5602
+       tristate "ALi USB m5602 Camera Driver"
+       depends on VIDEO_V4L2 && USB_GSPCA
+       help
+         Say Y here if you want support for cameras based on the
+         ALi m5602 connected to various image sensors.
+
+         See <file:Documentation/video4linux/m5602.txt> for more info.
+
+         To compile this driver as a module, choose M here: the
+         module will be called gspca_m5602.
diff --git a/drivers/media/video/gspca/m5602/Makefile b/drivers/media/video/gspca/m5602/Makefile
new file mode 100644 (file)
index 0000000..226ab4f
--- /dev/null
@@ -0,0 +1,11 @@
+obj-$(CONFIG_USB_M5602) += gspca_m5602.o
+
+gspca_m5602-objs := m5602_core.o \
+                   m5602_ov9650.o \
+                   m5602_mt9m111.o \
+                   m5602_po1030.o \
+                   m5602_s5k83a.o \
+                   m5602_s5k4aa.o
+
+EXTRA_CFLAGS += -Idrivers/media/video/gspca
+
diff --git a/drivers/media/video/gspca/m5602/m5602_bridge.h b/drivers/media/video/gspca/m5602/m5602_bridge.h
new file mode 100644 (file)
index 0000000..c786d7d
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * USB Driver for ALi m5602 based webcams
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_BRIDGE_H_
+#define M5602_BRIDGE_H_
+
+#include "gspca.h"
+
+#define MODULE_NAME "ALi m5602"
+
+/*****************************************************************************/
+
+#undef PDEBUG
+#undef info
+#undef err
+
+#define err(format, arg...) printk(KERN_ERR KBUILD_MODNAME ": " \
+       format "\n" , ## arg)
+#define info(format, arg...) printk(KERN_INFO KBUILD_MODNAME ": " \
+       format "\n" , ## arg)
+
+/* Debug parameters */
+#define DBG_INIT 0x1
+#define DBG_PROBE 0x2
+#define DBG_V4L2 0x4
+#define DBG_TRACE 0x8
+#define DBG_DATA 0x10
+#define DBG_V4L2_CID 0x20
+#define DBG_GSPCA 0x40
+
+#define PDEBUG(level, fmt, args...) \
+       do { \
+               if (m5602_debug & level)     \
+                       info("[%s:%d] " fmt, __func__, __LINE__ , \
+                       ## args); \
+       } while (0)
+
+/*****************************************************************************/
+
+#define M5602_XB_SENSOR_TYPE 0x00
+#define M5602_XB_SENSOR_CTRL 0x01
+#define M5602_XB_LINE_OF_FRAME_H 0x02
+#define M5602_XB_LINE_OF_FRAME_L 0x03
+#define M5602_XB_PIX_OF_LINE_H 0x04
+#define M5602_XB_PIX_OF_LINE_L 0x05
+#define M5602_XB_VSYNC_PARA 0x06
+#define M5602_XB_HSYNC_PARA 0x07
+#define M5602_XB_TEST_MODE_1 0x08
+#define M5602_XB_TEST_MODE_2 0x09
+#define M5602_XB_SIG_INI 0x0a
+#define M5602_XB_DS_PARA 0x0e
+#define M5602_XB_TRIG_PARA 0x0f
+#define M5602_XB_CLK_PD 0x10
+#define M5602_XB_MCU_CLK_CTRL 0x12
+#define M5602_XB_MCU_CLK_DIV 0x13
+#define M5602_XB_SEN_CLK_CTRL 0x14
+#define M5602_XB_SEN_CLK_DIV 0x15
+#define M5602_XB_AUD_CLK_CTRL 0x16
+#define M5602_XB_AUD_CLK_DIV 0x17
+#define M5602_XB_DEVCTR1 0x41
+#define M5602_XB_EPSETR0 0x42
+#define M5602_XB_EPAFCTR 0x47
+#define M5602_XB_EPBFCTR 0x49
+#define M5602_XB_EPEFCTR 0x4f
+#define M5602_XB_TEST_REG 0x53
+#define M5602_XB_ALT2SIZE 0x54
+#define M5602_XB_ALT3SIZE 0x55
+#define M5602_XB_OBSFRAME 0x56
+#define M5602_XB_PWR_CTL 0x59
+#define M5602_XB_ADC_CTRL 0x60
+#define M5602_XB_ADC_DATA 0x61
+#define M5602_XB_MISC_CTRL 0x62
+#define M5602_XB_SNAPSHOT 0x63
+#define M5602_XB_SCRATCH_1 0x64
+#define M5602_XB_SCRATCH_2 0x65
+#define M5602_XB_SCRATCH_3 0x66
+#define M5602_XB_SCRATCH_4 0x67
+#define M5602_XB_I2C_CTRL 0x68
+#define M5602_XB_I2C_CLK_DIV 0x69
+#define M5602_XB_I2C_DEV_ADDR 0x6a
+#define M5602_XB_I2C_REG_ADDR 0x6b
+#define M5602_XB_I2C_DATA 0x6c
+#define M5602_XB_I2C_STATUS 0x6d
+#define M5602_XB_GPIO_DAT_H 0x70
+#define M5602_XB_GPIO_DAT_L 0x71
+#define M5602_XB_GPIO_DIR_H 0x72
+#define M5602_XB_GPIO_DIR_L 0x73
+#define M5602_XB_GPIO_EN_H 0x74
+#define M5602_XB_GPIO_EN_L 0x75
+#define M5602_XB_GPIO_DAT 0x76
+#define M5602_XB_GPIO_DIR 0x77
+#define M5602_XB_MISC_CTL 0x70
+
+#define I2C_BUSY 0x80
+
+/*****************************************************************************/
+
+/* Driver info */
+#define DRIVER_AUTHOR "ALi m5602 Linux Driver Project"
+#define DRIVER_DESC "ALi m5602 webcam driver"
+
+#define M5602_ISOC_ENDPOINT_ADDR 0x81
+#define M5602_INTR_ENDPOINT_ADDR 0x82
+
+#define M5602_MAX_FRAMES       32
+#define M5602_URBS             2
+#define M5602_ISOC_PACKETS     14
+
+#define M5602_URB_TIMEOUT      msecs_to_jiffies(2 * M5602_ISOC_PACKETS)
+#define M5602_URB_MSG_TIMEOUT   5000
+#define M5602_FRAME_TIMEOUT    2
+
+/*****************************************************************************/
+
+/* A skeleton used for sending messages to the m5602 bridge */
+static const unsigned char bridge_urb_skeleton[] = {
+       0x13, 0x00, 0x81, 0x00
+};
+
+/* A skeleton used for sending messages to the sensor */
+static const unsigned char sensor_urb_skeleton[] = {
+       0x23, M5602_XB_GPIO_EN_H, 0x81, 0x06,
+       0x23, M5602_XB_MISC_CTRL, 0x81, 0x80,
+       0x13, M5602_XB_I2C_DEV_ADDR, 0x81, 0x00,
+       0x13, M5602_XB_I2C_REG_ADDR, 0x81, 0x00,
+       0x13, M5602_XB_I2C_DATA, 0x81, 0x00,
+       0x13, M5602_XB_I2C_CTRL, 0x81, 0x11
+};
+
+/* m5602 device descriptor, currently it just wraps the m5602_camera struct */
+struct sd {
+       struct gspca_dev gspca_dev;
+
+       /* The name of the m5602 camera */
+       char *name;
+
+       /* A pointer to the currently connected sensor */
+       struct m5602_sensor *sensor;
+
+       struct sd_desc *desc;
+
+       /* The current frame's id, used to detect frame boundaries */
+       u8 frame_id;
+
+       /* The current frame count */
+       u32 frame_count;
+};
+
+int m5602_read_bridge(
+       struct sd *sd, u8 address, u8 *i2c_data);
+
+int m5602_write_bridge(
+       struct sd *sd, u8 address, u8 i2c_data);
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_core.c b/drivers/media/video/gspca/m5602/m5602_core.c
new file mode 100644 (file)
index 0000000..19d5e35
--- /dev/null
@@ -0,0 +1,313 @@
+/*
+ * USB Driver for ALi m5602 based webcams
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_ov9650.h"
+#include "m5602_mt9m111.h"
+#include "m5602_po1030.h"
+#include "m5602_s5k83a.h"
+#include "m5602_s5k4aa.h"
+
+/* Kernel module parameters */
+int force_sensor;
+int dump_bridge;
+int dump_sensor;
+unsigned int m5602_debug;
+
+static const __devinitdata struct usb_device_id m5602_table[] = {
+       {USB_DEVICE(0x0402, 0x5602)},
+       {}
+};
+
+MODULE_DEVICE_TABLE(usb, m5602_table);
+
+/* Reads a byte from the m5602 */
+int m5602_read_bridge(struct sd *sd, u8 address, u8 *i2c_data)
+{
+       int err;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       err = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
+                             0x04, 0xc0, 0x14,
+                             0x8100 + address, buf,
+                             1, M5602_URB_MSG_TIMEOUT);
+       *i2c_data = buf[0];
+
+       PDEBUG(DBG_TRACE, "Reading bridge register 0x%x containing 0x%x",
+              address, *i2c_data);
+
+       /* usb_control_msg(...) returns the number of bytes sent upon success,
+       mask that and return zero upon success instead*/
+       return (err < 0) ? err : 0;
+}
+
+/* Writes a byte to to the m5602 */
+int m5602_write_bridge(struct sd *sd, u8 address, u8 i2c_data)
+{
+       int err;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       PDEBUG(DBG_TRACE, "Writing bridge register 0x%x with 0x%x",
+              address, i2c_data);
+
+       memcpy(buf, bridge_urb_skeleton,
+              sizeof(bridge_urb_skeleton));
+       buf[1] = address;
+       buf[3] = i2c_data;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                               0x04, 0x40, 0x19,
+                               0x0000, buf,
+                               4, M5602_URB_MSG_TIMEOUT);
+
+       /* usb_control_msg(...) returns the number of bytes sent upon success,
+          mask that and return zero upon success instead */
+       return (err < 0) ? err : 0;
+}
+
+/* Dump all the registers of the m5602 bridge,
+   unfortunately this breaks the camera until it's power cycled */
+static void m5602_dump_bridge(struct sd *sd)
+{
+       int i;
+       for (i = 0; i < 0x80; i++) {
+               unsigned char val = 0;
+               m5602_read_bridge(sd, i, &val);
+               info("ALi m5602 address 0x%x contains 0x%x", i, val);
+       }
+       info("Warning: The camera probably won't work until it's power cycled");
+}
+
+static int m5602_probe_sensor(struct sd *sd)
+{
+       /* Try the po1030 */
+       sd->sensor = &po1030;
+       if (!sd->sensor->probe(sd))
+               return 0;
+
+       /* Try the mt9m111 sensor */
+       sd->sensor = &mt9m111;
+       if (!sd->sensor->probe(sd))
+               return 0;
+
+       /* Try the s5k4aa */
+       sd->sensor = &s5k4aa;
+       if (!sd->sensor->probe(sd))
+               return 0;
+
+       /* Try the ov9650 */
+       sd->sensor = &ov9650;
+       if (!sd->sensor->probe(sd))
+               return 0;
+
+       /* Try the s5k83a */
+       sd->sensor = &s5k83a;
+       if (!sd->sensor->probe(sd))
+               return 0;
+
+       /* More sensor probe function goes here */
+       info("Failed to find a sensor");
+       sd->sensor = NULL;
+       return -ENODEV;
+}
+
+static int m5602_configure(struct gspca_dev *gspca_dev,
+                          const struct usb_device_id *id);
+
+static int m5602_init(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int err;
+
+       PDEBUG(DBG_TRACE, "Initializing ALi m5602 webcam");
+       /* Run the init sequence */
+       err = sd->sensor->init(sd);
+
+       return err;
+}
+
+static int m5602_start_transfer(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* Send start command to the camera */
+       const u8 buffer[4] = {0x13, 0xf9, 0x0f, 0x01};
+       memcpy(buf, buffer, sizeof(buffer));
+       usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
+                       0x04, 0x40, 0x19, 0x0000, buf,
+                       4, M5602_URB_MSG_TIMEOUT);
+
+       PDEBUG(DBG_V4L2, "Transfer started");
+       return 0;
+}
+
+static void m5602_urb_complete(struct gspca_dev *gspca_dev,
+                       struct gspca_frame *frame,
+                       __u8 *data, int len)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       if (len < 6) {
+               PDEBUG(DBG_DATA, "Packet is less than 6 bytes");
+               return;
+       }
+
+       /* Frame delimiter: ff xx xx xx ff ff */
+       if (data[0] == 0xff && data[4] == 0xff && data[5] == 0xff &&
+           data[2] != sd->frame_id) {
+               PDEBUG(DBG_DATA, "Frame delimiter detected");
+               sd->frame_id = data[2];
+
+               /* Remove the extra fluff appended on each header */
+               data += 6;
+               len -= 6;
+
+               /* Complete the last frame (if any) */
+               frame = gspca_frame_add(gspca_dev, LAST_PACKET,
+                                       frame, data, 0);
+               sd->frame_count++;
+
+               /* Create a new frame */
+               gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
+
+               PDEBUG(DBG_V4L2, "Starting new frame %d",
+                      sd->frame_count);
+
+       } else {
+               int cur_frame_len = frame->data_end - frame->data;
+
+               /* Remove urb header */
+               data += 4;
+               len -= 4;
+
+               if (cur_frame_len + len <= frame->v4l2_buf.length) {
+                       PDEBUG(DBG_DATA, "Continuing frame %d copying %d bytes",
+                              sd->frame_count, len);
+
+                       gspca_frame_add(gspca_dev, INTER_PACKET, frame,
+                                       data, len);
+               } else if (frame->v4l2_buf.length - cur_frame_len > 0) {
+                       /* Add the remaining data up to frame size */
+                       gspca_frame_add(gspca_dev, INTER_PACKET, frame, data,
+                                       frame->v4l2_buf.length - cur_frame_len);
+               }
+       }
+}
+
+static void m5602_stop_transfer(struct gspca_dev *gspca_dev)
+{
+       /* Is there are a command to stop a data transfer? */
+}
+
+/* sub-driver description, the ctrl and nctrl is filled at probe time */
+static struct sd_desc sd_desc = {
+       .name           = MODULE_NAME,
+       .config         = m5602_configure,
+       .init           = m5602_init,
+       .start          = m5602_start_transfer,
+       .stopN          = m5602_stop_transfer,
+       .pkt_scan       = m5602_urb_complete
+};
+
+/* this function is called at probe time */
+static int m5602_configure(struct gspca_dev *gspca_dev,
+                          const struct usb_device_id *id)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       struct cam *cam;
+       int err;
+
+       PDEBUG(DBG_GSPCA, "m5602_configure start");
+
+       cam = &gspca_dev->cam;
+       cam->epaddr = M5602_ISOC_ENDPOINT_ADDR;
+       sd->desc = &sd_desc;
+
+       if (dump_bridge)
+               m5602_dump_bridge(sd);
+
+       /* Probe sensor */
+       err = m5602_probe_sensor(sd);
+       if (err)
+               goto fail;
+
+       PDEBUG(DBG_GSPCA, "m5602_configure end");
+       return 0;
+
+fail:
+       PDEBUG(DBG_GSPCA, "m5602_configure failed");
+       cam->cam_mode = NULL;
+       cam->nmodes = 0;
+
+       return err;
+}
+
+static int m5602_probe(struct usb_interface *intf,
+                      const struct usb_device_id *id)
+{
+       return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
+                              THIS_MODULE);
+}
+
+static struct usb_driver sd_driver = {
+       .name = MODULE_NAME,
+       .id_table = m5602_table,
+       .probe = m5602_probe,
+#ifdef CONFIG_PM
+       .suspend = gspca_suspend,
+       .resume = gspca_resume,
+#endif
+       .disconnect = gspca_disconnect
+};
+
+/* -- module insert / remove -- */
+static int __init mod_m5602_init(void)
+{
+       if (usb_register(&sd_driver) < 0)
+               return -1;
+       PDEBUG(D_PROBE, "m5602 module registered");
+       return 0;
+}
+static void __exit mod_m5602_exit(void)
+{
+       usb_deregister(&sd_driver);
+       PDEBUG(D_PROBE, "m5602 module deregistered");
+}
+
+module_init(mod_m5602_init);
+module_exit(mod_m5602_exit);
+
+MODULE_AUTHOR(DRIVER_AUTHOR);
+MODULE_DESCRIPTION(DRIVER_DESC);
+MODULE_LICENSE("GPL");
+module_param_named(debug, m5602_debug, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(debug, "toggles debug on/off");
+
+module_param(force_sensor, int, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(force_sensor,
+               "force detection of sensor, "
+               "1 = OV9650, 2 = S5K83A, 3 = S5K4AA, 4 = MT9M111, 5 = PO1030");
+
+module_param(dump_bridge, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dump_bridge, "Dumps all usb bridge registers at startup");
+
+module_param(dump_sensor, bool, S_IRUGO | S_IWUSR);
+MODULE_PARM_DESC(dump_sensor, "Dumps all usb sensor registers "
+               "at startup providing a sensor is found");
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.c b/drivers/media/video/gspca/m5602/m5602_mt9m111.c
new file mode 100644 (file)
index 0000000..566d492
--- /dev/null
@@ -0,0 +1,345 @@
+/*
+ * Driver for the mt9m111 sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_mt9m111.h"
+
+int mt9m111_probe(struct sd *sd)
+{
+       u8 data[2] = {0x00, 0x00};
+       int i;
+
+       if (force_sensor) {
+               if (force_sensor == MT9M111_SENSOR) {
+                       info("Forcing a %s sensor", mt9m111.name);
+                       goto sensor_found;
+               }
+               /* If we want to force another sensor, don't try to probe this
+                * one */
+               return -ENODEV;
+       }
+
+       info("Probing for a mt9m111 sensor");
+
+       /* Do the preinit */
+       for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) {
+               if (preinit_mt9m111[i][0] == BRIDGE) {
+                       m5602_write_bridge(sd,
+                               preinit_mt9m111[i][1],
+                               preinit_mt9m111[i][2]);
+               } else {
+                       data[0] = preinit_mt9m111[i][2];
+                       data[1] = preinit_mt9m111[i][3];
+                       mt9m111_write_sensor(sd,
+                               preinit_mt9m111[i][1], data, 2);
+               }
+       }
+
+       if (mt9m111_read_sensor(sd, MT9M111_SC_CHIPVER, data, 2))
+               return -ENODEV;
+
+       if ((data[0] == 0x14) && (data[1] == 0x3a)) {
+               info("Detected a mt9m111 sensor");
+               goto sensor_found;
+       }
+
+       return -ENODEV;
+
+sensor_found:
+       sd->gspca_dev.cam.cam_mode = mt9m111.modes;
+       sd->gspca_dev.cam.nmodes = mt9m111.nmodes;
+       sd->desc->ctrls = mt9m111.ctrls;
+       sd->desc->nctrls = mt9m111.nctrls;
+       return 0;
+}
+
+int mt9m111_init(struct sd *sd)
+{
+       int i, err = 0;
+
+       /* Init the sensor */
+       for (i = 0; i < ARRAY_SIZE(init_mt9m111); i++) {
+               u8 data[2];
+
+               if (init_mt9m111[i][0] == BRIDGE) {
+                       err = m5602_write_bridge(sd,
+                               init_mt9m111[i][1],
+                               init_mt9m111[i][2]);
+               } else {
+                       data[0] = init_mt9m111[i][2];
+                       data[1] = init_mt9m111[i][3];
+                       err = mt9m111_write_sensor(sd,
+                               init_mt9m111[i][1], data, 2);
+               }
+       }
+
+       if (dump_sensor)
+               mt9m111_dump_registers(sd);
+
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_power_down(struct sd *sd)
+{
+       return 0;
+}
+
+int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
+                                 data, 2);
+       *val = data[0] & MT9M111_RMB_MIRROR_ROWS;
+       PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
+
+       /* Set the correct page map */
+       err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
+       if (err < 0)
+               goto out;
+
+       err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
+       if (err < 0)
+               goto out;
+
+       data[0] = (data[0] & 0xfe) | val;
+       err = mt9m111_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
+                                  data, 2);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
+                                 data, 2);
+       *val = data[0] & MT9M111_RMB_MIRROR_COLS;
+       PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d", val);
+
+       /* Set the correct page map */
+       err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
+       if (err < 0)
+               goto out;
+
+       err = mt9m111_read_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B, data, 2);
+       if (err < 0)
+               goto out;
+
+       data[0] = (data[0] & 0xfd) | ((val << 1) & 0x02);
+       err = mt9m111_write_sensor(sd, MT9M111_SC_R_MODE_CONTEXT_B,
+                                       data, 2);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err, tmp;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = mt9m111_read_sensor(sd, MT9M111_SC_GLOBAL_GAIN, data, 2);
+       tmp = ((data[1] << 8) | data[0]);
+
+       *val = ((tmp & (1 << 10)) * 2) |
+             ((tmp & (1 <<  9)) * 2) |
+             ((tmp & (1 <<  8)) * 2) |
+              (tmp & 0x7f);
+
+       PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err, tmp;
+       u8 data[2] = {0x00, 0x00};
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       /* Set the correct page map */
+       err = mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, data, 2);
+       if (err < 0)
+               goto out;
+
+       if (val >= INITIAL_MAX_GAIN * 2 * 2 * 2)
+               return -EINVAL;
+
+       if ((val >= INITIAL_MAX_GAIN * 2 * 2) &&
+           (val < (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2))
+               tmp = (1 << 10) | (val << 9) |
+                               (val << 8) | (val / 8);
+       else if ((val >= INITIAL_MAX_GAIN * 2) &&
+                (val <  INITIAL_MAX_GAIN * 2 * 2))
+               tmp = (1 << 9) | (1 << 8) | (val / 4);
+       else if ((val >= INITIAL_MAX_GAIN) &&
+                (val < INITIAL_MAX_GAIN * 2))
+               tmp = (1 << 8) | (val / 2);
+       else
+               tmp = val;
+
+       data[1] = (tmp & 0xff00) >> 8;
+       data[0] = (tmp & 0xff);
+       PDEBUG(DBG_V4L2_CID, "tmp=%d, data[1]=%d, data[0]=%d", tmp,
+              data[1], data[0]);
+
+       err = mt9m111_write_sensor(sd, MT9M111_SC_GLOBAL_GAIN,
+                                  data, 2);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_read_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len) {
+       int err, i;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
+                                sd->sensor->i2c_slave_id);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x1a);
+       if (err < 0)
+               goto out;
+
+       for (i = 0; i < len && !err; i++) {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
+
+               PDEBUG(DBG_TRACE, "Reading sensor register "
+                      "0x%x contains 0x%x ", address, *i2c_data);
+       }
+out:
+       return (err < 0) ? err : 0;
+}
+
+int mt9m111_write_sensor(struct sd *sd, const u8 address,
+                               u8 *i2c_data, const u8 len)
+{
+       int err, i;
+       u8 *p;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* No sensor with a data width larger
+          than 16 bits has yet been seen, nor with 0 :p*/
+       if (len > 2 || !len)
+               return -EINVAL;
+
+       memcpy(buf, sensor_urb_skeleton,
+              sizeof(sensor_urb_skeleton));
+
+       buf[11] = sd->sensor->i2c_slave_id;
+       buf[15] = address;
+
+       p = buf + 16;
+
+       /* Copy a four byte write sequence for each byte to be written to */
+       for (i = 0; i < len; i++) {
+               memcpy(p, sensor_urb_skeleton + 16, 4);
+               p[3] = i2c_data[i];
+               p += 4;
+               PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
+                      address, i2c_data[i]);
+       }
+
+       /* Copy the tailer */
+       memcpy(p, sensor_urb_skeleton + 20, 4);
+
+       /* Set the total length */
+       p[3] = 0x10 + len;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                             0x04, 0x40, 0x19,
+                             0x0000, buf,
+                             20 + len * 4, M5602_URB_MSG_TIMEOUT);
+
+       return (err < 0) ? err : 0;
+}
+
+void mt9m111_dump_registers(struct sd *sd)
+{
+       u8 address, value[2] = {0x00, 0x00};
+
+       info("Dumping the mt9m111 register state");
+
+       info("Dumping the mt9m111 sensor core registers");
+       value[1] = MT9M111_SENSOR_CORE;
+       mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
+       for (address = 0; address < 0xff; address++) {
+               mt9m111_read_sensor(sd, address, value, 2);
+               info("register 0x%x contains 0x%x%x",
+                    address, value[0], value[1]);
+       }
+
+       info("Dumping the mt9m111 color pipeline registers");
+       value[1] = MT9M111_COLORPIPE;
+       mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
+       for (address = 0; address < 0xff; address++) {
+               mt9m111_read_sensor(sd, address, value, 2);
+               info("register 0x%x contains 0x%x%x",
+                    address, value[0], value[1]);
+       }
+
+       info("Dumping the mt9m111 camera control registers");
+       value[1] = MT9M111_CAMERA_CONTROL;
+       mt9m111_write_sensor(sd, MT9M111_PAGE_MAP, value, 2);
+       for (address = 0; address < 0xff; address++) {
+               mt9m111_read_sensor(sd, address, value, 2);
+               info("register 0x%x contains 0x%x%x",
+                    address, value[0], value[1]);
+       }
+
+       info("mt9m111 register state dump complete");
+}
diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.h b/drivers/media/video/gspca/m5602/m5602_mt9m111.h
new file mode 100644 (file)
index 0000000..79a5d88
--- /dev/null
@@ -0,0 +1,1020 @@
+/*
+ * Driver for the mt9m111 sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * Some defines taken from the mt9m111 sensor driver
+ * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_MT9M111_H_
+#define M5602_MT9M111_H_
+
+#include "m5602_sensor.h"
+
+/*****************************************************************************/
+
+#define MT9M111_SC_CHIPVER                     0x00
+#define MT9M111_SC_ROWSTART                    0x01
+#define MT9M111_SC_COLSTART                    0x02
+#define MT9M111_SC_WINDOW_HEIGHT               0x03
+#define MT9M111_SC_WINDOW_WIDTH                        0x04
+#define MT9M111_SC_HBLANK_CONTEXT_B            0x05
+#define MT9M111_SC_VBLANK_CONTEXT_B            0x06
+#define MT9M111_SC_HBLANK_CONTEXT_A            0x07
+#define MT9M111_SC_VBLANK_CONTEXT_A            0x08
+#define MT9M111_SC_SHUTTER_WIDTH               0x09
+#define MT9M111_SC_ROW_SPEED                   0x0a
+
+#define MT9M111_SC_EXTRA_DELAY                 0x0b
+#define MT9M111_SC_SHUTTER_DELAY               0x0c
+#define MT9M111_SC_RESET                       0x0d
+#define MT9M111_SC_R_MODE_CONTEXT_B            0x20
+#define MT9M111_SC_R_MODE_CONTEXT_A            0x21
+#define MT9M111_SC_FLASH_CONTROL               0x23
+#define MT9M111_SC_GREEN_1_GAIN                        0x2b
+#define MT9M111_SC_BLUE_GAIN                   0x2c
+#define MT9M111_SC_RED_GAIN                    0x2d
+#define MT9M111_SC_GREEN_2_GAIN                        0x2e
+#define MT9M111_SC_GLOBAL_GAIN                 0x2f
+
+#define MT9M111_RMB_MIRROR_ROWS                        (1 << 0)
+#define MT9M111_RMB_MIRROR_COLS                        (1 << 1)
+
+#define MT9M111_CONTEXT_CONTROL                        0xc8
+#define MT9M111_PAGE_MAP                       0xf0
+#define MT9M111_BYTEWISE_ADDRESS               0xf1
+
+#define MT9M111_CP_OPERATING_MODE_CTL          0x06
+#define MT9M111_CP_LUMA_OFFSET                 0x34
+#define MT9M111_CP_LUMA_CLIP                   0x35
+#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A 0x3a
+#define MT9M111_CP_LENS_CORRECTION_1           0x3b
+#define MT9M111_CP_DEFECT_CORR_CONTEXT_A       0x4c
+#define MT9M111_CP_DEFECT_CORR_CONTEXT_B       0x4d
+#define MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B 0x9b
+#define MT9M111_CP_GLOBAL_CLK_CONTROL          0xb3
+
+#define MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18   0x65
+#define MT9M111_CC_AWB_PARAMETER_7             0x28
+
+#define MT9M111_SENSOR_CORE                    0x00
+#define MT9M111_COLORPIPE                      0x01
+#define MT9M111_CAMERA_CONTROL                 0x02
+
+#define INITIAL_MAX_GAIN                       64
+#define DEFAULT_GAIN                           283
+
+/*****************************************************************************/
+
+/* Kernel module parameters */
+extern int force_sensor;
+extern int dump_sensor;
+extern unsigned int m5602_debug;
+
+int mt9m111_probe(struct sd *sd);
+int mt9m111_init(struct sd *sd);
+int mt9m111_power_down(struct sd *sd);
+
+int mt9m111_read_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len);
+
+int mt9m111_write_sensor(struct sd *sd, const u8 address,
+                        u8 *i2c_data, const u8 len);
+
+void mt9m111_dump_registers(struct sd *sd);
+
+int mt9m111_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
+int mt9m111_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
+int mt9m111_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
+int mt9m111_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
+int mt9m111_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int mt9m111_set_gain(struct gspca_dev *gspca_dev, __s32 val);
+
+static struct m5602_sensor mt9m111 = {
+       .name = "MT9M111",
+
+       .i2c_slave_id = 0xba,
+
+       .probe = mt9m111_probe,
+       .init = mt9m111_init,
+       .power_down = mt9m111_power_down,
+
+       .read_sensor = mt9m111_read_sensor,
+       .write_sensor = mt9m111_write_sensor,
+
+       .nctrls = 3,
+       .ctrls = {
+       {
+               {
+                       .id             = V4L2_CID_VFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "vertical flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = mt9m111_set_vflip,
+               .get = mt9m111_get_vflip
+       }, {
+               {
+                       .id             = V4L2_CID_HFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "horizontal flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = mt9m111_set_hflip,
+               .get = mt9m111_get_hflip
+       }, {
+               {
+                       .id             = V4L2_CID_GAIN,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "gain",
+                       .minimum        = 0,
+                       .maximum        = (INITIAL_MAX_GAIN - 1) * 2 * 2 * 2,
+                       .step           = 1,
+                       .default_value  = DEFAULT_GAIN,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = mt9m111_set_hflip,
+               .get = mt9m111_get_hflip
+       }
+       },
+
+       .nmodes = 1,
+       .modes = {
+       {
+               M5602_DEFAULT_FRAME_WIDTH,
+               M5602_DEFAULT_FRAME_HEIGHT,
+               V4L2_PIX_FMT_SBGGR8,
+               V4L2_FIELD_NONE,
+               .sizeimage =
+                       M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
+               .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 1
+       }
+       }
+};
+
+static const unsigned char preinit_mt9m111[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xf7},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00}
+};
+
+static const unsigned char init_mt9m111[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xde},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xff},
+       {SENSOR, MT9M111_SC_RESET, 0xff, 0xf7},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
+
+       {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0xff, 0xff},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
+       {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
+       {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
+
+       {SENSOR, 0xcd, 0x00, 0x0e},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
+       {SENSOR, 0xd0, 0x00, 0x40},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
+       {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {SENSOR, 0x33, 0x03, 0x49},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+
+       {SENSOR, 0x33, 0x03, 0x49},
+       {SENSOR, 0x34, 0xc0, 0x19},
+       {SENSOR, 0x3f, 0x20, 0x20},
+       {SENSOR, 0x40, 0x20, 0x20},
+       {SENSOR, 0x5a, 0xc0, 0x0a},
+       {SENSOR, 0x70, 0x7b, 0x0a},
+       {SENSOR, 0x71, 0xff, 0x00},
+       {SENSOR, 0x72, 0x19, 0x0e},
+       {SENSOR, 0x73, 0x18, 0x0f},
+       {SENSOR, 0x74, 0x57, 0x32},
+       {SENSOR, 0x75, 0x56, 0x34},
+       {SENSOR, 0x76, 0x73, 0x35},
+       {SENSOR, 0x77, 0x30, 0x12},
+       {SENSOR, 0x78, 0x79, 0x02},
+       {SENSOR, 0x79, 0x75, 0x06},
+       {SENSOR, 0x7a, 0x77, 0x0a},
+       {SENSOR, 0x7b, 0x78, 0x09},
+       {SENSOR, 0x7c, 0x7d, 0x06},
+       {SENSOR, 0x7d, 0x31, 0x10},
+       {SENSOR, 0x7e, 0x00, 0x7e},
+       {SENSOR, 0x80, 0x59, 0x04},
+       {SENSOR, 0x81, 0x59, 0x04},
+       {SENSOR, 0x82, 0x57, 0x0a},
+       {SENSOR, 0x83, 0x58, 0x0b},
+       {SENSOR, 0x84, 0x47, 0x0c},
+       {SENSOR, 0x85, 0x48, 0x0e},
+       {SENSOR, 0x86, 0x5b, 0x02},
+       {SENSOR, 0x87, 0x00, 0x5c},
+       {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
+       {SENSOR, 0x60, 0x00, 0x80},
+       {SENSOR, 0x61, 0x00, 0x00},
+       {SENSOR, 0x62, 0x00, 0x00},
+       {SENSOR, 0x63, 0x00, 0x00},
+       {SENSOR, 0x64, 0x00, 0x00},
+
+       {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
+       {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
+       {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
+       {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
+       {SENSOR, 0x30, 0x04, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
+       {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
+       {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
+       {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
+       {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
+       {SENSOR, 0xcd, 0x00, 0x0e},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
+       {SENSOR, 0xd0, 0x00, 0x40},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
+       {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {SENSOR, 0x33, 0x03, 0x49},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+
+       {SENSOR, 0x33, 0x03, 0x49},
+       {SENSOR, 0x34, 0xc0, 0x19},
+       {SENSOR, 0x3f, 0x20, 0x20},
+       {SENSOR, 0x40, 0x20, 0x20},
+       {SENSOR, 0x5a, 0xc0, 0x0a},
+       {SENSOR, 0x70, 0x7b, 0x0a},
+       {SENSOR, 0x71, 0xff, 0x00},
+       {SENSOR, 0x72, 0x19, 0x0e},
+       {SENSOR, 0x73, 0x18, 0x0f},
+       {SENSOR, 0x74, 0x57, 0x32},
+       {SENSOR, 0x75, 0x56, 0x34},
+       {SENSOR, 0x76, 0x73, 0x35},
+       {SENSOR, 0x77, 0x30, 0x12},
+       {SENSOR, 0x78, 0x79, 0x02},
+       {SENSOR, 0x79, 0x75, 0x06},
+       {SENSOR, 0x7a, 0x77, 0x0a},
+       {SENSOR, 0x7b, 0x78, 0x09},
+       {SENSOR, 0x7c, 0x7d, 0x06},
+       {SENSOR, 0x7d, 0x31, 0x10},
+       {SENSOR, 0x7e, 0x00, 0x7e},
+       {SENSOR, 0x80, 0x59, 0x04},
+       {SENSOR, 0x81, 0x59, 0x04},
+       {SENSOR, 0x82, 0x57, 0x0a},
+       {SENSOR, 0x83, 0x58, 0x0b},
+       {SENSOR, 0x84, 0x47, 0x0c},
+       {SENSOR, 0x85, 0x48, 0x0e},
+       {SENSOR, 0x86, 0x5b, 0x02},
+       {SENSOR, 0x87, 0x00, 0x5c},
+       {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
+       {SENSOR, 0x60, 0x00, 0x80},
+       {SENSOR, 0x61, 0x00, 0x00},
+       {SENSOR, 0x62, 0x00, 0x00},
+       {SENSOR, 0x63, 0x00, 0x00},
+       {SENSOR, 0x64, 0x00, 0x00},
+
+       {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
+       {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
+       {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
+       {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
+       {SENSOR, 0x30, 0x04, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
+       {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
+       {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
+       {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
+       {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
+       {SENSOR, 0xcd, 0x00, 0x0e},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
+       {SENSOR, 0xd0, 0x00, 0x40},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
+       {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {SENSOR, 0x33, 0x03, 0x49},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+
+       {SENSOR, 0x33, 0x03, 0x49},
+       {SENSOR, 0x34, 0xc0, 0x19},
+       {SENSOR, 0x3f, 0x20, 0x20},
+       {SENSOR, 0x40, 0x20, 0x20},
+       {SENSOR, 0x5a, 0xc0, 0x0a},
+       {SENSOR, 0x70, 0x7b, 0x0a},
+       {SENSOR, 0x71, 0xff, 0x00},
+       {SENSOR, 0x72, 0x19, 0x0e},
+       {SENSOR, 0x73, 0x18, 0x0f},
+       {SENSOR, 0x74, 0x57, 0x32},
+       {SENSOR, 0x75, 0x56, 0x34},
+       {SENSOR, 0x76, 0x73, 0x35},
+       {SENSOR, 0x77, 0x30, 0x12},
+       {SENSOR, 0x78, 0x79, 0x02},
+       {SENSOR, 0x79, 0x75, 0x06},
+       {SENSOR, 0x7a, 0x77, 0x0a},
+       {SENSOR, 0x7b, 0x78, 0x09},
+       {SENSOR, 0x7c, 0x7d, 0x06},
+       {SENSOR, 0x7d, 0x31, 0x10},
+       {SENSOR, 0x7e, 0x00, 0x7e},
+       {SENSOR, 0x80, 0x59, 0x04},
+       {SENSOR, 0x81, 0x59, 0x04},
+       {SENSOR, 0x82, 0x57, 0x0a},
+       {SENSOR, 0x83, 0x58, 0x0b},
+       {SENSOR, 0x84, 0x47, 0x0c},
+       {SENSOR, 0x85, 0x48, 0x0e},
+       {SENSOR, 0x86, 0x5b, 0x02},
+       {SENSOR, 0x87, 0x00, 0x5c},
+       {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
+       {SENSOR, 0x60, 0x00, 0x80},
+       {SENSOR, 0x61, 0x00, 0x00},
+       {SENSOR, 0x62, 0x00, 0x00},
+       {SENSOR, 0x63, 0x00, 0x00},
+       {SENSOR, 0x64, 0x00, 0x00},
+
+       {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
+       {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x18},
+       {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x04},
+       {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x08},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x38},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x03},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x03},
+       {SENSOR, 0x30, 0x04, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x04, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x05, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x07, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0xf4},
+       {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xea},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
+       {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
+       {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0xcd, 0x00, 0x0e},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0xd0, 0x00, 0x40},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
+       {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0x33, 0x03, 0x49},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+
+       {SENSOR, 0x33, 0x03, 0x49},
+       {SENSOR, 0x34, 0xc0, 0x19},
+       {SENSOR, 0x3f, 0x20, 0x20},
+       {SENSOR, 0x40, 0x20, 0x20},
+       {SENSOR, 0x5a, 0xc0, 0x0a},
+       {SENSOR, 0x70, 0x7b, 0x0a},
+       {SENSOR, 0x71, 0xff, 0x00},
+       {SENSOR, 0x72, 0x19, 0x0e},
+       {SENSOR, 0x73, 0x18, 0x0f},
+       {SENSOR, 0x74, 0x57, 0x32},
+       {SENSOR, 0x75, 0x56, 0x34},
+       {SENSOR, 0x76, 0x73, 0x35},
+       {SENSOR, 0x77, 0x30, 0x12},
+       {SENSOR, 0x78, 0x79, 0x02},
+       {SENSOR, 0x79, 0x75, 0x06},
+       {SENSOR, 0x7a, 0x77, 0x0a},
+       {SENSOR, 0x7b, 0x78, 0x09},
+       {SENSOR, 0x7c, 0x7d, 0x06},
+       {SENSOR, 0x7d, 0x31, 0x10},
+       {SENSOR, 0x7e, 0x00, 0x7e},
+       {SENSOR, 0x80, 0x59, 0x04},
+       {SENSOR, 0x81, 0x59, 0x04},
+       {SENSOR, 0x82, 0x57, 0x0a},
+       {SENSOR, 0x83, 0x58, 0x0b},
+       {SENSOR, 0x84, 0x47, 0x0c},
+       {SENSOR, 0x85, 0x48, 0x0e},
+       {SENSOR, 0x86, 0x5b, 0x02},
+       {SENSOR, 0x87, 0x00, 0x5c},
+       {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
+       {SENSOR, 0x60, 0x00, 0x80},
+       {SENSOR, 0x61, 0x00, 0x00},
+       {SENSOR, 0x62, 0x00, 0x00},
+       {SENSOR, 0x63, 0x00, 0x00},
+       {SENSOR, 0x64, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
+       {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x12},
+       {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x00},
+       {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x10},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x60},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x60},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x0f},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x0f},
+       {SENSOR, 0x30, 0x04, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe3, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0x90},
+       {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x00, 0xe6},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x09},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x0c},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x04},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xb3, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CP_GLOBAL_CLK_CONTROL, 0x00, 0x03},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3e, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x07, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x0b, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a, 0x00},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x05},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x29},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_SC_RESET, 0x00, 0x08},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_OPERATING_MODE_CTL, 0x00, 0x10},
+       {SENSOR, MT9M111_CP_LENS_CORRECTION_1, 0x04, 0x2a},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_A, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_DEFECT_CORR_CONTEXT_B, 0x00, 0x01},
+       {SENSOR, MT9M111_CP_LUMA_OFFSET, 0x00, 0x00},
+       {SENSOR, MT9M111_CP_LUMA_CLIP, 0xff, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_A, 0x14, 0x00},
+       {SENSOR, MT9M111_CP_OUTPUT_FORMAT_CTL2_CONTEXT_B, 0x14, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xcd, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0xcd, 0x00, 0x0e},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0xd0, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0xd0, 0x00, 0x40},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x02},
+       {SENSOR, MT9M111_CC_AUTO_EXPOSURE_PARAMETER_18, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x07},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x28, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, MT9M111_CC_AWB_PARAMETER_7, 0xef, 0x03},
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+       {SENSOR, 0x33, 0x03, 0x49},
+       {BRIDGE, M5602_XB_I2C_DEV_ADDR, 0xba, 0x00},
+       {BRIDGE, M5602_XB_I2C_REG_ADDR, 0x33, 0x00},
+       {BRIDGE, M5602_XB_I2C_CTRL, 0x1a, 0x00},
+
+       {SENSOR, 0x33, 0x03, 0x49},
+       {SENSOR, 0x34, 0xc0, 0x19},
+       {SENSOR, 0x3f, 0x20, 0x20},
+       {SENSOR, 0x40, 0x20, 0x20},
+       {SENSOR, 0x5a, 0xc0, 0x0a},
+       {SENSOR, 0x70, 0x7b, 0x0a},
+       {SENSOR, 0x71, 0xff, 0x00},
+       {SENSOR, 0x72, 0x19, 0x0e},
+       {SENSOR, 0x73, 0x18, 0x0f},
+       {SENSOR, 0x74, 0x57, 0x32},
+       {SENSOR, 0x75, 0x56, 0x34},
+       {SENSOR, 0x76, 0x73, 0x35},
+       {SENSOR, 0x77, 0x30, 0x12},
+       {SENSOR, 0x78, 0x79, 0x02},
+       {SENSOR, 0x79, 0x75, 0x06},
+       {SENSOR, 0x7a, 0x77, 0x0a},
+       {SENSOR, 0x7b, 0x78, 0x09},
+       {SENSOR, 0x7c, 0x7d, 0x06},
+       {SENSOR, 0x7d, 0x31, 0x10},
+       {SENSOR, 0x7e, 0x00, 0x7e},
+       {SENSOR, 0x80, 0x59, 0x04},
+       {SENSOR, 0x81, 0x59, 0x04},
+       {SENSOR, 0x82, 0x57, 0x0a},
+       {SENSOR, 0x83, 0x58, 0x0b},
+       {SENSOR, 0x84, 0x47, 0x0c},
+       {SENSOR, 0x85, 0x48, 0x0e},
+       {SENSOR, 0x86, 0x5b, 0x02},
+       {SENSOR, 0x87, 0x00, 0x5c},
+       {SENSOR, MT9M111_CONTEXT_CONTROL, 0x00, 0x08},
+       {SENSOR, 0x60, 0x00, 0x80},
+       {SENSOR, 0x61, 0x00, 0x00},
+       {SENSOR, 0x62, 0x00, 0x00},
+       {SENSOR, 0x63, 0x00, 0x00},
+       {SENSOR, 0x64, 0x00, 0x00},
+
+       {SENSOR, MT9M111_SC_ROWSTART, 0x00, 0x0d},
+       {SENSOR, MT9M111_SC_COLSTART, 0x00, 0x12},
+       {SENSOR, MT9M111_SC_WINDOW_HEIGHT, 0x04, 0x00},
+       {SENSOR, MT9M111_SC_WINDOW_WIDTH, 0x05, 0x10},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_B, 0x01, 0x60},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_B, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_HBLANK_CONTEXT_A, 0x01, 0x60},
+       {SENSOR, MT9M111_SC_VBLANK_CONTEXT_A, 0x00, 0x11},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_B, 0x01, 0x0f},
+       {SENSOR, MT9M111_SC_R_MODE_CONTEXT_A, 0x01, 0x0f},
+       {SENSOR, 0x30, 0x04, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, MT9M111_PAGE_MAP, 0x00, 0x00},
+       /* Set number of blank rows chosen to 400 */
+       {SENSOR, MT9M111_SC_SHUTTER_WIDTH, 0x01, 0x90},
+       /* Set the global gain to 283 (of 512) */
+       {SENSOR, MT9M111_SC_GLOBAL_GAIN, 0x03, 0x63}
+};
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c
new file mode 100644 (file)
index 0000000..31c5896
--- /dev/null
@@ -0,0 +1,546 @@
+/*
+ * Driver for the ov9650 sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_ov9650.h"
+
+int ov9650_read_sensor(struct sd *sd, const u8 address,
+                     u8 *i2c_data, const u8 len)
+{
+       int err, i;
+
+       /* The ov9650 registers have a max depth of one byte */
+       if (len > 1 || !len)
+               return -EINVAL;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+
+       m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
+                          ov9650.i2c_slave_id);
+       m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
+       m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len);
+       m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
+
+       for (i = 0; i < len; i++) {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
+
+               PDEBUG(DBG_TRACE, "Reading sensor register "
+                               "0x%x containing 0x%x ", address, *i2c_data);
+       }
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_write_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len)
+{
+       int err, i;
+       u8 *p;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* The ov9650 only supports one byte writes */
+       if (len > 1 || !len)
+               return -EINVAL;
+
+       memcpy(buf, sensor_urb_skeleton,
+              sizeof(sensor_urb_skeleton));
+
+       buf[11] = sd->sensor->i2c_slave_id;
+       buf[15] = address;
+
+       /* Special case larger sensor writes */
+       p = buf + 16;
+
+       /* Copy a four byte write sequence for each byte to be written to */
+       for (i = 0; i < len; i++) {
+               memcpy(p, sensor_urb_skeleton + 16, 4);
+               p[3] = i2c_data[i];
+               p += 4;
+               PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
+                      address, i2c_data[i]);
+       }
+
+       /* Copy the tailer */
+       memcpy(p, sensor_urb_skeleton + 20, 4);
+
+       /* Set the total length */
+       p[3] = 0x10 + len;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                             0x04, 0x40, 0x19,
+                             0x0000, buf,
+                             20 + len * 4, M5602_URB_MSG_TIMEOUT);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_probe(struct sd *sd)
+{
+       u8 prod_id = 0, ver_id = 0, i;
+
+       if (force_sensor) {
+               if (force_sensor == OV9650_SENSOR) {
+                       info("Forcing an %s sensor", ov9650.name);
+                       goto sensor_found;
+               }
+               /* If we want to force another sensor,
+                  don't try to probe this one */
+               return -ENODEV;
+       }
+
+       info("Probing for an ov9650 sensor");
+
+       /* Run the pre-init to actually probe the unit */
+       for (i = 0; i < ARRAY_SIZE(preinit_ov9650); i++) {
+               u8 data = preinit_ov9650[i][2];
+               if (preinit_ov9650[i][0] == SENSOR)
+                       ov9650_write_sensor(sd,
+                                           preinit_ov9650[i][1], &data, 1);
+               else
+                       m5602_write_bridge(sd, preinit_ov9650[i][1], data);
+       }
+
+       if (ov9650_read_sensor(sd, OV9650_PID, &prod_id, 1))
+               return -ENODEV;
+
+       if (ov9650_read_sensor(sd, OV9650_VER, &ver_id, 1))
+               return -ENODEV;
+
+       if ((prod_id == 0x96) && (ver_id == 0x52)) {
+               info("Detected an ov9650 sensor");
+               goto sensor_found;
+       }
+
+       return -ENODEV;
+
+sensor_found:
+       sd->gspca_dev.cam.cam_mode = ov9650.modes;
+       sd->gspca_dev.cam.nmodes = ov9650.nmodes;
+       sd->desc->ctrls = ov9650.ctrls;
+       sd->desc->nctrls = ov9650.nctrls;
+       return 0;
+}
+
+int ov9650_init(struct sd *sd)
+{
+       int i, err = 0;
+       u8 data;
+
+       if (dump_sensor)
+               ov9650_dump_registers(sd);
+
+       for (i = 0; i < ARRAY_SIZE(init_ov9650) && !err; i++) {
+               data = init_ov9650[i][2];
+               if (init_ov9650[i][0] == SENSOR)
+                       err = ov9650_write_sensor(sd, init_ov9650[i][1],
+                                                 &data, 1);
+               else
+                       err = m5602_write_bridge(sd, init_ov9650[i][1], data);
+       }
+
+       if (!err && dmi_check_system(ov9650_flip_dmi_table)) {
+               info("vflip quirk active");
+               data = 0x30;
+               err = ov9650_write_sensor(sd, OV9650_MVFP, &data, 1);
+       }
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_power_down(struct sd *sd)
+{
+       int i;
+       for (i = 0; i < ARRAY_SIZE(power_down_ov9650); i++) {
+               u8 data = power_down_ov9650[i][2];
+               if (power_down_ov9650[i][0] == SENSOR)
+                       ov9650_write_sensor(sd,
+                                           power_down_ov9650[i][1], &data, 1);
+               else
+                       m5602_write_bridge(sd, power_down_ov9650[i][1], data);
+       }
+
+       return 0;
+}
+
+int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       err = ov9650_read_sensor(sd, OV9650_COM1, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+       *val = i2c_data & 0x03;
+
+       err = ov9650_read_sensor(sd, OV9650_AECH, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+       *val |= (i2c_data << 2);
+
+       err = ov9650_read_sensor(sd, OV9650_AECHM, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+       *val |= (i2c_data & 0x3f) << 10;
+
+       PDEBUG(DBG_V4L2_CID, "Read exposure %d", *val);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       PDEBUG(DBG_V4L2_CID, "Set exposure to %d",
+              val & 0xffff);
+
+       /* The 6 MSBs */
+       i2c_data = (val >> 10) & 0x3f;
+       err = ov9650_write_sensor(sd, OV9650_AECHM,
+                                 &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       /* The 8 middle bits */
+       i2c_data = (val >> 2) & 0xff;
+       err = ov9650_write_sensor(sd, OV9650_AECH,
+                                 &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       /* The 2 LSBs */
+       i2c_data = val & 0x03;
+       err = ov9650_write_sensor(sd, OV9650_COM1, &i2c_data, 1);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
+       *val = (i2c_data & 0x03) << 8;
+
+       err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
+       *val |= i2c_data;
+       PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       /* The 2 MSB */
+       /* Read the OV9650_VREF register first to avoid
+          corrupting the VREF high and low bits */
+       ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
+       /* Mask away all uninteresting bits */
+       i2c_data = ((val & 0x0300) >> 2) |
+                       (i2c_data & 0x3F);
+       err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
+
+       /* The 8 LSBs */
+       i2c_data = val & 0xff;
+       err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_RED, &i2c_data, 1);
+       *val = i2c_data;
+
+       PDEBUG(DBG_V4L2_CID, "Read red gain %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set red gain to %d",
+                            val & 0xff);
+
+       i2c_data = val & 0xff;
+       err = ov9650_write_sensor(sd, OV9650_RED, &i2c_data, 1);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_BLUE, &i2c_data, 1);
+       *val = i2c_data;
+
+       PDEBUG(DBG_V4L2_CID, "Read blue gain %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set blue gain to %d",
+              val & 0xff);
+
+       i2c_data = val & 0xff;
+       err = ov9650_write_sensor(sd, OV9650_BLUE, &i2c_data, 1);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+       if (dmi_check_system(ov9650_flip_dmi_table))
+               *val = ((i2c_data & OV9650_HFLIP) >> 5) ? 0 : 1;
+       else
+               *val = (i2c_data & OV9650_HFLIP) >> 5;
+       PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d", val);
+       err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       if (dmi_check_system(ov9650_flip_dmi_table))
+               i2c_data = ((i2c_data & 0xdf) |
+                               (((val ? 0 : 1) & 0x01) << 5));
+       else
+               i2c_data = ((i2c_data & 0xdf) |
+                               ((val & 0x01) << 5));
+
+       err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+       if (dmi_check_system(ov9650_flip_dmi_table))
+               *val = ((i2c_data & 0x10) >> 4) ? 0 : 1;
+       else
+               *val = (i2c_data & 0x10) >> 4;
+       PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
+       err = ov9650_read_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       if (dmi_check_system(ov9650_flip_dmi_table))
+               i2c_data = ((i2c_data & 0xef) |
+                               (((val ? 0 : 1) & 0x01) << 4));
+       else
+               i2c_data = ((i2c_data & 0xef) |
+                               ((val & 0x01) << 4));
+
+       err = ov9650_write_sensor(sd, OV9650_MVFP, &i2c_data, 1);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+       *val = (i2c_data & 0x03) << 8;
+
+       err = ov9650_read_sensor(sd, OV9650_GAIN, &i2c_data, 1);
+       *val |= i2c_data;
+       PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set gain to %d", val & 0x3ff);
+
+       /* Read the OV9650_VREF register first to avoid
+               corrupting the VREF high and low bits */
+       err = ov9650_read_sensor(sd, OV9650_VREF, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       /* Mask away all uninteresting bits */
+       i2c_data = ((val & 0x0300) >> 2) | (i2c_data & 0x3F);
+       err = ov9650_write_sensor(sd, OV9650_VREF, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       /* The 8 LSBs */
+       i2c_data = val & 0xff;
+       err = ov9650_write_sensor(sd, OV9650_GAIN, &i2c_data, 1);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
+       *val = (i2c_data & OV9650_AWB_EN) >> 1;
+       PDEBUG(DBG_V4L2_CID, "Read auto white balance %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set auto white balance to %d", val);
+       err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       i2c_data = ((i2c_data & 0xfd) | ((val & 0x01) << 1));
+       err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
+       *val = (i2c_data & OV9650_AGC_EN) >> 2;
+       PDEBUG(DBG_V4L2_CID, "Read auto gain control %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 i2c_data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(DBG_V4L2_CID, "Set auto gain control to %d", val);
+       err = ov9650_read_sensor(sd, OV9650_COM8, &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       i2c_data = ((i2c_data & 0xfb) | ((val & 0x01) << 2));
+       err = ov9650_write_sensor(sd, OV9650_COM8, &i2c_data, 1);
+out:
+       return (err < 0) ? err : 0;
+}
+
+void ov9650_dump_registers(struct sd *sd)
+{
+       int address;
+       info("Dumping the ov9650 register state");
+       for (address = 0; address < 0xa9; address++) {
+               u8 value;
+               ov9650_read_sensor(sd, address, &value, 1);
+               info("register 0x%x contains 0x%x",
+                    address, value);
+       }
+
+       info("ov9650 register state dump complete");
+
+       info("Probing for which registers that are read/write");
+       for (address = 0; address < 0xff; address++) {
+               u8 old_value, ctrl_value;
+               u8 test_value[2] = {0xff, 0xff};
+
+               ov9650_read_sensor(sd, address, &old_value, 1);
+               ov9650_write_sensor(sd, address, test_value, 1);
+               ov9650_read_sensor(sd, address, &ctrl_value, 1);
+
+               if (ctrl_value == test_value[0])
+                       info("register 0x%x is writeable", address);
+               else
+                       info("register 0x%x is read only", address);
+
+               /* Restore original value */
+               ov9650_write_sensor(sd, address, &old_value, 1);
+       }
+}
diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.h b/drivers/media/video/gspca/m5602/m5602_ov9650.h
new file mode 100644 (file)
index 0000000..2f29cb0
--- /dev/null
@@ -0,0 +1,503 @@
+/*
+ * Driver for the ov9650 sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_OV9650_H_
+#define M5602_OV9650_H_
+
+#include <linux/dmi.h>
+
+#include "m5602_sensor.h"
+
+/*****************************************************************************/
+
+#define OV9650_GAIN                    0x00
+#define OV9650_BLUE                    0x01
+#define OV9650_RED                     0x02
+#define OV9650_VREF                    0x03
+#define OV9650_COM1                    0x04
+#define OV9650_BAVE                    0x05
+#define OV9650_GEAVE                   0x06
+#define OV9650_RSVD7                   0x07
+#define OV9650_PID                     0x0a
+#define OV9650_VER                     0x0b
+#define OV9650_COM3                    0x0c
+#define OV9650_COM5                    0x0e
+#define OV9650_COM6                    0x0f
+#define OV9650_AECH                    0x10
+#define OV9650_CLKRC                   0x11
+#define OV9650_COM7                    0x12
+#define OV9650_COM8                    0x13
+#define OV9650_COM9                    0x14
+#define OV9650_COM10                   0x15
+#define OV9650_RSVD16                  0x16
+#define OV9650_HSTART                  0x17
+#define OV9650_HSTOP                   0x18
+#define OV9650_VSTRT                   0x19
+#define OV9650_VSTOP                   0x1a
+#define OV9650_PSHFT                   0x1b
+#define OV9650_MVFP                    0x1e
+#define OV9650_AEW                     0x24
+#define OV9650_AEB                     0x25
+#define OV9650_VPT                     0x26
+#define OV9650_BBIAS                   0x27
+#define OV9650_GbBIAS                  0x28
+#define OV9650_Gr_COM                  0x29
+#define OV9650_RBIAS                   0x2c
+#define OV9650_HREF                    0x32
+#define OV9650_CHLF                    0x33
+#define OV9650_ARBLM                   0x34
+#define OV9650_RSVD35                  0x35
+#define OV9650_RSVD36                  0x36
+#define OV9650_ADC                     0x37
+#define OV9650_ACOM38                  0x38
+#define OV9650_OFON                    0x39
+#define OV9650_TSLB                    0x3a
+#define OV9650_COM12                   0x3c
+#define OV9650_COM13                   0x3d
+#define OV9650_COM15                   0x40
+#define OV9650_COM16                   0x41
+#define OV9650_LCC1                    0x62
+#define OV9650_LCC2                    0x63
+#define OV9650_LCC3                    0x64
+#define OV9650_LCC4                    0x65
+#define OV9650_LCC5                    0x66
+#define OV9650_HV                      0x69
+#define OV9650_DBLV                    0x6b
+#define OV9650_COM21                   0x8b
+#define OV9650_COM22                   0x8c
+#define OV9650_COM24                   0x8e
+#define OV9650_DBLC1                   0x8f
+#define OV9650_RSVD94                  0x94
+#define OV9650_RSVD95                  0x95
+#define OV9650_RSVD96                  0x96
+#define OV9650_LCCFB                   0x9d
+#define OV9650_LCCFR                   0x9e
+#define OV9650_AECHM                   0xa1
+#define OV9650_COM26                   0xa5
+#define OV9650_ACOMA8                  0xa8
+#define OV9650_ACOMA9                  0xa9
+
+#define OV9650_REGISTER_RESET          (1 << 7)
+#define OV9650_VGA_SELECT              (1 << 6)
+#define OV9650_RGB_SELECT              (1 << 2)
+#define OV9650_RAW_RGB_SELECT          (1 << 0)
+
+#define OV9650_FAST_AGC_AEC            (1 << 7)
+#define OV9650_AEC_UNLIM_STEP_SIZE     (1 << 6)
+#define OV9650_BANDING                 (1 << 5)
+#define OV9650_AGC_EN                  (1 << 2)
+#define OV9650_AWB_EN                  (1 << 1)
+#define OV9650_AEC_EN                  (1 << 0)
+
+#define OV9650_VARIOPIXEL              (1 << 2)
+#define OV9650_SYSTEM_CLK_SEL          (1 << 7)
+#define OV9650_SLAM_MODE               (1 << 4)
+
+#define OV9650_VFLIP                   (1 << 4)
+#define OV9650_HFLIP                   (1 << 5)
+
+#define GAIN_DEFAULT                   0x14
+#define RED_GAIN_DEFAULT               0x70
+#define BLUE_GAIN_DEFAULT              0x20
+#define EXPOSURE_DEFAULT               0x5003
+
+/*****************************************************************************/
+
+/* Kernel module parameters */
+extern int force_sensor;
+extern int dump_sensor;
+extern unsigned int m5602_debug;
+
+int ov9650_probe(struct sd *sd);
+int ov9650_init(struct sd *sd);
+int ov9650_power_down(struct sd *sd);
+
+int ov9650_read_sensor(struct sd *sd, const u8 address,
+                      u8 *i2c_data, const u8 len);
+int ov9650_write_sensor(struct sd *sd, const u8 address,
+                      u8 *i2c_data, const u8 len);
+
+void ov9650_dump_registers(struct sd *sd);
+
+int ov9650_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_gain(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_auto_white_balance(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_auto_white_balance(struct gspca_dev *gspca_dev, __s32 val);
+int ov9650_get_auto_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int ov9650_set_auto_gain(struct gspca_dev *gspca_dev, __s32 val);
+
+static struct m5602_sensor ov9650 = {
+       .name = "OV9650",
+       .i2c_slave_id = 0x60,
+       .probe = ov9650_probe,
+       .init = ov9650_init,
+       .power_down = ov9650_power_down,
+       .read_sensor = ov9650_read_sensor,
+       .write_sensor = ov9650_write_sensor,
+
+       .nctrls = 8,
+       .ctrls = {
+       {
+               {
+                       .id             = V4L2_CID_EXPOSURE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "exposure",
+                       .minimum        = 0x00,
+                       .maximum        = 0xffff,
+                       .step           = 0x1,
+                       .default_value  = EXPOSURE_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = ov9650_set_exposure,
+               .get = ov9650_get_exposure
+       }, {
+               {
+                       .id             = V4L2_CID_GAIN,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "gain",
+                       .minimum        = 0x00,
+                       .maximum        = 0x3ff,
+                       .step           = 0x1,
+                       .default_value  = GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = ov9650_set_gain,
+               .get = ov9650_get_gain
+       }, {
+               {
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "red balance",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = RED_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = ov9650_set_red_balance,
+               .get = ov9650_get_red_balance
+       }, {
+               {
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "blue balance",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = BLUE_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = ov9650_set_blue_balance,
+               .get = ov9650_get_blue_balance
+       }, {
+               {
+                       .id             = V4L2_CID_HFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "horizontal flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = ov9650_set_hflip,
+               .get = ov9650_get_hflip
+       }, {
+               {
+                       .id             = V4L2_CID_VFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "vertical flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = ov9650_set_vflip,
+               .get = ov9650_get_vflip
+       }, {
+               {
+                       .id             = V4L2_CID_AUTO_WHITE_BALANCE,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "auto white balance",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = ov9650_set_auto_white_balance,
+               .get = ov9650_get_auto_white_balance
+       }, {
+               {
+                       .id             = V4L2_CID_AUTOGAIN,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "auto gain control",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = ov9650_set_auto_gain,
+               .get = ov9650_get_auto_gain
+       }
+       },
+
+       .nmodes = 1,
+       .modes = {
+       {
+               M5602_DEFAULT_FRAME_WIDTH,
+               M5602_DEFAULT_FRAME_HEIGHT,
+               V4L2_PIX_FMT_SBGGR8,
+               V4L2_FIELD_NONE,
+               .sizeimage =
+                       M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
+               .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 1
+       }
+       }
+};
+
+static const unsigned char preinit_ov9650[][3] =
+{
+       /* [INITCAM] */
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
+
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
+       /* Reset chip */
+       {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
+       /* Enable double clock */
+       {SENSOR, OV9650_CLKRC, 0x80},
+       /* Do something out of spec with the power */
+       {SENSOR, OV9650_OFON, 0x40}
+};
+
+static const unsigned char init_ov9650[][3] =
+{
+       /* [INITCAM] */
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
+
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x0a},
+       /* Reset chip */
+       {SENSOR, OV9650_COM7, OV9650_REGISTER_RESET},
+       /* Enable double clock */
+       {SENSOR, OV9650_CLKRC, 0x80},
+       /* Do something out of spec with the power */
+       {SENSOR, OV9650_OFON, 0x40},
+
+       /* Set QQVGA */
+       {SENSOR, OV9650_COM1, 0x20},
+       /* Set fast AGC/AEC algorithm with unlimited step size */
+       {SENSOR, OV9650_COM8, OV9650_FAST_AGC_AEC |
+                             OV9650_AEC_UNLIM_STEP_SIZE |
+                             OV9650_AWB_EN | OV9650_AGC_EN},
+
+       {SENSOR, OV9650_CHLF, 0x10},
+       {SENSOR, OV9650_ARBLM, 0xbf},
+       {SENSOR, OV9650_ACOM38, 0x81},
+       /* Turn off color matrix coefficient double option */
+       {SENSOR, OV9650_COM16, 0x00},
+               /* Enable color matrix for RGB/YUV, Delay Y channel,
+       set output Y/UV delay to 1 */
+       {SENSOR, OV9650_COM13, 0x19},
+       /* Enable digital BLC, Set output mode to U Y V Y */
+       {SENSOR, OV9650_TSLB, 0x0c},
+       /* Limit the AGC/AEC stable upper region */
+       {SENSOR, OV9650_COM24, 0x00},
+       /* Enable HREF and some out of spec things */
+       {SENSOR, OV9650_COM12, 0x73},
+               /* Set all DBLC offset signs to positive and
+       do some out of spec stuff */
+       {SENSOR, OV9650_DBLC1, 0xdf},
+       {SENSOR, OV9650_COM21, 0x06},
+       {SENSOR, OV9650_RSVD35, 0x91},
+       /* Necessary, no camera stream without it */
+       {SENSOR, OV9650_RSVD16, 0x06},
+       {SENSOR, OV9650_RSVD94, 0x99},
+       {SENSOR, OV9650_RSVD95, 0x99},
+       {SENSOR, OV9650_RSVD96, 0x04},
+       /* Enable full range output */
+       {SENSOR, OV9650_COM15, 0x0},
+               /* Enable HREF at optical black, enable ADBLC bias,
+       enable ADBLC, reset timings at format change */
+       {SENSOR, OV9650_COM6, 0x4b},
+       /* Subtract 32 from the B channel bias */
+       {SENSOR, OV9650_BBIAS, 0xa0},
+       /* Subtract 32 from the Gb channel bias */
+       {SENSOR, OV9650_GbBIAS, 0xa0},
+       /* Do not bypass the analog BLC and to some out of spec stuff */
+       {SENSOR, OV9650_Gr_COM, 0x00},
+       /* Subtract 32 from the R channel bias */
+       {SENSOR, OV9650_RBIAS, 0xa0},
+       /* Subtract 32 from the R channel bias */
+       {SENSOR, OV9650_RBIAS, 0x0},
+       {SENSOR, OV9650_COM26, 0x80},
+       {SENSOR, OV9650_ACOMA9, 0x98},
+       /* Set the AGC/AEC stable region upper limit */
+       {SENSOR, OV9650_AEW, 0x68},
+       /* Set the AGC/AEC stable region lower limit */
+       {SENSOR, OV9650_AEB, 0x5c},
+       /* Set the high and low limit nibbles to 3 */
+       {SENSOR, OV9650_VPT, 0xc3},
+               /* Set the Automatic Gain Ceiling (AGC) to 128x,
+       drop VSYNC at frame drop,
+       limit exposure timing,
+       drop frame when the AEC step is larger than the exposure gap */
+       {SENSOR, OV9650_COM9, 0x6e},
+       /* Set VSYNC negative, Set RESET to SLHS (slave mode horizontal sync)
+       and set PWDN to SLVS (slave mode vertical sync) */
+       {SENSOR, OV9650_COM10, 0x42},
+       /* Set horizontal column start high to default value */
+       {SENSOR, OV9650_HSTART, 0x1a},
+       /* Set horizontal column end */
+       {SENSOR, OV9650_HSTOP, 0xbf},
+       /* Complementing register to the two writes above */
+       {SENSOR, OV9650_HREF, 0xb2},
+       /* Set vertical row start high bits */
+       {SENSOR, OV9650_VSTRT, 0x02},
+       /* Set vertical row end low bits */
+       {SENSOR, OV9650_VSTOP, 0x7e},
+       /* Set complementing vertical frame control */
+       {SENSOR, OV9650_VREF, 0x10},
+       /* Set raw RGB output format with VGA resolution */
+       {SENSOR, OV9650_COM7, OV9650_VGA_SELECT |
+                             OV9650_RGB_SELECT |
+                             OV9650_RAW_RGB_SELECT},
+       {SENSOR, OV9650_ADC, 0x04},
+       {SENSOR, OV9650_HV, 0x40},
+       /* Enable denoise, and white-pixel erase */
+       {SENSOR, OV9650_COM22, 0x23},
+
+       /* Set the high bits of the exposure value */
+       {SENSOR, OV9650_AECH, ((EXPOSURE_DEFAULT & 0xff00) >> 8)},
+
+       /* Set the low bits of the exposure value */
+       {SENSOR, OV9650_COM1, (EXPOSURE_DEFAULT & 0xff)},
+       {SENSOR, OV9650_GAIN, GAIN_DEFAULT},
+       {SENSOR, OV9650_BLUE, BLUE_GAIN_DEFAULT},
+       {SENSOR, OV9650_RED, RED_GAIN_DEFAULT},
+
+       {SENSOR, OV9650_COM3, OV9650_VARIOPIXEL},
+       {SENSOR, OV9650_COM5, OV9650_SYSTEM_CLK_SEL},
+
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x82},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_L, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_L, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x09},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x5e},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0xde}
+};
+
+static const unsigned char power_down_ov9650[][3] =
+{
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {SENSOR, OV9650_COM7, 0x80},
+       {SENSOR, OV9650_OFON, 0xf4},
+       {SENSOR, OV9650_MVFP, 0x80},
+       {SENSOR, OV9650_DBLV, 0x3f},
+       {SENSOR, OV9650_RSVD36, 0x49},
+       {SENSOR, OV9650_COM7, 0x05},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0}
+};
+
+/* Vertically and horizontally flips the image if matched, needed for machines
+   where the sensor is mounted upside down */
+static
+    const
+       struct dmi_system_id ov9650_flip_dmi_table[] = {
+       {
+               .ident = "ASUS A6VC",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "A6VC")
+               }
+       },
+       {
+               .ident = "ASUS A6VM",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "A6VM")
+               }
+       },
+       {
+               .ident = "ASUS A6JC",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "A6JC")
+               }
+       },
+       {
+               .ident = "ASUS A6Kt",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "ASUSTeK Computer Inc."),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "A6Kt")
+               }
+       },
+       { }
+};
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.c b/drivers/media/video/gspca/m5602/m5602_po1030.c
new file mode 100644 (file)
index 0000000..08c015b
--- /dev/null
@@ -0,0 +1,336 @@
+/*
+ * Driver for the po1030 sensor
+ *
+ * Copyright (c) 2008 Erik Andren
+ * Copyright (c) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (c) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_po1030.h"
+
+int po1030_probe(struct sd *sd)
+{
+       u8 prod_id = 0, ver_id = 0, i;
+
+       if (force_sensor) {
+               if (force_sensor == PO1030_SENSOR) {
+                       info("Forcing a %s sensor", po1030.name);
+                       goto sensor_found;
+               }
+               /* If we want to force another sensor, don't try to probe this
+                * one */
+               return -ENODEV;
+       }
+
+       info("Probing for a po1030 sensor");
+
+       /* Run the pre-init to actually probe the unit */
+       for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) {
+               u8 data = preinit_po1030[i][2];
+               if (preinit_po1030[i][0] == SENSOR)
+                       po1030_write_sensor(sd,
+                               preinit_po1030[i][1], &data, 1);
+               else
+                       m5602_write_bridge(sd, preinit_po1030[i][1], data);
+       }
+
+       if (po1030_read_sensor(sd, 0x3, &prod_id, 1))
+               return -ENODEV;
+
+       if (po1030_read_sensor(sd, 0x4, &ver_id, 1))
+               return -ENODEV;
+
+       if ((prod_id == 0x02) && (ver_id == 0xef)) {
+               info("Detected a po1030 sensor");
+               goto sensor_found;
+       }
+       return -ENODEV;
+
+sensor_found:
+       sd->gspca_dev.cam.cam_mode = po1030.modes;
+       sd->gspca_dev.cam.nmodes = po1030.nmodes;
+       sd->desc->ctrls = po1030.ctrls;
+       sd->desc->nctrls = po1030.nctrls;
+       return 0;
+}
+
+int po1030_read_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len)
+{
+       int err, i;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+
+       m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
+                          sd->sensor->i2c_slave_id);
+       m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
+       m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x10 + len);
+       m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x08);
+
+       for (i = 0; i < len; i++) {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
+
+               PDEBUG(DBG_TRACE, "Reading sensor register "
+                               "0x%x containing 0x%x ", address, *i2c_data);
+       }
+       return (err < 0) ? err : 0;
+}
+
+int po1030_write_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len)
+{
+       int err, i;
+       u8 *p;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* The po1030 only supports one byte writes */
+       if (len > 1 || !len)
+               return -EINVAL;
+
+       memcpy(buf, sensor_urb_skeleton, sizeof(sensor_urb_skeleton));
+
+       buf[11] = sd->sensor->i2c_slave_id;
+       buf[15] = address;
+
+       p = buf + 16;
+
+       /* Copy a four byte write sequence for each byte to be written to */
+       for (i = 0; i < len; i++) {
+               memcpy(p, sensor_urb_skeleton + 16, 4);
+               p[3] = i2c_data[i];
+               p += 4;
+               PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
+                      address, i2c_data[i]);
+       }
+
+       /* Copy the footer */
+       memcpy(p, sensor_urb_skeleton + 20, 4);
+
+       /* Set the total length */
+       p[3] = 0x10 + len;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                             0x04, 0x40, 0x19,
+                             0x0000, buf,
+                             20 + len * 4, M5602_URB_MSG_TIMEOUT);
+
+       return (err < 0) ? err : 0;
+}
+
+int po1030_init(struct sd *sd)
+{
+       int i, err = 0;
+
+       /* Init the sensor */
+       for (i = 0; i < ARRAY_SIZE(init_po1030); i++) {
+               u8 data[2] = {0x00, 0x00};
+
+               switch (init_po1030[i][0]) {
+               case BRIDGE:
+                       err = m5602_write_bridge(sd,
+                               init_po1030[i][1],
+                               init_po1030[i][2]);
+                       break;
+
+               case SENSOR:
+                       data[0] = init_po1030[i][2];
+                       err = po1030_write_sensor(sd,
+                               init_po1030[i][1], data, 1);
+                       break;
+
+               case SENSOR_LONG:
+                       data[0] = init_po1030[i][2];
+                       data[1] = init_po1030[i][3];
+                       err = po1030_write_sensor(sd,
+                               init_po1030[i][1], data, 2);
+                       break;
+               default:
+                       info("Invalid stream command, exiting init");
+                       return -EINVAL;
+               }
+       }
+
+       if (dump_sensor)
+               po1030_dump_registers(sd);
+
+       return (err < 0) ? err : 0;
+}
+
+int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       err = po1030_read_sensor(sd, PO1030_REG_INTEGLINES_H,
+                                &i2c_data, 1);
+       if (err < 0)
+               goto out;
+       *val = (i2c_data << 8);
+
+       err = po1030_read_sensor(sd, PO1030_REG_INTEGLINES_M,
+                                &i2c_data, 1);
+       *val |= i2c_data;
+
+       PDEBUG(DBG_V4L2_CID, "Exposure read as %d", *val);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       PDEBUG(DBG_V4L2, "Set exposure to %d", val & 0xffff);
+
+       i2c_data = ((val & 0xff00) >> 8);
+       PDEBUG(DBG_V4L2, "Set exposure to high byte to 0x%x",
+              i2c_data);
+
+       err = po1030_write_sensor(sd, PO1030_REG_INTEGLINES_H,
+                                 &i2c_data, 1);
+       if (err < 0)
+               goto out;
+
+       i2c_data = (val & 0xff);
+       PDEBUG(DBG_V4L2, "Set exposure to low byte to 0x%x",
+              i2c_data);
+       err = po1030_write_sensor(sd, PO1030_REG_INTEGLINES_M,
+                                 &i2c_data, 1);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       err = po1030_read_sensor(sd, PO1030_REG_GLOBALGAIN,
+                                &i2c_data, 1);
+       *val = i2c_data;
+       PDEBUG(DBG_V4L2_CID, "Read global gain %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       i2c_data = val & 0xff;
+       PDEBUG(DBG_V4L2, "Set global gain to %d", i2c_data);
+       err = po1030_write_sensor(sd, PO1030_REG_GLOBALGAIN,
+                                 &i2c_data, 1);
+       return (err < 0) ? err : 0;
+}
+
+int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       err = po1030_read_sensor(sd, PO1030_REG_RED_GAIN,
+                                &i2c_data, 1);
+       *val = i2c_data;
+       PDEBUG(DBG_V4L2_CID, "Read red gain %d", *val);
+       return (err < 0) ? err : 0;
+}
+
+int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       i2c_data = val & 0xff;
+       PDEBUG(DBG_V4L2, "Set red gain to %d", i2c_data);
+       err = po1030_write_sensor(sd, PO1030_REG_RED_GAIN,
+                                 &i2c_data, 1);
+       return (err < 0) ? err : 0;
+}
+
+int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+
+       err = po1030_read_sensor(sd, PO1030_REG_BLUE_GAIN,
+                                &i2c_data, 1);
+       *val = i2c_data;
+       PDEBUG(DBG_V4L2_CID, "Read blue gain %d", *val);
+
+       return (err < 0) ? err : 0;
+}
+
+int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 i2c_data;
+       int err;
+       i2c_data = val & 0xff;
+       PDEBUG(DBG_V4L2, "Set blue gain to %d", i2c_data);
+       err = po1030_write_sensor(sd, PO1030_REG_BLUE_GAIN,
+                                 &i2c_data, 1);
+
+       return (err < 0) ? err : 0;
+}
+
+int po1030_power_down(struct sd *sd)
+{
+       return 0;
+}
+
+void po1030_dump_registers(struct sd *sd)
+{
+       int address;
+       u8 value = 0;
+
+       info("Dumping the po1030 sensor core registers");
+       for (address = 0; address < 0x7f; address++) {
+               po1030_read_sensor(sd, address, &value, 1);
+               info("register 0x%x contains 0x%x",
+                    address, value);
+       }
+
+       info("po1030 register state dump complete");
+
+       info("Probing for which registers that are read/write");
+       for (address = 0; address < 0xff; address++) {
+               u8 old_value, ctrl_value;
+               u8 test_value[2] = {0xff, 0xff};
+
+               po1030_read_sensor(sd, address, &old_value, 1);
+               po1030_write_sensor(sd, address, test_value, 1);
+               po1030_read_sensor(sd, address, &ctrl_value, 1);
+
+               if (ctrl_value == test_value[0])
+                       info("register 0x%x is writeable", address);
+               else
+                       info("register 0x%x is read only", address);
+
+               /* Restore original value */
+               po1030_write_sensor(sd, address, &old_value, 1);
+       }
+}
diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.h b/drivers/media/video/gspca/m5602/m5602_po1030.h
new file mode 100644 (file)
index 0000000..68f34c9
--- /dev/null
@@ -0,0 +1,478 @@
+/*
+ * Driver for the po1030 sensor.
+ * This is probably a pixel plus sensor but we haven't identified it yet
+ *
+ * Copyright (c) 2008 Erik Andren
+ * Copyright (c) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (c) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * Register defines taken from Pascal Stangs Proxycon Armlib
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_PO1030_H_
+#define M5602_PO1030_H_
+
+#include "m5602_sensor.h"
+
+/*****************************************************************************/
+
+#define PO1030_REG_DEVID_H             0x00
+#define PO1030_REG_DEVID_L             0x01
+#define PO1030_REG_FRAMEWIDTH_H                0x04
+#define PO1030_REG_FRAMEWIDTH_L                0x05
+#define PO1030_REG_FRAMEHEIGHT_H       0x06
+#define PO1030_REG_FRAMEHEIGHT_L       0x07
+#define PO1030_REG_WINDOWX_H           0x08
+#define PO1030_REG_WINDOWX_L           0x09
+#define PO1030_REG_WINDOWY_H           0x0a
+#define PO1030_REG_WINDOWY_L           0x0b
+#define PO1030_REG_WINDOWWIDTH_H       0x0c
+#define PO1030_REG_WINDOWWIDTH_L       0x0d
+#define PO1030_REG_WINDOWHEIGHT_H      0x0e
+#define PO1030_REG_WINDOWHEIGHT_L      0x0f
+
+#define PO1030_REG_GLOBALIBIAS         0x12
+#define PO1030_REG_PIXELIBIAS          0x13
+
+#define PO1030_REG_GLOBALGAIN          0x15
+#define PO1030_REG_RED_GAIN            0x16
+#define PO1030_REG_GREEN_1_GAIN                0x17
+#define PO1030_REG_BLUE_GAIN           0x18
+#define PO1030_REG_GREEN_2_GAIN                0x19
+
+#define PO1030_REG_INTEGLINES_H                0x1a
+#define PO1030_REG_INTEGLINES_M                0x1b
+#define PO1030_REG_INTEGLINES_L                0x1c
+
+#define PO1030_REG_CONTROL1            0x1d
+#define PO1030_REG_CONTROL2            0x1e
+#define PO1030_REG_CONTROL3            0x1f
+#define PO1030_REG_CONTROL4            0x20
+
+#define PO1030_REG_PERIOD50_H          0x23
+#define PO1030_REG_PERIOD50_L          0x24
+#define PO1030_REG_PERIOD60_H          0x25
+#define PO1030_REG_PERIOD60_L          0x26
+#define PO1030_REG_REGCLK167           0x27
+#define PO1030_REG_DELTA50             0x28
+#define PO1030_REG_DELTA60             0x29
+
+#define PO1030_REG_ADCOFFSET           0x2c
+
+/* Gamma Correction Coeffs */
+#define PO1030_REG_GC0                 0x2d
+#define PO1030_REG_GC1                 0x2e
+#define PO1030_REG_GC2                 0x2f
+#define PO1030_REG_GC3                 0x30
+#define PO1030_REG_GC4                 0x31
+#define PO1030_REG_GC5                 0x32
+#define PO1030_REG_GC6                 0x33
+#define PO1030_REG_GC7                 0x34
+
+/* Color Transform Matrix */
+#define PO1030_REG_CT0                 0x35
+#define PO1030_REG_CT1                 0x36
+#define PO1030_REG_CT2                 0x37
+#define PO1030_REG_CT3                 0x38
+#define PO1030_REG_CT4                 0x39
+#define PO1030_REG_CT5                 0x3a
+#define PO1030_REG_CT6                 0x3b
+#define PO1030_REG_CT7                 0x3c
+#define PO1030_REG_CT8                 0x3d
+
+#define PO1030_REG_AUTOCTRL1           0x3e
+#define PO1030_REG_AUTOCTRL2           0x3f
+
+#define PO1030_REG_YTARGET             0x40
+#define PO1030_REG_GLOBALGAINMIN       0x41
+#define PO1030_REG_GLOBALGAINMAX       0x42
+
+/* Output format control */
+#define PO1030_REG_OUTFORMCTRL1                0x5a
+#define PO1030_REG_OUTFORMCTRL2                0x5b
+#define PO1030_REG_OUTFORMCTRL3                0x5c
+#define PO1030_REG_OUTFORMCTRL4                0x5d
+#define PO1030_REG_OUTFORMCTRL5                0x5e
+
+/* Imaging coefficients */
+#define PO1030_REG_YBRIGHT             0x73
+#define PO1030_REG_YCONTRAST           0x74
+#define PO1030_REG_YSATURATION         0x75
+
+/*****************************************************************************/
+
+#define PO1030_GLOBAL_GAIN_DEFAULT     0x12
+#define PO1030_EXPOSURE_DEFAULT                0xf0ff
+#define PO1030_BLUE_GAIN_DEFAULT       0x40
+#define PO1030_RED_GAIN_DEFAULT        0x40
+
+/*****************************************************************************/
+
+/* Kernel module parameters */
+extern int force_sensor;
+extern int dump_sensor;
+extern unsigned int m5602_debug;
+
+int po1030_probe(struct sd *sd);
+int po1030_init(struct sd *sd);
+int po1030_power_down(struct sd *sd);
+
+void po1030_dump_registers(struct sd *sd);
+
+int po1030_read_sensor(struct sd *sd, const u8 address,
+                             u8 *i2c_data, const u8 len);
+int po1030_write_sensor(struct sd *sd, const u8 address,
+                              u8 *i2c_data, const u8 len);
+
+int po1030_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
+int po1030_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
+int po1030_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int po1030_set_gain(struct gspca_dev *gspca_dev, __s32 val);
+int po1030_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val);
+int po1030_set_red_balance(struct gspca_dev *gspca_dev, __s32 val);
+int po1030_get_blue_balance(struct gspca_dev *gspca_dev, __s32 *val);
+int po1030_set_blue_balance(struct gspca_dev *gspca_dev, __s32 val);
+
+static struct m5602_sensor po1030 = {
+       .name = "PO1030",
+
+       .i2c_slave_id = 0xdc,
+
+       .probe = po1030_probe,
+       .init = po1030_init,
+       .power_down = po1030_power_down,
+
+       .nctrls = 4,
+       .ctrls = {
+       {
+               {
+                       .id             = V4L2_CID_GAIN,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "gain",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = PO1030_GLOBAL_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = po1030_set_gain,
+               .get = po1030_get_gain
+       }, {
+               {
+                       .id             = V4L2_CID_EXPOSURE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "exposure",
+                       .minimum        = 0x00,
+                       .maximum        = 0xffff,
+                       .step           = 0x1,
+                       .default_value  = PO1030_EXPOSURE_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = po1030_set_exposure,
+               .get = po1030_get_exposure
+       }, {
+               {
+                       .id             = V4L2_CID_RED_BALANCE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "red balance",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = PO1030_RED_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = po1030_set_red_balance,
+               .get = po1030_get_red_balance
+       }, {
+               {
+                       .id             = V4L2_CID_BLUE_BALANCE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "blue balance",
+                       .minimum        = 0x00,
+                       .maximum        = 0xff,
+                       .step           = 0x1,
+                       .default_value  = PO1030_BLUE_GAIN_DEFAULT,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = po1030_set_blue_balance,
+               .get = po1030_get_blue_balance
+       }
+       },
+       .nmodes = 1,
+       .modes = {
+       {
+               M5602_DEFAULT_FRAME_WIDTH,
+               M5602_DEFAULT_FRAME_HEIGHT,
+               V4L2_PIX_FMT_SBGGR8,
+               V4L2_FIELD_NONE,
+               .sizeimage =
+                       M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
+               .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 1
+       }
+       }
+};
+
+static const unsigned char preinit_po1030[][3] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+
+       {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+
+       {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00}
+};
+
+static const unsigned char init_po1030[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0},
+       /*sequence 1*/
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d},
+
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       /*end of sequence 1*/
+
+       /*sequence 2 (same as stop sequence)*/
+       {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       /*end of sequence 2*/
+
+       /*sequence 5*/
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x87},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       /*end of sequence 5*/
+
+       /*sequence 2 stop */
+       {SENSOR, PO1030_REG_AUTOCTRL2, 0x24},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x04},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x02},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x04},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       /*end of sequence 2 stop */
+
+/* ---------------------------------
+ * end of init - begin of start
+ * --------------------------------- */
+
+       /*sequence 3*/
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       /*end of sequence 3*/
+       /*sequence 4*/
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x05},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00},
+
+       {SENSOR, PO1030_REG_AUTOCTRL2, 0x04},
+
+       /* Set the width to 751 */
+       {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
+       {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef},
+
+       /* Set the height to 540 */
+       {SENSOR, PO1030_REG_FRAMEHEIGHT_H, 0x02},
+       {SENSOR, PO1030_REG_FRAMEHEIGHT_L, 0x1c},
+
+       /* Set the x window to 1 */
+       {SENSOR, PO1030_REG_WINDOWX_H, 0x00},
+       {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
+
+       /* Set the y window to 1 */
+       {SENSOR, PO1030_REG_WINDOWY_H, 0x00},
+       {SENSOR, PO1030_REG_WINDOWX_L, 0x01},
+
+       {SENSOR, PO1030_REG_WINDOWWIDTH_H, 0x02},
+       {SENSOR, PO1030_REG_WINDOWWIDTH_L, 0x87},
+       {SENSOR, PO1030_REG_WINDOWHEIGHT_H, 0x01},
+       {SENSOR, PO1030_REG_WINDOWHEIGHT_L, 0xe3},
+
+       {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
+       {SENSOR, PO1030_REG_OUTFORMCTRL2, 0x04},
+       {SENSOR, PO1030_REG_AUTOCTRL1, 0x08},
+       {SENSOR, PO1030_REG_CONTROL2, 0x03},
+       {SENSOR, 0x21, 0x90},
+       {SENSOR, PO1030_REG_YTARGET, 0x60},
+       {SENSOR, 0x59, 0x13},
+       {SENSOR, PO1030_REG_OUTFORMCTRL1, 0x40},
+       {SENSOR, 0x5f, 0x00},
+       {SENSOR, 0x60, 0x80},
+       {SENSOR, 0x78, 0x14},
+       {SENSOR, 0x6f, 0x01},
+       {SENSOR, PO1030_REG_CONTROL1, 0x18},
+       {SENSOR, PO1030_REG_GLOBALGAINMAX, 0x14},
+       {SENSOR, 0x63, 0x38},
+       {SENSOR, 0x64, 0x38},
+       {SENSOR, PO1030_REG_CONTROL1, 0x58},
+       {SENSOR, PO1030_REG_RED_GAIN, 0x30},
+       {SENSOR, PO1030_REG_GREEN_1_GAIN, 0x30},
+       {SENSOR, PO1030_REG_BLUE_GAIN, 0x30},
+       {SENSOR, PO1030_REG_GREEN_2_GAIN, 0x30},
+       {SENSOR, PO1030_REG_GC0, 0x10},
+       {SENSOR, PO1030_REG_GC1, 0x20},
+       {SENSOR, PO1030_REG_GC2, 0x40},
+       {SENSOR, PO1030_REG_GC3, 0x60},
+       {SENSOR, PO1030_REG_GC4, 0x80},
+       {SENSOR, PO1030_REG_GC5, 0xa0},
+       {SENSOR, PO1030_REG_GC6, 0xc0},
+       {SENSOR, PO1030_REG_GC7, 0xff},
+       /*end of sequence 4*/
+       /*sequence 5*/
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0c},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xec},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x7e},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00},
+       /*end of sequence 5*/
+
+       /*sequence 6*/
+       /* Changing 40 in f0 the image becomes green in bayer mode and red in
+        * rgb mode */
+       {SENSOR, PO1030_REG_RED_GAIN, PO1030_RED_GAIN_DEFAULT},
+       /* in changing 40 in f0 the image becomes green in bayer mode and red in
+        * rgb mode */
+       {SENSOR, PO1030_REG_BLUE_GAIN, PO1030_BLUE_GAIN_DEFAULT},
+
+       /* with a very low lighted environment increase the exposure but
+        * decrease the FPS (Frame Per Second) */
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0},
+
+       /* Controls high exposure more than SENSOR_LOW_EXPOSURE, use only in
+        * low lighted environment (f0 is more than ff ?)*/
+       {SENSOR, PO1030_REG_INTEGLINES_H, ((PO1030_EXPOSURE_DEFAULT >> 2)
+               & 0xff)},
+
+       /* Controls middle exposure, use only in high lighted environment */
+       {SENSOR, PO1030_REG_INTEGLINES_M, PO1030_EXPOSURE_DEFAULT & 0xff},
+
+       /* Controls clarity (not sure) */
+       {SENSOR, PO1030_REG_INTEGLINES_L, 0x00},
+       /* Controls gain (the image is more lighted) */
+       {SENSOR, PO1030_REG_GLOBALGAIN, PO1030_GLOBAL_GAIN_DEFAULT},
+
+       /* Sets the width */
+       {SENSOR, PO1030_REG_FRAMEWIDTH_H, 0x02},
+       {SENSOR, PO1030_REG_FRAMEWIDTH_L, 0xef}
+       /*end of sequence 6*/
+};
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c
new file mode 100644 (file)
index 0000000..6820256
--- /dev/null
@@ -0,0 +1,463 @@
+/*
+ * Driver for the s5k4aa sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_s5k4aa.h"
+
+int s5k4aa_probe(struct sd *sd)
+{
+       u8 prod_id[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
+       const u8 expected_prod_id[6] = {0x00, 0x10, 0x00, 0x4b, 0x33, 0x75};
+       int i, err = 0;
+
+       if (force_sensor) {
+               if (force_sensor == S5K4AA_SENSOR) {
+                       info("Forcing a %s sensor", s5k4aa.name);
+                       goto sensor_found;
+               }
+               /* If we want to force another sensor, don't try to probe this
+                * one */
+               return -ENODEV;
+       }
+
+       info("Probing for a s5k4aa sensor");
+
+       /* Preinit the sensor */
+       for (i = 0; i < ARRAY_SIZE(preinit_s5k4aa) && !err; i++) {
+               u8 data[2] = {0x00, 0x00};
+
+               switch (preinit_s5k4aa[i][0]) {
+               case BRIDGE:
+                       err = m5602_write_bridge(sd,
+                                                preinit_s5k4aa[i][1],
+                                                preinit_s5k4aa[i][2]);
+                       break;
+
+               case SENSOR:
+                       data[0] = preinit_s5k4aa[i][2];
+                       err = s5k4aa_write_sensor(sd,
+                                                 preinit_s5k4aa[i][1],
+                                                 data, 1);
+                       break;
+
+               case SENSOR_LONG:
+                       data[0] = preinit_s5k4aa[i][2];
+                       data[1] = preinit_s5k4aa[i][3];
+                       err = s5k4aa_write_sensor(sd,
+                                                 preinit_s5k4aa[i][1],
+                                                 data, 2);
+                       break;
+               default:
+                       info("Invalid stream command, exiting init");
+                       return -EINVAL;
+               }
+       }
+
+       /* Test some registers, but we don't know their exact meaning yet */
+       if (s5k4aa_read_sensor(sd, 0x00, prod_id, sizeof(prod_id)))
+               return -ENODEV;
+
+       if (memcmp(prod_id, expected_prod_id, sizeof(prod_id)))
+               return -ENODEV;
+       else
+               info("Detected a s5k4aa sensor");
+sensor_found:
+       sd->gspca_dev.cam.cam_mode = s5k4aa.modes;
+       sd->gspca_dev.cam.nmodes = s5k4aa.nmodes;
+       sd->desc->ctrls = s5k4aa.ctrls;
+       sd->desc->nctrls = s5k4aa.nctrls;
+
+       return 0;
+}
+
+int s5k4aa_read_sensor(struct sd *sd, const u8 address,
+                      u8 *i2c_data, const u8 len)
+{
+       int err, i;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
+                                sd->sensor->i2c_slave_id);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
+       if (err < 0)
+               goto out;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+       if (err < 0)
+               goto out;
+
+       for (i = 0; (i < len) & !err; i++) {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
+
+               PDEBUG(DBG_TRACE, "Reading sensor register "
+                                 "0x%x containing 0x%x ", address, *i2c_data);
+       }
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_write_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len)
+{
+       int err, i;
+       u8 *p;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* No sensor with a data width larger than 16 bits has yet been seen */
+       if (len > 2 || !len)
+               return -EINVAL;
+
+       memcpy(buf, sensor_urb_skeleton,
+              sizeof(sensor_urb_skeleton));
+
+       buf[11] = sd->sensor->i2c_slave_id;
+       buf[15] = address;
+
+       /* Special case larger sensor writes */
+       p = buf + 16;
+
+       /* Copy a four byte write sequence for each byte to be written to */
+       for (i = 0; i < len; i++) {
+               memcpy(p, sensor_urb_skeleton + 16, 4);
+               p[3] = i2c_data[i];
+               p += 4;
+               PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
+                      address, i2c_data[i]);
+       }
+
+       /* Copy the tailer */
+       memcpy(p, sensor_urb_skeleton + 20, 4);
+
+       /* Set the total length */
+       p[3] = 0x10 + len;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                             0x04, 0x40, 0x19,
+                             0x0000, buf,
+                             20 + len * 4, M5602_URB_MSG_TIMEOUT);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_init(struct sd *sd)
+{
+       int i, err = 0;
+
+       for (i = 0; i < ARRAY_SIZE(init_s5k4aa) && !err; i++) {
+               u8 data[2] = {0x00, 0x00};
+
+               switch (init_s5k4aa[i][0]) {
+               case BRIDGE:
+                       err = m5602_write_bridge(sd,
+                               init_s5k4aa[i][1],
+                               init_s5k4aa[i][2]);
+                       break;
+
+               case SENSOR:
+                       data[0] = init_s5k4aa[i][2];
+                       err = s5k4aa_write_sensor(sd,
+                               init_s5k4aa[i][1], data, 1);
+                       break;
+
+               case SENSOR_LONG:
+                       data[0] = init_s5k4aa[i][2];
+                       data[1] = init_s5k4aa[i][3];
+                       err = s5k4aa_write_sensor(sd,
+                               init_s5k4aa[i][1], data, 2);
+                       break;
+               default:
+                       info("Invalid stream command, exiting init");
+                       return -EINVAL;
+               }
+       }
+
+       if (dump_sensor)
+               s5k4aa_dump_registers(sd);
+
+       if (!err && dmi_check_system(s5k4aa_vflip_dmi_table)) {
+               u8 data = 0x02;
+               info("vertical flip quirk active");
+               s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+               s5k4aa_read_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+               data |= S5K4AA_RM_V_FLIP;
+               data &= ~S5K4AA_RM_H_FLIP;
+               s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+
+               /* Decrement COLSTART to preserve color order (BGGR) */
+               s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+               data--;
+               s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+
+               /* Increment ROWSTART to preserve color order (BGGR) */
+               s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+               data++;
+               s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+       }
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_power_down(struct sd *sd)
+{
+       return 0;
+}
+
+int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+
+       err = s5k4aa_read_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
+       if (err < 0)
+               goto out;
+
+       *val = data << 8;
+       err = s5k4aa_read_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
+       *val |= data;
+       PDEBUG(DBG_V4L2_CID, "Read exposure %d", *val);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       PDEBUG(DBG_V4L2_CID, "Set exposure to %d", val);
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+       data = (val >> 8) & 0xff;
+       err = s5k4aa_write_sensor(sd, S5K4AA_EXPOSURE_HI, &data, 1);
+       if (err < 0)
+               goto out;
+       data = val & 0xff;
+       err = s5k4aa_write_sensor(sd, S5K4AA_EXPOSURE_LO, &data, 1);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+
+       err = s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       *val = (data & S5K4AA_RM_V_FLIP) >> 7;
+       PDEBUG(DBG_V4L2_CID, "Read vertical flip %d", *val);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       PDEBUG(DBG_V4L2_CID, "Set vertical flip to %d", val);
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+       err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+       if (err < 0)
+               goto out;
+       data = ((data & ~S5K4AA_RM_V_FLIP)
+                       | ((val & 0x01) << 7));
+       err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+       if (err < 0)
+               goto out;
+
+       if (val) {
+               err = s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+               if (err < 0)
+                       goto out;
+
+               data++;
+               err = s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+       } else {
+               err = s5k4aa_read_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+               if (err < 0)
+                       goto out;
+
+               data--;
+               err = s5k4aa_write_sensor(sd, S5K4AA_ROWSTART_LO, &data, 1);
+       }
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+
+       err = s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       *val = (data & S5K4AA_RM_H_FLIP) >> 6;
+       PDEBUG(DBG_V4L2_CID, "Read horizontal flip %d", *val);
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       PDEBUG(DBG_V4L2_CID, "Set horizontal flip to %d",
+              val);
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+       err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+       if (err < 0)
+               goto out;
+
+       data = ((data & ~S5K4AA_RM_H_FLIP) | ((val & 0x01) << 6));
+       err = s5k4aa_write_sensor(sd, S5K4AA_READ_MODE, &data, 1);
+       if (err < 0)
+               goto out;
+
+       if (val) {
+               err = s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+               if (err < 0)
+                       goto out;
+               data++;
+               err = s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+               if (err < 0)
+                       goto out;
+       } else {
+               err = s5k4aa_read_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+               if (err < 0)
+                       goto out;
+               data--;
+               err = s5k4aa_write_sensor(sd, S5K4AA_COLSTART_LO, &data, 1);
+       }
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+
+       err = s5k4aa_read_sensor(sd, S5K4AA_GAIN_2, &data, 1);
+       *val = data;
+       PDEBUG(DBG_V4L2_CID, "Read gain %d", *val);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       u8 data = S5K4AA_PAGE_MAP_2;
+       int err;
+
+       PDEBUG(DBG_V4L2_CID, "Set gain to %d", val);
+       err = s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &data, 1);
+       if (err < 0)
+               goto out;
+
+       data = val & 0xff;
+       err = s5k4aa_write_sensor(sd, S5K4AA_GAIN_2, &data, 1);
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+void s5k4aa_dump_registers(struct sd *sd)
+{
+       int address;
+       u8 page, old_page;
+       s5k4aa_read_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
+       for (page = 0; page < 16; page++) {
+               s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
+               info("Dumping the s5k4aa register state for page 0x%x", page);
+               for (address = 0; address <= 0xff; address++) {
+                       u8 value = 0;
+                       s5k4aa_read_sensor(sd, address, &value, 1);
+                       info("register 0x%x contains 0x%x",
+                            address, value);
+               }
+       }
+       info("s5k4aa register state dump complete");
+
+       for (page = 0; page < 16; page++) {
+               s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &page, 1);
+               info("Probing for which registers that are "
+                    "read/write for page 0x%x", page);
+               for (address = 0; address <= 0xff; address++) {
+                       u8 old_value, ctrl_value, test_value = 0xff;
+
+                       s5k4aa_read_sensor(sd, address, &old_value, 1);
+                       s5k4aa_write_sensor(sd, address, &test_value, 1);
+                       s5k4aa_read_sensor(sd, address, &ctrl_value, 1);
+
+                       if (ctrl_value == test_value)
+                               info("register 0x%x is writeable", address);
+                       else
+                               info("register 0x%x is read only", address);
+
+                       /* Restore original value */
+                       s5k4aa_write_sensor(sd, address, &old_value, 1);
+               }
+       }
+       info("Read/write register probing complete");
+       s5k4aa_write_sensor(sd, S5K4AA_PAGE_MAP, &old_page, 1);
+}
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.h b/drivers/media/video/gspca/m5602/m5602_s5k4aa.h
new file mode 100644 (file)
index 0000000..bb7f7e3
--- /dev/null
@@ -0,0 +1,370 @@
+/*
+ * Driver for the s5k4aa sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_S5K4AA_H_
+#define M5602_S5K4AA_H_
+
+#include <linux/dmi.h>
+
+#include "m5602_sensor.h"
+
+/*****************************************************************************/
+
+#define S5K4AA_PAGE_MAP                        0xec
+
+#define S5K4AA_PAGE_MAP_0              0x00
+#define S5K4AA_PAGE_MAP_1              0x01
+#define S5K4AA_PAGE_MAP_2              0x02
+
+/* Sensor register definitions for page 0x02 */
+#define S5K4AA_READ_MODE               0x03
+#define S5K4AA_ROWSTART_HI             0x04
+#define S5K4AA_ROWSTART_LO             0x05
+#define S5K4AA_COLSTART_HI             0x06
+#define S5K4AA_COLSTART_LO             0x07
+#define S5K4AA_WINDOW_HEIGHT_HI                0x08
+#define S5K4AA_WINDOW_HEIGHT_LO                0x09
+#define S5K4AA_WINDOW_WIDTH_HI         0x0a
+#define S5K4AA_WINDOW_WIDTH_LO         0x0b
+#define S5K4AA_GLOBAL_GAIN__           0x0f /* Only a guess ATM !!! */
+#define S5K4AA_H_BLANK_HI__            0x1d /* Only a guess ATM !!! sync lost
+                                               if too low, reduces frame rate
+                                               if too high */
+#define S5K4AA_H_BLANK_LO__            0x1e /* Only a guess ATM !!! */
+#define S5K4AA_EXPOSURE_HI             0x17
+#define S5K4AA_EXPOSURE_LO             0x18
+#define S5K4AA_GAIN_1                  0x1f /* (digital?) gain : 5 bits */
+#define S5K4AA_GAIN_2                  0x20 /* (analogue?) gain : 7 bits */
+
+#define S5K4AA_RM_ROW_SKIP_4X          0x08
+#define S5K4AA_RM_ROW_SKIP_2X          0x04
+#define S5K4AA_RM_COL_SKIP_4X          0x02
+#define S5K4AA_RM_COL_SKIP_2X          0x01
+#define S5K4AA_RM_H_FLIP               0x40
+#define S5K4AA_RM_V_FLIP               0x80
+
+/*****************************************************************************/
+
+/* Kernel module parameters */
+extern int force_sensor;
+extern int dump_sensor;
+extern unsigned int m5602_debug;
+
+int s5k4aa_probe(struct sd *sd);
+int s5k4aa_init(struct sd *sd);
+int s5k4aa_power_down(struct sd *sd);
+
+void s5k4aa_dump_registers(struct sd *sd);
+
+int s5k4aa_read_sensor(struct sd *sd, const u8 address,
+                      u8 *i2c_data, const u8 len);
+int s5k4aa_write_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len);
+
+int s5k4aa_get_exposure(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k4aa_set_exposure(struct gspca_dev *gspca_dev, __s32 val);
+int s5k4aa_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k4aa_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
+int s5k4aa_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k4aa_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
+int s5k4aa_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k4aa_set_gain(struct gspca_dev *gspca_dev, __s32 val);
+
+static struct m5602_sensor s5k4aa = {
+       .name = "S5K4AA",
+       .probe = s5k4aa_probe,
+       .init = s5k4aa_init,
+       .power_down = s5k4aa_power_down,
+       .read_sensor = s5k4aa_read_sensor,
+       .write_sensor = s5k4aa_write_sensor,
+       .i2c_slave_id = 0x5a,
+       .nctrls = 4,
+       .ctrls = {
+       {
+               {
+                       .id             = V4L2_CID_VFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "vertical flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = s5k4aa_set_vflip,
+               .get = s5k4aa_get_vflip
+
+       }, {
+               {
+                       .id             = V4L2_CID_HFLIP,
+                       .type           = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name           = "horizontal flip",
+                       .minimum        = 0,
+                       .maximum        = 1,
+                       .step           = 1,
+                       .default_value  = 0
+               },
+               .set = s5k4aa_set_hflip,
+               .get = s5k4aa_get_hflip
+
+       }, {
+               {
+                       .id             = V4L2_CID_GAIN,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "Gain",
+                       .minimum        = 0,
+                       .maximum        = 127,
+                       .step           = 1,
+                       .default_value  = 0xa0,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = s5k4aa_set_gain,
+               .get = s5k4aa_get_gain
+       }, {
+               {
+                       .id             = V4L2_CID_EXPOSURE,
+                       .type           = V4L2_CTRL_TYPE_INTEGER,
+                       .name           = "Exposure",
+                       .minimum        = 13,
+                       .maximum        = 0xfff,
+                       .step           = 1,
+                       .default_value  = 0x100,
+                       .flags          = V4L2_CTRL_FLAG_SLIDER
+               },
+               .set = s5k4aa_set_exposure,
+               .get = s5k4aa_get_exposure
+       }
+       },
+
+       .nmodes = 1,
+       .modes = {
+       {
+               M5602_DEFAULT_FRAME_WIDTH,
+               M5602_DEFAULT_FRAME_HEIGHT,
+               V4L2_PIX_FMT_SBGGR8,
+               V4L2_FIELD_NONE,
+               .sizeimage =
+                       M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
+               .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 1
+       }
+       }
+};
+
+static const unsigned char preinit_s5k4aa[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
+
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
+
+       {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00}
+};
+
+static const unsigned char init_s5k4aa[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
+
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x14, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
+
+       {SENSOR, S5K4AA_PAGE_MAP, 0x07, 0x00},
+       {SENSOR, 0x36, 0x01, 0x00},
+       {SENSOR, S5K4AA_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, 0x7b, 0xff, 0x00},
+       {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
+       {SENSOR, 0x0c, 0x05, 0x00},
+       {SENSOR, 0x02, 0x0e, 0x00},
+       {SENSOR, S5K4AA_GAIN_1, 0x0f, 0x00},
+       {SENSOR, S5K4AA_GAIN_2, 0x00, 0x00},
+       {SENSOR, S5K4AA_GLOBAL_GAIN__, 0x01, 0x00},
+       {SENSOR, 0x11, 0x00, 0x00},
+       {SENSOR, 0x12, 0x00, 0x00},
+       {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
+       {SENSOR, S5K4AA_READ_MODE, 0xa0, 0x00},
+       {SENSOR, 0x37, 0x00, 0x00},
+       {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
+       {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
+       {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
+       {SENSOR, S5K4AA_COLSTART_LO, 0x0b, 0x00},
+       {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
+       {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc4, 0x00},
+       {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
+       {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x08, 0x00},
+       {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
+       {SENSOR, S5K4AA_H_BLANK_LO__, 0x48, 0x00},
+       {SENSOR, S5K4AA_EXPOSURE_HI, 0x00, 0x00},
+       {SENSOR, S5K4AA_EXPOSURE_LO, 0x43, 0x00},
+       {SENSOR, 0x11, 0x04, 0x00},
+       {SENSOR, 0x12, 0xc3, 0x00},
+       {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x08, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       /* VSYNC_PARA, VSYNC_PARA : img height 480 = 0x01e0 */
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe0, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       /* HSYNC_PARA, HSYNC_PARA : img width 640 = 0x0280 */
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x80, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xa0, 0x00}, /* 48 MHz */
+
+       {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
+       {SENSOR, S5K4AA_READ_MODE, S5K4AA_RM_H_FLIP | S5K4AA_RM_ROW_SKIP_2X
+               | S5K4AA_RM_COL_SKIP_2X, 0x00},
+       /* 0x37 : Fix image stability when light is too bright and improves
+        * image quality in 640x480, but worsens it in 1280x1024 */
+       {SENSOR, 0x37, 0x01, 0x00},
+       /* ROWSTART_HI, ROWSTART_LO : 10 + (1024-960)/2 = 42 = 0x002a */
+       {SENSOR, S5K4AA_ROWSTART_HI, 0x00, 0x00},
+       {SENSOR, S5K4AA_ROWSTART_LO, 0x2a, 0x00},
+       {SENSOR, S5K4AA_COLSTART_HI, 0x00, 0x00},
+       {SENSOR, S5K4AA_COLSTART_LO, 0x0c, 0x00},
+       /* window_height_hi, window_height_lo : 960 = 0x03c0 */
+       {SENSOR, S5K4AA_WINDOW_HEIGHT_HI, 0x03, 0x00},
+       {SENSOR, S5K4AA_WINDOW_HEIGHT_LO, 0xc0, 0x00},
+       /* window_width_hi, window_width_lo : 1280 = 0x0500 */
+       {SENSOR, S5K4AA_WINDOW_WIDTH_HI, 0x05, 0x00},
+       {SENSOR, S5K4AA_WINDOW_WIDTH_LO, 0x00, 0x00},
+       {SENSOR, S5K4AA_H_BLANK_HI__, 0x00, 0x00},
+       {SENSOR, S5K4AA_H_BLANK_LO__, 0xa8, 0x00}, /* helps to sync... */
+       {SENSOR, S5K4AA_EXPOSURE_HI, 0x01, 0x00},
+       {SENSOR, S5K4AA_EXPOSURE_LO, 0x00, 0x00},
+       {SENSOR, 0x11, 0x04, 0x00},
+       {SENSOR, 0x12, 0xc3, 0x00},
+       {SENSOR, S5K4AA_PAGE_MAP, 0x02, 0x00},
+       {SENSOR, 0x02, 0x0e, 0x00},
+       {SENSOR_LONG, S5K4AA_GLOBAL_GAIN__, 0x0f, 0x00},
+       {SENSOR, S5K4AA_GAIN_1, 0x0b, 0x00},
+       {SENSOR, S5K4AA_GAIN_2, 0xa0, 0x00}
+};
+
+static
+    const
+       struct dmi_system_id s5k4aa_vflip_dmi_table[] = {
+       {
+               .ident = "Fujitsu-Siemens Amilo Xa 2528",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xa 2528")
+               }
+       },
+       {
+               .ident = "Fujitsu-Siemens Amilo Xi 2550",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "FUJITSU SIEMENS"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "AMILO Xi 2550")
+               }
+       },
+               {
+               .ident = "MSI GX700",
+               .matches = {
+                       DMI_MATCH(DMI_SYS_VENDOR, "Micro-Star International"),
+                       DMI_MATCH(DMI_PRODUCT_NAME, "GX700"),
+                       DMI_MATCH(DMI_BIOS_DATE, "07/26/2007")
+               }
+       },
+       { }
+};
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c
new file mode 100644 (file)
index 0000000..b4b33c2
--- /dev/null
@@ -0,0 +1,423 @@
+/*
+ * Driver for the s5k83a sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#include "m5602_s5k83a.h"
+
+int s5k83a_probe(struct sd *sd)
+{
+       u8 prod_id = 0, ver_id = 0;
+       int i, err = 0;
+
+       if (force_sensor) {
+               if (force_sensor == S5K83A_SENSOR) {
+                       info("Forcing a %s sensor", s5k83a.name);
+                       goto sensor_found;
+               }
+               /* If we want to force another sensor, don't try to probe this
+                * one */
+               return -ENODEV;
+       }
+
+       info("Probing for a s5k83a sensor");
+
+       /* Preinit the sensor */
+       for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) {
+               u8 data[2] = {preinit_s5k83a[i][2], preinit_s5k83a[i][3]};
+               if (preinit_s5k83a[i][0] == SENSOR)
+                       err = s5k83a_write_sensor(sd, preinit_s5k83a[i][1],
+                               data, 2);
+               else
+                       err = m5602_write_bridge(sd, preinit_s5k83a[i][1],
+                               data[0]);
+       }
+
+       /* We don't know what register (if any) that contain the product id
+        * Just pick the first addresses that seem to produce the same results
+        * on multiple machines */
+       if (s5k83a_read_sensor(sd, 0x00, &prod_id, 1))
+               return -ENODEV;
+
+       if (s5k83a_read_sensor(sd, 0x01, &ver_id, 1))
+               return -ENODEV;
+
+       if ((prod_id == 0xff) || (ver_id == 0xff))
+               return -ENODEV;
+       else
+               info("Detected a s5k83a sensor");
+
+sensor_found:
+       sd->gspca_dev.cam.cam_mode = s5k83a.modes;
+       sd->gspca_dev.cam.nmodes = s5k83a.nmodes;
+       sd->desc->ctrls = s5k83a.ctrls;
+       sd->desc->nctrls = s5k83a.nctrls;
+       return 0;
+}
+
+int s5k83a_read_sensor(struct sd *sd, const u8 address,
+                             u8 *i2c_data, const u8 len)
+{
+       int err, i;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_DEV_ADDR,
+                                sd->sensor->i2c_slave_id);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_REG_ADDR, address);
+       if (err < 0)
+               goto out;
+
+       err = m5602_write_bridge(sd, M5602_XB_I2C_CTRL, 0x18 + len);
+       if (err < 0)
+               goto out;
+
+       do {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_STATUS, i2c_data);
+       } while ((*i2c_data & I2C_BUSY) && !err);
+
+       if (err < 0)
+               goto out;
+       for (i = 0; i < len && !len; i++) {
+               err = m5602_read_bridge(sd, M5602_XB_I2C_DATA, &(i2c_data[i]));
+
+               PDEBUG(DBG_TRACE, "Reading sensor register "
+                                 "0x%x containing 0x%x ", address, *i2c_data);
+       }
+
+out:
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_write_sensor(struct sd *sd, const u8 address,
+                              u8 *i2c_data, const u8 len)
+{
+       int err, i;
+       u8 *p;
+       struct usb_device *udev = sd->gspca_dev.dev;
+       __u8 *buf = sd->gspca_dev.usb_buf;
+
+       /* No sensor with a data width larger than 16 bits has yet been seen */
+       if (len > 2 || !len)
+               return -EINVAL;
+
+       memcpy(buf, sensor_urb_skeleton,
+              sizeof(sensor_urb_skeleton));
+
+       buf[11] = sd->sensor->i2c_slave_id;
+       buf[15] = address;
+
+       /* Special case larger sensor writes */
+       p = buf + 16;
+
+       /* Copy a four byte write sequence for each byte to be written to */
+       for (i = 0; i < len; i++) {
+               memcpy(p, sensor_urb_skeleton + 16, 4);
+               p[3] = i2c_data[i];
+               p += 4;
+               PDEBUG(DBG_TRACE, "Writing sensor register 0x%x with 0x%x",
+                      address, i2c_data[i]);
+       }
+
+       /* Copy the tailer */
+       memcpy(p, sensor_urb_skeleton + 20, 4);
+
+       /* Set the total length */
+       p[3] = 0x10 + len;
+
+       err = usb_control_msg(udev, usb_sndctrlpipe(udev, 0),
+                             0x04, 0x40, 0x19,
+                             0x0000, buf,
+                             20 + len * 4, M5602_URB_MSG_TIMEOUT);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_init(struct sd *sd)
+{
+       int i, err = 0;
+
+       for (i = 0; i < ARRAY_SIZE(init_s5k83a) && !err; i++) {
+               u8 data[2] = {0x00, 0x00};
+
+               switch (init_s5k83a[i][0]) {
+               case BRIDGE:
+                       err = m5602_write_bridge(sd,
+                                       init_s5k83a[i][1],
+                                       init_s5k83a[i][2]);
+                       break;
+
+               case SENSOR:
+                       data[0] = init_s5k83a[i][2];
+                       err = s5k83a_write_sensor(sd,
+                               init_s5k83a[i][1], data, 1);
+                       break;
+
+               case SENSOR_LONG:
+                       data[0] = init_s5k83a[i][2];
+                       data[1] = init_s5k83a[i][3];
+                       err = s5k83a_write_sensor(sd,
+                               init_s5k83a[i][1], data, 2);
+                       break;
+               default:
+                       info("Invalid stream command, exiting init");
+                       return -EINVAL;
+               }
+       }
+
+       if (dump_sensor)
+               s5k83a_dump_registers(sd);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_power_down(struct sd *sd)
+{
+       return 0;
+}
+
+void s5k83a_dump_registers(struct sd *sd)
+{
+       int address;
+       u8 page, old_page;
+       s5k83a_read_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1);
+
+       for (page = 0; page < 16; page++) {
+               s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
+               info("Dumping the s5k83a register state for page 0x%x", page);
+               for (address = 0; address <= 0xff; address++) {
+                       u8 val = 0;
+                       s5k83a_read_sensor(sd, address, &val, 1);
+                       info("register 0x%x contains 0x%x",
+                            address, val);
+               }
+       }
+       info("s5k83a register state dump complete");
+
+       for (page = 0; page < 16; page++) {
+               s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &page, 1);
+               info("Probing for which registers that are read/write "
+                     "for page 0x%x", page);
+               for (address = 0; address <= 0xff; address++) {
+                       u8 old_val, ctrl_val, test_val = 0xff;
+
+                       s5k83a_read_sensor(sd, address, &old_val, 1);
+                       s5k83a_write_sensor(sd, address, &test_val, 1);
+                       s5k83a_read_sensor(sd, address, &ctrl_val, 1);
+
+                       if (ctrl_val == test_val)
+                               info("register 0x%x is writeable", address);
+                       else
+                               info("register 0x%x is read only", address);
+
+                       /* Restore original val */
+                       s5k83a_write_sensor(sd, address, &old_val, 1);
+               }
+       }
+       info("Read/write register probing complete");
+       s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, &old_page, 1);
+}
+
+int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[2];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = s5k83a_read_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
+       data[1] = data[1] << 1;
+       *val = data[1];
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[2];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0x00;
+       data[1] = 0x20;
+       err = s5k83a_write_sensor(sd, 0x14, data, 2);
+       if (err < 0)
+               return err;
+
+       data[0] = 0x01;
+       data[1] = 0x00;
+       err = s5k83a_write_sensor(sd, 0x0d, data, 2);
+       if (err < 0)
+               return err;
+
+       /* FIXME: This is not sane, we need to figure out the composition
+                 of these registers */
+       data[0] = val >> 3; /* brightness, high 5 bits */
+       data[1] = val >> 1; /* brightness, high 7 bits */
+       err = s5k83a_write_sensor(sd, S5K83A_BRIGHTNESS, data, 2);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data;
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = s5k83a_read_sensor(sd, S5K83A_WHITENESS, &data, 1);
+
+       *val = data;
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[1];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = val;
+       err = s5k83a_write_sensor(sd, S5K83A_WHITENESS, data, 1);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[2];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       err = s5k83a_read_sensor(sd, S5K83A_GAIN, data, 2);
+
+       data[1] = data[1] & 0x3f;
+       if (data[1] > S5K83A_MAXIMUM_GAIN)
+               data[1] = S5K83A_MAXIMUM_GAIN;
+
+       *val = data[1];
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[2];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0;
+       data[1] = val;
+       err = s5k83a_write_sensor(sd, S5K83A_GAIN, data, 2);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[1];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0x05;
+       err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
+       if (err < 0)
+               return err;
+
+       err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
+       *val = (data[0] | 0x40) ? 1 : 0;
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[1];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0x05;
+       err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
+       if (err < 0)
+               return err;
+
+       err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
+       if (err < 0)
+               return err;
+
+       /* set or zero six bit, seven is hflip */
+       data[0] = (val) ? (data[0] & 0x80) | 0x40 | S5K83A_FLIP_MASK
+                       : (data[0] & 0x80) | S5K83A_FLIP_MASK;
+       err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1);
+       if (err < 0)
+               return err;
+
+       data[0] = (val) ? 0x0b : 0x0a;
+       err = s5k83a_write_sensor(sd, S5K83A_VFLIP_TUNE, data, 1);
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       int err;
+       u8 data[1];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0x05;
+       err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
+       if (err < 0)
+               return err;
+
+       err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
+       *val = (data[0] | 0x80) ? 1 : 0;
+
+       return (err < 0) ? err : 0;
+}
+
+int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       int err;
+       u8 data[1];
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       data[0] = 0x05;
+       err = s5k83a_write_sensor(sd, S5K83A_PAGE_MAP, data, 1);
+       if (err < 0)
+               return err;
+
+       err = s5k83a_read_sensor(sd, S5K83A_FLIP, data, 1);
+       if (err < 0)
+               return err;
+
+       /* set or zero seven bit, six is vflip */
+       data[0] = (val) ? (data[0] & 0x40) | 0x80 | S5K83A_FLIP_MASK
+                       : (data[0] & 0x40) | S5K83A_FLIP_MASK;
+       err = s5k83a_write_sensor(sd, S5K83A_FLIP, data, 1);
+       if (err < 0)
+               return err;
+
+       data[0] = (val) ? 0x0a : 0x0b;
+       err = s5k83a_write_sensor(sd, S5K83A_HFLIP_TUNE, data, 1);
+
+       return (err < 0) ? err : 0;
+}
diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.h b/drivers/media/video/gspca/m5602/m5602_s5k83a.h
new file mode 100644 (file)
index 0000000..833708e
--- /dev/null
@@ -0,0 +1,484 @@
+/*
+ * Driver for the s5k83a sensor
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_S5K83A_H_
+#define M5602_S5K83A_H_
+
+#include "m5602_sensor.h"
+
+#define S5K83A_FLIP                            0x01
+#define S5K83A_HFLIP_TUNE              0x03
+#define S5K83A_VFLIP_TUNE              0x05
+#define S5K83A_WHITENESS               0x0a
+#define S5K83A_GAIN                            0x18
+#define S5K83A_BRIGHTNESS              0x1b
+#define S5K83A_PAGE_MAP                        0xec
+
+#define S5K83A_DEFAULT_BRIGHTNESS      0x71
+#define S5K83A_DEFAULT_WHITENESS       0x7e
+#define S5K83A_DEFAULT_GAIN                    0x00
+#define S5K83A_MAXIMUM_GAIN                    0x3c
+#define S5K83A_FLIP_MASK                       0x10
+
+
+/*****************************************************************************/
+
+/* Kernel module parameters */
+extern int force_sensor;
+extern int dump_sensor;
+extern unsigned int m5602_debug;
+
+
+int s5k83a_probe(struct sd *sd);
+int s5k83a_init(struct sd *sd);
+int s5k83a_power_down(struct sd *sd);
+
+void s5k83a_dump_registers(struct sd *sd);
+
+int s5k83a_read_sensor(struct sd *sd, const u8 address,
+                      u8 *i2c_data, const u8 len);
+int s5k83a_write_sensor(struct sd *sd, const u8 address,
+                       u8 *i2c_data, const u8 len);
+
+int s5k83a_set_brightness(struct gspca_dev *gspca_dev, __s32 val);
+int s5k83a_get_brightness(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k83a_set_whiteness(struct gspca_dev *gspca_dev, __s32 val);
+int s5k83a_get_whiteness(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k83a_set_gain(struct gspca_dev *gspca_dev, __s32 val);
+int s5k83a_get_gain(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k83a_get_vflip(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k83a_set_vflip(struct gspca_dev *gspca_dev, __s32 val);
+int s5k83a_get_hflip(struct gspca_dev *gspca_dev, __s32 *val);
+int s5k83a_set_hflip(struct gspca_dev *gspca_dev, __s32 val);
+
+
+static struct m5602_sensor s5k83a = {
+       .name = "S5K83A",
+       .probe = s5k83a_probe,
+       .init = s5k83a_init,
+       .power_down = s5k83a_power_down,
+       .read_sensor = s5k83a_read_sensor,
+       .write_sensor = s5k83a_write_sensor,
+       .i2c_slave_id = 0x5a,
+       .nctrls = 5,
+       .ctrls = {
+       {
+               {
+                       .id = V4L2_CID_BRIGHTNESS,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "brightness",
+                       .minimum = 0x00,
+                       .maximum = 0xff,
+                       .step = 0x01,
+                       .default_value = S5K83A_DEFAULT_BRIGHTNESS,
+                       .flags = V4L2_CTRL_FLAG_SLIDER
+               },
+                       .set = s5k83a_set_brightness,
+                       .get = s5k83a_get_brightness
+
+       }, {
+               {
+                       .id = V4L2_CID_WHITENESS,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "whiteness",
+                       .minimum = 0x00,
+                       .maximum = 0xff,
+                       .step = 0x01,
+                       .default_value = S5K83A_DEFAULT_WHITENESS,
+                       .flags = V4L2_CTRL_FLAG_SLIDER
+               },
+                       .set = s5k83a_set_whiteness,
+                       .get = s5k83a_get_whiteness,
+       }, {
+               {
+                       .id = V4L2_CID_GAIN,
+                       .type = V4L2_CTRL_TYPE_INTEGER,
+                       .name = "gain",
+                       .minimum = 0x00,
+                       .maximum = S5K83A_MAXIMUM_GAIN,
+                       .step = 0x01,
+                       .default_value = S5K83A_DEFAULT_GAIN,
+                       .flags = V4L2_CTRL_FLAG_SLIDER
+               },
+                       .set = s5k83a_set_gain,
+                       .get = s5k83a_get_gain
+       }, {
+               {
+                       .id         = V4L2_CID_HFLIP,
+                       .type       = V4L2_CTRL_TYPE_BOOLEAN,
+                       .name       = "horizontal flip",
+                       .minimum    = 0,
+                       .maximum    = 1,
+                       .step       = 1,
+                       .default_value  = 0
+               },
+                       .set = s5k83a_set_hflip,
+                       .get = s5k83a_get_hflip
+       }, {
+               {
+                .id         = V4L2_CID_VFLIP,
+               .type       = V4L2_CTRL_TYPE_BOOLEAN,
+               .name       = "vertical flip",
+               .minimum    = 0,
+               .maximum    = 1,
+               .step       = 1,
+               .default_value  = 0
+               },
+               .set = s5k83a_set_vflip,
+               .get = s5k83a_get_vflip
+               }
+       },
+       .nmodes = 1,
+       .modes = {
+       {
+               M5602_DEFAULT_FRAME_WIDTH,
+               M5602_DEFAULT_FRAME_HEIGHT,
+               V4L2_PIX_FMT_SBGGR8,
+               V4L2_FIELD_NONE,
+               .sizeimage =
+                       M5602_DEFAULT_FRAME_WIDTH * M5602_DEFAULT_FRAME_HEIGHT,
+               .bytesperline = M5602_DEFAULT_FRAME_WIDTH,
+               .colorspace = V4L2_COLORSPACE_SRGB,
+               .priv = 1
+       }
+       }
+};
+
+static const unsigned char preinit_s5k83a[][4] =
+{
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x0d, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_CTRL, 0x00, 0x00},
+
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00}
+};
+
+/* This could probably be considerably shortened.
+   I don't have the hardware to experiment with it, patches welcome
+*/
+static const unsigned char init_s5k83a[][4] =
+{
+       {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
+       {SENSOR, 0xaf, 0x01, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, 0x7b, 0xff, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x01, 0x50, 0x00},
+       {SENSOR, 0x12, 0x20, 0x00},
+       {SENSOR, 0x17, 0x40, 0x00},
+       {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
+       {SENSOR, 0x1c, 0x00, 0x00},
+       {SENSOR, 0x02, 0x70, 0x00},
+       {SENSOR, 0x03, 0x0b, 0x00},
+       {SENSOR, 0x04, 0xf0, 0x00},
+       {SENSOR, 0x05, 0x0b, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x06, 0x71, 0x00},
+       {SENSOR, 0x07, 0xe8, 0x00},
+       {SENSOR, 0x08, 0x02, 0x00},
+       {SENSOR, 0x09, 0x88, 0x00},
+       {SENSOR, 0x14, 0x00, 0x00},
+       {SENSOR, 0x15, 0x20, 0x00},
+       {SENSOR, 0x19, 0x00, 0x00},
+       {SENSOR, 0x1a, 0x98, 0x00},
+       {SENSOR, 0x0f, 0x02, 0x00},
+       {SENSOR, 0x10, 0xe5, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR_LONG, 0x14, 0x00, 0x20},
+       {SENSOR_LONG, 0x0d, 0x00, 0x7d},
+       {SENSOR_LONG, 0x1b, 0x0d, 0x05},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x87, 0x00},
+
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
+       {SENSOR, 0xaf, 0x01, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       /* ff ( init value )is very dark) || 71 and f0 better */
+       {SENSOR, 0x7b, 0xff, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x01, 0x50, 0x00},
+       {SENSOR, 0x12, 0x20, 0x00},
+       {SENSOR, 0x17, 0x40, 0x00},
+       {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
+       {SENSOR, 0x1c, 0x00, 0x00},
+       {SENSOR, 0x02, 0x70, 0x00},
+       /* some values like 0x10 give a blue-purple image */
+       {SENSOR, 0x03, 0x0b, 0x00},
+       {SENSOR, 0x04, 0xf0, 0x00},
+       {SENSOR, 0x05, 0x0b, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       /* under 80 don't work, highter depend on value */
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
+
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x06, 0x71, 0x00},
+       {SENSOR, 0x07, 0xe8, 0x00},
+       {SENSOR, 0x08, 0x02, 0x00},
+       {SENSOR, 0x09, 0x88, 0x00},
+       {SENSOR, 0x14, 0x00, 0x00},
+       {SENSOR, 0x15, 0x20, 0x00},
+       {SENSOR, 0x19, 0x00, 0x00},
+       {SENSOR, 0x1a, 0x98, 0x00},
+       {SENSOR, 0x0f, 0x02, 0x00},
+       {SENSOR, 0x10, 0xe5, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR_LONG, 0x14, 0x00, 0x20},
+       {SENSOR_LONG, 0x0d, 0x00, 0x7d},
+       {SENSOR_LONG, 0x1b, 0x0d, 0x05},
+
+       /* The following sequence is useless after a clean boot
+          but is necessary after resume from suspend */
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x08, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x3f, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_L, 0xff, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0x80, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_DIV, 0x02, 0x00},
+       {BRIDGE, M5602_XB_MCU_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xf0, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR, 0x1d, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT, 0x1c, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DIR_H, 0x06, 0x00},
+       {BRIDGE, M5602_XB_GPIO_DAT_H, 0x00, 0x00},
+       {BRIDGE, M5602_XB_GPIO_EN_L, 0x00, 0x00},
+       {BRIDGE, M5602_XB_I2C_CLK_DIV, 0x20, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x04, 0x00},
+       {SENSOR, 0xaf, 0x01, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x00, 0x00},
+       {SENSOR, 0x7b, 0xff, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x01, 0x50, 0x00},
+       {SENSOR, 0x12, 0x20, 0x00},
+       {SENSOR, 0x17, 0x40, 0x00},
+       {SENSOR, S5K83A_BRIGHTNESS, 0x0f, 0x00},
+       {SENSOR, 0x1c, 0x00, 0x00},
+       {SENSOR, 0x02, 0x70, 0x00},
+       {SENSOR, 0x03, 0x0b, 0x00},
+       {SENSOR, 0x04, 0xf0, 0x00},
+       {SENSOR, 0x05, 0x0b, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x06, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+       {BRIDGE, M5602_XB_ADC_CTRL, 0xc0, 0x00},
+       {BRIDGE, M5602_XB_SENSOR_TYPE, 0x09, 0x00},
+       {BRIDGE, M5602_XB_LINE_OF_FRAME_H, 0x81, 0x00},
+       {BRIDGE, M5602_XB_PIX_OF_LINE_H, 0x82, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x01, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0xe4, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_VSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x00, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x02, 0x00},
+       {BRIDGE, M5602_XB_HSYNC_PARA, 0x7f, 0x00},
+       {BRIDGE, M5602_XB_SIG_INI, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_DIV, 0x00, 0x00},
+       {BRIDGE, M5602_XB_SEN_CLK_CTRL, 0xb0, 0x00},
+
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, 0x06, 0x71, 0x00},
+       {SENSOR, 0x07, 0xe8, 0x00},
+       {SENSOR, 0x08, 0x02, 0x00},
+       {SENSOR, 0x09, 0x88, 0x00},
+       {SENSOR, 0x14, 0x00, 0x00},
+       {SENSOR, 0x15, 0x20, 0x00},
+       {SENSOR, 0x19, 0x00, 0x00},
+       {SENSOR, 0x1a, 0x98, 0x00},
+       {SENSOR, 0x0f, 0x02, 0x00},
+
+       {SENSOR, 0x10, 0xe5, 0x00},
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR_LONG, 0x14, 0x00, 0x20},
+       {SENSOR_LONG, 0x0d, 0x00, 0x7d},
+       {SENSOR_LONG, 0x1b, 0x0d, 0x05},
+
+       /* normal colors
+          (this is value after boot, but after tries can be different) */
+       {SENSOR, 0x00, 0x06, 0x00},
+
+       /* set default brightness */
+       {SENSOR_LONG, 0x14, 0x00, 0x20},
+       {SENSOR_LONG, 0x0d, 0x01, 0x00},
+       {SENSOR_LONG, 0x1b, S5K83A_DEFAULT_BRIGHTNESS >> 3,
+                           S5K83A_DEFAULT_BRIGHTNESS >> 1},
+
+       /* set default whiteness */
+       {SENSOR, S5K83A_WHITENESS, S5K83A_DEFAULT_WHITENESS, 0x00},
+
+       /* set default gain */
+       {SENSOR_LONG, 0x18, 0x00, S5K83A_DEFAULT_GAIN},
+
+       /* set default flip */
+       {SENSOR, S5K83A_PAGE_MAP, 0x05, 0x00},
+       {SENSOR, S5K83A_FLIP, 0x00 | S5K83A_FLIP_MASK, 0x00},
+       {SENSOR, S5K83A_HFLIP_TUNE, 0x0b, 0x00},
+       {SENSOR, S5K83A_VFLIP_TUNE, 0x0a, 0x00}
+
+};
+
+#endif
diff --git a/drivers/media/video/gspca/m5602/m5602_sensor.h b/drivers/media/video/gspca/m5602/m5602_sensor.h
new file mode 100644 (file)
index 0000000..930fcaa
--- /dev/null
@@ -0,0 +1,76 @@
+/*
+ * USB Driver for ALi m5602 based webcams
+ *
+ * Copyright (C) 2008 Erik Andren
+ * Copyright (C) 2007 Ilyes Gouta. Based on the m5603x Linux Driver Project.
+ * Copyright (C) 2005 m5603x Linux Driver Project <m5602@x3ng.com.br>
+ *
+ * Portions of code to USB interface and ALi driver software,
+ * Copyright (c) 2006 Willem Duinker
+ * v4l2 interface modeled after the V4L2 driver
+ * for SN9C10x PC Camera Controllers
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation, version 2.
+ *
+ */
+
+#ifndef M5602_SENSOR_H_
+#define M5602_SENSOR_H_
+
+#include "m5602_bridge.h"
+
+#define M5602_DEFAULT_FRAME_WIDTH  640
+#define M5602_DEFAULT_FRAME_HEIGHT 480
+
+#define M5602_MAX_CTRLS                (V4L2_CID_LASTP1 - V4L2_CID_BASE + 10)
+
+/* Enumerates all supported sensors */
+enum sensors {
+       OV9650_SENSOR   = 1,
+       S5K83A_SENSOR   = 2,
+       S5K4AA_SENSOR   = 3,
+       MT9M111_SENSOR  = 4,
+       PO1030_SENSOR   = 5
+};
+
+/* Enumerates all possible instruction types */
+enum instruction {
+       BRIDGE,
+       SENSOR,
+       SENSOR_LONG
+};
+
+struct m5602_sensor {
+       /* Defines the name of a sensor */
+       char name[32];
+
+       /* What i2c address the sensor is connected to */
+       u8 i2c_slave_id;
+
+       /* Probes if the sensor is connected */
+       int (*probe)(struct sd *sd);
+
+       /* Performs a initialization sequence */
+       int (*init)(struct sd *sd);
+
+       /* Performs a power down sequence */
+       int (*power_down)(struct sd *sd);
+
+       /* Reads a sensor register */
+       int (*read_sensor)(struct sd *sd, const u8 address,
+             u8 *i2c_data, const u8 len);
+
+       /* Writes to a sensor register */
+       int (*write_sensor)(struct sd *sd, const u8 address,
+             u8 *i2c_data, const u8 len);
+
+       int nctrls;
+       struct ctrl ctrls[M5602_MAX_CTRLS];
+
+       char nmodes;
+       struct v4l2_pix_format modes[];
+};
+
+#endif
index 4d5db47ba8cbf3564d9287a86153e4f46733f2e8..277ca34a881775cf8ee72a7801bb4202e2864f5c 100644 (file)
@@ -134,7 +134,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        int err_code;
        __u8 *data;
@@ -143,9 +143,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
        int intpipe;
 
        PDEBUG(D_STREAM, "camera start, iface %d, alt 8", gspca_dev->iface);
-       if (usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8) < 0) {
+       err_code = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 8);
+       if (err_code < 0) {
                PDEBUG(D_ERR|D_STREAM, "Set packet size: set interface error");
-               return;
+               return err_code;
        }
 
        data = gspca_dev->usb_buf;
@@ -154,7 +155,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
        err_code = reg_w(gspca_dev, data[0], 2);
        if (err_code < 0)
-               return;
+               return err_code;
 
        /*
           Initialize the MR97113 chip register
@@ -180,14 +181,14 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
        err_code = reg_w(gspca_dev, data[0], 11);
        if (err_code < 0)
-               return;
+               return err_code;
 
        data[0] = 0x23;         /* address */
        data[1] = 0x09;         /* reg 35, append frame header */
 
        err_code = reg_w(gspca_dev, data[0], 2);
        if (err_code < 0)
-               return;
+               return err_code;
 
        data[0] = 0x3c;         /* address */
 /*     if (gspca_dev->width == 1280) */
@@ -198,7 +199,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                                 *      (unit: 4KB) 200KB */
        err_code = reg_w(gspca_dev, data[0], 2);
        if (err_code < 0)
-               return;
+               return err_code;
 
        if (0) {                        /* fixed dark-gain */
                data[1] = 0;            /* reg 94, Y Gain (1.75) */
@@ -240,13 +241,13 @@ static void sd_start(struct gspca_dev *gspca_dev)
 
        err_code = reg_w(gspca_dev, data[0], 6);
        if (err_code < 0)
-               return;
+               return err_code;
 
        data[0] = 0x67;
        data[1] = 0x13;         /* reg 103, first pixel B, disable sharpness */
        err_code = reg_w(gspca_dev, data[0], 2);
        if (err_code < 0)
-               return;
+               return err_code;
 
        /*
         * initialize the value of MI sensor...
@@ -326,6 +327,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        data[0] = 0x00;
        data[1] = 0x4d;         /* ISOC transfering enable... */
        reg_w(gspca_dev, data[0], 2);
+       return err_code;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 4df4eec9f7e71163fe35950bf02a303ca5a3272c..ca671194679e3adef083dbbe3f3e20df8956ebf2 100644 (file)
@@ -1854,7 +1854,7 @@ static int set_ov_sensor_window(struct sd *sd)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int ret;
@@ -1871,9 +1871,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
                goto out;
        PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt);
        ov51x_led_control(sd, 1);
-       return;
+       return 0;
 out:
        PDEBUG(D_ERR, "camera start error:%d", ret);
+       return ret;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 83b5f740c9470960b3bf42aef54472726bbce098..0b0c573d06da1ee3da37fed3d3f74948375845c4 100644 (file)
@@ -281,7 +281,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        __u8 mode;
@@ -323,6 +323,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        sd->sof_read = 0;
        sd->autogain_ignore_frames = 0;
        atomic_set(&sd->avg_lum, -1);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -534,6 +535,7 @@ static const __devinitdata struct usb_device_id device_table[] = {
        {USB_DEVICE(0x093a, 0x2470)},
        {USB_DEVICE(0x093a, 0x2471)},
        {USB_DEVICE(0x093a, 0x2472)},
+       {USB_DEVICE(0x093a, 0x2476)},
        {USB_DEVICE(0x2001, 0xf115)},
        {}
 };
index ba865b7f1ed81710e902fdf86eb2ae1c1cf06e8a..e5ff9a6199ef16261e85faec7d9ab85d97ebfc49 100644 (file)
@@ -675,7 +675,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
@@ -724,6 +724,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                reg_w(gspca_dev, 0x78, 0x01);
        else
                reg_w(gspca_dev, 0x78, 0x05);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 12b81ae526b7206c0e982e3a845e20c4d1386ca2..6c69bc7778fc2f9cf322d0282a3151a91bcc9f82 100644 (file)
@@ -490,7 +490,7 @@ static const __u8 tas5130_sensor_init[][8] = {
        {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10},
 };
 
-struct sensor_data sensor_data[] = {
+static struct sensor_data sensor_data[] = {
 SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0),
 SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60),
 SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3,
@@ -892,7 +892,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        struct cam *cam = &gspca_dev->cam;
@@ -976,6 +976,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        sd->frames_to_drop = 0;
        sd->autogain_ignore_frames = 0;
        atomic_set(&sd->avg_lum, -1);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 572b0f363b640ccb407b7d312716c75c4da85e95..53cb82d9e7c6a28909636595968ae335c9809698 100644 (file)
@@ -39,6 +39,7 @@ struct sd {
        unsigned char contrast;
        unsigned char colors;
        unsigned char autogain;
+       __u8 vflip;                     /* ov7630 only */
 
        signed char ag_cnt;
 #define AG_CNT_START 13
@@ -70,6 +71,8 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val);
 static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val);
 static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val);
+static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val);
+static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val);
 
 static struct ctrl sd_ctrls[] = {
        {
@@ -131,6 +134,22 @@ static struct ctrl sd_ctrls[] = {
            .set = sd_setautogain,
            .get = sd_getautogain,
        },
+/* ov7630 only */
+#define VFLIP_IDX 4
+       {
+           {
+               .id      = V4L2_CID_VFLIP,
+               .type    = V4L2_CTRL_TYPE_BOOLEAN,
+               .name    = "Vflip",
+               .minimum = 0,
+               .maximum = 1,
+               .step    = 1,
+#define VFLIP_DEF 1
+               .default_value = VFLIP_DEF,
+           },
+           .set = sd_setvflip,
+           .get = sd_getvflip,
+       },
 };
 
 static struct v4l2_pix_format vga_mode[] = {
@@ -248,10 +267,12 @@ static const __u8 gamma_def[] = {
        0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff
 };
 
+/* color matrix and offsets */
 static const __u8 reg84[] = {
-       0x14, 0x00, 0x27, 0x00, 0x07, 0x00, 0xe5, 0x0f,
-       0xe4, 0x0f, 0x38, 0x00, 0x3e, 0x00, 0xc3, 0x0f,
-       0xf7, 0x0f, 0x00, 0x00, 0x00
+       0x14, 0x00, 0x27, 0x00, 0x07, 0x00,     /* YR YG YB gains */
+       0xe8, 0x0f, 0xda, 0x0f, 0x40, 0x00,     /* UR UG UB */
+       0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f,     /* VR VG VB */
+       0x00, 0x00, 0x00                        /* YUV offsets */
 };
 static const __u8 hv7131r_sensor_init[][8] = {
        {0xC1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10},
@@ -434,7 +455,8 @@ static const __u8 ov7630_sensor_init[][8] = {
        {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
        {0xa1, 0x21, 0x12, 0x48, 0x00, 0x00, 0x00, 0x10},
 /*fixme: + 0x12, 0x04*/
-       {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10},
+/*     {0xa1, 0x21, 0x75, 0x82, 0x00, 0x00, 0x00, 0x10},  * COMN
+                                                        * set by setvflip */
        {0xa1, 0x21, 0x10, 0x32, 0x00, 0x00, 0x00, 0x10},
        {0xa1, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10},
        {0xb1, 0x21, 0x01, 0x80, 0x80, 0x00, 0x00, 0x10},
@@ -949,6 +971,8 @@ static int sd_config(struct gspca_dev *gspca_dev,
                gspca_dev->ctrl_dis = (1 << AUTOGAIN_IDX);
                break;
        }
+       if (sd->sensor != SENSOR_OV7630)
+               gspca_dev->ctrl_dis |= (1 << VFLIP_IDX);
 
        return 0;
 }
@@ -1080,20 +1104,17 @@ static unsigned int setexposure(struct gspca_dev *gspca_dev,
 static void setbrightcont(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-       unsigned val;
+       int val;
        __u8 reg84_full[0x15];
 
-       memset(reg84_full, 0, sizeof reg84_full);
-       val = sd->contrast * 0x20 / CONTRAST_MAX + 0x10;        /* 10..30 */
-       reg84_full[2] = val;
-       reg84_full[0] = (val + 1) / 2;
-       reg84_full[4] = (val + 1) / 5;
-       if (val > BRIGHTNESS_DEF)
-               val = (sd->brightness - BRIGHTNESS_DEF) * 0x20
+       memcpy(reg84_full, reg84, sizeof reg84_full);
+       val = sd->contrast * 0x30 / CONTRAST_MAX + 0x10;        /* 10..40 */
+       reg84_full[0] = (val + 1) / 2;          /* red */
+       reg84_full[2] = val;                    /* green */
+       reg84_full[4] = (val + 1) / 5;          /* blue */
+       val = (sd->brightness - BRIGHTNESS_DEF) * 0x10
                        / BRIGHTNESS_MAX;
-       else
-               val = 0;
-       reg84_full[0x12] = val;                 /* 00..1f */
+       reg84_full[0x12] = val & 0x1f;          /* 5:0 signed value */
        reg_w(gspca_dev, 0x84, reg84_full, sizeof reg84_full);
 }
 
@@ -1172,8 +1193,16 @@ static void setautogain(struct gspca_dev *gspca_dev)
                sd->ag_cnt = -1;
 }
 
+static void setvflip(struct sd *sd)
+{
+       if (sd->sensor != SENSOR_OV7630)
+               return;
+       i2c_w1(&sd->gspca_dev, 0x75,                    /* COMN */
+               sd->vflip ? 0x82 : 0x02);
+}
+
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int i;
@@ -1263,6 +1292,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                break;
        case SENSOR_OV7630:
                ov7630_InitSensor(gspca_dev);
+               setvflip(sd);
                reg17 = 0xe2;
                reg1 = 0x44;
                break;
@@ -1320,12 +1350,16 @@ static void sd_start(struct gspca_dev *gspca_dev)
                setbrightness(gspca_dev);
                setcontrast(gspca_dev);
                break;
+       case SENSOR_OV7630:
+               setvflip(sd);
+               /* fall thru */
        default:                        /* OV76xx */
                setbrightcont(gspca_dev);
                break;
        }
        setautogain(gspca_dev);
        reg_w1(gspca_dev, 0x01, reg1);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -1546,6 +1580,24 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val)
        return 0;
 }
 
+static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       sd->vflip = val;
+       if (gspca_dev->streaming)
+               setvflip(sd);
+       return 0;
+}
+
+static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       *val = sd->vflip;
+       return 0;
+}
+
 /* sub-driver description */
 static const struct sd_desc sd_desc = {
        .name = MODULE_NAME,
@@ -1567,6 +1619,7 @@ static const struct sd_desc sd_desc = {
 static const __devinitdata struct usb_device_id device_table[] = {
 #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
        {USB_DEVICE(0x0458, 0x7025), BSI(SN9C120, MI0360, 0x5d)},
+       {USB_DEVICE(0x0458, 0x702e), BSI(SN9C120, OV7660, 0x21)},
        {USB_DEVICE(0x045e, 0x00f5), BSI(SN9C105, OV7660, 0x21)},
        {USB_DEVICE(0x045e, 0x00f7), BSI(SN9C105, OV7660, 0x21)},
        {USB_DEVICE(0x0471, 0x0327), BSI(SN9C105, MI0360, 0x5d)},
@@ -1588,7 +1641,9 @@ static const __devinitdata struct usb_device_id device_table[] = {
 /*     {USB_DEVICE(0x0c45, 0x60fa), BSI(SN9C105, OV7648, 0x??)}, */
        {USB_DEVICE(0x0c45, 0x60fb), BSI(SN9C105, OV7660, 0x21)},
        {USB_DEVICE(0x0c45, 0x60fc), BSI(SN9C105, HV7131R, 0x11)},
-/*     {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x??)}, */
+#if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE
+       {USB_DEVICE(0x0c45, 0x60fe), BSI(SN9C105, OV7630, 0x21)},
+#endif
 /*     {USB_DEVICE(0x0c45, 0x6108), BSI(SN9C120, OM6801, 0x??)}, */
 /*     {USB_DEVICE(0x0c45, 0x6122), BSI(SN9C110, ICM105C, 0x??)}, */
 /*     {USB_DEVICE(0x0c45, 0x6123), BSI(SN9C110, SanyoCCD, 0x??)}, */
index 6e733901fcca24129457aba26946e4229af6ca0f..bca106c153faa3dc4708ad77a6e33eac2c73615d 100644 (file)
@@ -660,7 +660,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        int err;
@@ -867,6 +867,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                write_vector(gspca_dev, Clicksmart510_defaults);
                break;
        }
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index e9eb59bae4fbf1b82effe0d21d5496213a86db80..b742f260c7caa6bb4fd8b1769be95c87988bafcb 100644 (file)
@@ -1980,7 +1980,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct usb_device *dev = gspca_dev->dev;
        int mode;
@@ -2012,6 +2012,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        setbrightness(gspca_dev);
        setcontrast(gspca_dev);
        setcolors(gspca_dev);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index f601daf19ebeabacaf044af300f1914ed69caa61..b345749213cf16e9e0bd9e5cf2703d4cb9c9388f 100644 (file)
@@ -688,7 +688,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct usb_device *dev = gspca_dev->dev;
        int ret;
@@ -733,6 +733,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
 /*     reg_write(dev, 0x5, 0x0, 0x0); */
 /*     reg_write(dev, 0x5, 0x0, 0x1); */
 /*     reg_write(dev, 0x5, 0x11, 0x2); */
+       return ret;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 195dce96ef068d5579b1cd896c623ed242619378..645ee9d44d0267dbb908ddf2e9beea692b413d05 100644 (file)
@@ -422,7 +422,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct usb_device *dev = gspca_dev->dev;
        __u16 norme;
@@ -549,6 +549,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        PDEBUG(D_STREAM, "webcam started");
        spca506_GetNormeInput(gspca_dev, &norme, &channel);
        spca506_SetNormeInput(gspca_dev, norme, channel);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 281ce02103a336ced7a1d10042b3c830fdcf1155..63ec902c895d0398116f30732e098d8d74daeb69 100644 (file)
@@ -1528,7 +1528,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        int mode;
 
@@ -1546,6 +1546,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                break;
        }
        reg_write(gspca_dev->dev, 0x8112, 0x10 | 0x20);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 95fcfcb9e31b51c8d2ce871fdae89b0096df1862..020a03c466c10f75042fcd090d0f1be7643e7fdc 100644 (file)
@@ -152,7 +152,7 @@ static void reg_w_val(struct usb_device *dev, __u16 index, __u8 value)
 
        ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0),
                              0,                /* request */
-                             USB_TYPE_VENDOR | USB_RECIP_DEVICE,
+                             USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
                              value, index, NULL, 0, 500);
        PDEBUG(D_USBO, "reg write: 0x%02x:0x%02x", index, value);
        if (ret < 0)
@@ -699,7 +699,7 @@ static void setautogain(struct gspca_dev *gspca_dev)
                sd->ag_cnt = -1;
 }
 
-static void sd_start_12a(struct gspca_dev *gspca_dev)
+static int sd_start_12a(struct gspca_dev *gspca_dev)
 {
        struct usb_device *dev = gspca_dev->dev;
        int Clck = 0x8a; /* lower 0x8X values lead to fps > 30 */
@@ -725,8 +725,9 @@ static void sd_start_12a(struct gspca_dev *gspca_dev)
        setwhite(gspca_dev);
        setautogain(gspca_dev);
        setexposure(gspca_dev);
+       return 0;
 }
-static void sd_start_72a(struct gspca_dev *gspca_dev)
+static int sd_start_72a(struct gspca_dev *gspca_dev)
 {
        struct usb_device *dev = gspca_dev->dev;
        int Clck;
@@ -750,6 +751,7 @@ static void sd_start_72a(struct gspca_dev *gspca_dev)
        reg_w_val(dev, 0x8700, Clck);   /* 0x27 clock */
        reg_w_val(dev, 0x8112, 0x10 | 0x20);
        setautogain(gspca_dev);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
@@ -1064,7 +1066,7 @@ static struct ctrl sd_ctrls_12a[] = {
            {
                .id = V4L2_CID_DO_WHITE_BALANCE,
                .type = V4L2_CTRL_TYPE_INTEGER,
-               .name = "While Balance",
+               .name = "White Balance",
                .minimum = WHITE_MIN,
                .maximum = WHITE_MAX,
                .step = 1,
index 2f2de429e273470669c42aa7d25749add1a33800..d9d64911f22a21220e73f0aa05ea5e415419ea87 100644 (file)
@@ -324,7 +324,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        int ret, value;
 
@@ -374,9 +374,10 @@ static void sd_start(struct gspca_dev *gspca_dev)
        set_par(gspca_dev, 0x01000000);
        set_par(gspca_dev, 0x01000000);
        PDEBUG(D_STREAM, "camera started alt: 0x%02x", gspca_dev->alt);
-       return;
+       return 0;
 out:
        PDEBUG(D_ERR|D_STREAM, "camera start err %d", ret);
+       return ret;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index 1cfcc6c4955874ab0bb05da32ef387136967c701..bd9288665a80c26c9e98e8bd451643652c19b023 100644 (file)
@@ -961,7 +961,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        struct usb_device *dev = gspca_dev->dev;
@@ -1042,6 +1042,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                break;
        }
        sp5xx_initContBrigHueRegisters(gspca_dev);
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index f034c748fc7ef5c3a608ff88e6ca1ab18e94261e..b561f7c4f066632571d8b12265b1ed776dc49231 100644 (file)
@@ -28,8 +28,6 @@
 
 #include "gspca.h"
 
-#define MAX_GAMMA 0x10         /* 0 to 15 */
-
 #define V4L2_CID_EFFECTS (V4L2_CID_PRIVATE_BASE + 0)
 
 MODULE_AUTHOR("Leandro Costantino <le_costantino@pixartargentina.com.ar>");
@@ -49,6 +47,10 @@ struct sd {
        unsigned char whitebalance;
        unsigned char mirror;
        unsigned char effect;
+
+       __u8 sensor;
+#define SENSOR_TAS5130A 0
+#define SENSOR_OTHER 1
 };
 
 /* V4L2 controls supported by the driver */
@@ -83,9 +85,9 @@ static struct ctrl sd_ctrls[] = {
          .type = V4L2_CTRL_TYPE_INTEGER,
          .name = "Brightness",
          .minimum = 0,
-         .maximum = 0x0f,
+         .maximum = 14,
          .step = 1,
-         .default_value = 0x09,
+         .default_value = 8,
          },
         .set = sd_setbrightness,
         .get = sd_getbrightness,
@@ -118,16 +120,17 @@ static struct ctrl sd_ctrls[] = {
         .set = sd_setcolors,
         .get = sd_getcolors,
         },
-#define SD_GAMMA 3
+#define GAMMA_MAX 16
+#define GAMMA_DEF 10
        {
         {
          .id = V4L2_CID_GAMMA, /* (gamma on win) */
          .type = V4L2_CTRL_TYPE_INTEGER,
-         .name = "Gamma (Untested)",
+         .name = "Gamma",
          .minimum = 0,
-         .maximum = MAX_GAMMA,
+         .maximum = GAMMA_MAX - 1,
          .step = 1,
-         .default_value = 0x09,
+         .default_value = GAMMA_DEF,
          },
         .set = sd_setgamma,
         .get = sd_getgamma,
@@ -197,7 +200,7 @@ static struct ctrl sd_ctrls[] = {
          .type = V4L2_CTRL_TYPE_INTEGER,
          .name = "Sharpness",
          .minimum = 0,
-         .maximum = MAX_GAMMA, /* 0 to 16 */
+         .maximum = 15,
          .step = 1,
          .default_value = 0x06,
          },
@@ -258,7 +261,6 @@ static struct v4l2_pix_format vga_mode_t16[] = {
                .priv = 0},
 };
 
-#define T16_OFFSET_DATA 631
 #define MAX_EFFECTS 7
 /* easily done by soft, this table could be removed,
  * i keep it here just in case */
@@ -272,87 +274,87 @@ static const __u8 effects_table[MAX_EFFECTS][6] = {
        {0xa8, 0xc8, 0xc6, 0xd2, 0xc0, 0x40},   /* Negative */
 };
 
-static const __u8 gamma_table[MAX_GAMMA][34] = {
-       {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85,
+static const __u8 gamma_table[GAMMA_MAX][34] = {
+       {0x90, 0x00, 0x91, 0x3e, 0x92, 0x69, 0x93, 0x85,        /* 0 */
         0x94, 0x95, 0x95, 0xa1, 0x96, 0xae, 0x97, 0xb9,
         0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdb,
         0x9c, 0xe3, 0x9d, 0xea, 0x9e, 0xf1, 0x9f, 0xf8,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x33, 0x92, 0x5A, 0x93, 0x75,
-        0x94, 0x85, 0x95, 0x93, 0x96, 0xA1, 0x97, 0xAD,
-        0x98, 0xB7, 0x99, 0xC2, 0x9A, 0xCB, 0x9B, 0xD4,
-        0x9C, 0xDE, 0x9D, 0xE7, 0x9E, 0xF0, 0x9F, 0xF7,
+       {0x90, 0x00, 0x91, 0x33, 0x92, 0x5a, 0x93, 0x75,        /* 1 */
+        0x94, 0x85, 0x95, 0x93, 0x96, 0xa1, 0x97, 0xad,
+        0x98, 0xb7, 0x99, 0xc2, 0x9a, 0xcb, 0x9b, 0xd4,
+        0x9c, 0xde, 0x9D, 0xe7, 0x9e, 0xf0, 0x9f, 0xf7,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x2F, 0x92, 0x51, 0x93, 0x6B,
-        0x94, 0x7C, 0x95, 0x8A, 0x96, 0x99, 0x97, 0xA6,
-        0x98, 0xB1, 0x99, 0xBC, 0x9A, 0xC6, 0x9B, 0xD0,
-        0x9C, 0xDB, 0x9D, 0xE4, 0x9E, 0xED, 0x9F, 0xF6,
+       {0x90, 0x00, 0x91, 0x2f, 0x92, 0x51, 0x93, 0x6b,        /* 2 */
+        0x94, 0x7c, 0x95, 0x8a, 0x96, 0x99, 0x97, 0xa6,
+        0x98, 0xb1, 0x99, 0xbc, 0x9a, 0xc6, 0x9b, 0xd0,
+        0x9c, 0xdb, 0x9d, 0xe4, 0x9e, 0xed, 0x9f, 0xf6,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60,
-        0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9E,
-        0x98, 0xAA, 0x99, 0xB5, 0x9A, 0xBF, 0x9B, 0xCB,
-        0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5,
+       {0x90, 0x00, 0x91, 0x29, 0x92, 0x48, 0x93, 0x60,        /* 3 */
+        0x94, 0x72, 0x95, 0x81, 0x96, 0x90, 0x97, 0x9e,
+        0x98, 0xaa, 0x99, 0xb5, 0x9a, 0xbf, 0x9b, 0xcb,
+        0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x23, 0x92, 0x3F, 0x93, 0x55,
+       {0x90, 0x00, 0x91, 0x23, 0x92, 0x3f, 0x93, 0x55,        /* 4 */
         0x94, 0x68, 0x95, 0x77, 0x96, 0x86, 0x97, 0x95,
-        0x98, 0xA2, 0x99, 0xAD, 0x9A, 0xB9, 0x9B, 0xC6,
-        0x9C, 0xD2, 0x9D, 0xDE, 0x9E, 0xE9, 0x9F, 0xF4,
+        0x98, 0xa2, 0x99, 0xad, 0x9a, 0xb9, 0x9b, 0xc6,
+        0x9c, 0xd2, 0x9d, 0xde, 0x9e, 0xe9, 0x9f, 0xf4,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x1B, 0x92, 0x33, 0x93, 0x48,
+       {0x90, 0x00, 0x91, 0x1b, 0x92, 0x33, 0x93, 0x48,        /* 5 */
         0x94, 0x59, 0x95, 0x69, 0x96, 0x79, 0x97, 0x87,
-        0x98, 0x96, 0x99, 0xA3, 0x9A, 0xB1, 0x9B, 0xBE,
-        0x9C, 0xCC, 0x9D, 0xDA, 0x9E, 0xE7, 0x9F, 0xF3,
+        0x98, 0x96, 0x99, 0xa3, 0x9a, 0xb1, 0x9b, 0xbe,
+        0x9c, 0xcc, 0x9d, 0xda, 0x9e, 0xe7, 0x9f, 0xf3,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20,
+       {0x90, 0x00, 0x91, 0x02, 0x92, 0x10, 0x93, 0x20,        /* 6 */
         0x94, 0x32, 0x95, 0x40, 0x96, 0x57, 0x97, 0x67,
         0x98, 0x77, 0x99, 0x88, 0x9a, 0x99, 0x9b, 0xaa,
         0x9c, 0xbb, 0x9d, 0xcc, 0x9e, 0xdd, 0x9f, 0xee,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26,
-        0x94, 0x38, 0x95, 0x4A, 0x96, 0x60, 0x97, 0x70,
-        0x98, 0x80, 0x99, 0x90, 0x9A, 0xA0, 0x9B, 0xB0,
-        0x9C, 0xC0, 0x9D, 0xD0, 0x9E, 0xE0, 0x9F, 0xF0,
+       {0x90, 0x00, 0x91, 0x02, 0x92, 0x14, 0x93, 0x26,        /* 7 */
+        0x94, 0x38, 0x95, 0x4a, 0x96, 0x60, 0x97, 0x70,
+        0x98, 0x80, 0x99, 0x90, 0x9a, 0xa0, 0x9b, 0xb0,
+        0x9c, 0xc0, 0x9D, 0xd0, 0x9e, 0xe0, 0x9f, 0xf0,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35,
-        0x94, 0x47, 0x95, 0x5A, 0x96, 0x69, 0x97, 0x79,
-        0x98, 0x88, 0x99, 0x97, 0x9A, 0xA7, 0x9B, 0xB6,
-        0x9C, 0xC4, 0x9D, 0xD3, 0x9E, 0xE0, 0x9F, 0xF0,
+       {0x90, 0x00, 0x91, 0x10, 0x92, 0x22, 0x93, 0x35,        /* 8 */
+        0x94, 0x47, 0x95, 0x5a, 0x96, 0x69, 0x97, 0x79,
+        0x98, 0x88, 0x99, 0x97, 0x9a, 0xa7, 0x9b, 0xb6,
+        0x9c, 0xc4, 0x9d, 0xd3, 0x9e, 0xe0, 0x9f, 0xf0,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40,
+       {0x90, 0x00, 0x91, 0x10, 0x92, 0x26, 0x93, 0x40,        /* 9 */
         0x94, 0x54, 0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
         0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd,
         0x9c, 0xca, 0x9d, 0xd6, 0x9e, 0xe0, 0x9f, 0xf0,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x18, 0x92, 0x2B, 0x93, 0x44,
-        0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8E,
-        0x98, 0x9C, 0x99, 0xAA, 0x9A, 0xB7, 0x9B, 0xC4,
-        0x9C, 0xD0, 0x9D, 0xD8, 0x9E, 0xE2, 0x9F, 0xF0,
+       {0x90, 0x00, 0x91, 0x18, 0x92, 0x2b, 0x93, 0x44,        /* 10 */
+        0x94, 0x60, 0x95, 0x70, 0x96, 0x80, 0x97, 0x8e,
+        0x98, 0x9c, 0x99, 0xaa, 0x9a, 0xb7, 0x9b, 0xc4,
+        0x9c, 0xd0, 0x9d, 0xd8, 0x9e, 0xe2, 0x9f, 0xf0,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x1A, 0x92, 0x34, 0x93, 0x52,
-        0x94, 0x66, 0x95, 0x7E, 0x96, 0x8D, 0x97, 0x9B,
-        0x98, 0xA8, 0x99, 0xB4, 0x9A, 0xC0, 0x9B, 0xCB,
-        0x9C, 0xD6, 0x9D, 0xE1, 0x9E, 0xEB, 0x9F, 0xF5,
+       {0x90, 0x00, 0x91, 0x1a, 0x92, 0x34, 0x93, 0x52,        /* 11 */
+        0x94, 0x66, 0x95, 0x7e, 0x96, 0x8D, 0x97, 0x9B,
+        0x98, 0xa8, 0x99, 0xb4, 0x9a, 0xc0, 0x9b, 0xcb,
+        0x9c, 0xd6, 0x9d, 0xe1, 0x9e, 0xeb, 0x9f, 0xf5,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x3F, 0x92, 0x5A, 0x93, 0x6E,
-        0x94, 0x7F, 0x95, 0x8E, 0x96, 0x9C, 0x97, 0xA8,
-        0x98, 0xB4, 0x99, 0xBF, 0x9A, 0xC9, 0x9B, 0xD3,
-        0x9C, 0xDC, 0x9D, 0xE5, 0x9E, 0xEE, 0x9F, 0xF6,
-        0xA0, 0xFF},
-       {0x90, 0x00, 0x91, 0x54, 0x92, 0x6F, 0x93, 0x83,
-        0x94, 0x93, 0x95, 0xA0, 0x96, 0xAD, 0x97, 0xB7,
-        0x98, 0xC2, 0x99, 0xCB, 0x9A, 0xD4, 0x9B, 0xDC,
-        0x9C, 0xE4, 0x9D, 0xEB, 0x9E, 0xF2, 0x9F, 0xF9,
+       {0x90, 0x00, 0x91, 0x3f, 0x92, 0x5a, 0x93, 0x6e,        /* 12 */
+        0x94, 0x7f, 0x95, 0x8e, 0x96, 0x9c, 0x97, 0xa8,
+        0x98, 0xb4, 0x99, 0xbf, 0x9a, 0xc9, 0x9b, 0xd3,
+        0x9c, 0xdc, 0x9d, 0xe5, 0x9e, 0xee, 0x9f, 0xf6,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x6E, 0x92, 0x88, 0x93, 0x9A,
-        0x94, 0xA8, 0x95, 0xB3, 0x96, 0xBD, 0x97, 0xC6,
-        0x98, 0xCF, 0x99, 0xD6, 0x9A, 0xDD, 0x9B, 0xE3,
-        0x9C, 0xE9, 0x9D, 0xEF, 0x9E, 0xF4, 0x9F, 0xFA,
+       {0x90, 0x00, 0x91, 0x54, 0x92, 0x6f, 0x93, 0x83,        /* 13 */
+        0x94, 0x93, 0x95, 0xa0, 0x96, 0xad, 0x97, 0xb7,
+        0x98, 0xc2, 0x99, 0xcb, 0x9a, 0xd4, 0x9b, 0xdc,
+        0x9c, 0xe4, 0x9d, 0xeb, 0x9e, 0xf2, 0x9f, 0xf9,
         0xa0, 0xff},
-       {0x90, 0x00, 0x91, 0x93, 0x92, 0xA8, 0x93, 0xB7,
-        0x94, 0xC1, 0x95, 0xCA, 0x96, 0xD2, 0x97, 0xD8,
-        0x98, 0xDE, 0x99, 0xE3, 0x9A, 0xE8, 0x9B, 0xED,
-        0x9C, 0xF1, 0x9D, 0xF5, 0x9E, 0xF8, 0x9F, 0xFC,
-        0xA0, 0xFF}
+       {0x90, 0x00, 0x91, 0x6e, 0x92, 0x88, 0x93, 0x9a,        /* 14 */
+        0x94, 0xa8, 0x95, 0xb3, 0x96, 0xbd, 0x97, 0xc6,
+        0x98, 0xcf, 0x99, 0xd6, 0x9a, 0xdd, 0x9b, 0xe3,
+        0x9c, 0xe9, 0x9d, 0xef, 0x9e, 0xf4, 0x9f, 0xfa,
+        0xa0, 0xff},
+       {0x90, 0x00, 0x91, 0x93, 0x92, 0xa8, 0x93, 0xb7,        /* 15 */
+        0x94, 0xc1, 0x95, 0xca, 0x96, 0xd2, 0x97, 0xd8,
+        0x98, 0xde, 0x99, 0xe3, 0x9a, 0xe8, 0x9b, 0xed,
+        0x9c, 0xf1, 0x9d, 0xf5, 0x9e, 0xf8, 0x9f, 0xfc,
+        0xa0, 0xff}
 };
 
 static const __u8 tas5130a_sensor_init[][8] = {
@@ -364,7 +366,7 @@ static const __u8 tas5130a_sensor_init[][8] = {
 };
 
 /* read 1 byte */
-static int reg_r_1(struct gspca_dev *gspca_dev,
+static int reg_r(struct gspca_dev *gspca_dev,
                   __u16 index)
 {
        usb_control_msg(gspca_dev->dev,
@@ -378,26 +380,26 @@ static int reg_r_1(struct gspca_dev *gspca_dev,
 }
 
 static void reg_w(struct gspca_dev *gspca_dev,
-                       __u16 value,
-                       __u16 index,
-                       const __u8 *buffer, __u16 len)
+                 __u16 index)
+{
+       usb_control_msg(gspca_dev->dev,
+                       usb_sndctrlpipe(gspca_dev->dev, 0),
+                       0,
+                       USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
+                       0, index,
+                       NULL, 0, 500);
+}
+
+static void i2c_w(struct gspca_dev *gspca_dev,
+                 const __u8 *buffer, __u16 len)
 {
-       if (buffer == NULL) {
-               usb_control_msg(gspca_dev->dev,
-                               usb_sndctrlpipe(gspca_dev->dev, 0),
-                               0,
-                          USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
-                               value, index,
-                               NULL, 0, 500);
-               return;
-       }
        if (len <= USB_BUF_SZ) {
                memcpy(gspca_dev->usb_buf, buffer, len);
                usb_control_msg(gspca_dev->dev,
                                usb_sndctrlpipe(gspca_dev->dev, 0),
                                0,
                           USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
-                               value, index,
+                               0x01, 0,
                                gspca_dev->usb_buf, len, 500);
        } else {
                __u8 *tmpbuf;
@@ -408,12 +410,56 @@ static void reg_w(struct gspca_dev *gspca_dev,
                                usb_sndctrlpipe(gspca_dev->dev, 0),
                                0,
                           USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE,
-                               value, index,
+                               0x01, 0,
                                tmpbuf, len, 500);
                kfree(tmpbuf);
        }
 }
 
+static void other_sensor_init(struct gspca_dev *gspca_dev)
+{
+       int i;
+       const __u8 *p;
+       __u8 byte;
+       __u8 val[6] = {0x62, 0, 0x64, 0, 0x60, 0x05};
+       static const __u8 sensor_init[] = {
+               0xdf, 0x6d,
+               0xdd, 0x18,
+               0x5a, 0xe0,
+               0x5c, 0x07,
+               0x5d, 0xb0,
+               0x5e, 0x1e,
+               0x60, 0x71,
+               0xef, 0x00,
+               0xe9, 0x00,
+               0xea, 0x00,
+               0x90, 0x24,
+               0x91, 0xb2,
+               0x82, 0x32,
+               0xfd, 0x00,
+               0xfd, 0x01,
+               0xfd, 0x41,
+               0x00                    /* table end */
+       };
+
+       p = sensor_init;
+       while (*p != 0) {
+               val[1] = *p++;
+               val[3] = *p++;
+               if (*p == 0)
+                       reg_w(gspca_dev, 0x3c80);
+               i2c_w(gspca_dev, val, sizeof val);
+               i = 4;
+               while (--i >= 0) {
+                       msleep(15);
+                       byte = reg_r(gspca_dev, 0x60);
+                       if (!(byte & 0x01))
+                               break;
+               }
+       }
+                       reg_w(gspca_dev, 0x3c80);
+}
+
 /* this function is called at probe time */
 static int sd_config(struct gspca_dev *gspca_dev,
                     const struct usb_device_id *id)
@@ -430,7 +476,7 @@ static int sd_config(struct gspca_dev *gspca_dev,
        sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value;
        sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value;
        sd->colors = sd_ctrls[SD_COLOR].qctrl.default_value;
-       sd->gamma = sd_ctrls[SD_GAMMA].qctrl.default_value;
+       sd->gamma = GAMMA_DEF;
        sd->mirror = sd_ctrls[SD_MIRROR].qctrl.default_value;
        sd->freq = sd_ctrls[SD_LIGHTFREQ].qctrl.default_value;
        sd->whitebalance = sd_ctrls[SD_WHITE_BALANCE].qctrl.default_value;
@@ -439,27 +485,37 @@ static int sd_config(struct gspca_dev *gspca_dev,
        return 0;
 }
 
-static int init_default_parameters(struct gspca_dev *gspca_dev)
+static void setgamma(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+
+       PDEBUG(D_CONF, "Gamma: %d", sd->gamma);
+       i2c_w(gspca_dev, gamma_table[sd->gamma], sizeof gamma_table[0]);
+}
+
+/* this function is called at probe and resume time */
+static int sd_init(struct gspca_dev *gspca_dev)
 {
        /* some of this registers are not really neded, because
         * they are overriden by setbrigthness, setcontrast, etc,
         * but wont hurt anyway, and can help someone with similar webcam
         * to see the initial parameters.*/
-       int i = 0;
-       __u8 test_byte;
+       struct sd *sd = (struct sd *) gspca_dev;
+       int i;
+       __u8 byte, test_byte;
 
        static const __u8 read_indexs[] =
                { 0x06, 0x07, 0x0a, 0x0b, 0x66, 0x80, 0x81, 0x8e, 0x8f, 0xa5,
                  0xa6, 0xa8, 0xbb, 0xbc, 0xc6, 0x00, 0x00 };
-       static const __u8 n1[6] =
+       static const __u8 n1[] =
                        {0x08, 0x03, 0x09, 0x03, 0x12, 0x04};
-       static const __u8 n2[2] =
+       static const __u8 n2[] =
                        {0x08, 0x00};
-       static const __u8 nset[6] =
-               { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 };
-       static const __u8 n3[6] =
+       static const __u8 nset[] =
+                       { 0x61, 0x68, 0x62, 0xff, 0x60, 0x07 };
+       static const __u8 n3[] =
                        {0x61, 0x68, 0x65, 0x0a, 0x60, 0x04};
-       static const __u8 n4[0x46] =
+       static const __u8 n4[] =
                {0x09, 0x01, 0x12, 0x04, 0x66, 0x8a, 0x80, 0x3c,
                 0x81, 0x22, 0x84, 0x50, 0x8a, 0x78, 0x8b, 0x68,
                 0x8c, 0x88, 0x8e, 0x33, 0x8f, 0x24, 0xaa, 0xb1,
@@ -469,33 +525,26 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
                 0x65, 0x0a, 0xbb, 0x86, 0xaf, 0x58, 0xb0, 0x68,
                 0x87, 0x40, 0x89, 0x2b, 0x8d, 0xff, 0x83, 0x40,
                 0xac, 0x84, 0xad, 0x86, 0xaf, 0x46};
-       static const __u8 nset4[18] = {
+       static const __u8 nset4[] = {
                0xe0, 0x60, 0xe1, 0xa8, 0xe2, 0xe0, 0xe3, 0x60, 0xe4, 0xa8,
                0xe5, 0xe0, 0xe6, 0x60, 0xe7, 0xa8,
                0xe8, 0xe0
        };
        /* ojo puede ser 0xe6 en vez de 0xe9 */
-       static const __u8 nset2[20] = {
+       static const __u8 nset2[] = {
                0xd0, 0xbb, 0xd1, 0x28, 0xd2, 0x10, 0xd3, 0x10, 0xd4, 0xbb,
                0xd5, 0x28, 0xd6, 0x1e, 0xd7, 0x27,
                0xd8, 0xc8, 0xd9, 0xfc
        };
-       static const __u8 missing[8] =
+       static const __u8 missing[] =
                { 0x87, 0x20, 0x88, 0x20, 0x89, 0x20, 0x80, 0x38 };
-       static const __u8 nset3[18] = {
+       static const __u8 nset3[] = {
                0xc7, 0x60, 0xc8, 0xa8, 0xc9, 0xe0, 0xca, 0x60, 0xcb, 0xa8,
                0xcc, 0xe0, 0xcd, 0x60, 0xce, 0xa8,
                0xcf, 0xe0
        };
-       static const __u8 nset5[4] =
-               { 0x8f, 0x24, 0xc3, 0x00 };     /* bright */
-       static const __u8 nset6[34] = {
-               0x90, 0x00, 0x91, 0x1c, 0x92, 0x30, 0x93, 0x43, 0x94, 0x54,
-               0x95, 0x65, 0x96, 0x75, 0x97, 0x84,
-               0x98, 0x93, 0x99, 0xa1, 0x9a, 0xb0, 0x9b, 0xbd, 0x9c, 0xca,
-               0x9d, 0xd8, 0x9e, 0xe5, 0x9f, 0xf2,
-               0xa0, 0xff
-       };                      /* Gamma */
+       static const __u8 nset5[] =
+                       { 0x8f, 0x24, 0xc3, 0x00 };     /* bright */
        static const __u8 nset7[4] =
                        { 0x66, 0xca, 0xa8, 0xf8 };     /* 50/60 Hz */
        static const __u8 nset9[4] =
@@ -505,95 +554,111 @@ static int init_default_parameters(struct gspca_dev *gspca_dev)
        static const __u8 nset10[6] =
                        { 0x0c, 0x03, 0xab, 0x10, 0x81, 0x20 };
 
-       reg_w(gspca_dev, 0x01, 0x0000, n1, 0x06);
-       reg_w(gspca_dev, 0x01, 0x0000, nset, 0x06);
-       reg_r_1(gspca_dev, 0x0063);
-       reg_w(gspca_dev, 0x01, 0x0000, n2, 0x02);
+       byte = reg_r(gspca_dev, 0x06);
+       test_byte = reg_r(gspca_dev, 0x07);
+       if (byte == 0x08 && test_byte == 0x07) {
+               PDEBUG(D_CONF, "other sensor");
+               sd->sensor = SENSOR_OTHER;
+       } else {
+               PDEBUG(D_CONF, "sensor %02x %02x", byte, test_byte);
+               sd->sensor = SENSOR_TAS5130A;
+       }
+
+       i2c_w(gspca_dev, n1, sizeof n1);
+       test_byte = 0;
+       i = 5;
+       while (--i >= 0) {
+               i2c_w(gspca_dev, nset, sizeof nset);
+               msleep(5);
+               test_byte = reg_r(gspca_dev, 0x0063);
+               msleep(100);
+               if (test_byte == 0x17)
+                       break;          /* OK */
+       }
+       if (i < 0) {
+               err("Bad sensor reset %02x", test_byte);
+/*             return -EIO; */
+/*fixme: test - continue */
+       }
+       i2c_w(gspca_dev, n2, sizeof n2);
 
+       i = 0;
        while (read_indexs[i] != 0x00) {
-               test_byte = reg_r_1(gspca_dev, read_indexs[i]);
-               PDEBUG(D_CONF, "Reg 0x%02x => 0x%02x", read_indexs[i],
+               test_byte = reg_r(gspca_dev, read_indexs[i]);
+               PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", read_indexs[i],
                       test_byte);
                i++;
        }
 
-       reg_w(gspca_dev, 0x01, 0x0000, n3, 0x06);
-       reg_w(gspca_dev, 0x01, 0x0000, n4, 0x46);
-       reg_r_1(gspca_dev, 0x0080);
-       reg_w(gspca_dev, 0x00, 0x2c80, NULL, 0);
-       reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14);
-       reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12);
-       reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12);
-       reg_w(gspca_dev, 0x00, 0x3880, NULL, 0);
-       reg_w(gspca_dev, 0x00, 0x3880, NULL, 0);
-       reg_w(gspca_dev, 0x00, 0x338e, NULL, 0);
-       reg_w(gspca_dev, 0x01, 0x0000, nset5, 0x04);
-       reg_w(gspca_dev, 0x00, 0x00a9, NULL, 0);
-       reg_w(gspca_dev, 0x01, 0x0000, nset6, 0x22);
-       reg_w(gspca_dev, 0x00, 0x86bb, NULL, 0);
-       reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0);
-
-       reg_w(gspca_dev, 0x01, 0x0000, missing, 0x08);
-
-       reg_w(gspca_dev, 0x00, 0x2087, NULL, 0);
-       reg_w(gspca_dev, 0x00, 0x2088, NULL, 0);
-       reg_w(gspca_dev, 0x00, 0x2089, NULL, 0);
-
-       reg_w(gspca_dev, 0x01, 0x0000, nset7, 0x04);
-       reg_w(gspca_dev, 0x01, 0x0000, nset10, 0x06);
-       reg_w(gspca_dev, 0x01, 0x0000, nset8, 0x06);
-       reg_w(gspca_dev, 0x01, 0x0000, nset9, 0x04);
-
-       reg_w(gspca_dev, 0x00, 0x2880, NULL, 0);
-       reg_w(gspca_dev, 0x01, 0x0000, nset2, 0x14);
-       reg_w(gspca_dev, 0x01, 0x0000, nset3, 0x12);
-       reg_w(gspca_dev, 0x01, 0x0000, nset4, 0x12);
+       i2c_w(gspca_dev, n3, sizeof n3);
+       i2c_w(gspca_dev, n4, sizeof n4);
+       reg_r(gspca_dev, 0x0080);
+       reg_w(gspca_dev, 0x2c80);
+       i2c_w(gspca_dev, nset2, sizeof nset2);
+       i2c_w(gspca_dev, nset3, sizeof nset3);
+       i2c_w(gspca_dev, nset4, sizeof nset4);
+       reg_w(gspca_dev, 0x3880);
+       reg_w(gspca_dev, 0x3880);
+       reg_w(gspca_dev, 0x338e);
+       i2c_w(gspca_dev, nset5, sizeof nset5);
+       reg_w(gspca_dev, 0x00a9);
+       setgamma(gspca_dev);
+       reg_w(gspca_dev, 0x86bb);
+       reg_w(gspca_dev, 0x4aa6);
+
+       i2c_w(gspca_dev, missing, sizeof missing);
+
+       reg_w(gspca_dev, 0x2087);
+       reg_w(gspca_dev, 0x2088);
+       reg_w(gspca_dev, 0x2089);
+
+       i2c_w(gspca_dev, nset7, sizeof nset7);
+       i2c_w(gspca_dev, nset10, sizeof nset10);
+       i2c_w(gspca_dev, nset8, sizeof nset8);
+       i2c_w(gspca_dev, nset9, sizeof nset9);
+
+       reg_w(gspca_dev, 0x2880);
+       i2c_w(gspca_dev, nset2, sizeof nset2);
+       i2c_w(gspca_dev, nset3, sizeof nset3);
+       i2c_w(gspca_dev, nset4, sizeof nset4);
 
        return 0;
 }
 
-/* this function is called at probe and resume time */
-static int sd_init(struct gspca_dev *gspca_dev)
-{
-       init_default_parameters(gspca_dev);
-       return 0;
-}
-
 static void setbrightness(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        unsigned int brightness;
-       __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x80 };
-       brightness = sd->brightness;
+       __u8 set6[4] = { 0x8f, 0x26, 0xc3, 0x00 };
 
+       brightness = sd->brightness;
        if (brightness < 7) {
-               set6[3] = 0x70 - (brightness * 0xa);
+               set6[3] = 0x70 - brightness * 0x10;
        } else {
                set6[1] = 0x24;
-               set6[3] = 0x00 + ((brightness - 7) * 0xa);
+               set6[3] = 0x00 + ((brightness - 7) * 0x10);
        }
 
-       reg_w(gspca_dev, 0x01, 0x0000, set6, 4);
+       i2c_w(gspca_dev, set6, sizeof set6);
 }
 
 static void setflip(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
-
        __u8 flipcmd[8] =
-           { 0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09 };
+               {0x62, 0x07, 0x63, 0x03, 0x64, 0x00, 0x60, 0x09};
 
-       if (sd->mirror == 1)
+       if (sd->mirror)
                flipcmd[3] = 0x01;
 
-       reg_w(gspca_dev, 0x01, 0x0000, flipcmd, 8);
+       i2c_w(gspca_dev, flipcmd, sizeof flipcmd);
 }
 
 static void seteffect(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
 
-       reg_w(gspca_dev, 0x01, 0x0000, effects_table[sd->effect], 0x06);
+       i2c_w(gspca_dev, effects_table[sd->effect], sizeof effects_table[0]);
        if (sd->effect == 1 || sd->effect == 5) {
                PDEBUG(D_CONF,
                       "This effect have been disabled for webcam \"safety\"");
@@ -601,9 +666,9 @@ static void seteffect(struct gspca_dev *gspca_dev)
        }
 
        if (sd->effect == 1 || sd->effect == 4)
-               reg_w(gspca_dev, 0x00, 0x4aa6, NULL, 0);
+               reg_w(gspca_dev, 0x4aa6);
        else
-               reg_w(gspca_dev, 0x00, 0xfaa6, NULL, 0);
+               reg_w(gspca_dev, 0xfaa6);
 }
 
 static void setwhitebalance(struct gspca_dev *gspca_dev)
@@ -616,7 +681,7 @@ static void setwhitebalance(struct gspca_dev *gspca_dev)
        if (sd->whitebalance == 1)
                white_balance[7] = 0x3c;
 
-       reg_w(gspca_dev, 0x01, 0x0000, white_balance, 8);
+       i2c_w(gspca_dev, white_balance, sizeof white_balance);
 }
 
 static void setlightfreq(struct gspca_dev *gspca_dev)
@@ -627,21 +692,21 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
        if (sd->freq == 2)      /* 60hz */
                freq[1] = 0x00;
 
-       reg_w(gspca_dev, 0x1, 0x0000, freq, 0x4);
+       i2c_w(gspca_dev, freq, sizeof freq);
 }
 
 static void setcontrast(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        unsigned int contrast = sd->contrast;
-       __u16 reg_to_write = 0x00;
+       __u16 reg_to_write;
 
        if (contrast < 7)
                reg_to_write = 0x8ea9 - (0x200 * contrast);
        else
                reg_to_write = (0x00a9 + ((contrast - 7) * 0x200));
 
-       reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
+       reg_w(gspca_dev, reg_to_write);
 }
 
 static void setcolors(struct gspca_dev *gspca_dev)
@@ -650,11 +715,7 @@ static void setcolors(struct gspca_dev *gspca_dev)
        __u16 reg_to_write;
 
        reg_to_write = 0xc0bb + sd->colors * 0x100;
-       reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
-}
-
-static void setgamma(struct gspca_dev *gspca_dev)
-{
+       reg_w(gspca_dev, reg_to_write);
 }
 
 static void setsharpness(struct gspca_dev *gspca_dev)
@@ -664,7 +725,99 @@ static void setsharpness(struct gspca_dev *gspca_dev)
 
        reg_to_write = 0x0aa6 + 0x1000 * sd->sharpness;
 
-       reg_w(gspca_dev, 0x00, reg_to_write, NULL, 0);
+       reg_w(gspca_dev, reg_to_write);
+}
+
+static int sd_start(struct gspca_dev *gspca_dev)
+{
+       struct sd *sd = (struct sd *) gspca_dev;
+       int i, mode;
+       static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
+       __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
+       static const __u8 t3[] =
+               { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
+                 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
+       static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
+
+       mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
+       switch (mode) {
+       case 1:         /* 352x288 */
+               t2[1] = 0x40;
+               break;
+       case 2:         /* 320x240 */
+               t2[1] = 0x10;
+               break;
+       case 3:         /* 176x144 */
+               t2[1] = 0x50;
+               break;
+       case 4:         /* 160x120 */
+               t2[1] = 0x20;
+               break;
+       default:        /* 640x480 (0x00) */
+               break;
+       }
+
+       if (sd->sensor == SENSOR_TAS5130A) {
+               i = 0;
+               while (tas5130a_sensor_init[i][0] != 0) {
+                       i2c_w(gspca_dev, tas5130a_sensor_init[i],
+                                        sizeof tas5130a_sensor_init[0]);
+                       i++;
+               }
+               reg_w(gspca_dev, 0x3c80);
+               /* just in case and to keep sync with logs (for mine) */
+               i2c_w(gspca_dev, tas5130a_sensor_init[3],
+                                sizeof tas5130a_sensor_init[0]);
+               reg_w(gspca_dev, 0x3c80);
+       } else {
+               other_sensor_init(gspca_dev);
+       }
+       /* just in case and to keep sync with logs  (for mine) */
+       i2c_w(gspca_dev, t1, sizeof t1);
+       i2c_w(gspca_dev, t2, sizeof t2);
+       reg_r(gspca_dev, 0x0012);
+       i2c_w(gspca_dev, t3, sizeof t3);
+       reg_w(gspca_dev, 0x0013);
+       i2c_w(gspca_dev, t4, sizeof t4);
+       /* restart on each start, just in case, sometimes regs goes wrong
+        * when using controls from app */
+       setbrightness(gspca_dev);
+       setcontrast(gspca_dev);
+       setcolors(gspca_dev);
+       return 0;
+}
+
+static void sd_pkt_scan(struct gspca_dev *gspca_dev,
+                       struct gspca_frame *frame,      /* target */
+                       __u8 *data,                     /* isoc packet */
+                       int len)                        /* iso packet length */
+{
+       static __u8 ffd9[] = { 0xff, 0xd9 };
+
+       if (data[0] == 0x5a) {
+               /* Control Packet, after this came the header again,
+                * but extra bytes came in the packet before this,
+                * sometimes an EOF arrives, sometimes not... */
+               return;
+       }
+       data += 2;
+       len -= 2;
+       if (data[0] == 0xff && data[1] == 0xd8) {
+               /* extra bytes....., could be processed too but would be
+                * a waste of time, right now leave the application and
+                * libjpeg do it for ourserlves.. */
+               frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
+                                       ffd9, 2);
+               gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
+               return;
+       }
+
+       if (data[len - 2] == 0xff && data[len - 1] == 0xd9) {
+               /* Just in case, i have seen packets with the marker,
+                * other's do not include it... */
+               len -= 2;
+       }
+       gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
 }
 
 static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val)
@@ -788,6 +941,7 @@ static int sd_setgamma(struct gspca_dev *gspca_dev, __s32 val)
 static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val)
 {
        struct sd *sd = (struct sd *) gspca_dev;
+
        *val = sd->gamma;
        return 0;
 }
@@ -835,9 +989,9 @@ static int sd_setlowlight(struct gspca_dev *gspca_dev, __s32 val)
 
        sd->autogain = val;
        if (val != 0)
-               reg_w(gspca_dev, 0x00, 0xf48e, NULL, 0);
+               reg_w(gspca_dev, 0xf48e);
        else
-               reg_w(gspca_dev, 0x00, 0xb48e, NULL, 0);
+               reg_w(gspca_dev, 0xb48e);
        return 0;
 }
 
@@ -849,99 +1003,6 @@ static int sd_getlowlight(struct gspca_dev *gspca_dev, __s32 *val)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
-{
-       int mode;
-
-       static const __u8 t1[] = { 0x66, 0x00, 0xa8, 0xe8 };
-       __u8 t2[] = { 0x07, 0x00, 0x0d, 0x60, 0x0e, 0x80 };
-       static const __u8 t3[] =
-               { 0xb3, 0x07, 0xb4, 0x00, 0xb5, 0x88, 0xb6, 0x02, 0xb7, 0x06,
-                 0xb8, 0x00, 0xb9, 0xe7, 0xba, 0x01 };
-       static const __u8 t4[] = { 0x0b, 0x04, 0x0a, 0x40 };
-
-       mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode]. priv;
-       switch (mode) {
-       case 1:         /* 352x288 */
-               t2[1] = 0x40;
-               break;
-       case 2:         /* 320x240 */
-               t2[1] = 0x10;
-               break;
-       case 3:         /* 176x144 */
-               t2[1] = 0x50;
-               break;
-       case 4:         /* 160x120 */
-               t2[1] = 0x20;
-               break;
-       default:        /* 640x480 (0x00) */
-               break;
-       }
-
-       reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[0], 0x8);
-       reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[1], 0x8);
-       reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[2], 0x8);
-       reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
-       reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
-               /* just in case and to keep sync with logs  (for mine) */
-       reg_w(gspca_dev, 0x01, 0x0000, tas5130a_sensor_init[3], 0x8);
-       reg_w(gspca_dev, 0x00, 0x3c80, NULL, 0);
-               /* just in case and to keep sync with logs  (for mine) */
-       reg_w(gspca_dev, 0x01, 0x0000, t1, 4);
-       reg_w(gspca_dev, 0x01, 0x0000, t2, 6);
-       reg_r_1(gspca_dev, 0x0012);
-       reg_w(gspca_dev, 0x01, 0x0000, t3, 0x10);
-       reg_w(gspca_dev, 0x00, 0x0013, NULL, 0);
-       reg_w(gspca_dev, 0x01, 0x0000, t4, 0x4);
-       /* restart on each start, just in case, sometimes regs goes wrong
-        * when using controls from app */
-       setbrightness(gspca_dev);
-       setcontrast(gspca_dev);
-       setcolors(gspca_dev);
-}
-
-static void sd_pkt_scan(struct gspca_dev *gspca_dev,
-                       struct gspca_frame *frame,      /* target */
-                       __u8 *data,                     /* isoc packet */
-                       int len)                        /* iso packet length */
-{
-       int sof = 0;
-       static __u8 ffd9[] = { 0xff, 0xd9 };
-
-       if (data[0] == 0x5a) {
-               /* Control Packet, after this came the header again,
-                * but extra bytes came in the packet before this,
-                * sometimes an EOF arrives, sometimes not... */
-               return;
-       }
-
-       if (data[len - 1] == 0xff && data[len] == 0xd9) {
-               /* Just in case, i have seen packets with the marker,
-                * other's do not include it... */
-               data += 2;
-               len -= 4;
-       } else if (data[2] == 0xff && data[3] == 0xd8) {
-               sof = 1;
-               data += 2;
-               len -= 2;
-       } else {
-               data += 2;
-               len -= 2;
-       }
-
-       if (sof) {
-               /* extra bytes....., could be processed too but would be
-                * a waste of time, right now leave the application and
-                * libjpeg do it for ourserlves.. */
-               frame = gspca_frame_add(gspca_dev, LAST_PACKET, frame,
-                                       ffd9, 2);
-               gspca_frame_add(gspca_dev, FIRST_PACKET, frame, data, len);
-               return;
-       }
-
-       gspca_frame_add(gspca_dev, INTER_PACKET, frame, data, len);
-}
-
 static int sd_querymenu(struct gspca_dev *gspca_dev,
                        struct v4l2_querymenu *menu)
 {
index 084af05302a0399f7e84e993437557d7433e3a3e..968a5911704fd381c2fe8ac67ead6b49d361b72f 100644 (file)
@@ -390,7 +390,7 @@ static void setbrightness(struct gspca_dev *gspca_dev)
 }
 
 /* -- start the camera -- */
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        reg_w_1(gspca_dev, TV8532_AD_SLOPE, 0x32);
        reg_w_1(gspca_dev, TV8532_AD_BITCTRL, 0x00);
@@ -443,6 +443,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
        /************************************************/
        tv_8532_PollReg(gspca_dev);
        reg_w_1(gspca_dev, TV8532_UDP_UPDATE, 0x00);    /* 0x31 */
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index bd4c226c9a077843d2b787210cf227574c8dedea..be46d92325404d66b48c6e527005c736c5102812 100644 (file)
@@ -80,7 +80,6 @@ static struct ctrl sd_ctrls[] = {
                .step    = 1,
 #define FREQ_DEF 1
                .default_value = FREQ_DEF,
-               .default_value = 1,
            },
            .set = sd_setfreq,
            .get = sd_getfreq,
@@ -1502,7 +1501,7 @@ static void setlightfreq(struct gspca_dev *gspca_dev)
        usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]);
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        const __u8 *GammaT = NULL;
@@ -1586,7 +1585,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                break;
        default:
                PDEBUG(D_PROBE, "Damned !! no sensor found Bye");
-               return;
+               return -EMEDIUMTYPE;
        }
        if (GammaT && MatrixT) {
                put_tab_to_reg(gspca_dev, GammaT, 17, 0xb84a);
@@ -1622,6 +1621,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                setautogain(gspca_dev);
                setlightfreq(gspca_dev);
        }
+       return 0;
 }
 
 static void sd_stopN(struct gspca_dev *gspca_dev)
index d61ef727e0c241e08fe65b4f972450c154828da3..d0a4451dc46f2cf48ff3e73bba6e415aed9f086b 100644 (file)
@@ -7178,7 +7178,7 @@ static int sd_init(struct gspca_dev *gspca_dev)
        return 0;
 }
 
-static void sd_start(struct gspca_dev *gspca_dev)
+static int sd_start(struct gspca_dev *gspca_dev)
 {
        struct sd *sd = (struct sd *) gspca_dev;
        struct usb_device *dev = gspca_dev->dev;
@@ -7331,6 +7331,7 @@ static void sd_start(struct gspca_dev *gspca_dev)
                reg_w(dev, 0x02, 0x0008);
                break;
        }
+       return 0;
 }
 
 static void sd_stop0(struct gspca_dev *gspca_dev)
index a30254bed3119ed8483270d7f6e8cdb79624da6f..efe849981ab7c3766bb61efe78e437ebc1bb6ff1 100644 (file)
  *      Markus Rechberger <mrechberger@gmail.com>
  * modified for DViCO Fusion HDTV 5 RT GOLD by
  *      Chaogui Zhang <czhang1974@gmail.com>
+ * modified for MSI TV@nywhere Plus by
+ *      Henry Wong <henry@stuffedcow.net>
+ *      Mark Schultz <n9xmj@yahoo.com>
+ *      Brian Rogers <brian_rogers@comcast.net>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -65,7 +69,7 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
                               int size, int offset)
 {
        unsigned char buf[6];
-       int start, range, toggle, dev, code;
+       int start, range, toggle, dev, code, ircode;
 
        /* poll IR chip */
        if (size != i2c_master_recv(&ir->c,buf,size))
@@ -85,6 +89,24 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
        if (!start)
                /* no key pressed */
                return 0;
+       /*
+        * Hauppauge remotes (black/silver) always use
+        * specific device ids. If we do not filter the
+        * device ids then messages destined for devices
+        * such as TVs (id=0) will get through causing
+        * mis-fired events.
+        *
+        * We also filter out invalid key presses which
+        * produce annoying debug log entries.
+        */
+       ircode= (start << 12) | (toggle << 11) | (dev << 6) | code;
+       if ((ircode & 0x1fff)==0x1fff)
+               /* invalid key press */
+               return 0;
+
+       if (dev!=0x1e && dev!=0x1f)
+               /* not a hauppauge remote */
+               return 0;
 
        if (!range)
                code += 64;
@@ -94,7 +116,7 @@ static int get_key_haup_common(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw,
 
        /* return key */
        *ir_key = code;
-       *ir_raw = (start << 12) | (toggle << 11) | (dev << 6) | code;
+       *ir_raw = ircode;
        return 1;
 }
 
@@ -224,9 +246,15 @@ static void ir_timer(unsigned long data)
 static void ir_work(struct work_struct *work)
 {
        struct IR_i2c *ir = container_of(work, struct IR_i2c, work);
+       int polling_interval = 100;
+
+       /* MSI TV@nywhere Plus requires more frequent polling
+          otherwise it will miss some keypresses */
+       if (ir->c.adapter->id == I2C_HW_SAA7134 && ir->c.addr == 0x30)
+               polling_interval = 50;
 
        ir_key_poll(ir);
-       mod_timer(&ir->timer, jiffies + msecs_to_jiffies(100));
+       mod_timer(&ir->timer, jiffies + msecs_to_jiffies(polling_interval));
 }
 
 /* ----------------------------------------------------------------------- */
@@ -465,9 +493,37 @@ static int ir_probe(struct i2c_adapter *adap)
                        (1 == rc) ? "yes" : "no");
                if (1 == rc) {
                        ir_attach(adap, probe[i], 0, 0);
-                       break;
+                       return 0;
                }
        }
+
+       /* Special case for MSI TV@nywhere Plus remote */
+       if (adap->id == I2C_HW_SAA7134) {
+               u8 temp;
+
+               /* MSI TV@nywhere Plus controller doesn't seem to
+                  respond to probes unless we read something from
+                  an existing device. Weird... */
+
+               msg.addr = 0x50;
+               rc = i2c_transfer(adap, &msg, 1);
+                       dprintk(1, "probe 0x%02x @ %s: %s\n",
+                       msg.addr, adap->name,
+                       (1 == rc) ? "yes" : "no");
+
+               /* Now do the probe. The controller does not respond
+                  to 0-byte reads, so we use a 1-byte read instead. */
+               msg.addr = 0x30;
+               msg.len = 1;
+               msg.buf = &temp;
+               rc = i2c_transfer(adap, &msg, 1);
+               dprintk(1, "probe 0x%02x @ %s: %s\n",
+                       msg.addr, adap->name,
+                       (1 == rc) ? "yes" : "no");
+               if (1 == rc)
+                       ir_attach(adap, msg.addr, 0, 0);
+       }
+
        return 0;
 }
 
index 381af1bceef84c9924ee69b0c33f31a64a78820e..0b8fe85fb697972aae85181a36e09fe86f99e946 100644 (file)
 #define IVTV_CAP_ENCODER (V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_TUNER | \
                          V4L2_CAP_AUDIO | V4L2_CAP_READWRITE | V4L2_CAP_VBI_CAPTURE | \
                          V4L2_CAP_SLICED_VBI_CAPTURE)
-#define IVTV_CAP_DECODER (V4L2_CAP_VBI_OUTPUT | V4L2_CAP_VIDEO_OUTPUT | \
+#define IVTV_CAP_DECODER (V4L2_CAP_VIDEO_OUTPUT | \
                          V4L2_CAP_SLICED_VBI_OUTPUT | V4L2_CAP_VIDEO_OUTPUT_OVERLAY)
 
 struct ivtv_card_video_input {
index 4afc7ea07e86ec16866862c4c4e118367dd8116a..aeaa13f6cb3639edda26bbc3178e4105fcdb283b 100644 (file)
 #include "tuner-xc2028.h"
 
 /* var to keep track of the number of array elements in use */
-int ivtv_cards_active = 0;
+int ivtv_cards_active;
 
 /* If you have already X v4l cards, then set this to X. This way
    the device numbers stay matched. Example: you have a WinTV card
    without radio and a PVR-350 with. Normally this would give a
    video1 device together with a radio0 device for the PVR. By
    setting this to 1 you ensure that radio0 is now also radio1. */
-int ivtv_first_minor = 0;
+int ivtv_first_minor;
 
 /* Master variable for all ivtv info */
 struct ivtv *ivtv_cards[IVTV_MAX_CARDS];
@@ -251,7 +251,7 @@ MODULE_PARM_DESC(newi2c,
                 "\t\t\t-1 is autodetect, 0 is off, 1 is on\n"
                 "\t\t\tDefault is autodetect");
 
-MODULE_PARM_DESC(ivtv_first_minor, "Set minor assigned to first card");
+MODULE_PARM_DESC(ivtv_first_minor, "Set kernel number assigned to first card");
 
 MODULE_AUTHOR("Kevin Thayer, Chris Kennedy, Hans Verkuil");
 MODULE_DESCRIPTION("CX23415/CX23416 driver");
@@ -655,9 +655,9 @@ done:
 
        if (itv->card == NULL) {
                itv->card = ivtv_get_card(IVTV_CARD_PVR_150);
-               IVTV_ERR("Unknown card: vendor/device: %04x/%04x\n",
+               IVTV_ERR("Unknown card: vendor/device: [%04x:%04x]\n",
                     itv->dev->vendor, itv->dev->device);
-               IVTV_ERR("              subsystem vendor/device: %04x/%04x\n",
+               IVTV_ERR("              subsystem vendor/device: [%04x:%04x]\n",
                     itv->dev->subsystem_vendor, itv->dev->subsystem_device);
                IVTV_ERR("              %s based\n", chipname);
                IVTV_ERR("Defaulting to %s card\n", itv->card->name);
@@ -720,7 +720,7 @@ static int __devinit ivtv_init_struct1(struct ivtv *itv)
        itv->speed = 1000;
 
        /* VBI */
-       itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
+       itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
        itv->vbi.sliced_in = &itv->vbi.in.fmt.sliced;
 
        /* Init the sg table for osd/yuv output */
index 2ceb5227637c86e3a268323741b72f5fd021effb..bc29436e8a3cd4c3acc93a3c62df8b884d88d478 100644 (file)
@@ -49,7 +49,6 @@
 #include <linux/i2c-algo-bit.h>
 #include <linux/list.h>
 #include <linux/unistd.h>
-#include <linux/byteorder/swab.h>
 #include <linux/pagemap.h>
 #include <linux/scatterlist.h>
 #include <linux/workqueue.h>
@@ -507,6 +506,8 @@ struct yuv_playback_info
        struct v4l2_rect main_rect;
        u32 v4l2_src_w;
        u32 v4l2_src_h;
+
+       u8 running; /* Have any frames been displayed */
 };
 
 #define IVTV_VBI_FRAMES 32
@@ -751,6 +752,12 @@ void ivtv_read_eeprom(struct ivtv *itv, struct tveeprom *tv);
 /* First-open initialization: load firmware, init cx25840, etc. */
 int ivtv_init_on_first_open(struct ivtv *itv);
 
+/* Test if the current VBI mode is raw (1) or sliced (0) */
+static inline int ivtv_raw_vbi(const struct ivtv *itv)
+{
+       return itv->vbi.in.type == V4L2_BUF_TYPE_VBI_CAPTURE;
+}
+
 /* This is a PCI post thing, where if the pci register is not read, then
    the write doesn't always take effect right away. By reading back the
    register any pending PCI writes will be performed (in order), and so
index 7ec5c99f9ad1211c73d6004b3bbe12a4f822c2f4..b7457fc60ba5964c5131cc5282c1b2f29f831411 100644 (file)
@@ -39,7 +39,7 @@
    associated VBI streams are also automatically claimed.
    Possible error returns: -EBUSY if someone else has claimed
    the stream or 0 on success. */
-int ivtv_claim_stream(struct ivtv_open_id *id, int type)
+static int ivtv_claim_stream(struct ivtv_open_id *id, int type)
 {
        struct ivtv *itv = id->itv;
        struct ivtv_stream *s = &itv->streams[type];
@@ -78,7 +78,7 @@ int ivtv_claim_stream(struct ivtv_open_id *id, int type)
        if (type == IVTV_DEC_STREAM_TYPE_MPG) {
                vbi_type = IVTV_DEC_STREAM_TYPE_VBI;
        } else if (type == IVTV_ENC_STREAM_TYPE_MPG &&
-                  itv->vbi.insert_mpeg && itv->vbi.sliced_in->service_set) {
+                  itv->vbi.insert_mpeg && !ivtv_raw_vbi(itv)) {
                vbi_type = IVTV_ENC_STREAM_TYPE_VBI;
        } else {
                return 0;
@@ -305,7 +305,7 @@ static size_t ivtv_copy_buf_to_user(struct ivtv_stream *s, struct ivtv_buffer *b
 
        if (len > ucount) len = ucount;
        if (itv->vbi.insert_mpeg && s->type == IVTV_ENC_STREAM_TYPE_MPG &&
-           itv->vbi.sliced_in->service_set && buf != &itv->vbi.sliced_mpeg_buf) {
+           !ivtv_raw_vbi(itv) && buf != &itv->vbi.sliced_mpeg_buf) {
                const char *start = buf->buf + buf->readpos;
                const char *p = start + 1;
                const u8 *q;
@@ -372,7 +372,7 @@ static ssize_t ivtv_read(struct ivtv_stream *s, char __user *ubuf, size_t tot_co
        /* Each VBI buffer is one frame, the v4l2 API says that for VBI the frames should
           arrive one-by-one, so make sure we never output more than one VBI frame at a time */
        if (s->type == IVTV_DEC_STREAM_TYPE_VBI ||
-                       (s->type == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set))
+           (s->type == IVTV_ENC_STREAM_TYPE_VBI && !ivtv_raw_vbi(itv)))
                single_frame = 1;
 
        for (;;) {
index 2c8d5186c9c3cca56f09021a633066f473674cbf..df81e790147f71a9e839d5efda508a614778ef77 100644 (file)
@@ -38,11 +38,6 @@ void ivtv_unmute(struct ivtv *itv);
 
 /* Utilities */
 
-/* Try to claim a stream for the filehandle. Return 0 on success,
-   -EBUSY if stream already claimed. Once a stream is claimed, it
-   remains claimed until the associated filehandle is closed. */
-int ivtv_claim_stream(struct ivtv_open_id *id, int type);
-
 /* Release a previously claimed stream. */
 void ivtv_release_stream(struct ivtv_stream *s);
 
index bc22905ea20fa58c5f890a58a418361d495a46ef..74a44844ccaf346a1a46c05941178f728b261fbf 100644 (file)
@@ -124,7 +124,7 @@ void ivtv_reset_ir_gpio(struct ivtv *itv)
 }
 
 /* Xceive tuner reset function */
-int ivtv_reset_tuner_gpio(void *dev, int cmd, int value)
+int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value)
 {
        struct i2c_algo_bit_data *algo = dev;
        struct ivtv *itv = algo->data;
index 964a265d91a9c27c4cf0f54238ec122104210aaa..48b6291613a23397065bae0699f3809aef1093e4 100644 (file)
@@ -24,7 +24,7 @@
 /* GPIO stuff */
 void ivtv_gpio_init(struct ivtv *itv);
 void ivtv_reset_ir_gpio(struct ivtv *itv);
-int ivtv_reset_tuner_gpio(void *dev, int cmd, int value);
+int ivtv_reset_tuner_gpio(void *dev, int component, int cmd, int value);
 int ivtv_gpio(struct ivtv *itv, unsigned int command, void *arg);
 
 #endif
index af154238fb9afdc7817bc8e685923aa18e607950..24700c211d5264e660696e64cf92373d69e82793 100644 (file)
@@ -64,8 +64,6 @@
 #include "ivtv-gpio.h"
 #include "ivtv-i2c.h"
 
-#include <media/ir-kbd-i2c.h>
-
 /* i2c implementation for cx23415/6 chip, ivtv project.
  * Author: Kevin Thayer (nufan_wfk at yahoo.com)
  */
index 61030309d0ad876b696478355b5ba683eb832879..8696527ab134bfb6daaee2e49eb7911a5c0cbf44 100644 (file)
@@ -101,18 +101,15 @@ void ivtv_expand_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
        }
 }
 
-static int check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
+static void check_service_set(struct v4l2_sliced_vbi_format *fmt, int is_pal)
 {
        int f, l;
-       u16 set = 0;
 
        for (f = 0; f < 2; f++) {
                for (l = 0; l < 24; l++) {
                        fmt->service_lines[f][l] = select_service_from_set(f, l, fmt->service_lines[f][l], is_pal);
-                       set |= fmt->service_lines[f][l];
                }
        }
-       return set != 0;
 }
 
 u16 ivtv_get_service_set(struct v4l2_sliced_vbi_format *fmt)
@@ -474,7 +471,7 @@ static int ivtv_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format
        int h = fmt->fmt.pix.height;
 
        w = min(w, 720);
-       w = max(w, 1);
+       w = max(w, 2);
        h = min(h, itv->is_50hz ? 576 : 480);
        h = max(h, 2);
        ivtv_g_fmt_vid_cap(file, fh, fmt);
@@ -512,27 +509,20 @@ static int ivtv_try_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_
 static int ivtv_try_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *fmt)
 {
        struct ivtv_open_id *id = fh;
-       s32 w, h;
-       int field;
-       int ret;
+       struct ivtv *itv = id->itv;
+       s32 w = fmt->fmt.pix.width;
+       s32 h = fmt->fmt.pix.height;
+       int field = fmt->fmt.pix.field;
+       int ret = ivtv_g_fmt_vid_out(file, fh, fmt);
 
-       w = fmt->fmt.pix.width;
-       h = fmt->fmt.pix.height;
-       field = fmt->fmt.pix.field;
-       ret = ivtv_g_fmt_vid_out(file, fh, fmt);
+       w = min(w, 720);
+       w = max(w, 2);
+       h = min(h, itv->is_out_50hz ? 576 : 480);
+       h = max(h, 2);
+       if (id->type == IVTV_DEC_STREAM_TYPE_YUV)
+               fmt->fmt.pix.field = field;
        fmt->fmt.pix.width = w;
        fmt->fmt.pix.height = h;
-       if (!ret && id->type == IVTV_DEC_STREAM_TYPE_YUV) {
-               fmt->fmt.pix.field = field;
-               if (fmt->fmt.pix.width < 2)
-                       fmt->fmt.pix.width = 2;
-               if (fmt->fmt.pix.width > 720)
-                       fmt->fmt.pix.width = 720;
-               if (fmt->fmt.pix.height < 2)
-                       fmt->fmt.pix.height = 2;
-               if (fmt->fmt.pix.height > 576)
-                       fmt->fmt.pix.height = 576;
-       }
        return ret;
 }
 
@@ -560,9 +550,9 @@ static int ivtv_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *f
        struct ivtv_open_id *id = fh;
        struct ivtv *itv = id->itv;
        struct cx2341x_mpeg_params *p = &itv->params;
+       int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
        int w = fmt->fmt.pix.width;
        int h = fmt->fmt.pix.height;
-       int ret = ivtv_try_fmt_vid_cap(file, fh, fmt);
 
        if (ret)
                return ret;
@@ -585,8 +575,11 @@ static int ivtv_s_fmt_vbi_cap(struct file *file, void *fh, struct v4l2_format *f
 {
        struct ivtv *itv = ((struct ivtv_open_id *)fh)->itv;
 
+       if (!ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
+               return -EBUSY;
        itv->vbi.sliced_in->service_set = 0;
-       itv->video_dec_func(itv, VIDIOC_S_FMT, &itv->vbi.in);
+       itv->vbi.in.type = V4L2_BUF_TYPE_VBI_CAPTURE;
+       itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
        return ivtv_g_fmt_vbi_cap(file, fh, fmt);
 }
 
@@ -600,10 +593,10 @@ static int ivtv_s_fmt_sliced_vbi_cap(struct file *file, void *fh, struct v4l2_fo
        if (ret || id->type == IVTV_DEC_STREAM_TYPE_VBI)
                return ret;
 
-       if (check_service_set(vbifmt, itv->is_50hz) == 0)
-               return -EINVAL;
-       if (atomic_read(&itv->capturing) > 0)
+       check_service_set(vbifmt, itv->is_50hz);
+       if (ivtv_raw_vbi(itv) && atomic_read(&itv->capturing) > 0)
                return -EBUSY;
+       itv->vbi.in.type = V4L2_BUF_TYPE_SLICED_VBI_CAPTURE;
        itv->video_dec_func(itv, VIDIOC_S_FMT, fmt);
        memcpy(itv->vbi.sliced_in, vbifmt, sizeof(*itv->vbi.sliced_in));
        return 0;
@@ -651,8 +644,6 @@ static int ivtv_s_fmt_vid_out(struct file *file, void *fh, struct v4l2_format *f
                itv->dma_data_req_size =
                        1080 * ((yi->v4l2_src_h + 31) & ~31);
 
-       /* Force update of yuv registers */
-       yi->yuv_forced_update = 1;
        return 0;
 }
 
@@ -761,7 +752,7 @@ static int ivtv_querycap(struct file *file, void *fh, struct v4l2_capability *vc
 
        strlcpy(vcap->driver, IVTV_DRIVER_NAME, sizeof(vcap->driver));
        strlcpy(vcap->card, itv->card_name, sizeof(vcap->card));
-       strlcpy(vcap->bus_info, pci_name(itv->dev), sizeof(vcap->bus_info));
+       snprintf(vcap->bus_info, sizeof(vcap->bus_info), "PCI:%s", pci_name(itv->dev));
        vcap->version = IVTV_DRIVER_VERSION;        /* version */
        vcap->capabilities = itv->v4l2_cap;         /* capabilities */
        return 0;
@@ -1370,6 +1361,9 @@ static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
        if (itv->osd_global_alpha_state)
                fb->flags |= V4L2_FBUF_FLAG_GLOBAL_ALPHA;
 
+       if (yi->track_osd)
+               fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
+
        pixfmt &= 7;
 
        /* no local alpha for RGB565 or unknown formats */
@@ -1389,8 +1383,6 @@ static int ivtv_g_fbuf(struct file *file, void *fh, struct v4l2_framebuffer *fb)
                else
                        fb->flags |= V4L2_FBUF_FLAG_LOCAL_ALPHA;
        }
-       if (yi->track_osd)
-               fb->flags |= V4L2_FBUF_FLAG_OVERLAY;
 
        return 0;
 }
index 34f3ab82785853634bc3c47deb7587d7590508d3..f5d00ec5da73501cb2b99ad93404b9b5dc63a881 100644 (file)
@@ -753,7 +753,7 @@ static void ivtv_irq_vsync(struct ivtv *itv)
         */
        unsigned int frame = read_reg(0x28c0) & 1;
        struct yuv_playback_info *yi = &itv->yuv_info;
-       int last_dma_frame = atomic_read(&itv->yuv_info.next_dma_frame);
+       int last_dma_frame = atomic_read(&yi->next_dma_frame);
        struct yuv_frame_info *f = &yi->new_frame_info[last_dma_frame];
 
        if (0) IVTV_DEBUG_IRQ("DEC VSYNC\n");
@@ -772,6 +772,7 @@ static void ivtv_irq_vsync(struct ivtv *itv)
                                next_dma_frame = (next_dma_frame + 1) % IVTV_YUV_BUFFERS;
                                atomic_set(&yi->next_dma_frame, next_dma_frame);
                                yi->fields_lapsed = -1;
+                               yi->running = 1;
                        }
                }
        }
@@ -804,9 +805,11 @@ static void ivtv_irq_vsync(struct ivtv *itv)
                }
 
                /* Check if we need to update the yuv registers */
-               if ((yi->yuv_forced_update || f->update) && last_dma_frame != -1) {
+               if (yi->running && (yi->yuv_forced_update || f->update)) {
                        if (!f->update) {
-                               last_dma_frame = (u8)(last_dma_frame - 1) % IVTV_YUV_BUFFERS;
+                               last_dma_frame =
+                                       (u8)(atomic_read(&yi->next_dma_frame) -
+                                                1) % IVTV_YUV_BUFFERS;
                                f = &yi->new_frame_info[last_dma_frame];
                        }
 
index 730e85d86fc82d0c27e7351ea4b4689dbcb5bd89..5bbf31e393048fd6b1cd6740a4c02b9ace8f051b 100644 (file)
@@ -75,7 +75,7 @@ static const struct file_operations ivtv_v4l2_dec_fops = {
 static struct {
        const char *name;
        int vfl_type;
-       int minor_offset;
+       int num_offset;
        int dma, pio;
        enum v4l2_buf_type buf_type;
        const struct file_operations *fops;
@@ -171,8 +171,8 @@ static void ivtv_stream_init(struct ivtv *itv, int type)
 static int ivtv_prep_dev(struct ivtv *itv, int type)
 {
        struct ivtv_stream *s = &itv->streams[type];
-       int minor_offset = ivtv_stream_info[type].minor_offset;
-       int minor;
+       int num_offset = ivtv_stream_info[type].num_offset;
+       int num = itv->num + ivtv_first_minor + num_offset;
 
        /* These four fields are always initialized. If v4l2dev == NULL, then
           this stream is not in use. In that case no other fields but these
@@ -188,9 +188,6 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
        if (type >= IVTV_DEC_STREAM_TYPE_MPG && !(itv->v4l2_cap & V4L2_CAP_VIDEO_OUTPUT))
                return 0;
 
-       /* card number + user defined offset + device offset */
-       minor = itv->num + ivtv_first_minor + minor_offset;
-
        /* User explicitly selected 0 buffers for these streams, so don't
           create them. */
        if (ivtv_stream_info[type].dma != PCI_DMA_NONE &&
@@ -211,7 +208,7 @@ static int ivtv_prep_dev(struct ivtv *itv, int type)
        snprintf(s->v4l2dev->name, sizeof(s->v4l2dev->name), "ivtv%d %s",
                        itv->num, s->name);
 
-       s->v4l2dev->minor = minor;
+       s->v4l2dev->num = num;
        s->v4l2dev->parent = &itv->dev->dev;
        s->v4l2dev->fops = ivtv_stream_info[type].fops;
        s->v4l2dev->release = video_device_release;
@@ -250,39 +247,46 @@ static int ivtv_reg_dev(struct ivtv *itv, int type)
 {
        struct ivtv_stream *s = &itv->streams[type];
        int vfl_type = ivtv_stream_info[type].vfl_type;
-       int minor;
+       int num;
 
        if (s->v4l2dev == NULL)
                return 0;
 
-       minor = s->v4l2dev->minor;
+       num = s->v4l2dev->num;
+       /* card number + user defined offset + device offset */
+       if (type != IVTV_ENC_STREAM_TYPE_MPG) {
+               struct ivtv_stream *s_mpg = &itv->streams[IVTV_ENC_STREAM_TYPE_MPG];
+
+               if (s_mpg->v4l2dev)
+                       num = s_mpg->v4l2dev->num + ivtv_stream_info[type].num_offset;
+       }
+
        /* Register device. First try the desired minor, then any free one. */
-       if (video_register_device(s->v4l2dev, vfl_type, minor) &&
-                       video_register_device(s->v4l2dev, vfl_type, -1)) {
-               IVTV_ERR("Couldn't register v4l2 device for %s minor %d\n",
-                               s->name, minor);
+       if (video_register_device(s->v4l2dev, vfl_type, num)) {
+               IVTV_ERR("Couldn't register v4l2 device for %s kernel number %d\n",
+                               s->name, num);
                video_device_release(s->v4l2dev);
                s->v4l2dev = NULL;
                return -ENOMEM;
        }
+       num = s->v4l2dev->num;
 
        switch (vfl_type) {
        case VFL_TYPE_GRABBER:
                IVTV_INFO("Registered device video%d for %s (%d kB)\n",
-                       s->v4l2dev->minor, s->name, itv->options.kilobytes[type]);
+                       num, s->name, itv->options.kilobytes[type]);
                break;
        case VFL_TYPE_RADIO:
                IVTV_INFO("Registered device radio%d for %s\n",
-                       s->v4l2dev->minor - MINOR_VFL_TYPE_RADIO_MIN, s->name);
+                       num, s->name);
                break;
        case VFL_TYPE_VBI:
                if (itv->options.kilobytes[type])
                        IVTV_INFO("Registered device vbi%d for %s (%d kB)\n",
-                               s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN,
-                               s->name, itv->options.kilobytes[type]);
+                               num, s->name, itv->options.kilobytes[type]);
                else
                        IVTV_INFO("Registered device vbi%d for %s\n",
-                               s->v4l2dev->minor - MINOR_VFL_TYPE_VBI_MIN, s->name);
+                               num, s->name);
                break;
        }
        return 0;
@@ -330,7 +334,7 @@ void ivtv_streams_cleanup(struct ivtv *itv, int unregister)
 
 static void ivtv_vbi_setup(struct ivtv *itv)
 {
-       int raw = itv->vbi.sliced_in->service_set == 0;
+       int raw = ivtv_raw_vbi(itv);
        u32 data[CX2341X_MBOX_MAX_DATA];
        int lines;
        int i;
index 1ce9deb1104fc1bdc970811d65ea52a346087570..4a37a7d2e69d53332341dd2f7cda8f66e6d6bc3e 100644 (file)
@@ -334,7 +334,7 @@ void ivtv_process_vbi_data(struct ivtv *itv, struct ivtv_buffer *buf,
        int y;
 
        /* Raw VBI data */
-       if (streamtype == IVTV_ENC_STREAM_TYPE_VBI && itv->vbi.sliced_in->service_set == 0) {
+       if (streamtype == IVTV_ENC_STREAM_TYPE_VBI && ivtv_raw_vbi(itv)) {
                u8 type;
 
                ivtv_buf_swap(buf);
index 3092ff1d00a066a24a4d04b3de06f1999159a299..ee91107376c75440ca56f6620924724a2267c5ab 100644 (file)
@@ -1147,6 +1147,7 @@ void ivtv_yuv_close(struct ivtv *itv)
        IVTV_DEBUG_YUV("ivtv_yuv_close\n");
        ivtv_waitq(&itv->vsync_waitq);
 
+       yi->running = 0;
        atomic_set(&yi->next_dma_frame, -1);
        atomic_set(&yi->next_fill_frame, 0);
 
index bdfda48e56bf55e0b5ea3af83404348053fd26b8..8a4a150b12fb1083c787da3fb3ddcbdb9ab9a51c 100644 (file)
@@ -275,7 +275,6 @@ static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
                                  int size_in_bytes)
 {
        DEFINE_WAIT(wait);
-       int ret = 0;
        int got_sig = 0;
 
        mutex_lock(&itv->udma.lock);
@@ -316,7 +315,7 @@ static int ivtvfb_prep_dec_dma_to_device(struct ivtv *itv,
                return -EINTR;
        }
 
-       return ret;
+       return 0;
 }
 
 static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
@@ -368,11 +367,12 @@ static int ivtvfb_prep_frame(struct ivtv *itv, int cmd, void __user *source,
 }
 
 static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
-                    size_t count, loff_t *ppos)
+                                               size_t count, loff_t *ppos)
 {
        unsigned long p = *ppos;
        void *dst;
        int err = 0;
+       int dma_err;
        unsigned long total_size;
        struct ivtv *itv = (struct ivtv *) info->par;
        unsigned long dma_offset =
@@ -399,7 +399,6 @@ static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
        if (count + p > total_size) {
                if (!err)
                        err = -ENOSPC;
-
                count = total_size - p;
        }
 
@@ -408,39 +407,34 @@ static ssize_t ivtvfb_write(struct fb_info *info, const char __user *buf,
        if (info->fbops->fb_sync)
                info->fbops->fb_sync(info);
 
-       if (!access_ok(VERIFY_READ, buf, count)) {
-               IVTVFB_WARN("Invalid userspace pointer 0x%08lx\n",
-                       (unsigned long)buf);
-               err = -EFAULT;
-       }
-
-       if (!err) {
-               /* If transfer size > threshold and both src/dst
-               addresses are aligned, use DMA */
-               if (count >= 4096 &&
-                   ((unsigned long)buf & 3) == ((unsigned long)dst & 3)) {
-                       /* Odd address = can't DMA. Align */
-                       if ((unsigned long)dst & 3) {
-                               lead = 4 - ((unsigned long)dst & 3);
-                               memcpy(dst, buf, lead);
-                               buf += lead;
-                               dst += lead;
-                       }
-                       /* DMA resolution is 32 bits */
-                       if ((count - lead) & 3)
-                               tail = (count - lead) & 3;
-                       /* DMA the data */
-                       dma_size = count - lead - tail;
-                       err = ivtvfb_prep_dec_dma_to_device(itv,
-                              p + lead + dma_offset, (void *)buf, dma_size);
-                       dst += dma_size;
-                       buf += dma_size;
-                       /* Copy any leftover data */
-                       if (tail)
-                               memcpy(dst, buf, tail);
-               } else {
-                       memcpy(dst, buf, count);
+       /* If transfer size > threshold and both src/dst
+       addresses are aligned, use DMA */
+       if (count >= 4096 &&
+           ((unsigned long)buf & 3) == ((unsigned long)dst & 3)) {
+               /* Odd address = can't DMA. Align */
+               if ((unsigned long)dst & 3) {
+                       lead = 4 - ((unsigned long)dst & 3);
+                       if (copy_from_user(dst, buf, lead))
+                               return -EFAULT;
+                       buf += lead;
+                       dst += lead;
                }
+               /* DMA resolution is 32 bits */
+               if ((count - lead) & 3)
+                       tail = (count - lead) & 3;
+               /* DMA the data */
+               dma_size = count - lead - tail;
+               dma_err = ivtvfb_prep_dec_dma_to_device(itv,
+                      p + lead + dma_offset, (void __user *)buf, dma_size);
+               if (dma_err)
+                       return dma_err;
+               dst += dma_size;
+               buf += dma_size;
+               /* Copy any leftover data */
+               if (tail && copy_from_user(dst, buf, tail))
+                       return -EFAULT;
+       } else if (copy_from_user(dst, buf, count)) {
+               return -EFAULT;
        }
 
        if  (!err)
@@ -463,9 +457,12 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
                        vblank.flags = FB_VBLANK_HAVE_COUNT |FB_VBLANK_HAVE_VCOUNT |
                                        FB_VBLANK_HAVE_VSYNC;
                        trace = read_reg(0x028c0) >> 16;
-                       if (itv->is_50hz && trace > 312) trace -= 312;
-                       else if (itv->is_60hz && trace > 262) trace -= 262;
-                       if (trace == 1) vblank.flags |= FB_VBLANK_VSYNCING;
+                       if (itv->is_50hz && trace > 312)
+                               trace -= 312;
+                       else if (itv->is_60hz && trace > 262)
+                               trace -= 262;
+                       if (trace == 1)
+                               vblank.flags |= FB_VBLANK_VSYNCING;
                        vblank.count = itv->last_vsync_field;
                        vblank.vcount = trace;
                        vblank.hcount = 0;
@@ -476,7 +473,8 @@ static int ivtvfb_ioctl(struct fb_info *info, unsigned int cmd, unsigned long ar
 
                case FBIO_WAITFORVSYNC:
                        prepare_to_wait(&itv->vsync_waitq, &wait, TASK_INTERRUPTIBLE);
-                       if (!schedule_timeout(msecs_to_jiffies(50))) rc = -ETIMEDOUT;
+                       if (!schedule_timeout(msecs_to_jiffies(50)))
+                               rc = -ETIMEDOUT;
                        finish_wait(&itv->vsync_waitq, &wait);
                        return rc;
 
index a9ef7802eb5fcdaf793d8f695d4ecc35e0ddb903..6418f4a78f2a86afc716ff9e6e4d377ceceb434d 100644 (file)
@@ -843,17 +843,16 @@ again:
 
 static int meye_open(struct inode *inode, struct file *file)
 {
-       int i, err;
+       int i;
 
-       err = video_exclusive_open(inode, file);
-       if (err < 0)
-               return err;
+       if (test_and_set_bit(0, &meye.in_use))
+               return -EBUSY;
 
        mchip_hic_stop();
 
        if (mchip_dma_alloc()) {
                printk(KERN_ERR "meye: mchip framebuffer allocation failed\n");
-               video_exclusive_release(inode, file);
+               clear_bit(0, &meye.in_use);
                return -ENOBUFS;
        }
 
@@ -868,7 +867,7 @@ static int meye_release(struct inode *inode, struct file *file)
 {
        mchip_hic_stop();
        mchip_dma_free();
-       video_exclusive_release(inode, file);
+       clear_bit(0, &meye.in_use);
        return 0;
 }
 
@@ -1774,6 +1773,7 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
                goto outnotdev;
        }
 
+       ret = -ENOMEM;
        meye.mchip_dev = pcidev;
        meye.video_dev = video_device_alloc();
        if (!meye.video_dev) {
@@ -1781,7 +1781,6 @@ static int __devinit meye_probe(struct pci_dev *pcidev,
                goto outnotdev;
        }
 
-       ret = -ENOMEM;
        meye.grab_temp = vmalloc(MCHIP_NB_PAGES_MJPEG * PAGE_SIZE);
        if (!meye.grab_temp) {
                printk(KERN_ERR "meye: grab buffer allocation failed\n");
index d535748df445a9d50f121addae83dd9e92d8b617..5f70a106ba2bbc8597256a8d0443d75fbb98416b 100644 (file)
@@ -311,6 +311,7 @@ struct meye {
        struct video_device *video_dev; /* video device parameters */
        struct video_picture picture;   /* video picture parameters */
        struct meye_params params;      /* additional parameters */
+       unsigned long in_use;           /* set to 1 if the device is in use */
 #ifdef CONFIG_PM
        u8 pm_mchip_mode;               /* old mchip mode */
 #endif
index 554d2295484e5f1b02f7fec28c34768fa596d0dd..0c524376b67e66baa4f67ddcf262a647a02143e1 100644 (file)
@@ -117,24 +117,51 @@ static int reg_clear(struct soc_camera_device *icd, const u8 reg,
 
 static int mt9m001_init(struct soc_camera_device *icd)
 {
+       struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+       struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
        int ret;
 
-       /* Disable chip, synchronous option update */
        dev_dbg(icd->vdev->parent, "%s\n", __func__);
 
-       ret = reg_write(icd, MT9M001_RESET, 1);
-       if (ret >= 0)
-               ret = reg_write(icd, MT9M001_RESET, 0);
-       if (ret >= 0)
+       if (icl->power) {
+               ret = icl->power(&mt9m001->client->dev, 1);
+               if (ret < 0) {
+                       dev_err(icd->vdev->parent,
+                               "Platform failed to power-on the camera.\n");
+                       return ret;
+               }
+       }
+
+       /* The camera could have been already on, we reset it additionally */
+       if (icl->reset)
+               ret = icl->reset(&mt9m001->client->dev);
+       else
+               ret = -ENODEV;
+
+       if (ret < 0) {
+               /* Either no platform reset, or platform reset failed */
+               ret = reg_write(icd, MT9M001_RESET, 1);
+               if (!ret)
+                       ret = reg_write(icd, MT9M001_RESET, 0);
+       }
+       /* Disable chip, synchronous option update */
+       if (!ret)
                ret = reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
 
-       return ret >= 0 ? 0 : -EIO;
+       return ret;
 }
 
 static int mt9m001_release(struct soc_camera_device *icd)
 {
+       struct mt9m001 *mt9m001 = container_of(icd, struct mt9m001, icd);
+       struct soc_camera_link *icl = mt9m001->client->dev.platform_data;
+
        /* Disable the chip */
        reg_write(icd, MT9M001_OUTPUT_CONTROL, 0);
+
+       if (icl->power)
+               icl->power(&mt9m001->client->dev, 0);
+
        return 0;
 }
 
@@ -267,24 +294,24 @@ static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
 
        /* Blanking and start values - default... */
        ret = reg_write(icd, MT9M001_HORIZONTAL_BLANKING, hblank);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9M001_VERTICAL_BLANKING, vblank);
 
        /* The caller provides a supported format, as verified per
         * call to icd->try_fmt_cap() */
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9M001_COLUMN_START, rect->left);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9M001_ROW_START, rect->top);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9M001_WINDOW_WIDTH, rect->width - 1);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9M001_WINDOW_HEIGHT,
                                rect->height + icd->y_skip_top - 1);
-       if (ret >= 0 && mt9m001->autoexposure) {
+       if (!ret && mt9m001->autoexposure) {
                ret = reg_write(icd, MT9M001_SHUTTER_WIDTH,
                                rect->height + icd->y_skip_top + vblank);
-               if (ret >= 0) {
+               if (!ret) {
                        const struct v4l2_queryctrl *qctrl =
                                soc_camera_find_qctrl(icd->ops,
                                                      V4L2_CID_EXPOSURE);
@@ -295,7 +322,7 @@ static int mt9m001_set_fmt_cap(struct soc_camera_device *icd,
                }
        }
 
-       return ret < 0 ? ret : 0;
+       return ret;
 }
 
 static int mt9m001_try_fmt_cap(struct soc_camera_device *icd,
diff --git a/drivers/media/video/mt9m111.c b/drivers/media/video/mt9m111.c
new file mode 100644 (file)
index 0000000..da0b2d5
--- /dev/null
@@ -0,0 +1,973 @@
+/*
+ * Driver for MT9M111 CMOS Image Sensor from Micron
+ *
+ * Copyright (C) 2008, Robert Jarzmik <robert.jarzmik@free.fr>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+#include <linux/videodev2.h>
+#include <linux/slab.h>
+#include <linux/i2c.h>
+#include <linux/log2.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/soc_camera.h>
+
+/*
+ * mt9m111 i2c address is 0x5d or 0x48 (depending on SAddr pin)
+ * The platform has to define i2c_board_info and call i2c_register_board_info()
+ */
+
+/* mt9m111: Sensor register addresses */
+#define MT9M111_CHIP_VERSION           0x000
+#define MT9M111_ROW_START              0x001
+#define MT9M111_COLUMN_START           0x002
+#define MT9M111_WINDOW_HEIGHT          0x003
+#define MT9M111_WINDOW_WIDTH           0x004
+#define MT9M111_HORIZONTAL_BLANKING_B  0x005
+#define MT9M111_VERTICAL_BLANKING_B    0x006
+#define MT9M111_HORIZONTAL_BLANKING_A  0x007
+#define MT9M111_VERTICAL_BLANKING_A    0x008
+#define MT9M111_SHUTTER_WIDTH          0x009
+#define MT9M111_ROW_SPEED              0x00a
+#define MT9M111_EXTRA_DELAY            0x00b
+#define MT9M111_SHUTTER_DELAY          0x00c
+#define MT9M111_RESET                  0x00d
+#define MT9M111_READ_MODE_B            0x020
+#define MT9M111_READ_MODE_A            0x021
+#define MT9M111_FLASH_CONTROL          0x023
+#define MT9M111_GREEN1_GAIN            0x02b
+#define MT9M111_BLUE_GAIN              0x02c
+#define MT9M111_RED_GAIN               0x02d
+#define MT9M111_GREEN2_GAIN            0x02e
+#define MT9M111_GLOBAL_GAIN            0x02f
+#define MT9M111_CONTEXT_CONTROL                0x0c8
+#define MT9M111_PAGE_MAP               0x0f0
+#define MT9M111_BYTE_WISE_ADDR         0x0f1
+
+#define MT9M111_RESET_SYNC_CHANGES     (1 << 15)
+#define MT9M111_RESET_RESTART_BAD_FRAME        (1 << 9)
+#define MT9M111_RESET_SHOW_BAD_FRAMES  (1 << 8)
+#define MT9M111_RESET_RESET_SOC                (1 << 5)
+#define MT9M111_RESET_OUTPUT_DISABLE   (1 << 4)
+#define MT9M111_RESET_CHIP_ENABLE      (1 << 3)
+#define MT9M111_RESET_ANALOG_STANDBY   (1 << 2)
+#define MT9M111_RESET_RESTART_FRAME    (1 << 1)
+#define MT9M111_RESET_RESET_MODE       (1 << 0)
+
+#define MT9M111_RMB_MIRROR_COLS                (1 << 1)
+#define MT9M111_RMB_MIRROR_ROWS                (1 << 0)
+#define MT9M111_CTXT_CTRL_RESTART      (1 << 15)
+#define MT9M111_CTXT_CTRL_DEFECTCOR_B  (1 << 12)
+#define MT9M111_CTXT_CTRL_RESIZE_B     (1 << 10)
+#define MT9M111_CTXT_CTRL_CTRL2_B      (1 << 9)
+#define MT9M111_CTXT_CTRL_GAMMA_B      (1 << 8)
+#define MT9M111_CTXT_CTRL_XENON_EN     (1 << 7)
+#define MT9M111_CTXT_CTRL_READ_MODE_B  (1 << 3)
+#define MT9M111_CTXT_CTRL_LED_FLASH_EN (1 << 2)
+#define MT9M111_CTXT_CTRL_VBLANK_SEL_B (1 << 1)
+#define MT9M111_CTXT_CTRL_HBLANK_SEL_B (1 << 0)
+/*
+ * mt9m111: Colorpipe register addresses (0x100..0x1ff)
+ */
+#define MT9M111_OPER_MODE_CTRL         0x106
+#define MT9M111_OUTPUT_FORMAT_CTRL     0x108
+#define MT9M111_REDUCER_XZOOM_B                0x1a0
+#define MT9M111_REDUCER_XSIZE_B                0x1a1
+#define MT9M111_REDUCER_YZOOM_B                0x1a3
+#define MT9M111_REDUCER_YSIZE_B                0x1a4
+#define MT9M111_REDUCER_XZOOM_A                0x1a6
+#define MT9M111_REDUCER_XSIZE_A                0x1a7
+#define MT9M111_REDUCER_YZOOM_A                0x1a9
+#define MT9M111_REDUCER_YSIZE_A                0x1aa
+
+#define MT9M111_OUTPUT_FORMAT_CTRL2_A  0x13a
+#define MT9M111_OUTPUT_FORMAT_CTRL2_B  0x19b
+
+#define MT9M111_OPMODE_AUTOEXPO_EN     (1 << 14)
+
+
+#define MT9M111_OUTFMT_PROCESSED_BAYER (1 << 14)
+#define MT9M111_OUTFMT_BYPASS_IFP      (1 << 10)
+#define MT9M111_OUTFMT_INV_PIX_CLOCK   (1 << 9)
+#define MT9M111_OUTFMT_RGB             (1 << 8)
+#define MT9M111_OUTFMT_RGB565          (0x0 << 6)
+#define MT9M111_OUTFMT_RGB555          (0x1 << 6)
+#define MT9M111_OUTFMT_RGB444x         (0x2 << 6)
+#define MT9M111_OUTFMT_RGBx444         (0x3 << 6)
+#define MT9M111_OUTFMT_TST_RAMP_OFF    (0x0 << 4)
+#define MT9M111_OUTFMT_TST_RAMP_COL    (0x1 << 4)
+#define MT9M111_OUTFMT_TST_RAMP_ROW    (0x2 << 4)
+#define MT9M111_OUTFMT_TST_RAMP_FRAME  (0x3 << 4)
+#define MT9M111_OUTFMT_SHIFT_3_UP      (1 << 3)
+#define MT9M111_OUTFMT_AVG_CHROMA      (1 << 2)
+#define MT9M111_OUTFMT_SWAP_YCbCr_C_Y  (1 << 1)
+#define MT9M111_OUTFMT_SWAP_RGB_EVEN   (1 << 1)
+#define MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr        (1 << 0)
+/*
+ * mt9m111: Camera control register addresses (0x200..0x2ff not implemented)
+ */
+
+#define reg_read(reg) mt9m111_reg_read(icd, MT9M111_##reg)
+#define reg_write(reg, val) mt9m111_reg_write(icd, MT9M111_##reg, (val))
+#define reg_set(reg, val) mt9m111_reg_set(icd, MT9M111_##reg, (val))
+#define reg_clear(reg, val) mt9m111_reg_clear(icd, MT9M111_##reg, (val))
+
+#define MT9M111_MIN_DARK_ROWS  8
+#define MT9M111_MIN_DARK_COLS  24
+#define MT9M111_MAX_HEIGHT     1024
+#define MT9M111_MAX_WIDTH      1280
+
+#define COL_FMT(_name, _depth, _fourcc, _colorspace) \
+       { .name = _name, .depth = _depth, .fourcc = _fourcc, \
+       .colorspace = _colorspace }
+#define RGB_FMT(_name, _depth, _fourcc) \
+       COL_FMT(_name, _depth, _fourcc, V4L2_COLORSPACE_SRGB)
+
+static const struct soc_camera_data_format mt9m111_colour_formats[] = {
+       COL_FMT("YCrYCb 8 bit", 8, V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_JPEG),
+       RGB_FMT("RGB 565", 16, V4L2_PIX_FMT_RGB565),
+       RGB_FMT("RGB 555", 16, V4L2_PIX_FMT_RGB555),
+       RGB_FMT("Bayer (sRGB) 10 bit", 10, V4L2_PIX_FMT_SBGGR16),
+       RGB_FMT("Bayer (sRGB) 8 bit", 8, V4L2_PIX_FMT_SBGGR8),
+};
+
+enum mt9m111_context {
+       HIGHPOWER = 0,
+       LOWPOWER,
+};
+
+struct mt9m111 {
+       struct i2c_client *client;
+       struct soc_camera_device icd;
+       int model;      /* V4L2_IDENT_MT9M111* codes from v4l2-chip-ident.h */
+       enum mt9m111_context context;
+       unsigned int left, top, width, height;
+       u32 pixfmt;
+       unsigned char autoexposure;
+       unsigned char datawidth;
+       unsigned int powered:1;
+       unsigned int hflip:1;
+       unsigned int vflip:1;
+       unsigned int swap_rgb_even_odd:1;
+       unsigned int swap_rgb_red_blue:1;
+       unsigned int swap_yuv_y_chromas:1;
+       unsigned int swap_yuv_cb_cr:1;
+};
+
+static int reg_page_map_set(struct i2c_client *client, const u16 reg)
+{
+       int ret;
+       u16 page;
+       static int lastpage = -1;       /* PageMap cache value */
+
+       page = (reg >> 8);
+       if (page == lastpage)
+               return 0;
+       if (page > 2)
+               return -EINVAL;
+
+       ret = i2c_smbus_write_word_data(client, MT9M111_PAGE_MAP, swab16(page));
+       if (!ret)
+               lastpage = page;
+       return ret;
+}
+
+static int mt9m111_reg_read(struct soc_camera_device *icd, const u16 reg)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       struct i2c_client *client = mt9m111->client;
+       int ret;
+
+       ret = reg_page_map_set(client, reg);
+       if (!ret)
+               ret = swab16(i2c_smbus_read_word_data(client, (reg & 0xff)));
+
+       dev_dbg(&icd->dev, "read  reg.%03x -> %04x\n", reg, ret);
+       return ret;
+}
+
+static int mt9m111_reg_write(struct soc_camera_device *icd, const u16 reg,
+                            const u16 data)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       struct i2c_client *client = mt9m111->client;
+       int ret;
+
+       ret = reg_page_map_set(client, reg);
+       if (!ret)
+               ret = i2c_smbus_write_word_data(mt9m111->client, (reg & 0xff),
+                                               swab16(data));
+       dev_dbg(&icd->dev, "write reg.%03x = %04x -> %d\n", reg, data, ret);
+       return ret;
+}
+
+static int mt9m111_reg_set(struct soc_camera_device *icd, const u16 reg,
+                          const u16 data)
+{
+       int ret;
+
+       ret = mt9m111_reg_read(icd, reg);
+       if (ret >= 0)
+               ret = mt9m111_reg_write(icd, reg, ret | data);
+       return ret;
+}
+
+static int mt9m111_reg_clear(struct soc_camera_device *icd, const u16 reg,
+                            const u16 data)
+{
+       int ret;
+
+       ret = mt9m111_reg_read(icd, reg);
+       return mt9m111_reg_write(icd, reg, ret & ~data);
+}
+
+static int mt9m111_set_context(struct soc_camera_device *icd,
+                              enum mt9m111_context ctxt)
+{
+       int valB = MT9M111_CTXT_CTRL_RESTART | MT9M111_CTXT_CTRL_DEFECTCOR_B
+               | MT9M111_CTXT_CTRL_RESIZE_B | MT9M111_CTXT_CTRL_CTRL2_B
+               | MT9M111_CTXT_CTRL_GAMMA_B | MT9M111_CTXT_CTRL_READ_MODE_B
+               | MT9M111_CTXT_CTRL_VBLANK_SEL_B
+               | MT9M111_CTXT_CTRL_HBLANK_SEL_B;
+       int valA = MT9M111_CTXT_CTRL_RESTART;
+
+       if (ctxt == HIGHPOWER)
+               return reg_write(CONTEXT_CONTROL, valB);
+       else
+               return reg_write(CONTEXT_CONTROL, valA);
+}
+
+static int mt9m111_setup_rect(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret, is_raw_format;
+       int width = mt9m111->width;
+       int height = mt9m111->height;
+
+       if ((mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR8)
+           || (mt9m111->pixfmt == V4L2_PIX_FMT_SBGGR16))
+               is_raw_format = 1;
+       else
+               is_raw_format = 0;
+
+       ret = reg_write(COLUMN_START, mt9m111->left);
+       if (!ret)
+               ret = reg_write(ROW_START, mt9m111->top);
+
+       if (is_raw_format) {
+               if (!ret)
+                       ret = reg_write(WINDOW_WIDTH, width);
+               if (!ret)
+                       ret = reg_write(WINDOW_HEIGHT, height);
+       } else {
+               if (!ret)
+                       ret = reg_write(REDUCER_XZOOM_B, MT9M111_MAX_WIDTH);
+               if (!ret)
+                       ret = reg_write(REDUCER_YZOOM_B, MT9M111_MAX_HEIGHT);
+               if (!ret)
+                       ret = reg_write(REDUCER_XSIZE_B, width);
+               if (!ret)
+                       ret = reg_write(REDUCER_YSIZE_B, height);
+               if (!ret)
+                       ret = reg_write(REDUCER_XZOOM_A, MT9M111_MAX_WIDTH);
+               if (!ret)
+                       ret = reg_write(REDUCER_YZOOM_A, MT9M111_MAX_HEIGHT);
+               if (!ret)
+                       ret = reg_write(REDUCER_XSIZE_A, width);
+               if (!ret)
+                       ret = reg_write(REDUCER_YSIZE_A, height);
+       }
+
+       return ret;
+}
+
+static int mt9m111_setup_pixfmt(struct soc_camera_device *icd, u16 outfmt)
+{
+       int ret;
+
+       ret = reg_write(OUTPUT_FORMAT_CTRL2_A, outfmt);
+       if (!ret)
+               ret = reg_write(OUTPUT_FORMAT_CTRL2_B, outfmt);
+       return ret;
+}
+
+static int mt9m111_setfmt_bayer8(struct soc_camera_device *icd)
+{
+       return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_PROCESSED_BAYER);
+}
+
+static int mt9m111_setfmt_bayer10(struct soc_camera_device *icd)
+{
+       return mt9m111_setup_pixfmt(icd, MT9M111_OUTFMT_BYPASS_IFP);
+}
+
+static int mt9m111_setfmt_rgb565(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int val = 0;
+
+       if (mt9m111->swap_rgb_red_blue)
+               val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
+       if (mt9m111->swap_rgb_even_odd)
+               val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
+       val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB565;
+
+       return mt9m111_setup_pixfmt(icd, val);
+}
+
+static int mt9m111_setfmt_rgb555(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int val = 0;
+
+       if (mt9m111->swap_rgb_red_blue)
+               val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
+       if (mt9m111->swap_rgb_even_odd)
+               val |= MT9M111_OUTFMT_SWAP_RGB_EVEN;
+       val |= MT9M111_OUTFMT_RGB | MT9M111_OUTFMT_RGB555;
+
+       return mt9m111_setup_pixfmt(icd, val);
+}
+
+static int mt9m111_setfmt_yuv(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int val = 0;
+
+       if (mt9m111->swap_yuv_cb_cr)
+               val |= MT9M111_OUTFMT_SWAP_YCbCr_Cb_Cr;
+       if (mt9m111->swap_yuv_y_chromas)
+               val |= MT9M111_OUTFMT_SWAP_YCbCr_C_Y;
+
+       return mt9m111_setup_pixfmt(icd, val);
+}
+
+static int mt9m111_enable(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
+       int ret;
+
+       if (icl->power) {
+               ret = icl->power(&mt9m111->client->dev, 1);
+               if (ret < 0) {
+                       dev_err(icd->vdev->parent,
+                               "Platform failed to power-on the camera.\n");
+                       return ret;
+               }
+       }
+
+       ret = reg_set(RESET, MT9M111_RESET_CHIP_ENABLE);
+       if (!ret)
+               mt9m111->powered = 1;
+       return ret;
+}
+
+static int mt9m111_disable(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       struct soc_camera_link *icl = mt9m111->client->dev.platform_data;
+       int ret;
+
+       ret = reg_clear(RESET, MT9M111_RESET_CHIP_ENABLE);
+       if (!ret)
+               mt9m111->powered = 0;
+
+       if (icl->power)
+               icl->power(&mt9m111->client->dev, 0);
+
+       return ret;
+}
+
+static int mt9m111_reset(struct soc_camera_device *icd)
+{
+       int ret;
+
+       ret = reg_set(RESET, MT9M111_RESET_RESET_MODE);
+       if (!ret)
+               ret = reg_set(RESET, MT9M111_RESET_RESET_SOC);
+       if (!ret)
+               ret = reg_clear(RESET, MT9M111_RESET_RESET_MODE
+                               | MT9M111_RESET_RESET_SOC);
+       return ret;
+}
+
+static int mt9m111_start_capture(struct soc_camera_device *icd)
+{
+       return 0;
+}
+
+static int mt9m111_stop_capture(struct soc_camera_device *icd)
+{
+       return 0;
+}
+
+static unsigned long mt9m111_query_bus_param(struct soc_camera_device *icd)
+{
+       return SOCAM_MASTER | SOCAM_PCLK_SAMPLE_RISING |
+               SOCAM_HSYNC_ACTIVE_HIGH | SOCAM_VSYNC_ACTIVE_HIGH |
+               SOCAM_DATAWIDTH_8;
+}
+
+static int mt9m111_set_bus_param(struct soc_camera_device *icd, unsigned long f)
+{
+       return 0;
+}
+
+static int mt9m111_set_pixfmt(struct soc_camera_device *icd, u32 pixfmt)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret;
+
+       switch (pixfmt) {
+       case V4L2_PIX_FMT_SBGGR8:
+               ret = mt9m111_setfmt_bayer8(icd);
+               break;
+       case V4L2_PIX_FMT_SBGGR16:
+               ret = mt9m111_setfmt_bayer10(icd);
+               break;
+       case V4L2_PIX_FMT_RGB555:
+               ret = mt9m111_setfmt_rgb555(icd);
+               break;
+       case V4L2_PIX_FMT_RGB565:
+               ret = mt9m111_setfmt_rgb565(icd);
+               break;
+       case V4L2_PIX_FMT_YUYV:
+               ret = mt9m111_setfmt_yuv(icd);
+               break;
+       default:
+               dev_err(&icd->dev, "Pixel format not handled : %x\n", pixfmt);
+               ret = -EINVAL;
+       }
+
+       if (!ret)
+               mt9m111->pixfmt = pixfmt;
+
+       return ret;
+}
+
+static int mt9m111_set_fmt_cap(struct soc_camera_device *icd,
+                              __u32 pixfmt, struct v4l2_rect *rect)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret;
+
+       mt9m111->left = rect->left;
+       mt9m111->top = rect->top;
+       mt9m111->width = rect->width;
+       mt9m111->height = rect->height;
+
+       dev_dbg(&icd->dev, "%s fmt=%x left=%d, top=%d, width=%d, height=%d\n",
+               __func__, pixfmt, mt9m111->left, mt9m111->top, mt9m111->width,
+               mt9m111->height);
+
+       ret = mt9m111_setup_rect(icd);
+       if (!ret)
+               ret = mt9m111_set_pixfmt(icd, pixfmt);
+       return ret;
+}
+
+static int mt9m111_try_fmt_cap(struct soc_camera_device *icd,
+                              struct v4l2_format *f)
+{
+       if (f->fmt.pix.height > MT9M111_MAX_HEIGHT)
+               f->fmt.pix.height = MT9M111_MAX_HEIGHT;
+       if (f->fmt.pix.width > MT9M111_MAX_WIDTH)
+               f->fmt.pix.width = MT9M111_MAX_WIDTH;
+
+       return 0;
+}
+
+static int mt9m111_get_chip_id(struct soc_camera_device *icd,
+                              struct v4l2_chip_ident *id)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+
+       if (id->match_type != V4L2_CHIP_MATCH_I2C_ADDR)
+               return -EINVAL;
+
+       if (id->match_chip != mt9m111->client->addr)
+               return -ENODEV;
+
+       id->ident       = mt9m111->model;
+       id->revision    = 0;
+
+       return 0;
+}
+
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+static int mt9m111_get_register(struct soc_camera_device *icd,
+                               struct v4l2_register *reg)
+{
+       int val;
+
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+
+       if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
+               return -EINVAL;
+       if (reg->match_chip != mt9m111->client->addr)
+               return -ENODEV;
+
+       val = mt9m111_reg_read(icd, reg->reg);
+       reg->val = (u64)val;
+
+       if (reg->val > 0xffff)
+               return -EIO;
+
+       return 0;
+}
+
+static int mt9m111_set_register(struct soc_camera_device *icd,
+                               struct v4l2_register *reg)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+
+       if (reg->match_type != V4L2_CHIP_MATCH_I2C_ADDR || reg->reg > 0x2ff)
+               return -EINVAL;
+
+       if (reg->match_chip != mt9m111->client->addr)
+               return -ENODEV;
+
+       if (mt9m111_reg_write(icd, reg->reg, reg->val) < 0)
+               return -EIO;
+
+       return 0;
+}
+#endif
+
+static const struct v4l2_queryctrl mt9m111_controls[] = {
+       {
+               .id             = V4L2_CID_VFLIP,
+               .type           = V4L2_CTRL_TYPE_BOOLEAN,
+               .name           = "Flip Verticaly",
+               .minimum        = 0,
+               .maximum        = 1,
+               .step           = 1,
+               .default_value  = 0,
+       }, {
+               .id             = V4L2_CID_HFLIP,
+               .type           = V4L2_CTRL_TYPE_BOOLEAN,
+               .name           = "Flip Horizontaly",
+               .minimum        = 0,
+               .maximum        = 1,
+               .step           = 1,
+               .default_value  = 0,
+       }, {    /* gain = 1/32*val (=>gain=1 if val==32) */
+               .id             = V4L2_CID_GAIN,
+               .type           = V4L2_CTRL_TYPE_INTEGER,
+               .name           = "Gain",
+               .minimum        = 0,
+               .maximum        = 63 * 2 * 2,
+               .step           = 1,
+               .default_value  = 32,
+               .flags          = V4L2_CTRL_FLAG_SLIDER,
+       }, {
+               .id             = V4L2_CID_EXPOSURE_AUTO,
+               .type           = V4L2_CTRL_TYPE_BOOLEAN,
+               .name           = "Auto Exposure",
+               .minimum        = 0,
+               .maximum        = 1,
+               .step           = 1,
+               .default_value  = 1,
+       }
+};
+
+static int mt9m111_video_probe(struct soc_camera_device *);
+static void mt9m111_video_remove(struct soc_camera_device *);
+static int mt9m111_get_control(struct soc_camera_device *,
+                              struct v4l2_control *);
+static int mt9m111_set_control(struct soc_camera_device *,
+                              struct v4l2_control *);
+static int mt9m111_resume(struct soc_camera_device *icd);
+static int mt9m111_init(struct soc_camera_device *icd);
+static int mt9m111_release(struct soc_camera_device *icd);
+
+static struct soc_camera_ops mt9m111_ops = {
+       .owner                  = THIS_MODULE,
+       .probe                  = mt9m111_video_probe,
+       .remove                 = mt9m111_video_remove,
+       .init                   = mt9m111_init,
+       .resume                 = mt9m111_resume,
+       .release                = mt9m111_release,
+       .start_capture          = mt9m111_start_capture,
+       .stop_capture           = mt9m111_stop_capture,
+       .set_fmt_cap            = mt9m111_set_fmt_cap,
+       .try_fmt_cap            = mt9m111_try_fmt_cap,
+       .query_bus_param        = mt9m111_query_bus_param,
+       .set_bus_param          = mt9m111_set_bus_param,
+       .controls               = mt9m111_controls,
+       .num_controls           = ARRAY_SIZE(mt9m111_controls),
+       .get_control            = mt9m111_get_control,
+       .set_control            = mt9m111_set_control,
+       .get_chip_id            = mt9m111_get_chip_id,
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       .get_register           = mt9m111_get_register,
+       .set_register           = mt9m111_set_register,
+#endif
+};
+
+static int mt9m111_set_flip(struct soc_camera_device *icd, int flip, int mask)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret;
+
+       if (mt9m111->context == HIGHPOWER) {
+               if (flip)
+                       ret = reg_set(READ_MODE_B, mask);
+               else
+                       ret = reg_clear(READ_MODE_B, mask);
+       } else {
+               if (flip)
+                       ret = reg_set(READ_MODE_A, mask);
+               else
+                       ret = reg_clear(READ_MODE_A, mask);
+       }
+
+       return ret;
+}
+
+static int mt9m111_get_global_gain(struct soc_camera_device *icd)
+{
+       unsigned int data, gain;
+
+       data = reg_read(GLOBAL_GAIN);
+       if (data >= 0)
+               gain = ((data & (1 << 10)) * 2)
+                       | ((data & (1 << 9)) * 2)
+                       | (data & 0x2f);
+       else
+               gain = data;
+
+       return gain;
+}
+static int mt9m111_set_global_gain(struct soc_camera_device *icd, int gain)
+{
+       u16 val;
+
+       if (gain > 63 * 2 * 2)
+               return -EINVAL;
+
+       icd->gain = gain;
+       if ((gain >= 64 * 2) && (gain < 63 * 2 * 2))
+               val = (1 << 10) | (1 << 9) | (gain / 4);
+       else if ((gain >= 64) && (gain < 64 * 2))
+               val = (1 << 9) | (gain / 2);
+       else
+               val = gain;
+
+       return reg_write(GLOBAL_GAIN, val);
+}
+
+static int mt9m111_set_autoexposure(struct soc_camera_device *icd, int on)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret;
+
+       if (on)
+               ret = reg_set(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
+       else
+               ret = reg_clear(OPER_MODE_CTRL, MT9M111_OPMODE_AUTOEXPO_EN);
+
+       if (!ret)
+               mt9m111->autoexposure = on;
+
+       return ret;
+}
+static int mt9m111_get_control(struct soc_camera_device *icd,
+                              struct v4l2_control *ctrl)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int data;
+
+       switch (ctrl->id) {
+       case V4L2_CID_VFLIP:
+               if (mt9m111->context == HIGHPOWER)
+                       data = reg_read(READ_MODE_B);
+               else
+                       data = reg_read(READ_MODE_A);
+
+               if (data < 0)
+                       return -EIO;
+               ctrl->value = !!(data & MT9M111_RMB_MIRROR_ROWS);
+               break;
+       case V4L2_CID_HFLIP:
+               if (mt9m111->context == HIGHPOWER)
+                       data = reg_read(READ_MODE_B);
+               else
+                       data = reg_read(READ_MODE_A);
+
+               if (data < 0)
+                       return -EIO;
+               ctrl->value = !!(data & MT9M111_RMB_MIRROR_COLS);
+               break;
+       case V4L2_CID_GAIN:
+               data = mt9m111_get_global_gain(icd);
+               if (data < 0)
+                       return data;
+               ctrl->value = data;
+               break;
+       case V4L2_CID_EXPOSURE_AUTO:
+               ctrl->value = mt9m111->autoexposure;
+               break;
+       }
+       return 0;
+}
+
+static int mt9m111_set_control(struct soc_camera_device *icd,
+                              struct v4l2_control *ctrl)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       const struct v4l2_queryctrl *qctrl;
+       int ret;
+
+       qctrl = soc_camera_find_qctrl(&mt9m111_ops, ctrl->id);
+
+       if (!qctrl)
+               return -EINVAL;
+
+       switch (ctrl->id) {
+       case V4L2_CID_VFLIP:
+               mt9m111->vflip = ctrl->value;
+               ret = mt9m111_set_flip(icd, ctrl->value,
+                                       MT9M111_RMB_MIRROR_ROWS);
+               break;
+       case V4L2_CID_HFLIP:
+               mt9m111->hflip = ctrl->value;
+               ret = mt9m111_set_flip(icd, ctrl->value,
+                                       MT9M111_RMB_MIRROR_COLS);
+               break;
+       case V4L2_CID_GAIN:
+               ret = mt9m111_set_global_gain(icd, ctrl->value);
+               break;
+       case V4L2_CID_EXPOSURE_AUTO:
+               ret =  mt9m111_set_autoexposure(icd, ctrl->value);
+               break;
+       default:
+               ret = -EINVAL;
+       }
+
+       return ret;
+}
+
+static int mt9m111_restore_state(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+
+       mt9m111_set_context(icd, mt9m111->context);
+       mt9m111_set_pixfmt(icd, mt9m111->pixfmt);
+       mt9m111_setup_rect(icd);
+       mt9m111_set_flip(icd, mt9m111->hflip, MT9M111_RMB_MIRROR_COLS);
+       mt9m111_set_flip(icd, mt9m111->vflip, MT9M111_RMB_MIRROR_ROWS);
+       mt9m111_set_global_gain(icd, icd->gain);
+       mt9m111_set_autoexposure(icd, mt9m111->autoexposure);
+       return 0;
+}
+
+static int mt9m111_resume(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret = 0;
+
+       if (mt9m111->powered) {
+               ret = mt9m111_enable(icd);
+               if (!ret)
+                       ret = mt9m111_reset(icd);
+               if (!ret)
+                       ret = mt9m111_restore_state(icd);
+       }
+       return ret;
+}
+
+static int mt9m111_init(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       int ret;
+
+       mt9m111->context = HIGHPOWER;
+       ret = mt9m111_enable(icd);
+       if (!ret)
+               ret = mt9m111_reset(icd);
+       if (!ret)
+               ret = mt9m111_set_context(icd, mt9m111->context);
+       if (!ret)
+               ret = mt9m111_set_autoexposure(icd, mt9m111->autoexposure);
+       if (ret)
+               dev_err(&icd->dev, "mt9m111 init failed: %d\n", ret);
+       return ret;
+}
+
+static int mt9m111_release(struct soc_camera_device *icd)
+{
+       int ret;
+
+       ret = mt9m111_disable(icd);
+       if (ret < 0)
+               dev_err(&icd->dev, "mt9m111 release failed: %d\n", ret);
+
+       return ret;
+}
+
+/*
+ * Interface active, can use i2c. If it fails, it can indeed mean, that
+ * this wasn't our capture interface, so, we wait for the right one
+ */
+static int mt9m111_video_probe(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+       s32 data;
+       int ret;
+
+       /*
+        * We must have a parent by now. And it cannot be a wrong one.
+        * So this entire test is completely redundant.
+        */
+       if (!icd->dev.parent ||
+           to_soc_camera_host(icd->dev.parent)->nr != icd->iface)
+               return -ENODEV;
+
+       ret = mt9m111_enable(icd);
+       if (ret)
+               goto ei2c;
+       ret = mt9m111_reset(icd);
+       if (ret)
+               goto ei2c;
+
+       data = reg_read(CHIP_VERSION);
+
+       switch (data) {
+       case 0x143a:
+               mt9m111->model = V4L2_IDENT_MT9M111;
+               icd->formats = mt9m111_colour_formats;
+               icd->num_formats = ARRAY_SIZE(mt9m111_colour_formats);
+               break;
+       default:
+               ret = -ENODEV;
+               dev_err(&icd->dev,
+                       "No MT9M111 chip detected, register read %x\n", data);
+               goto ei2c;
+       }
+
+       dev_info(&icd->dev, "Detected a MT9M111 chip ID 0x143a\n");
+
+       ret = soc_camera_video_start(icd);
+       if (ret)
+               goto eisis;
+
+       mt9m111->autoexposure = 1;
+
+       mt9m111->swap_rgb_even_odd = 1;
+       mt9m111->swap_rgb_red_blue = 1;
+
+       return 0;
+eisis:
+ei2c:
+       return ret;
+}
+
+static void mt9m111_video_remove(struct soc_camera_device *icd)
+{
+       struct mt9m111 *mt9m111 = container_of(icd, struct mt9m111, icd);
+
+       dev_dbg(&icd->dev, "Video %x removed: %p, %p\n", mt9m111->client->addr,
+               mt9m111->icd.dev.parent, mt9m111->icd.vdev);
+       soc_camera_video_stop(&mt9m111->icd);
+}
+
+static int mt9m111_probe(struct i2c_client *client,
+                        const struct i2c_device_id *did)
+{
+       struct mt9m111 *mt9m111;
+       struct soc_camera_device *icd;
+       struct i2c_adapter *adapter = to_i2c_adapter(client->dev.parent);
+       struct soc_camera_link *icl = client->dev.platform_data;
+       int ret;
+
+       if (!icl) {
+               dev_err(&client->dev, "MT9M111 driver needs platform data\n");
+               return -EINVAL;
+       }
+
+       if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WORD_DATA)) {
+               dev_warn(&adapter->dev,
+                        "I2C-Adapter doesn't support I2C_FUNC_SMBUS_WORD\n");
+               return -EIO;
+       }
+
+       mt9m111 = kzalloc(sizeof(struct mt9m111), GFP_KERNEL);
+       if (!mt9m111)
+               return -ENOMEM;
+
+       mt9m111->client = client;
+       i2c_set_clientdata(client, mt9m111);
+
+       /* Second stage probe - when a capture adapter is there */
+       icd             = &mt9m111->icd;
+       icd->ops        = &mt9m111_ops;
+       icd->control    = &client->dev;
+       icd->x_min      = MT9M111_MIN_DARK_COLS;
+       icd->y_min      = MT9M111_MIN_DARK_ROWS;
+       icd->x_current  = icd->x_min;
+       icd->y_current  = icd->y_min;
+       icd->width_min  = MT9M111_MIN_DARK_ROWS;
+       icd->width_max  = MT9M111_MAX_WIDTH;
+       icd->height_min = MT9M111_MIN_DARK_COLS;
+       icd->height_max = MT9M111_MAX_HEIGHT;
+       icd->y_skip_top = 0;
+       icd->iface      = icl->bus_id;
+
+       ret = soc_camera_device_register(icd);
+       if (ret)
+               goto eisdr;
+       return 0;
+
+eisdr:
+       kfree(mt9m111);
+       return ret;
+}
+
+static int mt9m111_remove(struct i2c_client *client)
+{
+       struct mt9m111 *mt9m111 = i2c_get_clientdata(client);
+       soc_camera_device_unregister(&mt9m111->icd);
+       kfree(mt9m111);
+
+       return 0;
+}
+
+static const struct i2c_device_id mt9m111_id[] = {
+       { "mt9m111", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, mt9m111_id);
+
+static struct i2c_driver mt9m111_i2c_driver = {
+       .driver = {
+               .name = "mt9m111",
+       },
+       .probe          = mt9m111_probe,
+       .remove         = mt9m111_remove,
+       .id_table       = mt9m111_id,
+};
+
+static int __init mt9m111_mod_init(void)
+{
+       return i2c_add_driver(&mt9m111_i2c_driver);
+}
+
+static void __exit mt9m111_mod_exit(void)
+{
+       i2c_del_driver(&mt9m111_i2c_driver);
+}
+
+module_init(mt9m111_mod_init);
+module_exit(mt9m111_mod_exit);
+
+MODULE_DESCRIPTION("Micron MT9M111 Camera driver");
+MODULE_AUTHOR("Robert Jarzmik");
+MODULE_LICENSE("GPL");
index 56808cd2f8a96ac1079db1dbb2d33782194feaf9..2584201059d8570efff3d72a59325e9a11a9d82a 100644 (file)
@@ -134,34 +134,56 @@ static int reg_clear(struct soc_camera_device *icd, const u8 reg,
 static int mt9v022_init(struct soc_camera_device *icd)
 {
        struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
+       struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
        int ret;
 
+       if (icl->power) {
+               ret = icl->power(&mt9v022->client->dev, 1);
+               if (ret < 0) {
+                       dev_err(icd->vdev->parent,
+                               "Platform failed to power-on the camera.\n");
+                       return ret;
+               }
+       }
+
+       /*
+        * The camera could have been already on, we hard-reset it additionally,
+        * if available. Soft reset is done in video_probe().
+        */
+       if (icl->reset)
+               icl->reset(&mt9v022->client->dev);
+
        /* Almost the default mode: master, parallel, simultaneous, and an
         * undocumented bit 0x200, which is present in table 7, but not in 8,
         * plus snapshot mode to disable scan for now */
        mt9v022->chip_control |= 0x10;
        ret = reg_write(icd, MT9V022_CHIP_CONTROL, mt9v022->chip_control);
-       if (ret >= 0)
-               reg_write(icd, MT9V022_READ_MODE, 0x300);
+       if (!ret)
+               ret = reg_write(icd, MT9V022_READ_MODE, 0x300);
 
        /* All defaults */
-       if (ret >= 0)
+       if (!ret)
                /* AEC, AGC on */
                ret = reg_set(icd, MT9V022_AEC_AGC_ENABLE, 0x3);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_MAX_TOTAL_SHUTTER_WIDTH, 480);
-       if (ret >= 0)
+       if (!ret)
                /* default - auto */
                ret = reg_clear(icd, MT9V022_BLACK_LEVEL_CALIB_CTRL, 1);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_DIGITAL_TEST_PATTERN, 0);
 
-       return ret >= 0 ? 0 : -EIO;
+       return ret;
 }
 
 static int mt9v022_release(struct soc_camera_device *icd)
 {
-       /* Nothing? */
+       struct mt9v022 *mt9v022 = container_of(icd, struct mt9v022, icd);
+       struct soc_camera_link *icl = mt9v022->client->dev.platform_data;
+
+       if (icl->power)
+               icl->power(&mt9v022->client->dev, 0);
+
        return 0;
 }
 
@@ -352,21 +374,21 @@ static int mt9v022_set_fmt_cap(struct soc_camera_device *icd,
                                        rect->height + icd->y_skip_top + 43);
        }
        /* Setup frame format: defaults apart from width and height */
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_COLUMN_START, rect->left);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_ROW_START, rect->top);
-       if (ret >= 0)
+       if (!ret)
                /* Default 94, Phytec driver says:
                 * "width + horizontal blank >= 660" */
                ret = reg_write(icd, MT9V022_HORIZONTAL_BLANKING,
                                rect->width > 660 - 43 ? 43 :
                                660 - rect->width);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_VERTICAL_BLANKING, 45);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_WINDOW_WIDTH, rect->width);
-       if (ret >= 0)
+       if (!ret)
                ret = reg_write(icd, MT9V022_WINDOW_HEIGHT,
                                rect->height + icd->y_skip_top);
 
@@ -717,7 +739,7 @@ static int mt9v022_video_probe(struct soc_camera_device *icd)
                        icd->num_formats = 1;
        }
 
-       if (ret >= 0)
+       if (!ret)
                ret = soc_camera_video_start(icd);
        if (ret < 0)
                goto eisis;
index 8ef578caba3b982c8d63f1047b4c300ac11b45ee..7f130284b5c730a0573bcc0c10c9cd925cb5dfec 100644 (file)
@@ -27,6 +27,7 @@
 #include <media/tuner.h>
 #include <linux/video_decoder.h>
 #include <media/v4l2-common.h>
+#include <media/saa7115.h>
 
 #include "mxb.h"
 #include "tea6415c.h"
@@ -122,6 +123,8 @@ static struct saa7146_extension_ioctls ioctls[] = {
        { VIDIOC_S_FREQUENCY,   SAA7146_EXCLUSIVE },
        { VIDIOC_G_AUDIO,       SAA7146_EXCLUSIVE },
        { VIDIOC_S_AUDIO,       SAA7146_EXCLUSIVE },
+       { VIDIOC_DBG_G_REGISTER,        SAA7146_EXCLUSIVE },
+       { VIDIOC_DBG_S_REGISTER,        SAA7146_EXCLUSIVE },
        { MXB_S_AUDIO_CD,       SAA7146_EXCLUSIVE },    /* custom control */
        { MXB_S_AUDIO_LINE,     SAA7146_EXCLUSIVE },    /* custom control */
        { 0,                    0 }
@@ -134,12 +137,12 @@ struct mxb
 
        struct i2c_adapter      i2c_adapter;
 
-       struct i2c_client*      saa7111a;
-       struct i2c_client*      tda9840;
-       struct i2c_client*      tea6415c;
-       struct i2c_client*      tuner;
-       struct i2c_client*      tea6420_1;
-       struct i2c_client*      tea6420_2;
+       struct i2c_client       *saa7111a;
+       struct i2c_client       *tda9840;
+       struct i2c_client       *tea6415c;
+       struct i2c_client       *tuner;
+       struct i2c_client       *tea6420_1;
+       struct i2c_client       *tea6420_2;
 
        int     cur_mode;       /* current audio mode (mono, stereo, ...) */
        int     cur_input;      /* current input */
@@ -151,23 +154,23 @@ static struct saa7146_extension extension;
 
 static int mxb_check_clients(struct device *dev, void *data)
 {
-       struct mxbmxb = data;
+       struct mxb *mxb = data;
        struct i2c_client *client = i2c_verify_client(dev);
 
-       if( !client )
+       if (!client)
                return 0;
 
-       if( I2C_ADDR_TEA6420_1 == client->addr )
+       if (I2C_ADDR_TEA6420_1 == client->addr)
                mxb->tea6420_1 = client;
-       if( I2C_ADDR_TEA6420_2 == client->addr )
+       if (I2C_ADDR_TEA6420_2 == client->addr)
                mxb->tea6420_2 = client;
-       if( I2C_TEA6415C_2 == client->addr )
+       if (I2C_TEA6415C_2 == client->addr)
                mxb->tea6415c = client;
-       if( I2C_ADDR_TDA9840 == client->addr )
+       if (I2C_ADDR_TDA9840 == client->addr)
                mxb->tda9840 = client;
-       if( I2C_SAA7111 == client->addr )
+       if (I2C_SAA7111 == client->addr)
                mxb->saa7111a = client;
-       if( 0x60 == client->addr )
+       if (0x60 == client->addr)
                mxb->tuner = client;
 
        return 0;
@@ -178,23 +181,28 @@ static int mxb_probe(struct saa7146_dev* dev)
        struct mxb* mxb = NULL;
        int result;
 
-       if ((result = request_module("saa7111")) < 0) {
+       result = request_module("saa7115");
+       if (result < 0) {
                printk("mxb: saa7111 i2c module not available.\n");
                return -ENODEV;
        }
-       if ((result = request_module("tea6420")) < 0) {
+       result = request_module("tea6420");
+       if (result < 0) {
                printk("mxb: tea6420 i2c module not available.\n");
                return -ENODEV;
        }
-       if ((result = request_module("tea6415c")) < 0) {
+       result = request_module("tea6415c");
+       if (result < 0) {
                printk("mxb: tea6415c i2c module not available.\n");
                return -ENODEV;
        }
-       if ((result = request_module("tda9840")) < 0) {
+       result = request_module("tda9840");
+       if (result < 0) {
                printk("mxb: tda9840 i2c module not available.\n");
                return -ENODEV;
        }
-       if ((result = request_module("tuner")) < 0) {
+       result = request_module("tuner");
+       if (result < 0) {
                printk("mxb: tuner i2c module not available.\n");
                return -ENODEV;
        }
@@ -207,9 +215,10 @@ static int mxb_probe(struct saa7146_dev* dev)
 
        mxb->i2c_adapter = (struct i2c_adapter) {
                .class = I2C_CLASS_TV_ANALOG,
-               .name = "mxb",
        };
 
+       snprintf(mxb->i2c_adapter.name, sizeof(mxb->i2c_adapter.name), "mxb%d", mxb_num);
+
        saa7146_i2c_adapter_prepare(dev, &mxb->i2c_adapter, SAA7146_I2C_BUS_BIT_RATE_480);
        if(i2c_add_adapter(&mxb->i2c_adapter) < 0) {
                DEB_S(("cannot register i2c-device. skipping.\n"));
@@ -290,38 +299,7 @@ static struct {
        { 9, { 0x1d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
        { 9, { 0x3d, 0xed, 0xd0, 0x68, 0x29, 0xb4, 0xe1, 0x00, 0xb8 } },
        { 3, { 0x80, 0xb3, 0x0a } },
-       {-1, { 0} }
-};
-
-static const unsigned char mxb_saa7111_init[] = {
-       0x00, 0x00,       /* 00 - ID byte */
-       0x01, 0x00,       /* 01 - reserved */
-
-       /*front end */
-       0x02, 0xd8,       /* 02 - FUSE=x, GUDL=x, MODE=x */
-       0x03, 0x23,       /* 03 - HLNRS=0, VBSL=1, WPOFF=0, HOLDG=0, GAFIX=0, GAI1=256, GAI2=256 */
-       0x04, 0x00,       /* 04 - GAI1=256 */
-       0x05, 0x00,       /* 05 - GAI2=256 */
-
-       /* decoder */
-       0x06, 0xf0,       /* 06 - HSB at  xx(50Hz) /  xx(60Hz) pixels after end of last line */
-       0x07, 0x30,       /* 07 - HSS at  xx(50Hz) /  xx(60Hz) pixels after end of last line */
-       0x08, 0xa8,       /* 08 - AUFD=x, FSEL=x, EXFIL=x, VTRC=x, HPLL=x, VNOI=x */
-       0x09, 0x02,       /* 09 - BYPS=x, PREF=x, BPSS=x, VBLB=x, UPTCV=x, APER=x */
-       0x0a, 0x80,       /* 0a - BRIG=128 */
-       0x0b, 0x47,       /* 0b - CONT=1.109 */
-       0x0c, 0x40,       /* 0c - SATN=1.0 */
-       0x0d, 0x00,       /* 0d - HUE=0 */
-       0x0e, 0x01,       /* 0e - CDTO=0, CSTD=0, DCCF=0, FCTC=0, CHBW=1 */
-       0x0f, 0x00,       /* 0f - reserved */
-       0x10, 0xd0,       /* 10 - OFTS=x, HDEL=x, VRLN=x, YDEL=x */
-       0x11, 0x8c,       /* 11 - GPSW=x, CM99=x, FECO=x, COMPO=x, OEYC=1, OEHV=1, VIPB=0, COLO=0 */
-       0x12, 0x80,       /* 12 - xx output control 2 */
-       0x13, 0x30,       /* 13 - xx output control 3 */
-       0x14, 0x00,       /* 14 - reserved */
-       0x15, 0x15,       /* 15 - VBI */
-       0x16, 0x04,       /* 16 - VBI */
-       0x17, 0x00,       /* 17 - VBI */
+       {-1, { 0 } }
 };
 
 /* bring hardware to a sane state. this has to be done, just in case someone
@@ -331,37 +309,28 @@ static const unsigned char mxb_saa7111_init[] = {
 static int mxb_init_done(struct saa7146_dev* dev)
 {
        struct mxb* mxb = (struct mxb*)dev->ext_priv;
-       struct video_decoder_init init;
        struct i2c_msg msg;
        struct tuner_setup tun_setup;
        v4l2_std_id std = V4L2_STD_PAL_BG;
+       struct v4l2_routing route;
 
        int i = 0, err = 0;
-       struct  tea6415c_multiplex vm;
+       struct tea6415c_multiplex vm;
 
        /* select video mode in saa7111a */
-       i = VIDEO_MODE_PAL;
-       /* fixme: currently pointless: gets overwritten by configuration below */
-       mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_NORM, &i);
-
-       /* write configuration to saa7111a */
-       init.data = mxb_saa7111_init;
-       init.len = sizeof(mxb_saa7111_init);
-       mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_INIT, &init);
+       mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_S_STD, &std);
 
        /* select tuner-output on saa7111a */
        i = 0;
-       mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i);
-
-       /* enable vbi bypass */
-       i = 1;
-       mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_VBI_BYPASS, &i);
+       route.input = SAA7115_COMPOSITE0;
+       route.output = SAA7111_FMT_CCIR | SAA7111_VBI_BYPASS;
+       mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route);
 
        /* select a tuner type */
        tun_setup.mode_mask = T_ANALOG_TV;
        tun_setup.addr = ADDR_UNSET;
        tun_setup.type = TUNER_PHILIPS_PAL;
-       mxb->tuner->driver->command(mxb->tuner,TUNER_SET_TYPE_ADDR, &tun_setup);
+       mxb->tuner->driver->command(mxb->tuner, TUNER_SET_TYPE_ADDR, &tun_setup);
        /* tune in some frequency on tuner */
        mxb->cur_freq.tuner = 0;
        mxb->cur_freq.type = V4L2_TUNER_ANALOG_TV;
@@ -373,27 +342,26 @@ static int mxb_init_done(struct saa7146_dev* dev)
        mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
 
        /* mute audio on tea6420s */
-       mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
-       mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]);
-       mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_cd[6][0]);
-       mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_cd[6][1]);
+       mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_line[6][0]);
+       mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_line[6][1]);
+       mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH, &TEA6420_cd[6][0]);
+       mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH, &TEA6420_cd[6][1]);
 
        /* switch to tuner-channel on tea6415c*/
        vm.out = 17;
        vm.in  = 3;
-       mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
+       mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);
 
        /* select tuner-output on multicable on tea6415c*/
        vm.in  = 3;
        vm.out = 13;
-       mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm);
+       mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm);
 
        /* the rest for mxb */
        mxb->cur_input = 0;
        mxb->cur_mute = 1;
 
        mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
-       mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &mxb->cur_mode);
 
        /* check if the saa7740 (aka 'sound arena module') is present
           on the mxb. if so, we must initialize it. due to lack of
@@ -404,21 +372,22 @@ static int mxb_init_done(struct saa7146_dev* dev)
        msg.len = mxb_saa7740_init[0].length;
        msg.buf = &mxb_saa7740_init[0].data[0];
 
-       if( 1 == (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) {
+       err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
+       if (err == 1) {
                /* the sound arena module is a pos, that's probably the reason
                   philips refuses to hand out a datasheet for the saa7740...
                   it seems to screw up the i2c bus, so we disable fast irq
                   based i2c transactions here and rely on the slow and safe
                   polling method ... */
                extension.flags &= ~SAA7146_USE_I2C_IRQ;
-               for(i = 1;;i++) {
-                       if( -1 == mxb_saa7740_init[i].length ) {
+               for (i = 1; ; i++) {
+                       if (-1 == mxb_saa7740_init[i].length)
                                break;
-                       }
 
                        msg.len = mxb_saa7740_init[i].length;
                        msg.buf = &mxb_saa7740_init[i].data[0];
-                       if( 1 != (err = i2c_transfer(&mxb->i2c_adapter, &msg, 1))) {
+                       err = i2c_transfer(&mxb->i2c_adapter, &msg, 1);
+                       if (err != 1) {
                                DEB_D(("failed to initialize 'sound arena module'.\n"));
                                goto err;
                        }
@@ -432,7 +401,8 @@ err:
        /* ext->saa has been filled by the core driver */
 
        /* some stuff is done via variables */
-       saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source, input_port_selection[mxb->cur_input].hps_sync);
+       saa7146_set_hps_source_and_sync(dev, input_port_selection[mxb->cur_input].hps_source,
+                       input_port_selection[mxb->cur_input].hps_sync);
 
        /* some stuff is done via direct write to the registers */
 
@@ -457,24 +427,24 @@ void mxb_irq_bh(struct saa7146_dev* dev, u32* irq_mask)
 static struct saa7146_ext_vv vv_data;
 
 /* this function only gets called when the probing was successful */
-static int mxb_attach(struct saa7146_devdev, struct saa7146_pci_extension_data *info)
+static int mxb_attach(struct saa7146_dev *dev, struct saa7146_pci_extension_data *info)
 {
-       struct mxb* mxb = (struct mxb*)dev->ext_priv;
+       struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE(("dev:%p\n", dev));
 
        /* checking for i2c-devices can be omitted here, because we
           already did this in "mxb_vl42_probe" */
 
-       saa7146_vv_init(dev,&vv_data);
-       if( 0 != saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
+       saa7146_vv_init(dev, &vv_data);
+       if (saa7146_register_device(&mxb->video_dev, dev, "mxb", VFL_TYPE_GRABBER)) {
                ERR(("cannot register capture v4l2 device. skipping.\n"));
                return -1;
        }
 
        /* initialization stuff (vbi) (only for revision > 0 and for extensions which want it)*/
-       if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) {
-               if( 0 != saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
+       if (MXB_BOARD_CAN_DO_VBI(dev)) {
+               if (saa7146_register_device(&mxb->vbi_dev, dev, "mxb", VFL_TYPE_VBI)) {
                        ERR(("cannot register vbi v4l2 device. skipping.\n"));
                }
        }
@@ -486,18 +456,18 @@ static int mxb_attach(struct saa7146_dev* dev, struct saa7146_pci_extension_data
        i2c_use_client(mxb->saa7111a);
        i2c_use_client(mxb->tuner);
 
-       printk("mxb: found 'Multimedia eXtension Board'-%d.\n",mxb_num);
+       printk("mxb: found Multimedia eXtension Board #%d.\n", mxb_num);
 
        mxb_num++;
        mxb_init_done(dev);
        return 0;
 }
 
-static int mxb_detach(struct saa7146_devdev)
+static int mxb_detach(struct saa7146_dev *dev)
 {
-       struct mxb* mxb = (struct mxb*)dev->ext_priv;
+       struct mxb *mxb = (struct mxb *)dev->ext_priv;
 
-       DEB_EE(("dev:%p\n",dev));
+       DEB_EE(("dev:%p\n", dev));
 
        i2c_release_client(mxb->tea6420_1);
        i2c_release_client(mxb->tea6420_2);
@@ -507,9 +477,8 @@ static int mxb_detach(struct saa7146_dev* dev)
        i2c_release_client(mxb->tuner);
 
        saa7146_unregister_device(&mxb->video_dev,dev);
-       if( 0 != MXB_BOARD_CAN_DO_VBI(dev)) {
-               saa7146_unregister_device(&mxb->vbi_dev,dev);
-       }
+       if (MXB_BOARD_CAN_DO_VBI(dev))
+               saa7146_unregister_device(&mxb->vbi_dev, dev);
        saa7146_vv_release(dev);
 
        mxb_num--;
@@ -523,7 +492,7 @@ static int mxb_detach(struct saa7146_dev* dev)
 static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
 {
        struct saa7146_dev *dev = fh->dev;
-       struct mxb* mxb = (struct mxb*)dev->ext_priv;
+       struct mxb *mxb = (struct mxb *)dev->ext_priv;
        struct saa7146_vv *vv = dev->vv_data;
 
        switch(cmd) {
@@ -532,11 +501,9 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
                struct v4l2_input *i = arg;
 
                DEB_EE(("VIDIOC_ENUMINPUT %d.\n",i->index));
-               if( i->index < 0 || i->index >= MXB_INPUTS) {
+               if (i->index < 0 || i->index >= MXB_INPUTS)
                        return -EINVAL;
-               }
                memcpy(i, &mxb_inputs[i->index], sizeof(struct v4l2_input));
-
                return 0;
        }
        /* the saa7146 provides some controls (brightness, contrast, saturation)
@@ -550,7 +517,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
                for (i = MAXCONTROLS - 1; i >= 0; i--) {
                        if (mxb_controls[i].id == qc->id) {
                                *qc = mxb_controls[i];
-                               DEB_D(("VIDIOC_QUERYCTRL %d.\n",qc->id));
+                               DEB_D(("VIDIOC_QUERYCTRL %d.\n", qc->id));
                                return 0;
                        }
                }
@@ -562,56 +529,51 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
                int i;
 
                for (i = MAXCONTROLS - 1; i >= 0; i--) {
-                       if (mxb_controls[i].id == vc->id) {
+                       if (mxb_controls[i].id == vc->id)
                                break;
-                       }
                }
 
-               if( i < 0 ) {
+               if (i < 0)
                        return -EAGAIN;
-               }
 
-               switch (vc->id ) {
-                       case V4L2_CID_AUDIO_MUTE: {
-                               vc->value = mxb->cur_mute;
-                               DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value));
-                               return 0;
-                       }
+               if (vc->id == V4L2_CID_AUDIO_MUTE) {
+                       vc->value = mxb->cur_mute;
+                       DEB_D(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
+                       return 0;
                }
 
-               DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n",vc->value));
+               DEB_EE(("VIDIOC_G_CTRL V4L2_CID_AUDIO_MUTE:%d.\n", vc->value));
                return 0;
        }
 
        case VIDIOC_S_CTRL:
        {
-               struct  v4l2_control    *vc = arg;
+               struct v4l2_control *vc = arg;
                int i = 0;
 
                for (i = MAXCONTROLS - 1; i >= 0; i--) {
-                       if (mxb_controls[i].id == vc->id) {
+                       if (mxb_controls[i].id == vc->id)
                                break;
-                       }
                }
 
-               if( i < 0 ) {
+               if (i < 0)
                        return -EAGAIN;
-               }
 
-               switch (vc->id ) {
-                       case V4L2_CID_AUDIO_MUTE: {
-                               mxb->cur_mute = vc->value;
-                               if( 0 == vc->value ) {
-                                       /* switch the audio-source */
-                                       mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
-                                       mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
-                               } else {
-                                       mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[6][0]);
-                                       mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[6][1]);
-                               }
-                               DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n",vc->value));
-                               break;
+               if (vc->id == V4L2_CID_AUDIO_MUTE) {
+                       mxb->cur_mute = vc->value;
+                       if (!vc->value) {
+                               /* switch the audio-source */
+                               mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+                                               &TEA6420_line[video_audio_connect[mxb->cur_input]][0]);
+                               mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+                                               &TEA6420_line[video_audio_connect[mxb->cur_input]][1]);
+                       } else {
+                               mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+                                               &TEA6420_line[6][0]);
+                               mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+                                               &TEA6420_line[6][1]);
                        }
+                       DEB_EE(("VIDIOC_S_CTRL, V4L2_CID_AUDIO_MUTE: %d.\n", vc->value));
                }
                return 0;
        }
@@ -620,106 +582,84 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
                int *input = (int *)arg;
                *input = mxb->cur_input;
 
-               DEB_EE(("VIDIOC_G_INPUT %d.\n",*input));
+               DEB_EE(("VIDIOC_G_INPUT %d.\n", *input));
                return 0;
        }
        case VIDIOC_S_INPUT:
        {
                int input = *(int *)arg;
-               struct  tea6415c_multiplex vm;
+               struct tea6415c_multiplex vm;
+               struct v4l2_routing route;
                int i = 0;
 
-               DEB_EE(("VIDIOC_S_INPUT %d.\n",input));
+               DEB_EE(("VIDIOC_S_INPUT %d.\n", input));
 
-               if (input < 0 || input >= MXB_INPUTS) {
+               if (input < 0 || input >= MXB_INPUTS)
                        return -EINVAL;
-               }
-
-               /* fixme: locke das setzen des inputs mit hilfe des mutexes
-               mutex_lock(&dev->lock);
-               video_mux(dev,*i);
-               mutex_unlock(&dev->lock);
-               */
-
-               /* fixme: check if streaming capture
-               if ( 0 != dev->streaming ) {
-                       DEB_D(("VIDIOC_S_INPUT illegal while streaming.\n"));
-                       return -EPERM;
-               }
-               */
 
                mxb->cur_input = input;
 
-               saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source, input_port_selection[input].hps_sync);
+               saa7146_set_hps_source_and_sync(dev, input_port_selection[input].hps_source,
+                               input_port_selection[input].hps_sync);
 
                /* prepare switching of tea6415c and saa7111a;
                   have a look at the 'background'-file for further informations  */
-               switch( input ) {
-
-                       case TUNER:
-                       {
-                               i = 0;
-                               vm.in  = 3;
-                               vm.out = 17;
-
-                       if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) {
-                                       printk("VIDIOC_S_INPUT: could not address tea6415c #1\n");
-                                       return -EFAULT;
-                               }
-                               /* connect tuner-output always to multicable */
-                               vm.in  = 3;
-                               vm.out = 13;
-                               break;
-                       }
-                       case AUX3_YC:
-                       {
-                               /* nothing to be done here. aux3_yc is
-                                  directly connected to the saa711a */
-                               i = 5;
-                               break;
-                       }
-                       case AUX3:
-                       {
-                               /* nothing to be done here. aux3 is
-                                  directly connected to the saa711a */
-                               i = 1;
-                               break;
-                       }
-                       case AUX1:
-                       {
-                               i = 0;
-                               vm.in  = 1;
-                               vm.out = 17;
-                               break;
+               switch (input) {
+               case TUNER:
+                       i = SAA7115_COMPOSITE0;
+                       vm.in  = 3;
+                       vm.out = 17;
+
+                       if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
+                               printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #1\n");
+                               return -EFAULT;
                        }
+                       /* connect tuner-output always to multicable */
+                       vm.in  = 3;
+                       vm.out = 13;
+                       break;
+               case AUX3_YC:
+                       /* nothing to be done here. aux3_yc is
+                          directly connected to the saa711a */
+                       i = SAA7115_SVIDEO1;
+                       break;
+               case AUX3:
+                       /* nothing to be done here. aux3 is
+                          directly connected to the saa711a */
+                       i = SAA7115_COMPOSITE1;
+                       break;
+               case AUX1:
+                       i = SAA7115_COMPOSITE0;
+                       vm.in  = 1;
+                       vm.out = 17;
+                       break;
                }
 
                /* switch video in tea6415c only if necessary */
-               switch( input ) {
-                       case TUNER:
-                       case AUX1:
-                       {
-                               if ( 0 != mxb->tea6415c->driver->command(mxb->tea6415c,TEA6415C_SWITCH, &vm)) {
-                                       printk("VIDIOC_S_INPUT: could not address tea6415c #3\n");
-                                       return -EFAULT;
-                               }
-                               break;
-                       }
-                       default:
-                       {
-                               break;
+               switch (input) {
+               case TUNER:
+               case AUX1:
+                       if (mxb->tea6415c->driver->command(mxb->tea6415c, TEA6415C_SWITCH, &vm)) {
+                               printk(KERN_ERR "VIDIOC_S_INPUT: could not address tea6415c #3\n");
+                               return -EFAULT;
                        }
+                       break;
+               default:
+                       break;
                }
 
                /* switch video in saa7111a */
-               if ( 0 != mxb->saa7111a->driver->command(mxb->saa7111a,DECODER_SET_INPUT, &i)) {
+               route.input = i;
+               route.output = 0;
+               if (mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_VIDEO_ROUTING, &route))
                        printk("VIDIOC_S_INPUT: could not address saa7111a #1.\n");
-               }
 
                /* switch the audio-source only if necessary */
                if( 0 == mxb->cur_mute ) {
-                       mxb->tea6420_1->driver->command(mxb->tea6420_1,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][0]);
-                       mxb->tea6420_2->driver->command(mxb->tea6420_2,TEA6420_SWITCH, &TEA6420_line[video_audio_connect[input]][1]);
+                       mxb->tea6420_1->driver->command(mxb->tea6420_1, TEA6420_SWITCH,
+                                       &TEA6420_line[video_audio_connect[input]][0]);
+                       mxb->tea6420_2->driver->command(mxb->tea6420_2, TEA6420_SWITCH,
+                                      &TEA6420_line[video_audio_connect[input]][1]);
                }
 
                return 0;
@@ -727,114 +667,44 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        case VIDIOC_G_TUNER:
        {
                struct v4l2_tuner *t = arg;
-               int byte = 0;
 
-               if( 0 != t->index ) {
+               if (t->index) {
                        DEB_D(("VIDIOC_G_TUNER: channel %d does not have a tuner attached.\n", t->index));
                        return -EINVAL;
                }
 
                DEB_EE(("VIDIOC_G_TUNER: %d\n", t->index));
 
-               memset(t,0,sizeof(*t));
-               strcpy(t->name, "Television");
+               memset(t, 0, sizeof(*t));
+               i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
 
+               strlcpy(t->name, "TV Tuner", sizeof(t->name));
                t->type = V4L2_TUNER_ANALOG_TV;
-               t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
-               t->rangelow = 772;      /* 48.25 MHZ / 62.5 kHz = 772, see fi1216mk2-specs, page 2 */
-               t->rangehigh = 13684;   /* 855.25 MHz / 62.5 kHz = 13684 */
-               /* FIXME: add the real signal strength here */
-               t->signal = 0xffff;
-               t->afc = 0;
-
-               mxb->tda9840->driver->command(mxb->tda9840,TDA9840_DETECT, &byte);
+               t->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO | \
+                       V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2 | V4L2_TUNER_CAP_SAP;
                t->audmode = mxb->cur_mode;
-
-               if( byte < 0 ) {
-                       t->rxsubchans  = V4L2_TUNER_SUB_MONO;
-               } else {
-                       switch(byte) {
-                               case TDA9840_MONO_DETECT: {
-                                       t->rxsubchans   = V4L2_TUNER_SUB_MONO;
-                                       DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_MONO.\n"));
-                                       break;
-                               }
-                               case TDA9840_DUAL_DETECT: {
-                                       t->rxsubchans   = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
-                                       DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_LANG1.\n"));
-                                       break;
-                               }
-                               case TDA9840_STEREO_DETECT: {
-                                       t->rxsubchans   = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
-                                       DEB_D(("VIDIOC_G_TUNER: V4L2_TUNER_MODE_STEREO.\n"));
-                                       break;
-                               }
-                               default: { /* TDA9840_INCORRECT_DETECT */
-                                       t->rxsubchans   = V4L2_TUNER_MODE_MONO;
-                                       DEB_D(("VIDIOC_G_TUNER: TDA9840_INCORRECT_DETECT => V4L2_TUNER_MODE_MONO\n"));
-                                       break;
-                               }
-                       }
-               }
-
                return 0;
        }
        case VIDIOC_S_TUNER:
        {
                struct v4l2_tuner *t = arg;
-               int result = 0;
-               int byte = 0;
 
-               if( 0 != t->index ) {
+               if (t->index) {
                        DEB_D(("VIDIOC_S_TUNER: channel %d does not have a tuner attached.\n",t->index));
                        return -EINVAL;
                }
 
-               switch(t->audmode) {
-                       case V4L2_TUNER_MODE_STEREO: {
-                               mxb->cur_mode = V4L2_TUNER_MODE_STEREO;
-                               byte = TDA9840_SET_STEREO;
-                               DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_STEREO\n"));
-                               break;
-                       }
-                       case V4L2_TUNER_MODE_LANG1_LANG2: {
-                               mxb->cur_mode = V4L2_TUNER_MODE_LANG1_LANG2;
-                               byte = TDA9840_SET_BOTH;
-                               DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1_LANG2\n"));
-                               break;
-                       }
-                       case V4L2_TUNER_MODE_LANG1: {
-                               mxb->cur_mode = V4L2_TUNER_MODE_LANG1;
-                               byte = TDA9840_SET_LANG1;
-                               DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG1\n"));
-                               break;
-                       }
-                       case V4L2_TUNER_MODE_LANG2: {
-                               mxb->cur_mode = V4L2_TUNER_MODE_LANG2;
-                               byte = TDA9840_SET_LANG2;
-                               DEB_D(("VIDIOC_S_TUNER: V4L2_TUNER_MODE_LANG2\n"));
-                               break;
-                       }
-                       default: { /* case V4L2_TUNER_MODE_MONO: {*/
-                               mxb->cur_mode = V4L2_TUNER_MODE_MONO;
-                               byte = TDA9840_SET_MONO;
-                               DEB_D(("VIDIOC_S_TUNER: TDA9840_SET_MONO\n"));
-                               break;
-                       }
-               }
-
-               if( 0 != (result = mxb->tda9840->driver->command(mxb->tda9840, TDA9840_SWITCH, &byte))) {
-                       printk("VIDIOC_S_TUNER error. result:%d, byte:%d\n",result,byte);
-               }
-
+               mxb->cur_mode = t->audmode;
+               i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
                return 0;
        }
        case VIDIOC_G_FREQUENCY:
        {
                struct v4l2_frequency *f = arg;
 
-               if(0 != mxb->cur_input) {
-                       DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",mxb->cur_input));
+               if (mxb->cur_input) {
+                       DEB_D(("VIDIOC_G_FREQ: channel %d does not have a tuner!\n",
+                                               mxb->cur_input));
                        return -EINVAL;
                }
 
@@ -847,14 +717,14 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        {
                struct v4l2_frequency *f = arg;
 
-               if (0 != f->tuner)
+               if (f->tuner)
                        return -EINVAL;
 
                if (V4L2_TUNER_ANALOG_TV != f->type)
                        return -EINVAL;
 
-               if(0 != mxb->cur_input) {
-                       DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n",mxb->cur_input));
+               if (mxb->cur_input) {
+                       DEB_D(("VIDIOC_S_FREQ: channel %d does not have a tuner!\n", mxb->cur_input));
                        return -EINVAL;
                }
 
@@ -875,7 +745,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        {
                int i = *(int*)arg;
 
-               if( i < 0 || i >= MXB_AUDIOS ) {
+               if (i < 0 || i >= MXB_AUDIOS) {
                        DEB_D(("illegal argument to MXB_S_AUDIO_CD: i:%d.\n",i));
                        return -EINVAL;
                }
@@ -891,7 +761,7 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        {
                int i = *(int*)arg;
 
-               if( i < 0 || i >= MXB_AUDIOS ) {
+               if (i < 0 || i >= MXB_AUDIOS) {
                        DEB_D(("illegal argument to MXB_S_AUDIO_LINE: i:%d.\n",i));
                        return -EINVAL;
                }
@@ -906,12 +776,12 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        {
                struct v4l2_audio *a = arg;
 
-               if( a->index < 0 || a->index > MXB_INPUTS ) {
-                       DEB_D(("VIDIOC_G_AUDIO %d out of range.\n",a->index));
+               if (a->index < 0 || a->index > MXB_INPUTS) {
+                       DEB_D(("VIDIOC_G_AUDIO %d out of range.\n", a->index));
                        return -EINVAL;
                }
 
-               DEB_EE(("VIDIOC_G_AUDIO %d.\n",a->index));
+               DEB_EE(("VIDIOC_G_AUDIO %d.\n", a->index));
                memcpy(a, &mxb_audios[video_audio_connect[mxb->cur_input]], sizeof(struct v4l2_audio));
 
                return 0;
@@ -919,9 +789,16 @@ static int mxb_ioctl(struct saa7146_fh *fh, unsigned int cmd, void *arg)
        case VIDIOC_S_AUDIO:
        {
                struct v4l2_audio *a = arg;
-               DEB_D(("VIDIOC_S_AUDIO %d.\n",a->index));
+
+               DEB_D(("VIDIOC_S_AUDIO %d.\n", a->index));
                return 0;
        }
+#ifdef CONFIG_VIDEO_ADV_DEBUG
+       case VIDIOC_DBG_S_REGISTER:
+       case VIDIOC_DBG_G_REGISTER:
+               i2c_clients_command(&mxb->i2c_adapter, cmd, arg);
+               return 0;
+#endif
        default:
 /*
                DEB2(printk("does not handle this ioctl.\n"));
@@ -944,7 +821,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
                /* set the 7146 gpio register -- I don't know what this does exactly */
                saa7146_write(dev, GPIO_CTRL, 0x00404050);
                /* unset the 7111 gpio register -- I don't know what this does exactly */
-               mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &zero);
+               mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &zero);
                mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
        } else {
                v4l2_std_id std = V4L2_STD_PAL_BG;
@@ -953,7 +830,7 @@ static int std_callback(struct saa7146_dev *dev, struct saa7146_standard *standa
                /* set the 7146 gpio register -- I don't know what this does exactly */
                saa7146_write(dev, GPIO_CTRL, 0x00404050);
                /* set the 7111 gpio register -- I don't know what this does exactly */
-               mxb->saa7111a->driver->command(mxb->saa7111a, DECODER_SET_GPIO, &one);
+               mxb->saa7111a->driver->command(mxb->saa7111a, VIDIOC_INT_S_GPIO, &one);
                mxb->tuner->driver->command(mxb->tuner, VIDIOC_S_STD, &std);
        }
        return 0;
@@ -1029,7 +906,7 @@ static struct saa7146_extension extension = {
 
 static int __init mxb_init_module(void)
 {
-       if( 0 != saa7146_register_extension(&extension)) {
+       if (saa7146_register_extension(&extension)) {
                DEB_S(("failed to register extension.\n"));
                return -ENODEV;
        }
index c6852402c5e986d3b93161b636db049789f5b6a4..935d73de57bd3c8cf78ade18ff9245c2ab4c4799 100644 (file)
@@ -974,14 +974,14 @@ dump_i2c_range(struct usb_ov511 *ov, int reg1, int regn)
 
        for (i = reg1; i <= regn; i++) {
                rc = i2c_r(ov, i);
-               info("Sensor[0x%02X] = 0x%02X", i, rc);
+               dev_info(&ov->dev->dev, "Sensor[0x%02X] = 0x%02X\n", i, rc);
        }
 }
 
 static void
 dump_i2c_regs(struct usb_ov511 *ov)
 {
-       info("I2C REGS");
+       dev_info(&ov->dev->dev, "I2C REGS\n");
        dump_i2c_range(ov, 0x00, 0x7C);
 }
 
@@ -992,28 +992,28 @@ dump_reg_range(struct usb_ov511 *ov, int reg1, int regn)
 
        for (i = reg1; i <= regn; i++) {
                rc = reg_r(ov, i);
-               info("OV511[0x%02X] = 0x%02X", i, rc);
+               dev_info(&ov->dev->dev, "OV511[0x%02X] = 0x%02X\n", i, rc);
        }
 }
 
 static void
 ov511_dump_regs(struct usb_ov511 *ov)
 {
-       info("CAMERA INTERFACE REGS");
+       dev_info(&ov->dev->dev, "CAMERA INTERFACE REGS\n");
        dump_reg_range(ov, 0x10, 0x1f);
-       info("DRAM INTERFACE REGS");
+       dev_info(&ov->dev->dev, "DRAM INTERFACE REGS\n");
        dump_reg_range(ov, 0x20, 0x23);
-       info("ISO FIFO REGS");
+       dev_info(&ov->dev->dev, "ISO FIFO REGS\n");
        dump_reg_range(ov, 0x30, 0x31);
-       info("PIO REGS");
+       dev_info(&ov->dev->dev, "PIO REGS\n");
        dump_reg_range(ov, 0x38, 0x39);
        dump_reg_range(ov, 0x3e, 0x3e);
-       info("I2C REGS");
+       dev_info(&ov->dev->dev, "I2C REGS\n");
        dump_reg_range(ov, 0x40, 0x49);
-       info("SYSTEM CONTROL REGS");
+       dev_info(&ov->dev->dev, "SYSTEM CONTROL REGS\n");
        dump_reg_range(ov, 0x50, 0x55);
        dump_reg_range(ov, 0x5e, 0x5f);
-       info("OmniCE REGS");
+       dev_info(&ov->dev->dev, "OmniCE REGS\n");
        dump_reg_range(ov, 0x70, 0x79);
        /* NOTE: Quantization tables are not readable. You will get the value
         * in reg. 0x79 for every table register */
@@ -1025,25 +1025,25 @@ ov511_dump_regs(struct usb_ov511 *ov)
 static void
 ov518_dump_regs(struct usb_ov511 *ov)
 {
-       info("VIDEO MODE REGS");
+       dev_info(&ov->dev->dev, "VIDEO MODE REGS\n");
        dump_reg_range(ov, 0x20, 0x2f);
-       info("DATA PUMP AND SNAPSHOT REGS");
+       dev_info(&ov->dev->dev, "DATA PUMP AND SNAPSHOT REGS\n");
        dump_reg_range(ov, 0x30, 0x3f);
-       info("I2C REGS");
+       dev_info(&ov->dev->dev, "I2C REGS\n");
        dump_reg_range(ov, 0x40, 0x4f);
-       info("SYSTEM CONTROL AND VENDOR REGS");
+       dev_info(&ov->dev->dev, "SYSTEM CONTROL AND VENDOR REGS\n");
        dump_reg_range(ov, 0x50, 0x5f);
-       info("60 - 6F");
+       dev_info(&ov->dev->dev, "60 - 6F\n");
        dump_reg_range(ov, 0x60, 0x6f);
-       info("70 - 7F");
+       dev_info(&ov->dev->dev, "70 - 7F\n");
        dump_reg_range(ov, 0x70, 0x7f);
-       info("Y QUANTIZATION TABLE");
+       dev_info(&ov->dev->dev, "Y QUANTIZATION TABLE\n");
        dump_reg_range(ov, 0x80, 0x8f);
-       info("UV QUANTIZATION TABLE");
+       dev_info(&ov->dev->dev, "UV QUANTIZATION TABLE\n");
        dump_reg_range(ov, 0x90, 0x9f);
-       info("A0 - BF");
+       dev_info(&ov->dev->dev, "A0 - BF\n");
        dump_reg_range(ov, 0xa0, 0xbf);
-       info("CBR");
+       dev_info(&ov->dev->dev, "CBR\n");
        dump_reg_range(ov, 0xc0, 0xcf);
 }
 #endif
@@ -3205,9 +3205,10 @@ ov511_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
         */
 
        if (printph) {
-               info("ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x",
-                    pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
-                    in[7], in[8], in[9], in[10], in[11]);
+               dev_info(&ov->dev->dev,
+                        "ph(%3d): %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x %2x\n",
+                        pnum, in[0], in[1], in[2], in[3], in[4], in[5], in[6],
+                        in[7], in[8], in[9], in[10], in[11]);
        }
 
        /* Check for SOF/EOF packet */
@@ -3366,8 +3367,10 @@ ov518_move_data(struct usb_ov511 *ov, unsigned char *in, int n)
         * the definitive SOF/EOF format */
        if ((!(in[0] | in[1] | in[2] | in[3] | in[5])) && in[6]) {
                if (printph) {
-                       info("ph: %2x %2x %2x %2x %2x %2x %2x %2x", in[0],
-                            in[1], in[2], in[3], in[4], in[5], in[6], in[7]);
+                       dev_info(&ov->dev->dev,
+                                "ph: %2x %2x %2x %2x %2x %2x %2x %2x\n",
+                                in[0], in[1], in[2], in[3], in[4], in[5],
+                                in[6], in[7]);
                }
 
                if (frame->scanstate == STATE_LINES) {
@@ -3646,14 +3649,16 @@ ov51x_init_isoc(struct usb_ov511 *ov)
                if (packetsize == -1) {
                        ov518_set_packet_size(ov, 640);
                } else {
-                       info("Forcing packet size to %d", packetsize);
+                       dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
+                                packetsize);
                        ov518_set_packet_size(ov, packetsize);
                }
        } else {
                if (packetsize == -1) {
                        ov511_set_packet_size(ov, size);
                } else {
-                       info("Forcing packet size to %d", packetsize);
+                       dev_info(&ov->dev->dev, "Forcing packet size to %d\n",
+                                packetsize);
                        ov511_set_packet_size(ov, packetsize);
                }
        }
@@ -4121,7 +4126,7 @@ ov51x_v4l1_ioctl_internal(struct inode *inode, struct file *file,
                        return -EIO;
 
                if (force_palette && p->palette != force_palette) {
-                       info("Palette rejected (%s)",
+                       dev_info(&ov->dev->dev, "Palette rejected (%s)\n",
                             symbolic(v4l1_plist, p->palette));
                        return -EINVAL;
                }
@@ -4849,26 +4854,27 @@ ov7xx0_configure(struct usb_ov511 *ov)
                err("Error detecting sensor type");
                return -1;
        } else if ((rc & 3) == 3) {
-               info("Sensor is an OV7610");
+               dev_info(&ov->dev->dev, "Sensor is an OV7610\n");
                ov->sensor = SEN_OV7610;
        } else if ((rc & 3) == 1) {
                /* I don't know what's different about the 76BE yet. */
                if (i2c_r(ov, 0x15) & 1)
-                       info("Sensor is an OV7620AE");
+                       dev_info(&ov->dev->dev, "Sensor is an OV7620AE\n");
                else
-                       info("Sensor is an OV76BE");
+                       dev_info(&ov->dev->dev, "Sensor is an OV76BE\n");
 
                /* OV511+ will return all zero isoc data unless we
                 * configure the sensor as a 7620. Someone needs to
                 * find the exact reg. setting that causes this. */
                if (ov->bridge == BRG_OV511PLUS) {
-                       info("Enabling 511+/7620AE workaround");
+                       dev_info(&ov->dev->dev,
+                                "Enabling 511+/7620AE workaround\n");
                        ov->sensor = SEN_OV7620;
                } else {
                        ov->sensor = SEN_OV76BE;
                }
        } else if ((rc & 3) == 0) {
-               info("Sensor is an OV7620");
+               dev_info(&ov->dev->dev, "Sensor is an OV7620\n");
                ov->sensor = SEN_OV7620;
        } else {
                err("Unknown image sensor version: %d", rc & 3);
@@ -5024,16 +5030,16 @@ ov6xx0_configure(struct usb_ov511 *ov)
 
        if ((rc & 3) == 0) {
                ov->sensor = SEN_OV6630;
-               info("Sensor is an OV6630");
+               dev_info(&ov->dev->dev, "Sensor is an OV6630\n");
        } else if ((rc & 3) == 1) {
                ov->sensor = SEN_OV6620;
-               info("Sensor is an OV6620");
+               dev_info(&ov->dev->dev, "Sensor is an OV6620\n");
        } else if ((rc & 3) == 2) {
                ov->sensor = SEN_OV6630;
-               info("Sensor is an OV6630AE");
+               dev_info(&ov->dev->dev, "Sensor is an OV6630AE\n");
        } else if ((rc & 3) == 3) {
                ov->sensor = SEN_OV6630;
-               info("Sensor is an OV6630AF");
+               dev_info(&ov->dev->dev, "Sensor is an OV6630AF\n");
        }
 
        /* Set sensor-specific vars */
@@ -5088,10 +5094,10 @@ ks0127_configure(struct usb_ov511 *ov)
                        err("Error detecting sensor type");
                        return -1;
                } else if ((rc & 0x0f) == 0) {
-                       info("Sensor is a KS0127");
+                       dev_info(&ov->dev->dev, "Sensor is a KS0127\n");
                        ov->sensor = SEN_KS0127;
                } else if ((rc & 0x0f) == 9) {
-                       info("Sensor is a KS0127B Rev. A");
+                       dev_info(&ov->dev->dev, "Sensor is a KS0127B Rev. A\n");
                        ov->sensor = SEN_KS0127B;
                }
        } else {
@@ -5200,7 +5206,8 @@ saa7111a_configure(struct usb_ov511 *ov)
                err("Error detecting sensor version");
                return -1;
        } else {
-               info("Sensor is an SAA7111A (version 0x%x)", rc);
+               dev_info(&ov->dev->dev,
+                        "Sensor is an SAA7111A (version 0x%x)\n", rc);
                ov->sensor = SEN_SAA7111A;
        }
 
@@ -5262,7 +5269,7 @@ ov511_configure(struct usb_ov511 *ov)
 
        PDEBUG (1, "CustomID = %d", ov->customid);
        ov->desc = symbolic(camlist, ov->customid);
-       info("model: %s", ov->desc);
+       dev_info(&ov->dev->dev, "model: %s\n", ov->desc);
 
        if (0 == strcmp(ov->desc, NOT_DEFINED_STR)) {
                err("Camera type (%d) not recognized", ov->customid);
@@ -5426,7 +5433,8 @@ ov518_configure(struct usb_ov511 *ov)
        PDEBUG(4, "");
 
        /* First 5 bits of custom ID reg are a revision ID on OV518 */
-       info("Device revision %d", 0x1F & reg_r(ov, R511_SYS_CUST_ID));
+       dev_info(&ov->dev->dev, "Device revision %d\n",
+                0x1F & reg_r(ov, R511_SYS_CUST_ID));
 
        /* Give it the default description */
        ov->desc = symbolic(camlist, 0);
@@ -5773,7 +5781,8 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
                goto error;
        }
 
-       info("USB %s video device found", symbolic(brglist, ov->bridge));
+       dev_info(&intf->dev, "USB %s video device found\n",
+                symbolic(brglist, ov->bridge));
 
        init_waitqueue_head(&ov->wq);
 
@@ -5854,8 +5863,8 @@ ov51x_probe(struct usb_interface *intf, const struct usb_device_id *id)
                goto error;
        }
 
-       info("Device at %s registered to minor %d", ov->usb_path,
-            ov->vdev->minor);
+       dev_info(&intf->dev, "Device at %s registered to minor %d\n",
+                ov->usb_path, ov->vdev->minor);
 
        usb_set_intfdata(intf, ov);
        if (ov_create_sysfs(ov->vdev)) {
@@ -5958,7 +5967,8 @@ usb_ov511_init(void)
        if (retval)
                goto out;
 
-       info(DRIVER_VERSION " : " DRIVER_DESC);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
 
 out:
        return retval;
@@ -5968,8 +5978,7 @@ static void __exit
 usb_ov511_exit(void)
 {
        usb_deregister(&ov511_driver);
-       info("driver deregistered");
-
+       printk(KERN_INFO KBUILD_MODNAME ": driver deregistered\n");
 }
 
 module_init(usb_ov511_init);
index baded1262ca9f68b675ca72d3ad18d045d8f2f41..70d99e52329d53ff457d9d335982808e92171d8f 100644 (file)
@@ -12,7 +12,8 @@
 
 #ifdef OV511_DEBUG
        #define PDEBUG(level, fmt, args...) \
-               if (debug >= (level)) info("[%s:%d] " fmt, \
+               if (debug >= (level))   \
+                       printk(KERN_INFO KBUILD_MODNAME "[%s:%d] \n" fmt, \
                __func__, __LINE__ , ## args)
 #else
        #define PDEBUG(level, fmt, args...) do {} while(0)
index 065c2454113e717ddb2cb6fd276b5e16e3382c0f..2c4acbf5a4feae2f5f425c8d9f8b925ec4cdcbd9 100644 (file)
@@ -49,12 +49,6 @@ MODULE_LICENSE("GPL");
 #define GENERIC_REG_ID_LOW        0x1D /* manufacturer ID LSB */
 #define GENERIC_REG_COM_I         0x29 /* misc ID bits */
 
-extern struct ovcamchip_ops ov6x20_ops;
-extern struct ovcamchip_ops ov6x30_ops;
-extern struct ovcamchip_ops ov7x10_ops;
-extern struct ovcamchip_ops ov7x20_ops;
-extern struct ovcamchip_ops ov76be_ops;
-
 static char *chip_names[NUM_CC_TYPES] = {
        [CC_UNKNOWN]    = "Unknown chip",
        [CC_OV76BE]     = "OV76BE",
index 9afa4fe47726011f4e78edb87fd97095d3410c35..a05650faedda435363e6bfeb5339b51fe896541e 100644 (file)
@@ -53,6 +53,12 @@ struct ovcamchip {
        int initialized;           /* OVCAMCHIP_CMD_INITIALIZE was successful */
 };
 
+extern struct ovcamchip_ops ov6x20_ops;
+extern struct ovcamchip_ops ov6x30_ops;
+extern struct ovcamchip_ops ov7x10_ops;
+extern struct ovcamchip_ops ov7x20_ops;
+extern struct ovcamchip_ops ov76be_ops;
+
 /* --------------------------------- */
 /*              I2C I/O              */
 /* --------------------------------- */
index 7c84f795db54bcb188d39b541cb0f1f673246c8c..994807818aa26eacd2ffc09920445d2cc69f58d9 100644 (file)
@@ -47,6 +47,7 @@ struct pms_device
        struct video_picture picture;
        int height;
        int width;
+       unsigned long in_use;
        struct mutex lock;
 };
 
@@ -881,10 +882,27 @@ static ssize_t pms_read(struct file *file, char __user *buf,
        return len;
 }
 
+static int pms_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct video_device *v = video_devdata(file);
+       struct pms_device *pd = (struct pms_device *)v;
+
+       return test_and_set_bit(0, &pd->in_use) ? -EBUSY : 0;
+}
+
+static int pms_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct video_device *v = video_devdata(file);
+       struct pms_device *pd = (struct pms_device *)v;
+
+       clear_bit(0, &pd->in_use);
+       return 0;
+}
+
 static const struct file_operations pms_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = pms_exclusive_open,
+       .release        = pms_exclusive_release,
        .ioctl          = pms_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -897,6 +915,7 @@ static struct video_device pms_template=
 {
        .name           = "Mediavision PMS",
        .fops           = &pms_fops,
+       .release        = video_device_release_empty,
 };
 
 static struct pms_device pms_device;
index 0764fbfffb73b036c0687b34c94afd1a9d3b58a3..203f54cd18a16ac164e151166743b3a45327a95a 100644 (file)
@@ -134,13 +134,17 @@ int pvr2_ctrl_get_min(struct pvr2_ctrl *cptr)
 
 
 /* Retrieve control's default value (any type) */
-int pvr2_ctrl_get_def(struct pvr2_ctrl *cptr)
+int pvr2_ctrl_get_def(struct pvr2_ctrl *cptr, int *valptr)
 {
        int ret = 0;
        if (!cptr) return 0;
        LOCK_TAKE(cptr->hdw->big_lock); do {
                if (cptr->info->type == pvr2_ctl_int) {
-                       ret = cptr->info->default_value;
+                       if (cptr->info->get_def_value) {
+                               ret = cptr->info->get_def_value(cptr, valptr);
+                       } else {
+                               *valptr = cptr->info->default_value;
+                       }
                }
        } while(0); LOCK_GIVE(cptr->hdw->big_lock);
        return ret;
index 0371ae6e6e4eb61b1e42e8799f92598d5a86e1ff..794ff90121c7d367ee221507f72a12d4ea8aca58 100644 (file)
@@ -49,7 +49,7 @@ int pvr2_ctrl_get_max(struct pvr2_ctrl *);
 int pvr2_ctrl_get_min(struct pvr2_ctrl *);
 
 /* Retrieve control's default value (any type) */
-int pvr2_ctrl_get_def(struct pvr2_ctrl *);
+int pvr2_ctrl_get_def(struct pvr2_ctrl *, int *valptr);
 
 /* Retrieve control's enumeration count (enum only) */
 int pvr2_ctrl_get_cnt(struct pvr2_ctrl *);
index 657f861593b352516c324fa7da471462c7250a67..de7ee7264be63bc8855380942b1e14ae222ca7d6 100644 (file)
@@ -82,6 +82,7 @@ struct pvr2_ctl_info {
 
        /* Control's implementation */
        pvr2_ctlf_get_value get_value;      /* Get its value */
+       pvr2_ctlf_get_value get_def_value;  /* Get its default value */
        pvr2_ctlf_get_value get_min_value;  /* Get minimum allowed value */
        pvr2_ctlf_get_value get_max_value;  /* Get maximum allowed value */
        pvr2_ctlf_set_value set_value;      /* Set its value */
@@ -307,6 +308,10 @@ struct pvr2_hdw {
        struct v4l2_tuner tuner_signal_info;
        int tuner_signal_stale;
 
+       /* Cropping capability info */
+       struct v4l2_cropcap cropcap_info;
+       int cropcap_stale;
+
        /* Video standard handling */
        v4l2_std_id std_mask_eeprom; // Hardware supported selections
        v4l2_std_id std_mask_avail;  // Which standards we may select from
@@ -367,6 +372,10 @@ struct pvr2_hdw {
        VCREATE_DATA(bass);
        VCREATE_DATA(treble);
        VCREATE_DATA(mute);
+       VCREATE_DATA(cropl);
+       VCREATE_DATA(cropt);
+       VCREATE_DATA(cropw);
+       VCREATE_DATA(croph);
        VCREATE_DATA(input);
        VCREATE_DATA(audiomode);
        VCREATE_DATA(res_hor);
index f051c6aa7f1f223cd36744df1b6cc2af4b26d82a..94265bd3d926c1b2a8960ae743a05f962aec75c2 100644 (file)
@@ -298,6 +298,7 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
                                unsigned int timeout,int probe_fl,
                                void *write_data,unsigned int write_len,
                                void *read_data,unsigned int read_len);
+static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw);
 
 
 static void trace_stbit(const char *name,int val)
@@ -402,6 +403,194 @@ static int ctrl_freq_set(struct pvr2_ctrl *cptr,int m,int v)
        return 0;
 }
 
+static int ctrl_cropl_min_get(struct pvr2_ctrl *cptr, int *left)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *left = cap->bounds.left;
+       return 0;
+}
+
+static int ctrl_cropl_max_get(struct pvr2_ctrl *cptr, int *left)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *left = cap->bounds.left;
+       if (cap->bounds.width > cptr->hdw->cropw_val) {
+               *left += cap->bounds.width - cptr->hdw->cropw_val;
+       }
+       return 0;
+}
+
+static int ctrl_cropt_min_get(struct pvr2_ctrl *cptr, int *top)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *top = cap->bounds.top;
+       return 0;
+}
+
+static int ctrl_cropt_max_get(struct pvr2_ctrl *cptr, int *top)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *top = cap->bounds.top;
+       if (cap->bounds.height > cptr->hdw->croph_val) {
+               *top += cap->bounds.height - cptr->hdw->croph_val;
+       }
+       return 0;
+}
+
+static int ctrl_cropw_max_get(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = 0;
+       if (cap->bounds.width > cptr->hdw->cropl_val) {
+               *val = cap->bounds.width - cptr->hdw->cropl_val;
+       }
+       return 0;
+}
+
+static int ctrl_croph_max_get(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = 0;
+       if (cap->bounds.height > cptr->hdw->cropt_val) {
+               *val = cap->bounds.height - cptr->hdw->cropt_val;
+       }
+       return 0;
+}
+
+static int ctrl_get_cropcapbl(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->bounds.left;
+       return 0;
+}
+
+static int ctrl_get_cropcapbt(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->bounds.top;
+       return 0;
+}
+
+static int ctrl_get_cropcapbw(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->bounds.width;
+       return 0;
+}
+
+static int ctrl_get_cropcapbh(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->bounds.height;
+       return 0;
+}
+
+static int ctrl_get_cropcapdl(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->defrect.left;
+       return 0;
+}
+
+static int ctrl_get_cropcapdt(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->defrect.top;
+       return 0;
+}
+
+static int ctrl_get_cropcapdw(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->defrect.width;
+       return 0;
+}
+
+static int ctrl_get_cropcapdh(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->defrect.height;
+       return 0;
+}
+
+static int ctrl_get_cropcappan(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->pixelaspect.numerator;
+       return 0;
+}
+
+static int ctrl_get_cropcappad(struct pvr2_ctrl *cptr, int *val)
+{
+       struct v4l2_cropcap *cap = &cptr->hdw->cropcap_info;
+       int stat = pvr2_hdw_check_cropcap(cptr->hdw);
+       if (stat != 0) {
+               return stat;
+       }
+       *val = cap->pixelaspect.denominator;
+       return 0;
+}
+
 static int ctrl_vres_max_get(struct pvr2_ctrl *cptr,int *vp)
 {
        /* Actual maximum depends on the video standard in effect. */
@@ -779,6 +968,10 @@ VCREATE_FUNCS(balance)
 VCREATE_FUNCS(bass)
 VCREATE_FUNCS(treble)
 VCREATE_FUNCS(mute)
+VCREATE_FUNCS(cropl)
+VCREATE_FUNCS(cropt)
+VCREATE_FUNCS(cropw)
+VCREATE_FUNCS(croph)
 VCREATE_FUNCS(audiomode)
 VCREATE_FUNCS(res_hor)
 VCREATE_FUNCS(res_ver)
@@ -849,6 +1042,72 @@ static const struct pvr2_ctl_info control_defs[] = {
                .default_value = 0,
                DEFREF(mute),
                DEFBOOL,
+       }, {
+               .desc = "Capture crop left margin",
+               .name = "crop_left",
+               .internal_id = PVR2_CID_CROPL,
+               .default_value = 0,
+               DEFREF(cropl),
+               DEFINT(-129, 340),
+               .get_min_value = ctrl_cropl_min_get,
+               .get_max_value = ctrl_cropl_max_get,
+               .get_def_value = ctrl_get_cropcapdl,
+       }, {
+               .desc = "Capture crop top margin",
+               .name = "crop_top",
+               .internal_id = PVR2_CID_CROPT,
+               .default_value = 0,
+               DEFREF(cropt),
+               DEFINT(-35, 544),
+               .get_min_value = ctrl_cropt_min_get,
+               .get_max_value = ctrl_cropt_max_get,
+               .get_def_value = ctrl_get_cropcapdt,
+       }, {
+               .desc = "Capture crop width",
+               .name = "crop_width",
+               .internal_id = PVR2_CID_CROPW,
+               .default_value = 720,
+               DEFREF(cropw),
+               .get_max_value = ctrl_cropw_max_get,
+               .get_def_value = ctrl_get_cropcapdw,
+       }, {
+               .desc = "Capture crop height",
+               .name = "crop_height",
+               .internal_id = PVR2_CID_CROPH,
+               .default_value = 480,
+               DEFREF(croph),
+               .get_max_value = ctrl_croph_max_get,
+               .get_def_value = ctrl_get_cropcapdh,
+       }, {
+               .desc = "Capture capability pixel aspect numerator",
+               .name = "cropcap_pixel_numerator",
+               .internal_id = PVR2_CID_CROPCAPPAN,
+               .get_value = ctrl_get_cropcappan,
+       }, {
+               .desc = "Capture capability pixel aspect denominator",
+               .name = "cropcap_pixel_denominator",
+               .internal_id = PVR2_CID_CROPCAPPAD,
+               .get_value = ctrl_get_cropcappad,
+       }, {
+               .desc = "Capture capability bounds top",
+               .name = "cropcap_bounds_top",
+               .internal_id = PVR2_CID_CROPCAPBT,
+               .get_value = ctrl_get_cropcapbt,
+       }, {
+               .desc = "Capture capability bounds left",
+               .name = "cropcap_bounds_left",
+               .internal_id = PVR2_CID_CROPCAPBL,
+               .get_value = ctrl_get_cropcapbl,
+       }, {
+               .desc = "Capture capability bounds width",
+               .name = "cropcap_bounds_width",
+               .internal_id = PVR2_CID_CROPCAPBW,
+               .get_value = ctrl_get_cropcapbw,
+       }, {
+               .desc = "Capture capability bounds height",
+               .name = "cropcap_bounds_height",
+               .internal_id = PVR2_CID_CROPCAPBH,
+               .get_value = ctrl_get_cropcapbh,
        },{
                .desc = "Video Source",
                .name = "input",
@@ -1313,9 +1572,19 @@ int pvr2_upload_firmware2(struct pvr2_hdw *hdw)
                if (bcnt > FIRMWARE_CHUNK_SIZE) bcnt = FIRMWARE_CHUNK_SIZE;
                memcpy(fw_ptr, fw_entry->data + fw_done, bcnt);
                /* Usbsnoop log shows that we must swap bytes... */
+               /* Some background info: The data being swapped here is a
+                  firmware image destined for the mpeg encoder chip that
+                  lives at the other end of a USB endpoint.  The encoder
+                  chip always talks in 32 bit chunks and its storage is
+                  organized into 32 bit words.  However from the file
+                  system to the encoder chip everything is purely a byte
+                  stream.  The firmware file's contents are always 32 bit
+                  swapped from what the encoder expects.  Thus the need
+                  always exists to swap the bytes regardless of the endian
+                  type of the host processor and therefore swab32() makes
+                  the most sense. */
                for (icnt = 0; icnt < bcnt/4 ; icnt++)
-                       ((u32 *)fw_ptr)[icnt] =
-                               ___swab32(((u32 *)fw_ptr)[icnt]);
+                       ((u32 *)fw_ptr)[icnt] = swab32(((u32 *)fw_ptr)[icnt]);
 
                ret |= usb_bulk_msg(hdw->usb_dev, pipe, fw_ptr,bcnt,
                                    &actual_length, HZ);
@@ -1905,7 +2174,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
                                 const struct usb_device_id *devid)
 {
        unsigned int idx,cnt1,cnt2,m;
-       struct pvr2_hdw *hdw;
+       struct pvr2_hdw *hdw = NULL;
        int valid_std_mask;
        struct pvr2_ctrl *cptr;
        const struct pvr2_device_desc *hdw_desc;
@@ -1915,6 +2184,16 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
 
        hdw_desc = (const struct pvr2_device_desc *)(devid->driver_info);
 
+       if (hdw_desc == NULL) {
+               pvr2_trace(PVR2_TRACE_INIT, "pvr2_hdw_create:"
+                          " No device description pointer,"
+                          " unable to continue.");
+               pvr2_trace(PVR2_TRACE_INIT, "If you have a new device type,"
+                          " please contact Mike Isely <isely@pobox.com>"
+                          " to get it included in the driver\n");
+               goto fail;
+       }
+
        hdw = kzalloc(sizeof(*hdw),GFP_KERNEL);
        pvr2_trace(PVR2_TRACE_INIT,"pvr2_hdw_create: hdw=%p, type \"%s\"",
                   hdw,hdw_desc->description);
@@ -2072,6 +2351,7 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
                        valid_std_mask;
        }
 
+       hdw->cropcap_stale = !0;
        hdw->eeprom_addr = -1;
        hdw->unit_number = -1;
        hdw->v4l_minor_number_video = -1;
@@ -2508,6 +2788,28 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
                /* Can't commit anything until pathway is ok. */
                return 0;
        }
+       /* The broadcast decoder can only scale down, so if
+        * res_*_dirty && crop window < output format ==> enlarge crop.
+        *
+        * The mpeg encoder receives fields of res_hor_val dots and
+        * res_ver_val halflines.  Limits: hor<=720, ver<=576.
+        */
+       if (hdw->res_hor_dirty && hdw->cropw_val < hdw->res_hor_val) {
+               hdw->cropw_val = hdw->res_hor_val;
+               hdw->cropw_dirty = !0;
+       } else if (hdw->cropw_dirty) {
+               hdw->res_hor_dirty = !0;           /* must rescale */
+               hdw->res_hor_val = min(720, hdw->cropw_val);
+       }
+       if (hdw->res_ver_dirty && hdw->croph_val < hdw->res_ver_val) {
+               hdw->croph_val = hdw->res_ver_val;
+               hdw->croph_dirty = !0;
+       } else if (hdw->croph_dirty) {
+               int nvres = hdw->std_mask_cur & V4L2_STD_525_60 ? 480 : 576;
+               hdw->res_ver_dirty = !0;
+               hdw->res_ver_val = min(nvres, hdw->croph_val);
+       }
+
        /* If any of the below has changed, then we can't do the update
           while the pipeline is running.  Pipeline must be paused first
           and decoder -> encoder connection be made quiescent before we
@@ -2518,6 +2820,8 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
                 hdw->srate_dirty ||
                 hdw->res_ver_dirty ||
                 hdw->res_hor_dirty ||
+                hdw->cropw_dirty ||
+                hdw->croph_dirty ||
                 hdw->input_dirty ||
                 (hdw->active_stream_type != hdw->desired_stream_type));
        if (disruptive_change && !hdw->state_pipeline_idle) {
@@ -2587,6 +2891,9 @@ static int pvr2_hdw_commit_execute(struct pvr2_hdw *hdw)
        }
 
        hdw->state_pipeline_config = !0;
+       /* Hardware state may have changed in a way to cause the cropping
+          capabilities to have changed.  So mark it stale, which will
+          cause a later re-fetch. */
        trace_stbit("state_pipeline_config",hdw->state_pipeline_config);
        return !0;
 }
@@ -2677,6 +2984,33 @@ void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *hdw)
 }
 
 
+static int pvr2_hdw_check_cropcap(struct pvr2_hdw *hdw)
+{
+       if (!hdw->cropcap_stale) {
+               return 0;
+       }
+       pvr2_i2c_core_status_poll(hdw);
+       if (hdw->cropcap_stale) {
+               return -EIO;
+       }
+       return 0;
+}
+
+
+/* Return information about cropping capabilities */
+int pvr2_hdw_get_cropcap(struct pvr2_hdw *hdw, struct v4l2_cropcap *pp)
+{
+       int stat = 0;
+       LOCK_TAKE(hdw->big_lock);
+       stat = pvr2_hdw_check_cropcap(hdw);
+       if (!stat) {
+               memcpy(pp, &hdw->cropcap_info, sizeof(hdw->cropcap_info));
+       }
+       LOCK_GIVE(hdw->big_lock);
+       return stat;
+}
+
+
 /* Return information about the tuner */
 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *hdw,struct v4l2_tuner *vtp)
 {
index c04956d304a7da07814030a29543fcf1c0d55651..49482d1f2b28d71b87ccd3318e3b0b45afeda2e1 100644 (file)
 #define PVR2_CID_FREQUENCY 6
 #define PVR2_CID_HRES 7
 #define PVR2_CID_VRES 8
+#define PVR2_CID_CROPL 9
+#define PVR2_CID_CROPT 10
+#define PVR2_CID_CROPW 11
+#define PVR2_CID_CROPH 12
+#define PVR2_CID_CROPCAPPAN 13
+#define PVR2_CID_CROPCAPPAD 14
+#define PVR2_CID_CROPCAPBL 15
+#define PVR2_CID_CROPCAPBT 16
+#define PVR2_CID_CROPCAPBW 17
+#define PVR2_CID_CROPCAPBH 18
 
 /* Legal values for the INPUT state variable */
 #define PVR2_CVAL_INPUT_TV 0
@@ -170,6 +180,9 @@ void pvr2_hdw_execute_tuner_poll(struct pvr2_hdw *);
 /* Return information about the tuner */
 int pvr2_hdw_get_tuner_status(struct pvr2_hdw *,struct v4l2_tuner *);
 
+/* Return information about cropping capabilities */
+int pvr2_hdw_get_cropcap(struct pvr2_hdw *, struct v4l2_cropcap *);
+
 /* Query device and see if it thinks it is on a high-speed USB link */
 int pvr2_hdw_is_hsm(struct pvr2_hdw *);
 
index ccdb429fc7afc8f5b91fa1574aeb417a0a194b41..94a47718e88eb0dcd275f9c080d23440dfbdad85 100644 (file)
@@ -37,8 +37,9 @@
 #define OP_VOLUME 3
 #define OP_FREQ 4
 #define OP_AUDIORATE 5
-#define OP_SIZE 6
-#define OP_LOG 7
+#define OP_CROP 6
+#define OP_SIZE 7
+#define OP_LOG 8
 
 static const struct pvr2_i2c_op * const ops[] = {
        [OP_STANDARD] = &pvr2_i2c_op_v4l2_standard,
@@ -46,6 +47,7 @@ static const struct pvr2_i2c_op * const ops[] = {
        [OP_BCSH] = &pvr2_i2c_op_v4l2_bcsh,
        [OP_VOLUME] = &pvr2_i2c_op_v4l2_volume,
        [OP_FREQ] = &pvr2_i2c_op_v4l2_frequency,
+       [OP_CROP] = &pvr2_i2c_op_v4l2_crop,
        [OP_SIZE] = &pvr2_i2c_op_v4l2_size,
        [OP_LOG] = &pvr2_i2c_op_v4l2_log,
 };
@@ -59,6 +61,7 @@ void pvr2_i2c_probe(struct pvr2_hdw *hdw,struct pvr2_i2c_client *cp)
                        (1 << OP_BCSH) |
                        (1 << OP_VOLUME) |
                        (1 << OP_FREQ) |
+                       (1 << OP_CROP) |
                        (1 << OP_SIZE) |
                        (1 << OP_LOG));
        cp->status_poll = pvr2_v4l2_cmd_status_poll;
index 55f04a0b2047eca152455e7a87c3db1d22e86f4f..16bb11902a522ef0881e44e47aacc4779c4a57e3 100644 (file)
@@ -37,6 +37,7 @@ static void set_standard(struct pvr2_hdw *hdw)
                pvr2_i2c_core_cmd(hdw,VIDIOC_S_STD,&vs);
        }
        hdw->tuner_signal_stale = !0;
+       hdw->cropcap_stale = !0;
 }
 
 
@@ -233,6 +234,37 @@ const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size = {
 };
 
 
+static void set_crop(struct pvr2_hdw *hdw)
+{
+       struct v4l2_crop crop;
+
+       memset(&crop, 0, sizeof crop);
+       crop.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+       crop.c.left = hdw->cropl_val;
+       crop.c.top = hdw->cropt_val;
+       crop.c.height = hdw->croph_val;
+       crop.c.width = hdw->cropw_val;
+
+       pvr2_trace(PVR2_TRACE_CHIPS,
+                  "i2c v4l2 set_crop crop=%d:%d:%d:%d",
+                  crop.c.width, crop.c.height, crop.c.left, crop.c.top);
+
+       pvr2_i2c_core_cmd(hdw, VIDIOC_S_CROP, &crop);
+}
+
+static int check_crop(struct pvr2_hdw *hdw)
+{
+       return (hdw->cropl_dirty || hdw->cropt_dirty ||
+               hdw->cropw_dirty || hdw->croph_dirty);
+}
+
+const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop = {
+       .check = check_crop,
+       .update = set_crop,
+       .name = "v4l2_crop",
+};
+
+
 static void do_log(struct pvr2_hdw *hdw)
 {
        pvr2_trace(PVR2_TRACE_CHIPS,"i2c v4l2 do_log()");
@@ -263,7 +295,19 @@ void pvr2_v4l2_cmd_stream(struct pvr2_i2c_client *cp,int fl)
 
 void pvr2_v4l2_cmd_status_poll(struct pvr2_i2c_client *cp)
 {
-       pvr2_i2c_client_cmd(cp,VIDIOC_G_TUNER,&cp->hdw->tuner_signal_info);
+       int stat;
+       struct pvr2_hdw *hdw = cp->hdw;
+       if (hdw->cropcap_stale) {
+               hdw->cropcap_info.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               stat = pvr2_i2c_client_cmd(cp, VIDIOC_CROPCAP,
+                                          &hdw->cropcap_info);
+               if (stat == 0) {
+                       /* Check was successful, so the data is no
+                          longer considered stale. */
+                       hdw->cropcap_stale = 0;
+               }
+       }
+       pvr2_i2c_client_cmd(cp, VIDIOC_G_TUNER, &hdw->tuner_signal_info);
 }
 
 
index 7fa38683b3b1f309bc2f23835cf63d7d05a308c4..eb744a20610d4ec15d68f648626e268487172619 100644 (file)
@@ -29,6 +29,7 @@ extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_radio;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_bcsh;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_volume;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_frequency;
+extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_crop;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_size;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_audiomode;
 extern const struct pvr2_i2c_op pvr2_i2c_op_v4l2_log;
index e600576a6c4b5b7092293052230e54ff3a857cec..d6a35401fefb78186ad40e758003a4c34b77ce84 100644 (file)
@@ -827,7 +827,7 @@ static unsigned int pvr2_i2c_client_describe(struct pvr2_i2c_client *cp,
        if ((detail & PVR2_I2C_DETAIL_CTLMASK) && cp->ctl_mask) {
                unsigned int idx;
                unsigned long msk,sm;
-               int spcfl;
+
                bcnt = scnprintf(buf,maxlen," [");
                ccnt += bcnt; buf += bcnt; maxlen -= bcnt;
                sm = 0;
@@ -891,6 +891,7 @@ static int pvr2_i2c_attach_inform(struct i2c_client *client)
        INIT_LIST_HEAD(&cp->list);
        cp->client = client;
        mutex_lock(&hdw->i2c_list_lock); do {
+               hdw->cropcap_stale = !0;
                list_add_tail(&cp->list,&hdw->i2c_clients);
                hdw->i2c_pend_types |= PVR2_I2C_PEND_DETECT;
        } while (0); mutex_unlock(&hdw->i2c_list_lock);
@@ -905,6 +906,7 @@ static int pvr2_i2c_detach_inform(struct i2c_client *client)
        unsigned long amask = 0;
        int foundfl = 0;
        mutex_lock(&hdw->i2c_list_lock); do {
+               hdw->cropcap_stale = !0;
                list_for_each_entry_safe(cp, ncp, &hdw->i2c_clients, list) {
                        if (cp->client == client) {
                                trace_i2c("pvr2_i2c_detach"
@@ -946,22 +948,32 @@ static struct i2c_adapter pvr2_i2c_adap_template = {
        .client_unregister = pvr2_i2c_detach_inform,
 };
 
-static void do_i2c_scan(struct pvr2_hdw *hdw)
+
+/* Return true if device exists at given address */
+static int do_i2c_probe(struct pvr2_hdw *hdw, int addr)
 {
        struct i2c_msg msg[1];
-       int i,rc;
+       int rc;
        msg[0].addr = 0;
        msg[0].flags = I2C_M_RD;
        msg[0].len = 0;
        msg[0].buf = NULL;
-       printk("%s: i2c scan beginning\n",hdw->name);
+       msg[0].addr = addr;
+       rc = i2c_transfer(&hdw->i2c_adap, msg, ARRAY_SIZE(msg));
+       return rc == 1;
+}
+
+static void do_i2c_scan(struct pvr2_hdw *hdw)
+{
+       int i;
+       printk(KERN_INFO "%s: i2c scan beginning\n", hdw->name);
        for (i = 0; i < 128; i++) {
-               msg[0].addr = i;
-               rc = i2c_transfer(&hdw->i2c_adap,msg, ARRAY_SIZE(msg));
-               if (rc != 1) continue;
-               printk("%s: i2c scan: found device @ 0x%x\n",hdw->name,i);
+               if (do_i2c_probe(hdw, i)) {
+                       printk(KERN_INFO "%s: i2c scan: found device @ 0x%x\n",
+                              hdw->name, i);
+               }
        }
-       printk("%s: i2c scan done.\n",hdw->name);
+       printk(KERN_INFO "%s: i2c scan done.\n", hdw->name);
 }
 
 void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
@@ -980,8 +992,6 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
                hdw->i2c_func[0x18] = i2c_black_hole;
        } else if (ir_mode[hdw->unit_number] == 1) {
                if (hdw->hdw_desc->ir_scheme == PVR2_IR_SCHEME_24XXX) {
-                       /* This comment is present PURELY to get
-                          checkpatch.pl to STFU.  Lovely, eh? */
                        hdw->i2c_func[0x18] = i2c_24xxx_ir;
                }
        }
@@ -1006,6 +1016,16 @@ void pvr2_i2c_core_init(struct pvr2_hdw *hdw)
        mutex_init(&hdw->i2c_list_lock);
        hdw->i2c_linked = !0;
        i2c_add_adapter(&hdw->i2c_adap);
+       if (hdw->i2c_func[0x18] == i2c_24xxx_ir) {
+               /* Probe for a different type of IR receiver on this
+                  device.  If present, disable the emulated IR receiver. */
+               if (do_i2c_probe(hdw, 0x71)) {
+                       pvr2_trace(PVR2_TRACE_INFO,
+                                  "Device has newer IR hardware;"
+                                  " disabling unneeded virtual IR device");
+                       hdw->i2c_func[0x18] = NULL;
+               }
+       }
        if (i2c_scan) do_i2c_scan(hdw);
 }
 
index ad0d98c2ebb4165ab34ef638f7786bd89463a30e..9b3c874d96d612c18bc07a9e72fb88f2fb78caad 100644 (file)
@@ -137,9 +137,11 @@ static int __init pvr_init(void)
        ret = usb_register(&pvr_driver);
 
        if (ret == 0)
-               info(DRIVER_DESC " : " DRIVER_VERSION);
-       if (pvrusb2_debug) info("Debug mask is %d (0x%x)",
-                               pvrusb2_debug,pvrusb2_debug);
+               printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+                      DRIVER_DESC "\n");
+       if (pvrusb2_debug)
+               printk(KERN_INFO KBUILD_MODNAME ": Debug mask is %d (0x%x)\n",
+                      pvrusb2_debug,pvrusb2_debug);
 
        pvr2_trace(PVR2_TRACE_INIT,"pvr_init complete");
 
index 46a8c39ba03028fc07ecd7392d2fd44522779869..733680f2131714a7f1642cf0f36655f28695b024 100644 (file)
@@ -65,6 +65,7 @@ struct pvr2_sysfs_ctl_item {
        struct device_attribute attr_type;
        struct device_attribute attr_min;
        struct device_attribute attr_max;
+       struct device_attribute attr_def;
        struct device_attribute attr_enum;
        struct device_attribute attr_bits;
        struct device_attribute attr_val;
@@ -145,6 +146,23 @@ static ssize_t show_max(struct device *class_dev,
        return scnprintf(buf, PAGE_SIZE, "%ld\n", val);
 }
 
+static ssize_t show_def(struct device *class_dev,
+                       struct device_attribute *attr,
+                       char *buf)
+{
+       struct pvr2_sysfs_ctl_item *cip;
+       int val;
+       int ret;
+       cip = container_of(attr, struct pvr2_sysfs_ctl_item, attr_def);
+       ret = pvr2_ctrl_get_def(cip->cptr, &val);
+       pvr2_sysfs_trace("pvr2_sysfs(%p) show_def(cid=%d) is %d, stat=%d",
+                        cip->chptr, cip->ctl_id, val, ret);
+       if (ret < 0) {
+               return ret;
+       }
+       return scnprintf(buf, PAGE_SIZE, "%d\n", val);
+}
+
 static ssize_t show_val_norm(struct device *class_dev,
                             struct device_attribute *attr,
                             char *buf)
@@ -320,6 +338,10 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
        cip->attr_max.attr.mode = S_IRUGO;
        cip->attr_max.show = show_max;
 
+       cip->attr_def.attr.name = "def_val";
+       cip->attr_def.attr.mode = S_IRUGO;
+       cip->attr_def.show = show_def;
+
        cip->attr_val.attr.name = "cur_val";
        cip->attr_val.attr.mode = S_IRUGO;
 
@@ -343,6 +365,7 @@ static void pvr2_sysfs_add_control(struct pvr2_sysfs *sfp,int ctl_id)
        cip->attr_gen[acnt++] = &cip->attr_name.attr;
        cip->attr_gen[acnt++] = &cip->attr_type.attr;
        cip->attr_gen[acnt++] = &cip->attr_val.attr;
+       cip->attr_gen[acnt++] = &cip->attr_def.attr;
        cip->attr_val.show = show_val_norm;
        cip->attr_val.store = store_val_norm;
        if (pvr2_ctrl_has_custom_symbols(cptr)) {
index 00306faeac015f1ab9a99c8aaf32b894032bc444..f048d80b77e58b8e7e5e05ff9c2fec798929e135 100644 (file)
@@ -533,7 +533,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
 
                        lmin = pvr2_ctrl_get_min(hcp);
                        lmax = pvr2_ctrl_get_max(hcp);
-                       ldef = pvr2_ctrl_get_def(hcp);
+                       pvr2_ctrl_get_def(hcp, &ldef);
                        if (w == -1) {
                                w = ldef;
                        } else if (w < lmin) {
@@ -543,7 +543,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                        }
                        lmin = pvr2_ctrl_get_min(vcp);
                        lmax = pvr2_ctrl_get_max(vcp);
-                       ldef = pvr2_ctrl_get_def(vcp);
+                       pvr2_ctrl_get_def(vcp, &ldef);
                        if (h == -1) {
                                h = ldef;
                        } else if (h < lmin) {
@@ -604,6 +604,7 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
        case VIDIOC_QUERYCTRL:
        {
                struct pvr2_ctrl *cptr;
+               int val;
                struct v4l2_queryctrl *vc = (struct v4l2_queryctrl *)arg;
                ret = 0;
                if (vc->id & V4L2_CTRL_FLAG_NEXT_CTRL) {
@@ -627,7 +628,8 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                           pvr2_ctrl_get_desc(cptr));
                strlcpy(vc->name,pvr2_ctrl_get_desc(cptr),sizeof(vc->name));
                vc->flags = pvr2_ctrl_get_v4lflags(cptr);
-               vc->default_value = pvr2_ctrl_get_def(cptr);
+               pvr2_ctrl_get_def(cptr, &val);
+               vc->default_value = val;
                switch (pvr2_ctrl_get_type(cptr)) {
                case pvr2_ctl_enum:
                        vc->type = V4L2_CTRL_TYPE_MENU;
@@ -753,6 +755,92 @@ static int pvr2_v4l2_do_ioctl(struct inode *inode, struct file *file,
                break;
        }
 
+       case VIDIOC_CROPCAP:
+       {
+               struct v4l2_cropcap *cap = (struct v4l2_cropcap *)arg;
+               if (cap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_hdw_get_cropcap(hdw, cap);
+               cap->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; /* paranoia */
+               break;
+       }
+       case VIDIOC_G_CROP:
+       {
+               struct v4l2_crop *crop = (struct v4l2_crop *)arg;
+               int val = 0;
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.left = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.top = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.width = val;
+               ret = pvr2_ctrl_get_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH), &val);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               crop->c.height = val;
+       }
+       case VIDIOC_S_CROP:
+       {
+               struct v4l2_crop *crop = (struct v4l2_crop *)arg;
+               struct v4l2_cropcap cap;
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                       ret = -EINVAL;
+                       break;
+               }
+               cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPL),
+                       crop->c.left);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPT),
+                       crop->c.top);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPW),
+                       crop->c.width);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+               ret = pvr2_ctrl_set_value(
+                       pvr2_hdw_get_ctrl_by_id(hdw, PVR2_CID_CROPH),
+                       crop->c.height);
+               if (ret != 0) {
+                       ret = -EINVAL;
+                       break;
+               }
+       }
        case VIDIOC_LOG_STATUS:
        {
                pvr2_hdw_trigger_module_log(hdw);
index dbc560742553ec98b3c5aa2e487f0e2e05d232a5..c6653021019224c697053b869d62a656333a89d5 100644 (file)
@@ -41,7 +41,6 @@
 #include <asm/uaccess.h>
 #endif
 #include <asm/errno.h>
-#include <linux/version.h>
 
 #include "pwc.h"
 #include "pwc-uncompress.h"
index 9aee7cb6f79a9e310e57021ac7d50a1fb73d0dc9..ab28389b4cdadf17d0e28282dd6c186237c2fe14 100644 (file)
@@ -1112,7 +1112,7 @@ static int pwc_video_open(struct inode *inode, struct file *file)
 
        PWC_DEBUG_OPEN(">> video_open called(vdev = 0x%p).\n", vdev);
 
-       pdev = (struct pwc_device *)vdev->priv;
+       pdev = video_get_drvdata(vdev);
        BUG_ON(!pdev);
        if (pdev->vopen) {
                PWC_DEBUG_OPEN("I'm busy, someone is using the device.\n");
@@ -1233,7 +1233,7 @@ static int pwc_video_close(struct inode *inode, struct file *file)
        PWC_DEBUG_OPEN(">> video_close called(vdev = 0x%p).\n", vdev);
 
        lock_kernel();
-       pdev = (struct pwc_device *)vdev->priv;
+       pdev = video_get_drvdata(vdev);
        if (pdev->vopen == 0)
                PWC_DEBUG_MODULE("video_close() called on closed device?\n");
 
@@ -1304,7 +1304,7 @@ static ssize_t pwc_video_read(struct file *file, char __user *buf,
                        vdev, buf, count);
        if (vdev == NULL)
                return -EFAULT;
-       pdev = vdev->priv;
+       pdev = video_get_drvdata(vdev);
        if (pdev == NULL)
                return -EFAULT;
 
@@ -1386,7 +1386,7 @@ static unsigned int pwc_video_poll(struct file *file, poll_table *wait)
 
        if (vdev == NULL)
                return -EFAULT;
-       pdev = vdev->priv;
+       pdev = video_get_drvdata(vdev);
        if (pdev == NULL)
                return -EFAULT;
 
@@ -1408,7 +1408,7 @@ static int pwc_video_ioctl(struct inode *inode, struct file *file,
 
        if (!vdev)
                goto out;
-       pdev = vdev->priv;
+       pdev = video_get_drvdata(vdev);
 
        mutex_lock(&pdev->modlock);
        if (!pdev->unplugged)
@@ -1428,7 +1428,7 @@ static int pwc_video_mmap(struct file *file, struct vm_area_struct *vma)
        int index;
 
        PWC_DEBUG_MEMORY(">> %s\n", __func__);
-       pdev = vdev->priv;
+       pdev = video_get_drvdata(vdev);
        size = vma->vm_end - vma->vm_start;
        start = vma->vm_start;
 
index 1742889874df08c6f944b4b066fa1111fcff2e4a..76a1376c9751dd1c06acacc766af6676a36efe40 100644 (file)
@@ -346,7 +346,7 @@ int pwc_video_do_ioctl(struct inode *inode, struct file *file,
 
        if (vdev == NULL)
                return -EFAULT;
-       pdev = vdev->priv;
+       pdev = video_get_drvdata(vdev);
        if (pdev == NULL)
                return -EFAULT;
 
index cf96b2cc4f1c4b70f59ef279ad8cfee8b4535f1a..eb6be580292899ed8a6b5d0fa41b204f52d9f07d 100644 (file)
@@ -629,17 +629,6 @@ static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
                pdata->init(pcdev->dev);
        }
 
-       if (pdata && pdata->power) {
-               dev_dbg(pcdev->dev, "%s: Power on camera\n", __func__);
-               pdata->power(pcdev->dev, 1);
-       }
-
-       if (pdata && pdata->reset) {
-               dev_dbg(pcdev->dev, "%s: Releasing camera reset\n",
-                       __func__);
-               pdata->reset(pcdev->dev, 1);
-       }
-
        CICR0 = 0x3FF;   /* disable all interrupts */
 
        if (pcdev->platform_flags & PXA_CAMERA_PCLK_EN)
@@ -660,20 +649,7 @@ static void pxa_camera_activate(struct pxa_camera_dev *pcdev)
 
 static void pxa_camera_deactivate(struct pxa_camera_dev *pcdev)
 {
-       struct pxacamera_platform_data *board = pcdev->pdata;
-
        clk_disable(pcdev->clk);
-
-       if (board && board->reset) {
-               dev_dbg(pcdev->dev, "%s: Asserting camera reset\n",
-                       __func__);
-               board->reset(pcdev->dev, 0);
-       }
-
-       if (board && board->power) {
-               dev_dbg(pcdev->dev, "%s: Power off camera\n", __func__);
-               board->power(pcdev->dev, 0);
-       }
 }
 
 static irqreturn_t pxa_camera_irq(int irq, void *data)
@@ -1144,31 +1120,31 @@ static int pxa_camera_probe(struct platform_device *pdev)
        pcdev->dev = &pdev->dev;
 
        /* request dma */
-       pcdev->dma_chans[0] = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
-                                             pxa_camera_dma_irq_y, pcdev);
-       if (pcdev->dma_chans[0] < 0) {
+       err = pxa_request_dma("CI_Y", DMA_PRIO_HIGH,
+                             pxa_camera_dma_irq_y, pcdev);
+       if (err < 0) {
                dev_err(pcdev->dev, "Can't request DMA for Y\n");
-               err = -ENOMEM;
                goto exit_iounmap;
        }
+       pcdev->dma_chans[0] = err;
        dev_dbg(pcdev->dev, "got DMA channel %d\n", pcdev->dma_chans[0]);
 
-       pcdev->dma_chans[1] = pxa_request_dma("CI_U", DMA_PRIO_HIGH,
-                                             pxa_camera_dma_irq_u, pcdev);
-       if (pcdev->dma_chans[1] < 0) {
+       err = pxa_request_dma("CI_U", DMA_PRIO_HIGH,
+                             pxa_camera_dma_irq_u, pcdev);
+       if (err < 0) {
                dev_err(pcdev->dev, "Can't request DMA for U\n");
-               err = -ENOMEM;
                goto exit_free_dma_y;
        }
+       pcdev->dma_chans[1] = err;
        dev_dbg(pcdev->dev, "got DMA channel (U) %d\n", pcdev->dma_chans[1]);
 
-       pcdev->dma_chans[2] = pxa_request_dma("CI_V", DMA_PRIO_HIGH,
-                                             pxa_camera_dma_irq_v, pcdev);
-       if (pcdev->dma_chans[0] < 0) {
+       err = pxa_request_dma("CI_V", DMA_PRIO_HIGH,
+                             pxa_camera_dma_irq_v, pcdev);
+       if (err < 0) {
                dev_err(pcdev->dev, "Can't request DMA for V\n");
-               err = -ENOMEM;
                goto exit_free_dma_u;
        }
+       pcdev->dma_chans[2] = err;
        dev_dbg(pcdev->dev, "got DMA channel (V) %d\n", pcdev->dma_chans[2]);
 
        DRCMR(68) = pcdev->dma_chans[0] | DRCMR_MAPVLD;
index 92b83feae3668d2bca19f32a956962c2107de7f7..5272926db73e93763f21aaf8ecc746fbb88f93f9 100644 (file)
@@ -58,6 +58,8 @@
 
 
 
+/* default JPEG quality */
+#define S2255_DEF_JPEG_QUAL     50
 /* vendor request in */
 #define S2255_VR_IN            0
 /* vendor request out */
 /* USB endpoint number for configuring the device */
 #define S2255_CONFIG_EP         2
 /* maximum time for DSP to start responding after last FW word loaded(ms) */
-#define S2255_DSP_BOOTTIME      400
+#define S2255_DSP_BOOTTIME      800
 /* maximum time to wait for firmware to load (ms) */
 #define S2255_LOAD_TIMEOUT      (5000 + S2255_DSP_BOOTTIME)
 #define S2255_DEF_BUFS          16
+#define S2255_SETMODE_TIMEOUT   500
 #define MAX_CHANNELS           4
-#define FRAME_MARKER           0x2255DA4AL
-#define MAX_PIPE_USBBLOCK      (40 * 1024)
-#define DEFAULT_PIPE_USBBLOCK  (16 * 1024)
+#define S2255_MARKER_FRAME     0x2255DA4AL
+#define S2255_MARKER_RESPONSE  0x2255ACACL
+#define S2255_USB_XFER_SIZE    (16 * 1024)
 #define MAX_CHANNELS           4
 #define MAX_PIPE_BUFFERS       1
 #define SYS_FRAMES             4
 /* maximum size is PAL full size plus room for the marker header(s) */
-#define SYS_FRAMES_MAXSIZE     (720 * 288 * 2 * 2 + 4096)
-#define DEF_USB_BLOCK          (4096)
+#define SYS_FRAMES_MAXSIZE     (720*288*2*2 + 4096)
+#define DEF_USB_BLOCK          S2255_USB_XFER_SIZE
 #define LINE_SZ_4CIFS_NTSC     640
 #define LINE_SZ_2CIFS_NTSC     640
 #define LINE_SZ_1CIFS_NTSC     320
 #define COLOR_YUVPL    1       /* YUV planar */
 #define COLOR_YUVPK    2       /* YUV packed */
 #define COLOR_Y8       4       /* monochrome */
+#define COLOR_JPG       5       /* JPEG */
+#define MASK_COLOR      0xff
+#define MASK_JPG_QUALITY 0xff00
 
 /* frame decimation. Not implemented by V4L yet(experimental in V4L) */
 #define FDEC_1         1       /* capture every frame. default */
@@ -148,16 +154,14 @@ struct s2255_mode {
        u32 restart;    /* if DSP requires restart */
 };
 
-/* frame structure */
-#define FRAME_STATE_UNUSED     0
-#define FRAME_STATE_FILLING    1
-#define FRAME_STATE_FULL       2
 
+#define S2255_READ_IDLE                0
+#define S2255_READ_FRAME       1
 
+/* frame structure */
 struct s2255_framei {
        unsigned long size;
-
-       unsigned long ulState;  /* ulState ==0 unused, 1 being filled, 2 full */
+       unsigned long ulState;  /* ulState:S2255_READ_IDLE, S2255_READ_FRAME*/
        void *lpvbits;          /* image data */
        unsigned long cur_size; /* current data copied to it */
 };
@@ -188,6 +192,10 @@ struct s2255_dmaqueue {
 #define S2255_FW_FAILED                3
 #define S2255_FW_DISCONNECTING  4
 
+#define S2255_FW_MARKER         0x22552f2f
+/* 2255 read states */
+#define S2255_READ_IDLE         0
+#define S2255_READ_FRAME        1
 struct s2255_fw {
        int                   fw_loaded;
        int                   fw_size;
@@ -195,7 +203,6 @@ struct s2255_fw {
        atomic_t              fw_state;
        void                  *pfw_data;
        wait_queue_head_t     wait_fw;
-       struct timer_list     dsp_wait;
        const struct firmware *fw;
 };
 
@@ -237,15 +244,27 @@ struct s2255_dev {
        struct s2255_pipeinfo   pipes[MAX_PIPE_BUFFERS];
        struct s2255_bufferi            buffer[MAX_CHANNELS];
        struct s2255_mode       mode[MAX_CHANNELS];
+       /* jpeg compression */
+       struct v4l2_jpegcompression jc[MAX_CHANNELS];
        const struct s2255_fmt  *cur_fmt[MAX_CHANNELS];
        int                     cur_frame[MAX_CHANNELS];
        int                     last_frame[MAX_CHANNELS];
        u32                     cc;     /* current channel */
        int                     b_acquire[MAX_CHANNELS];
+       /* allocated image size */
        unsigned long           req_image_size[MAX_CHANNELS];
+       /* received packet size */
+       unsigned long           pkt_size[MAX_CHANNELS];
        int                     bad_payload[MAX_CHANNELS];
        unsigned long           frame_count[MAX_CHANNELS];
        int                     frame_ready;
+       /* if JPEG image */
+       int                     jpg_size[MAX_CHANNELS];
+       /* if channel configured to default state */
+       int                     chn_configured[MAX_CHANNELS];
+       wait_queue_head_t       wait_setmode[MAX_CHANNELS];
+       int                     setmode_ready[MAX_CHANNELS];
+       int                     chn_ready;
        struct kref             kref;
        spinlock_t              slock;
 };
@@ -306,12 +325,16 @@ static void s2255_stop_readpipe(struct s2255_dev *dev);
 static int s2255_start_acquire(struct s2255_dev *dev, unsigned long chn);
 static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn);
 static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
-                          int chn);
+                          int chn, int jpgsize);
 static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
                          struct s2255_mode *mode);
 static int s2255_board_shutdown(struct s2255_dev *dev);
 static void s2255_exit_v4l(struct s2255_dev *dev);
-static void s2255_fwload_start(struct s2255_dev *dev);
+static void s2255_fwload_start(struct s2255_dev *dev, int reset);
+static void s2255_destroy(struct kref *kref);
+static long s2255_vendor_req(struct s2255_dev *dev, unsigned char req,
+                            u16 index, u16 value, void *buf,
+                            s32 buf_len, int bOut);
 
 #define dprintk(level, fmt, arg...)                                    \
        do {                                                            \
@@ -406,6 +429,10 @@ static const struct s2255_fmt formats[] = {
                .name = "4:2:2, packed, UYVY",
                .fourcc = V4L2_PIX_FMT_UYVY,
                .depth = 16
+       }, {
+               .name = "JPG",
+               .fourcc = V4L2_PIX_FMT_JPEG,
+               .depth = 24
        }, {
                .name = "8bpp GREY",
                .fourcc = V4L2_PIX_FMT_GREY,
@@ -464,6 +491,13 @@ static void planar422p_to_yuv_packed(const unsigned char *in,
        return;
 }
 
+static void s2255_reset_dsppower(struct s2255_dev *dev)
+{
+       s2255_vendor_req(dev, 0x40, 0x0b0b, 0x0b0b, NULL, 0, 1);
+       msleep(10);
+       s2255_vendor_req(dev, 0x50, 0x0000, 0x0000, NULL, 0, 1);
+       return;
+}
 
 /* kickstarts the firmware loading. from probe
  */
@@ -480,18 +514,6 @@ static void s2255_timer(unsigned long user_data)
        }
 }
 
-/* called when DSP is up and running.  DSP is guaranteed to
-   be running after S2255_DSP_BOOTTIME */
-static void s2255_dsp_running(unsigned long user_data)
-{
-       struct s2255_fw *data = (struct s2255_fw *)user_data;
-       dprintk(1, "dsp running\n");
-       atomic_set(&data->fw_state, S2255_FW_SUCCESS);
-       wake_up(&data->wait_fw);
-       printk(KERN_INFO "s2255: firmware loaded successfully\n");
-       return;
-}
-
 
 /* this loads the firmware asynchronously.
    Originally this was done synchroously in probe.
@@ -549,19 +571,14 @@ static void s2255_fwchunk_complete(struct urb *urb)
                }
                data->fw_loaded += len;
        } else {
-               init_timer(&data->dsp_wait);
-               data->dsp_wait.function = s2255_dsp_running;
-               data->dsp_wait.data = (unsigned long)data;
                atomic_set(&data->fw_state, S2255_FW_LOADED_DSPWAIT);
-               mod_timer(&data->dsp_wait, msecs_to_jiffies(S2255_DSP_BOOTTIME)
-                         + jiffies);
        }
        dprintk(100, "2255 complete done\n");
        return;
 
 }
 
-static int s2255_got_frame(struct s2255_dev *dev, int chn)
+static int s2255_got_frame(struct s2255_dev *dev, int chn, int jpgsize)
 {
        struct s2255_dmaqueue *dma_q = &dev->vidq[chn];
        struct s2255_buffer *buf;
@@ -586,8 +603,7 @@ static int s2255_got_frame(struct s2255_dev *dev, int chn)
        list_del(&buf->vb.queue);
        do_gettimeofday(&buf->vb.ts);
        dprintk(100, "[%p/%d] wakeup\n", buf, buf->vb.i);
-
-       s2255_fillbuff(dev, buf, dma_q->channel);
+       s2255_fillbuff(dev, buf, dma_q->channel, jpgsize);
        wake_up(&buf->vb.done);
        dprintk(2, "wakeup [buf/i] [%p/%d]\n", buf, buf->vb.i);
 unlock:
@@ -621,7 +637,7 @@ static const struct s2255_fmt *format_by_fourcc(int fourcc)
  *
  */
 static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
-                          int chn)
+                          int chn, int jpgsize)
 {
        int pos = 0;
        struct timeval ts;
@@ -649,6 +665,10 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
                case V4L2_PIX_FMT_GREY:
                        memcpy(vbuf, tmpbuf, buf->vb.width * buf->vb.height);
                        break;
+               case V4L2_PIX_FMT_JPEG:
+                       buf->vb.size = jpgsize;
+                       memcpy(vbuf, tmpbuf, buf->vb.size);
+                       break;
                case V4L2_PIX_FMT_YUV422P:
                        memcpy(vbuf, tmpbuf,
                               buf->vb.width * buf->vb.height * 2);
@@ -657,9 +677,6 @@ static void s2255_fillbuff(struct s2255_dev *dev, struct s2255_buffer *buf,
                        printk(KERN_DEBUG "s2255: unknown format?\n");
                }
                dev->last_frame[chn] = -1;
-               /* done with the frame, free it */
-               frm->ulState = 0;
-               dprintk(4, "freeing buffer\n");
        } else {
                printk(KERN_ERR "s2255: =======no frame\n");
                return;
@@ -1021,6 +1038,10 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
        case V4L2_PIX_FMT_GREY:
                fh->mode.color = COLOR_Y8;
                break;
+       case V4L2_PIX_FMT_JPEG:
+               fh->mode.color = COLOR_JPG |
+                       (fh->dev->jc[fh->channel].quality << 8);
+               break;
        case V4L2_PIX_FMT_YUV422P:
                fh->mode.color = COLOR_YUVPL;
                break;
@@ -1139,7 +1160,7 @@ static u32 get_transfer_size(struct s2255_mode *mode)
                }
        }
        outImageSize = linesPerFrame * pixelsPerLine;
-       if (mode->color != COLOR_Y8) {
+       if ((mode->color & MASK_COLOR) != COLOR_Y8) {
                /* 2 bytes/pixel if not monochrome */
                outImageSize *= 2;
        }
@@ -1185,12 +1206,17 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
        u32 *buffer;
        unsigned long chn_rev;
 
+       mutex_lock(&dev->lock);
        chn_rev = G_chnmap[chn];
        dprintk(3, "mode scale [%ld] %p %d\n", chn, mode, mode->scale);
        dprintk(3, "mode scale [%ld] %p %d\n", chn, &dev->mode[chn],
                dev->mode[chn].scale);
        dprintk(2, "mode contrast %x\n", mode->contrast);
 
+       /* if JPEG, set the quality */
+       if ((mode->color & MASK_COLOR) == COLOR_JPG)
+               mode->color = (dev->jc[chn].quality << 8) | COLOR_JPG;
+
        /* save the mode */
        dev->mode[chn] = *mode;
        dev->req_image_size[chn] = get_transfer_size(mode);
@@ -1199,6 +1225,7 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
        buffer = kzalloc(512, GFP_KERNEL);
        if (buffer == NULL) {
                dev_err(&dev->udev->dev, "out of mem\n");
+               mutex_unlock(&dev->lock);
                return -ENOMEM;
        }
 
@@ -1214,12 +1241,20 @@ static int s2255_set_mode(struct s2255_dev *dev, unsigned long chn,
        dprintk(1, "set mode done chn %lu, %d\n", chn, res);
 
        /* wait at least 3 frames before continuing */
-       if (mode->restart)
-               msleep(125);
+       if (mode->restart) {
+               dev->setmode_ready[chn] = 0;
+               wait_event_timeout(dev->wait_setmode[chn],
+                                  (dev->setmode_ready[chn] != 0),
+                                  msecs_to_jiffies(S2255_SETMODE_TIMEOUT));
+               if (dev->setmode_ready[chn] != 1) {
+                       printk(KERN_DEBUG "s2255: no set mode response\n");
+                       res = -EFAULT;
+               }
+       }
 
        /* clear the restart flag */
        dev->mode[chn].restart = 0;
-
+       mutex_unlock(&dev->lock);
        return res;
 }
 
@@ -1270,7 +1305,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
        dev->cur_frame[chn] = 0;
        dev->frame_count[chn] = 0;
        for (j = 0; j < SYS_FRAMES; j++) {
-               dev->buffer[chn].frame[j].ulState = 0;
+               dev->buffer[chn].frame[j].ulState = S2255_READ_IDLE;
                dev->buffer[chn].frame[j].cur_size = 0;
        }
        res = videobuf_streamon(&fh->vb_vidq);
@@ -1446,6 +1481,27 @@ static int vidioc_s_ctrl(struct file *file, void *priv,
        return -EINVAL;
 }
 
+static int vidioc_g_jpegcomp(struct file *file, void *priv,
+                        struct v4l2_jpegcompression *jc)
+{
+       struct s2255_fh *fh = priv;
+       struct s2255_dev *dev = fh->dev;
+       *jc = dev->jc[fh->channel];
+       dprintk(2, "getting jpegcompression, quality %d\n", jc->quality);
+       return 0;
+}
+
+static int vidioc_s_jpegcomp(struct file *file, void *priv,
+                        struct v4l2_jpegcompression *jc)
+{
+       struct s2255_fh *fh = priv;
+       struct s2255_dev *dev = fh->dev;
+       if (jc->quality < 0 || jc->quality > 100)
+               return -EINVAL;
+       dev->jc[fh->channel].quality = jc->quality;
+       dprintk(2, "setting jpeg quality %d\n", jc->quality);
+       return 0;
+}
 static int s2255_open(struct inode *inode, struct file *file)
 {
        int minor = iminor(inode);
@@ -1455,8 +1511,10 @@ static int s2255_open(struct inode *inode, struct file *file)
        enum v4l2_buf_type type = 0;
        int i = 0;
        int cur_channel = -1;
+       int state;
        dprintk(1, "s2255: open called (minor=%d)\n", minor);
 
+       lock_kernel();
        list_for_each(list, &s2255_devlist) {
                h = list_entry(list, struct s2255_dev, s2255_devlist);
                for (i = 0; i < MAX_CHANNELS; i++) {
@@ -1469,45 +1527,78 @@ static int s2255_open(struct inode *inode, struct file *file)
        }
 
        if ((NULL == dev) || (cur_channel == -1)) {
-               dprintk(1, "s2255: openv4l no dev\n");
+               unlock_kernel();
+               printk(KERN_INFO "s2255: openv4l no dev\n");
                return -ENODEV;
        }
 
+       if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_DISCONNECTING) {
+               unlock_kernel();
+               printk(KERN_INFO "disconnecting\n");
+               return -ENODEV;
+       }
+       kref_get(&dev->kref);
        mutex_lock(&dev->open_lock);
 
        dev->users[cur_channel]++;
        dprintk(4, "s2255: open_handles %d\n", dev->users[cur_channel]);
 
-       if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_FAILED) {
+       switch (atomic_read(&dev->fw_data->fw_state)) {
+       case S2255_FW_FAILED:
                err("2255 firmware load failed. retrying.\n");
-               s2255_fwload_start(dev);
+               s2255_fwload_start(dev, 1);
                wait_event_timeout(dev->fw_data->wait_fw,
-                                  (atomic_read(&dev->fw_data->fw_state)
-                                   != S2255_FW_NOTLOADED),
+                                  ((atomic_read(&dev->fw_data->fw_state)
+                                    == S2255_FW_SUCCESS) ||
+                                   (atomic_read(&dev->fw_data->fw_state)
+                                    == S2255_FW_DISCONNECTING)),
                                   msecs_to_jiffies(S2255_LOAD_TIMEOUT));
-               if (atomic_read(&dev->fw_data->fw_state)
-                   != S2255_FW_SUCCESS) {
-                       printk(KERN_INFO "2255 FW load failed.\n");
-                       dev->users[cur_channel]--;
-                       mutex_unlock(&dev->open_lock);
-                       return -EFAULT;
-               }
-       } else if (atomic_read(&dev->fw_data->fw_state) == S2255_FW_NOTLOADED) {
+               break;
+       case S2255_FW_NOTLOADED:
+       case S2255_FW_LOADED_DSPWAIT:
                /* give S2255_LOAD_TIMEOUT time for firmware to load in case
                   driver loaded and then device immediately opened */
                printk(KERN_INFO "%s waiting for firmware load\n", __func__);
                wait_event_timeout(dev->fw_data->wait_fw,
-                                  (atomic_read(&dev->fw_data->fw_state)
-                                  != S2255_FW_NOTLOADED),
-                                  msecs_to_jiffies(S2255_LOAD_TIMEOUT));
-               if (atomic_read(&dev->fw_data->fw_state)
-                   != S2255_FW_SUCCESS) {
-                       printk(KERN_INFO "2255 firmware not loaded"
-                              "try again\n");
-                       dev->users[cur_channel]--;
-                       mutex_unlock(&dev->open_lock);
-                       return -EBUSY;
+                                  ((atomic_read(&dev->fw_data->fw_state)
+                                    == S2255_FW_SUCCESS) ||
+                                   (atomic_read(&dev->fw_data->fw_state)
+                                    == S2255_FW_DISCONNECTING)),
+                       msecs_to_jiffies(S2255_LOAD_TIMEOUT));
+               break;
+       case S2255_FW_SUCCESS:
+       default:
+               break;
+       }
+       state = atomic_read(&dev->fw_data->fw_state);
+       if (state != S2255_FW_SUCCESS) {
+               int rc;
+               switch (state) {
+               case S2255_FW_FAILED:
+                       printk(KERN_INFO "2255 FW load failed. %d\n", state);
+                       rc = -ENODEV;
+                       break;
+               case S2255_FW_DISCONNECTING:
+                       printk(KERN_INFO "%s: disconnecting\n", __func__);
+                       rc = -ENODEV;
+                       break;
+               case S2255_FW_LOADED_DSPWAIT:
+               case S2255_FW_NOTLOADED:
+                       printk(KERN_INFO "%s: firmware not loaded yet"
+                              "please try again later\n",
+                              __func__);
+                       rc = -EAGAIN;
+                       break;
+               default:
+                       printk(KERN_INFO "%s: unknown state\n", __func__);
+                       rc = -EFAULT;
+                       break;
                }
+               dev->users[cur_channel]--;
+               mutex_unlock(&dev->open_lock);
+               kref_put(&dev->kref, s2255_destroy);
+               unlock_kernel();
+               return rc;
        }
 
        /* allocate + initialize per filehandle data */
@@ -1515,6 +1606,8 @@ static int s2255_open(struct inode *inode, struct file *file)
        if (NULL == fh) {
                dev->users[cur_channel]--;
                mutex_unlock(&dev->open_lock);
+               kref_put(&dev->kref, s2255_destroy);
+               unlock_kernel();
                return -ENOMEM;
        }
 
@@ -1528,6 +1621,13 @@ static int s2255_open(struct inode *inode, struct file *file)
        fh->height = NUM_LINES_4CIFS_NTSC * 2;
        fh->channel = cur_channel;
 
+       /* configure channel to default state */
+       if (!dev->chn_configured[cur_channel]) {
+               s2255_set_mode(dev, cur_channel, &fh->mode);
+               dev->chn_configured[cur_channel] = 1;
+       }
+
+
        /* Put all controls at a sane state */
        for (i = 0; i < ARRAY_SIZE(s2255_qctrl); i++)
                qctl_regs[i] = s2255_qctrl[i].default_value;
@@ -1546,8 +1646,8 @@ static int s2255_open(struct inode *inode, struct file *file)
                                    V4L2_FIELD_INTERLACED,
                                    sizeof(struct s2255_buffer), fh);
 
-       kref_get(&dev->kref);
        mutex_unlock(&dev->open_lock);
+       unlock_kernel();
        return 0;
 }
 
@@ -1569,30 +1669,24 @@ static unsigned int s2255_poll(struct file *file,
 static void s2255_destroy(struct kref *kref)
 {
        struct s2255_dev *dev = to_s2255_dev(kref);
+       struct list_head *list;
+       int i;
        if (!dev) {
                printk(KERN_ERR "s2255drv: kref problem\n");
                return;
        }
-
-       /*
-        * Wake up any firmware load waiting (only done in .open,
-        * which holds the open_lock mutex)
-        */
        atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
        wake_up(&dev->fw_data->wait_fw);
-
-       /* prevent s2255_disconnect from racing s2255_open */
+       for (i = 0; i < MAX_CHANNELS; i++) {
+               dev->setmode_ready[i] = 1;
+               wake_up(&dev->wait_setmode[i]);
+       }
        mutex_lock(&dev->open_lock);
+       /* reset the DSP so firmware can be reload next time */
+       s2255_reset_dsppower(dev);
        s2255_exit_v4l(dev);
-       /*
-        * device unregistered so no longer possible to open. open_mutex
-        *  can be unlocked and timers deleted afterwards.
-        */
-       mutex_unlock(&dev->open_lock);
-
        /* board shutdown stops the read pipe if it is running */
        s2255_board_shutdown(dev);
-
        /* make sure firmware still not trying to load */
        del_timer(&dev->timer);  /* only started in .probe and .open */
 
@@ -1602,23 +1696,19 @@ static void s2255_destroy(struct kref *kref)
                usb_free_urb(dev->fw_data->fw_urb);
                dev->fw_data->fw_urb = NULL;
        }
-
-       /*
-        * delete the dsp_wait timer, which sets the firmware
-        * state on completion.  This is done before fw_data
-        * is freed below.
-        */
-
-       del_timer(&dev->fw_data->dsp_wait); /* only started in .open */
-
        if (dev->fw_data->fw)
                release_firmware(dev->fw_data->fw);
        kfree(dev->fw_data->pfw_data);
        kfree(dev->fw_data);
-
        usb_put_dev(dev->udev);
        dprintk(1, "%s", __func__);
        kfree(dev);
+
+       while (!list_empty(&s2255_devlist)) {
+               list = s2255_devlist.next;
+               list_del(list);
+       }
+       mutex_unlock(&dev->open_lock);
 }
 
 static int s2255_close(struct inode *inode, struct file *file)
@@ -1702,6 +1792,8 @@ static const struct v4l2_ioctl_ops s2255_ioctl_ops = {
 #ifdef CONFIG_VIDEO_V4L1_COMPAT
        .vidiocgmbuf = vidioc_cgmbuf,
 #endif
+       .vidioc_s_jpegcomp = vidioc_s_jpegcomp,
+       .vidioc_g_jpegcomp = vidioc_g_jpegcomp,
 };
 
 static struct video_device template = {
@@ -1740,7 +1832,7 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
                        ret = video_register_device(dev->vdev[i],
                                                    VFL_TYPE_GRABBER,
                                                    cur_nr + i);
-               dev->vdev[i]->priv = dev;
+               video_set_drvdata(dev->vdev[i], dev);
 
                if (ret != 0) {
                        dev_err(&dev->udev->dev,
@@ -1754,18 +1846,16 @@ static int s2255_probe_v4l(struct s2255_dev *dev)
 
 static void s2255_exit_v4l(struct s2255_dev *dev)
 {
-       struct list_head *list;
+
        int i;
-       /* unregister the video devices */
-       while (!list_empty(&s2255_devlist)) {
-               list = s2255_devlist.next;
-               list_del(list);
-       }
        for (i = 0; i < MAX_CHANNELS; i++) {
-               if (-1 != dev->vdev[i]->minor)
+               if (-1 != dev->vdev[i]->minor) {
                        video_unregister_device(dev->vdev[i]);
-               else
+                       printk(KERN_INFO "s2255 unregistered\n");
+               } else {
                        video_device_release(dev->vdev[i]);
+                       printk(KERN_INFO "s2255 released\n");
+               }
        }
 }
 
@@ -1775,134 +1865,123 @@ static void s2255_exit_v4l(struct s2255_dev *dev)
  * function again).
  *
  * Received frame structure:
- * bytes 0-3:  marker : 0x2255DA4AL (FRAME_MARKER)
+ * bytes 0-3:  marker : 0x2255DA4AL (S2255_MARKER_FRAME)
  * bytes 4-7:  channel: 0-3
  * bytes 8-11: payload size:  size of the frame
  * bytes 12-payloadsize+12:  frame data
  */
 static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
 {
-       static int dbgsync; /* = 0; */
        char *pdest;
        u32 offset = 0;
-       int bsync = 0;
-       int btrunc = 0;
+       int bframe = 0;
        char *psrc;
        unsigned long copy_size;
        unsigned long size;
        s32 idx = -1;
        struct s2255_framei *frm;
        unsigned char *pdata;
-       unsigned long cur_size;
-       int bsearch = 0;
-       struct s2255_bufferi *buf;
+
        dprintk(100, "buffer to user\n");
 
        idx = dev->cur_frame[dev->cc];
-       buf = &dev->buffer[dev->cc];
-       frm = &buf->frame[idx];
-
-       if (frm->ulState == 0) {
-               frm->ulState = 1;
-               frm->cur_size = 0;
-               bsearch = 1;
-       } else if (frm->ulState == 2) {
-               /* system frame was not freed */
-               dprintk(2, "sys frame not free.  overrun ringbuf\n");
-               bsearch = 1;
-               frm->ulState = 1;
-               frm->cur_size = 0;
-       }
-
-       if (bsearch) {
-               if (*(s32 *) pipe_info->transfer_buffer != FRAME_MARKER) {
-                       u32 jj;
-                       if (dbgsync == 0) {
-                               dprintk(3, "not synched, discarding all packets"
-                                       "until marker\n");
+       frm = &dev->buffer[dev->cc].frame[idx];
 
-                               dbgsync++;
-                       }
-                       pdata = (unsigned char *)pipe_info->transfer_buffer;
-                       for (jj = 0; jj < (pipe_info->cur_transfer_size - 12);
-                            jj++) {
-                               if (*(s32 *) pdata == FRAME_MARKER) {
-                                       int cc;
-                                       dprintk(3,
-                                               "found frame marker at offset:"
-                                               " %d [%x %x]\n", jj, pdata[0],
-                                               pdata[1]);
-                                       offset = jj;
-                                       bsync = 1;
-                                       cc = *(u32 *) (pdata + sizeof(u32));
-                                       if (cc >= MAX_CHANNELS) {
-                                               printk(KERN_ERR
-                                                      "bad channel\n");
-                                               return -EINVAL;
-                                       }
-                                       /* reverse it */
-                                       dev->cc = G_chnmap[cc];
+       if (frm->ulState == S2255_READ_IDLE) {
+               int jj;
+               unsigned int cc;
+               s32 *pdword;
+               int payload;
+               /* search for marker codes */
+               pdata = (unsigned char *)pipe_info->transfer_buffer;
+               for (jj = 0; jj < (pipe_info->cur_transfer_size - 12); jj++) {
+                       switch (*(s32 *) pdata) {
+                       case S2255_MARKER_FRAME:
+                               pdword = (s32 *)pdata;
+                               dprintk(4, "found frame marker at offset:"
+                                       " %d [%x %x]\n", jj, pdata[0],
+                                       pdata[1]);
+                               offset = jj + PREFIX_SIZE;
+                               bframe = 1;
+                               cc = pdword[1];
+                               if (cc >= MAX_CHANNELS) {
+                                       printk(KERN_ERR
+                                              "bad channel\n");
+                                       return -EINVAL;
+                               }
+                               /* reverse it */
+                               dev->cc = G_chnmap[cc];
+                               payload =  pdword[3];
+                               if (payload > dev->req_image_size[dev->cc]) {
+                                       dev->bad_payload[dev->cc]++;
+                                       /* discard the bad frame */
+                                       return -EINVAL;
+                               }
+                               dev->pkt_size[dev->cc] = payload;
+                               dev->jpg_size[dev->cc] = pdword[4];
+                               break;
+                       case S2255_MARKER_RESPONSE:
+                               pdword = (s32 *)pdata;
+                               pdata += DEF_USB_BLOCK;
+                               jj += DEF_USB_BLOCK;
+                               if (pdword[1] >= MAX_CHANNELS)
+                                       break;
+                               cc = G_chnmap[pdword[1]];
+                               if (!(cc >= 0 && cc < MAX_CHANNELS))
+                                       break;
+                               switch (pdword[2]) {
+                               case 0x01:
+                                       /* check if channel valid */
+                                       /* set mode ready */
+                                       dev->setmode_ready[cc] = 1;
+                                       wake_up(&dev->wait_setmode[cc]);
+                                       dprintk(5, "setmode ready %d\n", cc);
                                        break;
+                               case 0x10:
+
+                                       dev->chn_ready |= (1 << cc);
+                                       if ((dev->chn_ready & 0x0f) != 0x0f)
+                                               break;
+                                       /* all channels ready */
+                                       printk(KERN_INFO "s2255: fw loaded\n");
+                                       atomic_set(&dev->fw_data->fw_state,
+                                                  S2255_FW_SUCCESS);
+                                       wake_up(&dev->fw_data->wait_fw);
+                                       break;
+                               default:
+                                       printk(KERN_INFO "s2255 unknwn resp\n");
                                }
+                       default:
                                pdata++;
+                               break;
                        }
-                       if (bsync == 0)
-                               return -EINVAL;
-               } else {
-                       u32 *pword;
-                       u32 payload;
-                       int cc;
-                       dbgsync = 0;
-                       bsync = 1;
-                       pword = (u32 *) pipe_info->transfer_buffer;
-                       cc = pword[1];
-
-                       if (cc >= MAX_CHANNELS) {
-                               printk("invalid channel found. "
-                                       "throwing out data!\n");
-                               return -EINVAL;
-                       }
-                       dev->cc = G_chnmap[cc];
-                       payload = pword[2];
-                       if (payload != dev->req_image_size[dev->cc]) {
-                               dprintk(1, "[%d][%d]unexpected payload: %d"
-                                       "required: %lu \n", cc, dev->cc,
-                                       payload, dev->req_image_size[dev->cc]);
-                               dev->bad_payload[dev->cc]++;
-                               /* discard the bad frame */
-                               return -EINVAL;
-                       }
-
-               }
-       }
-       /* search done.  now find out if should be acquiring
-          on this channel */
-       if (!dev->b_acquire[dev->cc]) {
-               frm->ulState = 0;
-               return -EINVAL;
+                       if (bframe)
+                               break;
+               } /* for */
+               if (!bframe)
+                       return -EINVAL;
        }
 
+
        idx = dev->cur_frame[dev->cc];
        frm = &dev->buffer[dev->cc].frame[idx];
 
-       if (frm->ulState == 0) {
-               frm->ulState = 1;
-               frm->cur_size = 0;
-       } else if (frm->ulState == 2) {
-               /* system frame ring buffer overrun */
-               dprintk(2, "sys frame overrun.  overwriting frame %d %d\n",
-                       dev->cc, idx);
-               frm->ulState = 1;
-               frm->cur_size = 0;
+       /* search done.  now find out if should be acquiring on this channel */
+       if (!dev->b_acquire[dev->cc]) {
+               /* we found a frame, but this channel is turned off */
+               frm->ulState = S2255_READ_IDLE;
+               return -EINVAL;
        }
 
-       if (bsync) {
-               /* skip the marker 512 bytes (and offset if out of sync) */
-               psrc = (u8 *)pipe_info->transfer_buffer + offset + PREFIX_SIZE;
-       } else {
-               psrc = (u8 *)pipe_info->transfer_buffer;
+       if (frm->ulState == S2255_READ_IDLE) {
+               frm->ulState = S2255_READ_FRAME;
+               frm->cur_size = 0;
        }
 
+       /* skip the marker 512 bytes (and offset if out of sync) */
+       psrc = (u8 *)pipe_info->transfer_buffer + offset;
+
+
        if (frm->lpvbits == NULL) {
                dprintk(1, "s2255 frame buffer == NULL.%p %p %d %d",
                        frm, dev, dev->cc, idx);
@@ -1911,33 +1990,20 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
 
        pdest = frm->lpvbits + frm->cur_size;
 
-       if (bsync) {
-               copy_size =
-                   (pipe_info->cur_transfer_size - offset) - PREFIX_SIZE;
-               if (copy_size > pipe_info->cur_transfer_size) {
-                       printk("invalid copy size, overflow!\n");
-                       return -ENOMEM;
-               }
-       } else {
-               copy_size = pipe_info->cur_transfer_size;
-       }
+       copy_size = (pipe_info->cur_transfer_size - offset);
 
-       cur_size = frm->cur_size;
-       size = dev->req_image_size[dev->cc];
+       size = dev->pkt_size[dev->cc] - PREFIX_SIZE;
 
-       if ((copy_size + cur_size) > size) {
-               copy_size = size - cur_size;
-               btrunc = 1;
-       }
+       /* sanity check on pdest */
+       if ((copy_size + frm->cur_size) < dev->req_image_size[dev->cc])
+               memcpy(pdest, psrc, copy_size);
 
-       memcpy(pdest, psrc, copy_size);
-       cur_size += copy_size;
        frm->cur_size += copy_size;
-       dprintk(50, "cur_size size %lu size %lu \n", cur_size, size);
+       dprintk(4, "cur_size size %lu size %lu \n", frm->cur_size, size);
+
+       if (frm->cur_size >= size) {
 
-       if (cur_size >= (size - PREFIX_SIZE)) {
                u32 cc = dev->cc;
-               frm->ulState = 2;
                dprintk(2, "****************[%d]Buffer[%d]full*************\n",
                        cc, idx);
                dev->last_frame[cc] = dev->cur_frame[cc];
@@ -1946,16 +2012,13 @@ static int save_frame(struct s2255_dev *dev, struct s2255_pipeinfo *pipe_info)
                if ((dev->cur_frame[cc] == SYS_FRAMES) ||
                    (dev->cur_frame[cc] == dev->buffer[cc].dwFrames))
                        dev->cur_frame[cc] = 0;
-
-               /* signal the semaphore for this channel */
+               /* frame ready */
                if (dev->b_acquire[cc])
-                       s2255_got_frame(dev, cc);
+                       s2255_got_frame(dev, cc, dev->jpg_size[cc]);
                dev->frame_count[cc]++;
-       }
-       /* frame was truncated */
-       if (btrunc) {
-               /* return more data to process */
-               return EAGAIN;
+               frm->ulState = S2255_READ_IDLE;
+               frm->cur_size = 0;
+
        }
        /* done successfully */
        return 0;
@@ -1974,8 +2037,8 @@ static void s2255_read_video_callback(struct s2255_dev *dev,
        }
        /* otherwise copy to the system buffers */
        res = save_frame(dev, pipe_info);
-       if (res == EAGAIN)
-               save_frame(dev, pipe_info);
+       if (res != 0)
+               dprintk(4, "s2255: read callback failed\n");
 
        dprintk(50, "callback read video done\n");
        return;
@@ -2095,11 +2158,9 @@ static int s2255_board_init(struct s2255_dev *dev)
 
                memset(pipe, 0, sizeof(*pipe));
                pipe->dev = dev;
-               pipe->cur_transfer_size = DEFAULT_PIPE_USBBLOCK;
-               pipe->max_transfer_size = MAX_PIPE_USBBLOCK;
+               pipe->cur_transfer_size = S2255_USB_XFER_SIZE;
+               pipe->max_transfer_size = S2255_USB_XFER_SIZE;
 
-               if (pipe->cur_transfer_size > pipe->max_transfer_size)
-                       pipe->cur_transfer_size = pipe->max_transfer_size;
                pipe->transfer_buffer = kzalloc(pipe->max_transfer_size,
                                                GFP_KERNEL);
                if (pipe->transfer_buffer == NULL) {
@@ -2119,6 +2180,7 @@ static int s2255_board_init(struct s2255_dev *dev)
        for (j = 0; j < MAX_CHANNELS; j++) {
                dev->b_acquire[j] = 0;
                dev->mode[j] = mode_def;
+               dev->jc[j].quality = S2255_DEF_JPEG_QUAL;
                dev->cur_fmt[j] = &formats[0];
                dev->mode[j].restart = 1;
                dev->req_image_size[j] = get_transfer_size(&mode_def);
@@ -2323,7 +2385,7 @@ static int s2255_stop_acquire(struct s2255_dev *dev, unsigned long chn)
        kfree(buffer);
        dev->b_acquire[chn] = 0;
 
-       return 0;
+       return res;
 }
 
 static void s2255_stop_readpipe(struct s2255_dev *dev)
@@ -2359,8 +2421,10 @@ static void s2255_stop_readpipe(struct s2255_dev *dev)
        return;
 }
 
-static void s2255_fwload_start(struct s2255_dev *dev)
+static void s2255_fwload_start(struct s2255_dev *dev, int reset)
 {
+       if (reset)
+               s2255_reset_dsppower(dev);
        dev->fw_data->fw_size = dev->fw_data->fw->size;
        atomic_set(&dev->fw_data->fw_state, S2255_FW_NOTLOADED);
        memcpy(dev->fw_data->pfw_data,
@@ -2383,6 +2447,8 @@ static int s2255_probe(struct usb_interface *interface,
        struct usb_endpoint_descriptor *endpoint;
        int i;
        int retval = -ENOMEM;
+       __le32 *pdata;
+       int fw_size;
 
        dprintk(2, "s2255: probe\n");
 
@@ -2437,6 +2503,8 @@ static int s2255_probe(struct usb_interface *interface,
        dev->timer.data = (unsigned long)dev->fw_data;
 
        init_waitqueue_head(&dev->fw_data->wait_fw);
+       for (i = 0; i < MAX_CHANNELS; i++)
+               init_waitqueue_head(&dev->wait_setmode[i]);
 
 
        dev->fw_data->fw_urb = usb_alloc_urb(0, GFP_KERNEL);
@@ -2456,16 +2524,30 @@ static int s2255_probe(struct usb_interface *interface,
                printk(KERN_ERR "sensoray 2255 failed to get firmware\n");
                goto error;
        }
+       /* check the firmware is valid */
+       fw_size = dev->fw_data->fw->size;
+       pdata = (__le32 *) &dev->fw_data->fw->data[fw_size - 8];
 
+       if (*pdata != S2255_FW_MARKER) {
+               printk(KERN_INFO "Firmware invalid.\n");
+               retval = -ENODEV;
+               goto error;
+       } else {
+               /* make sure firmware is the latest */
+               __le32 *pRel;
+               pRel = (__le32 *) &dev->fw_data->fw->data[fw_size - 4];
+               printk(KERN_INFO "s2255 dsp fw version %x\n", *pRel);
+       }
        /* loads v4l specific */
        s2255_probe_v4l(dev);
+       usb_reset_device(dev->udev);
        /* load 2255 board specific */
        s2255_board_init(dev);
 
        dprintk(4, "before probe done %p\n", dev);
        spin_lock_init(&dev->slock);
 
-       s2255_fwload_start(dev);
+       s2255_fwload_start(dev, 0);
        dev_info(&interface->dev, "Sensoray 2255 detected\n");
        return 0;
 error:
@@ -2476,14 +2558,30 @@ error:
 static void s2255_disconnect(struct usb_interface *interface)
 {
        struct s2255_dev *dev = NULL;
+       int i;
        dprintk(1, "s2255: disconnect interface %p\n", interface);
        dev = usb_get_intfdata(interface);
+
+       /*
+        * wake up any of the timers to allow open_lock to be
+        * acquired sooner
+        */
+       atomic_set(&dev->fw_data->fw_state, S2255_FW_DISCONNECTING);
+       wake_up(&dev->fw_data->wait_fw);
+       for (i = 0; i < MAX_CHANNELS; i++) {
+               dev->setmode_ready[i] = 1;
+               wake_up(&dev->wait_setmode[i]);
+       }
+
+       mutex_lock(&dev->open_lock);
+       usb_set_intfdata(interface, NULL);
+       mutex_unlock(&dev->open_lock);
+
        if (dev) {
                kref_put(&dev->kref, s2255_destroy);
                dprintk(1, "s2255drv: disconnect\n");
                dev_info(&interface->dev, "s2255usb now disconnected\n");
        }
-       usb_set_intfdata(interface, NULL);
 }
 
 static struct usb_driver s2255_driver = {
index 6ee63e69b36c4d7106fd0b2bcafb0433df47d64b..4a21b8a6a7091a844c98e27b3090fb93f5c3cf9e 100644 (file)
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/i2c.h>
+#include <linux/smp_lock.h>
+#include <linux/mutex.h>
 #include <linux/videotext.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
-#include <linux/mutex.h>
-
-#include "saa5246a.h"
+#include <media/v4l2-i2c-drv-legacy.h>
 
 MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
 MODULE_DESCRIPTION("Philips SAA5246A, SAA5281 Teletext decoder driver");
 MODULE_LICENSE("GPL");
 
-struct saa5246a_device
-{
-       u8     pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
-       int    is_searching[NUM_DAUS];
-       struct i2c_client *client;
-       struct mutex lock;
-};
+#define MAJOR_VERSION 1                /* driver major version number */
+#define MINOR_VERSION 8                /* driver minor version number */
+
+/* Number of DAUs = number of pages that can be searched at the same time. */
+#define NUM_DAUS 4
+
+#define NUM_ROWS_PER_PAGE 40
+
+/* first column is 0 (not 1) */
+#define POS_TIME_START 32
+#define POS_TIME_END 39
+
+#define POS_HEADER_START 7
+#define POS_HEADER_END 31
+
+/* Returns 'true' if the part of the videotext page described with req contains
+   (at least parts of) the time field */
+#define REQ_CONTAINS_TIME(p_req) \
+       ((p_req)->start <= POS_TIME_END && \
+        (p_req)->end   >= POS_TIME_START)
+
+/* Returns 'true' if the part of the videotext page described with req contains
+   (at least parts of) the page header */
+#define REQ_CONTAINS_HEADER(p_req) \
+       ((p_req)->start <= POS_HEADER_END && \
+        (p_req)->end   >= POS_HEADER_START)
+
+/*****************************************************************************/
+/* Mode register numbers of the SAA5246A                                    */
+/*****************************************************************************/
+#define SAA5246A_REGISTER_R0    0
+#define SAA5246A_REGISTER_R1    1
+#define SAA5246A_REGISTER_R2    2
+#define SAA5246A_REGISTER_R3    3
+#define SAA5246A_REGISTER_R4    4
+#define SAA5246A_REGISTER_R5    5
+#define SAA5246A_REGISTER_R6    6
+#define SAA5246A_REGISTER_R7    7
+#define SAA5246A_REGISTER_R8    8
+#define SAA5246A_REGISTER_R9    9
+#define SAA5246A_REGISTER_R10  10
+#define SAA5246A_REGISTER_R11  11
+#define SAA5246A_REGISTER_R11B 11
+
+/* SAA5246A mode registers often autoincrement to the next register.
+   Therefore we use variable argument lists. The following macro indicates
+   the end of a command list. */
+#define COMMAND_END (-1)
+
+/*****************************************************************************/
+/* Contents of the mode registers of the SAA5246A                           */
+/*****************************************************************************/
+/* Register R0 (Advanced Control) */
+#define R0_SELECT_R11                                     0x00
+#define R0_SELECT_R11B                                    0x01
+
+#define R0_PLL_TIME_CONSTANT_LONG                         0x00
+#define R0_PLL_TIME_CONSTANT_SHORT                        0x02
+
+#define R0_ENABLE_nODD_EVEN_OUTPUT                        0x00
+#define R0_DISABLE_nODD_EVEN_OUTPUT                       0x04
+
+#define R0_ENABLE_HDR_POLL                                0x00
+#define R0_DISABLE_HDR_POLL                               0x10
+
+#define R0_DO_NOT_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x00
+#define R0_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED       0x20
+
+#define R0_NO_FREE_RUN_PLL                                0x00
+#define R0_FREE_RUN_PLL                                           0x40
+
+#define R0_NO_AUTOMATIC_FASTEXT_PROMPT                    0x00
+#define R0_AUTOMATIC_FASTEXT_PROMPT                       0x80
+
+/* Register R1 (Mode) */
+#define R1_INTERLACED_312_AND_HALF_312_AND_HALF_LINES     0x00
+#define R1_NON_INTERLACED_312_313_LINES                           0x01
+#define R1_NON_INTERLACED_312_312_LINES                           0x02
+#define R1_FFB_LEADING_EDGE_IN_FIRST_BROAD_PULSE          0x03
+#define R1_FFB_LEADING_EDGE_IN_SECOND_BROAD_PULSE         0x07
+
+#define R1_DEW                                            0x00
+#define R1_FULL_FIELD                                     0x08
+
+#define R1_EXTENDED_PACKET_DISABLE                        0x00
+#define R1_EXTENDED_PACKET_ENABLE                         0x10
+
+#define R1_DAUS_ALL_ON                                    0x00
+#define R1_DAUS_ALL_OFF                                           0x20
+
+#define R1_7_BITS_PLUS_PARITY                             0x00
+#define R1_8_BITS_NO_PARITY                               0x40
+
+#define R1_VCS_TO_SCS                                     0x00
+#define R1_NO_VCS_TO_SCS                                  0x80
+
+/* Register R2 (Page request address) */
+#define R2_IN_R3_SELECT_PAGE_HUNDREDS                     0x00
+#define R2_IN_R3_SELECT_PAGE_TENS                         0x01
+#define R2_IN_R3_SELECT_PAGE_UNITS                        0x02
+#define R2_IN_R3_SELECT_HOURS_TENS                        0x03
+#define R2_IN_R3_SELECT_HOURS_UNITS                       0x04
+#define R2_IN_R3_SELECT_MINUTES_TENS                      0x05
+#define R2_IN_R3_SELECT_MINUTES_UNITS                     0x06
+
+#define R2_DAU_0                                          0x00
+#define R2_DAU_1                                          0x10
+#define R2_DAU_2                                          0x20
+#define R2_DAU_3                                          0x30
+
+#define R2_BANK_0                                         0x00
+#define R2_BANK 1                                         0x40
+
+#define R2_HAMMING_CHECK_ON                               0x80
+#define R2_HAMMING_CHECK_OFF                              0x00
+
+/* Register R3 (Page request data) */
+#define R3_PAGE_HUNDREDS_0                                0x00
+#define R3_PAGE_HUNDREDS_1                                0x01
+#define R3_PAGE_HUNDREDS_2                                0x02
+#define R3_PAGE_HUNDREDS_3                                0x03
+#define R3_PAGE_HUNDREDS_4                                0x04
+#define R3_PAGE_HUNDREDS_5                                0x05
+#define R3_PAGE_HUNDREDS_6                                0x06
+#define R3_PAGE_HUNDREDS_7                                0x07
 
-static struct video_device saa_template;       /* Declared near bottom */
+#define R3_HOLD_PAGE                                      0x00
+#define R3_UPDATE_PAGE                                    0x08
 
-/* Addresses to scan */
-static unsigned short normal_i2c[]      = { I2C_ADDRESS, I2C_CLIENT_END };
+#define R3_PAGE_HUNDREDS_DO_NOT_CARE                      0x00
+#define R3_PAGE_HUNDREDS_DO_CARE                          0x10
 
-I2C_CLIENT_INSMOD;
+#define R3_PAGE_TENS_DO_NOT_CARE                          0x00
+#define R3_PAGE_TENS_DO_CARE                              0x10
 
-static struct i2c_client client_template;
+#define R3_PAGE_UNITS_DO_NOT_CARE                         0x00
+#define R3_PAGE_UNITS_DO_CARE                             0x10
 
-static int saa5246a_attach(struct i2c_adapter *adap, int addr, int kind)
-{
-       int pgbuf;
-       int err;
-       struct i2c_client *client;
-       struct video_device *vd;
-       struct saa5246a_device *t;
+#define R3_HOURS_TENS_DO_NOT_CARE                         0x00
+#define R3_HOURS_TENS_DO_CARE                             0x10
 
-       printk(KERN_INFO "saa5246a: teletext chip found.\n");
-       client=kmalloc(sizeof(*client), GFP_KERNEL);
-       if(client==NULL)
-               return -ENOMEM;
-       client_template.adapter = adap;
-       client_template.addr = addr;
-       memcpy(client, &client_template, sizeof(*client));
-       t = kzalloc(sizeof(*t), GFP_KERNEL);
-       if(t==NULL)
-       {
-               kfree(client);
-               return -ENOMEM;
-       }
-       strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
-       mutex_init(&t->lock);
+#define R3_HOURS_UNITS_DO_NOT_CARE                        0x00
+#define R3_HOURS_UNITS_DO_CARE                            0x10
 
-       /*
-        *      Now create a video4linux device
-        */
+#define R3_MINUTES_TENS_DO_NOT_CARE                       0x00
+#define R3_MINUTES_TENS_DO_CARE                                   0x10
 
-       vd = video_device_alloc();
-       if(vd==NULL)
-       {
-               kfree(t);
-               kfree(client);
-               return -ENOMEM;
-       }
-       i2c_set_clientdata(client, vd);
-       memcpy(vd, &saa_template, sizeof(*vd));
+#define R3_MINUTES_UNITS_DO_NOT_CARE                      0x00
+#define R3_MINUTES_UNITS_DO_CARE                          0x10
 
-       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
-       {
-               memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
-               t->is_searching[pgbuf] = false;
-       }
-       vd->priv=t;
+/* Register R4 (Display chapter) */
+#define R4_DISPLAY_PAGE_0                                 0x00
+#define R4_DISPLAY_PAGE_1                                 0x01
+#define R4_DISPLAY_PAGE_2                                 0x02
+#define R4_DISPLAY_PAGE_3                                 0x03
+#define R4_DISPLAY_PAGE_4                                 0x04
+#define R4_DISPLAY_PAGE_5                                 0x05
+#define R4_DISPLAY_PAGE_6                                 0x06
+#define R4_DISPLAY_PAGE_7                                 0x07
 
+/* Register R5 (Normal display control) */
+#define R5_PICTURE_INSIDE_BOXING_OFF                      0x00
+#define R5_PICTURE_INSIDE_BOXING_ON                       0x01
 
-       /*
-        *      Register it
-        */
+#define R5_PICTURE_OUTSIDE_BOXING_OFF                     0x00
+#define R5_PICTURE_OUTSIDE_BOXING_ON                      0x02
 
-       if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
-       {
-               kfree(t);
-               kfree(client);
-               video_device_release(vd);
-               return err;
-       }
-       t->client = client;
-       i2c_attach_client(client);
-       return 0;
-}
+#define R5_TEXT_INSIDE_BOXING_OFF                         0x00
+#define R5_TEXT_INSIDE_BOXING_ON                          0x04
 
-/*
- *     We do most of the hard work when we become a device on the i2c.
- */
-static int saa5246a_probe(struct i2c_adapter *adap)
-{
-       if (adap->class & I2C_CLASS_TV_ANALOG)
-               return i2c_probe(adap, &addr_data, saa5246a_attach);
-       return 0;
-}
+#define R5_TEXT_OUTSIDE_BOXING_OFF                        0x00
+#define R5_TEXT_OUTSIDE_BOXING_ON                         0x08
 
-static int saa5246a_detach(struct i2c_client *client)
-{
-       struct video_device *vd = i2c_get_clientdata(client);
-       i2c_detach_client(client);
-       video_unregister_device(vd);
-       kfree(vd->priv);
-       kfree(client);
-       return 0;
-}
+#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_OFF                   0x00
+#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_ON            0x10
 
-/*
- *     I2C interfaces
- */
+#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF          0x00
+#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON                   0x20
+
+#define R5_BACKGROUND_COLOR_INSIDE_BOXING_OFF             0x00
+#define R5_BACKGROUND_COLOR_INSIDE_BOXING_ON              0x40
+
+#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF            0x00
+#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_ON             0x80
+
+/* Register R6 (Newsflash display) */
+#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_OFF            0x00
+#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_ON             0x01
+
+#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_OFF                   0x00
+#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_ON            0x02
+
+#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_OFF               0x00
+#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_ON                0x04
+
+#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_OFF              0x00
+#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_ON               0x08
+
+#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_OFF  0x00
+#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_ON   0x10
+
+#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
+#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON  0x20
+
+#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_OFF    0x00
+#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_ON    0x40
+
+#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF   0x00
+#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_ON    0x80
+
+/* Register R7 (Display mode) */
+#define R7_BOX_OFF_ROW_0                                  0x00
+#define R7_BOX_ON_ROW_0                                           0x01
+
+#define R7_BOX_OFF_ROW_1_TO_23                            0x00
+#define R7_BOX_ON_ROW_1_TO_23                             0x02
+
+#define R7_BOX_OFF_ROW_24                                 0x00
+#define R7_BOX_ON_ROW_24                                  0x04
+
+#define R7_SINGLE_HEIGHT                                  0x00
+#define R7_DOUBLE_HEIGHT                                  0x08
+
+#define R7_TOP_HALF                                       0x00
+#define R7_BOTTOM_HALF                                    0x10
+
+#define R7_REVEAL_OFF                                     0x00
+#define R7_REVEAL_ON                                      0x20
+
+#define R7_CURSER_OFF                                     0x00
+#define R7_CURSER_ON                                      0x40
+
+#define R7_STATUS_BOTTOM                                  0x00
+#define R7_STATUS_TOP                                     0x80
+
+/* Register R8 (Active chapter) */
+#define R8_ACTIVE_CHAPTER_0                               0x00
+#define R8_ACTIVE_CHAPTER_1                               0x01
+#define R8_ACTIVE_CHAPTER_2                               0x02
+#define R8_ACTIVE_CHAPTER_3                               0x03
+#define R8_ACTIVE_CHAPTER_4                               0x04
+#define R8_ACTIVE_CHAPTER_5                               0x05
+#define R8_ACTIVE_CHAPTER_6                               0x06
+#define R8_ACTIVE_CHAPTER_7                               0x07
+
+#define R8_CLEAR_MEMORY                                           0x08
+#define R8_DO_NOT_CLEAR_MEMORY                            0x00
+
+/* Register R9 (Curser row) */
+#define R9_CURSER_ROW_0                                           0x00
+#define R9_CURSER_ROW_1                                           0x01
+#define R9_CURSER_ROW_2                                           0x02
+#define R9_CURSER_ROW_25                                  0x19
+
+/* Register R10 (Curser column) */
+#define R10_CURSER_COLUMN_0                               0x00
+#define R10_CURSER_COLUMN_6                               0x06
+#define R10_CURSER_COLUMN_8                               0x08
+
+/*****************************************************************************/
+/* Row 25 control data in column 0 to 9                                             */
+/*****************************************************************************/
+#define ROW25_COLUMN0_PAGE_UNITS                          0x0F
+
+#define ROW25_COLUMN1_PAGE_TENS                                   0x0F
+
+#define ROW25_COLUMN2_MINUTES_UNITS                       0x0F
 
-static struct i2c_driver i2c_driver_videotext =
+#define ROW25_COLUMN3_MINUTES_TENS                        0x07
+#define ROW25_COLUMN3_DELETE_PAGE                         0x08
+
+#define ROW25_COLUMN4_HOUR_UNITS                          0x0F
+
+#define ROW25_COLUMN5_HOUR_TENS                                   0x03
+#define ROW25_COLUMN5_INSERT_HEADLINE                     0x04
+#define ROW25_COLUMN5_INSERT_SUBTITLE                     0x08
+
+#define ROW25_COLUMN6_SUPPRESS_HEADER                     0x01
+#define ROW25_COLUMN6_UPDATE_PAGE                         0x02
+#define ROW25_COLUMN6_INTERRUPTED_SEQUENCE                0x04
+#define ROW25_COLUMN6_SUPPRESS_DISPLAY                    0x08
+
+#define ROW25_COLUMN7_SERIAL_MODE                         0x01
+#define ROW25_COLUMN7_CHARACTER_SET                       0x0E
+
+#define ROW25_COLUMN8_PAGE_HUNDREDS                       0x07
+#define ROW25_COLUMN8_PAGE_NOT_FOUND                      0x10
+
+#define ROW25_COLUMN9_PAGE_BEING_LOOKED_FOR               0x20
+
+#define ROW25_COLUMN0_TO_7_HAMMING_ERROR                  0x10
+
+/*****************************************************************************/
+/* Helper macros for extracting page, hour and minute digits                */
+/*****************************************************************************/
+/* BYTE_POS  0 is at row 0, column 0,
+   BYTE_POS  1 is at row 0, column 1,
+   BYTE_POS 40 is at row 1, column 0, (with NUM_ROWS_PER_PAGE = 40)
+   BYTE_POS 41 is at row 1, column 1, (with NUM_ROWS_PER_PAGE = 40),
+   ... */
+#define ROW(BYTE_POS)    (BYTE_POS / NUM_ROWS_PER_PAGE)
+#define COLUMN(BYTE_POS) (BYTE_POS % NUM_ROWS_PER_PAGE)
+
+/*****************************************************************************/
+/* Helper macros for extracting page, hour and minute digits                */
+/*****************************************************************************/
+/* Macros for extracting hundreds, tens and units of a page number which
+   must be in the range 0 ... 0x799.
+   Note that page is coded in hexadecimal, i.e. 0x123 means page 123.
+   page 0x.. means page 8.. */
+#define HUNDREDS_OF_PAGE(page) (((page) / 0x100) & 0x7)
+#define TENS_OF_PAGE(page)     (((page) / 0x10)  & 0xF)
+#define UNITS_OF_PAGE(page)     ((page) & 0xF)
+
+/* Macros for extracting tens and units of a hour information which
+   must be in the range 0 ... 0x24.
+   Note that hour is coded in hexadecimal, i.e. 0x12 means 12 hours */
+#define TENS_OF_HOUR(hour)  ((hour) / 0x10)
+#define UNITS_OF_HOUR(hour) ((hour) & 0xF)
+
+/* Macros for extracting tens and units of a minute information which
+   must be in the range 0 ... 0x59.
+   Note that minute is coded in hexadecimal, i.e. 0x12 means 12 minutes */
+#define TENS_OF_MINUTE(minute)  ((minute) / 0x10)
+#define UNITS_OF_MINUTE(minute) ((minute) & 0xF)
+
+#define HOUR_MAX   0x23
+#define MINUTE_MAX 0x59
+#define PAGE_MAX   0x8FF
+
+
+struct saa5246a_device
 {
-       .driver = {
-               .name   = IF_NAME,              /* name */
-       },
-       .id             = I2C_DRIVERID_SAA5249, /* in i2c.h */
-       .attach_adapter = saa5246a_probe,
-       .detach_client  = saa5246a_detach,
+       u8     pgbuf[NUM_DAUS][VTX_VIRTUALSIZE];
+       int    is_searching[NUM_DAUS];
+       struct i2c_client *client;
+       unsigned long in_use;
+       struct mutex lock;
 };
 
-static struct i2c_client client_template = {
-       .driver         = &i2c_driver_videotext,
-       .name           = "(unset)",
-};
+static struct video_device saa_template;       /* Declared near bottom */
+
+/*
+ *     I2C interfaces
+ */
 
 static int i2c_sendbuf(struct saa5246a_device *t, int reg, int count, u8 *data)
 {
@@ -579,8 +807,8 @@ static inline int saa5246a_stop_dau(struct saa5246a_device *t,
 static int do_saa5246a_ioctl(struct inode *inode, struct file *file,
                            unsigned int cmd, void *arg)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5246a_device *t=vd->priv;
+       struct saa5246a_device *t = video_drvdata(file);
+
        switch(cmd)
        {
                case VTXIOCGETINFO:
@@ -720,8 +948,7 @@ static inline unsigned int vtx_fix_command(unsigned int cmd)
 static int saa5246a_ioctl(struct inode *inode, struct file *file,
                         unsigned int cmd, unsigned long arg)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5246a_device *t = vd->priv;
+       struct saa5246a_device *t = video_drvdata(file);
        int err;
 
        cmd = vtx_fix_command(cmd);
@@ -733,21 +960,15 @@ static int saa5246a_ioctl(struct inode *inode, struct file *file,
 
 static int saa5246a_open(struct inode *inode, struct file *file)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5246a_device *t = vd->priv;
-       int err;
+       struct saa5246a_device *t = video_drvdata(file);
 
-       err = video_exclusive_open(inode,file);
-       if (err < 0)
-               return err;
+       if (t->client == NULL)
+               return -ENODEV;
 
-       if (t->client==NULL) {
-               err = -ENODEV;
-               goto fail;
-       }
+       if (test_and_set_bit(0, &t->in_use))
+               return -EBUSY;
 
        if (i2c_senddata(t, SAA5246A_REGISTER_R0,
-
                R0_SELECT_R11 |
                R0_PLL_TIME_CONSTANT_LONG |
                R0_ENABLE_nODD_EVEN_OUTPUT |
@@ -773,21 +994,15 @@ static int saa5246a_open(struct inode *inode, struct file *file)
 
                COMMAND_END))
        {
-               err = -EIO;
-               goto fail;
+               clear_bit(0, &t->in_use);
+               return -EIO;
        }
-
        return 0;
-
-fail:
-       video_exclusive_release(inode,file);
-       return err;
 }
 
 static int saa5246a_release(struct inode *inode, struct file *file)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5246a_device *t = vd->priv;
+       struct saa5246a_device *t = video_drvdata(file);
 
        /* Stop all acquisition circuits. */
        i2c_senddata(t, SAA5246A_REGISTER_R1,
@@ -800,26 +1015,10 @@ static int saa5246a_release(struct inode *inode, struct file *file)
                R1_VCS_TO_SCS,
 
                COMMAND_END);
-       video_exclusive_release(inode,file);
+       clear_bit(0, &t->in_use);
        return 0;
 }
 
-static int __init init_saa_5246a (void)
-{
-       printk(KERN_INFO
-               "SAA5246A (or compatible) Teletext decoder driver version %d.%d\n",
-               MAJOR_VERSION, MINOR_VERSION);
-       return i2c_add_driver(&i2c_driver_videotext);
-}
-
-static void __exit cleanup_saa_5246a (void)
-{
-       i2c_del_driver(&i2c_driver_videotext);
-}
-
-module_init(init_saa_5246a);
-module_exit(cleanup_saa_5246a);
-
 static const struct file_operations saa_fops = {
        .owner   = THIS_MODULE,
        .open    = saa5246a_open,
@@ -830,8 +1029,79 @@ static const struct file_operations saa_fops = {
 
 static struct video_device saa_template =
 {
-       .name     = IF_NAME,
+       .name     = "saa5246a",
        .fops     = &saa_fops,
        .release  = video_device_release,
        .minor    = -1,
 };
+
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
+
+I2C_CLIENT_INSMOD;
+
+static int saa5246a_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       int pgbuf;
+       int err;
+       struct video_device *vd;
+       struct saa5246a_device *t;
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
+       v4l_info(client, "VideoText version %d.%d\n",
+                       MAJOR_VERSION, MINOR_VERSION);
+       t = kzalloc(sizeof(*t), GFP_KERNEL);
+       if (t == NULL)
+               return -ENOMEM;
+       mutex_init(&t->lock);
+
+       /* Now create a video4linux device */
+       vd = video_device_alloc();
+       if (vd == NULL) {
+               kfree(t);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(client, vd);
+       memcpy(vd, &saa_template, sizeof(*vd));
+
+       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
+               memset(t->pgbuf[pgbuf], ' ', sizeof(t->pgbuf[0]));
+               t->is_searching[pgbuf] = false;
+       }
+       video_set_drvdata(vd, t);
+
+       /* Register it */
+       err = video_register_device(vd, VFL_TYPE_VTX, -1);
+       if (err < 0) {
+               kfree(t);
+               video_device_release(vd);
+               return err;
+       }
+       t->client = client;
+       return 0;
+}
+
+static int saa5246a_remove(struct i2c_client *client)
+{
+       struct video_device *vd = i2c_get_clientdata(client);
+
+       video_unregister_device(vd);
+       kfree(video_get_drvdata(vd));
+       return 0;
+}
+
+static const struct i2c_device_id saa5246a_id[] = {
+       { "saa5246a", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, saa5246a_id);
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "saa5246a",
+       .driverid = I2C_DRIVERID_SAA5249,
+       .probe = saa5246a_probe,
+       .remove = saa5246a_remove,
+       .id_table = saa5246a_id,
+};
diff --git a/drivers/media/video/saa5246a.h b/drivers/media/video/saa5246a.h
deleted file mode 100644 (file)
index 64394c0..0000000
+++ /dev/null
@@ -1,359 +0,0 @@
-/*
-   Driver for the SAA5246A or SAA5281 Teletext (=Videotext) decoder chips from
-   Philips.
-
-   Copyright (C) 2004 Michael Geng (linux@MichaelGeng.de)
-
-   This program is free software; you can redistribute it and/or modify
-   it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
-   (at your option) any later version.
-
-   This program is distributed in the hope that it will be useful,
-   but WITHOUT ANY WARRANTY; without even the implied warranty of
-   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-   GNU General Public License for more details.
-
-   You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
-
- */
-#ifndef __SAA5246A_H__
-#define __SAA5246A_H__
-
-#define MAJOR_VERSION 1                /* driver major version number */
-#define MINOR_VERSION 8                /* driver minor version number */
-
-#define IF_NAME "SAA5246A"
-
-#define I2C_ADDRESS 17
-
-/* Number of DAUs = number of pages that can be searched at the same time. */
-#define NUM_DAUS 4
-
-#define NUM_ROWS_PER_PAGE 40
-
-/* first column is 0 (not 1) */
-#define POS_TIME_START 32
-#define POS_TIME_END 39
-
-#define POS_HEADER_START 7
-#define POS_HEADER_END 31
-
-/* Returns 'true' if the part of the videotext page described with req contains
-   (at least parts of) the time field */
-#define REQ_CONTAINS_TIME(p_req) \
-       ((p_req)->start <= POS_TIME_END && \
-        (p_req)->end   >= POS_TIME_START)
-
-/* Returns 'true' if the part of the videotext page described with req contains
-   (at least parts of) the page header */
-#define REQ_CONTAINS_HEADER(p_req) \
-       ((p_req)->start <= POS_HEADER_END && \
-        (p_req)->end   >= POS_HEADER_START)
-
-/*****************************************************************************/
-/* Mode register numbers of the SAA5246A                                    */
-/*****************************************************************************/
-#define SAA5246A_REGISTER_R0    0
-#define SAA5246A_REGISTER_R1    1
-#define SAA5246A_REGISTER_R2    2
-#define SAA5246A_REGISTER_R3    3
-#define SAA5246A_REGISTER_R4    4
-#define SAA5246A_REGISTER_R5    5
-#define SAA5246A_REGISTER_R6    6
-#define SAA5246A_REGISTER_R7    7
-#define SAA5246A_REGISTER_R8    8
-#define SAA5246A_REGISTER_R9    9
-#define SAA5246A_REGISTER_R10  10
-#define SAA5246A_REGISTER_R11  11
-#define SAA5246A_REGISTER_R11B 11
-
-/* SAA5246A mode registers often autoincrement to the next register.
-   Therefore we use variable argument lists. The following macro indicates
-   the end of a command list. */
-#define COMMAND_END (- 1)
-
-/*****************************************************************************/
-/* Contents of the mode registers of the SAA5246A                           */
-/*****************************************************************************/
-/* Register R0 (Advanced Control) */
-#define R0_SELECT_R11                                     0x00
-#define R0_SELECT_R11B                                    0x01
-
-#define R0_PLL_TIME_CONSTANT_LONG                         0x00
-#define R0_PLL_TIME_CONSTANT_SHORT                        0x02
-
-#define R0_ENABLE_nODD_EVEN_OUTPUT                        0x00
-#define R0_DISABLE_nODD_EVEN_OUTPUT                       0x04
-
-#define R0_ENABLE_HDR_POLL                                0x00
-#define R0_DISABLE_HDR_POLL                               0x10
-
-#define R0_DO_NOT_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED 0x00
-#define R0_FORCE_nODD_EVEN_LOW_IF_PICTURE_DISPLAYED       0x20
-
-#define R0_NO_FREE_RUN_PLL                                0x00
-#define R0_FREE_RUN_PLL                                           0x40
-
-#define R0_NO_AUTOMATIC_FASTEXT_PROMPT                    0x00
-#define R0_AUTOMATIC_FASTEXT_PROMPT                       0x80
-
-/* Register R1 (Mode) */
-#define R1_INTERLACED_312_AND_HALF_312_AND_HALF_LINES     0x00
-#define R1_NON_INTERLACED_312_313_LINES                           0x01
-#define R1_NON_INTERLACED_312_312_LINES                           0x02
-#define R1_FFB_LEADING_EDGE_IN_FIRST_BROAD_PULSE          0x03
-#define R1_FFB_LEADING_EDGE_IN_SECOND_BROAD_PULSE         0x07
-
-#define R1_DEW                                            0x00
-#define R1_FULL_FIELD                                     0x08
-
-#define R1_EXTENDED_PACKET_DISABLE                        0x00
-#define R1_EXTENDED_PACKET_ENABLE                         0x10
-
-#define R1_DAUS_ALL_ON                                    0x00
-#define R1_DAUS_ALL_OFF                                           0x20
-
-#define R1_7_BITS_PLUS_PARITY                             0x00
-#define R1_8_BITS_NO_PARITY                               0x40
-
-#define R1_VCS_TO_SCS                                     0x00
-#define R1_NO_VCS_TO_SCS                                  0x80
-
-/* Register R2 (Page request address) */
-#define R2_IN_R3_SELECT_PAGE_HUNDREDS                     0x00
-#define R2_IN_R3_SELECT_PAGE_TENS                         0x01
-#define R2_IN_R3_SELECT_PAGE_UNITS                        0x02
-#define R2_IN_R3_SELECT_HOURS_TENS                        0x03
-#define R2_IN_R3_SELECT_HOURS_UNITS                       0x04
-#define R2_IN_R3_SELECT_MINUTES_TENS                      0x05
-#define R2_IN_R3_SELECT_MINUTES_UNITS                     0x06
-
-#define R2_DAU_0                                          0x00
-#define R2_DAU_1                                          0x10
-#define R2_DAU_2                                          0x20
-#define R2_DAU_3                                          0x30
-
-#define R2_BANK_0                                         0x00
-#define R2_BANK 1                                         0x40
-
-#define R2_HAMMING_CHECK_ON                               0x80
-#define R2_HAMMING_CHECK_OFF                              0x00
-
-/* Register R3 (Page request data) */
-#define R3_PAGE_HUNDREDS_0                                0x00
-#define R3_PAGE_HUNDREDS_1                                0x01
-#define R3_PAGE_HUNDREDS_2                                0x02
-#define R3_PAGE_HUNDREDS_3                                0x03
-#define R3_PAGE_HUNDREDS_4                                0x04
-#define R3_PAGE_HUNDREDS_5                                0x05
-#define R3_PAGE_HUNDREDS_6                                0x06
-#define R3_PAGE_HUNDREDS_7                                0x07
-
-#define R3_HOLD_PAGE                                      0x00
-#define R3_UPDATE_PAGE                                    0x08
-
-#define R3_PAGE_HUNDREDS_DO_NOT_CARE                      0x00
-#define R3_PAGE_HUNDREDS_DO_CARE                          0x10
-
-#define R3_PAGE_TENS_DO_NOT_CARE                          0x00
-#define R3_PAGE_TENS_DO_CARE                              0x10
-
-#define R3_PAGE_UNITS_DO_NOT_CARE                         0x00
-#define R3_PAGE_UNITS_DO_CARE                             0x10
-
-#define R3_HOURS_TENS_DO_NOT_CARE                         0x00
-#define R3_HOURS_TENS_DO_CARE                             0x10
-
-#define R3_HOURS_UNITS_DO_NOT_CARE                        0x00
-#define R3_HOURS_UNITS_DO_CARE                            0x10
-
-#define R3_MINUTES_TENS_DO_NOT_CARE                       0x00
-#define R3_MINUTES_TENS_DO_CARE                                   0x10
-
-#define R3_MINUTES_UNITS_DO_NOT_CARE                      0x00
-#define R3_MINUTES_UNITS_DO_CARE                          0x10
-
-/* Register R4 (Display chapter) */
-#define R4_DISPLAY_PAGE_0                                 0x00
-#define R4_DISPLAY_PAGE_1                                 0x01
-#define R4_DISPLAY_PAGE_2                                 0x02
-#define R4_DISPLAY_PAGE_3                                 0x03
-#define R4_DISPLAY_PAGE_4                                 0x04
-#define R4_DISPLAY_PAGE_5                                 0x05
-#define R4_DISPLAY_PAGE_6                                 0x06
-#define R4_DISPLAY_PAGE_7                                 0x07
-
-/* Register R5 (Normal display control) */
-#define R5_PICTURE_INSIDE_BOXING_OFF                      0x00
-#define R5_PICTURE_INSIDE_BOXING_ON                       0x01
-
-#define R5_PICTURE_OUTSIDE_BOXING_OFF                     0x00
-#define R5_PICTURE_OUTSIDE_BOXING_ON                      0x02
-
-#define R5_TEXT_INSIDE_BOXING_OFF                         0x00
-#define R5_TEXT_INSIDE_BOXING_ON                          0x04
-
-#define R5_TEXT_OUTSIDE_BOXING_OFF                        0x00
-#define R5_TEXT_OUTSIDE_BOXING_ON                         0x08
-
-#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_OFF                   0x00
-#define R5_CONTRAST_REDUCTION_INSIDE_BOXING_ON            0x10
-
-#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF          0x00
-#define R5_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON                   0x20
-
-#define R5_BACKGROUND_COLOR_INSIDE_BOXING_OFF             0x00
-#define R5_BACKGROUND_COLOR_INSIDE_BOXING_ON              0x40
-
-#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF            0x00
-#define R5_BACKGROUND_COLOR_OUTSIDE_BOXING_ON             0x80
-
-/* Register R6 (Newsflash display) */
-#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_OFF            0x00
-#define R6_NEWSFLASH_PICTURE_INSIDE_BOXING_ON             0x01
-
-#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_OFF                   0x00
-#define R6_NEWSFLASH_PICTURE_OUTSIDE_BOXING_ON            0x02
-
-#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_OFF               0x00
-#define R6_NEWSFLASH_TEXT_INSIDE_BOXING_ON                0x04
-
-#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_OFF              0x00
-#define R6_NEWSFLASH_TEXT_OUTSIDE_BOXING_ON               0x08
-
-#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_OFF  0x00
-#define R6_NEWSFLASH_CONTRAST_REDUCTION_INSIDE_BOXING_ON   0x10
-
-#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_OFF 0x00
-#define R6_NEWSFLASH_CONTRAST_REDUCTION_OUTSIDE_BOXING_ON  0x20
-
-#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_OFF    0x00
-#define R6_NEWSFLASH_BACKGROUND_COLOR_INSIDE_BOXING_ON    0x40
-
-#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_OFF   0x00
-#define R6_NEWSFLASH_BACKGROUND_COLOR_OUTSIDE_BOXING_ON    0x80
-
-/* Register R7 (Display mode) */
-#define R7_BOX_OFF_ROW_0                                  0x00
-#define R7_BOX_ON_ROW_0                                           0x01
-
-#define R7_BOX_OFF_ROW_1_TO_23                            0x00
-#define R7_BOX_ON_ROW_1_TO_23                             0x02
-
-#define R7_BOX_OFF_ROW_24                                 0x00
-#define R7_BOX_ON_ROW_24                                  0x04
-
-#define R7_SINGLE_HEIGHT                                  0x00
-#define R7_DOUBLE_HEIGHT                                  0x08
-
-#define R7_TOP_HALF                                       0x00
-#define R7_BOTTOM_HALF                                    0x10
-
-#define R7_REVEAL_OFF                                     0x00
-#define R7_REVEAL_ON                                      0x20
-
-#define R7_CURSER_OFF                                     0x00
-#define R7_CURSER_ON                                      0x40
-
-#define R7_STATUS_BOTTOM                                  0x00
-#define R7_STATUS_TOP                                     0x80
-
-/* Register R8 (Active chapter) */
-#define R8_ACTIVE_CHAPTER_0                               0x00
-#define R8_ACTIVE_CHAPTER_1                               0x01
-#define R8_ACTIVE_CHAPTER_2                               0x02
-#define R8_ACTIVE_CHAPTER_3                               0x03
-#define R8_ACTIVE_CHAPTER_4                               0x04
-#define R8_ACTIVE_CHAPTER_5                               0x05
-#define R8_ACTIVE_CHAPTER_6                               0x06
-#define R8_ACTIVE_CHAPTER_7                               0x07
-
-#define R8_CLEAR_MEMORY                                           0x08
-#define R8_DO_NOT_CLEAR_MEMORY                            0x00
-
-/* Register R9 (Curser row) */
-#define R9_CURSER_ROW_0                                           0x00
-#define R9_CURSER_ROW_1                                           0x01
-#define R9_CURSER_ROW_2                                           0x02
-#define R9_CURSER_ROW_25                                  0x19
-
-/* Register R10 (Curser column) */
-#define R10_CURSER_COLUMN_0                               0x00
-#define R10_CURSER_COLUMN_6                               0x06
-#define R10_CURSER_COLUMN_8                               0x08
-
-/*****************************************************************************/
-/* Row 25 control data in column 0 to 9                                             */
-/*****************************************************************************/
-#define ROW25_COLUMN0_PAGE_UNITS                          0x0F
-
-#define ROW25_COLUMN1_PAGE_TENS                                   0x0F
-
-#define ROW25_COLUMN2_MINUTES_UNITS                       0x0F
-
-#define ROW25_COLUMN3_MINUTES_TENS                        0x07
-#define ROW25_COLUMN3_DELETE_PAGE                         0x08
-
-#define ROW25_COLUMN4_HOUR_UNITS                          0x0F
-
-#define ROW25_COLUMN5_HOUR_TENS                                   0x03
-#define ROW25_COLUMN5_INSERT_HEADLINE                     0x04
-#define ROW25_COLUMN5_INSERT_SUBTITLE                     0x08
-
-#define ROW25_COLUMN6_SUPPRESS_HEADER                     0x01
-#define ROW25_COLUMN6_UPDATE_PAGE                         0x02
-#define ROW25_COLUMN6_INTERRUPTED_SEQUENCE                0x04
-#define ROW25_COLUMN6_SUPPRESS_DISPLAY                    0x08
-
-#define ROW25_COLUMN7_SERIAL_MODE                         0x01
-#define ROW25_COLUMN7_CHARACTER_SET                       0x0E
-
-#define ROW25_COLUMN8_PAGE_HUNDREDS                       0x07
-#define ROW25_COLUMN8_PAGE_NOT_FOUND                      0x10
-
-#define ROW25_COLUMN9_PAGE_BEING_LOOKED_FOR               0x20
-
-#define ROW25_COLUMN0_TO_7_HAMMING_ERROR                  0x10
-
-/*****************************************************************************/
-/* Helper macros for extracting page, hour and minute digits                */
-/*****************************************************************************/
-/* BYTE_POS  0 is at row 0, column 0,
-   BYTE_POS  1 is at row 0, column 1,
-   BYTE_POS 40 is at row 1, column 0, (with NUM_ROWS_PER_PAGE = 40)
-   BYTE_POS 41 is at row 1, column 1, (with NUM_ROWS_PER_PAGE = 40),
-   ... */
-#define ROW(BYTE_POS)    (BYTE_POS / NUM_ROWS_PER_PAGE)
-#define COLUMN(BYTE_POS) (BYTE_POS % NUM_ROWS_PER_PAGE)
-
-/*****************************************************************************/
-/* Helper macros for extracting page, hour and minute digits                */
-/*****************************************************************************/
-/* Macros for extracting hundreds, tens and units of a page number which
-   must be in the range 0 ... 0x799.
-   Note that page is coded in hexadecimal, i.e. 0x123 means page 123.
-   page 0x.. means page 8.. */
-#define HUNDREDS_OF_PAGE(page) (((page) / 0x100) & 0x7)
-#define TENS_OF_PAGE(page)     (((page) / 0x10)  & 0xF)
-#define UNITS_OF_PAGE(page)     ((page) & 0xF)
-
-/* Macros for extracting tens and units of a hour information which
-   must be in the range 0 ... 0x24.
-   Note that hour is coded in hexadecimal, i.e. 0x12 means 12 hours */
-#define TENS_OF_HOUR(hour)  ((hour) / 0x10)
-#define UNITS_OF_HOUR(hour) ((hour) & 0xF)
-
-/* Macros for extracting tens and units of a minute information which
-   must be in the range 0 ... 0x59.
-   Note that minute is coded in hexadecimal, i.e. 0x12 means 12 minutes */
-#define TENS_OF_MINUTE(minute)  ((minute) / 0x10)
-#define UNITS_OF_MINUTE(minute) ((minute) & 0xF)
-
-#define HOUR_MAX   0x23
-#define MINUTE_MAX 0x59
-#define PAGE_MAX   0x8FF
-
-#endif  /* __SAA5246A_H__ */
index 0d639738d4e68044f4fa651b97d35573b820da83..3bb959c25d9d5724e720cec199538d609d340073 100644 (file)
@@ -15,8 +15,6 @@
  *
  *     Copyright (c) 1998 Richard Guenther <richard.guenther@student.uni-tuebingen.de>
  *
- * $Id: saa5249.c,v 1.1 1998/03/30 22:23:23 alan Exp $
- *
  *     Derived From
  *
  * vtx.c:
 
 #include <linux/module.h>
 #include <linux/kernel.h>
-#include <linux/sched.h>
 #include <linux/mm.h>
-#include <linux/errno.h>
-#include <linux/delay.h>
-#include <linux/ioport.h>
-#include <linux/slab.h>
 #include <linux/init.h>
-#include <stdarg.h>
 #include <linux/i2c.h>
+#include <linux/smp_lock.h>
+#include <linux/mutex.h>
+#include <linux/delay.h>
 #include <linux/videotext.h>
 #include <linux/videodev.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
-#include <linux/mutex.h>
-
+#include <media/v4l2-i2c-drv-legacy.h>
 
-#include <asm/io.h>
-#include <asm/uaccess.h>
+MODULE_AUTHOR("Michael Geng <linux@MichaelGeng.de>");
+MODULE_DESCRIPTION("Philips SAA5249 Teletext decoder driver");
+MODULE_LICENSE("GPL");
 
 #define VTX_VER_MAJ 1
 #define VTX_VER_MIN 8
 
 
-
 #define NUM_DAUS 4
 #define NUM_BUFS 8
-#define IF_NAME "SAA5249"
 
 static const int disp_modes[8][3] =
 {
@@ -109,6 +102,7 @@ struct saa5249_device
        int disp_mode;
        int virtual_mode;
        struct i2c_client *client;
+       unsigned long in_use;
        struct mutex lock;
 };
 
@@ -123,125 +117,8 @@ struct saa5249_device
 
 #define VTX_DEV_MINOR 0
 
-/* General defines and debugging support */
-
-#define RESCHED do { cond_resched(); } while(0)
-
 static struct video_device saa_template;       /* Declared near bottom */
 
-/* Addresses to scan */
-static unsigned short normal_i2c[] = {34>>1,I2C_CLIENT_END};
-
-I2C_CLIENT_INSMOD;
-
-static struct i2c_client client_template;
-
-static int saa5249_attach(struct i2c_adapter *adap, int addr, int kind)
-{
-       int pgbuf;
-       int err;
-       struct i2c_client *client;
-       struct video_device *vd;
-       struct saa5249_device *t;
-
-       printk(KERN_INFO "saa5249: teletext chip found.\n");
-       client=kmalloc(sizeof(*client), GFP_KERNEL);
-       if(client==NULL)
-               return -ENOMEM;
-       client_template.adapter = adap;
-       client_template.addr = addr;
-       memcpy(client, &client_template, sizeof(*client));
-       t = kzalloc(sizeof(*t), GFP_KERNEL);
-       if(t==NULL)
-       {
-               kfree(client);
-               return -ENOMEM;
-       }
-       strlcpy(client->name, IF_NAME, I2C_NAME_SIZE);
-       mutex_init(&t->lock);
-
-       /*
-        *      Now create a video4linux device
-        */
-
-       vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
-       if(vd==NULL)
-       {
-               kfree(t);
-               kfree(client);
-               return -ENOMEM;
-       }
-       i2c_set_clientdata(client, vd);
-       memcpy(vd, &saa_template, sizeof(*vd));
-
-       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
-       {
-               memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
-               memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
-               memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
-               t->vdau[pgbuf].expire = 0;
-               t->vdau[pgbuf].clrfound = true;
-               t->vdau[pgbuf].stopped = true;
-               t->is_searching[pgbuf] = false;
-       }
-       vd->priv=t;
-
-
-       /*
-        *      Register it
-        */
-
-       if((err=video_register_device(vd, VFL_TYPE_VTX,-1))<0)
-       {
-               kfree(t);
-               kfree(vd);
-               kfree(client);
-               return err;
-       }
-       t->client = client;
-       i2c_attach_client(client);
-       return 0;
-}
-
-/*
- *     We do most of the hard work when we become a device on the i2c.
- */
-
-static int saa5249_probe(struct i2c_adapter *adap)
-{
-       if (adap->class & I2C_CLASS_TV_ANALOG)
-               return i2c_probe(adap, &addr_data, saa5249_attach);
-       return 0;
-}
-
-static int saa5249_detach(struct i2c_client *client)
-{
-       struct video_device *vd = i2c_get_clientdata(client);
-       i2c_detach_client(client);
-       video_unregister_device(vd);
-       kfree(vd->priv);
-       kfree(vd);
-       kfree(client);
-       return 0;
-}
-
-/* new I2C driver support */
-
-static struct i2c_driver i2c_driver_videotext =
-{
-       .driver = {
-               .name   = IF_NAME,              /* name */
-       },
-       .id             = I2C_DRIVERID_SAA5249, /* in i2c.h */
-       .attach_adapter = saa5249_probe,
-       .detach_client  = saa5249_detach,
-};
-
-static struct i2c_client client_template = {
-       .driver         = &i2c_driver_videotext,
-       .name           = "(unset)",
-};
-
 /*
  *     Wait the given number of jiffies (10ms). This calls the scheduler, so the actual
  *     delay may be longer.
@@ -275,7 +152,7 @@ static int i2c_sendbuf(struct saa5249_device *t, int reg, int count, u8 *data)
        buf[0] = reg;
        memcpy(buf+1, data, count);
 
-       if(i2c_master_send(t->client, buf, count+1)==count+1)
+       if (i2c_master_send(t->client, buf, count + 1) == count + 1)
                return 0;
        return -1;
 }
@@ -317,246 +194,236 @@ static int do_saa5249_ioctl(struct inode *inode, struct file *file,
                            unsigned int cmd, void *arg)
 {
        static int virtual_mode = false;
-       struct video_device *vd = video_devdata(file);
-       struct saa5249_device *t=vd->priv;
+       struct saa5249_device *t = video_drvdata(file);
 
-       switch(cmd)
+       switch (cmd) {
+       case VTXIOCGETINFO:
        {
-               case VTXIOCGETINFO:
-               {
-                       vtx_info_t *info = arg;
-                       info->version_major = VTX_VER_MAJ;
-                       info->version_minor = VTX_VER_MIN;
-                       info->numpages = NUM_DAUS;
-                       /*info->cct_type = CCT_TYPE;*/
-                       return 0;
-               }
+               vtx_info_t *info = arg;
+               info->version_major = VTX_VER_MAJ;
+               info->version_minor = VTX_VER_MIN;
+               info->numpages = NUM_DAUS;
+               /*info->cct_type = CCT_TYPE;*/
+               return 0;
+       }
 
-               case VTXIOCCLRPAGE:
-               {
-                       vtx_pagereq_t *req = arg;
+       case VTXIOCCLRPAGE:
+       {
+               vtx_pagereq_t *req = arg;
 
-                       if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
-                               return -EINVAL;
-                       memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
-                       t->vdau[req->pgbuf].clrfound = true;
-                       return 0;
-               }
+               if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
+                       return -EINVAL;
+               memset(t->vdau[req->pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
+               t->vdau[req->pgbuf].clrfound = true;
+               return 0;
+       }
 
-               case VTXIOCCLRFOUND:
-               {
-                       vtx_pagereq_t *req = arg;
+       case VTXIOCCLRFOUND:
+       {
+               vtx_pagereq_t *req = arg;
 
-                       if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
-                               return -EINVAL;
-                       t->vdau[req->pgbuf].clrfound = true;
-                       return 0;
-               }
+               if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
+                       return -EINVAL;
+               t->vdau[req->pgbuf].clrfound = true;
+               return 0;
+       }
 
-               case VTXIOCPAGEREQ:
-               {
-                       vtx_pagereq_t *req = arg;
-                       if (!(req->pagemask & PGMASK_PAGE))
-                               req->page = 0;
-                       if (!(req->pagemask & PGMASK_HOUR))
-                               req->hour = 0;
-                       if (!(req->pagemask & PGMASK_MINUTE))
-                               req->minute = 0;
-                       if (req->page < 0 || req->page > 0x8ff) /* 7FF ?? */
-                               return -EINVAL;
-                       req->page &= 0x7ff;
-                       if (req->hour < 0 || req->hour > 0x3f || req->minute < 0 || req->minute > 0x7f ||
-                               req->pagemask < 0 || req->pagemask >= PGMASK_MAX || req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
-                               return -EINVAL;
-                       t->vdau[req->pgbuf].sregs[0] = (req->pagemask & PG_HUND ? 0x10 : 0) | (req->page / 0x100);
-                       t->vdau[req->pgbuf].sregs[1] = (req->pagemask & PG_TEN ? 0x10 : 0) | ((req->page / 0x10) & 0xf);
-                       t->vdau[req->pgbuf].sregs[2] = (req->pagemask & PG_UNIT ? 0x10 : 0) | (req->page & 0xf);
-                       t->vdau[req->pgbuf].sregs[3] = (req->pagemask & HR_TEN ? 0x10 : 0) | (req->hour / 0x10);
-                       t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf);
-                       t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10);
-                       t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf);
-                       t->vdau[req->pgbuf].stopped = false;
-                       t->vdau[req->pgbuf].clrfound = true;
-                       t->is_searching[req->pgbuf] = true;
-                       return 0;
-               }
+       case VTXIOCPAGEREQ:
+       {
+               vtx_pagereq_t *req = arg;
+               if (!(req->pagemask & PGMASK_PAGE))
+                       req->page = 0;
+               if (!(req->pagemask & PGMASK_HOUR))
+                       req->hour = 0;
+               if (!(req->pagemask & PGMASK_MINUTE))
+                       req->minute = 0;
+               if (req->page < 0 || req->page > 0x8ff) /* 7FF ?? */
+                       return -EINVAL;
+               req->page &= 0x7ff;
+               if (req->hour < 0 || req->hour > 0x3f || req->minute < 0 || req->minute > 0x7f ||
+                       req->pagemask < 0 || req->pagemask >= PGMASK_MAX || req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
+                       return -EINVAL;
+               t->vdau[req->pgbuf].sregs[0] = (req->pagemask & PG_HUND ? 0x10 : 0) | (req->page / 0x100);
+               t->vdau[req->pgbuf].sregs[1] = (req->pagemask & PG_TEN ? 0x10 : 0) | ((req->page / 0x10) & 0xf);
+               t->vdau[req->pgbuf].sregs[2] = (req->pagemask & PG_UNIT ? 0x10 : 0) | (req->page & 0xf);
+               t->vdau[req->pgbuf].sregs[3] = (req->pagemask & HR_TEN ? 0x10 : 0) | (req->hour / 0x10);
+               t->vdau[req->pgbuf].sregs[4] = (req->pagemask & HR_UNIT ? 0x10 : 0) | (req->hour & 0xf);
+               t->vdau[req->pgbuf].sregs[5] = (req->pagemask & MIN_TEN ? 0x10 : 0) | (req->minute / 0x10);
+               t->vdau[req->pgbuf].sregs[6] = (req->pagemask & MIN_UNIT ? 0x10 : 0) | (req->minute & 0xf);
+               t->vdau[req->pgbuf].stopped = false;
+               t->vdau[req->pgbuf].clrfound = true;
+               t->is_searching[req->pgbuf] = true;
+               return 0;
+       }
 
-               case VTXIOCGETSTAT:
-               {
-                       vtx_pagereq_t *req = arg;
-                       u8 infobits[10];
-                       vtx_pageinfo_t info;
-                       int a;
-
-                       if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
-                               return -EINVAL;
-                       if (!t->vdau[req->pgbuf].stopped)
-                       {
-                               if (i2c_senddata(t, 2, 0, -1) ||
-                                       i2c_sendbuf(t, 3, sizeof(t->vdau[0].sregs), t->vdau[req->pgbuf].sregs) ||
-                                       i2c_senddata(t, 8, 0, 25, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', -1) ||
-                                       i2c_senddata(t, 2, 0, t->vdau[req->pgbuf].sregs[0] | 8, -1) ||
-                                       i2c_senddata(t, 8, 0, 25, 0, -1))
-                                       return -EIO;
-                               jdelay(PAGE_WAIT);
-                               if (i2c_getdata(t, 10, infobits))
-                                       return -EIO;
+       case VTXIOCGETSTAT:
+       {
+               vtx_pagereq_t *req = arg;
+               u8 infobits[10];
+               vtx_pageinfo_t info;
+               int a;
+
+               if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
+                       return -EINVAL;
+               if (!t->vdau[req->pgbuf].stopped) {
+                       if (i2c_senddata(t, 2, 0, -1) ||
+                               i2c_sendbuf(t, 3, sizeof(t->vdau[0].sregs), t->vdau[req->pgbuf].sregs) ||
+                               i2c_senddata(t, 8, 0, 25, 0, ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', -1) ||
+                               i2c_senddata(t, 2, 0, t->vdau[req->pgbuf].sregs[0] | 8, -1) ||
+                               i2c_senddata(t, 8, 0, 25, 0, -1))
+                               return -EIO;
+                       jdelay(PAGE_WAIT);
+                       if (i2c_getdata(t, 10, infobits))
+                               return -EIO;
 
-                               if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) &&   /* check FOUND-bit */
-                                       (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) ||
-                                       time_after_eq(jiffies, t->vdau[req->pgbuf].expire)))
-                               {               /* check if new page arrived */
-                                       if (i2c_senddata(t, 8, 0, 0, 0, -1) ||
-                                               i2c_getdata(t, VTX_PAGESIZE, t->vdau[req->pgbuf].pgbuf))
+                       if (!(infobits[8] & 0x10) && !(infobits[7] & 0xf0) &&   /* check FOUND-bit */
+                               (memcmp(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits)) ||
+                               time_after_eq(jiffies, t->vdau[req->pgbuf].expire)))
+                       {               /* check if new page arrived */
+                               if (i2c_senddata(t, 8, 0, 0, 0, -1) ||
+                                       i2c_getdata(t, VTX_PAGESIZE, t->vdau[req->pgbuf].pgbuf))
+                                       return -EIO;
+                               t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
+                               memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
+                               if (t->virtual_mode) {
+                                       /* Packet X/24 */
+                                       if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
+                                               i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 20 * 40))
+                                               return -EIO;
+                                       /* Packet X/27/0 */
+                                       if (i2c_senddata(t, 8, 0, 0x21, 0, -1) ||
+                                               i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 16 * 40))
+                                               return -EIO;
+                                       /* Packet 8/30/0...8/30/15
+                                        * FIXME: AFAIK, the 5249 does hamming-decoding for some bytes in packet 8/30,
+                                        *        so we should undo this here.
+                                        */
+                                       if (i2c_senddata(t, 8, 0, 0x22, 0, -1) ||
+                                               i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
                                                return -EIO;
-                                       t->vdau[req->pgbuf].expire = jiffies + PGBUF_EXPIRE;
-                                       memset(t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE, ' ', VTX_VIRTUALSIZE - VTX_PAGESIZE);
-                                       if (t->virtual_mode)
-                                       {
-                                               /* Packet X/24 */
-                                               if (i2c_senddata(t, 8, 0, 0x20, 0, -1) ||
-                                                       i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 20 * 40))
-                                                       return -EIO;
-                                               /* Packet X/27/0 */
-                                               if (i2c_senddata(t, 8, 0, 0x21, 0, -1) ||
-                                                       i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 16 * 40))
-                                                       return -EIO;
-                                               /* Packet 8/30/0...8/30/15
-                                                * FIXME: AFAIK, the 5249 does hamming-decoding for some bytes in packet 8/30,
-                                                *        so we should undo this here.
-                                                */
-                                               if (i2c_senddata(t, 8, 0, 0x22, 0, -1) ||
-                                                       i2c_getdata(t, 40, t->vdau[req->pgbuf].pgbuf + VTX_PAGESIZE + 23 * 40))
-                                                       return -EIO;
-                                       }
-                                       t->vdau[req->pgbuf].clrfound = false;
-                                       memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
-                               }
-                               else
-                               {
-                                       memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
                                }
-                       }
-                       else
-                       {
+                               t->vdau[req->pgbuf].clrfound = false;
+                               memcpy(t->vdau[req->pgbuf].laststat, infobits, sizeof(infobits));
+                       } else {
                                memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
                        }
+               } else {
+                       memcpy(infobits, t->vdau[req->pgbuf].laststat, sizeof(infobits));
+               }
 
-                       info.pagenum = ((infobits[8] << 8) & 0x700) | ((infobits[1] << 4) & 0xf0) | (infobits[0] & 0x0f);
-                       if (info.pagenum < 0x100)
-                               info.pagenum += 0x800;
-                       info.hour = ((infobits[5] << 4) & 0x30) | (infobits[4] & 0x0f);
-                       info.minute = ((infobits[3] << 4) & 0x70) | (infobits[2] & 0x0f);
-                       info.charset = ((infobits[7] >> 1) & 7);
-                       info.delete = !!(infobits[3] & 8);
-                       info.headline = !!(infobits[5] & 4);
-                       info.subtitle = !!(infobits[5] & 8);
-                       info.supp_header = !!(infobits[6] & 1);
-                       info.update = !!(infobits[6] & 2);
-                       info.inter_seq = !!(infobits[6] & 4);
-                       info.dis_disp = !!(infobits[6] & 8);
-                       info.serial = !!(infobits[7] & 1);
-                       info.notfound = !!(infobits[8] & 0x10);
-                       info.pblf = !!(infobits[9] & 0x20);
-                       info.hamming = 0;
-                       for (a = 0; a <= 7; a++)
-                       {
-                               if (infobits[a] & 0xf0)
-                               {
-                                       info.hamming = 1;
-                                       break;
-                               }
-                       }
-                       if (t->vdau[req->pgbuf].clrfound)
-                               info.notfound = 1;
-                       if(copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
-                               return -EFAULT;
-                       if (!info.hamming && !info.notfound)
-                       {
-                               t->is_searching[req->pgbuf] = false;
+               info.pagenum = ((infobits[8] << 8) & 0x700) | ((infobits[1] << 4) & 0xf0) | (infobits[0] & 0x0f);
+               if (info.pagenum < 0x100)
+                       info.pagenum += 0x800;
+               info.hour = ((infobits[5] << 4) & 0x30) | (infobits[4] & 0x0f);
+               info.minute = ((infobits[3] << 4) & 0x70) | (infobits[2] & 0x0f);
+               info.charset = ((infobits[7] >> 1) & 7);
+               info.delete = !!(infobits[3] & 8);
+               info.headline = !!(infobits[5] & 4);
+               info.subtitle = !!(infobits[5] & 8);
+               info.supp_header = !!(infobits[6] & 1);
+               info.update = !!(infobits[6] & 2);
+               info.inter_seq = !!(infobits[6] & 4);
+               info.dis_disp = !!(infobits[6] & 8);
+               info.serial = !!(infobits[7] & 1);
+               info.notfound = !!(infobits[8] & 0x10);
+               info.pblf = !!(infobits[9] & 0x20);
+               info.hamming = 0;
+               for (a = 0; a <= 7; a++) {
+                       if (infobits[a] & 0xf0) {
+                               info.hamming = 1;
+                               break;
                        }
-                       return 0;
                }
+               if (t->vdau[req->pgbuf].clrfound)
+                       info.notfound = 1;
+               if (copy_to_user(req->buffer, &info, sizeof(vtx_pageinfo_t)))
+                       return -EFAULT;
+               if (!info.hamming && !info.notfound)
+                       t->is_searching[req->pgbuf] = false;
+               return 0;
+       }
 
-               case VTXIOCGETPAGE:
-               {
-                       vtx_pagereq_t *req = arg;
-                       int start, end;
-
-                       if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS || req->start < 0 ||
-                               req->start > req->end || req->end >= (virtual_mode ? VTX_VIRTUALSIZE : VTX_PAGESIZE))
-                               return -EINVAL;
-                       if(copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1))
+       case VTXIOCGETPAGE:
+       {
+               vtx_pagereq_t *req = arg;
+               int start, end;
+
+               if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS || req->start < 0 ||
+                       req->start > req->end || req->end >= (virtual_mode ? VTX_VIRTUALSIZE : VTX_PAGESIZE))
+                       return -EINVAL;
+               if (copy_to_user(req->buffer, &t->vdau[req->pgbuf].pgbuf[req->start], req->end - req->start + 1))
+                       return -EFAULT;
+
+                /*
+                 *     Always read the time directly from SAA5249
+                 */
+
+               if (req->start <= 39 && req->end >= 32) {
+                       int len;
+                       char buf[16];
+                       start = max(req->start, 32);
+                       end = min(req->end, 39);
+                       len = end - start + 1;
+                       if (i2c_senddata(t, 8, 0, 0, start, -1) ||
+                               i2c_getdata(t, len, buf))
+                               return -EIO;
+                       if (copy_to_user(req->buffer + start - req->start, buf, len))
+                               return -EFAULT;
+               }
+               /* Insert the current header if DAU is still searching for a page */
+               if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf]) {
+                       char buf[32];
+                       int len;
+
+                       start = max(req->start, 7);
+                       end = min(req->end, 31);
+                       len = end - start + 1;
+                       if (i2c_senddata(t, 8, 0, 0, start, -1) ||
+                               i2c_getdata(t, len, buf))
+                               return -EIO;
+                       if (copy_to_user(req->buffer + start - req->start, buf, len))
                                return -EFAULT;
-
-                        /*
-                         *     Always read the time directly from SAA5249
-                         */
-
-                       if (req->start <= 39 && req->end >= 32)
-                       {
-                               int len;
-                               char buf[16];
-                               start = max(req->start, 32);
-                               end = min(req->end, 39);
-                               len=end-start+1;
-                               if (i2c_senddata(t, 8, 0, 0, start, -1) ||
-                                       i2c_getdata(t, len, buf))
-                                       return -EIO;
-                               if(copy_to_user(req->buffer+start-req->start, buf, len))
-                                       return -EFAULT;
-                       }
-                       /* Insert the current header if DAU is still searching for a page */
-                       if (req->start <= 31 && req->end >= 7 && t->is_searching[req->pgbuf])
-                       {
-                               char buf[32];
-                               int len;
-                               start = max(req->start, 7);
-                               end = min(req->end, 31);
-                               len=end-start+1;
-                               if (i2c_senddata(t, 8, 0, 0, start, -1) ||
-                                       i2c_getdata(t, len, buf))
-                                       return -EIO;
-                               if(copy_to_user(req->buffer+start-req->start, buf, len))
-                                       return -EFAULT;
-                       }
-                       return 0;
                }
+               return 0;
+       }
 
-               case VTXIOCSTOPDAU:
-               {
-                       vtx_pagereq_t *req = arg;
+       case VTXIOCSTOPDAU:
+       {
+               vtx_pagereq_t *req = arg;
 
-                       if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
-                               return -EINVAL;
-                       t->vdau[req->pgbuf].stopped = true;
-                       t->is_searching[req->pgbuf] = false;
-                       return 0;
-               }
+               if (req->pgbuf < 0 || req->pgbuf >= NUM_DAUS)
+                       return -EINVAL;
+               t->vdau[req->pgbuf].stopped = true;
+               t->is_searching[req->pgbuf] = false;
+               return 0;
+       }
 
-               case VTXIOCPUTPAGE:
-               case VTXIOCSETDISP:
-               case VTXIOCPUTSTAT:
-                       return 0;
+       case VTXIOCPUTPAGE:
+       case VTXIOCSETDISP:
+       case VTXIOCPUTSTAT:
+               return 0;
 
-               case VTXIOCCLRCACHE:
-               {
-                       if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11,
-                               ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',
-                               ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ', -1))
-                               return -EIO;
-                       if (i2c_senddata(t, 3, 0x20, -1))
-                               return -EIO;
-                       jdelay(10 * CLEAR_DELAY);                       /* I have no idea how long we have to wait here */
-                       return 0;
-               }
+       case VTXIOCCLRCACHE:
+       {
+               if (i2c_senddata(t, 0, NUM_DAUS, 0, 8, -1) || i2c_senddata(t, 11,
+                       ' ', ' ', ' ', ' ', ' ', ' ',
+                       ' ', ' ', ' ', ' ', ' ', ' ',
+                       ' ', ' ', ' ', ' ', ' ', ' ',
+                       ' ', ' ', ' ', ' ', ' ', ' ',
+                       -1))
+                       return -EIO;
+               if (i2c_senddata(t, 3, 0x20, -1))
+                       return -EIO;
+               jdelay(10 * CLEAR_DELAY);                       /* I have no idea how long we have to wait here */
+               return 0;
+       }
 
-               case VTXIOCSETVIRT:
-               {
-                       /* The SAA5249 has virtual-row reception turned on always */
-                       t->virtual_mode = (int)(long)arg;
-                       return 0;
-               }
+       case VTXIOCSETVIRT:
+       {
+               /* The SAA5249 has virtual-row reception turned on always */
+               t->virtual_mode = (int)(long)arg;
+               return 0;
+       }
        }
        return -EINVAL;
 }
@@ -616,8 +483,7 @@ static inline unsigned int vtx_fix_command(unsigned int cmd)
 static int saa5249_ioctl(struct inode *inode, struct file *file,
                         unsigned int cmd, unsigned long arg)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5249_device *t=vd->priv;
+       struct saa5249_device *t = video_drvdata(file);
        int err;
 
        cmd = vtx_fix_command(cmd);
@@ -629,32 +495,27 @@ static int saa5249_ioctl(struct inode *inode, struct file *file,
 
 static int saa5249_open(struct inode *inode, struct file *file)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5249_device *t=vd->priv;
-       int err,pgbuf;
+       struct saa5249_device *t = video_drvdata(file);
+       int pgbuf;
 
-       err = video_exclusive_open(inode,file);
-       if (err < 0)
-               return err;
+       if (t->client == NULL)
+               return -ENODEV;
 
-       if (t->client==NULL) {
-               err = -ENODEV;
-               goto fail;
-       }
+       if (test_and_set_bit(0, &t->in_use))
+               return -EBUSY;
 
-       if (i2c_senddata(t, 0, 0, -1) ||                /* Select R11 */
-                                               /* Turn off parity checks (we do this ourselves) */
+       if (i2c_senddata(t, 0, 0, -1) || /* Select R11 */
+               /* Turn off parity checks (we do this ourselves) */
                i2c_senddata(t, 1, disp_modes[t->disp_mode][0], 0, -1) ||
-                                               /* Display TV-picture, no virtual rows */
-               i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1)) /* Set display to page 4 */
-
+               /* Display TV-picture, no virtual rows */
+               i2c_senddata(t, 4, NUM_DAUS, disp_modes[t->disp_mode][1], disp_modes[t->disp_mode][2], 7, -1))
+               /* Set display to page 4 */
        {
-               err = -EIO;
-               goto fail;
+               clear_bit(0, &t->in_use);
+               return -EIO;
        }
 
-       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++)
-       {
+       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
                memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
                memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
                memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
@@ -665,39 +526,20 @@ static int saa5249_open(struct inode *inode, struct file *file)
        }
        t->virtual_mode = false;
        return 0;
-
- fail:
-       video_exclusive_release(inode,file);
-       return err;
 }
 
 
 
 static int saa5249_release(struct inode *inode, struct file *file)
 {
-       struct video_device *vd = video_devdata(file);
-       struct saa5249_device *t=vd->priv;
+       struct saa5249_device *t = video_drvdata(file);
+
        i2c_senddata(t, 1, 0x20, -1);           /* Turn off CCT */
        i2c_senddata(t, 5, 3, 3, -1);           /* Turn off TV-display */
-       video_exclusive_release(inode,file);
+       clear_bit(0, &t->in_use);
        return 0;
 }
 
-static int __init init_saa_5249 (void)
-{
-       printk(KERN_INFO "SAA5249 driver (" IF_NAME " interface) for VideoText version %d.%d\n",
-                       VTX_VER_MAJ, VTX_VER_MIN);
-       return i2c_add_driver(&i2c_driver_videotext);
-}
-
-static void __exit cleanup_saa_5249 (void)
-{
-       i2c_del_driver(&i2c_driver_videotext);
-}
-
-module_init(init_saa_5249);
-module_exit(cleanup_saa_5249);
-
 static const struct file_operations saa_fops = {
        .owner          = THIS_MODULE,
        .open           = saa5249_open,
@@ -711,8 +553,84 @@ static const struct file_operations saa_fops = {
 
 static struct video_device saa_template =
 {
-       .name           = IF_NAME,
+       .name           = "saa5249",
        .fops           = &saa_fops,
+       .release        = video_device_release,
 };
 
-MODULE_LICENSE("GPL");
+/* Addresses to scan */
+static unsigned short normal_i2c[] = { 0x22 >> 1, I2C_CLIENT_END };
+
+I2C_CLIENT_INSMOD;
+
+static int saa5249_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       int pgbuf;
+       int err;
+       struct video_device *vd;
+       struct saa5249_device *t;
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
+       v4l_info(client, "VideoText version %d.%d\n",
+                       VTX_VER_MAJ, VTX_VER_MIN);
+       t = kzalloc(sizeof(*t), GFP_KERNEL);
+       if (t == NULL)
+               return -ENOMEM;
+       mutex_init(&t->lock);
+
+       /* Now create a video4linux device */
+       vd = kmalloc(sizeof(struct video_device), GFP_KERNEL);
+       if (vd == NULL) {
+               kfree(client);
+               return -ENOMEM;
+       }
+       i2c_set_clientdata(client, vd);
+       memcpy(vd, &saa_template, sizeof(*vd));
+
+       for (pgbuf = 0; pgbuf < NUM_DAUS; pgbuf++) {
+               memset(t->vdau[pgbuf].pgbuf, ' ', sizeof(t->vdau[0].pgbuf));
+               memset(t->vdau[pgbuf].sregs, 0, sizeof(t->vdau[0].sregs));
+               memset(t->vdau[pgbuf].laststat, 0, sizeof(t->vdau[0].laststat));
+               t->vdau[pgbuf].expire = 0;
+               t->vdau[pgbuf].clrfound = true;
+               t->vdau[pgbuf].stopped = true;
+               t->is_searching[pgbuf] = false;
+       }
+       video_set_drvdata(vd, t);
+
+       /* Register it */
+       err = video_register_device(vd, VFL_TYPE_VTX, -1);
+       if (err < 0) {
+               kfree(t);
+               kfree(vd);
+               return err;
+       }
+       t->client = client;
+       return 0;
+}
+
+static int saa5249_remove(struct i2c_client *client)
+{
+       struct video_device *vd = i2c_get_clientdata(client);
+
+       video_unregister_device(vd);
+       kfree(video_get_drvdata(vd));
+       kfree(vd);
+       return 0;
+}
+
+static const struct i2c_device_id saa5249_id[] = {
+       { "saa5249", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, saa5249_id);
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "saa5249",
+       .driverid = I2C_DRIVERID_SAA5249,
+       .probe = saa5249_probe,
+       .remove = saa5249_remove,
+       .id_table = saa5249_id,
+};
index ad733caec720f1b782921f5b4718ea56fdf246f7..c8e9cb3db30a9651692e3c4d732cca6a82643c06 100644 (file)
@@ -1057,7 +1057,7 @@ static void saa711x_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
        for (i = 0; i <= 23; i++)
                lcr[i] = 0xff;
 
-       if (fmt->service_set == 0) {
+       if (fmt == NULL) {
                /* raw VBI */
                if (is_50hz)
                        for (i = 6; i <= 23; i++)
@@ -1113,7 +1113,7 @@ static void saa711x_set_lcr(struct i2c_client *client, struct v4l2_sliced_vbi_fo
        }
 
        /* enable/disable raw VBI capturing */
-       saa711x_writeregs(client, fmt->service_set == 0 ?
+       saa711x_writeregs(client, fmt == NULL ?
                                saa7115_cfg_vbi_on :
                                saa7115_cfg_vbi_off);
 }
@@ -1153,6 +1153,10 @@ static int saa711x_set_v4lfmt(struct i2c_client *client, struct v4l2_format *fmt
                saa711x_set_lcr(client, &fmt->fmt.sliced);
                return 0;
        }
+       if (fmt->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
+               saa711x_set_lcr(client, NULL);
+               return 0;
+       }
        if (fmt->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
                return -EINVAL;
 
@@ -1309,10 +1313,13 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
        case VIDIOC_INT_S_VIDEO_ROUTING:
        {
                struct v4l2_routing *route = arg;
+               u32 input = route->input;
+               u8 mask = (state->ident == V4L2_IDENT_SAA7111) ? 0xf8 : 0xf0;
 
                v4l_dbg(1, debug, client, "decoder set input %d output %d\n", route->input, route->output);
-               /* saa7113 does not have these inputs */
-               if (state->ident == V4L2_IDENT_SAA7113 &&
+               /* saa7111/3 does not have these inputs */
+               if ((state->ident == V4L2_IDENT_SAA7113 ||
+                    state->ident == V4L2_IDENT_SAA7111) &&
                    (route->input == SAA7115_COMPOSITE4 ||
                     route->input == SAA7115_COMPOSITE5)) {
                        return -EINVAL;
@@ -1327,10 +1334,23 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
                        (route->input >= SAA7115_SVIDEO0) ? "S-Video" : "Composite", (route->output == SAA7115_IPORT_ON) ? "iport on" : "iport off");
                state->input = route->input;
 
+               /* saa7111 has slightly different input numbering */
+               if (state->ident == V4L2_IDENT_SAA7111) {
+                       if (input >= SAA7115_COMPOSITE4)
+                               input -= 2;
+                       /* saa7111 specific */
+                       saa711x_write(client, R_10_CHROMA_CNTL_2,
+                                       (saa711x_read(client, R_10_CHROMA_CNTL_2) & 0x3f) |
+                                       ((route->output & 0xc0) ^ 0x40));
+                       saa711x_write(client, R_13_RT_X_PORT_OUT_CNTL,
+                                       (saa711x_read(client, R_13_RT_X_PORT_OUT_CNTL) & 0xf0) |
+                                       ((route->output & 2) ? 0x0a : 0));
+               }
+
                /* select mode */
                saa711x_write(client, R_02_INPUT_CNTL_1,
-                             (saa711x_read(client, R_02_INPUT_CNTL_1) & 0xf0) |
-                              state->input);
+                             (saa711x_read(client, R_02_INPUT_CNTL_1) & mask) |
+                              input);
 
                /* bypass chrominance trap for S-Video modes */
                saa711x_write(client, R_09_LUMA_CNTL,
@@ -1384,6 +1404,13 @@ static int saa7115_command(struct i2c_client *client, unsigned int cmd, void *ar
                saa711x_writeregs(client, saa7115_cfg_reset_scaler);
                break;
 
+       case VIDIOC_INT_S_GPIO:
+               if (state->ident != V4L2_IDENT_SAA7111)
+                       return -EINVAL;
+               saa711x_write(client, 0x11, (saa711x_read(client, 0x11) & 0x7f) |
+                       (*(u32 *)arg ? 0x80 : 0));
+               break;
+
        case VIDIOC_INT_G_VBI_DATA:
        {
                struct v4l2_sliced_vbi_data *data = arg;
@@ -1539,7 +1566,8 @@ static int saa7115_probe(struct i2c_client *client,
                state->crystal_freq = SAA7115_FREQ_32_11_MHZ;
                saa711x_writeregs(client, saa7115_init_auto_input);
        }
-       saa711x_writeregs(client, saa7115_init_misc);
+       if (state->ident != V4L2_IDENT_SAA7111)
+               saa711x_writeregs(client, saa7115_init_misc);
        saa711x_set_v4lstd(client, V4L2_STD_NTSC);
 
        v4l_dbg(1, debug, client, "status: (1E) 0x%02x, (1F) 0x%02x\n",
index 707be175509dbebcf00f1833ae7fc622e43c7c0d..1fb6eccdade32ac5f22a1c6493914e6ce041bc8c 100644 (file)
@@ -1,3 +1,27 @@
+ /*
+    saa6752hs - i2c-driver for the saa6752hs by Philips
+
+    Copyright (C) 2004 Andrew de Quincey
+
+    AC-3 support:
+
+    Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
+
+    This program is free software; you can redistribute it and/or modify
+    it under the terms of the GNU General Public License vs published by
+    the Free Software Foundation; either version 2 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program; if not, write to the Free Software
+    Foundation, Inc., 675 Mvss Ave, Cambridge, MA 02139, USA.
+  */
+
 #include <linux/module.h>
 #include <linux/kernel.h>
 #include <linux/string.h>
@@ -10,6 +34,8 @@
 #include <linux/types.h>
 #include <linux/videodev2.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
+#include <media/v4l2-i2c-drv-legacy.h>
 #include <linux/init.h>
 #include <linux/crc32.h>
 
@@ -27,9 +53,6 @@ MODULE_DESCRIPTION("device driver for saa6752hs MPEG2 encoder");
 MODULE_AUTHOR("Andrew de Quincey");
 MODULE_LICENSE("GPL");
 
-static struct i2c_driver driver;
-static struct i2c_client client_template;
-
 enum saa6752hs_videoformat {
        SAA6752HS_VF_D1 = 0,    /* standard D1 video format: 720x576 */
        SAA6752HS_VF_2_3_D1 = 1,/* 2/3D1 video format: 480x576 */
@@ -46,7 +69,9 @@ struct saa6752hs_mpeg_params {
        __u16                           ts_pid_pcr;
 
        /* audio */
-       enum v4l2_mpeg_audio_l2_bitrate au_l2_bitrate;
+       enum v4l2_mpeg_audio_encoding    au_encoding;
+       enum v4l2_mpeg_audio_l2_bitrate  au_l2_bitrate;
+       enum v4l2_mpeg_audio_ac3_bitrate au_ac3_bitrate;
 
        /* video */
        enum v4l2_mpeg_video_aspect     vi_aspect;
@@ -70,7 +95,9 @@ static const struct v4l2_format v4l2_format_table[] =
 };
 
 struct saa6752hs_state {
-       struct i2c_client             client;
+       int                           chip;
+       u32                           revision;
+       int                           has_ac3;
        struct saa6752hs_mpeg_params  params;
        enum saa6752hs_videoformat    video_format;
        v4l2_std_id                   standard;
@@ -145,6 +172,39 @@ static u8 PMT[] = {
        0x00, 0x00, 0x00, 0x00 /* CRC32 */
 };
 
+static u8 PMT_AC3[] = {
+       0xc2, /* i2c register */
+       0x01, /* table number for encoder(1) */
+       0x47, /* sync */
+
+       0x40, /* transport_error_indicator(0), payload_unit_start(1), transport_priority(0) */
+       0x10, /* PMT PID (0x0010) */
+       0x10, /* transport_scrambling_control(00), adaptation_field_control(01), continuity_counter(0) */
+
+       0x00, /* PSI pointer to start of table */
+
+       0x02, /* TID (2) */
+       0xb0, 0x1a, /* section_syntax_indicator(1), section_length(26) */
+
+       0x00, 0x01, /* program_number(1) */
+
+       0xc1, /* version_number(0), current_next_indicator(1) */
+
+       0x00, 0x00, /* section_number(0), last_section_number(0) */
+
+       0xe1, 0x04, /* PCR_PID (0x0104) */
+
+       0xf0, 0x00, /* program_info_length(0) */
+
+       0x02, 0xe1, 0x00, 0xf0, 0x00, /* video stream type(2), pid */
+       0x06, 0xe1, 0x03, 0xf0, 0x03, /* audio stream type(6), pid */
+       0x6a, /* AC3 */
+       0x01, /* Descriptor_length(1) */
+       0x00, /* component_type_flag(0), bsid_flag(0), mainid_flag(0), asvc_flag(0), reserved flags(0) */
+
+       0xED, 0xDE, 0x2D, 0xF3 /* CRC32 BE */
+};
+
 static struct saa6752hs_mpeg_params param_defaults =
 {
        .ts_pid_pmt      = 16,
@@ -157,12 +217,14 @@ static struct saa6752hs_mpeg_params param_defaults =
        .vi_bitrate_peak = 6000,
        .vi_bitrate_mode = V4L2_MPEG_VIDEO_BITRATE_MODE_VBR,
 
+       .au_encoding     = V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
        .au_l2_bitrate   = V4L2_MPEG_AUDIO_L2_BITRATE_256K,
+       .au_ac3_bitrate  = V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
 };
 
 /* ---------------------------------------------------------------------- */
 
-static int saa6752hs_chip_command(struct i2c_clientclient,
+static int saa6752hs_chip_command(struct i2c_client *client,
                                  enum saa6752hs_command command)
 {
        unsigned char buf[3];
@@ -229,45 +291,61 @@ static int saa6752hs_chip_command(struct i2c_client* client,
 }
 
 
-static int saa6752hs_set_bitrate(struct i2c_client* client,
-                                struct saa6752hs_mpeg_params* params)
+static inline void set_reg8(struct i2c_client *client, uint8_t reg, uint8_t val)
+{
+       u8 buf[2];
+
+       buf[0] = reg;
+       buf[1] = val;
+       i2c_master_send(client, buf, 2);
+}
+
+static inline void set_reg16(struct i2c_client *client, uint8_t reg, uint16_t val)
 {
        u8 buf[3];
+
+       buf[0] = reg;
+       buf[1] = val >> 8;
+       buf[2] = val & 0xff;
+       i2c_master_send(client, buf, 3);
+}
+
+static int saa6752hs_set_bitrate(struct i2c_client *client,
+                                struct saa6752hs_state *h)
+{
+       struct saa6752hs_mpeg_params *params = &h->params;
        int tot_bitrate;
+       int is_384k;
 
        /* set the bitrate mode */
-       buf[0] = 0x71;
-       buf[1] = (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) ? 0 : 1;
-       i2c_master_send(client, buf, 2);
+       set_reg8(client, 0x71,
+               params->vi_bitrate_mode != V4L2_MPEG_VIDEO_BITRATE_MODE_VBR);
 
        /* set the video bitrate */
        if (params->vi_bitrate_mode == V4L2_MPEG_VIDEO_BITRATE_MODE_VBR) {
                /* set the target bitrate */
-               buf[0] = 0x80;
-               buf[1] = params->vi_bitrate >> 8;
-               buf[2] = params->vi_bitrate & 0xff;
-               i2c_master_send(client, buf, 3);
+               set_reg16(client, 0x80, params->vi_bitrate);
 
                /* set the max bitrate */
-               buf[0] = 0x81;
-               buf[1] = params->vi_bitrate_peak >> 8;
-               buf[2] = params->vi_bitrate_peak & 0xff;
-               i2c_master_send(client, buf, 3);
+               set_reg16(client, 0x81, params->vi_bitrate_peak);
                tot_bitrate = params->vi_bitrate_peak;
        } else {
                /* set the target bitrate (no max bitrate for CBR) */
-               buf[0] = 0x81;
-               buf[1] = params->vi_bitrate >> 8;
-               buf[2] = params->vi_bitrate & 0xff;
-               i2c_master_send(client, buf, 3);
+               set_reg16(client, 0x81, params->vi_bitrate);
                tot_bitrate = params->vi_bitrate;
        }
 
+       /* set the audio encoding */
+       set_reg8(client, 0x93,
+                       params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3);
+
        /* set the audio bitrate */
-       buf[0] = 0x94;
-       buf[1] = (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 0 : 1;
-       i2c_master_send(client, buf, 2);
-       tot_bitrate += (V4L2_MPEG_AUDIO_L2_BITRATE_256K == params->au_l2_bitrate) ? 256 : 384;
+       if (params->au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3)
+               is_384k = V4L2_MPEG_AUDIO_AC3_BITRATE_384K == params->au_ac3_bitrate;
+       else
+               is_384k = V4L2_MPEG_AUDIO_L2_BITRATE_384K == params->au_l2_bitrate;
+       set_reg8(client, 0x94, is_384k);
+       tot_bitrate += is_384k ? 384 : 256;
 
        /* Note: the total max bitrate is determined by adding the video and audio
           bitrates together and also adding an extra 768kbit/s to stay on the
@@ -278,16 +356,12 @@ static int saa6752hs_set_bitrate(struct i2c_client* client,
                tot_bitrate = MPEG_TOTAL_TARGET_BITRATE_MAX;
 
        /* set the total bitrate */
-       buf[0] = 0xb1;
-       buf[1] = tot_bitrate >> 8;
-       buf[2] = tot_bitrate & 0xff;
-       i2c_master_send(client, buf, 3);
-
+       set_reg16(client, 0xb1, tot_bitrate);
        return 0;
 }
 
-static void saa6752hs_set_subsampling(struct i2c_clientclient,
-                                     struct v4l2_formatf)
+static void saa6752hs_set_subsampling(struct i2c_client *client,
+                                     struct v4l2_format *f)
 {
        struct saa6752hs_state *h = i2c_get_clientdata(client);
        int dist_352, dist_480, dist_720;
@@ -332,7 +406,7 @@ static void saa6752hs_set_subsampling(struct i2c_client* client,
 }
 
 
-static int handle_ctrl(struct saa6752hs_mpeg_params *params,
+static int handle_ctrl(int has_ac3, struct saa6752hs_mpeg_params *params,
                struct v4l2_ext_control *ctrl, unsigned int cmd)
 {
        int old = 0, new;
@@ -379,8 +453,9 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
                        params->ts_pid_pcr = new;
                        break;
                case V4L2_CID_MPEG_AUDIO_ENCODING:
-                       old = V4L2_MPEG_AUDIO_ENCODING_LAYER_2;
-                       if (set && new != old)
+                       old = params->au_encoding;
+                       if (set && new != V4L2_MPEG_AUDIO_ENCODING_LAYER_2 &&
+                           (!has_ac3 || new != V4L2_MPEG_AUDIO_ENCODING_AC3))
                                return -ERANGE;
                        new = old;
                        break;
@@ -395,6 +470,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
                                new = V4L2_MPEG_AUDIO_L2_BITRATE_384K;
                        params->au_l2_bitrate = new;
                        break;
+               case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
+                       if (!has_ac3)
+                               return -EINVAL;
+                       old = params->au_ac3_bitrate;
+                       if (set && new != V4L2_MPEG_AUDIO_AC3_BITRATE_256K &&
+                                  new != V4L2_MPEG_AUDIO_AC3_BITRATE_384K)
+                               return -ERANGE;
+                       if (new <= V4L2_MPEG_AUDIO_AC3_BITRATE_256K)
+                               new = V4L2_MPEG_AUDIO_AC3_BITRATE_256K;
+                       else
+                               new = V4L2_MPEG_AUDIO_AC3_BITRATE_384K;
+                       params->au_ac3_bitrate = new;
+                       break;
                case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
                        old = V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000;
                        if (set && new != old)
@@ -448,17 +536,19 @@ static int handle_ctrl(struct saa6752hs_mpeg_params *params,
        return 0;
 }
 
-static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
+static int saa6752hs_qctrl(struct saa6752hs_state *h,
                struct v4l2_queryctrl *qctrl)
 {
+       struct saa6752hs_mpeg_params *params = &h->params;
        int err;
 
        switch (qctrl->id) {
        case V4L2_CID_MPEG_AUDIO_ENCODING:
                return v4l2_ctrl_query_fill(qctrl,
                                V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
-                               V4L2_MPEG_AUDIO_ENCODING_LAYER_2, 1,
-                               V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
+                               h->has_ac3 ? V4L2_MPEG_AUDIO_ENCODING_AC3 :
+                                       V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
+                               1, V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
 
        case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
                return v4l2_ctrl_query_fill(qctrl,
@@ -466,6 +556,14 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
                                V4L2_MPEG_AUDIO_L2_BITRATE_384K, 1,
                                V4L2_MPEG_AUDIO_L2_BITRATE_256K);
 
+       case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
+               if (!h->has_ac3)
+                       return -EINVAL;
+               return v4l2_ctrl_query_fill(qctrl,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_384K, 1,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_256K);
+
        case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ:
                return v4l2_ctrl_query_fill(qctrl,
                                V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000,
@@ -512,44 +610,57 @@ static int saa6752hs_qctrl(struct saa6752hs_mpeg_params *params,
        return -EINVAL;
 }
 
-static int saa6752hs_qmenu(struct saa6752hs_mpeg_params *params,
+static int saa6752hs_qmenu(struct saa6752hs_state *h,
                struct v4l2_querymenu *qmenu)
 {
-       static const char *mpeg_audio_l2_bitrate[] = {
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "",
-               "256 kbps",
-               "",
-               "384 kbps",
-               NULL
+       static const u32 mpeg_audio_encoding[] = {
+               V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
+               V4L2_CTRL_MENU_IDS_END
+       };
+       static const u32 mpeg_audio_ac3_encoding[] = {
+               V4L2_MPEG_AUDIO_ENCODING_LAYER_2,
+               V4L2_MPEG_AUDIO_ENCODING_AC3,
+               V4L2_CTRL_MENU_IDS_END
+       };
+       static u32 mpeg_audio_l2_bitrate[] = {
+               V4L2_MPEG_AUDIO_L2_BITRATE_256K,
+               V4L2_MPEG_AUDIO_L2_BITRATE_384K,
+               V4L2_CTRL_MENU_IDS_END
+       };
+       static u32 mpeg_audio_ac3_bitrate[] = {
+               V4L2_MPEG_AUDIO_AC3_BITRATE_256K,
+               V4L2_MPEG_AUDIO_AC3_BITRATE_384K,
+               V4L2_CTRL_MENU_IDS_END
        };
        struct v4l2_queryctrl qctrl;
        int err;
 
        qctrl.id = qmenu->id;
-       err = saa6752hs_qctrl(params, &qctrl);
+       err = saa6752hs_qctrl(h, &qctrl);
        if (err)
                return err;
-       if (qmenu->id == V4L2_CID_MPEG_AUDIO_L2_BITRATE)
-               return v4l2_ctrl_query_menu(qmenu, &qctrl,
+       switch (qmenu->id) {
+       case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
+               return v4l2_ctrl_query_menu_valid_items(qmenu,
                                mpeg_audio_l2_bitrate);
-       return v4l2_ctrl_query_menu(qmenu, &qctrl,
-                       v4l2_ctrl_get_menu(qmenu->id));
+       case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
+               if (!h->has_ac3)
+                       return -EINVAL;
+               return v4l2_ctrl_query_menu_valid_items(qmenu,
+                               mpeg_audio_ac3_bitrate);
+       case V4L2_CID_MPEG_AUDIO_ENCODING:
+               return v4l2_ctrl_query_menu_valid_items(qmenu,
+                       h->has_ac3 ? mpeg_audio_ac3_encoding :
+                               mpeg_audio_encoding);
+       }
+       return v4l2_ctrl_query_menu(qmenu, &qctrl, NULL);
 }
 
-static int saa6752hs_init(struct i2c_client* client)
+static int saa6752hs_init(struct i2c_client *client, u32 leading_null_bytes)
 {
        unsigned char buf[9], buf2[4];
        struct saa6752hs_state *h;
+       unsigned size;
        u32 crc;
        unsigned char localPAT[256];
        unsigned char localPMT[256];
@@ -557,45 +668,31 @@ static int saa6752hs_init(struct i2c_client* client)
        h = i2c_get_clientdata(client);
 
        /* Set video format - must be done first as it resets other settings */
-       buf[0] = 0x41;
-       buf[1] = h->video_format;
-       i2c_master_send(client, buf, 2);
+       set_reg8(client, 0x41, h->video_format);
 
        /* Set number of lines in input signal */
-       buf[0] = 0x40;
-       buf[1] = 0x00;
-       if (h->standard & V4L2_STD_525_60)
-               buf[1] = 0x01;
-       i2c_master_send(client, buf, 2);
+       set_reg8(client, 0x40, (h->standard & V4L2_STD_525_60) ? 1 : 0);
 
        /* set bitrate */
-       saa6752hs_set_bitrate(client, &h->params);
+       saa6752hs_set_bitrate(client, h);
 
        /* Set GOP structure {3, 13} */
-       buf[0] = 0x72;
-       buf[1] = 0x03;
-       buf[2] = 0x0D;
-       i2c_master_send(client,buf,3);
+       set_reg16(client, 0x72, 0x030d);
 
        /* Set minimum Q-scale {4} */
-       buf[0] = 0x82;
-       buf[1] = 0x04;
-       i2c_master_send(client,buf,2);
+       set_reg8(client, 0x82, 0x04);
 
        /* Set maximum Q-scale {12} */
-       buf[0] = 0x83;
-       buf[1] = 0x0C;
-       i2c_master_send(client,buf,2);
+       set_reg8(client, 0x83, 0x0c);
 
        /* Set Output Protocol */
-       buf[0] = 0xD0;
-       buf[1] = 0x81;
-       i2c_master_send(client,buf,2);
+       set_reg8(client, 0xd0, 0x81);
 
        /* Set video output stream format {TS} */
-       buf[0] = 0xB0;
-       buf[1] = 0x05;
-       i2c_master_send(client,buf,2);
+       set_reg8(client, 0xb0, 0x05);
+
+       /* Set leading null byte for TS */
+       set_reg16(client, 0xf6, leading_null_bytes);
 
        /* compute PAT */
        memcpy(localPAT, PAT, sizeof(PAT));
@@ -608,7 +705,13 @@ static int saa6752hs_init(struct i2c_client* client)
        localPAT[sizeof(PAT) - 1] = crc & 0xFF;
 
        /* compute PMT */
-       memcpy(localPMT, PMT, sizeof(PMT));
+       if (h->params.au_encoding == V4L2_MPEG_AUDIO_ENCODING_AC3) {
+               size = sizeof(PMT_AC3);
+               memcpy(localPMT, PMT_AC3, size);
+       } else {
+               size = sizeof(PMT);
+               memcpy(localPMT, PMT, size);
+       }
        localPMT[3] = 0x40 | ((h->params.ts_pid_pmt >> 8) & 0x0f);
        localPMT[4] = h->params.ts_pid_pmt & 0xff;
        localPMT[15] = 0xE0 | ((h->params.ts_pid_pcr >> 8) & 0x0F);
@@ -617,40 +720,28 @@ static int saa6752hs_init(struct i2c_client* client)
        localPMT[21] = h->params.ts_pid_video & 0xFF;
        localPMT[25] = 0xE0 | ((h->params.ts_pid_audio >> 8) & 0x0F);
        localPMT[26] = h->params.ts_pid_audio & 0xFF;
-       crc = crc32_be(~0, &localPMT[7], sizeof(PMT) - 7 - 4);
-       localPMT[sizeof(PMT) - 4] = (crc >> 24) & 0xFF;
-       localPMT[sizeof(PMT) - 3] = (crc >> 16) & 0xFF;
-       localPMT[sizeof(PMT) - 2] = (crc >> 8) & 0xFF;
-       localPMT[sizeof(PMT) - 1] = crc & 0xFF;
+       crc = crc32_be(~0, &localPMT[7], size - 7 - 4);
+       localPMT[size - 4] = (crc >> 24) & 0xFF;
+       localPMT[size - 3] = (crc >> 16) & 0xFF;
+       localPMT[size - 2] = (crc >> 8) & 0xFF;
+       localPMT[size - 1] = crc & 0xFF;
 
        /* Set Audio PID */
-       buf[0] = 0xC1;
-       buf[1] = (h->params.ts_pid_audio >> 8) & 0xFF;
-       buf[2] = h->params.ts_pid_audio & 0xFF;
-       i2c_master_send(client,buf,3);
+       set_reg16(client, 0xc1, h->params.ts_pid_audio);
 
        /* Set Video PID */
-       buf[0] = 0xC0;
-       buf[1] = (h->params.ts_pid_video >> 8) & 0xFF;
-       buf[2] = h->params.ts_pid_video & 0xFF;
-       i2c_master_send(client,buf,3);
+       set_reg16(client, 0xc0, h->params.ts_pid_video);
 
        /* Set PCR PID */
-       buf[0] = 0xC4;
-       buf[1] = (h->params.ts_pid_pcr >> 8) & 0xFF;
-       buf[2] = h->params.ts_pid_pcr & 0xFF;
-       i2c_master_send(client,buf,3);
+       set_reg16(client, 0xc4, h->params.ts_pid_pcr);
 
        /* Send SI tables */
-       i2c_master_send(client,localPAT,sizeof(PAT));
-       i2c_master_send(client,localPMT,sizeof(PMT));
+       i2c_master_send(client, localPAT, sizeof(PAT));
+       i2c_master_send(client, localPMT, size);
 
        /* mute then unmute audio. This removes buzzing artefacts */
-       buf[0] = 0xa4;
-       buf[1] = 1;
-       i2c_master_send(client, buf, 2);
-       buf[1] = 0;
-       i2c_master_send(client, buf, 2);
+       set_reg8(client, 0xa4, 1);
+       set_reg8(client, 0xa4, 0);
 
        /* start it going */
        saa6752hs_chip_command(client, SAA6752HS_COMMAND_START);
@@ -688,45 +779,6 @@ static int saa6752hs_init(struct i2c_client* client)
        return 0;
 }
 
-static int saa6752hs_attach(struct i2c_adapter *adap, int addr, int kind)
-{
-       struct saa6752hs_state *h;
-
-
-       if (NULL == (h = kzalloc(sizeof(*h), GFP_KERNEL)))
-               return -ENOMEM;
-       h->client = client_template;
-       h->params = param_defaults;
-       h->client.adapter = adap;
-       h->client.addr = addr;
-
-       /* Assume 625 input lines */
-       h->standard = 0;
-
-       i2c_set_clientdata(&h->client, h);
-       i2c_attach_client(&h->client);
-
-       v4l_info(&h->client,"saa6752hs: chip found @ 0x%x\n", addr<<1);
-       return 0;
-}
-
-static int saa6752hs_probe(struct i2c_adapter *adap)
-{
-       if (adap->class & I2C_CLASS_TV_ANALOG)
-               return i2c_probe(adap, &addr_data, saa6752hs_attach);
-       return 0;
-}
-
-static int saa6752hs_detach(struct i2c_client *client)
-{
-       struct saa6752hs_state *h;
-
-       h = i2c_get_clientdata(client);
-       i2c_detach_client(client);
-       kfree(h);
-       return 0;
-}
-
 static int
 saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
 {
@@ -737,14 +789,13 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
        int i;
 
        switch (cmd) {
+       case VIDIOC_INT_INIT:
+               /* apply settings and start encoder */
+               saa6752hs_init(client, *(u32 *)arg);
+               break;
        case VIDIOC_S_EXT_CTRLS:
                if (ctrls->ctrl_class != V4L2_CTRL_CLASS_MPEG)
                        return -EINVAL;
-               if (ctrls->count == 0) {
-                       /* apply settings and start encoder */
-                       saa6752hs_init(client);
-                       break;
-               }
                /* fall through */
        case VIDIOC_TRY_EXT_CTRLS:
        case VIDIOC_G_EXT_CTRLS:
@@ -752,7 +803,8 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
                        return -EINVAL;
                params = h->params;
                for (i = 0; i < ctrls->count; i++) {
-                       if ((err = handle_ctrl(&params, ctrls->controls + i, cmd))) {
+                       err = handle_ctrl(h->has_ac3, &params, ctrls->controls + i, cmd);
+                       if (err) {
                                ctrls->error_idx = i;
                                return err;
                        }
@@ -760,9 +812,9 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
                h->params = params;
                break;
        case VIDIOC_QUERYCTRL:
-               return saa6752hs_qctrl(&h->params, arg);
+               return saa6752hs_qctrl(h, arg);
        case VIDIOC_QUERYMENU:
-               return saa6752hs_qmenu(&h->params, arg);
+               return saa6752hs_qmenu(h, arg);
        case VIDIOC_G_FMT:
        {
           struct v4l2_format *f = arg;
@@ -785,6 +837,11 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
        case VIDIOC_S_STD:
                h->standard = *((v4l2_std_id *) arg);
                break;
+
+       case VIDIOC_G_CHIP_IDENT:
+               return v4l2_chip_ident_i2c_client(client,
+                               arg, h->chip, h->revision);
+
        default:
                /* nothing */
                break;
@@ -793,36 +850,55 @@ saa6752hs_command(struct i2c_client *client, unsigned int cmd, void *arg)
        return err;
 }
 
-/* ----------------------------------------------------------------------- */
+static int saa6752hs_probe(struct i2c_client *client,
+                       const struct i2c_device_id *id)
+{
+       struct saa6752hs_state *h = kzalloc(sizeof(*h), GFP_KERNEL);
+       u8 addr = 0x13;
+       u8 data[12];
 
-static struct i2c_driver driver = {
-       .driver = {
-               .name   = "saa6752hs",
-       },
-       .id             = I2C_DRIVERID_SAA6752HS,
-       .attach_adapter = saa6752hs_probe,
-       .detach_client  = saa6752hs_detach,
-       .command        = saa6752hs_command,
-};
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
+       if (h == NULL)
+               return -ENOMEM;
 
-static struct i2c_client client_template =
-{
-       .name       = "saa6752hs",
-       .driver     = &driver,
-};
+       i2c_master_send(client, &addr, 1);
+       i2c_master_recv(client, data, sizeof(data));
+       h->chip = V4L2_IDENT_SAA6752HS;
+       h->revision = (data[8] << 8) | data[9];
+       h->has_ac3 = 0;
+       if (h->revision == 0x0206) {
+               h->chip = V4L2_IDENT_SAA6752HS_AC3;
+               h->has_ac3 = 1;
+               v4l_info(client, "support AC-3\n");
+       }
+       h->params = param_defaults;
+       h->standard = 0; /* Assume 625 input lines */
 
-static int __init saa6752hs_init_module(void)
-{
-       return i2c_add_driver(&driver);
+       i2c_set_clientdata(client, h);
+       return 0;
 }
 
-static void __exit saa6752hs_cleanup_module(void)
+static int saa6752hs_remove(struct i2c_client *client)
 {
-       i2c_del_driver(&driver);
+       kfree(i2c_get_clientdata(client));
+       return 0;
 }
 
-module_init(saa6752hs_init_module);
-module_exit(saa6752hs_cleanup_module);
+static const struct i2c_device_id saa6752hs_id[] = {
+       { "saa6752hs", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, saa6752hs_id);
+
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "saa6752hs",
+       .driverid = I2C_DRIVERID_SAA6752HS,
+       .command = saa6752hs_command,
+       .probe = saa6752hs_probe,
+       .remove = saa6752hs_remove,
+       .id_table = saa6752hs_id,
+};
 
 /*
  * Overrides for Emacs so that we follow Linus's tabbing style.
index 98364d171def6ba442c92b28e60125649d6cb7e6..ddc5402c5fb071c1db008c77e506d009fbcd4915 100644 (file)
@@ -3260,6 +3260,7 @@ struct saa7134_board saa7134_boards[] = {
        },
        [SAA7134_BOARD_HAUPPAUGE_HVR1110] = {
                /* Thomas Genty <tomlohave@gmail.com> */
+               /* David Bentham <db260179@hotmail.com> */
                .name           = "Hauppauge WinTV-HVR1110 DVB-T/Hybrid",
                .audio_clock    = 0x00187de7,
                .tuner_type     = TUNER_PHILIPS_TDA8290,
@@ -3268,23 +3269,26 @@ struct saa7134_board saa7134_boards[] = {
                .radio_addr     = ADDR_UNSET,
                .tuner_config   = 1,
                .mpeg           = SAA7134_MPEG_DVB,
+               .gpiomask       = 0x0200100,
                .inputs         = {{
                        .name = name_tv,
                        .vmux = 1,
                        .amux = TV,
                        .tv   = 1,
-               },{
-                       .name   = name_comp1,
-                       .vmux   = 3,
-                       .amux   = LINE2, /* FIXME: audio doesn't work on svideo/composite */
-               },{
-                       .name   = name_svideo,
-                       .vmux   = 8,
-                       .amux   = LINE2, /* FIXME: audio doesn't work on svideo/composite */
-               }},
+                       .gpio = 0x0000100,
+               }, {
+                       .name = name_comp1,
+                       .vmux = 3,
+                       .amux = LINE1,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 8,
+                       .amux = LINE1,
+               } },
                .radio = {
                        .name = name_radio,
-                       .amux   = TV,
+                       .amux = TV,
+                       .gpio = 0x0200100,
                },
        },
        [SAA7134_BOARD_CINERGY_HT_PCMCIA] = {
@@ -3388,6 +3392,42 @@ struct saa7134_board saa7134_boards[] = {
                        .amux = 0,
                },
        },
+       [SAA7134_BOARD_ENCORE_ENLTV_FM53] = {
+               .name           = "Encore ENLTV-FM v5.3",
+               .audio_clock    = 0x00200000,
+               .tuner_type     = TUNER_TNF_5335MF,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .gpiomask       = 0x7000,
+               .inputs         = { {
+                       .name = name_tv,
+                       .vmux = 1,
+                       .amux = 1,
+                       .tv   = 1,
+                       .gpio = 0x50000,
+               }, {
+                       .name = name_comp1,
+                       .vmux = 3,
+                       .amux = 2,
+                       .gpio = 0x2000,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 8,
+                       .amux = 2,
+                       .gpio = 0x2000,
+               } },
+               .radio = {
+                       .name = name_radio,
+                       .vmux = 1,
+                       .amux = 1,
+               },
+               .mute = {
+                       .name = name_mute,
+                       .gpio = 0xf000,
+                       .amux = 0,
+               },
+       },
        [SAA7134_BOARD_CINERGY_HT_PCI] = {
                .name           = "Terratec Cinergy HT PCI",
                .audio_clock    = 0x00187de7,
@@ -3631,6 +3671,40 @@ struct saa7134_board saa7134_boards[] = {
                        .tv     = 1,
                }},
        },
+       [SAA7134_BOARD_AVERMEDIA_M135A] = {
+               .name           = "Avermedia PCI pure analog (M135A)",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_PHILIPS_TDA8290,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .tuner_config   = 2,
+               .gpiomask       = 0x020200000,
+               .inputs         = {{
+                       .name = name_tv,
+                       .vmux = 1,
+                       .amux = TV,
+                       .tv   = 1,
+               }, {
+                       .name = name_comp1,
+                       .vmux = 3,
+                       .amux = LINE1,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 8,
+                       .amux = LINE1,
+               } },
+               .radio = {
+                       .name = name_radio,
+                       .amux = TV,
+                       .gpio = 0x00200000,
+               },
+               .mute = {
+                       .name = name_mute,
+                       .amux = TV,
+                       .gpio = 0x01,
+               },
+       },
        [SAA7134_BOARD_BEHOLD_401] = {
                /*       Beholder Intl. Ltd. 2008      */
                /*Dmitry Belimov <d.belimov@gmail.com> */
@@ -4409,6 +4483,129 @@ struct saa7134_board saa7134_boards[] = {
                /* no DVB support for now */
                /* .mpeg           = SAA7134_MPEG_DVB, */
        },
+       [SAA7134_BOARD_ASUSTeK_TIGER_3IN1] = {
+               .name           = "Asus Tiger 3in1",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_PHILIPS_TDA8290,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .tuner_config   = 2,
+               .gpiomask       = 1 << 21,
+               .mpeg           = SAA7134_MPEG_DVB,
+               .inputs         = {{
+                       .name = name_tv,
+                       .vmux = 1,
+                       .amux = TV,
+                       .tv   = 1,
+               }, {
+                       .name = name_comp,
+                       .vmux = 0,
+                       .amux = LINE2,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 8,
+                       .amux = LINE2,
+               } },
+               .radio = {
+                       .name = name_radio,
+                       .amux = TV,
+                       .gpio = 0x0200000,
+               },
+       },
+       [SAA7134_BOARD_REAL_ANGEL_220] = {
+               .name           = "Zogis Real Angel 220",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_TNF_5335MF,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .gpiomask       = 0x801a8087,
+               .inputs = { {
+                       .name   = name_tv,
+                       .vmux   = 3,
+                       .amux   = LINE2,
+                       .tv     = 1,
+                       .gpio   = 0x624000,
+               }, {
+                       .name   = name_comp1,
+                       .vmux   = 1,
+                       .amux   = LINE1,
+                       .gpio   = 0x624000,
+               }, {
+                       .name   = name_svideo,
+                       .vmux   = 1,
+                       .amux   = LINE1,
+                       .gpio   = 0x624000,
+               } },
+               .radio = {
+                       .name   = name_radio,
+                       .amux   = LINE2,
+                       .gpio   = 0x624001,
+               },
+               .mute = {
+                       .name = name_mute,
+                       .amux = TV,
+               },
+       },
+       [SAA7134_BOARD_ADS_INSTANT_HDTV_PCI] = {
+               .name           = "ADS Tech Instant HDTV",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_PHILIPS_TUV1236D,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .tda9887_conf   = TDA9887_PRESENT,
+               .mpeg           = SAA7134_MPEG_DVB,
+               .inputs         = { {
+                       .name = name_tv,
+                       .vmux = 1,
+                       .amux = TV,
+                       .tv   = 1,
+               }, {
+                       .name = name_comp,
+                       .vmux = 4,
+                       .amux = LINE1,
+               }, {
+                       .name = name_svideo,
+                       .vmux = 8,
+                       .amux = LINE1,
+               } },
+       },
+       [SAA7134_BOARD_ASUSTeK_TIGER] = {
+               .name           = "Asus Tiger Rev:1.00",
+               .audio_clock    = 0x00187de7,
+               .tuner_type     = TUNER_PHILIPS_TDA8290,
+               .radio_type     = UNSET,
+               .tuner_addr     = ADDR_UNSET,
+               .radio_addr     = ADDR_UNSET,
+               .tuner_config   = 0,
+               .mpeg           = SAA7134_MPEG_DVB,
+               .gpiomask       = 0x0200000,
+               .inputs = { {
+                       .name   = name_tv,
+                       .vmux   = 1,
+                       .amux   = TV,
+                       .tv     = 1,
+               }, {
+                       .name   = name_comp1,
+                       .vmux   = 3,
+                       .amux   = LINE2,
+               }, {
+                       .name   = name_comp2,
+                       .vmux   = 0,
+                       .amux   = LINE2,
+               }, {
+                       .name   = name_svideo,
+                       .vmux   = 8,
+                       .amux   = LINE2,
+               } },
+               .radio = {
+                       .name   = name_radio,
+                       .amux   = TV,
+                       .gpio   = 0x0200000,
+               },
+       },
 };
 
 const unsigned int saa7134_bcount = ARRAY_SIZE(saa7134_boards);
@@ -4776,6 +4973,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .driver_data  = SAA7134_BOARD_AVERMEDIA_GO_007_FM,
 
        },{
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
+               .subvendor    = 0x1461, /* Avermedia Technologies Inc */
+               .subdevice    = 0xf11d,
+               .driver_data  = SAA7134_BOARD_AVERMEDIA_M135A,
+       }, {
                .vendor       = PCI_VENDOR_ID_PHILIPS,
                .device       = PCI_DEVICE_ID_PHILIPS_SAA7130,
                .subvendor    = PCI_VENDOR_ID_PHILIPS,
@@ -5156,6 +5359,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .subdevice    = 0x230f,
                .driver_data  = SAA7134_BOARD_ENCORE_ENLTV_FM,
        },{
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7130,
+               .subvendor    = 0x1a7f,
+               .subdevice    = 0x2008,
+               .driver_data  = SAA7134_BOARD_ENCORE_ENLTV_FM53,
+       }, {
                .vendor       = PCI_VENDOR_ID_PHILIPS,
                .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
                .subvendor    = 0x153b,
@@ -5183,8 +5392,8 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .vendor       = PCI_VENDOR_ID_PHILIPS,
                .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
                .subvendor    = 0x1043,
-               .subdevice    = 0x4857,
-               .driver_data  = SAA7134_BOARD_ASUSTeK_P7131_DUAL,
+               .subdevice    = 0x4857,         /* REV:1.00 */
+               .driver_data  = SAA7134_BOARD_ASUSTeK_TIGER,
        },{
                .vendor       = PCI_VENDOR_ID_PHILIPS,
                .device       = PCI_DEVICE_ID_PHILIPS_SAA7134,
@@ -5413,6 +5622,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .subvendor    = 0x185b,
                .subdevice    = 0xc900,
                .driver_data  = SAA7134_BOARD_VIDEOMATE_T750,
+       }, {
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7133, /* SAA7135HL */
+               .subvendor    = 0x1421,
+               .subdevice    = 0x0380,
+               .driver_data  = SAA7134_BOARD_ADS_INSTANT_HDTV_PCI,
        }, {
                .vendor       = PCI_VENDOR_ID_PHILIPS,
                .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
@@ -5431,6 +5646,12 @@ struct pci_device_id saa7134_pci_tbl[] = {
                .subvendor    = 0x1461, /* Avermedia Technologies Inc */
                .subdevice    = 0xf636,
                .driver_data  = SAA7134_BOARD_AVERMEDIA_M103,
+       }, {
+               .vendor       = PCI_VENDOR_ID_PHILIPS,
+               .device       = PCI_DEVICE_ID_PHILIPS_SAA7133,
+               .subvendor    = 0x1043,
+               .subdevice    = 0x4878, /* REV:1.02G */
+               .driver_data  = SAA7134_BOARD_ASUSTeK_TIGER_3IN1,
        }, {
                /* --- boards without eeprom + subsystem ID --- */
                .vendor       = PCI_VENDOR_ID_PHILIPS,
@@ -5540,7 +5761,7 @@ static int saa7134_tda8290_callback(struct saa7134_dev *dev,
        return 0;
 }
 
-int saa7134_tuner_callback(void *priv, int command, int arg)
+int saa7134_tuner_callback(void *priv, int component, int command, int arg)
 {
        struct saa7134_dev *dev = priv;
        if (dev != NULL) {
@@ -5620,6 +5841,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_AVERMEDIA_STUDIO_507:
        case SAA7134_BOARD_AVERMEDIA_GO_007_FM:
        case SAA7134_BOARD_AVERMEDIA_777:
+       case SAA7134_BOARD_AVERMEDIA_M135A:
 /*      case SAA7134_BOARD_SABRENT_SBTTVFM:  */ /* not finished yet */
        case SAA7134_BOARD_VIDEOMATE_TV_PVR:
        case SAA7134_BOARD_VIDEOMATE_GOLD_PLUS:
@@ -5644,6 +5866,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_AVERMEDIA_A16AR:
        case SAA7134_BOARD_ENCORE_ENLTV:
        case SAA7134_BOARD_ENCORE_ENLTV_FM:
+       case SAA7134_BOARD_ENCORE_ENLTV_FM53:
        case SAA7134_BOARD_10MOONSTVMASTER3:
        case SAA7134_BOARD_BEHOLD_401:
        case SAA7134_BOARD_BEHOLD_403:
@@ -5656,6 +5879,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_BEHOLD_505FM:
        case SAA7134_BOARD_BEHOLD_507_9FM:
        case SAA7134_BOARD_GENIUS_TVGO_A11MCE:
+       case SAA7134_BOARD_REAL_ANGEL_220:
                dev->has_remote = SAA7134_REMOTE_GPIO;
                break;
        case SAA7134_BOARD_FLYDVBS_LR300:
@@ -5745,6 +5969,7 @@ int saa7134_board_init1(struct saa7134_dev *dev)
        case SAA7134_BOARD_PINNACLE_PCTV_110i:
        case SAA7134_BOARD_PINNACLE_PCTV_310i:
        case SAA7134_BOARD_UPMOST_PURPLE_TV:
+       case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
        case SAA7134_BOARD_HAUPPAUGE_HVR1110:
        case SAA7134_BOARD_BEHOLD_607_9FM:
        case SAA7134_BOARD_BEHOLD_M6:
@@ -5987,6 +6212,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
        case SAA7134_BOARD_PINNACLE_PCTV_310i:
        case SAA7134_BOARD_KWORLD_DVBT_210:
        case SAA7134_BOARD_TEVION_DVBT_220RF:
+       case SAA7134_BOARD_ASUSTeK_TIGER:
        case SAA7134_BOARD_ASUSTeK_P7131_DUAL:
        case SAA7134_BOARD_ASUSTeK_P7131_HYBRID_LNA:
        case SAA7134_BOARD_MEDION_MD8800_QUADRO:
@@ -6002,6 +6228,14 @@ int saa7134_board_init2(struct saa7134_dev *dev)
                i2c_transfer(&dev->i2c_adap, &msg, 1);
                break;
        }
+       case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
+       {
+               u8 data[] = { 0x3c, 0x33, 0x60};
+               struct i2c_msg msg = {.addr = 0x0b, .flags = 0, .buf = data,
+                                                       .len = sizeof(data)};
+               i2c_transfer(&dev->i2c_adap, &msg, 1);
+               break;
+       }
        case SAA7134_BOARD_FLYDVB_TRIO:
        {
                u8 data[] = { 0x3c, 0x33, 0x62};
@@ -6027,6 +6261,7 @@ int saa7134_board_init2(struct saa7134_dev *dev)
                i2c_transfer(&dev->i2c_adap, &msg, 1);
                break;
        }
+       case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
        case SAA7134_BOARD_KWORLD_ATSC110:
        {
                /* enable tuner */
index 75d618415f4f401e9b9239e8d936ef8d8d0647eb..b686bfabbde0defb53a765a8b3bf8978e1f21b0a 100644 (file)
@@ -215,7 +215,7 @@ unsigned long saa7134_buffer_base(struct saa7134_buf *buf)
 int saa7134_pgtable_alloc(struct pci_dev *pci, struct saa7134_pgtable *pt)
 {
        __le32       *cpu;
-       dma_addr_t   dma_addr;
+       dma_addr_t   dma_addr = 0;
 
        cpu = pci_alloc_consistent(pci, SAA7134_PGTABLE_SIZE, &dma_addr);
        if (NULL == cpu)
@@ -359,32 +359,6 @@ void saa7134_buffer_timeout(unsigned long data)
        spin_unlock_irqrestore(&dev->slock,flags);
 }
 
-/* resends a current buffer in queue after resume */
-
-static int saa7134_buffer_requeue(struct saa7134_dev *dev,
-                                 struct saa7134_dmaqueue *q)
-{
-       struct saa7134_buf *buf, *next;
-
-       assert_spin_locked(&dev->slock);
-
-       buf  = q->curr;
-       next = buf;
-       dprintk("buffer_requeue\n");
-
-       if (!buf)
-               return 0;
-
-       dprintk("buffer_requeue : resending active buffers \n");
-
-       if (!list_empty(&q->queue))
-               next = list_entry(q->queue.next, struct saa7134_buf,
-                                         vb.queue);
-       buf->activate(dev, buf, next);
-
-       return 0;
-}
-
 /* ------------------------------------------------------------------ */
 
 int saa7134_set_dmabits(struct saa7134_dev *dev)
@@ -442,9 +416,7 @@ int saa7134_set_dmabits(struct saa7134_dev *dev)
        /* TS capture -- dma 5 */
        if (dev->ts_q.curr) {
                ctrl |= SAA7134_MAIN_CTRL_TE5;
-               irq  |= SAA7134_IRQ1_INTE_RA2_3 |
-                       SAA7134_IRQ1_INTE_RA2_2 |
-                       SAA7134_IRQ1_INTE_RA2_1 |
+               irq  |= SAA7134_IRQ1_INTE_RA2_1 |
                        SAA7134_IRQ1_INTE_RA2_0;
        }
 
@@ -727,6 +699,10 @@ static int saa7134_hw_enable2(struct saa7134_dev *dev)
                        irq2_mask |= SAA7134_IRQ2_INTE_GPIO18A;
        }
 
+       if (dev->has_remote == SAA7134_REMOTE_I2C) {
+               request_module("ir-kbd-i2c");
+       }
+
        saa_writel(SAA7134_IRQ1, 0);
        saa_writel(SAA7134_IRQ2, irq2_mask);
 
@@ -1139,6 +1115,32 @@ static void __devexit saa7134_finidev(struct pci_dev *pci_dev)
 }
 
 #ifdef CONFIG_PM
+
+/* resends a current buffer in queue after resume */
+static int saa7134_buffer_requeue(struct saa7134_dev *dev,
+                                 struct saa7134_dmaqueue *q)
+{
+       struct saa7134_buf *buf, *next;
+
+       assert_spin_locked(&dev->slock);
+
+       buf  = q->curr;
+       next = buf;
+       dprintk("buffer_requeue\n");
+
+       if (!buf)
+               return 0;
+
+       dprintk("buffer_requeue : resending active buffers \n");
+
+       if (!list_empty(&q->queue))
+               next = list_entry(q->queue.next, struct saa7134_buf,
+                                         vb.queue);
+       buf->activate(dev, buf, next);
+
+       return 0;
+}
+
 static int saa7134_suspend(struct pci_dev *pci_dev , pm_message_t state)
 {
 
index be48b9b66a67ef9833daaeb3a4709b1dbddbb39d..87c10983266f3392f3f4fa173e6046bd60e77e71 100644 (file)
@@ -553,7 +553,6 @@ static int configure_tda827x_fe(struct saa7134_dev *dev,
 /* ------------------------------------------------------------------ */
 
 static struct tda827x_config tda827x_cfg_0 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 0,
@@ -561,7 +560,6 @@ static struct tda827x_config tda827x_cfg_0 = {
 };
 
 static struct tda827x_config tda827x_cfg_1 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 1,
@@ -569,7 +567,6 @@ static struct tda827x_config tda827x_cfg_1 = {
 };
 
 static struct tda827x_config tda827x_cfg_2 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 2,
@@ -577,7 +574,6 @@ static struct tda827x_config tda827x_cfg_2 = {
 };
 
 static struct tda827x_config tda827x_cfg_2_sw42 = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = philips_tda827x_tuner_init,
        .sleep = philips_tda827x_tuner_sleep,
        .config = 2,
@@ -799,6 +795,20 @@ static struct tda1004x_config twinhan_dtv_dvb_3056_config = {
        .request_firmware = philips_tda1004x_request_firmware
 };
 
+static struct tda1004x_config asus_tiger_3in1_config = {
+       .demod_address = 0x0b,
+       .invert        = 1,
+       .invert_oclk   = 0,
+       .xtal_freq     = TDA10046_XTAL_16M,
+       .agc_config    = TDA10046_AGC_TDA827X,
+       .gpio_config   = TDA10046_GP11_I,
+       .if_freq       = TDA10046_FREQ_045,
+       .i2c_gate      = 0x4b,
+       .tuner_address = 0x61,
+       .antenna_switch = 1,
+       .request_firmware = philips_tda1004x_request_firmware
+};
+
 /* ------------------------------------------------------------------
  * special case: this card uses saa713x GPIO22 for the mode switch
  */
@@ -822,7 +832,6 @@ static int ads_duo_tuner_sleep(struct dvb_frontend *fe)
 }
 
 static struct tda827x_config ads_duo_cfg = {
-       .tuner_callback = saa7134_tuner_callback,
        .init = ads_duo_tuner_init,
        .sleep = ads_duo_tuner_sleep,
        .config = 0
@@ -1147,6 +1156,7 @@ static int dvb_init(struct saa7134_dev *dev)
                        dvb_attach(dvb_pll_attach, dev->dvb.frontend, 0x61,
                                   NULL, DVB_PLL_TDHU2);
                break;
+       case SAA7134_BOARD_ADS_INSTANT_HDTV_PCI:
        case SAA7134_BOARD_KWORLD_ATSC110:
                dev->dvb.frontend = dvb_attach(nxt200x_attach, &kworldatsc110,
                                               &dev->i2c_adap);
@@ -1300,6 +1310,36 @@ static int dvb_init(struct saa7134_dev *dev)
                                                &dev->i2c_adap);
                attach_xc3028 = 1;
                break;
+       case SAA7134_BOARD_ASUSTeK_TIGER_3IN1:
+               if (!use_frontend) {     /* terrestrial */
+                       if (configure_tda827x_fe(dev, &asus_tiger_3in1_config,
+                                                       &tda827x_cfg_2) < 0)
+                               goto dettach_frontend;
+               } else {                /* satellite */
+                       dev->dvb.frontend = dvb_attach(tda10086_attach,
+                                               &flydvbs, &dev->i2c_adap);
+                       if (dev->dvb.frontend) {
+                               if (dvb_attach(tda826x_attach,
+                                               dev->dvb.frontend, 0x60,
+                                               &dev->i2c_adap, 0) == NULL) {
+                                       wprintk("%s: Asus Tiger 3in1, no "
+                                               "tda826x found!\n", __func__);
+                                       goto dettach_frontend;
+                               }
+                               if (dvb_attach(lnbp21_attach, dev->dvb.frontend,
+                                               &dev->i2c_adap, 0, 0) == NULL) {
+                                       wprintk("%s: Asus Tiger 3in1, no lnbp21"
+                                               " found!\n", __func__);
+                                       goto dettach_frontend;
+                               }
+                       }
+               }
+               break;
+       case SAA7134_BOARD_ASUSTeK_TIGER:
+               if (configure_tda827x_fe(dev, &philips_tiger_config,
+                                        &tda827x_cfg_0) < 0)
+                       goto dettach_frontend;
+               break;
        default:
                wprintk("Huh? unknown DVB card?\n");
                break;
@@ -1327,6 +1367,8 @@ static int dvb_init(struct saa7134_dev *dev)
                printk(KERN_ERR "%s/dvb: frontend initialization failed\n", dev->name);
                return -1;
        }
+       /* define general-purpose callback pointer */
+       dev->dvb.frontend->callback = saa7134_tuner_callback;
 
        /* register everything else */
        ret = videobuf_dvb_register(&dev->dvb, THIS_MODULE, dev, &dev->pci->dev,
index c0c5d7509c25a81c9fb5fda2c79b74cf2314617a..9a8766a78a0c31f45ddadeb561d4d837662730ba 100644 (file)
@@ -29,6 +29,7 @@
 
 #include <media/saa6752hs.h>
 #include <media/v4l2-common.h>
+#include <media/v4l2-chip-ident.h>
 
 /* ------------------------------------------------------------------ */
 
@@ -63,10 +64,19 @@ static void ts_reset_encoder(struct saa7134_dev* dev)
 
 static int ts_init_encoder(struct saa7134_dev* dev)
 {
-       struct v4l2_ext_controls ctrls = { V4L2_CTRL_CLASS_MPEG, 0 };
+       u32 leading_null_bytes = 0;
 
+       /* If more cards start to need this, then this
+          should probably be added to the card definitions. */
+       switch (dev->board) {
+       case SAA7134_BOARD_BEHOLD_M6:
+       case SAA7134_BOARD_BEHOLD_M63:
+       case SAA7134_BOARD_BEHOLD_M6_EXTRA:
+               leading_null_bytes = 1;
+               break;
+       }
        ts_reset_encoder(dev);
-       saa7134_i2c_call_clients(dev, VIDIOC_S_EXT_CTRLS, &ctrls);
+       saa7134_i2c_call_clients(dev, VIDIOC_INT_INIT, &leading_null_bytes);
        dev->empress_started = 1;
        return 0;
 }
@@ -79,9 +89,11 @@ static int ts_open(struct inode *inode, struct file *file)
        struct saa7134_dev *dev;
        int err;
 
+       lock_kernel();
        list_for_each_entry(dev, &saa7134_devlist, devlist)
                if (dev->empress_dev && dev->empress_dev->minor == minor)
                        goto found;
+       unlock_kernel();
        return -ENODEV;
  found:
 
@@ -103,6 +115,7 @@ static int ts_open(struct inode *inode, struct file *file)
 done_up:
        mutex_unlock(&dev->empress_tsq.vb_lock);
 done:
+       unlock_kernel();
        return err;
 }
 
@@ -290,15 +303,6 @@ static int empress_streamoff(struct file *file, void *priv,
        return videobuf_streamoff(&dev->empress_tsq);
 }
 
-static int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
-                                             unsigned int cmd, void *arg)
-{
-       if (dev->mpeg_i2c_client == NULL)
-               return -EINVAL;
-       return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
-                                                               cmd, arg);
-}
-
 static int empress_s_ext_ctrls(struct file *file, void *priv,
                               struct v4l2_ext_controls *ctrls)
 {
@@ -400,6 +404,39 @@ static int empress_querymenu(struct file *file, void *priv,
        return saa7134_i2c_call_saa6752(dev, VIDIOC_QUERYMENU, c);
 }
 
+static int empress_g_chip_ident(struct file *file, void *fh,
+              struct v4l2_chip_ident *chip)
+{
+       struct saa7134_dev *dev = file->private_data;
+
+       chip->ident = V4L2_IDENT_NONE;
+       chip->revision = 0;
+       if (dev->mpeg_i2c_client == NULL)
+               return -EINVAL;
+       if (chip->match_type == V4L2_CHIP_MATCH_I2C_DRIVER &&
+           chip->match_chip == I2C_DRIVERID_SAA6752HS)
+               return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
+       if (chip->match_type == V4L2_CHIP_MATCH_I2C_ADDR &&
+           chip->match_chip == dev->mpeg_i2c_client->addr)
+               return saa7134_i2c_call_saa6752(dev, VIDIOC_G_CHIP_IDENT, chip);
+       return -EINVAL;
+}
+
+static int empress_s_std(struct file *file, void *priv, v4l2_std_id *id)
+{
+       struct saa7134_dev *dev = file->private_data;
+
+       return saa7134_s_std_internal(dev, NULL, id);
+}
+
+static int empress_g_std(struct file *file, void *priv, v4l2_std_id *id)
+{
+       struct saa7134_dev *dev = file->private_data;
+
+       *id = dev->tvnorm->id;
+       return 0;
+}
+
 static const struct file_operations ts_fops =
 {
        .owner    = THIS_MODULE,
@@ -428,11 +465,13 @@ static const struct v4l2_ioctl_ops ts_ioctl_ops = {
        .vidioc_enum_input              = empress_enum_input,
        .vidioc_g_input                 = empress_g_input,
        .vidioc_s_input                 = empress_s_input,
-
        .vidioc_queryctrl               = empress_queryctrl,
        .vidioc_querymenu               = empress_querymenu,
        .vidioc_g_ctrl                  = empress_g_ctrl,
        .vidioc_s_ctrl                  = empress_s_ctrl,
+       .vidioc_g_chip_ident            = empress_g_chip_ident,
+       .vidioc_s_std                   = empress_s_std,
+       .vidioc_g_std                   = empress_g_std,
 };
 
 /* ----------------------------------------------------------- */
index 5f713e6376839a3cac595821c736866bf1cbcc65..20c1b33caf7b64bbd551a929db1f2a52bbf3da32 100644 (file)
@@ -337,6 +337,7 @@ static int attach_inform(struct i2c_client *client)
                case 0x47:
                case 0x71:
                case 0x2d:
+               case 0x30:
                {
                        struct IR_i2c *ir = i2c_get_clientdata(client);
                        d1printk("%s i2c IR detected (%s).\n",
@@ -427,6 +428,16 @@ void saa7134_i2c_call_clients(struct saa7134_dev *dev,
        i2c_clients_command(&dev->i2c_adap, cmd, arg);
 }
 
+int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
+                                             unsigned int cmd, void *arg)
+{
+       if (dev->mpeg_i2c_client == NULL)
+               return -EINVAL;
+       return dev->mpeg_i2c_client->driver->command(dev->mpeg_i2c_client,
+                                                               cmd, arg);
+}
+EXPORT_SYMBOL_GPL(saa7134_i2c_call_saa6752);
+
 int saa7134_i2c_register(struct saa7134_dev *dev)
 {
        dev->i2c_adap = saa7134_adap_template;
index ad08d13dffdd8eaba60feb65d5d9bfd2c521888b..c53fd5f9f6b553bac073483b5c69ced28f7d6967 100644 (file)
@@ -62,8 +62,11 @@ MODULE_PARM_DESC(disable_other_ir, "disable full codes of "
 #define i2cdprintk(fmt, arg...)    if (ir_debug) \
        printk(KERN_DEBUG "%s/ir: " fmt, ir->c.name , ## arg)
 
-/** rc5 functions */
+/* Helper functions for RC5 and NEC decoding at GPIO16 or GPIO18 */
 static int saa7134_rc5_irq(struct saa7134_dev *dev);
+static int saa7134_nec_irq(struct saa7134_dev *dev);
+static void nec_task(unsigned long data);
+static void saa7134_nec_timer(unsigned long data);
 
 /* -------------------- GPIO generic keycode builder -------------------- */
 
@@ -115,6 +118,53 @@ static int build_key(struct saa7134_dev *dev)
 
 /* --------------------- Chip specific I2C key builders ----------------- */
 
+static int get_key_msi_tvanywhere_plus(struct IR_i2c *ir, u32 *ir_key,
+                                      u32 *ir_raw)
+{
+       unsigned char b;
+       int gpio;
+
+       /* <dev> is needed to access GPIO. Used by the saa_readl macro. */
+       struct saa7134_dev *dev = ir->c.adapter->algo_data;
+       if (dev == NULL) {
+               dprintk("get_key_msi_tvanywhere_plus: "
+                       "gir->c.adapter->algo_data is NULL!\n");
+               return -EIO;
+       }
+
+       /* rising SAA7134_GPIO_GPRESCAN reads the status */
+
+       saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+       saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+
+       gpio = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2);
+
+       /* GPIO&0x40 is pulsed low when a button is pressed. Don't do
+          I2C receive if gpio&0x40 is not low. */
+
+       if (gpio & 0x40)
+               return 0;       /* No button press */
+
+       /* GPIO says there is a button press. Get it. */
+
+       if (1 != i2c_master_recv(&ir->c, &b, 1)) {
+               i2cdprintk("read error\n");
+               return -EIO;
+       }
+
+       /* No button press */
+
+       if (b == 0xff)
+               return 0;
+
+       /* Button pressed */
+
+       dprintk("get_key_msi_tvanywhere_plus: Key = 0x%02X\n", b);
+       *ir_key = b;
+       *ir_raw = b;
+       return 1;
+}
+
 static int get_key_purpletv(struct IR_i2c *ir, u32 *ir_key, u32 *ir_raw)
 {
        unsigned char b;
@@ -280,7 +330,9 @@ void saa7134_input_irq(struct saa7134_dev *dev)
 {
        struct card_ir *ir = dev->remote;
 
-       if (!ir->polling && !ir->rc5_gpio) {
+       if (ir->nec_gpio) {
+               saa7134_nec_irq(dev);
+       } else if (!ir->polling && !ir->rc5_gpio) {
                build_key(dev);
        } else if (ir->rc5_gpio) {
                saa7134_rc5_irq(dev);
@@ -316,6 +368,10 @@ void saa7134_ir_start(struct saa7134_dev *dev, struct card_ir *ir)
                ir->addr = 0x17;
                ir->rc5_key_timeout = ir_rc5_key_timeout;
                ir->rc5_remote_gap = ir_rc5_remote_gap;
+       } else if (ir->nec_gpio) {
+               setup_timer(&ir->timer_keyup, saa7134_nec_timer,
+                           (unsigned long)dev);
+               tasklet_init(&ir->tlet, nec_task, (unsigned long)dev);
        }
 }
 
@@ -335,6 +391,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        u32 mask_keyup   = 0;
        int polling      = 0;
        int rc5_gpio     = 0;
+       int nec_gpio     = 0;
        int ir_type      = IR_TYPE_OTHER;
        int err;
 
@@ -391,6 +448,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                saa_setb(SAA7134_GPIO_GPMODE0, 0x4);
                saa_setb(SAA7134_GPIO_GPSTATUS0, 0x4);
                break;
+       case SAA7134_BOARD_AVERMEDIA_M135A:
+               ir_codes     = ir_codes_avermedia_m135a;
+               mask_keydown = 0x0040000;
+               mask_keycode = 0x00013f;
+               nec_gpio     = 1;
+               break;
        case SAA7134_BOARD_AVERMEDIA_777:
        case SAA7134_BOARD_AVERMEDIA_A16AR:
                ir_codes     = ir_codes_avermedia;
@@ -499,6 +562,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                mask_keyup   = 0x040000;
                polling      = 50; // ms
                break;
+       case SAA7134_BOARD_ENCORE_ENLTV_FM53:
+               ir_codes     = ir_codes_encore_enltv_fm53;
+               mask_keydown = 0x0040000;
+               mask_keycode = 0x00007f;
+               nec_gpio = 1;
+               break;
        case SAA7134_BOARD_10MOONSTVMASTER3:
                ir_codes     = ir_codes_encore_enltv;
                mask_keycode = 0x5f80000;
@@ -511,6 +580,12 @@ int saa7134_input_init1(struct saa7134_dev *dev)
                mask_keydown = 0xf00000;
                polling = 50; /* ms */
                break;
+       case SAA7134_BOARD_REAL_ANGEL_220:
+               ir_codes     = ir_codes_real_audio_220_32_keys;
+               mask_keycode = 0x3f00;
+               mask_keyup   = 0x4000;
+               polling = 50; /* ms */
+               break;
        }
        if (NULL == ir_codes) {
                printk("%s: Oops: IR config error [card=%d]\n",
@@ -533,6 +608,7 @@ int saa7134_input_init1(struct saa7134_dev *dev)
        ir->mask_keyup   = mask_keyup;
        ir->polling      = polling;
        ir->rc5_gpio     = rc5_gpio;
+       ir->nec_gpio     = nec_gpio;
 
        /* init input device */
        snprintf(ir->name, sizeof(ir->name), "saa7134 IR (%s)",
@@ -612,6 +688,11 @@ void saa7134_set_i2c_ir(struct saa7134_dev *dev, struct IR_i2c *ir)
                ir->get_key   = get_key_purpletv;
                ir->ir_codes  = ir_codes_purpletv;
                break;
+       case SAA7134_BOARD_MSI_TVATANYWHERE_PLUS:
+               snprintf(ir->c.name, sizeof(ir->c.name), "MSI TV@nywhere Plus");
+               ir->get_key  = get_key_msi_tvanywhere_plus;
+               ir->ir_codes = ir_codes_msi_tvanywhere_plus;
+               break;
        case SAA7134_BOARD_HAUPPAUGE_HVR1110:
                snprintf(ir->c.name, sizeof(ir->c.name), "HVR 1110");
                ir->get_key   = get_key_hvr1110;
@@ -675,8 +756,125 @@ static int saa7134_rc5_irq(struct saa7134_dev *dev)
        return 1;
 }
 
-/* ----------------------------------------------------------------------
- * Local variables:
- * c-basic-offset: 8
- * End:
+
+/* On NEC protocol, One has 2.25 ms, and zero has 1.125 ms
+   The first pulse (start) has 9 + 4.5 ms
  */
+
+static void saa7134_nec_timer(unsigned long data)
+{
+       struct saa7134_dev *dev = (struct saa7134_dev *) data;
+       struct card_ir *ir = dev->remote;
+
+       dprintk("Cancel key repeat\n");
+
+       ir_input_nokey(ir->dev, &ir->ir);
+}
+
+static void nec_task(unsigned long data)
+{
+       struct saa7134_dev *dev = (struct saa7134_dev *) data;
+       struct card_ir *ir;
+       struct timeval tv;
+       int count, pulse, oldpulse, gap;
+       u32 ircode = 0, not_code = 0;
+       int ngap = 0;
+
+       if (!data) {
+               printk(KERN_ERR "saa713x/ir: Can't recover dev struct\n");
+               /* GPIO will be kept disabled */
+               return;
+       }
+
+       ir = dev->remote;
+
+       /* rising SAA7134_GPIO_GPRESCAN reads the status */
+       saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+       saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+
+       oldpulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2) & ir->mask_keydown;
+       pulse = oldpulse;
+
+       do_gettimeofday(&tv);
+       ir->base_time = tv;
+
+       /* Decode NEC pulsecode. This code can take up to 76.5 ms to run.
+          Unfortunately, using IRQ to decode pulse didn't work, since it uses
+          a pulse train of 38KHz. This means one pulse on each 52 us
+        */
+       do {
+               /* Wait until the end of pulse/space or 5 ms */
+               for (count = 0; count < 500; count++)  {
+                       udelay(10);
+                       /* rising SAA7134_GPIO_GPRESCAN reads the status */
+                       saa_clearb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+                       saa_setb(SAA7134_GPIO_GPMODE3, SAA7134_GPIO_GPRESCAN);
+                       pulse = saa_readl(SAA7134_GPIO_GPSTATUS0 >> 2)
+                               & ir->mask_keydown;
+                       if (pulse != oldpulse)
+                               break;
+               }
+
+               do_gettimeofday(&tv);
+               gap = 1000000 * (tv.tv_sec - ir->base_time.tv_sec) +
+                               tv.tv_usec - ir->base_time.tv_usec;
+
+               if (!pulse) {
+                       /* Bit 0 has 560 us, while bit 1 has 1120 us.
+                          Do something only if bit == 1
+                        */
+                       if (ngap && (gap > 560 + 280)) {
+                               unsigned int shift = ngap - 1;
+
+                               /* Address first, then command */
+                               if (shift < 8) {
+                                       shift += 8;
+                                       ircode |= 1 << shift;
+                               } else if (shift < 16) {
+                                       not_code |= 1 << shift;
+                               } else if (shift < 24) {
+                                       shift -= 16;
+                                       ircode |= 1 << shift;
+                               } else {
+                                       shift -= 24;
+                                       not_code |= 1 << shift;
+                               }
+                       }
+                       ngap++;
+               }
+
+
+               ir->base_time = tv;
+
+               /* TIMEOUT - Long pulse */
+               if (gap >= 5000)
+                       break;
+               oldpulse = pulse;
+       } while (ngap < 32);
+
+       if (ngap == 32) {
+               /* FIXME: should check if not_code == ~ircode */
+               ir->code = ir_extract_bits(ircode, ir->mask_keycode);
+
+               dprintk("scancode = 0x%02x (code = 0x%02x, notcode= 0x%02x)\n",
+                        ir->code, ircode, not_code);
+
+               ir_input_keydown(ir->dev, &ir->ir, ir->code, ir->code);
+       } else
+               dprintk("Repeat last key\n");
+
+       /* Keep repeating the last key */
+       mod_timer(&ir->timer_keyup, jiffies + msecs_to_jiffies(150));
+
+       saa_setl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
+}
+
+static int saa7134_nec_irq(struct saa7134_dev *dev)
+{
+       struct card_ir *ir = dev->remote;
+
+       saa_clearl(SAA7134_IRQ2, SAA7134_IRQ2_INTE_GPIO18);
+       tasklet_schedule(&ir->tlet);
+
+       return 1;
+}
index eae72fd60cec6f6b3aa888d4bb380cb62cc10209..ef55a59f0cda59623cec062bea0a313051d8857a 100644 (file)
@@ -66,11 +66,29 @@ static int buffer_activate(struct saa7134_dev *dev,
        saa7134_set_dmabits(dev);
 
        mod_timer(&dev->ts_q.timeout, jiffies+BUFFER_TIMEOUT);
+
+       if (dev->ts_state == SAA7134_TS_BUFF_DONE) {
+               /* Clear TS cache */
+               dev->buff_cnt = 0;
+               saa_writeb(SAA7134_TS_SERIAL1, 0x00);
+               saa_writeb(SAA7134_TS_SERIAL1, 0x03);
+               saa_writeb(SAA7134_TS_SERIAL1, 0x00);
+               saa_writeb(SAA7134_TS_SERIAL1, 0x01);
+
+               /* TS clock non-inverted */
+               saa_writeb(SAA7134_TS_SERIAL1, 0x00);
+
+               /* Start TS stream */
+               saa_writeb(SAA7134_TS_SERIAL0, 0x40);
+               saa_writeb(SAA7134_TS_PARALLEL, 0xEC);
+               dev->ts_state = SAA7134_TS_STARTED;
+       }
+
        return 0;
 }
 
 static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
-                         enum v4l2_field field)
+               enum v4l2_field field)
 {
        struct saa7134_dev *dev = q->priv_data;
        struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
@@ -110,16 +128,22 @@ static int buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
                        goto oops;
        }
 
-       /* dma: setup channel 5 (= TS) */
-       control = SAA7134_RS_CONTROL_BURST_16 |
-                 SAA7134_RS_CONTROL_ME |
-                 (buf->pt->dma >> 12);
-
-       saa_writeb(SAA7134_TS_DMA0, ((lines-1)&0xff));
-       saa_writeb(SAA7134_TS_DMA1, (((lines-1)>>8)&0xff));
-       saa_writeb(SAA7134_TS_DMA2, ((((lines-1)>>16)&0x3f) | 0x00)); /* TSNOPIT=0, TSCOLAP=0 */
-       saa_writel(SAA7134_RS_PITCH(5),TS_PACKET_SIZE);
-       saa_writel(SAA7134_RS_CONTROL(5),control);
+       dev->buff_cnt++;
+
+       if (dev->buff_cnt == dev->ts.nr_bufs) {
+               dev->ts_state = SAA7134_TS_BUFF_DONE;
+               /* dma: setup channel 5 (= TS) */
+               control = SAA7134_RS_CONTROL_BURST_16 |
+                       SAA7134_RS_CONTROL_ME |
+                       (buf->pt->dma >> 12);
+
+               saa_writeb(SAA7134_TS_DMA0, (lines - 1) & 0xff);
+               saa_writeb(SAA7134_TS_DMA1, ((lines - 1) >> 8) & 0xff);
+               /* TSNOPIT=0, TSCOLAP=0 */
+               saa_writeb(SAA7134_TS_DMA2, (((lines - 1) >> 16) & 0x3f) | 0x00);
+               saa_writel(SAA7134_RS_PITCH(5), TS_PACKET_SIZE);
+               saa_writel(SAA7134_RS_CONTROL(5), control);
+       }
 
        buf->vb.state = VIDEOBUF_PREPARED;
        buf->activate = buffer_activate;
@@ -140,6 +164,8 @@ buffer_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
        if (0 == *count)
                *count = dev->ts.nr_bufs;
        *count = saa7134_buffer_count(*size,*count);
+       dev->buff_cnt = 0;
+       dev->ts_state = SAA7134_TS_STOPPED;
        return 0;
 }
 
@@ -154,7 +180,13 @@ static void buffer_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
 static void buffer_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
 {
        struct saa7134_buf *buf = container_of(vb,struct saa7134_buf,vb);
+       struct saa7134_dev *dev = q->priv_data;
 
+       if (dev->ts_state == SAA7134_TS_STARTED) {
+               /* Stop TS transport */
+               saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
+               dev->ts_state = SAA7134_TS_STOPPED;
+       }
        saa7134_dma_free(q,buf);
 }
 
@@ -182,7 +214,7 @@ int saa7134_ts_init_hw(struct saa7134_dev *dev)
        /* deactivate TS softreset */
        saa_writeb(SAA7134_TS_SERIAL1, 0x00);
        /* TSSOP high active, TSVAL high active, TSLOCK ignored */
-       saa_writeb(SAA7134_TS_PARALLEL, 0xec);
+       saa_writeb(SAA7134_TS_PARALLEL, 0x6c);
        saa_writeb(SAA7134_TS_PARALLEL_SERIAL, (TS_PACKET_SIZE-1));
        saa_writeb(SAA7134_TS_DMA0, ((dev->ts.nr_packets-1)&0xff));
        saa_writeb(SAA7134_TS_DMA1, (((dev->ts.nr_packets-1)>>8)&0xff));
index 68c268981861dee9e8abc93e640a036480eecce8..02bb6747a39c846fa7c19c288e9703054c1c40d5 100644 (file)
@@ -628,6 +628,9 @@ void saa7134_set_tvnorm_hw(struct saa7134_dev *dev)
 
        if (card_in(dev, dev->ctl_input).tv)
                saa7134_i2c_call_clients(dev, VIDIOC_S_STD, &dev->tvnorm->id);
+       /* Set the correct norm for the saa6752hs. This function
+          does nothing if there is no saa6752hs. */
+       saa7134_i2c_call_saa6752(dev, VIDIOC_S_STD, &dev->tvnorm->id);
 }
 
 static void set_h_prescale(struct saa7134_dev *dev, int task, int prescale)
@@ -1330,6 +1333,8 @@ static int video_open(struct inode *inode, struct file *file)
        struct saa7134_fh *fh;
        enum v4l2_buf_type type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
        int radio = 0;
+
+       lock_kernel();
        list_for_each_entry(dev, &saa7134_devlist, devlist) {
                if (dev->video_dev && (dev->video_dev->minor == minor))
                        goto found;
@@ -1342,6 +1347,7 @@ static int video_open(struct inode *inode, struct file *file)
                        goto found;
                }
        }
+       unlock_kernel();
        return -ENODEV;
  found:
 
@@ -1350,8 +1356,10 @@ static int video_open(struct inode *inode, struct file *file)
 
        /* allocate + initialize per filehandle data */
        fh = kzalloc(sizeof(*fh),GFP_KERNEL);
-       if (NULL == fh)
+       if (NULL == fh) {
+               unlock_kernel();
                return -ENOMEM;
+       }
        file->private_data = fh;
        fh->dev      = dev;
        fh->radio    = radio;
@@ -1384,6 +1392,7 @@ static int video_open(struct inode *inode, struct file *file)
                /* switch to video/vbi mode */
                video_mux(dev,dev->ctl_input);
        }
+       unlock_kernel();
        return 0;
 }
 
@@ -1790,18 +1799,25 @@ static int saa7134_querycap(struct file *file, void  *priv,
                return 0;
 }
 
-static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
+int saa7134_s_std_internal(struct saa7134_dev *dev, struct saa7134_fh *fh, v4l2_std_id *id)
 {
-       struct saa7134_fh *fh = priv;
-       struct saa7134_dev *dev = fh->dev;
        unsigned long flags;
        unsigned int i;
        v4l2_std_id fixup;
        int err;
 
-       err = v4l2_prio_check(&dev->prio, &fh->prio);
-       if (0 != err)
-               return err;
+       /* When called from the empress code fh == NULL.
+          That needs to be fixed somehow, but for now this is
+          good enough. */
+       if (fh) {
+               err = v4l2_prio_check(&dev->prio, &fh->prio);
+               if (0 != err)
+                       return err;
+       } else if (res_locked(dev, RESOURCE_OVERLAY)) {
+               /* Don't change the std from the mpeg device
+                  if overlay is active. */
+               return -EBUSY;
+       }
 
        for (i = 0; i < TVNORMS; i++)
                if (*id == tvnorms[i].id)
@@ -1834,7 +1850,7 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
        *id = tvnorms[i].id;
 
        mutex_lock(&dev->lock);
-       if (res_check(fh, RESOURCE_OVERLAY)) {
+       if (fh && res_check(fh, RESOURCE_OVERLAY)) {
                spin_lock_irqsave(&dev->slock, flags);
                stop_preview(dev, fh);
                spin_unlock_irqrestore(&dev->slock, flags);
@@ -1851,6 +1867,23 @@ static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
        mutex_unlock(&dev->lock);
        return 0;
 }
+EXPORT_SYMBOL_GPL(saa7134_s_std_internal);
+
+static int saa7134_s_std(struct file *file, void *priv, v4l2_std_id *id)
+{
+       struct saa7134_fh *fh = priv;
+
+       return saa7134_s_std_internal(fh->dev, fh, id);
+}
+
+static int saa7134_g_std(struct file *file, void *priv, v4l2_std_id *id)
+{
+       struct saa7134_fh *fh = priv;
+       struct saa7134_dev *dev = fh->dev;
+
+       *id = dev->tvnorm->id;
+       return 0;
+}
 
 static int saa7134_cropcap(struct file *file, void *priv,
                                        struct v4l2_cropcap *cap)
@@ -2077,18 +2110,6 @@ static int saa7134_enum_fmt_vid_overlay(struct file *file, void  *priv,
        return 0;
 }
 
-static int saa7134_enum_fmt_vbi_cap(struct file *file, void  *priv,
-                                       struct v4l2_fmtdesc *f)
-{
-       if (0 != f->index)
-               return -EINVAL;
-
-       f->pixelformat = V4L2_PIX_FMT_GREY;
-       strcpy(f->description, "vbi data");
-
-       return 0;
-}
-
 static int saa7134_g_fbuf(struct file *file, void *f,
                                struct v4l2_framebuffer *fb)
 {
@@ -2379,7 +2400,6 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_g_fmt_vid_overlay       = saa7134_g_fmt_vid_overlay,
        .vidioc_try_fmt_vid_overlay     = saa7134_try_fmt_vid_overlay,
        .vidioc_s_fmt_vid_overlay       = saa7134_s_fmt_vid_overlay,
-       .vidioc_enum_fmt_vbi_cap        = saa7134_enum_fmt_vbi_cap,
        .vidioc_g_fmt_vbi_cap           = saa7134_try_get_set_fmt_vbi_cap,
        .vidioc_try_fmt_vbi_cap         = saa7134_try_get_set_fmt_vbi_cap,
        .vidioc_s_fmt_vbi_cap           = saa7134_try_get_set_fmt_vbi_cap,
@@ -2391,6 +2411,7 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
        .vidioc_qbuf                    = saa7134_qbuf,
        .vidioc_dqbuf                   = saa7134_dqbuf,
        .vidioc_s_std                   = saa7134_s_std,
+       .vidioc_g_std                   = saa7134_g_std,
        .vidioc_enum_input              = saa7134_enum_input,
        .vidioc_g_input                 = saa7134_g_input,
        .vidioc_s_input                 = saa7134_s_input,
index a0884f639f6504b6826c9e791107f3bbe3f9f06c..491ab1f8fdd3cbadba1a3421e8dfc2cd30bb6340 100644 (file)
@@ -269,6 +269,12 @@ struct saa7134_format {
 #define SAA7134_BOARD_BEHOLD_M6_EXTRA    144
 #define SAA7134_BOARD_AVERMEDIA_M103    145
 #define SAA7134_BOARD_ASUSTeK_P7131_ANALOG 146
+#define SAA7134_BOARD_ASUSTeK_TIGER_3IN1   147
+#define SAA7134_BOARD_ENCORE_ENLTV_FM53 148
+#define SAA7134_BOARD_AVERMEDIA_M135A    149
+#define SAA7134_BOARD_REAL_ANGEL_220     150
+#define SAA7134_BOARD_ADS_INSTANT_HDTV_PCI  151
+#define SAA7134_BOARD_ASUSTeK_TIGER         152
 
 #define SAA7134_MAXBOARDS 8
 #define SAA7134_INPUT_MAX 8
@@ -462,6 +468,12 @@ struct saa7134_mpeg_ops {
        void                       (*signal_change)(struct saa7134_dev *dev);
 };
 
+enum saa7134_ts_status {
+       SAA7134_TS_STOPPED,
+       SAA7134_TS_BUFF_DONE,
+       SAA7134_TS_STARTED,
+};
+
 /* global device status */
 struct saa7134_dev {
        struct list_head           devlist;
@@ -555,6 +567,8 @@ struct saa7134_dev {
        /* SAA7134_MPEG_* */
        struct saa7134_ts          ts;
        struct saa7134_dmaqueue    ts_q;
+       enum saa7134_ts_status     ts_state;
+       unsigned int               buff_cnt;
        struct saa7134_mpeg_ops    *mops;
        struct i2c_client          *mpeg_i2c_client;
 
@@ -644,7 +658,7 @@ extern struct pci_device_id __devinitdata saa7134_pci_tbl[];
 
 extern int saa7134_board_init1(struct saa7134_dev *dev);
 extern int saa7134_board_init2(struct saa7134_dev *dev);
-int saa7134_tuner_callback(void *priv, int command, int arg);
+int saa7134_tuner_callback(void *priv, int component, int command, int arg);
 
 
 /* ----------------------------------------------------------- */
@@ -654,6 +668,8 @@ int saa7134_i2c_register(struct saa7134_dev *dev);
 int saa7134_i2c_unregister(struct saa7134_dev *dev);
 void saa7134_i2c_call_clients(struct saa7134_dev *dev,
                              unsigned int cmd, void *arg);
+int saa7134_i2c_call_saa6752(struct saa7134_dev *dev,
+                             unsigned int cmd, void *arg);
 
 
 /* ----------------------------------------------------------- */
@@ -666,6 +682,7 @@ extern struct video_device saa7134_radio_template;
 int saa7134_s_ctrl_internal(struct saa7134_dev *dev,  struct saa7134_fh *fh, struct v4l2_control *c);
 int saa7134_g_ctrl_internal(struct saa7134_dev *dev,  struct saa7134_fh *fh, struct v4l2_control *c);
 int saa7134_queryctrl(struct file *file, void *priv, struct v4l2_queryctrl *c);
+int saa7134_s_std_internal(struct saa7134_dev *dev,  struct saa7134_fh *fh, v4l2_std_id *id);
 
 int saa7134_videoport_init(struct saa7134_dev *dev);
 void saa7134_set_tvnorm_hw(struct saa7134_dev *dev);
index acceed5d04aee9f9a0aa1b0abb4cb1fef52d90f3..ae3949180c4ed3ace8801f67b94c24899e0b916f 100644 (file)
@@ -288,7 +288,7 @@ static void se401_button_irq(struct urb *urb)
        int status;
 
        if (!se401->dev) {
-               info("ohoh: device vapourished");
+               dev_info(&urb->dev->dev, "device vapourished\n");
                return;
        }
 
@@ -328,7 +328,7 @@ static void se401_video_irq(struct urb *urb)
                return;
 
        if (!se401->dev) {
-               info ("ohoh: device vapourished");
+               dev_info(&urb->dev->dev, "device vapourished\n");
                return;
        }
 
@@ -375,7 +375,7 @@ static void se401_video_irq(struct urb *urb)
        urb->status=0;
        urb->dev=se401->dev;
        if(usb_submit_urb(urb, GFP_KERNEL))
-               info("urb burned down");
+               dev_info(&urb->dev->dev, "urb burned down\n");
        return;
 }
 
@@ -860,7 +860,8 @@ static int se401_newframe(struct usb_se401 *se401, int framenr)
                );
                if (se401->nullpackets > SE401_MAX_NULLPACKETS) {
                        se401->nullpackets=0;
-                       info("to many null length packets, restarting capture");
+                       dev_info(&se401->dev->dev,
+                                "too many null length packets, restarting capture\n");
                        se401_stop_stream(se401);
                        se401_start_stream(se401);
                } else {
@@ -880,7 +881,8 @@ static int se401_newframe(struct usb_se401 *se401, int framenr)
                                se401->scratch_use=0;
                        if (errors > SE401_MAX_ERRORS) {
                                errors=0;
-                               info("to much errors, restarting capture");
+                               dev_info(&se401->dev->dev,
+                                        "too many errors, restarting capture\n");
                                se401_stop_stream(se401);
                                se401_start_stream(se401);
                        }
@@ -913,7 +915,7 @@ static void usb_se401_remove_disconnected (struct usb_se401 *se401)
                usb_kill_urb(se401->inturb);
                usb_free_urb(se401->inturb);
        }
-       info("%s disconnected", se401->camera_name);
+       dev_info(&se401->dev->dev, "%s disconnected", se401->camera_name);
 
        /* Free the memory */
        kfree(se401->width);
@@ -936,14 +938,18 @@ static int se401_open(struct inode *inode, struct file *file)
        struct usb_se401 *se401 = (struct usb_se401 *)dev;
        int err = 0;
 
-       if (se401->user)
+       lock_kernel();
+       if (se401->user) {
+               unlock_kernel();
                return -EBUSY;
+       }
        se401->fbuf = rvmalloc(se401->maxframesize * SE401_NUMFRAMES);
        if (se401->fbuf)
                file->private_data = dev;
        else
                err = -ENOMEM;
        se401->user = !err;
+       unlock_kernel();
 
        return err;
 }
@@ -956,8 +962,8 @@ static int se401_close(struct inode *inode, struct file *file)
 
        rvfree(se401->fbuf, se401->maxframesize * SE401_NUMFRAMES);
        if (se401->removed) {
+               dev_info(&se401->dev->dev, "device unregistered\n");
                usb_se401_remove_disconnected(se401);
-               info("device unregistered");
        } else {
                for (i=0; i<SE401_NUMFRAMES; i++)
                        se401->frame[i].grabstate=FRAME_UNUSED;
@@ -1232,6 +1238,7 @@ static const struct file_operations se401_fops = {
 static struct video_device se401_template = {
        .name =         "se401 USB camera",
        .fops =         &se401_fops,
+       .release = video_device_release_empty,
 };
 
 
@@ -1271,7 +1278,7 @@ static int se401_init(struct usb_se401 *se401, int button)
        for (i=0; i<se401->sizes; i++) {
                sprintf(temp, "%s %dx%d", temp, se401->width[i], se401->height[i]);
        }
-       info("%s", temp);
+       dev_info(&se401->dev->dev, "%s\n", temp);
        se401->maxframesize=se401->width[se401->sizes-1]*se401->height[se401->sizes-1]*3;
 
        rc=se401_sndctrl(0, se401, SE401_REQ_GET_WIDTH, 0, cp, sizeof(cp));
@@ -1305,7 +1312,8 @@ static int se401_init(struct usb_se401 *se401, int button)
        if (button) {
                se401->inturb=usb_alloc_urb(0, GFP_KERNEL);
                if (!se401->inturb) {
-                       info("Allocation of inturb failed");
+                       dev_info(&se401->dev->dev,
+                                "Allocation of inturb failed\n");
                        return 1;
                }
                usb_fill_int_urb(se401->inturb, se401->dev,
@@ -1316,7 +1324,7 @@ static int se401_init(struct usb_se401 *se401, int button)
                    8
                );
                if (usb_submit_urb(se401->inturb, GFP_KERNEL)) {
-                       info("int urb burned down");
+                       dev_info(&se401->dev->dev, "int urb burned down\n");
                        return 1;
                }
        } else
@@ -1373,7 +1381,7 @@ static int se401_probe(struct usb_interface *intf,
                return -ENODEV;
 
        /* We found one */
-       info("SE401 camera found: %s", camera_name);
+       dev_info(&intf->dev, "SE401 camera found: %s\n", camera_name);
 
        if ((se401 = kzalloc(sizeof(*se401), GFP_KERNEL)) == NULL) {
                err("couldn't kmalloc se401 struct");
@@ -1384,7 +1392,8 @@ static int se401_probe(struct usb_interface *intf,
        se401->iface = interface->bInterfaceNumber;
        se401->camera_name = camera_name;
 
-       info("firmware version: %02x", le16_to_cpu(dev->descriptor.bcdDevice) & 255);
+       dev_info(&intf->dev, "firmware version: %02x\n",
+                le16_to_cpu(dev->descriptor.bcdDevice) & 255);
 
        if (se401_init(se401, button)) {
                kfree(se401);
@@ -1402,7 +1411,8 @@ static int se401_probe(struct usb_interface *intf,
                err("video_register_device failed");
                return -EIO;
        }
-       info("registered new video device: video%d", se401->vdev.minor);
+       dev_info(&intf->dev, "registered new video device: video%d\n",
+                se401->vdev.minor);
 
        usb_set_intfdata (intf, se401);
        return 0;
@@ -1446,10 +1456,10 @@ static struct usb_driver se401_driver = {
 
 static int __init usb_se401_init(void)
 {
-       info("SE401 usb camera driver version %s registering", version);
+       printk(KERN_INFO "SE401 usb camera driver version %s registering\n", version);
        if (flickerless)
                if (flickerless!=50 && flickerless!=60) {
-                       info("Invallid flickerless value, use 0, 50 or 60.");
+                       printk(KERN_ERR "Invallid flickerless value, use 0, 50 or 60.\n");
                        return -1;
        }
        return usb_register(&se401_driver);
@@ -1458,7 +1468,7 @@ static int __init usb_se401_init(void)
 static void __exit usb_se401_exit(void)
 {
        usb_deregister(&se401_driver);
-       info("SE401 driver deregistered");
+       printk(KERN_INFO "SE401 driver deregistered\frame");
 }
 
 module_init(usb_se401_init);
index 318754e731326ee1bdd92a76b829d23736e1cf79..76838091dc66ce05140b63912ec106422e2bc542 100644 (file)
@@ -304,9 +304,6 @@ static int sh_mobile_ceu_add_device(struct soc_camera_device *icd)
                 "SuperH Mobile CEU driver attached to camera %d\n",
                 icd->devnum);
 
-       if (pcdev->pdata->enable_camera)
-               pcdev->pdata->enable_camera();
-
        ret = icd->ops->init(icd);
        if (ret)
                goto err;
@@ -333,8 +330,6 @@ static void sh_mobile_ceu_remove_device(struct soc_camera_device *icd)
        ceu_write(pcdev, CEIER, 0);
        ceu_write(pcdev, CAPSR, 1 << 16); /* reset */
        icd->ops->release(icd);
-       if (pcdev->pdata->disable_camera)
-               pcdev->pdata->disable_camera();
 
        dev_info(&icd->dev,
                 "SuperH Mobile CEU driver detached from camera %d\n",
index 2da6938718f2c1a7969065f24b575d4615afdea5..20e30bd9364be9eb3d988079e8764029ed8543c9 100644 (file)
@@ -116,6 +116,26 @@ MODULE_PARM_DESC(debug,
                 "\n");
 #endif
 
+/*
+   Add the probe entries to this table. Be sure to add the entry in the right
+   place, since, on failure, the next probing routine is called according to
+   the order of the list below, from top to bottom.
+*/
+static int (*sn9c102_sensor_table[])(struct sn9c102_device *) = {
+       &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_mt9v111, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_ov7660, /* strong detection based on SENSOR ids */
+       &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
+       &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
+       &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
+};
+
 /*****************************************************************************/
 
 static u32
@@ -1746,7 +1766,7 @@ static int sn9c102_open(struct inode* inode, struct file* filp)
        if (!down_read_trylock(&sn9c102_dev_lock))
                return -ERESTARTSYS;
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        if (wait_for_completion_interruptible(&cam->probe)) {
                up_read(&sn9c102_dev_lock);
@@ -1843,7 +1863,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
 
        down_write(&sn9c102_dev_lock);
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        sn9c102_stop_transfer(cam);
        sn9c102_release_buffers(cam);
@@ -1863,7 +1883,7 @@ static int sn9c102_release(struct inode* inode, struct file* filp)
 static ssize_t
 sn9c102_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
 {
-       struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
+       struct sn9c102_device *cam = video_drvdata(filp);
        struct sn9c102_frame_t* f, * i;
        unsigned long lock_flags;
        long timeout;
@@ -1987,7 +2007,7 @@ exit:
 
 static unsigned int sn9c102_poll(struct file *filp, poll_table *wait)
 {
-       struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
+       struct sn9c102_device *cam = video_drvdata(filp);
        struct sn9c102_frame_t* f;
        unsigned long lock_flags;
        unsigned int mask = 0;
@@ -2063,7 +2083,7 @@ static struct vm_operations_struct sn9c102_vm_ops = {
 
 static int sn9c102_mmap(struct file* filp, struct vm_area_struct *vma)
 {
-       struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
+       struct sn9c102_device *cam = video_drvdata(filp);
        unsigned long size = vma->vm_end - vma->vm_start,
                      start = vma->vm_start;
        void *pos;
@@ -3075,7 +3095,7 @@ sn9c102_vidioc_s_audio(struct sn9c102_device* cam, void __user * arg)
 static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
                              unsigned int cmd, void __user * arg)
 {
-       struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
+       struct sn9c102_device *cam = video_drvdata(filp);
 
        switch (cmd) {
 
@@ -3179,7 +3199,7 @@ static int sn9c102_ioctl_v4l2(struct inode* inode, struct file* filp,
 static int sn9c102_ioctl(struct inode* inode, struct file* filp,
                         unsigned int cmd, unsigned long arg)
 {
-       struct sn9c102_device* cam = video_get_drvdata(video_devdata(filp));
+       struct sn9c102_device *cam = video_drvdata(filp);
        int err = 0;
 
        if (mutex_lock_interruptible(&cam->fileop_mutex))
index 90a401dc38849b20cba1fe16cffba82e2f3fe16f..e23734f6d6e2255535875b297204585ebb8d0478 100644 (file)
@@ -140,24 +140,4 @@ extern int sn9c102_probe_tas5110c1b(struct sn9c102_device* cam);
 extern int sn9c102_probe_tas5110d(struct sn9c102_device* cam);
 extern int sn9c102_probe_tas5130d1b(struct sn9c102_device* cam);
 
-/*
-   Add the above entries to this table. Be sure to add the entry in the right
-   place, since, on failure, the next probing routine is called according to
-   the order of the list below, from top to bottom.
-*/
-static int (*sn9c102_sensor_table[])(struct sn9c102_device*) = {
-       &sn9c102_probe_hv7131d, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_hv7131r, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_mi0343, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_mi0360, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_mt9v111, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_pas106b, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_pas202bcb, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_ov7630, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_ov7660, /* strong detection based on SENSOR ids */
-       &sn9c102_probe_tas5110c1b, /* detection based on USB pid/vid */
-       &sn9c102_probe_tas5110d, /* detection based on USB pid/vid */
-       &sn9c102_probe_tas5130d1b, /* detection based on USB pid/vid */
-};
-
 #endif /* _SN9C102_DEVTABLE_H_ */
index eaf9ad0dc8a65596a8b5836a161a4d334d34fa87..db2434948939f226c228c110250ec8affd69a868 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int hv7131d_init(struct sn9c102_device* cam)
index 0fc401223cfc9c08741fa3595b93cadf7811f5b3..4295887ff6098b610a50acddfd46a8a3e2f023d4 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int hv7131r_init(struct sn9c102_device* cam)
index 00b134ca0a3d56ac0d122bc15040c9f38cb99633..1f5b09bec89c7ec2f729e18c57848f965fa4ef76 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int mi0343_init(struct sn9c102_device* cam)
index f8d81d82e8d50e537ea85004b897e086aa1e4a97..d973fc1973d999fafb44a1434a0b8daf5208c515 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int mi0360_init(struct sn9c102_device* cam)
index 3b98ac3bbc38013a8276202a1ae89db8c3d425ae..95986eb492e4b9b065d95e413ff4e80dd2911954 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int mt9v111_init(struct sn9c102_device *cam)
index e4856fd779823af7c0bd508f1c313b1673453245..803712c29f020edd0dc2bbbd00483a334e89d93b 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int ov7630_init(struct sn9c102_device* cam)
index 8aae416ba8ec236bf06c88cc67ffbfb32e6a575c..7977795d342b73b7d8d0f20773cf61e29ab0a934 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int ov7660_init(struct sn9c102_device* cam)
index 360f2a848bc018212b8b8a3052f91d5787400cfe..81cd969c1b7b19d7e1472071403d1427dfec8bb6 100644 (file)
@@ -21,6 +21,7 @@
 
 #include <linux/delay.h>
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int pas106b_init(struct sn9c102_device* cam)
index ca4a1506ed3df7cee74976afb2973d41152bf15e..2782f94cf6f80e7c04cb84b93c2994f2bb018d7b 100644 (file)
@@ -26,6 +26,7 @@
 
 #include <linux/delay.h>
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int pas202bcb_init(struct sn9c102_device* cam)
index e7d2de2bace1096d837f16de2d03c39ce6c92f95..04cdfdde8564d3f9697cf2f772c136ad11c0ebd5 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int tas5110c1b_init(struct sn9c102_device* cam)
index d32fdbccdc5eb3fbbcc8fe5f083887f8049d284f..9372e6f9fcff72ecf620dc5f4fdb188661468070 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int tas5110d_init(struct sn9c102_device* cam)
index 56fb1d575a8a6fd74a247de569a5e3d323c97080..a30bbc4389f5d9d2cbb8d98391784897a32292be 100644 (file)
@@ -20,6 +20,7 @@
  ***************************************************************************/
 
 #include "sn9c102_sensor.h"
+#include "sn9c102_devtable.h"
 
 
 static int tas5130d1b_init(struct sn9c102_device* cam)
index ad36af30e0992195fa1f72da85428f394d4251a4..db69bc5556d6776c84a51c78f7460f927d04d350 100644 (file)
@@ -65,22 +65,6 @@ static struct usb_device_id stkwebcam_table[] = {
 };
 MODULE_DEVICE_TABLE(usb, stkwebcam_table);
 
-static void stk_camera_cleanup(struct kref *kref)
-{
-       struct stk_camera *dev = to_stk_camera(kref);
-
-       STK_INFO("Syntek USB2.0 Camera release resources"
-               " video device /dev/video%d\n", dev->vdev.minor);
-       video_unregister_device(&dev->vdev);
-       dev->vdev.priv = NULL;
-
-       if (dev->sio_bufs != NULL || dev->isobufs != NULL)
-               STK_ERROR("We are leaking memory\n");
-       usb_put_intf(dev->interface);
-       kfree(dev);
-}
-
-
 /*
  * Basic stuff
  */
@@ -689,34 +673,24 @@ static int v4l_stk_open(struct inode *inode, struct file *fp)
        vdev = video_devdata(fp);
        dev = vdev_to_camera(vdev);
 
-       if (dev == NULL || !is_present(dev))
+       lock_kernel();
+       if (dev == NULL || !is_present(dev)) {
+               unlock_kernel();
                return -ENXIO;
-       fp->private_data = vdev;
-       kref_get(&dev->kref);
+       }
+       fp->private_data = dev;
        usb_autopm_get_interface(dev->interface);
+       unlock_kernel();
 
        return 0;
 }
 
 static int v4l_stk_release(struct inode *inode, struct file *fp)
 {
-       struct stk_camera *dev;
-       struct video_device *vdev;
-
-       vdev = video_devdata(fp);
-       if (vdev == NULL) {
-               STK_ERROR("v4l_release called w/o video devdata\n");
-               return -EFAULT;
-       }
-       dev = vdev_to_camera(vdev);
-       if (dev == NULL) {
-               STK_ERROR("v4l_release called on removed device\n");
-               return -ENODEV;
-       }
+       struct stk_camera *dev = fp->private_data;
 
        if (dev->owner != fp) {
                usb_autopm_put_interface(dev->interface);
-               kref_put(&dev->kref, stk_camera_cleanup);
                return 0;
        }
 
@@ -727,7 +701,6 @@ static int v4l_stk_release(struct inode *inode, struct file *fp)
        dev->owner = NULL;
 
        usb_autopm_put_interface(dev->interface);
-       kref_put(&dev->kref, stk_camera_cleanup);
 
        return 0;
 }
@@ -738,14 +711,8 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
        int i;
        int ret;
        unsigned long flags;
-       struct stk_camera *dev;
-       struct video_device *vdev;
        struct stk_sio_buffer *sbuf;
-
-       vdev = video_devdata(fp);
-       if (vdev == NULL)
-               return -EFAULT;
-       dev = vdev_to_camera(vdev);
+       struct stk_camera *dev = fp->private_data;
 
        if (dev == NULL)
                return -EIO;
@@ -804,15 +771,8 @@ static ssize_t v4l_stk_read(struct file *fp, char __user *buf,
 
 static unsigned int v4l_stk_poll(struct file *fp, poll_table *wait)
 {
-       struct stk_camera *dev;
-       struct video_device *vdev;
-
-       vdev = video_devdata(fp);
-
-       if (vdev == NULL)
-               return -EFAULT;
+       struct stk_camera *dev = fp->private_data;
 
-       dev = vdev_to_camera(vdev);
        if (dev == NULL)
                return -ENODEV;
 
@@ -850,16 +810,12 @@ static int v4l_stk_mmap(struct file *fp, struct vm_area_struct *vma)
        unsigned int i;
        int ret;
        unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
-       struct stk_camera *dev;
-       struct video_device *vdev;
+       struct stk_camera *dev = fp->private_data;
        struct stk_sio_buffer *sbuf = NULL;
 
        if (!(vma->vm_flags & VM_WRITE) || !(vma->vm_flags & VM_SHARED))
                return -EINVAL;
 
-       vdev = video_devdata(fp);
-       dev = vdev_to_camera(vdev);
-
        for (i = 0; i < dev->n_sbufs; i++) {
                if (dev->sio_bufs[i].v4lbuf.m.offset == offset) {
                        sbuf = dev->sio_bufs + i;
@@ -1355,6 +1311,12 @@ static const struct v4l2_ioctl_ops v4l_stk_ioctl_ops = {
 
 static void stk_v4l_dev_release(struct video_device *vd)
 {
+       struct stk_camera *dev = vdev_to_camera(vd);
+
+       if (dev->sio_bufs != NULL || dev->isobufs != NULL)
+               STK_ERROR("We are leaking memory\n");
+       usb_put_intf(dev->interface);
+       kfree(dev);
 }
 
 static struct video_device stk_v4l_data = {
@@ -1375,7 +1337,6 @@ static int stk_register_video_device(struct stk_camera *dev)
        dev->vdev = stk_v4l_data;
        dev->vdev.debug = debug;
        dev->vdev.parent = &dev->interface->dev;
-       dev->vdev.priv = dev;
        err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
        if (err)
                STK_ERROR("v4l registration failed\n");
@@ -1392,7 +1353,7 @@ static int stk_camera_probe(struct usb_interface *interface,
                const struct usb_device_id *id)
 {
        int i;
-       int err;
+       int err = 0;
 
        struct stk_camera *dev = NULL;
        struct usb_device *udev = interface_to_usbdev(interface);
@@ -1405,7 +1366,6 @@ static int stk_camera_probe(struct usb_interface *interface,
                return -ENOMEM;
        }
 
-       kref_init(&dev->kref);
        spin_lock_init(&dev->spinlock);
        init_waitqueue_head(&dev->wait_frame);
 
@@ -1438,8 +1398,8 @@ static int stk_camera_probe(struct usb_interface *interface,
        }
        if (!dev->isoc_ep) {
                STK_ERROR("Could not find isoc-in endpoint");
-               kref_put(&dev->kref, stk_camera_cleanup);
-               return -ENODEV;
+               err = -ENODEV;
+               goto error;
        }
        dev->vsettings.brightness = 0x7fff;
        dev->vsettings.palette = V4L2_PIX_FMT_RGB565;
@@ -1453,14 +1413,17 @@ static int stk_camera_probe(struct usb_interface *interface,
 
        err = stk_register_video_device(dev);
        if (err) {
-               kref_put(&dev->kref, stk_camera_cleanup);
-               return err;
+               goto error;
        }
 
        stk_create_sysfs_files(&dev->vdev);
        usb_autopm_enable(dev->interface);
 
        return 0;
+
+error:
+       kfree(dev);
+       return err;
 }
 
 static void stk_camera_disconnect(struct usb_interface *interface)
@@ -1473,7 +1436,10 @@ static void stk_camera_disconnect(struct usb_interface *interface)
        wake_up_interruptible(&dev->wait_frame);
        stk_remove_sysfs_files(&dev->vdev);
 
-       kref_put(&dev->kref, stk_camera_cleanup);
+       STK_INFO("Syntek USB2.0 Camera release resources"
+               "video device /dev/video%d\n", dev->vdev.minor);
+
+       video_unregister_device(&dev->vdev);
 }
 
 #ifdef CONFIG_PM
index df4dfefc5327e1652ae607c6fb903af214092b10..084a85bdd16e642a49d27175a68677cbd2d8bda2 100644 (file)
@@ -99,7 +99,6 @@ struct stk_camera {
 
        u8 isoc_ep;
 
-       struct kref kref;
        /* Not sure if this is right */
        atomic_t urbs_used;
 
@@ -121,7 +120,6 @@ struct stk_camera {
        unsigned sequence;
 };
 
-#define to_stk_camera(d) container_of(d, struct stk_camera, kref)
 #define vdev_to_camera(d) container_of(d, struct stk_camera, vdev)
 
 void stk_camera_delete(struct kref *);
index 276bded06ab3eb9ac9b7f9414000b1918d81ce24..bbad54f85c83c83a92d8d4d41cdedf70af3b1803 100644 (file)
@@ -1882,12 +1882,16 @@ static int saa_open(struct inode *inode, struct file *file)
        struct video_device *vdev = video_devdata(file);
        struct saa7146 *saa = container_of(vdev, struct saa7146, video_dev);
 
+       lock_kernel();
        file->private_data = saa;
 
        saa->user++;
-       if (saa->user > 1)
+       if (saa->user > 1) {
+               unlock_kernel();
                return 0;       /* device open already, don't reset */
+       }
        saa->writemode = VID_WRITE_MPEG_VID;    /* default to video */
+       unlock_kernel();
        return 0;
 }
 
@@ -1921,6 +1925,7 @@ static struct video_device saa_template = {
        .name = "SAA7146A",
        .fops = &saa_fops,
        .minor = -1,
+       .release = video_device_release_empty,
 };
 
 static int __devinit configure_saa7146(struct pci_dev *pdev, int num)
index dce947439459ca46e2d020b49440a318a6c9e20c..9c549d93599426c3d0ad53348b481edeb8decb52 100644 (file)
@@ -84,7 +84,8 @@ static unsigned int debug;
 #define PDEBUG(level, fmt, args...) \
        do { \
        if (debug >= level)     \
-               info("[%s:%d] " fmt, __func__, __LINE__ , ## args);     \
+               printk(KERN_INFO KBUILD_MODNAME " [%s:%d] \n" fmt,      \
+                       __func__, __LINE__ , ## args);  \
        } while (0)
 
 
@@ -1086,6 +1087,7 @@ static int stv_open (struct inode *inode, struct file *file)
        int err = 0;
 
        /* we are called with the BKL held */
+       lock_kernel();
        stv680->user = 1;
        err = stv_init (stv680);        /* main initialization routine for camera */
 
@@ -1099,6 +1101,7 @@ static int stv_open (struct inode *inode, struct file *file)
        }
        if (err)
                stv680->user = 0;
+       unlock_kernel();
 
        return err;
 }
@@ -1550,7 +1553,8 @@ static int __init usb_stv680_init (void)
        }
        PDEBUG (0, "STV(i): usb camera driver version %s registering", DRIVER_VERSION);
 
-       info(DRIVER_DESC " " DRIVER_VERSION);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
        return 0;
 }
 
index 2437c1a269c58e98890ecf3f91c811c5d577938f..1c391f0328fd195c1f977956cae06d5ab02428fa 100644 (file)
@@ -2,6 +2,7 @@
     tda9840 - i2c-driver for the tda9840 by SGS Thomson
 
     Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
+    Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
 
     The tda9840 is a stereo/dual sound processor with digital
     identification. It can be found at address 0x84 on the i2c-bus.
 #include <linux/module.h>
 #include <linux/ioctl.h>
 #include <linux/i2c.h>
-
+#include <media/v4l2-common.h>
+#include <media/v4l2-i2c-drv-legacy.h>
 #include "tda9840.h"
 
-static int debug;              /* insmod parameter */
+MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
+MODULE_DESCRIPTION("tda9840 driver");
+MODULE_LICENSE("GPL");
+
+static int debug;
 module_param(debug, int, 0644);
-MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
 
-#define dprintk(args...) \
-           do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
+MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
 #define        SWITCH          0x00
 #define        LEVEL_ADJUST    0x02
 #define        STEREO_ADJUST   0x03
 #define        TEST            0x04
 
+#define TDA9840_SET_MUTE                0x00
+#define TDA9840_SET_MONO                0x10
+#define TDA9840_SET_STEREO              0x2a
+#define TDA9840_SET_LANG1               0x12
+#define TDA9840_SET_LANG2               0x1e
+#define TDA9840_SET_BOTH                0x1a
+#define TDA9840_SET_BOTH_R              0x16
+#define TDA9840_SET_EXTERNAL            0x7a
+
 /* addresses to scan, found only at 0x42 (7-Bit) */
 static unsigned short normal_i2c[] = { I2C_ADDR_TDA9840, I2C_CLIENT_END };
 
 /* magic definition of all other variables and things */
 I2C_CLIENT_INSMOD;
 
-static struct i2c_driver driver;
-static struct i2c_client client_template;
+static void tda9840_write(struct i2c_client *client, u8 reg, u8 val)
+{
+       if (i2c_smbus_write_byte_data(client, reg, val))
+               v4l_dbg(1, debug, client, "error writing %02x to %02x\n",
+                               val, reg);
+}
 
-static int command(struct i2c_client *client, unsigned int cmd, void *arg)
+static int tda9840_command(struct i2c_client *client, unsigned cmd, void *arg)
 {
-       int result;
        int byte = *(int *)arg;
 
        switch (cmd) {
-       case TDA9840_SWITCH:
-
-               dprintk("TDA9840_SWITCH: 0x%02x\n", byte);
-
-               if (byte != TDA9840_SET_MONO
-                   && byte != TDA9840_SET_MUTE
-                   && byte != TDA9840_SET_STEREO
-                   && byte != TDA9840_SET_LANG1
-                   && byte != TDA9840_SET_LANG2
-                   && byte != TDA9840_SET_BOTH
-                   && byte != TDA9840_SET_BOTH_R
-                   && byte != TDA9840_SET_EXTERNAL) {
+       case VIDIOC_S_TUNER: {
+               struct v4l2_tuner *t = arg;
+               int byte;
+
+               if (t->index)
                        return -EINVAL;
+
+               switch (t->audmode) {
+               case V4L2_TUNER_MODE_STEREO:
+                       byte = TDA9840_SET_STEREO;
+                       break;
+               case V4L2_TUNER_MODE_LANG1_LANG2:
+                       byte = TDA9840_SET_BOTH;
+                       break;
+               case V4L2_TUNER_MODE_LANG1:
+                       byte = TDA9840_SET_LANG1;
+                       break;
+               case V4L2_TUNER_MODE_LANG2:
+                       byte = TDA9840_SET_LANG2;
+                       break;
+               default:
+                       byte = TDA9840_SET_MONO;
+                       break;
+               }
+               v4l_dbg(1, debug, client, "TDA9840_SWITCH: 0x%02x\n", byte);
+               tda9840_write(client, SWITCH, byte);
+               break;
+       }
+
+       case VIDIOC_G_TUNER: {
+               struct v4l2_tuner *t = arg;
+               u8 byte;
+
+               t->rxsubchans = V4L2_TUNER_SUB_MONO;
+               if (1 != i2c_master_recv(client, &byte, 1)) {
+                       v4l_dbg(1, debug, client,
+                               "i2c_master_recv() failed\n");
+                       return -EIO;
                }
 
-               result = i2c_smbus_write_byte_data(client, SWITCH, byte);
-               if (result)
-                       dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
+               if (byte & 0x80) {
+                       v4l_dbg(1, debug, client,
+                               "TDA9840_DETECT: register contents invalid\n");
+                       return -EINVAL;
+               }
+
+               v4l_dbg(1, debug, client, "TDA9840_DETECT: byte: 0x%02x\n", byte);
+
+               switch (byte & 0x60) {
+               case 0x00:
+                       t->rxsubchans = V4L2_TUNER_SUB_MONO;
+                       break;
+               case 0x20:
+                       t->rxsubchans = V4L2_TUNER_SUB_LANG1 | V4L2_TUNER_SUB_LANG2;
+                       break;
+               case 0x40:
+                       t->rxsubchans = V4L2_TUNER_SUB_STEREO | V4L2_TUNER_SUB_MONO;
+                       break;
+               default: /* Incorrect detect */
+                       t->rxsubchans = V4L2_TUNER_MODE_MONO;
+                       break;
+               }
                break;
+       }
 
        case TDA9840_LEVEL_ADJUST:
-
-               dprintk("TDA9840_LEVEL_ADJUST: %d\n", byte);
+               v4l_dbg(1, debug, client, "TDA9840_LEVEL_ADJUST: %d\n", byte);
 
                /* check for correct range */
                if (byte > 25 || byte < -20)
@@ -92,15 +152,11 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
                        byte += 0x8;
                else
                        byte = -byte;
-
-               result = i2c_smbus_write_byte_data(client, LEVEL_ADJUST, byte);
-               if (result)
-                       dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
+               tda9840_write(client, LEVEL_ADJUST, byte);
                break;
 
        case TDA9840_STEREO_ADJUST:
-
-               dprintk("TDA9840_STEREO_ADJUST: %d\n", byte);
+               v4l_dbg(1, debug, client, "TDA9840_STEREO_ADJUST: %d\n", byte);
 
                /* check for correct range */
                if (byte > 25 || byte < -24)
@@ -113,143 +169,59 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
                else
                        byte = -byte;
 
-               result = i2c_smbus_write_byte_data(client, STEREO_ADJUST, byte);
-               if (result)
-                       dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
-               break;
-
-       case TDA9840_DETECT: {
-               int *ret = (int *)arg;
-
-               byte = i2c_smbus_read_byte_data(client, STEREO_ADJUST);
-               if (byte == -1) {
-                       dprintk("i2c_smbus_read_byte_data() failed\n");
-                       return -EIO;
-               }
-
-               if (0 != (byte & 0x80)) {
-                       dprintk("TDA9840_DETECT: register contents invalid\n");
-                       return -EINVAL;
-               }
-
-               dprintk("TDA9840_DETECT: byte: 0x%02x\n", byte);
-               *ret = ((byte & 0x60) >> 5);
-               result = 0;
-               break;
-       }
-       case TDA9840_TEST:
-               dprintk("TDA9840_TEST: 0x%02x\n", byte);
-
-               /* mask out irrelevant bits */
-               byte &= 0x3;
-
-               result = i2c_smbus_write_byte_data(client, TEST, byte);
-               if (result)
-                       dprintk("i2c_smbus_write_byte() failed, ret:%d\n", result);
+               tda9840_write(client, STEREO_ADJUST, byte);
                break;
        default:
                return -ENOIOCTLCMD;
        }
 
-       if (result)
-               return -EIO;
-
        return 0;
 }
 
-static int detect(struct i2c_adapter *adapter, int address, int kind)
+static int tda9840_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
 {
-       struct i2c_client *client;
-       int result = 0;
-
-       int byte = 0x0;
+       int result;
+       int byte;
 
        /* let's see whether this adapter can support what we need */
-       if (0 == i2c_check_functionality(adapter,
-                                   I2C_FUNC_SMBUS_READ_BYTE_DATA |
-                                   I2C_FUNC_SMBUS_WRITE_BYTE_DATA)) {
+       if (!i2c_check_functionality(client->adapter,
+                       I2C_FUNC_SMBUS_READ_BYTE_DATA |
+                       I2C_FUNC_SMBUS_WRITE_BYTE_DATA))
                return 0;
-       }
-
-       /* allocate memory for client structure */
-       client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (!client) {
-               printk("not enough kernel memory\n");
-               return -ENOMEM;
-       }
-
-       /* fill client structure */
-       memcpy(client, &client_template, sizeof(struct i2c_client));
-       client->addr = address;
-       client->adapter = adapter;
 
-       /* tell the i2c layer a new client has arrived */
-       if (0 != (result = i2c_attach_client(client))) {
-               kfree(client);
-               return result;
-       }
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
 
        /* set initial values for level & stereo - adjustment, mode */
        byte = 0;
-       result  = command(client, TDA9840_LEVEL_ADJUST, &byte);
-       result += command(client, TDA9840_STEREO_ADJUST, &byte);
-       byte = TDA9840_SET_MONO;
-       result = command(client, TDA9840_SWITCH, &byte);
+       result = tda9840_command(client, TDA9840_LEVEL_ADJUST, &byte);
+       result += tda9840_command(client, TDA9840_STEREO_ADJUST, &byte);
+       tda9840_write(client, SWITCH, TDA9840_SET_STEREO);
        if (result) {
-               dprintk("could not initialize tda9840\n");
+               v4l_dbg(1, debug, client, "could not initialize tda9840\n");
                return -ENODEV;
        }
-
-       printk("tda9840: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
        return 0;
 }
 
-static int attach(struct i2c_adapter *adapter)
-{
-       /* let's see whether this is a know adapter we can attach to */
-       if (adapter->id != I2C_HW_SAA7146) {
-               dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
-               return -ENODEV;
-       }
-
-       return i2c_probe(adapter, &addr_data, &detect);
-}
-
-static int detach(struct i2c_client *client)
+static int tda9840_legacy_probe(struct i2c_adapter *adapter)
 {
-       int ret = i2c_detach_client(client);
-       kfree(client);
-       return ret;
+       /* Let's see whether this is a known adapter we can attach to.
+          Prevents conflicts with tvaudio.c. */
+       return adapter->id == I2C_HW_SAA7146;
 }
-
-static struct i2c_driver driver = {
-       .driver = {
-               .name = "tda9840",
-       },
-       .id     = I2C_DRIVERID_TDA9840,
-       .attach_adapter = attach,
-       .detach_client  = detach,
-       .command        = command,
+static const struct i2c_device_id tda9840_id[] = {
+       { "tda9840", 0 },
+       { }
 };
+MODULE_DEVICE_TABLE(i2c, tda9840_id);
 
-static struct i2c_client client_template = {
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
        .name = "tda9840",
-       .driver = &driver,
+       .driverid = I2C_DRIVERID_TDA9840,
+       .command = tda9840_command,
+       .probe = tda9840_probe,
+       .legacy_probe = tda9840_legacy_probe,
+       .id_table = tda9840_id,
 };
-
-static int __init this_module_init(void)
-{
-       return i2c_add_driver(&driver);
-}
-
-static void __exit this_module_exit(void)
-{
-       i2c_del_driver(&driver);
-}
-
-module_init(this_module_init);
-module_exit(this_module_exit);
-
-MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
-MODULE_DESCRIPTION("tda9840 driver");
-MODULE_LICENSE("GPL");
index 7da8432cdca7378ea1c4879c0e7db27213753d75..dc12ae7caf6f0b3801e37df82e387db1707c168a 100644 (file)
@@ -3,24 +3,6 @@
 
 #define        I2C_ADDR_TDA9840                0x42
 
-#define TDA9840_DETECT         _IOR('v',1,int)
-/* return values for TDA9840_DETCT */
-#define TDA9840_MONO_DETECT            0x0
-#define        TDA9840_DUAL_DETECT             0x1
-#define        TDA9840_STEREO_DETECT           0x2
-#define        TDA9840_INCORRECT_DETECT        0x3
-
-#define TDA9840_SWITCH         _IOW('v',2,int)
-/* modes than can be set with TDA9840_SWITCH */
-#define        TDA9840_SET_MUTE                0x00
-#define        TDA9840_SET_MONO                0x10
-#define        TDA9840_SET_STEREO              0x2a
-#define        TDA9840_SET_LANG1               0x12
-#define        TDA9840_SET_LANG2               0x1e
-#define        TDA9840_SET_BOTH                0x1a
-#define        TDA9840_SET_BOTH_R              0x16
-#define        TDA9840_SET_EXTERNAL            0x7a
-
 /* values may range between +2.5 and -2.0;
    the value has to be multiplied with 10 */
 #define TDA9840_LEVEL_ADJUST   _IOW('v',3,int)
@@ -29,7 +11,4 @@
    the value has to be multiplied with 10 */
 #define TDA9840_STEREO_ADJUST  _IOW('v',4,int)
 
-/* currently not implemented */
-#define TDA9840_TEST           _IOW('v',5,int)
-
 #endif
index 421c1445e96cd5210ceddb22d2156b474292aa70..cde092adbb5abffdd1aafaf0b21d2b566ff20bcd 100644 (file)
@@ -2,6 +2,7 @@
     tea6415c - i2c-driver for the tea6415c by SGS Thomson
 
     Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
+    Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
 
     The tea6415c is a bus controlled video-matrix-switch
     with 8 inputs and 6 outputs.
 #include <linux/module.h>
 #include <linux/ioctl.h>
 #include <linux/i2c.h>
-
+#include <media/v4l2-common.h>
+#include <media/v4l2-i2c-drv-legacy.h>
 #include "tea6415c.h"
 
-static int debug;              /* insmod parameter */
-module_param(debug, int, 0644);
-MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
+MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
+MODULE_DESCRIPTION("tea6415c driver");
+MODULE_LICENSE("GPL");
 
-#define dprintk(args...) \
-           do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
+static int debug;
+module_param(debug, int, 0644);
 
-#define TEA6415C_NUM_INPUTS    8
-#define TEA6415C_NUM_OUTPUTS   6
+MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
 /* addresses to scan, found only at 0x03 and/or 0x43 (7-bit) */
 static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIENT_END };
@@ -49,60 +50,6 @@ static unsigned short normal_i2c[] = { I2C_TEA6415C_1, I2C_TEA6415C_2, I2C_CLIEN
 /* magic definition of all other variables and things */
 I2C_CLIENT_INSMOD;
 
-static struct i2c_driver driver;
-static struct i2c_client client_template;
-
-/* this function is called by i2c_probe */
-static int detect(struct i2c_adapter *adapter, int address, int kind)
-{
-       struct i2c_client *client = NULL;
-       int err = 0;
-
-       /* let's see whether this adapter can support what we need */
-       if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
-               return 0;
-       }
-
-       /* allocate memory for client structure */
-       client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (!client) {
-               return -ENOMEM;
-       }
-
-       /* fill client structure */
-       memcpy(client, &client_template, sizeof(struct i2c_client));
-       client->addr = address;
-       client->adapter = adapter;
-
-       /* tell the i2c layer a new client has arrived */
-       if (0 != (err = i2c_attach_client(client))) {
-               kfree(client);
-               return err;
-       }
-
-       printk("tea6415c: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
-
-       return 0;
-}
-
-static int attach(struct i2c_adapter *adapter)
-{
-       /* let's see whether this is a know adapter we can attach to */
-       if (adapter->id != I2C_HW_SAA7146) {
-               dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
-               return -ENODEV;
-       }
-
-       return i2c_probe(adapter, &addr_data, &detect);
-}
-
-static int detach(struct i2c_client *client)
-{
-       int ret = i2c_detach_client(client);
-       kfree(client);
-       return ret;
-}
-
 /* makes a connection between the input-pin 'i' and the output-pin 'o'
    for the tea6415c-client 'client' */
 static int switch_matrix(struct i2c_client *client, int i, int o)
@@ -110,7 +57,7 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
        u8 byte = 0;
        int ret;
 
-       dprintk("adr:0x%02x, i:%d, o:%d\n", client->addr, i, o);
+       v4l_dbg(1, debug, client, "i=%d, o=%d\n", i, o);
 
        /* check if the pins are valid */
        if (0 == ((1 == i ||  3 == i ||  5 == i ||  6 == i ||  8 == i || 10 == i || 20 == i || 11 == i)
@@ -168,14 +115,14 @@ static int switch_matrix(struct i2c_client *client, int i, int o)
 
        ret = i2c_smbus_write_byte(client, byte);
        if (ret) {
-               dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret);
+               v4l_dbg(1, debug, client,
+                       "i2c_smbus_write_byte() failed, ret:%d\n", ret);
                return -EIO;
        }
-
        return ret;
 }
 
-static int command(struct i2c_client *client, unsigned int cmd, void *arg)
+static int tea6415c_command(struct i2c_client *client, unsigned cmd, void *arg)
 {
        struct tea6415c_multiplex *v = (struct tea6415c_multiplex *)arg;
        int result = 0;
@@ -187,38 +134,40 @@ static int command(struct i2c_client *client, unsigned int cmd, void *arg)
        default:
                return -ENOIOCTLCMD;
        }
-
        return result;
 }
 
-static struct i2c_driver driver = {
-       .driver = {
-               .name = "tea6415c",
-       },
-       .id     = I2C_DRIVERID_TEA6415C,
-       .attach_adapter = attach,
-       .detach_client  = detach,
-       .command        = command,
-};
-
-static struct i2c_client client_template = {
-       .name = "tea6415c",
-       .driver = &driver,
-};
-
-static int __init this_module_init(void)
+/* this function is called by i2c_probe */
+static int tea6415c_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
 {
-       return i2c_add_driver(&driver);
+       /* let's see whether this adapter can support what we need */
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
+               return 0;
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
+       return 0;
 }
 
-static void __exit this_module_exit(void)
+static int tea6415c_legacy_probe(struct i2c_adapter *adapter)
 {
-       i2c_del_driver(&driver);
+       /* Let's see whether this is a known adapter we can attach to.
+          Prevents conflicts with tvaudio.c. */
+       return adapter->id == I2C_HW_SAA7146;
 }
 
-module_init(this_module_init);
-module_exit(this_module_exit);
+static const struct i2c_device_id tea6415c_id[] = {
+       { "tea6415c", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, tea6415c_id);
 
-MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
-MODULE_DESCRIPTION("tea6415c driver");
-MODULE_LICENSE("GPL");
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
+       .name = "tea6415c",
+       .driverid = I2C_DRIVERID_TEA6415C,
+       .command = tea6415c_command,
+       .probe = tea6415c_probe,
+       .legacy_probe = tea6415c_legacy_probe,
+       .id_table = tea6415c_id,
+};
index b5c8957d130e0115d450c3d0b56ab78b15a9ba03..e50820969e6485f5bde152e43bcc0f741df685ac 100644 (file)
@@ -2,6 +2,7 @@
     tea6420 - i2c-driver for the tea6420 by SGS Thomson
 
     Copyright (C) 1998-2003 Michael Hunold <michael@mihu.de>
+    Copyright (C) 2008 Hans Verkuil <hverkuil@xs4all.nl>
 
     The tea6420 is a bus controlled audio-matrix with 5 stereo inputs,
     4 stereo outputs and gain control for each output.
 #include <linux/module.h>
 #include <linux/ioctl.h>
 #include <linux/i2c.h>
-
+#include <media/v4l2-common.h>
+#include <media/v4l2-i2c-drv-legacy.h>
 #include "tea6420.h"
 
-static int debug;              /* insmod parameter */
+MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
+MODULE_DESCRIPTION("tea6420 driver");
+MODULE_LICENSE("GPL");
+
+static int debug;
 module_param(debug, int, 0644);
-MODULE_PARM_DESC(debug, "Turn on/off device debugging (default:off).");
 
-#define dprintk(args...) \
-           do { if (debug) { printk("%s: %s()[%d]: ", KBUILD_MODNAME, __func__, __LINE__); printk(args); } } while (0)
+MODULE_PARM_DESC(debug, "Debug level (0-1)");
 
 /* addresses to scan, found only at 0x4c and/or 0x4d (7-Bit) */
 static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I2C_CLIENT_END };
@@ -46,23 +50,20 @@ static unsigned short normal_i2c[] = { I2C_ADDR_TEA6420_1, I2C_ADDR_TEA6420_2, I
 /* magic definition of all other variables and things */
 I2C_CLIENT_INSMOD;
 
-static struct i2c_driver driver;
-static struct i2c_client client_template;
-
 /* make a connection between the input 'i' and the output 'o'
    with gain 'g' for the tea6420-client 'client' (note: i = 6 means 'mute') */
 static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
 {
-       u8 byte = 0;
+       u8 byte;
        int ret;
 
-       dprintk("adr:0x%02x, i:%d, o:%d, g:%d\n", client->addr, i, o, g);
+       v4l_dbg(1, debug, client, "i=%d, o=%d, g=%d\n", i, o, g);
 
        /* check if the parameters are valid */
        if (i < 1 || i > 6 || o < 1 || o > 4 || g < 0 || g > 6 || g % 2 != 0)
                return -1;
 
-       byte  = ((o - 1) << 5);
+       byte = ((o - 1) << 5);
        byte |= (i - 1);
 
        /* to understand this, have a look at the tea6420-specs (p.5) */
@@ -82,40 +83,41 @@ static int tea6420_switch(struct i2c_client *client, int i, int o, int g)
 
        ret = i2c_smbus_write_byte(client, byte);
        if (ret) {
-               dprintk("i2c_smbus_write_byte() failed, ret:%d\n", ret);
+               v4l_dbg(1, debug, client,
+                       "i2c_smbus_write_byte() failed, ret:%d\n", ret);
                return -EIO;
        }
-
        return 0;
 }
 
-/* this function is called by i2c_probe */
-static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
+static int tea6420_command(struct i2c_client *client, unsigned cmd, void *arg)
 {
-       struct i2c_client *client;
-       int err = 0, i = 0;
+       struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
+       int result = 0;
 
-       /* let's see whether this adapter can support what we need */
-       if (0 == i2c_check_functionality(adapter, I2C_FUNC_SMBUS_WRITE_BYTE)) {
-               return 0;
+       switch (cmd) {
+       case TEA6420_SWITCH:
+               result = tea6420_switch(client, a->in, a->out, a->gain);
+               break;
+       default:
+               return -ENOIOCTLCMD;
        }
 
-       /* allocate memory for client structure */
-       client = kzalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (!client) {
-               return -ENOMEM;
-       }
+       return result;
+}
 
-       /* fill client structure */
-       memcpy(client, &client_template, sizeof(struct i2c_client));
-       client->addr = address;
-       client->adapter = adapter;
+/* this function is called by i2c_probe */
+static int tea6420_probe(struct i2c_client *client,
+                         const struct i2c_device_id *id)
+{
+       int err, i;
 
-       /* tell the i2c layer a new client has arrived */
-       if (0 != (err = i2c_attach_client(client))) {
-               kfree(client);
-               return err;
-       }
+       /* let's see whether this adapter can support what we need */
+       if (!i2c_check_functionality(client->adapter, I2C_FUNC_SMBUS_WRITE_BYTE))
+               return -EIO;
+
+       v4l_info(client, "chip found @ 0x%x (%s)\n",
+                       client->addr << 1, client->adapter->name);
 
        /* set initial values: set "mute"-input to all outputs at gain 0 */
        err = 0;
@@ -123,78 +125,31 @@ static int tea6420_detect(struct i2c_adapter *adapter, int address, int kind)
                err += tea6420_switch(client, 6, i, 0);
        }
        if (err) {
-               dprintk("could not initialize tea6420\n");
+               v4l_dbg(1, debug, client, "could not initialize tea6420\n");
                kfree(client);
                return -ENODEV;
        }
-
-       printk("tea6420: detected @ 0x%02x on adapter %s\n", address, &client->adapter->name[0]);
-
        return 0;
 }
 
-static int attach(struct i2c_adapter *adapter)
+static int tea6420_legacy_probe(struct i2c_adapter *adapter)
 {
-       /* let's see whether this is a know adapter we can attach to */
-       if (adapter->id != I2C_HW_SAA7146) {
-               dprintk("refusing to probe on unknown adapter [name='%s',id=0x%x]\n", adapter->name, adapter->id);
-               return -ENODEV;
-       }
-
-       return i2c_probe(adapter, &addr_data, &tea6420_detect);
-}
-
-static int detach(struct i2c_client *client)
-{
-       int ret = i2c_detach_client(client);
-       kfree(client);
-       return ret;
-}
-
-static int command(struct i2c_client *client, unsigned int cmd, void *arg)
-{
-       struct tea6420_multiplex *a = (struct tea6420_multiplex *)arg;
-       int result = 0;
-
-       switch (cmd) {
-       case TEA6420_SWITCH:
-               result = tea6420_switch(client, a->in, a->out, a->gain);
-               break;
-       default:
-               return -ENOIOCTLCMD;
-       }
-
-       return result;
+       /* Let's see whether this is a known adapter we can attach to.
+          Prevents conflicts with tvaudio.c. */
+       return adapter->id == I2C_HW_SAA7146;
 }
 
-static struct i2c_driver driver = {
-       .driver = {
-               .name = "tea6420",
-       },
-       .id     = I2C_DRIVERID_TEA6420,
-       .attach_adapter = attach,
-       .detach_client  = detach,
-       .command        = command,
+static const struct i2c_device_id tea6420_id[] = {
+       { "tea6420", 0 },
+       { }
 };
+MODULE_DEVICE_TABLE(i2c, tea6420_id);
 
-static struct i2c_client client_template = {
+static struct v4l2_i2c_driver_data v4l2_i2c_data = {
        .name = "tea6420",
-       .driver = &driver,
+       .driverid = I2C_DRIVERID_TEA6420,
+       .command = tea6420_command,
+       .probe = tea6420_probe,
+       .legacy_probe = tea6420_legacy_probe,
+       .id_table = tea6420_id,
 };
-
-static int __init this_module_init(void)
-{
-       return i2c_add_driver(&driver);
-}
-
-static void __exit this_module_exit(void)
-{
-       i2c_del_driver(&driver);
-}
-
-module_init(this_module_init);
-module_exit(this_module_exit);
-
-MODULE_AUTHOR("Michael Hunold <michael@mihu.de>");
-MODULE_DESCRIPTION("tea6420 driver");
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/tuner-3036.c b/drivers/media/video/tuner-3036.c
deleted file mode 100644 (file)
index bdf506e..0000000
+++ /dev/null
@@ -1,214 +0,0 @@
-/*
- * Driver for Philips SAB3036 "CITAC" tuner control chip.
- *
- * Author: Phil Blundell <philb@gnu.org>
- *
- * The SAB3036 is just about different enough from the chips that
- * tuner.c copes with to make it not worth the effort to crowbar
- * the support into that file.  So instead we have a separate driver.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version
- * 2 of the License, or (at your option) any later version.
- */
-
-#include <linux/module.h>
-#include <linux/kernel.h>
-#include <linux/sched.h>
-#include <linux/string.h>
-#include <linux/timer.h>
-#include <linux/delay.h>
-#include <linux/errno.h>
-#include <linux/slab.h>
-#include <linux/init.h>
-
-#include <linux/i2c.h>
-#include <linux/videodev.h>
-#include <media/v4l2-common.h>
-
-#include <media/tuner.h>
-
-static int debug;      /* insmod parameter */
-static int this_adap;
-
-static struct i2c_client client_template;
-
-/* Addresses to scan */
-static unsigned short normal_i2c[] = { 0x60, 0x61, I2C_CLIENT_END };
-static unsigned short ignore = I2C_CLIENT_END;
-
-static struct i2c_client_address_data addr_data = {
-       .normal_i2c     = normal_i2c,
-       .probe          = &ignore,
-       .ignore         = &ignore,
-};
-
-/* ---------------------------------------------------------------------- */
-
-static unsigned char
-tuner_getstatus (struct i2c_client *c)
-{
-       unsigned char byte;
-       if (i2c_master_recv(c, &byte, 1) != 1)
-               printk(KERN_ERR "tuner-3036: I/O error.\n");
-       return byte;
-}
-
-#define TUNER_FL        0x80
-
-static int
-tuner_islocked (struct i2c_client *c)
-{
-       return (tuner_getstatus(c) & TUNER_FL);
-}
-
-/* ---------------------------------------------------------------------- */
-
-static void
-set_tv_freq(struct i2c_client *c, int freq)
-{
-       u16 div = ((freq * 20) / 16);
-       unsigned long give_up = jiffies + HZ;
-       unsigned char buffer[2];
-
-       if (debug)
-               printk(KERN_DEBUG "tuner: setting frequency %dMHz, divisor %x\n", freq / 16, div);
-
-       /* Select high tuning current */
-       buffer[0] = 0x29;
-       buffer[1] = 0x3e;
-
-       if (i2c_master_send(c, buffer, 2) != 2)
-               printk("tuner: i2c i/o error 1\n");
-
-       buffer[0] = 0x80 | ((div>>8) & 0x7f);
-       buffer[1] = div & 0xff;
-
-       if (i2c_master_send(c, buffer, 2) != 2)
-               printk("tuner: i2c i/o error 2\n");
-
-       while (!tuner_islocked(c) && time_before(jiffies, give_up))
-               schedule();
-
-       if (!tuner_islocked(c))
-               printk(KERN_WARNING "tuner: failed to achieve PLL lock\n");
-
-       /* Select low tuning current and engage AFC */
-       buffer[0] = 0x29;
-       buffer[1] = 0xb2;
-
-       if (i2c_master_send(c, buffer, 2) != 2)
-               printk("tuner: i2c i/o error 3\n");
-
-       if (debug)
-               printk(KERN_DEBUG "tuner: status %02x\n", tuner_getstatus(c));
-}
-
-/* ---------------------------------------------------------------------- */
-
-static int
-tuner_attach(struct i2c_adapter *adap, int addr, int kind)
-{
-       static unsigned char buffer[] = { 0x29, 0x32, 0x2a, 0, 0x2b, 0 };
-
-       struct i2c_client *client;
-
-       if (this_adap > 0)
-               return -1;
-       this_adap++;
-
-       client_template.adapter = adap;
-       client_template.addr = addr;
-
-       client = kmalloc(sizeof(struct i2c_client), GFP_KERNEL);
-       if (client == NULL)
-               return -ENOMEM;
-       memcpy(client, &client_template, sizeof(struct i2c_client));
-
-       printk("tuner: SAB3036 found, status %02x\n", tuner_getstatus(client));
-
-       i2c_attach_client(client);
-
-       if (i2c_master_send(client, buffer, 2) != 2)
-               printk("tuner: i2c i/o error 1\n");
-       if (i2c_master_send(client, buffer+2, 2) != 2)
-               printk("tuner: i2c i/o error 2\n");
-       if (i2c_master_send(client, buffer+4, 2) != 2)
-               printk("tuner: i2c i/o error 3\n");
-       return 0;
-}
-
-static int
-tuner_detach(struct i2c_client *c)
-{
-       return 0;
-}
-
-static int
-tuner_command(struct i2c_client *client, unsigned int cmd, void *arg)
-{
-       int *iarg = (int*)arg;
-
-       switch (cmd)
-       {
-               case VIDIOCSFREQ:
-                       set_tv_freq(client, *iarg);
-                       break;
-
-               default:
-                       return -EINVAL;
-       }
-       return 0;
-}
-
-static int
-tuner_probe(struct i2c_adapter *adap)
-{
-       this_adap = 0;
-       if (adap->id == I2C_HW_B_LP)
-               return i2c_probe(adap, &addr_data, tuner_attach);
-       return 0;
-}
-
-/* ----------------------------------------------------------------------- */
-
-static struct i2c_driver
-i2c_driver_tuner =
-{
-       .driver = {
-               .name   =       "sab3036",
-       },
-       .id             =       I2C_DRIVERID_SAB3036,
-       .attach_adapter =       tuner_probe,
-       .detach_client  =       tuner_detach,
-       .command        =       tuner_command
-};
-
-static struct i2c_client client_template =
-{
-       .driver         = &i2c_driver_tuner,
-       .name           = "SAB3036",
-};
-
-static int __init
-tuner3036_init(void)
-{
-       return i2c_add_driver(&i2c_driver_tuner);
-}
-
-static void __exit
-tuner3036_exit(void)
-{
-       i2c_del_driver(&i2c_driver_tuner);
-}
-
-MODULE_DESCRIPTION("SAB3036 tuner driver");
-MODULE_AUTHOR("Philip Blundell <philb@gnu.org>");
-MODULE_LICENSE("GPL");
-
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug,"Enable debugging output");
-
-module_init(tuner3036_init);
-module_exit(tuner3036_exit);
index d806a3556eedd9f48b8ba40fc07ef8bf7417bef2..4a7735c6c1a65e022c11689c8b6ef4b1a8f86406 100644 (file)
@@ -92,7 +92,6 @@ struct tuner {
 
        unsigned int        type; /* chip type id */
        unsigned int        config;
-       int (*tuner_callback) (void *dev, int command, int arg);
        const char          *name;
 };
 
@@ -346,7 +345,7 @@ static struct xc5000_config xc5000_cfg;
 
 static void set_type(struct i2c_client *c, unsigned int type,
                     unsigned int new_mode_mask, unsigned int new_config,
-                    int (*tuner_callback) (void *dev, int command,int arg))
+                    int (*tuner_callback) (void *dev, int component, int cmd, int arg))
 {
        struct tuner *t = i2c_get_clientdata(c);
        struct dvb_tuner_ops *fe_tuner_ops = &t->fe.ops.tuner_ops;
@@ -362,7 +361,7 @@ static void set_type(struct i2c_client *c, unsigned int type,
        t->config = new_config;
        if (tuner_callback != NULL) {
                tuner_dbg("defining GPIO callback\n");
-               t->tuner_callback = tuner_callback;
+               t->fe.callback = tuner_callback;
        }
 
        if (t->mode == T_UNINITIALIZED) {
@@ -385,7 +384,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
        {
                struct tda829x_config cfg = {
                        .lna_cfg        = t->config,
-                       .tuner_callback = t->tuner_callback,
                };
                if (!dvb_attach(tda829x_attach, &t->fe, t->i2c->adapter,
                                t->i2c->addr, &cfg))
@@ -433,7 +431,6 @@ static void set_type(struct i2c_client *c, unsigned int type,
                struct xc2028_config cfg = {
                        .i2c_adap  = t->i2c->adapter,
                        .i2c_addr  = t->i2c->addr,
-                       .callback  = t->tuner_callback,
                };
                if (!dvb_attach(xc2028_attach, &t->fe, &cfg))
                        goto attach_failed;
@@ -450,10 +447,8 @@ static void set_type(struct i2c_client *c, unsigned int type,
 
                xc5000_cfg.i2c_address    = t->i2c->addr;
                xc5000_cfg.if_khz         = 5380;
-               xc5000_cfg.tuner_callback = t->tuner_callback;
                if (!dvb_attach(xc5000_attach,
-                               &t->fe, t->i2c->adapter, &xc5000_cfg,
-                               c->adapter->algo_data))
+                               &t->fe, t->i2c->adapter, &xc5000_cfg))
                        goto attach_failed;
 
                xc_tuner_ops = &t->fe.ops.tuner_ops;
@@ -1225,7 +1220,7 @@ register_client:
        } else {
                t->mode = V4L2_TUNER_DIGITAL_TV;
        }
-       set_type(client, t->type, t->mode_mask, t->config, t->tuner_callback);
+       set_type(client, t->type, t->mode_mask, t->config, t->fe.callback);
        list_add_tail(&t->list, &tuner_list);
        return 0;
 }
index cc27efe121ddb225fd598d426da3ba44e7379ae0..28421d386f1e5b1561763ca4a3da320f7e8a3e5d 100644 (file)
@@ -258,7 +258,9 @@ static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame h
                            (RING_QUEUE_PEEK(&uvd->dp, 2) == 0x00))
                        {
 #if 0                          /* This code helps to detect new frame markers */
-                               info("Header sig: 00 FF 00 %02X", RING_QUEUE_PEEK(&uvd->dp, 3));
+                               dev_info(&uvd->dev->dev,
+                                        "Header sig: 00 FF 00 %02X\n",
+                                        RING_QUEUE_PEEK(&uvd->dp, 3));
 #endif
                                frame->header = RING_QUEUE_PEEK(&uvd->dp, 3);
                                if ((frame->header == HDRSIG_MODEL1_128x96) ||
@@ -266,7 +268,8 @@ static enum ParseState ibmcam_find_header(struct uvd *uvd) /* FIXME: Add frame h
                                    (frame->header == HDRSIG_MODEL1_352x288))
                                {
 #if 0
-                                       info("Header found.");
+                                       dev_info(&uvd->dev->dev,
+                                                "Header found.\n");
 #endif
                                        RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
                                        icam->has_hdr = 1;
@@ -295,7 +298,7 @@ case IBMCAM_MODEL_4:
                            (RING_QUEUE_PEEK(&uvd->dp, 1) == 0xFF))
                        {
 #if 0
-                               info("Header found.");
+                               dev_info(&uvd->dev->dev, "Header found.\n");
 #endif
                                RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
                                icam->has_hdr = 1;
@@ -338,7 +341,7 @@ case IBMCAM_MODEL_4:
                                byte4 = RING_QUEUE_PEEK(&uvd->dp, 3);
                                frame->header = (byte3 << 8) | byte4;
 #if 0
-                               info("Header found.");
+                               dev_info(&uvd->dev->dev, "Header found.\n");
 #endif
                                RING_QUEUE_DEQUEUE_BYTES(&uvd->dp, marker_len);
                                icam->has_hdr = 1;
@@ -354,7 +357,8 @@ case IBMCAM_MODEL_4:
        }
        if (!icam->has_hdr) {
                if (uvd->debug > 2)
-                       info("Skipping frame, no header");
+                       dev_info(&uvd->dev->dev,
+                                "Skipping frame, no header\n");
                return scan_EndParse;
        }
 
@@ -881,7 +885,9 @@ static enum ParseState ibmcam_model3_parse_lines(
         */
        if ((frame->curline + 1) >= data_h) {
                if (uvd->debug >= 3)
-                       info("Reached line %d. (frame is done)", frame->curline);
+                       dev_info(&uvd->dev->dev,
+                                "Reached line %d. (frame is done)\n",
+                                frame->curline);
                return scan_NextFrame;
        }
 
@@ -954,8 +960,9 @@ static enum ParseState ibmcam_model3_parse_lines(
 
        if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
                if (uvd->debug >= 3) {
-                       info("All requested lines (%ld.) done.",
-                            VIDEOSIZE_Y(frame->request));
+                       dev_info(&uvd->dev->dev,
+                                "All requested lines (%ld.) done.\n",
+                                VIDEOSIZE_Y(frame->request));
                }
                return scan_NextFrame;
        } else
@@ -1000,7 +1007,9 @@ static enum ParseState ibmcam_model4_128x96_parse_lines(
         */
        if ((frame->curline + 1) >= data_h) {
                if (uvd->debug >= 3)
-                       info("Reached line %d. (frame is done)", frame->curline);
+                       dev_info(&uvd->dev->dev,
+                                "Reached line %d. (frame is done)\n",
+                                frame->curline);
                return scan_NextFrame;
        }
 
@@ -1049,8 +1058,9 @@ static enum ParseState ibmcam_model4_128x96_parse_lines(
 
        if (frame->curline >= VIDEOSIZE_Y(frame->request)) {
                if (uvd->debug >= 3) {
-                       info("All requested lines (%ld.) done.",
-                            VIDEOSIZE_Y(frame->request));
+                       dev_info(&uvd->dev->dev,
+                                "All requested lines (%ld.) done.\n",
+                                VIDEOSIZE_Y(frame->request));
                }
                return scan_NextFrame;
        } else
@@ -1171,10 +1181,11 @@ static int ibmcam_veio(
                        sizeof(cp),
                        1000);
 #if 0
-               info("USB => %02x%02x%02x%02x%02x%02x%02x%02x "
-                      "(req=$%02x val=$%04x ind=$%04x)",
-                      cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
-                      req, value, index);
+               dev_info(&uvd->dev->dev,
+                        "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
+                        "(req=$%02x val=$%04x ind=$%04x)\n",
+                        cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
+                        req, value, index);
 #endif
        } else {
                i = usb_control_msg(
@@ -1449,10 +1460,9 @@ static void ibmcam_adjust_contrast(struct uvd *uvd)
  */
 static void ibmcam_change_lighting_conditions(struct uvd *uvd)
 {
-       static const char proc[] = "ibmcam_change_lighting_conditions";
-
        if (debug > 0)
-               info("%s: Set lighting to %hu.", proc, lighting);
+               dev_info(&uvd->dev->dev,
+                        "%s: Set lighting to %hu.\n", __func__, lighting);
 
        switch (IBMCAM_T(uvd)->camera_model) {
        case IBMCAM_MODEL_1:
@@ -1495,8 +1505,6 @@ static void ibmcam_change_lighting_conditions(struct uvd *uvd)
  */
 static void ibmcam_set_sharpness(struct uvd *uvd)
 {
-       static const char proc[] = "ibmcam_set_sharpness";
-
        switch (IBMCAM_T(uvd)->camera_model) {
        case IBMCAM_MODEL_1:
        {
@@ -1505,7 +1513,8 @@ static void ibmcam_set_sharpness(struct uvd *uvd)
 
                RESTRICT_TO_RANGE(sharpness, SHARPNESS_MIN, SHARPNESS_MAX);
                if (debug > 0)
-                       info("%s: Set sharpness to %hu.", proc, sharpness);
+                       dev_info(&uvd->dev->dev, "%s: Set sharpness to %hu.\n",
+                                __func__, sharpness);
 
                sv = sa[sharpness - SHARPNESS_MIN];
                for (i=0; i < 2; i++) {
@@ -1564,11 +1573,11 @@ static void ibmcam_set_sharpness(struct uvd *uvd)
  */
 static void ibmcam_set_brightness(struct uvd *uvd)
 {
-       static const char proc[] = "ibmcam_set_brightness";
        static const unsigned short n = 1;
 
        if (debug > 0)
-               info("%s: Set brightness to %hu.", proc, uvd->vpic.brightness);
+               dev_info(&uvd->dev->dev, "%s: Set brightness to %hu.\n",
+                        __func__, uvd->vpic.brightness);
 
        switch (IBMCAM_T(uvd)->camera_model) {
        case IBMCAM_MODEL_1:
@@ -2115,7 +2124,8 @@ static void ibmcam_model2_setup_after_video_if(struct uvd *uvd)
                        break;
                }
                if (uvd->debug > 0)
-                       info("Framerate (hardware): %hd.", hw_fps);
+                       dev_info(&uvd->dev->dev, "Framerate (hardware): %hd.\n",
+                                hw_fps);
                RESTRICT_TO_RANGE(hw_fps, 0, 31);
                ibmcam_model2_Packet1(uvd, mod2_set_framerate, hw_fps);
        }
@@ -3487,7 +3497,7 @@ static void ibmcam_model3_setup_after_video_if(struct uvd *uvd)
        /* 01.01.08 - Added for RCA video in support -LO */
        if(init_model3_input) {
                if (debug > 0)
-                       info("Setting input to RCA.");
+                       dev_info(&uvd->dev->dev, "Setting input to RCA.\n");
                for (i=0; i < ARRAY_SIZE(initData); i++) {
                        ibmcam_veio(uvd, initData[i].req, initData[i].value, initData[i].index);
                }
@@ -3685,7 +3695,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
        unsigned char video_ep = 0;
 
        if (debug >= 1)
-               info("ibmcam_probe(%p,%u.)", intf, ifnum);
+               dev_info(&uvd->dev->dev, "ibmcam_probe(%p,%u.)\n", intf, ifnum);
 
        /* We don't handle multi-config cameras */
        if (dev->descriptor.bNumConfigurations != 1)
@@ -3736,14 +3746,16 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
                        brand = "IBM PC Camera"; /* a.k.a. Xirlink C-It */
                        break;
                }
-               info("%s USB camera found (model %d, rev. 0x%04x)",
-                    brand, model, le16_to_cpu(dev->descriptor.bcdDevice));
+               dev_info(&uvd->dev->dev,
+                        "%s USB camera found (model %d, rev. 0x%04x)\n",
+                        brand, model, le16_to_cpu(dev->descriptor.bcdDevice));
        } while (0);
 
        /* Validate found interface: must have one ISO endpoint */
        nas = intf->num_altsetting;
        if (debug > 0)
-               info("Number of alternate settings=%d.", nas);
+               dev_info(&uvd->dev->dev, "Number of alternate settings=%d.\n",
+                        nas);
        if (nas < 2) {
                err("Too few alternate settings for this camera!");
                return -ENODEV;
@@ -3787,7 +3799,9 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
                                actInterface = i;
                                maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
                                if (debug > 0)
-                                       info("Active setting=%d. maxPS=%d.", i, maxPS);
+                                       dev_info(&uvd->dev->dev,
+                                                "Active setting=%d. "
+                                                "maxPS=%d.\n", i, maxPS);
                        } else
                                err("More than one active alt. setting! Ignoring #%d.", i);
                }
@@ -3826,7 +3840,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
                        RESTRICT_TO_RANGE(framerate, 0, 5);
                        break;
                default:
-                       info("IBM camera: using 320x240");
+                       dev_info(&uvd->dev->dev, "IBM camera: using 320x240\n");
                        size = SIZE_320x240;
                        /* No break here */
                case SIZE_320x240:
@@ -3855,7 +3869,7 @@ static int ibmcam_probe(struct usb_interface *intf, const struct usb_device_id *
                        canvasY = 120;
                        break;
                default:
-                       info("IBM NetCamera: using 176x144");
+                       dev_info(&uvd->dev->dev, "IBM NetCamera: using 176x144\n");
                        size = SIZE_176x144;
                        /* No break here */
                case SIZE_176x144:
index 1c180284ec6c2f35aa6fb3bd31e63ee97d562c0d..e986c28b7bb0f73ab289260c12f24a5cc44b5e1c 100644 (file)
@@ -337,7 +337,8 @@ static int konicawc_compress_iso(struct uvd *uvd, struct urb *dataurb, struct ur
                }
 
                if((sts > 0x01) && (sts < 0x80)) {
-                       info("unknown status %2.2x", sts);
+                       dev_info(&uvd->dev->dev, "unknown status %2.2x\n",
+                                sts);
                        bad++;
                        continue;
                }
@@ -568,8 +569,12 @@ static void konicawc_process_isoc(struct uvd *uvd, struct usbvideo_frame *frame)
                                        fdrops = (0x80 + curframe - cam->lastframe) & 0x7F;
                                        fdrops--;
                                        if(fdrops) {
-                                               info("Dropped %d frames (%d -> %d)", fdrops,
-                                                    cam->lastframe, curframe);
+                                               dev_info(&uvd->dev->dev,
+                                                        "Dropped %d frames "
+                                                        "(%d -> %d)\n",
+                                                        fdrops,
+                                                        cam->lastframe,
+                                                        curframe);
                                        }
                                }
                                cam->lastframe = curframe;
@@ -784,7 +789,8 @@ static int konicawc_probe(struct usb_interface *intf, const struct usb_device_id
        if (dev->descriptor.bNumConfigurations != 1)
                return -ENODEV;
 
-       info("Konica Webcam (rev. 0x%04x)", le16_to_cpu(dev->descriptor.bcdDevice));
+       dev_info(&intf->dev, "Konica Webcam (rev. 0x%04x)\n",
+                le16_to_cpu(dev->descriptor.bcdDevice));
        RESTRICT_TO_RANGE(speed, 0, MAX_SPEED);
 
        /* Validate found interface: must have one ISO endpoint */
@@ -925,7 +931,8 @@ static struct usb_device_id id_table[] = {
 static int __init konicawc_init(void)
 {
        struct usbvideo_cb cbTbl;
-       info(DRIVER_DESC " " DRIVER_VERSION);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
        memset(&cbTbl, 0, sizeof(cbTbl));
        cbTbl.probe = konicawc_probe;
        cbTbl.setupOnOpen = konicawc_setup_on_open;
index 3d26a30abe1ef99b1c9de8873816efa00f1dc7ee..05c61b52311541dbee042c9d9039f8260ede9d5a 100644 (file)
@@ -1080,7 +1080,8 @@ static struct usbvideo_cb qcm_driver = {
 
 static int __init qcm_init(void)
 {
-       info(DRIVER_DESC " " DRIVER_VERSION);
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
+              DRIVER_DESC "\n");
 
        return usbvideo_register(
                &cams,
index 9544e644bf0de4bc6f01b8e22107d20809683657..9714baab7833b61a696ce5120427c42c0a9aa7cd 100644 (file)
@@ -156,10 +156,11 @@ static int ultracam_veio(
                        sizeof(cp),
                        1000);
 #if 1
-               info("USB => %02x%02x%02x%02x%02x%02x%02x%02x "
-                      "(req=$%02x val=$%04x ind=$%04x)",
-                      cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
-                      req, value, index);
+               dev_info(&uvd->dev->dev,
+                        "USB => %02x%02x%02x%02x%02x%02x%02x%02x "
+                        "(req=$%02x val=$%04x ind=$%04x)\n",
+                        cp[0],cp[1],cp[2],cp[3],cp[4],cp[5],cp[6],cp[7],
+                        req, value, index);
 #endif
        } else {
                i = usb_control_msg(
@@ -517,19 +518,20 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
        unsigned char video_ep = 0;
 
        if (debug >= 1)
-               info("ultracam_probe(%p)", intf);
+               dev_info(&intf->dev, "ultracam_probe\n");
 
        /* We don't handle multi-config cameras */
        if (dev->descriptor.bNumConfigurations != 1)
                return -ENODEV;
 
-       info("IBM Ultra camera found (rev. 0x%04x)",
-               le16_to_cpu(dev->descriptor.bcdDevice));
+       dev_info(&intf->dev, "IBM Ultra camera found (rev. 0x%04x)\n",
+                le16_to_cpu(dev->descriptor.bcdDevice));
 
        /* Validate found interface: must have one ISO endpoint */
        nas = intf->num_altsetting;
        if (debug > 0)
-               info("Number of alternate settings=%d.", nas);
+               dev_info(&intf->dev, "Number of alternate settings=%d.\n",
+                        nas);
        if (nas < 8) {
                err("Too few alternate settings for this camera!");
                return -ENODEV;
@@ -576,7 +578,9 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
                                actInterface = i;
                                maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
                                if (debug > 0)
-                                       info("Active setting=%d. maxPS=%d.", i, maxPS);
+                                       dev_info(&intf->dev,
+                                                "Active setting=%d. "
+                                                "maxPS=%d.\n", i, maxPS);
                        } else {
                                /* Got another active alt. setting */
                                if (maxPS < le16_to_cpu(endpoint->wMaxPacketSize)) {
@@ -584,8 +588,11 @@ static int ultracam_probe(struct usb_interface *intf, const struct usb_device_id
                                        actInterface = i;
                                        maxPS = le16_to_cpu(endpoint->wMaxPacketSize);
                                        if (debug > 0) {
-                                               info("Even better ctive setting=%d. maxPS=%d.",
-                                                    i, maxPS);
+                                               dev_info(&intf->dev,
+                                                        "Even better ctive "
+                                                        "setting=%d. "
+                                                        "maxPS=%d.\n",
+                                                        i, maxPS);
                                        }
                                }
                        }
index bf1bc2f69b02f727a4cad6ff13cf1f9b46b96a55..07cd87d16f69f602dcbd8bf416347200ce79a8d0 100644 (file)
@@ -468,8 +468,9 @@ static void usbvideo_ReportStatistics(const struct uvd *uvd)
                        percent = (100 * goodPackets) / allPackets;
                else
                        percent = goodPackets / (allPackets / 100);
-               info("Packet Statistics: Total=%lu. Empty=%lu. Usage=%lu%%",
-                    allPackets, badPackets, percent);
+               dev_info(&uvd->dev->dev,
+                        "Packet Statistics: Total=%lu. Empty=%lu. Usage=%lu%%\n",
+                        allPackets, badPackets, percent);
                if (uvd->iso_packet_len > 0) {
                        unsigned long allBytes, xferBytes;
                        char multiplier = ' ';
@@ -497,8 +498,9 @@ static void usbvideo_ReportStatistics(const struct uvd *uvd)
                                        }
                                }
                        }
-                       info("Transfer Statistics: Transferred=%lu%cB Usage=%lu%%",
-                            xferBytes, multiplier, percent);
+                       dev_info(&uvd->dev->dev,
+                                "Transfer Statistics: Transferred=%lu%cB Usage=%lu%%\n",
+                                xferBytes, multiplier, percent);
                }
        }
 }
@@ -545,7 +547,7 @@ void usbvideo_TestPattern(struct uvd *uvd, int fullframe, int pmode)
        {       /* For debugging purposes only */
                char tmp[20];
                usbvideo_VideosizeToString(tmp, sizeof(tmp), frame->request);
-               info("testpattern: frame=%s", tmp);
+               dev_info(&uvd->dev->dev, "testpattern: frame=%s\n", tmp);
        }
 #endif
        /* Form every scan line */
@@ -854,7 +856,7 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
 
        usbvideo_ClientIncModCount(uvd);
        if (uvd->debug > 0)
-               info("%s(%p.)", __func__, intf);
+               dev_info(&intf->dev, "%s(%p.)\n", __func__, intf);
 
        mutex_lock(&uvd->lock);
        uvd->remove_pending = 1; /* Now all ISO data will be ignored */
@@ -870,14 +872,15 @@ static void usbvideo_Disconnect(struct usb_interface *intf)
 
        video_unregister_device(&uvd->vdev);
        if (uvd->debug > 0)
-               info("%s: Video unregistered.", __func__);
+               dev_info(&intf->dev, "%s: Video unregistered.\n", __func__);
 
        if (uvd->user)
-               info("%s: In use, disconnect pending.", __func__);
+               dev_info(&intf->dev, "%s: In use, disconnect pending.\n",
+                        __func__);
        else
                usbvideo_CameraRelease(uvd);
        mutex_unlock(&uvd->lock);
-       info("USB camera disconnected.");
+       dev_info(&intf->dev, "USB camera disconnected.\n");
 
        usbvideo_ClientDecModCount(uvd);
 }
@@ -1015,14 +1018,17 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
                return -EINVAL;
        }
        if (uvd->video_endp == 0) {
-               info("%s: No video endpoint specified; data pump disabled.", __func__);
+               dev_info(&uvd->dev->dev,
+                        "%s: No video endpoint specified; data pump disabled.\n",
+                        __func__);
        }
        if (uvd->paletteBits == 0) {
                err("%s: No palettes specified!", __func__);
                return -EINVAL;
        }
        if (uvd->defaultPalette == 0) {
-               info("%s: No default palette!", __func__);
+               dev_info(&uvd->dev->dev, "%s: No default palette!\n",
+                        __func__);
        }
 
        uvd->max_frame_size = VIDEOSIZE_X(uvd->canvas) *
@@ -1031,25 +1037,29 @@ int usbvideo_RegisterVideoDevice(struct uvd *uvd)
        usbvideo_VideosizeToString(tmp2, sizeof(tmp2), uvd->canvas);
 
        if (uvd->debug > 0) {
-               info("%s: iface=%d. endpoint=$%02x paletteBits=$%08lx",
-                    __func__, uvd->iface, uvd->video_endp, uvd->paletteBits);
+               dev_info(&uvd->dev->dev,
+                        "%s: iface=%d. endpoint=$%02x paletteBits=$%08lx\n",
+                        __func__, uvd->iface, uvd->video_endp,
+                        uvd->paletteBits);
        }
        if (uvd->dev == NULL) {
                err("%s: uvd->dev == NULL", __func__);
                return -EINVAL;
        }
        uvd->vdev.parent = &uvd->dev->dev;
-       if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) == -1) {
+       uvd->vdev.release = video_device_release_empty;
+       if (video_register_device(&uvd->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
                err("%s: video_register_device failed", __func__);
                return -EPIPE;
        }
        if (uvd->debug > 1) {
-               info("%s: video_register_device() successful", __func__);
+               dev_info(&uvd->dev->dev,
+                        "%s: video_register_device() successful\n", __func__);
        }
 
-       info("%s on /dev/video%d: canvas=%s videosize=%s",
-            (uvd->handle != NULL) ? uvd->handle->drvName : "???",
-            uvd->vdev.minor, tmp2, tmp1);
+       dev_info(&uvd->dev->dev, "%s on /dev/video%d: canvas=%s videosize=%s\n",
+                (uvd->handle != NULL) ? uvd->handle->drvName : "???",
+                uvd->vdev.minor, tmp2, tmp1);
 
        usb_get_dev(uvd->dev);
        return 0;
@@ -1111,7 +1121,7 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
        int i, errCode = 0;
 
        if (uvd->debug > 1)
-               info("%s($%p)", __func__, dev);
+               dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, dev);
 
        if (0 < usbvideo_ClientIncModCount(uvd))
                return -ENODEV;
@@ -1178,19 +1188,25 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
                if (errCode == 0) {
                        if (VALID_CALLBACK(uvd, setupOnOpen)) {
                                if (uvd->debug > 1)
-                                       info("%s: setupOnOpen callback", __func__);
+                                       dev_info(&uvd->dev->dev,
+                                                "%s: setupOnOpen callback\n",
+                                                __func__);
                                errCode = GET_CALLBACK(uvd, setupOnOpen)(uvd);
                                if (errCode < 0) {
                                        err("%s: setupOnOpen callback failed (%d.).",
                                            __func__, errCode);
                                } else if (uvd->debug > 1) {
-                                       info("%s: setupOnOpen callback successful", __func__);
+                                       dev_info(&uvd->dev->dev,
+                                                "%s: setupOnOpen callback successful\n",
+                                                __func__);
                                }
                        }
                        if (errCode == 0) {
                                uvd->settingsAdjusted = 0;
                                if (uvd->debug > 1)
-                                       info("%s: Open succeeded.", __func__);
+                                       dev_info(&uvd->dev->dev,
+                                                "%s: Open succeeded.\n",
+                                                __func__);
                                uvd->user++;
                                file->private_data = uvd;
                        }
@@ -1200,7 +1216,8 @@ static int usbvideo_v4l_open(struct inode *inode, struct file *file)
        if (errCode != 0)
                usbvideo_ClientDecModCount(uvd);
        if (uvd->debug > 0)
-               info("%s: Returning %d.", __func__, errCode);
+               dev_info(&uvd->dev->dev, "%s: Returning %d.\n", __func__,
+                        errCode);
        return errCode;
 }
 
@@ -1223,7 +1240,7 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
        int i;
 
        if (uvd->debug > 1)
-               info("%s($%p)", __func__, dev);
+               dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, dev);
 
        mutex_lock(&uvd->lock);
        GET_CALLBACK(uvd, stopDataPump)(uvd);
@@ -1243,14 +1260,15 @@ static int usbvideo_v4l_close(struct inode *inode, struct file *file)
        uvd->user--;
        if (uvd->remove_pending) {
                if (uvd->debug > 0)
-                       info("usbvideo_v4l_close: Final disconnect.");
+                       dev_info(&uvd->dev->dev, "%s: Final disconnect.\n",
+                                __func__);
                usbvideo_CameraRelease(uvd);
        }
        mutex_unlock(&uvd->lock);
        usbvideo_ClientDecModCount(uvd);
 
        if (uvd->debug > 1)
-               info("%s: Completed.", __func__);
+               dev_info(&uvd->dev->dev, "%s: Completed.\n", __func__);
        file->private_data = NULL;
        return 0;
 }
@@ -1364,8 +1382,9 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
                        struct video_mmap *vm = arg;
 
                        if (uvd->debug >= 1) {
-                               info("VIDIOCMCAPTURE: frame=%d. size=%dx%d, format=%d.",
-                                    vm->frame, vm->width, vm->height, vm->format);
+                               dev_info(&uvd->dev->dev,
+                                        "VIDIOCMCAPTURE: frame=%d. size=%dx%d, format=%d.\n",
+                                        vm->frame, vm->width, vm->height, vm->format);
                        }
                        /*
                         * Check if the requested size is supported. If the requestor
@@ -1383,18 +1402,24 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
                        if ((vm->width > VIDEOSIZE_X(uvd->canvas)) ||
                            (vm->height > VIDEOSIZE_Y(uvd->canvas))) {
                                if (uvd->debug > 0) {
-                                       info("VIDIOCMCAPTURE: Size=%dx%d too large; "
-                                            "allowed only up to %ldx%ld", vm->width, vm->height,
-                                            VIDEOSIZE_X(uvd->canvas), VIDEOSIZE_Y(uvd->canvas));
+                                       dev_info(&uvd->dev->dev,
+                                                "VIDIOCMCAPTURE: Size=%dx%d "
+                                                "too large; allowed only up "
+                                                "to %ldx%ld\n", vm->width,
+                                                vm->height,
+                                                VIDEOSIZE_X(uvd->canvas),
+                                                VIDEOSIZE_Y(uvd->canvas));
                                }
                                return -EINVAL;
                        }
                        /* Check if the palette is supported */
                        if (((1L << vm->format) & uvd->paletteBits) == 0) {
                                if (uvd->debug > 0) {
-                                       info("VIDIOCMCAPTURE: format=%d. not supported"
-                                            " (paletteBits=$%08lx)",
-                                            vm->format, uvd->paletteBits);
+                                       dev_info(&uvd->dev->dev,
+                                                "VIDIOCMCAPTURE: format=%d. "
+                                                "not supported "
+                                                "(paletteBits=$%08lx)\n",
+                                                vm->format, uvd->paletteBits);
                                }
                                return -EINVAL;
                        }
@@ -1422,7 +1447,9 @@ static int usbvideo_v4l_do_ioctl(struct inode *inode, struct file *file,
                                return -EINVAL;
 
                        if (uvd->debug >= 1)
-                               info("VIDIOCSYNC: syncing to frame %d.", *frameNum);
+                               dev_info(&uvd->dev->dev,
+                                        "VIDIOCSYNC: syncing to frame %d.\n",
+                                        *frameNum);
                        if (uvd->flags & FLAGS_NO_DECODING)
                                ret = usbvideo_GetFrame(uvd, *frameNum);
                        else if (VALID_CALLBACK(uvd, getFrame)) {
@@ -1504,7 +1531,9 @@ static ssize_t usbvideo_v4l_read(struct file *file, char __user *buf,
                return -EFAULT;
 
        if (uvd->debug >= 1)
-               info("%s: %Zd. bytes, noblock=%d.", __func__, count, noblock);
+               dev_info(&uvd->dev->dev,
+                        "%s: %Zd. bytes, noblock=%d.\n",
+                        __func__, count, noblock);
 
        mutex_lock(&uvd->lock);
 
@@ -1685,18 +1714,21 @@ static void usbvideo_IsocIrq(struct urb *urb)
                return;
 #if 0
        if (urb->actual_length > 0) {
-               info("urb=$%p status=%d. errcount=%d. length=%d.",
-                    urb, urb->status, urb->error_count, urb->actual_length);
+               dev_info(&uvd->dev->dev,
+                        "urb=$%p status=%d. errcount=%d. length=%d.\n",
+                        urb, urb->status, urb->error_count,
+                        urb->actual_length);
        } else {
                static int c = 0;
                if (c++ % 100 == 0)
-                       info("No Isoc data");
+                       dev_info(&uvd->dev->dev, "No Isoc data\n");
        }
 #endif
 
        if (!uvd->streaming) {
                if (uvd->debug >= 1)
-                       info("Not streaming, but interrupt!");
+                       dev_info(&uvd->dev->dev,
+                                "Not streaming, but interrupt!\n");
                return;
        }
 
@@ -1741,7 +1773,7 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
        int i, errFlag;
 
        if (uvd->debug > 1)
-               info("%s($%p)", __func__, uvd);
+               dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, uvd);
 
        if (!CAMERA_IS_OPERATIONAL(uvd)) {
                err("%s: Camera is not operational", __func__);
@@ -1789,7 +1821,9 @@ static int usbvideo_StartDataPump(struct uvd *uvd)
 
        uvd->streaming = 1;
        if (uvd->debug > 1)
-               info("%s: streaming=1 video_endp=$%02x", __func__, uvd->video_endp);
+               dev_info(&uvd->dev->dev,
+                        "%s: streaming=1 video_endp=$%02x\n", __func__,
+                        uvd->video_endp);
        return 0;
 }
 
@@ -1811,14 +1845,14 @@ static void usbvideo_StopDataPump(struct uvd *uvd)
                return;
 
        if (uvd->debug > 1)
-               info("%s($%p)", __func__, uvd);
+               dev_info(&uvd->dev->dev, "%s($%p)\n", __func__, uvd);
 
        /* Unschedule all of the iso td's */
        for (i=0; i < USBVIDEO_NUMSBUF; i++) {
                usb_kill_urb(uvd->sbuf[i].urb);
        }
        if (uvd->debug > 1)
-               info("%s: streaming=0", __func__);
+               dev_info(&uvd->dev->dev, "%s: streaming=0\n", __func__);
        uvd->streaming = 0;
 
        if (!uvd->remove_pending) {
@@ -1850,7 +1884,8 @@ static int usbvideo_NewFrame(struct uvd *uvd, int framenum)
        int n;
 
        if (uvd->debug > 1)
-               info("usbvideo_NewFrame($%p,%d.)", uvd, framenum);
+               dev_info(&uvd->dev->dev, "usbvideo_NewFrame($%p,%d.)\n", uvd,
+                        framenum);
 
        /* If we're not grabbing a frame right now and the other frame is */
        /*  ready to be grabbed into, then use it instead */
@@ -1955,12 +1990,14 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
        struct usbvideo_frame *frame = &uvd->frame[frameNum];
 
        if (uvd->debug >= 2)
-               info("%s($%p,%d.)", __func__, uvd, frameNum);
+               dev_info(&uvd->dev->dev, "%s($%p,%d.)\n", __func__, uvd,
+                        frameNum);
 
        switch (frame->frameState) {
        case FrameState_Unused:
                if (uvd->debug >= 2)
-                       info("%s: FrameState_Unused", __func__);
+                       dev_info(&uvd->dev->dev, "%s: FrameState_Unused\n",
+                                __func__);
                return -EINVAL;
        case FrameState_Ready:
        case FrameState_Grabbing:
@@ -1970,7 +2007,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
        redo:
                if (!CAMERA_IS_OPERATIONAL(uvd)) {
                        if (uvd->debug >= 2)
-                               info("%s: Camera is not operational (1)", __func__);
+                               dev_info(&uvd->dev->dev,
+                                        "%s: Camera is not operational (1)\n",
+                                        __func__);
                        return -EIO;
                }
                ntries = 0;
@@ -1979,24 +2018,33 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
                        signalPending = signal_pending(current);
                        if (!CAMERA_IS_OPERATIONAL(uvd)) {
                                if (uvd->debug >= 2)
-                                       info("%s: Camera is not operational (2)", __func__);
+                                       dev_info(&uvd->dev->dev,
+                                                "%s: Camera is not "
+                                                "operational (2)\n", __func__);
                                return -EIO;
                        }
                        assert(uvd->fbuf != NULL);
                        if (signalPending) {
                                if (uvd->debug >= 2)
-                                       info("%s: Signal=$%08x", __func__, signalPending);
+                                       dev_info(&uvd->dev->dev,
+                                       "%s: Signal=$%08x\n", __func__,
+                                       signalPending);
                                if (uvd->flags & FLAGS_RETRY_VIDIOCSYNC) {
                                        usbvideo_TestPattern(uvd, 1, 0);
                                        uvd->curframe = -1;
                                        uvd->stats.frame_num++;
                                        if (uvd->debug >= 2)
-                                               info("%s: Forced test pattern screen", __func__);
+                                               dev_info(&uvd->dev->dev,
+                                                        "%s: Forced test "
+                                                        "pattern screen\n",
+                                                        __func__);
                                        return 0;
                                } else {
                                        /* Standard answer: Interrupted! */
                                        if (uvd->debug >= 2)
-                                               info("%s: Interrupted!", __func__);
+                                               dev_info(&uvd->dev->dev,
+                                                        "%s: Interrupted!\n",
+                                                        __func__);
                                        return -EINTR;
                                }
                        } else {
@@ -2010,8 +2058,10 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
                        }
                } while (frame->frameState == FrameState_Grabbing);
                if (uvd->debug >= 2) {
-                       info("%s: Grabbing done; state=%d. (%lu. bytes)",
-                            __func__, frame->frameState, frame->seqRead_Length);
+                       dev_info(&uvd->dev->dev,
+                                "%s: Grabbing done; state=%d. (%lu. bytes)\n",
+                                __func__, frame->frameState,
+                                frame->seqRead_Length);
                }
                if (frame->frameState == FrameState_Error) {
                        int ret = usbvideo_NewFrame(uvd, frameNum);
@@ -2048,7 +2098,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
                }
                frame->frameState = FrameState_Done_Hold;
                if (uvd->debug >= 2)
-                       info("%s: Entered FrameState_Done_Hold state.", __func__);
+                       dev_info(&uvd->dev->dev,
+                                "%s: Entered FrameState_Done_Hold state.\n",
+                                __func__);
                return 0;
 
        case FrameState_Done_Hold:
@@ -2059,7 +2111,9 @@ static int usbvideo_GetFrame(struct uvd *uvd, int frameNum)
                 * it will be released back into the wild to roam freely.
                 */
                if (uvd->debug >= 2)
-                       info("%s: FrameState_Done_Hold state.", __func__);
+                       dev_info(&uvd->dev->dev,
+                                "%s: FrameState_Done_Hold state.\n",
+                                __func__);
                return 0;
        }
 
index 2eb45829791ccf509a04a15599df1381f1c732cd..7a127d6bfdee5432770136980b3899afc6f25825 100644 (file)
@@ -472,9 +472,8 @@ vicam_ioctl(struct inode *inode, struct file *file, unsigned int ioctlnr, unsign
 static int
 vicam_open(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vicam_camera *cam =
-           (struct vicam_camera *) dev->priv;
+       struct vicam_camera *cam = video_drvdata(file);
+
        DBG("open\n");
 
        if (!cam) {
@@ -488,20 +487,24 @@ vicam_open(struct inode *inode, struct file *file)
         * rely on this fact forever.
         */
 
+       lock_kernel();
        if (cam->open_count > 0) {
                printk(KERN_INFO
                       "vicam_open called on already opened camera");
+               unlock_kernel();
                return -EBUSY;
        }
 
        cam->raw_image = kmalloc(VICAM_MAX_READ_SIZE, GFP_KERNEL);
        if (!cam->raw_image) {
+               unlock_kernel();
                return -ENOMEM;
        }
 
        cam->framebuf = rvmalloc(VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
        if (!cam->framebuf) {
                kfree(cam->raw_image);
+               unlock_kernel();
                return -ENOMEM;
        }
 
@@ -509,6 +512,7 @@ vicam_open(struct inode *inode, struct file *file)
        if (!cam->cntrlbuf) {
                kfree(cam->raw_image);
                rvfree(cam->framebuf, VICAM_MAX_FRAME_SIZE * VICAM_FRAMES);
+               unlock_kernel();
                return -ENOMEM;
        }
 
@@ -526,6 +530,7 @@ vicam_open(struct inode *inode, struct file *file)
        cam->open_count++;
 
        file->private_data = cam;
+       unlock_kernel();
 
        return 0;
 }
@@ -795,6 +800,7 @@ static struct video_device vicam_template = {
        .name           = "ViCam-based USB Camera",
        .fops           = &vicam_fops,
        .minor          = -1,
+       .release        = video_device_release_empty,
 };
 
 /* table of devices that work with this driver */
@@ -859,9 +865,8 @@ vicam_probe( struct usb_interface *intf, const struct usb_device_id *id)
 
        mutex_init(&cam->cam_lock);
 
-       memcpy(&cam->vdev, &vicam_template,
-              sizeof (vicam_template));
-       cam->vdev.priv = cam;   // sort of a reverse mapping for those functions that get vdev only
+       memcpy(&cam->vdev, &vicam_template, sizeof(vicam_template));
+       video_set_drvdata(&cam->vdev, cam);
 
        cam->udev = dev;
        cam->bulkEndpoint = bulkEndpoint;
index c317ed7a8482fdbcaf47e5f7e635cc634e1cbee9..b26b563a0b0a299a98bd7c4ef7114878fdb66d07 100644 (file)
@@ -84,7 +84,8 @@ MODULE_PARM_DESC(adjust_Y_Offset, "adjust Y offset display [core]");
 #ifdef USBVISION_DEBUG
        #define PDEBUG(level, fmt, args...) { \
                if (core_debug & (level)) \
-                       info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
+                       printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
+                               __func__, __LINE__ , ## args); \
        }
 #else
        #define PDEBUG(level, fmt, args...) do {} while(0)
index a6d00858b07ecad47da68bf54ccb06280fe55352..92427fdc1459b2b62af94aabe79063a08dc335f3 100644 (file)
@@ -47,7 +47,8 @@ MODULE_PARM_DESC(i2c_debug, "enable debug messages [i2c]");
 
 #define PDEBUG(level, fmt, args...) { \
                if (i2c_debug & (level)) \
-                       info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
+                       printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
+                               __func__, __LINE__ , ## args); \
        }
 
 static int usbvision_i2c_write(struct usb_usbvision *usbvision, unsigned char addr, char *buf,
index b977116a0dd99ccfa6475940c01bb860605dea13..e10b256aeba4bc103675937df43ae71512336904 100644 (file)
@@ -98,7 +98,8 @@ USBVISION_DRIVER_VERSION_PATCHLEVEL)
 #ifdef USBVISION_DEBUG
        #define PDEBUG(level, fmt, args...) { \
                if (video_debug & (level)) \
-                       info("[%s:%d] " fmt, __func__, __LINE__ , ## args); \
+                       printk(KERN_INFO KBUILD_MODNAME ":[%s:%d] " fmt, \
+                               __func__, __LINE__ , ## args); \
        }
 #else
        #define PDEBUG(level, fmt, args...) do {} while(0)
@@ -360,13 +361,12 @@ static void usbvision_remove_sysfs(struct video_device *vdev)
  */
 static int usbvision_v4l2_open(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int errCode = 0;
 
        PDEBUG(DBG_IO, "open");
 
+       lock_kernel();
        usbvision_reset_powerOffTimer(usbvision);
 
        if (usbvision->user)
@@ -424,6 +424,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
        usbvision_empty_framequeues(usbvision);
 
        PDEBUG(DBG_IO, "success");
+       unlock_kernel();
        return errCode;
 }
 
@@ -437,9 +438,7 @@ static int usbvision_v4l2_open(struct inode *inode, struct file *file)
  */
 static int usbvision_v4l2_close(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        PDEBUG(DBG_IO, "close");
        mutex_lock(&usbvision->lock);
@@ -484,9 +483,7 @@ static int usbvision_v4l2_close(struct inode *inode, struct file *file)
 static int vidioc_g_register (struct file *file, void *priv,
                                struct v4l2_register *reg)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int errCode;
 
        if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
@@ -505,9 +502,7 @@ static int vidioc_g_register (struct file *file, void *priv,
 static int vidioc_s_register (struct file *file, void *priv,
                                struct v4l2_register *reg)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int errCode;
 
        if (!v4l2_chip_match_host(reg->match_type, reg->match_chip))
@@ -526,9 +521,7 @@ static int vidioc_s_register (struct file *file, void *priv,
 static int vidioc_querycap (struct file *file, void  *priv,
                                        struct v4l2_capability *vc)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        strlcpy(vc->driver, "USBVision", sizeof(vc->driver));
        strlcpy(vc->card,
@@ -548,9 +541,7 @@ static int vidioc_querycap (struct file *file, void  *priv,
 static int vidioc_enum_input (struct file *file, void *priv,
                                struct v4l2_input *vi)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int chan;
 
        if ((vi->index >= usbvision->video_inputs) || (vi->index < 0) )
@@ -603,9 +594,7 @@ static int vidioc_enum_input (struct file *file, void *priv,
 
 static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        *input = usbvision->ctl_input;
        return 0;
@@ -613,9 +602,7 @@ static int vidioc_g_input (struct file *file, void *priv, unsigned int *input)
 
 static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        if ((input >= usbvision->video_inputs) || (input < 0) )
                return -EINVAL;
@@ -632,9 +619,8 @@ static int vidioc_s_input (struct file *file, void *priv, unsigned int input)
 
 static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
+
        usbvision->tvnormId=*id;
 
        mutex_lock(&usbvision->lock);
@@ -650,9 +636,7 @@ static int vidioc_s_std (struct file *file, void *priv, v4l2_std_id *id)
 static int vidioc_g_tuner (struct file *file, void *priv,
                                struct v4l2_tuner *vt)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        if (!usbvision->have_tuner || vt->index)        // Only tuner 0
                return -EINVAL;
@@ -671,9 +655,7 @@ static int vidioc_g_tuner (struct file *file, void *priv,
 static int vidioc_s_tuner (struct file *file, void *priv,
                                struct v4l2_tuner *vt)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        // Only no or one tuner for now
        if (!usbvision->have_tuner || vt->index)
@@ -687,9 +669,7 @@ static int vidioc_s_tuner (struct file *file, void *priv,
 static int vidioc_g_frequency (struct file *file, void *priv,
                                struct v4l2_frequency *freq)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        freq->tuner = 0; // Only one tuner
        if(usbvision->radio) {
@@ -705,9 +685,7 @@ static int vidioc_g_frequency (struct file *file, void *priv,
 static int vidioc_s_frequency (struct file *file, void *priv,
                                struct v4l2_frequency *freq)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        // Only no or one tuner for now
        if (!usbvision->have_tuner || freq->tuner)
@@ -721,9 +699,7 @@ static int vidioc_s_frequency (struct file *file, void *priv,
 
 static int vidioc_g_audio (struct file *file, void *priv, struct v4l2_audio *a)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        memset(a,0,sizeof(*a));
        if(usbvision->radio) {
@@ -748,9 +724,7 @@ static int vidioc_s_audio (struct file *file, void *fh,
 static int vidioc_queryctrl (struct file *file, void *priv,
                            struct v4l2_queryctrl *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int id=ctrl->id;
 
        memset(ctrl,0,sizeof(*ctrl));
@@ -767,9 +741,7 @@ static int vidioc_queryctrl (struct file *file, void *priv,
 static int vidioc_g_ctrl (struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        call_i2c_clients(usbvision, VIDIOC_G_CTRL, ctrl);
 
        return 0;
@@ -778,9 +750,7 @@ static int vidioc_g_ctrl (struct file *file, void *priv,
 static int vidioc_s_ctrl (struct file *file, void *priv,
                                struct v4l2_control *ctrl)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        call_i2c_clients(usbvision, VIDIOC_S_CTRL, ctrl);
 
        return 0;
@@ -789,9 +759,7 @@ static int vidioc_s_ctrl (struct file *file, void *priv,
 static int vidioc_reqbufs (struct file *file,
                           void *priv, struct v4l2_requestbuffers *vr)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int ret;
 
        RESTRICT_TO_RANGE(vr->count,1,USBVISION_NUMFRAMES);
@@ -819,9 +787,7 @@ static int vidioc_reqbufs (struct file *file,
 static int vidioc_querybuf (struct file *file,
                            void *priv, struct v4l2_buffer *vb)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        struct usbvision_frame *frame;
 
        /* FIXME : must control
@@ -857,9 +823,7 @@ static int vidioc_querybuf (struct file *file,
 
 static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        struct usbvision_frame *frame;
        unsigned long lock_flags;
 
@@ -896,9 +860,7 @@ static int vidioc_qbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
 
 static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int ret;
        struct usbvision_frame *f;
        unsigned long lock_flags;
@@ -939,9 +901,7 @@ static int vidioc_dqbuf (struct file *file, void *priv, struct v4l2_buffer *vb)
 
 static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
        usbvision->streaming = Stream_On;
@@ -953,9 +913,7 @@ static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
 static int vidioc_streamoff(struct file *file,
                            void *priv, enum v4l2_buf_type type)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int b=V4L2_BUF_TYPE_VIDEO_CAPTURE;
 
        if (type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
@@ -988,9 +946,7 @@ static int vidioc_enum_fmt_vid_cap (struct file *file, void  *priv,
 static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
                                        struct v4l2_format *vf)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        vf->fmt.pix.width = usbvision->curwidth;
        vf->fmt.pix.height = usbvision->curheight;
        vf->fmt.pix.pixelformat = usbvision->palette.format;
@@ -1006,9 +962,7 @@ static int vidioc_g_fmt_vid_cap (struct file *file, void *priv,
 static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
                               struct v4l2_format *vf)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int formatIdx;
 
        /* Find requested format in available ones */
@@ -1036,9 +990,7 @@ static int vidioc_try_fmt_vid_cap (struct file *file, void *priv,
 static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
                               struct v4l2_format *vf)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int ret;
 
        if( 0 != (ret=vidioc_try_fmt_vid_cap (file, priv, vf)) ) {
@@ -1066,9 +1018,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
 static ssize_t usbvision_v4l2_read(struct file *file, char __user *buf,
                      size_t count, loff_t *ppos)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int noblock = file->f_flags & O_NONBLOCK;
        unsigned long lock_flags;
 
@@ -1177,10 +1127,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
                start = vma->vm_start;
        void *pos;
        u32 i;
-
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
 
        PDEBUG(DBG_MMAP, "mmap");
 
@@ -1237,9 +1184,7 @@ static int usbvision_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
  */
 static int usbvision_radio_open(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int errCode = 0;
 
        PDEBUG(DBG_IO, "%s:", __func__);
@@ -1289,9 +1234,7 @@ out:
 
 static int usbvision_radio_close(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct usb_usbvision *usbvision =
-               (struct usb_usbvision *) video_get_drvdata(dev);
+       struct usb_usbvision *usbvision = video_drvdata(file);
        int errCode = 0;
 
        PDEBUG(DBG_IO, "");
index feab12aa2c7b5e9c0efb030a7eb1551611dbc766..f16aafe9cf145a6cbbdc44af3451649939573968 100644 (file)
@@ -81,6 +81,22 @@ static struct uvc_control_info uvc_ctrls[] = {
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
                                | UVC_CONTROL_RESTORE,
        },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
+               .index          = 6,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_CONTROL,
+               .index          = 7,
+               .size           = 4,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
        {
                .entity         = UVC_GUID_UVC_PROCESSING,
                .selector       = PU_BACKLIGHT_COMPENSATION_CONTROL,
@@ -113,6 +129,60 @@ static struct uvc_control_info uvc_ctrls[] = {
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
                                | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
        },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
+               .index          = 12,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
+               .index          = 13,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_DIGITAL_MULTIPLIER_CONTROL,
+               .index          = 14,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_DIGITAL_MULTIPLIER_LIMIT_CONTROL,
+               .index          = 15,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_ANALOG_VIDEO_STANDARD_CONTROL,
+               .index          = 16,
+               .size           = 1,
+               .flags          = UVC_CONTROL_GET_CUR,
+       },
+       {
+               .entity         = UVC_GUID_UVC_PROCESSING,
+               .selector       = PU_ANALOG_LOCK_STATUS_CONTROL,
+               .index          = 17,
+               .size           = 1,
+               .flags          = UVC_CONTROL_GET_CUR,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_SCANNING_MODE_CONTROL,
+               .index          = 0,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_RESTORE,
+       },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
                .selector       = CT_AE_MODE_CONTROL,
@@ -138,6 +208,14 @@ static struct uvc_control_info uvc_ctrls[] = {
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
                                | UVC_CONTROL_RESTORE,
        },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_EXPOSURE_TIME_RELATIVE_CONTROL,
+               .index          = 4,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
+                               | UVC_CONTROL_RESTORE,
+       },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
                .selector       = CT_FOCUS_ABSOLUTE_CONTROL,
@@ -148,42 +226,90 @@ static struct uvc_control_info uvc_ctrls[] = {
        },
        {
                .entity         = UVC_GUID_UVC_CAMERA,
-               .selector       = CT_FOCUS_AUTO_CONTROL,
-               .index          = 17,
-               .size           = 1,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
-                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+               .selector       = CT_FOCUS_RELATIVE_CONTROL,
+               .index          = 6,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_AUTO_UPDATE,
        },
        {
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = PU_WHITE_BALANCE_TEMPERATURE_AUTO_CONTROL,
-               .index          = 12,
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_IRIS_ABSOLUTE_CONTROL,
+               .index          = 7,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_IRIS_RELATIVE_CONTROL,
+               .index          = 8,
                .size           = 1,
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
-                               | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
+                               | UVC_CONTROL_AUTO_UPDATE,
        },
        {
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = PU_WHITE_BALANCE_TEMPERATURE_CONTROL,
-               .index          = 6,
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_ZOOM_ABSOLUTE_CONTROL,
+               .index          = 9,
                .size           = 2,
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
                                | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
        },
        {
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = PU_WHITE_BALANCE_COMPONENT_AUTO_CONTROL,
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_ZOOM_RELATIVE_CONTROL,
+               .index          = 10,
+               .size           = 3,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_PANTILT_ABSOLUTE_CONTROL,
+               .index          = 11,
+               .size           = 8,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_PANTILT_RELATIVE_CONTROL,
+               .index          = 12,
+               .size           = 4,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_ROLL_ABSOLUTE_CONTROL,
                .index          = 13,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_ROLL_RELATIVE_CONTROL,
+               .index          = 14,
+               .size           = 2,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+                               | UVC_CONTROL_AUTO_UPDATE,
+       },
+       {
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_FOCUS_AUTO_CONTROL,
+               .index          = 17,
                .size           = 1,
                .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
                                | UVC_CONTROL_GET_DEF | UVC_CONTROL_RESTORE,
        },
        {
-               .entity         = UVC_GUID_UVC_PROCESSING,
-               .selector       = PU_WHITE_BALANCE_COMPONENT_CONTROL,
-               .index          = 7,
-               .size           = 4,
-               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_RANGE
+               .entity         = UVC_GUID_UVC_CAMERA,
+               .selector       = CT_PRIVACY_CONTROL,
+               .index          = 18,
+               .size           = 1,
+               .flags          = UVC_CONTROL_SET_CUR | UVC_CONTROL_GET_CUR
                                | UVC_CONTROL_RESTORE | UVC_CONTROL_AUTO_UPDATE,
        },
 };
@@ -711,7 +837,17 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
 
        for (i = 0; i < entity->ncontrols; ++i) {
                ctrl = &entity->controls[i];
-               if (ctrl->info == NULL || !ctrl->dirty)
+               if (ctrl->info == NULL)
+                       continue;
+
+               /* Reset the loaded flag for auto-update controls that were
+                * marked as loaded in uvc_ctrl_get/uvc_ctrl_set to prevent
+                * uvc_ctrl_get from using the cached value.
+                */
+               if (ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE)
+                       ctrl->loaded = 0;
+
+               if (!ctrl->dirty)
                        continue;
 
                if (!rollback)
@@ -727,9 +863,6 @@ static int uvc_ctrl_commit_entity(struct uvc_device *dev,
                               uvc_ctrl_data(ctrl, UVC_CTRL_DATA_BACKUP),
                               ctrl->info->size);
 
-               if ((ctrl->info->flags & UVC_CONTROL_GET_CUR) == 0)
-                       ctrl->loaded = 0;
-
                ctrl->dirty = 0;
 
                if (ret < 0)
@@ -787,8 +920,7 @@ int uvc_ctrl_get(struct uvc_video_device *video,
                if (ret < 0)
                        return ret;
 
-               if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0)
-                       ctrl->loaded = 1;
+               ctrl->loaded = 1;
        }
 
        xctrl->value = uvc_get_le_value(
@@ -839,8 +971,7 @@ int uvc_ctrl_set(struct uvc_video_device *video,
                                return ret;
                }
 
-               if ((ctrl->info->flags & UVC_CONTROL_AUTO_UPDATE) == 0)
-                       ctrl->loaded = 1;
+               ctrl->loaded = 1;
        }
 
        if (!ctrl->dirty) {
index 7e102034d38da0726ffca86d58e1bd36fb7ca167..d7ad060640bc5758fd526d7864fc94adcab8a52c 100644 (file)
@@ -1663,7 +1663,7 @@ static int uvc_suspend(struct usb_interface *intf, pm_message_t message)
        return uvc_video_suspend(&dev->video);
 }
 
-static int uvc_resume(struct usb_interface *intf)
+static int __uvc_resume(struct usb_interface *intf, int reset)
 {
        struct uvc_device *dev = usb_get_intfdata(intf);
        int ret;
@@ -1672,7 +1672,7 @@ static int uvc_resume(struct usb_interface *intf)
                intf->cur_altsetting->desc.bInterfaceNumber);
 
        if (intf->cur_altsetting->desc.bInterfaceSubClass == SC_VIDEOCONTROL) {
-               if ((ret = uvc_ctrl_resume_device(dev)) < 0)
+               if (reset && (ret = uvc_ctrl_resume_device(dev)) < 0)
                        return ret;
 
                return uvc_status_resume(dev);
@@ -1687,6 +1687,16 @@ static int uvc_resume(struct usb_interface *intf)
        return uvc_video_resume(&dev->video);
 }
 
+static int uvc_resume(struct usb_interface *intf)
+{
+       return __uvc_resume(intf, 0);
+}
+
+static int uvc_reset_resume(struct usb_interface *intf)
+{
+       return __uvc_resume(intf, 1);
+}
+
 /* ------------------------------------------------------------------------
  * Driver initialization and cleanup
  */
@@ -1902,6 +1912,24 @@ static struct usb_device_id uvc_ids[] = {
          .bInterfaceSubClass   = 1,
          .bInterfaceProtocol   = 0,
          .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Compaq Presario B1200 - Bison Electronics */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0104,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /* Acer Travelmate 7720 - Bison Electronics */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0105,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
        /* Medion Akoya Mini E1210 - Bison Electronics */
        { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                                | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1920,6 +1948,24 @@ static struct usb_device_id uvc_ids[] = {
          .bInterfaceSubClass   = 1,
          .bInterfaceProtocol   = 0,
          .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /*  Fujitsu Amilo SI2636 - Bison Electronics */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0202,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
+       /*  Advent 4211 - Bison Electronics */
+       { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
+                               | USB_DEVICE_ID_MATCH_INT_INFO,
+         .idVendor             = 0x5986,
+         .idProduct            = 0x0203,
+         .bInterfaceClass      = USB_CLASS_VIDEO,
+         .bInterfaceSubClass   = 1,
+         .bInterfaceProtocol   = 0,
+         .driver_info          = UVC_QUIRK_PROBE_MINMAX },
        /* Bison Electronics */
        { .match_flags          = USB_DEVICE_ID_MATCH_DEVICE
                                | USB_DEVICE_ID_MATCH_INT_INFO,
@@ -1952,6 +1998,7 @@ struct uvc_driver uvc_driver = {
                .disconnect     = uvc_disconnect,
                .suspend        = uvc_suspend,
                .resume         = uvc_resume,
+               .reset_resume   = uvc_reset_resume,
                .id_table       = uvc_ids,
                .supports_autosuspend = 1,
        },
index 75e678ac54ebbe027aae395133e8a30ad76900b0..5d60b264d59a1d2f7d2a3b41c224023cc5aff40e 100644 (file)
@@ -177,9 +177,15 @@ int uvc_status_init(struct uvc_device *dev)
 
        uvc_input_init(dev);
 
+       dev->status = kzalloc(UVC_MAX_STATUS_SIZE, GFP_KERNEL);
+       if (dev->status == NULL)
+               return -ENOMEM;
+
        dev->int_urb = usb_alloc_urb(0, GFP_KERNEL);
-       if (dev->int_urb == NULL)
+       if (dev->int_urb == NULL) {
+               kfree(dev->status);
                return -ENOMEM;
+       }
 
        pipe = usb_rcvintpipe(dev->udev, ep->desc.bEndpointAddress);
 
@@ -192,7 +198,7 @@ int uvc_status_init(struct uvc_device *dev)
                interval = fls(interval) - 1;
 
        usb_fill_int_urb(dev->int_urb, dev->udev, pipe,
-               dev->status, sizeof dev->status, uvc_status_complete,
+               dev->status, UVC_MAX_STATUS_SIZE, uvc_status_complete,
                dev, interval);
 
        return usb_submit_urb(dev->int_urb, GFP_KERNEL);
@@ -202,6 +208,7 @@ void uvc_status_cleanup(struct uvc_device *dev)
 {
        usb_kill_urb(dev->int_urb);
        usb_free_urb(dev->int_urb);
+       kfree(dev->status);
        uvc_input_cleanup(dev);
 }
 
index d7bd71be40a9d8f76afd3a71c12b5025c714867d..78e4c4e09d89cb1c5fae161b7cce07f412712917 100644 (file)
@@ -400,15 +400,13 @@ static int uvc_has_privileges(struct uvc_fh *handle)
 
 static int uvc_v4l2_open(struct inode *inode, struct file *file)
 {
-       struct video_device *vdev;
        struct uvc_video_device *video;
        struct uvc_fh *handle;
        int ret = 0;
 
        uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_open\n");
        mutex_lock(&uvc_driver.open_mutex);
-       vdev = video_devdata(file);
-       video = video_get_drvdata(vdev);
+       video = video_drvdata(file);
 
        if (video->dev->state & UVC_DEV_DISCONNECTED) {
                ret = -ENODEV;
@@ -440,8 +438,7 @@ done:
 
 static int uvc_v4l2_release(struct inode *inode, struct file *file)
 {
-       struct video_device *vdev = video_devdata(file);
-       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_video_device *video = video_drvdata(file);
        struct uvc_fh *handle = (struct uvc_fh *)file->private_data;
 
        uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_release\n");
@@ -845,10 +842,6 @@ static int uvc_v4l2_do_ioctl(struct inode *inode, struct file *file,
                if (ret < 0)
                        return ret;
 
-               if (!(video->streaming->cur_format->flags &
-                   UVC_FMT_FLAG_COMPRESSED))
-                       video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
-
                rb->count = ret;
                ret = 0;
                break;
@@ -1031,8 +1024,7 @@ static struct vm_operations_struct uvc_vm_ops = {
 
 static int uvc_v4l2_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct video_device *vdev = video_devdata(file);
-       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_video_device *video = video_drvdata(file);
        struct uvc_buffer *uninitialized_var(buffer);
        struct page *page;
        unsigned long addr, start, size;
@@ -1085,8 +1077,7 @@ done:
 
 static unsigned int uvc_v4l2_poll(struct file *file, poll_table *wait)
 {
-       struct video_device *vdev = video_devdata(file);
-       struct uvc_video_device *video = video_get_drvdata(vdev);
+       struct uvc_video_device *video = video_drvdata(file);
 
        uvc_trace(UVC_TRACE_CALLS, "uvc_v4l2_poll\n");
 
index 6854ac78a1615b07353acfc6ca3d79286cc78e3f..b7bb23820d803013548ef99ce91ccd52039102fb 100644 (file)
@@ -455,7 +455,8 @@ static void uvc_video_decode_isoc(struct urb *urb,
                        urb->iso_frame_desc[i].actual_length - ret);
 
                /* Process the header again. */
-               uvc_video_decode_end(video, buf, mem, ret);
+               uvc_video_decode_end(video, buf, mem,
+                       urb->iso_frame_desc[i].actual_length);
 
                if (buf->state == UVC_BUF_STATE_DONE ||
                    buf->state == UVC_BUF_STATE_ERROR)
@@ -512,7 +513,7 @@ static void uvc_video_decode_bulk(struct urb *urb,
            video->bulk.payload_size >= video->bulk.max_payload_size) {
                if (!video->bulk.skip_payload && buf != NULL) {
                        uvc_video_decode_end(video, buf, video->bulk.header,
-                               video->bulk.header_size);
+                               video->bulk.payload_size);
                        if (buf->state == UVC_BUF_STATE_DONE ||
                            buf->state == UVC_BUF_STATE_ERROR)
                                buf = uvc_queue_next_buffer(&video->queue, buf);
@@ -655,7 +656,7 @@ static int uvc_init_video_isoc(struct uvc_video_device *video,
        if (size > UVC_MAX_FRAME_SIZE)
                return -EINVAL;
 
-       npackets = (size + psize - 1) / psize;
+       npackets = DIV_ROUND_UP(size, psize);
        if (npackets > UVC_MAX_ISO_PACKETS)
                npackets = UVC_MAX_ISO_PACKETS;
 
@@ -970,6 +971,11 @@ int uvc_video_enable(struct uvc_video_device *video, int enable)
                return 0;
        }
 
+       if (video->streaming->cur_format->flags & UVC_FMT_FLAG_COMPRESSED)
+               video->queue.flags &= ~UVC_QUEUE_DROP_INCOMPLETE;
+       else
+               video->queue.flags |= UVC_QUEUE_DROP_INCOMPLETE;
+
        if ((ret = uvc_queue_enable(&video->queue, 1)) < 0)
                return ret;
 
index bafe3406e305bd035465851bdd70bd5438b1349a..9a6bc1aafb166bf5533f94494c7a71d68bdae7a1 100644 (file)
@@ -303,6 +303,8 @@ struct uvc_xu_control {
 #define UVC_MAX_FRAME_SIZE     (16*1024*1024)
 /* Maximum number of video buffers. */
 #define UVC_MAX_VIDEO_BUFFERS  32
+/* Maximum status buffer size in bytes of interrupt URB. */
+#define UVC_MAX_STATUS_SIZE    16
 
 #define UVC_CTRL_CONTROL_TIMEOUT       300
 #define UVC_CTRL_STREAMING_TIMEOUT     1000
@@ -634,7 +636,7 @@ struct uvc_device {
        /* Status Interrupt Endpoint */
        struct usb_host_endpoint *int_ep;
        struct urb *int_urb;
-       __u8 status[16];
+       __u8 *status;
        struct input_dev *input;
 
        /* Video Streaming interfaces */
index 88ca1310441767ff7314a546a02a8675b69f2cc5..20c3be8617ea62eb583fd7827ad6c0c019de6d63 100644 (file)
@@ -187,9 +187,11 @@ const char **v4l2_ctrl_get_menu(u32 id)
                NULL
        };
        static const char *mpeg_audio_encoding[] = {
-               "Layer I",
-               "Layer II",
-               "Layer III",
+               "MPEG-1/2 Layer I",
+               "MPEG-1/2 Layer II",
+               "MPEG-1/2 Layer III",
+               "MPEG-2/4 AAC",
+               "AC-3",
                NULL
        };
        static const char *mpeg_audio_l1_bitrate[] = {
@@ -243,6 +245,28 @@ const char **v4l2_ctrl_get_menu(u32 id)
                "320 kbps",
                NULL
        };
+       static const char *mpeg_audio_ac3_bitrate[] = {
+               "32 kbps",
+               "40 kbps",
+               "48 kbps",
+               "56 kbps",
+               "64 kbps",
+               "80 kbps",
+               "96 kbps",
+               "112 kbps",
+               "128 kbps",
+               "160 kbps",
+               "192 kbps",
+               "224 kbps",
+               "256 kbps",
+               "320 kbps",
+               "384 kbps",
+               "448 kbps",
+               "512 kbps",
+               "576 kbps",
+               "640 kbps",
+               NULL
+       };
        static const char *mpeg_audio_mode[] = {
                "Stereo",
                "Joint Stereo",
@@ -271,6 +295,7 @@ const char **v4l2_ctrl_get_menu(u32 id)
        static const char *mpeg_video_encoding[] = {
                "MPEG-1",
                "MPEG-2",
+               "MPEG-4 AVC",
                NULL
        };
        static const char *mpeg_video_aspect[] = {
@@ -311,6 +336,8 @@ const char **v4l2_ctrl_get_menu(u32 id)
                        return mpeg_audio_l2_bitrate;
                case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
                        return mpeg_audio_l3_bitrate;
+               case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
+                       return mpeg_audio_ac3_bitrate;
                case V4L2_CID_MPEG_AUDIO_MODE:
                        return mpeg_audio_mode;
                case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
@@ -335,62 +362,73 @@ const char **v4l2_ctrl_get_menu(u32 id)
 }
 EXPORT_SYMBOL(v4l2_ctrl_get_menu);
 
-/* Fill in a struct v4l2_queryctrl */
-int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
+/* Return the control name. */
+const char *v4l2_ctrl_get_name(u32 id)
 {
-       const char *name;
-
-       qctrl->flags = 0;
-       switch (qctrl->id) {
+       switch (id) {
        /* USER controls */
-       case V4L2_CID_USER_CLASS:       name = "User Controls"; break;
-       case V4L2_CID_AUDIO_VOLUME:     name = "Volume"; break;
-       case V4L2_CID_AUDIO_MUTE:       name = "Mute"; break;
-       case V4L2_CID_AUDIO_BALANCE:    name = "Balance"; break;
-       case V4L2_CID_AUDIO_BASS:       name = "Bass"; break;
-       case V4L2_CID_AUDIO_TREBLE:     name = "Treble"; break;
-       case V4L2_CID_AUDIO_LOUDNESS:   name = "Loudness"; break;
-       case V4L2_CID_BRIGHTNESS:       name = "Brightness"; break;
-       case V4L2_CID_CONTRAST:         name = "Contrast"; break;
-       case V4L2_CID_SATURATION:       name = "Saturation"; break;
-       case V4L2_CID_HUE:              name = "Hue"; break;
+       case V4L2_CID_USER_CLASS:       return "User Controls";
+       case V4L2_CID_AUDIO_VOLUME:     return "Volume";
+       case V4L2_CID_AUDIO_MUTE:       return "Mute";
+       case V4L2_CID_AUDIO_BALANCE:    return "Balance";
+       case V4L2_CID_AUDIO_BASS:       return "Bass";
+       case V4L2_CID_AUDIO_TREBLE:     return "Treble";
+       case V4L2_CID_AUDIO_LOUDNESS:   return "Loudness";
+       case V4L2_CID_BRIGHTNESS:       return "Brightness";
+       case V4L2_CID_CONTRAST:         return "Contrast";
+       case V4L2_CID_SATURATION:       return "Saturation";
+       case V4L2_CID_HUE:              return "Hue";
 
        /* MPEG controls */
-       case V4L2_CID_MPEG_CLASS:               name = "MPEG Encoder Controls"; break;
-       case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: name = "Audio Sampling Frequency"; break;
-       case V4L2_CID_MPEG_AUDIO_ENCODING:      name = "Audio Encoding Layer"; break;
-       case V4L2_CID_MPEG_AUDIO_L1_BITRATE:    name = "Audio Layer I Bitrate"; break;
-       case V4L2_CID_MPEG_AUDIO_L2_BITRATE:    name = "Audio Layer II Bitrate"; break;
-       case V4L2_CID_MPEG_AUDIO_L3_BITRATE:    name = "Audio Layer III Bitrate"; break;
-       case V4L2_CID_MPEG_AUDIO_MODE:          name = "Audio Stereo Mode"; break;
-       case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: name = "Audio Stereo Mode Extension"; break;
-       case V4L2_CID_MPEG_AUDIO_EMPHASIS:      name = "Audio Emphasis"; break;
-       case V4L2_CID_MPEG_AUDIO_CRC:           name = "Audio CRC"; break;
-       case V4L2_CID_MPEG_AUDIO_MUTE:          name = "Audio Mute"; break;
-       case V4L2_CID_MPEG_VIDEO_ENCODING:      name = "Video Encoding"; break;
-       case V4L2_CID_MPEG_VIDEO_ASPECT:        name = "Video Aspect"; break;
-       case V4L2_CID_MPEG_VIDEO_B_FRAMES:      name = "Video B Frames"; break;
-       case V4L2_CID_MPEG_VIDEO_GOP_SIZE:      name = "Video GOP Size"; break;
-       case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:   name = "Video GOP Closure"; break;
-       case V4L2_CID_MPEG_VIDEO_PULLDOWN:      name = "Video Pulldown"; break;
-       case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:  name = "Video Bitrate Mode"; break;
-       case V4L2_CID_MPEG_VIDEO_BITRATE:       name = "Video Bitrate"; break;
-       case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:  name = "Video Peak Bitrate"; break;
-       case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: name = "Video Temporal Decimation"; break;
-       case V4L2_CID_MPEG_VIDEO_MUTE:          name = "Video Mute"; break;
-       case V4L2_CID_MPEG_VIDEO_MUTE_YUV:      name = "Video Mute YUV"; break;
-       case V4L2_CID_MPEG_STREAM_TYPE:         name = "Stream Type"; break;
-       case V4L2_CID_MPEG_STREAM_PID_PMT:      name = "Stream PMT Program ID"; break;
-       case V4L2_CID_MPEG_STREAM_PID_AUDIO:    name = "Stream Audio Program ID"; break;
-       case V4L2_CID_MPEG_STREAM_PID_VIDEO:    name = "Stream Video Program ID"; break;
-       case V4L2_CID_MPEG_STREAM_PID_PCR:      name = "Stream PCR Program ID"; break;
-       case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: name = "Stream PES Audio ID"; break;
-       case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: name = "Stream PES Video ID"; break;
-       case V4L2_CID_MPEG_STREAM_VBI_FMT:      name = "Stream VBI Format"; break;
+       case V4L2_CID_MPEG_CLASS:               return "MPEG Encoder Controls";
+       case V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ: return "Audio Sampling Frequency";
+       case V4L2_CID_MPEG_AUDIO_ENCODING:      return "Audio Encoding";
+       case V4L2_CID_MPEG_AUDIO_L1_BITRATE:    return "Audio Layer I Bitrate";
+       case V4L2_CID_MPEG_AUDIO_L2_BITRATE:    return "Audio Layer II Bitrate";
+       case V4L2_CID_MPEG_AUDIO_L3_BITRATE:    return "Audio Layer III Bitrate";
+       case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:   return "Audio AAC Bitrate";
+       case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:   return "Audio AC-3 Bitrate";
+       case V4L2_CID_MPEG_AUDIO_MODE:          return "Audio Stereo Mode";
+       case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION: return "Audio Stereo Mode Extension";
+       case V4L2_CID_MPEG_AUDIO_EMPHASIS:      return "Audio Emphasis";
+       case V4L2_CID_MPEG_AUDIO_CRC:           return "Audio CRC";
+       case V4L2_CID_MPEG_AUDIO_MUTE:          return "Audio Mute";
+       case V4L2_CID_MPEG_VIDEO_ENCODING:      return "Video Encoding";
+       case V4L2_CID_MPEG_VIDEO_ASPECT:        return "Video Aspect";
+       case V4L2_CID_MPEG_VIDEO_B_FRAMES:      return "Video B Frames";
+       case V4L2_CID_MPEG_VIDEO_GOP_SIZE:      return "Video GOP Size";
+       case V4L2_CID_MPEG_VIDEO_GOP_CLOSURE:   return "Video GOP Closure";
+       case V4L2_CID_MPEG_VIDEO_PULLDOWN:      return "Video Pulldown";
+       case V4L2_CID_MPEG_VIDEO_BITRATE_MODE:  return "Video Bitrate Mode";
+       case V4L2_CID_MPEG_VIDEO_BITRATE:       return "Video Bitrate";
+       case V4L2_CID_MPEG_VIDEO_BITRATE_PEAK:  return "Video Peak Bitrate";
+       case V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION: return "Video Temporal Decimation";
+       case V4L2_CID_MPEG_VIDEO_MUTE:          return "Video Mute";
+       case V4L2_CID_MPEG_VIDEO_MUTE_YUV:      return "Video Mute YUV";
+       case V4L2_CID_MPEG_STREAM_TYPE:         return "Stream Type";
+       case V4L2_CID_MPEG_STREAM_PID_PMT:      return "Stream PMT Program ID";
+       case V4L2_CID_MPEG_STREAM_PID_AUDIO:    return "Stream Audio Program ID";
+       case V4L2_CID_MPEG_STREAM_PID_VIDEO:    return "Stream Video Program ID";
+       case V4L2_CID_MPEG_STREAM_PID_PCR:      return "Stream PCR Program ID";
+       case V4L2_CID_MPEG_STREAM_PES_ID_AUDIO: return "Stream PES Audio ID";
+       case V4L2_CID_MPEG_STREAM_PES_ID_VIDEO: return "Stream PES Video ID";
+       case V4L2_CID_MPEG_STREAM_VBI_FMT:      return "Stream VBI Format";
 
        default:
-               return -EINVAL;
+               return NULL;
        }
+}
+EXPORT_SYMBOL(v4l2_ctrl_get_name);
+
+/* Fill in a struct v4l2_queryctrl */
+int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def)
+{
+       const char *name = v4l2_ctrl_get_name(qctrl->id);
+
+       qctrl->flags = 0;
+       if (name == NULL)
+               return -EINVAL;
+
        switch (qctrl->id) {
        case V4L2_CID_AUDIO_MUTE:
        case V4L2_CID_AUDIO_LOUDNESS:
@@ -407,6 +445,7 @@ int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 ste
        case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
        case V4L2_CID_MPEG_AUDIO_L2_BITRATE:
        case V4L2_CID_MPEG_AUDIO_L3_BITRATE:
+       case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
        case V4L2_CID_MPEG_AUDIO_MODE:
        case V4L2_CID_MPEG_AUDIO_MODE_EXTENSION:
        case V4L2_CID_MPEG_AUDIO_EMPHASIS:
@@ -493,7 +532,7 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
        case V4L2_CID_MPEG_AUDIO_ENCODING:
                return v4l2_ctrl_query_fill(qctrl,
                                V4L2_MPEG_AUDIO_ENCODING_LAYER_1,
-                               V4L2_MPEG_AUDIO_ENCODING_LAYER_3, 1,
+                               V4L2_MPEG_AUDIO_ENCODING_AC3, 1,
                                V4L2_MPEG_AUDIO_ENCODING_LAYER_2);
        case V4L2_CID_MPEG_AUDIO_L1_BITRATE:
                return v4l2_ctrl_query_fill(qctrl,
@@ -510,6 +549,13 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
                                V4L2_MPEG_AUDIO_L3_BITRATE_32K,
                                V4L2_MPEG_AUDIO_L3_BITRATE_320K, 1,
                                V4L2_MPEG_AUDIO_L3_BITRATE_192K);
+       case V4L2_CID_MPEG_AUDIO_AAC_BITRATE:
+               return v4l2_ctrl_query_fill(qctrl, 0, 6400, 1, 3200000);
+       case V4L2_CID_MPEG_AUDIO_AC3_BITRATE:
+               return v4l2_ctrl_query_fill(qctrl,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_32K,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_640K, 1,
+                               V4L2_MPEG_AUDIO_AC3_BITRATE_384K);
        case V4L2_CID_MPEG_AUDIO_MODE:
                return v4l2_ctrl_query_fill(qctrl,
                                V4L2_MPEG_AUDIO_MODE_STEREO,
@@ -535,7 +581,7 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
        case V4L2_CID_MPEG_VIDEO_ENCODING:
                return v4l2_ctrl_query_fill(qctrl,
                                V4L2_MPEG_VIDEO_ENCODING_MPEG_1,
-                               V4L2_MPEG_VIDEO_ENCODING_MPEG_2, 1,
+                               V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, 1,
                                V4L2_MPEG_VIDEO_ENCODING_MPEG_2);
        case V4L2_CID_MPEG_VIDEO_ASPECT:
                return v4l2_ctrl_query_fill(qctrl,
@@ -594,12 +640,17 @@ int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl)
 EXPORT_SYMBOL(v4l2_ctrl_query_fill_std);
 
 /* Fill in a struct v4l2_querymenu based on the struct v4l2_queryctrl and
-   the menu. The qctrl pointer may be NULL, in which case it is ignored. */
+   the menu. The qctrl pointer may be NULL, in which case it is ignored.
+   If menu_items is NULL, then the menu items are retrieved using
+   v4l2_ctrl_get_menu. */
 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qctrl,
               const char **menu_items)
 {
        int i;
 
+       qmenu->reserved = 0;
+       if (menu_items == NULL)
+               menu_items = v4l2_ctrl_get_menu(qmenu->id);
        if (menu_items == NULL ||
            (qctrl && (qmenu->index < qctrl->minimum || qmenu->index > qctrl->maximum)))
                return -EINVAL;
@@ -607,11 +658,31 @@ int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu, struct v4l2_queryctrl *qc
        if (menu_items[i] == NULL || menu_items[i][0] == '\0')
                return -EINVAL;
        snprintf(qmenu->name, sizeof(qmenu->name), menu_items[qmenu->index]);
-       qmenu->reserved = 0;
        return 0;
 }
 EXPORT_SYMBOL(v4l2_ctrl_query_menu);
 
+/* Fill in a struct v4l2_querymenu based on the specified array of valid
+   menu items (terminated by V4L2_CTRL_MENU_IDS_END).
+   Use this if there are 'holes' in the list of valid menu items. */
+int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids)
+{
+       const char **menu_items = v4l2_ctrl_get_menu(qmenu->id);
+
+       qmenu->reserved = 0;
+       if (menu_items == NULL || ids == NULL)
+               return -EINVAL;
+       while (*ids != V4L2_CTRL_MENU_IDS_END) {
+               if (*ids++ == qmenu->index) {
+                       snprintf(qmenu->name, sizeof(qmenu->name),
+                                      menu_items[qmenu->index]);
+                       return 0;
+               }
+       }
+       return -EINVAL;
+}
+EXPORT_SYMBOL(v4l2_ctrl_query_menu_valid_items);
+
 /* ctrl_classes points to an array of u32 pointers, the last element is
    a NULL pointer. Each u32 array is a 0-terminated array of control IDs.
    Each array must be sorted low to high and belong to the same control
index 155fdec9ac7d7c4fc0aa773581021fbe59ab3355..ccd6566a515e1c293ec85f8f067f48fb4fea4643 100644 (file)
@@ -42,6 +42,7 @@ static ssize_t show_index(struct device *cd,
                         struct device_attribute *attr, char *buf)
 {
        struct video_device *vfd = container_of(cd, struct video_device, dev);
+
        return sprintf(buf, "%i\n", vfd->index);
 }
 
@@ -49,6 +50,7 @@ static ssize_t show_name(struct device *cd,
                         struct device_attribute *attr, char *buf)
 {
        struct video_device *vfd = container_of(cd, struct video_device, dev);
+
        return sprintf(buf, "%.*s\n", (int)sizeof(vfd->name), vfd->name);
 }
 
@@ -58,12 +60,16 @@ static struct device_attribute video_device_attrs[] = {
        __ATTR_NULL
 };
 
+/*
+ *     Active devices
+ */
+static struct video_device *video_device[VIDEO_NUM_DEVICES];
+static DEFINE_MUTEX(videodev_lock);
+static DECLARE_BITMAP(video_nums[VFL_TYPE_MAX], VIDEO_NUM_DEVICES);
+
 struct video_device *video_device_alloc(void)
 {
-       struct video_device *vfd;
-
-       vfd = kzalloc(sizeof(*vfd), GFP_KERNEL);
-       return vfd;
+       return kzalloc(sizeof(struct video_device), GFP_KERNEL);
 }
 EXPORT_SYMBOL(video_device_alloc);
 
@@ -73,16 +79,52 @@ void video_device_release(struct video_device *vfd)
 }
 EXPORT_SYMBOL(video_device_release);
 
+void video_device_release_empty(struct video_device *vfd)
+{
+       /* Do nothing */
+       /* Only valid when the video_device struct is a static. */
+}
+EXPORT_SYMBOL(video_device_release_empty);
+
+/* Called when the last user of the character device is gone. */
+static void v4l2_chardev_release(struct kobject *kobj)
+{
+       struct video_device *vfd = container_of(kobj, struct video_device, cdev.kobj);
+
+       mutex_lock(&videodev_lock);
+       if (video_device[vfd->minor] != vfd) {
+               mutex_unlock(&videodev_lock);
+               BUG();
+               return;
+       }
+
+       /* Free up this device for reuse */
+       video_device[vfd->minor] = NULL;
+       clear_bit(vfd->num, video_nums[vfd->vfl_type]);
+       mutex_unlock(&videodev_lock);
+
+       /* Release the character device */
+       vfd->cdev_release(kobj);
+       /* Release video_device and perform other
+          cleanups as needed. */
+       if (vfd->release)
+               vfd->release(vfd);
+}
+
+/* The new kobj_type for the character device */
+static struct kobj_type v4l2_ktype_cdev_default = {
+       .release = v4l2_chardev_release,
+};
+
 static void video_release(struct device *cd)
 {
        struct video_device *vfd = container_of(cd, struct video_device, dev);
 
-#if 1
-       /* needed until all drivers are fixed */
-       if (!vfd->release)
-               return;
-#endif
-       vfd->release(vfd);
+       /* It's now safe to delete the char device.
+          This will either trigger the v4l2_chardev_release immediately (if
+          the refcount goes to 0) or later when the last user of the
+          character device closes it. */
+       cdev_del(&vfd->cdev);
 }
 
 static struct class video_class = {
@@ -91,87 +133,12 @@ static struct class video_class = {
        .dev_release = video_release,
 };
 
-/*
- *     Active devices
- */
-
-static struct video_device *video_device[VIDEO_NUM_DEVICES];
-static DEFINE_MUTEX(videodev_lock);
-
 struct video_device *video_devdata(struct file *file)
 {
        return video_device[iminor(file->f_path.dentry->d_inode)];
 }
 EXPORT_SYMBOL(video_devdata);
 
-/*
- *     Open a video device - FIXME: Obsoleted
- */
-static int video_open(struct inode *inode, struct file *file)
-{
-       unsigned int minor = iminor(inode);
-       int err = 0;
-       struct video_device *vfl;
-       const struct file_operations *old_fops;
-
-       if (minor >= VIDEO_NUM_DEVICES)
-               return -ENODEV;
-       lock_kernel();
-       mutex_lock(&videodev_lock);
-       vfl = video_device[minor];
-       if (vfl == NULL) {
-               mutex_unlock(&videodev_lock);
-               request_module("char-major-%d-%d", VIDEO_MAJOR, minor);
-               mutex_lock(&videodev_lock);
-               vfl = video_device[minor];
-               if (vfl == NULL) {
-                       mutex_unlock(&videodev_lock);
-                       unlock_kernel();
-                       return -ENODEV;
-               }
-       }
-       old_fops = file->f_op;
-       file->f_op = fops_get(vfl->fops);
-       if (file->f_op->open)
-               err = file->f_op->open(inode, file);
-       if (err) {
-               fops_put(file->f_op);
-               file->f_op = fops_get(old_fops);
-       }
-       fops_put(old_fops);
-       mutex_unlock(&videodev_lock);
-       unlock_kernel();
-       return err;
-}
-
-/*
- * open/release helper functions -- handle exclusive opens
- * Should be removed soon
- */
-int video_exclusive_open(struct inode *inode, struct file *file)
-{
-       struct video_device *vfl = video_devdata(file);
-       int retval = 0;
-
-       mutex_lock(&vfl->lock);
-       if (vfl->users)
-               retval = -EBUSY;
-       else
-               vfl->users++;
-       mutex_unlock(&vfl->lock);
-       return retval;
-}
-EXPORT_SYMBOL(video_exclusive_open);
-
-int video_exclusive_release(struct inode *inode, struct file *file)
-{
-       struct video_device *vfl = video_devdata(file);
-
-       vfl->users--;
-       return 0;
-}
-EXPORT_SYMBOL(video_exclusive_release);
-
 /**
  * get_index - assign stream number based on parent device
  * @vdev: video_device to assign index number to, vdev->dev should be assigned
@@ -252,33 +219,29 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
                                        int index)
 {
        int i = 0;
-       int base;
-       int end;
        int ret;
-       char *name_base;
+       int minor_offset = 0;
+       int minor_cnt = VIDEO_NUM_DEVICES;
+       const char *name_base;
+       void *priv = video_get_drvdata(vfd);
+
+       /* the release callback MUST be present */
+       BUG_ON(!vfd->release);
 
        if (vfd == NULL)
                return -EINVAL;
 
        switch (type) {
        case VFL_TYPE_GRABBER:
-               base = MINOR_VFL_TYPE_GRABBER_MIN;
-               end = MINOR_VFL_TYPE_GRABBER_MAX+1;
                name_base = "video";
                break;
        case VFL_TYPE_VTX:
-               base = MINOR_VFL_TYPE_VTX_MIN;
-               end = MINOR_VFL_TYPE_VTX_MAX+1;
                name_base = "vtx";
                break;
        case VFL_TYPE_VBI:
-               base = MINOR_VFL_TYPE_VBI_MIN;
-               end = MINOR_VFL_TYPE_VBI_MAX+1;
                name_base = "vbi";
                break;
        case VFL_TYPE_RADIO:
-               base = MINOR_VFL_TYPE_RADIO_MIN;
-               end = MINOR_VFL_TYPE_RADIO_MAX+1;
                name_base = "radio";
                break;
        default:
@@ -287,28 +250,70 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
                return -EINVAL;
        }
 
+       vfd->vfl_type = type;
+
+#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
+       /* Keep the ranges for the first four types for historical
+        * reasons.
+        * Newer devices (not yet in place) should use the range
+        * of 128-191 and just pick the first free minor there
+        * (new style). */
+       switch (type) {
+       case VFL_TYPE_GRABBER:
+               minor_offset = 0;
+               minor_cnt = 64;
+               break;
+       case VFL_TYPE_RADIO:
+               minor_offset = 64;
+               minor_cnt = 64;
+               break;
+       case VFL_TYPE_VTX:
+               minor_offset = 192;
+               minor_cnt = 32;
+               break;
+       case VFL_TYPE_VBI:
+               minor_offset = 224;
+               minor_cnt = 32;
+               break;
+       default:
+               minor_offset = 128;
+               minor_cnt = 64;
+               break;
+       }
+#endif
+
+       /* Initialize the character device */
+       cdev_init(&vfd->cdev, vfd->fops);
+       vfd->cdev.owner = vfd->fops->owner;
        /* pick a minor number */
        mutex_lock(&videodev_lock);
-       if (nr >= 0  &&  nr < end-base) {
-               /* use the one the driver asked for */
-               i = base + nr;
-               if (NULL != video_device[i]) {
-                       mutex_unlock(&videodev_lock);
-                       return -ENFILE;
-               }
-       } else {
-               /* use first free */
-               for (i = base; i < end; i++)
-                       if (NULL == video_device[i])
-                               break;
-               if (i == end) {
-                       mutex_unlock(&videodev_lock);
-                       return -ENFILE;
-               }
+       nr = find_next_zero_bit(video_nums[type], minor_cnt, nr == -1 ? 0 : nr);
+       if (nr == minor_cnt)
+               nr = find_first_zero_bit(video_nums[type], minor_cnt);
+       if (nr == minor_cnt) {
+               printk(KERN_ERR "could not get a free kernel number\n");
+               mutex_unlock(&videodev_lock);
+               return -ENFILE;
        }
-       video_device[i] = vfd;
-       vfd->vfl_type = type;
-       vfd->minor = i;
+#ifdef CONFIG_VIDEO_FIXED_MINOR_RANGES
+       /* 1-on-1 mapping of kernel number to minor number */
+       i = nr;
+#else
+       /* The kernel number and minor numbers are independent */
+       for (i = 0; i < VIDEO_NUM_DEVICES; i++)
+               if (video_device[i] == NULL)
+                       break;
+       if (i == VIDEO_NUM_DEVICES) {
+               mutex_unlock(&videodev_lock);
+               printk(KERN_ERR "could not get a free minor\n");
+               return -ENFILE;
+       }
+#endif
+       vfd->minor = i + minor_offset;
+       vfd->num = nr;
+       set_bit(nr, video_nums[type]);
+       BUG_ON(video_device[vfd->minor]);
+       video_device[vfd->minor] = vfd;
 
        ret = get_index(vfd, index);
        vfd->index = ret;
@@ -320,35 +325,41 @@ int video_register_device_index(struct video_device *vfd, int type, int nr,
                goto fail_minor;
        }
 
-       mutex_init(&vfd->lock);
-
+       ret = cdev_add(&vfd->cdev, MKDEV(VIDEO_MAJOR, vfd->minor), 1);
+       if (ret < 0) {
+               printk(KERN_ERR "%s: cdev_add failed\n", __func__);
+               goto fail_minor;
+       }
        /* sysfs class */
-       memset(&vfd->dev, 0x00, sizeof(vfd->dev));
+       memset(&vfd->dev, 0, sizeof(vfd->dev));
+       /* The memset above cleared the device's drvdata, so
+          put back the copy we made earlier. */
+       video_set_drvdata(vfd, priv);
        vfd->dev.class = &video_class;
        vfd->dev.devt = MKDEV(VIDEO_MAJOR, vfd->minor);
        if (vfd->parent)
                vfd->dev.parent = vfd->parent;
-       sprintf(vfd->dev.bus_id, "%s%d", name_base, i - base);
+       sprintf(vfd->dev.bus_id, "%s%d", name_base, nr);
        ret = device_register(&vfd->dev);
        if (ret < 0) {
                printk(KERN_ERR "%s: device_register failed\n", __func__);
-               goto fail_minor;
+               goto del_cdev;
        }
-
-#if 1
-       /* needed until all drivers are fixed */
-       if (!vfd->release)
-               printk(KERN_WARNING "videodev: \"%s\" has no release callback. "
-                      "Please fix your driver for proper sysfs support, see "
-                      "http://lwn.net/Articles/36850/\n", vfd->name);
-#endif
+       /* Remember the cdev's release function */
+       vfd->cdev_release = vfd->cdev.kobj.ktype->release;
+       /* Install our own */
+       vfd->cdev.kobj.ktype = &v4l2_ktype_cdev_default;
        return 0;
 
+del_cdev:
+       cdev_del(&vfd->cdev);
+
 fail_minor:
        mutex_lock(&videodev_lock);
        video_device[vfd->minor] = NULL;
-       vfd->minor = -1;
+       clear_bit(vfd->num, video_nums[type]);
        mutex_unlock(&videodev_lock);
+       vfd->minor = -1;
        return ret;
 }
 EXPORT_SYMBOL(video_register_device_index);
@@ -363,42 +374,29 @@ EXPORT_SYMBOL(video_register_device_index);
 
 void video_unregister_device(struct video_device *vfd)
 {
-       mutex_lock(&videodev_lock);
-       if (video_device[vfd->minor] != vfd)
-               panic("videodev: bad unregister");
-
-       video_device[vfd->minor] = NULL;
        device_unregister(&vfd->dev);
-       mutex_unlock(&videodev_lock);
 }
 EXPORT_SYMBOL(video_unregister_device);
 
-/*
- * Video fs operations
- */
-static const struct file_operations video_fops = {
-       .owner          = THIS_MODULE,
-       .llseek         = no_llseek,
-       .open           = video_open,
-};
-
 /*
  *     Initialise video for linux
  */
-
 static int __init videodev_init(void)
 {
+       dev_t dev = MKDEV(VIDEO_MAJOR, 0);
        int ret;
 
        printk(KERN_INFO "Linux video capture interface: v2.00\n");
-       if (register_chrdev(VIDEO_MAJOR, VIDEO_NAME, &video_fops)) {
-               printk(KERN_WARNING "video_dev: unable to get major %d\n", VIDEO_MAJOR);
-               return -EIO;
+       ret = register_chrdev_region(dev, VIDEO_NUM_DEVICES, VIDEO_NAME);
+       if (ret < 0) {
+               printk(KERN_WARNING "videodev: unable to get major %d\n",
+                               VIDEO_MAJOR);
+               return ret;
        }
 
        ret = class_register(&video_class);
        if (ret < 0) {
-               unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
+               unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
                printk(KERN_WARNING "video_dev: class_register failed\n");
                return -EIO;
        }
@@ -408,8 +406,10 @@ static int __init videodev_init(void)
 
 static void __exit videodev_exit(void)
 {
+       dev_t dev = MKDEV(VIDEO_MAJOR, 0);
+
        class_unregister(&video_class);
-       unregister_chrdev(VIDEO_MAJOR, VIDEO_NAME);
+       unregister_chrdev_region(dev, VIDEO_NUM_DEVICES);
 }
 
 module_init(videodev_init)
index 140ef92c19c1e5c1333f1e30881a8150c0edbfed..155c9d77a463531d43989b75e2505da632f901b2 100644 (file)
@@ -746,18 +746,6 @@ static int __video_do_ioctl(struct inode *inode, struct file *file,
                                ret = ops->vidioc_enum_fmt_vid_overlay(file,
                                        fh, f);
                        break;
-#if 1
-               /* V4L2_BUF_TYPE_VBI_CAPTURE should not support VIDIOC_ENUM_FMT
-                * according to the spec. The bttv and saa7134 drivers support
-                * it though, so just warn that this is deprecated and will be
-                * removed in the near future. */
-               case V4L2_BUF_TYPE_VBI_CAPTURE:
-                       if (ops->vidioc_enum_fmt_vbi_cap) {
-                               printk(KERN_WARNING "vidioc_enum_fmt_vbi_cap will be removed in 2.6.28!\n");
-                               ret = ops->vidioc_enum_fmt_vbi_cap(file, fh, f);
-                       }
-                       break;
-#endif
                case V4L2_BUF_TYPE_VIDEO_OUTPUT:
                        if (ops->vidioc_enum_fmt_vid_out)
                                ret = ops->vidioc_enum_fmt_vid_out(file, fh, f);
diff --git a/drivers/media/video/videocodec.c b/drivers/media/video/videocodec.c
deleted file mode 100644 (file)
index cf24956..0000000
+++ /dev/null
@@ -1,408 +0,0 @@
-/*
- * VIDEO MOTION CODECs internal API for video devices
- *
- * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
- * bound to a master device.
- *
- * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: videocodec.c,v 1.1.2.8 2003/03/29 07:16:04 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#define VIDEOCODEC_VERSION "v0.2"
-
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/types.h>
-#include <linux/slab.h>
-
-// kernel config is here (procfs flag)
-
-#ifdef CONFIG_PROC_FS
-#include <linux/proc_fs.h>
-#include <linux/seq_file.h>
-#include <asm/uaccess.h>
-#endif
-
-#include "videocodec.h"
-
-static int debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0-4)");
-
-#define dprintk(num, format, args...) \
-       do { \
-               if (debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
-struct attached_list {
-       struct videocodec *codec;
-       struct attached_list *next;
-};
-
-struct codec_list {
-       const struct videocodec *codec;
-       int attached;
-       struct attached_list *list;
-       struct codec_list *next;
-};
-
-static struct codec_list *codeclist_top = NULL;
-
-/* ================================================= */
-/* function prototypes of the master/slave interface */
-/* ================================================= */
-
-struct videocodec *
-videocodec_attach (struct videocodec_master *master)
-{
-       struct codec_list *h = codeclist_top;
-       struct attached_list *a, *ptr;
-       struct videocodec *codec;
-       int res;
-
-       if (!master) {
-               dprintk(1, KERN_ERR "videocodec_attach: no data\n");
-               return NULL;
-       }
-
-       dprintk(2,
-               "videocodec_attach: '%s', flags %lx, magic %lx\n",
-               master->name, master->flags, master->magic);
-
-       if (!h) {
-               dprintk(1,
-                       KERN_ERR
-                       "videocodec_attach: no device available\n");
-               return NULL;
-       }
-
-       while (h) {
-               // attach only if the slave has at least the flags
-               // expected by the master
-               if ((master->flags & h->codec->flags) == master->flags) {
-                       dprintk(4, "videocodec_attach: try '%s'\n",
-                               h->codec->name);
-
-                       if (!try_module_get(h->codec->owner))
-                               return NULL;
-
-                       codec =
-                           kmalloc(sizeof(struct videocodec), GFP_KERNEL);
-                       if (!codec) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "videocodec_attach: no mem\n");
-                               goto out_module_put;
-                       }
-                       memcpy(codec, h->codec, sizeof(struct videocodec));
-
-                       snprintf(codec->name, sizeof(codec->name),
-                                "%s[%d]", codec->name, h->attached);
-                       codec->master_data = master;
-                       res = codec->setup(codec);
-                       if (res == 0) {
-                               dprintk(3, "videocodec_attach '%s'\n",
-                                       codec->name);
-                               ptr = kzalloc(sizeof(struct attached_list), GFP_KERNEL);
-                               if (!ptr) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "videocodec_attach: no memory\n");
-                                       goto out_kfree;
-                               }
-                               ptr->codec = codec;
-
-                               a = h->list;
-                               if (!a) {
-                                       h->list = ptr;
-                                       dprintk(4,
-                                               "videocodec: first element\n");
-                               } else {
-                                       while (a->next)
-                                               a = a->next;    // find end
-                                       a->next = ptr;
-                                       dprintk(4,
-                                               "videocodec: in after '%s'\n",
-                                               h->codec->name);
-                               }
-
-                               h->attached += 1;
-                               return codec;
-                       } else {
-                               kfree(codec);
-                       }
-               }
-               h = h->next;
-       }
-
-       dprintk(1, KERN_ERR "videocodec_attach: no codec found!\n");
-       return NULL;
-
- out_module_put:
-       module_put(h->codec->owner);
- out_kfree:
-       kfree(codec);
-       return NULL;
-}
-
-int
-videocodec_detach (struct videocodec *codec)
-{
-       struct codec_list *h = codeclist_top;
-       struct attached_list *a, *prev;
-       int res;
-
-       if (!codec) {
-               dprintk(1, KERN_ERR "videocodec_detach: no data\n");
-               return -EINVAL;
-       }
-
-       dprintk(2,
-               "videocodec_detach: '%s', type: %x, flags %lx, magic %lx\n",
-               codec->name, codec->type, codec->flags, codec->magic);
-
-       if (!h) {
-               dprintk(1,
-                       KERN_ERR "videocodec_detach: no device left...\n");
-               return -ENXIO;
-       }
-
-       while (h) {
-               a = h->list;
-               prev = NULL;
-               while (a) {
-                       if (codec == a->codec) {
-                               res = a->codec->unset(a->codec);
-                               if (res >= 0) {
-                                       dprintk(3,
-                                               "videocodec_detach: '%s'\n",
-                                               a->codec->name);
-                                       a->codec->master_data = NULL;
-                               } else {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "videocodec_detach: '%s'\n",
-                                               a->codec->name);
-                                       a->codec->master_data = NULL;
-                               }
-                               if (prev == NULL) {
-                                       h->list = a->next;
-                                       dprintk(4,
-                                               "videocodec: delete first\n");
-                               } else {
-                                       prev->next = a->next;
-                                       dprintk(4,
-                                               "videocodec: delete middle\n");
-                               }
-                               module_put(a->codec->owner);
-                               kfree(a->codec);
-                               kfree(a);
-                               h->attached -= 1;
-                               return 0;
-                       }
-                       prev = a;
-                       a = a->next;
-               }
-               h = h->next;
-       }
-
-       dprintk(1, KERN_ERR "videocodec_detach: given codec not found!\n");
-       return -EINVAL;
-}
-
-int
-videocodec_register (const struct videocodec *codec)
-{
-       struct codec_list *ptr, *h = codeclist_top;
-
-       if (!codec) {
-               dprintk(1, KERN_ERR "videocodec_register: no data!\n");
-               return -EINVAL;
-       }
-
-       dprintk(2,
-               "videocodec: register '%s', type: %x, flags %lx, magic %lx\n",
-               codec->name, codec->type, codec->flags, codec->magic);
-
-       ptr = kzalloc(sizeof(struct codec_list), GFP_KERNEL);
-       if (!ptr) {
-               dprintk(1, KERN_ERR "videocodec_register: no memory\n");
-               return -ENOMEM;
-       }
-       ptr->codec = codec;
-
-       if (!h) {
-               codeclist_top = ptr;
-               dprintk(4, "videocodec: hooked in as first element\n");
-       } else {
-               while (h->next)
-                       h = h->next;    // find the end
-               h->next = ptr;
-               dprintk(4, "videocodec: hooked in after '%s'\n",
-                       h->codec->name);
-       }
-
-       return 0;
-}
-
-int
-videocodec_unregister (const struct videocodec *codec)
-{
-       struct codec_list *prev = NULL, *h = codeclist_top;
-
-       if (!codec) {
-               dprintk(1, KERN_ERR "videocodec_unregister: no data!\n");
-               return -EINVAL;
-       }
-
-       dprintk(2,
-               "videocodec: unregister '%s', type: %x, flags %lx, magic %lx\n",
-               codec->name, codec->type, codec->flags, codec->magic);
-
-       if (!h) {
-               dprintk(1,
-                       KERN_ERR
-                       "videocodec_unregister: no device left...\n");
-               return -ENXIO;
-       }
-
-       while (h) {
-               if (codec == h->codec) {
-                       if (h->attached) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "videocodec: '%s' is used\n",
-                                       h->codec->name);
-                               return -EBUSY;
-                       }
-                       dprintk(3, "videocodec: unregister '%s' is ok.\n",
-                               h->codec->name);
-                       if (prev == NULL) {
-                               codeclist_top = h->next;
-                               dprintk(4,
-                                       "videocodec: delete first element\n");
-                       } else {
-                               prev->next = h->next;
-                               dprintk(4,
-                                       "videocodec: delete middle element\n");
-                       }
-                       kfree(h);
-                       return 0;
-               }
-               prev = h;
-               h = h->next;
-       }
-
-       dprintk(1,
-               KERN_ERR
-               "videocodec_unregister: given codec not found!\n");
-       return -EINVAL;
-}
-
-#ifdef CONFIG_PROC_FS
-static int proc_videocodecs_show(struct seq_file *m, void *v)
-{
-       struct codec_list *h = codeclist_top;
-       struct attached_list *a;
-
-       seq_printf(m, "<S>lave or attached <M>aster name  type flags    magic    ");
-       seq_printf(m, "(connected as)\n");
-
-       h = codeclist_top;
-       while (h) {
-               seq_printf(m, "S %32s %04x %08lx %08lx (TEMPLATE)\n",
-                             h->codec->name, h->codec->type,
-                             h->codec->flags, h->codec->magic);
-               a = h->list;
-               while (a) {
-                       seq_printf(m, "M %32s %04x %08lx %08lx (%s)\n",
-                                     a->codec->master_data->name,
-                                     a->codec->master_data->type,
-                                     a->codec->master_data->flags,
-                                     a->codec->master_data->magic,
-                                     a->codec->name);
-                       a = a->next;
-               }
-               h = h->next;
-       }
-
-       return 0;
-}
-
-static int proc_videocodecs_open(struct inode *inode, struct file *file)
-{
-       return single_open(file, proc_videocodecs_show, NULL);
-}
-
-static const struct file_operations videocodecs_proc_fops = {
-       .owner          = THIS_MODULE,
-       .open           = proc_videocodecs_open,
-       .read           = seq_read,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-};
-#endif
-
-/* ===================== */
-/* hook in driver module */
-/* ===================== */
-static int __init
-videocodec_init (void)
-{
-#ifdef CONFIG_PROC_FS
-       static struct proc_dir_entry *videocodec_proc_entry;
-#endif
-
-       printk(KERN_INFO "Linux video codec intermediate layer: %s\n",
-              VIDEOCODEC_VERSION);
-
-#ifdef CONFIG_PROC_FS
-       videocodec_proc_entry = proc_create("videocodecs", 0, NULL, &videocodecs_proc_fops);
-       if (!videocodec_proc_entry) {
-               dprintk(1, KERN_ERR "videocodec: can't init procfs.\n");
-       }
-#endif
-       return 0;
-}
-
-static void __exit
-videocodec_exit (void)
-{
-#ifdef CONFIG_PROC_FS
-       remove_proc_entry("videocodecs", NULL);
-#endif
-}
-
-EXPORT_SYMBOL(videocodec_attach);
-EXPORT_SYMBOL(videocodec_detach);
-EXPORT_SYMBOL(videocodec_register);
-EXPORT_SYMBOL(videocodec_unregister);
-
-module_init(videocodec_init);
-module_exit(videocodec_exit);
-
-MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
-MODULE_DESCRIPTION("Intermediate API module for video codecs "
-                  VIDEOCODEC_VERSION);
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/videocodec.h b/drivers/media/video/videocodec.h
deleted file mode 100644 (file)
index 97a3bbe..0000000
+++ /dev/null
@@ -1,358 +0,0 @@
-/*
- * VIDEO MOTION CODECs internal API for video devices
- *
- * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
- * bound to a master device.
- *
- * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: videocodec.h,v 1.1.2.4 2003/01/14 21:15:03 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-/* =================== */
-/* general description */
-/* =================== */
-
-/* Should ease the (re-)usage of drivers supporting cards with (different)
-   video codecs. The codecs register to this module their functionality,
-   and the processors (masters) can attach to them if they fit.
-
-   The codecs are typically have a "strong" binding to their master - so I
-   don't think it makes sense to have a full blown interfacing as with e.g.
-   i2c. If you have an other opinion, let's discuss & implement it :-)))
-
-   Usage:
-
-   The slave has just to setup the videocodec structure and use two functions:
-   videocodec_register(codecdata);
-   videocodec_unregister(codecdata);
-   The best is just calling them at module (de-)initialisation.
-
-   The master sets up the structure videocodec_master and calls:
-   codecdata=videocodec_attach(master_codecdata);
-   videocodec_detach(codecdata);
-
-   The slave is called during attach/detach via functions setup previously
-   during register. At that time, the master_data pointer is set up
-   and the slave can access any io registers of the master device (in the case
-   the slave is bound to it). Otherwise it doesn't need this functions and
-   therfor they may not be initialized.
-
-   The other fuctions are just for convenience, as they are for sure used by
-   most/all of the codecs. The last ones may be ommited, too.
-
-   See the structure declaration below for more information and which data has
-   to be set up for the master and the slave.
-
-   ----------------------------------------------------------------------------
-   The master should have "knowledge" of the slave and vice versa.  So the data
-   structures sent to/from slave via set_data/get_data set_image/get_image are
-   device dependent and vary between MJPEG/MPEG/WAVELET/... devices. (!!!!)
-   ----------------------------------------------------------------------------
-*/
-\f
-
-/* ========================================== */
-/* description of the videocodec_io structure */
-/* ========================================== */
-
-/*
-   ==== master setup ====
-   name -> name of the device structure for reference and debugging
-   master_data ->  data ref. for the master (e.g. the zr36055,57,67)
-   readreg -> ref. to read-fn from register (setup by master, used by slave)
-   writereg -> ref. to write-fn to register (setup by master, used by slave)
-              this two functions do the lowlevel I/O job
-
-   ==== slave functionality setup ====
-   slave_data -> data ref. for the slave (e.g. the zr36050,60)
-   check -> fn-ref. checks availability of an device, returns -EIO on failure or
-           the type on success
-           this makes espcecially sense if a driver module supports more than
-           one codec which may be quite similar to access, nevertheless it
-           is good for a first functionality check
-
-   -- main functions you always need for compression/decompression --
-
-   set_mode -> this fn-ref. resets the entire codec, and sets up the mode
-              with the last defined norm/size (or device default if not
-              available) - it returns 0 if the mode is possible
-   set_size -> this fn-ref. sets the norm and image size for
-              compression/decompression (returns 0 on success)
-              the norm param is defined in videodev.h (VIDEO_MODE_*)
-
-   additional setup may be available, too - but the codec should work with
-   some default values even without this
-
-   set_data -> sets device-specific data (tables, quality etc.)
-   get_data -> query device-specific data (tables, quality etc.)
-
-   if the device delivers interrupts, they may be setup/handled here
-   setup_interrupt -> codec irq setup (not needed for 36050/60)
-   handle_interrupt -> codec irq handling (not needed for 36050/60)
-
-   if the device delivers pictures, they may be handled here
-   put_image -> puts image data to the codec (not needed for 36050/60)
-   get_image -> gets image data from the codec (not needed for 36050/60)
-               the calls include frame numbers and flags (even/odd/...)
-               if needed and a flag which allows blocking until its ready
-*/
-\f
-/* ============== */
-/* user interface */
-/* ============== */
-
-/*
-   Currently there is only a information display planned, as the layer
-   is not visible for the user space at all.
-
-   Information is available via procfs. The current entry is "/proc/videocodecs"
-   but it makes sense to "hide" it in the /proc/video tree of v4l(2) --TODO--.
-
-A example for such an output is:
-
-<S>lave or attached <M>aster name  type flags    magic    (connected as)
-S                          zr36050 0002 0000d001 00000000 (TEMPLATE)
-M                       zr36055[0] 0001 0000c001 00000000 (zr36050[0])
-M                       zr36055[1] 0001 0000c001 00000000 (zr36050[1])
-
-*/
-\f
-
-/* =============================================== */
-/* special defines for the videocodec_io structure */
-/* =============================================== */
-
-#ifndef __LINUX_VIDEOCODEC_H
-#define __LINUX_VIDEOCODEC_H
-
-#include <linux/videodev.h>
-
-//should be in videodev.h ??? (VID_DO_....)
-#define CODEC_DO_COMPRESSION 0
-#define CODEC_DO_EXPANSION   1
-
-/* this are the current codec flags I think they are needed */
-/*  -> type value in structure */
-#define CODEC_FLAG_JPEG      0x00000001L       // JPEG codec
-#define CODEC_FLAG_MPEG      0x00000002L       // MPEG1/2/4 codec
-#define CODEC_FLAG_DIVX      0x00000004L       // DIVX codec
-#define CODEC_FLAG_WAVELET   0x00000008L       // WAVELET codec
-                                         // room for other types
-
-#define CODEC_FLAG_MAGIC     0x00000800L       // magic key must match
-#define CODEC_FLAG_HARDWARE  0x00001000L       // is a hardware codec
-#define CODEC_FLAG_VFE       0x00002000L       // has direct video frontend
-#define CODEC_FLAG_ENCODER   0x00004000L       // compression capability
-#define CODEC_FLAG_DECODER   0x00008000L       // decompression capability
-#define CODEC_FLAG_NEEDIRQ   0x00010000L       // needs irq handling
-#define CODEC_FLAG_RDWRPIC   0x00020000L       // handles picture I/O
-
-/* a list of modes, some are just examples (is there any HW?) */
-#define CODEC_MODE_BJPG      0x0001    // Baseline JPEG
-#define CODEC_MODE_LJPG      0x0002    // Lossless JPEG
-#define CODEC_MODE_MPEG1     0x0003    // MPEG 1
-#define CODEC_MODE_MPEG2     0x0004    // MPEG 2
-#define CODEC_MODE_MPEG4     0x0005    // MPEG 4
-#define CODEC_MODE_MSDIVX    0x0006    // MS DivX
-#define CODEC_MODE_ODIVX     0x0007    // Open DivX
-#define CODEC_MODE_WAVELET   0x0008    // Wavelet
-
-/* this are the current codec types I want to implement */
-/*  -> type value in structure */
-#define CODEC_TYPE_NONE    0
-#define CODEC_TYPE_L64702  1
-#define CODEC_TYPE_ZR36050 2
-#define CODEC_TYPE_ZR36016 3
-#define CODEC_TYPE_ZR36060 4
-
-/* the type of data may be enhanced by future implementations (data-fn.'s) */
-/*  -> used in command                                                     */
-#define CODEC_G_STATUS         0x0000  /* codec status (query only) */
-#define CODEC_S_CODEC_MODE     0x0001  /* codec mode (baseline JPEG, MPEG1,... */
-#define CODEC_G_CODEC_MODE     0x8001
-#define CODEC_S_VFE            0x0002  /* additional video frontend setup */
-#define CODEC_G_VFE            0x8002
-#define CODEC_S_MMAP           0x0003  /* MMAP setup (if available) */
-
-#define CODEC_S_JPEG_TDS_BYTE  0x0010  /* target data size in bytes */
-#define CODEC_G_JPEG_TDS_BYTE  0x8010
-#define CODEC_S_JPEG_SCALE     0x0011  /* scaling factor for quant. tables */
-#define CODEC_G_JPEG_SCALE     0x8011
-#define CODEC_S_JPEG_HDT_DATA  0x0018  /* huffman-tables */
-#define CODEC_G_JPEG_HDT_DATA  0x8018
-#define CODEC_S_JPEG_QDT_DATA  0x0019  /* quantizing-tables */
-#define CODEC_G_JPEG_QDT_DATA  0x8019
-#define CODEC_S_JPEG_APP_DATA  0x001A  /* APP marker */
-#define CODEC_G_JPEG_APP_DATA  0x801A
-#define CODEC_S_JPEG_COM_DATA  0x001B  /* COM marker */
-#define CODEC_G_JPEG_COM_DATA  0x801B
-
-#define CODEC_S_PRIVATE        0x1000  /* "private" commands start here */
-#define CODEC_G_PRIVATE        0x9000
-
-#define CODEC_G_FLAG           0x8000  /* this is how 'get' is detected */
-
-/* types of transfer, directly user space or a kernel buffer (image-fn.'s) */
-/*  -> used in get_image, put_image                                        */
-#define CODEC_TRANSFER_KERNEL 0        /* use "memcopy" */
-#define CODEC_TRANSFER_USER   1        /* use "to/from_user" */
-\f
-
-/* ========================= */
-/* the structures itself ... */
-/* ========================= */
-
-struct vfe_polarity {
-       unsigned int vsync_pol:1;
-       unsigned int hsync_pol:1;
-       unsigned int field_pol:1;
-       unsigned int blank_pol:1;
-       unsigned int subimg_pol:1;
-       unsigned int poe_pol:1;
-       unsigned int pvalid_pol:1;
-       unsigned int vclk_pol:1;
-};
-
-struct vfe_settings {
-       __u32 x, y;             /* Offsets into image */
-       __u32 width, height;    /* Area to capture */
-       __u16 decimation;       /* Decimation divider */
-       __u16 flags;            /* Flags for capture */
-/* flags are the same as in struct video_capture - see videodev.h:
-#define VIDEO_CAPTURE_ODD              0
-#define VIDEO_CAPTURE_EVEN             1
-*/
-       __u16 quality;          /* quality of the video */
-};
-
-struct tvnorm {
-       u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
-};
-
-struct jpeg_com_marker {
-       int len; /* number of usable bytes in data */
-       char data[60];
-};
-
-struct jpeg_app_marker {
-       int appn; /* number app segment */
-       int len; /* number of usable bytes in data */
-       char data[60];
-};
-
-struct videocodec {
-       struct module *owner;
-       /* -- filled in by slave device during register -- */
-       char name[32];
-       unsigned long magic;    /* may be used for client<->master attaching */
-       unsigned long flags;    /* functionality flags */
-       unsigned int type;      /* codec type */
-
-       /* -- these is filled in later during master device attach -- */
-
-       struct videocodec_master *master_data;
-
-       /* -- these are filled in by the slave device during register -- */
-
-       void *data;             /* private slave data */
-
-       /* attach/detach client functions (indirect call) */
-       int (*setup) (struct videocodec * codec);
-       int (*unset) (struct videocodec * codec);
-
-       /* main functions, every client needs them for sure! */
-       // set compression or decompression (or freeze, stop, standby, etc)
-       int (*set_mode) (struct videocodec * codec,
-                        int mode);
-       // setup picture size and norm (for the codec's video frontend)
-       int (*set_video) (struct videocodec * codec,
-                         struct tvnorm * norm,
-                         struct vfe_settings * cap,
-                         struct vfe_polarity * pol);
-       // other control commands, also mmap setup etc.
-       int (*control) (struct videocodec * codec,
-                       int type,
-                       int size,
-                       void *data);
-
-       /* additional setup/query/processing (may be NULL pointer) */
-       // interrupt setup / handling (for irq's delivered by master)
-       int (*setup_interrupt) (struct videocodec * codec,
-                               long mode);
-       int (*handle_interrupt) (struct videocodec * codec,
-                                int source,
-                                long flag);
-       // picture interface (if any)
-       long (*put_image) (struct videocodec * codec,
-                          int tr_type,
-                          int block,
-                          long *fr_num,
-                          long *flag,
-                          long size,
-                          void *buf);
-       long (*get_image) (struct videocodec * codec,
-                          int tr_type,
-                          int block,
-                          long *fr_num,
-                          long *flag,
-                          long size,
-                          void *buf);
-};
-
-struct videocodec_master {
-       /* -- filled in by master device for registration -- */
-       char name[32];
-       unsigned long magic;    /* may be used for client<->master attaching */
-       unsigned long flags;    /* functionality flags */
-       unsigned int type;      /* master type */
-
-       void *data;             /* private master data */
-
-        __u32(*readreg) (struct videocodec * codec,
-                         __u16 reg);
-       void (*writereg) (struct videocodec * codec,
-                         __u16 reg,
-                         __u32 value);
-};
-\f
-
-/* ================================================= */
-/* function prototypes of the master/slave interface */
-/* ================================================= */
-
-/* attach and detach commands for the master */
-// * master structure needs to be kmalloc'ed before calling attach
-//   and free'd after calling detach
-// * returns pointer on success, NULL on failure
-extern struct videocodec *videocodec_attach(struct videocodec_master *);
-// * 0 on success, <0 (errno) on failure
-extern int videocodec_detach(struct videocodec *);
-
-/* register and unregister commands for the slaves */
-// * 0 on success, <0 (errno) on failure
-extern int videocodec_register(const struct videocodec *);
-// * 0 on success, <0 (errno) on failure
-extern int videocodec_unregister(const struct videocodec *);
-
-/* the other calls are directly done via the videocodec structure! */
-
-#endif                         /*ifndef __LINUX_VIDEOCODEC_H */
index 1edda456fc646c9accaba0b037c46ed44a6a97e2..8ec57df1904f1e83d4940f395060459ecde38733 100644 (file)
@@ -39,7 +39,6 @@
 #include <linux/i2c-algo-sgi.h>
 
 #include <linux/videodev2.h>
-#include <media/v4l2-ioctl.h>
 #include <media/v4l2-common.h>
 #include <media/v4l2-ioctl.h>
 #include <linux/video_decoder.h>
@@ -810,7 +809,7 @@ static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
        dprintk("vino_free_buffer_with_count(): count = %d\n", count);
 
        for (i = 0; i < count; i++) {
-               ClearPageReserved(virt_to_page(fb->desc_table.virtual[i]));
+               ClearPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
                dma_unmap_single(NULL,
                                 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
                                 PAGE_SIZE, DMA_FROM_DEVICE);
@@ -888,7 +887,7 @@ static int vino_allocate_buffer(struct vino_framebuffer *fb,
                                dma_data_addr + VINO_PAGE_SIZE * j;
                }
 
-               SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
+               SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
        }
 
        /* page_count needs to be set anyway, because the descriptor table has
@@ -975,7 +974,7 @@ static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
                                dma_data_addr + VINO_PAGE_SIZE * j;
                }
 
-               SetPageReserved(virt_to_page(fb->desc_table.virtual[i]));
+               SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
        }
 
        /* page_count needs to be set anyway, because the descriptor table has
@@ -4025,8 +4024,7 @@ out:
 
 static int vino_open(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
        int ret = 0;
        dprintk("open(): channel = %c\n",
               (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
@@ -4057,8 +4055,7 @@ static int vino_open(struct inode *inode, struct file *file)
 
 static int vino_close(struct inode *inode, struct file *file)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
        dprintk("close():\n");
 
        mutex_lock(&vcs->mutex);
@@ -4101,8 +4098,7 @@ static struct vm_operations_struct vino_vm_ops = {
 
 static int vino_mmap(struct file *file, struct vm_area_struct *vma)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
 
        unsigned long start = vma->vm_start;
        unsigned long size = vma->vm_end - vma->vm_start;
@@ -4207,8 +4203,7 @@ out:
 
 static unsigned int vino_poll(struct file *file, poll_table *pt)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
        unsigned int outgoing;
        unsigned int ret = 0;
 
@@ -4248,8 +4243,7 @@ error:
 static int vino_do_ioctl(struct inode *inode, struct file *file,
                      unsigned int cmd, void *arg)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
 
 #ifdef VINO_DEBUG
        switch (_IOC_TYPE(cmd)) {
@@ -4356,8 +4350,7 @@ static int vino_do_ioctl(struct inode *inode, struct file *file,
 static int vino_ioctl(struct inode *inode, struct file *file,
                      unsigned int cmd, unsigned long arg)
 {
-       struct video_device *dev = video_devdata(file);
-       struct vino_channel_settings *vcs = video_get_drvdata(dev);
+       struct vino_channel_settings *vcs = video_drvdata(file);
        int ret;
 
        if (mutex_lock_interruptible(&vcs->mutex))
index 8ba8daafd7ea2a3a2dff574b535a2908128b8d8b..65c8af18e767a7e889ac239517b23823e71c9993 100644 (file)
@@ -898,9 +898,11 @@ static int vivi_open(struct inode *inode, struct file *file)
 
        printk(KERN_DEBUG "vivi: open called (minor=%d)\n", minor);
 
+       lock_kernel();
        list_for_each_entry(dev, &vivi_devlist, vivi_devlist)
                if (dev->vfd->minor == minor)
                        goto found;
+       unlock_kernel();
        return -ENODEV;
 
 found:
@@ -925,8 +927,10 @@ found:
        }
 unlock:
        mutex_unlock(&dev->mutex);
-       if (retval)
+       if (retval) {
+               unlock_kernel();
                return retval;
+       }
 
        file->private_data = fh;
        fh->dev      = dev;
@@ -955,6 +959,7 @@ unlock:
                        sizeof(struct vivi_buffer), fh);
 
        vivi_start_thread(fh);
+       unlock_kernel();
 
        return 0;
 }
index 35293029da02423e1c31cb1aedb136f78c6b090f..45be9ec8edc4a10cba99ad26f5b7b446852506b2 100644 (file)
@@ -24,8 +24,6 @@
 #include <linux/types.h>
 #include <linux/slab.h>
 
-#include <linux/byteorder/swab.h>
-
 #include <asm/io.h>
 #include <asm/uaccess.h>
 
index 2ff00bc5ad64cf2aa79a2c915296ea03220a4572..b2dbe48a92bbd72360b1fec3dea0e59806dc671f 100644 (file)
@@ -113,6 +113,7 @@ struct w9966_dev {
        signed char contrast;
        signed char color;
        signed char hue;
+       unsigned long in_use;
 };
 
 /*
@@ -184,10 +185,25 @@ static int w9966_v4l_ioctl(struct inode *inode, struct file *file,
 static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
                              size_t count, loff_t *ppos);
 
+static int w9966_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct w9966_dev *cam = video_drvdata(file);
+
+       return test_and_set_bit(0, &cam->in_use) ? -EBUSY : 0;
+}
+
+static int w9966_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct w9966_dev *cam = video_drvdata(file);
+
+       clear_bit(0, &cam->in_use);
+       return 0;
+}
+
 static const struct file_operations w9966_fops = {
        .owner          = THIS_MODULE,
-       .open           = video_exclusive_open,
-       .release        = video_exclusive_release,
+       .open           = w9966_exclusive_open,
+       .release        = w9966_exclusive_release,
        .ioctl          = w9966_v4l_ioctl,
 #ifdef CONFIG_COMPAT
        .compat_ioctl   = v4l_compat_ioctl32,
@@ -198,6 +214,7 @@ static const struct file_operations w9966_fops = {
 static struct video_device w9966_template = {
        .name           = W9966_DRIVERNAME,
        .fops           = &w9966_fops,
+       .release        = video_device_release_empty,
 };
 
 /*
@@ -332,7 +349,7 @@ static int w9966_init(struct w9966_dev* cam, struct parport* port)
 
 // Fill in the video_device struct and register us to v4l
        memcpy(&cam->vdev, &w9966_template, sizeof(struct video_device));
-       cam->vdev.priv = cam;
+       video_set_drvdata(&cam->vdev, cam);
 
        if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
                return -1;
@@ -713,8 +730,7 @@ static int w9966_wReg_i2c(struct w9966_dev* cam, int reg, int data)
 static int w9966_v4l_do_ioctl(struct inode *inode, struct file *file,
                              unsigned int cmd, void *arg)
 {
-       struct video_device *vdev = video_devdata(file);
-       struct w9966_dev *cam = vdev->priv;
+       struct w9966_dev *cam = video_drvdata(file);
 
        switch(cmd)
        {
@@ -872,8 +888,7 @@ static int w9966_v4l_ioctl(struct inode *inode, struct file *file,
 static ssize_t w9966_v4l_read(struct file *file, char  __user *buf,
                              size_t count, loff_t *ppos)
 {
-       struct video_device *vdev = video_devdata(file);
-       struct w9966_dev *cam = vdev->priv;
+       struct w9966_dev *cam = video_drvdata(file);
        unsigned char addr = 0xa0;      // ECP, read, CCD-transfer, 00000
        unsigned char __user *dest = (unsigned char __user *)buf;
        unsigned long dleft = count;
index 0c3287734c93f0b77900cb2c9ca6156ee2de592d..6a0902bcba6bee88a250b0511cee48269d9c57bf 100644 (file)
@@ -657,7 +657,7 @@ static int zc0301_open(struct inode* inode, struct file* filp)
        if (!down_read_trylock(&zc0301_dev_lock))
                return -EAGAIN;
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        if (wait_for_completion_interruptible(&cam->probe)) {
                up_read(&zc0301_dev_lock);
@@ -739,7 +739,7 @@ static int zc0301_release(struct inode* inode, struct file* filp)
 
        down_write(&zc0301_dev_lock);
 
-       cam = video_get_drvdata(video_devdata(filp));
+       cam = video_drvdata(filp);
 
        zc0301_stop_transfer(cam);
        zc0301_release_buffers(cam);
@@ -759,7 +759,7 @@ static int zc0301_release(struct inode* inode, struct file* filp)
 static ssize_t
 zc0301_read(struct file* filp, char __user * buf, size_t count, loff_t* f_pos)
 {
-       struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
+       struct zc0301_device *cam = video_drvdata(filp);
        struct zc0301_frame_t* f, * i;
        unsigned long lock_flags;
        long timeout;
@@ -866,7 +866,7 @@ exit:
 
 static unsigned int zc0301_poll(struct file *filp, poll_table *wait)
 {
-       struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
+       struct zc0301_device *cam = video_drvdata(filp);
        struct zc0301_frame_t* f;
        unsigned long lock_flags;
        unsigned int mask = 0;
@@ -941,7 +941,7 @@ static struct vm_operations_struct zc0301_vm_ops = {
 
 static int zc0301_mmap(struct file* filp, struct vm_area_struct *vma)
 {
-       struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
+       struct zc0301_device *cam = video_drvdata(filp);
        unsigned long size = vma->vm_end - vma->vm_start,
                      start = vma->vm_start;
        void *pos;
@@ -1796,7 +1796,7 @@ zc0301_vidioc_s_parm(struct zc0301_device* cam, void __user * arg)
 static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
                             unsigned int cmd, void __user * arg)
 {
-       struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
+       struct zc0301_device *cam = video_drvdata(filp);
 
        switch (cmd) {
 
@@ -1891,7 +1891,7 @@ static int zc0301_ioctl_v4l2(struct inode* inode, struct file* filp,
 static int zc0301_ioctl(struct inode* inode, struct file* filp,
                        unsigned int cmd, unsigned long arg)
 {
-       struct zc0301_device* cam = video_get_drvdata(video_devdata(filp));
+       struct zc0301_device *cam = video_drvdata(filp);
        int err = 0;
 
        if (mutex_lock_interruptible(&cam->fileop_mutex))
diff --git a/drivers/media/video/zoran.h b/drivers/media/video/zoran.h
deleted file mode 100644 (file)
index 46b7ad4..0000000
+++ /dev/null
@@ -1,510 +0,0 @@
-/*
- * zoran - Iomega Buz driver
- *
- * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
- *
- * based on
- *
- * zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
- *
- * and
- *
- * bttv - Bt848 frame grabber driver
- * Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
- *                        & Marcus Metzler (mocm@thp.uni-koeln.de)
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef _BUZ_H_
-#define _BUZ_H_
-
-struct zoran_requestbuffers {
-       unsigned long count;    /* Number of buffers for MJPEG grabbing */
-       unsigned long size;     /* Size PER BUFFER in bytes */
-};
-
-struct zoran_sync {
-       unsigned long frame;    /* number of buffer that has been free'd */
-       unsigned long length;   /* number of code bytes in buffer (capture only) */
-       unsigned long seq;      /* frame sequence number */
-       struct timeval timestamp;       /* timestamp */
-};
-
-struct zoran_status {
-       int input;              /* Input channel, has to be set prior to BUZIOC_G_STATUS */
-       int signal;             /* Returned: 1 if valid video signal detected */
-       int norm;               /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
-       int color;              /* Returned: 1 if color signal detected */
-};
-
-struct zoran_params {
-
-       /* The following parameters can only be queried */
-
-       int major_version;      /* Major version number of driver */
-       int minor_version;      /* Minor version number of driver */
-
-       /* Main control parameters */
-
-       int input;              /* Input channel: 0 = Composite, 1 = S-VHS */
-       int norm;               /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
-       int decimation;         /* decimation of captured video,
-                                * enlargement of video played back.
-                                * Valid values are 1, 2, 4 or 0.
-                                * 0 is a special value where the user
-                                * has full control over video scaling */
-
-       /* The following parameters only have to be set if decimation==0,
-        * for other values of decimation they provide the data how the image is captured */
-
-       int HorDcm;             /* Horizontal decimation: 1, 2 or 4 */
-       int VerDcm;             /* Vertical decimation: 1 or 2 */
-       int TmpDcm;             /* Temporal decimation: 1 or 2,
-                                * if TmpDcm==2 in capture every second frame is dropped,
-                                * in playback every frame is played twice */
-       int field_per_buff;     /* Number of fields per buffer: 1 or 2 */
-       int img_x;              /* start of image in x direction */
-       int img_y;              /* start of image in y direction */
-       int img_width;          /* image width BEFORE decimation,
-                                * must be a multiple of HorDcm*16 */
-       int img_height;         /* image height BEFORE decimation,
-                                * must be a multiple of VerDcm*8 */
-
-       /* --- End of parameters for decimation==0 only --- */
-
-       /* JPEG control parameters */
-
-       int quality;            /* Measure for quality of compressed images.
-                                * Scales linearly with the size of the compressed images.
-                                * Must be beetween 0 and 100, 100 is a compression
-                                * ratio of 1:4 */
-
-       int odd_even;           /* Which field should come first ??? */
-
-       int APPn;               /* Number of APP segment to be written, must be 0..15 */
-       int APP_len;            /* Length of data in JPEG APPn segment */
-       char APP_data[60];      /* Data in the JPEG APPn segment. */
-
-       int COM_len;            /* Length of data in JPEG COM segment */
-       char COM_data[60];      /* Data in JPEG COM segment */
-
-       unsigned long jpeg_markers;     /* Which markers should go into the JPEG output.
-                                        * Unless you exactly know what you do, leave them untouched.
-                                        * Inluding less markers will make the resulting code
-                                        * smaller, but there will be fewer aplications
-                                        * which can read it.
-                                        * The presence of the APP and COM marker is
-                                        * influenced by APP0_len and COM_len ONLY! */
-#define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
-#define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
-#define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
-#define JPEG_MARKER_COM (1<<6) /* Comment segment */
-#define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
-
-       int VFIFO_FB;           /* Flag for enabling Video Fifo Feedback.
-                                * If this flag is turned on and JPEG decompressing
-                                * is going to the screen, the decompress process
-                                * is stopped every time the Video Fifo is full.
-                                * This enables a smooth decompress to the screen
-                                * but the video output signal will get scrambled */
-
-       /* Misc */
-
-       char reserved[312];     /* Makes 512 bytes for this structure */
-};
-
-/*
-Private IOCTL to set up for displaying MJPEG
-*/
-#define BUZIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct zoran_params)
-#define BUZIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct zoran_params)
-#define BUZIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct zoran_requestbuffers)
-#define BUZIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
-#define BUZIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
-#define BUZIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct zoran_sync)
-#define BUZIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct zoran_status)
-
-
-#ifdef __KERNEL__
-
-#define MAJOR_VERSION 0                /* driver major version */
-#define MINOR_VERSION 9                /* driver minor version */
-#define RELEASE_VERSION 5      /* release version */
-
-#define ZORAN_NAME    "ZORAN"  /* name of the device */
-
-#define ZR_DEVNAME(zr) ((zr)->name)
-
-#define   BUZ_MAX_WIDTH   (zr->timing->Wa)
-#define   BUZ_MAX_HEIGHT  (zr->timing->Ha)
-#define   BUZ_MIN_WIDTH    32  /* never display less than 32 pixels */
-#define   BUZ_MIN_HEIGHT   24  /* never display less than 24 rows */
-
-#define BUZ_NUM_STAT_COM    4
-#define BUZ_MASK_STAT_COM   3
-
-#define BUZ_MAX_FRAME     256  /* Must be a power of 2 */
-#define BUZ_MASK_FRAME    255  /* Must be BUZ_MAX_FRAME-1 */
-
-#define BUZ_MAX_INPUT       16
-
-#if VIDEO_MAX_FRAME <= 32
-#   define   V4L_MAX_FRAME   32
-#elif VIDEO_MAX_FRAME <= 64
-#   define   V4L_MAX_FRAME   64
-#else
-#   error   "Too many video frame buffers to handle"
-#endif
-#define   V4L_MASK_FRAME   (V4L_MAX_FRAME - 1)
-
-#define MAX_KMALLOC_MEM (128*1024)
-
-#include "zr36057.h"
-
-enum card_type {
-       UNKNOWN = -1,
-
-       /* Pinnacle/Miro */
-       DC10_old,               /* DC30 like */
-       DC10_new,               /* DC10plus like */
-       DC10plus,
-       DC30,
-       DC30plus,
-
-       /* Linux Media Labs */
-       LML33,
-       LML33R10,
-
-       /* Iomega */
-       BUZ,
-
-       /* AverMedia */
-       AVS6EYES,
-
-       /* total number of cards */
-       NUM_CARDS
-};
-
-enum zoran_codec_mode {
-       BUZ_MODE_IDLE,          /* nothing going on */
-       BUZ_MODE_MOTION_COMPRESS,       /* grabbing frames */
-       BUZ_MODE_MOTION_DECOMPRESS,     /* playing frames */
-       BUZ_MODE_STILL_COMPRESS,        /* still frame conversion */
-       BUZ_MODE_STILL_DECOMPRESS       /* still frame conversion */
-};
-
-enum zoran_buffer_state {
-       BUZ_STATE_USER,         /* buffer is owned by application */
-       BUZ_STATE_PEND,         /* buffer is queued in pend[] ready to feed to I/O */
-       BUZ_STATE_DMA,          /* buffer is queued in dma[] for I/O */
-       BUZ_STATE_DONE          /* buffer is ready to return to application */
-};
-
-enum zoran_map_mode {
-       ZORAN_MAP_MODE_RAW,
-       ZORAN_MAP_MODE_JPG_REC,
-#define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
-       ZORAN_MAP_MODE_JPG_PLAY,
-};
-
-enum gpio_type {
-       ZR_GPIO_JPEG_SLEEP = 0,
-       ZR_GPIO_JPEG_RESET,
-       ZR_GPIO_JPEG_FRAME,
-       ZR_GPIO_VID_DIR,
-       ZR_GPIO_VID_EN,
-       ZR_GPIO_VID_RESET,
-       ZR_GPIO_CLK_SEL1,
-       ZR_GPIO_CLK_SEL2,
-       ZR_GPIO_MAX,
-};
-
-enum gpcs_type {
-       GPCS_JPEG_RESET = 0,
-       GPCS_JPEG_START,
-       GPCS_MAX,
-};
-
-struct zoran_format {
-       char *name;
-#ifdef CONFIG_VIDEO_V4L1_COMPAT
-       int palette;
-#endif
-       __u32 fourcc;
-       int colorspace;
-       int depth;
-       __u32 flags;
-       __u32 vfespfr;
-};
-/* flags */
-#define ZORAN_FORMAT_COMPRESSED 1<<0
-#define ZORAN_FORMAT_OVERLAY    1<<1
-#define ZORAN_FORMAT_CAPTURE   1<<2
-#define ZORAN_FORMAT_PLAYBACK  1<<3
-
-/* overlay-settings */
-struct zoran_overlay_settings {
-       int is_set;
-       int x, y, width, height;        /* position */
-       int clipcount;          /* position and number of clips */
-       const struct zoran_format *format;      /* overlay format */
-};
-
-/* v4l-capture settings */
-struct zoran_v4l_settings {
-       int width, height, bytesperline;        /* capture size */
-       const struct zoran_format *format;      /* capture format */
-};
-
-/* jpg-capture/-playback settings */
-struct zoran_jpg_settings {
-       int decimation;         /* this bit is used to set everything to default */
-       int HorDcm, VerDcm, TmpDcm;     /* capture decimation settings (TmpDcm=1 means both fields) */
-       int field_per_buff, odd_even;   /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
-       int img_x, img_y, img_width, img_height;        /* crop settings (subframe capture) */
-       struct v4l2_jpegcompression jpg_comp;   /* JPEG-specific capture settings */
-};
-
-struct zoran_mapping {
-       struct file *file;
-       int count;
-};
-
-struct zoran_jpg_buffer {
-       struct zoran_mapping *map;
-       __le32 *frag_tab;               /* addresses of frag table */
-       u32 frag_tab_bus;       /* same value cached to save time in ISR */
-       enum zoran_buffer_state state;  /* non-zero if corresponding buffer is in use in grab queue */
-       struct zoran_sync bs;   /* DONE: info to return to application */
-};
-
-struct zoran_v4l_buffer {
-       struct zoran_mapping *map;
-       char *fbuffer;          /* virtual  address of frame buffer */
-       unsigned long fbuffer_phys;     /* physical address of frame buffer */
-       unsigned long fbuffer_bus;      /* bus      address of frame buffer */
-       enum zoran_buffer_state state;  /* state: unused/pending/done */
-       struct zoran_sync bs;   /* DONE: info to return to application */
-};
-
-enum zoran_lock_activity {
-       ZORAN_FREE,             /* free for use */
-       ZORAN_ACTIVE,           /* active but unlocked */
-       ZORAN_LOCKED,           /* locked */
-};
-
-/* buffer collections */
-struct zoran_jpg_struct {
-       enum zoran_lock_activity active;        /* feature currently in use? */
-       struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME];  /* buffers */
-       int num_buffers, buffer_size;
-       u8 allocated;           /* Flag if buffers are allocated  */
-       u8 ready_to_be_freed;   /* hack - see zoran_driver.c */
-       u8 need_contiguous;     /* Flag if contiguous buffers are needed */
-};
-
-struct zoran_v4l_struct {
-       enum zoran_lock_activity active;        /* feature currently in use? */
-       struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME];        /* buffers */
-       int num_buffers, buffer_size;
-       u8 allocated;           /* Flag if buffers are allocated  */
-       u8 ready_to_be_freed;   /* hack - see zoran_driver.c */
-};
-
-struct zoran;
-
-/* zoran_fh contains per-open() settings */
-struct zoran_fh {
-       struct zoran *zr;
-
-       enum zoran_map_mode map_mode;   /* Flag which bufferset will map by next mmap() */
-
-       struct zoran_overlay_settings overlay_settings;
-       u32 *overlay_mask;      /* overlay mask */
-       enum zoran_lock_activity overlay_active;        /* feature currently in use? */
-
-       struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
-       struct zoran_v4l_struct v4l_buffers;    /* V4L buffers' info */
-
-       struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
-       struct zoran_jpg_struct jpg_buffers;    /* MJPEG buffers' info */
-};
-
-struct card_info {
-       enum card_type type;
-       char name[32];
-       u16 i2c_decoder, i2c_encoder;                   /* I2C types */
-       u16 video_vfe, video_codec;                     /* videocodec types */
-       u16 audio_chip;                                 /* audio type */
-       u16 vendor_id, device_id;       /* subsystem vendor/device ID */
-
-       int inputs;             /* number of video inputs */
-       struct input {
-               int muxsel;
-               char name[32];
-       } input[BUZ_MAX_INPUT];
-
-       int norms;
-       struct tvnorm *tvn[3];  /* supported TV norms */
-
-       u32 jpeg_int;           /* JPEG interrupt */
-       u32 vsync_int;          /* VSYNC interrupt */
-       s8 gpio[ZR_GPIO_MAX];
-       u8 gpcs[GPCS_MAX];
-
-       struct vfe_polarity vfe_pol;
-       u8 gpio_pol[ZR_GPIO_MAX];
-
-       /* is the /GWS line conected? */
-       u8 gws_not_connected;
-
-       /* avs6eyes mux setting */
-       u8 input_mux;
-
-       void (*init) (struct zoran * zr);
-};
-
-struct zoran {
-       struct video_device *video_dev;
-
-       struct i2c_adapter i2c_adapter; /* */
-       struct i2c_algo_bit_data i2c_algo;      /* */
-       u32 i2cbr;
-
-       struct i2c_client *decoder;     /* video decoder i2c client */
-       struct i2c_client *encoder;     /* video encoder i2c client */
-
-       struct videocodec *codec;       /* video codec */
-       struct videocodec *vfe; /* video front end */
-
-       struct mutex resource_lock;     /* prevent evil stuff */
-
-       u8 initialized;         /* flag if zoran has been correctly initalized */
-       int user;               /* number of current users */
-       struct card_info card;
-       struct tvnorm *timing;
-
-       unsigned short id;      /* number of this device */
-       char name[32];          /* name of this device */
-       struct pci_dev *pci_dev;        /* PCI device */
-       unsigned char revision; /* revision of zr36057 */
-       unsigned int zr36057_adr;       /* bus address of IO mem returned by PCI BIOS */
-       unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
-
-       spinlock_t spinlock;    /* Spinlock */
-
-       /* Video for Linux parameters */
-       int input, norm;        /* card's norm and input - norm=VIDEO_MODE_* */
-       int hue, saturation, contrast, brightness;      /* Current picture params */
-       struct video_buffer buffer;     /* Current buffer params */
-       struct zoran_overlay_settings overlay_settings;
-       u32 *overlay_mask;      /* overlay mask */
-       enum zoran_lock_activity overlay_active;        /* feature currently in use? */
-
-       wait_queue_head_t v4l_capq;
-
-       int v4l_overlay_active; /* Overlay grab is activated */
-       int v4l_memgrab_active; /* Memory grab is activated */
-
-       int v4l_grab_frame;     /* Frame number being currently grabbed */
-#define NO_GRAB_ACTIVE (-1)
-       unsigned long v4l_grab_seq;     /* Number of frames grabbed */
-       struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
-
-       /* V4L grab queue of frames pending */
-       unsigned long v4l_pend_head;
-       unsigned long v4l_pend_tail;
-       unsigned long v4l_sync_tail;
-       int v4l_pend[V4L_MAX_FRAME];
-       struct zoran_v4l_struct v4l_buffers;    /* V4L buffers' info */
-
-       /* Buz MJPEG parameters */
-       enum zoran_codec_mode codec_mode;       /* status of codec */
-       struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
-
-       wait_queue_head_t jpg_capq;     /* wait here for grab to finish */
-
-       /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
-       /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
-       /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
-       unsigned long jpg_que_head;     /* Index where to put next buffer which is queued */
-       unsigned long jpg_dma_head;     /* Index of next buffer which goes into stat_com  */
-       unsigned long jpg_dma_tail;     /* Index of last buffer in stat_com               */
-       unsigned long jpg_que_tail;     /* Index of last buffer in queue                  */
-       unsigned long jpg_seq_num;      /* count of frames since grab/play started        */
-       unsigned long jpg_err_seq;      /* last seq_num before error                      */
-       unsigned long jpg_err_shift;
-       unsigned long jpg_queued_num;   /* count of frames queued since grab/play started */
-
-       /* zr36057's code buffer table */
-       __le32 *stat_com;               /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
-
-       /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
-       int jpg_pend[BUZ_MAX_FRAME];
-
-       /* array indexed by frame number */
-       struct zoran_jpg_struct jpg_buffers;    /* MJPEG buffers' info */
-
-       /* Additional stuff for testing */
-#ifdef CONFIG_PROC_FS
-       struct proc_dir_entry *zoran_proc;
-#else
-       void *zoran_proc;
-#endif
-       int testing;
-       int jpeg_error;
-       int intr_counter_GIRQ1;
-       int intr_counter_GIRQ0;
-       int intr_counter_CodRepIRQ;
-       int intr_counter_JPEGRepIRQ;
-       int field_counter;
-       int IRQ1_in;
-       int IRQ1_out;
-       int JPEG_in;
-       int JPEG_out;
-       int JPEG_0;
-       int JPEG_1;
-       int END_event_missed;
-       int JPEG_missed;
-       int JPEG_error;
-       int num_errors;
-       int JPEG_max_missed;
-       int JPEG_min_missed;
-
-       u32 last_isr;
-       unsigned long frame_num;
-
-       wait_queue_head_t test_q;
-};
-
-/*The following should be done in more portable way. It depends on define
-  of _ALPHA_BUZ in the Makefile.*/
-
-#ifdef _ALPHA_BUZ
-#define btwrite(dat,adr)    writel((dat), zr->zr36057_adr+(adr))
-#define btread(adr)         readl(zr->zr36057_adr+(adr))
-#else
-#define btwrite(dat,adr)    writel((dat), zr->zr36057_mem+(adr))
-#define btread(adr)         readl(zr->zr36057_mem+(adr))
-#endif
-
-#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
-#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
-#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
-
-#endif                         /* __kernel__ */
-
-#endif
diff --git a/drivers/media/video/zoran/Kconfig b/drivers/media/video/zoran/Kconfig
new file mode 100644 (file)
index 0000000..4ea5fa7
--- /dev/null
@@ -0,0 +1,73 @@
+config VIDEO_ZORAN
+       tristate "Zoran ZR36057/36067 Video For Linux"
+       depends on PCI && I2C_ALGOBIT && VIDEO_V4L1 && VIRT_TO_BUS
+       help
+         Say Y for support for MJPEG capture cards based on the Zoran
+         36057/36067 PCI controller chipset. This includes the Iomega
+         Buz, Pinnacle DC10+ and the Linux Media Labs LML33. There is
+         a driver homepage at <http://mjpeg.sf.net/driver-zoran/>. For
+         more information, check <file:Documentation/video4linux/Zoran>.
+
+         To compile this driver as a module, choose M here: the
+         module will be called zr36067.
+
+config VIDEO_ZORAN_DC30
+       tristate "Pinnacle/Miro DC30(+) support"
+       depends on VIDEO_ZORAN
+       select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_VPX3220 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         Support for the Pinnacle/Miro DC30(+) MJPEG capture/playback
+         card. This also supports really old DC10 cards based on the
+         zr36050 MJPEG codec and zr36016 VFE.
+
+config VIDEO_ZORAN_ZR36060
+       tristate "Zoran ZR36060"
+       depends on VIDEO_ZORAN
+       help
+         Say Y to support Zoran boards based on 36060 chips.
+         This includes Iomega Buz, Pinnacle DC10, Linux media Labs 33
+         and 33 R10 and AverMedia 6 boards.
+
+config VIDEO_ZORAN_BUZ
+       tristate "Iomega Buz support"
+       depends on VIDEO_ZORAN_ZR36060
+       select VIDEO_SAA7111 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_SAA7185 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         Support for the Iomega Buz MJPEG capture/playback card.
+
+config VIDEO_ZORAN_DC10
+       tristate "Pinnacle/Miro DC10(+) support"
+       depends on VIDEO_ZORAN_ZR36060
+       select VIDEO_SAA7110 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_ADV7175 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         Support for the Pinnacle/Miro DC10(+) MJPEG capture/playback
+         card.
+
+config VIDEO_ZORAN_LML33
+       tristate "Linux Media Labs LML33 support"
+       depends on VIDEO_ZORAN_ZR36060
+       select VIDEO_BT819 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         Support for the Linux Media Labs LML33 MJPEG capture/playback
+         card.
+
+config VIDEO_ZORAN_LML33R10
+       tristate "Linux Media Labs LML33R10 support"
+       depends on VIDEO_ZORAN_ZR36060
+       select VIDEO_SAA7114 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_ADV7170 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         support for the Linux Media Labs LML33R10 MJPEG capture/playback
+         card.
+
+config VIDEO_ZORAN_AVS6EYES
+       tristate "AverMedia 6 Eyes support (EXPERIMENTAL)"
+       depends on VIDEO_ZORAN_ZR36060 && EXPERIMENTAL && VIDEO_V4L1
+       select VIDEO_BT856 if VIDEO_HELPER_CHIPS_AUTO
+       select VIDEO_KS0127 if VIDEO_HELPER_CHIPS_AUTO
+       help
+         Support for the AverMedia 6 Eyes video surveillance card.
diff --git a/drivers/media/video/zoran/Makefile b/drivers/media/video/zoran/Makefile
new file mode 100644 (file)
index 0000000..44cc133
--- /dev/null
@@ -0,0 +1,6 @@
+zr36067-objs   :=      zoran_procfs.o zoran_device.o \
+                       zoran_driver.o zoran_card.o
+
+obj-$(CONFIG_VIDEO_ZORAN) += zr36067.o videocodec.o
+obj-$(CONFIG_VIDEO_ZORAN_DC30) += zr36050.o zr36016.o
+obj-$(CONFIG_VIDEO_ZORAN_ZR36060) += zr36060.o
diff --git a/drivers/media/video/zoran/videocodec.c b/drivers/media/video/zoran/videocodec.c
new file mode 100644 (file)
index 0000000..cf24956
--- /dev/null
@@ -0,0 +1,408 @@
+/*
+ * VIDEO MOTION CODECs internal API for video devices
+ *
+ * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
+ * bound to a master device.
+ *
+ * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: videocodec.c,v 1.1.2.8 2003/03/29 07:16:04 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#define VIDEOCODEC_VERSION "v0.2"
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/types.h>
+#include <linux/slab.h>
+
+// kernel config is here (procfs flag)
+
+#ifdef CONFIG_PROC_FS
+#include <linux/proc_fs.h>
+#include <linux/seq_file.h>
+#include <asm/uaccess.h>
+#endif
+
+#include "videocodec.h"
+
+static int debug;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug level (0-4)");
+
+#define dprintk(num, format, args...) \
+       do { \
+               if (debug >= num) \
+                       printk(format, ##args); \
+       } while (0)
+
+struct attached_list {
+       struct videocodec *codec;
+       struct attached_list *next;
+};
+
+struct codec_list {
+       const struct videocodec *codec;
+       int attached;
+       struct attached_list *list;
+       struct codec_list *next;
+};
+
+static struct codec_list *codeclist_top = NULL;
+
+/* ================================================= */
+/* function prototypes of the master/slave interface */
+/* ================================================= */
+
+struct videocodec *
+videocodec_attach (struct videocodec_master *master)
+{
+       struct codec_list *h = codeclist_top;
+       struct attached_list *a, *ptr;
+       struct videocodec *codec;
+       int res;
+
+       if (!master) {
+               dprintk(1, KERN_ERR "videocodec_attach: no data\n");
+               return NULL;
+       }
+
+       dprintk(2,
+               "videocodec_attach: '%s', flags %lx, magic %lx\n",
+               master->name, master->flags, master->magic);
+
+       if (!h) {
+               dprintk(1,
+                       KERN_ERR
+                       "videocodec_attach: no device available\n");
+               return NULL;
+       }
+
+       while (h) {
+               // attach only if the slave has at least the flags
+               // expected by the master
+               if ((master->flags & h->codec->flags) == master->flags) {
+                       dprintk(4, "videocodec_attach: try '%s'\n",
+                               h->codec->name);
+
+                       if (!try_module_get(h->codec->owner))
+                               return NULL;
+
+                       codec =
+                           kmalloc(sizeof(struct videocodec), GFP_KERNEL);
+                       if (!codec) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "videocodec_attach: no mem\n");
+                               goto out_module_put;
+                       }
+                       memcpy(codec, h->codec, sizeof(struct videocodec));
+
+                       snprintf(codec->name, sizeof(codec->name),
+                                "%s[%d]", codec->name, h->attached);
+                       codec->master_data = master;
+                       res = codec->setup(codec);
+                       if (res == 0) {
+                               dprintk(3, "videocodec_attach '%s'\n",
+                                       codec->name);
+                               ptr = kzalloc(sizeof(struct attached_list), GFP_KERNEL);
+                               if (!ptr) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "videocodec_attach: no memory\n");
+                                       goto out_kfree;
+                               }
+                               ptr->codec = codec;
+
+                               a = h->list;
+                               if (!a) {
+                                       h->list = ptr;
+                                       dprintk(4,
+                                               "videocodec: first element\n");
+                               } else {
+                                       while (a->next)
+                                               a = a->next;    // find end
+                                       a->next = ptr;
+                                       dprintk(4,
+                                               "videocodec: in after '%s'\n",
+                                               h->codec->name);
+                               }
+
+                               h->attached += 1;
+                               return codec;
+                       } else {
+                               kfree(codec);
+                       }
+               }
+               h = h->next;
+       }
+
+       dprintk(1, KERN_ERR "videocodec_attach: no codec found!\n");
+       return NULL;
+
+ out_module_put:
+       module_put(h->codec->owner);
+ out_kfree:
+       kfree(codec);
+       return NULL;
+}
+
+int
+videocodec_detach (struct videocodec *codec)
+{
+       struct codec_list *h = codeclist_top;
+       struct attached_list *a, *prev;
+       int res;
+
+       if (!codec) {
+               dprintk(1, KERN_ERR "videocodec_detach: no data\n");
+               return -EINVAL;
+       }
+
+       dprintk(2,
+               "videocodec_detach: '%s', type: %x, flags %lx, magic %lx\n",
+               codec->name, codec->type, codec->flags, codec->magic);
+
+       if (!h) {
+               dprintk(1,
+                       KERN_ERR "videocodec_detach: no device left...\n");
+               return -ENXIO;
+       }
+
+       while (h) {
+               a = h->list;
+               prev = NULL;
+               while (a) {
+                       if (codec == a->codec) {
+                               res = a->codec->unset(a->codec);
+                               if (res >= 0) {
+                                       dprintk(3,
+                                               "videocodec_detach: '%s'\n",
+                                               a->codec->name);
+                                       a->codec->master_data = NULL;
+                               } else {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "videocodec_detach: '%s'\n",
+                                               a->codec->name);
+                                       a->codec->master_data = NULL;
+                               }
+                               if (prev == NULL) {
+                                       h->list = a->next;
+                                       dprintk(4,
+                                               "videocodec: delete first\n");
+                               } else {
+                                       prev->next = a->next;
+                                       dprintk(4,
+                                               "videocodec: delete middle\n");
+                               }
+                               module_put(a->codec->owner);
+                               kfree(a->codec);
+                               kfree(a);
+                               h->attached -= 1;
+                               return 0;
+                       }
+                       prev = a;
+                       a = a->next;
+               }
+               h = h->next;
+       }
+
+       dprintk(1, KERN_ERR "videocodec_detach: given codec not found!\n");
+       return -EINVAL;
+}
+
+int
+videocodec_register (const struct videocodec *codec)
+{
+       struct codec_list *ptr, *h = codeclist_top;
+
+       if (!codec) {
+               dprintk(1, KERN_ERR "videocodec_register: no data!\n");
+               return -EINVAL;
+       }
+
+       dprintk(2,
+               "videocodec: register '%s', type: %x, flags %lx, magic %lx\n",
+               codec->name, codec->type, codec->flags, codec->magic);
+
+       ptr = kzalloc(sizeof(struct codec_list), GFP_KERNEL);
+       if (!ptr) {
+               dprintk(1, KERN_ERR "videocodec_register: no memory\n");
+               return -ENOMEM;
+       }
+       ptr->codec = codec;
+
+       if (!h) {
+               codeclist_top = ptr;
+               dprintk(4, "videocodec: hooked in as first element\n");
+       } else {
+               while (h->next)
+                       h = h->next;    // find the end
+               h->next = ptr;
+               dprintk(4, "videocodec: hooked in after '%s'\n",
+                       h->codec->name);
+       }
+
+       return 0;
+}
+
+int
+videocodec_unregister (const struct videocodec *codec)
+{
+       struct codec_list *prev = NULL, *h = codeclist_top;
+
+       if (!codec) {
+               dprintk(1, KERN_ERR "videocodec_unregister: no data!\n");
+               return -EINVAL;
+       }
+
+       dprintk(2,
+               "videocodec: unregister '%s', type: %x, flags %lx, magic %lx\n",
+               codec->name, codec->type, codec->flags, codec->magic);
+
+       if (!h) {
+               dprintk(1,
+                       KERN_ERR
+                       "videocodec_unregister: no device left...\n");
+               return -ENXIO;
+       }
+
+       while (h) {
+               if (codec == h->codec) {
+                       if (h->attached) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "videocodec: '%s' is used\n",
+                                       h->codec->name);
+                               return -EBUSY;
+                       }
+                       dprintk(3, "videocodec: unregister '%s' is ok.\n",
+                               h->codec->name);
+                       if (prev == NULL) {
+                               codeclist_top = h->next;
+                               dprintk(4,
+                                       "videocodec: delete first element\n");
+                       } else {
+                               prev->next = h->next;
+                               dprintk(4,
+                                       "videocodec: delete middle element\n");
+                       }
+                       kfree(h);
+                       return 0;
+               }
+               prev = h;
+               h = h->next;
+       }
+
+       dprintk(1,
+               KERN_ERR
+               "videocodec_unregister: given codec not found!\n");
+       return -EINVAL;
+}
+
+#ifdef CONFIG_PROC_FS
+static int proc_videocodecs_show(struct seq_file *m, void *v)
+{
+       struct codec_list *h = codeclist_top;
+       struct attached_list *a;
+
+       seq_printf(m, "<S>lave or attached <M>aster name  type flags    magic    ");
+       seq_printf(m, "(connected as)\n");
+
+       h = codeclist_top;
+       while (h) {
+               seq_printf(m, "S %32s %04x %08lx %08lx (TEMPLATE)\n",
+                             h->codec->name, h->codec->type,
+                             h->codec->flags, h->codec->magic);
+               a = h->list;
+               while (a) {
+                       seq_printf(m, "M %32s %04x %08lx %08lx (%s)\n",
+                                     a->codec->master_data->name,
+                                     a->codec->master_data->type,
+                                     a->codec->master_data->flags,
+                                     a->codec->master_data->magic,
+                                     a->codec->name);
+                       a = a->next;
+               }
+               h = h->next;
+       }
+
+       return 0;
+}
+
+static int proc_videocodecs_open(struct inode *inode, struct file *file)
+{
+       return single_open(file, proc_videocodecs_show, NULL);
+}
+
+static const struct file_operations videocodecs_proc_fops = {
+       .owner          = THIS_MODULE,
+       .open           = proc_videocodecs_open,
+       .read           = seq_read,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+#endif
+
+/* ===================== */
+/* hook in driver module */
+/* ===================== */
+static int __init
+videocodec_init (void)
+{
+#ifdef CONFIG_PROC_FS
+       static struct proc_dir_entry *videocodec_proc_entry;
+#endif
+
+       printk(KERN_INFO "Linux video codec intermediate layer: %s\n",
+              VIDEOCODEC_VERSION);
+
+#ifdef CONFIG_PROC_FS
+       videocodec_proc_entry = proc_create("videocodecs", 0, NULL, &videocodecs_proc_fops);
+       if (!videocodec_proc_entry) {
+               dprintk(1, KERN_ERR "videocodec: can't init procfs.\n");
+       }
+#endif
+       return 0;
+}
+
+static void __exit
+videocodec_exit (void)
+{
+#ifdef CONFIG_PROC_FS
+       remove_proc_entry("videocodecs", NULL);
+#endif
+}
+
+EXPORT_SYMBOL(videocodec_attach);
+EXPORT_SYMBOL(videocodec_detach);
+EXPORT_SYMBOL(videocodec_register);
+EXPORT_SYMBOL(videocodec_unregister);
+
+module_init(videocodec_init);
+module_exit(videocodec_exit);
+
+MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
+MODULE_DESCRIPTION("Intermediate API module for video codecs "
+                  VIDEOCODEC_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zoran/videocodec.h b/drivers/media/video/zoran/videocodec.h
new file mode 100644 (file)
index 0000000..97a3bbe
--- /dev/null
@@ -0,0 +1,358 @@
+/*
+ * VIDEO MOTION CODECs internal API for video devices
+ *
+ * Interface for MJPEG (and maybe later MPEG/WAVELETS) codec's
+ * bound to a master device.
+ *
+ * (c) 2002 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: videocodec.h,v 1.1.2.4 2003/01/14 21:15:03 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+/* =================== */
+/* general description */
+/* =================== */
+
+/* Should ease the (re-)usage of drivers supporting cards with (different)
+   video codecs. The codecs register to this module their functionality,
+   and the processors (masters) can attach to them if they fit.
+
+   The codecs are typically have a "strong" binding to their master - so I
+   don't think it makes sense to have a full blown interfacing as with e.g.
+   i2c. If you have an other opinion, let's discuss & implement it :-)))
+
+   Usage:
+
+   The slave has just to setup the videocodec structure and use two functions:
+   videocodec_register(codecdata);
+   videocodec_unregister(codecdata);
+   The best is just calling them at module (de-)initialisation.
+
+   The master sets up the structure videocodec_master and calls:
+   codecdata=videocodec_attach(master_codecdata);
+   videocodec_detach(codecdata);
+
+   The slave is called during attach/detach via functions setup previously
+   during register. At that time, the master_data pointer is set up
+   and the slave can access any io registers of the master device (in the case
+   the slave is bound to it). Otherwise it doesn't need this functions and
+   therfor they may not be initialized.
+
+   The other fuctions are just for convenience, as they are for sure used by
+   most/all of the codecs. The last ones may be ommited, too.
+
+   See the structure declaration below for more information and which data has
+   to be set up for the master and the slave.
+
+   ----------------------------------------------------------------------------
+   The master should have "knowledge" of the slave and vice versa.  So the data
+   structures sent to/from slave via set_data/get_data set_image/get_image are
+   device dependent and vary between MJPEG/MPEG/WAVELET/... devices. (!!!!)
+   ----------------------------------------------------------------------------
+*/
+\f
+
+/* ========================================== */
+/* description of the videocodec_io structure */
+/* ========================================== */
+
+/*
+   ==== master setup ====
+   name -> name of the device structure for reference and debugging
+   master_data ->  data ref. for the master (e.g. the zr36055,57,67)
+   readreg -> ref. to read-fn from register (setup by master, used by slave)
+   writereg -> ref. to write-fn to register (setup by master, used by slave)
+              this two functions do the lowlevel I/O job
+
+   ==== slave functionality setup ====
+   slave_data -> data ref. for the slave (e.g. the zr36050,60)
+   check -> fn-ref. checks availability of an device, returns -EIO on failure or
+           the type on success
+           this makes espcecially sense if a driver module supports more than
+           one codec which may be quite similar to access, nevertheless it
+           is good for a first functionality check
+
+   -- main functions you always need for compression/decompression --
+
+   set_mode -> this fn-ref. resets the entire codec, and sets up the mode
+              with the last defined norm/size (or device default if not
+              available) - it returns 0 if the mode is possible
+   set_size -> this fn-ref. sets the norm and image size for
+              compression/decompression (returns 0 on success)
+              the norm param is defined in videodev.h (VIDEO_MODE_*)
+
+   additional setup may be available, too - but the codec should work with
+   some default values even without this
+
+   set_data -> sets device-specific data (tables, quality etc.)
+   get_data -> query device-specific data (tables, quality etc.)
+
+   if the device delivers interrupts, they may be setup/handled here
+   setup_interrupt -> codec irq setup (not needed for 36050/60)
+   handle_interrupt -> codec irq handling (not needed for 36050/60)
+
+   if the device delivers pictures, they may be handled here
+   put_image -> puts image data to the codec (not needed for 36050/60)
+   get_image -> gets image data from the codec (not needed for 36050/60)
+               the calls include frame numbers and flags (even/odd/...)
+               if needed and a flag which allows blocking until its ready
+*/
+\f
+/* ============== */
+/* user interface */
+/* ============== */
+
+/*
+   Currently there is only a information display planned, as the layer
+   is not visible for the user space at all.
+
+   Information is available via procfs. The current entry is "/proc/videocodecs"
+   but it makes sense to "hide" it in the /proc/video tree of v4l(2) --TODO--.
+
+A example for such an output is:
+
+<S>lave or attached <M>aster name  type flags    magic    (connected as)
+S                          zr36050 0002 0000d001 00000000 (TEMPLATE)
+M                       zr36055[0] 0001 0000c001 00000000 (zr36050[0])
+M                       zr36055[1] 0001 0000c001 00000000 (zr36050[1])
+
+*/
+\f
+
+/* =============================================== */
+/* special defines for the videocodec_io structure */
+/* =============================================== */
+
+#ifndef __LINUX_VIDEOCODEC_H
+#define __LINUX_VIDEOCODEC_H
+
+#include <linux/videodev.h>
+
+//should be in videodev.h ??? (VID_DO_....)
+#define CODEC_DO_COMPRESSION 0
+#define CODEC_DO_EXPANSION   1
+
+/* this are the current codec flags I think they are needed */
+/*  -> type value in structure */
+#define CODEC_FLAG_JPEG      0x00000001L       // JPEG codec
+#define CODEC_FLAG_MPEG      0x00000002L       // MPEG1/2/4 codec
+#define CODEC_FLAG_DIVX      0x00000004L       // DIVX codec
+#define CODEC_FLAG_WAVELET   0x00000008L       // WAVELET codec
+                                         // room for other types
+
+#define CODEC_FLAG_MAGIC     0x00000800L       // magic key must match
+#define CODEC_FLAG_HARDWARE  0x00001000L       // is a hardware codec
+#define CODEC_FLAG_VFE       0x00002000L       // has direct video frontend
+#define CODEC_FLAG_ENCODER   0x00004000L       // compression capability
+#define CODEC_FLAG_DECODER   0x00008000L       // decompression capability
+#define CODEC_FLAG_NEEDIRQ   0x00010000L       // needs irq handling
+#define CODEC_FLAG_RDWRPIC   0x00020000L       // handles picture I/O
+
+/* a list of modes, some are just examples (is there any HW?) */
+#define CODEC_MODE_BJPG      0x0001    // Baseline JPEG
+#define CODEC_MODE_LJPG      0x0002    // Lossless JPEG
+#define CODEC_MODE_MPEG1     0x0003    // MPEG 1
+#define CODEC_MODE_MPEG2     0x0004    // MPEG 2
+#define CODEC_MODE_MPEG4     0x0005    // MPEG 4
+#define CODEC_MODE_MSDIVX    0x0006    // MS DivX
+#define CODEC_MODE_ODIVX     0x0007    // Open DivX
+#define CODEC_MODE_WAVELET   0x0008    // Wavelet
+
+/* this are the current codec types I want to implement */
+/*  -> type value in structure */
+#define CODEC_TYPE_NONE    0
+#define CODEC_TYPE_L64702  1
+#define CODEC_TYPE_ZR36050 2
+#define CODEC_TYPE_ZR36016 3
+#define CODEC_TYPE_ZR36060 4
+
+/* the type of data may be enhanced by future implementations (data-fn.'s) */
+/*  -> used in command                                                     */
+#define CODEC_G_STATUS         0x0000  /* codec status (query only) */
+#define CODEC_S_CODEC_MODE     0x0001  /* codec mode (baseline JPEG, MPEG1,... */
+#define CODEC_G_CODEC_MODE     0x8001
+#define CODEC_S_VFE            0x0002  /* additional video frontend setup */
+#define CODEC_G_VFE            0x8002
+#define CODEC_S_MMAP           0x0003  /* MMAP setup (if available) */
+
+#define CODEC_S_JPEG_TDS_BYTE  0x0010  /* target data size in bytes */
+#define CODEC_G_JPEG_TDS_BYTE  0x8010
+#define CODEC_S_JPEG_SCALE     0x0011  /* scaling factor for quant. tables */
+#define CODEC_G_JPEG_SCALE     0x8011
+#define CODEC_S_JPEG_HDT_DATA  0x0018  /* huffman-tables */
+#define CODEC_G_JPEG_HDT_DATA  0x8018
+#define CODEC_S_JPEG_QDT_DATA  0x0019  /* quantizing-tables */
+#define CODEC_G_JPEG_QDT_DATA  0x8019
+#define CODEC_S_JPEG_APP_DATA  0x001A  /* APP marker */
+#define CODEC_G_JPEG_APP_DATA  0x801A
+#define CODEC_S_JPEG_COM_DATA  0x001B  /* COM marker */
+#define CODEC_G_JPEG_COM_DATA  0x801B
+
+#define CODEC_S_PRIVATE        0x1000  /* "private" commands start here */
+#define CODEC_G_PRIVATE        0x9000
+
+#define CODEC_G_FLAG           0x8000  /* this is how 'get' is detected */
+
+/* types of transfer, directly user space or a kernel buffer (image-fn.'s) */
+/*  -> used in get_image, put_image                                        */
+#define CODEC_TRANSFER_KERNEL 0        /* use "memcopy" */
+#define CODEC_TRANSFER_USER   1        /* use "to/from_user" */
+\f
+
+/* ========================= */
+/* the structures itself ... */
+/* ========================= */
+
+struct vfe_polarity {
+       unsigned int vsync_pol:1;
+       unsigned int hsync_pol:1;
+       unsigned int field_pol:1;
+       unsigned int blank_pol:1;
+       unsigned int subimg_pol:1;
+       unsigned int poe_pol:1;
+       unsigned int pvalid_pol:1;
+       unsigned int vclk_pol:1;
+};
+
+struct vfe_settings {
+       __u32 x, y;             /* Offsets into image */
+       __u32 width, height;    /* Area to capture */
+       __u16 decimation;       /* Decimation divider */
+       __u16 flags;            /* Flags for capture */
+/* flags are the same as in struct video_capture - see videodev.h:
+#define VIDEO_CAPTURE_ODD              0
+#define VIDEO_CAPTURE_EVEN             1
+*/
+       __u16 quality;          /* quality of the video */
+};
+
+struct tvnorm {
+       u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
+};
+
+struct jpeg_com_marker {
+       int len; /* number of usable bytes in data */
+       char data[60];
+};
+
+struct jpeg_app_marker {
+       int appn; /* number app segment */
+       int len; /* number of usable bytes in data */
+       char data[60];
+};
+
+struct videocodec {
+       struct module *owner;
+       /* -- filled in by slave device during register -- */
+       char name[32];
+       unsigned long magic;    /* may be used for client<->master attaching */
+       unsigned long flags;    /* functionality flags */
+       unsigned int type;      /* codec type */
+
+       /* -- these is filled in later during master device attach -- */
+
+       struct videocodec_master *master_data;
+
+       /* -- these are filled in by the slave device during register -- */
+
+       void *data;             /* private slave data */
+
+       /* attach/detach client functions (indirect call) */
+       int (*setup) (struct videocodec * codec);
+       int (*unset) (struct videocodec * codec);
+
+       /* main functions, every client needs them for sure! */
+       // set compression or decompression (or freeze, stop, standby, etc)
+       int (*set_mode) (struct videocodec * codec,
+                        int mode);
+       // setup picture size and norm (for the codec's video frontend)
+       int (*set_video) (struct videocodec * codec,
+                         struct tvnorm * norm,
+                         struct vfe_settings * cap,
+                         struct vfe_polarity * pol);
+       // other control commands, also mmap setup etc.
+       int (*control) (struct videocodec * codec,
+                       int type,
+                       int size,
+                       void *data);
+
+       /* additional setup/query/processing (may be NULL pointer) */
+       // interrupt setup / handling (for irq's delivered by master)
+       int (*setup_interrupt) (struct videocodec * codec,
+                               long mode);
+       int (*handle_interrupt) (struct videocodec * codec,
+                                int source,
+                                long flag);
+       // picture interface (if any)
+       long (*put_image) (struct videocodec * codec,
+                          int tr_type,
+                          int block,
+                          long *fr_num,
+                          long *flag,
+                          long size,
+                          void *buf);
+       long (*get_image) (struct videocodec * codec,
+                          int tr_type,
+                          int block,
+                          long *fr_num,
+                          long *flag,
+                          long size,
+                          void *buf);
+};
+
+struct videocodec_master {
+       /* -- filled in by master device for registration -- */
+       char name[32];
+       unsigned long magic;    /* may be used for client<->master attaching */
+       unsigned long flags;    /* functionality flags */
+       unsigned int type;      /* master type */
+
+       void *data;             /* private master data */
+
+        __u32(*readreg) (struct videocodec * codec,
+                         __u16 reg);
+       void (*writereg) (struct videocodec * codec,
+                         __u16 reg,
+                         __u32 value);
+};
+\f
+
+/* ================================================= */
+/* function prototypes of the master/slave interface */
+/* ================================================= */
+
+/* attach and detach commands for the master */
+// * master structure needs to be kmalloc'ed before calling attach
+//   and free'd after calling detach
+// * returns pointer on success, NULL on failure
+extern struct videocodec *videocodec_attach(struct videocodec_master *);
+// * 0 on success, <0 (errno) on failure
+extern int videocodec_detach(struct videocodec *);
+
+/* register and unregister commands for the slaves */
+// * 0 on success, <0 (errno) on failure
+extern int videocodec_register(const struct videocodec *);
+// * 0 on success, <0 (errno) on failure
+extern int videocodec_unregister(const struct videocodec *);
+
+/* the other calls are directly done via the videocodec structure! */
+
+#endif                         /*ifndef __LINUX_VIDEOCODEC_H */
diff --git a/drivers/media/video/zoran/zoran.h b/drivers/media/video/zoran/zoran.h
new file mode 100644 (file)
index 0000000..46b7ad4
--- /dev/null
@@ -0,0 +1,510 @@
+/*
+ * zoran - Iomega Buz driver
+ *
+ * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
+ *
+ * based on
+ *
+ * zoran.0.0.3 Copyright (C) 1998 Dave Perks <dperks@ibm.net>
+ *
+ * and
+ *
+ * bttv - Bt848 frame grabber driver
+ * Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
+ *                        & Marcus Metzler (mocm@thp.uni-koeln.de)
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _BUZ_H_
+#define _BUZ_H_
+
+struct zoran_requestbuffers {
+       unsigned long count;    /* Number of buffers for MJPEG grabbing */
+       unsigned long size;     /* Size PER BUFFER in bytes */
+};
+
+struct zoran_sync {
+       unsigned long frame;    /* number of buffer that has been free'd */
+       unsigned long length;   /* number of code bytes in buffer (capture only) */
+       unsigned long seq;      /* frame sequence number */
+       struct timeval timestamp;       /* timestamp */
+};
+
+struct zoran_status {
+       int input;              /* Input channel, has to be set prior to BUZIOC_G_STATUS */
+       int signal;             /* Returned: 1 if valid video signal detected */
+       int norm;               /* Returned: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+       int color;              /* Returned: 1 if color signal detected */
+};
+
+struct zoran_params {
+
+       /* The following parameters can only be queried */
+
+       int major_version;      /* Major version number of driver */
+       int minor_version;      /* Minor version number of driver */
+
+       /* Main control parameters */
+
+       int input;              /* Input channel: 0 = Composite, 1 = S-VHS */
+       int norm;               /* Norm: VIDEO_MODE_PAL or VIDEO_MODE_NTSC */
+       int decimation;         /* decimation of captured video,
+                                * enlargement of video played back.
+                                * Valid values are 1, 2, 4 or 0.
+                                * 0 is a special value where the user
+                                * has full control over video scaling */
+
+       /* The following parameters only have to be set if decimation==0,
+        * for other values of decimation they provide the data how the image is captured */
+
+       int HorDcm;             /* Horizontal decimation: 1, 2 or 4 */
+       int VerDcm;             /* Vertical decimation: 1 or 2 */
+       int TmpDcm;             /* Temporal decimation: 1 or 2,
+                                * if TmpDcm==2 in capture every second frame is dropped,
+                                * in playback every frame is played twice */
+       int field_per_buff;     /* Number of fields per buffer: 1 or 2 */
+       int img_x;              /* start of image in x direction */
+       int img_y;              /* start of image in y direction */
+       int img_width;          /* image width BEFORE decimation,
+                                * must be a multiple of HorDcm*16 */
+       int img_height;         /* image height BEFORE decimation,
+                                * must be a multiple of VerDcm*8 */
+
+       /* --- End of parameters for decimation==0 only --- */
+
+       /* JPEG control parameters */
+
+       int quality;            /* Measure for quality of compressed images.
+                                * Scales linearly with the size of the compressed images.
+                                * Must be beetween 0 and 100, 100 is a compression
+                                * ratio of 1:4 */
+
+       int odd_even;           /* Which field should come first ??? */
+
+       int APPn;               /* Number of APP segment to be written, must be 0..15 */
+       int APP_len;            /* Length of data in JPEG APPn segment */
+       char APP_data[60];      /* Data in the JPEG APPn segment. */
+
+       int COM_len;            /* Length of data in JPEG COM segment */
+       char COM_data[60];      /* Data in JPEG COM segment */
+
+       unsigned long jpeg_markers;     /* Which markers should go into the JPEG output.
+                                        * Unless you exactly know what you do, leave them untouched.
+                                        * Inluding less markers will make the resulting code
+                                        * smaller, but there will be fewer aplications
+                                        * which can read it.
+                                        * The presence of the APP and COM marker is
+                                        * influenced by APP0_len and COM_len ONLY! */
+#define JPEG_MARKER_DHT (1<<3) /* Define Huffman Tables */
+#define JPEG_MARKER_DQT (1<<4) /* Define Quantization Tables */
+#define JPEG_MARKER_DRI (1<<5) /* Define Restart Interval */
+#define JPEG_MARKER_COM (1<<6) /* Comment segment */
+#define JPEG_MARKER_APP (1<<7) /* App segment, driver will allways use APP0 */
+
+       int VFIFO_FB;           /* Flag for enabling Video Fifo Feedback.
+                                * If this flag is turned on and JPEG decompressing
+                                * is going to the screen, the decompress process
+                                * is stopped every time the Video Fifo is full.
+                                * This enables a smooth decompress to the screen
+                                * but the video output signal will get scrambled */
+
+       /* Misc */
+
+       char reserved[312];     /* Makes 512 bytes for this structure */
+};
+
+/*
+Private IOCTL to set up for displaying MJPEG
+*/
+#define BUZIOC_G_PARAMS       _IOR ('v', BASE_VIDIOCPRIVATE+0,  struct zoran_params)
+#define BUZIOC_S_PARAMS       _IOWR('v', BASE_VIDIOCPRIVATE+1,  struct zoran_params)
+#define BUZIOC_REQBUFS        _IOWR('v', BASE_VIDIOCPRIVATE+2,  struct zoran_requestbuffers)
+#define BUZIOC_QBUF_CAPT      _IOW ('v', BASE_VIDIOCPRIVATE+3,  int)
+#define BUZIOC_QBUF_PLAY      _IOW ('v', BASE_VIDIOCPRIVATE+4,  int)
+#define BUZIOC_SYNC           _IOR ('v', BASE_VIDIOCPRIVATE+5,  struct zoran_sync)
+#define BUZIOC_G_STATUS       _IOWR('v', BASE_VIDIOCPRIVATE+6,  struct zoran_status)
+
+
+#ifdef __KERNEL__
+
+#define MAJOR_VERSION 0                /* driver major version */
+#define MINOR_VERSION 9                /* driver minor version */
+#define RELEASE_VERSION 5      /* release version */
+
+#define ZORAN_NAME    "ZORAN"  /* name of the device */
+
+#define ZR_DEVNAME(zr) ((zr)->name)
+
+#define   BUZ_MAX_WIDTH   (zr->timing->Wa)
+#define   BUZ_MAX_HEIGHT  (zr->timing->Ha)
+#define   BUZ_MIN_WIDTH    32  /* never display less than 32 pixels */
+#define   BUZ_MIN_HEIGHT   24  /* never display less than 24 rows */
+
+#define BUZ_NUM_STAT_COM    4
+#define BUZ_MASK_STAT_COM   3
+
+#define BUZ_MAX_FRAME     256  /* Must be a power of 2 */
+#define BUZ_MASK_FRAME    255  /* Must be BUZ_MAX_FRAME-1 */
+
+#define BUZ_MAX_INPUT       16
+
+#if VIDEO_MAX_FRAME <= 32
+#   define   V4L_MAX_FRAME   32
+#elif VIDEO_MAX_FRAME <= 64
+#   define   V4L_MAX_FRAME   64
+#else
+#   error   "Too many video frame buffers to handle"
+#endif
+#define   V4L_MASK_FRAME   (V4L_MAX_FRAME - 1)
+
+#define MAX_KMALLOC_MEM (128*1024)
+
+#include "zr36057.h"
+
+enum card_type {
+       UNKNOWN = -1,
+
+       /* Pinnacle/Miro */
+       DC10_old,               /* DC30 like */
+       DC10_new,               /* DC10plus like */
+       DC10plus,
+       DC30,
+       DC30plus,
+
+       /* Linux Media Labs */
+       LML33,
+       LML33R10,
+
+       /* Iomega */
+       BUZ,
+
+       /* AverMedia */
+       AVS6EYES,
+
+       /* total number of cards */
+       NUM_CARDS
+};
+
+enum zoran_codec_mode {
+       BUZ_MODE_IDLE,          /* nothing going on */
+       BUZ_MODE_MOTION_COMPRESS,       /* grabbing frames */
+       BUZ_MODE_MOTION_DECOMPRESS,     /* playing frames */
+       BUZ_MODE_STILL_COMPRESS,        /* still frame conversion */
+       BUZ_MODE_STILL_DECOMPRESS       /* still frame conversion */
+};
+
+enum zoran_buffer_state {
+       BUZ_STATE_USER,         /* buffer is owned by application */
+       BUZ_STATE_PEND,         /* buffer is queued in pend[] ready to feed to I/O */
+       BUZ_STATE_DMA,          /* buffer is queued in dma[] for I/O */
+       BUZ_STATE_DONE          /* buffer is ready to return to application */
+};
+
+enum zoran_map_mode {
+       ZORAN_MAP_MODE_RAW,
+       ZORAN_MAP_MODE_JPG_REC,
+#define ZORAN_MAP_MODE_JPG ZORAN_MAP_MODE_JPG_REC
+       ZORAN_MAP_MODE_JPG_PLAY,
+};
+
+enum gpio_type {
+       ZR_GPIO_JPEG_SLEEP = 0,
+       ZR_GPIO_JPEG_RESET,
+       ZR_GPIO_JPEG_FRAME,
+       ZR_GPIO_VID_DIR,
+       ZR_GPIO_VID_EN,
+       ZR_GPIO_VID_RESET,
+       ZR_GPIO_CLK_SEL1,
+       ZR_GPIO_CLK_SEL2,
+       ZR_GPIO_MAX,
+};
+
+enum gpcs_type {
+       GPCS_JPEG_RESET = 0,
+       GPCS_JPEG_START,
+       GPCS_MAX,
+};
+
+struct zoran_format {
+       char *name;
+#ifdef CONFIG_VIDEO_V4L1_COMPAT
+       int palette;
+#endif
+       __u32 fourcc;
+       int colorspace;
+       int depth;
+       __u32 flags;
+       __u32 vfespfr;
+};
+/* flags */
+#define ZORAN_FORMAT_COMPRESSED 1<<0
+#define ZORAN_FORMAT_OVERLAY    1<<1
+#define ZORAN_FORMAT_CAPTURE   1<<2
+#define ZORAN_FORMAT_PLAYBACK  1<<3
+
+/* overlay-settings */
+struct zoran_overlay_settings {
+       int is_set;
+       int x, y, width, height;        /* position */
+       int clipcount;          /* position and number of clips */
+       const struct zoran_format *format;      /* overlay format */
+};
+
+/* v4l-capture settings */
+struct zoran_v4l_settings {
+       int width, height, bytesperline;        /* capture size */
+       const struct zoran_format *format;      /* capture format */
+};
+
+/* jpg-capture/-playback settings */
+struct zoran_jpg_settings {
+       int decimation;         /* this bit is used to set everything to default */
+       int HorDcm, VerDcm, TmpDcm;     /* capture decimation settings (TmpDcm=1 means both fields) */
+       int field_per_buff, odd_even;   /* field-settings (odd_even=1 (+TmpDcm=1) means top-field-first) */
+       int img_x, img_y, img_width, img_height;        /* crop settings (subframe capture) */
+       struct v4l2_jpegcompression jpg_comp;   /* JPEG-specific capture settings */
+};
+
+struct zoran_mapping {
+       struct file *file;
+       int count;
+};
+
+struct zoran_jpg_buffer {
+       struct zoran_mapping *map;
+       __le32 *frag_tab;               /* addresses of frag table */
+       u32 frag_tab_bus;       /* same value cached to save time in ISR */
+       enum zoran_buffer_state state;  /* non-zero if corresponding buffer is in use in grab queue */
+       struct zoran_sync bs;   /* DONE: info to return to application */
+};
+
+struct zoran_v4l_buffer {
+       struct zoran_mapping *map;
+       char *fbuffer;          /* virtual  address of frame buffer */
+       unsigned long fbuffer_phys;     /* physical address of frame buffer */
+       unsigned long fbuffer_bus;      /* bus      address of frame buffer */
+       enum zoran_buffer_state state;  /* state: unused/pending/done */
+       struct zoran_sync bs;   /* DONE: info to return to application */
+};
+
+enum zoran_lock_activity {
+       ZORAN_FREE,             /* free for use */
+       ZORAN_ACTIVE,           /* active but unlocked */
+       ZORAN_LOCKED,           /* locked */
+};
+
+/* buffer collections */
+struct zoran_jpg_struct {
+       enum zoran_lock_activity active;        /* feature currently in use? */
+       struct zoran_jpg_buffer buffer[BUZ_MAX_FRAME];  /* buffers */
+       int num_buffers, buffer_size;
+       u8 allocated;           /* Flag if buffers are allocated  */
+       u8 ready_to_be_freed;   /* hack - see zoran_driver.c */
+       u8 need_contiguous;     /* Flag if contiguous buffers are needed */
+};
+
+struct zoran_v4l_struct {
+       enum zoran_lock_activity active;        /* feature currently in use? */
+       struct zoran_v4l_buffer buffer[VIDEO_MAX_FRAME];        /* buffers */
+       int num_buffers, buffer_size;
+       u8 allocated;           /* Flag if buffers are allocated  */
+       u8 ready_to_be_freed;   /* hack - see zoran_driver.c */
+};
+
+struct zoran;
+
+/* zoran_fh contains per-open() settings */
+struct zoran_fh {
+       struct zoran *zr;
+
+       enum zoran_map_mode map_mode;   /* Flag which bufferset will map by next mmap() */
+
+       struct zoran_overlay_settings overlay_settings;
+       u32 *overlay_mask;      /* overlay mask */
+       enum zoran_lock_activity overlay_active;        /* feature currently in use? */
+
+       struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
+       struct zoran_v4l_struct v4l_buffers;    /* V4L buffers' info */
+
+       struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
+       struct zoran_jpg_struct jpg_buffers;    /* MJPEG buffers' info */
+};
+
+struct card_info {
+       enum card_type type;
+       char name[32];
+       u16 i2c_decoder, i2c_encoder;                   /* I2C types */
+       u16 video_vfe, video_codec;                     /* videocodec types */
+       u16 audio_chip;                                 /* audio type */
+       u16 vendor_id, device_id;       /* subsystem vendor/device ID */
+
+       int inputs;             /* number of video inputs */
+       struct input {
+               int muxsel;
+               char name[32];
+       } input[BUZ_MAX_INPUT];
+
+       int norms;
+       struct tvnorm *tvn[3];  /* supported TV norms */
+
+       u32 jpeg_int;           /* JPEG interrupt */
+       u32 vsync_int;          /* VSYNC interrupt */
+       s8 gpio[ZR_GPIO_MAX];
+       u8 gpcs[GPCS_MAX];
+
+       struct vfe_polarity vfe_pol;
+       u8 gpio_pol[ZR_GPIO_MAX];
+
+       /* is the /GWS line conected? */
+       u8 gws_not_connected;
+
+       /* avs6eyes mux setting */
+       u8 input_mux;
+
+       void (*init) (struct zoran * zr);
+};
+
+struct zoran {
+       struct video_device *video_dev;
+
+       struct i2c_adapter i2c_adapter; /* */
+       struct i2c_algo_bit_data i2c_algo;      /* */
+       u32 i2cbr;
+
+       struct i2c_client *decoder;     /* video decoder i2c client */
+       struct i2c_client *encoder;     /* video encoder i2c client */
+
+       struct videocodec *codec;       /* video codec */
+       struct videocodec *vfe; /* video front end */
+
+       struct mutex resource_lock;     /* prevent evil stuff */
+
+       u8 initialized;         /* flag if zoran has been correctly initalized */
+       int user;               /* number of current users */
+       struct card_info card;
+       struct tvnorm *timing;
+
+       unsigned short id;      /* number of this device */
+       char name[32];          /* name of this device */
+       struct pci_dev *pci_dev;        /* PCI device */
+       unsigned char revision; /* revision of zr36057 */
+       unsigned int zr36057_adr;       /* bus address of IO mem returned by PCI BIOS */
+       unsigned char __iomem *zr36057_mem;/* pointer to mapped IO memory */
+
+       spinlock_t spinlock;    /* Spinlock */
+
+       /* Video for Linux parameters */
+       int input, norm;        /* card's norm and input - norm=VIDEO_MODE_* */
+       int hue, saturation, contrast, brightness;      /* Current picture params */
+       struct video_buffer buffer;     /* Current buffer params */
+       struct zoran_overlay_settings overlay_settings;
+       u32 *overlay_mask;      /* overlay mask */
+       enum zoran_lock_activity overlay_active;        /* feature currently in use? */
+
+       wait_queue_head_t v4l_capq;
+
+       int v4l_overlay_active; /* Overlay grab is activated */
+       int v4l_memgrab_active; /* Memory grab is activated */
+
+       int v4l_grab_frame;     /* Frame number being currently grabbed */
+#define NO_GRAB_ACTIVE (-1)
+       unsigned long v4l_grab_seq;     /* Number of frames grabbed */
+       struct zoran_v4l_settings v4l_settings; /* structure with a lot of things to play with */
+
+       /* V4L grab queue of frames pending */
+       unsigned long v4l_pend_head;
+       unsigned long v4l_pend_tail;
+       unsigned long v4l_sync_tail;
+       int v4l_pend[V4L_MAX_FRAME];
+       struct zoran_v4l_struct v4l_buffers;    /* V4L buffers' info */
+
+       /* Buz MJPEG parameters */
+       enum zoran_codec_mode codec_mode;       /* status of codec */
+       struct zoran_jpg_settings jpg_settings; /* structure with a lot of things to play with */
+
+       wait_queue_head_t jpg_capq;     /* wait here for grab to finish */
+
+       /* grab queue counts/indices, mask with BUZ_MASK_STAT_COM before using as index */
+       /* (dma_head - dma_tail) is number active in DMA, must be <= BUZ_NUM_STAT_COM */
+       /* (value & BUZ_MASK_STAT_COM) corresponds to index in stat_com table */
+       unsigned long jpg_que_head;     /* Index where to put next buffer which is queued */
+       unsigned long jpg_dma_head;     /* Index of next buffer which goes into stat_com  */
+       unsigned long jpg_dma_tail;     /* Index of last buffer in stat_com               */
+       unsigned long jpg_que_tail;     /* Index of last buffer in queue                  */
+       unsigned long jpg_seq_num;      /* count of frames since grab/play started        */
+       unsigned long jpg_err_seq;      /* last seq_num before error                      */
+       unsigned long jpg_err_shift;
+       unsigned long jpg_queued_num;   /* count of frames queued since grab/play started */
+
+       /* zr36057's code buffer table */
+       __le32 *stat_com;               /* stat_com[i] is indexed by dma_head/tail & BUZ_MASK_STAT_COM */
+
+       /* (value & BUZ_MASK_FRAME) corresponds to index in pend[] queue */
+       int jpg_pend[BUZ_MAX_FRAME];
+
+       /* array indexed by frame number */
+       struct zoran_jpg_struct jpg_buffers;    /* MJPEG buffers' info */
+
+       /* Additional stuff for testing */
+#ifdef CONFIG_PROC_FS
+       struct proc_dir_entry *zoran_proc;
+#else
+       void *zoran_proc;
+#endif
+       int testing;
+       int jpeg_error;
+       int intr_counter_GIRQ1;
+       int intr_counter_GIRQ0;
+       int intr_counter_CodRepIRQ;
+       int intr_counter_JPEGRepIRQ;
+       int field_counter;
+       int IRQ1_in;
+       int IRQ1_out;
+       int JPEG_in;
+       int JPEG_out;
+       int JPEG_0;
+       int JPEG_1;
+       int END_event_missed;
+       int JPEG_missed;
+       int JPEG_error;
+       int num_errors;
+       int JPEG_max_missed;
+       int JPEG_min_missed;
+
+       u32 last_isr;
+       unsigned long frame_num;
+
+       wait_queue_head_t test_q;
+};
+
+/*The following should be done in more portable way. It depends on define
+  of _ALPHA_BUZ in the Makefile.*/
+
+#ifdef _ALPHA_BUZ
+#define btwrite(dat,adr)    writel((dat), zr->zr36057_adr+(adr))
+#define btread(adr)         readl(zr->zr36057_adr+(adr))
+#else
+#define btwrite(dat,adr)    writel((dat), zr->zr36057_mem+(adr))
+#define btread(adr)         readl(zr->zr36057_mem+(adr))
+#endif
+
+#define btand(dat,adr)      btwrite((dat) & btread(adr), adr)
+#define btor(dat,adr)       btwrite((dat) | btread(adr), adr)
+#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
+
+#endif                         /* __kernel__ */
+
+#endif
diff --git a/drivers/media/video/zoran/zoran_card.c b/drivers/media/video/zoran/zoran_card.c
new file mode 100644 (file)
index 0000000..3282be7
--- /dev/null
@@ -0,0 +1,1670 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles card-specific data and detection
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/delay.h>
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/vmalloc.h>
+
+#include <linux/proc_fs.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/videodev.h>
+#include <media/v4l2-common.h>
+#include <linux/spinlock.h>
+#include <linux/sem.h>
+#include <linux/kmod.h>
+#include <linux/wait.h>
+
+#include <linux/pci.h>
+#include <linux/interrupt.h>
+#include <linux/video_decoder.h>
+#include <linux/video_encoder.h>
+#include <linux/mutex.h>
+
+#include <asm/io.h>
+
+#include "videocodec.h"
+#include "zoran.h"
+#include "zoran_card.h"
+#include "zoran_device.h"
+#include "zoran_procfs.h"
+
+extern const struct zoran_format zoran_formats[];
+
+static int card[BUZ_MAX] = { -1, -1, -1, -1 };
+module_param_array(card, int, NULL, 0444);
+MODULE_PARM_DESC(card, "The type of card");
+
+static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
+module_param_array(encoder, int, NULL, 0444);
+MODULE_PARM_DESC(encoder, "i2c TV encoder");
+
+static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
+module_param_array(decoder, int, NULL, 0444);
+MODULE_PARM_DESC(decoder, "i2c TV decoder");
+
+/*
+   The video mem address of the video card.
+   The driver has a little database for some videocards
+   to determine it from there. If your video card is not in there
+   you have either to give it to the driver as a parameter
+   or set in in a VIDIOCSFBUF ioctl
+ */
+
+static unsigned long vidmem;   /* default = 0 - Video memory base address */
+module_param(vidmem, ulong, 0444);
+MODULE_PARM_DESC(vidmem, "Default video memory base address");
+
+/*
+   Default input and video norm at startup of the driver.
+*/
+
+static unsigned int default_input;     /* default 0 = Composite, 1 = S-Video */
+module_param(default_input, uint, 0444);
+MODULE_PARM_DESC(default_input,
+                "Default input (0=Composite, 1=S-Video, 2=Internal)");
+
+static int default_mux = 1;    /* 6 Eyes input selection */
+module_param(default_mux, int, 0644);
+MODULE_PARM_DESC(default_mux,
+                "Default 6 Eyes mux setting (Input selection)");
+
+static int default_norm;       /* default 0 = PAL, 1 = NTSC 2 = SECAM */
+module_param(default_norm, int, 0444);
+MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
+
+/* /dev/videoN, -1 for autodetect */
+static int video_nr[BUZ_MAX] = {-1, -1, -1, -1};
+module_param_array(video_nr, int, NULL, 0444);
+MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
+
+/*
+   Number and size of grab buffers for Video 4 Linux
+   The vast majority of applications should not need more than 2,
+   the very popular BTTV driver actually does ONLY have 2.
+   Time sensitive applications might need more, the maximum
+   is VIDEO_MAX_FRAME (defined in <linux/videodev.h>).
+
+   The size is set so that the maximum possible request
+   can be satisfied. Decrease  it, if bigphys_area alloc'd
+   memory is low. If you don't have the bigphys_area patch,
+   set it to 128 KB. Will you allow only to grab small
+   images with V4L, but that's better than nothing.
+
+   v4l_bufsize has to be given in KB !
+
+*/
+
+int v4l_nbufs = 2;
+int v4l_bufsize = 128;         /* Everybody should be able to work with this setting */
+module_param(v4l_nbufs, int, 0644);
+MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
+module_param(v4l_bufsize, int, 0644);
+MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
+
+int jpg_nbufs = 32;
+int jpg_bufsize = 512;         /* max size for 100% quality full-PAL frame */
+module_param(jpg_nbufs, int, 0644);
+MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
+module_param(jpg_bufsize, int, 0644);
+MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
+
+int pass_through = 0;          /* 1=Pass through TV signal when device is not used */
+                               /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
+module_param(pass_through, int, 0644);
+MODULE_PARM_DESC(pass_through,
+                "Pass TV signal through to TV-out when idling");
+
+int zr36067_debug = 1;
+module_param_named(debug, zr36067_debug, int, 0644);
+MODULE_PARM_DESC(debug, "Debug level (0-5)");
+
+MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
+MODULE_AUTHOR("Serguei Miridonov");
+MODULE_LICENSE("GPL");
+
+static struct pci_device_id zr36067_pci_tbl[] = {
+       {PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057,
+        PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
+       {0}
+};
+MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
+
+int zoran_num;                 /* number of Buzs in use */
+struct zoran *zoran[BUZ_MAX];
+
+/* videocodec bus functions ZR36060 */
+static u32
+zr36060_read (struct videocodec *codec,
+             u16                reg)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+       __u32 data;
+
+       if (post_office_wait(zr)
+           || post_office_write(zr, 0, 1, reg >> 8)
+           || post_office_write(zr, 0, 2, reg & 0xff)) {
+               return -1;
+       }
+
+       data = post_office_read(zr, 0, 3) & 0xff;
+       return data;
+}
+
+static void
+zr36060_write (struct videocodec *codec,
+              u16                reg,
+              u32                val)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+
+       if (post_office_wait(zr)
+           || post_office_write(zr, 0, 1, reg >> 8)
+           || post_office_write(zr, 0, 2, reg & 0xff)) {
+               return;
+       }
+
+       post_office_write(zr, 0, 3, val & 0xff);
+}
+
+/* videocodec bus functions ZR36050 */
+static u32
+zr36050_read (struct videocodec *codec,
+             u16                reg)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+       __u32 data;
+
+       if (post_office_wait(zr)
+           || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
+               return -1;
+       }
+
+       data = post_office_read(zr, 0, reg & 0x03) & 0xff;      // reg. LOWBYTES + read
+       return data;
+}
+
+static void
+zr36050_write (struct videocodec *codec,
+              u16                reg,
+              u32                val)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+
+       if (post_office_wait(zr)
+           || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
+               return;
+       }
+
+       post_office_write(zr, 0, reg & 0x03, val & 0xff);       // reg. LOWBYTES + wr. data
+}
+
+/* videocodec bus functions ZR36016 */
+static u32
+zr36016_read (struct videocodec *codec,
+             u16                reg)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+       __u32 data;
+
+       if (post_office_wait(zr)) {
+               return -1;
+       }
+
+       data = post_office_read(zr, 2, reg & 0x03) & 0xff;      // read
+       return data;
+}
+
+/* hack for in zoran_device.c */
+void
+zr36016_write (struct videocodec *codec,
+              u16                reg,
+              u32                val)
+{
+       struct zoran *zr = (struct zoran *) codec->master_data->data;
+
+       if (post_office_wait(zr)) {
+               return;
+       }
+
+       post_office_write(zr, 2, reg & 0x03, val & 0x0ff);      // wr. data
+}
+
+/*
+ * Board specific information
+ */
+
+static void
+dc10_init (struct zoran *zr)
+{
+       dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr));
+
+       /* Pixel clock selection */
+       GPIO(zr, 4, 0);
+       GPIO(zr, 5, 1);
+       /* Enable the video bus sync signals */
+       GPIO(zr, 7, 0);
+}
+
+static void
+dc10plus_init (struct zoran *zr)
+{
+       dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr));
+}
+
+static void
+buz_init (struct zoran *zr)
+{
+       dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr));
+
+       /* some stuff from Iomega */
+       pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
+       pci_write_config_dword(zr->pci_dev, 0x0c, 0x00012020);
+       pci_write_config_dword(zr->pci_dev, 0xe8, 0xc0200000);
+}
+
+static void
+lml33_init (struct zoran *zr)
+{
+       dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr));
+
+       GPIO(zr, 2, 1);         // Set Composite input/output
+}
+
+static void
+avs6eyes_init (struct zoran *zr)
+{
+       // AverMedia 6-Eyes original driver by Christer Weinigel
+
+       // Lifted straight from Christer's old driver and
+       // modified slightly by Martin Samuelsson.
+
+       int mux = default_mux; /* 1 = BT866, 7 = VID1 */
+
+       GPIO(zr, 4, 1); /* Bt866 SLEEP on */
+       udelay(2);
+
+       GPIO(zr, 0, 1); /* ZR36060 /RESET on */
+       GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
+       GPIO(zr, 2, mux & 1);   /* MUX S0 */
+       GPIO(zr, 3, 0); /* /FRAME on */
+       GPIO(zr, 4, 0); /* Bt866 SLEEP off */
+       GPIO(zr, 5, mux & 2);   /* MUX S1 */
+       GPIO(zr, 6, 0); /* ? */
+       GPIO(zr, 7, mux & 4);   /* MUX S2 */
+
+}
+
+static char *
+i2cid_to_modulename (u16 i2c_id)
+{
+       char *name = NULL;
+
+       switch (i2c_id) {
+       case I2C_DRIVERID_SAA7110:
+               name = "saa7110";
+               break;
+       case I2C_DRIVERID_SAA7111A:
+               name = "saa7111";
+               break;
+       case I2C_DRIVERID_SAA7114:
+               name = "saa7114";
+               break;
+       case I2C_DRIVERID_SAA7185B:
+               name = "saa7185";
+               break;
+       case I2C_DRIVERID_ADV7170:
+               name = "adv7170";
+               break;
+       case I2C_DRIVERID_ADV7175:
+               name = "adv7175";
+               break;
+       case I2C_DRIVERID_BT819:
+               name = "bt819";
+               break;
+       case I2C_DRIVERID_BT856:
+               name = "bt856";
+               break;
+       case I2C_DRIVERID_BT866:
+               name = "bt866";
+               break;
+       case I2C_DRIVERID_VPX3220:
+               name = "vpx3220";
+               break;
+       case I2C_DRIVERID_KS0127:
+               name = "ks0127";
+               break;
+       }
+
+       return name;
+}
+
+static char *
+codecid_to_modulename (u16 codecid)
+{
+       char *name = NULL;
+
+       switch (codecid) {
+       case CODEC_TYPE_ZR36060:
+               name = "zr36060";
+               break;
+       case CODEC_TYPE_ZR36050:
+               name = "zr36050";
+               break;
+       case CODEC_TYPE_ZR36016:
+               name = "zr36016";
+               break;
+       }
+
+       return name;
+}
+
+// struct tvnorm {
+//      u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
+// };
+
+static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
+static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
+static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
+
+static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
+
+/* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
+static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
+static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
+
+/* FIXME: I cannot swap U and V in saa7114, so i do one
+ * pixel left shift in zoran (75 -> 74)
+ * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
+static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
+
+/* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
+ * copy Maxim's left shift hack for the 6 Eyes.
+ *
+ * Christer's driver used the unshifted norms, though...
+ * /Sam  */
+static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
+static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
+
+static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
+       {
+               .type = DC10_old,
+               .name = "DC10(old)",
+               .i2c_decoder = I2C_DRIVERID_VPX3220,
+               .video_codec = CODEC_TYPE_ZR36050,
+               .video_vfe = CODEC_TYPE_ZR36016,
+
+               .inputs = 3,
+               .input = {
+                       { 1, "Composite" },
+                       { 2, "S-Video" },
+                       { 0, "Internal/comp" }
+               },
+               .norms = 3,
+               .tvn = {
+                       &f50sqpixel_dc10,
+                       &f60sqpixel_dc10,
+                       &f50sqpixel_dc10
+               },
+               .jpeg_int = 0,
+               .vsync_int = ZR36057_ISR_GIRQ1,
+               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
+               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
+               .gpcs = { -1, 0 },
+               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gws_not_connected = 0,
+               .input_mux = 0,
+               .init = &dc10_init,
+       }, {
+               .type = DC10_new,
+               .name = "DC10(new)",
+               .i2c_decoder = I2C_DRIVERID_SAA7110,
+               .i2c_encoder = I2C_DRIVERID_ADV7175,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 3,
+               .input = {
+                               { 0, "Composite" },
+                               { 7, "S-Video" },
+                               { 5, "Internal/comp" }
+                       },
+               .norms = 3,
+               .tvn = {
+                               &f50sqpixel,
+                               &f60sqpixel,
+                               &f50sqpixel},
+               .jpeg_int = ZR36057_ISR_GIRQ0,
+               .vsync_int = ZR36057_ISR_GIRQ1,
+               .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gpcs = { -1, 1},
+               .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
+               .gws_not_connected = 0,
+               .input_mux = 0,
+               .init = &dc10plus_init,
+       }, {
+               .type = DC10plus,
+               .name = "DC10plus",
+               .vendor_id = PCI_VENDOR_ID_MIRO,
+               .device_id = PCI_DEVICE_ID_MIRO_DC10PLUS,
+               .i2c_decoder = I2C_DRIVERID_SAA7110,
+               .i2c_encoder = I2C_DRIVERID_ADV7175,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 3,
+               .input = {
+                       { 0, "Composite" },
+                       { 7, "S-Video" },
+                       { 5, "Internal/comp" }
+               },
+               .norms = 3,
+               .tvn = {
+                       &f50sqpixel,
+                       &f60sqpixel,
+                       &f50sqpixel
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ0,
+               .vsync_int = ZR36057_ISR_GIRQ1,
+               .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gpcs = { -1, 1 },
+               .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
+               .gws_not_connected = 0,
+               .input_mux = 0,
+               .init = &dc10plus_init,
+       }, {
+               .type = DC30,
+               .name = "DC30",
+               .i2c_decoder = I2C_DRIVERID_VPX3220,
+               .i2c_encoder = I2C_DRIVERID_ADV7175,
+               .video_codec = CODEC_TYPE_ZR36050,
+               .video_vfe = CODEC_TYPE_ZR36016,
+
+               .inputs = 3,
+               .input = {
+                       { 1, "Composite" },
+                       { 2, "S-Video" },
+                       { 0, "Internal/comp" }
+               },
+               .norms = 3,
+               .tvn = {
+                       &f50sqpixel_dc10,
+                       &f60sqpixel_dc10,
+                       &f50sqpixel_dc10
+               },
+               .jpeg_int = 0,
+               .vsync_int = ZR36057_ISR_GIRQ1,
+               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
+               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
+               .gpcs = { -1, 0 },
+               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gws_not_connected = 0,
+               .input_mux = 0,
+               .init = &dc10_init,
+       }, {
+               .type = DC30plus,
+               .name = "DC30plus",
+               .vendor_id = PCI_VENDOR_ID_MIRO,
+               .device_id = PCI_DEVICE_ID_MIRO_DC30PLUS,
+               .i2c_decoder = I2C_DRIVERID_VPX3220,
+               .i2c_encoder = I2C_DRIVERID_ADV7175,
+               .video_codec = CODEC_TYPE_ZR36050,
+               .video_vfe = CODEC_TYPE_ZR36016,
+
+               .inputs = 3,
+               .input = {
+                       { 1, "Composite" },
+                       { 2, "S-Video" },
+                       { 0, "Internal/comp" }
+               },
+               .norms = 3,
+               .tvn = {
+                       &f50sqpixel_dc10,
+                       &f60sqpixel_dc10,
+                       &f50sqpixel_dc10
+               },
+               .jpeg_int = 0,
+               .vsync_int = ZR36057_ISR_GIRQ1,
+               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
+               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
+               .gpcs = { -1, 0 },
+               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gws_not_connected = 0,
+               .input_mux = 0,
+               .init = &dc10_init,
+       }, {
+               .type = LML33,
+               .name = "LML33",
+               .i2c_decoder = I2C_DRIVERID_BT819,
+               .i2c_encoder = I2C_DRIVERID_BT856,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 2,
+               .input = {
+                       { 0, "Composite" },
+                       { 7, "S-Video" }
+               },
+               .norms = 2,
+               .tvn = {
+                       &f50ccir601_lml33,
+                       &f60ccir601_lml33,
+                       NULL
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
+               .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
+               .gpcs = { 3, 1 },
+               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
+               .gws_not_connected = 1,
+               .input_mux = 0,
+               .init = &lml33_init,
+       }, {
+               .type = LML33R10,
+               .name = "LML33R10",
+               .vendor_id = PCI_VENDOR_ID_ELECTRONICDESIGNGMBH,
+               .device_id = PCI_DEVICE_ID_LML_33R10,
+               .i2c_decoder = I2C_DRIVERID_SAA7114,
+               .i2c_encoder = I2C_DRIVERID_ADV7170,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 2,
+               .input = {
+                       { 0, "Composite" },
+                       { 7, "S-Video" }
+               },
+               .norms = 2,
+               .tvn = {
+                       &f50ccir601_lm33r10,
+                       &f60ccir601_lm33r10,
+                       NULL
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
+               .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
+               .gpcs = { 3, 1 },
+               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
+               .gws_not_connected = 1,
+               .input_mux = 0,
+               .init = &lml33_init,
+       }, {
+               .type = BUZ,
+               .name = "Buz",
+               .vendor_id = PCI_VENDOR_ID_IOMEGA,
+               .device_id = PCI_DEVICE_ID_IOMEGA_BUZ,
+               .i2c_decoder = I2C_DRIVERID_SAA7111A,
+               .i2c_encoder = I2C_DRIVERID_SAA7185B,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 2,
+               .input = {
+                       { 3, "Composite" },
+                       { 7, "S-Video" }
+               },
+               .norms = 3,
+               .tvn = {
+                       &f50ccir601,
+                       &f60ccir601,
+                       &f50ccir601
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
+               .gpcs = { 3, 1 },
+               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
+               .gws_not_connected = 1,
+               .input_mux = 0,
+               .init = &buz_init,
+       }, {
+               .type = AVS6EYES,
+               .name = "6-Eyes",
+               /* AverMedia chose not to brand the 6-Eyes. Thus it
+                  can't be autodetected, and requires card=x. */
+               .vendor_id = -1,
+               .device_id = -1,
+               .i2c_decoder = I2C_DRIVERID_KS0127,
+               .i2c_encoder = I2C_DRIVERID_BT866,
+               .video_codec = CODEC_TYPE_ZR36060,
+
+               .inputs = 10,
+               .input = {
+                       { 0, "Composite 1" },
+                       { 1, "Composite 2" },
+                       { 2, "Composite 3" },
+                       { 4, "Composite 4" },
+                       { 5, "Composite 5" },
+                       { 6, "Composite 6" },
+                       { 8, "S-Video 1" },
+                       { 9, "S-Video 2" },
+                       {10, "S-Video 3" },
+                       {15, "YCbCr" }
+               },
+               .norms = 2,
+               .tvn = {
+                       &f50ccir601_avs6eyes,
+                       &f60ccir601_avs6eyes,
+                       NULL
+               },
+               .jpeg_int = ZR36057_ISR_GIRQ1,
+               .vsync_int = ZR36057_ISR_GIRQ0,
+               .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
+               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
+               .gpcs = { 3, 1 },                       // Validity unknown /Sam
+               .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 },  // Validity unknown /Sam
+               .gws_not_connected = 1,
+               .input_mux = 1,
+               .init = &avs6eyes_init,
+       }
+
+};
+
+/*
+ * I2C functions
+ */
+/* software I2C functions */
+static int
+zoran_i2c_getsda (void *data)
+{
+       struct zoran *zr = (struct zoran *) data;
+
+       return (btread(ZR36057_I2CBR) >> 1) & 1;
+}
+
+static int
+zoran_i2c_getscl (void *data)
+{
+       struct zoran *zr = (struct zoran *) data;
+
+       return btread(ZR36057_I2CBR) & 1;
+}
+
+static void
+zoran_i2c_setsda (void *data,
+                 int   state)
+{
+       struct zoran *zr = (struct zoran *) data;
+
+       if (state)
+               zr->i2cbr |= 2;
+       else
+               zr->i2cbr &= ~2;
+       btwrite(zr->i2cbr, ZR36057_I2CBR);
+}
+
+static void
+zoran_i2c_setscl (void *data,
+                 int   state)
+{
+       struct zoran *zr = (struct zoran *) data;
+
+       if (state)
+               zr->i2cbr |= 1;
+       else
+               zr->i2cbr &= ~1;
+       btwrite(zr->i2cbr, ZR36057_I2CBR);
+}
+
+static int
+zoran_i2c_client_register (struct i2c_client *client)
+{
+       struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
+       int res = 0;
+
+       dprintk(2,
+               KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
+               ZR_DEVNAME(zr), client->driver->id);
+
+       mutex_lock(&zr->resource_lock);
+
+       if (zr->user > 0) {
+               /* we're already busy, so we keep a reference to
+                * them... Could do a lot of stuff here, but this
+                * is easiest. (Did I ever mention I'm a lazy ass?)
+                */
+               res = -EBUSY;
+               goto clientreg_unlock_and_return;
+       }
+
+       if (client->driver->id == zr->card.i2c_decoder)
+               zr->decoder = client;
+       else if (client->driver->id == zr->card.i2c_encoder)
+               zr->encoder = client;
+       else {
+               res = -ENODEV;
+               goto clientreg_unlock_and_return;
+       }
+
+clientreg_unlock_and_return:
+       mutex_unlock(&zr->resource_lock);
+
+       return res;
+}
+
+static int
+zoran_i2c_client_unregister (struct i2c_client *client)
+{
+       struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
+       int res = 0;
+
+       dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
+
+       mutex_lock(&zr->resource_lock);
+
+       if (zr->user > 0) {
+               res = -EBUSY;
+               goto clientunreg_unlock_and_return;
+       }
+
+       /* try to locate it */
+       if (client == zr->encoder) {
+               zr->encoder = NULL;
+       } else if (client == zr->decoder) {
+               zr->decoder = NULL;
+               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
+       }
+clientunreg_unlock_and_return:
+       mutex_unlock(&zr->resource_lock);
+       return res;
+}
+
+static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
+       .setsda = zoran_i2c_setsda,
+       .setscl = zoran_i2c_setscl,
+       .getsda = zoran_i2c_getsda,
+       .getscl = zoran_i2c_getscl,
+       .udelay = 10,
+       .timeout = 100,
+};
+
+static int
+zoran_register_i2c (struct zoran *zr)
+{
+       memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
+              sizeof(struct i2c_algo_bit_data));
+       zr->i2c_algo.data = zr;
+       zr->i2c_adapter.id = I2C_HW_B_ZR36067;
+       zr->i2c_adapter.client_register = zoran_i2c_client_register;
+       zr->i2c_adapter.client_unregister = zoran_i2c_client_unregister;
+       strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
+               sizeof(zr->i2c_adapter.name));
+       i2c_set_adapdata(&zr->i2c_adapter, zr);
+       zr->i2c_adapter.algo_data = &zr->i2c_algo;
+       zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
+       return i2c_bit_add_bus(&zr->i2c_adapter);
+}
+
+static void
+zoran_unregister_i2c (struct zoran *zr)
+{
+       i2c_del_adapter(&zr->i2c_adapter);
+}
+
+/* Check a zoran_params struct for correctness, insert default params */
+
+int
+zoran_check_jpg_settings (struct zoran              *zr,
+                         struct zoran_jpg_settings *settings)
+{
+       int err = 0, err0 = 0;
+
+       dprintk(4,
+               KERN_DEBUG
+               "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
+               ZR_DEVNAME(zr), settings->decimation, settings->HorDcm,
+               settings->VerDcm, settings->TmpDcm);
+       dprintk(4,
+               KERN_DEBUG
+               "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n",
+               ZR_DEVNAME(zr), settings->img_x, settings->img_y,
+               settings->img_width, settings->img_height);
+       /* Check decimation, set default values for decimation = 1, 2, 4 */
+       switch (settings->decimation) {
+       case 1:
+
+               settings->HorDcm = 1;
+               settings->VerDcm = 1;
+               settings->TmpDcm = 1;
+               settings->field_per_buff = 2;
+               settings->img_x = 0;
+               settings->img_y = 0;
+               settings->img_width = BUZ_MAX_WIDTH;
+               settings->img_height = BUZ_MAX_HEIGHT / 2;
+               break;
+       case 2:
+
+               settings->HorDcm = 2;
+               settings->VerDcm = 1;
+               settings->TmpDcm = 2;
+               settings->field_per_buff = 1;
+               settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
+               settings->img_y = 0;
+               settings->img_width =
+                   (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
+               settings->img_height = BUZ_MAX_HEIGHT / 2;
+               break;
+       case 4:
+
+               if (zr->card.type == DC10_new) {
+                       dprintk(1,
+                               KERN_DEBUG
+                               "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n",
+                               ZR_DEVNAME(zr));
+                       err0++;
+                       break;
+               }
+
+               settings->HorDcm = 4;
+               settings->VerDcm = 2;
+               settings->TmpDcm = 2;
+               settings->field_per_buff = 1;
+               settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
+               settings->img_y = 0;
+               settings->img_width =
+                   (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
+               settings->img_height = BUZ_MAX_HEIGHT / 2;
+               break;
+       case 0:
+
+               /* We have to check the data the user has set */
+
+               if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
+                   (zr->card.type == DC10_new || settings->HorDcm != 4))
+                       err0++;
+               if (settings->VerDcm != 1 && settings->VerDcm != 2)
+                       err0++;
+               if (settings->TmpDcm != 1 && settings->TmpDcm != 2)
+                       err0++;
+               if (settings->field_per_buff != 1 &&
+                   settings->field_per_buff != 2)
+                       err0++;
+               if (settings->img_x < 0)
+                       err0++;
+               if (settings->img_y < 0)
+                       err0++;
+               if (settings->img_width < 0)
+                       err0++;
+               if (settings->img_height < 0)
+                       err0++;
+               if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH)
+                       err0++;
+               if (settings->img_y + settings->img_height >
+                   BUZ_MAX_HEIGHT / 2)
+                       err0++;
+               if (settings->HorDcm && settings->VerDcm) {
+                       if (settings->img_width %
+                           (16 * settings->HorDcm) != 0)
+                               err0++;
+                       if (settings->img_height %
+                           (8 * settings->VerDcm) != 0)
+                               err0++;
+               }
+
+               if (err0) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: check_jpg_settings() - error in params for decimation = 0\n",
+                               ZR_DEVNAME(zr));
+                       err++;
+               }
+               break;
+       default:
+               dprintk(1,
+                       KERN_ERR
+                       "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n",
+                       ZR_DEVNAME(zr), settings->decimation);
+               err++;
+               break;
+       }
+
+       if (settings->jpg_comp.quality > 100)
+               settings->jpg_comp.quality = 100;
+       if (settings->jpg_comp.quality < 5)
+               settings->jpg_comp.quality = 5;
+       if (settings->jpg_comp.APPn < 0)
+               settings->jpg_comp.APPn = 0;
+       if (settings->jpg_comp.APPn > 15)
+               settings->jpg_comp.APPn = 15;
+       if (settings->jpg_comp.APP_len < 0)
+               settings->jpg_comp.APP_len = 0;
+       if (settings->jpg_comp.APP_len > 60)
+               settings->jpg_comp.APP_len = 60;
+       if (settings->jpg_comp.COM_len < 0)
+               settings->jpg_comp.COM_len = 0;
+       if (settings->jpg_comp.COM_len > 60)
+               settings->jpg_comp.COM_len = 60;
+       if (err)
+               return -EINVAL;
+       return 0;
+}
+
+void
+zoran_open_init_params (struct zoran *zr)
+{
+       int i;
+
+       /* User must explicitly set a window */
+       zr->overlay_settings.is_set = 0;
+       zr->overlay_mask = NULL;
+       zr->overlay_active = ZORAN_FREE;
+
+       zr->v4l_memgrab_active = 0;
+       zr->v4l_overlay_active = 0;
+       zr->v4l_grab_frame = NO_GRAB_ACTIVE;
+       zr->v4l_grab_seq = 0;
+       zr->v4l_settings.width = 192;
+       zr->v4l_settings.height = 144;
+       zr->v4l_settings.format = &zoran_formats[7];    /* YUY2 - YUV-4:2:2 packed */
+       zr->v4l_settings.bytesperline =
+           zr->v4l_settings.width *
+           ((zr->v4l_settings.format->depth + 7) / 8);
+
+       /* DMA ring stuff for V4L */
+       zr->v4l_pend_tail = 0;
+       zr->v4l_pend_head = 0;
+       zr->v4l_sync_tail = 0;
+       zr->v4l_buffers.active = ZORAN_FREE;
+       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+               zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
+       }
+       zr->v4l_buffers.allocated = 0;
+
+       for (i = 0; i < BUZ_MAX_FRAME; i++) {
+               zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
+       }
+       zr->jpg_buffers.active = ZORAN_FREE;
+       zr->jpg_buffers.allocated = 0;
+       /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
+       zr->jpg_settings.decimation = 1;
+       zr->jpg_settings.jpg_comp.quality = 50; /* default compression factor 8 */
+       if (zr->card.type != BUZ)
+               zr->jpg_settings.odd_even = 1;
+       else
+               zr->jpg_settings.odd_even = 0;
+       zr->jpg_settings.jpg_comp.APPn = 0;
+       zr->jpg_settings.jpg_comp.APP_len = 0;  /* No APPn marker */
+       memset(zr->jpg_settings.jpg_comp.APP_data, 0,
+              sizeof(zr->jpg_settings.jpg_comp.APP_data));
+       zr->jpg_settings.jpg_comp.COM_len = 0;  /* No COM marker */
+       memset(zr->jpg_settings.jpg_comp.COM_data, 0,
+              sizeof(zr->jpg_settings.jpg_comp.COM_data));
+       zr->jpg_settings.jpg_comp.jpeg_markers =
+           JPEG_MARKER_DHT | JPEG_MARKER_DQT;
+       i = zoran_check_jpg_settings(zr, &zr->jpg_settings);
+       if (i)
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_open_init_params() internal error\n",
+                       ZR_DEVNAME(zr));
+
+       clear_interrupt_counters(zr);
+       zr->testing = 0;
+}
+
+static void __devinit
+test_interrupts (struct zoran *zr)
+{
+       DEFINE_WAIT(wait);
+       int timeout, icr;
+
+       clear_interrupt_counters(zr);
+
+       zr->testing = 1;
+       icr = btread(ZR36057_ICR);
+       btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
+       prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
+       timeout = schedule_timeout(HZ);
+       finish_wait(&zr->test_q, &wait);
+       btwrite(0, ZR36057_ICR);
+       btwrite(0x78000000, ZR36057_ISR);
+       zr->testing = 0;
+       dprintk(5, KERN_INFO "%s: Testing interrupts...\n", ZR_DEVNAME(zr));
+       if (timeout) {
+               dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
+       }
+       if (zr36067_debug > 1)
+               print_interrupts(zr);
+       btwrite(icr, ZR36057_ICR);
+}
+
+static int __devinit
+zr36057_init (struct zoran *zr)
+{
+       int j, err;
+       int two = 2;
+       int zero = 0;
+
+       dprintk(1,
+               KERN_INFO
+               "%s: zr36057_init() - initializing card[%d], zr=%p\n",
+               ZR_DEVNAME(zr), zr->id, zr);
+
+       /* default setup of all parameters which will persist between opens */
+       zr->user = 0;
+
+       init_waitqueue_head(&zr->v4l_capq);
+       init_waitqueue_head(&zr->jpg_capq);
+       init_waitqueue_head(&zr->test_q);
+       zr->jpg_buffers.allocated = 0;
+       zr->v4l_buffers.allocated = 0;
+
+       zr->buffer.base = (void *) vidmem;
+       zr->buffer.width = 0;
+       zr->buffer.height = 0;
+       zr->buffer.depth = 0;
+       zr->buffer.bytesperline = 0;
+
+       /* Avoid nonsense settings from user for default input/norm */
+       if (default_norm < VIDEO_MODE_PAL &&
+           default_norm > VIDEO_MODE_SECAM)
+               default_norm = VIDEO_MODE_PAL;
+       zr->norm = default_norm;
+       if (!(zr->timing = zr->card.tvn[zr->norm])) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n",
+                       ZR_DEVNAME(zr));
+               zr->norm = VIDEO_MODE_PAL;
+               zr->timing = zr->card.tvn[zr->norm];
+       }
+
+       if (default_input > zr->card.inputs-1) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: default_input value %d out of range (0-%d)\n",
+                       ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
+               default_input = 0;
+       }
+       zr->input = default_input;
+
+       /* Should the following be reset at every open ? */
+       zr->hue = 32768;
+       zr->contrast = 32768;
+       zr->saturation = 32768;
+       zr->brightness = 32768;
+
+       /* default setup (will be repeated at every open) */
+       zoran_open_init_params(zr);
+
+       /* allocate memory *before* doing anything to the hardware
+        * in case allocation fails */
+       zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
+       zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
+       if (!zr->stat_com || !zr->video_dev) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
+                       ZR_DEVNAME(zr));
+               err = -ENOMEM;
+               goto exit_free;
+       }
+       for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
+               zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
+       }
+
+       /*
+        *   Now add the template and register the device unit.
+        */
+       memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
+       strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
+       err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
+       if (err < 0)
+               goto exit_unregister;
+
+       zoran_init_hardware(zr);
+       if (zr36067_debug > 2)
+               detect_guest_activity(zr);
+       test_interrupts(zr);
+       if (!pass_through) {
+               decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
+               encoder_command(zr, ENCODER_SET_INPUT, &two);
+       }
+
+       zr->zoran_proc = NULL;
+       zr->initialized = 1;
+       return 0;
+
+exit_unregister:
+       zoran_unregister_i2c(zr);
+exit_free:
+       kfree(zr->stat_com);
+       kfree(zr->video_dev);
+       return err;
+}
+
+static void
+zoran_release (struct zoran *zr)
+{
+       if (!zr->initialized)
+               goto exit_free;
+       /* unregister videocodec bus */
+       if (zr->codec) {
+               struct videocodec_master *master = zr->codec->master_data;
+
+               videocodec_detach(zr->codec);
+               kfree(master);
+       }
+       if (zr->vfe) {
+               struct videocodec_master *master = zr->vfe->master_data;
+
+               videocodec_detach(zr->vfe);
+               kfree(master);
+       }
+
+       /* unregister i2c bus */
+       zoran_unregister_i2c(zr);
+       /* disable PCI bus-mastering */
+       zoran_set_pci_master(zr, 0);
+       /* put chip into reset */
+       btwrite(0, ZR36057_SPGPPCR);
+       free_irq(zr->pci_dev->irq, zr);
+       /* unmap and free memory */
+       kfree(zr->stat_com);
+       zoran_proc_cleanup(zr);
+       iounmap(zr->zr36057_mem);
+       pci_disable_device(zr->pci_dev);
+       video_unregister_device(zr->video_dev);
+exit_free:
+       kfree(zr);
+}
+
+void
+zoran_vdev_release (struct video_device *vdev)
+{
+       kfree(vdev);
+}
+
+static struct videocodec_master * __devinit
+zoran_setup_videocodec (struct zoran *zr,
+                       int           type)
+{
+       struct videocodec_master *m = NULL;
+
+       m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
+       if (!m) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_setup_videocodec() - no memory\n",
+                       ZR_DEVNAME(zr));
+               return m;
+       }
+
+       /* magic and type are unused for master struct. Makes sense only at
+          codec structs.
+          In the past, .type were initialized to the old V4L1 .hardware
+          value, as VID_HARDWARE_ZR36067
+        */
+       m->magic = 0L;
+       m->type = 0;
+
+       m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
+       strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
+       m->data = zr;
+
+       switch (type)
+       {
+       case CODEC_TYPE_ZR36060:
+               m->readreg = zr36060_read;
+               m->writereg = zr36060_write;
+               m->flags |= CODEC_FLAG_JPEG | CODEC_FLAG_VFE;
+               break;
+       case CODEC_TYPE_ZR36050:
+               m->readreg = zr36050_read;
+               m->writereg = zr36050_write;
+               m->flags |= CODEC_FLAG_JPEG;
+               break;
+       case CODEC_TYPE_ZR36016:
+               m->readreg = zr36016_read;
+               m->writereg = zr36016_write;
+               m->flags |= CODEC_FLAG_VFE;
+               break;
+       }
+
+       return m;
+}
+
+/*
+ *   Scan for a Buz card (actually for the PCI controller ZR36057),
+ *   request the irq and map the io memory
+ */
+static int __devinit
+find_zr36057 (void)
+{
+       unsigned char latency, need_latency;
+       struct zoran *zr;
+       struct pci_dev *dev = NULL;
+       int result;
+       struct videocodec_master *master_vfe = NULL;
+       struct videocodec_master *master_codec = NULL;
+       int card_num;
+       char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name;
+
+       zoran_num = 0;
+       while (zoran_num < BUZ_MAX &&
+              (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
+               card_num = card[zoran_num];
+               zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
+               if (!zr) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: find_zr36057() - kzalloc failed\n",
+                               ZORAN_NAME);
+                       continue;
+               }
+               zr->pci_dev = dev;
+               //zr->zr36057_mem = NULL;
+               zr->id = zoran_num;
+               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
+               spin_lock_init(&zr->spinlock);
+               mutex_init(&zr->resource_lock);
+               if (pci_enable_device(dev))
+                       goto zr_free_mem;
+               zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
+               pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION,
+                                    &zr->revision);
+               if (zr->revision < 2) {
+                       dprintk(1,
+                               KERN_INFO
+                               "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n",
+                               ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
+                               zr->zr36057_adr);
+
+                       if (card_num == -1) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - no card specified, please use the card=X insmod option\n",
+                                       ZR_DEVNAME(zr));
+                               goto zr_free_mem;
+                       }
+               } else {
+                       int i;
+                       unsigned short ss_vendor, ss_device;
+
+                       ss_vendor = zr->pci_dev->subsystem_vendor;
+                       ss_device = zr->pci_dev->subsystem_device;
+                       dprintk(1,
+                               KERN_INFO
+                               "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n",
+                               ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
+                               zr->zr36057_adr);
+                       dprintk(1,
+                               KERN_INFO
+                               "%s: subsystem vendor=0x%04x id=0x%04x\n",
+                               ZR_DEVNAME(zr), ss_vendor, ss_device);
+                       if (card_num == -1) {
+                               dprintk(3,
+                                       KERN_DEBUG
+                                       "%s: find_zr36057() - trying to autodetect card type\n",
+                                       ZR_DEVNAME(zr));
+                               for (i=0;i<NUM_CARDS;i++) {
+                                       if (ss_vendor == zoran_cards[i].vendor_id &&
+                                           ss_device == zoran_cards[i].device_id) {
+                                               dprintk(3,
+                                                       KERN_DEBUG
+                                                       "%s: find_zr36057() - card %s detected\n",
+                                                       ZR_DEVNAME(zr),
+                                                       zoran_cards[i].name);
+                                               card_num = i;
+                                               break;
+                                       }
+                               }
+                               if (i == NUM_CARDS) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: find_zr36057() - unknown card\n",
+                                               ZR_DEVNAME(zr));
+                                       goto zr_free_mem;
+                               }
+                       }
+               }
+
+               if (card_num < 0 || card_num >= NUM_CARDS) {
+                       dprintk(2,
+                               KERN_ERR
+                               "%s: find_zr36057() - invalid cardnum %d\n",
+                               ZR_DEVNAME(zr), card_num);
+                       goto zr_free_mem;
+               }
+
+               /* even though we make this a non pointer and thus
+                * theoretically allow for making changes to this struct
+                * on a per-individual card basis at runtime, this is
+                * strongly discouraged. This structure is intended to
+                * keep general card information, no settings or anything */
+               zr->card = zoran_cards[card_num];
+               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
+                        "%s[%u]", zr->card.name, zr->id);
+
+               zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000);
+               if (!zr->zr36057_mem) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: find_zr36057() - ioremap failed\n",
+                               ZR_DEVNAME(zr));
+                       goto zr_free_mem;
+               }
+
+               result = request_irq(zr->pci_dev->irq,
+                                    zoran_irq,
+                                    IRQF_SHARED | IRQF_DISABLED,
+                                    ZR_DEVNAME(zr),
+                                    (void *) zr);
+               if (result < 0) {
+                       if (result == -EINVAL) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - bad irq number or handler\n",
+                                       ZR_DEVNAME(zr));
+                       } else if (result == -EBUSY) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
+                                       ZR_DEVNAME(zr), zr->pci_dev->irq);
+                       } else {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - can't assign irq, error code %d\n",
+                                       ZR_DEVNAME(zr), result);
+                       }
+                       goto zr_unmap;
+               }
+
+               /* set PCI latency timer */
+               pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
+                                    &latency);
+               need_latency = zr->revision > 1 ? 32 : 48;
+               if (latency != need_latency) {
+                       dprintk(2,
+                               KERN_INFO
+                               "%s: Changing PCI latency from %d to %d.\n",
+                               ZR_DEVNAME(zr), latency, need_latency);
+                       pci_write_config_byte(zr->pci_dev,
+                                             PCI_LATENCY_TIMER,
+                                             need_latency);
+               }
+
+               zr36057_restart(zr);
+               /* i2c */
+               dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
+                       ZR_DEVNAME(zr));
+
+               /* i2c decoder */
+               if (decoder[zr->id] != -1) {
+                       i2c_dec_name = i2cid_to_modulename(decoder[zr->id]);
+                       zr->card.i2c_decoder = decoder[zr->id];
+               } else if (zr->card.i2c_decoder != 0) {
+                       i2c_dec_name =
+                               i2cid_to_modulename(zr->card.i2c_decoder);
+               } else {
+                       i2c_dec_name = NULL;
+               }
+
+               if (i2c_dec_name) {
+                       if ((result = request_module(i2c_dec_name)) < 0) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: failed to load module %s: %d\n",
+                                       ZR_DEVNAME(zr), i2c_dec_name, result);
+                       }
+               }
+
+               /* i2c encoder */
+               if (encoder[zr->id] != -1) {
+                       i2c_enc_name = i2cid_to_modulename(encoder[zr->id]);
+                       zr->card.i2c_encoder = encoder[zr->id];
+               } else if (zr->card.i2c_encoder != 0) {
+                       i2c_enc_name =
+                               i2cid_to_modulename(zr->card.i2c_encoder);
+               } else {
+                       i2c_enc_name = NULL;
+               }
+
+               if (i2c_enc_name) {
+                       if ((result = request_module(i2c_enc_name)) < 0) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: failed to load module %s: %d\n",
+                                       ZR_DEVNAME(zr), i2c_enc_name, result);
+                       }
+               }
+
+               if (zoran_register_i2c(zr) < 0) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: find_zr36057() - can't initialize i2c bus\n",
+                               ZR_DEVNAME(zr));
+                       goto zr_free_irq;
+               }
+
+               dprintk(2,
+                       KERN_INFO "%s: Initializing videocodec bus...\n",
+                       ZR_DEVNAME(zr));
+
+               if (zr->card.video_codec != 0 &&
+                   (codec_name =
+                    codecid_to_modulename(zr->card.video_codec)) != NULL) {
+                       if ((result = request_module(codec_name)) < 0) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: failed to load modules %s: %d\n",
+                                       ZR_DEVNAME(zr), codec_name, result);
+                       }
+               }
+               if (zr->card.video_vfe != 0 &&
+                   (vfe_name =
+                    codecid_to_modulename(zr->card.video_vfe)) != NULL) {
+                       if ((result = request_module(vfe_name)) < 0) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: failed to load modules %s: %d\n",
+                                       ZR_DEVNAME(zr), vfe_name, result);
+                       }
+               }
+
+               /* reset JPEG codec */
+               jpeg_codec_sleep(zr, 1);
+               jpeg_codec_reset(zr);
+               /* video bus enabled */
+               /* display codec revision */
+               if (zr->card.video_codec != 0) {
+                       master_codec = zoran_setup_videocodec(zr,
+                                                             zr->card.video_codec);
+                       if (!master_codec)
+                               goto zr_unreg_i2c;
+                       zr->codec = videocodec_attach(master_codec);
+                       if (!zr->codec) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - no codec found\n",
+                                       ZR_DEVNAME(zr));
+                               goto zr_free_codec;
+                       }
+                       if (zr->codec->type != zr->card.video_codec) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - wrong codec\n",
+                                       ZR_DEVNAME(zr));
+                               goto zr_detach_codec;
+                       }
+               }
+               if (zr->card.video_vfe != 0) {
+                       master_vfe = zoran_setup_videocodec(zr,
+                                                           zr->card.video_vfe);
+                       if (!master_vfe)
+                               goto zr_detach_codec;
+                       zr->vfe = videocodec_attach(master_vfe);
+                       if (!zr->vfe) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() - no VFE found\n",
+                                       ZR_DEVNAME(zr));
+                               goto zr_free_vfe;
+                       }
+                       if (zr->vfe->type != zr->card.video_vfe) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: find_zr36057() = wrong VFE\n",
+                                       ZR_DEVNAME(zr));
+                               goto zr_detach_vfe;
+                       }
+               }
+               /* Success so keep the pci_dev referenced */
+               pci_dev_get(zr->pci_dev);
+               zoran[zoran_num++] = zr;
+               continue;
+
+               // Init errors
+             zr_detach_vfe:
+               videocodec_detach(zr->vfe);
+             zr_free_vfe:
+               kfree(master_vfe);
+             zr_detach_codec:
+               videocodec_detach(zr->codec);
+             zr_free_codec:
+               kfree(master_codec);
+             zr_unreg_i2c:
+               zoran_unregister_i2c(zr);
+             zr_free_irq:
+               btwrite(0, ZR36057_SPGPPCR);
+               free_irq(zr->pci_dev->irq, zr);
+             zr_unmap:
+               iounmap(zr->zr36057_mem);
+             zr_free_mem:
+               kfree(zr);
+               continue;
+       }
+       if (dev)        /* Clean up ref count on early exit */
+               pci_dev_put(dev);
+
+       if (zoran_num == 0) {
+               dprintk(1, KERN_INFO "No known MJPEG cards found.\n");
+       }
+       return zoran_num;
+}
+
+static int __init
+init_dc10_cards (void)
+{
+       int i;
+
+       memset(zoran, 0, sizeof(zoran));
+       printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
+              MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
+
+       /* Look for cards */
+       if (find_zr36057() < 0) {
+               return -EIO;
+       }
+       if (zoran_num == 0)
+               return -ENODEV;
+       dprintk(1, KERN_INFO "%s: %d card(s) found\n", ZORAN_NAME,
+               zoran_num);
+       /* check the parameters we have been given, adjust if necessary */
+       if (v4l_nbufs < 2)
+               v4l_nbufs = 2;
+       if (v4l_nbufs > VIDEO_MAX_FRAME)
+               v4l_nbufs = VIDEO_MAX_FRAME;
+       /* The user specfies the in KB, we want them in byte
+        * (and page aligned) */
+       v4l_bufsize = PAGE_ALIGN(v4l_bufsize * 1024);
+       if (v4l_bufsize < 32768)
+               v4l_bufsize = 32768;
+       /* 2 MB is arbitrary but sufficient for the maximum possible images */
+       if (v4l_bufsize > 2048 * 1024)
+               v4l_bufsize = 2048 * 1024;
+       if (jpg_nbufs < 4)
+               jpg_nbufs = 4;
+       if (jpg_nbufs > BUZ_MAX_FRAME)
+               jpg_nbufs = BUZ_MAX_FRAME;
+       jpg_bufsize = PAGE_ALIGN(jpg_bufsize * 1024);
+       if (jpg_bufsize < 8192)
+               jpg_bufsize = 8192;
+       if (jpg_bufsize > (512 * 1024))
+               jpg_bufsize = 512 * 1024;
+       /* Use parameter for vidmem or try to find a video card */
+       if (vidmem) {
+               dprintk(1,
+                       KERN_INFO
+                       "%s: Using supplied video memory base address @ 0x%lx\n",
+                       ZORAN_NAME, vidmem);
+       }
+
+       /* random nonsense */
+       dprintk(6, KERN_DEBUG "Jotti is een held!\n");
+
+       /* some mainboards might not do PCI-PCI data transfer well */
+       if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: chipset does not support reliable PCI-PCI DMA\n",
+                       ZORAN_NAME);
+       }
+
+       /* take care of Natoma chipset and a revision 1 zr36057 */
+       for (i = 0; i < zoran_num; i++) {
+               struct zoran *zr = zoran[i];
+
+               if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
+                       zr->jpg_buffers.need_contiguous = 1;
+                       dprintk(1,
+                               KERN_INFO
+                               "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
+                               ZR_DEVNAME(zr));
+               }
+
+               if (zr36057_init(zr) < 0) {
+                       for (i = 0; i < zoran_num; i++)
+                               zoran_release(zoran[i]);
+                       return -EIO;
+               }
+               zoran_proc_init(zr);
+       }
+
+       return 0;
+}
+
+static void __exit
+unload_dc10_cards (void)
+{
+       int i;
+
+       for (i = 0; i < zoran_num; i++)
+               zoran_release(zoran[i]);
+}
+
+module_init(init_dc10_cards);
+module_exit(unload_dc10_cards);
diff --git a/drivers/media/video/zoran/zoran_card.h b/drivers/media/video/zoran/zoran_card.h
new file mode 100644 (file)
index 0000000..e4dc9d2
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles card-specific data and detection
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __ZORAN_CARD_H__
+#define __ZORAN_CARD_H__
+
+extern int zr36067_debug;
+
+#define dprintk(num, format, args...) \
+       do { \
+               if (zr36067_debug >= num) \
+                       printk(format, ##args); \
+       } while (0)
+
+/* Anybody who uses more than four? */
+#define BUZ_MAX 4
+extern int zoran_num;
+extern struct zoran *zoran[BUZ_MAX];
+
+extern struct video_device zoran_template;
+
+extern int zoran_check_jpg_settings(struct zoran *zr,
+                                   struct zoran_jpg_settings *settings);
+extern void zoran_open_init_params(struct zoran *zr);
+extern void zoran_vdev_release(struct video_device *vdev);
+
+void zr36016_write(struct videocodec *codec, u16 reg, u32 val);
+
+#endif                         /* __ZORAN_CARD_H__ */
diff --git a/drivers/media/video/zoran/zoran_device.c b/drivers/media/video/zoran/zoran_device.c
new file mode 100644 (file)
index 0000000..5d948ff
--- /dev/null
@@ -0,0 +1,1747 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles device access (PCI/I2C/codec/...)
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+
+#include <linux/interrupt.h>
+#include <linux/proc_fs.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/videodev.h>
+#include <linux/spinlock.h>
+#include <linux/sem.h>
+
+#include <linux/pci.h>
+#include <linux/video_decoder.h>
+#include <linux/video_encoder.h>
+#include <linux/delay.h>
+#include <linux/wait.h>
+
+#include <asm/byteorder.h>
+#include <asm/io.h>
+
+#include "videocodec.h"
+#include "zoran.h"
+#include "zoran_device.h"
+#include "zoran_card.h"
+
+#define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
+                  ZR36057_ISR_GIRQ1 | \
+                  ZR36057_ISR_JPEGRepIRQ )
+
+static int lml33dpath;         /* default = 0
+                                * 1 will use digital path in capture
+                                * mode instead of analog. It can be
+                                * used for picture adjustments using
+                                * tool like xawtv while watching image
+                                * on TV monitor connected to the output.
+                                * However, due to absence of 75 Ohm
+                                * load on Bt819 input, there will be
+                                * some image imperfections */
+
+module_param(lml33dpath, bool, 0644);
+MODULE_PARM_DESC(lml33dpath,
+                "Use digital path capture mode (on LML33 cards)");
+
+static void
+zr36057_init_vfe (struct zoran *zr);
+
+/*
+ * General Purpose I/O and Guest bus access
+ */
+
+/*
+ * This is a bit tricky. When a board lacks a GPIO function, the corresponding
+ * GPIO bit number in the card_info structure is set to 0.
+ */
+
+void
+GPIO (struct zoran *zr,
+      int           bit,
+      unsigned int  value)
+{
+       u32 reg;
+       u32 mask;
+
+       /* Make sure the bit number is legal
+        * A bit number of -1 (lacking) gives a mask of 0,
+        * making it harmless */
+       mask = (1 << (24 + bit)) & 0xff000000;
+       reg = btread(ZR36057_GPPGCR1) & ~mask;
+       if (value) {
+               reg |= mask;
+       }
+       btwrite(reg, ZR36057_GPPGCR1);
+       udelay(1);
+}
+
+/*
+ * Wait til post office is no longer busy
+ */
+
+int
+post_office_wait (struct zoran *zr)
+{
+       u32 por;
+
+//      while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
+       while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
+               /* wait for something to happen */
+       }
+       if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
+               /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
+               dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
+                       por);
+               return -1;
+       }
+
+       return 0;
+}
+
+int
+post_office_write (struct zoran *zr,
+                  unsigned int  guest,
+                  unsigned int  reg,
+                  unsigned int  value)
+{
+       u32 por;
+
+       por =
+           ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
+           ((reg & 7) << 16) | (value & 0xFF);
+       btwrite(por, ZR36057_POR);
+
+       return post_office_wait(zr);
+}
+
+int
+post_office_read (struct zoran *zr,
+                 unsigned int  guest,
+                 unsigned int  reg)
+{
+       u32 por;
+
+       por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
+       btwrite(por, ZR36057_POR);
+       if (post_office_wait(zr) < 0) {
+               return -1;
+       }
+
+       return btread(ZR36057_POR) & 0xFF;
+}
+
+/*
+ * detect guests
+ */
+
+static void
+dump_guests (struct zoran *zr)
+{
+       if (zr36067_debug > 2) {
+               int i, guest[8];
+
+               for (i = 1; i < 8; i++) {       // Don't read jpeg codec here
+                       guest[i] = post_office_read(zr, i, 0);
+               }
+
+               printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
+
+               for (i = 1; i < 8; i++) {
+                       printk(" 0x%02x", guest[i]);
+               }
+               printk("\n");
+       }
+}
+
+static inline unsigned long
+get_time (void)
+{
+       struct timeval tv;
+
+       do_gettimeofday(&tv);
+       return (1000000 * tv.tv_sec + tv.tv_usec);
+}
+
+void
+detect_guest_activity (struct zoran *zr)
+{
+       int timeout, i, j, res, guest[8], guest0[8], change[8][3];
+       unsigned long t0, t1;
+
+       dump_guests(zr);
+       printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
+              ZR_DEVNAME(zr));
+       for (i = 1; i < 8; i++) {       // Don't read jpeg codec here
+               guest0[i] = guest[i] = post_office_read(zr, i, 0);
+       }
+
+       timeout = 0;
+       j = 0;
+       t0 = get_time();
+       while (timeout < 10000) {
+               udelay(10);
+               timeout++;
+               for (i = 1; (i < 8) && (j < 8); i++) {
+                       res = post_office_read(zr, i, 0);
+                       if (res != guest[i]) {
+                               t1 = get_time();
+                               change[j][0] = (t1 - t0);
+                               t0 = t1;
+                               change[j][1] = i;
+                               change[j][2] = res;
+                               j++;
+                               guest[i] = res;
+                       }
+               }
+               if (j >= 8)
+                       break;
+       }
+       printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
+
+       for (i = 1; i < 8; i++) {
+               printk(" 0x%02x", guest0[i]);
+       }
+       printk("\n");
+       if (j == 0) {
+               printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
+               return;
+       }
+       for (i = 0; i < j; i++) {
+               printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
+                      change[i][0], change[i][1], change[i][2]);
+       }
+}
+
+/*
+ * JPEG Codec access
+ */
+
+void
+jpeg_codec_sleep (struct zoran *zr,
+                 int           sleep)
+{
+       GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep);
+       if (!sleep) {
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
+                       ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
+               udelay(500);
+       } else {
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
+                       ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
+               udelay(2);
+       }
+}
+
+int
+jpeg_codec_reset (struct zoran *zr)
+{
+       /* Take the codec out of sleep */
+       jpeg_codec_sleep(zr, 0);
+
+       if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
+               post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
+                                 0);
+               udelay(2);
+       } else {
+               GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0);
+               udelay(2);
+               GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1);
+               udelay(2);
+       }
+
+       return 0;
+}
+
+/*
+ *   Set the registers for the size we have specified. Don't bother
+ *   trying to understand this without the ZR36057 manual in front of
+ *   you [AC].
+ *
+ *   PS: The manual is free for download in .pdf format from
+ *   www.zoran.com - nicely done those folks.
+ */
+
+static void
+zr36057_adjust_vfe (struct zoran          *zr,
+                   enum zoran_codec_mode  mode)
+{
+       u32 reg;
+
+       switch (mode) {
+       case BUZ_MODE_MOTION_DECOMPRESS:
+               btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
+               reg = btread(ZR36057_VFEHCR);
+               if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
+                       reg += ((1 << 10) | 1);
+               }
+               btwrite(reg, ZR36057_VFEHCR);
+               break;
+       case BUZ_MODE_MOTION_COMPRESS:
+       case BUZ_MODE_IDLE:
+       default:
+               if (zr->norm == VIDEO_MODE_NTSC ||
+                   (zr->card.type == LML33R10 &&
+                    zr->norm == VIDEO_MODE_PAL))
+                       btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
+               else
+                       btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
+               reg = btread(ZR36057_VFEHCR);
+               if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
+                       reg -= ((1 << 10) | 1);
+               }
+               btwrite(reg, ZR36057_VFEHCR);
+               break;
+       }
+}
+
+/*
+ * set geometry
+ */
+
+static void
+zr36057_set_vfe (struct zoran              *zr,
+                int                        video_width,
+                int                        video_height,
+                const struct zoran_format *format)
+{
+       struct tvnorm *tvn;
+       unsigned HStart, HEnd, VStart, VEnd;
+       unsigned DispMode;
+       unsigned VidWinWid, VidWinHt;
+       unsigned hcrop1, hcrop2, vcrop1, vcrop2;
+       unsigned Wa, We, Ha, He;
+       unsigned X, Y, HorDcm, VerDcm;
+       u32 reg;
+       unsigned mask_line_size;
+
+       tvn = zr->timing;
+
+       Wa = tvn->Wa;
+       Ha = tvn->Ha;
+
+       dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
+               ZR_DEVNAME(zr), video_width, video_height);
+
+       if (zr->norm != VIDEO_MODE_PAL &&
+           zr->norm != VIDEO_MODE_NTSC &&
+           zr->norm != VIDEO_MODE_SECAM) {
+               dprintk(1,
+                       KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
+                       ZR_DEVNAME(zr), zr->norm);
+               return;
+       }
+       if (video_width < BUZ_MIN_WIDTH ||
+           video_height < BUZ_MIN_HEIGHT ||
+           video_width > Wa || video_height > Ha) {
+               dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
+                       ZR_DEVNAME(zr), video_width, video_height);
+               return;
+       }
+
+       /**** zr36057 ****/
+
+       /* horizontal */
+       VidWinWid = video_width;
+       X = DIV_ROUND_UP(VidWinWid * 64, tvn->Wa);
+       We = (VidWinWid * 64) / X;
+       HorDcm = 64 - X;
+       hcrop1 = 2 * ((tvn->Wa - We) / 4);
+       hcrop2 = tvn->Wa - We - hcrop1;
+       HStart = tvn->HStart ? tvn->HStart : 1;
+       /* (Ronald) Original comment:
+        * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
+        * this is false. It inverses chroma values on the LML33R10 (so Cr
+        * suddenly is shown as Cb and reverse, really cool effect if you
+        * want to see blue faces, not useful otherwise). So don't use |1.
+        * However, the DC10 has '0' as HStart, but does need |1, so we
+        * use a dirty check...
+        */
+       HEnd = HStart + tvn->Wa - 1;
+       HStart += hcrop1;
+       HEnd -= hcrop2;
+       reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
+           | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
+       if (zr->card.vfe_pol.hsync_pol)
+               reg |= ZR36057_VFEHCR_HSPol;
+       btwrite(reg, ZR36057_VFEHCR);
+
+       /* Vertical */
+       DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
+       VidWinHt = DispMode ? video_height : video_height / 2;
+       Y = DIV_ROUND_UP(VidWinHt * 64 * 2, tvn->Ha);
+       He = (VidWinHt * 64) / Y;
+       VerDcm = 64 - Y;
+       vcrop1 = (tvn->Ha / 2 - He) / 2;
+       vcrop2 = tvn->Ha / 2 - He - vcrop1;
+       VStart = tvn->VStart;
+       VEnd = VStart + tvn->Ha / 2;    // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
+       VStart += vcrop1;
+       VEnd -= vcrop2;
+       reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
+           | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
+       if (zr->card.vfe_pol.vsync_pol)
+               reg |= ZR36057_VFEVCR_VSPol;
+       btwrite(reg, ZR36057_VFEVCR);
+
+       /* scaler and pixel format */
+       reg = 0;
+       reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
+       reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
+       reg |= (DispMode << ZR36057_VFESPFR_DispMode);
+       /* RJ: I don't know, why the following has to be the opposite
+        * of the corresponding ZR36060 setting, but only this way
+        * we get the correct colors when uncompressing to the screen  */
+       //reg |= ZR36057_VFESPFR_VCLKPol; /**/
+       /* RJ: Don't know if that is needed for NTSC also */
+       if (zr->norm != VIDEO_MODE_NTSC)
+               reg |= ZR36057_VFESPFR_ExtFl;   // NEEDED!!!!!!! Wolfgang
+       reg |= ZR36057_VFESPFR_TopField;
+       if (HorDcm >= 48) {
+               reg |= 3 << ZR36057_VFESPFR_HFilter;    /* 5 tap filter */
+       } else if (HorDcm >= 32) {
+               reg |= 2 << ZR36057_VFESPFR_HFilter;    /* 4 tap filter */
+       } else if (HorDcm >= 16) {
+               reg |= 1 << ZR36057_VFESPFR_HFilter;    /* 3 tap filter */
+       }
+       reg |= format->vfespfr;
+       btwrite(reg, ZR36057_VFESPFR);
+
+       /* display configuration */
+       reg = (16 << ZR36057_VDCR_MinPix)
+           | (VidWinHt << ZR36057_VDCR_VidWinHt)
+           | (VidWinWid << ZR36057_VDCR_VidWinWid);
+       if (pci_pci_problems & PCIPCI_TRITON)
+               // || zr->revision < 1) // Revision 1 has also Triton support
+               reg &= ~ZR36057_VDCR_Triton;
+       else
+               reg |= ZR36057_VDCR_Triton;
+       btwrite(reg, ZR36057_VDCR);
+
+       /* (Ronald) don't write this if overlay_mask = NULL */
+       if (zr->overlay_mask) {
+               /* Write overlay clipping mask data, but don't enable overlay clipping */
+               /* RJ: since this makes only sense on the screen, we use
+                * zr->overlay_settings.width instead of video_width */
+
+               mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
+               reg = virt_to_bus(zr->overlay_mask);
+               btwrite(reg, ZR36057_MMTR);
+               reg = virt_to_bus(zr->overlay_mask + mask_line_size);
+               btwrite(reg, ZR36057_MMBR);
+               reg =
+                   mask_line_size - (zr->overlay_settings.width +
+                                     31) / 32;
+               if (DispMode == 0)
+                       reg += mask_line_size;
+               reg <<= ZR36057_OCR_MaskStride;
+               btwrite(reg, ZR36057_OCR);
+       }
+
+       zr36057_adjust_vfe(zr, zr->codec_mode);
+}
+
+/*
+ * Switch overlay on or off
+ */
+
+void
+zr36057_overlay (struct zoran *zr,
+                int           on)
+{
+       u32 reg;
+
+       if (on) {
+               /* do the necessary settings ... */
+               btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);       /* switch it off first */
+
+               zr36057_set_vfe(zr,
+                               zr->overlay_settings.width,
+                               zr->overlay_settings.height,
+                               zr->overlay_settings.format);
+
+               /* Start and length of each line MUST be 4-byte aligned.
+                * This should be allready checked before the call to this routine.
+                * All error messages are internal driver checking only! */
+
+               /* video display top and bottom registers */
+               reg = (long) zr->buffer.base +
+                   zr->overlay_settings.x *
+                   ((zr->overlay_settings.format->depth + 7) / 8) +
+                   zr->overlay_settings.y *
+                   zr->buffer.bytesperline;
+               btwrite(reg, ZR36057_VDTR);
+               if (reg & 3)
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: zr36057_overlay() - video_address not aligned\n",
+                               ZR_DEVNAME(zr));
+               if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
+                       reg += zr->buffer.bytesperline;
+               btwrite(reg, ZR36057_VDBR);
+
+               /* video stride, status, and frame grab register */
+               reg = zr->buffer.bytesperline -
+                   zr->overlay_settings.width *
+                   ((zr->overlay_settings.format->depth + 7) / 8);
+               if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
+                       reg += zr->buffer.bytesperline;
+               if (reg & 3)
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: zr36057_overlay() - video_stride not aligned\n",
+                               ZR_DEVNAME(zr));
+               reg = (reg << ZR36057_VSSFGR_DispStride);
+               reg |= ZR36057_VSSFGR_VidOvf;   /* clear overflow status */
+               btwrite(reg, ZR36057_VSSFGR);
+
+               /* Set overlay clipping */
+               if (zr->overlay_settings.clipcount > 0)
+                       btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
+
+               /* ... and switch it on */
+               btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
+       } else {
+               /* Switch it off */
+               btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
+       }
+}
+
+/*
+ * The overlay mask has one bit for each pixel on a scan line,
+ *  and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
+ */
+
+void
+write_overlay_mask (struct file       *file,
+                   struct video_clip *vp,
+                   int                count)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
+       u32 *mask;
+       int x, y, width, height;
+       unsigned i, j, k;
+       u32 reg;
+
+       /* fill mask with one bits */
+       memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
+       reg = 0;
+
+       for (i = 0; i < count; ++i) {
+               /* pick up local copy of clip */
+               x = vp[i].x;
+               y = vp[i].y;
+               width = vp[i].width;
+               height = vp[i].height;
+
+               /* trim clips that extend beyond the window */
+               if (x < 0) {
+                       width += x;
+                       x = 0;
+               }
+               if (y < 0) {
+                       height += y;
+                       y = 0;
+               }
+               if (x + width > fh->overlay_settings.width) {
+                       width = fh->overlay_settings.width - x;
+               }
+               if (y + height > fh->overlay_settings.height) {
+                       height = fh->overlay_settings.height - y;
+               }
+
+               /* ignore degenerate clips */
+               if (height <= 0) {
+                       continue;
+               }
+               if (width <= 0) {
+                       continue;
+               }
+
+               /* apply clip for each scan line */
+               for (j = 0; j < height; ++j) {
+                       /* reset bit for each pixel */
+                       /* this can be optimized later if need be */
+                       mask = fh->overlay_mask + (y + j) * mask_line_size;
+                       for (k = 0; k < width; ++k) {
+                               mask[(x + k) / 32] &=
+                                   ~((u32) 1 << (x + k) % 32);
+                       }
+               }
+       }
+}
+
+/* Enable/Disable uncompressed memory grabbing of the 36057 */
+
+void
+zr36057_set_memgrab (struct zoran *zr,
+                    int           mode)
+{
+       if (mode) {
+               /* We only check SnapShot and not FrameGrab here.  SnapShot==1
+                * means a capture is already in progress, but FrameGrab==1
+                * doesn't necessary mean that.  It's more correct to say a 1
+                * to 0 transition indicates a capture completed.  If a
+                * capture is pending when capturing is tuned off, FrameGrab
+                * will be stuck at 1 until capturing is turned back on.
+                */
+               if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
+                       dprintk(1,
+                               KERN_WARNING
+                               "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
+                               ZR_DEVNAME(zr));
+
+               /* switch on VSync interrupts */
+               btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
+               btor(zr->card.vsync_int, ZR36057_ICR);  // SW
+
+               /* enable SnapShot */
+               btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
+
+               /* Set zr36057 video front end  and enable video */
+               zr36057_set_vfe(zr, zr->v4l_settings.width,
+                               zr->v4l_settings.height,
+                               zr->v4l_settings.format);
+
+               zr->v4l_memgrab_active = 1;
+       } else {
+               /* switch off VSync interrupts */
+               btand(~zr->card.vsync_int, ZR36057_ICR);        // SW
+
+               zr->v4l_memgrab_active = 0;
+               zr->v4l_grab_frame = NO_GRAB_ACTIVE;
+
+               /* reenable grabbing to screen if it was running */
+               if (zr->v4l_overlay_active) {
+                       zr36057_overlay(zr, 1);
+               } else {
+                       btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
+                       btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
+               }
+       }
+}
+
+int
+wait_grab_pending (struct zoran *zr)
+{
+       unsigned long flags;
+
+       /* wait until all pending grabs are finished */
+
+       if (!zr->v4l_memgrab_active)
+               return 0;
+
+       wait_event_interruptible(zr->v4l_capq,
+                       (zr->v4l_pend_tail == zr->v4l_pend_head));
+       if (signal_pending(current))
+               return -ERESTARTSYS;
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+       zr36057_set_memgrab(zr, 0);
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       return 0;
+}
+
+/*****************************************************************************
+ *                                                                           *
+ *  Set up the Buz-specific MJPEG part                                       *
+ *                                                                           *
+ *****************************************************************************/
+
+static inline void
+set_frame (struct zoran *zr,
+          int           val)
+{
+       GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val);
+}
+
+static void
+set_videobus_dir (struct zoran *zr,
+                 int           val)
+{
+       switch (zr->card.type) {
+       case LML33:
+       case LML33R10:
+               if (lml33dpath == 0)
+                       GPIO(zr, 5, val);
+               else
+                       GPIO(zr, 5, 1);
+               break;
+       default:
+               GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR],
+                    zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val);
+               break;
+       }
+}
+
+static void
+init_jpeg_queue (struct zoran *zr)
+{
+       int i;
+
+       /* re-initialize DMA ring stuff */
+       zr->jpg_que_head = 0;
+       zr->jpg_dma_head = 0;
+       zr->jpg_dma_tail = 0;
+       zr->jpg_que_tail = 0;
+       zr->jpg_seq_num = 0;
+       zr->JPEG_error = 0;
+       zr->num_errors = 0;
+       zr->jpg_err_seq = 0;
+       zr->jpg_err_shift = 0;
+       zr->jpg_queued_num = 0;
+       for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
+               zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
+       }
+       for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
+               zr->stat_com[i] = cpu_to_le32(1);       /* mark as unavailable to zr36057 */
+       }
+}
+
+static void
+zr36057_set_jpg (struct zoran          *zr,
+                enum zoran_codec_mode  mode)
+{
+       struct tvnorm *tvn;
+       u32 reg;
+
+       tvn = zr->timing;
+
+       /* assert P_Reset, disable code transfer, deassert Active */
+       btwrite(0, ZR36057_JPC);
+
+       /* MJPEG compression mode */
+       switch (mode) {
+
+       case BUZ_MODE_MOTION_COMPRESS:
+       default:
+               reg = ZR36057_JMC_MJPGCmpMode;
+               break;
+
+       case BUZ_MODE_MOTION_DECOMPRESS:
+               reg = ZR36057_JMC_MJPGExpMode;
+               reg |= ZR36057_JMC_SyncMstr;
+               /* RJ: The following is experimental - improves the output to screen */
+               //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
+               break;
+
+       case BUZ_MODE_STILL_COMPRESS:
+               reg = ZR36057_JMC_JPGCmpMode;
+               break;
+
+       case BUZ_MODE_STILL_DECOMPRESS:
+               reg = ZR36057_JMC_JPGExpMode;
+               break;
+
+       }
+       reg |= ZR36057_JMC_JPG;
+       if (zr->jpg_settings.field_per_buff == 1)
+               reg |= ZR36057_JMC_Fld_per_buff;
+       btwrite(reg, ZR36057_JMC);
+
+       /* vertical */
+       btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
+       reg = (6 << ZR36057_VSP_VsyncSize) |
+             (tvn->Ht << ZR36057_VSP_FrmTot);
+       btwrite(reg, ZR36057_VSP);
+       reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
+             (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
+       btwrite(reg, ZR36057_FVAP);
+
+       /* horizontal */
+       if (zr->card.vfe_pol.hsync_pol)
+               btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
+       else
+               btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
+       reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
+             (tvn->Wt << ZR36057_HSP_LineTot);
+       btwrite(reg, ZR36057_HSP);
+       reg = ((zr->jpg_settings.img_x +
+               tvn->HStart + 4) << ZR36057_FHAP_NAX) |
+             (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
+       btwrite(reg, ZR36057_FHAP);
+
+       /* field process parameters */
+       if (zr->jpg_settings.odd_even)
+               reg = ZR36057_FPP_Odd_Even;
+       else
+               reg = 0;
+
+       btwrite(reg, ZR36057_FPP);
+
+       /* Set proper VCLK Polarity, else colors will be wrong during playback */
+       //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
+
+       /* code base address */
+       reg = virt_to_bus(zr->stat_com);
+       btwrite(reg, ZR36057_JCBA);
+
+       /* FIFO threshold (FIFO is 160. double words) */
+       /* NOTE: decimal values here */
+       switch (mode) {
+
+       case BUZ_MODE_STILL_COMPRESS:
+       case BUZ_MODE_MOTION_COMPRESS:
+               if (zr->card.type != BUZ)
+                       reg = 140;
+               else
+                       reg = 60;
+               break;
+
+       case BUZ_MODE_STILL_DECOMPRESS:
+       case BUZ_MODE_MOTION_DECOMPRESS:
+               reg = 20;
+               break;
+
+       default:
+               reg = 80;
+               break;
+
+       }
+       btwrite(reg, ZR36057_JCFT);
+       zr36057_adjust_vfe(zr, mode);
+
+}
+
+void
+print_interrupts (struct zoran *zr)
+{
+       int res, noerr = 0;
+
+       printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
+       if ((res = zr->field_counter) < -1 || res > 1) {
+               printk(" FD:%d", res);
+       }
+       if ((res = zr->intr_counter_GIRQ1) != 0) {
+               printk(" GIRQ1:%d", res);
+               noerr++;
+       }
+       if ((res = zr->intr_counter_GIRQ0) != 0) {
+               printk(" GIRQ0:%d", res);
+               noerr++;
+       }
+       if ((res = zr->intr_counter_CodRepIRQ) != 0) {
+               printk(" CodRepIRQ:%d", res);
+               noerr++;
+       }
+       if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
+               printk(" JPEGRepIRQ:%d", res);
+               noerr++;
+       }
+       if (zr->JPEG_max_missed) {
+               printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
+                      zr->JPEG_min_missed);
+       }
+       if (zr->END_event_missed) {
+               printk(" ENDs missed: %d", zr->END_event_missed);
+       }
+       //if (zr->jpg_queued_num) {
+       printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
+              zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
+       //}
+       if (!noerr) {
+               printk(": no interrupts detected.");
+       }
+       printk("\n");
+}
+
+void
+clear_interrupt_counters (struct zoran *zr)
+{
+       zr->intr_counter_GIRQ1 = 0;
+       zr->intr_counter_GIRQ0 = 0;
+       zr->intr_counter_CodRepIRQ = 0;
+       zr->intr_counter_JPEGRepIRQ = 0;
+       zr->field_counter = 0;
+       zr->IRQ1_in = 0;
+       zr->IRQ1_out = 0;
+       zr->JPEG_in = 0;
+       zr->JPEG_out = 0;
+       zr->JPEG_0 = 0;
+       zr->JPEG_1 = 0;
+       zr->END_event_missed = 0;
+       zr->JPEG_missed = 0;
+       zr->JPEG_max_missed = 0;
+       zr->JPEG_min_missed = 0x7fffffff;
+}
+
+static u32
+count_reset_interrupt (struct zoran *zr)
+{
+       u32 isr;
+
+       if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
+               if (isr & ZR36057_ISR_GIRQ1) {
+                       btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
+                       zr->intr_counter_GIRQ1++;
+               }
+               if (isr & ZR36057_ISR_GIRQ0) {
+                       btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
+                       zr->intr_counter_GIRQ0++;
+               }
+               if (isr & ZR36057_ISR_CodRepIRQ) {
+                       btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
+                       zr->intr_counter_CodRepIRQ++;
+               }
+               if (isr & ZR36057_ISR_JPEGRepIRQ) {
+                       btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
+                       zr->intr_counter_JPEGRepIRQ++;
+               }
+       }
+       return isr;
+}
+
+void
+jpeg_start (struct zoran *zr)
+{
+       int reg;
+
+       zr->frame_num = 0;
+
+       /* deassert P_reset, disable code transfer, deassert Active */
+       btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
+       /* stop flushing the internal code buffer */
+       btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
+       /* enable code transfer */
+       btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
+
+       /* clear IRQs */
+       btwrite(IRQ_MASK, ZR36057_ISR);
+       /* enable the JPEG IRQs */
+       btwrite(zr->card.jpeg_int |
+                       ZR36057_ICR_JPEGRepIRQ |
+                       ZR36057_ICR_IntPinEn,
+               ZR36057_ICR);
+
+       set_frame(zr, 0);       // \FRAME
+
+       /* set the JPEG codec guest ID */
+       reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
+              (0 << ZR36057_JCGI_JPEGuestReg);
+       btwrite(reg, ZR36057_JCGI);
+
+       if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
+           zr->card.video_codec == CODEC_TYPE_ZR36050) {
+               /* Enable processing on the ZR36016 */
+               if (zr->vfe)
+                       zr36016_write(zr->vfe, 0, 1);
+
+               /* load the address of the GO register in the ZR36050 latch */
+               post_office_write(zr, 0, 0, 0);
+       }
+
+       /* assert Active */
+       btor(ZR36057_JPC_Active, ZR36057_JPC);
+
+       /* enable the Go generation */
+       btor(ZR36057_JMC_Go_en, ZR36057_JMC);
+       udelay(30);
+
+       set_frame(zr, 1);       // /FRAME
+
+       dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
+}
+
+void
+zr36057_enable_jpg (struct zoran          *zr,
+                   enum zoran_codec_mode  mode)
+{
+       static int zero;
+       static int one = 1;
+       struct vfe_settings cap;
+       int field_size =
+           zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
+
+       zr->codec_mode = mode;
+
+       cap.x = zr->jpg_settings.img_x;
+       cap.y = zr->jpg_settings.img_y;
+       cap.width = zr->jpg_settings.img_width;
+       cap.height = zr->jpg_settings.img_height;
+       cap.decimation =
+           zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
+       cap.quality = zr->jpg_settings.jpg_comp.quality;
+
+       switch (mode) {
+
+       case BUZ_MODE_MOTION_COMPRESS: {
+               struct jpeg_app_marker app;
+               struct jpeg_com_marker com;
+
+               /* In motion compress mode, the decoder output must be enabled, and
+                * the video bus direction set to input.
+                */
+               set_videobus_dir(zr, 0);
+               decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
+               encoder_command(zr, ENCODER_SET_INPUT, &zero);
+
+               /* Take the JPEG codec and the VFE out of sleep */
+               jpeg_codec_sleep(zr, 0);
+
+               /* set JPEG app/com marker */
+               app.appn = zr->jpg_settings.jpg_comp.APPn;
+               app.len = zr->jpg_settings.jpg_comp.APP_len;
+               memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
+               zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
+                                  sizeof(struct jpeg_app_marker), &app);
+
+               com.len = zr->jpg_settings.jpg_comp.COM_len;
+               memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
+               zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
+                                  sizeof(struct jpeg_com_marker), &com);
+
+               /* Setup the JPEG codec */
+               zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
+                                  sizeof(int), &field_size);
+               zr->codec->set_video(zr->codec, zr->timing, &cap,
+                                    &zr->card.vfe_pol);
+               zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
+
+               /* Setup the VFE */
+               if (zr->vfe) {
+                       zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
+                                        sizeof(int), &field_size);
+                       zr->vfe->set_video(zr->vfe, zr->timing, &cap,
+                                          &zr->card.vfe_pol);
+                       zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
+               }
+
+               init_jpeg_queue(zr);
+               zr36057_set_jpg(zr, mode);      // \P_Reset, ... Video param, FIFO
+
+               clear_interrupt_counters(zr);
+               dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
+                       ZR_DEVNAME(zr));
+               break;
+       }
+
+       case BUZ_MODE_MOTION_DECOMPRESS:
+               /* In motion decompression mode, the decoder output must be disabled, and
+                * the video bus direction set to output.
+                */
+               decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
+               set_videobus_dir(zr, 1);
+               encoder_command(zr, ENCODER_SET_INPUT, &one);
+
+               /* Take the JPEG codec and the VFE out of sleep */
+               jpeg_codec_sleep(zr, 0);
+               /* Setup the VFE */
+               if (zr->vfe) {
+                       zr->vfe->set_video(zr->vfe, zr->timing, &cap,
+                                          &zr->card.vfe_pol);
+                       zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
+               }
+               /* Setup the JPEG codec */
+               zr->codec->set_video(zr->codec, zr->timing, &cap,
+                                    &zr->card.vfe_pol);
+               zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
+
+               init_jpeg_queue(zr);
+               zr36057_set_jpg(zr, mode);      // \P_Reset, ... Video param, FIFO
+
+               clear_interrupt_counters(zr);
+               dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
+                       ZR_DEVNAME(zr));
+               break;
+
+       case BUZ_MODE_IDLE:
+       default:
+               /* shut down processing */
+               btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
+                     ZR36057_ICR);
+               btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
+                       ZR36057_ISR);
+               btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
+
+               msleep(50);
+
+               set_videobus_dir(zr, 0);
+               set_frame(zr, 1);       // /FRAME
+               btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);      // /CFlush
+               btwrite(0, ZR36057_JPC);        // \P_Reset,\CodTrnsEn,\Active
+               btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
+               btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
+               jpeg_codec_reset(zr);
+               jpeg_codec_sleep(zr, 1);
+               zr36057_adjust_vfe(zr, mode);
+
+               decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
+               encoder_command(zr, ENCODER_SET_INPUT, &zero);
+
+               dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
+               break;
+
+       }
+}
+
+/* when this is called the spinlock must be held */
+void
+zoran_feed_stat_com (struct zoran *zr)
+{
+       /* move frames from pending queue to DMA */
+
+       int frame, i, max_stat_com;
+
+       max_stat_com =
+           (zr->jpg_settings.TmpDcm ==
+            1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
+
+       while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
+              zr->jpg_dma_head < zr->jpg_que_head) {
+
+               frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
+               if (zr->jpg_settings.TmpDcm == 1) {
+                       /* fill 1 stat_com entry */
+                       i = (zr->jpg_dma_head -
+                            zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
+                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
+                               break;
+                       zr->stat_com[i] =
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
+               } else {
+                       /* fill 2 stat_com entries */
+                       i = ((zr->jpg_dma_head -
+                             zr->jpg_err_shift) & 1) * 2;
+                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
+                               break;
+                       zr->stat_com[i] =
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
+                       zr->stat_com[i + 1] =
+                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
+               }
+               zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
+               zr->jpg_dma_head++;
+
+       }
+       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
+               zr->jpg_queued_num++;
+}
+
+/* when this is called the spinlock must be held */
+static void
+zoran_reap_stat_com (struct zoran *zr)
+{
+       /* move frames from DMA queue to done queue */
+
+       int i;
+       u32 stat_com;
+       unsigned int seq;
+       unsigned int dif;
+       struct zoran_jpg_buffer *buffer;
+       int frame;
+
+       /* In motion decompress we don't have a hardware frame counter,
+        * we just count the interrupts here */
+
+       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
+               zr->jpg_seq_num++;
+       }
+       while (zr->jpg_dma_tail < zr->jpg_dma_head) {
+               if (zr->jpg_settings.TmpDcm == 1)
+                       i = (zr->jpg_dma_tail -
+                            zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
+               else
+                       i = ((zr->jpg_dma_tail -
+                             zr->jpg_err_shift) & 1) * 2 + 1;
+
+               stat_com = le32_to_cpu(zr->stat_com[i]);
+
+               if ((stat_com & 1) == 0) {
+                       return;
+               }
+               frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
+               buffer = &zr->jpg_buffers.buffer[frame];
+               do_gettimeofday(&buffer->bs.timestamp);
+
+               if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
+                       buffer->bs.length = (stat_com & 0x7fffff) >> 1;
+
+                       /* update sequence number with the help of the counter in stat_com */
+
+                       seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
+                       dif = (seq - zr->jpg_seq_num) & 0xff;
+                       zr->jpg_seq_num += dif;
+               } else {
+                       buffer->bs.length = 0;
+               }
+               buffer->bs.seq =
+                   zr->jpg_settings.TmpDcm ==
+                   2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
+               buffer->state = BUZ_STATE_DONE;
+
+               zr->jpg_dma_tail++;
+       }
+}
+
+static void
+error_handler (struct zoran *zr,
+              u32           astat,
+              u32           stat)
+{
+       /* This is JPEG error handling part */
+       if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
+           (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
+               //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
+               return;
+       }
+
+       if ((stat & 1) == 0 &&
+           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
+           zr->jpg_dma_tail - zr->jpg_que_tail >=
+            zr->jpg_buffers.num_buffers) {
+               /* No free buffers... */
+               zoran_reap_stat_com(zr);
+               zoran_feed_stat_com(zr);
+               wake_up_interruptible(&zr->jpg_capq);
+               zr->JPEG_missed = 0;
+               return;
+       }
+
+       if (zr->JPEG_error != 1) {
+               /*
+                * First entry: error just happened during normal operation
+                *
+                * In BUZ_MODE_MOTION_COMPRESS:
+                *
+                * Possible glitch in TV signal. In this case we should
+                * stop the codec and wait for good quality signal before
+                * restarting it to avoid further problems
+                *
+                * In BUZ_MODE_MOTION_DECOMPRESS:
+                *
+                * Bad JPEG frame: we have to mark it as processed (codec crashed
+                * and was not able to do it itself), and to remove it from queue.
+                */
+               btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
+               udelay(1);
+               stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
+               btwrite(0, ZR36057_JPC);
+               btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
+               jpeg_codec_reset(zr);
+               jpeg_codec_sleep(zr, 1);
+               zr->JPEG_error = 1;
+               zr->num_errors++;
+
+               /* Report error */
+               if (zr36067_debug > 1 && zr->num_errors <= 8) {
+                       long frame;
+                       frame =
+                           zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
+                       printk(KERN_ERR
+                              "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
+                              ZR_DEVNAME(zr), stat, zr->last_isr,
+                              zr->jpg_que_tail, zr->jpg_dma_tail,
+                              zr->jpg_dma_head, zr->jpg_que_head,
+                              zr->jpg_seq_num, frame);
+                       printk("stat_com frames:");
+                       {
+                               int i, j;
+                               for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
+                                       for (i = 0;
+                                            i < zr->jpg_buffers.num_buffers;
+                                            i++) {
+                                               if (le32_to_cpu(zr->stat_com[j]) ==
+                                                   zr->jpg_buffers.
+                                                   buffer[i].
+                                                   frag_tab_bus) {
+                                                       printk("% d->%d",
+                                                              j, i);
+                                               }
+                                       }
+                               }
+                               printk("\n");
+                       }
+               }
+               /* Find an entry in stat_com and rotate contents */
+               {
+                       int i;
+
+                       if (zr->jpg_settings.TmpDcm == 1)
+                               i = (zr->jpg_dma_tail -
+                                    zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
+                       else
+                               i = ((zr->jpg_dma_tail -
+                                     zr->jpg_err_shift) & 1) * 2;
+                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
+                               /* Mimic zr36067 operation */
+                               zr->stat_com[i] |= cpu_to_le32(1);
+                               if (zr->jpg_settings.TmpDcm != 1)
+                                       zr->stat_com[i + 1] |= cpu_to_le32(1);
+                               /* Refill */
+                               zoran_reap_stat_com(zr);
+                               zoran_feed_stat_com(zr);
+                               wake_up_interruptible(&zr->jpg_capq);
+                               /* Find an entry in stat_com again after refill */
+                               if (zr->jpg_settings.TmpDcm == 1)
+                                       i = (zr->jpg_dma_tail -
+                                            zr->jpg_err_shift) &
+                                           BUZ_MASK_STAT_COM;
+                               else
+                                       i = ((zr->jpg_dma_tail -
+                                             zr->jpg_err_shift) & 1) * 2;
+                       }
+                       if (i) {
+                               /* Rotate stat_comm entries to make current entry first */
+                               int j;
+                               __le32 bus_addr[BUZ_NUM_STAT_COM];
+
+                               /* Here we are copying the stat_com array, which
+                                * is already in little endian format, so
+                                * no endian conversions here
+                                */
+                               memcpy(bus_addr, zr->stat_com,
+                                      sizeof(bus_addr));
+                               for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
+                                       zr->stat_com[j] =
+                                           bus_addr[(i + j) &
+                                                    BUZ_MASK_STAT_COM];
+
+                               }
+                               zr->jpg_err_shift += i;
+                               zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
+                       }
+                       if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
+                               zr->jpg_err_seq = zr->jpg_seq_num;      /* + 1; */
+               }
+       }
+
+       /* Now the stat_comm buffer is ready for restart */
+       do {
+               int status, mode;
+
+               if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
+                       decoder_command(zr, DECODER_GET_STATUS, &status);
+                       mode = CODEC_DO_COMPRESSION;
+               } else {
+                       status = 0;
+                       mode = CODEC_DO_EXPANSION;
+               }
+               if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
+                   (status & DECODER_STATUS_GOOD)) {
+                       /********** RESTART code *************/
+                       jpeg_codec_reset(zr);
+                       zr->codec->set_mode(zr->codec, mode);
+                       zr36057_set_jpg(zr, zr->codec_mode);
+                       jpeg_start(zr);
+
+                       if (zr->num_errors <= 8)
+                               dprintk(2, KERN_INFO "%s: Restart\n",
+                                       ZR_DEVNAME(zr));
+
+                       zr->JPEG_missed = 0;
+                       zr->JPEG_error = 2;
+                       /********** End RESTART code ***********/
+               }
+       } while (0);
+}
+
+irqreturn_t
+zoran_irq (int             irq,
+          void           *dev_id)
+{
+       u32 stat, astat;
+       int count;
+       struct zoran *zr;
+       unsigned long flags;
+
+       zr = dev_id;
+       count = 0;
+
+       if (zr->testing) {
+               /* Testing interrupts */
+               spin_lock_irqsave(&zr->spinlock, flags);
+               while ((stat = count_reset_interrupt(zr))) {
+                       if (count++ > 100) {
+                               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
+                                       ZR_DEVNAME(zr), stat);
+                               wake_up_interruptible(&zr->test_q);
+                       }
+               }
+               zr->last_isr = stat;
+               spin_unlock_irqrestore(&zr->spinlock, flags);
+               return IRQ_HANDLED;
+       }
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+       while (1) {
+               /* get/clear interrupt status bits */
+               stat = count_reset_interrupt(zr);
+               astat = stat & IRQ_MASK;
+               if (!astat) {
+                       break;
+               }
+               dprintk(4,
+                       KERN_DEBUG
+                       "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
+                       astat, btread(ZR36057_ICR));
+               if (astat & zr->card.vsync_int) {       // SW
+
+                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
+                           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
+                               /* count missed interrupts */
+                               zr->JPEG_missed++;
+                       }
+                       //post_office_read(zr,1,0);
+                       /* Interrupts may still happen when
+                        * zr->v4l_memgrab_active is switched off.
+                        * We simply ignore them */
+
+                       if (zr->v4l_memgrab_active) {
+
+                               /* A lot more checks should be here ... */
+                               if ((btread(ZR36057_VSSFGR) &
+                                    ZR36057_VSSFGR_SnapShot) == 0)
+                                       dprintk(1,
+                                               KERN_WARNING
+                                               "%s: BuzIRQ with SnapShot off ???\n",
+                                               ZR_DEVNAME(zr));
+
+                               if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
+                                       /* There is a grab on a frame going on, check if it has finished */
+
+                                       if ((btread(ZR36057_VSSFGR) &
+                                            ZR36057_VSSFGR_FrameGrab) ==
+                                           0) {
+                                               /* it is finished, notify the user */
+
+                                               zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
+                                               zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
+                                               do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
+                                               zr->v4l_grab_frame = NO_GRAB_ACTIVE;
+                                               zr->v4l_pend_tail++;
+                                       }
+                               }
+
+                               if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
+                                       wake_up_interruptible(&zr->v4l_capq);
+
+                               /* Check if there is another grab queued */
+
+                               if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
+                                   zr->v4l_pend_tail != zr->v4l_pend_head) {
+
+                                       int frame = zr->v4l_pend[zr->v4l_pend_tail &
+                                                        V4L_MASK_FRAME];
+                                       u32 reg;
+
+                                       zr->v4l_grab_frame = frame;
+
+                                       /* Set zr36057 video front end and enable video */
+
+                                       /* Buffer address */
+
+                                       reg =
+                                           zr->v4l_buffers.buffer[frame].
+                                           fbuffer_bus;
+                                       btwrite(reg, ZR36057_VDTR);
+                                       if (zr->v4l_settings.height >
+                                           BUZ_MAX_HEIGHT / 2)
+                                               reg +=
+                                                   zr->v4l_settings.
+                                                   bytesperline;
+                                       btwrite(reg, ZR36057_VDBR);
+
+                                       /* video stride, status, and frame grab register */
+                                       reg = 0;
+                                       if (zr->v4l_settings.height >
+                                           BUZ_MAX_HEIGHT / 2)
+                                               reg +=
+                                                   zr->v4l_settings.
+                                                   bytesperline;
+                                       reg =
+                                           (reg <<
+                                            ZR36057_VSSFGR_DispStride);
+                                       reg |= ZR36057_VSSFGR_VidOvf;
+                                       reg |= ZR36057_VSSFGR_SnapShot;
+                                       reg |= ZR36057_VSSFGR_FrameGrab;
+                                       btwrite(reg, ZR36057_VSSFGR);
+
+                                       btor(ZR36057_VDCR_VidEn,
+                                            ZR36057_VDCR);
+                               }
+                       }
+
+                       /* even if we don't grab, we do want to increment
+                        * the sequence counter to see lost frames */
+                       zr->v4l_grab_seq++;
+               }
+#if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
+               if (astat & ZR36057_ISR_CodRepIRQ) {
+                       zr->intr_counter_CodRepIRQ++;
+                       IDEBUG(printk
+                              (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
+                               ZR_DEVNAME(zr)));
+                       btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
+               }
+#endif                         /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
+
+#if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
+               if (astat & ZR36057_ISR_JPEGRepIRQ) {
+
+                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
+                           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
+                               if (zr36067_debug > 1 &&
+                                   (!zr->frame_num || zr->JPEG_error)) {
+                                       printk(KERN_INFO
+                                              "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
+                                              ZR_DEVNAME(zr), stat,
+                                              zr->jpg_settings.odd_even,
+                                              zr->jpg_settings.
+                                              field_per_buff,
+                                              zr->JPEG_missed);
+                                       {
+                                               char sc[] = "0000";
+                                               char sv[5];
+                                               int i;
+                                               strcpy(sv, sc);
+                                               for (i = 0; i < 4; i++) {
+                                                       if (le32_to_cpu(zr->stat_com[i]) & 1)
+                                                               sv[i] = '1';
+                                               }
+                                               sv[4] = 0;
+                                               printk(KERN_INFO
+                                                      "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
+                                                      ZR_DEVNAME(zr), sv,
+                                                      zr->jpg_que_tail,
+                                                      zr->jpg_dma_tail,
+                                                      zr->jpg_dma_head,
+                                                      zr->jpg_que_head);
+                                       }
+                               } else {
+                                       if (zr->JPEG_missed > zr->JPEG_max_missed)      // Get statistics
+                                               zr->JPEG_max_missed =
+                                                   zr->JPEG_missed;
+                                       if (zr->JPEG_missed <
+                                           zr->JPEG_min_missed)
+                                               zr->JPEG_min_missed =
+                                                   zr->JPEG_missed;
+                               }
+
+                               if (zr36067_debug > 2 && zr->frame_num < 6) {
+                                       int i;
+                                       printk("%s: seq=%ld stat_com:",
+                                              ZR_DEVNAME(zr), zr->jpg_seq_num);
+                                       for (i = 0; i < 4; i++) {
+                                               printk(" %08x",
+                                                      le32_to_cpu(zr->stat_com[i]));
+                                       }
+                                       printk("\n");
+                               }
+                               zr->frame_num++;
+                               zr->JPEG_missed = 0;
+                               zr->JPEG_error = 0;
+                               zoran_reap_stat_com(zr);
+                               zoran_feed_stat_com(zr);
+                               wake_up_interruptible(&zr->jpg_capq);
+                       } /*else {
+                             dprintk(1,
+                                       KERN_ERR
+                                       "%s: JPEG interrupt while not in motion (de)compress mode!\n",
+                                       ZR_DEVNAME(zr));
+                       }*/
+               }
+#endif                         /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
+
+               /* DATERR, too many fields missed, error processing */
+               if ((astat & zr->card.jpeg_int) ||
+                   zr->JPEG_missed > 25 ||
+                   zr->JPEG_error == 1 ||
+                   ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
+                    (zr->frame_num & (zr->JPEG_missed >
+                                      zr->jpg_settings.field_per_buff)))) {
+                       error_handler(zr, astat, stat);
+               }
+
+               count++;
+               if (count > 10) {
+                       dprintk(2, KERN_WARNING "%s: irq loop %d\n",
+                               ZR_DEVNAME(zr), count);
+                       if (count > 20) {
+                               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
+                               dprintk(2,
+                                       KERN_ERR
+                                       "%s: IRQ lockup, cleared int mask\n",
+                                       ZR_DEVNAME(zr));
+                               break;
+                       }
+               }
+               zr->last_isr = stat;
+       }
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       return IRQ_HANDLED;
+}
+
+void
+zoran_set_pci_master (struct zoran *zr,
+                     int           set_master)
+{
+       if (set_master) {
+               pci_set_master(zr->pci_dev);
+       } else {
+               u16 command;
+
+               pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
+               command &= ~PCI_COMMAND_MASTER;
+               pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
+       }
+}
+
+void
+zoran_init_hardware (struct zoran *zr)
+{
+       int j, zero = 0;
+
+       /* Enable bus-mastering */
+       zoran_set_pci_master(zr, 1);
+
+       /* Initialize the board */
+       if (zr->card.init) {
+               zr->card.init(zr);
+       }
+
+       j = zr->card.input[zr->input].muxsel;
+
+       decoder_command(zr, 0, NULL);
+       decoder_command(zr, DECODER_SET_NORM, &zr->norm);
+       decoder_command(zr, DECODER_SET_INPUT, &j);
+
+       encoder_command(zr, 0, NULL);
+       encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
+       encoder_command(zr, ENCODER_SET_INPUT, &zero);
+
+       /* toggle JPEG codec sleep to sync PLL */
+       jpeg_codec_sleep(zr, 1);
+       jpeg_codec_sleep(zr, 0);
+
+       /* set individual interrupt enables (without GIRQ1)
+        * but don't global enable until zoran_open() */
+
+       //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR);  // SW
+       // It looks like using only JPEGRepIRQEn is not always reliable,
+       // may be when JPEG codec crashes it won't generate IRQ? So,
+        /*CP*/                 //        btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM    WHY ? LP
+           zr36057_init_vfe(zr);
+
+       zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
+
+       btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
+}
+
+void
+zr36057_restart (struct zoran *zr)
+{
+       btwrite(0, ZR36057_SPGPPCR);
+       mdelay(1);
+       btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
+       mdelay(1);
+
+       /* assert P_Reset */
+       btwrite(0, ZR36057_JPC);
+       /* set up GPIO direction - all output */
+       btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
+
+       /* set up GPIO pins and guest bus timing */
+       btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
+}
+
+/*
+ * initialize video front end
+ */
+
+static void
+zr36057_init_vfe (struct zoran *zr)
+{
+       u32 reg;
+
+       reg = btread(ZR36057_VFESPFR);
+       reg |= ZR36057_VFESPFR_LittleEndian;
+       reg &= ~ZR36057_VFESPFR_VCLKPol;
+       reg |= ZR36057_VFESPFR_ExtFl;
+       reg |= ZR36057_VFESPFR_TopField;
+       btwrite(reg, ZR36057_VFESPFR);
+       reg = btread(ZR36057_VDCR);
+       if (pci_pci_problems & PCIPCI_TRITON)
+               // || zr->revision < 1) // Revision 1 has also Triton support
+               reg &= ~ZR36057_VDCR_Triton;
+       else
+               reg |= ZR36057_VDCR_Triton;
+       btwrite(reg, ZR36057_VDCR);
+}
+
+/*
+ * Interface to decoder and encoder chips using i2c bus
+ */
+
+int
+decoder_command (struct zoran *zr,
+                int           cmd,
+                void         *data)
+{
+       if (zr->decoder == NULL)
+               return -EIO;
+
+       if (zr->card.type == LML33 &&
+           (cmd == DECODER_SET_NORM || cmd == DECODER_SET_INPUT)) {
+               int res;
+
+               // Bt819 needs to reset its FIFO buffer using #FRST pin and
+               // LML33 card uses GPIO(7) for that.
+               GPIO(zr, 7, 0);
+               res = zr->decoder->driver->command(zr->decoder, cmd, data);
+               // Pull #FRST high.
+               GPIO(zr, 7, 1);
+               return res;
+       } else
+               return zr->decoder->driver->command(zr->decoder, cmd,
+                                                   data);
+}
+
+int
+encoder_command (struct zoran *zr,
+                int           cmd,
+                void         *data)
+{
+       if (zr->encoder == NULL)
+               return -1;
+
+       return zr->encoder->driver->command(zr->encoder, cmd, data);
+}
diff --git a/drivers/media/video/zoran/zoran_device.h b/drivers/media/video/zoran/zoran_device.h
new file mode 100644 (file)
index 0000000..74c6c8e
--- /dev/null
@@ -0,0 +1,97 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles card-specific data and detection
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __ZORAN_DEVICE_H__
+#define __ZORAN_DEVICE_H__
+
+/* general purpose I/O */
+extern void GPIO(struct zoran *zr,
+                int bit,
+                unsigned int value);
+
+/* codec (or actually: guest bus) access */
+extern int post_office_wait(struct zoran *zr);
+extern int post_office_write(struct zoran *zr,
+                            unsigned guest,
+                            unsigned reg,
+                            unsigned value);
+extern int post_office_read(struct zoran *zr,
+                           unsigned guest,
+                           unsigned reg);
+
+extern void detect_guest_activity(struct zoran *zr);
+
+extern void jpeg_codec_sleep(struct zoran *zr,
+                            int sleep);
+extern int jpeg_codec_reset(struct zoran *zr);
+
+/* zr360x7 access to raw capture */
+extern void zr36057_overlay(struct zoran *zr,
+                           int on);
+extern void write_overlay_mask(struct file *file,
+                              struct video_clip *vp,
+                              int count);
+extern void zr36057_set_memgrab(struct zoran *zr,
+                               int mode);
+extern int wait_grab_pending(struct zoran *zr);
+
+/* interrupts */
+extern void print_interrupts(struct zoran *zr);
+extern void clear_interrupt_counters(struct zoran *zr);
+extern irqreturn_t zoran_irq(int irq, void *dev_id);
+
+/* JPEG codec access */
+extern void jpeg_start(struct zoran *zr);
+extern void zr36057_enable_jpg(struct zoran *zr,
+                              enum zoran_codec_mode mode);
+extern void zoran_feed_stat_com(struct zoran *zr);
+
+/* general */
+extern void zoran_set_pci_master(struct zoran *zr,
+                                int set_master);
+extern void zoran_init_hardware(struct zoran *zr);
+extern void zr36057_restart(struct zoran *zr);
+
+extern const struct zoran_format zoran_formats[];
+
+extern int v4l_nbufs;
+extern int v4l_bufsize;
+extern int jpg_nbufs;
+extern int jpg_bufsize;
+extern int pass_through;
+
+/* i2c */
+extern int decoder_command(struct zoran *zr,
+                          int cmd,
+                          void *data);
+extern int encoder_command(struct zoran *zr,
+                          int cmd,
+                          void *data);
+
+#endif                         /* __ZORAN_DEVICE_H__ */
diff --git a/drivers/media/video/zoran/zoran_driver.c b/drivers/media/video/zoran/zoran_driver.c
new file mode 100644 (file)
index 0000000..25de763
--- /dev/null
@@ -0,0 +1,4649 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Changes for BUZ by Wolfgang Scherr <scherr@net4you.net>
+ *
+ * Changes for DC10/DC30 by Laurent Pinchart <laurent.pinchart@skynet.be>
+ *
+ * Changes for LML33R10 by Maxim Yevtyushkin <max@linuxmedialabs.com>
+ *
+ * Changes for videodev2/v4l2 by Ronald Bultje <rbultje@ronald.bitfreak.net>
+ *
+ * Based on
+ *
+ * Miro DC10 driver
+ * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net>
+ *
+ * Iomega Buz driver version 1.0
+ * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
+ *
+ * buz.0.0.3
+ * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
+ *
+ * bttv - Bt848 frame grabber driver
+ * Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
+ *                        & Marcus Metzler (mocm@thp.uni-koeln.de)
+ *
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/version.h>
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/pci.h>
+#include <linux/vmalloc.h>
+#include <linux/wait.h>
+
+#include <linux/interrupt.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+
+#include <linux/spinlock.h>
+#define     MAP_NR(x)       virt_to_page(x)
+#define     ZORAN_VID_TYPE  ( \
+                               VID_TYPE_CAPTURE | \
+                               VID_TYPE_OVERLAY | \
+                               VID_TYPE_CLIPPING | \
+                               VID_TYPE_FRAMERAM | \
+                               VID_TYPE_SCALES | \
+                               VID_TYPE_MJPEG_DECODER | \
+                               VID_TYPE_MJPEG_ENCODER \
+                            )
+
+#include <linux/videodev.h>
+#include <media/v4l2-common.h>
+#include <media/v4l2-ioctl.h>
+#include "videocodec.h"
+
+#include <asm/byteorder.h>
+#include <asm/io.h>
+#include <asm/uaccess.h>
+#include <linux/proc_fs.h>
+
+#include <linux/video_decoder.h>
+#include <linux/video_encoder.h>
+#include <linux/mutex.h>
+#include "zoran.h"
+#include "zoran_device.h"
+#include "zoran_card.h"
+
+       /* we declare some card type definitions here, they mean
+        * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
+#define ZORAN_V4L2_VID_FLAGS ( \
+                               V4L2_CAP_STREAMING |\
+                               V4L2_CAP_VIDEO_CAPTURE |\
+                               V4L2_CAP_VIDEO_OUTPUT |\
+                               V4L2_CAP_VIDEO_OVERLAY \
+                             )
+
+
+#if defined(CONFIG_VIDEO_V4L1_COMPAT)
+#define ZFMT(pal, fcc, cs) \
+       .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
+#else
+#define ZFMT(pal, fcc, cs) \
+       .fourcc = (fcc), .colorspace = (cs)
+#endif
+
+const struct zoran_format zoran_formats[] = {
+       {
+               .name = "15-bit RGB LE",
+               ZFMT(VIDEO_PALETTE_RGB555,
+                    V4L2_PIX_FMT_RGB555, V4L2_COLORSPACE_SRGB),
+               .depth = 15,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif|
+                          ZR36057_VFESPFR_LittleEndian,
+       }, {
+               .name = "15-bit RGB BE",
+               ZFMT(-1,
+                    V4L2_PIX_FMT_RGB555X, V4L2_COLORSPACE_SRGB),
+               .depth = 15,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif,
+       }, {
+               .name = "16-bit RGB LE",
+               ZFMT(VIDEO_PALETTE_RGB565,
+                    V4L2_PIX_FMT_RGB565, V4L2_COLORSPACE_SRGB),
+               .depth = 16,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif|
+                          ZR36057_VFESPFR_LittleEndian,
+       }, {
+               .name = "16-bit RGB BE",
+               ZFMT(-1,
+                    V4L2_PIX_FMT_RGB565X, V4L2_COLORSPACE_SRGB),
+               .depth = 16,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif,
+       }, {
+               .name = "24-bit RGB",
+               ZFMT(VIDEO_PALETTE_RGB24,
+                    V4L2_PIX_FMT_BGR24, V4L2_COLORSPACE_SRGB),
+               .depth = 24,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24,
+       }, {
+               .name = "32-bit RGB LE",
+               ZFMT(VIDEO_PALETTE_RGB32,
+                    V4L2_PIX_FMT_BGR32, V4L2_COLORSPACE_SRGB),
+               .depth = 32,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian,
+       }, {
+               .name = "32-bit RGB BE",
+               ZFMT(-1,
+                    V4L2_PIX_FMT_RGB32, V4L2_COLORSPACE_SRGB),
+               .depth = 32,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_RGB888,
+       }, {
+               .name = "4:2:2, packed, YUYV",
+               ZFMT(VIDEO_PALETTE_YUV422,
+                    V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_SMPTE170M),
+               .depth = 16,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_YUV422,
+       }, {
+               .name = "4:2:2, packed, UYVY",
+               ZFMT(VIDEO_PALETTE_UYVY,
+                    V4L2_PIX_FMT_UYVY, V4L2_COLORSPACE_SMPTE170M),
+               .depth = 16,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_OVERLAY,
+               .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian,
+       }, {
+               .name = "Hardware-encoded Motion-JPEG",
+               ZFMT(-1,
+                    V4L2_PIX_FMT_MJPEG, V4L2_COLORSPACE_SMPTE170M),
+               .depth = 0,
+               .flags = ZORAN_FORMAT_CAPTURE |
+                        ZORAN_FORMAT_PLAYBACK |
+                        ZORAN_FORMAT_COMPRESSED,
+       }
+};
+#define NUM_FORMATS ARRAY_SIZE(zoran_formats)
+
+// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
+
+
+static int lock_norm;  /* 0 = default 1 = Don't change TV standard (norm) */
+module_param(lock_norm, int, 0644);
+MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
+
+       /* small helper function for calculating buffersizes for v4l2
+        * we calculate the nearest higher power-of-two, which
+        * will be the recommended buffersize */
+static __u32
+zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings)
+{
+       __u8 div = settings->VerDcm * settings->HorDcm * settings->TmpDcm;
+       __u32 num = (1024 * 512) / (div);
+       __u32 result = 2;
+
+       num--;
+       while (num) {
+               num >>= 1;
+               result <<= 1;
+       }
+
+       if (result > jpg_bufsize)
+               return jpg_bufsize;
+       if (result < 8192)
+               return 8192;
+       return result;
+}
+
+/* forward references */
+static void v4l_fbuffer_free(struct file *file);
+static void jpg_fbuffer_free(struct file *file);
+
+/*
+ *   Allocate the V4L grab buffers
+ *
+ *   These have to be pysically contiguous.
+ *   If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc
+ *   else we try to allocate them with bigphysarea_alloc_pages
+ *   if the bigphysarea patch is present in the kernel,
+ *   else we try to use high memory (if the user has bootet
+ *   Linux with the necessary memory left over).
+ */
+
+static unsigned long
+get_high_mem (unsigned long size)
+{
+/*
+ * Check if there is usable memory at the end of Linux memory
+ * of at least size. Return the physical address of this memory,
+ * return 0 on failure.
+ *
+ * The idea is from Alexandro Rubini's book "Linux device drivers".
+ * The driver from him which is downloadable from O'Reilly's
+ * web site misses the "virt_to_phys(high_memory)" part
+ * (and therefore doesn't work at all - at least with 2.2.x kernels).
+ *
+ * It should be unnecessary to mention that THIS IS DANGEROUS,
+ * if more than one driver at a time has the idea to use this memory!!!!
+ */
+
+       volatile unsigned char __iomem *mem;
+       unsigned char c;
+       unsigned long hi_mem_ph;
+       unsigned long i;
+
+       /* Map the high memory to user space */
+
+       hi_mem_ph = virt_to_phys(high_memory);
+
+       mem = ioremap(hi_mem_ph, size);
+       if (!mem) {
+               dprintk(1,
+                       KERN_ERR "%s: get_high_mem() - ioremap failed\n",
+                       ZORAN_NAME);
+               return 0;
+       }
+
+       for (i = 0; i < size; i++) {
+               /* Check if it is memory */
+               c = i & 0xff;
+               writeb(c, mem + i);
+               if (readb(mem + i) != c)
+                       break;
+               c = 255 - c;
+               writeb(c, mem + i);
+               if (readb(mem + i) != c)
+                       break;
+               writeb(0, mem + i);     /* zero out memory */
+
+               /* give the kernel air to breath */
+               if ((i & 0x3ffff) == 0x3ffff)
+                       schedule();
+       }
+
+       iounmap(mem);
+
+       if (i != size) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: get_high_mem() - requested %lu, avail %lu\n",
+                       ZORAN_NAME, size, i);
+               return 0;
+       }
+
+       return hi_mem_ph;
+}
+
+static int
+v4l_fbuffer_alloc (struct file *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int i, off;
+       unsigned char *mem;
+       unsigned long pmem = 0;
+
+       /* we might have old buffers lying around... */
+       if (fh->v4l_buffers.ready_to_be_freed) {
+               v4l_fbuffer_free(file);
+       }
+
+       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
+               if (fh->v4l_buffers.buffer[i].fbuffer)
+                       dprintk(2,
+                               KERN_WARNING
+                               "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n",
+                               ZR_DEVNAME(zr), i);
+
+               //udelay(20);
+               if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
+                       /* Use kmalloc */
+
+                       mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL);
+                       if (!mem) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
+                                       ZR_DEVNAME(zr), i);
+                               v4l_fbuffer_free(file);
+                               return -ENOBUFS;
+                       }
+                       fh->v4l_buffers.buffer[i].fbuffer = mem;
+                       fh->v4l_buffers.buffer[i].fbuffer_phys =
+                           virt_to_phys(mem);
+                       fh->v4l_buffers.buffer[i].fbuffer_bus =
+                           virt_to_bus(mem);
+                       for (off = 0; off < fh->v4l_buffers.buffer_size;
+                            off += PAGE_SIZE)
+                               SetPageReserved(MAP_NR(mem + off));
+                       dprintk(4,
+                               KERN_INFO
+                               "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
+                               ZR_DEVNAME(zr), i, (unsigned long) mem,
+                               virt_to_bus(mem));
+               } else {
+
+                       /* Use high memory which has been left at boot time */
+
+                       /* Ok., Ok. this is an evil hack - we make
+                        * the assumption that physical addresses are
+                        * the same as bus addresses (true at least
+                        * for Intel processors). The whole method of
+                        * obtaining and using this memory is not very
+                        * nice - but I hope it saves some poor users
+                        * from kernel hacking, which might have even
+                        * more evil results */
+
+                       if (i == 0) {
+                               int size =
+                                   fh->v4l_buffers.num_buffers *
+                                   fh->v4l_buffers.buffer_size;
+
+                               pmem = get_high_mem(size);
+                               if (pmem == 0) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
+                                               ZR_DEVNAME(zr), size >> 10);
+                                       return -ENOBUFS;
+                               }
+                               fh->v4l_buffers.buffer[0].fbuffer = NULL;
+                               fh->v4l_buffers.buffer[0].fbuffer_phys = pmem;
+                               fh->v4l_buffers.buffer[0].fbuffer_bus = pmem;
+                               dprintk(4,
+                                       KERN_INFO
+                                       "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
+                                       ZR_DEVNAME(zr), size >> 10);
+                       } else {
+                               fh->v4l_buffers.buffer[i].fbuffer = NULL;
+                               fh->v4l_buffers.buffer[i].fbuffer_phys =
+                                   pmem + i * fh->v4l_buffers.buffer_size;
+                               fh->v4l_buffers.buffer[i].fbuffer_bus =
+                                   pmem + i * fh->v4l_buffers.buffer_size;
+                       }
+               }
+       }
+
+       fh->v4l_buffers.allocated = 1;
+
+       return 0;
+}
+
+/* free the V4L grab buffers */
+static void
+v4l_fbuffer_free (struct file *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int i, off;
+       unsigned char *mem;
+
+       dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr));
+
+       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
+               if (!fh->v4l_buffers.buffer[i].fbuffer)
+                       continue;
+
+               if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
+                       mem = fh->v4l_buffers.buffer[i].fbuffer;
+                       for (off = 0; off < fh->v4l_buffers.buffer_size;
+                            off += PAGE_SIZE)
+                               ClearPageReserved(MAP_NR(mem + off));
+                       kfree((void *) fh->v4l_buffers.buffer[i].fbuffer);
+               }
+               fh->v4l_buffers.buffer[i].fbuffer = NULL;
+       }
+
+       fh->v4l_buffers.allocated = 0;
+       fh->v4l_buffers.ready_to_be_freed = 0;
+}
+
+/*
+ *   Allocate the MJPEG grab buffers.
+ *
+ *   If the requested buffer size is smaller than MAX_KMALLOC_MEM,
+ *   kmalloc is used to request a physically contiguous area,
+ *   else we allocate the memory in framgents with get_zeroed_page.
+ *
+ *   If a Natoma chipset is present and this is a revision 1 zr36057,
+ *   each MJPEG buffer needs to be physically contiguous.
+ *   (RJ: This statement is from Dave Perks' original driver,
+ *   I could never check it because I have a zr36067)
+ *   The driver cares about this because it reduces the buffer
+ *   size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
+ *
+ *   RJ: The contents grab buffers needs never be accessed in the driver.
+ *       Therefore there is no need to allocate them with vmalloc in order
+ *       to get a contiguous virtual memory space.
+ *       I don't understand why many other drivers first allocate them with
+ *       vmalloc (which uses internally also get_zeroed_page, but delivers you
+ *       virtual addresses) and then again have to make a lot of efforts
+ *       to get the physical address.
+ *
+ *   Ben Capper:
+ *       On big-endian architectures (such as ppc) some extra steps
+ *       are needed. When reading and writing to the stat_com array
+ *       and fragment buffers, the device expects to see little-
+ *       endian values. The use of cpu_to_le32() and le32_to_cpu()
+ *       in this function (and one or two others in zoran_device.c)
+ *       ensure that these values are always stored in little-endian
+ *       form, regardless of architecture. The zr36057 does Very Bad
+ *       Things on big endian architectures if the stat_com array
+ *       and fragment buffers are not little-endian.
+ */
+
+static int
+jpg_fbuffer_alloc (struct file *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int i, j, off;
+       unsigned long mem;
+
+       /* we might have old buffers lying around */
+       if (fh->jpg_buffers.ready_to_be_freed) {
+               jpg_fbuffer_free(file);
+       }
+
+       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
+               if (fh->jpg_buffers.buffer[i].frag_tab)
+                       dprintk(2,
+                               KERN_WARNING
+                               "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n",
+                               ZR_DEVNAME(zr), i);
+
+               /* Allocate fragment table for this buffer */
+
+               mem = get_zeroed_page(GFP_KERNEL);
+               if (mem == 0) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
+                               ZR_DEVNAME(zr), i);
+                       jpg_fbuffer_free(file);
+                       return -ENOBUFS;
+               }
+               fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem;
+               fh->jpg_buffers.buffer[i].frag_tab_bus =
+                   virt_to_bus((void *) mem);
+
+               //if (alloc_contig) {
+               if (fh->jpg_buffers.need_contiguous) {
+                       mem =
+                           (unsigned long) kmalloc(fh->jpg_buffers.
+                                                   buffer_size,
+                                                   GFP_KERNEL);
+                       if (mem == 0) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
+                                       ZR_DEVNAME(zr), i);
+                               jpg_fbuffer_free(file);
+                               return -ENOBUFS;
+                       }
+                       fh->jpg_buffers.buffer[i].frag_tab[0] =
+                           cpu_to_le32(virt_to_bus((void *) mem));
+                       fh->jpg_buffers.buffer[i].frag_tab[1] =
+                           cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1);
+                       for (off = 0; off < fh->jpg_buffers.buffer_size;
+                            off += PAGE_SIZE)
+                               SetPageReserved(MAP_NR(mem + off));
+               } else {
+                       /* jpg_bufsize is allreay page aligned */
+                       for (j = 0;
+                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
+                            j++) {
+                               mem = get_zeroed_page(GFP_KERNEL);
+                               if (mem == 0) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
+                                               ZR_DEVNAME(zr), i);
+                                       jpg_fbuffer_free(file);
+                                       return -ENOBUFS;
+                               }
+
+                               fh->jpg_buffers.buffer[i].frag_tab[2 * j] =
+                                   cpu_to_le32(virt_to_bus((void *) mem));
+                               fh->jpg_buffers.buffer[i].frag_tab[2 * j +
+                                                                  1] =
+                                   cpu_to_le32((PAGE_SIZE / 4) << 1);
+                               SetPageReserved(MAP_NR(mem));
+                       }
+
+                       fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1);
+               }
+       }
+
+       dprintk(4,
+               KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n",
+               ZR_DEVNAME(zr),
+               (fh->jpg_buffers.num_buffers *
+                fh->jpg_buffers.buffer_size) >> 10);
+
+       fh->jpg_buffers.allocated = 1;
+
+       return 0;
+}
+
+/* free the MJPEG grab buffers */
+static void
+jpg_fbuffer_free (struct file *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int i, j, off;
+       unsigned char *mem;
+
+       dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr));
+
+       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
+               if (!fh->jpg_buffers.buffer[i].frag_tab)
+                       continue;
+
+               //if (alloc_contig) {
+               if (fh->jpg_buffers.need_contiguous) {
+                       if (fh->jpg_buffers.buffer[i].frag_tab[0]) {
+                               mem = (unsigned char *) bus_to_virt(le32_to_cpu(
+                                       fh->jpg_buffers.buffer[i].frag_tab[0]));
+                               for (off = 0;
+                                    off < fh->jpg_buffers.buffer_size;
+                                    off += PAGE_SIZE)
+                                       ClearPageReserved(MAP_NR
+                                                         (mem + off));
+                               kfree(mem);
+                               fh->jpg_buffers.buffer[i].frag_tab[0] = 0;
+                               fh->jpg_buffers.buffer[i].frag_tab[1] = 0;
+                       }
+               } else {
+                       for (j = 0;
+                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
+                            j++) {
+                               if (!fh->jpg_buffers.buffer[i].
+                                   frag_tab[2 * j])
+                                       break;
+                               ClearPageReserved(MAP_NR
+                                                 (bus_to_virt
+                                                  (le32_to_cpu
+                                                   (fh->jpg_buffers.
+                                                    buffer[i].frag_tab[2 *
+                                                                      j]))));
+                               free_page((unsigned long)
+                                         bus_to_virt
+                                                 (le32_to_cpu
+                                                  (fh->jpg_buffers.
+                                                     buffer[i].
+                                                     frag_tab[2 * j])));
+                               fh->jpg_buffers.buffer[i].frag_tab[2 * j] =
+                                   0;
+                               fh->jpg_buffers.buffer[i].frag_tab[2 * j +
+                                                                  1] = 0;
+                       }
+               }
+
+               free_page((unsigned long) fh->jpg_buffers.buffer[i].
+                         frag_tab);
+               fh->jpg_buffers.buffer[i].frag_tab = NULL;
+       }
+
+       fh->jpg_buffers.allocated = 0;
+       fh->jpg_buffers.ready_to_be_freed = 0;
+}
+
+/*
+ *   V4L Buffer grabbing
+ */
+
+static int
+zoran_v4l_set_format (struct file               *file,
+                     int                        width,
+                     int                        height,
+                     const struct zoran_format *format)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int bpp;
+
+       /* Check size and format of the grab wanted */
+
+       if (height < BUZ_MIN_HEIGHT || width < BUZ_MIN_WIDTH ||
+           height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_set_format() - wrong frame size (%dx%d)\n",
+                       ZR_DEVNAME(zr), width, height);
+               return -EINVAL;
+       }
+
+       bpp = (format->depth + 7) / 8;
+
+       /* Check against available buffer size */
+       if (height * width * bpp > fh->v4l_buffers.buffer_size) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_set_format() - video buffer size (%d kB) is too small\n",
+                       ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10);
+               return -EINVAL;
+       }
+
+       /* The video front end needs 4-byte alinged line sizes */
+
+       if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_set_format() - wrong frame alingment\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       fh->v4l_settings.width = width;
+       fh->v4l_settings.height = height;
+       fh->v4l_settings.format = format;
+       fh->v4l_settings.bytesperline = bpp * fh->v4l_settings.width;
+
+       return 0;
+}
+
+static int
+zoran_v4l_queue_frame (struct file *file,
+                      int          num)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned long flags;
+       int res = 0;
+
+       if (!fh->v4l_buffers.allocated) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_queue_frame() - buffers not yet allocated\n",
+                       ZR_DEVNAME(zr));
+               res = -ENOMEM;
+       }
+
+       /* No grabbing outside the buffer range! */
+       if (num >= fh->v4l_buffers.num_buffers || num < 0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_queue_frame() - buffer %d is out of range\n",
+                       ZR_DEVNAME(zr), num);
+               res = -EINVAL;
+       }
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+
+       if (fh->v4l_buffers.active == ZORAN_FREE) {
+               if (zr->v4l_buffers.active == ZORAN_FREE) {
+                       zr->v4l_buffers = fh->v4l_buffers;
+                       fh->v4l_buffers.active = ZORAN_ACTIVE;
+               } else {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: v4l_queue_frame() - another session is already capturing\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+               }
+       }
+
+       /* make sure a grab isn't going on currently with this buffer */
+       if (!res) {
+               switch (zr->v4l_buffers.buffer[num].state) {
+               default:
+               case BUZ_STATE_PEND:
+                       if (zr->v4l_buffers.active == ZORAN_FREE) {
+                               fh->v4l_buffers.active = ZORAN_FREE;
+                               zr->v4l_buffers.allocated = 0;
+                       }
+                       res = -EBUSY;   /* what are you doing? */
+                       break;
+               case BUZ_STATE_DONE:
+                       dprintk(2,
+                               KERN_WARNING
+                               "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n",
+                               ZR_DEVNAME(zr), num);
+               case BUZ_STATE_USER:
+                       /* since there is at least one unused buffer there's room for at least
+                        * one more pend[] entry */
+                       zr->v4l_pend[zr->v4l_pend_head++ &
+                                       V4L_MASK_FRAME] = num;
+                       zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND;
+                       zr->v4l_buffers.buffer[num].bs.length =
+                           fh->v4l_settings.bytesperline *
+                           zr->v4l_settings.height;
+                       fh->v4l_buffers.buffer[num] =
+                           zr->v4l_buffers.buffer[num];
+                       break;
+               }
+       }
+
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       if (!res && zr->v4l_buffers.active == ZORAN_FREE)
+               zr->v4l_buffers.active = fh->v4l_buffers.active;
+
+       return res;
+}
+
+static int
+v4l_grab (struct file       *file,
+         struct video_mmap *mp)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int res = 0, i;
+
+       for (i = 0; i < NUM_FORMATS; i++) {
+               if (zoran_formats[i].palette == mp->format &&
+                   zoran_formats[i].flags & ZORAN_FORMAT_CAPTURE &&
+                   !(zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED))
+                       break;
+       }
+       if (i == NUM_FORMATS || zoran_formats[i].depth == 0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_grab() - wrong bytes-per-pixel format\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       /*
+        * To minimize the time spent in the IRQ routine, we avoid setting up
+        * the video front end there.
+        * If this grab has different parameters from a running streaming capture
+        * we stop the streaming capture and start it over again.
+        */
+       if (zr->v4l_memgrab_active &&
+           (zr->v4l_settings.width != mp->width ||
+            zr->v4l_settings.height != mp->height ||
+            zr->v4l_settings.format->palette != mp->format)) {
+               res = wait_grab_pending(zr);
+               if (res)
+                       return res;
+       }
+       if ((res = zoran_v4l_set_format(file,
+                                       mp->width,
+                                       mp->height,
+                                       &zoran_formats[i])))
+               return res;
+       zr->v4l_settings = fh->v4l_settings;
+
+       /* queue the frame in the pending queue */
+       if ((res = zoran_v4l_queue_frame(file, mp->frame))) {
+               fh->v4l_buffers.active = ZORAN_FREE;
+               return res;
+       }
+
+       /* put the 36057 into frame grabbing mode */
+       if (!res && !zr->v4l_memgrab_active)
+               zr36057_set_memgrab(zr, 1);
+
+       //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
+
+       return res;
+}
+
+/*
+ * Sync on a V4L buffer
+ */
+
+static int
+v4l_sync (struct file *file,
+         int          frame)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned long flags;
+
+       if (fh->v4l_buffers.active == ZORAN_FREE) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_sync() - no grab active for this session\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       /* check passed-in frame number */
+       if (frame >= fh->v4l_buffers.num_buffers || frame < 0) {
+               dprintk(1,
+                       KERN_ERR "%s: v4l_sync() - frame %d is invalid\n",
+                       ZR_DEVNAME(zr), frame);
+               return -EINVAL;
+       }
+
+       /* Check if is buffer was queued at all */
+       if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n",
+                       ZR_DEVNAME(zr));
+               return -EPROTO;
+       }
+
+       /* wait on this buffer to get ready */
+       if (!wait_event_interruptible_timeout(zr->v4l_capq,
+                               (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND),
+                               10*HZ))
+               return -ETIME;
+       if (signal_pending(current))
+               return -ERESTARTSYS;
+
+       /* buffer should now be in BUZ_STATE_DONE */
+       if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE)
+               dprintk(2,
+                       KERN_ERR "%s: v4l_sync() - internal state error\n",
+                       ZR_DEVNAME(zr));
+
+       zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER;
+       fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame];
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+
+       /* Check if streaming capture has finished */
+       if (zr->v4l_pend_tail == zr->v4l_pend_head) {
+               zr36057_set_memgrab(zr, 0);
+               if (zr->v4l_buffers.active == ZORAN_ACTIVE) {
+                       fh->v4l_buffers.active = zr->v4l_buffers.active =
+                           ZORAN_FREE;
+                       zr->v4l_buffers.allocated = 0;
+               }
+       }
+
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       return 0;
+}
+
+/*
+ *   Queue a MJPEG buffer for capture/playback
+ */
+
+static int
+zoran_jpg_queue_frame (struct file          *file,
+                      int                   num,
+                      enum zoran_codec_mode mode)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned long flags;
+       int res = 0;
+
+       /* Check if buffers are allocated */
+       if (!fh->jpg_buffers.allocated) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_queue_frame() - buffers not yet allocated\n",
+                       ZR_DEVNAME(zr));
+               return -ENOMEM;
+       }
+
+       /* No grabbing outside the buffer range! */
+       if (num >= fh->jpg_buffers.num_buffers || num < 0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_queue_frame() - buffer %d out of range\n",
+                       ZR_DEVNAME(zr), num);
+               return -EINVAL;
+       }
+
+       /* what is the codec mode right now? */
+       if (zr->codec_mode == BUZ_MODE_IDLE) {
+               zr->jpg_settings = fh->jpg_settings;
+       } else if (zr->codec_mode != mode) {
+               /* wrong codec mode active - invalid */
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_queue_frame() - codec in wrong mode\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       if (fh->jpg_buffers.active == ZORAN_FREE) {
+               if (zr->jpg_buffers.active == ZORAN_FREE) {
+                       zr->jpg_buffers = fh->jpg_buffers;
+                       fh->jpg_buffers.active = ZORAN_ACTIVE;
+               } else {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: jpg_queue_frame() - another session is already capturing\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+               }
+       }
+
+       if (!res && zr->codec_mode == BUZ_MODE_IDLE) {
+               /* Ok load up the jpeg codec */
+               zr36057_enable_jpg(zr, mode);
+       }
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+
+       if (!res) {
+               switch (zr->jpg_buffers.buffer[num].state) {
+               case BUZ_STATE_DONE:
+                       dprintk(2,
+                               KERN_WARNING
+                               "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n",
+                               ZR_DEVNAME(zr));
+               case BUZ_STATE_USER:
+                       /* since there is at least one unused buffer there's room for at
+                        *least one more pend[] entry */
+                       zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] =
+                           num;
+                       zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND;
+                       fh->jpg_buffers.buffer[num] =
+                           zr->jpg_buffers.buffer[num];
+                       zoran_feed_stat_com(zr);
+                       break;
+               default:
+               case BUZ_STATE_DMA:
+               case BUZ_STATE_PEND:
+                       if (zr->jpg_buffers.active == ZORAN_FREE) {
+                               fh->jpg_buffers.active = ZORAN_FREE;
+                               zr->jpg_buffers.allocated = 0;
+                       }
+                       res = -EBUSY;   /* what are you doing? */
+                       break;
+               }
+       }
+
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       if (!res && zr->jpg_buffers.active == ZORAN_FREE) {
+               zr->jpg_buffers.active = fh->jpg_buffers.active;
+       }
+
+       return res;
+}
+
+static int
+jpg_qbuf (struct file          *file,
+         int                   frame,
+         enum zoran_codec_mode mode)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int res = 0;
+
+       /* Does the user want to stop streaming? */
+       if (frame < 0) {
+               if (zr->codec_mode == mode) {
+                       if (fh->jpg_buffers.active == ZORAN_FREE) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: jpg_qbuf(-1) - session not active\n",
+                                       ZR_DEVNAME(zr));
+                               return -EINVAL;
+                       }
+                       fh->jpg_buffers.active = zr->jpg_buffers.active =
+                           ZORAN_FREE;
+                       zr->jpg_buffers.allocated = 0;
+                       zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
+                       return 0;
+               } else {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: jpg_qbuf() - stop streaming but not in streaming mode\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+       }
+
+       if ((res = zoran_jpg_queue_frame(file, frame, mode)))
+               return res;
+
+       /* Start the jpeg codec when the first frame is queued  */
+       if (!res && zr->jpg_que_head == 1)
+               jpeg_start(zr);
+
+       return res;
+}
+
+/*
+ *   Sync on a MJPEG buffer
+ */
+
+static int
+jpg_sync (struct file       *file,
+         struct zoran_sync *bs)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned long flags;
+       int frame;
+
+       if (fh->jpg_buffers.active == ZORAN_FREE) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_sync() - capture is not currently active\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+       if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS &&
+           zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_sync() - codec not in streaming mode\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+       if (!wait_event_interruptible_timeout(zr->jpg_capq,
+                       (zr->jpg_que_tail != zr->jpg_dma_tail ||
+                        zr->jpg_dma_tail == zr->jpg_dma_head),
+                       10*HZ)) {
+               int isr;
+
+               btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
+               udelay(1);
+               zr->codec->control(zr->codec, CODEC_G_STATUS,
+                                          sizeof(isr), &isr);
+               dprintk(1,
+                       KERN_ERR
+                       "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
+                       ZR_DEVNAME(zr), isr);
+
+               return -ETIME;
+
+       }
+       if (signal_pending(current))
+               return -ERESTARTSYS;
+
+       spin_lock_irqsave(&zr->spinlock, flags);
+
+       if (zr->jpg_dma_tail != zr->jpg_dma_head)
+               frame = zr->jpg_pend[zr->jpg_que_tail++ & BUZ_MASK_FRAME];
+       else
+               frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
+
+       /* buffer should now be in BUZ_STATE_DONE */
+       if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE)
+               dprintk(2,
+                       KERN_ERR "%s: jpg_sync() - internal state error\n",
+                       ZR_DEVNAME(zr));
+
+       *bs = zr->jpg_buffers.buffer[frame].bs;
+       bs->frame = frame;
+       zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER;
+       fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame];
+
+       spin_unlock_irqrestore(&zr->spinlock, flags);
+
+       return 0;
+}
+
+static void
+zoran_open_init_session (struct file *file)
+{
+       int i;
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       /* Per default, map the V4L Buffers */
+       fh->map_mode = ZORAN_MAP_MODE_RAW;
+
+       /* take over the card's current settings */
+       fh->overlay_settings = zr->overlay_settings;
+       fh->overlay_settings.is_set = 0;
+       fh->overlay_settings.format = zr->overlay_settings.format;
+       fh->overlay_active = ZORAN_FREE;
+
+       /* v4l settings */
+       fh->v4l_settings = zr->v4l_settings;
+
+       /* v4l_buffers */
+       memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct));
+       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
+               fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
+               fh->v4l_buffers.buffer[i].bs.frame = i;
+       }
+       fh->v4l_buffers.allocated = 0;
+       fh->v4l_buffers.ready_to_be_freed = 0;
+       fh->v4l_buffers.active = ZORAN_FREE;
+       fh->v4l_buffers.buffer_size = v4l_bufsize;
+       fh->v4l_buffers.num_buffers = v4l_nbufs;
+
+       /* jpg settings */
+       fh->jpg_settings = zr->jpg_settings;
+
+       /* jpg_buffers */
+       memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct));
+       for (i = 0; i < BUZ_MAX_FRAME; i++) {
+               fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
+               fh->jpg_buffers.buffer[i].bs.frame = i;
+       }
+       fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous;
+       fh->jpg_buffers.allocated = 0;
+       fh->jpg_buffers.ready_to_be_freed = 0;
+       fh->jpg_buffers.active = ZORAN_FREE;
+       fh->jpg_buffers.buffer_size = jpg_bufsize;
+       fh->jpg_buffers.num_buffers = jpg_nbufs;
+}
+
+static void
+zoran_close_end_session (struct file *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       /* overlay */
+       if (fh->overlay_active != ZORAN_FREE) {
+               fh->overlay_active = zr->overlay_active = ZORAN_FREE;
+               zr->v4l_overlay_active = 0;
+               if (!zr->v4l_memgrab_active)
+                       zr36057_overlay(zr, 0);
+               zr->overlay_mask = NULL;
+       }
+
+       /* v4l capture */
+       if (fh->v4l_buffers.active != ZORAN_FREE) {
+               unsigned long flags;
+
+               spin_lock_irqsave(&zr->spinlock, flags);
+               zr36057_set_memgrab(zr, 0);
+               zr->v4l_buffers.allocated = 0;
+               zr->v4l_buffers.active = fh->v4l_buffers.active =
+                   ZORAN_FREE;
+               spin_unlock_irqrestore(&zr->spinlock, flags);
+       }
+
+       /* v4l buffers */
+       if (fh->v4l_buffers.allocated ||
+           fh->v4l_buffers.ready_to_be_freed) {
+               v4l_fbuffer_free(file);
+       }
+
+       /* jpg capture */
+       if (fh->jpg_buffers.active != ZORAN_FREE) {
+               zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
+               zr->jpg_buffers.allocated = 0;
+               zr->jpg_buffers.active = fh->jpg_buffers.active =
+                   ZORAN_FREE;
+       }
+
+       /* jpg buffers */
+       if (fh->jpg_buffers.allocated ||
+           fh->jpg_buffers.ready_to_be_freed) {
+               jpg_fbuffer_free(file);
+       }
+}
+
+/*
+ *   Open a zoran card. Right now the flags stuff is just playing
+ */
+
+static int
+zoran_open (struct inode *inode,
+           struct file  *file)
+{
+       unsigned int minor = iminor(inode);
+       struct zoran *zr = NULL;
+       struct zoran_fh *fh;
+       int i, res, first_open = 0, have_module_locks = 0;
+
+       lock_kernel();
+       /* find the device */
+       for (i = 0; i < zoran_num; i++) {
+               if (zoran[i]->video_dev->minor == minor) {
+                       zr = zoran[i];
+                       break;
+               }
+       }
+
+       if (!zr) {
+               dprintk(1, KERN_ERR "%s: device not found!\n", ZORAN_NAME);
+               res = -ENODEV;
+               goto open_unlock_and_return;
+       }
+
+       /* see fs/device.c - the kernel already locks during open(),
+        * so locking ourselves only causes deadlocks */
+       /*mutex_lock(&zr->resource_lock);*/
+
+       if (!zr->decoder) {
+               dprintk(1,
+                       KERN_ERR "%s: no TV decoder loaded for device!\n",
+                       ZR_DEVNAME(zr));
+               res = -EIO;
+               goto open_unlock_and_return;
+       }
+
+       /* try to grab a module lock */
+       if (!try_module_get(THIS_MODULE)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: failed to acquire my own lock! PANIC!\n",
+                       ZR_DEVNAME(zr));
+               res = -ENODEV;
+               goto open_unlock_and_return;
+       }
+       if (!try_module_get(zr->decoder->driver->driver.owner)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: failed to grab ownership of i2c decoder\n",
+                       ZR_DEVNAME(zr));
+               res = -EIO;
+               module_put(THIS_MODULE);
+               goto open_unlock_and_return;
+       }
+       if (zr->encoder &&
+           !try_module_get(zr->encoder->driver->driver.owner)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: failed to grab ownership of i2c encoder\n",
+                       ZR_DEVNAME(zr));
+               res = -EIO;
+               module_put(zr->decoder->driver->driver.owner);
+               module_put(THIS_MODULE);
+               goto open_unlock_and_return;
+       }
+
+       have_module_locks = 1;
+
+       if (zr->user >= 2048) {
+               dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
+                       ZR_DEVNAME(zr), zr->user);
+               res = -EBUSY;
+               goto open_unlock_and_return;
+       }
+
+       dprintk(1, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
+               ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
+
+       /* now, create the open()-specific file_ops struct */
+       fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
+       if (!fh) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_open() - allocation of zoran_fh failed\n",
+                       ZR_DEVNAME(zr));
+               res = -ENOMEM;
+               goto open_unlock_and_return;
+       }
+       /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
+        * on norm-change! */
+       fh->overlay_mask =
+           kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL);
+       if (!fh->overlay_mask) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_open() - allocation of overlay_mask failed\n",
+                       ZR_DEVNAME(zr));
+               kfree(fh);
+               res = -ENOMEM;
+               goto open_unlock_and_return;
+       }
+
+       if (zr->user++ == 0)
+               first_open = 1;
+
+       /*mutex_unlock(&zr->resource_lock);*/
+
+       /* default setup - TODO: look at flags */
+       if (first_open) {       /* First device open */
+               zr36057_restart(zr);
+               zoran_open_init_params(zr);
+               zoran_init_hardware(zr);
+
+               btor(ZR36057_ICR_IntPinEn, ZR36057_ICR);
+       }
+
+       /* set file_ops stuff */
+       file->private_data = fh;
+       fh->zr = zr;
+       zoran_open_init_session(file);
+       unlock_kernel();
+
+       return 0;
+
+open_unlock_and_return:
+       /* if we grabbed locks, release them accordingly */
+       if (have_module_locks) {
+               module_put(zr->decoder->driver->driver.owner);
+               if (zr->encoder) {
+                       module_put(zr->encoder->driver->driver.owner);
+               }
+               module_put(THIS_MODULE);
+       }
+
+       /* if there's no device found, we didn't obtain the lock either */
+       if (zr) {
+               /*mutex_unlock(&zr->resource_lock);*/
+       }
+       unlock_kernel();
+
+       return res;
+}
+
+static int
+zoran_close (struct inode *inode,
+            struct file  *file)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       dprintk(1, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
+               ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
+
+       /* kernel locks (fs/device.c), so don't do that ourselves
+        * (prevents deadlocks) */
+       /*mutex_lock(&zr->resource_lock);*/
+
+       zoran_close_end_session(file);
+
+       if (zr->user-- == 1) {  /* Last process */
+               /* Clean up JPEG process */
+               wake_up_interruptible(&zr->jpg_capq);
+               zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
+               zr->jpg_buffers.allocated = 0;
+               zr->jpg_buffers.active = ZORAN_FREE;
+
+               /* disable interrupts */
+               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
+
+               if (zr36067_debug > 1)
+                       print_interrupts(zr);
+
+               /* Overlay off */
+               zr->v4l_overlay_active = 0;
+               zr36057_overlay(zr, 0);
+               zr->overlay_mask = NULL;
+
+               /* capture off */
+               wake_up_interruptible(&zr->v4l_capq);
+               zr36057_set_memgrab(zr, 0);
+               zr->v4l_buffers.allocated = 0;
+               zr->v4l_buffers.active = ZORAN_FREE;
+               zoran_set_pci_master(zr, 0);
+
+               if (!pass_through) {    /* Switch to color bar */
+                       int zero = 0, two = 2;
+                       decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
+                       encoder_command(zr, ENCODER_SET_INPUT, &two);
+               }
+       }
+
+       file->private_data = NULL;
+       kfree(fh->overlay_mask);
+       kfree(fh);
+
+       /* release locks on the i2c modules */
+       module_put(zr->decoder->driver->driver.owner);
+       if (zr->encoder) {
+                module_put(zr->encoder->driver->driver.owner);
+       }
+       module_put(THIS_MODULE);
+
+       /*mutex_unlock(&zr->resource_lock);*/
+
+       dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
+
+       return 0;
+}
+
+
+static ssize_t
+zoran_read (struct file *file,
+           char        __user *data,
+           size_t       count,
+           loff_t      *ppos)
+{
+       /* we simply don't support read() (yet)... */
+
+       return -EINVAL;
+}
+
+static ssize_t
+zoran_write (struct file *file,
+            const char  __user *data,
+            size_t       count,
+            loff_t      *ppos)
+{
+       /* ...and the same goes for write() */
+
+       return -EINVAL;
+}
+
+static int
+setup_fbuffer (struct file               *file,
+              void                      *base,
+              const struct zoran_format *fmt,
+              int                        width,
+              int                        height,
+              int                        bytesperline)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       /* (Ronald) v4l/v4l2 guidelines */
+       if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
+               return -EPERM;
+
+       /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
+          ALi Magik (that needs very low latency while the card needs a
+          higher value always) */
+
+       if (pci_pci_problems & (PCIPCI_FAIL | PCIAGP_FAIL | PCIPCI_ALIMAGIK))
+               return -ENXIO;
+
+       /* we need a bytesperline value, even if not given */
+       if (!bytesperline)
+               bytesperline = width * ((fmt->depth + 7) & ~7) / 8;
+
+#if 0
+       if (zr->overlay_active) {
+               /* dzjee... stupid users... don't even bother to turn off
+                * overlay before changing the memory location...
+                * normally, we would return errors here. However, one of
+                * the tools that does this is... xawtv! and since xawtv
+                * is used by +/- 99% of the users, we'd rather be user-
+                * friendly and silently do as if nothing went wrong */
+               dprintk(3,
+                       KERN_ERR
+                       "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n",
+                       ZR_DEVNAME(zr));
+               zr36057_overlay(zr, 0);
+       }
+#endif
+
+       if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_fbuffer() - no valid overlay format given\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+       if (height <= 0 || width <= 0 || bytesperline <= 0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n",
+                       ZR_DEVNAME(zr), width, height, bytesperline);
+               return -EINVAL;
+       }
+       if (bytesperline & 3) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n",
+                       ZR_DEVNAME(zr), bytesperline);
+               return -EINVAL;
+       }
+
+       zr->buffer.base = (void *) ((unsigned long) base & ~3);
+       zr->buffer.height = height;
+       zr->buffer.width = width;
+       zr->buffer.depth = fmt->depth;
+       zr->overlay_settings.format = fmt;
+       zr->buffer.bytesperline = bytesperline;
+
+       /* The user should set new window parameters */
+       zr->overlay_settings.is_set = 0;
+
+       return 0;
+}
+
+
+static int
+setup_window (struct file       *file,
+             int                x,
+             int                y,
+             int                width,
+             int                height,
+             struct video_clip __user *clips,
+             int                clipcount,
+             void              __user *bitmap)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       struct video_clip *vcp = NULL;
+       int on, end;
+
+
+       if (!zr->buffer.base) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_window() - frame buffer has to be set first\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       if (!fh->overlay_settings.format) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_window() - no overlay format set\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       /*
+        * The video front end needs 4-byte alinged line sizes, we correct that
+        * silently here if necessary
+        */
+       if (zr->buffer.depth == 15 || zr->buffer.depth == 16) {
+               end = (x + width) & ~1; /* round down */
+               x = (x + 1) & ~1;       /* round up */
+               width = end - x;
+       }
+
+       if (zr->buffer.depth == 24) {
+               end = (x + width) & ~3; /* round down */
+               x = (x + 3) & ~3;       /* round up */
+               width = end - x;
+       }
+
+       if (width > BUZ_MAX_WIDTH)
+               width = BUZ_MAX_WIDTH;
+       if (height > BUZ_MAX_HEIGHT)
+               height = BUZ_MAX_HEIGHT;
+
+       /* Check for vaild parameters */
+       if (width < BUZ_MIN_WIDTH || height < BUZ_MIN_HEIGHT ||
+           width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_window() - width = %d or height = %d invalid\n",
+                       ZR_DEVNAME(zr), width, height);
+               return -EINVAL;
+       }
+
+       fh->overlay_settings.x = x;
+       fh->overlay_settings.y = y;
+       fh->overlay_settings.width = width;
+       fh->overlay_settings.height = height;
+       fh->overlay_settings.clipcount = clipcount;
+
+       /*
+        * If an overlay is running, we have to switch it off
+        * and switch it on again in order to get the new settings in effect.
+        *
+        * We also want to avoid that the overlay mask is written
+        * when an overlay is running.
+        */
+
+       on = zr->v4l_overlay_active && !zr->v4l_memgrab_active &&
+           zr->overlay_active != ZORAN_FREE &&
+           fh->overlay_active != ZORAN_FREE;
+       if (on)
+               zr36057_overlay(zr, 0);
+
+       /*
+        *   Write the overlay mask if clips are wanted.
+        *   We prefer a bitmap.
+        */
+       if (bitmap) {
+               /* fake value - it just means we want clips */
+               fh->overlay_settings.clipcount = 1;
+
+               if (copy_from_user(fh->overlay_mask, bitmap,
+                                  (width * height + 7) / 8)) {
+                       return -EFAULT;
+               }
+       } else if (clipcount > 0) {
+               /* write our own bitmap from the clips */
+               vcp = vmalloc(sizeof(struct video_clip) * (clipcount + 4));
+               if (vcp == NULL) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: setup_window() - Alloc of clip mask failed\n",
+                               ZR_DEVNAME(zr));
+                       return -ENOMEM;
+               }
+               if (copy_from_user
+                   (vcp, clips, sizeof(struct video_clip) * clipcount)) {
+                       vfree(vcp);
+                       return -EFAULT;
+               }
+               write_overlay_mask(file, vcp, clipcount);
+               vfree(vcp);
+       }
+
+       fh->overlay_settings.is_set = 1;
+       if (fh->overlay_active != ZORAN_FREE &&
+           zr->overlay_active != ZORAN_FREE)
+               zr->overlay_settings = fh->overlay_settings;
+
+       if (on)
+               zr36057_overlay(zr, 1);
+
+       /* Make sure the changes come into effect */
+       return wait_grab_pending(zr);
+}
+
+static int
+setup_overlay (struct file *file,
+              int          on)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       /* If there is nothing to do, return immediatly */
+       if ((on && fh->overlay_active != ZORAN_FREE) ||
+           (!on && fh->overlay_active == ZORAN_FREE))
+               return 0;
+
+       /* check whether we're touching someone else's overlay */
+       if (on && zr->overlay_active != ZORAN_FREE &&
+           fh->overlay_active == ZORAN_FREE) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_overlay() - overlay is already active for another session\n",
+                       ZR_DEVNAME(zr));
+               return -EBUSY;
+       }
+       if (!on && zr->overlay_active != ZORAN_FREE &&
+           fh->overlay_active == ZORAN_FREE) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: setup_overlay() - you cannot cancel someone else's session\n",
+                       ZR_DEVNAME(zr));
+               return -EPERM;
+       }
+
+       if (on == 0) {
+               zr->overlay_active = fh->overlay_active = ZORAN_FREE;
+               zr->v4l_overlay_active = 0;
+               /* When a grab is running, the video simply
+                * won't be switched on any more */
+               if (!zr->v4l_memgrab_active)
+                       zr36057_overlay(zr, 0);
+               zr->overlay_mask = NULL;
+       } else {
+               if (!zr->buffer.base || !fh->overlay_settings.is_set) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: setup_overlay() - buffer or window not set\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+               if (!fh->overlay_settings.format) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: setup_overlay() - no overlay format set\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+               zr->overlay_active = fh->overlay_active = ZORAN_LOCKED;
+               zr->v4l_overlay_active = 1;
+               zr->overlay_mask = fh->overlay_mask;
+               zr->overlay_settings = fh->overlay_settings;
+               if (!zr->v4l_memgrab_active)
+                       zr36057_overlay(zr, 1);
+               /* When a grab is running, the video will be
+                * switched on when grab is finished */
+       }
+
+       /* Make sure the changes come into effect */
+       return wait_grab_pending(zr);
+}
+
+       /* get the status of a buffer in the clients buffer queue */
+static int
+zoran_v4l2_buffer_status (struct file        *file,
+                         struct v4l2_buffer *buf,
+                         int                 num)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+
+       buf->flags = V4L2_BUF_FLAG_MAPPED;
+
+       switch (fh->map_mode) {
+       case ZORAN_MAP_MODE_RAW:
+
+               /* check range */
+               if (num < 0 || num >= fh->v4l_buffers.num_buffers ||
+                   !fh->v4l_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+
+               buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+               buf->length = fh->v4l_buffers.buffer_size;
+
+               /* get buffer */
+               buf->bytesused = fh->v4l_buffers.buffer[num].bs.length;
+               if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE ||
+                   fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) {
+                       buf->sequence = fh->v4l_buffers.buffer[num].bs.seq;
+                       buf->flags |= V4L2_BUF_FLAG_DONE;
+                       buf->timestamp =
+                           fh->v4l_buffers.buffer[num].bs.timestamp;
+               } else {
+                       buf->flags |= V4L2_BUF_FLAG_QUEUED;
+               }
+
+               if (fh->v4l_settings.height <= BUZ_MAX_HEIGHT / 2)
+                       buf->field = V4L2_FIELD_TOP;
+               else
+                       buf->field = V4L2_FIELD_INTERLACED;
+
+               break;
+
+       case ZORAN_MAP_MODE_JPG_REC:
+       case ZORAN_MAP_MODE_JPG_PLAY:
+
+               /* check range */
+               if (num < 0 || num >= fh->jpg_buffers.num_buffers ||
+                   !fh->jpg_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+
+               buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ?
+                             V4L2_BUF_TYPE_VIDEO_CAPTURE :
+                             V4L2_BUF_TYPE_VIDEO_OUTPUT;
+               buf->length = fh->jpg_buffers.buffer_size;
+
+               /* these variables are only written after frame has been captured */
+               if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE ||
+                   fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) {
+                       buf->sequence = fh->jpg_buffers.buffer[num].bs.seq;
+                       buf->timestamp =
+                           fh->jpg_buffers.buffer[num].bs.timestamp;
+                       buf->bytesused =
+                           fh->jpg_buffers.buffer[num].bs.length;
+                       buf->flags |= V4L2_BUF_FLAG_DONE;
+               } else {
+                       buf->flags |= V4L2_BUF_FLAG_QUEUED;
+               }
+
+               /* which fields are these? */
+               if (fh->jpg_settings.TmpDcm != 1)
+                       buf->field =
+                           fh->jpg_settings.
+                           odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM;
+               else
+                       buf->field =
+                           fh->jpg_settings.
+                           odd_even ? V4L2_FIELD_SEQ_TB :
+                           V4L2_FIELD_SEQ_BT;
+
+               break;
+
+       default:
+
+               dprintk(5,
+                       KERN_ERR
+                       "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n",
+                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
+               return -EINVAL;
+       }
+
+       buf->memory = V4L2_MEMORY_MMAP;
+       buf->index = num;
+       buf->m.offset = buf->length * num;
+
+       return 0;
+}
+
+static int
+zoran_set_norm (struct zoran *zr,
+               int           norm) /* VIDEO_MODE_* */
+{
+       int norm_encoder, on;
+
+       if (zr->v4l_buffers.active != ZORAN_FREE ||
+           zr->jpg_buffers.active != ZORAN_FREE) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: set_norm() called while in playback/capture mode\n",
+                       ZR_DEVNAME(zr));
+               return -EBUSY;
+       }
+
+       if (lock_norm && norm != zr->norm) {
+               if (lock_norm > 1) {
+                       dprintk(1,
+                               KERN_WARNING
+                               "%s: set_norm() - TV standard is locked, can not switch norm\n",
+                               ZR_DEVNAME(zr));
+                       return -EPERM;
+               } else {
+                       dprintk(1,
+                               KERN_WARNING
+                               "%s: set_norm() - TV standard is locked, norm was not changed\n",
+                               ZR_DEVNAME(zr));
+                       norm = zr->norm;
+               }
+       }
+
+       if (norm != VIDEO_MODE_AUTO &&
+           (norm < 0 || norm >= zr->card.norms ||
+            !zr->card.tvn[norm])) {
+               dprintk(1,
+                       KERN_ERR "%s: set_norm() - unsupported norm %d\n",
+                       ZR_DEVNAME(zr), norm);
+               return -EINVAL;
+       }
+
+       if (norm == VIDEO_MODE_AUTO) {
+               int status;
+
+               /* if we have autodetect, ... */
+               struct video_decoder_capability caps;
+               decoder_command(zr, DECODER_GET_CAPABILITIES, &caps);
+               if (!(caps.flags & VIDEO_DECODER_AUTO)) {
+                       dprintk(1, KERN_ERR "%s: norm=auto unsupported\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+
+               decoder_command(zr, DECODER_SET_NORM, &norm);
+
+               /* let changes come into effect */
+               ssleep(2);
+
+               decoder_command(zr, DECODER_GET_STATUS, &status);
+               if (!(status & DECODER_STATUS_GOOD)) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: set_norm() - no norm detected\n",
+                               ZR_DEVNAME(zr));
+                       /* reset norm */
+                       decoder_command(zr, DECODER_SET_NORM, &zr->norm);
+                       return -EIO;
+               }
+
+               if (status & DECODER_STATUS_NTSC)
+                       norm = VIDEO_MODE_NTSC;
+               else if (status & DECODER_STATUS_SECAM)
+                       norm = VIDEO_MODE_SECAM;
+               else
+                       norm = VIDEO_MODE_PAL;
+       }
+       zr->timing = zr->card.tvn[norm];
+       norm_encoder = norm;
+
+       /* We switch overlay off and on since a change in the
+        * norm needs different VFE settings */
+       on = zr->overlay_active && !zr->v4l_memgrab_active;
+       if (on)
+               zr36057_overlay(zr, 0);
+
+       decoder_command(zr, DECODER_SET_NORM, &norm);
+       encoder_command(zr, ENCODER_SET_NORM, &norm_encoder);
+
+       if (on)
+               zr36057_overlay(zr, 1);
+
+       /* Make sure the changes come into effect */
+       zr->norm = norm;
+
+       return 0;
+}
+
+static int
+zoran_set_input (struct zoran *zr,
+                int           input)
+{
+       int realinput;
+
+       if (input == zr->input) {
+               return 0;
+       }
+
+       if (zr->v4l_buffers.active != ZORAN_FREE ||
+           zr->jpg_buffers.active != ZORAN_FREE) {
+               dprintk(1,
+                       KERN_WARNING
+                       "%s: set_input() called while in playback/capture mode\n",
+                       ZR_DEVNAME(zr));
+               return -EBUSY;
+       }
+
+       if (input < 0 || input >= zr->card.inputs) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: set_input() - unnsupported input %d\n",
+                       ZR_DEVNAME(zr), input);
+               return -EINVAL;
+       }
+
+       realinput = zr->card.input[input].muxsel;
+       zr->input = input;
+
+       decoder_command(zr, DECODER_SET_INPUT, &realinput);
+
+       return 0;
+}
+
+/*
+ *   ioctl routine
+ */
+
+static int
+zoran_do_ioctl (struct inode *inode,
+               struct file  *file,
+               unsigned int  cmd,
+               void         *arg)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       /* CAREFUL: used in multiple places here */
+       struct zoran_jpg_settings settings;
+
+       /* we might have older buffers lying around... We don't want
+        * to wait, but we do want to try cleaning them up ASAP. So
+        * we try to obtain the lock and free them. If that fails, we
+        * don't do anything and wait for the next turn. In the end,
+        * zoran_close() or a new allocation will still free them...
+        * This is just a 'the sooner the better' extra 'feature'
+        *
+        * We don't free the buffers right on munmap() because that
+        * causes oopses (kfree() inside munmap() oopses for no
+        * apparent reason - it's also not reproduceable in any way,
+        * but moving the free code outside the munmap() handler fixes
+        * all this... If someone knows why, please explain me (Ronald)
+        */
+       if (mutex_trylock(&zr->resource_lock)) {
+               /* we obtained it! Let's try to free some things */
+               if (fh->jpg_buffers.ready_to_be_freed)
+                       jpg_fbuffer_free(file);
+               if (fh->v4l_buffers.ready_to_be_freed)
+                       v4l_fbuffer_free(file);
+
+               mutex_unlock(&zr->resource_lock);
+       }
+
+       switch (cmd) {
+
+       case VIDIOCGCAP:
+       {
+               struct video_capability *vcap = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGCAP\n", ZR_DEVNAME(zr));
+
+               memset(vcap, 0, sizeof(struct video_capability));
+               strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name)-1);
+               vcap->type = ZORAN_VID_TYPE;
+
+               vcap->channels = zr->card.inputs;
+               vcap->audios = 0;
+               mutex_lock(&zr->resource_lock);
+               vcap->maxwidth = BUZ_MAX_WIDTH;
+               vcap->maxheight = BUZ_MAX_HEIGHT;
+               vcap->minwidth = BUZ_MIN_WIDTH;
+               vcap->minheight = BUZ_MIN_HEIGHT;
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOCGCHAN:
+       {
+               struct video_channel *vchan = arg;
+               int channel = vchan->channel;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGCHAN - channel=%d\n",
+                       ZR_DEVNAME(zr), vchan->channel);
+
+               memset(vchan, 0, sizeof(struct video_channel));
+               if (channel > zr->card.inputs || channel < 0) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOCGCHAN on not existing channel %d\n",
+                               ZR_DEVNAME(zr), channel);
+                       return -EINVAL;
+               }
+
+               strcpy(vchan->name, zr->card.input[channel].name);
+
+               vchan->tuners = 0;
+               vchan->flags = 0;
+               vchan->type = VIDEO_TYPE_CAMERA;
+               mutex_lock(&zr->resource_lock);
+               vchan->norm = zr->norm;
+               mutex_unlock(&zr->resource_lock);
+               vchan->channel = channel;
+
+               return 0;
+       }
+               break;
+
+               /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
+                *
+                * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
+                * *                                 ^^^^^^^
+                * * The famos BTTV driver has it implemented with a struct video_channel argument
+                * * and we follow it for compatibility reasons
+                * *
+                * * BTW: this is the only way the user can set the norm!
+                */
+
+       case VIDIOCSCHAN:
+       {
+               struct video_channel *vchan = arg;
+               int res;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
+                       ZR_DEVNAME(zr), vchan->channel, vchan->norm);
+
+               mutex_lock(&zr->resource_lock);
+               if ((res = zoran_set_input(zr, vchan->channel)))
+                       goto schan_unlock_and_return;
+               if ((res = zoran_set_norm(zr, vchan->norm)))
+                       goto schan_unlock_and_return;
+
+               /* Make sure the changes come into effect */
+               res = wait_grab_pending(zr);
+       schan_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOCGPICT:
+       {
+               struct video_picture *vpict = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr));
+
+               memset(vpict, 0, sizeof(struct video_picture));
+               mutex_lock(&zr->resource_lock);
+               vpict->hue = zr->hue;
+               vpict->brightness = zr->brightness;
+               vpict->contrast = zr->contrast;
+               vpict->colour = zr->saturation;
+               if (fh->overlay_settings.format) {
+                       vpict->depth = fh->overlay_settings.format->depth;
+                       vpict->palette = fh->overlay_settings.format->palette;
+               } else {
+                       vpict->depth = 0;
+               }
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOCSPICT:
+       {
+               struct video_picture *vpict = arg;
+               int i;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
+                       ZR_DEVNAME(zr), vpict->brightness, vpict->hue,
+                       vpict->colour, vpict->contrast, vpict->depth,
+                       vpict->palette);
+
+               for (i = 0; i < NUM_FORMATS; i++) {
+                       const struct zoran_format *fmt = &zoran_formats[i];
+
+                       if (fmt->palette != -1 &&
+                           fmt->flags & ZORAN_FORMAT_OVERLAY &&
+                           fmt->palette == vpict->palette &&
+                           fmt->depth == vpict->depth)
+                               break;
+               }
+               if (i == NUM_FORMATS) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOCSPICT - Invalid palette %d\n",
+                               ZR_DEVNAME(zr), vpict->palette);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+
+               decoder_command(zr, DECODER_SET_PICTURE, vpict);
+
+               zr->hue = vpict->hue;
+               zr->contrast = vpict->contrast;
+               zr->saturation = vpict->colour;
+               zr->brightness = vpict->brightness;
+
+               fh->overlay_settings.format = &zoran_formats[i];
+
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOCCAPTURE:
+       {
+               int *on = arg, res;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n",
+                       ZR_DEVNAME(zr), *on);
+
+               mutex_lock(&zr->resource_lock);
+               res = setup_overlay(file, *on);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOCGWIN:
+       {
+               struct video_window *vwin = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr));
+
+               memset(vwin, 0, sizeof(struct video_window));
+               mutex_lock(&zr->resource_lock);
+               vwin->x = fh->overlay_settings.x;
+               vwin->y = fh->overlay_settings.y;
+               vwin->width = fh->overlay_settings.width;
+               vwin->height = fh->overlay_settings.height;
+               mutex_unlock(&zr->resource_lock);
+               vwin->clipcount = 0;
+               return 0;
+       }
+               break;
+
+       case VIDIOCSWIN:
+       {
+               struct video_window *vwin = arg;
+               int res;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
+                       ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width,
+                       vwin->height, vwin->clipcount);
+
+               mutex_lock(&zr->resource_lock);
+               res =
+                   setup_window(file, vwin->x, vwin->y, vwin->width,
+                                vwin->height, vwin->clips,
+                                vwin->clipcount, NULL);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOCGFBUF:
+       {
+               struct video_buffer *vbuf = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+               *vbuf = zr->buffer;
+               mutex_unlock(&zr->resource_lock);
+               return 0;
+       }
+               break;
+
+       case VIDIOCSFBUF:
+       {
+               struct video_buffer *vbuf = arg;
+               int i, res = 0;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
+                       ZR_DEVNAME(zr), vbuf->base, vbuf->width,
+                       vbuf->height, vbuf->depth, vbuf->bytesperline);
+
+               for (i = 0; i < NUM_FORMATS; i++)
+                       if (zoran_formats[i].depth == vbuf->depth)
+                               break;
+               if (i == NUM_FORMATS) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
+                               ZR_DEVNAME(zr), vbuf->depth);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+               res =
+                   setup_fbuffer(file, vbuf->base, &zoran_formats[i],
+                                 vbuf->width, vbuf->height,
+                                 vbuf->bytesperline);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOCSYNC:
+       {
+               int *frame = arg, res;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n",
+                       ZR_DEVNAME(zr), *frame);
+
+               mutex_lock(&zr->resource_lock);
+               res = v4l_sync(file, *frame);
+               mutex_unlock(&zr->resource_lock);
+               if (!res)
+                       zr->v4l_sync_tail++;
+               return res;
+       }
+               break;
+
+       case VIDIOCMCAPTURE:
+       {
+               struct video_mmap *vmap = arg;
+               int res;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
+                       ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height,
+                       vmap->format);
+
+               mutex_lock(&zr->resource_lock);
+               res = v4l_grab(file, vmap);
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOCGMBUF:
+       {
+               struct video_mbuf *vmbuf = arg;
+               int i, res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr));
+
+               vmbuf->size =
+                   fh->v4l_buffers.num_buffers *
+                   fh->v4l_buffers.buffer_size;
+               vmbuf->frames = fh->v4l_buffers.num_buffers;
+               for (i = 0; i < vmbuf->frames; i++) {
+                       vmbuf->offsets[i] =
+                           i * fh->v4l_buffers.buffer_size;
+               }
+
+               mutex_lock(&zr->resource_lock);
+
+               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOCGMBUF - buffers already allocated\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto v4l1reqbuf_unlock_and_return;
+               }
+
+               if (v4l_fbuffer_alloc(file)) {
+                       res = -ENOMEM;
+                       goto v4l1reqbuf_unlock_and_return;
+               }
+
+               /* The next mmap will map the V4L buffers */
+               fh->map_mode = ZORAN_MAP_MODE_RAW;
+       v4l1reqbuf_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOCGUNIT:
+       {
+               struct video_unit *vunit = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr));
+
+               vunit->video = zr->video_dev->minor;
+               vunit->vbi = VIDEO_NO_UNIT;
+               vunit->radio = VIDEO_NO_UNIT;
+               vunit->audio = VIDEO_NO_UNIT;
+               vunit->teletext = VIDEO_NO_UNIT;
+
+               return 0;
+       }
+               break;
+
+               /*
+                * RJ: In principal we could support subcaptures for V4L grabbing.
+                *     Not even the famous BTTV driver has them, however.
+                *     If there should be a strong demand, one could consider
+                *     to implement them.
+                */
+       case VIDIOCGCAPTURE:
+       {
+               dprintk(3, KERN_ERR "%s: VIDIOCGCAPTURE not supported\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+               break;
+
+       case VIDIOCSCAPTURE:
+       {
+               dprintk(3, KERN_ERR "%s: VIDIOCSCAPTURE not supported\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+               break;
+
+       case BUZIOC_G_PARAMS:
+       {
+               struct zoran_params *bparams = arg;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr));
+
+               memset(bparams, 0, sizeof(struct zoran_params));
+               bparams->major_version = MAJOR_VERSION;
+               bparams->minor_version = MINOR_VERSION;
+
+               mutex_lock(&zr->resource_lock);
+
+               bparams->norm = zr->norm;
+               bparams->input = zr->input;
+
+               bparams->decimation = fh->jpg_settings.decimation;
+               bparams->HorDcm = fh->jpg_settings.HorDcm;
+               bparams->VerDcm = fh->jpg_settings.VerDcm;
+               bparams->TmpDcm = fh->jpg_settings.TmpDcm;
+               bparams->field_per_buff = fh->jpg_settings.field_per_buff;
+               bparams->img_x = fh->jpg_settings.img_x;
+               bparams->img_y = fh->jpg_settings.img_y;
+               bparams->img_width = fh->jpg_settings.img_width;
+               bparams->img_height = fh->jpg_settings.img_height;
+               bparams->odd_even = fh->jpg_settings.odd_even;
+
+               bparams->quality = fh->jpg_settings.jpg_comp.quality;
+               bparams->APPn = fh->jpg_settings.jpg_comp.APPn;
+               bparams->APP_len = fh->jpg_settings.jpg_comp.APP_len;
+               memcpy(bparams->APP_data,
+                      fh->jpg_settings.jpg_comp.APP_data,
+                      sizeof(bparams->APP_data));
+               bparams->COM_len = zr->jpg_settings.jpg_comp.COM_len;
+               memcpy(bparams->COM_data,
+                      fh->jpg_settings.jpg_comp.COM_data,
+                      sizeof(bparams->COM_data));
+               bparams->jpeg_markers =
+                   fh->jpg_settings.jpg_comp.jpeg_markers;
+
+               mutex_unlock(&zr->resource_lock);
+
+               bparams->VFIFO_FB = 0;
+
+               return 0;
+       }
+               break;
+
+       case BUZIOC_S_PARAMS:
+       {
+               struct zoran_params *bparams = arg;
+               int res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr));
+
+               settings.decimation = bparams->decimation;
+               settings.HorDcm = bparams->HorDcm;
+               settings.VerDcm = bparams->VerDcm;
+               settings.TmpDcm = bparams->TmpDcm;
+               settings.field_per_buff = bparams->field_per_buff;
+               settings.img_x = bparams->img_x;
+               settings.img_y = bparams->img_y;
+               settings.img_width = bparams->img_width;
+               settings.img_height = bparams->img_height;
+               settings.odd_even = bparams->odd_even;
+
+               settings.jpg_comp.quality = bparams->quality;
+               settings.jpg_comp.APPn = bparams->APPn;
+               settings.jpg_comp.APP_len = bparams->APP_len;
+               memcpy(settings.jpg_comp.APP_data, bparams->APP_data,
+                      sizeof(bparams->APP_data));
+               settings.jpg_comp.COM_len = bparams->COM_len;
+               memcpy(settings.jpg_comp.COM_data, bparams->COM_data,
+                      sizeof(bparams->COM_data));
+               settings.jpg_comp.jpeg_markers = bparams->jpeg_markers;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (zr->codec_mode != BUZ_MODE_IDLE) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto sparams_unlock_and_return;
+               }
+
+               /* Check the params first before overwriting our
+                * nternal values */
+               if (zoran_check_jpg_settings(zr, &settings)) {
+                       res = -EINVAL;
+                       goto sparams_unlock_and_return;
+               }
+
+               fh->jpg_settings = settings;
+       sparams_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case BUZIOC_REQBUFS:
+       {
+               struct zoran_requestbuffers *breq = arg;
+               int res = 0;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
+                       ZR_DEVNAME(zr), breq->count, breq->size);
+
+               /* Enforce reasonable lower and upper limits */
+               if (breq->count < 4)
+                       breq->count = 4;        /* Could be choosen smaller */
+               if (breq->count > jpg_nbufs)
+                       breq->count = jpg_nbufs;
+               breq->size = PAGE_ALIGN(breq->size);
+               if (breq->size < 8192)
+                       breq->size = 8192;      /* Arbitrary */
+               /* breq->size is limited by 1 page for the stat_com
+                * tables to a Maximum of 2 MB */
+               if (breq->size > jpg_bufsize)
+                       breq->size = jpg_bufsize;
+               if (fh->jpg_buffers.need_contiguous &&
+                   breq->size > MAX_KMALLOC_MEM)
+                       breq->size = MAX_KMALLOC_MEM;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: BUZIOC_REQBUFS - buffers allready allocated\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+                       goto jpgreqbuf_unlock_and_return;
+               }
+
+               fh->jpg_buffers.num_buffers = breq->count;
+               fh->jpg_buffers.buffer_size = breq->size;
+
+               if (jpg_fbuffer_alloc(file)) {
+                       res = -ENOMEM;
+                       goto jpgreqbuf_unlock_and_return;
+               }
+
+               /* The next mmap will map the MJPEG buffers - could
+                * also be *_PLAY, but it doesn't matter here */
+               fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
+       jpgreqbuf_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case BUZIOC_QBUF_CAPT:
+       {
+               int *frame = arg, res;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n",
+                       ZR_DEVNAME(zr), *frame);
+
+               mutex_lock(&zr->resource_lock);
+               res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case BUZIOC_QBUF_PLAY:
+       {
+               int *frame = arg, res;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n",
+                       ZR_DEVNAME(zr), *frame);
+
+               mutex_lock(&zr->resource_lock);
+               res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case BUZIOC_SYNC:
+       {
+               struct zoran_sync *bsync = arg;
+               int res;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+               res = jpg_sync(file, bsync);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case BUZIOC_G_STATUS:
+       {
+               struct zoran_status *bstat = arg;
+               int norm, input, status, res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr));
+
+               if (zr->codec_mode != BUZ_MODE_IDLE) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
+                               ZR_DEVNAME(zr));
+                       return -EINVAL;
+               }
+
+               input = zr->card.input[bstat->input].muxsel;
+               norm = VIDEO_MODE_AUTO;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (zr->codec_mode != BUZ_MODE_IDLE) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto gstat_unlock_and_return;
+               }
+
+               decoder_command(zr, DECODER_SET_INPUT, &input);
+               decoder_command(zr, DECODER_SET_NORM, &norm);
+
+               /* sleep 1 second */
+               ssleep(1);
+
+               /* Get status of video decoder */
+               decoder_command(zr, DECODER_GET_STATUS, &status);
+
+               /* restore previous input and norm */
+               input = zr->card.input[zr->input].muxsel;
+               decoder_command(zr, DECODER_SET_INPUT, &input);
+               decoder_command(zr, DECODER_SET_NORM, &zr->norm);
+       gstat_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               if (!res) {
+                       bstat->signal =
+                           (status & DECODER_STATUS_GOOD) ? 1 : 0;
+                       if (status & DECODER_STATUS_NTSC)
+                               bstat->norm = VIDEO_MODE_NTSC;
+                       else if (status & DECODER_STATUS_SECAM)
+                               bstat->norm = VIDEO_MODE_SECAM;
+                       else
+                               bstat->norm = VIDEO_MODE_PAL;
+
+                       bstat->color =
+                           (status & DECODER_STATUS_COLOR) ? 1 : 0;
+               }
+
+               return res;
+       }
+               break;
+
+               /* The new video4linux2 capture interface - much nicer than video4linux1, since
+                * it allows for integrating the JPEG capturing calls inside standard v4l2
+                */
+
+       case VIDIOC_QUERYCAP:
+       {
+               struct v4l2_capability *cap = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr));
+
+               memset(cap, 0, sizeof(*cap));
+               strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1);
+               strncpy(cap->driver, "zoran", sizeof(cap->driver)-1);
+               snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
+                        pci_name(zr->pci_dev));
+               cap->version =
+                   KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION,
+                                  RELEASE_VERSION);
+               cap->capabilities = ZORAN_V4L2_VID_FLAGS;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_ENUM_FMT:
+       {
+               struct v4l2_fmtdesc *fmt = arg;
+               int index = fmt->index, num = -1, i, flag = 0, type =
+                   fmt->type;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUM_FMT - index=%d\n",
+                       ZR_DEVNAME(zr), fmt->index);
+
+               switch (fmt->type) {
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+                       flag = ZORAN_FORMAT_CAPTURE;
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       flag = ZORAN_FORMAT_PLAYBACK;
+                       break;
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       flag = ZORAN_FORMAT_OVERLAY;
+                       break;
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
+                               ZR_DEVNAME(zr), fmt->type);
+                       return -EINVAL;
+               }
+
+               for (i = 0; i < NUM_FORMATS; i++) {
+                       if (zoran_formats[i].flags & flag)
+                               num++;
+                       if (num == fmt->index)
+                               break;
+               }
+               if (fmt->index < 0 /* late, but not too late */  ||
+                   i == NUM_FORMATS)
+                       return -EINVAL;
+
+               memset(fmt, 0, sizeof(*fmt));
+               fmt->index = index;
+               fmt->type = type;
+               strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1);
+               fmt->pixelformat = zoran_formats[i].fourcc;
+               if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)
+                       fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_G_FMT:
+       {
+               struct v4l2_format *fmt = arg;
+               int type = fmt->type;
+
+               dprintk(5, KERN_DEBUG "%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr));
+
+               memset(fmt, 0, sizeof(*fmt));
+               fmt->type = type;
+
+               switch (fmt->type) {
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+
+                       mutex_lock(&zr->resource_lock);
+
+                       fmt->fmt.win.w.left = fh->overlay_settings.x;
+                       fmt->fmt.win.w.top = fh->overlay_settings.y;
+                       fmt->fmt.win.w.width = fh->overlay_settings.width;
+                       fmt->fmt.win.w.height =
+                           fh->overlay_settings.height;
+                       if (fh->overlay_settings.width * 2 >
+                           BUZ_MAX_HEIGHT)
+                               fmt->fmt.win.field = V4L2_FIELD_INTERLACED;
+                       else
+                               fmt->fmt.win.field = V4L2_FIELD_TOP;
+
+                       mutex_unlock(&zr->resource_lock);
+
+                       break;
+
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+
+                       mutex_lock(&zr->resource_lock);
+
+                       if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
+                           fh->map_mode == ZORAN_MAP_MODE_RAW) {
+
+                               fmt->fmt.pix.width =
+                                   fh->v4l_settings.width;
+                               fmt->fmt.pix.height =
+                                   fh->v4l_settings.height;
+                               fmt->fmt.pix.sizeimage =
+                                   fh->v4l_settings.bytesperline *
+                                   fh->v4l_settings.height;
+                               fmt->fmt.pix.pixelformat =
+                                   fh->v4l_settings.format->fourcc;
+                               fmt->fmt.pix.colorspace =
+                                   fh->v4l_settings.format->colorspace;
+                               fmt->fmt.pix.bytesperline =
+                                   fh->v4l_settings.bytesperline;
+                               if (BUZ_MAX_HEIGHT <
+                                   (fh->v4l_settings.height * 2))
+                                       fmt->fmt.pix.field =
+                                           V4L2_FIELD_INTERLACED;
+                               else
+                                       fmt->fmt.pix.field =
+                                           V4L2_FIELD_TOP;
+
+                       } else {
+
+                               fmt->fmt.pix.width =
+                                   fh->jpg_settings.img_width /
+                                   fh->jpg_settings.HorDcm;
+                               fmt->fmt.pix.height =
+                                   fh->jpg_settings.img_height /
+                                   (fh->jpg_settings.VerDcm *
+                                    fh->jpg_settings.TmpDcm);
+                               fmt->fmt.pix.sizeimage =
+                                   zoran_v4l2_calc_bufsize(&fh->
+                                                           jpg_settings);
+                               fmt->fmt.pix.pixelformat =
+                                   V4L2_PIX_FMT_MJPEG;
+                               if (fh->jpg_settings.TmpDcm == 1)
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_SEQ_BT :
+                                            V4L2_FIELD_SEQ_BT);
+                               else
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_TOP :
+                                            V4L2_FIELD_BOTTOM);
+
+                               fmt->fmt.pix.bytesperline = 0;
+                               fmt->fmt.pix.colorspace =
+                                   V4L2_COLORSPACE_SMPTE170M;
+                       }
+
+                       mutex_unlock(&zr->resource_lock);
+
+                       break;
+
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_G_FMT - unsupported type %d\n",
+                               ZR_DEVNAME(zr), fmt->type);
+                       return -EINVAL;
+               }
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_FMT:
+       {
+               struct v4l2_format *fmt = arg;
+               int i, res = 0;
+               __le32 printformat;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_FMT - type=%d, ",
+                       ZR_DEVNAME(zr), fmt->type);
+
+               switch (fmt->type) {
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+
+                       dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
+                               fmt->fmt.win.w.left, fmt->fmt.win.w.top,
+                               fmt->fmt.win.w.width,
+                               fmt->fmt.win.w.height,
+                               fmt->fmt.win.clipcount,
+                               fmt->fmt.win.bitmap);
+                       mutex_lock(&zr->resource_lock);
+                       res =
+                           setup_window(file, fmt->fmt.win.w.left,
+                                        fmt->fmt.win.w.top,
+                                        fmt->fmt.win.w.width,
+                                        fmt->fmt.win.w.height,
+                                        (struct video_clip __user *)
+                                          fmt->fmt.win.clips,
+                                        fmt->fmt.win.clipcount,
+                                        fmt->fmt.win.bitmap);
+                       mutex_unlock(&zr->resource_lock);
+                       return res;
+                       break;
+
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+
+                       printformat =
+                           __cpu_to_le32(fmt->fmt.pix.pixelformat);
+                       dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
+                               fmt->fmt.pix.width, fmt->fmt.pix.height,
+                               fmt->fmt.pix.pixelformat,
+                               (char *) &printformat);
+
+                       /* we can be requested to do JPEG/raw playback/capture */
+                       if (!
+                           (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                            (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+                             fmt->fmt.pix.pixelformat ==
+                             V4L2_PIX_FMT_MJPEG))) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
+                                       ZR_DEVNAME(zr), fmt->type,
+                                       fmt->fmt.pix.pixelformat,
+                                       (char *) &printformat);
+                               return -EINVAL;
+                       }
+
+                       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
+                               mutex_lock(&zr->resource_lock);
+
+                               settings = fh->jpg_settings;
+
+                               if (fh->v4l_buffers.allocated ||
+                                   fh->jpg_buffers.allocated) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: VIDIOC_S_FMT - cannot change capture mode\n",
+                                               ZR_DEVNAME(zr));
+                                       res = -EBUSY;
+                                       goto sfmtjpg_unlock_and_return;
+                               }
+
+                               /* we actually need to set 'real' parameters now */
+                               if ((fmt->fmt.pix.height * 2) >
+                                   BUZ_MAX_HEIGHT)
+                                       settings.TmpDcm = 1;
+                               else
+                                       settings.TmpDcm = 2;
+                               settings.decimation = 0;
+                               if (fmt->fmt.pix.height <=
+                                   fh->jpg_settings.img_height / 2)
+                                       settings.VerDcm = 2;
+                               else
+                                       settings.VerDcm = 1;
+                               if (fmt->fmt.pix.width <=
+                                   fh->jpg_settings.img_width / 4)
+                                       settings.HorDcm = 4;
+                               else if (fmt->fmt.pix.width <=
+                                        fh->jpg_settings.img_width / 2)
+                                       settings.HorDcm = 2;
+                               else
+                                       settings.HorDcm = 1;
+                               if (settings.TmpDcm == 1)
+                                       settings.field_per_buff = 2;
+                               else
+                                       settings.field_per_buff = 1;
+
+                               /* check */
+                               if ((res =
+                                    zoran_check_jpg_settings(zr,
+                                                             &settings)))
+                                       goto sfmtjpg_unlock_and_return;
+
+                               /* it's ok, so set them */
+                               fh->jpg_settings = settings;
+
+                               /* tell the user what we actually did */
+                               fmt->fmt.pix.width =
+                                   settings.img_width / settings.HorDcm;
+                               fmt->fmt.pix.height =
+                                   settings.img_height * 2 /
+                                   (settings.TmpDcm * settings.VerDcm);
+                               if (settings.TmpDcm == 1)
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_SEQ_TB :
+                                            V4L2_FIELD_SEQ_BT);
+                               else
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_TOP :
+                                            V4L2_FIELD_BOTTOM);
+                               fh->jpg_buffers.buffer_size =
+                                   zoran_v4l2_calc_bufsize(&fh->
+                                                           jpg_settings);
+                               fmt->fmt.pix.bytesperline = 0;
+                               fmt->fmt.pix.sizeimage =
+                                   fh->jpg_buffers.buffer_size;
+                               fmt->fmt.pix.colorspace =
+                                   V4L2_COLORSPACE_SMPTE170M;
+
+                               /* we hereby abuse this variable to show that
+                                * we're gonna do mjpeg capture */
+                               fh->map_mode =
+                                   (fmt->type ==
+                                    V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
+                                   ZORAN_MAP_MODE_JPG_REC :
+                                   ZORAN_MAP_MODE_JPG_PLAY;
+                       sfmtjpg_unlock_and_return:
+                               mutex_unlock(&zr->resource_lock);
+                       } else {
+                               for (i = 0; i < NUM_FORMATS; i++)
+                                       if (fmt->fmt.pix.pixelformat ==
+                                           zoran_formats[i].fourcc)
+                                               break;
+                               if (i == NUM_FORMATS) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
+                                               ZR_DEVNAME(zr),
+                                               fmt->fmt.pix.pixelformat,
+                                               (char *) &printformat);
+                                       return -EINVAL;
+                               }
+                               mutex_lock(&zr->resource_lock);
+                               if (fh->jpg_buffers.allocated ||
+                                   (fh->v4l_buffers.allocated &&
+                                    fh->v4l_buffers.active !=
+                                    ZORAN_FREE)) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: VIDIOC_S_FMT - cannot change capture mode\n",
+                                               ZR_DEVNAME(zr));
+                                       res = -EBUSY;
+                                       goto sfmtv4l_unlock_and_return;
+                               }
+                               if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
+                                       fmt->fmt.pix.height =
+                                           BUZ_MAX_HEIGHT;
+                               if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
+                                       fmt->fmt.pix.width = BUZ_MAX_WIDTH;
+
+                               if ((res =
+                                    zoran_v4l_set_format(file,
+                                                         fmt->fmt.pix.
+                                                         width,
+                                                         fmt->fmt.pix.
+                                                         height,
+                                                         &zoran_formats
+                                                         [i])))
+                                       goto sfmtv4l_unlock_and_return;
+
+                               /* tell the user the
+                                * results/missing stuff */
+                               fmt->fmt.pix.bytesperline =
+                                       fh->v4l_settings.bytesperline;
+                               fmt->fmt.pix.sizeimage =
+                                       fh->v4l_settings.height *
+                                       fh->v4l_settings.bytesperline;
+                               fmt->fmt.pix.colorspace =
+                                       fh->v4l_settings.format->colorspace;
+                               if (BUZ_MAX_HEIGHT <
+                                   (fh->v4l_settings.height * 2))
+                                       fmt->fmt.pix.field =
+                                           V4L2_FIELD_INTERLACED;
+                               else
+                                       fmt->fmt.pix.field =
+                                           V4L2_FIELD_TOP;
+
+                               fh->map_mode = ZORAN_MAP_MODE_RAW;
+                       sfmtv4l_unlock_and_return:
+                               mutex_unlock(&zr->resource_lock);
+                       }
+
+                       break;
+
+               default:
+                       dprintk(3, "unsupported\n");
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_S_FMT - unsupported type %d\n",
+                               ZR_DEVNAME(zr), fmt->type);
+                       return -EINVAL;
+               }
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_G_FBUF:
+       {
+               struct v4l2_framebuffer *fb = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr));
+
+               memset(fb, 0, sizeof(*fb));
+               mutex_lock(&zr->resource_lock);
+               fb->base = zr->buffer.base;
+               fb->fmt.width = zr->buffer.width;
+               fb->fmt.height = zr->buffer.height;
+               if (zr->overlay_settings.format) {
+                       fb->fmt.pixelformat =
+                               fh->overlay_settings.format->fourcc;
+               }
+               fb->fmt.bytesperline = zr->buffer.bytesperline;
+               mutex_unlock(&zr->resource_lock);
+               fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
+               fb->fmt.field = V4L2_FIELD_INTERLACED;
+               fb->flags = V4L2_FBUF_FLAG_OVERLAY;
+               fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_FBUF:
+       {
+               int i, res = 0;
+               struct v4l2_framebuffer *fb = arg;
+               __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat);
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n",
+                       ZR_DEVNAME(zr), fb->base, fb->fmt.width, fb->fmt.height,
+                       fb->fmt.bytesperline, fb->fmt.pixelformat,
+                       (char *) &printformat);
+
+               for (i = 0; i < NUM_FORMATS; i++)
+                       if (zoran_formats[i].fourcc == fb->fmt.pixelformat)
+                               break;
+               if (i == NUM_FORMATS) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
+                               ZR_DEVNAME(zr), fb->fmt.pixelformat,
+                               (char *) &printformat);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+               res =
+                   setup_fbuffer(file, fb->base, &zoran_formats[i],
+                                 fb->fmt.width, fb->fmt.height,
+                                 fb->fmt.bytesperline);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_OVERLAY:
+       {
+               int *on = arg, res;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n",
+                       ZR_DEVNAME(zr), *on);
+
+               mutex_lock(&zr->resource_lock);
+               res = setup_overlay(file, *on);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_REQBUFS:
+       {
+               struct v4l2_requestbuffers *req = arg;
+               int res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_REQBUFS - type=%d\n",
+                       ZR_DEVNAME(zr), req->type);
+
+               if (req->memory != V4L2_MEMORY_MMAP) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: only MEMORY_MMAP capture is supported, not %d\n",
+                               ZR_DEVNAME(zr), req->memory);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+
+               if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+                       goto v4l2reqbuf_unlock_and_return;
+               }
+
+               if (fh->map_mode == ZORAN_MAP_MODE_RAW &&
+                   req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+
+                       /* control user input */
+                       if (req->count < 2)
+                               req->count = 2;
+                       if (req->count > v4l_nbufs)
+                               req->count = v4l_nbufs;
+                       fh->v4l_buffers.num_buffers = req->count;
+
+                       if (v4l_fbuffer_alloc(file)) {
+                               res = -ENOMEM;
+                               goto v4l2reqbuf_unlock_and_return;
+                       }
+
+                       /* The next mmap will map the V4L buffers */
+                       fh->map_mode = ZORAN_MAP_MODE_RAW;
+
+               } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC ||
+                          fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
+
+                       /* we need to calculate size ourselves now */
+                       if (req->count < 4)
+                               req->count = 4;
+                       if (req->count > jpg_nbufs)
+                               req->count = jpg_nbufs;
+                       fh->jpg_buffers.num_buffers = req->count;
+                       fh->jpg_buffers.buffer_size =
+                           zoran_v4l2_calc_bufsize(&fh->jpg_settings);
+
+                       if (jpg_fbuffer_alloc(file)) {
+                               res = -ENOMEM;
+                               goto v4l2reqbuf_unlock_and_return;
+                       }
+
+                       /* The next mmap will map the MJPEG buffers */
+                       if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
+                               fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
+                       else
+                               fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY;
+
+               } else {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_REQBUFS - unknown type %d\n",
+                               ZR_DEVNAME(zr), req->type);
+                       res = -EINVAL;
+                       goto v4l2reqbuf_unlock_and_return;
+               }
+       v4l2reqbuf_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_QUERYBUF:
+       {
+               struct v4l2_buffer *buf = arg;
+               __u32 type = buf->type;
+               int index = buf->index, res;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
+                       ZR_DEVNAME(zr), buf->index, buf->type);
+
+               memset(buf, 0, sizeof(*buf));
+               buf->type = type;
+               buf->index = index;
+
+               mutex_lock(&zr->resource_lock);
+               res = zoran_v4l2_buffer_status(file, buf, buf->index);
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_QBUF:
+       {
+               struct v4l2_buffer *buf = arg;
+               int res = 0, codec_mode, buf_type;
+
+               dprintk(3,
+                       KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n",
+                       ZR_DEVNAME(zr), buf->type, buf->index);
+
+               mutex_lock(&zr->resource_lock);
+
+               switch (fh->map_mode) {
+               case ZORAN_MAP_MODE_RAW:
+                       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
+                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
+                               res = -EINVAL;
+                               goto qbuf_unlock_and_return;
+                       }
+
+                       res = zoran_v4l_queue_frame(file, buf->index);
+                       if (res)
+                               goto qbuf_unlock_and_return;
+                       if (!zr->v4l_memgrab_active &&
+                           fh->v4l_buffers.active == ZORAN_LOCKED)
+                               zr36057_set_memgrab(zr, 1);
+                       break;
+
+               case ZORAN_MAP_MODE_JPG_REC:
+               case ZORAN_MAP_MODE_JPG_PLAY:
+                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
+                               buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+                               codec_mode = BUZ_MODE_MOTION_DECOMPRESS;
+                       } else {
+                               buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+                               codec_mode = BUZ_MODE_MOTION_COMPRESS;
+                       }
+
+                       if (buf->type != buf_type) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
+                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
+                               res = -EINVAL;
+                               goto qbuf_unlock_and_return;
+                       }
+
+                       res =
+                           zoran_jpg_queue_frame(file, buf->index,
+                                                 codec_mode);
+                       if (res != 0)
+                               goto qbuf_unlock_and_return;
+                       if (zr->codec_mode == BUZ_MODE_IDLE &&
+                           fh->jpg_buffers.active == ZORAN_LOCKED) {
+                               zr36057_enable_jpg(zr, codec_mode);
+                       }
+                       break;
+
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_QBUF - unsupported type %d\n",
+                               ZR_DEVNAME(zr), buf->type);
+                       res = -EINVAL;
+                       goto qbuf_unlock_and_return;
+               }
+       qbuf_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_DQBUF:
+       {
+               struct v4l2_buffer *buf = arg;
+               int res = 0, buf_type, num = -1;        /* compiler borks here (?) */
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n",
+                       ZR_DEVNAME(zr), buf->type);
+
+               mutex_lock(&zr->resource_lock);
+
+               switch (fh->map_mode) {
+               case ZORAN_MAP_MODE_RAW:
+                       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
+                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
+                               res = -EINVAL;
+                               goto dqbuf_unlock_and_return;
+                       }
+
+                       num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME];
+                       if (file->f_flags & O_NONBLOCK &&
+                           zr->v4l_buffers.buffer[num].state !=
+                           BUZ_STATE_DONE) {
+                               res = -EAGAIN;
+                               goto dqbuf_unlock_and_return;
+                       }
+                       res = v4l_sync(file, num);
+                       if (res)
+                               goto dqbuf_unlock_and_return;
+                       else
+                               zr->v4l_sync_tail++;
+                       res = zoran_v4l2_buffer_status(file, buf, num);
+                       break;
+
+               case ZORAN_MAP_MODE_JPG_REC:
+               case ZORAN_MAP_MODE_JPG_PLAY:
+               {
+                       struct zoran_sync bs;
+
+                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY)
+                               buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
+                       else
+                               buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
+
+                       if (buf->type != buf_type) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
+                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
+                               res = -EINVAL;
+                               goto dqbuf_unlock_and_return;
+                       }
+
+                       num =
+                           zr->jpg_pend[zr->
+                                        jpg_que_tail & BUZ_MASK_FRAME];
+
+                       if (file->f_flags & O_NONBLOCK &&
+                           zr->jpg_buffers.buffer[num].state !=
+                           BUZ_STATE_DONE) {
+                               res = -EAGAIN;
+                               goto dqbuf_unlock_and_return;
+                       }
+                       res = jpg_sync(file, &bs);
+                       if (res)
+                               goto dqbuf_unlock_and_return;
+                       res =
+                           zoran_v4l2_buffer_status(file, buf, bs.frame);
+                       break;
+               }
+
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_DQBUF - unsupported type %d\n",
+                               ZR_DEVNAME(zr), buf->type);
+                       res = -EINVAL;
+                       goto dqbuf_unlock_and_return;
+               }
+       dqbuf_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_STREAMON:
+       {
+               int res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+
+               switch (fh->map_mode) {
+               case ZORAN_MAP_MODE_RAW:        /* raw capture */
+                       if (zr->v4l_buffers.active != ZORAN_ACTIVE ||
+                           fh->v4l_buffers.active != ZORAN_ACTIVE) {
+                               res = -EBUSY;
+                               goto strmon_unlock_and_return;
+                       }
+
+                       zr->v4l_buffers.active = fh->v4l_buffers.active =
+                           ZORAN_LOCKED;
+                       zr->v4l_settings = fh->v4l_settings;
+
+                       zr->v4l_sync_tail = zr->v4l_pend_tail;
+                       if (!zr->v4l_memgrab_active &&
+                           zr->v4l_pend_head != zr->v4l_pend_tail) {
+                               zr36057_set_memgrab(zr, 1);
+                       }
+                       break;
+
+               case ZORAN_MAP_MODE_JPG_REC:
+               case ZORAN_MAP_MODE_JPG_PLAY:
+                       /* what is the codec mode right now? */
+                       if (zr->jpg_buffers.active != ZORAN_ACTIVE ||
+                           fh->jpg_buffers.active != ZORAN_ACTIVE) {
+                               res = -EBUSY;
+                               goto strmon_unlock_and_return;
+                       }
+
+                       zr->jpg_buffers.active = fh->jpg_buffers.active =
+                           ZORAN_LOCKED;
+
+                       if (zr->jpg_que_head != zr->jpg_que_tail) {
+                               /* Start the jpeg codec when the first frame is queued  */
+                               jpeg_start(zr);
+                       }
+
+                       break;
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_STREAMON - invalid map mode %d\n",
+                               ZR_DEVNAME(zr), fh->map_mode);
+                       res = -EINVAL;
+                       goto strmon_unlock_and_return;
+               }
+       strmon_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_STREAMOFF:
+       {
+               int i, res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+
+               switch (fh->map_mode) {
+               case ZORAN_MAP_MODE_RAW:        /* raw capture */
+                       if (fh->v4l_buffers.active == ZORAN_FREE &&
+                           zr->v4l_buffers.active != ZORAN_FREE) {
+                               res = -EPERM;   /* stay off other's settings! */
+                               goto strmoff_unlock_and_return;
+                       }
+                       if (zr->v4l_buffers.active == ZORAN_FREE)
+                               goto strmoff_unlock_and_return;
+
+                       /* unload capture */
+                       if (zr->v4l_memgrab_active) {
+                               unsigned long flags;
+
+                               spin_lock_irqsave(&zr->spinlock, flags);
+                               zr36057_set_memgrab(zr, 0);
+                               spin_unlock_irqrestore(&zr->spinlock, flags);
+                       }
+
+                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++)
+                               zr->v4l_buffers.buffer[i].state =
+                                   BUZ_STATE_USER;
+                       fh->v4l_buffers = zr->v4l_buffers;
+
+                       zr->v4l_buffers.active = fh->v4l_buffers.active =
+                           ZORAN_FREE;
+
+                       zr->v4l_grab_seq = 0;
+                       zr->v4l_pend_head = zr->v4l_pend_tail = 0;
+                       zr->v4l_sync_tail = 0;
+
+                       break;
+
+               case ZORAN_MAP_MODE_JPG_REC:
+               case ZORAN_MAP_MODE_JPG_PLAY:
+                       if (fh->jpg_buffers.active == ZORAN_FREE &&
+                           zr->jpg_buffers.active != ZORAN_FREE) {
+                               res = -EPERM;   /* stay off other's settings! */
+                               goto strmoff_unlock_and_return;
+                       }
+                       if (zr->jpg_buffers.active == ZORAN_FREE)
+                               goto strmoff_unlock_and_return;
+
+                       res =
+                           jpg_qbuf(file, -1,
+                                    (fh->map_mode ==
+                                     ZORAN_MAP_MODE_JPG_REC) ?
+                                    BUZ_MODE_MOTION_COMPRESS :
+                                    BUZ_MODE_MOTION_DECOMPRESS);
+                       if (res)
+                               goto strmoff_unlock_and_return;
+                       break;
+               default:
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
+                               ZR_DEVNAME(zr), fh->map_mode);
+                       res = -EINVAL;
+                       goto strmoff_unlock_and_return;
+               }
+       strmoff_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_QUERYCTRL:
+       {
+               struct v4l2_queryctrl *ctrl = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCTRL - id=%d\n",
+                       ZR_DEVNAME(zr), ctrl->id);
+
+               /* we only support hue/saturation/contrast/brightness */
+               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
+                   ctrl->id > V4L2_CID_HUE)
+                       return -EINVAL;
+               else {
+                       int id = ctrl->id;
+                       memset(ctrl, 0, sizeof(*ctrl));
+                       ctrl->id = id;
+               }
+
+               switch (ctrl->id) {
+               case V4L2_CID_BRIGHTNESS:
+                       strncpy(ctrl->name, "Brightness", sizeof(ctrl->name)-1);
+                       break;
+               case V4L2_CID_CONTRAST:
+                       strncpy(ctrl->name, "Contrast", sizeof(ctrl->name)-1);
+                       break;
+               case V4L2_CID_SATURATION:
+                       strncpy(ctrl->name, "Saturation", sizeof(ctrl->name)-1);
+                       break;
+               case V4L2_CID_HUE:
+                       strncpy(ctrl->name, "Hue", sizeof(ctrl->name)-1);
+                       break;
+               }
+
+               ctrl->minimum = 0;
+               ctrl->maximum = 65535;
+               ctrl->step = 1;
+               ctrl->default_value = 32768;
+               ctrl->type = V4L2_CTRL_TYPE_INTEGER;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_G_CTRL:
+       {
+               struct v4l2_control *ctrl = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_CTRL - id=%d\n",
+                       ZR_DEVNAME(zr), ctrl->id);
+
+               /* we only support hue/saturation/contrast/brightness */
+               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
+                   ctrl->id > V4L2_CID_HUE)
+                       return -EINVAL;
+
+               mutex_lock(&zr->resource_lock);
+               switch (ctrl->id) {
+               case V4L2_CID_BRIGHTNESS:
+                       ctrl->value = zr->brightness;
+                       break;
+               case V4L2_CID_CONTRAST:
+                       ctrl->value = zr->contrast;
+                       break;
+               case V4L2_CID_SATURATION:
+                       ctrl->value = zr->saturation;
+                       break;
+               case V4L2_CID_HUE:
+                       ctrl->value = zr->hue;
+                       break;
+               }
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_CTRL:
+       {
+               struct v4l2_control *ctrl = arg;
+               struct video_picture pict;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_CTRL - id=%d\n",
+                       ZR_DEVNAME(zr), ctrl->id);
+
+               /* we only support hue/saturation/contrast/brightness */
+               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
+                   ctrl->id > V4L2_CID_HUE)
+                       return -EINVAL;
+
+               if (ctrl->value < 0 || ctrl->value > 65535) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n",
+                               ZR_DEVNAME(zr), ctrl->value, ctrl->id);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+               switch (ctrl->id) {
+               case V4L2_CID_BRIGHTNESS:
+                       zr->brightness = ctrl->value;
+                       break;
+               case V4L2_CID_CONTRAST:
+                       zr->contrast = ctrl->value;
+                       break;
+               case V4L2_CID_SATURATION:
+                       zr->saturation = ctrl->value;
+                       break;
+               case V4L2_CID_HUE:
+                       zr->hue = ctrl->value;
+                       break;
+               }
+               pict.brightness = zr->brightness;
+               pict.contrast = zr->contrast;
+               pict.colour = zr->saturation;
+               pict.hue = zr->hue;
+
+               decoder_command(zr, DECODER_SET_PICTURE, &pict);
+
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_ENUMSTD:
+       {
+               struct v4l2_standard *std = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMSTD - index=%d\n",
+                       ZR_DEVNAME(zr), std->index);
+
+               if (std->index < 0 || std->index >= (zr->card.norms + 1))
+                       return -EINVAL;
+               else {
+                       int id = std->index;
+                       memset(std, 0, sizeof(*std));
+                       std->index = id;
+               }
+
+               if (std->index == zr->card.norms) {
+                       /* if we have autodetect, ... */
+                       struct video_decoder_capability caps;
+                       decoder_command(zr, DECODER_GET_CAPABILITIES,
+                                       &caps);
+                       if (caps.flags & VIDEO_DECODER_AUTO) {
+                               std->id = V4L2_STD_ALL;
+                               strncpy(std->name, "Autodetect", sizeof(std->name)-1);
+                               return 0;
+                       } else
+                               return -EINVAL;
+               }
+               switch (std->index) {
+               case 0:
+                       std->id = V4L2_STD_PAL;
+                       strncpy(std->name, "PAL", sizeof(std->name)-1);
+                       std->frameperiod.numerator = 1;
+                       std->frameperiod.denominator = 25;
+                       std->framelines = zr->card.tvn[0]->Ht;
+                       break;
+               case 1:
+                       std->id = V4L2_STD_NTSC;
+                       strncpy(std->name, "NTSC", sizeof(std->name)-1);
+                       std->frameperiod.numerator = 1001;
+                       std->frameperiod.denominator = 30000;
+                       std->framelines = zr->card.tvn[1]->Ht;
+                       break;
+               case 2:
+                       std->id = V4L2_STD_SECAM;
+                       strncpy(std->name, "SECAM", sizeof(std->name)-1);
+                       std->frameperiod.numerator = 1;
+                       std->frameperiod.denominator = 25;
+                       std->framelines = zr->card.tvn[2]->Ht;
+                       break;
+               }
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_G_STD:
+       {
+               v4l2_std_id *std = arg;
+               int norm;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+               norm = zr->norm;
+               mutex_unlock(&zr->resource_lock);
+
+               switch (norm) {
+               case VIDEO_MODE_PAL:
+                       *std = V4L2_STD_PAL;
+                       break;
+               case VIDEO_MODE_NTSC:
+                       *std = V4L2_STD_NTSC;
+                       break;
+               case VIDEO_MODE_SECAM:
+                       *std = V4L2_STD_SECAM;
+                       break;
+               }
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_STD:
+       {
+               int norm = -1, res = 0;
+               v4l2_std_id *std = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_STD - norm=0x%llx\n",
+                       ZR_DEVNAME(zr), (unsigned long long)*std);
+
+               if ((*std & V4L2_STD_PAL) && !(*std & ~V4L2_STD_PAL))
+                       norm = VIDEO_MODE_PAL;
+               else if ((*std & V4L2_STD_NTSC) && !(*std & ~V4L2_STD_NTSC))
+                       norm = VIDEO_MODE_NTSC;
+               else if ((*std & V4L2_STD_SECAM) && !(*std & ~V4L2_STD_SECAM))
+                       norm = VIDEO_MODE_SECAM;
+               else if (*std == V4L2_STD_ALL)
+                       norm = VIDEO_MODE_AUTO;
+               else {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
+                               ZR_DEVNAME(zr), (unsigned long long)*std);
+                       return -EINVAL;
+               }
+
+               mutex_lock(&zr->resource_lock);
+               if ((res = zoran_set_norm(zr, norm)))
+                       goto sstd_unlock_and_return;
+
+               res = wait_grab_pending(zr);
+       sstd_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOC_ENUMINPUT:
+       {
+               struct v4l2_input *inp = arg;
+               int status;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMINPUT - index=%d\n",
+                       ZR_DEVNAME(zr), inp->index);
+
+               if (inp->index < 0 || inp->index >= zr->card.inputs)
+                       return -EINVAL;
+               else {
+                       int id = inp->index;
+                       memset(inp, 0, sizeof(*inp));
+                       inp->index = id;
+               }
+
+               strncpy(inp->name, zr->card.input[inp->index].name,
+                       sizeof(inp->name) - 1);
+               inp->type = V4L2_INPUT_TYPE_CAMERA;
+               inp->std = V4L2_STD_ALL;
+
+               /* Get status of video decoder */
+               mutex_lock(&zr->resource_lock);
+               decoder_command(zr, DECODER_GET_STATUS, &status);
+               mutex_unlock(&zr->resource_lock);
+
+               if (!(status & DECODER_STATUS_GOOD)) {
+                       inp->status |= V4L2_IN_ST_NO_POWER;
+                       inp->status |= V4L2_IN_ST_NO_SIGNAL;
+               }
+               if (!(status & DECODER_STATUS_COLOR))
+                       inp->status |= V4L2_IN_ST_NO_COLOR;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_G_INPUT:
+       {
+               int *input = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr));
+
+               mutex_lock(&zr->resource_lock);
+               *input = zr->input;
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_INPUT:
+       {
+               int *input = arg, res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n",
+                       ZR_DEVNAME(zr), *input);
+
+               mutex_lock(&zr->resource_lock);
+               if ((res = zoran_set_input(zr, *input)))
+                       goto sinput_unlock_and_return;
+
+               /* Make sure the changes come into effect */
+               res = wait_grab_pending(zr);
+       sinput_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOC_ENUMOUTPUT:
+       {
+               struct v4l2_output *outp = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMOUTPUT - index=%d\n",
+                       ZR_DEVNAME(zr), outp->index);
+
+               if (outp->index != 0)
+                       return -EINVAL;
+
+               memset(outp, 0, sizeof(*outp));
+               outp->index = 0;
+               outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
+               strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_G_OUTPUT:
+       {
+               int *output = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr));
+
+               *output = 0;
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_OUTPUT:
+       {
+               int *output = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_OUTPUT - output=%d\n",
+                       ZR_DEVNAME(zr), *output);
+
+               if (*output != 0)
+                       return -EINVAL;
+
+               return 0;
+       }
+               break;
+
+               /* cropping (sub-frame capture) */
+       case VIDIOC_CROPCAP:
+       {
+               struct v4l2_cropcap *cropcap = arg;
+               int type = cropcap->type, res = 0;
+
+               dprintk(3, KERN_ERR "%s: VIDIOC_CROPCAP - type=%d\n",
+                       ZR_DEVNAME(zr), cropcap->type);
+
+               memset(cropcap, 0, sizeof(*cropcap));
+               cropcap->type = type;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+                   (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto cropcap_unlock_and_return;
+               }
+
+               cropcap->bounds.top = cropcap->bounds.left = 0;
+               cropcap->bounds.width = BUZ_MAX_WIDTH;
+               cropcap->bounds.height = BUZ_MAX_HEIGHT;
+               cropcap->defrect.top = cropcap->defrect.left = 0;
+               cropcap->defrect.width = BUZ_MIN_WIDTH;
+               cropcap->defrect.height = BUZ_MIN_HEIGHT;
+       cropcap_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOC_G_CROP:
+       {
+               struct v4l2_crop *crop = arg;
+               int type = crop->type, res = 0;
+
+               dprintk(3, KERN_ERR "%s: VIDIOC_G_CROP - type=%d\n",
+                       ZR_DEVNAME(zr), crop->type);
+
+               memset(crop, 0, sizeof(*crop));
+               crop->type = type;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+                   (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto gcrop_unlock_and_return;
+               }
+
+               crop->c.top = fh->jpg_settings.img_y;
+               crop->c.left = fh->jpg_settings.img_x;
+               crop->c.width = fh->jpg_settings.img_width;
+               crop->c.height = fh->jpg_settings.img_height;
+
+       gcrop_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return res;
+       }
+               break;
+
+       case VIDIOC_S_CROP:
+       {
+               struct v4l2_crop *crop = arg;
+               int res = 0;
+
+               settings = fh->jpg_settings;
+
+               dprintk(3,
+                       KERN_ERR
+                       "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n",
+                       ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top,
+                       crop->c.width, crop->c.height);
+
+               mutex_lock(&zr->resource_lock);
+
+               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_S_CROP - cannot change settings while active\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+                       goto scrop_unlock_and_return;
+               }
+
+               if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
+                   (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
+                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
+                               ZR_DEVNAME(zr));
+                       res = -EINVAL;
+                       goto scrop_unlock_and_return;
+               }
+
+               /* move into a form that we understand */
+               settings.img_x = crop->c.left;
+               settings.img_y = crop->c.top;
+               settings.img_width = crop->c.width;
+               settings.img_height = crop->c.height;
+
+               /* check validity */
+               if ((res = zoran_check_jpg_settings(zr, &settings)))
+                       goto scrop_unlock_and_return;
+
+               /* accept */
+               fh->jpg_settings = settings;
+
+       scrop_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+               return res;
+       }
+               break;
+
+       case VIDIOC_G_JPEGCOMP:
+       {
+               struct v4l2_jpegcompression *params = arg;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_JPEGCOMP\n",
+                       ZR_DEVNAME(zr));
+
+               memset(params, 0, sizeof(*params));
+
+               mutex_lock(&zr->resource_lock);
+
+               params->quality = fh->jpg_settings.jpg_comp.quality;
+               params->APPn = fh->jpg_settings.jpg_comp.APPn;
+               memcpy(params->APP_data,
+                      fh->jpg_settings.jpg_comp.APP_data,
+                      fh->jpg_settings.jpg_comp.APP_len);
+               params->APP_len = fh->jpg_settings.jpg_comp.APP_len;
+               memcpy(params->COM_data,
+                      fh->jpg_settings.jpg_comp.COM_data,
+                      fh->jpg_settings.jpg_comp.COM_len);
+               params->COM_len = fh->jpg_settings.jpg_comp.COM_len;
+               params->jpeg_markers =
+                   fh->jpg_settings.jpg_comp.jpeg_markers;
+
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_S_JPEGCOMP:
+       {
+               struct v4l2_jpegcompression *params = arg;
+               int res = 0;
+
+               settings = fh->jpg_settings;
+
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
+                       ZR_DEVNAME(zr), params->quality, params->APPn,
+                       params->APP_len, params->COM_len);
+
+               settings.jpg_comp = *params;
+
+               mutex_lock(&zr->resource_lock);
+
+               if (fh->v4l_buffers.active != ZORAN_FREE ||
+                   fh->jpg_buffers.active != ZORAN_FREE) {
+                       dprintk(1,
+                               KERN_WARNING
+                               "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
+                               ZR_DEVNAME(zr));
+                       res = -EBUSY;
+                       goto sjpegc_unlock_and_return;
+               }
+
+               if ((res = zoran_check_jpg_settings(zr, &settings)))
+                       goto sjpegc_unlock_and_return;
+               if (!fh->jpg_buffers.allocated)
+                       fh->jpg_buffers.buffer_size =
+                           zoran_v4l2_calc_bufsize(&fh->jpg_settings);
+               fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
+       sjpegc_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               return 0;
+       }
+               break;
+
+       case VIDIOC_QUERYSTD:   /* why is this useful? */
+       {
+               v4l2_std_id *std = arg;
+
+               dprintk(3,
+                       KERN_DEBUG "%s: VIDIOC_QUERY_STD - std=0x%llx\n",
+                       ZR_DEVNAME(zr), (unsigned long long)*std);
+
+               if (*std == V4L2_STD_ALL || *std == V4L2_STD_NTSC ||
+                   *std == V4L2_STD_PAL || (*std == V4L2_STD_SECAM &&
+                                            zr->card.norms == 3)) {
+                       return 0;
+               }
+
+               return -EINVAL;
+       }
+               break;
+
+       case VIDIOC_TRY_FMT:
+       {
+               struct v4l2_format *fmt = arg;
+               int res = 0;
+
+               dprintk(3, KERN_DEBUG "%s: VIDIOC_TRY_FMT - type=%d\n",
+                       ZR_DEVNAME(zr), fmt->type);
+
+               switch (fmt->type) {
+               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
+                       mutex_lock(&zr->resource_lock);
+
+                       if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH)
+                               fmt->fmt.win.w.width = BUZ_MAX_WIDTH;
+                       if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH)
+                               fmt->fmt.win.w.width = BUZ_MIN_WIDTH;
+                       if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT)
+                               fmt->fmt.win.w.height = BUZ_MAX_HEIGHT;
+                       if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
+                               fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
+
+                       mutex_unlock(&zr->resource_lock);
+                       break;
+
+               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
+               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
+                       if (fmt->fmt.pix.bytesperline > 0)
+                               return -EINVAL;
+
+                       mutex_lock(&zr->resource_lock);
+
+                       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
+                               settings = fh->jpg_settings;
+
+                               /* we actually need to set 'real' parameters now */
+                               if ((fmt->fmt.pix.height * 2) >
+                                   BUZ_MAX_HEIGHT)
+                                       settings.TmpDcm = 1;
+                               else
+                                       settings.TmpDcm = 2;
+                               settings.decimation = 0;
+                               if (fmt->fmt.pix.height <=
+                                   fh->jpg_settings.img_height / 2)
+                                       settings.VerDcm = 2;
+                               else
+                                       settings.VerDcm = 1;
+                               if (fmt->fmt.pix.width <=
+                                   fh->jpg_settings.img_width / 4)
+                                       settings.HorDcm = 4;
+                               else if (fmt->fmt.pix.width <=
+                                        fh->jpg_settings.img_width / 2)
+                                       settings.HorDcm = 2;
+                               else
+                                       settings.HorDcm = 1;
+                               if (settings.TmpDcm == 1)
+                                       settings.field_per_buff = 2;
+                               else
+                                       settings.field_per_buff = 1;
+
+                               /* check */
+                               if ((res =
+                                    zoran_check_jpg_settings(zr,
+                                                             &settings)))
+                                       goto tryfmt_unlock_and_return;
+
+                               /* tell the user what we actually did */
+                               fmt->fmt.pix.width =
+                                   settings.img_width / settings.HorDcm;
+                               fmt->fmt.pix.height =
+                                   settings.img_height * 2 /
+                                   (settings.TmpDcm * settings.VerDcm);
+                               if (settings.TmpDcm == 1)
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_SEQ_TB :
+                                            V4L2_FIELD_SEQ_BT);
+                               else
+                                       fmt->fmt.pix.field =
+                                           (fh->jpg_settings.
+                                            odd_even ? V4L2_FIELD_TOP :
+                                            V4L2_FIELD_BOTTOM);
+
+                               fmt->fmt.pix.sizeimage =
+                                   zoran_v4l2_calc_bufsize(&settings);
+                       } else if (fmt->type ==
+                                  V4L2_BUF_TYPE_VIDEO_CAPTURE) {
+                               int i;
+
+                               for (i = 0; i < NUM_FORMATS; i++)
+                                       if (zoran_formats[i].fourcc ==
+                                           fmt->fmt.pix.pixelformat)
+                                               break;
+                               if (i == NUM_FORMATS) {
+                                       res = -EINVAL;
+                                       goto tryfmt_unlock_and_return;
+                               }
+
+                               if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
+                                       fmt->fmt.pix.width = BUZ_MAX_WIDTH;
+                               if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
+                                       fmt->fmt.pix.width = BUZ_MIN_WIDTH;
+                               if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
+                                       fmt->fmt.pix.height =
+                                           BUZ_MAX_HEIGHT;
+                               if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT)
+                                       fmt->fmt.pix.height =
+                                           BUZ_MIN_HEIGHT;
+                       } else {
+                               res = -EINVAL;
+                               goto tryfmt_unlock_and_return;
+                       }
+               tryfmt_unlock_and_return:
+                       mutex_unlock(&zr->resource_lock);
+
+                       return res;
+                       break;
+
+               default:
+                       return -EINVAL;
+               }
+
+               return 0;
+       }
+               break;
+
+       default:
+               dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n",
+                       ZR_DEVNAME(zr), cmd);
+               return -ENOIOCTLCMD;
+               break;
+
+       }
+       return 0;
+}
+
+
+static int
+zoran_ioctl (struct inode *inode,
+            struct file  *file,
+            unsigned int  cmd,
+            unsigned long arg)
+{
+       return video_usercopy(inode, file, cmd, arg, zoran_do_ioctl);
+}
+
+static unsigned int
+zoran_poll (struct file *file,
+           poll_table  *wait)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int res = 0, frame;
+       unsigned long flags;
+
+       /* we should check whether buffers are ready to be synced on
+        * (w/o waits - O_NONBLOCK) here
+        * if ready for read (sync), return POLLIN|POLLRDNORM,
+        * if ready for write (sync), return POLLOUT|POLLWRNORM,
+        * if error, return POLLERR,
+        * if no buffers queued or so, return POLLNVAL
+        */
+
+       mutex_lock(&zr->resource_lock);
+
+       switch (fh->map_mode) {
+       case ZORAN_MAP_MODE_RAW:
+               poll_wait(file, &zr->v4l_capq, wait);
+               frame = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME];
+
+               spin_lock_irqsave(&zr->spinlock, flags);
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
+                       ZR_DEVNAME(zr), __func__,
+                       "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail,
+                       "UPMD"[zr->v4l_buffers.buffer[frame].state],
+                       zr->v4l_pend_tail, zr->v4l_pend_head);
+               /* Process is the one capturing? */
+               if (fh->v4l_buffers.active != ZORAN_FREE &&
+                   /* Buffer ready to DQBUF? */
+                   zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE)
+                       res = POLLIN | POLLRDNORM;
+               spin_unlock_irqrestore(&zr->spinlock, flags);
+
+               break;
+
+       case ZORAN_MAP_MODE_JPG_REC:
+       case ZORAN_MAP_MODE_JPG_PLAY:
+               poll_wait(file, &zr->jpg_capq, wait);
+               frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
+
+               spin_lock_irqsave(&zr->spinlock, flags);
+               dprintk(3,
+                       KERN_DEBUG
+                       "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
+                       ZR_DEVNAME(zr), __func__,
+                       "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail,
+                       "UPMD"[zr->jpg_buffers.buffer[frame].state],
+                       zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head);
+               if (fh->jpg_buffers.active != ZORAN_FREE &&
+                   zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) {
+                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC)
+                               res = POLLIN | POLLRDNORM;
+                       else
+                               res = POLLOUT | POLLWRNORM;
+               }
+               spin_unlock_irqrestore(&zr->spinlock, flags);
+
+               break;
+
+       default:
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_poll() - internal error, unknown map_mode=%d\n",
+                       ZR_DEVNAME(zr), fh->map_mode);
+               res = POLLNVAL;
+       }
+
+       mutex_unlock(&zr->resource_lock);
+
+       return res;
+}
+
+
+/*
+ * This maps the buffers to user space.
+ *
+ * Depending on the state of fh->map_mode
+ * the V4L or the MJPEG buffers are mapped
+ * per buffer or all together
+ *
+ * Note that we need to connect to some
+ * unmap signal event to unmap the de-allocate
+ * the buffer accordingly (zoran_vm_close())
+ */
+
+static void
+zoran_vm_open (struct vm_area_struct *vma)
+{
+       struct zoran_mapping *map = vma->vm_private_data;
+
+       map->count++;
+}
+
+static void
+zoran_vm_close (struct vm_area_struct *vma)
+{
+       struct zoran_mapping *map = vma->vm_private_data;
+       struct file *file = map->file;
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       int i;
+
+       map->count--;
+       if (map->count == 0) {
+               switch (fh->map_mode) {
+               case ZORAN_MAP_MODE_JPG_REC:
+               case ZORAN_MAP_MODE_JPG_PLAY:
+
+                       dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n",
+                               ZR_DEVNAME(zr));
+
+                       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
+                               if (fh->jpg_buffers.buffer[i].map == map) {
+                                       fh->jpg_buffers.buffer[i].map =
+                                           NULL;
+                               }
+                       }
+                       kfree(map);
+
+                       for (i = 0; i < fh->jpg_buffers.num_buffers; i++)
+                               if (fh->jpg_buffers.buffer[i].map)
+                                       break;
+                       if (i == fh->jpg_buffers.num_buffers) {
+                               mutex_lock(&zr->resource_lock);
+
+                               if (fh->jpg_buffers.active != ZORAN_FREE) {
+                                       jpg_qbuf(file, -1, zr->codec_mode);
+                                       zr->jpg_buffers.allocated = 0;
+                                       zr->jpg_buffers.active =
+                                           fh->jpg_buffers.active =
+                                           ZORAN_FREE;
+                               }
+                               //jpg_fbuffer_free(file);
+                               fh->jpg_buffers.allocated = 0;
+                               fh->jpg_buffers.ready_to_be_freed = 1;
+
+                               mutex_unlock(&zr->resource_lock);
+                       }
+
+                       break;
+
+               case ZORAN_MAP_MODE_RAW:
+
+                       dprintk(3, KERN_INFO "%s: munmap(V4L)\n",
+                               ZR_DEVNAME(zr));
+
+                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
+                               if (fh->v4l_buffers.buffer[i].map == map) {
+                                       /* unqueue/unmap */
+                                       fh->v4l_buffers.buffer[i].map =
+                                           NULL;
+                               }
+                       }
+                       kfree(map);
+
+                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++)
+                               if (fh->v4l_buffers.buffer[i].map)
+                                       break;
+                       if (i == fh->v4l_buffers.num_buffers) {
+                               mutex_lock(&zr->resource_lock);
+
+                               if (fh->v4l_buffers.active != ZORAN_FREE) {
+                                       unsigned long flags;
+
+                                       spin_lock_irqsave(&zr->spinlock, flags);
+                                       zr36057_set_memgrab(zr, 0);
+                                       zr->v4l_buffers.allocated = 0;
+                                       zr->v4l_buffers.active =
+                                           fh->v4l_buffers.active =
+                                           ZORAN_FREE;
+                                       spin_unlock_irqrestore(&zr->spinlock, flags);
+                               }
+                               //v4l_fbuffer_free(file);
+                               fh->v4l_buffers.allocated = 0;
+                               fh->v4l_buffers.ready_to_be_freed = 1;
+
+                               mutex_unlock(&zr->resource_lock);
+                       }
+
+                       break;
+
+               default:
+                       printk(KERN_ERR
+                              "%s: munmap() - internal error - unknown map mode %d\n",
+                              ZR_DEVNAME(zr), fh->map_mode);
+                       break;
+
+               }
+       }
+}
+
+static struct vm_operations_struct zoran_vm_ops = {
+       .open = zoran_vm_open,
+       .close = zoran_vm_close,
+};
+
+static int
+zoran_mmap (struct file           *file,
+           struct vm_area_struct *vma)
+{
+       struct zoran_fh *fh = file->private_data;
+       struct zoran *zr = fh->zr;
+       unsigned long size = (vma->vm_end - vma->vm_start);
+       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
+       int i, j;
+       unsigned long page, start = vma->vm_start, todo, pos, fraglen;
+       int first, last;
+       struct zoran_mapping *map;
+       int res = 0;
+
+       dprintk(3,
+               KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
+               ZR_DEVNAME(zr),
+               fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG",
+               vma->vm_start, vma->vm_end, size);
+
+       if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) ||
+           !(vma->vm_flags & VM_WRITE)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n",
+                       ZR_DEVNAME(zr));
+               return -EINVAL;
+       }
+
+       switch (fh->map_mode) {
+
+       case ZORAN_MAP_MODE_JPG_REC:
+       case ZORAN_MAP_MODE_JPG_PLAY:
+
+               /* lock */
+               mutex_lock(&zr->resource_lock);
+
+               /* Map the MJPEG buffers */
+               if (!fh->jpg_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n",
+                               ZR_DEVNAME(zr));
+                       res = -ENOMEM;
+                       goto jpg_mmap_unlock_and_return;
+               }
+
+               first = offset / fh->jpg_buffers.buffer_size;
+               last = first - 1 + size / fh->jpg_buffers.buffer_size;
+               if (offset % fh->jpg_buffers.buffer_size != 0 ||
+                   size % fh->jpg_buffers.buffer_size != 0 || first < 0 ||
+                   last < 0 || first >= fh->jpg_buffers.num_buffers ||
+                   last >= fh->jpg_buffers.num_buffers) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
+                               ZR_DEVNAME(zr), offset, size,
+                               fh->jpg_buffers.buffer_size,
+                               fh->jpg_buffers.num_buffers);
+                       res = -EINVAL;
+                       goto jpg_mmap_unlock_and_return;
+               }
+               for (i = first; i <= last; i++) {
+                       if (fh->jpg_buffers.buffer[i].map) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: mmap(MJPEG) - buffer %d already mapped\n",
+                                       ZR_DEVNAME(zr), i);
+                               res = -EBUSY;
+                               goto jpg_mmap_unlock_and_return;
+                       }
+               }
+
+               /* map these buffers (v4l_buffers[i]) */
+               map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
+               if (!map) {
+                       res = -ENOMEM;
+                       goto jpg_mmap_unlock_and_return;
+               }
+               map->file = file;
+               map->count = 1;
+
+               vma->vm_ops = &zoran_vm_ops;
+               vma->vm_flags |= VM_DONTEXPAND;
+               vma->vm_private_data = map;
+
+               for (i = first; i <= last; i++) {
+                       for (j = 0;
+                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
+                            j++) {
+                               fraglen =
+                                   (le32_to_cpu(fh->jpg_buffers.buffer[i].
+                                    frag_tab[2 * j + 1]) & ~1) << 1;
+                               todo = size;
+                               if (todo > fraglen)
+                                       todo = fraglen;
+                               pos =
+                                   le32_to_cpu(fh->jpg_buffers.
+                                   buffer[i].frag_tab[2 * j]);
+                               /* should just be pos on i386 */
+                               page = virt_to_phys(bus_to_virt(pos))
+                                                               >> PAGE_SHIFT;
+                               if (remap_pfn_range(vma, start, page,
+                                                       todo, PAGE_SHARED)) {
+                                       dprintk(1,
+                                               KERN_ERR
+                                               "%s: zoran_mmap(V4L) - remap_pfn_range failed\n",
+                                               ZR_DEVNAME(zr));
+                                       res = -EAGAIN;
+                                       goto jpg_mmap_unlock_and_return;
+                               }
+                               size -= todo;
+                               start += todo;
+                               if (size == 0)
+                                       break;
+                               if (le32_to_cpu(fh->jpg_buffers.buffer[i].
+                                   frag_tab[2 * j + 1]) & 1)
+                                       break;  /* was last fragment */
+                       }
+                       fh->jpg_buffers.buffer[i].map = map;
+                       if (size == 0)
+                               break;
+
+               }
+       jpg_mmap_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               break;
+
+       case ZORAN_MAP_MODE_RAW:
+
+               mutex_lock(&zr->resource_lock);
+
+               /* Map the V4L buffers */
+               if (!fh->v4l_buffers.allocated) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
+                               ZR_DEVNAME(zr));
+                       res = -ENOMEM;
+                       goto v4l_mmap_unlock_and_return;
+               }
+
+               first = offset / fh->v4l_buffers.buffer_size;
+               last = first - 1 + size / fh->v4l_buffers.buffer_size;
+               if (offset % fh->v4l_buffers.buffer_size != 0 ||
+                   size % fh->v4l_buffers.buffer_size != 0 || first < 0 ||
+                   last < 0 || first >= fh->v4l_buffers.num_buffers ||
+                   last >= fh->v4l_buffers.buffer_size) {
+                       dprintk(1,
+                               KERN_ERR
+                               "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
+                               ZR_DEVNAME(zr), offset, size,
+                               fh->v4l_buffers.buffer_size,
+                               fh->v4l_buffers.num_buffers);
+                       res = -EINVAL;
+                       goto v4l_mmap_unlock_and_return;
+               }
+               for (i = first; i <= last; i++) {
+                       if (fh->v4l_buffers.buffer[i].map) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: mmap(V4L) - buffer %d already mapped\n",
+                                       ZR_DEVNAME(zr), i);
+                               res = -EBUSY;
+                               goto v4l_mmap_unlock_and_return;
+                       }
+               }
+
+               /* map these buffers (v4l_buffers[i]) */
+               map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
+               if (!map) {
+                       res = -ENOMEM;
+                       goto v4l_mmap_unlock_and_return;
+               }
+               map->file = file;
+               map->count = 1;
+
+               vma->vm_ops = &zoran_vm_ops;
+               vma->vm_flags |= VM_DONTEXPAND;
+               vma->vm_private_data = map;
+
+               for (i = first; i <= last; i++) {
+                       todo = size;
+                       if (todo > fh->v4l_buffers.buffer_size)
+                               todo = fh->v4l_buffers.buffer_size;
+                       page = fh->v4l_buffers.buffer[i].fbuffer_phys;
+                       if (remap_pfn_range(vma, start, page >> PAGE_SHIFT,
+                                                       todo, PAGE_SHARED)) {
+                               dprintk(1,
+                                       KERN_ERR
+                                       "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
+                                       ZR_DEVNAME(zr));
+                               res = -EAGAIN;
+                               goto v4l_mmap_unlock_and_return;
+                       }
+                       size -= todo;
+                       start += todo;
+                       fh->v4l_buffers.buffer[i].map = map;
+                       if (size == 0)
+                               break;
+               }
+       v4l_mmap_unlock_and_return:
+               mutex_unlock(&zr->resource_lock);
+
+               break;
+
+       default:
+               dprintk(1,
+                       KERN_ERR
+                       "%s: zoran_mmap() - internal error - unknown map mode %d\n",
+                       ZR_DEVNAME(zr), fh->map_mode);
+               break;
+       }
+
+       return 0;
+}
+
+static const struct file_operations zoran_fops = {
+       .owner = THIS_MODULE,
+       .open = zoran_open,
+       .release = zoran_close,
+       .ioctl = zoran_ioctl,
+#ifdef CONFIG_COMPAT
+       .compat_ioctl   = v4l_compat_ioctl32,
+#endif
+       .llseek = no_llseek,
+       .read = zoran_read,
+       .write = zoran_write,
+       .mmap = zoran_mmap,
+       .poll = zoran_poll,
+};
+
+struct video_device zoran_template __devinitdata = {
+       .name = ZORAN_NAME,
+       .fops = &zoran_fops,
+       .release = &zoran_vdev_release,
+       .minor = -1
+};
+
diff --git a/drivers/media/video/zoran/zoran_procfs.c b/drivers/media/video/zoran/zoran_procfs.c
new file mode 100644 (file)
index 0000000..870bc5a
--- /dev/null
@@ -0,0 +1,225 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles the procFS entries (/proc/ZORAN[%d])
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <linux/types.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/vmalloc.h>
+
+#include <linux/proc_fs.h>
+#include <linux/pci.h>
+#include <linux/i2c.h>
+#include <linux/i2c-algo-bit.h>
+#include <linux/videodev.h>
+#include <linux/spinlock.h>
+#include <linux/sem.h>
+#include <linux/seq_file.h>
+
+#include <linux/ctype.h>
+#include <linux/poll.h>
+#include <asm/io.h>
+
+#include "videocodec.h"
+#include "zoran.h"
+#include "zoran_procfs.h"
+#include "zoran_card.h"
+
+#ifdef CONFIG_PROC_FS
+struct procfs_params_zr36067 {
+       char *name;
+       short reg;
+       u32 mask;
+       short bit;
+};
+
+static const struct procfs_params_zr36067 zr67[] = {
+       {"HSPol", 0x000, 1, 30},
+       {"HStart", 0x000, 0x3ff, 10},
+       {"HEnd", 0x000, 0x3ff, 0},
+
+       {"VSPol", 0x004, 1, 30},
+       {"VStart", 0x004, 0x3ff, 10},
+       {"VEnd", 0x004, 0x3ff, 0},
+
+       {"ExtFl", 0x008, 1, 26},
+       {"TopField", 0x008, 1, 25},
+       {"VCLKPol", 0x008, 1, 24},
+       {"DupFld", 0x008, 1, 20},
+       {"LittleEndian", 0x008, 1, 0},
+
+       {"HsyncStart", 0x10c, 0xffff, 16},
+       {"LineTot", 0x10c, 0xffff, 0},
+
+       {"NAX", 0x110, 0xffff, 16},
+       {"PAX", 0x110, 0xffff, 0},
+
+       {"NAY", 0x114, 0xffff, 16},
+       {"PAY", 0x114, 0xffff, 0},
+
+       /* {"",,,}, */
+
+       {NULL, 0, 0, 0},
+};
+
+static void
+setparam (struct zoran *zr,
+         char         *name,
+         char         *sval)
+{
+       int i = 0, reg0, reg, val;
+
+       while (zr67[i].name != NULL) {
+               if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) {
+                       reg = reg0 = btread(zr67[i].reg);
+                       reg &= ~(zr67[i].mask << zr67[i].bit);
+                       if (!isdigit(sval[0]))
+                               break;
+                       val = simple_strtoul(sval, NULL, 0);
+                       if ((val & ~zr67[i].mask))
+                               break;
+                       reg |= (val & zr67[i].mask) << zr67[i].bit;
+                       dprintk(4,
+                               KERN_INFO
+                               "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%d\n",
+                               ZR_DEVNAME(zr), zr67[i].reg, reg0, reg,
+                               zr67[i].name, val);
+                       btwrite(reg, zr67[i].reg);
+                       break;
+               }
+               i++;
+       }
+}
+
+static int zoran_show(struct seq_file *p, void *v)
+{
+       struct zoran *zr = p->private;
+       int i;
+
+       seq_printf(p, "ZR36067 registers:\n");
+       for (i = 0; i < 0x130; i += 16)
+               seq_printf(p, "%03X %08X  %08X  %08X  %08X \n", i,
+                          btread(i), btread(i+4), btread(i+8), btread(i+12));
+       return 0;
+}
+
+static int zoran_open(struct inode *inode, struct file *file)
+{
+       struct zoran *data = PDE(inode)->data;
+       return single_open(file, zoran_show, data);
+}
+
+static ssize_t zoran_write(struct file *file, const char __user *buffer,
+                       size_t count, loff_t *ppos)
+{
+       struct zoran *zr = PDE(file->f_path.dentry->d_inode)->data;
+       char *string, *sp;
+       char *line, *ldelim, *varname, *svar, *tdelim;
+
+       if (count > 32768)      /* Stupidity filter */
+               return -EINVAL;
+
+       string = sp = vmalloc(count + 1);
+       if (!string) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: write_proc: can not allocate memory\n",
+                       ZR_DEVNAME(zr));
+               return -ENOMEM;
+       }
+       if (copy_from_user(string, buffer, count)) {
+               vfree (string);
+               return -EFAULT;
+       }
+       string[count] = 0;
+       dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n",
+               ZR_DEVNAME(zr), file->f_path.dentry->d_name.name, count, zr);
+       ldelim = " \t\n";
+       tdelim = "=";
+       line = strpbrk(sp, ldelim);
+       while (line) {
+               *line = 0;
+               svar = strpbrk(sp, tdelim);
+               if (svar) {
+                       *svar = 0;
+                       varname = sp;
+                       svar++;
+                       setparam(zr, varname, svar);
+               }
+               sp = line + 1;
+               line = strpbrk(sp, ldelim);
+       }
+       vfree(string);
+
+       return count;
+}
+
+static const struct file_operations zoran_operations = {
+       .owner          = THIS_MODULE,
+       .open           = zoran_open,
+       .read           = seq_read,
+       .write          = zoran_write,
+       .llseek         = seq_lseek,
+       .release        = single_release,
+};
+#endif
+
+int
+zoran_proc_init (struct zoran *zr)
+{
+#ifdef CONFIG_PROC_FS
+       char name[8];
+
+       snprintf(name, 7, "zoran%d", zr->id);
+       zr->zoran_proc = proc_create_data(name, 0, NULL, &zoran_operations, zr);
+       if (zr->zoran_proc != NULL) {
+               dprintk(2,
+                       KERN_INFO
+                       "%s: procfs entry /proc/%s allocated. data=%p\n",
+                       ZR_DEVNAME(zr), name, zr->zoran_proc->data);
+       } else {
+               dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
+                       ZR_DEVNAME(zr), name);
+               return 1;
+       }
+#endif
+       return 0;
+}
+
+void
+zoran_proc_cleanup (struct zoran *zr)
+{
+#ifdef CONFIG_PROC_FS
+       char name[8];
+
+       snprintf(name, 7, "zoran%d", zr->id);
+       if (zr->zoran_proc)
+               remove_proc_entry(name, NULL);
+       zr->zoran_proc = NULL;
+#endif
+}
diff --git a/drivers/media/video/zoran/zoran_procfs.h b/drivers/media/video/zoran/zoran_procfs.h
new file mode 100644 (file)
index 0000000..f2d5b1b
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Zoran zr36057/zr36067 PCI controller driver, for the
+ * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
+ * Media Labs LML33/LML33R10.
+ *
+ * This part handles card-specific data and detection
+ *
+ * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
+ *
+ * Currently maintained by:
+ *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
+ *   Laurent Pinchart <laurent.pinchart@skynet.be>
+ *   Mailinglist      <mjpeg-users@lists.sf.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __ZORAN_PROCFS_H__
+#define __ZORAN_PROCFS_H__
+
+extern int zoran_proc_init(struct zoran *zr);
+extern void zoran_proc_cleanup(struct zoran *zr);
+
+#endif                         /* __ZORAN_PROCFS_H__ */
diff --git a/drivers/media/video/zoran/zr36016.c b/drivers/media/video/zoran/zr36016.c
new file mode 100644 (file)
index 0000000..00d132b
--- /dev/null
@@ -0,0 +1,529 @@
+/*
+ * Zoran ZR36016 basic configuration functions
+ *
+ * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: zr36016.c,v 1.1.2.14 2003/08/20 19:46:55 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#define ZR016_VERSION "v0.7"
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <linux/types.h>
+#include <linux/wait.h>
+
+/* includes for structures and defines regarding video
+   #include<linux/videodev.h> */
+
+/* I/O commands, error codes */
+#include <asm/io.h>
+//#include<errno.h>
+
+/* v4l  API */
+#include <linux/videodev.h>
+
+/* headerfile of this module */
+#include"zr36016.h"
+
+/* codec io API */
+#include"videocodec.h"
+
+/* it doesn't make sense to have more than 20 or so,
+  just to prevent some unwanted loops */
+#define MAX_CODECS 20
+
+/* amount of chips attached via this driver */
+static int zr36016_codecs;
+
+/* debugging is available via module parameter */
+static int debug;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug level (0-4)");
+
+#define dprintk(num, format, args...) \
+       do { \
+               if (debug >= num) \
+                       printk(format, ##args); \
+       } while (0)
+
+/* =========================================================================
+   Local hardware I/O functions:
+
+   read/write via codec layer (registers are located in the master device)
+   ========================================================================= */
+
+/* read and write functions */
+static u8
+zr36016_read (struct zr36016 *ptr,
+             u16             reg)
+{
+       u8 value = 0;
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->readreg)
+               value =
+                   (ptr->codec->master_data->
+                    readreg(ptr->codec, reg)) & 0xFF;
+       else
+               dprintk(1,
+                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
+                       ptr->name);
+
+       dprintk(4, "%s: reading from 0x%04x: %02x\n", ptr->name, reg,
+               value);
+
+       return value;
+}
+
+static void
+zr36016_write (struct zr36016 *ptr,
+              u16             reg,
+              u8              value)
+{
+       dprintk(4, "%s: writing 0x%02x to 0x%04x\n", ptr->name, value,
+               reg);
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->writereg) {
+               ptr->codec->master_data->writereg(ptr->codec, reg, value);
+       } else
+               dprintk(1,
+                       KERN_ERR
+                       "%s: invalid I/O setup, nothing written!\n",
+                       ptr->name);
+}
+
+/* indirect read and write functions */
+/* the 016 supports auto-addr-increment, but
+ * writing it all time cost not much and is safer... */
+static u8
+zr36016_readi (struct zr36016 *ptr,
+              u16             reg)
+{
+       u8 value = 0;
+
+       // just in case something is wrong...
+       if ((ptr->codec->master_data->writereg) &&
+           (ptr->codec->master_data->readreg)) {
+               ptr->codec->master_data->writereg(ptr->codec, ZR016_IADDR, reg & 0x0F); // ADDR
+               value = (ptr->codec->master_data->readreg(ptr->codec, ZR016_IDATA)) & 0xFF;     // DATA
+       } else
+               dprintk(1,
+                       KERN_ERR
+                       "%s: invalid I/O setup, nothing read (i)!\n",
+                       ptr->name);
+
+       dprintk(4, "%s: reading indirect from 0x%04x: %02x\n", ptr->name,
+               reg, value);
+       return value;
+}
+
+static void
+zr36016_writei (struct zr36016 *ptr,
+               u16             reg,
+               u8              value)
+{
+       dprintk(4, "%s: writing indirect 0x%02x to 0x%04x\n", ptr->name,
+               value, reg);
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->writereg) {
+               ptr->codec->master_data->writereg(ptr->codec, ZR016_IADDR, reg & 0x0F); // ADDR
+               ptr->codec->master_data->writereg(ptr->codec, ZR016_IDATA, value & 0x0FF);      // DATA
+       } else
+               dprintk(1,
+                       KERN_ERR
+                       "%s: invalid I/O setup, nothing written (i)!\n",
+                       ptr->name);
+}
+
+/* =========================================================================
+   Local helper function:
+
+   version read
+   ========================================================================= */
+
+/* version kept in datastructure */
+static u8
+zr36016_read_version (struct zr36016 *ptr)
+{
+       ptr->version = zr36016_read(ptr, 0) >> 4;
+       return ptr->version;
+}
+
+/* =========================================================================
+   Local helper function:
+
+   basic test of "connectivity", writes/reads to/from PAX-Lo register
+   ========================================================================= */
+
+static int
+zr36016_basic_test (struct zr36016 *ptr)
+{
+       if (debug) {
+               int i;
+               zr36016_writei(ptr, ZR016I_PAX_LO, 0x55);
+               dprintk(1, KERN_INFO "%s: registers: ", ptr->name);
+               for (i = 0; i <= 0x0b; i++)
+                       dprintk(1, "%02x ", zr36016_readi(ptr, i));
+               dprintk(1, "\n");
+       }
+       // for testing just write 0, then the default value to a register and read
+       // it back in both cases
+       zr36016_writei(ptr, ZR016I_PAX_LO, 0x00);
+       if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, can't connect to vfe processor!\n",
+                       ptr->name);
+               return -ENXIO;
+       }
+       zr36016_writei(ptr, ZR016I_PAX_LO, 0x0d0);
+       if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0d0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, can't connect to vfe processor!\n",
+                       ptr->name);
+               return -ENXIO;
+       }
+       // we allow version numbers from 0-3, should be enough, though
+       zr36016_read_version(ptr);
+       if (ptr->version & 0x0c) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, suspicious version %d found...\n",
+                       ptr->name, ptr->version);
+               return -ENXIO;
+       }
+
+       return 0;               /* looks good! */
+}
+
+/* =========================================================================
+   Local helper function:
+
+   simple loop for pushing the init datasets - NO USE --
+   ========================================================================= */
+
+#if 0
+static int zr36016_pushit (struct zr36016 *ptr,
+                          u16             startreg,
+                          u16             len,
+                          const char     *data)
+{
+       int i=0;
+
+       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n",
+               ptr->name, startreg,len);
+       while (i<len) {
+               zr36016_writei(ptr, startreg++,  data[i++]);
+       }
+
+       return i;
+}
+#endif
+
+/* =========================================================================
+   Basic datasets & init:
+
+   //TODO//
+   ========================================================================= */
+
+// needed offset values          PAL NTSC SECAM
+static const int zr016_xoff[] = { 20, 20, 20 };
+static const int zr016_yoff[] = { 8, 9, 7 };
+
+static void
+zr36016_init (struct zr36016 *ptr)
+{
+       // stop any processing
+       zr36016_write(ptr, ZR016_GOSTOP, 0);
+
+       // mode setup (yuv422 in and out, compression/expansuon due to mode)
+       zr36016_write(ptr, ZR016_MODE,
+                     ZR016_YUV422 | ZR016_YUV422_YUV422 |
+                     (ptr->mode == CODEC_DO_COMPRESSION ?
+                      ZR016_COMPRESSION : ZR016_EXPANSION));
+
+       // misc setup
+       zr36016_writei(ptr, ZR016I_SETUP1,
+                      (ptr->xdec ? (ZR016_HRFL | ZR016_HORZ) : 0) |
+                      (ptr->ydec ? ZR016_VERT : 0) | ZR016_CNTI);
+       zr36016_writei(ptr, ZR016I_SETUP2, ZR016_CCIR);
+
+       // Window setup
+       // (no extra offset for now, norm defines offset, default width height)
+       zr36016_writei(ptr, ZR016I_PAX_HI, ptr->width >> 8);
+       zr36016_writei(ptr, ZR016I_PAX_LO, ptr->width & 0xFF);
+       zr36016_writei(ptr, ZR016I_PAY_HI, ptr->height >> 8);
+       zr36016_writei(ptr, ZR016I_PAY_LO, ptr->height & 0xFF);
+       zr36016_writei(ptr, ZR016I_NAX_HI, ptr->xoff >> 8);
+       zr36016_writei(ptr, ZR016I_NAX_LO, ptr->xoff & 0xFF);
+       zr36016_writei(ptr, ZR016I_NAY_HI, ptr->yoff >> 8);
+       zr36016_writei(ptr, ZR016I_NAY_LO, ptr->yoff & 0xFF);
+
+       /* shall we continue now, please? */
+       zr36016_write(ptr, ZR016_GOSTOP, 1);
+}
+
+/* =========================================================================
+   CODEC API FUNCTIONS
+
+   this functions are accessed by the master via the API structure
+   ========================================================================= */
+
+/* set compression/expansion mode and launches codec -
+   this should be the last call from the master before starting processing */
+static int
+zr36016_set_mode (struct videocodec *codec,
+                 int                mode)
+{
+       struct zr36016 *ptr = (struct zr36016 *) codec->data;
+
+       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
+
+       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
+               return -EINVAL;
+
+       ptr->mode = mode;
+       zr36016_init(ptr);
+
+       return 0;
+}
+
+/* set picture size */
+static int
+zr36016_set_video (struct videocodec   *codec,
+                  struct tvnorm       *norm,
+                  struct vfe_settings *cap,
+                  struct vfe_polarity *pol)
+{
+       struct zr36016 *ptr = (struct zr36016 *) codec->data;
+
+       dprintk(2, "%s: set_video %d.%d, %d/%d-%dx%d (0x%x) call\n",
+               ptr->name, norm->HStart, norm->VStart,
+               cap->x, cap->y, cap->width, cap->height,
+               cap->decimation);
+
+       /* if () return -EINVAL;
+        * trust the master driver that it knows what it does - so
+        * we allow invalid startx/y for now ... */
+       ptr->width = cap->width;
+       ptr->height = cap->height;
+       /* (Ronald) This is ugly. zoran_device.c, line 387
+        * already mentions what happens if HStart is even
+        * (blue faces, etc., cr/cb inversed). There's probably
+        * some good reason why HStart is 0 instead of 1, so I'm
+        * leaving it to this for now, but really... This can be
+        * done a lot simpler */
+       ptr->xoff = (norm->HStart ? norm->HStart : 1) + cap->x;
+       /* Something to note here (I don't understand it), setting
+        * VStart too high will cause the codec to 'not work'. I
+        * really don't get it. values of 16 (VStart) already break
+        * it here. Just '0' seems to work. More testing needed! */
+       ptr->yoff = norm->VStart + cap->y;
+       /* (Ronald) dzjeeh, can't this thing do hor_decimation = 4? */
+       ptr->xdec = ((cap->decimation & 0xff) == 1) ? 0 : 1;
+       ptr->ydec = (((cap->decimation >> 8) & 0xff) == 1) ? 0 : 1;
+
+       return 0;
+}
+
+/* additional control functions */
+static int
+zr36016_control (struct videocodec *codec,
+                int                type,
+                int                size,
+                void              *data)
+{
+       struct zr36016 *ptr = (struct zr36016 *) codec->data;
+       int *ival = (int *) data;
+
+       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
+               size);
+
+       switch (type) {
+       case CODEC_G_STATUS:    /* get last status - we don't know it ... */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = 0;
+               break;
+
+       case CODEC_G_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = 0;
+               break;
+
+       case CODEC_S_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               if (*ival != 0)
+                       return -EINVAL;
+               /* not needed, do nothing */
+               return 0;
+
+       case CODEC_G_VFE:
+       case CODEC_S_VFE:
+               return 0;
+
+       case CODEC_S_MMAP:
+               /* not available, give an error */
+               return -ENXIO;
+
+       default:
+               return -EINVAL;
+       }
+
+       return size;
+}
+
+/* =========================================================================
+   Exit and unregister function:
+
+   Deinitializes Zoran's JPEG processor
+   ========================================================================= */
+
+static int
+zr36016_unset (struct videocodec *codec)
+{
+       struct zr36016 *ptr = codec->data;
+
+       if (ptr) {
+               /* do wee need some codec deinit here, too ???? */
+
+               dprintk(1, "%s: finished codec #%d\n", ptr->name,
+                       ptr->num);
+               kfree(ptr);
+               codec->data = NULL;
+
+               zr36016_codecs--;
+               return 0;
+       }
+
+       return -EFAULT;
+}
+
+/* =========================================================================
+   Setup and registry function:
+
+   Initializes Zoran's JPEG processor
+
+   Also sets pixel size, average code size, mode (compr./decompr.)
+   (the given size is determined by the processor with the video interface)
+   ========================================================================= */
+
+static int
+zr36016_setup (struct videocodec *codec)
+{
+       struct zr36016 *ptr;
+       int res;
+
+       dprintk(2, "zr36016: initializing VFE subsystem #%d.\n",
+               zr36016_codecs);
+
+       if (zr36016_codecs == MAX_CODECS) {
+               dprintk(1,
+                       KERN_ERR "zr36016: Can't attach more codecs!\n");
+               return -ENOSPC;
+       }
+       //mem structure init
+       codec->data = ptr = kzalloc(sizeof(struct zr36016), GFP_KERNEL);
+       if (NULL == ptr) {
+               dprintk(1, KERN_ERR "zr36016: Can't get enough memory!\n");
+               return -ENOMEM;
+       }
+
+       snprintf(ptr->name, sizeof(ptr->name), "zr36016[%d]",
+                zr36016_codecs);
+       ptr->num = zr36016_codecs++;
+       ptr->codec = codec;
+
+       //testing
+       res = zr36016_basic_test(ptr);
+       if (res < 0) {
+               zr36016_unset(codec);
+               return res;
+       }
+       //final setup
+       ptr->mode = CODEC_DO_COMPRESSION;
+       ptr->width = 768;
+       ptr->height = 288;
+       ptr->xdec = 1;
+       ptr->ydec = 0;
+       zr36016_init(ptr);
+
+       dprintk(1, KERN_INFO "%s: codec v%d attached and running\n",
+               ptr->name, ptr->version);
+
+       return 0;
+}
+
+static const struct videocodec zr36016_codec = {
+       .owner = THIS_MODULE,
+       .name = "zr36016",
+       .magic = 0L,            // magic not used
+       .flags =
+           CODEC_FLAG_HARDWARE | CODEC_FLAG_VFE | CODEC_FLAG_ENCODER |
+           CODEC_FLAG_DECODER,
+       .type = CODEC_TYPE_ZR36016,
+       .setup = zr36016_setup, // functionality
+       .unset = zr36016_unset,
+       .set_mode = zr36016_set_mode,
+       .set_video = zr36016_set_video,
+       .control = zr36016_control,
+       // others are not used
+};
+
+/* =========================================================================
+   HOOK IN DRIVER AS KERNEL MODULE
+   ========================================================================= */
+
+static int __init
+zr36016_init_module (void)
+{
+       //dprintk(1, "ZR36016 driver %s\n",ZR016_VERSION);
+       zr36016_codecs = 0;
+       return videocodec_register(&zr36016_codec);
+}
+
+static void __exit
+zr36016_cleanup_module (void)
+{
+       if (zr36016_codecs) {
+               dprintk(1,
+                       "zr36016: something's wrong - %d codecs left somehow.\n",
+                       zr36016_codecs);
+       }
+       videocodec_unregister(&zr36016_codec);
+}
+
+module_init(zr36016_init_module);
+module_exit(zr36016_cleanup_module);
+
+MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
+MODULE_DESCRIPTION("Driver module for ZR36016 video frontends "
+                  ZR016_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zoran/zr36016.h b/drivers/media/video/zoran/zr36016.h
new file mode 100644 (file)
index 0000000..8c79229
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * Zoran ZR36016 basic configuration functions - header file
+ *
+ * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: zr36016.h,v 1.1.2.3 2003/01/14 21:18:07 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#ifndef ZR36016_H
+#define ZR36016_H
+
+/* data stored for each zoran jpeg codec chip */
+struct zr36016 {
+       char name[32];
+       int num;
+       /* io datastructure */
+       struct videocodec *codec;
+       // coder status
+       __u8 version;
+       // actual coder setup
+       int mode;
+
+       __u16 xoff;
+       __u16 yoff;
+       __u16 width;
+       __u16 height;
+       __u16 xdec;
+       __u16 ydec;
+};
+
+/* direct  register addresses */
+#define ZR016_GOSTOP      0x00
+#define ZR016_MODE        0x01
+#define ZR016_IADDR       0x02
+#define ZR016_IDATA       0x03
+
+/* indirect  register addresses */
+#define ZR016I_SETUP1     0x00
+#define ZR016I_SETUP2     0x01
+#define ZR016I_NAX_LO     0x02
+#define ZR016I_NAX_HI     0x03
+#define ZR016I_PAX_LO     0x04
+#define ZR016I_PAX_HI     0x05
+#define ZR016I_NAY_LO     0x06
+#define ZR016I_NAY_HI     0x07
+#define ZR016I_PAY_LO     0x08
+#define ZR016I_PAY_HI     0x09
+#define ZR016I_NOL_LO     0x0a
+#define ZR016I_NOL_HI     0x0b
+
+/* possible values for mode register */
+#define ZR016_RGB444_YUV444  0x00
+#define ZR016_RGB444_YUV422  0x01
+#define ZR016_RGB444_YUV411  0x02
+#define ZR016_RGB444_Y400    0x03
+#define ZR016_RGB444_RGB444  0x04
+#define ZR016_YUV444_YUV444  0x08
+#define ZR016_YUV444_YUV422  0x09
+#define ZR016_YUV444_YUV411  0x0a
+#define ZR016_YUV444_Y400    0x0b
+#define ZR016_YUV444_RGB444  0x0c
+#define ZR016_YUV422_YUV422  0x11
+#define ZR016_YUV422_YUV411  0x12
+#define ZR016_YUV422_Y400    0x13
+#define ZR016_YUV411_YUV411  0x16
+#define ZR016_YUV411_Y400    0x17
+#define ZR016_4444_4444      0x19
+#define ZR016_100_100        0x1b
+
+#define ZR016_RGB444         0x00
+#define ZR016_YUV444         0x20
+#define ZR016_YUV422         0x40
+
+#define ZR016_COMPRESSION    0x80
+#define ZR016_EXPANSION      0x80
+
+/* possible values for setup 1 register */
+#define ZR016_CKRT           0x80
+#define ZR016_VERT           0x40
+#define ZR016_HORZ           0x20
+#define ZR016_HRFL           0x10
+#define ZR016_DSFL           0x08
+#define ZR016_SBFL           0x04
+#define ZR016_RSTR           0x02
+#define ZR016_CNTI           0x01
+
+/* possible values for setup 2 register */
+#define ZR016_SYEN           0x40
+#define ZR016_CCIR           0x04
+#define ZR016_SIGN           0x02
+#define ZR016_YMCS           0x01
+
+#endif                         /*fndef ZR36016_H */
diff --git a/drivers/media/video/zoran/zr36050.c b/drivers/media/video/zoran/zr36050.c
new file mode 100644 (file)
index 0000000..cf8b271
--- /dev/null
@@ -0,0 +1,904 @@
+/*
+ * Zoran ZR36050 basic configuration functions
+ *
+ * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: zr36050.c,v 1.1.2.11 2003/08/03 14:54:53 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#define ZR050_VERSION "v0.7.1"
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <linux/types.h>
+#include <linux/wait.h>
+
+/* includes for structures and defines regarding video
+   #include<linux/videodev.h> */
+
+/* I/O commands, error codes */
+#include <asm/io.h>
+//#include<errno.h>
+
+/* headerfile of this module */
+#include "zr36050.h"
+
+/* codec io API */
+#include "videocodec.h"
+
+/* it doesn't make sense to have more than 20 or so,
+  just to prevent some unwanted loops */
+#define MAX_CODECS 20
+
+/* amount of chips attached via this driver */
+static int zr36050_codecs;
+
+/* debugging is available via module parameter */
+static int debug;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug level (0-4)");
+
+#define dprintk(num, format, args...) \
+       do { \
+               if (debug >= num) \
+                       printk(format, ##args); \
+       } while (0)
+
+/* =========================================================================
+   Local hardware I/O functions:
+
+   read/write via codec layer (registers are located in the master device)
+   ========================================================================= */
+
+/* read and write functions */
+static u8
+zr36050_read (struct zr36050 *ptr,
+             u16             reg)
+{
+       u8 value = 0;
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->readreg)
+               value = (ptr->codec->master_data->readreg(ptr->codec,
+                                                         reg)) & 0xFF;
+       else
+               dprintk(1,
+                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
+                       ptr->name);
+
+       dprintk(4, "%s: reading from 0x%04x: %02x\n", ptr->name, reg,
+               value);
+
+       return value;
+}
+
+static void
+zr36050_write (struct zr36050 *ptr,
+              u16             reg,
+              u8              value)
+{
+       dprintk(4, "%s: writing 0x%02x to 0x%04x\n", ptr->name, value,
+               reg);
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->writereg)
+               ptr->codec->master_data->writereg(ptr->codec, reg, value);
+       else
+               dprintk(1,
+                       KERN_ERR
+                       "%s: invalid I/O setup, nothing written!\n",
+                       ptr->name);
+}
+
+/* =========================================================================
+   Local helper function:
+
+   status read
+   ========================================================================= */
+
+/* status is kept in datastructure */
+static u8
+zr36050_read_status1 (struct zr36050 *ptr)
+{
+       ptr->status1 = zr36050_read(ptr, ZR050_STATUS_1);
+
+       zr36050_read(ptr, 0);
+       return ptr->status1;
+}
+
+/* =========================================================================
+   Local helper function:
+
+   scale factor read
+   ========================================================================= */
+
+/* scale factor is kept in datastructure */
+static u16
+zr36050_read_scalefactor (struct zr36050 *ptr)
+{
+       ptr->scalefact = (zr36050_read(ptr, ZR050_SF_HI) << 8) |
+                        (zr36050_read(ptr, ZR050_SF_LO) & 0xFF);
+
+       /* leave 0 selected for an eventually GO from master */
+       zr36050_read(ptr, 0);
+       return ptr->scalefact;
+}
+
+/* =========================================================================
+   Local helper function:
+
+   wait if codec is ready to proceed (end of processing) or time is over
+   ========================================================================= */
+
+static void
+zr36050_wait_end (struct zr36050 *ptr)
+{
+       int i = 0;
+
+       while (!(zr36050_read_status1(ptr) & 0x4)) {
+               udelay(1);
+               if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
+                       dprintk(1,
+                               "%s: timeout at wait_end (last status: 0x%02x)\n",
+                               ptr->name, ptr->status1);
+                       break;
+               }
+       }
+}
+
+/* =========================================================================
+   Local helper function:
+
+   basic test of "connectivity", writes/reads to/from memory the SOF marker
+   ========================================================================= */
+
+static int
+zr36050_basic_test (struct zr36050 *ptr)
+{
+       zr36050_write(ptr, ZR050_SOF_IDX, 0x00);
+       zr36050_write(ptr, ZR050_SOF_IDX + 1, 0x00);
+       if ((zr36050_read(ptr, ZR050_SOF_IDX) |
+            zr36050_read(ptr, ZR050_SOF_IDX + 1)) != 0x0000) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, can't connect to jpeg processor!\n",
+                       ptr->name);
+               return -ENXIO;
+       }
+       zr36050_write(ptr, ZR050_SOF_IDX, 0xff);
+       zr36050_write(ptr, ZR050_SOF_IDX + 1, 0xc0);
+       if (((zr36050_read(ptr, ZR050_SOF_IDX) << 8) |
+            zr36050_read(ptr, ZR050_SOF_IDX + 1)) != 0xffc0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, can't connect to jpeg processor!\n",
+                       ptr->name);
+               return -ENXIO;
+       }
+
+       zr36050_wait_end(ptr);
+       if ((ptr->status1 & 0x4) == 0) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, jpeg processor failed (end flag)!\n",
+                       ptr->name);
+               return -EBUSY;
+       }
+
+       return 0;               /* looks good! */
+}
+
+/* =========================================================================
+   Local helper function:
+
+   simple loop for pushing the init datasets
+   ========================================================================= */
+
+static int
+zr36050_pushit (struct zr36050 *ptr,
+               u16             startreg,
+               u16             len,
+               const char     *data)
+{
+       int i = 0;
+
+       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n", ptr->name,
+               startreg, len);
+       while (i < len) {
+               zr36050_write(ptr, startreg++, data[i++]);
+       }
+
+       return i;
+}
+
+/* =========================================================================
+   Basic datasets:
+
+   jpeg baseline setup data (you find it on lots places in internet, or just
+   extract it from any regular .jpg image...)
+
+   Could be variable, but until it's not needed it they are just fixed to save
+   memory. Otherwise expand zr36050 structure with arrays, push the values to
+   it and initalize from there, as e.g. the linux zr36057/60 driver does it.
+   ========================================================================= */
+
+static const char zr36050_dqt[0x86] = {
+       0xff, 0xdb,             //Marker: DQT
+       0x00, 0x84,             //Length: 2*65+2
+       0x00,                   //Pq,Tq first table
+       0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
+       0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
+       0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
+       0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
+       0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
+       0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
+       0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
+       0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
+       0x01,                   //Pq,Tq second table
+       0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
+       0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
+};
+
+static const char zr36050_dht[0x1a4] = {
+       0xff, 0xc4,             //Marker: DHT
+       0x01, 0xa2,             //Length: 2*AC, 2*DC
+       0x00,                   //DC first table
+       0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
+       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
+       0x01,                   //DC second table
+       0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+       0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
+       0x10,                   //AC first table
+       0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03,
+       0x05, 0x05, 0x04, 0x04, 0x00, 0x00,
+       0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
+       0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
+       0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,
+       0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24,
+       0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17,
+       0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34,
+       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
+       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
+       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
+       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+       0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+       0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+       0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+       0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9,
+       0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8,
+       0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
+       0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+       0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+       0xF8, 0xF9, 0xFA,
+       0x11,                   //AC second table
+       0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
+       0x07, 0x05, 0x04, 0x04, 0x00, 0x01,
+       0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
+       0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+       0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+       0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62,
+       0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25,
+       0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
+       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
+       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
+       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
+       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+       0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+       0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+       0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
+       0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
+       0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+       0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8,
+       0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+       0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
+       0xF9, 0xFA
+};
+
+/* jpeg baseline setup, this is just fixed in this driver (YUV pictures) */
+#define NO_OF_COMPONENTS          0x3  //Y,U,V
+#define BASELINE_PRECISION        0x8  //MCU size (?)
+static const char zr36050_tq[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's QT
+static const char zr36050_td[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's DC
+static const char zr36050_ta[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's AC
+
+/* horizontal 422 decimation setup (maybe we support 411 or so later, too) */
+static const char zr36050_decimation_h[8] = { 2, 1, 1, 0, 0, 0, 0, 0 };
+static const char zr36050_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
+
+/* =========================================================================
+   Local helper functions:
+
+   calculation and setup of parameter-dependent JPEG baseline segments
+   (needed for compression only)
+   ========================================================================= */
+
+/* ------------------------------------------------------------------------- */
+
+/* SOF (start of frame) segment depends on width, height and sampling ratio
+                        of each color component */
+
+static int
+zr36050_set_sof (struct zr36050 *ptr)
+{
+       char sof_data[34];      // max. size of register set
+       int i;
+
+       dprintk(3, "%s: write SOF (%dx%d, %d components)\n", ptr->name,
+               ptr->width, ptr->height, NO_OF_COMPONENTS);
+       sof_data[0] = 0xff;
+       sof_data[1] = 0xc0;
+       sof_data[2] = 0x00;
+       sof_data[3] = (3 * NO_OF_COMPONENTS) + 8;
+       sof_data[4] = BASELINE_PRECISION;       // only '8' possible with zr36050
+       sof_data[5] = (ptr->height) >> 8;
+       sof_data[6] = (ptr->height) & 0xff;
+       sof_data[7] = (ptr->width) >> 8;
+       sof_data[8] = (ptr->width) & 0xff;
+       sof_data[9] = NO_OF_COMPONENTS;
+       for (i = 0; i < NO_OF_COMPONENTS; i++) {
+               sof_data[10 + (i * 3)] = i;     // index identifier
+               sof_data[11 + (i * 3)] = (ptr->h_samp_ratio[i] << 4) | (ptr->v_samp_ratio[i]);  // sampling ratios
+               sof_data[12 + (i * 3)] = zr36050_tq[i]; // Q table selection
+       }
+       return zr36050_pushit(ptr, ZR050_SOF_IDX,
+                             (3 * NO_OF_COMPONENTS) + 10, sof_data);
+}
+
+/* ------------------------------------------------------------------------- */
+
+/* SOS (start of scan) segment depends on the used scan components
+                       of each color component */
+
+static int
+zr36050_set_sos (struct zr36050 *ptr)
+{
+       char sos_data[16];      // max. size of register set
+       int i;
+
+       dprintk(3, "%s: write SOS\n", ptr->name);
+       sos_data[0] = 0xff;
+       sos_data[1] = 0xda;
+       sos_data[2] = 0x00;
+       sos_data[3] = 2 + 1 + (2 * NO_OF_COMPONENTS) + 3;
+       sos_data[4] = NO_OF_COMPONENTS;
+       for (i = 0; i < NO_OF_COMPONENTS; i++) {
+               sos_data[5 + (i * 2)] = i;      // index
+               sos_data[6 + (i * 2)] = (zr36050_td[i] << 4) | zr36050_ta[i];   // AC/DC tbl.sel.
+       }
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00;      // scan start
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3F;
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 4] = 00;
+       return zr36050_pushit(ptr, ZR050_SOS1_IDX,
+                             4 + 1 + (2 * NO_OF_COMPONENTS) + 3,
+                             sos_data);
+}
+
+/* ------------------------------------------------------------------------- */
+
+/* DRI (define restart interval) */
+
+static int
+zr36050_set_dri (struct zr36050 *ptr)
+{
+       char dri_data[6];       // max. size of register set
+
+       dprintk(3, "%s: write DRI\n", ptr->name);
+       dri_data[0] = 0xff;
+       dri_data[1] = 0xdd;
+       dri_data[2] = 0x00;
+       dri_data[3] = 0x04;
+       dri_data[4] = ptr->dri >> 8;
+       dri_data[5] = ptr->dri & 0xff;
+       return zr36050_pushit(ptr, ZR050_DRI_IDX, 6, dri_data);
+}
+
+/* =========================================================================
+   Setup function:
+
+   Setup compression/decompression of Zoran's JPEG processor
+   ( see also zoran 36050 manual )
+
+   ... sorry for the spaghetti code ...
+   ========================================================================= */
+static void
+zr36050_init (struct zr36050 *ptr)
+{
+       int sum = 0;
+       long bitcnt, tmp;
+
+       if (ptr->mode == CODEC_DO_COMPRESSION) {
+               dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);
+
+               /* 050 communicates with 057 in master mode */
+               zr36050_write(ptr, ZR050_HARDWARE, ZR050_HW_MSTR);
+
+               /* encoding table preload for compression */
+               zr36050_write(ptr, ZR050_MODE,
+                             ZR050_MO_COMP | ZR050_MO_TLM);
+               zr36050_write(ptr, ZR050_OPTIONS, 0);
+
+               /* disable all IRQs */
+               zr36050_write(ptr, ZR050_INT_REQ_0, 0);
+               zr36050_write(ptr, ZR050_INT_REQ_1, 3); // low 2 bits always 1
+
+               /* volume control settings */
+               /*zr36050_write(ptr, ZR050_MBCV, ptr->max_block_vol);*/
+               zr36050_write(ptr, ZR050_SF_HI, ptr->scalefact >> 8);
+               zr36050_write(ptr, ZR050_SF_LO, ptr->scalefact & 0xff);
+
+               zr36050_write(ptr, ZR050_AF_HI, 0xff);
+               zr36050_write(ptr, ZR050_AF_M, 0xff);
+               zr36050_write(ptr, ZR050_AF_LO, 0xff);
+
+               /* setup the variable jpeg tables */
+               sum += zr36050_set_sof(ptr);
+               sum += zr36050_set_sos(ptr);
+               sum += zr36050_set_dri(ptr);
+
+               /* setup the fixed jpeg tables - maybe variable, though -
+                * (see table init section above) */
+               dprintk(3, "%s: write DQT, DHT, APP\n", ptr->name);
+               sum += zr36050_pushit(ptr, ZR050_DQT_IDX,
+                                     sizeof(zr36050_dqt), zr36050_dqt);
+               sum += zr36050_pushit(ptr, ZR050_DHT_IDX,
+                                     sizeof(zr36050_dht), zr36050_dht);
+               zr36050_write(ptr, ZR050_APP_IDX, 0xff);
+               zr36050_write(ptr, ZR050_APP_IDX + 1, 0xe0 + ptr->app.appn);
+               zr36050_write(ptr, ZR050_APP_IDX + 2, 0x00);
+               zr36050_write(ptr, ZR050_APP_IDX + 3, ptr->app.len + 2);
+               sum += zr36050_pushit(ptr, ZR050_APP_IDX + 4, 60,
+                                     ptr->app.data) + 4;
+               zr36050_write(ptr, ZR050_COM_IDX, 0xff);
+               zr36050_write(ptr, ZR050_COM_IDX + 1, 0xfe);
+               zr36050_write(ptr, ZR050_COM_IDX + 2, 0x00);
+               zr36050_write(ptr, ZR050_COM_IDX + 3, ptr->com.len + 2);
+               sum += zr36050_pushit(ptr, ZR050_COM_IDX + 4, 60,
+                                     ptr->com.data) + 4;
+
+               /* do the internal huffman table preload */
+               zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);
+
+               zr36050_write(ptr, ZR050_GO, 1);        // launch codec
+               zr36050_wait_end(ptr);
+               dprintk(2, "%s: Status after table preload: 0x%02x\n",
+                       ptr->name, ptr->status1);
+
+               if ((ptr->status1 & 0x4) == 0) {
+                       dprintk(1, KERN_ERR "%s: init aborted!\n",
+                               ptr->name);
+                       return; // something is wrong, its timed out!!!!
+               }
+
+               /* setup misc. data for compression (target code sizes) */
+
+               /* size of compressed code to reach without header data */
+               sum = ptr->real_code_vol - sum;
+               bitcnt = sum << 3;      /* need the size in bits */
+
+               tmp = bitcnt >> 16;
+               dprintk(3,
+                       "%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
+                       ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
+               zr36050_write(ptr, ZR050_TCV_NET_HI, tmp >> 8);
+               zr36050_write(ptr, ZR050_TCV_NET_MH, tmp & 0xff);
+               tmp = bitcnt & 0xffff;
+               zr36050_write(ptr, ZR050_TCV_NET_ML, tmp >> 8);
+               zr36050_write(ptr, ZR050_TCV_NET_LO, tmp & 0xff);
+
+               bitcnt -= bitcnt >> 7;  // bits without stuffing
+               bitcnt -= ((bitcnt * 5) >> 6);  // bits without eob
+
+               tmp = bitcnt >> 16;
+               dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
+                       ptr->name, bitcnt, tmp);
+               zr36050_write(ptr, ZR050_TCV_DATA_HI, tmp >> 8);
+               zr36050_write(ptr, ZR050_TCV_DATA_MH, tmp & 0xff);
+               tmp = bitcnt & 0xffff;
+               zr36050_write(ptr, ZR050_TCV_DATA_ML, tmp >> 8);
+               zr36050_write(ptr, ZR050_TCV_DATA_LO, tmp & 0xff);
+
+               /* compression setup with or without bitrate control */
+               zr36050_write(ptr, ZR050_MODE,
+                             ZR050_MO_COMP | ZR050_MO_PASS2 |
+                             (ptr->bitrate_ctrl ? ZR050_MO_BRC : 0));
+
+               /* this headers seem to deliver "valid AVI" jpeg frames */
+               zr36050_write(ptr, ZR050_MARKERS_EN,
+                             ZR050_ME_DQT | ZR050_ME_DHT |
+                             ((ptr->app.len > 0) ? ZR050_ME_APP : 0) |
+                             ((ptr->com.len > 0) ? ZR050_ME_COM : 0));
+       } else {
+               dprintk(2, "%s: EXPANSION SETUP\n", ptr->name);
+
+               /* 050 communicates with 055 in master mode */
+               zr36050_write(ptr, ZR050_HARDWARE,
+                             ZR050_HW_MSTR | ZR050_HW_CFIS_2_CLK);
+
+               /* encoding table preload */
+               zr36050_write(ptr, ZR050_MODE, ZR050_MO_TLM);
+
+               /* disable all IRQs */
+               zr36050_write(ptr, ZR050_INT_REQ_0, 0);
+               zr36050_write(ptr, ZR050_INT_REQ_1, 3); // low 2 bits always 1
+
+               dprintk(3, "%s: write DHT\n", ptr->name);
+               zr36050_pushit(ptr, ZR050_DHT_IDX, sizeof(zr36050_dht),
+                              zr36050_dht);
+
+               /* do the internal huffman table preload */
+               zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);
+
+               zr36050_write(ptr, ZR050_GO, 1);        // launch codec
+               zr36050_wait_end(ptr);
+               dprintk(2, "%s: Status after table preload: 0x%02x\n",
+                       ptr->name, ptr->status1);
+
+               if ((ptr->status1 & 0x4) == 0) {
+                       dprintk(1, KERN_ERR "%s: init aborted!\n",
+                               ptr->name);
+                       return; // something is wrong, its timed out!!!!
+               }
+
+               /* setup misc. data for expansion */
+               zr36050_write(ptr, ZR050_MODE, 0);
+               zr36050_write(ptr, ZR050_MARKERS_EN, 0);
+       }
+
+       /* adr on selected, to allow GO from master */
+       zr36050_read(ptr, 0);
+}
+
+/* =========================================================================
+   CODEC API FUNCTIONS
+
+   this functions are accessed by the master via the API structure
+   ========================================================================= */
+
+/* set compression/expansion mode and launches codec -
+   this should be the last call from the master before starting processing */
+static int
+zr36050_set_mode (struct videocodec *codec,
+                 int                mode)
+{
+       struct zr36050 *ptr = (struct zr36050 *) codec->data;
+
+       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
+
+       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
+               return -EINVAL;
+
+       ptr->mode = mode;
+       zr36050_init(ptr);
+
+       return 0;
+}
+
+/* set picture size (norm is ignored as the codec doesn't know about it) */
+static int
+zr36050_set_video (struct videocodec   *codec,
+                  struct tvnorm       *norm,
+                  struct vfe_settings *cap,
+                  struct vfe_polarity *pol)
+{
+       struct zr36050 *ptr = (struct zr36050 *) codec->data;
+       int size;
+
+       dprintk(2, "%s: set_video %d.%d, %d/%d-%dx%d (0x%x) q%d call\n",
+               ptr->name, norm->HStart, norm->VStart,
+               cap->x, cap->y, cap->width, cap->height,
+               cap->decimation, cap->quality);
+       /* if () return -EINVAL;
+        * trust the master driver that it knows what it does - so
+        * we allow invalid startx/y and norm for now ... */
+       ptr->width = cap->width / (cap->decimation & 0xff);
+       ptr->height = cap->height / ((cap->decimation >> 8) & 0xff);
+
+       /* (KM) JPEG quality */
+       size = ptr->width * ptr->height;
+       size *= 16; /* size in bits */
+       /* apply quality setting */
+       size = size * cap->quality / 200;
+
+       /* Minimum: 1kb */
+       if (size < 8192)
+               size = 8192;
+       /* Maximum: 7/8 of code buffer */
+       if (size > ptr->total_code_vol * 7)
+               size = ptr->total_code_vol * 7;
+
+       ptr->real_code_vol = size >> 3; /* in bytes */
+
+       /* Set max_block_vol here (previously in zr36050_init, moved
+        * here for consistency with zr36060 code */
+       zr36050_write(ptr, ZR050_MBCV, ptr->max_block_vol);
+
+       return 0;
+}
+
+/* additional control functions */
+static int
+zr36050_control (struct videocodec *codec,
+                int                type,
+                int                size,
+                void              *data)
+{
+       struct zr36050 *ptr = (struct zr36050 *) codec->data;
+       int *ival = (int *) data;
+
+       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
+               size);
+
+       switch (type) {
+       case CODEC_G_STATUS:    /* get last status */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               zr36050_read_status1(ptr);
+               *ival = ptr->status1;
+               break;
+
+       case CODEC_G_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = CODEC_MODE_BJPG;
+               break;
+
+       case CODEC_S_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               if (*ival != CODEC_MODE_BJPG)
+                       return -EINVAL;
+               /* not needed, do nothing */
+               return 0;
+
+       case CODEC_G_VFE:
+       case CODEC_S_VFE:
+               /* not needed, do nothing */
+               return 0;
+
+       case CODEC_S_MMAP:
+               /* not available, give an error */
+               return -ENXIO;
+
+       case CODEC_G_JPEG_TDS_BYTE:     /* get target volume in byte */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = ptr->total_code_vol;
+               break;
+
+       case CODEC_S_JPEG_TDS_BYTE:     /* get target volume in byte */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               ptr->total_code_vol = *ival;
+               /* (Kieran Morrissey)
+                * code copied from zr36060.c to ensure proper bitrate */
+               ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
+               break;
+
+       case CODEC_G_JPEG_SCALE:        /* get scaling factor */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = zr36050_read_scalefactor(ptr);
+               break;
+
+       case CODEC_S_JPEG_SCALE:        /* set scaling factor */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               ptr->scalefact = *ival;
+               break;
+
+       case CODEC_G_JPEG_APP_DATA: {   /* get appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               *app = ptr->app;
+               break;
+       }
+
+       case CODEC_S_JPEG_APP_DATA: {    /* set appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               ptr->app = *app;
+               break;
+       }
+
+       case CODEC_G_JPEG_COM_DATA: {   /* get comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               *com = ptr->com;
+               break;
+       }
+
+       case CODEC_S_JPEG_COM_DATA: {   /* set comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               ptr->com = *com;
+               break;
+       }
+
+       default:
+               return -EINVAL;
+       }
+
+       return size;
+}
+
+/* =========================================================================
+   Exit and unregister function:
+
+   Deinitializes Zoran's JPEG processor
+   ========================================================================= */
+
+static int
+zr36050_unset (struct videocodec *codec)
+{
+       struct zr36050 *ptr = codec->data;
+
+       if (ptr) {
+               /* do wee need some codec deinit here, too ???? */
+
+               dprintk(1, "%s: finished codec #%d\n", ptr->name,
+                       ptr->num);
+               kfree(ptr);
+               codec->data = NULL;
+
+               zr36050_codecs--;
+               return 0;
+       }
+
+       return -EFAULT;
+}
+
+/* =========================================================================
+   Setup and registry function:
+
+   Initializes Zoran's JPEG processor
+
+   Also sets pixel size, average code size, mode (compr./decompr.)
+   (the given size is determined by the processor with the video interface)
+   ========================================================================= */
+
+static int
+zr36050_setup (struct videocodec *codec)
+{
+       struct zr36050 *ptr;
+       int res;
+
+       dprintk(2, "zr36050: initializing MJPEG subsystem #%d.\n",
+               zr36050_codecs);
+
+       if (zr36050_codecs == MAX_CODECS) {
+               dprintk(1,
+                       KERN_ERR "zr36050: Can't attach more codecs!\n");
+               return -ENOSPC;
+       }
+       //mem structure init
+       codec->data = ptr = kzalloc(sizeof(struct zr36050), GFP_KERNEL);
+       if (NULL == ptr) {
+               dprintk(1, KERN_ERR "zr36050: Can't get enough memory!\n");
+               return -ENOMEM;
+       }
+
+       snprintf(ptr->name, sizeof(ptr->name), "zr36050[%d]",
+                zr36050_codecs);
+       ptr->num = zr36050_codecs++;
+       ptr->codec = codec;
+
+       //testing
+       res = zr36050_basic_test(ptr);
+       if (res < 0) {
+               zr36050_unset(codec);
+               return res;
+       }
+       //final setup
+       memcpy(ptr->h_samp_ratio, zr36050_decimation_h, 8);
+       memcpy(ptr->v_samp_ratio, zr36050_decimation_v, 8);
+
+       ptr->bitrate_ctrl = 0;  /* 0 or 1 - fixed file size flag
+                                * (what is the difference?) */
+       ptr->mode = CODEC_DO_COMPRESSION;
+       ptr->width = 384;
+       ptr->height = 288;
+       ptr->total_code_vol = 16000;
+       ptr->max_block_vol = 240;
+       ptr->scalefact = 0x100;
+       ptr->dri = 1;
+
+       /* no app/com marker by default */
+       ptr->app.appn = 0;
+       ptr->app.len = 0;
+       ptr->com.len = 0;
+
+       zr36050_init(ptr);
+
+       dprintk(1, KERN_INFO "%s: codec attached and running\n",
+               ptr->name);
+
+       return 0;
+}
+
+static const struct videocodec zr36050_codec = {
+       .owner = THIS_MODULE,
+       .name = "zr36050",
+       .magic = 0L,            // magic not used
+       .flags =
+           CODEC_FLAG_JPEG | CODEC_FLAG_HARDWARE | CODEC_FLAG_ENCODER |
+           CODEC_FLAG_DECODER,
+       .type = CODEC_TYPE_ZR36050,
+       .setup = zr36050_setup, // functionality
+       .unset = zr36050_unset,
+       .set_mode = zr36050_set_mode,
+       .set_video = zr36050_set_video,
+       .control = zr36050_control,
+       // others are not used
+};
+
+/* =========================================================================
+   HOOK IN DRIVER AS KERNEL MODULE
+   ========================================================================= */
+
+static int __init
+zr36050_init_module (void)
+{
+       //dprintk(1, "ZR36050 driver %s\n",ZR050_VERSION);
+       zr36050_codecs = 0;
+       return videocodec_register(&zr36050_codec);
+}
+
+static void __exit
+zr36050_cleanup_module (void)
+{
+       if (zr36050_codecs) {
+               dprintk(1,
+                       "zr36050: something's wrong - %d codecs left somehow.\n",
+                       zr36050_codecs);
+       }
+       videocodec_unregister(&zr36050_codec);
+}
+
+module_init(zr36050_init_module);
+module_exit(zr36050_cleanup_module);
+
+MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
+MODULE_DESCRIPTION("Driver module for ZR36050 jpeg processors "
+                  ZR050_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zoran/zr36050.h b/drivers/media/video/zoran/zr36050.h
new file mode 100644 (file)
index 0000000..9f52f0c
--- /dev/null
@@ -0,0 +1,184 @@
+/*
+ * Zoran ZR36050 basic configuration functions - header file
+ *
+ * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
+ *
+ * $Id: zr36050.h,v 1.1.2.2 2003/01/14 21:18:22 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#ifndef ZR36050_H
+#define ZR36050_H
+
+#include "videocodec.h"
+
+/* data stored for each zoran jpeg codec chip */
+struct zr36050 {
+       char name[32];
+       int num;
+       /* io datastructure */
+       struct videocodec *codec;
+       // last coder status
+       __u8 status1;
+       // actual coder setup
+       int mode;
+
+       __u16 width;
+       __u16 height;
+
+       __u16 bitrate_ctrl;
+
+       __u32 total_code_vol;
+       __u32 real_code_vol;
+       __u16 max_block_vol;
+
+       __u8 h_samp_ratio[8];
+       __u8 v_samp_ratio[8];
+       __u16 scalefact;
+       __u16 dri;
+
+       /* com/app marker */
+       struct jpeg_com_marker com;
+       struct jpeg_app_marker app;
+};
+
+/* zr36050 register addresses */
+#define ZR050_GO                  0x000
+#define ZR050_HARDWARE            0x002
+#define ZR050_MODE                0x003
+#define ZR050_OPTIONS             0x004
+#define ZR050_MBCV                0x005
+#define ZR050_MARKERS_EN          0x006
+#define ZR050_INT_REQ_0           0x007
+#define ZR050_INT_REQ_1           0x008
+#define ZR050_TCV_NET_HI          0x009
+#define ZR050_TCV_NET_MH          0x00a
+#define ZR050_TCV_NET_ML          0x00b
+#define ZR050_TCV_NET_LO          0x00c
+#define ZR050_TCV_DATA_HI         0x00d
+#define ZR050_TCV_DATA_MH         0x00e
+#define ZR050_TCV_DATA_ML         0x00f
+#define ZR050_TCV_DATA_LO         0x010
+#define ZR050_SF_HI               0x011
+#define ZR050_SF_LO               0x012
+#define ZR050_AF_HI               0x013
+#define ZR050_AF_M                0x014
+#define ZR050_AF_LO               0x015
+#define ZR050_ACV_HI              0x016
+#define ZR050_ACV_MH              0x017
+#define ZR050_ACV_ML              0x018
+#define ZR050_ACV_LO              0x019
+#define ZR050_ACT_HI              0x01a
+#define ZR050_ACT_MH              0x01b
+#define ZR050_ACT_ML              0x01c
+#define ZR050_ACT_LO              0x01d
+#define ZR050_ACV_TRUN_HI         0x01e
+#define ZR050_ACV_TRUN_MH         0x01f
+#define ZR050_ACV_TRUN_ML         0x020
+#define ZR050_ACV_TRUN_LO         0x021
+#define ZR050_STATUS_0            0x02e
+#define ZR050_STATUS_1            0x02f
+
+#define ZR050_SOF_IDX             0x040
+#define ZR050_SOS1_IDX            0x07a
+#define ZR050_SOS2_IDX            0x08a
+#define ZR050_SOS3_IDX            0x09a
+#define ZR050_SOS4_IDX            0x0aa
+#define ZR050_DRI_IDX             0x0c0
+#define ZR050_DNL_IDX             0x0c6
+#define ZR050_DQT_IDX             0x0cc
+#define ZR050_DHT_IDX             0x1d4
+#define ZR050_APP_IDX             0x380
+#define ZR050_COM_IDX             0x3c0
+
+/* zr36050 hardware register bits */
+
+#define ZR050_HW_BSWD                0x80
+#define ZR050_HW_MSTR                0x40
+#define ZR050_HW_DMA                 0x20
+#define ZR050_HW_CFIS_1_CLK          0x00
+#define ZR050_HW_CFIS_2_CLK          0x04
+#define ZR050_HW_CFIS_3_CLK          0x08
+#define ZR050_HW_CFIS_4_CLK          0x0C
+#define ZR050_HW_CFIS_5_CLK          0x10
+#define ZR050_HW_CFIS_6_CLK          0x14
+#define ZR050_HW_CFIS_7_CLK          0x18
+#define ZR050_HW_CFIS_8_CLK          0x1C
+#define ZR050_HW_BELE                0x01
+
+/* zr36050 mode register bits */
+
+#define ZR050_MO_COMP                0x80
+#define ZR050_MO_COMP                0x80
+#define ZR050_MO_ATP                 0x40
+#define ZR050_MO_PASS2               0x20
+#define ZR050_MO_TLM                 0x10
+#define ZR050_MO_DCONLY              0x08
+#define ZR050_MO_BRC                 0x04
+
+#define ZR050_MO_ATP                 0x40
+#define ZR050_MO_PASS2               0x20
+#define ZR050_MO_TLM                 0x10
+#define ZR050_MO_DCONLY              0x08
+
+/* zr36050 option register bits */
+
+#define ZR050_OP_NSCN_1              0x00
+#define ZR050_OP_NSCN_2              0x20
+#define ZR050_OP_NSCN_3              0x40
+#define ZR050_OP_NSCN_4              0x60
+#define ZR050_OP_NSCN_5              0x80
+#define ZR050_OP_NSCN_6              0xA0
+#define ZR050_OP_NSCN_7              0xC0
+#define ZR050_OP_NSCN_8              0xE0
+#define ZR050_OP_OVF                 0x10
+
+
+/* zr36050 markers-enable register bits */
+
+#define ZR050_ME_APP                 0x80
+#define ZR050_ME_COM                 0x40
+#define ZR050_ME_DRI                 0x20
+#define ZR050_ME_DQT                 0x10
+#define ZR050_ME_DHT                 0x08
+#define ZR050_ME_DNL                 0x04
+#define ZR050_ME_DQTI                0x02
+#define ZR050_ME_DHTI                0x01
+
+/* zr36050 status0/1 register bit masks */
+
+#define ZR050_ST_RST_MASK            0x20
+#define ZR050_ST_SOF_MASK            0x02
+#define ZR050_ST_SOS_MASK            0x02
+#define ZR050_ST_DATRDY_MASK         0x80
+#define ZR050_ST_MRKDET_MASK         0x40
+#define ZR050_ST_RFM_MASK            0x10
+#define ZR050_ST_RFD_MASK            0x08
+#define ZR050_ST_END_MASK            0x04
+#define ZR050_ST_TCVOVF_MASK         0x02
+#define ZR050_ST_DATOVF_MASK         0x01
+
+/* pixel component idx */
+
+#define ZR050_Y_COMPONENT         0
+#define ZR050_U_COMPONENT         1
+#define ZR050_V_COMPONENT         2
+
+#endif                         /*fndef ZR36050_H */
diff --git a/drivers/media/video/zoran/zr36057.h b/drivers/media/video/zoran/zr36057.h
new file mode 100644 (file)
index 0000000..54c9362
--- /dev/null
@@ -0,0 +1,168 @@
+/*
+ * zr36057.h - zr36057 register offsets
+ *
+ * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef _ZR36057_H_
+#define _ZR36057_H_
+
+
+/* Zoran ZR36057 registers */
+
+#define ZR36057_VFEHCR          0x000  /* Video Front End, Horizontal Configuration Register */
+#define ZR36057_VFEHCR_HSPol            (1<<30)
+#define ZR36057_VFEHCR_HStart           10
+#define ZR36057_VFEHCR_HEnd            0
+#define ZR36057_VFEHCR_Hmask           0x3ff
+
+#define ZR36057_VFEVCR          0x004  /* Video Front End, Vertical Configuration Register */
+#define ZR36057_VFEVCR_VSPol            (1<<30)
+#define ZR36057_VFEVCR_VStart           10
+#define ZR36057_VFEVCR_VEnd            0
+#define ZR36057_VFEVCR_Vmask           0x3ff
+
+#define ZR36057_VFESPFR         0x008  /* Video Front End, Scaler and Pixel Format Register */
+#define ZR36057_VFESPFR_ExtFl           (1<<26)
+#define ZR36057_VFESPFR_TopField        (1<<25)
+#define ZR36057_VFESPFR_VCLKPol         (1<<24)
+#define ZR36057_VFESPFR_HFilter         21
+#define ZR36057_VFESPFR_HorDcm          14
+#define ZR36057_VFESPFR_VerDcm          8
+#define ZR36057_VFESPFR_DispMode        6
+#define ZR36057_VFESPFR_YUV422          (0<<3)
+#define ZR36057_VFESPFR_RGB888          (1<<3)
+#define ZR36057_VFESPFR_RGB565          (2<<3)
+#define ZR36057_VFESPFR_RGB555          (3<<3)
+#define ZR36057_VFESPFR_ErrDif          (1<<2)
+#define ZR36057_VFESPFR_Pack24          (1<<1)
+#define ZR36057_VFESPFR_LittleEndian    (1<<0)
+
+#define ZR36057_VDTR            0x00c  /* Video Display "Top" Register */
+
+#define ZR36057_VDBR            0x010  /* Video Display "Bottom" Register */
+
+#define ZR36057_VSSFGR          0x014  /* Video Stride, Status, and Frame Grab Register */
+#define ZR36057_VSSFGR_DispStride       16
+#define ZR36057_VSSFGR_VidOvf           (1<<8)
+#define ZR36057_VSSFGR_SnapShot         (1<<1)
+#define ZR36057_VSSFGR_FrameGrab        (1<<0)
+
+#define ZR36057_VDCR            0x018  /* Video Display Configuration Register */
+#define ZR36057_VDCR_VidEn              (1<<31)
+#define ZR36057_VDCR_MinPix             24
+#define ZR36057_VDCR_Triton             (1<<24)
+#define ZR36057_VDCR_VidWinHt           12
+#define ZR36057_VDCR_VidWinWid          0
+
+#define ZR36057_MMTR            0x01c  /* Masking Map "Top" Register */
+
+#define ZR36057_MMBR            0x020  /* Masking Map "Bottom" Register */
+
+#define ZR36057_OCR             0x024  /* Overlay Control Register */
+#define ZR36057_OCR_OvlEnable           (1 << 15)
+#define ZR36057_OCR_MaskStride          0
+
+#define ZR36057_SPGPPCR         0x028  /* System, PCI, and General Purpose Pins Control Register */
+#define ZR36057_SPGPPCR_SoftReset      (1<<24)
+
+#define ZR36057_GPPGCR1         0x02c  /* General Purpose Pins and GuestBus Control Register (1) */
+
+#define ZR36057_MCSAR           0x030  /* MPEG Code Source Address Register */
+
+#define ZR36057_MCTCR           0x034  /* MPEG Code Transfer Control Register */
+#define ZR36057_MCTCR_CodTime           (1 << 30)
+#define ZR36057_MCTCR_CEmpty            (1 << 29)
+#define ZR36057_MCTCR_CFlush            (1 << 28)
+#define ZR36057_MCTCR_CodGuestID       20
+#define ZR36057_MCTCR_CodGuestReg      16
+
+#define ZR36057_MCMPR           0x038  /* MPEG Code Memory Pointer Register */
+
+#define ZR36057_ISR             0x03c  /* Interrupt Status Register */
+#define ZR36057_ISR_GIRQ1               (1<<30)
+#define ZR36057_ISR_GIRQ0               (1<<29)
+#define ZR36057_ISR_CodRepIRQ           (1<<28)
+#define ZR36057_ISR_JPEGRepIRQ          (1<<27)
+
+#define ZR36057_ICR             0x040  /* Interrupt Control Register */
+#define ZR36057_ICR_GIRQ1               (1<<30)
+#define ZR36057_ICR_GIRQ0               (1<<29)
+#define ZR36057_ICR_CodRepIRQ           (1<<28)
+#define ZR36057_ICR_JPEGRepIRQ          (1<<27)
+#define ZR36057_ICR_IntPinEn            (1<<24)
+
+#define ZR36057_I2CBR           0x044  /* I2C Bus Register */
+#define ZR36057_I2CBR_SDA              (1<<1)
+#define ZR36057_I2CBR_SCL              (1<<0)
+
+#define ZR36057_JMC             0x100  /* JPEG Mode and Control */
+#define ZR36057_JMC_JPG                 (1 << 31)
+#define ZR36057_JMC_JPGExpMode          (0 << 29)
+#define ZR36057_JMC_JPGCmpMode          (1 << 29)
+#define ZR36057_JMC_MJPGExpMode         (2 << 29)
+#define ZR36057_JMC_MJPGCmpMode         (3 << 29)
+#define ZR36057_JMC_RTBUSY_FB           (1 << 6)
+#define ZR36057_JMC_Go_en               (1 << 5)
+#define ZR36057_JMC_SyncMstr            (1 << 4)
+#define ZR36057_JMC_Fld_per_buff        (1 << 3)
+#define ZR36057_JMC_VFIFO_FB            (1 << 2)
+#define ZR36057_JMC_CFIFO_FB            (1 << 1)
+#define ZR36057_JMC_Stll_LitEndian      (1 << 0)
+
+#define ZR36057_JPC             0x104  /* JPEG Process Control */
+#define ZR36057_JPC_P_Reset             (1 << 7)
+#define ZR36057_JPC_CodTrnsEn           (1 << 5)
+#define ZR36057_JPC_Active              (1 << 0)
+
+#define ZR36057_VSP             0x108  /* Vertical Sync Parameters */
+#define ZR36057_VSP_VsyncSize           16
+#define ZR36057_VSP_FrmTot              0
+
+#define ZR36057_HSP             0x10c  /* Horizontal Sync Parameters */
+#define ZR36057_HSP_HsyncStart          16
+#define ZR36057_HSP_LineTot             0
+
+#define ZR36057_FHAP            0x110  /* Field Horizontal Active Portion */
+#define ZR36057_FHAP_NAX                16
+#define ZR36057_FHAP_PAX                0
+
+#define ZR36057_FVAP            0x114  /* Field Vertical Active Portion */
+#define ZR36057_FVAP_NAY                16
+#define ZR36057_FVAP_PAY                0
+
+#define ZR36057_FPP             0x118  /* Field Process Parameters */
+#define ZR36057_FPP_Odd_Even            (1 << 0)
+
+#define ZR36057_JCBA            0x11c  /* JPEG Code Base Address */
+
+#define ZR36057_JCFT            0x120  /* JPEG Code FIFO Threshold */
+
+#define ZR36057_JCGI            0x124  /* JPEG Codec Guest ID */
+#define ZR36057_JCGI_JPEGuestID         4
+#define ZR36057_JCGI_JPEGuestReg        0
+
+#define ZR36057_GCR2            0x12c  /* GuestBus Control Register (2) */
+
+#define ZR36057_POR             0x200  /* Post Office Register */
+#define ZR36057_POR_POPen               (1<<25)
+#define ZR36057_POR_POTime              (1<<24)
+#define ZR36057_POR_PODir               (1<<23)
+
+#define ZR36057_STR             0x300  /* "Still" Transfer Register */
+
+#endif
diff --git a/drivers/media/video/zoran/zr36060.c b/drivers/media/video/zoran/zr36060.c
new file mode 100644 (file)
index 0000000..8e74054
--- /dev/null
@@ -0,0 +1,1014 @@
+/*
+ * Zoran ZR36060 basic configuration functions
+ *
+ * Copyright (C) 2002 Laurent Pinchart <laurent.pinchart@skynet.be>
+ *
+ * $Id: zr36060.c,v 1.1.2.22 2003/05/06 09:35:36 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#define ZR060_VERSION "v0.7"
+
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/delay.h>
+
+#include <linux/types.h>
+#include <linux/wait.h>
+
+/* includes for structures and defines regarding video
+   #include<linux/videodev.h> */
+
+/* I/O commands, error codes */
+#include <asm/io.h>
+//#include<errno.h>
+
+/* headerfile of this module */
+#include "zr36060.h"
+
+/* codec io API */
+#include "videocodec.h"
+
+/* it doesn't make sense to have more than 20 or so,
+  just to prevent some unwanted loops */
+#define MAX_CODECS 20
+
+/* amount of chips attached via this driver */
+static int zr36060_codecs;
+
+static int low_bitrate;
+module_param(low_bitrate, bool, 0);
+MODULE_PARM_DESC(low_bitrate, "Buz compatibility option, halves bitrate");
+
+/* debugging is available via module parameter */
+static int debug;
+module_param(debug, int, 0);
+MODULE_PARM_DESC(debug, "Debug level (0-4)");
+
+#define dprintk(num, format, args...) \
+       do { \
+               if (debug >= num) \
+                       printk(format, ##args); \
+       } while (0)
+
+/* =========================================================================
+   Local hardware I/O functions:
+
+   read/write via codec layer (registers are located in the master device)
+   ========================================================================= */
+
+/* read and write functions */
+static u8
+zr36060_read (struct zr36060 *ptr,
+             u16             reg)
+{
+       u8 value = 0;
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->readreg)
+               value = (ptr->codec->master_data->readreg(ptr->codec,
+                                                         reg)) & 0xff;
+       else
+               dprintk(1,
+                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
+                       ptr->name);
+
+       //dprintk(4, "%s: reading from 0x%04x: %02x\n",ptr->name,reg,value);
+
+       return value;
+}
+
+static void
+zr36060_write(struct zr36060 *ptr,
+             u16             reg,
+             u8              value)
+{
+       //dprintk(4, "%s: writing 0x%02x to 0x%04x\n",ptr->name,value,reg);
+       dprintk(4, "0x%02x @0x%04x\n", value, reg);
+
+       // just in case something is wrong...
+       if (ptr->codec->master_data->writereg)
+               ptr->codec->master_data->writereg(ptr->codec, reg, value);
+       else
+               dprintk(1,
+                       KERN_ERR
+                       "%s: invalid I/O setup, nothing written!\n",
+                       ptr->name);
+}
+
+/* =========================================================================
+   Local helper function:
+
+   status read
+   ========================================================================= */
+
+/* status is kept in datastructure */
+static u8
+zr36060_read_status (struct zr36060 *ptr)
+{
+       ptr->status = zr36060_read(ptr, ZR060_CFSR);
+
+       zr36060_read(ptr, 0);
+       return ptr->status;
+}
+
+/* =========================================================================
+   Local helper function:
+
+   scale factor read
+   ========================================================================= */
+
+/* scale factor is kept in datastructure */
+static u16
+zr36060_read_scalefactor (struct zr36060 *ptr)
+{
+       ptr->scalefact = (zr36060_read(ptr, ZR060_SF_HI) << 8) |
+                        (zr36060_read(ptr, ZR060_SF_LO) & 0xFF);
+
+       /* leave 0 selected for an eventually GO from master */
+       zr36060_read(ptr, 0);
+       return ptr->scalefact;
+}
+
+/* =========================================================================
+   Local helper function:
+
+   wait if codec is ready to proceed (end of processing) or time is over
+   ========================================================================= */
+
+static void
+zr36060_wait_end (struct zr36060 *ptr)
+{
+       int i = 0;
+
+       while (zr36060_read_status(ptr) & ZR060_CFSR_Busy) {
+               udelay(1);
+               if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
+                       dprintk(1,
+                               "%s: timeout at wait_end (last status: 0x%02x)\n",
+                               ptr->name, ptr->status);
+                       break;
+               }
+       }
+}
+
+/* =========================================================================
+   Local helper function:
+
+   basic test of "connectivity", writes/reads to/from memory the SOF marker
+   ========================================================================= */
+
+static int
+zr36060_basic_test (struct zr36060 *ptr)
+{
+       if ((zr36060_read(ptr, ZR060_IDR_DEV) != 0x33) &&
+           (zr36060_read(ptr, ZR060_IDR_REV) != 0x01)) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, can't connect to jpeg processor!\n",
+                       ptr->name);
+               return -ENXIO;
+       }
+
+       zr36060_wait_end(ptr);
+       if (ptr->status & ZR060_CFSR_Busy) {
+               dprintk(1,
+                       KERN_ERR
+                       "%s: attach failed, jpeg processor failed (end flag)!\n",
+                       ptr->name);
+               return -EBUSY;
+       }
+
+       return 0;               /* looks good! */
+}
+
+/* =========================================================================
+   Local helper function:
+
+   simple loop for pushing the init datasets
+   ========================================================================= */
+
+static int
+zr36060_pushit (struct zr36060 *ptr,
+               u16             startreg,
+               u16             len,
+               const char     *data)
+{
+       int i = 0;
+
+       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n", ptr->name,
+               startreg, len);
+       while (i < len) {
+               zr36060_write(ptr, startreg++, data[i++]);
+       }
+
+       return i;
+}
+
+/* =========================================================================
+   Basic datasets:
+
+   jpeg baseline setup data (you find it on lots places in internet, or just
+   extract it from any regular .jpg image...)
+
+   Could be variable, but until it's not needed it they are just fixed to save
+   memory. Otherwise expand zr36060 structure with arrays, push the values to
+   it and initalize from there, as e.g. the linux zr36057/60 driver does it.
+   ========================================================================= */
+
+static const char zr36060_dqt[0x86] = {
+       0xff, 0xdb,             //Marker: DQT
+       0x00, 0x84,             //Length: 2*65+2
+       0x00,                   //Pq,Tq first table
+       0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
+       0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
+       0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
+       0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
+       0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
+       0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
+       0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
+       0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
+       0x01,                   //Pq,Tq second table
+       0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
+       0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
+       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
+};
+
+static const char zr36060_dht[0x1a4] = {
+       0xff, 0xc4,             //Marker: DHT
+       0x01, 0xa2,             //Length: 2*AC, 2*DC
+       0x00,                   //DC first table
+       0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
+       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
+       0x01,                   //DC second table
+       0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
+       0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
+       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
+       0x10,                   //AC first table
+       0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03,
+       0x05, 0x05, 0x04, 0x04, 0x00, 0x00,
+       0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
+       0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
+       0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,
+       0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24,
+       0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17,
+       0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34,
+       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
+       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
+       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
+       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+       0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
+       0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
+       0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
+       0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9,
+       0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8,
+       0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
+       0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+       0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
+       0xF8, 0xF9, 0xFA,
+       0x11,                   //AC second table
+       0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
+       0x07, 0x05, 0x04, 0x04, 0x00, 0x01,
+       0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
+       0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
+       0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
+       0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62,
+       0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25,
+       0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
+       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
+       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
+       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
+       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
+       0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+       0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
+       0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
+       0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
+       0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
+       0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8,
+       0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
+       0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
+       0xF9, 0xFA
+};
+
+/* jpeg baseline setup, this is just fixed in this driver (YUV pictures) */
+#define NO_OF_COMPONENTS          0x3  //Y,U,V
+#define BASELINE_PRECISION        0x8  //MCU size (?)
+static const char zr36060_tq[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's QT
+static const char zr36060_td[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's DC
+static const char zr36060_ta[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's AC
+
+/* horizontal 422 decimation setup (maybe we support 411 or so later, too) */
+static const char zr36060_decimation_h[8] = { 2, 1, 1, 0, 0, 0, 0, 0 };
+static const char zr36060_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
+
+/* =========================================================================
+   Local helper functions:
+
+   calculation and setup of parameter-dependent JPEG baseline segments
+   (needed for compression only)
+   ========================================================================= */
+
+/* ------------------------------------------------------------------------- */
+
+/* SOF (start of frame) segment depends on width, height and sampling ratio
+                        of each color component */
+
+static int
+zr36060_set_sof (struct zr36060 *ptr)
+{
+       char sof_data[34];      // max. size of register set
+       int i;
+
+       dprintk(3, "%s: write SOF (%dx%d, %d components)\n", ptr->name,
+               ptr->width, ptr->height, NO_OF_COMPONENTS);
+       sof_data[0] = 0xff;
+       sof_data[1] = 0xc0;
+       sof_data[2] = 0x00;
+       sof_data[3] = (3 * NO_OF_COMPONENTS) + 8;
+       sof_data[4] = BASELINE_PRECISION;       // only '8' possible with zr36060
+       sof_data[5] = (ptr->height) >> 8;
+       sof_data[6] = (ptr->height) & 0xff;
+       sof_data[7] = (ptr->width) >> 8;
+       sof_data[8] = (ptr->width) & 0xff;
+       sof_data[9] = NO_OF_COMPONENTS;
+       for (i = 0; i < NO_OF_COMPONENTS; i++) {
+               sof_data[10 + (i * 3)] = i;     // index identifier
+               sof_data[11 + (i * 3)] = (ptr->h_samp_ratio[i] << 4) |
+                                        (ptr->v_samp_ratio[i]); // sampling ratios
+               sof_data[12 + (i * 3)] = zr36060_tq[i]; // Q table selection
+       }
+       return zr36060_pushit(ptr, ZR060_SOF_IDX,
+                             (3 * NO_OF_COMPONENTS) + 10, sof_data);
+}
+
+/* ------------------------------------------------------------------------- */
+
+/* SOS (start of scan) segment depends on the used scan components
+                       of each color component */
+
+static int
+zr36060_set_sos (struct zr36060 *ptr)
+{
+       char sos_data[16];      // max. size of register set
+       int i;
+
+       dprintk(3, "%s: write SOS\n", ptr->name);
+       sos_data[0] = 0xff;
+       sos_data[1] = 0xda;
+       sos_data[2] = 0x00;
+       sos_data[3] = 2 + 1 + (2 * NO_OF_COMPONENTS) + 3;
+       sos_data[4] = NO_OF_COMPONENTS;
+       for (i = 0; i < NO_OF_COMPONENTS; i++) {
+               sos_data[5 + (i * 2)] = i;      // index
+               sos_data[6 + (i * 2)] = (zr36060_td[i] << 4) |
+                                       zr36060_ta[i]; // AC/DC tbl.sel.
+       }
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00;      // scan start
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3f;
+       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 4] = 00;
+       return zr36060_pushit(ptr, ZR060_SOS_IDX,
+                             4 + 1 + (2 * NO_OF_COMPONENTS) + 3,
+                             sos_data);
+}
+
+/* ------------------------------------------------------------------------- */
+
+/* DRI (define restart interval) */
+
+static int
+zr36060_set_dri (struct zr36060 *ptr)
+{
+       char dri_data[6];       // max. size of register set
+
+       dprintk(3, "%s: write DRI\n", ptr->name);
+       dri_data[0] = 0xff;
+       dri_data[1] = 0xdd;
+       dri_data[2] = 0x00;
+       dri_data[3] = 0x04;
+       dri_data[4] = (ptr->dri) >> 8;
+       dri_data[5] = (ptr->dri) & 0xff;
+       return zr36060_pushit(ptr, ZR060_DRI_IDX, 6, dri_data);
+}
+
+/* =========================================================================
+   Setup function:
+
+   Setup compression/decompression of Zoran's JPEG processor
+   ( see also zoran 36060 manual )
+
+   ... sorry for the spaghetti code ...
+   ========================================================================= */
+static void
+zr36060_init (struct zr36060 *ptr)
+{
+       int sum = 0;
+       long bitcnt, tmp;
+
+       if (ptr->mode == CODEC_DO_COMPRESSION) {
+               dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);
+
+               zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
+
+               /* 060 communicates with 067 in master mode */
+               zr36060_write(ptr, ZR060_CIR, ZR060_CIR_CodeMstr);
+
+               /* Compression with or without variable scale factor */
+               /*FIXME: What about ptr->bitrate_ctrl? */
+               zr36060_write(ptr, ZR060_CMR,
+                             ZR060_CMR_Comp | ZR060_CMR_Pass2 |
+                             ZR060_CMR_BRB);
+
+               /* Must be zero */
+               zr36060_write(ptr, ZR060_MBZ, 0x00);
+               zr36060_write(ptr, ZR060_TCR_HI, 0x00);
+               zr36060_write(ptr, ZR060_TCR_LO, 0x00);
+
+               /* Disable all IRQs - no DataErr means autoreset */
+               zr36060_write(ptr, ZR060_IMR, 0);
+
+               /* volume control settings */
+               zr36060_write(ptr, ZR060_SF_HI, ptr->scalefact >> 8);
+               zr36060_write(ptr, ZR060_SF_LO, ptr->scalefact & 0xff);
+
+               zr36060_write(ptr, ZR060_AF_HI, 0xff);
+               zr36060_write(ptr, ZR060_AF_M, 0xff);
+               zr36060_write(ptr, ZR060_AF_LO, 0xff);
+
+               /* setup the variable jpeg tables */
+               sum += zr36060_set_sof(ptr);
+               sum += zr36060_set_sos(ptr);
+               sum += zr36060_set_dri(ptr);
+
+               /* setup the fixed jpeg tables - maybe variable, though -
+                * (see table init section above) */
+               sum +=
+                   zr36060_pushit(ptr, ZR060_DQT_IDX, sizeof(zr36060_dqt),
+                                  zr36060_dqt);
+               sum +=
+                   zr36060_pushit(ptr, ZR060_DHT_IDX, sizeof(zr36060_dht),
+                                  zr36060_dht);
+               zr36060_write(ptr, ZR060_APP_IDX, 0xff);
+               zr36060_write(ptr, ZR060_APP_IDX + 1, 0xe0 + ptr->app.appn);
+               zr36060_write(ptr, ZR060_APP_IDX + 2, 0x00);
+               zr36060_write(ptr, ZR060_APP_IDX + 3, ptr->app.len + 2);
+               sum += zr36060_pushit(ptr, ZR060_APP_IDX + 4, 60,
+                                     ptr->app.data) + 4;
+               zr36060_write(ptr, ZR060_COM_IDX, 0xff);
+               zr36060_write(ptr, ZR060_COM_IDX + 1, 0xfe);
+               zr36060_write(ptr, ZR060_COM_IDX + 2, 0x00);
+               zr36060_write(ptr, ZR060_COM_IDX + 3, ptr->com.len + 2);
+               sum += zr36060_pushit(ptr, ZR060_COM_IDX + 4, 60,
+                                     ptr->com.data) + 4;
+
+               /* setup misc. data for compression (target code sizes) */
+
+               /* size of compressed code to reach without header data */
+               sum = ptr->real_code_vol - sum;
+               bitcnt = sum << 3;      /* need the size in bits */
+
+               tmp = bitcnt >> 16;
+               dprintk(3,
+                       "%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
+                       ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
+               zr36060_write(ptr, ZR060_TCV_NET_HI, tmp >> 8);
+               zr36060_write(ptr, ZR060_TCV_NET_MH, tmp & 0xff);
+               tmp = bitcnt & 0xffff;
+               zr36060_write(ptr, ZR060_TCV_NET_ML, tmp >> 8);
+               zr36060_write(ptr, ZR060_TCV_NET_LO, tmp & 0xff);
+
+               bitcnt -= bitcnt >> 7;  // bits without stuffing
+               bitcnt -= ((bitcnt * 5) >> 6);  // bits without eob
+
+               tmp = bitcnt >> 16;
+               dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
+                       ptr->name, bitcnt, tmp);
+               zr36060_write(ptr, ZR060_TCV_DATA_HI, tmp >> 8);
+               zr36060_write(ptr, ZR060_TCV_DATA_MH, tmp & 0xff);
+               tmp = bitcnt & 0xffff;
+               zr36060_write(ptr, ZR060_TCV_DATA_ML, tmp >> 8);
+               zr36060_write(ptr, ZR060_TCV_DATA_LO, tmp & 0xff);
+
+               /* JPEG markers to be included in the compressed stream */
+               zr36060_write(ptr, ZR060_MER,
+                             ZR060_MER_DQT | ZR060_MER_DHT |
+                             ((ptr->com.len > 0) ? ZR060_MER_Com : 0) |
+                             ((ptr->app.len > 0) ? ZR060_MER_App : 0));
+
+               /* Setup the Video Frontend */
+               /* Limit pixel range to 16..235 as per CCIR-601 */
+               zr36060_write(ptr, ZR060_VCR, ZR060_VCR_Range);
+
+       } else {
+               dprintk(2, "%s: EXPANSION SETUP\n", ptr->name);
+
+               zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
+
+               /* 060 communicates with 067 in master mode */
+               zr36060_write(ptr, ZR060_CIR, ZR060_CIR_CodeMstr);
+
+               /* Decompression */
+               zr36060_write(ptr, ZR060_CMR, 0);
+
+               /* Must be zero */
+               zr36060_write(ptr, ZR060_MBZ, 0x00);
+               zr36060_write(ptr, ZR060_TCR_HI, 0x00);
+               zr36060_write(ptr, ZR060_TCR_LO, 0x00);
+
+               /* Disable all IRQs - no DataErr means autoreset */
+               zr36060_write(ptr, ZR060_IMR, 0);
+
+               /* setup misc. data for expansion */
+               zr36060_write(ptr, ZR060_MER, 0);
+
+               /* setup the fixed jpeg tables - maybe variable, though -
+                * (see table init section above) */
+               zr36060_pushit(ptr, ZR060_DHT_IDX, sizeof(zr36060_dht),
+                              zr36060_dht);
+
+               /* Setup the Video Frontend */
+               //zr36060_write(ptr, ZR060_VCR, ZR060_VCR_FIExt);
+               //this doesn't seem right and doesn't work...
+               zr36060_write(ptr, ZR060_VCR, ZR060_VCR_Range);
+       }
+
+       /* Load the tables */
+       zr36060_write(ptr, ZR060_LOAD,
+                     ZR060_LOAD_SyncRst | ZR060_LOAD_Load);
+       zr36060_wait_end(ptr);
+       dprintk(2, "%s: Status after table preload: 0x%02x\n", ptr->name,
+               ptr->status);
+
+       if (ptr->status & ZR060_CFSR_Busy) {
+               dprintk(1, KERN_ERR "%s: init aborted!\n", ptr->name);
+               return;         // something is wrong, its timed out!!!!
+       }
+}
+
+/* =========================================================================
+   CODEC API FUNCTIONS
+
+   this functions are accessed by the master via the API structure
+   ========================================================================= */
+
+/* set compression/expansion mode and launches codec -
+   this should be the last call from the master before starting processing */
+static int
+zr36060_set_mode (struct videocodec *codec,
+                 int                mode)
+{
+       struct zr36060 *ptr = (struct zr36060 *) codec->data;
+
+       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
+
+       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
+               return -EINVAL;
+
+       ptr->mode = mode;
+       zr36060_init(ptr);
+
+       return 0;
+}
+
+/* set picture size (norm is ignored as the codec doesn't know about it) */
+static int
+zr36060_set_video (struct videocodec   *codec,
+                  struct tvnorm       *norm,
+                  struct vfe_settings *cap,
+                  struct vfe_polarity *pol)
+{
+       struct zr36060 *ptr = (struct zr36060 *) codec->data;
+       u32 reg;
+       int size;
+
+       dprintk(2, "%s: set_video %d/%d-%dx%d (%%%d) call\n", ptr->name,
+               cap->x, cap->y, cap->width, cap->height, cap->decimation);
+
+       /* if () return -EINVAL;
+        * trust the master driver that it knows what it does - so
+        * we allow invalid startx/y and norm for now ... */
+       ptr->width = cap->width / (cap->decimation & 0xff);
+       ptr->height = cap->height / (cap->decimation >> 8);
+
+       zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
+
+       /* Note that VSPol/HSPol bits in zr36060 have the opposite
+        * meaning of their zr360x7 counterparts with the same names
+        * N.b. for VSPol this is only true if FIVEdge = 0 (default,
+        * left unchanged here - in accordance with datasheet).
+       */
+       reg = (!pol->vsync_pol ? ZR060_VPR_VSPol : 0)
+           | (!pol->hsync_pol ? ZR060_VPR_HSPol : 0)
+           | (pol->field_pol ? ZR060_VPR_FIPol : 0)
+           | (pol->blank_pol ? ZR060_VPR_BLPol : 0)
+           | (pol->subimg_pol ? ZR060_VPR_SImgPol : 0)
+           | (pol->poe_pol ? ZR060_VPR_PoePol : 0)
+           | (pol->pvalid_pol ? ZR060_VPR_PValPol : 0)
+           | (pol->vclk_pol ? ZR060_VPR_VCLKPol : 0);
+       zr36060_write(ptr, ZR060_VPR, reg);
+
+       reg = 0;
+       switch (cap->decimation & 0xff) {
+       default:
+       case 1:
+               break;
+
+       case 2:
+               reg |= ZR060_SR_HScale2;
+               break;
+
+       case 4:
+               reg |= ZR060_SR_HScale4;
+               break;
+       }
+
+       switch (cap->decimation >> 8) {
+       default:
+       case 1:
+               break;
+
+       case 2:
+               reg |= ZR060_SR_VScale;
+               break;
+       }
+       zr36060_write(ptr, ZR060_SR, reg);
+
+       zr36060_write(ptr, ZR060_BCR_Y, 0x00);
+       zr36060_write(ptr, ZR060_BCR_U, 0x80);
+       zr36060_write(ptr, ZR060_BCR_V, 0x80);
+
+       /* sync generator */
+
+       reg = norm->Ht - 1;     /* Vtotal */
+       zr36060_write(ptr, ZR060_SGR_VTOTAL_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SGR_VTOTAL_LO, (reg >> 0) & 0xff);
+
+       reg = norm->Wt - 1;     /* Htotal */
+       zr36060_write(ptr, ZR060_SGR_HTOTAL_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SGR_HTOTAL_LO, (reg >> 0) & 0xff);
+
+       reg = 6 - 1;            /* VsyncSize */
+       zr36060_write(ptr, ZR060_SGR_VSYNC, reg);
+
+       //reg   = 30 - 1;               /* HsyncSize */
+///*CP*/        reg = (zr->params.norm == 1 ? 57 : 68);
+       reg = 68;
+       zr36060_write(ptr, ZR060_SGR_HSYNC, reg);
+
+       reg = norm->VStart - 1; /* BVstart */
+       zr36060_write(ptr, ZR060_SGR_BVSTART, reg);
+
+       reg += norm->Ha / 2;    /* BVend */
+       zr36060_write(ptr, ZR060_SGR_BVEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SGR_BVEND_LO, (reg >> 0) & 0xff);
+
+       reg = norm->HStart - 1; /* BHstart */
+       zr36060_write(ptr, ZR060_SGR_BHSTART, reg);
+
+       reg += norm->Wa;        /* BHend */
+       zr36060_write(ptr, ZR060_SGR_BHEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SGR_BHEND_LO, (reg >> 0) & 0xff);
+
+       /* active area */
+       reg = cap->y + norm->VStart;    /* Vstart */
+       zr36060_write(ptr, ZR060_AAR_VSTART_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_AAR_VSTART_LO, (reg >> 0) & 0xff);
+
+       reg += cap->height;     /* Vend */
+       zr36060_write(ptr, ZR060_AAR_VEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_AAR_VEND_LO, (reg >> 0) & 0xff);
+
+       reg = cap->x + norm->HStart;    /* Hstart */
+       zr36060_write(ptr, ZR060_AAR_HSTART_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_AAR_HSTART_LO, (reg >> 0) & 0xff);
+
+       reg += cap->width;      /* Hend */
+       zr36060_write(ptr, ZR060_AAR_HEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_AAR_HEND_LO, (reg >> 0) & 0xff);
+
+       /* subimage area */
+       reg = norm->VStart - 4; /* SVstart */
+       zr36060_write(ptr, ZR060_SWR_VSTART_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SWR_VSTART_LO, (reg >> 0) & 0xff);
+
+       reg += norm->Ha / 2 + 8;        /* SVend */
+       zr36060_write(ptr, ZR060_SWR_VEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SWR_VEND_LO, (reg >> 0) & 0xff);
+
+       reg = norm->HStart /*+ 64 */  - 4;      /* SHstart */
+       zr36060_write(ptr, ZR060_SWR_HSTART_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SWR_HSTART_LO, (reg >> 0) & 0xff);
+
+       reg += norm->Wa + 8;    /* SHend */
+       zr36060_write(ptr, ZR060_SWR_HEND_HI, (reg >> 8) & 0xff);
+       zr36060_write(ptr, ZR060_SWR_HEND_LO, (reg >> 0) & 0xff);
+
+       size = ptr->width * ptr->height;
+       /* Target compressed field size in bits: */
+       size = size * 16;       /* uncompressed size in bits */
+       /* (Ronald) by default, quality = 100 is a compression
+        * ratio 1:2. Setting low_bitrate (insmod option) sets
+        * it to 1:4 (instead of 1:2, zr36060 max) as limit because the
+        * buz can't handle more at decimation=1... Use low_bitrate if
+        * you have a Buz, unless you know what you're doing */
+       size = size * cap->quality / (low_bitrate ? 400 : 200);
+       /* Lower limit (arbitrary, 1 KB) */
+       if (size < 8192)
+               size = 8192;
+       /* Upper limit: 7/8 of the code buffers */
+       if (size > ptr->total_code_vol * 7)
+               size = ptr->total_code_vol * 7;
+
+       ptr->real_code_vol = size >> 3; /* in bytes */
+
+       /* the MBCVR is the *maximum* block volume, according to the
+        * JPEG ISO specs, this shouldn't be used, since that allows
+        * for the best encoding quality. So set it to it's max value */
+       reg = ptr->max_block_vol;
+       zr36060_write(ptr, ZR060_MBCVR, reg);
+
+       return 0;
+}
+
+/* additional control functions */
+static int
+zr36060_control (struct videocodec *codec,
+                int                type,
+                int                size,
+                void              *data)
+{
+       struct zr36060 *ptr = (struct zr36060 *) codec->data;
+       int *ival = (int *) data;
+
+       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
+               size);
+
+       switch (type) {
+       case CODEC_G_STATUS:    /* get last status */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               zr36060_read_status(ptr);
+               *ival = ptr->status;
+               break;
+
+       case CODEC_G_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = CODEC_MODE_BJPG;
+               break;
+
+       case CODEC_S_CODEC_MODE:
+               if (size != sizeof(int))
+                       return -EFAULT;
+               if (*ival != CODEC_MODE_BJPG)
+                       return -EINVAL;
+               /* not needed, do nothing */
+               return 0;
+
+       case CODEC_G_VFE:
+       case CODEC_S_VFE:
+               /* not needed, do nothing */
+               return 0;
+
+       case CODEC_S_MMAP:
+               /* not available, give an error */
+               return -ENXIO;
+
+       case CODEC_G_JPEG_TDS_BYTE:     /* get target volume in byte */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = ptr->total_code_vol;
+               break;
+
+       case CODEC_S_JPEG_TDS_BYTE:     /* get target volume in byte */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               ptr->total_code_vol = *ival;
+               ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
+               break;
+
+       case CODEC_G_JPEG_SCALE:        /* get scaling factor */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               *ival = zr36060_read_scalefactor(ptr);
+               break;
+
+       case CODEC_S_JPEG_SCALE:        /* set scaling factor */
+               if (size != sizeof(int))
+                       return -EFAULT;
+               ptr->scalefact = *ival;
+               break;
+
+       case CODEC_G_JPEG_APP_DATA: {   /* get appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               *app = ptr->app;
+               break;
+       }
+
+       case CODEC_S_JPEG_APP_DATA: {   /* set appn marker data */
+               struct jpeg_app_marker *app = data;
+
+               if (size != sizeof(struct jpeg_app_marker))
+                       return -EFAULT;
+
+               ptr->app = *app;
+               break;
+       }
+
+       case CODEC_G_JPEG_COM_DATA: {   /* get comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               *com = ptr->com;
+               break;
+       }
+
+       case CODEC_S_JPEG_COM_DATA: {   /* set comment marker data */
+               struct jpeg_com_marker *com = data;
+
+               if (size != sizeof(struct jpeg_com_marker))
+                       return -EFAULT;
+
+               ptr->com = *com;
+               break;
+       }
+
+       default:
+               return -EINVAL;
+       }
+
+       return size;
+}
+
+/* =========================================================================
+   Exit and unregister function:
+
+   Deinitializes Zoran's JPEG processor
+   ========================================================================= */
+
+static int
+zr36060_unset (struct videocodec *codec)
+{
+       struct zr36060 *ptr = codec->data;
+
+       if (ptr) {
+               /* do wee need some codec deinit here, too ???? */
+
+               dprintk(1, "%s: finished codec #%d\n", ptr->name,
+                       ptr->num);
+               kfree(ptr);
+               codec->data = NULL;
+
+               zr36060_codecs--;
+               return 0;
+       }
+
+       return -EFAULT;
+}
+
+/* =========================================================================
+   Setup and registry function:
+
+   Initializes Zoran's JPEG processor
+
+   Also sets pixel size, average code size, mode (compr./decompr.)
+   (the given size is determined by the processor with the video interface)
+   ========================================================================= */
+
+static int
+zr36060_setup (struct videocodec *codec)
+{
+       struct zr36060 *ptr;
+       int res;
+
+       dprintk(2, "zr36060: initializing MJPEG subsystem #%d.\n",
+               zr36060_codecs);
+
+       if (zr36060_codecs == MAX_CODECS) {
+               dprintk(1,
+                       KERN_ERR "zr36060: Can't attach more codecs!\n");
+               return -ENOSPC;
+       }
+       //mem structure init
+       codec->data = ptr = kzalloc(sizeof(struct zr36060), GFP_KERNEL);
+       if (NULL == ptr) {
+               dprintk(1, KERN_ERR "zr36060: Can't get enough memory!\n");
+               return -ENOMEM;
+       }
+
+       snprintf(ptr->name, sizeof(ptr->name), "zr36060[%d]",
+                zr36060_codecs);
+       ptr->num = zr36060_codecs++;
+       ptr->codec = codec;
+
+       //testing
+       res = zr36060_basic_test(ptr);
+       if (res < 0) {
+               zr36060_unset(codec);
+               return res;
+       }
+       //final setup
+       memcpy(ptr->h_samp_ratio, zr36060_decimation_h, 8);
+       memcpy(ptr->v_samp_ratio, zr36060_decimation_v, 8);
+
+       ptr->bitrate_ctrl = 0;  /* 0 or 1 - fixed file size flag
+                                * (what is the difference?) */
+       ptr->mode = CODEC_DO_COMPRESSION;
+       ptr->width = 384;
+       ptr->height = 288;
+       ptr->total_code_vol = 16000;    /* CHECKME */
+       ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
+       ptr->max_block_vol = 240;       /* CHECKME, was 120 is 240 */
+       ptr->scalefact = 0x100;
+       ptr->dri = 1;           /* CHECKME, was 8 is 1 */
+
+       /* by default, no COM or APP markers - app should set those */
+       ptr->com.len = 0;
+       ptr->app.appn = 0;
+       ptr->app.len = 0;
+
+       zr36060_init(ptr);
+
+       dprintk(1, KERN_INFO "%s: codec attached and running\n",
+               ptr->name);
+
+       return 0;
+}
+
+static const struct videocodec zr36060_codec = {
+       .owner = THIS_MODULE,
+       .name = "zr36060",
+       .magic = 0L,            // magic not used
+       .flags =
+           CODEC_FLAG_JPEG | CODEC_FLAG_HARDWARE | CODEC_FLAG_ENCODER |
+           CODEC_FLAG_DECODER | CODEC_FLAG_VFE,
+       .type = CODEC_TYPE_ZR36060,
+       .setup = zr36060_setup, // functionality
+       .unset = zr36060_unset,
+       .set_mode = zr36060_set_mode,
+       .set_video = zr36060_set_video,
+       .control = zr36060_control,
+       // others are not used
+};
+
+/* =========================================================================
+   HOOK IN DRIVER AS KERNEL MODULE
+   ========================================================================= */
+
+static int __init
+zr36060_init_module (void)
+{
+       //dprintk(1, "zr36060 driver %s\n",ZR060_VERSION);
+       zr36060_codecs = 0;
+       return videocodec_register(&zr36060_codec);
+}
+
+static void __exit
+zr36060_cleanup_module (void)
+{
+       if (zr36060_codecs) {
+               dprintk(1,
+                       "zr36060: something's wrong - %d codecs left somehow.\n",
+                       zr36060_codecs);
+       }
+
+       /* however, we can't just stay alive */
+       videocodec_unregister(&zr36060_codec);
+}
+
+module_init(zr36060_init_module);
+module_exit(zr36060_cleanup_module);
+
+MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@skynet.be>");
+MODULE_DESCRIPTION("Driver module for ZR36060 jpeg processors "
+                  ZR060_VERSION);
+MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zoran/zr36060.h b/drivers/media/video/zoran/zr36060.h
new file mode 100644 (file)
index 0000000..914ffa4
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Zoran ZR36060 basic configuration functions - header file
+ *
+ * Copyright (C) 2002 Laurent Pinchart <laurent.pinchart@skynet.be>
+ *
+ * $Id: zr36060.h,v 1.1.1.1.2.3 2003/01/14 21:18:47 rbultje Exp $
+ *
+ * ------------------------------------------------------------------------
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *
+ * ------------------------------------------------------------------------
+ */
+
+#ifndef ZR36060_H
+#define ZR36060_H
+
+#include "videocodec.h"
+
+/* data stored for each zoran jpeg codec chip */
+struct zr36060 {
+       char name[32];
+       int num;
+       /* io datastructure */
+       struct videocodec *codec;
+       // last coder status
+       __u8 status;
+       // actual coder setup
+       int mode;
+
+       __u16 width;
+       __u16 height;
+
+       __u16 bitrate_ctrl;
+
+       __u32 total_code_vol;
+       __u32 real_code_vol;
+       __u16 max_block_vol;
+
+       __u8 h_samp_ratio[8];
+       __u8 v_samp_ratio[8];
+       __u16 scalefact;
+       __u16 dri;
+
+       /* app/com marker data */
+       struct jpeg_app_marker app;
+       struct jpeg_com_marker com;
+};
+
+/* ZR36060 register addresses */
+#define ZR060_LOAD                     0x000
+#define ZR060_CFSR                     0x001
+#define ZR060_CIR                      0x002
+#define ZR060_CMR                      0x003
+#define ZR060_MBZ                      0x004
+#define ZR060_MBCVR                    0x005
+#define ZR060_MER                      0x006
+#define ZR060_IMR                      0x007
+#define ZR060_ISR                      0x008
+#define ZR060_TCV_NET_HI               0x009
+#define ZR060_TCV_NET_MH               0x00a
+#define ZR060_TCV_NET_ML               0x00b
+#define ZR060_TCV_NET_LO               0x00c
+#define ZR060_TCV_DATA_HI              0x00d
+#define ZR060_TCV_DATA_MH              0x00e
+#define ZR060_TCV_DATA_ML              0x00f
+#define ZR060_TCV_DATA_LO              0x010
+#define ZR060_SF_HI                    0x011
+#define ZR060_SF_LO                    0x012
+#define ZR060_AF_HI                    0x013
+#define ZR060_AF_M                     0x014
+#define ZR060_AF_LO                    0x015
+#define ZR060_ACV_HI                   0x016
+#define ZR060_ACV_MH                   0x017
+#define ZR060_ACV_ML                   0x018
+#define ZR060_ACV_LO                   0x019
+#define ZR060_ACT_HI                   0x01a
+#define ZR060_ACT_MH                   0x01b
+#define ZR060_ACT_ML                   0x01c
+#define ZR060_ACT_LO                   0x01d
+#define ZR060_ACV_TRUN_HI              0x01e
+#define ZR060_ACV_TRUN_MH              0x01f
+#define ZR060_ACV_TRUN_ML              0x020
+#define ZR060_ACV_TRUN_LO              0x021
+#define ZR060_IDR_DEV                  0x022
+#define ZR060_IDR_REV                  0x023
+#define ZR060_TCR_HI                   0x024
+#define ZR060_TCR_LO                   0x025
+#define ZR060_VCR                      0x030
+#define ZR060_VPR                      0x031
+#define ZR060_SR                       0x032
+#define ZR060_BCR_Y                    0x033
+#define ZR060_BCR_U                    0x034
+#define ZR060_BCR_V                    0x035
+#define ZR060_SGR_VTOTAL_HI            0x036
+#define ZR060_SGR_VTOTAL_LO            0x037
+#define ZR060_SGR_HTOTAL_HI            0x038
+#define ZR060_SGR_HTOTAL_LO            0x039
+#define ZR060_SGR_VSYNC                        0x03a
+#define ZR060_SGR_HSYNC                        0x03b
+#define ZR060_SGR_BVSTART              0x03c
+#define ZR060_SGR_BHSTART              0x03d
+#define ZR060_SGR_BVEND_HI             0x03e
+#define ZR060_SGR_BVEND_LO             0x03f
+#define ZR060_SGR_BHEND_HI             0x040
+#define ZR060_SGR_BHEND_LO             0x041
+#define ZR060_AAR_VSTART_HI            0x042
+#define ZR060_AAR_VSTART_LO            0x043
+#define ZR060_AAR_VEND_HI              0x044
+#define ZR060_AAR_VEND_LO              0x045
+#define ZR060_AAR_HSTART_HI            0x046
+#define ZR060_AAR_HSTART_LO            0x047
+#define ZR060_AAR_HEND_HI              0x048
+#define ZR060_AAR_HEND_LO              0x049
+#define ZR060_SWR_VSTART_HI            0x04a
+#define ZR060_SWR_VSTART_LO            0x04b
+#define ZR060_SWR_VEND_HI              0x04c
+#define ZR060_SWR_VEND_LO              0x04d
+#define ZR060_SWR_HSTART_HI            0x04e
+#define ZR060_SWR_HSTART_LO            0x04f
+#define ZR060_SWR_HEND_HI              0x050
+#define ZR060_SWR_HEND_LO              0x051
+
+#define ZR060_SOF_IDX                  0x060
+#define ZR060_SOS_IDX                  0x07a
+#define ZR060_DRI_IDX                  0x0c0
+#define ZR060_DQT_IDX                  0x0cc
+#define ZR060_DHT_IDX                  0x1d4
+#define ZR060_APP_IDX                  0x380
+#define ZR060_COM_IDX                  0x3c0
+
+/* ZR36060 LOAD register bits */
+
+#define ZR060_LOAD_Load                        (1 << 7)
+#define ZR060_LOAD_SyncRst             (1 << 0)
+
+/* ZR36060 Code FIFO Status register bits */
+
+#define ZR060_CFSR_Busy                        (1 << 7)
+#define ZR060_CFSR_CBusy               (1 << 2)
+#define ZR060_CFSR_CFIFO               (3 << 0)
+
+/* ZR36060 Code Interface register */
+
+#define ZR060_CIR_Code16               (1 << 7)
+#define ZR060_CIR_Endian               (1 << 6)
+#define ZR060_CIR_CFIS                 (1 << 2)
+#define ZR060_CIR_CodeMstr             (1 << 0)
+
+/* ZR36060 Codec Mode register */
+
+#define ZR060_CMR_Comp                 (1 << 7)
+#define ZR060_CMR_ATP                  (1 << 6)
+#define ZR060_CMR_Pass2                        (1 << 5)
+#define ZR060_CMR_TLM                  (1 << 4)
+#define ZR060_CMR_BRB                  (1 << 2)
+#define ZR060_CMR_FSF                  (1 << 1)
+
+/* ZR36060 Markers Enable register */
+
+#define ZR060_MER_App                  (1 << 7)
+#define ZR060_MER_Com                  (1 << 6)
+#define ZR060_MER_DRI                  (1 << 5)
+#define ZR060_MER_DQT                  (1 << 4)
+#define ZR060_MER_DHT                  (1 << 3)
+
+/* ZR36060 Interrupt Mask register */
+
+#define ZR060_IMR_EOAV                 (1 << 3)
+#define ZR060_IMR_EOI                  (1 << 2)
+#define ZR060_IMR_End                  (1 << 1)
+#define ZR060_IMR_DataErr              (1 << 0)
+
+/* ZR36060 Interrupt Status register */
+
+#define ZR060_ISR_ProCnt               (3 << 6)
+#define ZR060_ISR_EOAV                 (1 << 3)
+#define ZR060_ISR_EOI                  (1 << 2)
+#define ZR060_ISR_End                  (1 << 1)
+#define ZR060_ISR_DataErr              (1 << 0)
+
+/* ZR36060 Video Control register */
+
+#define ZR060_VCR_Video8               (1 << 7)
+#define ZR060_VCR_Range                        (1 << 6)
+#define ZR060_VCR_FIDet                        (1 << 3)
+#define ZR060_VCR_FIVedge              (1 << 2)
+#define ZR060_VCR_FIExt                        (1 << 1)
+#define ZR060_VCR_SyncMstr             (1 << 0)
+
+/* ZR36060 Video Polarity register */
+
+#define ZR060_VPR_VCLKPol              (1 << 7)
+#define ZR060_VPR_PValPol              (1 << 6)
+#define ZR060_VPR_PoePol               (1 << 5)
+#define ZR060_VPR_SImgPol              (1 << 4)
+#define ZR060_VPR_BLPol                        (1 << 3)
+#define ZR060_VPR_FIPol                        (1 << 2)
+#define ZR060_VPR_HSPol                        (1 << 1)
+#define ZR060_VPR_VSPol                        (1 << 0)
+
+/* ZR36060 Scaling register */
+
+#define ZR060_SR_VScale                        (1 << 2)
+#define ZR060_SR_HScale2               (1 << 0)
+#define ZR060_SR_HScale4               (2 << 0)
+
+#endif                         /*fndef ZR36060_H */
diff --git a/drivers/media/video/zoran_card.c b/drivers/media/video/zoran_card.c
deleted file mode 100644 (file)
index 3282be7..0000000
+++ /dev/null
@@ -1,1670 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles card-specific data and detection
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/delay.h>
-
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/vmalloc.h>
-
-#include <linux/proc_fs.h>
-#include <linux/i2c.h>
-#include <linux/i2c-algo-bit.h>
-#include <linux/videodev.h>
-#include <media/v4l2-common.h>
-#include <linux/spinlock.h>
-#include <linux/sem.h>
-#include <linux/kmod.h>
-#include <linux/wait.h>
-
-#include <linux/pci.h>
-#include <linux/interrupt.h>
-#include <linux/video_decoder.h>
-#include <linux/video_encoder.h>
-#include <linux/mutex.h>
-
-#include <asm/io.h>
-
-#include "videocodec.h"
-#include "zoran.h"
-#include "zoran_card.h"
-#include "zoran_device.h"
-#include "zoran_procfs.h"
-
-extern const struct zoran_format zoran_formats[];
-
-static int card[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(card, int, NULL, 0444);
-MODULE_PARM_DESC(card, "The type of card");
-
-static int encoder[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(encoder, int, NULL, 0444);
-MODULE_PARM_DESC(encoder, "i2c TV encoder");
-
-static int decoder[BUZ_MAX] = { -1, -1, -1, -1 };
-module_param_array(decoder, int, NULL, 0444);
-MODULE_PARM_DESC(decoder, "i2c TV decoder");
-
-/*
-   The video mem address of the video card.
-   The driver has a little database for some videocards
-   to determine it from there. If your video card is not in there
-   you have either to give it to the driver as a parameter
-   or set in in a VIDIOCSFBUF ioctl
- */
-
-static unsigned long vidmem;   /* default = 0 - Video memory base address */
-module_param(vidmem, ulong, 0444);
-MODULE_PARM_DESC(vidmem, "Default video memory base address");
-
-/*
-   Default input and video norm at startup of the driver.
-*/
-
-static unsigned int default_input;     /* default 0 = Composite, 1 = S-Video */
-module_param(default_input, uint, 0444);
-MODULE_PARM_DESC(default_input,
-                "Default input (0=Composite, 1=S-Video, 2=Internal)");
-
-static int default_mux = 1;    /* 6 Eyes input selection */
-module_param(default_mux, int, 0644);
-MODULE_PARM_DESC(default_mux,
-                "Default 6 Eyes mux setting (Input selection)");
-
-static int default_norm;       /* default 0 = PAL, 1 = NTSC 2 = SECAM */
-module_param(default_norm, int, 0444);
-MODULE_PARM_DESC(default_norm, "Default norm (0=PAL, 1=NTSC, 2=SECAM)");
-
-/* /dev/videoN, -1 for autodetect */
-static int video_nr[BUZ_MAX] = {-1, -1, -1, -1};
-module_param_array(video_nr, int, NULL, 0444);
-MODULE_PARM_DESC(video_nr, "video device number (-1=Auto)");
-
-/*
-   Number and size of grab buffers for Video 4 Linux
-   The vast majority of applications should not need more than 2,
-   the very popular BTTV driver actually does ONLY have 2.
-   Time sensitive applications might need more, the maximum
-   is VIDEO_MAX_FRAME (defined in <linux/videodev.h>).
-
-   The size is set so that the maximum possible request
-   can be satisfied. Decrease  it, if bigphys_area alloc'd
-   memory is low. If you don't have the bigphys_area patch,
-   set it to 128 KB. Will you allow only to grab small
-   images with V4L, but that's better than nothing.
-
-   v4l_bufsize has to be given in KB !
-
-*/
-
-int v4l_nbufs = 2;
-int v4l_bufsize = 128;         /* Everybody should be able to work with this setting */
-module_param(v4l_nbufs, int, 0644);
-MODULE_PARM_DESC(v4l_nbufs, "Maximum number of V4L buffers to use");
-module_param(v4l_bufsize, int, 0644);
-MODULE_PARM_DESC(v4l_bufsize, "Maximum size per V4L buffer (in kB)");
-
-int jpg_nbufs = 32;
-int jpg_bufsize = 512;         /* max size for 100% quality full-PAL frame */
-module_param(jpg_nbufs, int, 0644);
-MODULE_PARM_DESC(jpg_nbufs, "Maximum number of JPG buffers to use");
-module_param(jpg_bufsize, int, 0644);
-MODULE_PARM_DESC(jpg_bufsize, "Maximum size per JPG buffer (in kB)");
-
-int pass_through = 0;          /* 1=Pass through TV signal when device is not used */
-                               /* 0=Show color bar when device is not used (LML33: only if lml33dpath=1) */
-module_param(pass_through, int, 0644);
-MODULE_PARM_DESC(pass_through,
-                "Pass TV signal through to TV-out when idling");
-
-int zr36067_debug = 1;
-module_param_named(debug, zr36067_debug, int, 0644);
-MODULE_PARM_DESC(debug, "Debug level (0-5)");
-
-MODULE_DESCRIPTION("Zoran-36057/36067 JPEG codec driver");
-MODULE_AUTHOR("Serguei Miridonov");
-MODULE_LICENSE("GPL");
-
-static struct pci_device_id zr36067_pci_tbl[] = {
-       {PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057,
-        PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0},
-       {0}
-};
-MODULE_DEVICE_TABLE(pci, zr36067_pci_tbl);
-
-int zoran_num;                 /* number of Buzs in use */
-struct zoran *zoran[BUZ_MAX];
-
-/* videocodec bus functions ZR36060 */
-static u32
-zr36060_read (struct videocodec *codec,
-             u16                reg)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-       __u32 data;
-
-       if (post_office_wait(zr)
-           || post_office_write(zr, 0, 1, reg >> 8)
-           || post_office_write(zr, 0, 2, reg & 0xff)) {
-               return -1;
-       }
-
-       data = post_office_read(zr, 0, 3) & 0xff;
-       return data;
-}
-
-static void
-zr36060_write (struct videocodec *codec,
-              u16                reg,
-              u32                val)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-
-       if (post_office_wait(zr)
-           || post_office_write(zr, 0, 1, reg >> 8)
-           || post_office_write(zr, 0, 2, reg & 0xff)) {
-               return;
-       }
-
-       post_office_write(zr, 0, 3, val & 0xff);
-}
-
-/* videocodec bus functions ZR36050 */
-static u32
-zr36050_read (struct videocodec *codec,
-             u16                reg)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-       __u32 data;
-
-       if (post_office_wait(zr)
-           || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
-               return -1;
-       }
-
-       data = post_office_read(zr, 0, reg & 0x03) & 0xff;      // reg. LOWBYTES + read
-       return data;
-}
-
-static void
-zr36050_write (struct videocodec *codec,
-              u16                reg,
-              u32                val)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-
-       if (post_office_wait(zr)
-           || post_office_write(zr, 1, 0, reg >> 2)) { // reg. HIGHBYTES
-               return;
-       }
-
-       post_office_write(zr, 0, reg & 0x03, val & 0xff);       // reg. LOWBYTES + wr. data
-}
-
-/* videocodec bus functions ZR36016 */
-static u32
-zr36016_read (struct videocodec *codec,
-             u16                reg)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-       __u32 data;
-
-       if (post_office_wait(zr)) {
-               return -1;
-       }
-
-       data = post_office_read(zr, 2, reg & 0x03) & 0xff;      // read
-       return data;
-}
-
-/* hack for in zoran_device.c */
-void
-zr36016_write (struct videocodec *codec,
-              u16                reg,
-              u32                val)
-{
-       struct zoran *zr = (struct zoran *) codec->master_data->data;
-
-       if (post_office_wait(zr)) {
-               return;
-       }
-
-       post_office_write(zr, 2, reg & 0x03, val & 0x0ff);      // wr. data
-}
-
-/*
- * Board specific information
- */
-
-static void
-dc10_init (struct zoran *zr)
-{
-       dprintk(3, KERN_DEBUG "%s: dc10_init()\n", ZR_DEVNAME(zr));
-
-       /* Pixel clock selection */
-       GPIO(zr, 4, 0);
-       GPIO(zr, 5, 1);
-       /* Enable the video bus sync signals */
-       GPIO(zr, 7, 0);
-}
-
-static void
-dc10plus_init (struct zoran *zr)
-{
-       dprintk(3, KERN_DEBUG "%s: dc10plus_init()\n", ZR_DEVNAME(zr));
-}
-
-static void
-buz_init (struct zoran *zr)
-{
-       dprintk(3, KERN_DEBUG "%s: buz_init()\n", ZR_DEVNAME(zr));
-
-       /* some stuff from Iomega */
-       pci_write_config_dword(zr->pci_dev, 0xfc, 0x90680f15);
-       pci_write_config_dword(zr->pci_dev, 0x0c, 0x00012020);
-       pci_write_config_dword(zr->pci_dev, 0xe8, 0xc0200000);
-}
-
-static void
-lml33_init (struct zoran *zr)
-{
-       dprintk(3, KERN_DEBUG "%s: lml33_init()\n", ZR_DEVNAME(zr));
-
-       GPIO(zr, 2, 1);         // Set Composite input/output
-}
-
-static void
-avs6eyes_init (struct zoran *zr)
-{
-       // AverMedia 6-Eyes original driver by Christer Weinigel
-
-       // Lifted straight from Christer's old driver and
-       // modified slightly by Martin Samuelsson.
-
-       int mux = default_mux; /* 1 = BT866, 7 = VID1 */
-
-       GPIO(zr, 4, 1); /* Bt866 SLEEP on */
-       udelay(2);
-
-       GPIO(zr, 0, 1); /* ZR36060 /RESET on */
-       GPIO(zr, 1, 0); /* ZR36060 /SLEEP on */
-       GPIO(zr, 2, mux & 1);   /* MUX S0 */
-       GPIO(zr, 3, 0); /* /FRAME on */
-       GPIO(zr, 4, 0); /* Bt866 SLEEP off */
-       GPIO(zr, 5, mux & 2);   /* MUX S1 */
-       GPIO(zr, 6, 0); /* ? */
-       GPIO(zr, 7, mux & 4);   /* MUX S2 */
-
-}
-
-static char *
-i2cid_to_modulename (u16 i2c_id)
-{
-       char *name = NULL;
-
-       switch (i2c_id) {
-       case I2C_DRIVERID_SAA7110:
-               name = "saa7110";
-               break;
-       case I2C_DRIVERID_SAA7111A:
-               name = "saa7111";
-               break;
-       case I2C_DRIVERID_SAA7114:
-               name = "saa7114";
-               break;
-       case I2C_DRIVERID_SAA7185B:
-               name = "saa7185";
-               break;
-       case I2C_DRIVERID_ADV7170:
-               name = "adv7170";
-               break;
-       case I2C_DRIVERID_ADV7175:
-               name = "adv7175";
-               break;
-       case I2C_DRIVERID_BT819:
-               name = "bt819";
-               break;
-       case I2C_DRIVERID_BT856:
-               name = "bt856";
-               break;
-       case I2C_DRIVERID_BT866:
-               name = "bt866";
-               break;
-       case I2C_DRIVERID_VPX3220:
-               name = "vpx3220";
-               break;
-       case I2C_DRIVERID_KS0127:
-               name = "ks0127";
-               break;
-       }
-
-       return name;
-}
-
-static char *
-codecid_to_modulename (u16 codecid)
-{
-       char *name = NULL;
-
-       switch (codecid) {
-       case CODEC_TYPE_ZR36060:
-               name = "zr36060";
-               break;
-       case CODEC_TYPE_ZR36050:
-               name = "zr36050";
-               break;
-       case CODEC_TYPE_ZR36016:
-               name = "zr36016";
-               break;
-       }
-
-       return name;
-}
-
-// struct tvnorm {
-//      u16 Wt, Wa, HStart, HSyncStart, Ht, Ha, VStart;
-// };
-
-static struct tvnorm f50sqpixel = { 944, 768, 83, 880, 625, 576, 16 };
-static struct tvnorm f60sqpixel = { 780, 640, 51, 716, 525, 480, 12 };
-static struct tvnorm f50ccir601 = { 864, 720, 75, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601 = { 858, 720, 57, 788, 525, 480, 16 };
-
-static struct tvnorm f50ccir601_lml33 = { 864, 720, 75+34, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601_lml33 = { 858, 720, 57+34, 788, 525, 480, 16 };
-
-/* The DC10 (57/16/50) uses VActive as HSync, so HStart must be 0 */
-static struct tvnorm f50sqpixel_dc10 = { 944, 768, 0, 880, 625, 576, 0 };
-static struct tvnorm f60sqpixel_dc10 = { 780, 640, 0, 716, 525, 480, 12 };
-
-/* FIXME: I cannot swap U and V in saa7114, so i do one
- * pixel left shift in zoran (75 -> 74)
- * (Maxim Yevtyushkin <max@linuxmedialabs.com>) */
-static struct tvnorm f50ccir601_lm33r10 = { 864, 720, 74+54, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601_lm33r10 = { 858, 720, 56+54, 788, 525, 480, 16 };
-
-/* FIXME: The ks0127 seem incapable of swapping U and V, too, which is why I
- * copy Maxim's left shift hack for the 6 Eyes.
- *
- * Christer's driver used the unshifted norms, though...
- * /Sam  */
-static struct tvnorm f50ccir601_avs6eyes = { 864, 720, 74, 804, 625, 576, 18 };
-static struct tvnorm f60ccir601_avs6eyes = { 858, 720, 56, 788, 525, 480, 16 };
-
-static struct card_info zoran_cards[NUM_CARDS] __devinitdata = {
-       {
-               .type = DC10_old,
-               .name = "DC10(old)",
-               .i2c_decoder = I2C_DRIVERID_VPX3220,
-               .video_codec = CODEC_TYPE_ZR36050,
-               .video_vfe = CODEC_TYPE_ZR36016,
-
-               .inputs = 3,
-               .input = {
-                       { 1, "Composite" },
-                       { 2, "S-Video" },
-                       { 0, "Internal/comp" }
-               },
-               .norms = 3,
-               .tvn = {
-                       &f50sqpixel_dc10,
-                       &f60sqpixel_dc10,
-                       &f50sqpixel_dc10
-               },
-               .jpeg_int = 0,
-               .vsync_int = ZR36057_ISR_GIRQ1,
-               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
-               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
-               .gpcs = { -1, 0 },
-               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gws_not_connected = 0,
-               .input_mux = 0,
-               .init = &dc10_init,
-       }, {
-               .type = DC10_new,
-               .name = "DC10(new)",
-               .i2c_decoder = I2C_DRIVERID_SAA7110,
-               .i2c_encoder = I2C_DRIVERID_ADV7175,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 3,
-               .input = {
-                               { 0, "Composite" },
-                               { 7, "S-Video" },
-                               { 5, "Internal/comp" }
-                       },
-               .norms = 3,
-               .tvn = {
-                               &f50sqpixel,
-                               &f60sqpixel,
-                               &f50sqpixel},
-               .jpeg_int = ZR36057_ISR_GIRQ0,
-               .vsync_int = ZR36057_ISR_GIRQ1,
-               .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
-               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gpcs = { -1, 1},
-               .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
-               .gws_not_connected = 0,
-               .input_mux = 0,
-               .init = &dc10plus_init,
-       }, {
-               .type = DC10plus,
-               .name = "DC10plus",
-               .vendor_id = PCI_VENDOR_ID_MIRO,
-               .device_id = PCI_DEVICE_ID_MIRO_DC10PLUS,
-               .i2c_decoder = I2C_DRIVERID_SAA7110,
-               .i2c_encoder = I2C_DRIVERID_ADV7175,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 3,
-               .input = {
-                       { 0, "Composite" },
-                       { 7, "S-Video" },
-                       { 5, "Internal/comp" }
-               },
-               .norms = 3,
-               .tvn = {
-                       &f50sqpixel,
-                       &f60sqpixel,
-                       &f50sqpixel
-               },
-               .jpeg_int = ZR36057_ISR_GIRQ0,
-               .vsync_int = ZR36057_ISR_GIRQ1,
-               .gpio = { 3, 0, 6, 1, 2, -1, 4, 5 },
-               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gpcs = { -1, 1 },
-               .vfe_pol = { 1, 1, 1, 1, 0, 0, 0, 0 },
-               .gws_not_connected = 0,
-               .input_mux = 0,
-               .init = &dc10plus_init,
-       }, {
-               .type = DC30,
-               .name = "DC30",
-               .i2c_decoder = I2C_DRIVERID_VPX3220,
-               .i2c_encoder = I2C_DRIVERID_ADV7175,
-               .video_codec = CODEC_TYPE_ZR36050,
-               .video_vfe = CODEC_TYPE_ZR36016,
-
-               .inputs = 3,
-               .input = {
-                       { 1, "Composite" },
-                       { 2, "S-Video" },
-                       { 0, "Internal/comp" }
-               },
-               .norms = 3,
-               .tvn = {
-                       &f50sqpixel_dc10,
-                       &f60sqpixel_dc10,
-                       &f50sqpixel_dc10
-               },
-               .jpeg_int = 0,
-               .vsync_int = ZR36057_ISR_GIRQ1,
-               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
-               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
-               .gpcs = { -1, 0 },
-               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gws_not_connected = 0,
-               .input_mux = 0,
-               .init = &dc10_init,
-       }, {
-               .type = DC30plus,
-               .name = "DC30plus",
-               .vendor_id = PCI_VENDOR_ID_MIRO,
-               .device_id = PCI_DEVICE_ID_MIRO_DC30PLUS,
-               .i2c_decoder = I2C_DRIVERID_VPX3220,
-               .i2c_encoder = I2C_DRIVERID_ADV7175,
-               .video_codec = CODEC_TYPE_ZR36050,
-               .video_vfe = CODEC_TYPE_ZR36016,
-
-               .inputs = 3,
-               .input = {
-                       { 1, "Composite" },
-                       { 2, "S-Video" },
-                       { 0, "Internal/comp" }
-               },
-               .norms = 3,
-               .tvn = {
-                       &f50sqpixel_dc10,
-                       &f60sqpixel_dc10,
-                       &f50sqpixel_dc10
-               },
-               .jpeg_int = 0,
-               .vsync_int = ZR36057_ISR_GIRQ1,
-               .gpio = { 2, 1, -1, 3, 7, 0, 4, 5 },
-               .gpio_pol = { 0, 0, 0, 1, 0, 0, 0, 0 },
-               .gpcs = { -1, 0 },
-               .vfe_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gws_not_connected = 0,
-               .input_mux = 0,
-               .init = &dc10_init,
-       }, {
-               .type = LML33,
-               .name = "LML33",
-               .i2c_decoder = I2C_DRIVERID_BT819,
-               .i2c_encoder = I2C_DRIVERID_BT856,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 2,
-               .input = {
-                       { 0, "Composite" },
-                       { 7, "S-Video" }
-               },
-               .norms = 2,
-               .tvn = {
-                       &f50ccir601_lml33,
-                       &f60ccir601_lml33,
-                       NULL
-               },
-               .jpeg_int = ZR36057_ISR_GIRQ1,
-               .vsync_int = ZR36057_ISR_GIRQ0,
-               .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
-               .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
-               .gpcs = { 3, 1 },
-               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
-               .gws_not_connected = 1,
-               .input_mux = 0,
-               .init = &lml33_init,
-       }, {
-               .type = LML33R10,
-               .name = "LML33R10",
-               .vendor_id = PCI_VENDOR_ID_ELECTRONICDESIGNGMBH,
-               .device_id = PCI_DEVICE_ID_LML_33R10,
-               .i2c_decoder = I2C_DRIVERID_SAA7114,
-               .i2c_encoder = I2C_DRIVERID_ADV7170,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 2,
-               .input = {
-                       { 0, "Composite" },
-                       { 7, "S-Video" }
-               },
-               .norms = 2,
-               .tvn = {
-                       &f50ccir601_lm33r10,
-                       &f60ccir601_lm33r10,
-                       NULL
-               },
-               .jpeg_int = ZR36057_ISR_GIRQ1,
-               .vsync_int = ZR36057_ISR_GIRQ0,
-               .gpio = { 1, -1, 3, 5, 7, -1, -1, -1 },
-               .gpio_pol = { 0, 0, 0, 0, 1, 0, 0, 0 },
-               .gpcs = { 3, 1 },
-               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
-               .gws_not_connected = 1,
-               .input_mux = 0,
-               .init = &lml33_init,
-       }, {
-               .type = BUZ,
-               .name = "Buz",
-               .vendor_id = PCI_VENDOR_ID_IOMEGA,
-               .device_id = PCI_DEVICE_ID_IOMEGA_BUZ,
-               .i2c_decoder = I2C_DRIVERID_SAA7111A,
-               .i2c_encoder = I2C_DRIVERID_SAA7185B,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 2,
-               .input = {
-                       { 3, "Composite" },
-                       { 7, "S-Video" }
-               },
-               .norms = 3,
-               .tvn = {
-                       &f50ccir601,
-                       &f60ccir601,
-                       &f50ccir601
-               },
-               .jpeg_int = ZR36057_ISR_GIRQ1,
-               .vsync_int = ZR36057_ISR_GIRQ0,
-               .gpio = { 1, -1, 3, -1, -1, -1, -1, -1 },
-               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 },
-               .gpcs = { 3, 1 },
-               .vfe_pol = { 1, 1, 0, 0, 0, 1, 0, 0 },
-               .gws_not_connected = 1,
-               .input_mux = 0,
-               .init = &buz_init,
-       }, {
-               .type = AVS6EYES,
-               .name = "6-Eyes",
-               /* AverMedia chose not to brand the 6-Eyes. Thus it
-                  can't be autodetected, and requires card=x. */
-               .vendor_id = -1,
-               .device_id = -1,
-               .i2c_decoder = I2C_DRIVERID_KS0127,
-               .i2c_encoder = I2C_DRIVERID_BT866,
-               .video_codec = CODEC_TYPE_ZR36060,
-
-               .inputs = 10,
-               .input = {
-                       { 0, "Composite 1" },
-                       { 1, "Composite 2" },
-                       { 2, "Composite 3" },
-                       { 4, "Composite 4" },
-                       { 5, "Composite 5" },
-                       { 6, "Composite 6" },
-                       { 8, "S-Video 1" },
-                       { 9, "S-Video 2" },
-                       {10, "S-Video 3" },
-                       {15, "YCbCr" }
-               },
-               .norms = 2,
-               .tvn = {
-                       &f50ccir601_avs6eyes,
-                       &f60ccir601_avs6eyes,
-                       NULL
-               },
-               .jpeg_int = ZR36057_ISR_GIRQ1,
-               .vsync_int = ZR36057_ISR_GIRQ0,
-               .gpio = { 1, 0, 3, -1, -1, -1, -1, -1 },// Validity unknown /Sam
-               .gpio_pol = { 0, 0, 0, 0, 0, 0, 0, 0 }, // Validity unknown /Sam
-               .gpcs = { 3, 1 },                       // Validity unknown /Sam
-               .vfe_pol = { 1, 0, 0, 0, 0, 1, 0, 0 },  // Validity unknown /Sam
-               .gws_not_connected = 1,
-               .input_mux = 1,
-               .init = &avs6eyes_init,
-       }
-
-};
-
-/*
- * I2C functions
- */
-/* software I2C functions */
-static int
-zoran_i2c_getsda (void *data)
-{
-       struct zoran *zr = (struct zoran *) data;
-
-       return (btread(ZR36057_I2CBR) >> 1) & 1;
-}
-
-static int
-zoran_i2c_getscl (void *data)
-{
-       struct zoran *zr = (struct zoran *) data;
-
-       return btread(ZR36057_I2CBR) & 1;
-}
-
-static void
-zoran_i2c_setsda (void *data,
-                 int   state)
-{
-       struct zoran *zr = (struct zoran *) data;
-
-       if (state)
-               zr->i2cbr |= 2;
-       else
-               zr->i2cbr &= ~2;
-       btwrite(zr->i2cbr, ZR36057_I2CBR);
-}
-
-static void
-zoran_i2c_setscl (void *data,
-                 int   state)
-{
-       struct zoran *zr = (struct zoran *) data;
-
-       if (state)
-               zr->i2cbr |= 1;
-       else
-               zr->i2cbr &= ~1;
-       btwrite(zr->i2cbr, ZR36057_I2CBR);
-}
-
-static int
-zoran_i2c_client_register (struct i2c_client *client)
-{
-       struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
-       int res = 0;
-
-       dprintk(2,
-               KERN_DEBUG "%s: i2c_client_register() - driver id = %d\n",
-               ZR_DEVNAME(zr), client->driver->id);
-
-       mutex_lock(&zr->resource_lock);
-
-       if (zr->user > 0) {
-               /* we're already busy, so we keep a reference to
-                * them... Could do a lot of stuff here, but this
-                * is easiest. (Did I ever mention I'm a lazy ass?)
-                */
-               res = -EBUSY;
-               goto clientreg_unlock_and_return;
-       }
-
-       if (client->driver->id == zr->card.i2c_decoder)
-               zr->decoder = client;
-       else if (client->driver->id == zr->card.i2c_encoder)
-               zr->encoder = client;
-       else {
-               res = -ENODEV;
-               goto clientreg_unlock_and_return;
-       }
-
-clientreg_unlock_and_return:
-       mutex_unlock(&zr->resource_lock);
-
-       return res;
-}
-
-static int
-zoran_i2c_client_unregister (struct i2c_client *client)
-{
-       struct zoran *zr = (struct zoran *) i2c_get_adapdata(client->adapter);
-       int res = 0;
-
-       dprintk(2, KERN_DEBUG "%s: i2c_client_unregister()\n", ZR_DEVNAME(zr));
-
-       mutex_lock(&zr->resource_lock);
-
-       if (zr->user > 0) {
-               res = -EBUSY;
-               goto clientunreg_unlock_and_return;
-       }
-
-       /* try to locate it */
-       if (client == zr->encoder) {
-               zr->encoder = NULL;
-       } else if (client == zr->decoder) {
-               zr->decoder = NULL;
-               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%d]", zr->id);
-       }
-clientunreg_unlock_and_return:
-       mutex_unlock(&zr->resource_lock);
-       return res;
-}
-
-static const struct i2c_algo_bit_data zoran_i2c_bit_data_template = {
-       .setsda = zoran_i2c_setsda,
-       .setscl = zoran_i2c_setscl,
-       .getsda = zoran_i2c_getsda,
-       .getscl = zoran_i2c_getscl,
-       .udelay = 10,
-       .timeout = 100,
-};
-
-static int
-zoran_register_i2c (struct zoran *zr)
-{
-       memcpy(&zr->i2c_algo, &zoran_i2c_bit_data_template,
-              sizeof(struct i2c_algo_bit_data));
-       zr->i2c_algo.data = zr;
-       zr->i2c_adapter.id = I2C_HW_B_ZR36067;
-       zr->i2c_adapter.client_register = zoran_i2c_client_register;
-       zr->i2c_adapter.client_unregister = zoran_i2c_client_unregister;
-       strlcpy(zr->i2c_adapter.name, ZR_DEVNAME(zr),
-               sizeof(zr->i2c_adapter.name));
-       i2c_set_adapdata(&zr->i2c_adapter, zr);
-       zr->i2c_adapter.algo_data = &zr->i2c_algo;
-       zr->i2c_adapter.dev.parent = &zr->pci_dev->dev;
-       return i2c_bit_add_bus(&zr->i2c_adapter);
-}
-
-static void
-zoran_unregister_i2c (struct zoran *zr)
-{
-       i2c_del_adapter(&zr->i2c_adapter);
-}
-
-/* Check a zoran_params struct for correctness, insert default params */
-
-int
-zoran_check_jpg_settings (struct zoran              *zr,
-                         struct zoran_jpg_settings *settings)
-{
-       int err = 0, err0 = 0;
-
-       dprintk(4,
-               KERN_DEBUG
-               "%s: check_jpg_settings() - dec: %d, Hdcm: %d, Vdcm: %d, Tdcm: %d\n",
-               ZR_DEVNAME(zr), settings->decimation, settings->HorDcm,
-               settings->VerDcm, settings->TmpDcm);
-       dprintk(4,
-               KERN_DEBUG
-               "%s: check_jpg_settings() - x: %d, y: %d, w: %d, y: %d\n",
-               ZR_DEVNAME(zr), settings->img_x, settings->img_y,
-               settings->img_width, settings->img_height);
-       /* Check decimation, set default values for decimation = 1, 2, 4 */
-       switch (settings->decimation) {
-       case 1:
-
-               settings->HorDcm = 1;
-               settings->VerDcm = 1;
-               settings->TmpDcm = 1;
-               settings->field_per_buff = 2;
-               settings->img_x = 0;
-               settings->img_y = 0;
-               settings->img_width = BUZ_MAX_WIDTH;
-               settings->img_height = BUZ_MAX_HEIGHT / 2;
-               break;
-       case 2:
-
-               settings->HorDcm = 2;
-               settings->VerDcm = 1;
-               settings->TmpDcm = 2;
-               settings->field_per_buff = 1;
-               settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
-               settings->img_y = 0;
-               settings->img_width =
-                   (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
-               settings->img_height = BUZ_MAX_HEIGHT / 2;
-               break;
-       case 4:
-
-               if (zr->card.type == DC10_new) {
-                       dprintk(1,
-                               KERN_DEBUG
-                               "%s: check_jpg_settings() - HDec by 4 is not supported on the DC10\n",
-                               ZR_DEVNAME(zr));
-                       err0++;
-                       break;
-               }
-
-               settings->HorDcm = 4;
-               settings->VerDcm = 2;
-               settings->TmpDcm = 2;
-               settings->field_per_buff = 1;
-               settings->img_x = (BUZ_MAX_WIDTH == 720) ? 8 : 0;
-               settings->img_y = 0;
-               settings->img_width =
-                   (BUZ_MAX_WIDTH == 720) ? 704 : BUZ_MAX_WIDTH;
-               settings->img_height = BUZ_MAX_HEIGHT / 2;
-               break;
-       case 0:
-
-               /* We have to check the data the user has set */
-
-               if (settings->HorDcm != 1 && settings->HorDcm != 2 &&
-                   (zr->card.type == DC10_new || settings->HorDcm != 4))
-                       err0++;
-               if (settings->VerDcm != 1 && settings->VerDcm != 2)
-                       err0++;
-               if (settings->TmpDcm != 1 && settings->TmpDcm != 2)
-                       err0++;
-               if (settings->field_per_buff != 1 &&
-                   settings->field_per_buff != 2)
-                       err0++;
-               if (settings->img_x < 0)
-                       err0++;
-               if (settings->img_y < 0)
-                       err0++;
-               if (settings->img_width < 0)
-                       err0++;
-               if (settings->img_height < 0)
-                       err0++;
-               if (settings->img_x + settings->img_width > BUZ_MAX_WIDTH)
-                       err0++;
-               if (settings->img_y + settings->img_height >
-                   BUZ_MAX_HEIGHT / 2)
-                       err0++;
-               if (settings->HorDcm && settings->VerDcm) {
-                       if (settings->img_width %
-                           (16 * settings->HorDcm) != 0)
-                               err0++;
-                       if (settings->img_height %
-                           (8 * settings->VerDcm) != 0)
-                               err0++;
-               }
-
-               if (err0) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: check_jpg_settings() - error in params for decimation = 0\n",
-                               ZR_DEVNAME(zr));
-                       err++;
-               }
-               break;
-       default:
-               dprintk(1,
-                       KERN_ERR
-                       "%s: check_jpg_settings() - decimation = %d, must be 0, 1, 2 or 4\n",
-                       ZR_DEVNAME(zr), settings->decimation);
-               err++;
-               break;
-       }
-
-       if (settings->jpg_comp.quality > 100)
-               settings->jpg_comp.quality = 100;
-       if (settings->jpg_comp.quality < 5)
-               settings->jpg_comp.quality = 5;
-       if (settings->jpg_comp.APPn < 0)
-               settings->jpg_comp.APPn = 0;
-       if (settings->jpg_comp.APPn > 15)
-               settings->jpg_comp.APPn = 15;
-       if (settings->jpg_comp.APP_len < 0)
-               settings->jpg_comp.APP_len = 0;
-       if (settings->jpg_comp.APP_len > 60)
-               settings->jpg_comp.APP_len = 60;
-       if (settings->jpg_comp.COM_len < 0)
-               settings->jpg_comp.COM_len = 0;
-       if (settings->jpg_comp.COM_len > 60)
-               settings->jpg_comp.COM_len = 60;
-       if (err)
-               return -EINVAL;
-       return 0;
-}
-
-void
-zoran_open_init_params (struct zoran *zr)
-{
-       int i;
-
-       /* User must explicitly set a window */
-       zr->overlay_settings.is_set = 0;
-       zr->overlay_mask = NULL;
-       zr->overlay_active = ZORAN_FREE;
-
-       zr->v4l_memgrab_active = 0;
-       zr->v4l_overlay_active = 0;
-       zr->v4l_grab_frame = NO_GRAB_ACTIVE;
-       zr->v4l_grab_seq = 0;
-       zr->v4l_settings.width = 192;
-       zr->v4l_settings.height = 144;
-       zr->v4l_settings.format = &zoran_formats[7];    /* YUY2 - YUV-4:2:2 packed */
-       zr->v4l_settings.bytesperline =
-           zr->v4l_settings.width *
-           ((zr->v4l_settings.format->depth + 7) / 8);
-
-       /* DMA ring stuff for V4L */
-       zr->v4l_pend_tail = 0;
-       zr->v4l_pend_head = 0;
-       zr->v4l_sync_tail = 0;
-       zr->v4l_buffers.active = ZORAN_FREE;
-       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
-               zr->v4l_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
-       }
-       zr->v4l_buffers.allocated = 0;
-
-       for (i = 0; i < BUZ_MAX_FRAME; i++) {
-               zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
-       }
-       zr->jpg_buffers.active = ZORAN_FREE;
-       zr->jpg_buffers.allocated = 0;
-       /* Set necessary params and call zoran_check_jpg_settings to set the defaults */
-       zr->jpg_settings.decimation = 1;
-       zr->jpg_settings.jpg_comp.quality = 50; /* default compression factor 8 */
-       if (zr->card.type != BUZ)
-               zr->jpg_settings.odd_even = 1;
-       else
-               zr->jpg_settings.odd_even = 0;
-       zr->jpg_settings.jpg_comp.APPn = 0;
-       zr->jpg_settings.jpg_comp.APP_len = 0;  /* No APPn marker */
-       memset(zr->jpg_settings.jpg_comp.APP_data, 0,
-              sizeof(zr->jpg_settings.jpg_comp.APP_data));
-       zr->jpg_settings.jpg_comp.COM_len = 0;  /* No COM marker */
-       memset(zr->jpg_settings.jpg_comp.COM_data, 0,
-              sizeof(zr->jpg_settings.jpg_comp.COM_data));
-       zr->jpg_settings.jpg_comp.jpeg_markers =
-           JPEG_MARKER_DHT | JPEG_MARKER_DQT;
-       i = zoran_check_jpg_settings(zr, &zr->jpg_settings);
-       if (i)
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_open_init_params() internal error\n",
-                       ZR_DEVNAME(zr));
-
-       clear_interrupt_counters(zr);
-       zr->testing = 0;
-}
-
-static void __devinit
-test_interrupts (struct zoran *zr)
-{
-       DEFINE_WAIT(wait);
-       int timeout, icr;
-
-       clear_interrupt_counters(zr);
-
-       zr->testing = 1;
-       icr = btread(ZR36057_ICR);
-       btwrite(0x78000000 | ZR36057_ICR_IntPinEn, ZR36057_ICR);
-       prepare_to_wait(&zr->test_q, &wait, TASK_INTERRUPTIBLE);
-       timeout = schedule_timeout(HZ);
-       finish_wait(&zr->test_q, &wait);
-       btwrite(0, ZR36057_ICR);
-       btwrite(0x78000000, ZR36057_ISR);
-       zr->testing = 0;
-       dprintk(5, KERN_INFO "%s: Testing interrupts...\n", ZR_DEVNAME(zr));
-       if (timeout) {
-               dprintk(1, ": time spent: %d\n", 1 * HZ - timeout);
-       }
-       if (zr36067_debug > 1)
-               print_interrupts(zr);
-       btwrite(icr, ZR36057_ICR);
-}
-
-static int __devinit
-zr36057_init (struct zoran *zr)
-{
-       int j, err;
-       int two = 2;
-       int zero = 0;
-
-       dprintk(1,
-               KERN_INFO
-               "%s: zr36057_init() - initializing card[%d], zr=%p\n",
-               ZR_DEVNAME(zr), zr->id, zr);
-
-       /* default setup of all parameters which will persist between opens */
-       zr->user = 0;
-
-       init_waitqueue_head(&zr->v4l_capq);
-       init_waitqueue_head(&zr->jpg_capq);
-       init_waitqueue_head(&zr->test_q);
-       zr->jpg_buffers.allocated = 0;
-       zr->v4l_buffers.allocated = 0;
-
-       zr->buffer.base = (void *) vidmem;
-       zr->buffer.width = 0;
-       zr->buffer.height = 0;
-       zr->buffer.depth = 0;
-       zr->buffer.bytesperline = 0;
-
-       /* Avoid nonsense settings from user for default input/norm */
-       if (default_norm < VIDEO_MODE_PAL &&
-           default_norm > VIDEO_MODE_SECAM)
-               default_norm = VIDEO_MODE_PAL;
-       zr->norm = default_norm;
-       if (!(zr->timing = zr->card.tvn[zr->norm])) {
-               dprintk(1,
-                       KERN_WARNING
-                       "%s: zr36057_init() - default TV standard not supported by hardware. PAL will be used.\n",
-                       ZR_DEVNAME(zr));
-               zr->norm = VIDEO_MODE_PAL;
-               zr->timing = zr->card.tvn[zr->norm];
-       }
-
-       if (default_input > zr->card.inputs-1) {
-               dprintk(1,
-                       KERN_WARNING
-                       "%s: default_input value %d out of range (0-%d)\n",
-                       ZR_DEVNAME(zr), default_input, zr->card.inputs-1);
-               default_input = 0;
-       }
-       zr->input = default_input;
-
-       /* Should the following be reset at every open ? */
-       zr->hue = 32768;
-       zr->contrast = 32768;
-       zr->saturation = 32768;
-       zr->brightness = 32768;
-
-       /* default setup (will be repeated at every open) */
-       zoran_open_init_params(zr);
-
-       /* allocate memory *before* doing anything to the hardware
-        * in case allocation fails */
-       zr->stat_com = kzalloc(BUZ_NUM_STAT_COM * 4, GFP_KERNEL);
-       zr->video_dev = kmalloc(sizeof(struct video_device), GFP_KERNEL);
-       if (!zr->stat_com || !zr->video_dev) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zr36057_init() - kmalloc (STAT_COM) failed\n",
-                       ZR_DEVNAME(zr));
-               err = -ENOMEM;
-               goto exit_free;
-       }
-       for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
-               zr->stat_com[j] = cpu_to_le32(1); /* mark as unavailable to zr36057 */
-       }
-
-       /*
-        *   Now add the template and register the device unit.
-        */
-       memcpy(zr->video_dev, &zoran_template, sizeof(zoran_template));
-       strcpy(zr->video_dev->name, ZR_DEVNAME(zr));
-       err = video_register_device(zr->video_dev, VFL_TYPE_GRABBER, video_nr[zr->id]);
-       if (err < 0)
-               goto exit_unregister;
-
-       zoran_init_hardware(zr);
-       if (zr36067_debug > 2)
-               detect_guest_activity(zr);
-       test_interrupts(zr);
-       if (!pass_through) {
-               decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
-               encoder_command(zr, ENCODER_SET_INPUT, &two);
-       }
-
-       zr->zoran_proc = NULL;
-       zr->initialized = 1;
-       return 0;
-
-exit_unregister:
-       zoran_unregister_i2c(zr);
-exit_free:
-       kfree(zr->stat_com);
-       kfree(zr->video_dev);
-       return err;
-}
-
-static void
-zoran_release (struct zoran *zr)
-{
-       if (!zr->initialized)
-               goto exit_free;
-       /* unregister videocodec bus */
-       if (zr->codec) {
-               struct videocodec_master *master = zr->codec->master_data;
-
-               videocodec_detach(zr->codec);
-               kfree(master);
-       }
-       if (zr->vfe) {
-               struct videocodec_master *master = zr->vfe->master_data;
-
-               videocodec_detach(zr->vfe);
-               kfree(master);
-       }
-
-       /* unregister i2c bus */
-       zoran_unregister_i2c(zr);
-       /* disable PCI bus-mastering */
-       zoran_set_pci_master(zr, 0);
-       /* put chip into reset */
-       btwrite(0, ZR36057_SPGPPCR);
-       free_irq(zr->pci_dev->irq, zr);
-       /* unmap and free memory */
-       kfree(zr->stat_com);
-       zoran_proc_cleanup(zr);
-       iounmap(zr->zr36057_mem);
-       pci_disable_device(zr->pci_dev);
-       video_unregister_device(zr->video_dev);
-exit_free:
-       kfree(zr);
-}
-
-void
-zoran_vdev_release (struct video_device *vdev)
-{
-       kfree(vdev);
-}
-
-static struct videocodec_master * __devinit
-zoran_setup_videocodec (struct zoran *zr,
-                       int           type)
-{
-       struct videocodec_master *m = NULL;
-
-       m = kmalloc(sizeof(struct videocodec_master), GFP_KERNEL);
-       if (!m) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_setup_videocodec() - no memory\n",
-                       ZR_DEVNAME(zr));
-               return m;
-       }
-
-       /* magic and type are unused for master struct. Makes sense only at
-          codec structs.
-          In the past, .type were initialized to the old V4L1 .hardware
-          value, as VID_HARDWARE_ZR36067
-        */
-       m->magic = 0L;
-       m->type = 0;
-
-       m->flags = CODEC_FLAG_ENCODER | CODEC_FLAG_DECODER;
-       strncpy(m->name, ZR_DEVNAME(zr), sizeof(m->name));
-       m->data = zr;
-
-       switch (type)
-       {
-       case CODEC_TYPE_ZR36060:
-               m->readreg = zr36060_read;
-               m->writereg = zr36060_write;
-               m->flags |= CODEC_FLAG_JPEG | CODEC_FLAG_VFE;
-               break;
-       case CODEC_TYPE_ZR36050:
-               m->readreg = zr36050_read;
-               m->writereg = zr36050_write;
-               m->flags |= CODEC_FLAG_JPEG;
-               break;
-       case CODEC_TYPE_ZR36016:
-               m->readreg = zr36016_read;
-               m->writereg = zr36016_write;
-               m->flags |= CODEC_FLAG_VFE;
-               break;
-       }
-
-       return m;
-}
-
-/*
- *   Scan for a Buz card (actually for the PCI controller ZR36057),
- *   request the irq and map the io memory
- */
-static int __devinit
-find_zr36057 (void)
-{
-       unsigned char latency, need_latency;
-       struct zoran *zr;
-       struct pci_dev *dev = NULL;
-       int result;
-       struct videocodec_master *master_vfe = NULL;
-       struct videocodec_master *master_codec = NULL;
-       int card_num;
-       char *i2c_enc_name, *i2c_dec_name, *codec_name, *vfe_name;
-
-       zoran_num = 0;
-       while (zoran_num < BUZ_MAX &&
-              (dev = pci_get_device(PCI_VENDOR_ID_ZORAN, PCI_DEVICE_ID_ZORAN_36057, dev)) != NULL) {
-               card_num = card[zoran_num];
-               zr = kzalloc(sizeof(struct zoran), GFP_KERNEL);
-               if (!zr) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: find_zr36057() - kzalloc failed\n",
-                               ZORAN_NAME);
-                       continue;
-               }
-               zr->pci_dev = dev;
-               //zr->zr36057_mem = NULL;
-               zr->id = zoran_num;
-               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)), "MJPEG[%u]", zr->id);
-               spin_lock_init(&zr->spinlock);
-               mutex_init(&zr->resource_lock);
-               if (pci_enable_device(dev))
-                       goto zr_free_mem;
-               zr->zr36057_adr = pci_resource_start(zr->pci_dev, 0);
-               pci_read_config_byte(zr->pci_dev, PCI_CLASS_REVISION,
-                                    &zr->revision);
-               if (zr->revision < 2) {
-                       dprintk(1,
-                               KERN_INFO
-                               "%s: Zoran ZR36057 (rev %d) irq: %d, memory: 0x%08x.\n",
-                               ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
-                               zr->zr36057_adr);
-
-                       if (card_num == -1) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - no card specified, please use the card=X insmod option\n",
-                                       ZR_DEVNAME(zr));
-                               goto zr_free_mem;
-                       }
-               } else {
-                       int i;
-                       unsigned short ss_vendor, ss_device;
-
-                       ss_vendor = zr->pci_dev->subsystem_vendor;
-                       ss_device = zr->pci_dev->subsystem_device;
-                       dprintk(1,
-                               KERN_INFO
-                               "%s: Zoran ZR36067 (rev %d) irq: %d, memory: 0x%08x\n",
-                               ZR_DEVNAME(zr), zr->revision, zr->pci_dev->irq,
-                               zr->zr36057_adr);
-                       dprintk(1,
-                               KERN_INFO
-                               "%s: subsystem vendor=0x%04x id=0x%04x\n",
-                               ZR_DEVNAME(zr), ss_vendor, ss_device);
-                       if (card_num == -1) {
-                               dprintk(3,
-                                       KERN_DEBUG
-                                       "%s: find_zr36057() - trying to autodetect card type\n",
-                                       ZR_DEVNAME(zr));
-                               for (i=0;i<NUM_CARDS;i++) {
-                                       if (ss_vendor == zoran_cards[i].vendor_id &&
-                                           ss_device == zoran_cards[i].device_id) {
-                                               dprintk(3,
-                                                       KERN_DEBUG
-                                                       "%s: find_zr36057() - card %s detected\n",
-                                                       ZR_DEVNAME(zr),
-                                                       zoran_cards[i].name);
-                                               card_num = i;
-                                               break;
-                                       }
-                               }
-                               if (i == NUM_CARDS) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: find_zr36057() - unknown card\n",
-                                               ZR_DEVNAME(zr));
-                                       goto zr_free_mem;
-                               }
-                       }
-               }
-
-               if (card_num < 0 || card_num >= NUM_CARDS) {
-                       dprintk(2,
-                               KERN_ERR
-                               "%s: find_zr36057() - invalid cardnum %d\n",
-                               ZR_DEVNAME(zr), card_num);
-                       goto zr_free_mem;
-               }
-
-               /* even though we make this a non pointer and thus
-                * theoretically allow for making changes to this struct
-                * on a per-individual card basis at runtime, this is
-                * strongly discouraged. This structure is intended to
-                * keep general card information, no settings or anything */
-               zr->card = zoran_cards[card_num];
-               snprintf(ZR_DEVNAME(zr), sizeof(ZR_DEVNAME(zr)),
-                        "%s[%u]", zr->card.name, zr->id);
-
-               zr->zr36057_mem = ioremap_nocache(zr->zr36057_adr, 0x1000);
-               if (!zr->zr36057_mem) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: find_zr36057() - ioremap failed\n",
-                               ZR_DEVNAME(zr));
-                       goto zr_free_mem;
-               }
-
-               result = request_irq(zr->pci_dev->irq,
-                                    zoran_irq,
-                                    IRQF_SHARED | IRQF_DISABLED,
-                                    ZR_DEVNAME(zr),
-                                    (void *) zr);
-               if (result < 0) {
-                       if (result == -EINVAL) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - bad irq number or handler\n",
-                                       ZR_DEVNAME(zr));
-                       } else if (result == -EBUSY) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - IRQ %d busy, change your PnP config in BIOS\n",
-                                       ZR_DEVNAME(zr), zr->pci_dev->irq);
-                       } else {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - can't assign irq, error code %d\n",
-                                       ZR_DEVNAME(zr), result);
-                       }
-                       goto zr_unmap;
-               }
-
-               /* set PCI latency timer */
-               pci_read_config_byte(zr->pci_dev, PCI_LATENCY_TIMER,
-                                    &latency);
-               need_latency = zr->revision > 1 ? 32 : 48;
-               if (latency != need_latency) {
-                       dprintk(2,
-                               KERN_INFO
-                               "%s: Changing PCI latency from %d to %d.\n",
-                               ZR_DEVNAME(zr), latency, need_latency);
-                       pci_write_config_byte(zr->pci_dev,
-                                             PCI_LATENCY_TIMER,
-                                             need_latency);
-               }
-
-               zr36057_restart(zr);
-               /* i2c */
-               dprintk(2, KERN_INFO "%s: Initializing i2c bus...\n",
-                       ZR_DEVNAME(zr));
-
-               /* i2c decoder */
-               if (decoder[zr->id] != -1) {
-                       i2c_dec_name = i2cid_to_modulename(decoder[zr->id]);
-                       zr->card.i2c_decoder = decoder[zr->id];
-               } else if (zr->card.i2c_decoder != 0) {
-                       i2c_dec_name =
-                               i2cid_to_modulename(zr->card.i2c_decoder);
-               } else {
-                       i2c_dec_name = NULL;
-               }
-
-               if (i2c_dec_name) {
-                       if ((result = request_module(i2c_dec_name)) < 0) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: failed to load module %s: %d\n",
-                                       ZR_DEVNAME(zr), i2c_dec_name, result);
-                       }
-               }
-
-               /* i2c encoder */
-               if (encoder[zr->id] != -1) {
-                       i2c_enc_name = i2cid_to_modulename(encoder[zr->id]);
-                       zr->card.i2c_encoder = encoder[zr->id];
-               } else if (zr->card.i2c_encoder != 0) {
-                       i2c_enc_name =
-                               i2cid_to_modulename(zr->card.i2c_encoder);
-               } else {
-                       i2c_enc_name = NULL;
-               }
-
-               if (i2c_enc_name) {
-                       if ((result = request_module(i2c_enc_name)) < 0) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: failed to load module %s: %d\n",
-                                       ZR_DEVNAME(zr), i2c_enc_name, result);
-                       }
-               }
-
-               if (zoran_register_i2c(zr) < 0) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: find_zr36057() - can't initialize i2c bus\n",
-                               ZR_DEVNAME(zr));
-                       goto zr_free_irq;
-               }
-
-               dprintk(2,
-                       KERN_INFO "%s: Initializing videocodec bus...\n",
-                       ZR_DEVNAME(zr));
-
-               if (zr->card.video_codec != 0 &&
-                   (codec_name =
-                    codecid_to_modulename(zr->card.video_codec)) != NULL) {
-                       if ((result = request_module(codec_name)) < 0) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: failed to load modules %s: %d\n",
-                                       ZR_DEVNAME(zr), codec_name, result);
-                       }
-               }
-               if (zr->card.video_vfe != 0 &&
-                   (vfe_name =
-                    codecid_to_modulename(zr->card.video_vfe)) != NULL) {
-                       if ((result = request_module(vfe_name)) < 0) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: failed to load modules %s: %d\n",
-                                       ZR_DEVNAME(zr), vfe_name, result);
-                       }
-               }
-
-               /* reset JPEG codec */
-               jpeg_codec_sleep(zr, 1);
-               jpeg_codec_reset(zr);
-               /* video bus enabled */
-               /* display codec revision */
-               if (zr->card.video_codec != 0) {
-                       master_codec = zoran_setup_videocodec(zr,
-                                                             zr->card.video_codec);
-                       if (!master_codec)
-                               goto zr_unreg_i2c;
-                       zr->codec = videocodec_attach(master_codec);
-                       if (!zr->codec) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - no codec found\n",
-                                       ZR_DEVNAME(zr));
-                               goto zr_free_codec;
-                       }
-                       if (zr->codec->type != zr->card.video_codec) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - wrong codec\n",
-                                       ZR_DEVNAME(zr));
-                               goto zr_detach_codec;
-                       }
-               }
-               if (zr->card.video_vfe != 0) {
-                       master_vfe = zoran_setup_videocodec(zr,
-                                                           zr->card.video_vfe);
-                       if (!master_vfe)
-                               goto zr_detach_codec;
-                       zr->vfe = videocodec_attach(master_vfe);
-                       if (!zr->vfe) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() - no VFE found\n",
-                                       ZR_DEVNAME(zr));
-                               goto zr_free_vfe;
-                       }
-                       if (zr->vfe->type != zr->card.video_vfe) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: find_zr36057() = wrong VFE\n",
-                                       ZR_DEVNAME(zr));
-                               goto zr_detach_vfe;
-                       }
-               }
-               /* Success so keep the pci_dev referenced */
-               pci_dev_get(zr->pci_dev);
-               zoran[zoran_num++] = zr;
-               continue;
-
-               // Init errors
-             zr_detach_vfe:
-               videocodec_detach(zr->vfe);
-             zr_free_vfe:
-               kfree(master_vfe);
-             zr_detach_codec:
-               videocodec_detach(zr->codec);
-             zr_free_codec:
-               kfree(master_codec);
-             zr_unreg_i2c:
-               zoran_unregister_i2c(zr);
-             zr_free_irq:
-               btwrite(0, ZR36057_SPGPPCR);
-               free_irq(zr->pci_dev->irq, zr);
-             zr_unmap:
-               iounmap(zr->zr36057_mem);
-             zr_free_mem:
-               kfree(zr);
-               continue;
-       }
-       if (dev)        /* Clean up ref count on early exit */
-               pci_dev_put(dev);
-
-       if (zoran_num == 0) {
-               dprintk(1, KERN_INFO "No known MJPEG cards found.\n");
-       }
-       return zoran_num;
-}
-
-static int __init
-init_dc10_cards (void)
-{
-       int i;
-
-       memset(zoran, 0, sizeof(zoran));
-       printk(KERN_INFO "Zoran MJPEG board driver version %d.%d.%d\n",
-              MAJOR_VERSION, MINOR_VERSION, RELEASE_VERSION);
-
-       /* Look for cards */
-       if (find_zr36057() < 0) {
-               return -EIO;
-       }
-       if (zoran_num == 0)
-               return -ENODEV;
-       dprintk(1, KERN_INFO "%s: %d card(s) found\n", ZORAN_NAME,
-               zoran_num);
-       /* check the parameters we have been given, adjust if necessary */
-       if (v4l_nbufs < 2)
-               v4l_nbufs = 2;
-       if (v4l_nbufs > VIDEO_MAX_FRAME)
-               v4l_nbufs = VIDEO_MAX_FRAME;
-       /* The user specfies the in KB, we want them in byte
-        * (and page aligned) */
-       v4l_bufsize = PAGE_ALIGN(v4l_bufsize * 1024);
-       if (v4l_bufsize < 32768)
-               v4l_bufsize = 32768;
-       /* 2 MB is arbitrary but sufficient for the maximum possible images */
-       if (v4l_bufsize > 2048 * 1024)
-               v4l_bufsize = 2048 * 1024;
-       if (jpg_nbufs < 4)
-               jpg_nbufs = 4;
-       if (jpg_nbufs > BUZ_MAX_FRAME)
-               jpg_nbufs = BUZ_MAX_FRAME;
-       jpg_bufsize = PAGE_ALIGN(jpg_bufsize * 1024);
-       if (jpg_bufsize < 8192)
-               jpg_bufsize = 8192;
-       if (jpg_bufsize > (512 * 1024))
-               jpg_bufsize = 512 * 1024;
-       /* Use parameter for vidmem or try to find a video card */
-       if (vidmem) {
-               dprintk(1,
-                       KERN_INFO
-                       "%s: Using supplied video memory base address @ 0x%lx\n",
-                       ZORAN_NAME, vidmem);
-       }
-
-       /* random nonsense */
-       dprintk(6, KERN_DEBUG "Jotti is een held!\n");
-
-       /* some mainboards might not do PCI-PCI data transfer well */
-       if (pci_pci_problems & (PCIPCI_FAIL|PCIAGP_FAIL|PCIPCI_ALIMAGIK)) {
-               dprintk(1,
-                       KERN_WARNING
-                       "%s: chipset does not support reliable PCI-PCI DMA\n",
-                       ZORAN_NAME);
-       }
-
-       /* take care of Natoma chipset and a revision 1 zr36057 */
-       for (i = 0; i < zoran_num; i++) {
-               struct zoran *zr = zoran[i];
-
-               if ((pci_pci_problems & PCIPCI_NATOMA) && zr->revision <= 1) {
-                       zr->jpg_buffers.need_contiguous = 1;
-                       dprintk(1,
-                               KERN_INFO
-                               "%s: ZR36057/Natoma bug, max. buffer size is 128K\n",
-                               ZR_DEVNAME(zr));
-               }
-
-               if (zr36057_init(zr) < 0) {
-                       for (i = 0; i < zoran_num; i++)
-                               zoran_release(zoran[i]);
-                       return -EIO;
-               }
-               zoran_proc_init(zr);
-       }
-
-       return 0;
-}
-
-static void __exit
-unload_dc10_cards (void)
-{
-       int i;
-
-       for (i = 0; i < zoran_num; i++)
-               zoran_release(zoran[i]);
-}
-
-module_init(init_dc10_cards);
-module_exit(unload_dc10_cards);
diff --git a/drivers/media/video/zoran_card.h b/drivers/media/video/zoran_card.h
deleted file mode 100644 (file)
index e4dc9d2..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles card-specific data and detection
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __ZORAN_CARD_H__
-#define __ZORAN_CARD_H__
-
-extern int zr36067_debug;
-
-#define dprintk(num, format, args...) \
-       do { \
-               if (zr36067_debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
-/* Anybody who uses more than four? */
-#define BUZ_MAX 4
-extern int zoran_num;
-extern struct zoran *zoran[BUZ_MAX];
-
-extern struct video_device zoran_template;
-
-extern int zoran_check_jpg_settings(struct zoran *zr,
-                                   struct zoran_jpg_settings *settings);
-extern void zoran_open_init_params(struct zoran *zr);
-extern void zoran_vdev_release(struct video_device *vdev);
-
-void zr36016_write(struct videocodec *codec, u16 reg, u32 val);
-
-#endif                         /* __ZORAN_CARD_H__ */
diff --git a/drivers/media/video/zoran_device.c b/drivers/media/video/zoran_device.c
deleted file mode 100644 (file)
index 88d3697..0000000
+++ /dev/null
@@ -1,1749 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles device access (PCI/I2C/codec/...)
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/vmalloc.h>
-
-#include <linux/interrupt.h>
-#include <linux/proc_fs.h>
-#include <linux/i2c.h>
-#include <linux/i2c-algo-bit.h>
-#include <linux/videodev.h>
-#include <linux/spinlock.h>
-#include <linux/sem.h>
-
-#include <linux/pci.h>
-#include <linux/video_decoder.h>
-#include <linux/video_encoder.h>
-#include <linux/delay.h>
-#include <linux/wait.h>
-
-#include <asm/byteorder.h>
-#include <asm/io.h>
-
-#include "videocodec.h"
-#include "zoran.h"
-#include "zoran_device.h"
-#include "zoran_card.h"
-
-#define IRQ_MASK ( ZR36057_ISR_GIRQ0 | \
-                  ZR36057_ISR_GIRQ1 | \
-                  ZR36057_ISR_JPEGRepIRQ )
-
-extern const struct zoran_format zoran_formats[];
-
-static int lml33dpath;         /* default = 0
-                                * 1 will use digital path in capture
-                                * mode instead of analog. It can be
-                                * used for picture adjustments using
-                                * tool like xawtv while watching image
-                                * on TV monitor connected to the output.
-                                * However, due to absence of 75 Ohm
-                                * load on Bt819 input, there will be
-                                * some image imperfections */
-
-module_param(lml33dpath, bool, 0644);
-MODULE_PARM_DESC(lml33dpath,
-                "Use digital path capture mode (on LML33 cards)");
-
-static void
-zr36057_init_vfe (struct zoran *zr);
-
-/*
- * General Purpose I/O and Guest bus access
- */
-
-/*
- * This is a bit tricky. When a board lacks a GPIO function, the corresponding
- * GPIO bit number in the card_info structure is set to 0.
- */
-
-void
-GPIO (struct zoran *zr,
-      int           bit,
-      unsigned int  value)
-{
-       u32 reg;
-       u32 mask;
-
-       /* Make sure the bit number is legal
-        * A bit number of -1 (lacking) gives a mask of 0,
-        * making it harmless */
-       mask = (1 << (24 + bit)) & 0xff000000;
-       reg = btread(ZR36057_GPPGCR1) & ~mask;
-       if (value) {
-               reg |= mask;
-       }
-       btwrite(reg, ZR36057_GPPGCR1);
-       udelay(1);
-}
-
-/*
- * Wait til post office is no longer busy
- */
-
-int
-post_office_wait (struct zoran *zr)
-{
-       u32 por;
-
-//      while (((por = btread(ZR36057_POR)) & (ZR36057_POR_POPen | ZR36057_POR_POTime)) == ZR36057_POR_POPen) {
-       while ((por = btread(ZR36057_POR)) & ZR36057_POR_POPen) {
-               /* wait for something to happen */
-       }
-       if ((por & ZR36057_POR_POTime) && !zr->card.gws_not_connected) {
-               /* In LML33/BUZ \GWS line is not connected, so it has always timeout set */
-               dprintk(1, KERN_INFO "%s: pop timeout %08x\n", ZR_DEVNAME(zr),
-                       por);
-               return -1;
-       }
-
-       return 0;
-}
-
-int
-post_office_write (struct zoran *zr,
-                  unsigned int  guest,
-                  unsigned int  reg,
-                  unsigned int  value)
-{
-       u32 por;
-
-       por =
-           ZR36057_POR_PODir | ZR36057_POR_POTime | ((guest & 7) << 20) |
-           ((reg & 7) << 16) | (value & 0xFF);
-       btwrite(por, ZR36057_POR);
-
-       return post_office_wait(zr);
-}
-
-int
-post_office_read (struct zoran *zr,
-                 unsigned int  guest,
-                 unsigned int  reg)
-{
-       u32 por;
-
-       por = ZR36057_POR_POTime | ((guest & 7) << 20) | ((reg & 7) << 16);
-       btwrite(por, ZR36057_POR);
-       if (post_office_wait(zr) < 0) {
-               return -1;
-       }
-
-       return btread(ZR36057_POR) & 0xFF;
-}
-
-/*
- * detect guests
- */
-
-static void
-dump_guests (struct zoran *zr)
-{
-       if (zr36067_debug > 2) {
-               int i, guest[8];
-
-               for (i = 1; i < 8; i++) {       // Don't read jpeg codec here
-                       guest[i] = post_office_read(zr, i, 0);
-               }
-
-               printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
-
-               for (i = 1; i < 8; i++) {
-                       printk(" 0x%02x", guest[i]);
-               }
-               printk("\n");
-       }
-}
-
-static inline unsigned long
-get_time (void)
-{
-       struct timeval tv;
-
-       do_gettimeofday(&tv);
-       return (1000000 * tv.tv_sec + tv.tv_usec);
-}
-
-void
-detect_guest_activity (struct zoran *zr)
-{
-       int timeout, i, j, res, guest[8], guest0[8], change[8][3];
-       unsigned long t0, t1;
-
-       dump_guests(zr);
-       printk(KERN_INFO "%s: Detecting guests activity, please wait...\n",
-              ZR_DEVNAME(zr));
-       for (i = 1; i < 8; i++) {       // Don't read jpeg codec here
-               guest0[i] = guest[i] = post_office_read(zr, i, 0);
-       }
-
-       timeout = 0;
-       j = 0;
-       t0 = get_time();
-       while (timeout < 10000) {
-               udelay(10);
-               timeout++;
-               for (i = 1; (i < 8) && (j < 8); i++) {
-                       res = post_office_read(zr, i, 0);
-                       if (res != guest[i]) {
-                               t1 = get_time();
-                               change[j][0] = (t1 - t0);
-                               t0 = t1;
-                               change[j][1] = i;
-                               change[j][2] = res;
-                               j++;
-                               guest[i] = res;
-                       }
-               }
-               if (j >= 8)
-                       break;
-       }
-       printk(KERN_INFO "%s: Guests:", ZR_DEVNAME(zr));
-
-       for (i = 1; i < 8; i++) {
-               printk(" 0x%02x", guest0[i]);
-       }
-       printk("\n");
-       if (j == 0) {
-               printk(KERN_INFO "%s: No activity detected.\n", ZR_DEVNAME(zr));
-               return;
-       }
-       for (i = 0; i < j; i++) {
-               printk(KERN_INFO "%s: %6d: %d => 0x%02x\n", ZR_DEVNAME(zr),
-                      change[i][0], change[i][1], change[i][2]);
-       }
-}
-
-/*
- * JPEG Codec access
- */
-
-void
-jpeg_codec_sleep (struct zoran *zr,
-                 int           sleep)
-{
-       GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_SLEEP], !sleep);
-       if (!sleep) {
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: jpeg_codec_sleep() - wake GPIO=0x%08x\n",
-                       ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
-               udelay(500);
-       } else {
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: jpeg_codec_sleep() - sleep GPIO=0x%08x\n",
-                       ZR_DEVNAME(zr), btread(ZR36057_GPPGCR1));
-               udelay(2);
-       }
-}
-
-int
-jpeg_codec_reset (struct zoran *zr)
-{
-       /* Take the codec out of sleep */
-       jpeg_codec_sleep(zr, 0);
-
-       if (zr->card.gpcs[GPCS_JPEG_RESET] != 0xff) {
-               post_office_write(zr, zr->card.gpcs[GPCS_JPEG_RESET], 0,
-                                 0);
-               udelay(2);
-       } else {
-               GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 0);
-               udelay(2);
-               GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_RESET], 1);
-               udelay(2);
-       }
-
-       return 0;
-}
-
-/*
- *   Set the registers for the size we have specified. Don't bother
- *   trying to understand this without the ZR36057 manual in front of
- *   you [AC].
- *
- *   PS: The manual is free for download in .pdf format from
- *   www.zoran.com - nicely done those folks.
- */
-
-static void
-zr36057_adjust_vfe (struct zoran          *zr,
-                   enum zoran_codec_mode  mode)
-{
-       u32 reg;
-
-       switch (mode) {
-       case BUZ_MODE_MOTION_DECOMPRESS:
-               btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
-               reg = btread(ZR36057_VFEHCR);
-               if ((reg & (1 << 10)) && zr->card.type != LML33R10) {
-                       reg += ((1 << 10) | 1);
-               }
-               btwrite(reg, ZR36057_VFEHCR);
-               break;
-       case BUZ_MODE_MOTION_COMPRESS:
-       case BUZ_MODE_IDLE:
-       default:
-               if (zr->norm == VIDEO_MODE_NTSC ||
-                   (zr->card.type == LML33R10 &&
-                    zr->norm == VIDEO_MODE_PAL))
-                       btand(~ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
-               else
-                       btor(ZR36057_VFESPFR_ExtFl, ZR36057_VFESPFR);
-               reg = btread(ZR36057_VFEHCR);
-               if (!(reg & (1 << 10)) && zr->card.type != LML33R10) {
-                       reg -= ((1 << 10) | 1);
-               }
-               btwrite(reg, ZR36057_VFEHCR);
-               break;
-       }
-}
-
-/*
- * set geometry
- */
-
-static void
-zr36057_set_vfe (struct zoran              *zr,
-                int                        video_width,
-                int                        video_height,
-                const struct zoran_format *format)
-{
-       struct tvnorm *tvn;
-       unsigned HStart, HEnd, VStart, VEnd;
-       unsigned DispMode;
-       unsigned VidWinWid, VidWinHt;
-       unsigned hcrop1, hcrop2, vcrop1, vcrop2;
-       unsigned Wa, We, Ha, He;
-       unsigned X, Y, HorDcm, VerDcm;
-       u32 reg;
-       unsigned mask_line_size;
-
-       tvn = zr->timing;
-
-       Wa = tvn->Wa;
-       Ha = tvn->Ha;
-
-       dprintk(2, KERN_INFO "%s: set_vfe() - width = %d, height = %d\n",
-               ZR_DEVNAME(zr), video_width, video_height);
-
-       if (zr->norm != VIDEO_MODE_PAL &&
-           zr->norm != VIDEO_MODE_NTSC &&
-           zr->norm != VIDEO_MODE_SECAM) {
-               dprintk(1,
-                       KERN_ERR "%s: set_vfe() - norm = %d not valid\n",
-                       ZR_DEVNAME(zr), zr->norm);
-               return;
-       }
-       if (video_width < BUZ_MIN_WIDTH ||
-           video_height < BUZ_MIN_HEIGHT ||
-           video_width > Wa || video_height > Ha) {
-               dprintk(1, KERN_ERR "%s: set_vfe: w=%d h=%d not valid\n",
-                       ZR_DEVNAME(zr), video_width, video_height);
-               return;
-       }
-
-       /**** zr36057 ****/
-
-       /* horizontal */
-       VidWinWid = video_width;
-       X = (VidWinWid * 64 + tvn->Wa - 1) / tvn->Wa;
-       We = (VidWinWid * 64) / X;
-       HorDcm = 64 - X;
-       hcrop1 = 2 * ((tvn->Wa - We) / 4);
-       hcrop2 = tvn->Wa - We - hcrop1;
-       HStart = tvn->HStart ? tvn->HStart : 1;
-       /* (Ronald) Original comment:
-        * "| 1 Doesn't have any effect, tested on both a DC10 and a DC10+"
-        * this is false. It inverses chroma values on the LML33R10 (so Cr
-        * suddenly is shown as Cb and reverse, really cool effect if you
-        * want to see blue faces, not useful otherwise). So don't use |1.
-        * However, the DC10 has '0' as HStart, but does need |1, so we
-        * use a dirty check...
-        */
-       HEnd = HStart + tvn->Wa - 1;
-       HStart += hcrop1;
-       HEnd -= hcrop2;
-       reg = ((HStart & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HStart)
-           | ((HEnd & ZR36057_VFEHCR_Hmask) << ZR36057_VFEHCR_HEnd);
-       if (zr->card.vfe_pol.hsync_pol)
-               reg |= ZR36057_VFEHCR_HSPol;
-       btwrite(reg, ZR36057_VFEHCR);
-
-       /* Vertical */
-       DispMode = !(video_height > BUZ_MAX_HEIGHT / 2);
-       VidWinHt = DispMode ? video_height : video_height / 2;
-       Y = (VidWinHt * 64 * 2 + tvn->Ha - 1) / tvn->Ha;
-       He = (VidWinHt * 64) / Y;
-       VerDcm = 64 - Y;
-       vcrop1 = (tvn->Ha / 2 - He) / 2;
-       vcrop2 = tvn->Ha / 2 - He - vcrop1;
-       VStart = tvn->VStart;
-       VEnd = VStart + tvn->Ha / 2;    // - 1; FIXME SnapShot times out with -1 in 768*576 on the DC10 - LP
-       VStart += vcrop1;
-       VEnd -= vcrop2;
-       reg = ((VStart & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VStart)
-           | ((VEnd & ZR36057_VFEVCR_Vmask) << ZR36057_VFEVCR_VEnd);
-       if (zr->card.vfe_pol.vsync_pol)
-               reg |= ZR36057_VFEVCR_VSPol;
-       btwrite(reg, ZR36057_VFEVCR);
-
-       /* scaler and pixel format */
-       reg = 0;
-       reg |= (HorDcm << ZR36057_VFESPFR_HorDcm);
-       reg |= (VerDcm << ZR36057_VFESPFR_VerDcm);
-       reg |= (DispMode << ZR36057_VFESPFR_DispMode);
-       /* RJ: I don't know, why the following has to be the opposite
-        * of the corresponding ZR36060 setting, but only this way
-        * we get the correct colors when uncompressing to the screen  */
-       //reg |= ZR36057_VFESPFR_VCLKPol; /**/
-       /* RJ: Don't know if that is needed for NTSC also */
-       if (zr->norm != VIDEO_MODE_NTSC)
-               reg |= ZR36057_VFESPFR_ExtFl;   // NEEDED!!!!!!! Wolfgang
-       reg |= ZR36057_VFESPFR_TopField;
-       if (HorDcm >= 48) {
-               reg |= 3 << ZR36057_VFESPFR_HFilter;    /* 5 tap filter */
-       } else if (HorDcm >= 32) {
-               reg |= 2 << ZR36057_VFESPFR_HFilter;    /* 4 tap filter */
-       } else if (HorDcm >= 16) {
-               reg |= 1 << ZR36057_VFESPFR_HFilter;    /* 3 tap filter */
-       }
-       reg |= format->vfespfr;
-       btwrite(reg, ZR36057_VFESPFR);
-
-       /* display configuration */
-       reg = (16 << ZR36057_VDCR_MinPix)
-           | (VidWinHt << ZR36057_VDCR_VidWinHt)
-           | (VidWinWid << ZR36057_VDCR_VidWinWid);
-       if (pci_pci_problems & PCIPCI_TRITON)
-               // || zr->revision < 1) // Revision 1 has also Triton support
-               reg &= ~ZR36057_VDCR_Triton;
-       else
-               reg |= ZR36057_VDCR_Triton;
-       btwrite(reg, ZR36057_VDCR);
-
-       /* (Ronald) don't write this if overlay_mask = NULL */
-       if (zr->overlay_mask) {
-               /* Write overlay clipping mask data, but don't enable overlay clipping */
-               /* RJ: since this makes only sense on the screen, we use
-                * zr->overlay_settings.width instead of video_width */
-
-               mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
-               reg = virt_to_bus(zr->overlay_mask);
-               btwrite(reg, ZR36057_MMTR);
-               reg = virt_to_bus(zr->overlay_mask + mask_line_size);
-               btwrite(reg, ZR36057_MMBR);
-               reg =
-                   mask_line_size - (zr->overlay_settings.width +
-                                     31) / 32;
-               if (DispMode == 0)
-                       reg += mask_line_size;
-               reg <<= ZR36057_OCR_MaskStride;
-               btwrite(reg, ZR36057_OCR);
-       }
-
-       zr36057_adjust_vfe(zr, zr->codec_mode);
-}
-
-/*
- * Switch overlay on or off
- */
-
-void
-zr36057_overlay (struct zoran *zr,
-                int           on)
-{
-       u32 reg;
-
-       if (on) {
-               /* do the necessary settings ... */
-               btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);       /* switch it off first */
-
-               zr36057_set_vfe(zr,
-                               zr->overlay_settings.width,
-                               zr->overlay_settings.height,
-                               zr->overlay_settings.format);
-
-               /* Start and length of each line MUST be 4-byte aligned.
-                * This should be allready checked before the call to this routine.
-                * All error messages are internal driver checking only! */
-
-               /* video display top and bottom registers */
-               reg = (long) zr->buffer.base +
-                   zr->overlay_settings.x *
-                   ((zr->overlay_settings.format->depth + 7) / 8) +
-                   zr->overlay_settings.y *
-                   zr->buffer.bytesperline;
-               btwrite(reg, ZR36057_VDTR);
-               if (reg & 3)
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: zr36057_overlay() - video_address not aligned\n",
-                               ZR_DEVNAME(zr));
-               if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
-                       reg += zr->buffer.bytesperline;
-               btwrite(reg, ZR36057_VDBR);
-
-               /* video stride, status, and frame grab register */
-               reg = zr->buffer.bytesperline -
-                   zr->overlay_settings.width *
-                   ((zr->overlay_settings.format->depth + 7) / 8);
-               if (zr->overlay_settings.height > BUZ_MAX_HEIGHT / 2)
-                       reg += zr->buffer.bytesperline;
-               if (reg & 3)
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: zr36057_overlay() - video_stride not aligned\n",
-                               ZR_DEVNAME(zr));
-               reg = (reg << ZR36057_VSSFGR_DispStride);
-               reg |= ZR36057_VSSFGR_VidOvf;   /* clear overflow status */
-               btwrite(reg, ZR36057_VSSFGR);
-
-               /* Set overlay clipping */
-               if (zr->overlay_settings.clipcount > 0)
-                       btor(ZR36057_OCR_OvlEnable, ZR36057_OCR);
-
-               /* ... and switch it on */
-               btor(ZR36057_VDCR_VidEn, ZR36057_VDCR);
-       } else {
-               /* Switch it off */
-               btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
-       }
-}
-
-/*
- * The overlay mask has one bit for each pixel on a scan line,
- *  and the maximum window size is BUZ_MAX_WIDTH * BUZ_MAX_HEIGHT pixels.
- */
-
-void
-write_overlay_mask (struct file       *file,
-                   struct video_clip *vp,
-                   int                count)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned mask_line_size = (BUZ_MAX_WIDTH + 31) / 32;
-       u32 *mask;
-       int x, y, width, height;
-       unsigned i, j, k;
-       u32 reg;
-
-       /* fill mask with one bits */
-       memset(fh->overlay_mask, ~0, mask_line_size * 4 * BUZ_MAX_HEIGHT);
-       reg = 0;
-
-       for (i = 0; i < count; ++i) {
-               /* pick up local copy of clip */
-               x = vp[i].x;
-               y = vp[i].y;
-               width = vp[i].width;
-               height = vp[i].height;
-
-               /* trim clips that extend beyond the window */
-               if (x < 0) {
-                       width += x;
-                       x = 0;
-               }
-               if (y < 0) {
-                       height += y;
-                       y = 0;
-               }
-               if (x + width > fh->overlay_settings.width) {
-                       width = fh->overlay_settings.width - x;
-               }
-               if (y + height > fh->overlay_settings.height) {
-                       height = fh->overlay_settings.height - y;
-               }
-
-               /* ignore degenerate clips */
-               if (height <= 0) {
-                       continue;
-               }
-               if (width <= 0) {
-                       continue;
-               }
-
-               /* apply clip for each scan line */
-               for (j = 0; j < height; ++j) {
-                       /* reset bit for each pixel */
-                       /* this can be optimized later if need be */
-                       mask = fh->overlay_mask + (y + j) * mask_line_size;
-                       for (k = 0; k < width; ++k) {
-                               mask[(x + k) / 32] &=
-                                   ~((u32) 1 << (x + k) % 32);
-                       }
-               }
-       }
-}
-
-/* Enable/Disable uncompressed memory grabbing of the 36057 */
-
-void
-zr36057_set_memgrab (struct zoran *zr,
-                    int           mode)
-{
-       if (mode) {
-               /* We only check SnapShot and not FrameGrab here.  SnapShot==1
-                * means a capture is already in progress, but FrameGrab==1
-                * doesn't necessary mean that.  It's more correct to say a 1
-                * to 0 transition indicates a capture completed.  If a
-                * capture is pending when capturing is tuned off, FrameGrab
-                * will be stuck at 1 until capturing is turned back on.
-                */
-               if (btread(ZR36057_VSSFGR) & ZR36057_VSSFGR_SnapShot)
-                       dprintk(1,
-                               KERN_WARNING
-                               "%s: zr36057_set_memgrab(1) with SnapShot on!?\n",
-                               ZR_DEVNAME(zr));
-
-               /* switch on VSync interrupts */
-               btwrite(IRQ_MASK, ZR36057_ISR); // Clear Interrupts
-               btor(zr->card.vsync_int, ZR36057_ICR);  // SW
-
-               /* enable SnapShot */
-               btor(ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
-
-               /* Set zr36057 video front end  and enable video */
-               zr36057_set_vfe(zr, zr->v4l_settings.width,
-                               zr->v4l_settings.height,
-                               zr->v4l_settings.format);
-
-               zr->v4l_memgrab_active = 1;
-       } else {
-               /* switch off VSync interrupts */
-               btand(~zr->card.vsync_int, ZR36057_ICR);        // SW
-
-               zr->v4l_memgrab_active = 0;
-               zr->v4l_grab_frame = NO_GRAB_ACTIVE;
-
-               /* reenable grabbing to screen if it was running */
-               if (zr->v4l_overlay_active) {
-                       zr36057_overlay(zr, 1);
-               } else {
-                       btand(~ZR36057_VDCR_VidEn, ZR36057_VDCR);
-                       btand(~ZR36057_VSSFGR_SnapShot, ZR36057_VSSFGR);
-               }
-       }
-}
-
-int
-wait_grab_pending (struct zoran *zr)
-{
-       unsigned long flags;
-
-       /* wait until all pending grabs are finished */
-
-       if (!zr->v4l_memgrab_active)
-               return 0;
-
-       wait_event_interruptible(zr->v4l_capq,
-                       (zr->v4l_pend_tail == zr->v4l_pend_head));
-       if (signal_pending(current))
-               return -ERESTARTSYS;
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-       zr36057_set_memgrab(zr, 0);
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       return 0;
-}
-
-/*****************************************************************************
- *                                                                           *
- *  Set up the Buz-specific MJPEG part                                       *
- *                                                                           *
- *****************************************************************************/
-
-static inline void
-set_frame (struct zoran *zr,
-          int           val)
-{
-       GPIO(zr, zr->card.gpio[ZR_GPIO_JPEG_FRAME], val);
-}
-
-static void
-set_videobus_dir (struct zoran *zr,
-                 int           val)
-{
-       switch (zr->card.type) {
-       case LML33:
-       case LML33R10:
-               if (lml33dpath == 0)
-                       GPIO(zr, 5, val);
-               else
-                       GPIO(zr, 5, 1);
-               break;
-       default:
-               GPIO(zr, zr->card.gpio[ZR_GPIO_VID_DIR],
-                    zr->card.gpio_pol[ZR_GPIO_VID_DIR] ? !val : val);
-               break;
-       }
-}
-
-static void
-init_jpeg_queue (struct zoran *zr)
-{
-       int i;
-
-       /* re-initialize DMA ring stuff */
-       zr->jpg_que_head = 0;
-       zr->jpg_dma_head = 0;
-       zr->jpg_dma_tail = 0;
-       zr->jpg_que_tail = 0;
-       zr->jpg_seq_num = 0;
-       zr->JPEG_error = 0;
-       zr->num_errors = 0;
-       zr->jpg_err_seq = 0;
-       zr->jpg_err_shift = 0;
-       zr->jpg_queued_num = 0;
-       for (i = 0; i < zr->jpg_buffers.num_buffers; i++) {
-               zr->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
-       }
-       for (i = 0; i < BUZ_NUM_STAT_COM; i++) {
-               zr->stat_com[i] = cpu_to_le32(1);       /* mark as unavailable to zr36057 */
-       }
-}
-
-static void
-zr36057_set_jpg (struct zoran          *zr,
-                enum zoran_codec_mode  mode)
-{
-       struct tvnorm *tvn;
-       u32 reg;
-
-       tvn = zr->timing;
-
-       /* assert P_Reset, disable code transfer, deassert Active */
-       btwrite(0, ZR36057_JPC);
-
-       /* MJPEG compression mode */
-       switch (mode) {
-
-       case BUZ_MODE_MOTION_COMPRESS:
-       default:
-               reg = ZR36057_JMC_MJPGCmpMode;
-               break;
-
-       case BUZ_MODE_MOTION_DECOMPRESS:
-               reg = ZR36057_JMC_MJPGExpMode;
-               reg |= ZR36057_JMC_SyncMstr;
-               /* RJ: The following is experimental - improves the output to screen */
-               //if(zr->jpg_settings.VFIFO_FB) reg |= ZR36057_JMC_VFIFO_FB; // No, it doesn't. SM
-               break;
-
-       case BUZ_MODE_STILL_COMPRESS:
-               reg = ZR36057_JMC_JPGCmpMode;
-               break;
-
-       case BUZ_MODE_STILL_DECOMPRESS:
-               reg = ZR36057_JMC_JPGExpMode;
-               break;
-
-       }
-       reg |= ZR36057_JMC_JPG;
-       if (zr->jpg_settings.field_per_buff == 1)
-               reg |= ZR36057_JMC_Fld_per_buff;
-       btwrite(reg, ZR36057_JMC);
-
-       /* vertical */
-       btor(ZR36057_VFEVCR_VSPol, ZR36057_VFEVCR);
-       reg = (6 << ZR36057_VSP_VsyncSize) |
-             (tvn->Ht << ZR36057_VSP_FrmTot);
-       btwrite(reg, ZR36057_VSP);
-       reg = ((zr->jpg_settings.img_y + tvn->VStart) << ZR36057_FVAP_NAY) |
-             (zr->jpg_settings.img_height << ZR36057_FVAP_PAY);
-       btwrite(reg, ZR36057_FVAP);
-
-       /* horizontal */
-       if (zr->card.vfe_pol.hsync_pol)
-               btor(ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
-       else
-               btand(~ZR36057_VFEHCR_HSPol, ZR36057_VFEHCR);
-       reg = ((tvn->HSyncStart) << ZR36057_HSP_HsyncStart) |
-             (tvn->Wt << ZR36057_HSP_LineTot);
-       btwrite(reg, ZR36057_HSP);
-       reg = ((zr->jpg_settings.img_x +
-               tvn->HStart + 4) << ZR36057_FHAP_NAX) |
-             (zr->jpg_settings.img_width << ZR36057_FHAP_PAX);
-       btwrite(reg, ZR36057_FHAP);
-
-       /* field process parameters */
-       if (zr->jpg_settings.odd_even)
-               reg = ZR36057_FPP_Odd_Even;
-       else
-               reg = 0;
-
-       btwrite(reg, ZR36057_FPP);
-
-       /* Set proper VCLK Polarity, else colors will be wrong during playback */
-       //btor(ZR36057_VFESPFR_VCLKPol, ZR36057_VFESPFR);
-
-       /* code base address */
-       reg = virt_to_bus(zr->stat_com);
-       btwrite(reg, ZR36057_JCBA);
-
-       /* FIFO threshold (FIFO is 160. double words) */
-       /* NOTE: decimal values here */
-       switch (mode) {
-
-       case BUZ_MODE_STILL_COMPRESS:
-       case BUZ_MODE_MOTION_COMPRESS:
-               if (zr->card.type != BUZ)
-                       reg = 140;
-               else
-                       reg = 60;
-               break;
-
-       case BUZ_MODE_STILL_DECOMPRESS:
-       case BUZ_MODE_MOTION_DECOMPRESS:
-               reg = 20;
-               break;
-
-       default:
-               reg = 80;
-               break;
-
-       }
-       btwrite(reg, ZR36057_JCFT);
-       zr36057_adjust_vfe(zr, mode);
-
-}
-
-void
-print_interrupts (struct zoran *zr)
-{
-       int res, noerr = 0;
-
-       printk(KERN_INFO "%s: interrupts received:", ZR_DEVNAME(zr));
-       if ((res = zr->field_counter) < -1 || res > 1) {
-               printk(" FD:%d", res);
-       }
-       if ((res = zr->intr_counter_GIRQ1) != 0) {
-               printk(" GIRQ1:%d", res);
-               noerr++;
-       }
-       if ((res = zr->intr_counter_GIRQ0) != 0) {
-               printk(" GIRQ0:%d", res);
-               noerr++;
-       }
-       if ((res = zr->intr_counter_CodRepIRQ) != 0) {
-               printk(" CodRepIRQ:%d", res);
-               noerr++;
-       }
-       if ((res = zr->intr_counter_JPEGRepIRQ) != 0) {
-               printk(" JPEGRepIRQ:%d", res);
-               noerr++;
-       }
-       if (zr->JPEG_max_missed) {
-               printk(" JPEG delays: max=%d min=%d", zr->JPEG_max_missed,
-                      zr->JPEG_min_missed);
-       }
-       if (zr->END_event_missed) {
-               printk(" ENDs missed: %d", zr->END_event_missed);
-       }
-       //if (zr->jpg_queued_num) {
-       printk(" queue_state=%ld/%ld/%ld/%ld", zr->jpg_que_tail,
-              zr->jpg_dma_tail, zr->jpg_dma_head, zr->jpg_que_head);
-       //}
-       if (!noerr) {
-               printk(": no interrupts detected.");
-       }
-       printk("\n");
-}
-
-void
-clear_interrupt_counters (struct zoran *zr)
-{
-       zr->intr_counter_GIRQ1 = 0;
-       zr->intr_counter_GIRQ0 = 0;
-       zr->intr_counter_CodRepIRQ = 0;
-       zr->intr_counter_JPEGRepIRQ = 0;
-       zr->field_counter = 0;
-       zr->IRQ1_in = 0;
-       zr->IRQ1_out = 0;
-       zr->JPEG_in = 0;
-       zr->JPEG_out = 0;
-       zr->JPEG_0 = 0;
-       zr->JPEG_1 = 0;
-       zr->END_event_missed = 0;
-       zr->JPEG_missed = 0;
-       zr->JPEG_max_missed = 0;
-       zr->JPEG_min_missed = 0x7fffffff;
-}
-
-static u32
-count_reset_interrupt (struct zoran *zr)
-{
-       u32 isr;
-
-       if ((isr = btread(ZR36057_ISR) & 0x78000000)) {
-               if (isr & ZR36057_ISR_GIRQ1) {
-                       btwrite(ZR36057_ISR_GIRQ1, ZR36057_ISR);
-                       zr->intr_counter_GIRQ1++;
-               }
-               if (isr & ZR36057_ISR_GIRQ0) {
-                       btwrite(ZR36057_ISR_GIRQ0, ZR36057_ISR);
-                       zr->intr_counter_GIRQ0++;
-               }
-               if (isr & ZR36057_ISR_CodRepIRQ) {
-                       btwrite(ZR36057_ISR_CodRepIRQ, ZR36057_ISR);
-                       zr->intr_counter_CodRepIRQ++;
-               }
-               if (isr & ZR36057_ISR_JPEGRepIRQ) {
-                       btwrite(ZR36057_ISR_JPEGRepIRQ, ZR36057_ISR);
-                       zr->intr_counter_JPEGRepIRQ++;
-               }
-       }
-       return isr;
-}
-
-void
-jpeg_start (struct zoran *zr)
-{
-       int reg;
-
-       zr->frame_num = 0;
-
-       /* deassert P_reset, disable code transfer, deassert Active */
-       btwrite(ZR36057_JPC_P_Reset, ZR36057_JPC);
-       /* stop flushing the internal code buffer */
-       btand(~ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
-       /* enable code transfer */
-       btor(ZR36057_JPC_CodTrnsEn, ZR36057_JPC);
-
-       /* clear IRQs */
-       btwrite(IRQ_MASK, ZR36057_ISR);
-       /* enable the JPEG IRQs */
-       btwrite(zr->card.jpeg_int |
-                       ZR36057_ICR_JPEGRepIRQ |
-                       ZR36057_ICR_IntPinEn,
-               ZR36057_ICR);
-
-       set_frame(zr, 0);       // \FRAME
-
-       /* set the JPEG codec guest ID */
-       reg = (zr->card.gpcs[1] << ZR36057_JCGI_JPEGuestID) |
-              (0 << ZR36057_JCGI_JPEGuestReg);
-       btwrite(reg, ZR36057_JCGI);
-
-       if (zr->card.video_vfe == CODEC_TYPE_ZR36016 &&
-           zr->card.video_codec == CODEC_TYPE_ZR36050) {
-               /* Enable processing on the ZR36016 */
-               if (zr->vfe)
-                       zr36016_write(zr->vfe, 0, 1);
-
-               /* load the address of the GO register in the ZR36050 latch */
-               post_office_write(zr, 0, 0, 0);
-       }
-
-       /* assert Active */
-       btor(ZR36057_JPC_Active, ZR36057_JPC);
-
-       /* enable the Go generation */
-       btor(ZR36057_JMC_Go_en, ZR36057_JMC);
-       udelay(30);
-
-       set_frame(zr, 1);       // /FRAME
-
-       dprintk(3, KERN_DEBUG "%s: jpeg_start\n", ZR_DEVNAME(zr));
-}
-
-void
-zr36057_enable_jpg (struct zoran          *zr,
-                   enum zoran_codec_mode  mode)
-{
-       static int zero;
-       static int one = 1;
-       struct vfe_settings cap;
-       int field_size =
-           zr->jpg_buffers.buffer_size / zr->jpg_settings.field_per_buff;
-
-       zr->codec_mode = mode;
-
-       cap.x = zr->jpg_settings.img_x;
-       cap.y = zr->jpg_settings.img_y;
-       cap.width = zr->jpg_settings.img_width;
-       cap.height = zr->jpg_settings.img_height;
-       cap.decimation =
-           zr->jpg_settings.HorDcm | (zr->jpg_settings.VerDcm << 8);
-       cap.quality = zr->jpg_settings.jpg_comp.quality;
-
-       switch (mode) {
-
-       case BUZ_MODE_MOTION_COMPRESS: {
-               struct jpeg_app_marker app;
-               struct jpeg_com_marker com;
-
-               /* In motion compress mode, the decoder output must be enabled, and
-                * the video bus direction set to input.
-                */
-               set_videobus_dir(zr, 0);
-               decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
-               encoder_command(zr, ENCODER_SET_INPUT, &zero);
-
-               /* Take the JPEG codec and the VFE out of sleep */
-               jpeg_codec_sleep(zr, 0);
-
-               /* set JPEG app/com marker */
-               app.appn = zr->jpg_settings.jpg_comp.APPn;
-               app.len = zr->jpg_settings.jpg_comp.APP_len;
-               memcpy(app.data, zr->jpg_settings.jpg_comp.APP_data, 60);
-               zr->codec->control(zr->codec, CODEC_S_JPEG_APP_DATA,
-                                  sizeof(struct jpeg_app_marker), &app);
-
-               com.len = zr->jpg_settings.jpg_comp.COM_len;
-               memcpy(com.data, zr->jpg_settings.jpg_comp.COM_data, 60);
-               zr->codec->control(zr->codec, CODEC_S_JPEG_COM_DATA,
-                                  sizeof(struct jpeg_com_marker), &com);
-
-               /* Setup the JPEG codec */
-               zr->codec->control(zr->codec, CODEC_S_JPEG_TDS_BYTE,
-                                  sizeof(int), &field_size);
-               zr->codec->set_video(zr->codec, zr->timing, &cap,
-                                    &zr->card.vfe_pol);
-               zr->codec->set_mode(zr->codec, CODEC_DO_COMPRESSION);
-
-               /* Setup the VFE */
-               if (zr->vfe) {
-                       zr->vfe->control(zr->vfe, CODEC_S_JPEG_TDS_BYTE,
-                                        sizeof(int), &field_size);
-                       zr->vfe->set_video(zr->vfe, zr->timing, &cap,
-                                          &zr->card.vfe_pol);
-                       zr->vfe->set_mode(zr->vfe, CODEC_DO_COMPRESSION);
-               }
-
-               init_jpeg_queue(zr);
-               zr36057_set_jpg(zr, mode);      // \P_Reset, ... Video param, FIFO
-
-               clear_interrupt_counters(zr);
-               dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_COMPRESS)\n",
-                       ZR_DEVNAME(zr));
-               break;
-       }
-
-       case BUZ_MODE_MOTION_DECOMPRESS:
-               /* In motion decompression mode, the decoder output must be disabled, and
-                * the video bus direction set to output.
-                */
-               decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
-               set_videobus_dir(zr, 1);
-               encoder_command(zr, ENCODER_SET_INPUT, &one);
-
-               /* Take the JPEG codec and the VFE out of sleep */
-               jpeg_codec_sleep(zr, 0);
-               /* Setup the VFE */
-               if (zr->vfe) {
-                       zr->vfe->set_video(zr->vfe, zr->timing, &cap,
-                                          &zr->card.vfe_pol);
-                       zr->vfe->set_mode(zr->vfe, CODEC_DO_EXPANSION);
-               }
-               /* Setup the JPEG codec */
-               zr->codec->set_video(zr->codec, zr->timing, &cap,
-                                    &zr->card.vfe_pol);
-               zr->codec->set_mode(zr->codec, CODEC_DO_EXPANSION);
-
-               init_jpeg_queue(zr);
-               zr36057_set_jpg(zr, mode);      // \P_Reset, ... Video param, FIFO
-
-               clear_interrupt_counters(zr);
-               dprintk(2, KERN_INFO "%s: enable_jpg(MOTION_DECOMPRESS)\n",
-                       ZR_DEVNAME(zr));
-               break;
-
-       case BUZ_MODE_IDLE:
-       default:
-               /* shut down processing */
-               btand(~(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ),
-                     ZR36057_ICR);
-               btwrite(zr->card.jpeg_int | ZR36057_ICR_JPEGRepIRQ,
-                       ZR36057_ISR);
-               btand(~ZR36057_JMC_Go_en, ZR36057_JMC); // \Go_en
-
-               msleep(50);
-
-               set_videobus_dir(zr, 0);
-               set_frame(zr, 1);       // /FRAME
-               btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);      // /CFlush
-               btwrite(0, ZR36057_JPC);        // \P_Reset,\CodTrnsEn,\Active
-               btand(~ZR36057_JMC_VFIFO_FB, ZR36057_JMC);
-               btand(~ZR36057_JMC_SyncMstr, ZR36057_JMC);
-               jpeg_codec_reset(zr);
-               jpeg_codec_sleep(zr, 1);
-               zr36057_adjust_vfe(zr, mode);
-
-               decoder_command(zr, DECODER_ENABLE_OUTPUT, &one);
-               encoder_command(zr, ENCODER_SET_INPUT, &zero);
-
-               dprintk(2, KERN_INFO "%s: enable_jpg(IDLE)\n", ZR_DEVNAME(zr));
-               break;
-
-       }
-}
-
-/* when this is called the spinlock must be held */
-void
-zoran_feed_stat_com (struct zoran *zr)
-{
-       /* move frames from pending queue to DMA */
-
-       int frame, i, max_stat_com;
-
-       max_stat_com =
-           (zr->jpg_settings.TmpDcm ==
-            1) ? BUZ_NUM_STAT_COM : (BUZ_NUM_STAT_COM >> 1);
-
-       while ((zr->jpg_dma_head - zr->jpg_dma_tail) < max_stat_com &&
-              zr->jpg_dma_head < zr->jpg_que_head) {
-
-               frame = zr->jpg_pend[zr->jpg_dma_head & BUZ_MASK_FRAME];
-               if (zr->jpg_settings.TmpDcm == 1) {
-                       /* fill 1 stat_com entry */
-                       i = (zr->jpg_dma_head -
-                            zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
-                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
-                               break;
-                       zr->stat_com[i] =
-                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
-               } else {
-                       /* fill 2 stat_com entries */
-                       i = ((zr->jpg_dma_head -
-                             zr->jpg_err_shift) & 1) * 2;
-                       if (!(zr->stat_com[i] & cpu_to_le32(1)))
-                               break;
-                       zr->stat_com[i] =
-                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
-                       zr->stat_com[i + 1] =
-                           cpu_to_le32(zr->jpg_buffers.buffer[frame].frag_tab_bus);
-               }
-               zr->jpg_buffers.buffer[frame].state = BUZ_STATE_DMA;
-               zr->jpg_dma_head++;
-
-       }
-       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS)
-               zr->jpg_queued_num++;
-}
-
-/* when this is called the spinlock must be held */
-static void
-zoran_reap_stat_com (struct zoran *zr)
-{
-       /* move frames from DMA queue to done queue */
-
-       int i;
-       u32 stat_com;
-       unsigned int seq;
-       unsigned int dif;
-       struct zoran_jpg_buffer *buffer;
-       int frame;
-
-       /* In motion decompress we don't have a hardware frame counter,
-        * we just count the interrupts here */
-
-       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
-               zr->jpg_seq_num++;
-       }
-       while (zr->jpg_dma_tail < zr->jpg_dma_head) {
-               if (zr->jpg_settings.TmpDcm == 1)
-                       i = (zr->jpg_dma_tail -
-                            zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
-               else
-                       i = ((zr->jpg_dma_tail -
-                             zr->jpg_err_shift) & 1) * 2 + 1;
-
-               stat_com = le32_to_cpu(zr->stat_com[i]);
-
-               if ((stat_com & 1) == 0) {
-                       return;
-               }
-               frame = zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
-               buffer = &zr->jpg_buffers.buffer[frame];
-               do_gettimeofday(&buffer->bs.timestamp);
-
-               if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
-                       buffer->bs.length = (stat_com & 0x7fffff) >> 1;
-
-                       /* update sequence number with the help of the counter in stat_com */
-
-                       seq = ((stat_com >> 24) + zr->jpg_err_seq) & 0xff;
-                       dif = (seq - zr->jpg_seq_num) & 0xff;
-                       zr->jpg_seq_num += dif;
-               } else {
-                       buffer->bs.length = 0;
-               }
-               buffer->bs.seq =
-                   zr->jpg_settings.TmpDcm ==
-                   2 ? (zr->jpg_seq_num >> 1) : zr->jpg_seq_num;
-               buffer->state = BUZ_STATE_DONE;
-
-               zr->jpg_dma_tail++;
-       }
-}
-
-static void
-error_handler (struct zoran *zr,
-              u32           astat,
-              u32           stat)
-{
-       /* This is JPEG error handling part */
-       if ((zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) &&
-           (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS)) {
-               //dprintk(1, KERN_ERR "%s: Internal error: error handling request in mode %d\n", ZR_DEVNAME(zr), zr->codec_mode);
-               return;
-       }
-
-       if ((stat & 1) == 0 &&
-           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS &&
-           zr->jpg_dma_tail - zr->jpg_que_tail >=
-            zr->jpg_buffers.num_buffers) {
-               /* No free buffers... */
-               zoran_reap_stat_com(zr);
-               zoran_feed_stat_com(zr);
-               wake_up_interruptible(&zr->jpg_capq);
-               zr->JPEG_missed = 0;
-               return;
-       }
-
-       if (zr->JPEG_error != 1) {
-               /*
-                * First entry: error just happened during normal operation
-                *
-                * In BUZ_MODE_MOTION_COMPRESS:
-                *
-                * Possible glitch in TV signal. In this case we should
-                * stop the codec and wait for good quality signal before
-                * restarting it to avoid further problems
-                *
-                * In BUZ_MODE_MOTION_DECOMPRESS:
-                *
-                * Bad JPEG frame: we have to mark it as processed (codec crashed
-                * and was not able to do it itself), and to remove it from queue.
-                */
-               btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
-               udelay(1);
-               stat = stat | (post_office_read(zr, 7, 0) & 3) << 8;
-               btwrite(0, ZR36057_JPC);
-               btor(ZR36057_MCTCR_CFlush, ZR36057_MCTCR);
-               jpeg_codec_reset(zr);
-               jpeg_codec_sleep(zr, 1);
-               zr->JPEG_error = 1;
-               zr->num_errors++;
-
-               /* Report error */
-               if (zr36067_debug > 1 && zr->num_errors <= 8) {
-                       long frame;
-                       frame =
-                           zr->jpg_pend[zr->jpg_dma_tail & BUZ_MASK_FRAME];
-                       printk(KERN_ERR
-                              "%s: JPEG error stat=0x%08x(0x%08x) queue_state=%ld/%ld/%ld/%ld seq=%ld frame=%ld. Codec stopped. ",
-                              ZR_DEVNAME(zr), stat, zr->last_isr,
-                              zr->jpg_que_tail, zr->jpg_dma_tail,
-                              zr->jpg_dma_head, zr->jpg_que_head,
-                              zr->jpg_seq_num, frame);
-                       printk("stat_com frames:");
-                       {
-                               int i, j;
-                               for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
-                                       for (i = 0;
-                                            i < zr->jpg_buffers.num_buffers;
-                                            i++) {
-                                               if (le32_to_cpu(zr->stat_com[j]) ==
-                                                   zr->jpg_buffers.
-                                                   buffer[i].
-                                                   frag_tab_bus) {
-                                                       printk("% d->%d",
-                                                              j, i);
-                                               }
-                                       }
-                               }
-                               printk("\n");
-                       }
-               }
-               /* Find an entry in stat_com and rotate contents */
-               {
-                       int i;
-
-                       if (zr->jpg_settings.TmpDcm == 1)
-                               i = (zr->jpg_dma_tail -
-                                    zr->jpg_err_shift) & BUZ_MASK_STAT_COM;
-                       else
-                               i = ((zr->jpg_dma_tail -
-                                     zr->jpg_err_shift) & 1) * 2;
-                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) {
-                               /* Mimic zr36067 operation */
-                               zr->stat_com[i] |= cpu_to_le32(1);
-                               if (zr->jpg_settings.TmpDcm != 1)
-                                       zr->stat_com[i + 1] |= cpu_to_le32(1);
-                               /* Refill */
-                               zoran_reap_stat_com(zr);
-                               zoran_feed_stat_com(zr);
-                               wake_up_interruptible(&zr->jpg_capq);
-                               /* Find an entry in stat_com again after refill */
-                               if (zr->jpg_settings.TmpDcm == 1)
-                                       i = (zr->jpg_dma_tail -
-                                            zr->jpg_err_shift) &
-                                           BUZ_MASK_STAT_COM;
-                               else
-                                       i = ((zr->jpg_dma_tail -
-                                             zr->jpg_err_shift) & 1) * 2;
-                       }
-                       if (i) {
-                               /* Rotate stat_comm entries to make current entry first */
-                               int j;
-                               __le32 bus_addr[BUZ_NUM_STAT_COM];
-
-                               /* Here we are copying the stat_com array, which
-                                * is already in little endian format, so
-                                * no endian conversions here
-                                */
-                               memcpy(bus_addr, zr->stat_com,
-                                      sizeof(bus_addr));
-                               for (j = 0; j < BUZ_NUM_STAT_COM; j++) {
-                                       zr->stat_com[j] =
-                                           bus_addr[(i + j) &
-                                                    BUZ_MASK_STAT_COM];
-
-                               }
-                               zr->jpg_err_shift += i;
-                               zr->jpg_err_shift &= BUZ_MASK_STAT_COM;
-                       }
-                       if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS)
-                               zr->jpg_err_seq = zr->jpg_seq_num;      /* + 1; */
-               }
-       }
-
-       /* Now the stat_comm buffer is ready for restart */
-       do {
-               int status, mode;
-
-               if (zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
-                       decoder_command(zr, DECODER_GET_STATUS, &status);
-                       mode = CODEC_DO_COMPRESSION;
-               } else {
-                       status = 0;
-                       mode = CODEC_DO_EXPANSION;
-               }
-               if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
-                   (status & DECODER_STATUS_GOOD)) {
-                       /********** RESTART code *************/
-                       jpeg_codec_reset(zr);
-                       zr->codec->set_mode(zr->codec, mode);
-                       zr36057_set_jpg(zr, zr->codec_mode);
-                       jpeg_start(zr);
-
-                       if (zr->num_errors <= 8)
-                               dprintk(2, KERN_INFO "%s: Restart\n",
-                                       ZR_DEVNAME(zr));
-
-                       zr->JPEG_missed = 0;
-                       zr->JPEG_error = 2;
-                       /********** End RESTART code ***********/
-               }
-       } while (0);
-}
-
-irqreturn_t
-zoran_irq (int             irq,
-          void           *dev_id)
-{
-       u32 stat, astat;
-       int count;
-       struct zoran *zr;
-       unsigned long flags;
-
-       zr = dev_id;
-       count = 0;
-
-       if (zr->testing) {
-               /* Testing interrupts */
-               spin_lock_irqsave(&zr->spinlock, flags);
-               while ((stat = count_reset_interrupt(zr))) {
-                       if (count++ > 100) {
-                               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: IRQ lockup while testing, isr=0x%08x, cleared int mask\n",
-                                       ZR_DEVNAME(zr), stat);
-                               wake_up_interruptible(&zr->test_q);
-                       }
-               }
-               zr->last_isr = stat;
-               spin_unlock_irqrestore(&zr->spinlock, flags);
-               return IRQ_HANDLED;
-       }
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-       while (1) {
-               /* get/clear interrupt status bits */
-               stat = count_reset_interrupt(zr);
-               astat = stat & IRQ_MASK;
-               if (!astat) {
-                       break;
-               }
-               dprintk(4,
-                       KERN_DEBUG
-                       "zoran_irq: astat: 0x%08x, mask: 0x%08x\n",
-                       astat, btread(ZR36057_ICR));
-               if (astat & zr->card.vsync_int) {       // SW
-
-                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
-                           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
-                               /* count missed interrupts */
-                               zr->JPEG_missed++;
-                       }
-                       //post_office_read(zr,1,0);
-                       /* Interrupts may still happen when
-                        * zr->v4l_memgrab_active is switched off.
-                        * We simply ignore them */
-
-                       if (zr->v4l_memgrab_active) {
-
-                               /* A lot more checks should be here ... */
-                               if ((btread(ZR36057_VSSFGR) &
-                                    ZR36057_VSSFGR_SnapShot) == 0)
-                                       dprintk(1,
-                                               KERN_WARNING
-                                               "%s: BuzIRQ with SnapShot off ???\n",
-                                               ZR_DEVNAME(zr));
-
-                               if (zr->v4l_grab_frame != NO_GRAB_ACTIVE) {
-                                       /* There is a grab on a frame going on, check if it has finished */
-
-                                       if ((btread(ZR36057_VSSFGR) &
-                                            ZR36057_VSSFGR_FrameGrab) ==
-                                           0) {
-                                               /* it is finished, notify the user */
-
-                                               zr->v4l_buffers.buffer[zr->v4l_grab_frame].state = BUZ_STATE_DONE;
-                                               zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.seq = zr->v4l_grab_seq;
-                                               do_gettimeofday(&zr->v4l_buffers.buffer[zr->v4l_grab_frame].bs.timestamp);
-                                               zr->v4l_grab_frame = NO_GRAB_ACTIVE;
-                                               zr->v4l_pend_tail++;
-                                       }
-                               }
-
-                               if (zr->v4l_grab_frame == NO_GRAB_ACTIVE)
-                                       wake_up_interruptible(&zr->v4l_capq);
-
-                               /* Check if there is another grab queued */
-
-                               if (zr->v4l_grab_frame == NO_GRAB_ACTIVE &&
-                                   zr->v4l_pend_tail != zr->v4l_pend_head) {
-
-                                       int frame = zr->v4l_pend[zr->v4l_pend_tail &
-                                                        V4L_MASK_FRAME];
-                                       u32 reg;
-
-                                       zr->v4l_grab_frame = frame;
-
-                                       /* Set zr36057 video front end and enable video */
-
-                                       /* Buffer address */
-
-                                       reg =
-                                           zr->v4l_buffers.buffer[frame].
-                                           fbuffer_bus;
-                                       btwrite(reg, ZR36057_VDTR);
-                                       if (zr->v4l_settings.height >
-                                           BUZ_MAX_HEIGHT / 2)
-                                               reg +=
-                                                   zr->v4l_settings.
-                                                   bytesperline;
-                                       btwrite(reg, ZR36057_VDBR);
-
-                                       /* video stride, status, and frame grab register */
-                                       reg = 0;
-                                       if (zr->v4l_settings.height >
-                                           BUZ_MAX_HEIGHT / 2)
-                                               reg +=
-                                                   zr->v4l_settings.
-                                                   bytesperline;
-                                       reg =
-                                           (reg <<
-                                            ZR36057_VSSFGR_DispStride);
-                                       reg |= ZR36057_VSSFGR_VidOvf;
-                                       reg |= ZR36057_VSSFGR_SnapShot;
-                                       reg |= ZR36057_VSSFGR_FrameGrab;
-                                       btwrite(reg, ZR36057_VSSFGR);
-
-                                       btor(ZR36057_VDCR_VidEn,
-                                            ZR36057_VDCR);
-                               }
-                       }
-
-                       /* even if we don't grab, we do want to increment
-                        * the sequence counter to see lost frames */
-                       zr->v4l_grab_seq++;
-               }
-#if (IRQ_MASK & ZR36057_ISR_CodRepIRQ)
-               if (astat & ZR36057_ISR_CodRepIRQ) {
-                       zr->intr_counter_CodRepIRQ++;
-                       IDEBUG(printk
-                              (KERN_DEBUG "%s: ZR36057_ISR_CodRepIRQ\n",
-                               ZR_DEVNAME(zr)));
-                       btand(~ZR36057_ICR_CodRepIRQ, ZR36057_ICR);
-               }
-#endif                         /* (IRQ_MASK & ZR36057_ISR_CodRepIRQ) */
-
-#if (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ)
-               if (astat & ZR36057_ISR_JPEGRepIRQ) {
-
-                       if (zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS ||
-                           zr->codec_mode == BUZ_MODE_MOTION_COMPRESS) {
-                               if (zr36067_debug > 1 &&
-                                   (!zr->frame_num || zr->JPEG_error)) {
-                                       printk(KERN_INFO
-                                              "%s: first frame ready: state=0x%08x odd_even=%d field_per_buff=%d delay=%d\n",
-                                              ZR_DEVNAME(zr), stat,
-                                              zr->jpg_settings.odd_even,
-                                              zr->jpg_settings.
-                                              field_per_buff,
-                                              zr->JPEG_missed);
-                                       {
-                                               char sc[] = "0000";
-                                               char sv[5];
-                                               int i;
-                                               strcpy(sv, sc);
-                                               for (i = 0; i < 4; i++) {
-                                                       if (le32_to_cpu(zr->stat_com[i]) & 1)
-                                                               sv[i] = '1';
-                                               }
-                                               sv[4] = 0;
-                                               printk(KERN_INFO
-                                                      "%s: stat_com=%s queue_state=%ld/%ld/%ld/%ld\n",
-                                                      ZR_DEVNAME(zr), sv,
-                                                      zr->jpg_que_tail,
-                                                      zr->jpg_dma_tail,
-                                                      zr->jpg_dma_head,
-                                                      zr->jpg_que_head);
-                                       }
-                               } else {
-                                       if (zr->JPEG_missed > zr->JPEG_max_missed)      // Get statistics
-                                               zr->JPEG_max_missed =
-                                                   zr->JPEG_missed;
-                                       if (zr->JPEG_missed <
-                                           zr->JPEG_min_missed)
-                                               zr->JPEG_min_missed =
-                                                   zr->JPEG_missed;
-                               }
-
-                               if (zr36067_debug > 2 && zr->frame_num < 6) {
-                                       int i;
-                                       printk("%s: seq=%ld stat_com:",
-                                              ZR_DEVNAME(zr), zr->jpg_seq_num);
-                                       for (i = 0; i < 4; i++) {
-                                               printk(" %08x",
-                                                      le32_to_cpu(zr->stat_com[i]));
-                                       }
-                                       printk("\n");
-                               }
-                               zr->frame_num++;
-                               zr->JPEG_missed = 0;
-                               zr->JPEG_error = 0;
-                               zoran_reap_stat_com(zr);
-                               zoran_feed_stat_com(zr);
-                               wake_up_interruptible(&zr->jpg_capq);
-                       } /*else {
-                             dprintk(1,
-                                       KERN_ERR
-                                       "%s: JPEG interrupt while not in motion (de)compress mode!\n",
-                                       ZR_DEVNAME(zr));
-                       }*/
-               }
-#endif                         /* (IRQ_MASK & ZR36057_ISR_JPEGRepIRQ) */
-
-               /* DATERR, too many fields missed, error processing */
-               if ((astat & zr->card.jpeg_int) ||
-                   zr->JPEG_missed > 25 ||
-                   zr->JPEG_error == 1 ||
-                   ((zr->codec_mode == BUZ_MODE_MOTION_DECOMPRESS) &&
-                    (zr->frame_num & (zr->JPEG_missed >
-                                      zr->jpg_settings.field_per_buff)))) {
-                       error_handler(zr, astat, stat);
-               }
-
-               count++;
-               if (count > 10) {
-                       dprintk(2, KERN_WARNING "%s: irq loop %d\n",
-                               ZR_DEVNAME(zr), count);
-                       if (count > 20) {
-                               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
-                               dprintk(2,
-                                       KERN_ERR
-                                       "%s: IRQ lockup, cleared int mask\n",
-                                       ZR_DEVNAME(zr));
-                               break;
-                       }
-               }
-               zr->last_isr = stat;
-       }
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       return IRQ_HANDLED;
-}
-
-void
-zoran_set_pci_master (struct zoran *zr,
-                     int           set_master)
-{
-       if (set_master) {
-               pci_set_master(zr->pci_dev);
-       } else {
-               u16 command;
-
-               pci_read_config_word(zr->pci_dev, PCI_COMMAND, &command);
-               command &= ~PCI_COMMAND_MASTER;
-               pci_write_config_word(zr->pci_dev, PCI_COMMAND, command);
-       }
-}
-
-void
-zoran_init_hardware (struct zoran *zr)
-{
-       int j, zero = 0;
-
-       /* Enable bus-mastering */
-       zoran_set_pci_master(zr, 1);
-
-       /* Initialize the board */
-       if (zr->card.init) {
-               zr->card.init(zr);
-       }
-
-       j = zr->card.input[zr->input].muxsel;
-
-       decoder_command(zr, 0, NULL);
-       decoder_command(zr, DECODER_SET_NORM, &zr->norm);
-       decoder_command(zr, DECODER_SET_INPUT, &j);
-
-       encoder_command(zr, 0, NULL);
-       encoder_command(zr, ENCODER_SET_NORM, &zr->norm);
-       encoder_command(zr, ENCODER_SET_INPUT, &zero);
-
-       /* toggle JPEG codec sleep to sync PLL */
-       jpeg_codec_sleep(zr, 1);
-       jpeg_codec_sleep(zr, 0);
-
-       /* set individual interrupt enables (without GIRQ1)
-        * but don't global enable until zoran_open() */
-
-       //btwrite(IRQ_MASK & ~ZR36057_ISR_GIRQ1, ZR36057_ICR);  // SW
-       // It looks like using only JPEGRepIRQEn is not always reliable,
-       // may be when JPEG codec crashes it won't generate IRQ? So,
-        /*CP*/                 //        btwrite(IRQ_MASK, ZR36057_ICR); // Enable Vsync interrupts too. SM    WHY ? LP
-           zr36057_init_vfe(zr);
-
-       zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
-
-       btwrite(IRQ_MASK, ZR36057_ISR); // Clears interrupts
-}
-
-void
-zr36057_restart (struct zoran *zr)
-{
-       btwrite(0, ZR36057_SPGPPCR);
-       mdelay(1);
-       btor(ZR36057_SPGPPCR_SoftReset, ZR36057_SPGPPCR);
-       mdelay(1);
-
-       /* assert P_Reset */
-       btwrite(0, ZR36057_JPC);
-       /* set up GPIO direction - all output */
-       btwrite(ZR36057_SPGPPCR_SoftReset | 0, ZR36057_SPGPPCR);
-
-       /* set up GPIO pins and guest bus timing */
-       btwrite((0x81 << 24) | 0x8888, ZR36057_GPPGCR1);
-}
-
-/*
- * initialize video front end
- */
-
-static void
-zr36057_init_vfe (struct zoran *zr)
-{
-       u32 reg;
-
-       reg = btread(ZR36057_VFESPFR);
-       reg |= ZR36057_VFESPFR_LittleEndian;
-       reg &= ~ZR36057_VFESPFR_VCLKPol;
-       reg |= ZR36057_VFESPFR_ExtFl;
-       reg |= ZR36057_VFESPFR_TopField;
-       btwrite(reg, ZR36057_VFESPFR);
-       reg = btread(ZR36057_VDCR);
-       if (pci_pci_problems & PCIPCI_TRITON)
-               // || zr->revision < 1) // Revision 1 has also Triton support
-               reg &= ~ZR36057_VDCR_Triton;
-       else
-               reg |= ZR36057_VDCR_Triton;
-       btwrite(reg, ZR36057_VDCR);
-}
-
-/*
- * Interface to decoder and encoder chips using i2c bus
- */
-
-int
-decoder_command (struct zoran *zr,
-                int           cmd,
-                void         *data)
-{
-       if (zr->decoder == NULL)
-               return -EIO;
-
-       if (zr->card.type == LML33 &&
-           (cmd == DECODER_SET_NORM || cmd == DECODER_SET_INPUT)) {
-               int res;
-
-               // Bt819 needs to reset its FIFO buffer using #FRST pin and
-               // LML33 card uses GPIO(7) for that.
-               GPIO(zr, 7, 0);
-               res = zr->decoder->driver->command(zr->decoder, cmd, data);
-               // Pull #FRST high.
-               GPIO(zr, 7, 1);
-               return res;
-       } else
-               return zr->decoder->driver->command(zr->decoder, cmd,
-                                                   data);
-}
-
-int
-encoder_command (struct zoran *zr,
-                int           cmd,
-                void         *data)
-{
-       if (zr->encoder == NULL)
-               return -1;
-
-       return zr->encoder->driver->command(zr->encoder, cmd, data);
-}
diff --git a/drivers/media/video/zoran_device.h b/drivers/media/video/zoran_device.h
deleted file mode 100644 (file)
index 37fa86a..0000000
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles card-specific data and detection
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __ZORAN_DEVICE_H__
-#define __ZORAN_DEVICE_H__
-
-/* general purpose I/O */
-extern void GPIO(struct zoran *zr,
-                int bit,
-                unsigned int value);
-
-/* codec (or actually: guest bus) access */
-extern int post_office_wait(struct zoran *zr);
-extern int post_office_write(struct zoran *zr,
-                            unsigned guest,
-                            unsigned reg,
-                            unsigned value);
-extern int post_office_read(struct zoran *zr,
-                           unsigned guest,
-                           unsigned reg);
-
-extern void detect_guest_activity(struct zoran *zr);
-
-extern void jpeg_codec_sleep(struct zoran *zr,
-                            int sleep);
-extern int jpeg_codec_reset(struct zoran *zr);
-
-/* zr360x7 access to raw capture */
-extern void zr36057_overlay(struct zoran *zr,
-                           int on);
-extern void write_overlay_mask(struct file *file,
-                              struct video_clip *vp,
-                              int count);
-extern void zr36057_set_memgrab(struct zoran *zr,
-                               int mode);
-extern int wait_grab_pending(struct zoran *zr);
-
-/* interrupts */
-extern void print_interrupts(struct zoran *zr);
-extern void clear_interrupt_counters(struct zoran *zr);
-extern irqreturn_t zoran_irq(int irq, void *dev_id);
-
-/* JPEG codec access */
-extern void jpeg_start(struct zoran *zr);
-extern void zr36057_enable_jpg(struct zoran *zr,
-                              enum zoran_codec_mode mode);
-extern void zoran_feed_stat_com(struct zoran *zr);
-
-/* general */
-extern void zoran_set_pci_master(struct zoran *zr,
-                                int set_master);
-extern void zoran_init_hardware(struct zoran *zr);
-extern void zr36057_restart(struct zoran *zr);
-
-/* i2c */
-extern int decoder_command(struct zoran *zr,
-                          int cmd,
-                          void *data);
-extern int encoder_command(struct zoran *zr,
-                          int cmd,
-                          void *data);
-
-#endif                         /* __ZORAN_DEVICE_H__ */
diff --git a/drivers/media/video/zoran_driver.c b/drivers/media/video/zoran_driver.c
deleted file mode 100644 (file)
index 2dab9ee..0000000
+++ /dev/null
@@ -1,4648 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Changes for BUZ by Wolfgang Scherr <scherr@net4you.net>
- *
- * Changes for DC10/DC30 by Laurent Pinchart <laurent.pinchart@skynet.be>
- *
- * Changes for LML33R10 by Maxim Yevtyushkin <max@linuxmedialabs.com>
- *
- * Changes for videodev2/v4l2 by Ronald Bultje <rbultje@ronald.bitfreak.net>
- *
- * Based on
- *
- * Miro DC10 driver
- * Copyright (C) 1999 Wolfgang Scherr <scherr@net4you.net>
- *
- * Iomega Buz driver version 1.0
- * Copyright (C) 1999 Rainer Johanni <Rainer@Johanni.de>
- *
- * buz.0.0.3
- * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
- *
- * bttv - Bt848 frame grabber driver
- * Copyright (C) 1996,97,98 Ralph  Metzler (rjkm@thp.uni-koeln.de)
- *                        & Marcus Metzler (mocm@thp.uni-koeln.de)
- *
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/version.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/delay.h>
-#include <linux/slab.h>
-#include <linux/pci.h>
-#include <linux/vmalloc.h>
-#include <linux/wait.h>
-
-#include <linux/interrupt.h>
-#include <linux/i2c.h>
-#include <linux/i2c-algo-bit.h>
-
-#include <linux/spinlock.h>
-#define     MAP_NR(x)       virt_to_page(x)
-#define     ZORAN_VID_TYPE  ( \
-                               VID_TYPE_CAPTURE | \
-                               VID_TYPE_OVERLAY | \
-                               VID_TYPE_CLIPPING | \
-                               VID_TYPE_FRAMERAM | \
-                               VID_TYPE_SCALES | \
-                               VID_TYPE_MJPEG_DECODER | \
-                               VID_TYPE_MJPEG_ENCODER \
-                            )
-
-#include <linux/videodev.h>
-#include <media/v4l2-common.h>
-#include <media/v4l2-ioctl.h>
-#include "videocodec.h"
-
-#include <asm/byteorder.h>
-#include <asm/io.h>
-#include <asm/uaccess.h>
-#include <linux/proc_fs.h>
-
-#include <linux/video_decoder.h>
-#include <linux/video_encoder.h>
-#include <linux/mutex.h>
-#include "zoran.h"
-#include "zoran_device.h"
-#include "zoran_card.h"
-
-       /* we declare some card type definitions here, they mean
-        * the same as the v4l1 ZORAN_VID_TYPE above, except it's v4l2 */
-#define ZORAN_V4L2_VID_FLAGS ( \
-                               V4L2_CAP_STREAMING |\
-                               V4L2_CAP_VIDEO_CAPTURE |\
-                               V4L2_CAP_VIDEO_OUTPUT |\
-                               V4L2_CAP_VIDEO_OVERLAY \
-                             )
-
-
-#if defined(CONFIG_VIDEO_V4L1_COMPAT)
-#define ZFMT(pal, fcc, cs) \
-       .palette = (pal), .fourcc = (fcc), .colorspace = (cs)
-#else
-#define ZFMT(pal, fcc, cs) \
-       .fourcc = (fcc), .colorspace = (cs)
-#endif
-
-const struct zoran_format zoran_formats[] = {
-       {
-               .name = "15-bit RGB LE",
-               ZFMT(VIDEO_PALETTE_RGB555,
-                    V4L2_PIX_FMT_RGB555, V4L2_COLORSPACE_SRGB),
-               .depth = 15,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif|
-                          ZR36057_VFESPFR_LittleEndian,
-       }, {
-               .name = "15-bit RGB BE",
-               ZFMT(-1,
-                    V4L2_PIX_FMT_RGB555X, V4L2_COLORSPACE_SRGB),
-               .depth = 15,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB555|ZR36057_VFESPFR_ErrDif,
-       }, {
-               .name = "16-bit RGB LE",
-               ZFMT(VIDEO_PALETTE_RGB565,
-                    V4L2_PIX_FMT_RGB565, V4L2_COLORSPACE_SRGB),
-               .depth = 16,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif|
-                          ZR36057_VFESPFR_LittleEndian,
-       }, {
-               .name = "16-bit RGB BE",
-               ZFMT(-1,
-                    V4L2_PIX_FMT_RGB565X, V4L2_COLORSPACE_SRGB),
-               .depth = 16,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB565|ZR36057_VFESPFR_ErrDif,
-       }, {
-               .name = "24-bit RGB",
-               ZFMT(VIDEO_PALETTE_RGB24,
-                    V4L2_PIX_FMT_BGR24, V4L2_COLORSPACE_SRGB),
-               .depth = 24,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_Pack24,
-       }, {
-               .name = "32-bit RGB LE",
-               ZFMT(VIDEO_PALETTE_RGB32,
-                    V4L2_PIX_FMT_BGR32, V4L2_COLORSPACE_SRGB),
-               .depth = 32,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB888|ZR36057_VFESPFR_LittleEndian,
-       }, {
-               .name = "32-bit RGB BE",
-               ZFMT(-1,
-                    V4L2_PIX_FMT_RGB32, V4L2_COLORSPACE_SRGB),
-               .depth = 32,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_RGB888,
-       }, {
-               .name = "4:2:2, packed, YUYV",
-               ZFMT(VIDEO_PALETTE_YUV422,
-                    V4L2_PIX_FMT_YUYV, V4L2_COLORSPACE_SMPTE170M),
-               .depth = 16,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_YUV422,
-       }, {
-               .name = "4:2:2, packed, UYVY",
-               ZFMT(VIDEO_PALETTE_UYVY,
-                    V4L2_PIX_FMT_UYVY, V4L2_COLORSPACE_SMPTE170M),
-               .depth = 16,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_OVERLAY,
-               .vfespfr = ZR36057_VFESPFR_YUV422|ZR36057_VFESPFR_LittleEndian,
-       }, {
-               .name = "Hardware-encoded Motion-JPEG",
-               ZFMT(-1,
-                    V4L2_PIX_FMT_MJPEG, V4L2_COLORSPACE_SMPTE170M),
-               .depth = 0,
-               .flags = ZORAN_FORMAT_CAPTURE |
-                        ZORAN_FORMAT_PLAYBACK |
-                        ZORAN_FORMAT_COMPRESSED,
-       }
-};
-#define NUM_FORMATS ARRAY_SIZE(zoran_formats)
-
-// RJ: Test only - want to test BUZ_USE_HIMEM even when CONFIG_BIGPHYS_AREA is defined
-
-
-extern int v4l_nbufs;
-extern int v4l_bufsize;
-extern int jpg_nbufs;
-extern int jpg_bufsize;
-extern int pass_through;
-
-static int lock_norm;  /* 0 = default 1 = Don't change TV standard (norm) */
-module_param(lock_norm, int, 0644);
-MODULE_PARM_DESC(lock_norm, "Prevent norm changes (1 = ignore, >1 = fail)");
-
-       /* small helper function for calculating buffersizes for v4l2
-        * we calculate the nearest higher power-of-two, which
-        * will be the recommended buffersize */
-static __u32
-zoran_v4l2_calc_bufsize (struct zoran_jpg_settings *settings)
-{
-       __u8 div = settings->VerDcm * settings->HorDcm * settings->TmpDcm;
-       __u32 num = (1024 * 512) / (div);
-       __u32 result = 2;
-
-       num--;
-       while (num) {
-               num >>= 1;
-               result <<= 1;
-       }
-
-       if (result > jpg_bufsize)
-               return jpg_bufsize;
-       if (result < 8192)
-               return 8192;
-       return result;
-}
-
-/* forward references */
-static void v4l_fbuffer_free(struct file *file);
-static void jpg_fbuffer_free(struct file *file);
-
-/*
- *   Allocate the V4L grab buffers
- *
- *   These have to be pysically contiguous.
- *   If v4l_bufsize <= MAX_KMALLOC_MEM we use kmalloc
- *   else we try to allocate them with bigphysarea_alloc_pages
- *   if the bigphysarea patch is present in the kernel,
- *   else we try to use high memory (if the user has bootet
- *   Linux with the necessary memory left over).
- */
-
-static unsigned long
-get_high_mem (unsigned long size)
-{
-/*
- * Check if there is usable memory at the end of Linux memory
- * of at least size. Return the physical address of this memory,
- * return 0 on failure.
- *
- * The idea is from Alexandro Rubini's book "Linux device drivers".
- * The driver from him which is downloadable from O'Reilly's
- * web site misses the "virt_to_phys(high_memory)" part
- * (and therefore doesn't work at all - at least with 2.2.x kernels).
- *
- * It should be unnecessary to mention that THIS IS DANGEROUS,
- * if more than one driver at a time has the idea to use this memory!!!!
- */
-
-       volatile unsigned char __iomem *mem;
-       unsigned char c;
-       unsigned long hi_mem_ph;
-       unsigned long i;
-
-       /* Map the high memory to user space */
-
-       hi_mem_ph = virt_to_phys(high_memory);
-
-       mem = ioremap(hi_mem_ph, size);
-       if (!mem) {
-               dprintk(1,
-                       KERN_ERR "%s: get_high_mem() - ioremap failed\n",
-                       ZORAN_NAME);
-               return 0;
-       }
-
-       for (i = 0; i < size; i++) {
-               /* Check if it is memory */
-               c = i & 0xff;
-               writeb(c, mem + i);
-               if (readb(mem + i) != c)
-                       break;
-               c = 255 - c;
-               writeb(c, mem + i);
-               if (readb(mem + i) != c)
-                       break;
-               writeb(0, mem + i);     /* zero out memory */
-
-               /* give the kernel air to breath */
-               if ((i & 0x3ffff) == 0x3ffff)
-                       schedule();
-       }
-
-       iounmap(mem);
-
-       if (i != size) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: get_high_mem() - requested %lu, avail %lu\n",
-                       ZORAN_NAME, size, i);
-               return 0;
-       }
-
-       return hi_mem_ph;
-}
-
-static int
-v4l_fbuffer_alloc (struct file *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int i, off;
-       unsigned char *mem;
-       unsigned long pmem = 0;
-
-       /* we might have old buffers lying around... */
-       if (fh->v4l_buffers.ready_to_be_freed) {
-               v4l_fbuffer_free(file);
-       }
-
-       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
-               if (fh->v4l_buffers.buffer[i].fbuffer)
-                       dprintk(2,
-                               KERN_WARNING
-                               "%s: v4l_fbuffer_alloc() - buffer %d allready allocated!?\n",
-                               ZR_DEVNAME(zr), i);
-
-               //udelay(20);
-               if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
-                       /* Use kmalloc */
-
-                       mem = kmalloc(fh->v4l_buffers.buffer_size, GFP_KERNEL);
-                       if (!mem) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: v4l_fbuffer_alloc() - kmalloc for V4L buf %d failed\n",
-                                       ZR_DEVNAME(zr), i);
-                               v4l_fbuffer_free(file);
-                               return -ENOBUFS;
-                       }
-                       fh->v4l_buffers.buffer[i].fbuffer = mem;
-                       fh->v4l_buffers.buffer[i].fbuffer_phys =
-                           virt_to_phys(mem);
-                       fh->v4l_buffers.buffer[i].fbuffer_bus =
-                           virt_to_bus(mem);
-                       for (off = 0; off < fh->v4l_buffers.buffer_size;
-                            off += PAGE_SIZE)
-                               SetPageReserved(MAP_NR(mem + off));
-                       dprintk(4,
-                               KERN_INFO
-                               "%s: v4l_fbuffer_alloc() - V4L frame %d mem 0x%lx (bus: 0x%lx)\n",
-                               ZR_DEVNAME(zr), i, (unsigned long) mem,
-                               virt_to_bus(mem));
-               } else {
-
-                       /* Use high memory which has been left at boot time */
-
-                       /* Ok., Ok. this is an evil hack - we make
-                        * the assumption that physical addresses are
-                        * the same as bus addresses (true at least
-                        * for Intel processors). The whole method of
-                        * obtaining and using this memory is not very
-                        * nice - but I hope it saves some poor users
-                        * from kernel hacking, which might have even
-                        * more evil results */
-
-                       if (i == 0) {
-                               int size =
-                                   fh->v4l_buffers.num_buffers *
-                                   fh->v4l_buffers.buffer_size;
-
-                               pmem = get_high_mem(size);
-                               if (pmem == 0) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: v4l_fbuffer_alloc() - get_high_mem (size = %d KB) for V4L bufs failed\n",
-                                               ZR_DEVNAME(zr), size >> 10);
-                                       return -ENOBUFS;
-                               }
-                               fh->v4l_buffers.buffer[0].fbuffer = NULL;
-                               fh->v4l_buffers.buffer[0].fbuffer_phys = pmem;
-                               fh->v4l_buffers.buffer[0].fbuffer_bus = pmem;
-                               dprintk(4,
-                                       KERN_INFO
-                                       "%s: v4l_fbuffer_alloc() - using %d KB high memory\n",
-                                       ZR_DEVNAME(zr), size >> 10);
-                       } else {
-                               fh->v4l_buffers.buffer[i].fbuffer = NULL;
-                               fh->v4l_buffers.buffer[i].fbuffer_phys =
-                                   pmem + i * fh->v4l_buffers.buffer_size;
-                               fh->v4l_buffers.buffer[i].fbuffer_bus =
-                                   pmem + i * fh->v4l_buffers.buffer_size;
-                       }
-               }
-       }
-
-       fh->v4l_buffers.allocated = 1;
-
-       return 0;
-}
-
-/* free the V4L grab buffers */
-static void
-v4l_fbuffer_free (struct file *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int i, off;
-       unsigned char *mem;
-
-       dprintk(4, KERN_INFO "%s: v4l_fbuffer_free()\n", ZR_DEVNAME(zr));
-
-       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
-               if (!fh->v4l_buffers.buffer[i].fbuffer)
-                       continue;
-
-               if (fh->v4l_buffers.buffer_size <= MAX_KMALLOC_MEM) {
-                       mem = fh->v4l_buffers.buffer[i].fbuffer;
-                       for (off = 0; off < fh->v4l_buffers.buffer_size;
-                            off += PAGE_SIZE)
-                               ClearPageReserved(MAP_NR(mem + off));
-                       kfree((void *) fh->v4l_buffers.buffer[i].fbuffer);
-               }
-               fh->v4l_buffers.buffer[i].fbuffer = NULL;
-       }
-
-       fh->v4l_buffers.allocated = 0;
-       fh->v4l_buffers.ready_to_be_freed = 0;
-}
-
-/*
- *   Allocate the MJPEG grab buffers.
- *
- *   If the requested buffer size is smaller than MAX_KMALLOC_MEM,
- *   kmalloc is used to request a physically contiguous area,
- *   else we allocate the memory in framgents with get_zeroed_page.
- *
- *   If a Natoma chipset is present and this is a revision 1 zr36057,
- *   each MJPEG buffer needs to be physically contiguous.
- *   (RJ: This statement is from Dave Perks' original driver,
- *   I could never check it because I have a zr36067)
- *   The driver cares about this because it reduces the buffer
- *   size to MAX_KMALLOC_MEM in that case (which forces contiguous allocation).
- *
- *   RJ: The contents grab buffers needs never be accessed in the driver.
- *       Therefore there is no need to allocate them with vmalloc in order
- *       to get a contiguous virtual memory space.
- *       I don't understand why many other drivers first allocate them with
- *       vmalloc (which uses internally also get_zeroed_page, but delivers you
- *       virtual addresses) and then again have to make a lot of efforts
- *       to get the physical address.
- *
- *   Ben Capper:
- *       On big-endian architectures (such as ppc) some extra steps
- *       are needed. When reading and writing to the stat_com array
- *       and fragment buffers, the device expects to see little-
- *       endian values. The use of cpu_to_le32() and le32_to_cpu()
- *       in this function (and one or two others in zoran_device.c)
- *       ensure that these values are always stored in little-endian
- *       form, regardless of architecture. The zr36057 does Very Bad
- *       Things on big endian architectures if the stat_com array
- *       and fragment buffers are not little-endian.
- */
-
-static int
-jpg_fbuffer_alloc (struct file *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int i, j, off;
-       unsigned long mem;
-
-       /* we might have old buffers lying around */
-       if (fh->jpg_buffers.ready_to_be_freed) {
-               jpg_fbuffer_free(file);
-       }
-
-       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
-               if (fh->jpg_buffers.buffer[i].frag_tab)
-                       dprintk(2,
-                               KERN_WARNING
-                               "%s: jpg_fbuffer_alloc() - buffer %d allready allocated!?\n",
-                               ZR_DEVNAME(zr), i);
-
-               /* Allocate fragment table for this buffer */
-
-               mem = get_zeroed_page(GFP_KERNEL);
-               if (mem == 0) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: jpg_fbuffer_alloc() - get_zeroed_page (frag_tab) failed for buffer %d\n",
-                               ZR_DEVNAME(zr), i);
-                       jpg_fbuffer_free(file);
-                       return -ENOBUFS;
-               }
-               fh->jpg_buffers.buffer[i].frag_tab = (__le32 *) mem;
-               fh->jpg_buffers.buffer[i].frag_tab_bus =
-                   virt_to_bus((void *) mem);
-
-               //if (alloc_contig) {
-               if (fh->jpg_buffers.need_contiguous) {
-                       mem =
-                           (unsigned long) kmalloc(fh->jpg_buffers.
-                                                   buffer_size,
-                                                   GFP_KERNEL);
-                       if (mem == 0) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: jpg_fbuffer_alloc() - kmalloc failed for buffer %d\n",
-                                       ZR_DEVNAME(zr), i);
-                               jpg_fbuffer_free(file);
-                               return -ENOBUFS;
-                       }
-                       fh->jpg_buffers.buffer[i].frag_tab[0] =
-                           cpu_to_le32(virt_to_bus((void *) mem));
-                       fh->jpg_buffers.buffer[i].frag_tab[1] =
-                           cpu_to_le32(((fh->jpg_buffers.buffer_size / 4) << 1) | 1);
-                       for (off = 0; off < fh->jpg_buffers.buffer_size;
-                            off += PAGE_SIZE)
-                               SetPageReserved(MAP_NR(mem + off));
-               } else {
-                       /* jpg_bufsize is allreay page aligned */
-                       for (j = 0;
-                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
-                            j++) {
-                               mem = get_zeroed_page(GFP_KERNEL);
-                               if (mem == 0) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: jpg_fbuffer_alloc() - get_zeroed_page failed for buffer %d\n",
-                                               ZR_DEVNAME(zr), i);
-                                       jpg_fbuffer_free(file);
-                                       return -ENOBUFS;
-                               }
-
-                               fh->jpg_buffers.buffer[i].frag_tab[2 * j] =
-                                   cpu_to_le32(virt_to_bus((void *) mem));
-                               fh->jpg_buffers.buffer[i].frag_tab[2 * j +
-                                                                  1] =
-                                   cpu_to_le32((PAGE_SIZE / 4) << 1);
-                               SetPageReserved(MAP_NR(mem));
-                       }
-
-                       fh->jpg_buffers.buffer[i].frag_tab[2 * j - 1] |= cpu_to_le32(1);
-               }
-       }
-
-       dprintk(4,
-               KERN_DEBUG "%s: jpg_fbuffer_alloc() - %d KB allocated\n",
-               ZR_DEVNAME(zr),
-               (fh->jpg_buffers.num_buffers *
-                fh->jpg_buffers.buffer_size) >> 10);
-
-       fh->jpg_buffers.allocated = 1;
-
-       return 0;
-}
-
-/* free the MJPEG grab buffers */
-static void
-jpg_fbuffer_free (struct file *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int i, j, off;
-       unsigned char *mem;
-
-       dprintk(4, KERN_DEBUG "%s: jpg_fbuffer_free()\n", ZR_DEVNAME(zr));
-
-       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
-               if (!fh->jpg_buffers.buffer[i].frag_tab)
-                       continue;
-
-               //if (alloc_contig) {
-               if (fh->jpg_buffers.need_contiguous) {
-                       if (fh->jpg_buffers.buffer[i].frag_tab[0]) {
-                               mem = (unsigned char *) bus_to_virt(le32_to_cpu(
-                                       fh->jpg_buffers.buffer[i].frag_tab[0]));
-                               for (off = 0;
-                                    off < fh->jpg_buffers.buffer_size;
-                                    off += PAGE_SIZE)
-                                       ClearPageReserved(MAP_NR
-                                                         (mem + off));
-                               kfree(mem);
-                               fh->jpg_buffers.buffer[i].frag_tab[0] = 0;
-                               fh->jpg_buffers.buffer[i].frag_tab[1] = 0;
-                       }
-               } else {
-                       for (j = 0;
-                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
-                            j++) {
-                               if (!fh->jpg_buffers.buffer[i].
-                                   frag_tab[2 * j])
-                                       break;
-                               ClearPageReserved(MAP_NR
-                                                 (bus_to_virt
-                                                  (le32_to_cpu
-                                                   (fh->jpg_buffers.
-                                                    buffer[i].frag_tab[2 *
-                                                                      j]))));
-                               free_page((unsigned long)
-                                         bus_to_virt
-                                                 (le32_to_cpu
-                                                  (fh->jpg_buffers.
-                                                     buffer[i].
-                                                     frag_tab[2 * j])));
-                               fh->jpg_buffers.buffer[i].frag_tab[2 * j] =
-                                   0;
-                               fh->jpg_buffers.buffer[i].frag_tab[2 * j +
-                                                                  1] = 0;
-                       }
-               }
-
-               free_page((unsigned long) fh->jpg_buffers.buffer[i].
-                         frag_tab);
-               fh->jpg_buffers.buffer[i].frag_tab = NULL;
-       }
-
-       fh->jpg_buffers.allocated = 0;
-       fh->jpg_buffers.ready_to_be_freed = 0;
-}
-
-/*
- *   V4L Buffer grabbing
- */
-
-static int
-zoran_v4l_set_format (struct file               *file,
-                     int                        width,
-                     int                        height,
-                     const struct zoran_format *format)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int bpp;
-
-       /* Check size and format of the grab wanted */
-
-       if (height < BUZ_MIN_HEIGHT || width < BUZ_MIN_WIDTH ||
-           height > BUZ_MAX_HEIGHT || width > BUZ_MAX_WIDTH) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_set_format() - wrong frame size (%dx%d)\n",
-                       ZR_DEVNAME(zr), width, height);
-               return -EINVAL;
-       }
-
-       bpp = (format->depth + 7) / 8;
-
-       /* Check against available buffer size */
-       if (height * width * bpp > fh->v4l_buffers.buffer_size) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_set_format() - video buffer size (%d kB) is too small\n",
-                       ZR_DEVNAME(zr), fh->v4l_buffers.buffer_size >> 10);
-               return -EINVAL;
-       }
-
-       /* The video front end needs 4-byte alinged line sizes */
-
-       if ((bpp == 2 && (width & 1)) || (bpp == 3 && (width & 3))) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_set_format() - wrong frame alingment\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       fh->v4l_settings.width = width;
-       fh->v4l_settings.height = height;
-       fh->v4l_settings.format = format;
-       fh->v4l_settings.bytesperline = bpp * fh->v4l_settings.width;
-
-       return 0;
-}
-
-static int
-zoran_v4l_queue_frame (struct file *file,
-                      int          num)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned long flags;
-       int res = 0;
-
-       if (!fh->v4l_buffers.allocated) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_queue_frame() - buffers not yet allocated\n",
-                       ZR_DEVNAME(zr));
-               res = -ENOMEM;
-       }
-
-       /* No grabbing outside the buffer range! */
-       if (num >= fh->v4l_buffers.num_buffers || num < 0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_queue_frame() - buffer %d is out of range\n",
-                       ZR_DEVNAME(zr), num);
-               res = -EINVAL;
-       }
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-
-       if (fh->v4l_buffers.active == ZORAN_FREE) {
-               if (zr->v4l_buffers.active == ZORAN_FREE) {
-                       zr->v4l_buffers = fh->v4l_buffers;
-                       fh->v4l_buffers.active = ZORAN_ACTIVE;
-               } else {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: v4l_queue_frame() - another session is already capturing\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-               }
-       }
-
-       /* make sure a grab isn't going on currently with this buffer */
-       if (!res) {
-               switch (zr->v4l_buffers.buffer[num].state) {
-               default:
-               case BUZ_STATE_PEND:
-                       if (zr->v4l_buffers.active == ZORAN_FREE) {
-                               fh->v4l_buffers.active = ZORAN_FREE;
-                               zr->v4l_buffers.allocated = 0;
-                       }
-                       res = -EBUSY;   /* what are you doing? */
-                       break;
-               case BUZ_STATE_DONE:
-                       dprintk(2,
-                               KERN_WARNING
-                               "%s: v4l_queue_frame() - queueing buffer %d in state DONE!?\n",
-                               ZR_DEVNAME(zr), num);
-               case BUZ_STATE_USER:
-                       /* since there is at least one unused buffer there's room for at least
-                        * one more pend[] entry */
-                       zr->v4l_pend[zr->v4l_pend_head++ &
-                                       V4L_MASK_FRAME] = num;
-                       zr->v4l_buffers.buffer[num].state = BUZ_STATE_PEND;
-                       zr->v4l_buffers.buffer[num].bs.length =
-                           fh->v4l_settings.bytesperline *
-                           zr->v4l_settings.height;
-                       fh->v4l_buffers.buffer[num] =
-                           zr->v4l_buffers.buffer[num];
-                       break;
-               }
-       }
-
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       if (!res && zr->v4l_buffers.active == ZORAN_FREE)
-               zr->v4l_buffers.active = fh->v4l_buffers.active;
-
-       return res;
-}
-
-static int
-v4l_grab (struct file       *file,
-         struct video_mmap *mp)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int res = 0, i;
-
-       for (i = 0; i < NUM_FORMATS; i++) {
-               if (zoran_formats[i].palette == mp->format &&
-                   zoran_formats[i].flags & ZORAN_FORMAT_CAPTURE &&
-                   !(zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED))
-                       break;
-       }
-       if (i == NUM_FORMATS || zoran_formats[i].depth == 0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_grab() - wrong bytes-per-pixel format\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       /*
-        * To minimize the time spent in the IRQ routine, we avoid setting up
-        * the video front end there.
-        * If this grab has different parameters from a running streaming capture
-        * we stop the streaming capture and start it over again.
-        */
-       if (zr->v4l_memgrab_active &&
-           (zr->v4l_settings.width != mp->width ||
-            zr->v4l_settings.height != mp->height ||
-            zr->v4l_settings.format->palette != mp->format)) {
-               res = wait_grab_pending(zr);
-               if (res)
-                       return res;
-       }
-       if ((res = zoran_v4l_set_format(file,
-                                       mp->width,
-                                       mp->height,
-                                       &zoran_formats[i])))
-               return res;
-       zr->v4l_settings = fh->v4l_settings;
-
-       /* queue the frame in the pending queue */
-       if ((res = zoran_v4l_queue_frame(file, mp->frame))) {
-               fh->v4l_buffers.active = ZORAN_FREE;
-               return res;
-       }
-
-       /* put the 36057 into frame grabbing mode */
-       if (!res && !zr->v4l_memgrab_active)
-               zr36057_set_memgrab(zr, 1);
-
-       //dprintk(4, KERN_INFO "%s: Frame grab 3...\n", ZR_DEVNAME(zr));
-
-       return res;
-}
-
-/*
- * Sync on a V4L buffer
- */
-
-static int
-v4l_sync (struct file *file,
-         int          frame)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned long flags;
-
-       if (fh->v4l_buffers.active == ZORAN_FREE) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_sync() - no grab active for this session\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       /* check passed-in frame number */
-       if (frame >= fh->v4l_buffers.num_buffers || frame < 0) {
-               dprintk(1,
-                       KERN_ERR "%s: v4l_sync() - frame %d is invalid\n",
-                       ZR_DEVNAME(zr), frame);
-               return -EINVAL;
-       }
-
-       /* Check if is buffer was queued at all */
-       if (zr->v4l_buffers.buffer[frame].state == BUZ_STATE_USER) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: v4l_sync() - attempt to sync on a buffer which was not queued?\n",
-                       ZR_DEVNAME(zr));
-               return -EPROTO;
-       }
-
-       /* wait on this buffer to get ready */
-       if (!wait_event_interruptible_timeout(zr->v4l_capq,
-                               (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_PEND),
-                               10*HZ))
-               return -ETIME;
-       if (signal_pending(current))
-               return -ERESTARTSYS;
-
-       /* buffer should now be in BUZ_STATE_DONE */
-       if (zr->v4l_buffers.buffer[frame].state != BUZ_STATE_DONE)
-               dprintk(2,
-                       KERN_ERR "%s: v4l_sync() - internal state error\n",
-                       ZR_DEVNAME(zr));
-
-       zr->v4l_buffers.buffer[frame].state = BUZ_STATE_USER;
-       fh->v4l_buffers.buffer[frame] = zr->v4l_buffers.buffer[frame];
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-
-       /* Check if streaming capture has finished */
-       if (zr->v4l_pend_tail == zr->v4l_pend_head) {
-               zr36057_set_memgrab(zr, 0);
-               if (zr->v4l_buffers.active == ZORAN_ACTIVE) {
-                       fh->v4l_buffers.active = zr->v4l_buffers.active =
-                           ZORAN_FREE;
-                       zr->v4l_buffers.allocated = 0;
-               }
-       }
-
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       return 0;
-}
-
-/*
- *   Queue a MJPEG buffer for capture/playback
- */
-
-static int
-zoran_jpg_queue_frame (struct file          *file,
-                      int                   num,
-                      enum zoran_codec_mode mode)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned long flags;
-       int res = 0;
-
-       /* Check if buffers are allocated */
-       if (!fh->jpg_buffers.allocated) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_queue_frame() - buffers not yet allocated\n",
-                       ZR_DEVNAME(zr));
-               return -ENOMEM;
-       }
-
-       /* No grabbing outside the buffer range! */
-       if (num >= fh->jpg_buffers.num_buffers || num < 0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_queue_frame() - buffer %d out of range\n",
-                       ZR_DEVNAME(zr), num);
-               return -EINVAL;
-       }
-
-       /* what is the codec mode right now? */
-       if (zr->codec_mode == BUZ_MODE_IDLE) {
-               zr->jpg_settings = fh->jpg_settings;
-       } else if (zr->codec_mode != mode) {
-               /* wrong codec mode active - invalid */
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_queue_frame() - codec in wrong mode\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       if (fh->jpg_buffers.active == ZORAN_FREE) {
-               if (zr->jpg_buffers.active == ZORAN_FREE) {
-                       zr->jpg_buffers = fh->jpg_buffers;
-                       fh->jpg_buffers.active = ZORAN_ACTIVE;
-               } else {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: jpg_queue_frame() - another session is already capturing\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-               }
-       }
-
-       if (!res && zr->codec_mode == BUZ_MODE_IDLE) {
-               /* Ok load up the jpeg codec */
-               zr36057_enable_jpg(zr, mode);
-       }
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-
-       if (!res) {
-               switch (zr->jpg_buffers.buffer[num].state) {
-               case BUZ_STATE_DONE:
-                       dprintk(2,
-                               KERN_WARNING
-                               "%s: jpg_queue_frame() - queing frame in BUZ_STATE_DONE state!?\n",
-                               ZR_DEVNAME(zr));
-               case BUZ_STATE_USER:
-                       /* since there is at least one unused buffer there's room for at
-                        *least one more pend[] entry */
-                       zr->jpg_pend[zr->jpg_que_head++ & BUZ_MASK_FRAME] =
-                           num;
-                       zr->jpg_buffers.buffer[num].state = BUZ_STATE_PEND;
-                       fh->jpg_buffers.buffer[num] =
-                           zr->jpg_buffers.buffer[num];
-                       zoran_feed_stat_com(zr);
-                       break;
-               default:
-               case BUZ_STATE_DMA:
-               case BUZ_STATE_PEND:
-                       if (zr->jpg_buffers.active == ZORAN_FREE) {
-                               fh->jpg_buffers.active = ZORAN_FREE;
-                               zr->jpg_buffers.allocated = 0;
-                       }
-                       res = -EBUSY;   /* what are you doing? */
-                       break;
-               }
-       }
-
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       if (!res && zr->jpg_buffers.active == ZORAN_FREE) {
-               zr->jpg_buffers.active = fh->jpg_buffers.active;
-       }
-
-       return res;
-}
-
-static int
-jpg_qbuf (struct file          *file,
-         int                   frame,
-         enum zoran_codec_mode mode)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int res = 0;
-
-       /* Does the user want to stop streaming? */
-       if (frame < 0) {
-               if (zr->codec_mode == mode) {
-                       if (fh->jpg_buffers.active == ZORAN_FREE) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: jpg_qbuf(-1) - session not active\n",
-                                       ZR_DEVNAME(zr));
-                               return -EINVAL;
-                       }
-                       fh->jpg_buffers.active = zr->jpg_buffers.active =
-                           ZORAN_FREE;
-                       zr->jpg_buffers.allocated = 0;
-                       zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
-                       return 0;
-               } else {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: jpg_qbuf() - stop streaming but not in streaming mode\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-       }
-
-       if ((res = zoran_jpg_queue_frame(file, frame, mode)))
-               return res;
-
-       /* Start the jpeg codec when the first frame is queued  */
-       if (!res && zr->jpg_que_head == 1)
-               jpeg_start(zr);
-
-       return res;
-}
-
-/*
- *   Sync on a MJPEG buffer
- */
-
-static int
-jpg_sync (struct file       *file,
-         struct zoran_sync *bs)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned long flags;
-       int frame;
-
-       if (fh->jpg_buffers.active == ZORAN_FREE) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_sync() - capture is not currently active\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-       if (zr->codec_mode != BUZ_MODE_MOTION_DECOMPRESS &&
-           zr->codec_mode != BUZ_MODE_MOTION_COMPRESS) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_sync() - codec not in streaming mode\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-       if (!wait_event_interruptible_timeout(zr->jpg_capq,
-                       (zr->jpg_que_tail != zr->jpg_dma_tail ||
-                        zr->jpg_dma_tail == zr->jpg_dma_head),
-                       10*HZ)) {
-               int isr;
-
-               btand(~ZR36057_JMC_Go_en, ZR36057_JMC);
-               udelay(1);
-               zr->codec->control(zr->codec, CODEC_G_STATUS,
-                                          sizeof(isr), &isr);
-               dprintk(1,
-                       KERN_ERR
-                       "%s: jpg_sync() - timeout: codec isr=0x%02x\n",
-                       ZR_DEVNAME(zr), isr);
-
-               return -ETIME;
-
-       }
-       if (signal_pending(current))
-               return -ERESTARTSYS;
-
-       spin_lock_irqsave(&zr->spinlock, flags);
-
-       if (zr->jpg_dma_tail != zr->jpg_dma_head)
-               frame = zr->jpg_pend[zr->jpg_que_tail++ & BUZ_MASK_FRAME];
-       else
-               frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
-
-       /* buffer should now be in BUZ_STATE_DONE */
-       if (zr->jpg_buffers.buffer[frame].state != BUZ_STATE_DONE)
-               dprintk(2,
-                       KERN_ERR "%s: jpg_sync() - internal state error\n",
-                       ZR_DEVNAME(zr));
-
-       *bs = zr->jpg_buffers.buffer[frame].bs;
-       bs->frame = frame;
-       zr->jpg_buffers.buffer[frame].state = BUZ_STATE_USER;
-       fh->jpg_buffers.buffer[frame] = zr->jpg_buffers.buffer[frame];
-
-       spin_unlock_irqrestore(&zr->spinlock, flags);
-
-       return 0;
-}
-
-static void
-zoran_open_init_session (struct file *file)
-{
-       int i;
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       /* Per default, map the V4L Buffers */
-       fh->map_mode = ZORAN_MAP_MODE_RAW;
-
-       /* take over the card's current settings */
-       fh->overlay_settings = zr->overlay_settings;
-       fh->overlay_settings.is_set = 0;
-       fh->overlay_settings.format = zr->overlay_settings.format;
-       fh->overlay_active = ZORAN_FREE;
-
-       /* v4l settings */
-       fh->v4l_settings = zr->v4l_settings;
-
-       /* v4l_buffers */
-       memset(&fh->v4l_buffers, 0, sizeof(struct zoran_v4l_struct));
-       for (i = 0; i < VIDEO_MAX_FRAME; i++) {
-               fh->v4l_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
-               fh->v4l_buffers.buffer[i].bs.frame = i;
-       }
-       fh->v4l_buffers.allocated = 0;
-       fh->v4l_buffers.ready_to_be_freed = 0;
-       fh->v4l_buffers.active = ZORAN_FREE;
-       fh->v4l_buffers.buffer_size = v4l_bufsize;
-       fh->v4l_buffers.num_buffers = v4l_nbufs;
-
-       /* jpg settings */
-       fh->jpg_settings = zr->jpg_settings;
-
-       /* jpg_buffers */
-       memset(&fh->jpg_buffers, 0, sizeof(struct zoran_jpg_struct));
-       for (i = 0; i < BUZ_MAX_FRAME; i++) {
-               fh->jpg_buffers.buffer[i].state = BUZ_STATE_USER;       /* nothing going on */
-               fh->jpg_buffers.buffer[i].bs.frame = i;
-       }
-       fh->jpg_buffers.need_contiguous = zr->jpg_buffers.need_contiguous;
-       fh->jpg_buffers.allocated = 0;
-       fh->jpg_buffers.ready_to_be_freed = 0;
-       fh->jpg_buffers.active = ZORAN_FREE;
-       fh->jpg_buffers.buffer_size = jpg_bufsize;
-       fh->jpg_buffers.num_buffers = jpg_nbufs;
-}
-
-static void
-zoran_close_end_session (struct file *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       /* overlay */
-       if (fh->overlay_active != ZORAN_FREE) {
-               fh->overlay_active = zr->overlay_active = ZORAN_FREE;
-               zr->v4l_overlay_active = 0;
-               if (!zr->v4l_memgrab_active)
-                       zr36057_overlay(zr, 0);
-               zr->overlay_mask = NULL;
-       }
-
-       /* v4l capture */
-       if (fh->v4l_buffers.active != ZORAN_FREE) {
-               unsigned long flags;
-
-               spin_lock_irqsave(&zr->spinlock, flags);
-               zr36057_set_memgrab(zr, 0);
-               zr->v4l_buffers.allocated = 0;
-               zr->v4l_buffers.active = fh->v4l_buffers.active =
-                   ZORAN_FREE;
-               spin_unlock_irqrestore(&zr->spinlock, flags);
-       }
-
-       /* v4l buffers */
-       if (fh->v4l_buffers.allocated ||
-           fh->v4l_buffers.ready_to_be_freed) {
-               v4l_fbuffer_free(file);
-       }
-
-       /* jpg capture */
-       if (fh->jpg_buffers.active != ZORAN_FREE) {
-               zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
-               zr->jpg_buffers.allocated = 0;
-               zr->jpg_buffers.active = fh->jpg_buffers.active =
-                   ZORAN_FREE;
-       }
-
-       /* jpg buffers */
-       if (fh->jpg_buffers.allocated ||
-           fh->jpg_buffers.ready_to_be_freed) {
-               jpg_fbuffer_free(file);
-       }
-}
-
-/*
- *   Open a zoran card. Right now the flags stuff is just playing
- */
-
-static int
-zoran_open (struct inode *inode,
-           struct file  *file)
-{
-       unsigned int minor = iminor(inode);
-       struct zoran *zr = NULL;
-       struct zoran_fh *fh;
-       int i, res, first_open = 0, have_module_locks = 0;
-
-       /* find the device */
-       for (i = 0; i < zoran_num; i++) {
-               if (zoran[i]->video_dev->minor == minor) {
-                       zr = zoran[i];
-                       break;
-               }
-       }
-
-       if (!zr) {
-               dprintk(1, KERN_ERR "%s: device not found!\n", ZORAN_NAME);
-               res = -ENODEV;
-               goto open_unlock_and_return;
-       }
-
-       /* see fs/device.c - the kernel already locks during open(),
-        * so locking ourselves only causes deadlocks */
-       /*mutex_lock(&zr->resource_lock);*/
-
-       if (!zr->decoder) {
-               dprintk(1,
-                       KERN_ERR "%s: no TV decoder loaded for device!\n",
-                       ZR_DEVNAME(zr));
-               res = -EIO;
-               goto open_unlock_and_return;
-       }
-
-       /* try to grab a module lock */
-       if (!try_module_get(THIS_MODULE)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: failed to acquire my own lock! PANIC!\n",
-                       ZR_DEVNAME(zr));
-               res = -ENODEV;
-               goto open_unlock_and_return;
-       }
-       if (!try_module_get(zr->decoder->driver->driver.owner)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: failed to grab ownership of i2c decoder\n",
-                       ZR_DEVNAME(zr));
-               res = -EIO;
-               module_put(THIS_MODULE);
-               goto open_unlock_and_return;
-       }
-       if (zr->encoder &&
-           !try_module_get(zr->encoder->driver->driver.owner)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: failed to grab ownership of i2c encoder\n",
-                       ZR_DEVNAME(zr));
-               res = -EIO;
-               module_put(zr->decoder->driver->driver.owner);
-               module_put(THIS_MODULE);
-               goto open_unlock_and_return;
-       }
-
-       have_module_locks = 1;
-
-       if (zr->user >= 2048) {
-               dprintk(1, KERN_ERR "%s: too many users (%d) on device\n",
-                       ZR_DEVNAME(zr), zr->user);
-               res = -EBUSY;
-               goto open_unlock_and_return;
-       }
-
-       dprintk(1, KERN_INFO "%s: zoran_open(%s, pid=[%d]), users(-)=%d\n",
-               ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
-
-       /* now, create the open()-specific file_ops struct */
-       fh = kzalloc(sizeof(struct zoran_fh), GFP_KERNEL);
-       if (!fh) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_open() - allocation of zoran_fh failed\n",
-                       ZR_DEVNAME(zr));
-               res = -ENOMEM;
-               goto open_unlock_and_return;
-       }
-       /* used to be BUZ_MAX_WIDTH/HEIGHT, but that gives overflows
-        * on norm-change! */
-       fh->overlay_mask =
-           kmalloc(((768 + 31) / 32) * 576 * 4, GFP_KERNEL);
-       if (!fh->overlay_mask) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_open() - allocation of overlay_mask failed\n",
-                       ZR_DEVNAME(zr));
-               kfree(fh);
-               res = -ENOMEM;
-               goto open_unlock_and_return;
-       }
-
-       if (zr->user++ == 0)
-               first_open = 1;
-
-       /*mutex_unlock(&zr->resource_lock);*/
-
-       /* default setup - TODO: look at flags */
-       if (first_open) {       /* First device open */
-               zr36057_restart(zr);
-               zoran_open_init_params(zr);
-               zoran_init_hardware(zr);
-
-               btor(ZR36057_ICR_IntPinEn, ZR36057_ICR);
-       }
-
-       /* set file_ops stuff */
-       file->private_data = fh;
-       fh->zr = zr;
-       zoran_open_init_session(file);
-
-       return 0;
-
-open_unlock_and_return:
-       /* if we grabbed locks, release them accordingly */
-       if (have_module_locks) {
-               module_put(zr->decoder->driver->driver.owner);
-               if (zr->encoder) {
-                       module_put(zr->encoder->driver->driver.owner);
-               }
-               module_put(THIS_MODULE);
-       }
-
-       /* if there's no device found, we didn't obtain the lock either */
-       if (zr) {
-               /*mutex_unlock(&zr->resource_lock);*/
-       }
-
-       return res;
-}
-
-static int
-zoran_close (struct inode *inode,
-            struct file  *file)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       dprintk(1, KERN_INFO "%s: zoran_close(%s, pid=[%d]), users(+)=%d\n",
-               ZR_DEVNAME(zr), current->comm, task_pid_nr(current), zr->user);
-
-       /* kernel locks (fs/device.c), so don't do that ourselves
-        * (prevents deadlocks) */
-       /*mutex_lock(&zr->resource_lock);*/
-
-       zoran_close_end_session(file);
-
-       if (zr->user-- == 1) {  /* Last process */
-               /* Clean up JPEG process */
-               wake_up_interruptible(&zr->jpg_capq);
-               zr36057_enable_jpg(zr, BUZ_MODE_IDLE);
-               zr->jpg_buffers.allocated = 0;
-               zr->jpg_buffers.active = ZORAN_FREE;
-
-               /* disable interrupts */
-               btand(~ZR36057_ICR_IntPinEn, ZR36057_ICR);
-
-               if (zr36067_debug > 1)
-                       print_interrupts(zr);
-
-               /* Overlay off */
-               zr->v4l_overlay_active = 0;
-               zr36057_overlay(zr, 0);
-               zr->overlay_mask = NULL;
-
-               /* capture off */
-               wake_up_interruptible(&zr->v4l_capq);
-               zr36057_set_memgrab(zr, 0);
-               zr->v4l_buffers.allocated = 0;
-               zr->v4l_buffers.active = ZORAN_FREE;
-               zoran_set_pci_master(zr, 0);
-
-               if (!pass_through) {    /* Switch to color bar */
-                       int zero = 0, two = 2;
-                       decoder_command(zr, DECODER_ENABLE_OUTPUT, &zero);
-                       encoder_command(zr, ENCODER_SET_INPUT, &two);
-               }
-       }
-
-       file->private_data = NULL;
-       kfree(fh->overlay_mask);
-       kfree(fh);
-
-       /* release locks on the i2c modules */
-       module_put(zr->decoder->driver->driver.owner);
-       if (zr->encoder) {
-                module_put(zr->encoder->driver->driver.owner);
-       }
-       module_put(THIS_MODULE);
-
-       /*mutex_unlock(&zr->resource_lock);*/
-
-       dprintk(4, KERN_INFO "%s: zoran_close() done\n", ZR_DEVNAME(zr));
-
-       return 0;
-}
-
-
-static ssize_t
-zoran_read (struct file *file,
-           char        __user *data,
-           size_t       count,
-           loff_t      *ppos)
-{
-       /* we simply don't support read() (yet)... */
-
-       return -EINVAL;
-}
-
-static ssize_t
-zoran_write (struct file *file,
-            const char  __user *data,
-            size_t       count,
-            loff_t      *ppos)
-{
-       /* ...and the same goes for write() */
-
-       return -EINVAL;
-}
-
-static int
-setup_fbuffer (struct file               *file,
-              void                      *base,
-              const struct zoran_format *fmt,
-              int                        width,
-              int                        height,
-              int                        bytesperline)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       /* (Ronald) v4l/v4l2 guidelines */
-       if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RAWIO))
-               return -EPERM;
-
-       /* Don't allow frame buffer overlay if PCI or AGP is buggy, or on
-          ALi Magik (that needs very low latency while the card needs a
-          higher value always) */
-
-       if (pci_pci_problems & (PCIPCI_FAIL | PCIAGP_FAIL | PCIPCI_ALIMAGIK))
-               return -ENXIO;
-
-       /* we need a bytesperline value, even if not given */
-       if (!bytesperline)
-               bytesperline = width * ((fmt->depth + 7) & ~7) / 8;
-
-#if 0
-       if (zr->overlay_active) {
-               /* dzjee... stupid users... don't even bother to turn off
-                * overlay before changing the memory location...
-                * normally, we would return errors here. However, one of
-                * the tools that does this is... xawtv! and since xawtv
-                * is used by +/- 99% of the users, we'd rather be user-
-                * friendly and silently do as if nothing went wrong */
-               dprintk(3,
-                       KERN_ERR
-                       "%s: setup_fbuffer() - forced overlay turnoff because framebuffer changed\n",
-                       ZR_DEVNAME(zr));
-               zr36057_overlay(zr, 0);
-       }
-#endif
-
-       if (!(fmt->flags & ZORAN_FORMAT_OVERLAY)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_fbuffer() - no valid overlay format given\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-       if (height <= 0 || width <= 0 || bytesperline <= 0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_fbuffer() - invalid height/width/bpl value (%d|%d|%d)\n",
-                       ZR_DEVNAME(zr), width, height, bytesperline);
-               return -EINVAL;
-       }
-       if (bytesperline & 3) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_fbuffer() - bytesperline (%d) must be 4-byte aligned\n",
-                       ZR_DEVNAME(zr), bytesperline);
-               return -EINVAL;
-       }
-
-       zr->buffer.base = (void *) ((unsigned long) base & ~3);
-       zr->buffer.height = height;
-       zr->buffer.width = width;
-       zr->buffer.depth = fmt->depth;
-       zr->overlay_settings.format = fmt;
-       zr->buffer.bytesperline = bytesperline;
-
-       /* The user should set new window parameters */
-       zr->overlay_settings.is_set = 0;
-
-       return 0;
-}
-
-
-static int
-setup_window (struct file       *file,
-             int                x,
-             int                y,
-             int                width,
-             int                height,
-             struct video_clip __user *clips,
-             int                clipcount,
-             void              __user *bitmap)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       struct video_clip *vcp = NULL;
-       int on, end;
-
-
-       if (!zr->buffer.base) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_window() - frame buffer has to be set first\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       if (!fh->overlay_settings.format) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_window() - no overlay format set\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       /*
-        * The video front end needs 4-byte alinged line sizes, we correct that
-        * silently here if necessary
-        */
-       if (zr->buffer.depth == 15 || zr->buffer.depth == 16) {
-               end = (x + width) & ~1; /* round down */
-               x = (x + 1) & ~1;       /* round up */
-               width = end - x;
-       }
-
-       if (zr->buffer.depth == 24) {
-               end = (x + width) & ~3; /* round down */
-               x = (x + 3) & ~3;       /* round up */
-               width = end - x;
-       }
-
-       if (width > BUZ_MAX_WIDTH)
-               width = BUZ_MAX_WIDTH;
-       if (height > BUZ_MAX_HEIGHT)
-               height = BUZ_MAX_HEIGHT;
-
-       /* Check for vaild parameters */
-       if (width < BUZ_MIN_WIDTH || height < BUZ_MIN_HEIGHT ||
-           width > BUZ_MAX_WIDTH || height > BUZ_MAX_HEIGHT) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_window() - width = %d or height = %d invalid\n",
-                       ZR_DEVNAME(zr), width, height);
-               return -EINVAL;
-       }
-
-       fh->overlay_settings.x = x;
-       fh->overlay_settings.y = y;
-       fh->overlay_settings.width = width;
-       fh->overlay_settings.height = height;
-       fh->overlay_settings.clipcount = clipcount;
-
-       /*
-        * If an overlay is running, we have to switch it off
-        * and switch it on again in order to get the new settings in effect.
-        *
-        * We also want to avoid that the overlay mask is written
-        * when an overlay is running.
-        */
-
-       on = zr->v4l_overlay_active && !zr->v4l_memgrab_active &&
-           zr->overlay_active != ZORAN_FREE &&
-           fh->overlay_active != ZORAN_FREE;
-       if (on)
-               zr36057_overlay(zr, 0);
-
-       /*
-        *   Write the overlay mask if clips are wanted.
-        *   We prefer a bitmap.
-        */
-       if (bitmap) {
-               /* fake value - it just means we want clips */
-               fh->overlay_settings.clipcount = 1;
-
-               if (copy_from_user(fh->overlay_mask, bitmap,
-                                  (width * height + 7) / 8)) {
-                       return -EFAULT;
-               }
-       } else if (clipcount > 0) {
-               /* write our own bitmap from the clips */
-               vcp = vmalloc(sizeof(struct video_clip) * (clipcount + 4));
-               if (vcp == NULL) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: setup_window() - Alloc of clip mask failed\n",
-                               ZR_DEVNAME(zr));
-                       return -ENOMEM;
-               }
-               if (copy_from_user
-                   (vcp, clips, sizeof(struct video_clip) * clipcount)) {
-                       vfree(vcp);
-                       return -EFAULT;
-               }
-               write_overlay_mask(file, vcp, clipcount);
-               vfree(vcp);
-       }
-
-       fh->overlay_settings.is_set = 1;
-       if (fh->overlay_active != ZORAN_FREE &&
-           zr->overlay_active != ZORAN_FREE)
-               zr->overlay_settings = fh->overlay_settings;
-
-       if (on)
-               zr36057_overlay(zr, 1);
-
-       /* Make sure the changes come into effect */
-       return wait_grab_pending(zr);
-}
-
-static int
-setup_overlay (struct file *file,
-              int          on)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       /* If there is nothing to do, return immediatly */
-       if ((on && fh->overlay_active != ZORAN_FREE) ||
-           (!on && fh->overlay_active == ZORAN_FREE))
-               return 0;
-
-       /* check whether we're touching someone else's overlay */
-       if (on && zr->overlay_active != ZORAN_FREE &&
-           fh->overlay_active == ZORAN_FREE) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_overlay() - overlay is already active for another session\n",
-                       ZR_DEVNAME(zr));
-               return -EBUSY;
-       }
-       if (!on && zr->overlay_active != ZORAN_FREE &&
-           fh->overlay_active == ZORAN_FREE) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: setup_overlay() - you cannot cancel someone else's session\n",
-                       ZR_DEVNAME(zr));
-               return -EPERM;
-       }
-
-       if (on == 0) {
-               zr->overlay_active = fh->overlay_active = ZORAN_FREE;
-               zr->v4l_overlay_active = 0;
-               /* When a grab is running, the video simply
-                * won't be switched on any more */
-               if (!zr->v4l_memgrab_active)
-                       zr36057_overlay(zr, 0);
-               zr->overlay_mask = NULL;
-       } else {
-               if (!zr->buffer.base || !fh->overlay_settings.is_set) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: setup_overlay() - buffer or window not set\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-               if (!fh->overlay_settings.format) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: setup_overlay() - no overlay format set\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-               zr->overlay_active = fh->overlay_active = ZORAN_LOCKED;
-               zr->v4l_overlay_active = 1;
-               zr->overlay_mask = fh->overlay_mask;
-               zr->overlay_settings = fh->overlay_settings;
-               if (!zr->v4l_memgrab_active)
-                       zr36057_overlay(zr, 1);
-               /* When a grab is running, the video will be
-                * switched on when grab is finished */
-       }
-
-       /* Make sure the changes come into effect */
-       return wait_grab_pending(zr);
-}
-
-       /* get the status of a buffer in the clients buffer queue */
-static int
-zoran_v4l2_buffer_status (struct file        *file,
-                         struct v4l2_buffer *buf,
-                         int                 num)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-
-       buf->flags = V4L2_BUF_FLAG_MAPPED;
-
-       switch (fh->map_mode) {
-       case ZORAN_MAP_MODE_RAW:
-
-               /* check range */
-               if (num < 0 || num >= fh->v4l_buffers.num_buffers ||
-                   !fh->v4l_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-
-               buf->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-               buf->length = fh->v4l_buffers.buffer_size;
-
-               /* get buffer */
-               buf->bytesused = fh->v4l_buffers.buffer[num].bs.length;
-               if (fh->v4l_buffers.buffer[num].state == BUZ_STATE_DONE ||
-                   fh->v4l_buffers.buffer[num].state == BUZ_STATE_USER) {
-                       buf->sequence = fh->v4l_buffers.buffer[num].bs.seq;
-                       buf->flags |= V4L2_BUF_FLAG_DONE;
-                       buf->timestamp =
-                           fh->v4l_buffers.buffer[num].bs.timestamp;
-               } else {
-                       buf->flags |= V4L2_BUF_FLAG_QUEUED;
-               }
-
-               if (fh->v4l_settings.height <= BUZ_MAX_HEIGHT / 2)
-                       buf->field = V4L2_FIELD_TOP;
-               else
-                       buf->field = V4L2_FIELD_INTERLACED;
-
-               break;
-
-       case ZORAN_MAP_MODE_JPG_REC:
-       case ZORAN_MAP_MODE_JPG_PLAY:
-
-               /* check range */
-               if (num < 0 || num >= fh->jpg_buffers.num_buffers ||
-                   !fh->jpg_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: v4l2_buffer_status() - wrong number or buffers not allocated\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-
-               buf->type = (fh->map_mode == ZORAN_MAP_MODE_JPG_REC) ?
-                             V4L2_BUF_TYPE_VIDEO_CAPTURE :
-                             V4L2_BUF_TYPE_VIDEO_OUTPUT;
-               buf->length = fh->jpg_buffers.buffer_size;
-
-               /* these variables are only written after frame has been captured */
-               if (fh->jpg_buffers.buffer[num].state == BUZ_STATE_DONE ||
-                   fh->jpg_buffers.buffer[num].state == BUZ_STATE_USER) {
-                       buf->sequence = fh->jpg_buffers.buffer[num].bs.seq;
-                       buf->timestamp =
-                           fh->jpg_buffers.buffer[num].bs.timestamp;
-                       buf->bytesused =
-                           fh->jpg_buffers.buffer[num].bs.length;
-                       buf->flags |= V4L2_BUF_FLAG_DONE;
-               } else {
-                       buf->flags |= V4L2_BUF_FLAG_QUEUED;
-               }
-
-               /* which fields are these? */
-               if (fh->jpg_settings.TmpDcm != 1)
-                       buf->field =
-                           fh->jpg_settings.
-                           odd_even ? V4L2_FIELD_TOP : V4L2_FIELD_BOTTOM;
-               else
-                       buf->field =
-                           fh->jpg_settings.
-                           odd_even ? V4L2_FIELD_SEQ_TB :
-                           V4L2_FIELD_SEQ_BT;
-
-               break;
-
-       default:
-
-               dprintk(5,
-                       KERN_ERR
-                       "%s: v4l2_buffer_status() - invalid buffer type|map_mode (%d|%d)\n",
-                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
-               return -EINVAL;
-       }
-
-       buf->memory = V4L2_MEMORY_MMAP;
-       buf->index = num;
-       buf->m.offset = buf->length * num;
-
-       return 0;
-}
-
-static int
-zoran_set_norm (struct zoran *zr,
-               int           norm) /* VIDEO_MODE_* */
-{
-       int norm_encoder, on;
-
-       if (zr->v4l_buffers.active != ZORAN_FREE ||
-           zr->jpg_buffers.active != ZORAN_FREE) {
-               dprintk(1,
-                       KERN_WARNING
-                       "%s: set_norm() called while in playback/capture mode\n",
-                       ZR_DEVNAME(zr));
-               return -EBUSY;
-       }
-
-       if (lock_norm && norm != zr->norm) {
-               if (lock_norm > 1) {
-                       dprintk(1,
-                               KERN_WARNING
-                               "%s: set_norm() - TV standard is locked, can not switch norm\n",
-                               ZR_DEVNAME(zr));
-                       return -EPERM;
-               } else {
-                       dprintk(1,
-                               KERN_WARNING
-                               "%s: set_norm() - TV standard is locked, norm was not changed\n",
-                               ZR_DEVNAME(zr));
-                       norm = zr->norm;
-               }
-       }
-
-       if (norm != VIDEO_MODE_AUTO &&
-           (norm < 0 || norm >= zr->card.norms ||
-            !zr->card.tvn[norm])) {
-               dprintk(1,
-                       KERN_ERR "%s: set_norm() - unsupported norm %d\n",
-                       ZR_DEVNAME(zr), norm);
-               return -EINVAL;
-       }
-
-       if (norm == VIDEO_MODE_AUTO) {
-               int status;
-
-               /* if we have autodetect, ... */
-               struct video_decoder_capability caps;
-               decoder_command(zr, DECODER_GET_CAPABILITIES, &caps);
-               if (!(caps.flags & VIDEO_DECODER_AUTO)) {
-                       dprintk(1, KERN_ERR "%s: norm=auto unsupported\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-
-               decoder_command(zr, DECODER_SET_NORM, &norm);
-
-               /* let changes come into effect */
-               ssleep(2);
-
-               decoder_command(zr, DECODER_GET_STATUS, &status);
-               if (!(status & DECODER_STATUS_GOOD)) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: set_norm() - no norm detected\n",
-                               ZR_DEVNAME(zr));
-                       /* reset norm */
-                       decoder_command(zr, DECODER_SET_NORM, &zr->norm);
-                       return -EIO;
-               }
-
-               if (status & DECODER_STATUS_NTSC)
-                       norm = VIDEO_MODE_NTSC;
-               else if (status & DECODER_STATUS_SECAM)
-                       norm = VIDEO_MODE_SECAM;
-               else
-                       norm = VIDEO_MODE_PAL;
-       }
-       zr->timing = zr->card.tvn[norm];
-       norm_encoder = norm;
-
-       /* We switch overlay off and on since a change in the
-        * norm needs different VFE settings */
-       on = zr->overlay_active && !zr->v4l_memgrab_active;
-       if (on)
-               zr36057_overlay(zr, 0);
-
-       decoder_command(zr, DECODER_SET_NORM, &norm);
-       encoder_command(zr, ENCODER_SET_NORM, &norm_encoder);
-
-       if (on)
-               zr36057_overlay(zr, 1);
-
-       /* Make sure the changes come into effect */
-       zr->norm = norm;
-
-       return 0;
-}
-
-static int
-zoran_set_input (struct zoran *zr,
-                int           input)
-{
-       int realinput;
-
-       if (input == zr->input) {
-               return 0;
-       }
-
-       if (zr->v4l_buffers.active != ZORAN_FREE ||
-           zr->jpg_buffers.active != ZORAN_FREE) {
-               dprintk(1,
-                       KERN_WARNING
-                       "%s: set_input() called while in playback/capture mode\n",
-                       ZR_DEVNAME(zr));
-               return -EBUSY;
-       }
-
-       if (input < 0 || input >= zr->card.inputs) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: set_input() - unnsupported input %d\n",
-                       ZR_DEVNAME(zr), input);
-               return -EINVAL;
-       }
-
-       realinput = zr->card.input[input].muxsel;
-       zr->input = input;
-
-       decoder_command(zr, DECODER_SET_INPUT, &realinput);
-
-       return 0;
-}
-
-/*
- *   ioctl routine
- */
-
-static int
-zoran_do_ioctl (struct inode *inode,
-               struct file  *file,
-               unsigned int  cmd,
-               void         *arg)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       /* CAREFUL: used in multiple places here */
-       struct zoran_jpg_settings settings;
-
-       /* we might have older buffers lying around... We don't want
-        * to wait, but we do want to try cleaning them up ASAP. So
-        * we try to obtain the lock and free them. If that fails, we
-        * don't do anything and wait for the next turn. In the end,
-        * zoran_close() or a new allocation will still free them...
-        * This is just a 'the sooner the better' extra 'feature'
-        *
-        * We don't free the buffers right on munmap() because that
-        * causes oopses (kfree() inside munmap() oopses for no
-        * apparent reason - it's also not reproduceable in any way,
-        * but moving the free code outside the munmap() handler fixes
-        * all this... If someone knows why, please explain me (Ronald)
-        */
-       if (mutex_trylock(&zr->resource_lock)) {
-               /* we obtained it! Let's try to free some things */
-               if (fh->jpg_buffers.ready_to_be_freed)
-                       jpg_fbuffer_free(file);
-               if (fh->v4l_buffers.ready_to_be_freed)
-                       v4l_fbuffer_free(file);
-
-               mutex_unlock(&zr->resource_lock);
-       }
-
-       switch (cmd) {
-
-       case VIDIOCGCAP:
-       {
-               struct video_capability *vcap = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGCAP\n", ZR_DEVNAME(zr));
-
-               memset(vcap, 0, sizeof(struct video_capability));
-               strncpy(vcap->name, ZR_DEVNAME(zr), sizeof(vcap->name)-1);
-               vcap->type = ZORAN_VID_TYPE;
-
-               vcap->channels = zr->card.inputs;
-               vcap->audios = 0;
-               mutex_lock(&zr->resource_lock);
-               vcap->maxwidth = BUZ_MAX_WIDTH;
-               vcap->maxheight = BUZ_MAX_HEIGHT;
-               vcap->minwidth = BUZ_MIN_WIDTH;
-               vcap->minheight = BUZ_MIN_HEIGHT;
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOCGCHAN:
-       {
-               struct video_channel *vchan = arg;
-               int channel = vchan->channel;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGCHAN - channel=%d\n",
-                       ZR_DEVNAME(zr), vchan->channel);
-
-               memset(vchan, 0, sizeof(struct video_channel));
-               if (channel > zr->card.inputs || channel < 0) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOCGCHAN on not existing channel %d\n",
-                               ZR_DEVNAME(zr), channel);
-                       return -EINVAL;
-               }
-
-               strcpy(vchan->name, zr->card.input[channel].name);
-
-               vchan->tuners = 0;
-               vchan->flags = 0;
-               vchan->type = VIDEO_TYPE_CAMERA;
-               mutex_lock(&zr->resource_lock);
-               vchan->norm = zr->norm;
-               mutex_unlock(&zr->resource_lock);
-               vchan->channel = channel;
-
-               return 0;
-       }
-               break;
-
-               /* RJ: the documentation at http://roadrunner.swansea.linux.org.uk/v4lapi.shtml says:
-                *
-                * * "The VIDIOCSCHAN ioctl takes an integer argument and switches the capture to this input."
-                * *                                 ^^^^^^^
-                * * The famos BTTV driver has it implemented with a struct video_channel argument
-                * * and we follow it for compatibility reasons
-                * *
-                * * BTW: this is the only way the user can set the norm!
-                */
-
-       case VIDIOCSCHAN:
-       {
-               struct video_channel *vchan = arg;
-               int res;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOCSCHAN - channel=%d, norm=%d\n",
-                       ZR_DEVNAME(zr), vchan->channel, vchan->norm);
-
-               mutex_lock(&zr->resource_lock);
-               if ((res = zoran_set_input(zr, vchan->channel)))
-                       goto schan_unlock_and_return;
-               if ((res = zoran_set_norm(zr, vchan->norm)))
-                       goto schan_unlock_and_return;
-
-               /* Make sure the changes come into effect */
-               res = wait_grab_pending(zr);
-       schan_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOCGPICT:
-       {
-               struct video_picture *vpict = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGPICT\n", ZR_DEVNAME(zr));
-
-               memset(vpict, 0, sizeof(struct video_picture));
-               mutex_lock(&zr->resource_lock);
-               vpict->hue = zr->hue;
-               vpict->brightness = zr->brightness;
-               vpict->contrast = zr->contrast;
-               vpict->colour = zr->saturation;
-               if (fh->overlay_settings.format) {
-                       vpict->depth = fh->overlay_settings.format->depth;
-                       vpict->palette = fh->overlay_settings.format->palette;
-               } else {
-                       vpict->depth = 0;
-               }
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOCSPICT:
-       {
-               struct video_picture *vpict = arg;
-               int i;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOCSPICT - bri=%d, hue=%d, col=%d, con=%d, dep=%d, pal=%d\n",
-                       ZR_DEVNAME(zr), vpict->brightness, vpict->hue,
-                       vpict->colour, vpict->contrast, vpict->depth,
-                       vpict->palette);
-
-               for (i = 0; i < NUM_FORMATS; i++) {
-                       const struct zoran_format *fmt = &zoran_formats[i];
-
-                       if (fmt->palette != -1 &&
-                           fmt->flags & ZORAN_FORMAT_OVERLAY &&
-                           fmt->palette == vpict->palette &&
-                           fmt->depth == vpict->depth)
-                               break;
-               }
-               if (i == NUM_FORMATS) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOCSPICT - Invalid palette %d\n",
-                               ZR_DEVNAME(zr), vpict->palette);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-
-               decoder_command(zr, DECODER_SET_PICTURE, vpict);
-
-               zr->hue = vpict->hue;
-               zr->contrast = vpict->contrast;
-               zr->saturation = vpict->colour;
-               zr->brightness = vpict->brightness;
-
-               fh->overlay_settings.format = &zoran_formats[i];
-
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOCCAPTURE:
-       {
-               int *on = arg, res;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCCAPTURE - on=%d\n",
-                       ZR_DEVNAME(zr), *on);
-
-               mutex_lock(&zr->resource_lock);
-               res = setup_overlay(file, *on);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOCGWIN:
-       {
-               struct video_window *vwin = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGWIN\n", ZR_DEVNAME(zr));
-
-               memset(vwin, 0, sizeof(struct video_window));
-               mutex_lock(&zr->resource_lock);
-               vwin->x = fh->overlay_settings.x;
-               vwin->y = fh->overlay_settings.y;
-               vwin->width = fh->overlay_settings.width;
-               vwin->height = fh->overlay_settings.height;
-               mutex_unlock(&zr->resource_lock);
-               vwin->clipcount = 0;
-               return 0;
-       }
-               break;
-
-       case VIDIOCSWIN:
-       {
-               struct video_window *vwin = arg;
-               int res;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOCSWIN - x=%d, y=%d, w=%d, h=%d, clipcount=%d\n",
-                       ZR_DEVNAME(zr), vwin->x, vwin->y, vwin->width,
-                       vwin->height, vwin->clipcount);
-
-               mutex_lock(&zr->resource_lock);
-               res =
-                   setup_window(file, vwin->x, vwin->y, vwin->width,
-                                vwin->height, vwin->clips,
-                                vwin->clipcount, NULL);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOCGFBUF:
-       {
-               struct video_buffer *vbuf = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGFBUF\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-               *vbuf = zr->buffer;
-               mutex_unlock(&zr->resource_lock);
-               return 0;
-       }
-               break;
-
-       case VIDIOCSFBUF:
-       {
-               struct video_buffer *vbuf = arg;
-               int i, res = 0;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOCSFBUF - base=%p, w=%d, h=%d, depth=%d, bpl=%d\n",
-                       ZR_DEVNAME(zr), vbuf->base, vbuf->width,
-                       vbuf->height, vbuf->depth, vbuf->bytesperline);
-
-               for (i = 0; i < NUM_FORMATS; i++)
-                       if (zoran_formats[i].depth == vbuf->depth)
-                               break;
-               if (i == NUM_FORMATS) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOCSFBUF - invalid fbuf depth %d\n",
-                               ZR_DEVNAME(zr), vbuf->depth);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-               res =
-                   setup_fbuffer(file, vbuf->base, &zoran_formats[i],
-                                 vbuf->width, vbuf->height,
-                                 vbuf->bytesperline);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOCSYNC:
-       {
-               int *frame = arg, res;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCSYNC - frame=%d\n",
-                       ZR_DEVNAME(zr), *frame);
-
-               mutex_lock(&zr->resource_lock);
-               res = v4l_sync(file, *frame);
-               mutex_unlock(&zr->resource_lock);
-               if (!res)
-                       zr->v4l_sync_tail++;
-               return res;
-       }
-               break;
-
-       case VIDIOCMCAPTURE:
-       {
-               struct video_mmap *vmap = arg;
-               int res;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOCMCAPTURE - frame=%d, geom=%dx%d, fmt=%d\n",
-                       ZR_DEVNAME(zr), vmap->frame, vmap->width, vmap->height,
-                       vmap->format);
-
-               mutex_lock(&zr->resource_lock);
-               res = v4l_grab(file, vmap);
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOCGMBUF:
-       {
-               struct video_mbuf *vmbuf = arg;
-               int i, res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGMBUF\n", ZR_DEVNAME(zr));
-
-               vmbuf->size =
-                   fh->v4l_buffers.num_buffers *
-                   fh->v4l_buffers.buffer_size;
-               vmbuf->frames = fh->v4l_buffers.num_buffers;
-               for (i = 0; i < vmbuf->frames; i++) {
-                       vmbuf->offsets[i] =
-                           i * fh->v4l_buffers.buffer_size;
-               }
-
-               mutex_lock(&zr->resource_lock);
-
-               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOCGMBUF - buffers already allocated\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto v4l1reqbuf_unlock_and_return;
-               }
-
-               if (v4l_fbuffer_alloc(file)) {
-                       res = -ENOMEM;
-                       goto v4l1reqbuf_unlock_and_return;
-               }
-
-               /* The next mmap will map the V4L buffers */
-               fh->map_mode = ZORAN_MAP_MODE_RAW;
-       v4l1reqbuf_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOCGUNIT:
-       {
-               struct video_unit *vunit = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOCGUNIT\n", ZR_DEVNAME(zr));
-
-               vunit->video = zr->video_dev->minor;
-               vunit->vbi = VIDEO_NO_UNIT;
-               vunit->radio = VIDEO_NO_UNIT;
-               vunit->audio = VIDEO_NO_UNIT;
-               vunit->teletext = VIDEO_NO_UNIT;
-
-               return 0;
-       }
-               break;
-
-               /*
-                * RJ: In principal we could support subcaptures for V4L grabbing.
-                *     Not even the famous BTTV driver has them, however.
-                *     If there should be a strong demand, one could consider
-                *     to implement them.
-                */
-       case VIDIOCGCAPTURE:
-       {
-               dprintk(3, KERN_ERR "%s: VIDIOCGCAPTURE not supported\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-               break;
-
-       case VIDIOCSCAPTURE:
-       {
-               dprintk(3, KERN_ERR "%s: VIDIOCSCAPTURE not supported\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-               break;
-
-       case BUZIOC_G_PARAMS:
-       {
-               struct zoran_params *bparams = arg;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_G_PARAMS\n", ZR_DEVNAME(zr));
-
-               memset(bparams, 0, sizeof(struct zoran_params));
-               bparams->major_version = MAJOR_VERSION;
-               bparams->minor_version = MINOR_VERSION;
-
-               mutex_lock(&zr->resource_lock);
-
-               bparams->norm = zr->norm;
-               bparams->input = zr->input;
-
-               bparams->decimation = fh->jpg_settings.decimation;
-               bparams->HorDcm = fh->jpg_settings.HorDcm;
-               bparams->VerDcm = fh->jpg_settings.VerDcm;
-               bparams->TmpDcm = fh->jpg_settings.TmpDcm;
-               bparams->field_per_buff = fh->jpg_settings.field_per_buff;
-               bparams->img_x = fh->jpg_settings.img_x;
-               bparams->img_y = fh->jpg_settings.img_y;
-               bparams->img_width = fh->jpg_settings.img_width;
-               bparams->img_height = fh->jpg_settings.img_height;
-               bparams->odd_even = fh->jpg_settings.odd_even;
-
-               bparams->quality = fh->jpg_settings.jpg_comp.quality;
-               bparams->APPn = fh->jpg_settings.jpg_comp.APPn;
-               bparams->APP_len = fh->jpg_settings.jpg_comp.APP_len;
-               memcpy(bparams->APP_data,
-                      fh->jpg_settings.jpg_comp.APP_data,
-                      sizeof(bparams->APP_data));
-               bparams->COM_len = zr->jpg_settings.jpg_comp.COM_len;
-               memcpy(bparams->COM_data,
-                      fh->jpg_settings.jpg_comp.COM_data,
-                      sizeof(bparams->COM_data));
-               bparams->jpeg_markers =
-                   fh->jpg_settings.jpg_comp.jpeg_markers;
-
-               mutex_unlock(&zr->resource_lock);
-
-               bparams->VFIFO_FB = 0;
-
-               return 0;
-       }
-               break;
-
-       case BUZIOC_S_PARAMS:
-       {
-               struct zoran_params *bparams = arg;
-               int res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_S_PARAMS\n", ZR_DEVNAME(zr));
-
-               settings.decimation = bparams->decimation;
-               settings.HorDcm = bparams->HorDcm;
-               settings.VerDcm = bparams->VerDcm;
-               settings.TmpDcm = bparams->TmpDcm;
-               settings.field_per_buff = bparams->field_per_buff;
-               settings.img_x = bparams->img_x;
-               settings.img_y = bparams->img_y;
-               settings.img_width = bparams->img_width;
-               settings.img_height = bparams->img_height;
-               settings.odd_even = bparams->odd_even;
-
-               settings.jpg_comp.quality = bparams->quality;
-               settings.jpg_comp.APPn = bparams->APPn;
-               settings.jpg_comp.APP_len = bparams->APP_len;
-               memcpy(settings.jpg_comp.APP_data, bparams->APP_data,
-                      sizeof(bparams->APP_data));
-               settings.jpg_comp.COM_len = bparams->COM_len;
-               memcpy(settings.jpg_comp.COM_data, bparams->COM_data,
-                      sizeof(bparams->COM_data));
-               settings.jpg_comp.jpeg_markers = bparams->jpeg_markers;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (zr->codec_mode != BUZ_MODE_IDLE) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: BUZIOC_S_PARAMS called, but Buz in capture/playback mode\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto sparams_unlock_and_return;
-               }
-
-               /* Check the params first before overwriting our
-                * nternal values */
-               if (zoran_check_jpg_settings(zr, &settings)) {
-                       res = -EINVAL;
-                       goto sparams_unlock_and_return;
-               }
-
-               fh->jpg_settings = settings;
-       sparams_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case BUZIOC_REQBUFS:
-       {
-               struct zoran_requestbuffers *breq = arg;
-               int res = 0;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: BUZIOC_REQBUFS - count=%lu, size=%lu\n",
-                       ZR_DEVNAME(zr), breq->count, breq->size);
-
-               /* Enforce reasonable lower and upper limits */
-               if (breq->count < 4)
-                       breq->count = 4;        /* Could be choosen smaller */
-               if (breq->count > jpg_nbufs)
-                       breq->count = jpg_nbufs;
-               breq->size = PAGE_ALIGN(breq->size);
-               if (breq->size < 8192)
-                       breq->size = 8192;      /* Arbitrary */
-               /* breq->size is limited by 1 page for the stat_com
-                * tables to a Maximum of 2 MB */
-               if (breq->size > jpg_bufsize)
-                       breq->size = jpg_bufsize;
-               if (fh->jpg_buffers.need_contiguous &&
-                   breq->size > MAX_KMALLOC_MEM)
-                       breq->size = MAX_KMALLOC_MEM;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: BUZIOC_REQBUFS - buffers allready allocated\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-                       goto jpgreqbuf_unlock_and_return;
-               }
-
-               fh->jpg_buffers.num_buffers = breq->count;
-               fh->jpg_buffers.buffer_size = breq->size;
-
-               if (jpg_fbuffer_alloc(file)) {
-                       res = -ENOMEM;
-                       goto jpgreqbuf_unlock_and_return;
-               }
-
-               /* The next mmap will map the MJPEG buffers - could
-                * also be *_PLAY, but it doesn't matter here */
-               fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
-       jpgreqbuf_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case BUZIOC_QBUF_CAPT:
-       {
-               int *frame = arg, res;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_CAPT - frame=%d\n",
-                       ZR_DEVNAME(zr), *frame);
-
-               mutex_lock(&zr->resource_lock);
-               res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_COMPRESS);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case BUZIOC_QBUF_PLAY:
-       {
-               int *frame = arg, res;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_QBUF_PLAY - frame=%d\n",
-                       ZR_DEVNAME(zr), *frame);
-
-               mutex_lock(&zr->resource_lock);
-               res = jpg_qbuf(file, *frame, BUZ_MODE_MOTION_DECOMPRESS);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case BUZIOC_SYNC:
-       {
-               struct zoran_sync *bsync = arg;
-               int res;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_SYNC\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-               res = jpg_sync(file, bsync);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case BUZIOC_G_STATUS:
-       {
-               struct zoran_status *bstat = arg;
-               int norm, input, status, res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: BUZIOC_G_STATUS\n", ZR_DEVNAME(zr));
-
-               if (zr->codec_mode != BUZ_MODE_IDLE) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: BUZIOC_G_STATUS called but Buz in capture/playback mode\n",
-                               ZR_DEVNAME(zr));
-                       return -EINVAL;
-               }
-
-               input = zr->card.input[bstat->input].muxsel;
-               norm = VIDEO_MODE_AUTO;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (zr->codec_mode != BUZ_MODE_IDLE) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: BUZIOC_G_STATUS called, but Buz in capture/playback mode\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto gstat_unlock_and_return;
-               }
-
-               decoder_command(zr, DECODER_SET_INPUT, &input);
-               decoder_command(zr, DECODER_SET_NORM, &norm);
-
-               /* sleep 1 second */
-               ssleep(1);
-
-               /* Get status of video decoder */
-               decoder_command(zr, DECODER_GET_STATUS, &status);
-
-               /* restore previous input and norm */
-               input = zr->card.input[zr->input].muxsel;
-               decoder_command(zr, DECODER_SET_INPUT, &input);
-               decoder_command(zr, DECODER_SET_NORM, &zr->norm);
-       gstat_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               if (!res) {
-                       bstat->signal =
-                           (status & DECODER_STATUS_GOOD) ? 1 : 0;
-                       if (status & DECODER_STATUS_NTSC)
-                               bstat->norm = VIDEO_MODE_NTSC;
-                       else if (status & DECODER_STATUS_SECAM)
-                               bstat->norm = VIDEO_MODE_SECAM;
-                       else
-                               bstat->norm = VIDEO_MODE_PAL;
-
-                       bstat->color =
-                           (status & DECODER_STATUS_COLOR) ? 1 : 0;
-               }
-
-               return res;
-       }
-               break;
-
-               /* The new video4linux2 capture interface - much nicer than video4linux1, since
-                * it allows for integrating the JPEG capturing calls inside standard v4l2
-                */
-
-       case VIDIOC_QUERYCAP:
-       {
-               struct v4l2_capability *cap = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCAP\n", ZR_DEVNAME(zr));
-
-               memset(cap, 0, sizeof(*cap));
-               strncpy(cap->card, ZR_DEVNAME(zr), sizeof(cap->card)-1);
-               strncpy(cap->driver, "zoran", sizeof(cap->driver)-1);
-               snprintf(cap->bus_info, sizeof(cap->bus_info), "PCI:%s",
-                        pci_name(zr->pci_dev));
-               cap->version =
-                   KERNEL_VERSION(MAJOR_VERSION, MINOR_VERSION,
-                                  RELEASE_VERSION);
-               cap->capabilities = ZORAN_V4L2_VID_FLAGS;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_ENUM_FMT:
-       {
-               struct v4l2_fmtdesc *fmt = arg;
-               int index = fmt->index, num = -1, i, flag = 0, type =
-                   fmt->type;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUM_FMT - index=%d\n",
-                       ZR_DEVNAME(zr), fmt->index);
-
-               switch (fmt->type) {
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-                       flag = ZORAN_FORMAT_CAPTURE;
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       flag = ZORAN_FORMAT_PLAYBACK;
-                       break;
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       flag = ZORAN_FORMAT_OVERLAY;
-                       break;
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_ENUM_FMT - unknown type %d\n",
-                               ZR_DEVNAME(zr), fmt->type);
-                       return -EINVAL;
-               }
-
-               for (i = 0; i < NUM_FORMATS; i++) {
-                       if (zoran_formats[i].flags & flag)
-                               num++;
-                       if (num == fmt->index)
-                               break;
-               }
-               if (fmt->index < 0 /* late, but not too late */  ||
-                   i == NUM_FORMATS)
-                       return -EINVAL;
-
-               memset(fmt, 0, sizeof(*fmt));
-               fmt->index = index;
-               fmt->type = type;
-               strncpy(fmt->description, zoran_formats[i].name, sizeof(fmt->description)-1);
-               fmt->pixelformat = zoran_formats[i].fourcc;
-               if (zoran_formats[i].flags & ZORAN_FORMAT_COMPRESSED)
-                       fmt->flags |= V4L2_FMT_FLAG_COMPRESSED;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_G_FMT:
-       {
-               struct v4l2_format *fmt = arg;
-               int type = fmt->type;
-
-               dprintk(5, KERN_DEBUG "%s: VIDIOC_G_FMT\n", ZR_DEVNAME(zr));
-
-               memset(fmt, 0, sizeof(*fmt));
-               fmt->type = type;
-
-               switch (fmt->type) {
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-
-                       mutex_lock(&zr->resource_lock);
-
-                       fmt->fmt.win.w.left = fh->overlay_settings.x;
-                       fmt->fmt.win.w.top = fh->overlay_settings.y;
-                       fmt->fmt.win.w.width = fh->overlay_settings.width;
-                       fmt->fmt.win.w.height =
-                           fh->overlay_settings.height;
-                       if (fh->overlay_settings.width * 2 >
-                           BUZ_MAX_HEIGHT)
-                               fmt->fmt.win.field = V4L2_FIELD_INTERLACED;
-                       else
-                               fmt->fmt.win.field = V4L2_FIELD_TOP;
-
-                       mutex_unlock(&zr->resource_lock);
-
-                       break;
-
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-
-                       mutex_lock(&zr->resource_lock);
-
-                       if (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE &&
-                           fh->map_mode == ZORAN_MAP_MODE_RAW) {
-
-                               fmt->fmt.pix.width =
-                                   fh->v4l_settings.width;
-                               fmt->fmt.pix.height =
-                                   fh->v4l_settings.height;
-                               fmt->fmt.pix.sizeimage =
-                                   fh->v4l_settings.bytesperline *
-                                   fh->v4l_settings.height;
-                               fmt->fmt.pix.pixelformat =
-                                   fh->v4l_settings.format->fourcc;
-                               fmt->fmt.pix.colorspace =
-                                   fh->v4l_settings.format->colorspace;
-                               fmt->fmt.pix.bytesperline =
-                                   fh->v4l_settings.bytesperline;
-                               if (BUZ_MAX_HEIGHT <
-                                   (fh->v4l_settings.height * 2))
-                                       fmt->fmt.pix.field =
-                                           V4L2_FIELD_INTERLACED;
-                               else
-                                       fmt->fmt.pix.field =
-                                           V4L2_FIELD_TOP;
-
-                       } else {
-
-                               fmt->fmt.pix.width =
-                                   fh->jpg_settings.img_width /
-                                   fh->jpg_settings.HorDcm;
-                               fmt->fmt.pix.height =
-                                   fh->jpg_settings.img_height /
-                                   (fh->jpg_settings.VerDcm *
-                                    fh->jpg_settings.TmpDcm);
-                               fmt->fmt.pix.sizeimage =
-                                   zoran_v4l2_calc_bufsize(&fh->
-                                                           jpg_settings);
-                               fmt->fmt.pix.pixelformat =
-                                   V4L2_PIX_FMT_MJPEG;
-                               if (fh->jpg_settings.TmpDcm == 1)
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_SEQ_BT :
-                                            V4L2_FIELD_SEQ_BT);
-                               else
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_TOP :
-                                            V4L2_FIELD_BOTTOM);
-
-                               fmt->fmt.pix.bytesperline = 0;
-                               fmt->fmt.pix.colorspace =
-                                   V4L2_COLORSPACE_SMPTE170M;
-                       }
-
-                       mutex_unlock(&zr->resource_lock);
-
-                       break;
-
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_G_FMT - unsupported type %d\n",
-                               ZR_DEVNAME(zr), fmt->type);
-                       return -EINVAL;
-               }
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_FMT:
-       {
-               struct v4l2_format *fmt = arg;
-               int i, res = 0;
-               __le32 printformat;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_FMT - type=%d, ",
-                       ZR_DEVNAME(zr), fmt->type);
-
-               switch (fmt->type) {
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-
-                       dprintk(3, "x=%d, y=%d, w=%d, h=%d, cnt=%d, map=0x%p\n",
-                               fmt->fmt.win.w.left, fmt->fmt.win.w.top,
-                               fmt->fmt.win.w.width,
-                               fmt->fmt.win.w.height,
-                               fmt->fmt.win.clipcount,
-                               fmt->fmt.win.bitmap);
-                       mutex_lock(&zr->resource_lock);
-                       res =
-                           setup_window(file, fmt->fmt.win.w.left,
-                                        fmt->fmt.win.w.top,
-                                        fmt->fmt.win.w.width,
-                                        fmt->fmt.win.w.height,
-                                        (struct video_clip __user *)
-                                          fmt->fmt.win.clips,
-                                        fmt->fmt.win.clipcount,
-                                        fmt->fmt.win.bitmap);
-                       mutex_unlock(&zr->resource_lock);
-                       return res;
-                       break;
-
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-
-                       printformat =
-                           __cpu_to_le32(fmt->fmt.pix.pixelformat);
-                       dprintk(3, "size=%dx%d, fmt=0x%x (%4.4s)\n",
-                               fmt->fmt.pix.width, fmt->fmt.pix.height,
-                               fmt->fmt.pix.pixelformat,
-                               (char *) &printformat);
-
-                       /* we can be requested to do JPEG/raw playback/capture */
-                       if (!
-                           (fmt->type == V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-                            (fmt->type == V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-                             fmt->fmt.pix.pixelformat ==
-                             V4L2_PIX_FMT_MJPEG))) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: VIDIOC_S_FMT - unknown type %d/0x%x(%4.4s) combination\n",
-                                       ZR_DEVNAME(zr), fmt->type,
-                                       fmt->fmt.pix.pixelformat,
-                                       (char *) &printformat);
-                               return -EINVAL;
-                       }
-
-                       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
-                               mutex_lock(&zr->resource_lock);
-
-                               settings = fh->jpg_settings;
-
-                               if (fh->v4l_buffers.allocated ||
-                                   fh->jpg_buffers.allocated) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: VIDIOC_S_FMT - cannot change capture mode\n",
-                                               ZR_DEVNAME(zr));
-                                       res = -EBUSY;
-                                       goto sfmtjpg_unlock_and_return;
-                               }
-
-                               /* we actually need to set 'real' parameters now */
-                               if ((fmt->fmt.pix.height * 2) >
-                                   BUZ_MAX_HEIGHT)
-                                       settings.TmpDcm = 1;
-                               else
-                                       settings.TmpDcm = 2;
-                               settings.decimation = 0;
-                               if (fmt->fmt.pix.height <=
-                                   fh->jpg_settings.img_height / 2)
-                                       settings.VerDcm = 2;
-                               else
-                                       settings.VerDcm = 1;
-                               if (fmt->fmt.pix.width <=
-                                   fh->jpg_settings.img_width / 4)
-                                       settings.HorDcm = 4;
-                               else if (fmt->fmt.pix.width <=
-                                        fh->jpg_settings.img_width / 2)
-                                       settings.HorDcm = 2;
-                               else
-                                       settings.HorDcm = 1;
-                               if (settings.TmpDcm == 1)
-                                       settings.field_per_buff = 2;
-                               else
-                                       settings.field_per_buff = 1;
-
-                               /* check */
-                               if ((res =
-                                    zoran_check_jpg_settings(zr,
-                                                             &settings)))
-                                       goto sfmtjpg_unlock_and_return;
-
-                               /* it's ok, so set them */
-                               fh->jpg_settings = settings;
-
-                               /* tell the user what we actually did */
-                               fmt->fmt.pix.width =
-                                   settings.img_width / settings.HorDcm;
-                               fmt->fmt.pix.height =
-                                   settings.img_height * 2 /
-                                   (settings.TmpDcm * settings.VerDcm);
-                               if (settings.TmpDcm == 1)
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_SEQ_TB :
-                                            V4L2_FIELD_SEQ_BT);
-                               else
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_TOP :
-                                            V4L2_FIELD_BOTTOM);
-                               fh->jpg_buffers.buffer_size =
-                                   zoran_v4l2_calc_bufsize(&fh->
-                                                           jpg_settings);
-                               fmt->fmt.pix.bytesperline = 0;
-                               fmt->fmt.pix.sizeimage =
-                                   fh->jpg_buffers.buffer_size;
-
-                               /* we hereby abuse this variable to show that
-                                * we're gonna do mjpeg capture */
-                               fh->map_mode =
-                                   (fmt->type ==
-                                    V4L2_BUF_TYPE_VIDEO_CAPTURE) ?
-                                   ZORAN_MAP_MODE_JPG_REC :
-                                   ZORAN_MAP_MODE_JPG_PLAY;
-                       sfmtjpg_unlock_and_return:
-                               mutex_unlock(&zr->resource_lock);
-                       } else {
-                               for (i = 0; i < NUM_FORMATS; i++)
-                                       if (fmt->fmt.pix.pixelformat ==
-                                           zoran_formats[i].fourcc)
-                                               break;
-                               if (i == NUM_FORMATS) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: VIDIOC_S_FMT - unknown/unsupported format 0x%x (%4.4s)\n",
-                                               ZR_DEVNAME(zr),
-                                               fmt->fmt.pix.pixelformat,
-                                               (char *) &printformat);
-                                       return -EINVAL;
-                               }
-                               mutex_lock(&zr->resource_lock);
-                               if (fh->jpg_buffers.allocated ||
-                                   (fh->v4l_buffers.allocated &&
-                                    fh->v4l_buffers.active !=
-                                    ZORAN_FREE)) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: VIDIOC_S_FMT - cannot change capture mode\n",
-                                               ZR_DEVNAME(zr));
-                                       res = -EBUSY;
-                                       goto sfmtv4l_unlock_and_return;
-                               }
-                               if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
-                                       fmt->fmt.pix.height =
-                                           BUZ_MAX_HEIGHT;
-                               if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
-                                       fmt->fmt.pix.width = BUZ_MAX_WIDTH;
-
-                               if ((res =
-                                    zoran_v4l_set_format(file,
-                                                         fmt->fmt.pix.
-                                                         width,
-                                                         fmt->fmt.pix.
-                                                         height,
-                                                         &zoran_formats
-                                                         [i])))
-                                       goto sfmtv4l_unlock_and_return;
-
-                               /* tell the user the
-                                * results/missing stuff */
-                               fmt->fmt.pix.bytesperline =
-                                       fh->v4l_settings.bytesperline;
-                               fmt->fmt.pix.sizeimage =
-                                       fh->v4l_settings.height *
-                                       fh->v4l_settings.bytesperline;
-                               if (BUZ_MAX_HEIGHT <
-                                   (fh->v4l_settings.height * 2))
-                                       fmt->fmt.pix.field =
-                                           V4L2_FIELD_INTERLACED;
-                               else
-                                       fmt->fmt.pix.field =
-                                           V4L2_FIELD_TOP;
-
-                               fh->map_mode = ZORAN_MAP_MODE_RAW;
-                       sfmtv4l_unlock_and_return:
-                               mutex_unlock(&zr->resource_lock);
-                       }
-
-                       break;
-
-               default:
-                       dprintk(3, "unsupported\n");
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_S_FMT - unsupported type %d\n",
-                               ZR_DEVNAME(zr), fmt->type);
-                       return -EINVAL;
-               }
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_G_FBUF:
-       {
-               struct v4l2_framebuffer *fb = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_FBUF\n", ZR_DEVNAME(zr));
-
-               memset(fb, 0, sizeof(*fb));
-               mutex_lock(&zr->resource_lock);
-               fb->base = zr->buffer.base;
-               fb->fmt.width = zr->buffer.width;
-               fb->fmt.height = zr->buffer.height;
-               if (zr->overlay_settings.format) {
-                       fb->fmt.pixelformat =
-                               fh->overlay_settings.format->fourcc;
-               }
-               fb->fmt.bytesperline = zr->buffer.bytesperline;
-               mutex_unlock(&zr->resource_lock);
-               fb->fmt.colorspace = V4L2_COLORSPACE_SRGB;
-               fb->fmt.field = V4L2_FIELD_INTERLACED;
-               fb->flags = V4L2_FBUF_FLAG_OVERLAY;
-               fb->capability = V4L2_FBUF_CAP_LIST_CLIPPING;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_FBUF:
-       {
-               int i, res = 0;
-               struct v4l2_framebuffer *fb = arg;
-               __le32 printformat = __cpu_to_le32(fb->fmt.pixelformat);
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOC_S_FBUF - base=0x%p, size=%dx%d, bpl=%d, fmt=0x%x (%4.4s)\n",
-                       ZR_DEVNAME(zr), fb->base, fb->fmt.width, fb->fmt.height,
-                       fb->fmt.bytesperline, fb->fmt.pixelformat,
-                       (char *) &printformat);
-
-               for (i = 0; i < NUM_FORMATS; i++)
-                       if (zoran_formats[i].fourcc == fb->fmt.pixelformat)
-                               break;
-               if (i == NUM_FORMATS) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_S_FBUF - format=0x%x (%4.4s) not allowed\n",
-                               ZR_DEVNAME(zr), fb->fmt.pixelformat,
-                               (char *) &printformat);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-               res =
-                   setup_fbuffer(file, fb->base, &zoran_formats[i],
-                                 fb->fmt.width, fb->fmt.height,
-                                 fb->fmt.bytesperline);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_OVERLAY:
-       {
-               int *on = arg, res;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_PREVIEW - on=%d\n",
-                       ZR_DEVNAME(zr), *on);
-
-               mutex_lock(&zr->resource_lock);
-               res = setup_overlay(file, *on);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_REQBUFS:
-       {
-               struct v4l2_requestbuffers *req = arg;
-               int res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_REQBUFS - type=%d\n",
-                       ZR_DEVNAME(zr), req->type);
-
-               if (req->memory != V4L2_MEMORY_MMAP) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: only MEMORY_MMAP capture is supported, not %d\n",
-                               ZR_DEVNAME(zr), req->memory);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-
-               if (fh->v4l_buffers.allocated || fh->jpg_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_REQBUFS - buffers allready allocated\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-                       goto v4l2reqbuf_unlock_and_return;
-               }
-
-               if (fh->map_mode == ZORAN_MAP_MODE_RAW &&
-                   req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-
-                       /* control user input */
-                       if (req->count < 2)
-                               req->count = 2;
-                       if (req->count > v4l_nbufs)
-                               req->count = v4l_nbufs;
-                       fh->v4l_buffers.num_buffers = req->count;
-
-                       if (v4l_fbuffer_alloc(file)) {
-                               res = -ENOMEM;
-                               goto v4l2reqbuf_unlock_and_return;
-                       }
-
-                       /* The next mmap will map the V4L buffers */
-                       fh->map_mode = ZORAN_MAP_MODE_RAW;
-
-               } else if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC ||
-                          fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
-
-                       /* we need to calculate size ourselves now */
-                       if (req->count < 4)
-                               req->count = 4;
-                       if (req->count > jpg_nbufs)
-                               req->count = jpg_nbufs;
-                       fh->jpg_buffers.num_buffers = req->count;
-                       fh->jpg_buffers.buffer_size =
-                           zoran_v4l2_calc_bufsize(&fh->jpg_settings);
-
-                       if (jpg_fbuffer_alloc(file)) {
-                               res = -ENOMEM;
-                               goto v4l2reqbuf_unlock_and_return;
-                       }
-
-                       /* The next mmap will map the MJPEG buffers */
-                       if (req->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
-                               fh->map_mode = ZORAN_MAP_MODE_JPG_REC;
-                       else
-                               fh->map_mode = ZORAN_MAP_MODE_JPG_PLAY;
-
-               } else {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_REQBUFS - unknown type %d\n",
-                               ZR_DEVNAME(zr), req->type);
-                       res = -EINVAL;
-                       goto v4l2reqbuf_unlock_and_return;
-               }
-       v4l2reqbuf_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_QUERYBUF:
-       {
-               struct v4l2_buffer *buf = arg;
-               __u32 type = buf->type;
-               int index = buf->index, res;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOC_QUERYBUF - index=%d, type=%d\n",
-                       ZR_DEVNAME(zr), buf->index, buf->type);
-
-               memset(buf, 0, sizeof(*buf));
-               buf->type = type;
-               buf->index = index;
-
-               mutex_lock(&zr->resource_lock);
-               res = zoran_v4l2_buffer_status(file, buf, buf->index);
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_QBUF:
-       {
-               struct v4l2_buffer *buf = arg;
-               int res = 0, codec_mode, buf_type;
-
-               dprintk(3,
-                       KERN_DEBUG "%s: VIDIOC_QBUF - type=%d, index=%d\n",
-                       ZR_DEVNAME(zr), buf->type, buf->index);
-
-               mutex_lock(&zr->resource_lock);
-
-               switch (fh->map_mode) {
-               case ZORAN_MAP_MODE_RAW:
-                       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
-                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
-                               res = -EINVAL;
-                               goto qbuf_unlock_and_return;
-                       }
-
-                       res = zoran_v4l_queue_frame(file, buf->index);
-                       if (res)
-                               goto qbuf_unlock_and_return;
-                       if (!zr->v4l_memgrab_active &&
-                           fh->v4l_buffers.active == ZORAN_LOCKED)
-                               zr36057_set_memgrab(zr, 1);
-                       break;
-
-               case ZORAN_MAP_MODE_JPG_REC:
-               case ZORAN_MAP_MODE_JPG_PLAY:
-                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY) {
-                               buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-                               codec_mode = BUZ_MODE_MOTION_DECOMPRESS;
-                       } else {
-                               buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-                               codec_mode = BUZ_MODE_MOTION_COMPRESS;
-                       }
-
-                       if (buf->type != buf_type) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
-                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
-                               res = -EINVAL;
-                               goto qbuf_unlock_and_return;
-                       }
-
-                       res =
-                           zoran_jpg_queue_frame(file, buf->index,
-                                                 codec_mode);
-                       if (res != 0)
-                               goto qbuf_unlock_and_return;
-                       if (zr->codec_mode == BUZ_MODE_IDLE &&
-                           fh->jpg_buffers.active == ZORAN_LOCKED) {
-                               zr36057_enable_jpg(zr, codec_mode);
-                       }
-                       break;
-
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_QBUF - unsupported type %d\n",
-                               ZR_DEVNAME(zr), buf->type);
-                       res = -EINVAL;
-                       goto qbuf_unlock_and_return;
-               }
-       qbuf_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_DQBUF:
-       {
-               struct v4l2_buffer *buf = arg;
-               int res = 0, buf_type, num = -1;        /* compiler borks here (?) */
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_DQBUF - type=%d\n",
-                       ZR_DEVNAME(zr), buf->type);
-
-               mutex_lock(&zr->resource_lock);
-
-               switch (fh->map_mode) {
-               case ZORAN_MAP_MODE_RAW:
-                       if (buf->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
-                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
-                               res = -EINVAL;
-                               goto dqbuf_unlock_and_return;
-                       }
-
-                       num = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME];
-                       if (file->f_flags & O_NONBLOCK &&
-                           zr->v4l_buffers.buffer[num].state !=
-                           BUZ_STATE_DONE) {
-                               res = -EAGAIN;
-                               goto dqbuf_unlock_and_return;
-                       }
-                       res = v4l_sync(file, num);
-                       if (res)
-                               goto dqbuf_unlock_and_return;
-                       else
-                               zr->v4l_sync_tail++;
-                       res = zoran_v4l2_buffer_status(file, buf, num);
-                       break;
-
-               case ZORAN_MAP_MODE_JPG_REC:
-               case ZORAN_MAP_MODE_JPG_PLAY:
-               {
-                       struct zoran_sync bs;
-
-                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_PLAY)
-                               buf_type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
-                       else
-                               buf_type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
-
-                       if (buf->type != buf_type) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: VIDIOC_QBUF - invalid buf->type=%d for map_mode=%d\n",
-                                       ZR_DEVNAME(zr), buf->type, fh->map_mode);
-                               res = -EINVAL;
-                               goto dqbuf_unlock_and_return;
-                       }
-
-                       num =
-                           zr->jpg_pend[zr->
-                                        jpg_que_tail & BUZ_MASK_FRAME];
-
-                       if (file->f_flags & O_NONBLOCK &&
-                           zr->jpg_buffers.buffer[num].state !=
-                           BUZ_STATE_DONE) {
-                               res = -EAGAIN;
-                               goto dqbuf_unlock_and_return;
-                       }
-                       res = jpg_sync(file, &bs);
-                       if (res)
-                               goto dqbuf_unlock_and_return;
-                       res =
-                           zoran_v4l2_buffer_status(file, buf, bs.frame);
-                       break;
-               }
-
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_DQBUF - unsupported type %d\n",
-                               ZR_DEVNAME(zr), buf->type);
-                       res = -EINVAL;
-                       goto dqbuf_unlock_and_return;
-               }
-       dqbuf_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_STREAMON:
-       {
-               int res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMON\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-
-               switch (fh->map_mode) {
-               case ZORAN_MAP_MODE_RAW:        /* raw capture */
-                       if (zr->v4l_buffers.active != ZORAN_ACTIVE ||
-                           fh->v4l_buffers.active != ZORAN_ACTIVE) {
-                               res = -EBUSY;
-                               goto strmon_unlock_and_return;
-                       }
-
-                       zr->v4l_buffers.active = fh->v4l_buffers.active =
-                           ZORAN_LOCKED;
-                       zr->v4l_settings = fh->v4l_settings;
-
-                       zr->v4l_sync_tail = zr->v4l_pend_tail;
-                       if (!zr->v4l_memgrab_active &&
-                           zr->v4l_pend_head != zr->v4l_pend_tail) {
-                               zr36057_set_memgrab(zr, 1);
-                       }
-                       break;
-
-               case ZORAN_MAP_MODE_JPG_REC:
-               case ZORAN_MAP_MODE_JPG_PLAY:
-                       /* what is the codec mode right now? */
-                       if (zr->jpg_buffers.active != ZORAN_ACTIVE ||
-                           fh->jpg_buffers.active != ZORAN_ACTIVE) {
-                               res = -EBUSY;
-                               goto strmon_unlock_and_return;
-                       }
-
-                       zr->jpg_buffers.active = fh->jpg_buffers.active =
-                           ZORAN_LOCKED;
-
-                       if (zr->jpg_que_head != zr->jpg_que_tail) {
-                               /* Start the jpeg codec when the first frame is queued  */
-                               jpeg_start(zr);
-                       }
-
-                       break;
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_STREAMON - invalid map mode %d\n",
-                               ZR_DEVNAME(zr), fh->map_mode);
-                       res = -EINVAL;
-                       goto strmon_unlock_and_return;
-               }
-       strmon_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_STREAMOFF:
-       {
-               int i, res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_STREAMOFF\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-
-               switch (fh->map_mode) {
-               case ZORAN_MAP_MODE_RAW:        /* raw capture */
-                       if (fh->v4l_buffers.active == ZORAN_FREE &&
-                           zr->v4l_buffers.active != ZORAN_FREE) {
-                               res = -EPERM;   /* stay off other's settings! */
-                               goto strmoff_unlock_and_return;
-                       }
-                       if (zr->v4l_buffers.active == ZORAN_FREE)
-                               goto strmoff_unlock_and_return;
-
-                       /* unload capture */
-                       if (zr->v4l_memgrab_active) {
-                               unsigned long flags;
-
-                               spin_lock_irqsave(&zr->spinlock, flags);
-                               zr36057_set_memgrab(zr, 0);
-                               spin_unlock_irqrestore(&zr->spinlock, flags);
-                       }
-
-                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++)
-                               zr->v4l_buffers.buffer[i].state =
-                                   BUZ_STATE_USER;
-                       fh->v4l_buffers = zr->v4l_buffers;
-
-                       zr->v4l_buffers.active = fh->v4l_buffers.active =
-                           ZORAN_FREE;
-
-                       zr->v4l_grab_seq = 0;
-                       zr->v4l_pend_head = zr->v4l_pend_tail = 0;
-                       zr->v4l_sync_tail = 0;
-
-                       break;
-
-               case ZORAN_MAP_MODE_JPG_REC:
-               case ZORAN_MAP_MODE_JPG_PLAY:
-                       if (fh->jpg_buffers.active == ZORAN_FREE &&
-                           zr->jpg_buffers.active != ZORAN_FREE) {
-                               res = -EPERM;   /* stay off other's settings! */
-                               goto strmoff_unlock_and_return;
-                       }
-                       if (zr->jpg_buffers.active == ZORAN_FREE)
-                               goto strmoff_unlock_and_return;
-
-                       res =
-                           jpg_qbuf(file, -1,
-                                    (fh->map_mode ==
-                                     ZORAN_MAP_MODE_JPG_REC) ?
-                                    BUZ_MODE_MOTION_COMPRESS :
-                                    BUZ_MODE_MOTION_DECOMPRESS);
-                       if (res)
-                               goto strmoff_unlock_and_return;
-                       break;
-               default:
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_STREAMOFF - invalid map mode %d\n",
-                               ZR_DEVNAME(zr), fh->map_mode);
-                       res = -EINVAL;
-                       goto strmoff_unlock_and_return;
-               }
-       strmoff_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_QUERYCTRL:
-       {
-               struct v4l2_queryctrl *ctrl = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_QUERYCTRL - id=%d\n",
-                       ZR_DEVNAME(zr), ctrl->id);
-
-               /* we only support hue/saturation/contrast/brightness */
-               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
-                   ctrl->id > V4L2_CID_HUE)
-                       return -EINVAL;
-               else {
-                       int id = ctrl->id;
-                       memset(ctrl, 0, sizeof(*ctrl));
-                       ctrl->id = id;
-               }
-
-               switch (ctrl->id) {
-               case V4L2_CID_BRIGHTNESS:
-                       strncpy(ctrl->name, "Brightness", sizeof(ctrl->name)-1);
-                       break;
-               case V4L2_CID_CONTRAST:
-                       strncpy(ctrl->name, "Contrast", sizeof(ctrl->name)-1);
-                       break;
-               case V4L2_CID_SATURATION:
-                       strncpy(ctrl->name, "Saturation", sizeof(ctrl->name)-1);
-                       break;
-               case V4L2_CID_HUE:
-                       strncpy(ctrl->name, "Hue", sizeof(ctrl->name)-1);
-                       break;
-               }
-
-               ctrl->minimum = 0;
-               ctrl->maximum = 65535;
-               ctrl->step = 1;
-               ctrl->default_value = 32768;
-               ctrl->type = V4L2_CTRL_TYPE_INTEGER;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_G_CTRL:
-       {
-               struct v4l2_control *ctrl = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_CTRL - id=%d\n",
-                       ZR_DEVNAME(zr), ctrl->id);
-
-               /* we only support hue/saturation/contrast/brightness */
-               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
-                   ctrl->id > V4L2_CID_HUE)
-                       return -EINVAL;
-
-               mutex_lock(&zr->resource_lock);
-               switch (ctrl->id) {
-               case V4L2_CID_BRIGHTNESS:
-                       ctrl->value = zr->brightness;
-                       break;
-               case V4L2_CID_CONTRAST:
-                       ctrl->value = zr->contrast;
-                       break;
-               case V4L2_CID_SATURATION:
-                       ctrl->value = zr->saturation;
-                       break;
-               case V4L2_CID_HUE:
-                       ctrl->value = zr->hue;
-                       break;
-               }
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_CTRL:
-       {
-               struct v4l2_control *ctrl = arg;
-               struct video_picture pict;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_CTRL - id=%d\n",
-                       ZR_DEVNAME(zr), ctrl->id);
-
-               /* we only support hue/saturation/contrast/brightness */
-               if (ctrl->id < V4L2_CID_BRIGHTNESS ||
-                   ctrl->id > V4L2_CID_HUE)
-                       return -EINVAL;
-
-               if (ctrl->value < 0 || ctrl->value > 65535) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_S_CTRL - invalid value %d for id=%d\n",
-                               ZR_DEVNAME(zr), ctrl->value, ctrl->id);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-               switch (ctrl->id) {
-               case V4L2_CID_BRIGHTNESS:
-                       zr->brightness = ctrl->value;
-                       break;
-               case V4L2_CID_CONTRAST:
-                       zr->contrast = ctrl->value;
-                       break;
-               case V4L2_CID_SATURATION:
-                       zr->saturation = ctrl->value;
-                       break;
-               case V4L2_CID_HUE:
-                       zr->hue = ctrl->value;
-                       break;
-               }
-               pict.brightness = zr->brightness;
-               pict.contrast = zr->contrast;
-               pict.colour = zr->saturation;
-               pict.hue = zr->hue;
-
-               decoder_command(zr, DECODER_SET_PICTURE, &pict);
-
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_ENUMSTD:
-       {
-               struct v4l2_standard *std = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMSTD - index=%d\n",
-                       ZR_DEVNAME(zr), std->index);
-
-               if (std->index < 0 || std->index >= (zr->card.norms + 1))
-                       return -EINVAL;
-               else {
-                       int id = std->index;
-                       memset(std, 0, sizeof(*std));
-                       std->index = id;
-               }
-
-               if (std->index == zr->card.norms) {
-                       /* if we have autodetect, ... */
-                       struct video_decoder_capability caps;
-                       decoder_command(zr, DECODER_GET_CAPABILITIES,
-                                       &caps);
-                       if (caps.flags & VIDEO_DECODER_AUTO) {
-                               std->id = V4L2_STD_ALL;
-                               strncpy(std->name, "Autodetect", sizeof(std->name)-1);
-                               return 0;
-                       } else
-                               return -EINVAL;
-               }
-               switch (std->index) {
-               case 0:
-                       std->id = V4L2_STD_PAL;
-                       strncpy(std->name, "PAL", sizeof(std->name)-1);
-                       std->frameperiod.numerator = 1;
-                       std->frameperiod.denominator = 25;
-                       std->framelines = zr->card.tvn[0]->Ht;
-                       break;
-               case 1:
-                       std->id = V4L2_STD_NTSC;
-                       strncpy(std->name, "NTSC", sizeof(std->name)-1);
-                       std->frameperiod.numerator = 1001;
-                       std->frameperiod.denominator = 30000;
-                       std->framelines = zr->card.tvn[1]->Ht;
-                       break;
-               case 2:
-                       std->id = V4L2_STD_SECAM;
-                       strncpy(std->name, "SECAM", sizeof(std->name)-1);
-                       std->frameperiod.numerator = 1;
-                       std->frameperiod.denominator = 25;
-                       std->framelines = zr->card.tvn[2]->Ht;
-                       break;
-               }
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_G_STD:
-       {
-               v4l2_std_id *std = arg;
-               int norm;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_STD\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-               norm = zr->norm;
-               mutex_unlock(&zr->resource_lock);
-
-               switch (norm) {
-               case VIDEO_MODE_PAL:
-                       *std = V4L2_STD_PAL;
-                       break;
-               case VIDEO_MODE_NTSC:
-                       *std = V4L2_STD_NTSC;
-                       break;
-               case VIDEO_MODE_SECAM:
-                       *std = V4L2_STD_SECAM;
-                       break;
-               }
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_STD:
-       {
-               int norm = -1, res = 0;
-               v4l2_std_id *std = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_STD - norm=0x%llx\n",
-                       ZR_DEVNAME(zr), (unsigned long long)*std);
-
-               if ((*std & V4L2_STD_PAL) && !(*std & ~V4L2_STD_PAL))
-                       norm = VIDEO_MODE_PAL;
-               else if ((*std & V4L2_STD_NTSC) && !(*std & ~V4L2_STD_NTSC))
-                       norm = VIDEO_MODE_NTSC;
-               else if ((*std & V4L2_STD_SECAM) && !(*std & ~V4L2_STD_SECAM))
-                       norm = VIDEO_MODE_SECAM;
-               else if (*std == V4L2_STD_ALL)
-                       norm = VIDEO_MODE_AUTO;
-               else {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_S_STD - invalid norm 0x%llx\n",
-                               ZR_DEVNAME(zr), (unsigned long long)*std);
-                       return -EINVAL;
-               }
-
-               mutex_lock(&zr->resource_lock);
-               if ((res = zoran_set_norm(zr, norm)))
-                       goto sstd_unlock_and_return;
-
-               res = wait_grab_pending(zr);
-       sstd_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOC_ENUMINPUT:
-       {
-               struct v4l2_input *inp = arg;
-               int status;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMINPUT - index=%d\n",
-                       ZR_DEVNAME(zr), inp->index);
-
-               if (inp->index < 0 || inp->index >= zr->card.inputs)
-                       return -EINVAL;
-               else {
-                       int id = inp->index;
-                       memset(inp, 0, sizeof(*inp));
-                       inp->index = id;
-               }
-
-               strncpy(inp->name, zr->card.input[inp->index].name,
-                       sizeof(inp->name) - 1);
-               inp->type = V4L2_INPUT_TYPE_CAMERA;
-               inp->std = V4L2_STD_ALL;
-
-               /* Get status of video decoder */
-               mutex_lock(&zr->resource_lock);
-               decoder_command(zr, DECODER_GET_STATUS, &status);
-               mutex_unlock(&zr->resource_lock);
-
-               if (!(status & DECODER_STATUS_GOOD)) {
-                       inp->status |= V4L2_IN_ST_NO_POWER;
-                       inp->status |= V4L2_IN_ST_NO_SIGNAL;
-               }
-               if (!(status & DECODER_STATUS_COLOR))
-                       inp->status |= V4L2_IN_ST_NO_COLOR;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_G_INPUT:
-       {
-               int *input = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_INPUT\n", ZR_DEVNAME(zr));
-
-               mutex_lock(&zr->resource_lock);
-               *input = zr->input;
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_INPUT:
-       {
-               int *input = arg, res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_INPUT - input=%d\n",
-                       ZR_DEVNAME(zr), *input);
-
-               mutex_lock(&zr->resource_lock);
-               if ((res = zoran_set_input(zr, *input)))
-                       goto sinput_unlock_and_return;
-
-               /* Make sure the changes come into effect */
-               res = wait_grab_pending(zr);
-       sinput_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOC_ENUMOUTPUT:
-       {
-               struct v4l2_output *outp = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_ENUMOUTPUT - index=%d\n",
-                       ZR_DEVNAME(zr), outp->index);
-
-               if (outp->index != 0)
-                       return -EINVAL;
-
-               memset(outp, 0, sizeof(*outp));
-               outp->index = 0;
-               outp->type = V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY;
-               strncpy(outp->name, "Autodetect", sizeof(outp->name)-1);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_G_OUTPUT:
-       {
-               int *output = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_OUTPUT\n", ZR_DEVNAME(zr));
-
-               *output = 0;
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_OUTPUT:
-       {
-               int *output = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_S_OUTPUT - output=%d\n",
-                       ZR_DEVNAME(zr), *output);
-
-               if (*output != 0)
-                       return -EINVAL;
-
-               return 0;
-       }
-               break;
-
-               /* cropping (sub-frame capture) */
-       case VIDIOC_CROPCAP:
-       {
-               struct v4l2_cropcap *cropcap = arg;
-               int type = cropcap->type, res = 0;
-
-               dprintk(3, KERN_ERR "%s: VIDIOC_CROPCAP - type=%d\n",
-                       ZR_DEVNAME(zr), cropcap->type);
-
-               memset(cropcap, 0, sizeof(*cropcap));
-               cropcap->type = type;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (cropcap->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-                   (cropcap->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_CROPCAP - subcapture only supported for compressed capture\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto cropcap_unlock_and_return;
-               }
-
-               cropcap->bounds.top = cropcap->bounds.left = 0;
-               cropcap->bounds.width = BUZ_MAX_WIDTH;
-               cropcap->bounds.height = BUZ_MAX_HEIGHT;
-               cropcap->defrect.top = cropcap->defrect.left = 0;
-               cropcap->defrect.width = BUZ_MIN_WIDTH;
-               cropcap->defrect.height = BUZ_MIN_HEIGHT;
-       cropcap_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOC_G_CROP:
-       {
-               struct v4l2_crop *crop = arg;
-               int type = crop->type, res = 0;
-
-               dprintk(3, KERN_ERR "%s: VIDIOC_G_CROP - type=%d\n",
-                       ZR_DEVNAME(zr), crop->type);
-
-               memset(crop, 0, sizeof(*crop));
-               crop->type = type;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-                   (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto gcrop_unlock_and_return;
-               }
-
-               crop->c.top = fh->jpg_settings.img_y;
-               crop->c.left = fh->jpg_settings.img_x;
-               crop->c.width = fh->jpg_settings.img_width;
-               crop->c.height = fh->jpg_settings.img_height;
-
-       gcrop_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return res;
-       }
-               break;
-
-       case VIDIOC_S_CROP:
-       {
-               struct v4l2_crop *crop = arg;
-               int res = 0;
-
-               settings = fh->jpg_settings;
-
-               dprintk(3,
-                       KERN_ERR
-                       "%s: VIDIOC_S_CROP - type=%d, x=%d,y=%d,w=%d,h=%d\n",
-                       ZR_DEVNAME(zr), crop->type, crop->c.left, crop->c.top,
-                       crop->c.width, crop->c.height);
-
-               mutex_lock(&zr->resource_lock);
-
-               if (fh->jpg_buffers.allocated || fh->v4l_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_S_CROP - cannot change settings while active\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-                       goto scrop_unlock_and_return;
-               }
-
-               if (crop->type != V4L2_BUF_TYPE_VIDEO_OUTPUT &&
-                   (crop->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
-                    fh->map_mode == ZORAN_MAP_MODE_RAW)) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: VIDIOC_G_CROP - subcapture only supported for compressed capture\n",
-                               ZR_DEVNAME(zr));
-                       res = -EINVAL;
-                       goto scrop_unlock_and_return;
-               }
-
-               /* move into a form that we understand */
-               settings.img_x = crop->c.left;
-               settings.img_y = crop->c.top;
-               settings.img_width = crop->c.width;
-               settings.img_height = crop->c.height;
-
-               /* check validity */
-               if ((res = zoran_check_jpg_settings(zr, &settings)))
-                       goto scrop_unlock_and_return;
-
-               /* accept */
-               fh->jpg_settings = settings;
-
-       scrop_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-               return res;
-       }
-               break;
-
-       case VIDIOC_G_JPEGCOMP:
-       {
-               struct v4l2_jpegcompression *params = arg;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_G_JPEGCOMP\n",
-                       ZR_DEVNAME(zr));
-
-               memset(params, 0, sizeof(*params));
-
-               mutex_lock(&zr->resource_lock);
-
-               params->quality = fh->jpg_settings.jpg_comp.quality;
-               params->APPn = fh->jpg_settings.jpg_comp.APPn;
-               memcpy(params->APP_data,
-                      fh->jpg_settings.jpg_comp.APP_data,
-                      fh->jpg_settings.jpg_comp.APP_len);
-               params->APP_len = fh->jpg_settings.jpg_comp.APP_len;
-               memcpy(params->COM_data,
-                      fh->jpg_settings.jpg_comp.COM_data,
-                      fh->jpg_settings.jpg_comp.COM_len);
-               params->COM_len = fh->jpg_settings.jpg_comp.COM_len;
-               params->jpeg_markers =
-                   fh->jpg_settings.jpg_comp.jpeg_markers;
-
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_S_JPEGCOMP:
-       {
-               struct v4l2_jpegcompression *params = arg;
-               int res = 0;
-
-               settings = fh->jpg_settings;
-
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: VIDIOC_S_JPEGCOMP - quality=%d, APPN=%d, APP_len=%d, COM_len=%d\n",
-                       ZR_DEVNAME(zr), params->quality, params->APPn,
-                       params->APP_len, params->COM_len);
-
-               settings.jpg_comp = *params;
-
-               mutex_lock(&zr->resource_lock);
-
-               if (fh->v4l_buffers.active != ZORAN_FREE ||
-                   fh->jpg_buffers.active != ZORAN_FREE) {
-                       dprintk(1,
-                               KERN_WARNING
-                               "%s: VIDIOC_S_JPEGCOMP called while in playback/capture mode\n",
-                               ZR_DEVNAME(zr));
-                       res = -EBUSY;
-                       goto sjpegc_unlock_and_return;
-               }
-
-               if ((res = zoran_check_jpg_settings(zr, &settings)))
-                       goto sjpegc_unlock_and_return;
-               if (!fh->jpg_buffers.allocated)
-                       fh->jpg_buffers.buffer_size =
-                           zoran_v4l2_calc_bufsize(&fh->jpg_settings);
-               fh->jpg_settings.jpg_comp = *params = settings.jpg_comp;
-       sjpegc_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               return 0;
-       }
-               break;
-
-       case VIDIOC_QUERYSTD:   /* why is this useful? */
-       {
-               v4l2_std_id *std = arg;
-
-               dprintk(3,
-                       KERN_DEBUG "%s: VIDIOC_QUERY_STD - std=0x%llx\n",
-                       ZR_DEVNAME(zr), (unsigned long long)*std);
-
-               if (*std == V4L2_STD_ALL || *std == V4L2_STD_NTSC ||
-                   *std == V4L2_STD_PAL || (*std == V4L2_STD_SECAM &&
-                                            zr->card.norms == 3)) {
-                       return 0;
-               }
-
-               return -EINVAL;
-       }
-               break;
-
-       case VIDIOC_TRY_FMT:
-       {
-               struct v4l2_format *fmt = arg;
-               int res = 0;
-
-               dprintk(3, KERN_DEBUG "%s: VIDIOC_TRY_FMT - type=%d\n",
-                       ZR_DEVNAME(zr), fmt->type);
-
-               switch (fmt->type) {
-               case V4L2_BUF_TYPE_VIDEO_OVERLAY:
-                       mutex_lock(&zr->resource_lock);
-
-                       if (fmt->fmt.win.w.width > BUZ_MAX_WIDTH)
-                               fmt->fmt.win.w.width = BUZ_MAX_WIDTH;
-                       if (fmt->fmt.win.w.width < BUZ_MIN_WIDTH)
-                               fmt->fmt.win.w.width = BUZ_MIN_WIDTH;
-                       if (fmt->fmt.win.w.height > BUZ_MAX_HEIGHT)
-                               fmt->fmt.win.w.height = BUZ_MAX_HEIGHT;
-                       if (fmt->fmt.win.w.height < BUZ_MIN_HEIGHT)
-                               fmt->fmt.win.w.height = BUZ_MIN_HEIGHT;
-
-                       mutex_unlock(&zr->resource_lock);
-                       break;
-
-               case V4L2_BUF_TYPE_VIDEO_CAPTURE:
-               case V4L2_BUF_TYPE_VIDEO_OUTPUT:
-                       if (fmt->fmt.pix.bytesperline > 0)
-                               return -EINVAL;
-
-                       mutex_lock(&zr->resource_lock);
-
-                       if (fmt->fmt.pix.pixelformat == V4L2_PIX_FMT_MJPEG) {
-                               settings = fh->jpg_settings;
-
-                               /* we actually need to set 'real' parameters now */
-                               if ((fmt->fmt.pix.height * 2) >
-                                   BUZ_MAX_HEIGHT)
-                                       settings.TmpDcm = 1;
-                               else
-                                       settings.TmpDcm = 2;
-                               settings.decimation = 0;
-                               if (fmt->fmt.pix.height <=
-                                   fh->jpg_settings.img_height / 2)
-                                       settings.VerDcm = 2;
-                               else
-                                       settings.VerDcm = 1;
-                               if (fmt->fmt.pix.width <=
-                                   fh->jpg_settings.img_width / 4)
-                                       settings.HorDcm = 4;
-                               else if (fmt->fmt.pix.width <=
-                                        fh->jpg_settings.img_width / 2)
-                                       settings.HorDcm = 2;
-                               else
-                                       settings.HorDcm = 1;
-                               if (settings.TmpDcm == 1)
-                                       settings.field_per_buff = 2;
-                               else
-                                       settings.field_per_buff = 1;
-
-                               /* check */
-                               if ((res =
-                                    zoran_check_jpg_settings(zr,
-                                                             &settings)))
-                                       goto tryfmt_unlock_and_return;
-
-                               /* tell the user what we actually did */
-                               fmt->fmt.pix.width =
-                                   settings.img_width / settings.HorDcm;
-                               fmt->fmt.pix.height =
-                                   settings.img_height * 2 /
-                                   (settings.TmpDcm * settings.VerDcm);
-                               if (settings.TmpDcm == 1)
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_SEQ_TB :
-                                            V4L2_FIELD_SEQ_BT);
-                               else
-                                       fmt->fmt.pix.field =
-                                           (fh->jpg_settings.
-                                            odd_even ? V4L2_FIELD_TOP :
-                                            V4L2_FIELD_BOTTOM);
-
-                               fmt->fmt.pix.sizeimage =
-                                   zoran_v4l2_calc_bufsize(&settings);
-                       } else if (fmt->type ==
-                                  V4L2_BUF_TYPE_VIDEO_CAPTURE) {
-                               int i;
-
-                               for (i = 0; i < NUM_FORMATS; i++)
-                                       if (zoran_formats[i].fourcc ==
-                                           fmt->fmt.pix.pixelformat)
-                                               break;
-                               if (i == NUM_FORMATS) {
-                                       res = -EINVAL;
-                                       goto tryfmt_unlock_and_return;
-                               }
-
-                               if (fmt->fmt.pix.width > BUZ_MAX_WIDTH)
-                                       fmt->fmt.pix.width = BUZ_MAX_WIDTH;
-                               if (fmt->fmt.pix.width < BUZ_MIN_WIDTH)
-                                       fmt->fmt.pix.width = BUZ_MIN_WIDTH;
-                               if (fmt->fmt.pix.height > BUZ_MAX_HEIGHT)
-                                       fmt->fmt.pix.height =
-                                           BUZ_MAX_HEIGHT;
-                               if (fmt->fmt.pix.height < BUZ_MIN_HEIGHT)
-                                       fmt->fmt.pix.height =
-                                           BUZ_MIN_HEIGHT;
-                       } else {
-                               res = -EINVAL;
-                               goto tryfmt_unlock_and_return;
-                       }
-               tryfmt_unlock_and_return:
-                       mutex_unlock(&zr->resource_lock);
-
-                       return res;
-                       break;
-
-               default:
-                       return -EINVAL;
-               }
-
-               return 0;
-       }
-               break;
-
-       default:
-               dprintk(1, KERN_DEBUG "%s: UNKNOWN ioctl cmd: 0x%x\n",
-                       ZR_DEVNAME(zr), cmd);
-               return -ENOIOCTLCMD;
-               break;
-
-       }
-       return 0;
-}
-
-
-static int
-zoran_ioctl (struct inode *inode,
-            struct file  *file,
-            unsigned int  cmd,
-            unsigned long arg)
-{
-       return video_usercopy(inode, file, cmd, arg, zoran_do_ioctl);
-}
-
-static unsigned int
-zoran_poll (struct file *file,
-           poll_table  *wait)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int res = 0, frame;
-       unsigned long flags;
-
-       /* we should check whether buffers are ready to be synced on
-        * (w/o waits - O_NONBLOCK) here
-        * if ready for read (sync), return POLLIN|POLLRDNORM,
-        * if ready for write (sync), return POLLOUT|POLLWRNORM,
-        * if error, return POLLERR,
-        * if no buffers queued or so, return POLLNVAL
-        */
-
-       mutex_lock(&zr->resource_lock);
-
-       switch (fh->map_mode) {
-       case ZORAN_MAP_MODE_RAW:
-               poll_wait(file, &zr->v4l_capq, wait);
-               frame = zr->v4l_pend[zr->v4l_sync_tail & V4L_MASK_FRAME];
-
-               spin_lock_irqsave(&zr->spinlock, flags);
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: %s() raw - active=%c, sync_tail=%lu/%c, pend_tail=%lu, pend_head=%lu\n",
-                       ZR_DEVNAME(zr), __func__,
-                       "FAL"[fh->v4l_buffers.active], zr->v4l_sync_tail,
-                       "UPMD"[zr->v4l_buffers.buffer[frame].state],
-                       zr->v4l_pend_tail, zr->v4l_pend_head);
-               /* Process is the one capturing? */
-               if (fh->v4l_buffers.active != ZORAN_FREE &&
-                   /* Buffer ready to DQBUF? */
-                   zr->v4l_buffers.buffer[frame].state == BUZ_STATE_DONE)
-                       res = POLLIN | POLLRDNORM;
-               spin_unlock_irqrestore(&zr->spinlock, flags);
-
-               break;
-
-       case ZORAN_MAP_MODE_JPG_REC:
-       case ZORAN_MAP_MODE_JPG_PLAY:
-               poll_wait(file, &zr->jpg_capq, wait);
-               frame = zr->jpg_pend[zr->jpg_que_tail & BUZ_MASK_FRAME];
-
-               spin_lock_irqsave(&zr->spinlock, flags);
-               dprintk(3,
-                       KERN_DEBUG
-                       "%s: %s() jpg - active=%c, que_tail=%lu/%c, que_head=%lu, dma=%lu/%lu\n",
-                       ZR_DEVNAME(zr), __func__,
-                       "FAL"[fh->jpg_buffers.active], zr->jpg_que_tail,
-                       "UPMD"[zr->jpg_buffers.buffer[frame].state],
-                       zr->jpg_que_head, zr->jpg_dma_tail, zr->jpg_dma_head);
-               if (fh->jpg_buffers.active != ZORAN_FREE &&
-                   zr->jpg_buffers.buffer[frame].state == BUZ_STATE_DONE) {
-                       if (fh->map_mode == ZORAN_MAP_MODE_JPG_REC)
-                               res = POLLIN | POLLRDNORM;
-                       else
-                               res = POLLOUT | POLLWRNORM;
-               }
-               spin_unlock_irqrestore(&zr->spinlock, flags);
-
-               break;
-
-       default:
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_poll() - internal error, unknown map_mode=%d\n",
-                       ZR_DEVNAME(zr), fh->map_mode);
-               res = POLLNVAL;
-       }
-
-       mutex_unlock(&zr->resource_lock);
-
-       return res;
-}
-
-
-/*
- * This maps the buffers to user space.
- *
- * Depending on the state of fh->map_mode
- * the V4L or the MJPEG buffers are mapped
- * per buffer or all together
- *
- * Note that we need to connect to some
- * unmap signal event to unmap the de-allocate
- * the buffer accordingly (zoran_vm_close())
- */
-
-static void
-zoran_vm_open (struct vm_area_struct *vma)
-{
-       struct zoran_mapping *map = vma->vm_private_data;
-
-       map->count++;
-}
-
-static void
-zoran_vm_close (struct vm_area_struct *vma)
-{
-       struct zoran_mapping *map = vma->vm_private_data;
-       struct file *file = map->file;
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       int i;
-
-       map->count--;
-       if (map->count == 0) {
-               switch (fh->map_mode) {
-               case ZORAN_MAP_MODE_JPG_REC:
-               case ZORAN_MAP_MODE_JPG_PLAY:
-
-                       dprintk(3, KERN_INFO "%s: munmap(MJPEG)\n",
-                               ZR_DEVNAME(zr));
-
-                       for (i = 0; i < fh->jpg_buffers.num_buffers; i++) {
-                               if (fh->jpg_buffers.buffer[i].map == map) {
-                                       fh->jpg_buffers.buffer[i].map =
-                                           NULL;
-                               }
-                       }
-                       kfree(map);
-
-                       for (i = 0; i < fh->jpg_buffers.num_buffers; i++)
-                               if (fh->jpg_buffers.buffer[i].map)
-                                       break;
-                       if (i == fh->jpg_buffers.num_buffers) {
-                               mutex_lock(&zr->resource_lock);
-
-                               if (fh->jpg_buffers.active != ZORAN_FREE) {
-                                       jpg_qbuf(file, -1, zr->codec_mode);
-                                       zr->jpg_buffers.allocated = 0;
-                                       zr->jpg_buffers.active =
-                                           fh->jpg_buffers.active =
-                                           ZORAN_FREE;
-                               }
-                               //jpg_fbuffer_free(file);
-                               fh->jpg_buffers.allocated = 0;
-                               fh->jpg_buffers.ready_to_be_freed = 1;
-
-                               mutex_unlock(&zr->resource_lock);
-                       }
-
-                       break;
-
-               case ZORAN_MAP_MODE_RAW:
-
-                       dprintk(3, KERN_INFO "%s: munmap(V4L)\n",
-                               ZR_DEVNAME(zr));
-
-                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++) {
-                               if (fh->v4l_buffers.buffer[i].map == map) {
-                                       /* unqueue/unmap */
-                                       fh->v4l_buffers.buffer[i].map =
-                                           NULL;
-                               }
-                       }
-                       kfree(map);
-
-                       for (i = 0; i < fh->v4l_buffers.num_buffers; i++)
-                               if (fh->v4l_buffers.buffer[i].map)
-                                       break;
-                       if (i == fh->v4l_buffers.num_buffers) {
-                               mutex_lock(&zr->resource_lock);
-
-                               if (fh->v4l_buffers.active != ZORAN_FREE) {
-                                       unsigned long flags;
-
-                                       spin_lock_irqsave(&zr->spinlock, flags);
-                                       zr36057_set_memgrab(zr, 0);
-                                       zr->v4l_buffers.allocated = 0;
-                                       zr->v4l_buffers.active =
-                                           fh->v4l_buffers.active =
-                                           ZORAN_FREE;
-                                       spin_unlock_irqrestore(&zr->spinlock, flags);
-                               }
-                               //v4l_fbuffer_free(file);
-                               fh->v4l_buffers.allocated = 0;
-                               fh->v4l_buffers.ready_to_be_freed = 1;
-
-                               mutex_unlock(&zr->resource_lock);
-                       }
-
-                       break;
-
-               default:
-                       printk(KERN_ERR
-                              "%s: munmap() - internal error - unknown map mode %d\n",
-                              ZR_DEVNAME(zr), fh->map_mode);
-                       break;
-
-               }
-       }
-}
-
-static struct vm_operations_struct zoran_vm_ops = {
-       .open = zoran_vm_open,
-       .close = zoran_vm_close,
-};
-
-static int
-zoran_mmap (struct file           *file,
-           struct vm_area_struct *vma)
-{
-       struct zoran_fh *fh = file->private_data;
-       struct zoran *zr = fh->zr;
-       unsigned long size = (vma->vm_end - vma->vm_start);
-       unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
-       int i, j;
-       unsigned long page, start = vma->vm_start, todo, pos, fraglen;
-       int first, last;
-       struct zoran_mapping *map;
-       int res = 0;
-
-       dprintk(3,
-               KERN_INFO "%s: mmap(%s) of 0x%08lx-0x%08lx (size=%lu)\n",
-               ZR_DEVNAME(zr),
-               fh->map_mode == ZORAN_MAP_MODE_RAW ? "V4L" : "MJPEG",
-               vma->vm_start, vma->vm_end, size);
-
-       if (!(vma->vm_flags & VM_SHARED) || !(vma->vm_flags & VM_READ) ||
-           !(vma->vm_flags & VM_WRITE)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: mmap() - no MAP_SHARED/PROT_{READ,WRITE} given\n",
-                       ZR_DEVNAME(zr));
-               return -EINVAL;
-       }
-
-       switch (fh->map_mode) {
-
-       case ZORAN_MAP_MODE_JPG_REC:
-       case ZORAN_MAP_MODE_JPG_PLAY:
-
-               /* lock */
-               mutex_lock(&zr->resource_lock);
-
-               /* Map the MJPEG buffers */
-               if (!fh->jpg_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: zoran_mmap(MJPEG) - buffers not yet allocated\n",
-                               ZR_DEVNAME(zr));
-                       res = -ENOMEM;
-                       goto jpg_mmap_unlock_and_return;
-               }
-
-               first = offset / fh->jpg_buffers.buffer_size;
-               last = first - 1 + size / fh->jpg_buffers.buffer_size;
-               if (offset % fh->jpg_buffers.buffer_size != 0 ||
-                   size % fh->jpg_buffers.buffer_size != 0 || first < 0 ||
-                   last < 0 || first >= fh->jpg_buffers.num_buffers ||
-                   last >= fh->jpg_buffers.num_buffers) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: mmap(MJPEG) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
-                               ZR_DEVNAME(zr), offset, size,
-                               fh->jpg_buffers.buffer_size,
-                               fh->jpg_buffers.num_buffers);
-                       res = -EINVAL;
-                       goto jpg_mmap_unlock_and_return;
-               }
-               for (i = first; i <= last; i++) {
-                       if (fh->jpg_buffers.buffer[i].map) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: mmap(MJPEG) - buffer %d already mapped\n",
-                                       ZR_DEVNAME(zr), i);
-                               res = -EBUSY;
-                               goto jpg_mmap_unlock_and_return;
-                       }
-               }
-
-               /* map these buffers (v4l_buffers[i]) */
-               map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
-               if (!map) {
-                       res = -ENOMEM;
-                       goto jpg_mmap_unlock_and_return;
-               }
-               map->file = file;
-               map->count = 1;
-
-               vma->vm_ops = &zoran_vm_ops;
-               vma->vm_flags |= VM_DONTEXPAND;
-               vma->vm_private_data = map;
-
-               for (i = first; i <= last; i++) {
-                       for (j = 0;
-                            j < fh->jpg_buffers.buffer_size / PAGE_SIZE;
-                            j++) {
-                               fraglen =
-                                   (le32_to_cpu(fh->jpg_buffers.buffer[i].
-                                    frag_tab[2 * j + 1]) & ~1) << 1;
-                               todo = size;
-                               if (todo > fraglen)
-                                       todo = fraglen;
-                               pos =
-                                   le32_to_cpu(fh->jpg_buffers.
-                                   buffer[i].frag_tab[2 * j]);
-                               /* should just be pos on i386 */
-                               page = virt_to_phys(bus_to_virt(pos))
-                                                               >> PAGE_SHIFT;
-                               if (remap_pfn_range(vma, start, page,
-                                                       todo, PAGE_SHARED)) {
-                                       dprintk(1,
-                                               KERN_ERR
-                                               "%s: zoran_mmap(V4L) - remap_pfn_range failed\n",
-                                               ZR_DEVNAME(zr));
-                                       res = -EAGAIN;
-                                       goto jpg_mmap_unlock_and_return;
-                               }
-                               size -= todo;
-                               start += todo;
-                               if (size == 0)
-                                       break;
-                               if (le32_to_cpu(fh->jpg_buffers.buffer[i].
-                                   frag_tab[2 * j + 1]) & 1)
-                                       break;  /* was last fragment */
-                       }
-                       fh->jpg_buffers.buffer[i].map = map;
-                       if (size == 0)
-                               break;
-
-               }
-       jpg_mmap_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               break;
-
-       case ZORAN_MAP_MODE_RAW:
-
-               mutex_lock(&zr->resource_lock);
-
-               /* Map the V4L buffers */
-               if (!fh->v4l_buffers.allocated) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: zoran_mmap(V4L) - buffers not yet allocated\n",
-                               ZR_DEVNAME(zr));
-                       res = -ENOMEM;
-                       goto v4l_mmap_unlock_and_return;
-               }
-
-               first = offset / fh->v4l_buffers.buffer_size;
-               last = first - 1 + size / fh->v4l_buffers.buffer_size;
-               if (offset % fh->v4l_buffers.buffer_size != 0 ||
-                   size % fh->v4l_buffers.buffer_size != 0 || first < 0 ||
-                   last < 0 || first >= fh->v4l_buffers.num_buffers ||
-                   last >= fh->v4l_buffers.buffer_size) {
-                       dprintk(1,
-                               KERN_ERR
-                               "%s: mmap(V4L) - offset=%lu or size=%lu invalid for bufsize=%d and numbufs=%d\n",
-                               ZR_DEVNAME(zr), offset, size,
-                               fh->v4l_buffers.buffer_size,
-                               fh->v4l_buffers.num_buffers);
-                       res = -EINVAL;
-                       goto v4l_mmap_unlock_and_return;
-               }
-               for (i = first; i <= last; i++) {
-                       if (fh->v4l_buffers.buffer[i].map) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: mmap(V4L) - buffer %d already mapped\n",
-                                       ZR_DEVNAME(zr), i);
-                               res = -EBUSY;
-                               goto v4l_mmap_unlock_and_return;
-                       }
-               }
-
-               /* map these buffers (v4l_buffers[i]) */
-               map = kmalloc(sizeof(struct zoran_mapping), GFP_KERNEL);
-               if (!map) {
-                       res = -ENOMEM;
-                       goto v4l_mmap_unlock_and_return;
-               }
-               map->file = file;
-               map->count = 1;
-
-               vma->vm_ops = &zoran_vm_ops;
-               vma->vm_flags |= VM_DONTEXPAND;
-               vma->vm_private_data = map;
-
-               for (i = first; i <= last; i++) {
-                       todo = size;
-                       if (todo > fh->v4l_buffers.buffer_size)
-                               todo = fh->v4l_buffers.buffer_size;
-                       page = fh->v4l_buffers.buffer[i].fbuffer_phys;
-                       if (remap_pfn_range(vma, start, page >> PAGE_SHIFT,
-                                                       todo, PAGE_SHARED)) {
-                               dprintk(1,
-                                       KERN_ERR
-                                       "%s: zoran_mmap(V4L)i - remap_pfn_range failed\n",
-                                       ZR_DEVNAME(zr));
-                               res = -EAGAIN;
-                               goto v4l_mmap_unlock_and_return;
-                       }
-                       size -= todo;
-                       start += todo;
-                       fh->v4l_buffers.buffer[i].map = map;
-                       if (size == 0)
-                               break;
-               }
-       v4l_mmap_unlock_and_return:
-               mutex_unlock(&zr->resource_lock);
-
-               break;
-
-       default:
-               dprintk(1,
-                       KERN_ERR
-                       "%s: zoran_mmap() - internal error - unknown map mode %d\n",
-                       ZR_DEVNAME(zr), fh->map_mode);
-               break;
-       }
-
-       return 0;
-}
-
-static const struct file_operations zoran_fops = {
-       .owner = THIS_MODULE,
-       .open = zoran_open,
-       .release = zoran_close,
-       .ioctl = zoran_ioctl,
-#ifdef CONFIG_COMPAT
-       .compat_ioctl   = v4l_compat_ioctl32,
-#endif
-       .llseek = no_llseek,
-       .read = zoran_read,
-       .write = zoran_write,
-       .mmap = zoran_mmap,
-       .poll = zoran_poll,
-};
-
-struct video_device zoran_template __devinitdata = {
-       .name = ZORAN_NAME,
-       .fops = &zoran_fops,
-       .release = &zoran_vdev_release,
-       .minor = -1
-};
-
diff --git a/drivers/media/video/zoran_procfs.c b/drivers/media/video/zoran_procfs.c
deleted file mode 100644 (file)
index 870bc5a..0000000
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles the procFS entries (/proc/ZORAN[%d])
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#include <linux/types.h>
-#include <linux/kernel.h>
-#include <linux/module.h>
-#include <linux/vmalloc.h>
-
-#include <linux/proc_fs.h>
-#include <linux/pci.h>
-#include <linux/i2c.h>
-#include <linux/i2c-algo-bit.h>
-#include <linux/videodev.h>
-#include <linux/spinlock.h>
-#include <linux/sem.h>
-#include <linux/seq_file.h>
-
-#include <linux/ctype.h>
-#include <linux/poll.h>
-#include <asm/io.h>
-
-#include "videocodec.h"
-#include "zoran.h"
-#include "zoran_procfs.h"
-#include "zoran_card.h"
-
-#ifdef CONFIG_PROC_FS
-struct procfs_params_zr36067 {
-       char *name;
-       short reg;
-       u32 mask;
-       short bit;
-};
-
-static const struct procfs_params_zr36067 zr67[] = {
-       {"HSPol", 0x000, 1, 30},
-       {"HStart", 0x000, 0x3ff, 10},
-       {"HEnd", 0x000, 0x3ff, 0},
-
-       {"VSPol", 0x004, 1, 30},
-       {"VStart", 0x004, 0x3ff, 10},
-       {"VEnd", 0x004, 0x3ff, 0},
-
-       {"ExtFl", 0x008, 1, 26},
-       {"TopField", 0x008, 1, 25},
-       {"VCLKPol", 0x008, 1, 24},
-       {"DupFld", 0x008, 1, 20},
-       {"LittleEndian", 0x008, 1, 0},
-
-       {"HsyncStart", 0x10c, 0xffff, 16},
-       {"LineTot", 0x10c, 0xffff, 0},
-
-       {"NAX", 0x110, 0xffff, 16},
-       {"PAX", 0x110, 0xffff, 0},
-
-       {"NAY", 0x114, 0xffff, 16},
-       {"PAY", 0x114, 0xffff, 0},
-
-       /* {"",,,}, */
-
-       {NULL, 0, 0, 0},
-};
-
-static void
-setparam (struct zoran *zr,
-         char         *name,
-         char         *sval)
-{
-       int i = 0, reg0, reg, val;
-
-       while (zr67[i].name != NULL) {
-               if (!strncmp(name, zr67[i].name, strlen(zr67[i].name))) {
-                       reg = reg0 = btread(zr67[i].reg);
-                       reg &= ~(zr67[i].mask << zr67[i].bit);
-                       if (!isdigit(sval[0]))
-                               break;
-                       val = simple_strtoul(sval, NULL, 0);
-                       if ((val & ~zr67[i].mask))
-                               break;
-                       reg |= (val & zr67[i].mask) << zr67[i].bit;
-                       dprintk(4,
-                               KERN_INFO
-                               "%s: setparam: setting ZR36067 register 0x%03x: 0x%08x=>0x%08x %s=%d\n",
-                               ZR_DEVNAME(zr), zr67[i].reg, reg0, reg,
-                               zr67[i].name, val);
-                       btwrite(reg, zr67[i].reg);
-                       break;
-               }
-               i++;
-       }
-}
-
-static int zoran_show(struct seq_file *p, void *v)
-{
-       struct zoran *zr = p->private;
-       int i;
-
-       seq_printf(p, "ZR36067 registers:\n");
-       for (i = 0; i < 0x130; i += 16)
-               seq_printf(p, "%03X %08X  %08X  %08X  %08X \n", i,
-                          btread(i), btread(i+4), btread(i+8), btread(i+12));
-       return 0;
-}
-
-static int zoran_open(struct inode *inode, struct file *file)
-{
-       struct zoran *data = PDE(inode)->data;
-       return single_open(file, zoran_show, data);
-}
-
-static ssize_t zoran_write(struct file *file, const char __user *buffer,
-                       size_t count, loff_t *ppos)
-{
-       struct zoran *zr = PDE(file->f_path.dentry->d_inode)->data;
-       char *string, *sp;
-       char *line, *ldelim, *varname, *svar, *tdelim;
-
-       if (count > 32768)      /* Stupidity filter */
-               return -EINVAL;
-
-       string = sp = vmalloc(count + 1);
-       if (!string) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: write_proc: can not allocate memory\n",
-                       ZR_DEVNAME(zr));
-               return -ENOMEM;
-       }
-       if (copy_from_user(string, buffer, count)) {
-               vfree (string);
-               return -EFAULT;
-       }
-       string[count] = 0;
-       dprintk(4, KERN_INFO "%s: write_proc: name=%s count=%zu zr=%p\n",
-               ZR_DEVNAME(zr), file->f_path.dentry->d_name.name, count, zr);
-       ldelim = " \t\n";
-       tdelim = "=";
-       line = strpbrk(sp, ldelim);
-       while (line) {
-               *line = 0;
-               svar = strpbrk(sp, tdelim);
-               if (svar) {
-                       *svar = 0;
-                       varname = sp;
-                       svar++;
-                       setparam(zr, varname, svar);
-               }
-               sp = line + 1;
-               line = strpbrk(sp, ldelim);
-       }
-       vfree(string);
-
-       return count;
-}
-
-static const struct file_operations zoran_operations = {
-       .owner          = THIS_MODULE,
-       .open           = zoran_open,
-       .read           = seq_read,
-       .write          = zoran_write,
-       .llseek         = seq_lseek,
-       .release        = single_release,
-};
-#endif
-
-int
-zoran_proc_init (struct zoran *zr)
-{
-#ifdef CONFIG_PROC_FS
-       char name[8];
-
-       snprintf(name, 7, "zoran%d", zr->id);
-       zr->zoran_proc = proc_create_data(name, 0, NULL, &zoran_operations, zr);
-       if (zr->zoran_proc != NULL) {
-               dprintk(2,
-                       KERN_INFO
-                       "%s: procfs entry /proc/%s allocated. data=%p\n",
-                       ZR_DEVNAME(zr), name, zr->zoran_proc->data);
-       } else {
-               dprintk(1, KERN_ERR "%s: Unable to initialise /proc/%s\n",
-                       ZR_DEVNAME(zr), name);
-               return 1;
-       }
-#endif
-       return 0;
-}
-
-void
-zoran_proc_cleanup (struct zoran *zr)
-{
-#ifdef CONFIG_PROC_FS
-       char name[8];
-
-       snprintf(name, 7, "zoran%d", zr->id);
-       if (zr->zoran_proc)
-               remove_proc_entry(name, NULL);
-       zr->zoran_proc = NULL;
-#endif
-}
diff --git a/drivers/media/video/zoran_procfs.h b/drivers/media/video/zoran_procfs.h
deleted file mode 100644 (file)
index f2d5b1b..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Zoran zr36057/zr36067 PCI controller driver, for the
- * Pinnacle/Miro DC10/DC10+/DC30/DC30+, Iomega Buz, Linux
- * Media Labs LML33/LML33R10.
- *
- * This part handles card-specific data and detection
- *
- * Copyright (C) 2000 Serguei Miridonov <mirsev@cicese.mx>
- *
- * Currently maintained by:
- *   Ronald Bultje    <rbultje@ronald.bitfreak.net>
- *   Laurent Pinchart <laurent.pinchart@skynet.be>
- *   Mailinglist      <mjpeg-users@lists.sf.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef __ZORAN_PROCFS_H__
-#define __ZORAN_PROCFS_H__
-
-extern int zoran_proc_init(struct zoran *zr);
-extern void zoran_proc_cleanup(struct zoran *zr);
-
-#endif                         /* __ZORAN_PROCFS_H__ */
diff --git a/drivers/media/video/zr36016.c b/drivers/media/video/zr36016.c
deleted file mode 100644 (file)
index 00d132b..0000000
+++ /dev/null
@@ -1,529 +0,0 @@
-/*
- * Zoran ZR36016 basic configuration functions
- *
- * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: zr36016.c,v 1.1.2.14 2003/08/20 19:46:55 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#define ZR016_VERSION "v0.7"
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-
-#include <linux/types.h>
-#include <linux/wait.h>
-
-/* includes for structures and defines regarding video
-   #include<linux/videodev.h> */
-
-/* I/O commands, error codes */
-#include <asm/io.h>
-//#include<errno.h>
-
-/* v4l  API */
-#include <linux/videodev.h>
-
-/* headerfile of this module */
-#include"zr36016.h"
-
-/* codec io API */
-#include"videocodec.h"
-
-/* it doesn't make sense to have more than 20 or so,
-  just to prevent some unwanted loops */
-#define MAX_CODECS 20
-
-/* amount of chips attached via this driver */
-static int zr36016_codecs;
-
-/* debugging is available via module parameter */
-static int debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0-4)");
-
-#define dprintk(num, format, args...) \
-       do { \
-               if (debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
-/* =========================================================================
-   Local hardware I/O functions:
-
-   read/write via codec layer (registers are located in the master device)
-   ========================================================================= */
-
-/* read and write functions */
-static u8
-zr36016_read (struct zr36016 *ptr,
-             u16             reg)
-{
-       u8 value = 0;
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->readreg)
-               value =
-                   (ptr->codec->master_data->
-                    readreg(ptr->codec, reg)) & 0xFF;
-       else
-               dprintk(1,
-                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
-                       ptr->name);
-
-       dprintk(4, "%s: reading from 0x%04x: %02x\n", ptr->name, reg,
-               value);
-
-       return value;
-}
-
-static void
-zr36016_write (struct zr36016 *ptr,
-              u16             reg,
-              u8              value)
-{
-       dprintk(4, "%s: writing 0x%02x to 0x%04x\n", ptr->name, value,
-               reg);
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->writereg) {
-               ptr->codec->master_data->writereg(ptr->codec, reg, value);
-       } else
-               dprintk(1,
-                       KERN_ERR
-                       "%s: invalid I/O setup, nothing written!\n",
-                       ptr->name);
-}
-
-/* indirect read and write functions */
-/* the 016 supports auto-addr-increment, but
- * writing it all time cost not much and is safer... */
-static u8
-zr36016_readi (struct zr36016 *ptr,
-              u16             reg)
-{
-       u8 value = 0;
-
-       // just in case something is wrong...
-       if ((ptr->codec->master_data->writereg) &&
-           (ptr->codec->master_data->readreg)) {
-               ptr->codec->master_data->writereg(ptr->codec, ZR016_IADDR, reg & 0x0F); // ADDR
-               value = (ptr->codec->master_data->readreg(ptr->codec, ZR016_IDATA)) & 0xFF;     // DATA
-       } else
-               dprintk(1,
-                       KERN_ERR
-                       "%s: invalid I/O setup, nothing read (i)!\n",
-                       ptr->name);
-
-       dprintk(4, "%s: reading indirect from 0x%04x: %02x\n", ptr->name,
-               reg, value);
-       return value;
-}
-
-static void
-zr36016_writei (struct zr36016 *ptr,
-               u16             reg,
-               u8              value)
-{
-       dprintk(4, "%s: writing indirect 0x%02x to 0x%04x\n", ptr->name,
-               value, reg);
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->writereg) {
-               ptr->codec->master_data->writereg(ptr->codec, ZR016_IADDR, reg & 0x0F); // ADDR
-               ptr->codec->master_data->writereg(ptr->codec, ZR016_IDATA, value & 0x0FF);      // DATA
-       } else
-               dprintk(1,
-                       KERN_ERR
-                       "%s: invalid I/O setup, nothing written (i)!\n",
-                       ptr->name);
-}
-
-/* =========================================================================
-   Local helper function:
-
-   version read
-   ========================================================================= */
-
-/* version kept in datastructure */
-static u8
-zr36016_read_version (struct zr36016 *ptr)
-{
-       ptr->version = zr36016_read(ptr, 0) >> 4;
-       return ptr->version;
-}
-
-/* =========================================================================
-   Local helper function:
-
-   basic test of "connectivity", writes/reads to/from PAX-Lo register
-   ========================================================================= */
-
-static int
-zr36016_basic_test (struct zr36016 *ptr)
-{
-       if (debug) {
-               int i;
-               zr36016_writei(ptr, ZR016I_PAX_LO, 0x55);
-               dprintk(1, KERN_INFO "%s: registers: ", ptr->name);
-               for (i = 0; i <= 0x0b; i++)
-                       dprintk(1, "%02x ", zr36016_readi(ptr, i));
-               dprintk(1, "\n");
-       }
-       // for testing just write 0, then the default value to a register and read
-       // it back in both cases
-       zr36016_writei(ptr, ZR016I_PAX_LO, 0x00);
-       if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, can't connect to vfe processor!\n",
-                       ptr->name);
-               return -ENXIO;
-       }
-       zr36016_writei(ptr, ZR016I_PAX_LO, 0x0d0);
-       if (zr36016_readi(ptr, ZR016I_PAX_LO) != 0x0d0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, can't connect to vfe processor!\n",
-                       ptr->name);
-               return -ENXIO;
-       }
-       // we allow version numbers from 0-3, should be enough, though
-       zr36016_read_version(ptr);
-       if (ptr->version & 0x0c) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, suspicious version %d found...\n",
-                       ptr->name, ptr->version);
-               return -ENXIO;
-       }
-
-       return 0;               /* looks good! */
-}
-
-/* =========================================================================
-   Local helper function:
-
-   simple loop for pushing the init datasets - NO USE --
-   ========================================================================= */
-
-#if 0
-static int zr36016_pushit (struct zr36016 *ptr,
-                          u16             startreg,
-                          u16             len,
-                          const char     *data)
-{
-       int i=0;
-
-       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n",
-               ptr->name, startreg,len);
-       while (i<len) {
-               zr36016_writei(ptr, startreg++,  data[i++]);
-       }
-
-       return i;
-}
-#endif
-
-/* =========================================================================
-   Basic datasets & init:
-
-   //TODO//
-   ========================================================================= */
-
-// needed offset values          PAL NTSC SECAM
-static const int zr016_xoff[] = { 20, 20, 20 };
-static const int zr016_yoff[] = { 8, 9, 7 };
-
-static void
-zr36016_init (struct zr36016 *ptr)
-{
-       // stop any processing
-       zr36016_write(ptr, ZR016_GOSTOP, 0);
-
-       // mode setup (yuv422 in and out, compression/expansuon due to mode)
-       zr36016_write(ptr, ZR016_MODE,
-                     ZR016_YUV422 | ZR016_YUV422_YUV422 |
-                     (ptr->mode == CODEC_DO_COMPRESSION ?
-                      ZR016_COMPRESSION : ZR016_EXPANSION));
-
-       // misc setup
-       zr36016_writei(ptr, ZR016I_SETUP1,
-                      (ptr->xdec ? (ZR016_HRFL | ZR016_HORZ) : 0) |
-                      (ptr->ydec ? ZR016_VERT : 0) | ZR016_CNTI);
-       zr36016_writei(ptr, ZR016I_SETUP2, ZR016_CCIR);
-
-       // Window setup
-       // (no extra offset for now, norm defines offset, default width height)
-       zr36016_writei(ptr, ZR016I_PAX_HI, ptr->width >> 8);
-       zr36016_writei(ptr, ZR016I_PAX_LO, ptr->width & 0xFF);
-       zr36016_writei(ptr, ZR016I_PAY_HI, ptr->height >> 8);
-       zr36016_writei(ptr, ZR016I_PAY_LO, ptr->height & 0xFF);
-       zr36016_writei(ptr, ZR016I_NAX_HI, ptr->xoff >> 8);
-       zr36016_writei(ptr, ZR016I_NAX_LO, ptr->xoff & 0xFF);
-       zr36016_writei(ptr, ZR016I_NAY_HI, ptr->yoff >> 8);
-       zr36016_writei(ptr, ZR016I_NAY_LO, ptr->yoff & 0xFF);
-
-       /* shall we continue now, please? */
-       zr36016_write(ptr, ZR016_GOSTOP, 1);
-}
-
-/* =========================================================================
-   CODEC API FUNCTIONS
-
-   this functions are accessed by the master via the API structure
-   ========================================================================= */
-
-/* set compression/expansion mode and launches codec -
-   this should be the last call from the master before starting processing */
-static int
-zr36016_set_mode (struct videocodec *codec,
-                 int                mode)
-{
-       struct zr36016 *ptr = (struct zr36016 *) codec->data;
-
-       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
-
-       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
-               return -EINVAL;
-
-       ptr->mode = mode;
-       zr36016_init(ptr);
-
-       return 0;
-}
-
-/* set picture size */
-static int
-zr36016_set_video (struct videocodec   *codec,
-                  struct tvnorm       *norm,
-                  struct vfe_settings *cap,
-                  struct vfe_polarity *pol)
-{
-       struct zr36016 *ptr = (struct zr36016 *) codec->data;
-
-       dprintk(2, "%s: set_video %d.%d, %d/%d-%dx%d (0x%x) call\n",
-               ptr->name, norm->HStart, norm->VStart,
-               cap->x, cap->y, cap->width, cap->height,
-               cap->decimation);
-
-       /* if () return -EINVAL;
-        * trust the master driver that it knows what it does - so
-        * we allow invalid startx/y for now ... */
-       ptr->width = cap->width;
-       ptr->height = cap->height;
-       /* (Ronald) This is ugly. zoran_device.c, line 387
-        * already mentions what happens if HStart is even
-        * (blue faces, etc., cr/cb inversed). There's probably
-        * some good reason why HStart is 0 instead of 1, so I'm
-        * leaving it to this for now, but really... This can be
-        * done a lot simpler */
-       ptr->xoff = (norm->HStart ? norm->HStart : 1) + cap->x;
-       /* Something to note here (I don't understand it), setting
-        * VStart too high will cause the codec to 'not work'. I
-        * really don't get it. values of 16 (VStart) already break
-        * it here. Just '0' seems to work. More testing needed! */
-       ptr->yoff = norm->VStart + cap->y;
-       /* (Ronald) dzjeeh, can't this thing do hor_decimation = 4? */
-       ptr->xdec = ((cap->decimation & 0xff) == 1) ? 0 : 1;
-       ptr->ydec = (((cap->decimation >> 8) & 0xff) == 1) ? 0 : 1;
-
-       return 0;
-}
-
-/* additional control functions */
-static int
-zr36016_control (struct videocodec *codec,
-                int                type,
-                int                size,
-                void              *data)
-{
-       struct zr36016 *ptr = (struct zr36016 *) codec->data;
-       int *ival = (int *) data;
-
-       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
-               size);
-
-       switch (type) {
-       case CODEC_G_STATUS:    /* get last status - we don't know it ... */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = 0;
-               break;
-
-       case CODEC_G_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = 0;
-               break;
-
-       case CODEC_S_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               if (*ival != 0)
-                       return -EINVAL;
-               /* not needed, do nothing */
-               return 0;
-
-       case CODEC_G_VFE:
-       case CODEC_S_VFE:
-               return 0;
-
-       case CODEC_S_MMAP:
-               /* not available, give an error */
-               return -ENXIO;
-
-       default:
-               return -EINVAL;
-       }
-
-       return size;
-}
-
-/* =========================================================================
-   Exit and unregister function:
-
-   Deinitializes Zoran's JPEG processor
-   ========================================================================= */
-
-static int
-zr36016_unset (struct videocodec *codec)
-{
-       struct zr36016 *ptr = codec->data;
-
-       if (ptr) {
-               /* do wee need some codec deinit here, too ???? */
-
-               dprintk(1, "%s: finished codec #%d\n", ptr->name,
-                       ptr->num);
-               kfree(ptr);
-               codec->data = NULL;
-
-               zr36016_codecs--;
-               return 0;
-       }
-
-       return -EFAULT;
-}
-
-/* =========================================================================
-   Setup and registry function:
-
-   Initializes Zoran's JPEG processor
-
-   Also sets pixel size, average code size, mode (compr./decompr.)
-   (the given size is determined by the processor with the video interface)
-   ========================================================================= */
-
-static int
-zr36016_setup (struct videocodec *codec)
-{
-       struct zr36016 *ptr;
-       int res;
-
-       dprintk(2, "zr36016: initializing VFE subsystem #%d.\n",
-               zr36016_codecs);
-
-       if (zr36016_codecs == MAX_CODECS) {
-               dprintk(1,
-                       KERN_ERR "zr36016: Can't attach more codecs!\n");
-               return -ENOSPC;
-       }
-       //mem structure init
-       codec->data = ptr = kzalloc(sizeof(struct zr36016), GFP_KERNEL);
-       if (NULL == ptr) {
-               dprintk(1, KERN_ERR "zr36016: Can't get enough memory!\n");
-               return -ENOMEM;
-       }
-
-       snprintf(ptr->name, sizeof(ptr->name), "zr36016[%d]",
-                zr36016_codecs);
-       ptr->num = zr36016_codecs++;
-       ptr->codec = codec;
-
-       //testing
-       res = zr36016_basic_test(ptr);
-       if (res < 0) {
-               zr36016_unset(codec);
-               return res;
-       }
-       //final setup
-       ptr->mode = CODEC_DO_COMPRESSION;
-       ptr->width = 768;
-       ptr->height = 288;
-       ptr->xdec = 1;
-       ptr->ydec = 0;
-       zr36016_init(ptr);
-
-       dprintk(1, KERN_INFO "%s: codec v%d attached and running\n",
-               ptr->name, ptr->version);
-
-       return 0;
-}
-
-static const struct videocodec zr36016_codec = {
-       .owner = THIS_MODULE,
-       .name = "zr36016",
-       .magic = 0L,            // magic not used
-       .flags =
-           CODEC_FLAG_HARDWARE | CODEC_FLAG_VFE | CODEC_FLAG_ENCODER |
-           CODEC_FLAG_DECODER,
-       .type = CODEC_TYPE_ZR36016,
-       .setup = zr36016_setup, // functionality
-       .unset = zr36016_unset,
-       .set_mode = zr36016_set_mode,
-       .set_video = zr36016_set_video,
-       .control = zr36016_control,
-       // others are not used
-};
-
-/* =========================================================================
-   HOOK IN DRIVER AS KERNEL MODULE
-   ========================================================================= */
-
-static int __init
-zr36016_init_module (void)
-{
-       //dprintk(1, "ZR36016 driver %s\n",ZR016_VERSION);
-       zr36016_codecs = 0;
-       return videocodec_register(&zr36016_codec);
-}
-
-static void __exit
-zr36016_cleanup_module (void)
-{
-       if (zr36016_codecs) {
-               dprintk(1,
-                       "zr36016: something's wrong - %d codecs left somehow.\n",
-                       zr36016_codecs);
-       }
-       videocodec_unregister(&zr36016_codec);
-}
-
-module_init(zr36016_init_module);
-module_exit(zr36016_cleanup_module);
-
-MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
-MODULE_DESCRIPTION("Driver module for ZR36016 video frontends "
-                  ZR016_VERSION);
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zr36016.h b/drivers/media/video/zr36016.h
deleted file mode 100644 (file)
index 8c79229..0000000
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Zoran ZR36016 basic configuration functions - header file
- *
- * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: zr36016.h,v 1.1.2.3 2003/01/14 21:18:07 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#ifndef ZR36016_H
-#define ZR36016_H
-
-/* data stored for each zoran jpeg codec chip */
-struct zr36016 {
-       char name[32];
-       int num;
-       /* io datastructure */
-       struct videocodec *codec;
-       // coder status
-       __u8 version;
-       // actual coder setup
-       int mode;
-
-       __u16 xoff;
-       __u16 yoff;
-       __u16 width;
-       __u16 height;
-       __u16 xdec;
-       __u16 ydec;
-};
-
-/* direct  register addresses */
-#define ZR016_GOSTOP      0x00
-#define ZR016_MODE        0x01
-#define ZR016_IADDR       0x02
-#define ZR016_IDATA       0x03
-
-/* indirect  register addresses */
-#define ZR016I_SETUP1     0x00
-#define ZR016I_SETUP2     0x01
-#define ZR016I_NAX_LO     0x02
-#define ZR016I_NAX_HI     0x03
-#define ZR016I_PAX_LO     0x04
-#define ZR016I_PAX_HI     0x05
-#define ZR016I_NAY_LO     0x06
-#define ZR016I_NAY_HI     0x07
-#define ZR016I_PAY_LO     0x08
-#define ZR016I_PAY_HI     0x09
-#define ZR016I_NOL_LO     0x0a
-#define ZR016I_NOL_HI     0x0b
-
-/* possible values for mode register */
-#define ZR016_RGB444_YUV444  0x00
-#define ZR016_RGB444_YUV422  0x01
-#define ZR016_RGB444_YUV411  0x02
-#define ZR016_RGB444_Y400    0x03
-#define ZR016_RGB444_RGB444  0x04
-#define ZR016_YUV444_YUV444  0x08
-#define ZR016_YUV444_YUV422  0x09
-#define ZR016_YUV444_YUV411  0x0a
-#define ZR016_YUV444_Y400    0x0b
-#define ZR016_YUV444_RGB444  0x0c
-#define ZR016_YUV422_YUV422  0x11
-#define ZR016_YUV422_YUV411  0x12
-#define ZR016_YUV422_Y400    0x13
-#define ZR016_YUV411_YUV411  0x16
-#define ZR016_YUV411_Y400    0x17
-#define ZR016_4444_4444      0x19
-#define ZR016_100_100        0x1b
-
-#define ZR016_RGB444         0x00
-#define ZR016_YUV444         0x20
-#define ZR016_YUV422         0x40
-
-#define ZR016_COMPRESSION    0x80
-#define ZR016_EXPANSION      0x80
-
-/* possible values for setup 1 register */
-#define ZR016_CKRT           0x80
-#define ZR016_VERT           0x40
-#define ZR016_HORZ           0x20
-#define ZR016_HRFL           0x10
-#define ZR016_DSFL           0x08
-#define ZR016_SBFL           0x04
-#define ZR016_RSTR           0x02
-#define ZR016_CNTI           0x01
-
-/* possible values for setup 2 register */
-#define ZR016_SYEN           0x40
-#define ZR016_CCIR           0x04
-#define ZR016_SIGN           0x02
-#define ZR016_YMCS           0x01
-
-#endif                         /*fndef ZR36016_H */
diff --git a/drivers/media/video/zr36050.c b/drivers/media/video/zr36050.c
deleted file mode 100644 (file)
index cf8b271..0000000
+++ /dev/null
@@ -1,904 +0,0 @@
-/*
- * Zoran ZR36050 basic configuration functions
- *
- * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: zr36050.c,v 1.1.2.11 2003/08/03 14:54:53 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#define ZR050_VERSION "v0.7.1"
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-
-#include <linux/types.h>
-#include <linux/wait.h>
-
-/* includes for structures and defines regarding video
-   #include<linux/videodev.h> */
-
-/* I/O commands, error codes */
-#include <asm/io.h>
-//#include<errno.h>
-
-/* headerfile of this module */
-#include "zr36050.h"
-
-/* codec io API */
-#include "videocodec.h"
-
-/* it doesn't make sense to have more than 20 or so,
-  just to prevent some unwanted loops */
-#define MAX_CODECS 20
-
-/* amount of chips attached via this driver */
-static int zr36050_codecs;
-
-/* debugging is available via module parameter */
-static int debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0-4)");
-
-#define dprintk(num, format, args...) \
-       do { \
-               if (debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
-/* =========================================================================
-   Local hardware I/O functions:
-
-   read/write via codec layer (registers are located in the master device)
-   ========================================================================= */
-
-/* read and write functions */
-static u8
-zr36050_read (struct zr36050 *ptr,
-             u16             reg)
-{
-       u8 value = 0;
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->readreg)
-               value = (ptr->codec->master_data->readreg(ptr->codec,
-                                                         reg)) & 0xFF;
-       else
-               dprintk(1,
-                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
-                       ptr->name);
-
-       dprintk(4, "%s: reading from 0x%04x: %02x\n", ptr->name, reg,
-               value);
-
-       return value;
-}
-
-static void
-zr36050_write (struct zr36050 *ptr,
-              u16             reg,
-              u8              value)
-{
-       dprintk(4, "%s: writing 0x%02x to 0x%04x\n", ptr->name, value,
-               reg);
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->writereg)
-               ptr->codec->master_data->writereg(ptr->codec, reg, value);
-       else
-               dprintk(1,
-                       KERN_ERR
-                       "%s: invalid I/O setup, nothing written!\n",
-                       ptr->name);
-}
-
-/* =========================================================================
-   Local helper function:
-
-   status read
-   ========================================================================= */
-
-/* status is kept in datastructure */
-static u8
-zr36050_read_status1 (struct zr36050 *ptr)
-{
-       ptr->status1 = zr36050_read(ptr, ZR050_STATUS_1);
-
-       zr36050_read(ptr, 0);
-       return ptr->status1;
-}
-
-/* =========================================================================
-   Local helper function:
-
-   scale factor read
-   ========================================================================= */
-
-/* scale factor is kept in datastructure */
-static u16
-zr36050_read_scalefactor (struct zr36050 *ptr)
-{
-       ptr->scalefact = (zr36050_read(ptr, ZR050_SF_HI) << 8) |
-                        (zr36050_read(ptr, ZR050_SF_LO) & 0xFF);
-
-       /* leave 0 selected for an eventually GO from master */
-       zr36050_read(ptr, 0);
-       return ptr->scalefact;
-}
-
-/* =========================================================================
-   Local helper function:
-
-   wait if codec is ready to proceed (end of processing) or time is over
-   ========================================================================= */
-
-static void
-zr36050_wait_end (struct zr36050 *ptr)
-{
-       int i = 0;
-
-       while (!(zr36050_read_status1(ptr) & 0x4)) {
-               udelay(1);
-               if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
-                       dprintk(1,
-                               "%s: timeout at wait_end (last status: 0x%02x)\n",
-                               ptr->name, ptr->status1);
-                       break;
-               }
-       }
-}
-
-/* =========================================================================
-   Local helper function:
-
-   basic test of "connectivity", writes/reads to/from memory the SOF marker
-   ========================================================================= */
-
-static int
-zr36050_basic_test (struct zr36050 *ptr)
-{
-       zr36050_write(ptr, ZR050_SOF_IDX, 0x00);
-       zr36050_write(ptr, ZR050_SOF_IDX + 1, 0x00);
-       if ((zr36050_read(ptr, ZR050_SOF_IDX) |
-            zr36050_read(ptr, ZR050_SOF_IDX + 1)) != 0x0000) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, can't connect to jpeg processor!\n",
-                       ptr->name);
-               return -ENXIO;
-       }
-       zr36050_write(ptr, ZR050_SOF_IDX, 0xff);
-       zr36050_write(ptr, ZR050_SOF_IDX + 1, 0xc0);
-       if (((zr36050_read(ptr, ZR050_SOF_IDX) << 8) |
-            zr36050_read(ptr, ZR050_SOF_IDX + 1)) != 0xffc0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, can't connect to jpeg processor!\n",
-                       ptr->name);
-               return -ENXIO;
-       }
-
-       zr36050_wait_end(ptr);
-       if ((ptr->status1 & 0x4) == 0) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, jpeg processor failed (end flag)!\n",
-                       ptr->name);
-               return -EBUSY;
-       }
-
-       return 0;               /* looks good! */
-}
-
-/* =========================================================================
-   Local helper function:
-
-   simple loop for pushing the init datasets
-   ========================================================================= */
-
-static int
-zr36050_pushit (struct zr36050 *ptr,
-               u16             startreg,
-               u16             len,
-               const char     *data)
-{
-       int i = 0;
-
-       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n", ptr->name,
-               startreg, len);
-       while (i < len) {
-               zr36050_write(ptr, startreg++, data[i++]);
-       }
-
-       return i;
-}
-
-/* =========================================================================
-   Basic datasets:
-
-   jpeg baseline setup data (you find it on lots places in internet, or just
-   extract it from any regular .jpg image...)
-
-   Could be variable, but until it's not needed it they are just fixed to save
-   memory. Otherwise expand zr36050 structure with arrays, push the values to
-   it and initalize from there, as e.g. the linux zr36057/60 driver does it.
-   ========================================================================= */
-
-static const char zr36050_dqt[0x86] = {
-       0xff, 0xdb,             //Marker: DQT
-       0x00, 0x84,             //Length: 2*65+2
-       0x00,                   //Pq,Tq first table
-       0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
-       0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
-       0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
-       0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
-       0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
-       0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
-       0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
-       0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
-       0x01,                   //Pq,Tq second table
-       0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
-       0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
-};
-
-static const char zr36050_dht[0x1a4] = {
-       0xff, 0xc4,             //Marker: DHT
-       0x01, 0xa2,             //Length: 2*AC, 2*DC
-       0x00,                   //DC first table
-       0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
-       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
-       0x01,                   //DC second table
-       0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
-       0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
-       0x10,                   //AC first table
-       0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03,
-       0x05, 0x05, 0x04, 0x04, 0x00, 0x00,
-       0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
-       0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
-       0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,
-       0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24,
-       0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17,
-       0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34,
-       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
-       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
-       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
-       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
-       0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
-       0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
-       0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
-       0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9,
-       0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8,
-       0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
-       0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
-       0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
-       0xF8, 0xF9, 0xFA,
-       0x11,                   //AC second table
-       0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
-       0x07, 0x05, 0x04, 0x04, 0x00, 0x01,
-       0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
-       0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
-       0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
-       0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62,
-       0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25,
-       0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
-       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
-       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
-       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
-       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
-       0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-       0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
-       0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
-       0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
-       0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
-       0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8,
-       0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
-       0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
-       0xF9, 0xFA
-};
-
-/* jpeg baseline setup, this is just fixed in this driver (YUV pictures) */
-#define NO_OF_COMPONENTS          0x3  //Y,U,V
-#define BASELINE_PRECISION        0x8  //MCU size (?)
-static const char zr36050_tq[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's QT
-static const char zr36050_td[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's DC
-static const char zr36050_ta[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's AC
-
-/* horizontal 422 decimation setup (maybe we support 411 or so later, too) */
-static const char zr36050_decimation_h[8] = { 2, 1, 1, 0, 0, 0, 0, 0 };
-static const char zr36050_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
-
-/* =========================================================================
-   Local helper functions:
-
-   calculation and setup of parameter-dependent JPEG baseline segments
-   (needed for compression only)
-   ========================================================================= */
-
-/* ------------------------------------------------------------------------- */
-
-/* SOF (start of frame) segment depends on width, height and sampling ratio
-                        of each color component */
-
-static int
-zr36050_set_sof (struct zr36050 *ptr)
-{
-       char sof_data[34];      // max. size of register set
-       int i;
-
-       dprintk(3, "%s: write SOF (%dx%d, %d components)\n", ptr->name,
-               ptr->width, ptr->height, NO_OF_COMPONENTS);
-       sof_data[0] = 0xff;
-       sof_data[1] = 0xc0;
-       sof_data[2] = 0x00;
-       sof_data[3] = (3 * NO_OF_COMPONENTS) + 8;
-       sof_data[4] = BASELINE_PRECISION;       // only '8' possible with zr36050
-       sof_data[5] = (ptr->height) >> 8;
-       sof_data[6] = (ptr->height) & 0xff;
-       sof_data[7] = (ptr->width) >> 8;
-       sof_data[8] = (ptr->width) & 0xff;
-       sof_data[9] = NO_OF_COMPONENTS;
-       for (i = 0; i < NO_OF_COMPONENTS; i++) {
-               sof_data[10 + (i * 3)] = i;     // index identifier
-               sof_data[11 + (i * 3)] = (ptr->h_samp_ratio[i] << 4) | (ptr->v_samp_ratio[i]);  // sampling ratios
-               sof_data[12 + (i * 3)] = zr36050_tq[i]; // Q table selection
-       }
-       return zr36050_pushit(ptr, ZR050_SOF_IDX,
-                             (3 * NO_OF_COMPONENTS) + 10, sof_data);
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* SOS (start of scan) segment depends on the used scan components
-                       of each color component */
-
-static int
-zr36050_set_sos (struct zr36050 *ptr)
-{
-       char sos_data[16];      // max. size of register set
-       int i;
-
-       dprintk(3, "%s: write SOS\n", ptr->name);
-       sos_data[0] = 0xff;
-       sos_data[1] = 0xda;
-       sos_data[2] = 0x00;
-       sos_data[3] = 2 + 1 + (2 * NO_OF_COMPONENTS) + 3;
-       sos_data[4] = NO_OF_COMPONENTS;
-       for (i = 0; i < NO_OF_COMPONENTS; i++) {
-               sos_data[5 + (i * 2)] = i;      // index
-               sos_data[6 + (i * 2)] = (zr36050_td[i] << 4) | zr36050_ta[i];   // AC/DC tbl.sel.
-       }
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00;      // scan start
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3F;
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 4] = 00;
-       return zr36050_pushit(ptr, ZR050_SOS1_IDX,
-                             4 + 1 + (2 * NO_OF_COMPONENTS) + 3,
-                             sos_data);
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* DRI (define restart interval) */
-
-static int
-zr36050_set_dri (struct zr36050 *ptr)
-{
-       char dri_data[6];       // max. size of register set
-
-       dprintk(3, "%s: write DRI\n", ptr->name);
-       dri_data[0] = 0xff;
-       dri_data[1] = 0xdd;
-       dri_data[2] = 0x00;
-       dri_data[3] = 0x04;
-       dri_data[4] = ptr->dri >> 8;
-       dri_data[5] = ptr->dri & 0xff;
-       return zr36050_pushit(ptr, ZR050_DRI_IDX, 6, dri_data);
-}
-
-/* =========================================================================
-   Setup function:
-
-   Setup compression/decompression of Zoran's JPEG processor
-   ( see also zoran 36050 manual )
-
-   ... sorry for the spaghetti code ...
-   ========================================================================= */
-static void
-zr36050_init (struct zr36050 *ptr)
-{
-       int sum = 0;
-       long bitcnt, tmp;
-
-       if (ptr->mode == CODEC_DO_COMPRESSION) {
-               dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);
-
-               /* 050 communicates with 057 in master mode */
-               zr36050_write(ptr, ZR050_HARDWARE, ZR050_HW_MSTR);
-
-               /* encoding table preload for compression */
-               zr36050_write(ptr, ZR050_MODE,
-                             ZR050_MO_COMP | ZR050_MO_TLM);
-               zr36050_write(ptr, ZR050_OPTIONS, 0);
-
-               /* disable all IRQs */
-               zr36050_write(ptr, ZR050_INT_REQ_0, 0);
-               zr36050_write(ptr, ZR050_INT_REQ_1, 3); // low 2 bits always 1
-
-               /* volume control settings */
-               /*zr36050_write(ptr, ZR050_MBCV, ptr->max_block_vol);*/
-               zr36050_write(ptr, ZR050_SF_HI, ptr->scalefact >> 8);
-               zr36050_write(ptr, ZR050_SF_LO, ptr->scalefact & 0xff);
-
-               zr36050_write(ptr, ZR050_AF_HI, 0xff);
-               zr36050_write(ptr, ZR050_AF_M, 0xff);
-               zr36050_write(ptr, ZR050_AF_LO, 0xff);
-
-               /* setup the variable jpeg tables */
-               sum += zr36050_set_sof(ptr);
-               sum += zr36050_set_sos(ptr);
-               sum += zr36050_set_dri(ptr);
-
-               /* setup the fixed jpeg tables - maybe variable, though -
-                * (see table init section above) */
-               dprintk(3, "%s: write DQT, DHT, APP\n", ptr->name);
-               sum += zr36050_pushit(ptr, ZR050_DQT_IDX,
-                                     sizeof(zr36050_dqt), zr36050_dqt);
-               sum += zr36050_pushit(ptr, ZR050_DHT_IDX,
-                                     sizeof(zr36050_dht), zr36050_dht);
-               zr36050_write(ptr, ZR050_APP_IDX, 0xff);
-               zr36050_write(ptr, ZR050_APP_IDX + 1, 0xe0 + ptr->app.appn);
-               zr36050_write(ptr, ZR050_APP_IDX + 2, 0x00);
-               zr36050_write(ptr, ZR050_APP_IDX + 3, ptr->app.len + 2);
-               sum += zr36050_pushit(ptr, ZR050_APP_IDX + 4, 60,
-                                     ptr->app.data) + 4;
-               zr36050_write(ptr, ZR050_COM_IDX, 0xff);
-               zr36050_write(ptr, ZR050_COM_IDX + 1, 0xfe);
-               zr36050_write(ptr, ZR050_COM_IDX + 2, 0x00);
-               zr36050_write(ptr, ZR050_COM_IDX + 3, ptr->com.len + 2);
-               sum += zr36050_pushit(ptr, ZR050_COM_IDX + 4, 60,
-                                     ptr->com.data) + 4;
-
-               /* do the internal huffman table preload */
-               zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);
-
-               zr36050_write(ptr, ZR050_GO, 1);        // launch codec
-               zr36050_wait_end(ptr);
-               dprintk(2, "%s: Status after table preload: 0x%02x\n",
-                       ptr->name, ptr->status1);
-
-               if ((ptr->status1 & 0x4) == 0) {
-                       dprintk(1, KERN_ERR "%s: init aborted!\n",
-                               ptr->name);
-                       return; // something is wrong, its timed out!!!!
-               }
-
-               /* setup misc. data for compression (target code sizes) */
-
-               /* size of compressed code to reach without header data */
-               sum = ptr->real_code_vol - sum;
-               bitcnt = sum << 3;      /* need the size in bits */
-
-               tmp = bitcnt >> 16;
-               dprintk(3,
-                       "%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
-                       ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
-               zr36050_write(ptr, ZR050_TCV_NET_HI, tmp >> 8);
-               zr36050_write(ptr, ZR050_TCV_NET_MH, tmp & 0xff);
-               tmp = bitcnt & 0xffff;
-               zr36050_write(ptr, ZR050_TCV_NET_ML, tmp >> 8);
-               zr36050_write(ptr, ZR050_TCV_NET_LO, tmp & 0xff);
-
-               bitcnt -= bitcnt >> 7;  // bits without stuffing
-               bitcnt -= ((bitcnt * 5) >> 6);  // bits without eob
-
-               tmp = bitcnt >> 16;
-               dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
-                       ptr->name, bitcnt, tmp);
-               zr36050_write(ptr, ZR050_TCV_DATA_HI, tmp >> 8);
-               zr36050_write(ptr, ZR050_TCV_DATA_MH, tmp & 0xff);
-               tmp = bitcnt & 0xffff;
-               zr36050_write(ptr, ZR050_TCV_DATA_ML, tmp >> 8);
-               zr36050_write(ptr, ZR050_TCV_DATA_LO, tmp & 0xff);
-
-               /* compression setup with or without bitrate control */
-               zr36050_write(ptr, ZR050_MODE,
-                             ZR050_MO_COMP | ZR050_MO_PASS2 |
-                             (ptr->bitrate_ctrl ? ZR050_MO_BRC : 0));
-
-               /* this headers seem to deliver "valid AVI" jpeg frames */
-               zr36050_write(ptr, ZR050_MARKERS_EN,
-                             ZR050_ME_DQT | ZR050_ME_DHT |
-                             ((ptr->app.len > 0) ? ZR050_ME_APP : 0) |
-                             ((ptr->com.len > 0) ? ZR050_ME_COM : 0));
-       } else {
-               dprintk(2, "%s: EXPANSION SETUP\n", ptr->name);
-
-               /* 050 communicates with 055 in master mode */
-               zr36050_write(ptr, ZR050_HARDWARE,
-                             ZR050_HW_MSTR | ZR050_HW_CFIS_2_CLK);
-
-               /* encoding table preload */
-               zr36050_write(ptr, ZR050_MODE, ZR050_MO_TLM);
-
-               /* disable all IRQs */
-               zr36050_write(ptr, ZR050_INT_REQ_0, 0);
-               zr36050_write(ptr, ZR050_INT_REQ_1, 3); // low 2 bits always 1
-
-               dprintk(3, "%s: write DHT\n", ptr->name);
-               zr36050_pushit(ptr, ZR050_DHT_IDX, sizeof(zr36050_dht),
-                              zr36050_dht);
-
-               /* do the internal huffman table preload */
-               zr36050_write(ptr, ZR050_MARKERS_EN, ZR050_ME_DHTI);
-
-               zr36050_write(ptr, ZR050_GO, 1);        // launch codec
-               zr36050_wait_end(ptr);
-               dprintk(2, "%s: Status after table preload: 0x%02x\n",
-                       ptr->name, ptr->status1);
-
-               if ((ptr->status1 & 0x4) == 0) {
-                       dprintk(1, KERN_ERR "%s: init aborted!\n",
-                               ptr->name);
-                       return; // something is wrong, its timed out!!!!
-               }
-
-               /* setup misc. data for expansion */
-               zr36050_write(ptr, ZR050_MODE, 0);
-               zr36050_write(ptr, ZR050_MARKERS_EN, 0);
-       }
-
-       /* adr on selected, to allow GO from master */
-       zr36050_read(ptr, 0);
-}
-
-/* =========================================================================
-   CODEC API FUNCTIONS
-
-   this functions are accessed by the master via the API structure
-   ========================================================================= */
-
-/* set compression/expansion mode and launches codec -
-   this should be the last call from the master before starting processing */
-static int
-zr36050_set_mode (struct videocodec *codec,
-                 int                mode)
-{
-       struct zr36050 *ptr = (struct zr36050 *) codec->data;
-
-       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
-
-       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
-               return -EINVAL;
-
-       ptr->mode = mode;
-       zr36050_init(ptr);
-
-       return 0;
-}
-
-/* set picture size (norm is ignored as the codec doesn't know about it) */
-static int
-zr36050_set_video (struct videocodec   *codec,
-                  struct tvnorm       *norm,
-                  struct vfe_settings *cap,
-                  struct vfe_polarity *pol)
-{
-       struct zr36050 *ptr = (struct zr36050 *) codec->data;
-       int size;
-
-       dprintk(2, "%s: set_video %d.%d, %d/%d-%dx%d (0x%x) q%d call\n",
-               ptr->name, norm->HStart, norm->VStart,
-               cap->x, cap->y, cap->width, cap->height,
-               cap->decimation, cap->quality);
-       /* if () return -EINVAL;
-        * trust the master driver that it knows what it does - so
-        * we allow invalid startx/y and norm for now ... */
-       ptr->width = cap->width / (cap->decimation & 0xff);
-       ptr->height = cap->height / ((cap->decimation >> 8) & 0xff);
-
-       /* (KM) JPEG quality */
-       size = ptr->width * ptr->height;
-       size *= 16; /* size in bits */
-       /* apply quality setting */
-       size = size * cap->quality / 200;
-
-       /* Minimum: 1kb */
-       if (size < 8192)
-               size = 8192;
-       /* Maximum: 7/8 of code buffer */
-       if (size > ptr->total_code_vol * 7)
-               size = ptr->total_code_vol * 7;
-
-       ptr->real_code_vol = size >> 3; /* in bytes */
-
-       /* Set max_block_vol here (previously in zr36050_init, moved
-        * here for consistency with zr36060 code */
-       zr36050_write(ptr, ZR050_MBCV, ptr->max_block_vol);
-
-       return 0;
-}
-
-/* additional control functions */
-static int
-zr36050_control (struct videocodec *codec,
-                int                type,
-                int                size,
-                void              *data)
-{
-       struct zr36050 *ptr = (struct zr36050 *) codec->data;
-       int *ival = (int *) data;
-
-       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
-               size);
-
-       switch (type) {
-       case CODEC_G_STATUS:    /* get last status */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               zr36050_read_status1(ptr);
-               *ival = ptr->status1;
-               break;
-
-       case CODEC_G_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = CODEC_MODE_BJPG;
-               break;
-
-       case CODEC_S_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               if (*ival != CODEC_MODE_BJPG)
-                       return -EINVAL;
-               /* not needed, do nothing */
-               return 0;
-
-       case CODEC_G_VFE:
-       case CODEC_S_VFE:
-               /* not needed, do nothing */
-               return 0;
-
-       case CODEC_S_MMAP:
-               /* not available, give an error */
-               return -ENXIO;
-
-       case CODEC_G_JPEG_TDS_BYTE:     /* get target volume in byte */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = ptr->total_code_vol;
-               break;
-
-       case CODEC_S_JPEG_TDS_BYTE:     /* get target volume in byte */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               ptr->total_code_vol = *ival;
-               /* (Kieran Morrissey)
-                * code copied from zr36060.c to ensure proper bitrate */
-               ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
-               break;
-
-       case CODEC_G_JPEG_SCALE:        /* get scaling factor */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = zr36050_read_scalefactor(ptr);
-               break;
-
-       case CODEC_S_JPEG_SCALE:        /* set scaling factor */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               ptr->scalefact = *ival;
-               break;
-
-       case CODEC_G_JPEG_APP_DATA: {   /* get appn marker data */
-               struct jpeg_app_marker *app = data;
-
-               if (size != sizeof(struct jpeg_app_marker))
-                       return -EFAULT;
-
-               *app = ptr->app;
-               break;
-       }
-
-       case CODEC_S_JPEG_APP_DATA: {    /* set appn marker data */
-               struct jpeg_app_marker *app = data;
-
-               if (size != sizeof(struct jpeg_app_marker))
-                       return -EFAULT;
-
-               ptr->app = *app;
-               break;
-       }
-
-       case CODEC_G_JPEG_COM_DATA: {   /* get comment marker data */
-               struct jpeg_com_marker *com = data;
-
-               if (size != sizeof(struct jpeg_com_marker))
-                       return -EFAULT;
-
-               *com = ptr->com;
-               break;
-       }
-
-       case CODEC_S_JPEG_COM_DATA: {   /* set comment marker data */
-               struct jpeg_com_marker *com = data;
-
-               if (size != sizeof(struct jpeg_com_marker))
-                       return -EFAULT;
-
-               ptr->com = *com;
-               break;
-       }
-
-       default:
-               return -EINVAL;
-       }
-
-       return size;
-}
-
-/* =========================================================================
-   Exit and unregister function:
-
-   Deinitializes Zoran's JPEG processor
-   ========================================================================= */
-
-static int
-zr36050_unset (struct videocodec *codec)
-{
-       struct zr36050 *ptr = codec->data;
-
-       if (ptr) {
-               /* do wee need some codec deinit here, too ???? */
-
-               dprintk(1, "%s: finished codec #%d\n", ptr->name,
-                       ptr->num);
-               kfree(ptr);
-               codec->data = NULL;
-
-               zr36050_codecs--;
-               return 0;
-       }
-
-       return -EFAULT;
-}
-
-/* =========================================================================
-   Setup and registry function:
-
-   Initializes Zoran's JPEG processor
-
-   Also sets pixel size, average code size, mode (compr./decompr.)
-   (the given size is determined by the processor with the video interface)
-   ========================================================================= */
-
-static int
-zr36050_setup (struct videocodec *codec)
-{
-       struct zr36050 *ptr;
-       int res;
-
-       dprintk(2, "zr36050: initializing MJPEG subsystem #%d.\n",
-               zr36050_codecs);
-
-       if (zr36050_codecs == MAX_CODECS) {
-               dprintk(1,
-                       KERN_ERR "zr36050: Can't attach more codecs!\n");
-               return -ENOSPC;
-       }
-       //mem structure init
-       codec->data = ptr = kzalloc(sizeof(struct zr36050), GFP_KERNEL);
-       if (NULL == ptr) {
-               dprintk(1, KERN_ERR "zr36050: Can't get enough memory!\n");
-               return -ENOMEM;
-       }
-
-       snprintf(ptr->name, sizeof(ptr->name), "zr36050[%d]",
-                zr36050_codecs);
-       ptr->num = zr36050_codecs++;
-       ptr->codec = codec;
-
-       //testing
-       res = zr36050_basic_test(ptr);
-       if (res < 0) {
-               zr36050_unset(codec);
-               return res;
-       }
-       //final setup
-       memcpy(ptr->h_samp_ratio, zr36050_decimation_h, 8);
-       memcpy(ptr->v_samp_ratio, zr36050_decimation_v, 8);
-
-       ptr->bitrate_ctrl = 0;  /* 0 or 1 - fixed file size flag
-                                * (what is the difference?) */
-       ptr->mode = CODEC_DO_COMPRESSION;
-       ptr->width = 384;
-       ptr->height = 288;
-       ptr->total_code_vol = 16000;
-       ptr->max_block_vol = 240;
-       ptr->scalefact = 0x100;
-       ptr->dri = 1;
-
-       /* no app/com marker by default */
-       ptr->app.appn = 0;
-       ptr->app.len = 0;
-       ptr->com.len = 0;
-
-       zr36050_init(ptr);
-
-       dprintk(1, KERN_INFO "%s: codec attached and running\n",
-               ptr->name);
-
-       return 0;
-}
-
-static const struct videocodec zr36050_codec = {
-       .owner = THIS_MODULE,
-       .name = "zr36050",
-       .magic = 0L,            // magic not used
-       .flags =
-           CODEC_FLAG_JPEG | CODEC_FLAG_HARDWARE | CODEC_FLAG_ENCODER |
-           CODEC_FLAG_DECODER,
-       .type = CODEC_TYPE_ZR36050,
-       .setup = zr36050_setup, // functionality
-       .unset = zr36050_unset,
-       .set_mode = zr36050_set_mode,
-       .set_video = zr36050_set_video,
-       .control = zr36050_control,
-       // others are not used
-};
-
-/* =========================================================================
-   HOOK IN DRIVER AS KERNEL MODULE
-   ========================================================================= */
-
-static int __init
-zr36050_init_module (void)
-{
-       //dprintk(1, "ZR36050 driver %s\n",ZR050_VERSION);
-       zr36050_codecs = 0;
-       return videocodec_register(&zr36050_codec);
-}
-
-static void __exit
-zr36050_cleanup_module (void)
-{
-       if (zr36050_codecs) {
-               dprintk(1,
-                       "zr36050: something's wrong - %d codecs left somehow.\n",
-                       zr36050_codecs);
-       }
-       videocodec_unregister(&zr36050_codec);
-}
-
-module_init(zr36050_init_module);
-module_exit(zr36050_cleanup_module);
-
-MODULE_AUTHOR("Wolfgang Scherr <scherr@net4you.at>");
-MODULE_DESCRIPTION("Driver module for ZR36050 jpeg processors "
-                  ZR050_VERSION);
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zr36050.h b/drivers/media/video/zr36050.h
deleted file mode 100644 (file)
index 9f52f0c..0000000
+++ /dev/null
@@ -1,184 +0,0 @@
-/*
- * Zoran ZR36050 basic configuration functions - header file
- *
- * Copyright (C) 2001 Wolfgang Scherr <scherr@net4you.at>
- *
- * $Id: zr36050.h,v 1.1.2.2 2003/01/14 21:18:22 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#ifndef ZR36050_H
-#define ZR36050_H
-
-#include "videocodec.h"
-
-/* data stored for each zoran jpeg codec chip */
-struct zr36050 {
-       char name[32];
-       int num;
-       /* io datastructure */
-       struct videocodec *codec;
-       // last coder status
-       __u8 status1;
-       // actual coder setup
-       int mode;
-
-       __u16 width;
-       __u16 height;
-
-       __u16 bitrate_ctrl;
-
-       __u32 total_code_vol;
-       __u32 real_code_vol;
-       __u16 max_block_vol;
-
-       __u8 h_samp_ratio[8];
-       __u8 v_samp_ratio[8];
-       __u16 scalefact;
-       __u16 dri;
-
-       /* com/app marker */
-       struct jpeg_com_marker com;
-       struct jpeg_app_marker app;
-};
-
-/* zr36050 register addresses */
-#define ZR050_GO                  0x000
-#define ZR050_HARDWARE            0x002
-#define ZR050_MODE                0x003
-#define ZR050_OPTIONS             0x004
-#define ZR050_MBCV                0x005
-#define ZR050_MARKERS_EN          0x006
-#define ZR050_INT_REQ_0           0x007
-#define ZR050_INT_REQ_1           0x008
-#define ZR050_TCV_NET_HI          0x009
-#define ZR050_TCV_NET_MH          0x00a
-#define ZR050_TCV_NET_ML          0x00b
-#define ZR050_TCV_NET_LO          0x00c
-#define ZR050_TCV_DATA_HI         0x00d
-#define ZR050_TCV_DATA_MH         0x00e
-#define ZR050_TCV_DATA_ML         0x00f
-#define ZR050_TCV_DATA_LO         0x010
-#define ZR050_SF_HI               0x011
-#define ZR050_SF_LO               0x012
-#define ZR050_AF_HI               0x013
-#define ZR050_AF_M                0x014
-#define ZR050_AF_LO               0x015
-#define ZR050_ACV_HI              0x016
-#define ZR050_ACV_MH              0x017
-#define ZR050_ACV_ML              0x018
-#define ZR050_ACV_LO              0x019
-#define ZR050_ACT_HI              0x01a
-#define ZR050_ACT_MH              0x01b
-#define ZR050_ACT_ML              0x01c
-#define ZR050_ACT_LO              0x01d
-#define ZR050_ACV_TRUN_HI         0x01e
-#define ZR050_ACV_TRUN_MH         0x01f
-#define ZR050_ACV_TRUN_ML         0x020
-#define ZR050_ACV_TRUN_LO         0x021
-#define ZR050_STATUS_0            0x02e
-#define ZR050_STATUS_1            0x02f
-
-#define ZR050_SOF_IDX             0x040
-#define ZR050_SOS1_IDX            0x07a
-#define ZR050_SOS2_IDX            0x08a
-#define ZR050_SOS3_IDX            0x09a
-#define ZR050_SOS4_IDX            0x0aa
-#define ZR050_DRI_IDX             0x0c0
-#define ZR050_DNL_IDX             0x0c6
-#define ZR050_DQT_IDX             0x0cc
-#define ZR050_DHT_IDX             0x1d4
-#define ZR050_APP_IDX             0x380
-#define ZR050_COM_IDX             0x3c0
-
-/* zr36050 hardware register bits */
-
-#define ZR050_HW_BSWD                0x80
-#define ZR050_HW_MSTR                0x40
-#define ZR050_HW_DMA                 0x20
-#define ZR050_HW_CFIS_1_CLK          0x00
-#define ZR050_HW_CFIS_2_CLK          0x04
-#define ZR050_HW_CFIS_3_CLK          0x08
-#define ZR050_HW_CFIS_4_CLK          0x0C
-#define ZR050_HW_CFIS_5_CLK          0x10
-#define ZR050_HW_CFIS_6_CLK          0x14
-#define ZR050_HW_CFIS_7_CLK          0x18
-#define ZR050_HW_CFIS_8_CLK          0x1C
-#define ZR050_HW_BELE                0x01
-
-/* zr36050 mode register bits */
-
-#define ZR050_MO_COMP                0x80
-#define ZR050_MO_COMP                0x80
-#define ZR050_MO_ATP                 0x40
-#define ZR050_MO_PASS2               0x20
-#define ZR050_MO_TLM                 0x10
-#define ZR050_MO_DCONLY              0x08
-#define ZR050_MO_BRC                 0x04
-
-#define ZR050_MO_ATP                 0x40
-#define ZR050_MO_PASS2               0x20
-#define ZR050_MO_TLM                 0x10
-#define ZR050_MO_DCONLY              0x08
-
-/* zr36050 option register bits */
-
-#define ZR050_OP_NSCN_1              0x00
-#define ZR050_OP_NSCN_2              0x20
-#define ZR050_OP_NSCN_3              0x40
-#define ZR050_OP_NSCN_4              0x60
-#define ZR050_OP_NSCN_5              0x80
-#define ZR050_OP_NSCN_6              0xA0
-#define ZR050_OP_NSCN_7              0xC0
-#define ZR050_OP_NSCN_8              0xE0
-#define ZR050_OP_OVF                 0x10
-
-
-/* zr36050 markers-enable register bits */
-
-#define ZR050_ME_APP                 0x80
-#define ZR050_ME_COM                 0x40
-#define ZR050_ME_DRI                 0x20
-#define ZR050_ME_DQT                 0x10
-#define ZR050_ME_DHT                 0x08
-#define ZR050_ME_DNL                 0x04
-#define ZR050_ME_DQTI                0x02
-#define ZR050_ME_DHTI                0x01
-
-/* zr36050 status0/1 register bit masks */
-
-#define ZR050_ST_RST_MASK            0x20
-#define ZR050_ST_SOF_MASK            0x02
-#define ZR050_ST_SOS_MASK            0x02
-#define ZR050_ST_DATRDY_MASK         0x80
-#define ZR050_ST_MRKDET_MASK         0x40
-#define ZR050_ST_RFM_MASK            0x10
-#define ZR050_ST_RFD_MASK            0x08
-#define ZR050_ST_END_MASK            0x04
-#define ZR050_ST_TCVOVF_MASK         0x02
-#define ZR050_ST_DATOVF_MASK         0x01
-
-/* pixel component idx */
-
-#define ZR050_Y_COMPONENT         0
-#define ZR050_U_COMPONENT         1
-#define ZR050_V_COMPONENT         2
-
-#endif                         /*fndef ZR36050_H */
diff --git a/drivers/media/video/zr36057.h b/drivers/media/video/zr36057.h
deleted file mode 100644 (file)
index 54c9362..0000000
+++ /dev/null
@@ -1,168 +0,0 @@
-/*
- * zr36057.h - zr36057 register offsets
- *
- * Copyright (C) 1998 Dave Perks <dperks@ibm.net>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-
-#ifndef _ZR36057_H_
-#define _ZR36057_H_
-
-
-/* Zoran ZR36057 registers */
-
-#define ZR36057_VFEHCR          0x000  /* Video Front End, Horizontal Configuration Register */
-#define ZR36057_VFEHCR_HSPol            (1<<30)
-#define ZR36057_VFEHCR_HStart           10
-#define ZR36057_VFEHCR_HEnd            0
-#define ZR36057_VFEHCR_Hmask           0x3ff
-
-#define ZR36057_VFEVCR          0x004  /* Video Front End, Vertical Configuration Register */
-#define ZR36057_VFEVCR_VSPol            (1<<30)
-#define ZR36057_VFEVCR_VStart           10
-#define ZR36057_VFEVCR_VEnd            0
-#define ZR36057_VFEVCR_Vmask           0x3ff
-
-#define ZR36057_VFESPFR         0x008  /* Video Front End, Scaler and Pixel Format Register */
-#define ZR36057_VFESPFR_ExtFl           (1<<26)
-#define ZR36057_VFESPFR_TopField        (1<<25)
-#define ZR36057_VFESPFR_VCLKPol         (1<<24)
-#define ZR36057_VFESPFR_HFilter         21
-#define ZR36057_VFESPFR_HorDcm          14
-#define ZR36057_VFESPFR_VerDcm          8
-#define ZR36057_VFESPFR_DispMode        6
-#define ZR36057_VFESPFR_YUV422          (0<<3)
-#define ZR36057_VFESPFR_RGB888          (1<<3)
-#define ZR36057_VFESPFR_RGB565          (2<<3)
-#define ZR36057_VFESPFR_RGB555          (3<<3)
-#define ZR36057_VFESPFR_ErrDif          (1<<2)
-#define ZR36057_VFESPFR_Pack24          (1<<1)
-#define ZR36057_VFESPFR_LittleEndian    (1<<0)
-
-#define ZR36057_VDTR            0x00c  /* Video Display "Top" Register */
-
-#define ZR36057_VDBR            0x010  /* Video Display "Bottom" Register */
-
-#define ZR36057_VSSFGR          0x014  /* Video Stride, Status, and Frame Grab Register */
-#define ZR36057_VSSFGR_DispStride       16
-#define ZR36057_VSSFGR_VidOvf           (1<<8)
-#define ZR36057_VSSFGR_SnapShot         (1<<1)
-#define ZR36057_VSSFGR_FrameGrab        (1<<0)
-
-#define ZR36057_VDCR            0x018  /* Video Display Configuration Register */
-#define ZR36057_VDCR_VidEn              (1<<31)
-#define ZR36057_VDCR_MinPix             24
-#define ZR36057_VDCR_Triton             (1<<24)
-#define ZR36057_VDCR_VidWinHt           12
-#define ZR36057_VDCR_VidWinWid          0
-
-#define ZR36057_MMTR            0x01c  /* Masking Map "Top" Register */
-
-#define ZR36057_MMBR            0x020  /* Masking Map "Bottom" Register */
-
-#define ZR36057_OCR             0x024  /* Overlay Control Register */
-#define ZR36057_OCR_OvlEnable           (1 << 15)
-#define ZR36057_OCR_MaskStride          0
-
-#define ZR36057_SPGPPCR         0x028  /* System, PCI, and General Purpose Pins Control Register */
-#define ZR36057_SPGPPCR_SoftReset      (1<<24)
-
-#define ZR36057_GPPGCR1         0x02c  /* General Purpose Pins and GuestBus Control Register (1) */
-
-#define ZR36057_MCSAR           0x030  /* MPEG Code Source Address Register */
-
-#define ZR36057_MCTCR           0x034  /* MPEG Code Transfer Control Register */
-#define ZR36057_MCTCR_CodTime           (1 << 30)
-#define ZR36057_MCTCR_CEmpty            (1 << 29)
-#define ZR36057_MCTCR_CFlush            (1 << 28)
-#define ZR36057_MCTCR_CodGuestID       20
-#define ZR36057_MCTCR_CodGuestReg      16
-
-#define ZR36057_MCMPR           0x038  /* MPEG Code Memory Pointer Register */
-
-#define ZR36057_ISR             0x03c  /* Interrupt Status Register */
-#define ZR36057_ISR_GIRQ1               (1<<30)
-#define ZR36057_ISR_GIRQ0               (1<<29)
-#define ZR36057_ISR_CodRepIRQ           (1<<28)
-#define ZR36057_ISR_JPEGRepIRQ          (1<<27)
-
-#define ZR36057_ICR             0x040  /* Interrupt Control Register */
-#define ZR36057_ICR_GIRQ1               (1<<30)
-#define ZR36057_ICR_GIRQ0               (1<<29)
-#define ZR36057_ICR_CodRepIRQ           (1<<28)
-#define ZR36057_ICR_JPEGRepIRQ          (1<<27)
-#define ZR36057_ICR_IntPinEn            (1<<24)
-
-#define ZR36057_I2CBR           0x044  /* I2C Bus Register */
-#define ZR36057_I2CBR_SDA              (1<<1)
-#define ZR36057_I2CBR_SCL              (1<<0)
-
-#define ZR36057_JMC             0x100  /* JPEG Mode and Control */
-#define ZR36057_JMC_JPG                 (1 << 31)
-#define ZR36057_JMC_JPGExpMode          (0 << 29)
-#define ZR36057_JMC_JPGCmpMode          (1 << 29)
-#define ZR36057_JMC_MJPGExpMode         (2 << 29)
-#define ZR36057_JMC_MJPGCmpMode         (3 << 29)
-#define ZR36057_JMC_RTBUSY_FB           (1 << 6)
-#define ZR36057_JMC_Go_en               (1 << 5)
-#define ZR36057_JMC_SyncMstr            (1 << 4)
-#define ZR36057_JMC_Fld_per_buff        (1 << 3)
-#define ZR36057_JMC_VFIFO_FB            (1 << 2)
-#define ZR36057_JMC_CFIFO_FB            (1 << 1)
-#define ZR36057_JMC_Stll_LitEndian      (1 << 0)
-
-#define ZR36057_JPC             0x104  /* JPEG Process Control */
-#define ZR36057_JPC_P_Reset             (1 << 7)
-#define ZR36057_JPC_CodTrnsEn           (1 << 5)
-#define ZR36057_JPC_Active              (1 << 0)
-
-#define ZR36057_VSP             0x108  /* Vertical Sync Parameters */
-#define ZR36057_VSP_VsyncSize           16
-#define ZR36057_VSP_FrmTot              0
-
-#define ZR36057_HSP             0x10c  /* Horizontal Sync Parameters */
-#define ZR36057_HSP_HsyncStart          16
-#define ZR36057_HSP_LineTot             0
-
-#define ZR36057_FHAP            0x110  /* Field Horizontal Active Portion */
-#define ZR36057_FHAP_NAX                16
-#define ZR36057_FHAP_PAX                0
-
-#define ZR36057_FVAP            0x114  /* Field Vertical Active Portion */
-#define ZR36057_FVAP_NAY                16
-#define ZR36057_FVAP_PAY                0
-
-#define ZR36057_FPP             0x118  /* Field Process Parameters */
-#define ZR36057_FPP_Odd_Even            (1 << 0)
-
-#define ZR36057_JCBA            0x11c  /* JPEG Code Base Address */
-
-#define ZR36057_JCFT            0x120  /* JPEG Code FIFO Threshold */
-
-#define ZR36057_JCGI            0x124  /* JPEG Codec Guest ID */
-#define ZR36057_JCGI_JPEGuestID         4
-#define ZR36057_JCGI_JPEGuestReg        0
-
-#define ZR36057_GCR2            0x12c  /* GuestBus Control Register (2) */
-
-#define ZR36057_POR             0x200  /* Post Office Register */
-#define ZR36057_POR_POPen               (1<<25)
-#define ZR36057_POR_POTime              (1<<24)
-#define ZR36057_POR_PODir               (1<<23)
-
-#define ZR36057_STR             0x300  /* "Still" Transfer Register */
-
-#endif
diff --git a/drivers/media/video/zr36060.c b/drivers/media/video/zr36060.c
deleted file mode 100644 (file)
index 8e74054..0000000
+++ /dev/null
@@ -1,1014 +0,0 @@
-/*
- * Zoran ZR36060 basic configuration functions
- *
- * Copyright (C) 2002 Laurent Pinchart <laurent.pinchart@skynet.be>
- *
- * $Id: zr36060.c,v 1.1.2.22 2003/05/06 09:35:36 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#define ZR060_VERSION "v0.7"
-
-#include <linux/module.h>
-#include <linux/init.h>
-#include <linux/slab.h>
-#include <linux/delay.h>
-
-#include <linux/types.h>
-#include <linux/wait.h>
-
-/* includes for structures and defines regarding video
-   #include<linux/videodev.h> */
-
-/* I/O commands, error codes */
-#include <asm/io.h>
-//#include<errno.h>
-
-/* headerfile of this module */
-#include "zr36060.h"
-
-/* codec io API */
-#include "videocodec.h"
-
-/* it doesn't make sense to have more than 20 or so,
-  just to prevent some unwanted loops */
-#define MAX_CODECS 20
-
-/* amount of chips attached via this driver */
-static int zr36060_codecs;
-
-static int low_bitrate;
-module_param(low_bitrate, bool, 0);
-MODULE_PARM_DESC(low_bitrate, "Buz compatibility option, halves bitrate");
-
-/* debugging is available via module parameter */
-static int debug;
-module_param(debug, int, 0);
-MODULE_PARM_DESC(debug, "Debug level (0-4)");
-
-#define dprintk(num, format, args...) \
-       do { \
-               if (debug >= num) \
-                       printk(format, ##args); \
-       } while (0)
-
-/* =========================================================================
-   Local hardware I/O functions:
-
-   read/write via codec layer (registers are located in the master device)
-   ========================================================================= */
-
-/* read and write functions */
-static u8
-zr36060_read (struct zr36060 *ptr,
-             u16             reg)
-{
-       u8 value = 0;
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->readreg)
-               value = (ptr->codec->master_data->readreg(ptr->codec,
-                                                         reg)) & 0xff;
-       else
-               dprintk(1,
-                       KERN_ERR "%s: invalid I/O setup, nothing read!\n",
-                       ptr->name);
-
-       //dprintk(4, "%s: reading from 0x%04x: %02x\n",ptr->name,reg,value);
-
-       return value;
-}
-
-static void
-zr36060_write(struct zr36060 *ptr,
-             u16             reg,
-             u8              value)
-{
-       //dprintk(4, "%s: writing 0x%02x to 0x%04x\n",ptr->name,value,reg);
-       dprintk(4, "0x%02x @0x%04x\n", value, reg);
-
-       // just in case something is wrong...
-       if (ptr->codec->master_data->writereg)
-               ptr->codec->master_data->writereg(ptr->codec, reg, value);
-       else
-               dprintk(1,
-                       KERN_ERR
-                       "%s: invalid I/O setup, nothing written!\n",
-                       ptr->name);
-}
-
-/* =========================================================================
-   Local helper function:
-
-   status read
-   ========================================================================= */
-
-/* status is kept in datastructure */
-static u8
-zr36060_read_status (struct zr36060 *ptr)
-{
-       ptr->status = zr36060_read(ptr, ZR060_CFSR);
-
-       zr36060_read(ptr, 0);
-       return ptr->status;
-}
-
-/* =========================================================================
-   Local helper function:
-
-   scale factor read
-   ========================================================================= */
-
-/* scale factor is kept in datastructure */
-static u16
-zr36060_read_scalefactor (struct zr36060 *ptr)
-{
-       ptr->scalefact = (zr36060_read(ptr, ZR060_SF_HI) << 8) |
-                        (zr36060_read(ptr, ZR060_SF_LO) & 0xFF);
-
-       /* leave 0 selected for an eventually GO from master */
-       zr36060_read(ptr, 0);
-       return ptr->scalefact;
-}
-
-/* =========================================================================
-   Local helper function:
-
-   wait if codec is ready to proceed (end of processing) or time is over
-   ========================================================================= */
-
-static void
-zr36060_wait_end (struct zr36060 *ptr)
-{
-       int i = 0;
-
-       while (zr36060_read_status(ptr) & ZR060_CFSR_Busy) {
-               udelay(1);
-               if (i++ > 200000) {     // 200ms, there is for sure something wrong!!!
-                       dprintk(1,
-                               "%s: timeout at wait_end (last status: 0x%02x)\n",
-                               ptr->name, ptr->status);
-                       break;
-               }
-       }
-}
-
-/* =========================================================================
-   Local helper function:
-
-   basic test of "connectivity", writes/reads to/from memory the SOF marker
-   ========================================================================= */
-
-static int
-zr36060_basic_test (struct zr36060 *ptr)
-{
-       if ((zr36060_read(ptr, ZR060_IDR_DEV) != 0x33) &&
-           (zr36060_read(ptr, ZR060_IDR_REV) != 0x01)) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, can't connect to jpeg processor!\n",
-                       ptr->name);
-               return -ENXIO;
-       }
-
-       zr36060_wait_end(ptr);
-       if (ptr->status & ZR060_CFSR_Busy) {
-               dprintk(1,
-                       KERN_ERR
-                       "%s: attach failed, jpeg processor failed (end flag)!\n",
-                       ptr->name);
-               return -EBUSY;
-       }
-
-       return 0;               /* looks good! */
-}
-
-/* =========================================================================
-   Local helper function:
-
-   simple loop for pushing the init datasets
-   ========================================================================= */
-
-static int
-zr36060_pushit (struct zr36060 *ptr,
-               u16             startreg,
-               u16             len,
-               const char     *data)
-{
-       int i = 0;
-
-       dprintk(4, "%s: write data block to 0x%04x (len=%d)\n", ptr->name,
-               startreg, len);
-       while (i < len) {
-               zr36060_write(ptr, startreg++, data[i++]);
-       }
-
-       return i;
-}
-
-/* =========================================================================
-   Basic datasets:
-
-   jpeg baseline setup data (you find it on lots places in internet, or just
-   extract it from any regular .jpg image...)
-
-   Could be variable, but until it's not needed it they are just fixed to save
-   memory. Otherwise expand zr36060 structure with arrays, push the values to
-   it and initalize from there, as e.g. the linux zr36057/60 driver does it.
-   ========================================================================= */
-
-static const char zr36060_dqt[0x86] = {
-       0xff, 0xdb,             //Marker: DQT
-       0x00, 0x84,             //Length: 2*65+2
-       0x00,                   //Pq,Tq first table
-       0x10, 0x0b, 0x0c, 0x0e, 0x0c, 0x0a, 0x10, 0x0e,
-       0x0d, 0x0e, 0x12, 0x11, 0x10, 0x13, 0x18, 0x28,
-       0x1a, 0x18, 0x16, 0x16, 0x18, 0x31, 0x23, 0x25,
-       0x1d, 0x28, 0x3a, 0x33, 0x3d, 0x3c, 0x39, 0x33,
-       0x38, 0x37, 0x40, 0x48, 0x5c, 0x4e, 0x40, 0x44,
-       0x57, 0x45, 0x37, 0x38, 0x50, 0x6d, 0x51, 0x57,
-       0x5f, 0x62, 0x67, 0x68, 0x67, 0x3e, 0x4d, 0x71,
-       0x79, 0x70, 0x64, 0x78, 0x5c, 0x65, 0x67, 0x63,
-       0x01,                   //Pq,Tq second table
-       0x11, 0x12, 0x12, 0x18, 0x15, 0x18, 0x2f, 0x1a,
-       0x1a, 0x2f, 0x63, 0x42, 0x38, 0x42, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63,
-       0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63, 0x63
-};
-
-static const char zr36060_dht[0x1a4] = {
-       0xff, 0xc4,             //Marker: DHT
-       0x01, 0xa2,             //Length: 2*AC, 2*DC
-       0x00,                   //DC first table
-       0x00, 0x01, 0x05, 0x01, 0x01, 0x01, 0x01, 0x01,
-       0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
-       0x01,                   //DC second table
-       0x00, 0x03, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01,
-       0x01, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
-       0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B,
-       0x10,                   //AC first table
-       0x00, 0x02, 0x01, 0x03, 0x03, 0x02, 0x04, 0x03,
-       0x05, 0x05, 0x04, 0x04, 0x00, 0x00,
-       0x01, 0x7D, 0x01, 0x02, 0x03, 0x00, 0x04, 0x11,
-       0x05, 0x12, 0x21, 0x31, 0x41, 0x06, 0x13, 0x51, 0x61,
-       0x07, 0x22, 0x71, 0x14, 0x32, 0x81, 0x91, 0xA1,
-       0x08, 0x23, 0x42, 0xB1, 0xC1, 0x15, 0x52, 0xD1, 0xF0, 0x24,
-       0x33, 0x62, 0x72, 0x82, 0x09, 0x0A, 0x16, 0x17,
-       0x18, 0x19, 0x1A, 0x25, 0x26, 0x27, 0x28, 0x29, 0x2A, 0x34,
-       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
-       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
-       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
-       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
-       0x79, 0x7A, 0x83, 0x84, 0x85, 0x86, 0x87, 0x88,
-       0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99,
-       0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7, 0xA8,
-       0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8, 0xB9,
-       0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7, 0xC8,
-       0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8, 0xD9,
-       0xDA, 0xE1, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
-       0xE8, 0xE9, 0xEA, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
-       0xF8, 0xF9, 0xFA,
-       0x11,                   //AC second table
-       0x00, 0x02, 0x01, 0x02, 0x04, 0x04, 0x03, 0x04,
-       0x07, 0x05, 0x04, 0x04, 0x00, 0x01,
-       0x02, 0x77, 0x00, 0x01, 0x02, 0x03, 0x11, 0x04,
-       0x05, 0x21, 0x31, 0x06, 0x12, 0x41, 0x51, 0x07, 0x61, 0x71,
-       0x13, 0x22, 0x32, 0x81, 0x08, 0x14, 0x42, 0x91,
-       0xA1, 0xB1, 0xC1, 0x09, 0x23, 0x33, 0x52, 0xF0, 0x15, 0x62,
-       0x72, 0xD1, 0x0A, 0x16, 0x24, 0x34, 0xE1, 0x25,
-       0xF1, 0x17, 0x18, 0x19, 0x1A, 0x26, 0x27, 0x28, 0x29, 0x2A,
-       0x35, 0x36, 0x37, 0x38, 0x39, 0x3A, 0x43, 0x44,
-       0x45, 0x46, 0x47, 0x48, 0x49, 0x4A, 0x53, 0x54, 0x55, 0x56,
-       0x57, 0x58, 0x59, 0x5A, 0x63, 0x64, 0x65, 0x66,
-       0x67, 0x68, 0x69, 0x6A, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
-       0x79, 0x7A, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
-       0x88, 0x89, 0x8A, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98,
-       0x99, 0x9A, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6, 0xA7,
-       0xA8, 0xA9, 0xAA, 0xB2, 0xB3, 0xB4, 0xB5, 0xB6, 0xB7, 0xB8,
-       0xB9, 0xBA, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
-       0xC8, 0xC9, 0xCA, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6, 0xD7, 0xD8,
-       0xD9, 0xDA, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6, 0xE7,
-       0xE8, 0xE9, 0xEA, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7, 0xF8,
-       0xF9, 0xFA
-};
-
-/* jpeg baseline setup, this is just fixed in this driver (YUV pictures) */
-#define NO_OF_COMPONENTS          0x3  //Y,U,V
-#define BASELINE_PRECISION        0x8  //MCU size (?)
-static const char zr36060_tq[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's QT
-static const char zr36060_td[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's DC
-static const char zr36060_ta[8] = { 0, 1, 1, 0, 0, 0, 0, 0 };  //table idx's AC
-
-/* horizontal 422 decimation setup (maybe we support 411 or so later, too) */
-static const char zr36060_decimation_h[8] = { 2, 1, 1, 0, 0, 0, 0, 0 };
-static const char zr36060_decimation_v[8] = { 1, 1, 1, 0, 0, 0, 0, 0 };
-
-/* =========================================================================
-   Local helper functions:
-
-   calculation and setup of parameter-dependent JPEG baseline segments
-   (needed for compression only)
-   ========================================================================= */
-
-/* ------------------------------------------------------------------------- */
-
-/* SOF (start of frame) segment depends on width, height and sampling ratio
-                        of each color component */
-
-static int
-zr36060_set_sof (struct zr36060 *ptr)
-{
-       char sof_data[34];      // max. size of register set
-       int i;
-
-       dprintk(3, "%s: write SOF (%dx%d, %d components)\n", ptr->name,
-               ptr->width, ptr->height, NO_OF_COMPONENTS);
-       sof_data[0] = 0xff;
-       sof_data[1] = 0xc0;
-       sof_data[2] = 0x00;
-       sof_data[3] = (3 * NO_OF_COMPONENTS) + 8;
-       sof_data[4] = BASELINE_PRECISION;       // only '8' possible with zr36060
-       sof_data[5] = (ptr->height) >> 8;
-       sof_data[6] = (ptr->height) & 0xff;
-       sof_data[7] = (ptr->width) >> 8;
-       sof_data[8] = (ptr->width) & 0xff;
-       sof_data[9] = NO_OF_COMPONENTS;
-       for (i = 0; i < NO_OF_COMPONENTS; i++) {
-               sof_data[10 + (i * 3)] = i;     // index identifier
-               sof_data[11 + (i * 3)] = (ptr->h_samp_ratio[i] << 4) |
-                                        (ptr->v_samp_ratio[i]); // sampling ratios
-               sof_data[12 + (i * 3)] = zr36060_tq[i]; // Q table selection
-       }
-       return zr36060_pushit(ptr, ZR060_SOF_IDX,
-                             (3 * NO_OF_COMPONENTS) + 10, sof_data);
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* SOS (start of scan) segment depends on the used scan components
-                       of each color component */
-
-static int
-zr36060_set_sos (struct zr36060 *ptr)
-{
-       char sos_data[16];      // max. size of register set
-       int i;
-
-       dprintk(3, "%s: write SOS\n", ptr->name);
-       sos_data[0] = 0xff;
-       sos_data[1] = 0xda;
-       sos_data[2] = 0x00;
-       sos_data[3] = 2 + 1 + (2 * NO_OF_COMPONENTS) + 3;
-       sos_data[4] = NO_OF_COMPONENTS;
-       for (i = 0; i < NO_OF_COMPONENTS; i++) {
-               sos_data[5 + (i * 2)] = i;      // index
-               sos_data[6 + (i * 2)] = (zr36060_td[i] << 4) |
-                                       zr36060_ta[i]; // AC/DC tbl.sel.
-       }
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 2] = 00;      // scan start
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 3] = 0x3f;
-       sos_data[2 + 1 + (2 * NO_OF_COMPONENTS) + 4] = 00;
-       return zr36060_pushit(ptr, ZR060_SOS_IDX,
-                             4 + 1 + (2 * NO_OF_COMPONENTS) + 3,
-                             sos_data);
-}
-
-/* ------------------------------------------------------------------------- */
-
-/* DRI (define restart interval) */
-
-static int
-zr36060_set_dri (struct zr36060 *ptr)
-{
-       char dri_data[6];       // max. size of register set
-
-       dprintk(3, "%s: write DRI\n", ptr->name);
-       dri_data[0] = 0xff;
-       dri_data[1] = 0xdd;
-       dri_data[2] = 0x00;
-       dri_data[3] = 0x04;
-       dri_data[4] = (ptr->dri) >> 8;
-       dri_data[5] = (ptr->dri) & 0xff;
-       return zr36060_pushit(ptr, ZR060_DRI_IDX, 6, dri_data);
-}
-
-/* =========================================================================
-   Setup function:
-
-   Setup compression/decompression of Zoran's JPEG processor
-   ( see also zoran 36060 manual )
-
-   ... sorry for the spaghetti code ...
-   ========================================================================= */
-static void
-zr36060_init (struct zr36060 *ptr)
-{
-       int sum = 0;
-       long bitcnt, tmp;
-
-       if (ptr->mode == CODEC_DO_COMPRESSION) {
-               dprintk(2, "%s: COMPRESSION SETUP\n", ptr->name);
-
-               zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
-
-               /* 060 communicates with 067 in master mode */
-               zr36060_write(ptr, ZR060_CIR, ZR060_CIR_CodeMstr);
-
-               /* Compression with or without variable scale factor */
-               /*FIXME: What about ptr->bitrate_ctrl? */
-               zr36060_write(ptr, ZR060_CMR,
-                             ZR060_CMR_Comp | ZR060_CMR_Pass2 |
-                             ZR060_CMR_BRB);
-
-               /* Must be zero */
-               zr36060_write(ptr, ZR060_MBZ, 0x00);
-               zr36060_write(ptr, ZR060_TCR_HI, 0x00);
-               zr36060_write(ptr, ZR060_TCR_LO, 0x00);
-
-               /* Disable all IRQs - no DataErr means autoreset */
-               zr36060_write(ptr, ZR060_IMR, 0);
-
-               /* volume control settings */
-               zr36060_write(ptr, ZR060_SF_HI, ptr->scalefact >> 8);
-               zr36060_write(ptr, ZR060_SF_LO, ptr->scalefact & 0xff);
-
-               zr36060_write(ptr, ZR060_AF_HI, 0xff);
-               zr36060_write(ptr, ZR060_AF_M, 0xff);
-               zr36060_write(ptr, ZR060_AF_LO, 0xff);
-
-               /* setup the variable jpeg tables */
-               sum += zr36060_set_sof(ptr);
-               sum += zr36060_set_sos(ptr);
-               sum += zr36060_set_dri(ptr);
-
-               /* setup the fixed jpeg tables - maybe variable, though -
-                * (see table init section above) */
-               sum +=
-                   zr36060_pushit(ptr, ZR060_DQT_IDX, sizeof(zr36060_dqt),
-                                  zr36060_dqt);
-               sum +=
-                   zr36060_pushit(ptr, ZR060_DHT_IDX, sizeof(zr36060_dht),
-                                  zr36060_dht);
-               zr36060_write(ptr, ZR060_APP_IDX, 0xff);
-               zr36060_write(ptr, ZR060_APP_IDX + 1, 0xe0 + ptr->app.appn);
-               zr36060_write(ptr, ZR060_APP_IDX + 2, 0x00);
-               zr36060_write(ptr, ZR060_APP_IDX + 3, ptr->app.len + 2);
-               sum += zr36060_pushit(ptr, ZR060_APP_IDX + 4, 60,
-                                     ptr->app.data) + 4;
-               zr36060_write(ptr, ZR060_COM_IDX, 0xff);
-               zr36060_write(ptr, ZR060_COM_IDX + 1, 0xfe);
-               zr36060_write(ptr, ZR060_COM_IDX + 2, 0x00);
-               zr36060_write(ptr, ZR060_COM_IDX + 3, ptr->com.len + 2);
-               sum += zr36060_pushit(ptr, ZR060_COM_IDX + 4, 60,
-                                     ptr->com.data) + 4;
-
-               /* setup misc. data for compression (target code sizes) */
-
-               /* size of compressed code to reach without header data */
-               sum = ptr->real_code_vol - sum;
-               bitcnt = sum << 3;      /* need the size in bits */
-
-               tmp = bitcnt >> 16;
-               dprintk(3,
-                       "%s: code: csize=%d, tot=%d, bit=%ld, highbits=%ld\n",
-                       ptr->name, sum, ptr->real_code_vol, bitcnt, tmp);
-               zr36060_write(ptr, ZR060_TCV_NET_HI, tmp >> 8);
-               zr36060_write(ptr, ZR060_TCV_NET_MH, tmp & 0xff);
-               tmp = bitcnt & 0xffff;
-               zr36060_write(ptr, ZR060_TCV_NET_ML, tmp >> 8);
-               zr36060_write(ptr, ZR060_TCV_NET_LO, tmp & 0xff);
-
-               bitcnt -= bitcnt >> 7;  // bits without stuffing
-               bitcnt -= ((bitcnt * 5) >> 6);  // bits without eob
-
-               tmp = bitcnt >> 16;
-               dprintk(3, "%s: code: nettobit=%ld, highnettobits=%ld\n",
-                       ptr->name, bitcnt, tmp);
-               zr36060_write(ptr, ZR060_TCV_DATA_HI, tmp >> 8);
-               zr36060_write(ptr, ZR060_TCV_DATA_MH, tmp & 0xff);
-               tmp = bitcnt & 0xffff;
-               zr36060_write(ptr, ZR060_TCV_DATA_ML, tmp >> 8);
-               zr36060_write(ptr, ZR060_TCV_DATA_LO, tmp & 0xff);
-
-               /* JPEG markers to be included in the compressed stream */
-               zr36060_write(ptr, ZR060_MER,
-                             ZR060_MER_DQT | ZR060_MER_DHT |
-                             ((ptr->com.len > 0) ? ZR060_MER_Com : 0) |
-                             ((ptr->app.len > 0) ? ZR060_MER_App : 0));
-
-               /* Setup the Video Frontend */
-               /* Limit pixel range to 16..235 as per CCIR-601 */
-               zr36060_write(ptr, ZR060_VCR, ZR060_VCR_Range);
-
-       } else {
-               dprintk(2, "%s: EXPANSION SETUP\n", ptr->name);
-
-               zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
-
-               /* 060 communicates with 067 in master mode */
-               zr36060_write(ptr, ZR060_CIR, ZR060_CIR_CodeMstr);
-
-               /* Decompression */
-               zr36060_write(ptr, ZR060_CMR, 0);
-
-               /* Must be zero */
-               zr36060_write(ptr, ZR060_MBZ, 0x00);
-               zr36060_write(ptr, ZR060_TCR_HI, 0x00);
-               zr36060_write(ptr, ZR060_TCR_LO, 0x00);
-
-               /* Disable all IRQs - no DataErr means autoreset */
-               zr36060_write(ptr, ZR060_IMR, 0);
-
-               /* setup misc. data for expansion */
-               zr36060_write(ptr, ZR060_MER, 0);
-
-               /* setup the fixed jpeg tables - maybe variable, though -
-                * (see table init section above) */
-               zr36060_pushit(ptr, ZR060_DHT_IDX, sizeof(zr36060_dht),
-                              zr36060_dht);
-
-               /* Setup the Video Frontend */
-               //zr36060_write(ptr, ZR060_VCR, ZR060_VCR_FIExt);
-               //this doesn't seem right and doesn't work...
-               zr36060_write(ptr, ZR060_VCR, ZR060_VCR_Range);
-       }
-
-       /* Load the tables */
-       zr36060_write(ptr, ZR060_LOAD,
-                     ZR060_LOAD_SyncRst | ZR060_LOAD_Load);
-       zr36060_wait_end(ptr);
-       dprintk(2, "%s: Status after table preload: 0x%02x\n", ptr->name,
-               ptr->status);
-
-       if (ptr->status & ZR060_CFSR_Busy) {
-               dprintk(1, KERN_ERR "%s: init aborted!\n", ptr->name);
-               return;         // something is wrong, its timed out!!!!
-       }
-}
-
-/* =========================================================================
-   CODEC API FUNCTIONS
-
-   this functions are accessed by the master via the API structure
-   ========================================================================= */
-
-/* set compression/expansion mode and launches codec -
-   this should be the last call from the master before starting processing */
-static int
-zr36060_set_mode (struct videocodec *codec,
-                 int                mode)
-{
-       struct zr36060 *ptr = (struct zr36060 *) codec->data;
-
-       dprintk(2, "%s: set_mode %d call\n", ptr->name, mode);
-
-       if ((mode != CODEC_DO_EXPANSION) && (mode != CODEC_DO_COMPRESSION))
-               return -EINVAL;
-
-       ptr->mode = mode;
-       zr36060_init(ptr);
-
-       return 0;
-}
-
-/* set picture size (norm is ignored as the codec doesn't know about it) */
-static int
-zr36060_set_video (struct videocodec   *codec,
-                  struct tvnorm       *norm,
-                  struct vfe_settings *cap,
-                  struct vfe_polarity *pol)
-{
-       struct zr36060 *ptr = (struct zr36060 *) codec->data;
-       u32 reg;
-       int size;
-
-       dprintk(2, "%s: set_video %d/%d-%dx%d (%%%d) call\n", ptr->name,
-               cap->x, cap->y, cap->width, cap->height, cap->decimation);
-
-       /* if () return -EINVAL;
-        * trust the master driver that it knows what it does - so
-        * we allow invalid startx/y and norm for now ... */
-       ptr->width = cap->width / (cap->decimation & 0xff);
-       ptr->height = cap->height / (cap->decimation >> 8);
-
-       zr36060_write(ptr, ZR060_LOAD, ZR060_LOAD_SyncRst);
-
-       /* Note that VSPol/HSPol bits in zr36060 have the opposite
-        * meaning of their zr360x7 counterparts with the same names
-        * N.b. for VSPol this is only true if FIVEdge = 0 (default,
-        * left unchanged here - in accordance with datasheet).
-       */
-       reg = (!pol->vsync_pol ? ZR060_VPR_VSPol : 0)
-           | (!pol->hsync_pol ? ZR060_VPR_HSPol : 0)
-           | (pol->field_pol ? ZR060_VPR_FIPol : 0)
-           | (pol->blank_pol ? ZR060_VPR_BLPol : 0)
-           | (pol->subimg_pol ? ZR060_VPR_SImgPol : 0)
-           | (pol->poe_pol ? ZR060_VPR_PoePol : 0)
-           | (pol->pvalid_pol ? ZR060_VPR_PValPol : 0)
-           | (pol->vclk_pol ? ZR060_VPR_VCLKPol : 0);
-       zr36060_write(ptr, ZR060_VPR, reg);
-
-       reg = 0;
-       switch (cap->decimation & 0xff) {
-       default:
-       case 1:
-               break;
-
-       case 2:
-               reg |= ZR060_SR_HScale2;
-               break;
-
-       case 4:
-               reg |= ZR060_SR_HScale4;
-               break;
-       }
-
-       switch (cap->decimation >> 8) {
-       default:
-       case 1:
-               break;
-
-       case 2:
-               reg |= ZR060_SR_VScale;
-               break;
-       }
-       zr36060_write(ptr, ZR060_SR, reg);
-
-       zr36060_write(ptr, ZR060_BCR_Y, 0x00);
-       zr36060_write(ptr, ZR060_BCR_U, 0x80);
-       zr36060_write(ptr, ZR060_BCR_V, 0x80);
-
-       /* sync generator */
-
-       reg = norm->Ht - 1;     /* Vtotal */
-       zr36060_write(ptr, ZR060_SGR_VTOTAL_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SGR_VTOTAL_LO, (reg >> 0) & 0xff);
-
-       reg = norm->Wt - 1;     /* Htotal */
-       zr36060_write(ptr, ZR060_SGR_HTOTAL_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SGR_HTOTAL_LO, (reg >> 0) & 0xff);
-
-       reg = 6 - 1;            /* VsyncSize */
-       zr36060_write(ptr, ZR060_SGR_VSYNC, reg);
-
-       //reg   = 30 - 1;               /* HsyncSize */
-///*CP*/        reg = (zr->params.norm == 1 ? 57 : 68);
-       reg = 68;
-       zr36060_write(ptr, ZR060_SGR_HSYNC, reg);
-
-       reg = norm->VStart - 1; /* BVstart */
-       zr36060_write(ptr, ZR060_SGR_BVSTART, reg);
-
-       reg += norm->Ha / 2;    /* BVend */
-       zr36060_write(ptr, ZR060_SGR_BVEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SGR_BVEND_LO, (reg >> 0) & 0xff);
-
-       reg = norm->HStart - 1; /* BHstart */
-       zr36060_write(ptr, ZR060_SGR_BHSTART, reg);
-
-       reg += norm->Wa;        /* BHend */
-       zr36060_write(ptr, ZR060_SGR_BHEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SGR_BHEND_LO, (reg >> 0) & 0xff);
-
-       /* active area */
-       reg = cap->y + norm->VStart;    /* Vstart */
-       zr36060_write(ptr, ZR060_AAR_VSTART_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_AAR_VSTART_LO, (reg >> 0) & 0xff);
-
-       reg += cap->height;     /* Vend */
-       zr36060_write(ptr, ZR060_AAR_VEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_AAR_VEND_LO, (reg >> 0) & 0xff);
-
-       reg = cap->x + norm->HStart;    /* Hstart */
-       zr36060_write(ptr, ZR060_AAR_HSTART_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_AAR_HSTART_LO, (reg >> 0) & 0xff);
-
-       reg += cap->width;      /* Hend */
-       zr36060_write(ptr, ZR060_AAR_HEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_AAR_HEND_LO, (reg >> 0) & 0xff);
-
-       /* subimage area */
-       reg = norm->VStart - 4; /* SVstart */
-       zr36060_write(ptr, ZR060_SWR_VSTART_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SWR_VSTART_LO, (reg >> 0) & 0xff);
-
-       reg += norm->Ha / 2 + 8;        /* SVend */
-       zr36060_write(ptr, ZR060_SWR_VEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SWR_VEND_LO, (reg >> 0) & 0xff);
-
-       reg = norm->HStart /*+ 64 */  - 4;      /* SHstart */
-       zr36060_write(ptr, ZR060_SWR_HSTART_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SWR_HSTART_LO, (reg >> 0) & 0xff);
-
-       reg += norm->Wa + 8;    /* SHend */
-       zr36060_write(ptr, ZR060_SWR_HEND_HI, (reg >> 8) & 0xff);
-       zr36060_write(ptr, ZR060_SWR_HEND_LO, (reg >> 0) & 0xff);
-
-       size = ptr->width * ptr->height;
-       /* Target compressed field size in bits: */
-       size = size * 16;       /* uncompressed size in bits */
-       /* (Ronald) by default, quality = 100 is a compression
-        * ratio 1:2. Setting low_bitrate (insmod option) sets
-        * it to 1:4 (instead of 1:2, zr36060 max) as limit because the
-        * buz can't handle more at decimation=1... Use low_bitrate if
-        * you have a Buz, unless you know what you're doing */
-       size = size * cap->quality / (low_bitrate ? 400 : 200);
-       /* Lower limit (arbitrary, 1 KB) */
-       if (size < 8192)
-               size = 8192;
-       /* Upper limit: 7/8 of the code buffers */
-       if (size > ptr->total_code_vol * 7)
-               size = ptr->total_code_vol * 7;
-
-       ptr->real_code_vol = size >> 3; /* in bytes */
-
-       /* the MBCVR is the *maximum* block volume, according to the
-        * JPEG ISO specs, this shouldn't be used, since that allows
-        * for the best encoding quality. So set it to it's max value */
-       reg = ptr->max_block_vol;
-       zr36060_write(ptr, ZR060_MBCVR, reg);
-
-       return 0;
-}
-
-/* additional control functions */
-static int
-zr36060_control (struct videocodec *codec,
-                int                type,
-                int                size,
-                void              *data)
-{
-       struct zr36060 *ptr = (struct zr36060 *) codec->data;
-       int *ival = (int *) data;
-
-       dprintk(2, "%s: control %d call with %d byte\n", ptr->name, type,
-               size);
-
-       switch (type) {
-       case CODEC_G_STATUS:    /* get last status */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               zr36060_read_status(ptr);
-               *ival = ptr->status;
-               break;
-
-       case CODEC_G_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = CODEC_MODE_BJPG;
-               break;
-
-       case CODEC_S_CODEC_MODE:
-               if (size != sizeof(int))
-                       return -EFAULT;
-               if (*ival != CODEC_MODE_BJPG)
-                       return -EINVAL;
-               /* not needed, do nothing */
-               return 0;
-
-       case CODEC_G_VFE:
-       case CODEC_S_VFE:
-               /* not needed, do nothing */
-               return 0;
-
-       case CODEC_S_MMAP:
-               /* not available, give an error */
-               return -ENXIO;
-
-       case CODEC_G_JPEG_TDS_BYTE:     /* get target volume in byte */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = ptr->total_code_vol;
-               break;
-
-       case CODEC_S_JPEG_TDS_BYTE:     /* get target volume in byte */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               ptr->total_code_vol = *ival;
-               ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
-               break;
-
-       case CODEC_G_JPEG_SCALE:        /* get scaling factor */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               *ival = zr36060_read_scalefactor(ptr);
-               break;
-
-       case CODEC_S_JPEG_SCALE:        /* set scaling factor */
-               if (size != sizeof(int))
-                       return -EFAULT;
-               ptr->scalefact = *ival;
-               break;
-
-       case CODEC_G_JPEG_APP_DATA: {   /* get appn marker data */
-               struct jpeg_app_marker *app = data;
-
-               if (size != sizeof(struct jpeg_app_marker))
-                       return -EFAULT;
-
-               *app = ptr->app;
-               break;
-       }
-
-       case CODEC_S_JPEG_APP_DATA: {   /* set appn marker data */
-               struct jpeg_app_marker *app = data;
-
-               if (size != sizeof(struct jpeg_app_marker))
-                       return -EFAULT;
-
-               ptr->app = *app;
-               break;
-       }
-
-       case CODEC_G_JPEG_COM_DATA: {   /* get comment marker data */
-               struct jpeg_com_marker *com = data;
-
-               if (size != sizeof(struct jpeg_com_marker))
-                       return -EFAULT;
-
-               *com = ptr->com;
-               break;
-       }
-
-       case CODEC_S_JPEG_COM_DATA: {   /* set comment marker data */
-               struct jpeg_com_marker *com = data;
-
-               if (size != sizeof(struct jpeg_com_marker))
-                       return -EFAULT;
-
-               ptr->com = *com;
-               break;
-       }
-
-       default:
-               return -EINVAL;
-       }
-
-       return size;
-}
-
-/* =========================================================================
-   Exit and unregister function:
-
-   Deinitializes Zoran's JPEG processor
-   ========================================================================= */
-
-static int
-zr36060_unset (struct videocodec *codec)
-{
-       struct zr36060 *ptr = codec->data;
-
-       if (ptr) {
-               /* do wee need some codec deinit here, too ???? */
-
-               dprintk(1, "%s: finished codec #%d\n", ptr->name,
-                       ptr->num);
-               kfree(ptr);
-               codec->data = NULL;
-
-               zr36060_codecs--;
-               return 0;
-       }
-
-       return -EFAULT;
-}
-
-/* =========================================================================
-   Setup and registry function:
-
-   Initializes Zoran's JPEG processor
-
-   Also sets pixel size, average code size, mode (compr./decompr.)
-   (the given size is determined by the processor with the video interface)
-   ========================================================================= */
-
-static int
-zr36060_setup (struct videocodec *codec)
-{
-       struct zr36060 *ptr;
-       int res;
-
-       dprintk(2, "zr36060: initializing MJPEG subsystem #%d.\n",
-               zr36060_codecs);
-
-       if (zr36060_codecs == MAX_CODECS) {
-               dprintk(1,
-                       KERN_ERR "zr36060: Can't attach more codecs!\n");
-               return -ENOSPC;
-       }
-       //mem structure init
-       codec->data = ptr = kzalloc(sizeof(struct zr36060), GFP_KERNEL);
-       if (NULL == ptr) {
-               dprintk(1, KERN_ERR "zr36060: Can't get enough memory!\n");
-               return -ENOMEM;
-       }
-
-       snprintf(ptr->name, sizeof(ptr->name), "zr36060[%d]",
-                zr36060_codecs);
-       ptr->num = zr36060_codecs++;
-       ptr->codec = codec;
-
-       //testing
-       res = zr36060_basic_test(ptr);
-       if (res < 0) {
-               zr36060_unset(codec);
-               return res;
-       }
-       //final setup
-       memcpy(ptr->h_samp_ratio, zr36060_decimation_h, 8);
-       memcpy(ptr->v_samp_ratio, zr36060_decimation_v, 8);
-
-       ptr->bitrate_ctrl = 0;  /* 0 or 1 - fixed file size flag
-                                * (what is the difference?) */
-       ptr->mode = CODEC_DO_COMPRESSION;
-       ptr->width = 384;
-       ptr->height = 288;
-       ptr->total_code_vol = 16000;    /* CHECKME */
-       ptr->real_code_vol = (ptr->total_code_vol * 6) >> 3;
-       ptr->max_block_vol = 240;       /* CHECKME, was 120 is 240 */
-       ptr->scalefact = 0x100;
-       ptr->dri = 1;           /* CHECKME, was 8 is 1 */
-
-       /* by default, no COM or APP markers - app should set those */
-       ptr->com.len = 0;
-       ptr->app.appn = 0;
-       ptr->app.len = 0;
-
-       zr36060_init(ptr);
-
-       dprintk(1, KERN_INFO "%s: codec attached and running\n",
-               ptr->name);
-
-       return 0;
-}
-
-static const struct videocodec zr36060_codec = {
-       .owner = THIS_MODULE,
-       .name = "zr36060",
-       .magic = 0L,            // magic not used
-       .flags =
-           CODEC_FLAG_JPEG | CODEC_FLAG_HARDWARE | CODEC_FLAG_ENCODER |
-           CODEC_FLAG_DECODER | CODEC_FLAG_VFE,
-       .type = CODEC_TYPE_ZR36060,
-       .setup = zr36060_setup, // functionality
-       .unset = zr36060_unset,
-       .set_mode = zr36060_set_mode,
-       .set_video = zr36060_set_video,
-       .control = zr36060_control,
-       // others are not used
-};
-
-/* =========================================================================
-   HOOK IN DRIVER AS KERNEL MODULE
-   ========================================================================= */
-
-static int __init
-zr36060_init_module (void)
-{
-       //dprintk(1, "zr36060 driver %s\n",ZR060_VERSION);
-       zr36060_codecs = 0;
-       return videocodec_register(&zr36060_codec);
-}
-
-static void __exit
-zr36060_cleanup_module (void)
-{
-       if (zr36060_codecs) {
-               dprintk(1,
-                       "zr36060: something's wrong - %d codecs left somehow.\n",
-                       zr36060_codecs);
-       }
-
-       /* however, we can't just stay alive */
-       videocodec_unregister(&zr36060_codec);
-}
-
-module_init(zr36060_init_module);
-module_exit(zr36060_cleanup_module);
-
-MODULE_AUTHOR("Laurent Pinchart <laurent.pinchart@skynet.be>");
-MODULE_DESCRIPTION("Driver module for ZR36060 jpeg processors "
-                  ZR060_VERSION);
-MODULE_LICENSE("GPL");
diff --git a/drivers/media/video/zr36060.h b/drivers/media/video/zr36060.h
deleted file mode 100644 (file)
index 914ffa4..0000000
+++ /dev/null
@@ -1,220 +0,0 @@
-/*
- * Zoran ZR36060 basic configuration functions - header file
- *
- * Copyright (C) 2002 Laurent Pinchart <laurent.pinchart@skynet.be>
- *
- * $Id: zr36060.h,v 1.1.1.1.2.3 2003/01/14 21:18:47 rbultje Exp $
- *
- * ------------------------------------------------------------------------
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- *
- * ------------------------------------------------------------------------
- */
-
-#ifndef ZR36060_H
-#define ZR36060_H
-
-#include "videocodec.h"
-
-/* data stored for each zoran jpeg codec chip */
-struct zr36060 {
-       char name[32];
-       int num;
-       /* io datastructure */
-       struct videocodec *codec;
-       // last coder status
-       __u8 status;
-       // actual coder setup
-       int mode;
-
-       __u16 width;
-       __u16 height;
-
-       __u16 bitrate_ctrl;
-
-       __u32 total_code_vol;
-       __u32 real_code_vol;
-       __u16 max_block_vol;
-
-       __u8 h_samp_ratio[8];
-       __u8 v_samp_ratio[8];
-       __u16 scalefact;
-       __u16 dri;
-
-       /* app/com marker data */
-       struct jpeg_app_marker app;
-       struct jpeg_com_marker com;
-};
-
-/* ZR36060 register addresses */
-#define ZR060_LOAD                     0x000
-#define ZR060_CFSR                     0x001
-#define ZR060_CIR                      0x002
-#define ZR060_CMR                      0x003
-#define ZR060_MBZ                      0x004
-#define ZR060_MBCVR                    0x005
-#define ZR060_MER                      0x006
-#define ZR060_IMR                      0x007
-#define ZR060_ISR                      0x008
-#define ZR060_TCV_NET_HI               0x009
-#define ZR060_TCV_NET_MH               0x00a
-#define ZR060_TCV_NET_ML               0x00b
-#define ZR060_TCV_NET_LO               0x00c
-#define ZR060_TCV_DATA_HI              0x00d
-#define ZR060_TCV_DATA_MH              0x00e
-#define ZR060_TCV_DATA_ML              0x00f
-#define ZR060_TCV_DATA_LO              0x010
-#define ZR060_SF_HI                    0x011
-#define ZR060_SF_LO                    0x012
-#define ZR060_AF_HI                    0x013
-#define ZR060_AF_M                     0x014
-#define ZR060_AF_LO                    0x015
-#define ZR060_ACV_HI                   0x016
-#define ZR060_ACV_MH                   0x017
-#define ZR060_ACV_ML                   0x018
-#define ZR060_ACV_LO                   0x019
-#define ZR060_ACT_HI                   0x01a
-#define ZR060_ACT_MH                   0x01b
-#define ZR060_ACT_ML                   0x01c
-#define ZR060_ACT_LO                   0x01d
-#define ZR060_ACV_TRUN_HI              0x01e
-#define ZR060_ACV_TRUN_MH              0x01f
-#define ZR060_ACV_TRUN_ML              0x020
-#define ZR060_ACV_TRUN_LO              0x021
-#define ZR060_IDR_DEV                  0x022
-#define ZR060_IDR_REV                  0x023
-#define ZR060_TCR_HI                   0x024
-#define ZR060_TCR_LO                   0x025
-#define ZR060_VCR                      0x030
-#define ZR060_VPR                      0x031
-#define ZR060_SR                       0x032
-#define ZR060_BCR_Y                    0x033
-#define ZR060_BCR_U                    0x034
-#define ZR060_BCR_V                    0x035
-#define ZR060_SGR_VTOTAL_HI            0x036
-#define ZR060_SGR_VTOTAL_LO            0x037
-#define ZR060_SGR_HTOTAL_HI            0x038
-#define ZR060_SGR_HTOTAL_LO            0x039
-#define ZR060_SGR_VSYNC                        0x03a
-#define ZR060_SGR_HSYNC                        0x03b
-#define ZR060_SGR_BVSTART              0x03c
-#define ZR060_SGR_BHSTART              0x03d
-#define ZR060_SGR_BVEND_HI             0x03e
-#define ZR060_SGR_BVEND_LO             0x03f
-#define ZR060_SGR_BHEND_HI             0x040
-#define ZR060_SGR_BHEND_LO             0x041
-#define ZR060_AAR_VSTART_HI            0x042
-#define ZR060_AAR_VSTART_LO            0x043
-#define ZR060_AAR_VEND_HI              0x044
-#define ZR060_AAR_VEND_LO              0x045
-#define ZR060_AAR_HSTART_HI            0x046
-#define ZR060_AAR_HSTART_LO            0x047
-#define ZR060_AAR_HEND_HI              0x048
-#define ZR060_AAR_HEND_LO              0x049
-#define ZR060_SWR_VSTART_HI            0x04a
-#define ZR060_SWR_VSTART_LO            0x04b
-#define ZR060_SWR_VEND_HI              0x04c
-#define ZR060_SWR_VEND_LO              0x04d
-#define ZR060_SWR_HSTART_HI            0x04e
-#define ZR060_SWR_HSTART_LO            0x04f
-#define ZR060_SWR_HEND_HI              0x050
-#define ZR060_SWR_HEND_LO              0x051
-
-#define ZR060_SOF_IDX                  0x060
-#define ZR060_SOS_IDX                  0x07a
-#define ZR060_DRI_IDX                  0x0c0
-#define ZR060_DQT_IDX                  0x0cc
-#define ZR060_DHT_IDX                  0x1d4
-#define ZR060_APP_IDX                  0x380
-#define ZR060_COM_IDX                  0x3c0
-
-/* ZR36060 LOAD register bits */
-
-#define ZR060_LOAD_Load                        (1 << 7)
-#define ZR060_LOAD_SyncRst             (1 << 0)
-
-/* ZR36060 Code FIFO Status register bits */
-
-#define ZR060_CFSR_Busy                        (1 << 7)
-#define ZR060_CFSR_CBusy               (1 << 2)
-#define ZR060_CFSR_CFIFO               (3 << 0)
-
-/* ZR36060 Code Interface register */
-
-#define ZR060_CIR_Code16               (1 << 7)
-#define ZR060_CIR_Endian               (1 << 6)
-#define ZR060_CIR_CFIS                 (1 << 2)
-#define ZR060_CIR_CodeMstr             (1 << 0)
-
-/* ZR36060 Codec Mode register */
-
-#define ZR060_CMR_Comp                 (1 << 7)
-#define ZR060_CMR_ATP                  (1 << 6)
-#define ZR060_CMR_Pass2                        (1 << 5)
-#define ZR060_CMR_TLM                  (1 << 4)
-#define ZR060_CMR_BRB                  (1 << 2)
-#define ZR060_CMR_FSF                  (1 << 1)
-
-/* ZR36060 Markers Enable register */
-
-#define ZR060_MER_App                  (1 << 7)
-#define ZR060_MER_Com                  (1 << 6)
-#define ZR060_MER_DRI                  (1 << 5)
-#define ZR060_MER_DQT                  (1 << 4)
-#define ZR060_MER_DHT                  (1 << 3)
-
-/* ZR36060 Interrupt Mask register */
-
-#define ZR060_IMR_EOAV                 (1 << 3)
-#define ZR060_IMR_EOI                  (1 << 2)
-#define ZR060_IMR_End                  (1 << 1)
-#define ZR060_IMR_DataErr              (1 << 0)
-
-/* ZR36060 Interrupt Status register */
-
-#define ZR060_ISR_ProCnt               (3 << 6)
-#define ZR060_ISR_EOAV                 (1 << 3)
-#define ZR060_ISR_EOI                  (1 << 2)
-#define ZR060_ISR_End                  (1 << 1)
-#define ZR060_ISR_DataErr              (1 << 0)
-
-/* ZR36060 Video Control register */
-
-#define ZR060_VCR_Video8               (1 << 7)
-#define ZR060_VCR_Range                        (1 << 6)
-#define ZR060_VCR_FIDet                        (1 << 3)
-#define ZR060_VCR_FIVedge              (1 << 2)
-#define ZR060_VCR_FIExt                        (1 << 1)
-#define ZR060_VCR_SyncMstr             (1 << 0)
-
-/* ZR36060 Video Polarity register */
-
-#define ZR060_VPR_VCLKPol              (1 << 7)
-#define ZR060_VPR_PValPol              (1 << 6)
-#define ZR060_VPR_PoePol               (1 << 5)
-#define ZR060_VPR_SImgPol              (1 << 4)
-#define ZR060_VPR_BLPol                        (1 << 3)
-#define ZR060_VPR_FIPol                        (1 << 2)
-#define ZR060_VPR_HSPol                        (1 << 1)
-#define ZR060_VPR_VSPol                        (1 << 0)
-
-/* ZR36060 Scaling register */
-
-#define ZR060_SR_VScale                        (1 << 2)
-#define ZR060_SR_HScale2               (1 << 0)
-#define ZR060_SR_HScale4               (2 << 0)
-
-#endif                         /*fndef ZR36060_H */
index 18d1c4ba79fbf7c8384ba8497320d180ad226b44..7cdac99deea69fe909b0a03e5be6e25459e54b12 100644 (file)
@@ -52,7 +52,7 @@
 
 
 /* Debug macro */
-#define DBG(x...) if (debug) info(x)
+#define DBG(x...) if (debug) printk(KERN_INFO KBUILD_MODNAME x)
 
 
 /* Init methods, need to find nicer names for these
@@ -116,6 +116,7 @@ struct zr364xx_camera {
        int height;
        int method;
        struct mutex lock;
+       int users;
 };
 
 
@@ -127,7 +128,7 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
 
        unsigned char *transfer_buffer = kmalloc(size, GFP_KERNEL);
        if (!transfer_buffer) {
-               info("kmalloc(%d) failed", size);
+               dev_err(&udev->dev, "kmalloc(%d) failed\n", size);
                return -ENOMEM;
        }
 
@@ -143,7 +144,8 @@ static int send_control_msg(struct usb_device *udev, u8 request, u16 value,
        kfree(transfer_buffer);
 
        if (status < 0)
-               info("Failed sending control message, error %d.", status);
+               dev_err(&udev->dev,
+                       "Failed sending control message, error %d.\n", status);
 
        return status;
 }
@@ -303,11 +305,11 @@ static int read_frame(struct zr364xx_camera *cam, int framenum)
                DBG("buffer : %d %d", cam->buffer[0], cam->buffer[1]);
                DBG("bulk : n=%d size=%d", n, actual_length);
                if (n < 0) {
-                       info("error reading bulk msg");
+                       dev_err(&cam->udev->dev, "error reading bulk msg\n");
                        return 0;
                }
                if (actual_length < 0 || actual_length > BUFFER_SIZE) {
-                       info("wrong number of bytes");
+                       dev_err(&cam->udev->dev, "wrong number of bytes\n");
                        return 0;
                }
 
@@ -641,42 +643,47 @@ static int zr364xx_open(struct inode *inode, struct file *file)
 
        DBG("zr364xx_open");
 
-       cam->skip = 2;
+       mutex_lock(&cam->lock);
 
-       err = video_exclusive_open(inode, file);
-       if (err < 0)
-               return err;
+       if (cam->users) {
+               err = -EBUSY;
+               goto out;
+       }
 
        if (!cam->framebuf) {
                cam->framebuf = vmalloc_32(MAX_FRAME_SIZE * FRAMES);
                if (!cam->framebuf) {
-                       info("vmalloc_32 failed!");
-                       return -ENOMEM;
+                       dev_err(&cam->udev->dev, "vmalloc_32 failed!\n");
+                       err = -ENOMEM;
+                       goto out;
                }
        }
 
-       mutex_lock(&cam->lock);
        for (i = 0; init[cam->method][i].size != -1; i++) {
                err =
                    send_control_msg(udev, 1, init[cam->method][i].value,
                                     0, init[cam->method][i].bytes,
                                     init[cam->method][i].size);
                if (err < 0) {
-                       info("error during open sequence: %d", i);
-                       mutex_unlock(&cam->lock);
-                       return err;
+                       dev_err(&cam->udev->dev,
+                               "error during open sequence: %d\n", i);
+                       goto out;
                }
        }
 
+       cam->skip = 2;
+       cam->users++;
        file->private_data = vdev;
 
        /* Added some delay here, since opening/closing the camera quickly,
         * like Ekiga does during its startup, can crash the webcam
         */
        mdelay(100);
+       err = 0;
 
+out:
        mutex_unlock(&cam->lock);
-       return 0;
+       return err;
 }
 
 
@@ -697,28 +704,30 @@ static int zr364xx_release(struct inode *inode, struct file *file)
        udev = cam->udev;
 
        mutex_lock(&cam->lock);
+
+       cam->users--;
+       file->private_data = NULL;
+
        for (i = 0; i < 2; i++) {
                err =
                    send_control_msg(udev, 1, init[cam->method][i].value,
                                     0, init[i][cam->method].bytes,
                                     init[cam->method][i].size);
                if (err < 0) {
-                       info("error during release sequence");
-                       mutex_unlock(&cam->lock);
-                       return err;
+                       dev_err(&udev->dev, "error during release sequence\n");
+                       goto out;
                }
        }
 
-       file->private_data = NULL;
-       video_exclusive_release(inode, file);
-
        /* Added some delay here, since opening/closing the camera quickly,
         * like Ekiga does during its startup, can crash the webcam
         */
        mdelay(100);
+       err = 0;
 
+out:
        mutex_unlock(&cam->lock);
-       return 0;
+       return err;
 }
 
 
@@ -801,13 +810,14 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        DBG("probing...");
 
-       info(DRIVER_DESC " compatible webcam plugged");
-       info("model %04x:%04x detected", udev->descriptor.idVendor,
-            udev->descriptor.idProduct);
+       dev_info(&intf->dev, DRIVER_DESC " compatible webcam plugged\n");
+       dev_info(&intf->dev, "model %04x:%04x detected\n",
+                le16_to_cpu(udev->descriptor.idVendor),
+                le16_to_cpu(udev->descriptor.idProduct));
 
        cam = kzalloc(sizeof(struct zr364xx_camera), GFP_KERNEL);
        if (cam == NULL) {
-               info("cam: out of memory !");
+               dev_err(&udev->dev, "cam: out of memory !\n");
                return -ENOMEM;
        }
        /* save the init method used by this camera */
@@ -815,7 +825,7 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        cam->vdev = video_device_alloc();
        if (cam->vdev == NULL) {
-               info("cam->vdev: out of memory !");
+               dev_err(&udev->dev, "cam->vdev: out of memory !\n");
                kfree(cam);
                return -ENOMEM;
        }
@@ -827,7 +837,7 @@ static int zr364xx_probe(struct usb_interface *intf,
        cam->udev = udev;
 
        if ((cam->buffer = kmalloc(BUFFER_SIZE, GFP_KERNEL)) == NULL) {
-               info("cam->buffer: out of memory !");
+               dev_info(&udev->dev, "cam->buffer: out of memory !\n");
                video_device_release(cam->vdev);
                kfree(cam);
                return -ENODEV;
@@ -835,17 +845,17 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        switch (mode) {
        case 1:
-               info("160x120 mode selected");
+               dev_info(&udev->dev, "160x120 mode selected\n");
                cam->width = 160;
                cam->height = 120;
                break;
        case 2:
-               info("640x480 mode selected");
+               dev_info(&udev->dev, "640x480 mode selected\n");
                cam->width = 640;
                cam->height = 480;
                break;
        default:
-               info("320x240 mode selected");
+               dev_info(&udev->dev, "320x240 mode selected\n");
                cam->width = 320;
                cam->height = 240;
                break;
@@ -865,7 +875,7 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        err = video_register_device(cam->vdev, VFL_TYPE_GRABBER, -1);
        if (err) {
-               info("video_register_device failed");
+               dev_err(&udev->dev, "video_register_device failed\n");
                video_device_release(cam->vdev);
                kfree(cam->buffer);
                kfree(cam);
@@ -874,7 +884,8 @@ static int zr364xx_probe(struct usb_interface *intf,
 
        usb_set_intfdata(intf, cam);
 
-       info(DRIVER_DESC " controlling video device %d", cam->vdev->minor);
+       dev_info(&udev->dev, DRIVER_DESC " controlling video device %d\n",
+                cam->vdev->minor);
        return 0;
 }
 
@@ -884,7 +895,7 @@ static void zr364xx_disconnect(struct usb_interface *intf)
        struct zr364xx_camera *cam = usb_get_intfdata(intf);
        usb_set_intfdata(intf, NULL);
        dev_set_drvdata(&intf->dev, NULL);
-       info(DRIVER_DESC " webcam unplugged");
+       dev_info(&intf->dev, DRIVER_DESC " webcam unplugged\n");
        if (cam->vdev)
                video_unregister_device(cam->vdev);
        cam->vdev = NULL;
@@ -913,16 +924,16 @@ static int __init zr364xx_init(void)
        int retval;
        retval = usb_register(&zr364xx_driver);
        if (retval)
-               info("usb_register failed!");
+               printk(KERN_ERR KBUILD_MODNAME ": usb_register failed!\n");
        else
-               info(DRIVER_DESC " module loaded");
+               printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n");
        return retval;
 }
 
 
 static void __exit zr364xx_exit(void)
 {
-       info(DRIVER_DESC " module unloaded");
+       printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC " module unloaded\n");
        usb_deregister(&zr364xx_driver);
 }
 
index 0dae245c625953fa2194f643d580db06f00a3aac..5eff8ad834d6f6bae7da3e97a89a3a6c87a336fa 100644 (file)
@@ -87,6 +87,44 @@ config MFD_TC6393XB
        help
          Support for Toshiba Mobile IO Controller TC6393XB
 
+config MFD_WM8400
+       tristate "Support Wolfson Microelectronics WM8400"
+       help
+         Support for the Wolfson Microelecronics WM8400 PMIC and audio
+         CODEC.  This driver adds provides common support for accessing
+         the device, additional drivers must be enabled in order to use
+         the functionality of the device.
+
+config MFD_WM8350
+       tristate
+
+config MFD_WM8350_CONFIG_MODE_0
+       bool
+       depends on MFD_WM8350
+
+config MFD_WM8350_CONFIG_MODE_1
+       bool
+       depends on MFD_WM8350
+
+config MFD_WM8350_CONFIG_MODE_2
+       bool
+       depends on MFD_WM8350
+
+config MFD_WM8350_CONFIG_MODE_3
+       bool
+       depends on MFD_WM8350
+
+config MFD_WM8350_I2C
+       tristate "Support Wolfson Microelectronics WM8350 with I2C"
+       select MFD_WM8350
+       depends on I2C
+       help
+         The WM8350 is an integrated audio and power management
+         subsystem with watchdog and RTC functionality for embedded
+         systems.  This option enables core support for the WM8350 with
+         I2C as the control interface.  Additional options must be
+         selected to enable support for the functionality of the chip.
+
 endmenu
 
 menu "Multimedia Capabilities Port drivers"
index 6abebe364419ed9668f0e08ea68abf0c362a7733..759b1fe1c891a44bac2c5486ea51da90d1de0985 100644 (file)
@@ -12,6 +12,11 @@ obj-$(CONFIG_MFD_T7L66XB)    += t7l66xb.o
 obj-$(CONFIG_MFD_TC6387XB)     += tc6387xb.o
 obj-$(CONFIG_MFD_TC6393XB)     += tc6393xb.o
 
+obj-$(CONFIG_MFD_WM8400)       += wm8400-core.o
+wm8350-objs                    := wm8350-core.o wm8350-regmap.o wm8350-gpio.o
+obj-$(CONFIG_MFD_WM8350)       += wm8350.o
+obj-$(CONFIG_MFD_WM8350_I2C)   += wm8350-i2c.o
+
 obj-$(CONFIG_MFD_CORE)         += mfd-core.o
 
 obj-$(CONFIG_MCP)              += mcp-core.o
diff --git a/drivers/mfd/wm8350-core.c b/drivers/mfd/wm8350-core.c
new file mode 100644 (file)
index 0000000..25a7a5d
--- /dev/null
@@ -0,0 +1,1273 @@
+/*
+ * wm8350-core.c  --  Device access for Wolfson WM8350
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood, Mark Brown
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/init.h>
+#include <linux/bug.h>
+#include <linux/device.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/wm8350/core.h>
+#include <linux/mfd/wm8350/audio.h>
+#include <linux/mfd/wm8350/comparator.h>
+#include <linux/mfd/wm8350/gpio.h>
+#include <linux/mfd/wm8350/pmic.h>
+#include <linux/mfd/wm8350/rtc.h>
+#include <linux/mfd/wm8350/supply.h>
+#include <linux/mfd/wm8350/wdt.h>
+
+#define WM8350_UNLOCK_KEY              0x0013
+#define WM8350_LOCK_KEY                        0x0000
+
+#define WM8350_CLOCK_CONTROL_1         0x28
+#define WM8350_AIF_TEST                        0x74
+
+/* debug */
+#define WM8350_BUS_DEBUG 0
+#if WM8350_BUS_DEBUG
+#define dump(regs, src) do { \
+       int i_; \
+       u16 *src_ = src; \
+       printk(KERN_DEBUG); \
+       for (i_ = 0; i_ < regs; i_++) \
+               printk(" 0x%4.4x", *src_++); \
+       printk("\n"); \
+} while (0);
+#else
+#define dump(bytes, src)
+#endif
+
+#define WM8350_LOCK_DEBUG 0
+#if WM8350_LOCK_DEBUG
+#define ldbg(format, arg...) printk(format, ## arg)
+#else
+#define ldbg(format, arg...)
+#endif
+
+/*
+ * WM8350 Device IO
+ */
+static DEFINE_MUTEX(io_mutex);
+static DEFINE_MUTEX(reg_lock_mutex);
+static DEFINE_MUTEX(auxadc_mutex);
+
+/* Perform a physical read from the device.
+ */
+static int wm8350_phys_read(struct wm8350 *wm8350, u8 reg, int num_regs,
+                           u16 *dest)
+{
+       int i, ret;
+       int bytes = num_regs * 2;
+
+       dev_dbg(wm8350->dev, "volatile read\n");
+       ret = wm8350->read_dev(wm8350, reg, bytes, (char *)dest);
+
+       for (i = reg; i < reg + num_regs; i++) {
+               /* Cache is CPU endian */
+               dest[i - reg] = be16_to_cpu(dest[i - reg]);
+
+               /* Satisfy non-volatile bits from cache */
+               dest[i - reg] &= wm8350_reg_io_map[i].vol;
+               dest[i - reg] |= wm8350->reg_cache[i];
+
+               /* Mask out non-readable bits */
+               dest[i - reg] &= wm8350_reg_io_map[i].readable;
+       }
+
+       dump(num_regs, dest);
+
+       return ret;
+}
+
+static int wm8350_read(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *dest)
+{
+       int i;
+       int end = reg + num_regs;
+       int ret = 0;
+       int bytes = num_regs * 2;
+
+       if (wm8350->read_dev == NULL)
+               return -ENODEV;
+
+       if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) {
+               dev_err(wm8350->dev, "invalid reg %x\n",
+                       reg + num_regs - 1);
+               return -EINVAL;
+       }
+
+       dev_dbg(wm8350->dev,
+               "%s R%d(0x%2.2x) %d regs\n", __func__, reg, reg, num_regs);
+
+#if WM8350_BUS_DEBUG
+       /* we can _safely_ read any register, but warn if read not supported */
+       for (i = reg; i < end; i++) {
+               if (!wm8350_reg_io_map[i].readable)
+                       dev_warn(wm8350->dev,
+                               "reg R%d is not readable\n", i);
+       }
+#endif
+
+       /* if any volatile registers are required, then read back all */
+       for (i = reg; i < end; i++)
+               if (wm8350_reg_io_map[i].vol)
+                       return wm8350_phys_read(wm8350, reg, num_regs, dest);
+
+       /* no volatiles, then cache is good */
+       dev_dbg(wm8350->dev, "cache read\n");
+       memcpy(dest, &wm8350->reg_cache[reg], bytes);
+       dump(num_regs, dest);
+       return ret;
+}
+
+static inline int is_reg_locked(struct wm8350 *wm8350, u8 reg)
+{
+       if (reg == WM8350_SECURITY ||
+           wm8350->reg_cache[WM8350_SECURITY] == WM8350_UNLOCK_KEY)
+               return 0;
+
+       if ((reg == WM8350_GPIO_CONFIGURATION_I_O) ||
+           (reg >= WM8350_GPIO_FUNCTION_SELECT_1 &&
+            reg <= WM8350_GPIO_FUNCTION_SELECT_4) ||
+           (reg >= WM8350_BATTERY_CHARGER_CONTROL_1 &&
+            reg <= WM8350_BATTERY_CHARGER_CONTROL_3))
+               return 1;
+       return 0;
+}
+
+static int wm8350_write(struct wm8350 *wm8350, u8 reg, int num_regs, u16 *src)
+{
+       int i;
+       int end = reg + num_regs;
+       int bytes = num_regs * 2;
+
+       if (wm8350->write_dev == NULL)
+               return -ENODEV;
+
+       if ((reg + num_regs - 1) > WM8350_MAX_REGISTER) {
+               dev_err(wm8350->dev, "invalid reg %x\n",
+                       reg + num_regs - 1);
+               return -EINVAL;
+       }
+
+       /* it's generally not a good idea to write to RO or locked registers */
+       for (i = reg; i < end; i++) {
+               if (!wm8350_reg_io_map[i].writable) {
+                       dev_err(wm8350->dev,
+                               "attempted write to read only reg R%d\n", i);
+                       return -EINVAL;
+               }
+
+               if (is_reg_locked(wm8350, i)) {
+                       dev_err(wm8350->dev,
+                              "attempted write to locked reg R%d\n", i);
+                       return -EINVAL;
+               }
+
+               src[i - reg] &= wm8350_reg_io_map[i].writable;
+
+               wm8350->reg_cache[i] =
+                       (wm8350->reg_cache[i] & ~wm8350_reg_io_map[i].writable)
+                       | src[i - reg];
+
+               src[i - reg] = cpu_to_be16(src[i - reg]);
+       }
+
+       /* Actually write it out */
+       return wm8350->write_dev(wm8350, reg, bytes, (char *)src);
+}
+
+/*
+ * Safe read, modify, write methods
+ */
+int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask)
+{
+       u16 data;
+       int err;
+
+       mutex_lock(&io_mutex);
+       err = wm8350_read(wm8350, reg, 1, &data);
+       if (err) {
+               dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
+               goto out;
+       }
+
+       data &= ~mask;
+       err = wm8350_write(wm8350, reg, 1, &data);
+       if (err)
+               dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
+out:
+       mutex_unlock(&io_mutex);
+       return err;
+}
+EXPORT_SYMBOL_GPL(wm8350_clear_bits);
+
+int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask)
+{
+       u16 data;
+       int err;
+
+       mutex_lock(&io_mutex);
+       err = wm8350_read(wm8350, reg, 1, &data);
+       if (err) {
+               dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
+               goto out;
+       }
+
+       data |= mask;
+       err = wm8350_write(wm8350, reg, 1, &data);
+       if (err)
+               dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
+out:
+       mutex_unlock(&io_mutex);
+       return err;
+}
+EXPORT_SYMBOL_GPL(wm8350_set_bits);
+
+u16 wm8350_reg_read(struct wm8350 *wm8350, int reg)
+{
+       u16 data;
+       int err;
+
+       mutex_lock(&io_mutex);
+       err = wm8350_read(wm8350, reg, 1, &data);
+       if (err)
+               dev_err(wm8350->dev, "read from reg R%d failed\n", reg);
+
+       mutex_unlock(&io_mutex);
+       return data;
+}
+EXPORT_SYMBOL_GPL(wm8350_reg_read);
+
+int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val)
+{
+       int ret;
+       u16 data = val;
+
+       mutex_lock(&io_mutex);
+       ret = wm8350_write(wm8350, reg, 1, &data);
+       if (ret)
+               dev_err(wm8350->dev, "write to reg R%d failed\n", reg);
+       mutex_unlock(&io_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_reg_write);
+
+int wm8350_block_read(struct wm8350 *wm8350, int start_reg, int regs,
+                     u16 *dest)
+{
+       int err = 0;
+
+       mutex_lock(&io_mutex);
+       err = wm8350_read(wm8350, start_reg, regs, dest);
+       if (err)
+               dev_err(wm8350->dev, "block read starting from R%d failed\n",
+                       start_reg);
+       mutex_unlock(&io_mutex);
+       return err;
+}
+EXPORT_SYMBOL_GPL(wm8350_block_read);
+
+int wm8350_block_write(struct wm8350 *wm8350, int start_reg, int regs,
+                      u16 *src)
+{
+       int ret = 0;
+
+       mutex_lock(&io_mutex);
+       ret = wm8350_write(wm8350, start_reg, regs, src);
+       if (ret)
+               dev_err(wm8350->dev, "block write starting at R%d failed\n",
+                       start_reg);
+       mutex_unlock(&io_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_block_write);
+
+int wm8350_reg_lock(struct wm8350 *wm8350)
+{
+       u16 key = WM8350_LOCK_KEY;
+       int ret;
+
+       ldbg(__func__);
+       mutex_lock(&io_mutex);
+       ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
+       if (ret)
+               dev_err(wm8350->dev, "lock failed\n");
+       mutex_unlock(&io_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_reg_lock);
+
+int wm8350_reg_unlock(struct wm8350 *wm8350)
+{
+       u16 key = WM8350_UNLOCK_KEY;
+       int ret;
+
+       ldbg(__func__);
+       mutex_lock(&io_mutex);
+       ret = wm8350_write(wm8350, WM8350_SECURITY, 1, &key);
+       if (ret)
+               dev_err(wm8350->dev, "unlock failed\n");
+       mutex_unlock(&io_mutex);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_reg_unlock);
+
+static void wm8350_irq_call_handler(struct wm8350 *wm8350, int irq)
+{
+       mutex_lock(&wm8350->irq_mutex);
+
+       if (wm8350->irq[irq].handler)
+               wm8350->irq[irq].handler(wm8350, irq, wm8350->irq[irq].data);
+       else {
+               dev_err(wm8350->dev, "irq %d nobody cared. now masked.\n",
+                       irq);
+               wm8350_mask_irq(wm8350, irq);
+       }
+
+       mutex_unlock(&wm8350->irq_mutex);
+}
+
+/*
+ * wm8350_irq_worker actually handles the interrupts.  Since all
+ * interrupts are clear on read the IRQ line will be reasserted and
+ * the physical IRQ will be handled again if another interrupt is
+ * asserted while we run - in the normal course of events this is a
+ * rare occurrence so we save I2C/SPI reads.
+ */
+static void wm8350_irq_worker(struct work_struct *work)
+{
+       struct wm8350 *wm8350 = container_of(work, struct wm8350, irq_work);
+       u16 level_one, status1, status2, comp;
+
+       /* TODO: Use block reads to improve performance? */
+       level_one = wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS)
+               & ~wm8350_reg_read(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK);
+       status1 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_1)
+               & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_1_MASK);
+       status2 = wm8350_reg_read(wm8350, WM8350_INT_STATUS_2)
+               & ~wm8350_reg_read(wm8350, WM8350_INT_STATUS_2_MASK);
+       comp = wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS)
+               & ~wm8350_reg_read(wm8350, WM8350_COMPARATOR_INT_STATUS_MASK);
+
+       /* over current */
+       if (level_one & WM8350_OC_INT) {
+               u16 oc;
+
+               oc = wm8350_reg_read(wm8350, WM8350_OVER_CURRENT_INT_STATUS);
+               oc &= ~wm8350_reg_read(wm8350,
+                                      WM8350_OVER_CURRENT_INT_STATUS_MASK);
+
+               if (oc & WM8350_OC_LS_EINT)     /* limit switch */
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_OC_LS);
+       }
+
+       /* under voltage */
+       if (level_one & WM8350_UV_INT) {
+               u16 uv;
+
+               uv = wm8350_reg_read(wm8350, WM8350_UNDER_VOLTAGE_INT_STATUS);
+               uv &= ~wm8350_reg_read(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK);
+
+               if (uv & WM8350_UV_DC1_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC1);
+               if (uv & WM8350_UV_DC2_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC2);
+               if (uv & WM8350_UV_DC3_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC3);
+               if (uv & WM8350_UV_DC4_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC4);
+               if (uv & WM8350_UV_DC5_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC5);
+               if (uv & WM8350_UV_DC6_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_DC6);
+               if (uv & WM8350_UV_LDO1_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO1);
+               if (uv & WM8350_UV_LDO2_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO2);
+               if (uv & WM8350_UV_LDO3_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO3);
+               if (uv & WM8350_UV_LDO4_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_UV_LDO4);
+       }
+
+       /* charger, RTC */
+       if (status1) {
+               if (status1 & WM8350_CHG_BAT_HOT_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_BAT_HOT);
+               if (status1 & WM8350_CHG_BAT_COLD_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_BAT_COLD);
+               if (status1 & WM8350_CHG_BAT_FAIL_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_BAT_FAIL);
+               if (status1 & WM8350_CHG_TO_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_TO);
+               if (status1 & WM8350_CHG_END_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_END);
+               if (status1 & WM8350_CHG_START_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CHG_START);
+               if (status1 & WM8350_CHG_FAST_RDY_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_FAST_RDY);
+               if (status1 & WM8350_CHG_VBATT_LT_3P9_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_VBATT_LT_3P9);
+               if (status1 & WM8350_CHG_VBATT_LT_3P1_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_VBATT_LT_3P1);
+               if (status1 & WM8350_CHG_VBATT_LT_2P85_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CHG_VBATT_LT_2P85);
+               if (status1 & WM8350_RTC_ALM_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_ALM);
+               if (status1 & WM8350_RTC_SEC_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_SEC);
+               if (status1 & WM8350_RTC_PER_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_RTC_PER);
+       }
+
+       /* current sink, system, aux adc */
+       if (status2) {
+               if (status2 & WM8350_CS1_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS1);
+               if (status2 & WM8350_CS2_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CS2);
+
+               if (status2 & WM8350_SYS_HYST_COMP_FAIL_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_SYS_HYST_COMP_FAIL);
+               if (status2 & WM8350_SYS_CHIP_GT115_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_SYS_CHIP_GT115);
+               if (status2 & WM8350_SYS_CHIP_GT140_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_SYS_CHIP_GT140);
+               if (status2 & WM8350_SYS_WDOG_TO_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_SYS_WDOG_TO);
+
+               if (status2 & WM8350_AUXADC_DATARDY_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_AUXADC_DATARDY);
+               if (status2 & WM8350_AUXADC_DCOMP4_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_AUXADC_DCOMP4);
+               if (status2 & WM8350_AUXADC_DCOMP3_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_AUXADC_DCOMP3);
+               if (status2 & WM8350_AUXADC_DCOMP2_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_AUXADC_DCOMP2);
+               if (status2 & WM8350_AUXADC_DCOMP1_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_AUXADC_DCOMP1);
+
+               if (status2 & WM8350_USB_LIMIT_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_USB_LIMIT);
+       }
+
+       /* wake, codec, ext */
+       if (comp) {
+               if (comp & WM8350_WKUP_OFF_STATE_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_OFF_STATE);
+               if (comp & WM8350_WKUP_HIB_STATE_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_HIB_STATE);
+               if (comp & WM8350_WKUP_CONV_FAULT_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_CONV_FAULT);
+               if (comp & WM8350_WKUP_WDOG_RST_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_WDOG_RST);
+               if (comp & WM8350_WKUP_GP_PWR_ON_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_GP_PWR_ON);
+               if (comp & WM8350_WKUP_ONKEY_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_WKUP_ONKEY);
+               if (comp & WM8350_WKUP_GP_WAKEUP_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_WKUP_GP_WAKEUP);
+
+               if (comp & WM8350_CODEC_JCK_DET_L_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CODEC_JCK_DET_L);
+               if (comp & WM8350_CODEC_JCK_DET_R_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CODEC_JCK_DET_R);
+               if (comp & WM8350_CODEC_MICSCD_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_CODEC_MICSCD);
+               if (comp & WM8350_CODEC_MICD_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_CODEC_MICD);
+
+               if (comp & WM8350_EXT_USB_FB_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_USB_FB);
+               if (comp & WM8350_EXT_WALL_FB_EINT)
+                       wm8350_irq_call_handler(wm8350,
+                                               WM8350_IRQ_EXT_WALL_FB);
+               if (comp & WM8350_EXT_BAT_FB_EINT)
+                       wm8350_irq_call_handler(wm8350, WM8350_IRQ_EXT_BAT_FB);
+       }
+
+       if (level_one & WM8350_GP_INT) {
+               int i;
+               u16 gpio;
+
+               gpio = wm8350_reg_read(wm8350, WM8350_GPIO_INT_STATUS);
+               gpio &= ~wm8350_reg_read(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK);
+
+               for (i = 0; i < 12; i++) {
+                       if (gpio & (1 << i))
+                               wm8350_irq_call_handler(wm8350,
+                                                       WM8350_IRQ_GPIO(i));
+               }
+       }
+
+       enable_irq(wm8350->chip_irq);
+}
+
+static irqreturn_t wm8350_irq(int irq, void *data)
+{
+       struct wm8350 *wm8350 = data;
+
+       disable_irq_nosync(irq);
+       schedule_work(&wm8350->irq_work);
+
+       return IRQ_HANDLED;
+}
+
+int wm8350_register_irq(struct wm8350 *wm8350, int irq,
+                       void (*handler) (struct wm8350 *, int, void *),
+                       void *data)
+{
+       if (irq < 0 || irq > WM8350_NUM_IRQ || !handler)
+               return -EINVAL;
+
+       if (wm8350->irq[irq].handler)
+               return -EBUSY;
+
+       mutex_lock(&wm8350->irq_mutex);
+       wm8350->irq[irq].handler = handler;
+       wm8350->irq[irq].data = data;
+       mutex_unlock(&wm8350->irq_mutex);
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_register_irq);
+
+int wm8350_free_irq(struct wm8350 *wm8350, int irq)
+{
+       if (irq < 0 || irq > WM8350_NUM_IRQ)
+               return -EINVAL;
+
+       mutex_lock(&wm8350->irq_mutex);
+       wm8350->irq[irq].handler = NULL;
+       mutex_unlock(&wm8350->irq_mutex);
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_free_irq);
+
+int wm8350_mask_irq(struct wm8350 *wm8350, int irq)
+{
+       switch (irq) {
+       case WM8350_IRQ_CHG_BAT_HOT:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_BAT_HOT_EINT);
+       case WM8350_IRQ_CHG_BAT_COLD:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_BAT_COLD_EINT);
+       case WM8350_IRQ_CHG_BAT_FAIL:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_BAT_FAIL_EINT);
+       case WM8350_IRQ_CHG_TO:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_TO_EINT);
+       case WM8350_IRQ_CHG_END:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_END_EINT);
+       case WM8350_IRQ_CHG_START:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_START_EINT);
+       case WM8350_IRQ_CHG_FAST_RDY:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_FAST_RDY_EINT);
+       case WM8350_IRQ_RTC_PER:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_RTC_PER_EINT);
+       case WM8350_IRQ_RTC_SEC:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_RTC_SEC_EINT);
+       case WM8350_IRQ_RTC_ALM:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_RTC_ALM_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_3P9:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_VBATT_LT_3P9_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_3P1:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_VBATT_LT_3P1_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_2P85:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                      WM8350_IM_CHG_VBATT_LT_2P85_EINT);
+       case WM8350_IRQ_CS1:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_CS1_EINT);
+       case WM8350_IRQ_CS2:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_CS2_EINT);
+       case WM8350_IRQ_USB_LIMIT:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_USB_LIMIT_EINT);
+       case WM8350_IRQ_AUXADC_DATARDY:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_AUXADC_DATARDY_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP4:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_AUXADC_DCOMP4_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP3:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_AUXADC_DCOMP3_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP2:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_AUXADC_DCOMP2_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP1:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_AUXADC_DCOMP1_EINT);
+       case WM8350_IRQ_SYS_HYST_COMP_FAIL:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_SYS_HYST_COMP_FAIL_EINT);
+       case WM8350_IRQ_SYS_CHIP_GT115:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_SYS_CHIP_GT115_EINT);
+       case WM8350_IRQ_SYS_CHIP_GT140:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_SYS_CHIP_GT140_EINT);
+       case WM8350_IRQ_SYS_WDOG_TO:
+               return wm8350_set_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                      WM8350_IM_SYS_WDOG_TO_EINT);
+       case WM8350_IRQ_UV_LDO4:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_LDO4_EINT);
+       case WM8350_IRQ_UV_LDO3:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_LDO3_EINT);
+       case WM8350_IRQ_UV_LDO2:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_LDO2_EINT);
+       case WM8350_IRQ_UV_LDO1:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_LDO1_EINT);
+       case WM8350_IRQ_UV_DC6:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC6_EINT);
+       case WM8350_IRQ_UV_DC5:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC5_EINT);
+       case WM8350_IRQ_UV_DC4:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC4_EINT);
+       case WM8350_IRQ_UV_DC3:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC3_EINT);
+       case WM8350_IRQ_UV_DC2:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC2_EINT);
+       case WM8350_IRQ_UV_DC1:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                      WM8350_IM_UV_DC1_EINT);
+       case WM8350_IRQ_OC_LS:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_OVER_CURRENT_INT_STATUS_MASK,
+                                      WM8350_IM_OC_LS_EINT);
+       case WM8350_IRQ_EXT_USB_FB:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_EXT_USB_FB_EINT);
+       case WM8350_IRQ_EXT_WALL_FB:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_EXT_WALL_FB_EINT);
+       case WM8350_IRQ_EXT_BAT_FB:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_EXT_BAT_FB_EINT);
+       case WM8350_IRQ_CODEC_JCK_DET_L:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_CODEC_JCK_DET_L_EINT);
+       case WM8350_IRQ_CODEC_JCK_DET_R:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_CODEC_JCK_DET_R_EINT);
+       case WM8350_IRQ_CODEC_MICSCD:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_CODEC_MICSCD_EINT);
+       case WM8350_IRQ_CODEC_MICD:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_CODEC_MICD_EINT);
+       case WM8350_IRQ_WKUP_OFF_STATE:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_OFF_STATE_EINT);
+       case WM8350_IRQ_WKUP_HIB_STATE:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_HIB_STATE_EINT);
+       case WM8350_IRQ_WKUP_CONV_FAULT:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_CONV_FAULT_EINT);
+       case WM8350_IRQ_WKUP_WDOG_RST:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_OFF_STATE_EINT);
+       case WM8350_IRQ_WKUP_GP_PWR_ON:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_GP_PWR_ON_EINT);
+       case WM8350_IRQ_WKUP_ONKEY:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_ONKEY_EINT);
+       case WM8350_IRQ_WKUP_GP_WAKEUP:
+               return wm8350_set_bits(wm8350,
+                                      WM8350_COMPARATOR_INT_STATUS_MASK,
+                                      WM8350_IM_WKUP_GP_WAKEUP_EINT);
+       case WM8350_IRQ_GPIO(0):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP0_EINT);
+       case WM8350_IRQ_GPIO(1):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP1_EINT);
+       case WM8350_IRQ_GPIO(2):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP2_EINT);
+       case WM8350_IRQ_GPIO(3):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP3_EINT);
+       case WM8350_IRQ_GPIO(4):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP4_EINT);
+       case WM8350_IRQ_GPIO(5):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP5_EINT);
+       case WM8350_IRQ_GPIO(6):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP6_EINT);
+       case WM8350_IRQ_GPIO(7):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP7_EINT);
+       case WM8350_IRQ_GPIO(8):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP8_EINT);
+       case WM8350_IRQ_GPIO(9):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP9_EINT);
+       case WM8350_IRQ_GPIO(10):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP10_EINT);
+       case WM8350_IRQ_GPIO(11):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP11_EINT);
+       case WM8350_IRQ_GPIO(12):
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_INT_STATUS_MASK,
+                                      WM8350_IM_GP12_EINT);
+       default:
+               dev_warn(wm8350->dev, "Attempting to mask unknown IRQ %d\n",
+                        irq);
+               return -EINVAL;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_mask_irq);
+
+int wm8350_unmask_irq(struct wm8350 *wm8350, int irq)
+{
+       switch (irq) {
+       case WM8350_IRQ_CHG_BAT_HOT:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_BAT_HOT_EINT);
+       case WM8350_IRQ_CHG_BAT_COLD:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_BAT_COLD_EINT);
+       case WM8350_IRQ_CHG_BAT_FAIL:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_BAT_FAIL_EINT);
+       case WM8350_IRQ_CHG_TO:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_TO_EINT);
+       case WM8350_IRQ_CHG_END:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_END_EINT);
+       case WM8350_IRQ_CHG_START:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_START_EINT);
+       case WM8350_IRQ_CHG_FAST_RDY:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_FAST_RDY_EINT);
+       case WM8350_IRQ_RTC_PER:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_RTC_PER_EINT);
+       case WM8350_IRQ_RTC_SEC:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_RTC_SEC_EINT);
+       case WM8350_IRQ_RTC_ALM:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_RTC_ALM_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_3P9:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_VBATT_LT_3P9_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_3P1:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_VBATT_LT_3P1_EINT);
+       case WM8350_IRQ_CHG_VBATT_LT_2P85:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_1_MASK,
+                                        WM8350_IM_CHG_VBATT_LT_2P85_EINT);
+       case WM8350_IRQ_CS1:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_CS1_EINT);
+       case WM8350_IRQ_CS2:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_CS2_EINT);
+       case WM8350_IRQ_USB_LIMIT:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_USB_LIMIT_EINT);
+       case WM8350_IRQ_AUXADC_DATARDY:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_AUXADC_DATARDY_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP4:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_AUXADC_DCOMP4_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP3:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_AUXADC_DCOMP3_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP2:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_AUXADC_DCOMP2_EINT);
+       case WM8350_IRQ_AUXADC_DCOMP1:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_AUXADC_DCOMP1_EINT);
+       case WM8350_IRQ_SYS_HYST_COMP_FAIL:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_SYS_HYST_COMP_FAIL_EINT);
+       case WM8350_IRQ_SYS_CHIP_GT115:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_SYS_CHIP_GT115_EINT);
+       case WM8350_IRQ_SYS_CHIP_GT140:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_SYS_CHIP_GT140_EINT);
+       case WM8350_IRQ_SYS_WDOG_TO:
+               return wm8350_clear_bits(wm8350, WM8350_INT_STATUS_2_MASK,
+                                        WM8350_IM_SYS_WDOG_TO_EINT);
+       case WM8350_IRQ_UV_LDO4:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_LDO4_EINT);
+       case WM8350_IRQ_UV_LDO3:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_LDO3_EINT);
+       case WM8350_IRQ_UV_LDO2:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_LDO2_EINT);
+       case WM8350_IRQ_UV_LDO1:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_LDO1_EINT);
+       case WM8350_IRQ_UV_DC6:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC6_EINT);
+       case WM8350_IRQ_UV_DC5:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC5_EINT);
+       case WM8350_IRQ_UV_DC4:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC4_EINT);
+       case WM8350_IRQ_UV_DC3:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC3_EINT);
+       case WM8350_IRQ_UV_DC2:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC2_EINT);
+       case WM8350_IRQ_UV_DC1:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_UNDER_VOLTAGE_INT_STATUS_MASK,
+                                        WM8350_IM_UV_DC1_EINT);
+       case WM8350_IRQ_OC_LS:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_OVER_CURRENT_INT_STATUS_MASK,
+                                        WM8350_IM_OC_LS_EINT);
+       case WM8350_IRQ_EXT_USB_FB:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_EXT_USB_FB_EINT);
+       case WM8350_IRQ_EXT_WALL_FB:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_EXT_WALL_FB_EINT);
+       case WM8350_IRQ_EXT_BAT_FB:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_EXT_BAT_FB_EINT);
+       case WM8350_IRQ_CODEC_JCK_DET_L:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_CODEC_JCK_DET_L_EINT);
+       case WM8350_IRQ_CODEC_JCK_DET_R:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_CODEC_JCK_DET_R_EINT);
+       case WM8350_IRQ_CODEC_MICSCD:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_CODEC_MICSCD_EINT);
+       case WM8350_IRQ_CODEC_MICD:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_CODEC_MICD_EINT);
+       case WM8350_IRQ_WKUP_OFF_STATE:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_OFF_STATE_EINT);
+       case WM8350_IRQ_WKUP_HIB_STATE:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_HIB_STATE_EINT);
+       case WM8350_IRQ_WKUP_CONV_FAULT:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_CONV_FAULT_EINT);
+       case WM8350_IRQ_WKUP_WDOG_RST:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_OFF_STATE_EINT);
+       case WM8350_IRQ_WKUP_GP_PWR_ON:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_GP_PWR_ON_EINT);
+       case WM8350_IRQ_WKUP_ONKEY:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_ONKEY_EINT);
+       case WM8350_IRQ_WKUP_GP_WAKEUP:
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_COMPARATOR_INT_STATUS_MASK,
+                                        WM8350_IM_WKUP_GP_WAKEUP_EINT);
+       case WM8350_IRQ_GPIO(0):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP0_EINT);
+       case WM8350_IRQ_GPIO(1):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP1_EINT);
+       case WM8350_IRQ_GPIO(2):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP2_EINT);
+       case WM8350_IRQ_GPIO(3):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP3_EINT);
+       case WM8350_IRQ_GPIO(4):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP4_EINT);
+       case WM8350_IRQ_GPIO(5):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP5_EINT);
+       case WM8350_IRQ_GPIO(6):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP6_EINT);
+       case WM8350_IRQ_GPIO(7):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP7_EINT);
+       case WM8350_IRQ_GPIO(8):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP8_EINT);
+       case WM8350_IRQ_GPIO(9):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP9_EINT);
+       case WM8350_IRQ_GPIO(10):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP10_EINT);
+       case WM8350_IRQ_GPIO(11):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP11_EINT);
+       case WM8350_IRQ_GPIO(12):
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_STATUS_MASK,
+                                        WM8350_IM_GP12_EINT);
+       default:
+               dev_warn(wm8350->dev, "Attempting to unmask unknown IRQ %d\n",
+                        irq);
+               return -EINVAL;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_unmask_irq);
+
+/*
+ * Cache is always host endian.
+ */
+static int wm8350_create_cache(struct wm8350 *wm8350, int mode)
+{
+       int i, ret = 0;
+       u16 value;
+       const u16 *reg_map;
+
+       switch (mode) {
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0
+       case 0:
+               reg_map = wm8350_mode0_defaults;
+               break;
+#endif
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1
+       case 1:
+               reg_map = wm8350_mode1_defaults;
+               break;
+#endif
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2
+       case 2:
+               reg_map = wm8350_mode2_defaults;
+               break;
+#endif
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3
+       case 3:
+               reg_map = wm8350_mode3_defaults;
+               break;
+#endif
+       default:
+               dev_err(wm8350->dev, "Configuration mode %d not supported\n",
+                       mode);
+               return -EINVAL;
+       }
+
+       wm8350->reg_cache =
+           kzalloc(sizeof(u16) * (WM8350_MAX_REGISTER + 1), GFP_KERNEL);
+       if (wm8350->reg_cache == NULL)
+               return -ENOMEM;
+
+       /* Read the initial cache state back from the device - this is
+        * a PMIC so the device many not be in a virgin state and we
+        * can't rely on the silicon values.
+        */
+       for (i = 0; i < WM8350_MAX_REGISTER; i++) {
+               /* audio register range */
+               if (wm8350_reg_io_map[i].readable &&
+                   (i < WM8350_CLOCK_CONTROL_1 || i > WM8350_AIF_TEST)) {
+                       ret = wm8350->read_dev(wm8350, i, 2, (char *)&value);
+                       if (ret < 0) {
+                               dev_err(wm8350->dev,
+                                      "failed to read initial cache value\n");
+                               goto out;
+                       }
+                       value = be16_to_cpu(value);
+                       value &= wm8350_reg_io_map[i].readable;
+                       wm8350->reg_cache[i] = value;
+               } else
+                       wm8350->reg_cache[i] = reg_map[i];
+       }
+
+out:
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_create_cache);
+
+/*
+ * Register a client device.  This is non-fatal since there is no need to
+ * fail the entire device init due to a single platform device failing.
+ */
+static void wm8350_client_dev_register(struct wm8350 *wm8350,
+                                      const char *name,
+                                      struct platform_device **pdev)
+{
+       int ret;
+
+       *pdev = platform_device_alloc(name, -1);
+       if (pdev == NULL) {
+               dev_err(wm8350->dev, "Failed to allocate %s\n", name);
+               return;
+       }
+
+       (*pdev)->dev.parent = wm8350->dev;
+       platform_set_drvdata(*pdev, wm8350);
+       ret = platform_device_add(*pdev);
+       if (ret != 0) {
+               dev_err(wm8350->dev, "Failed to register %s: %d\n", name, ret);
+               platform_device_put(*pdev);
+               *pdev = NULL;
+       }
+}
+
+int wm8350_device_init(struct wm8350 *wm8350, int irq,
+                      struct wm8350_platform_data *pdata)
+{
+       int ret = -EINVAL;
+       u16 id1, id2, mask, mode;
+
+       /* get WM8350 revision and config mode */
+       wm8350->read_dev(wm8350, WM8350_RESET_ID, sizeof(id1), &id1);
+       wm8350->read_dev(wm8350, WM8350_ID, sizeof(id2), &id2);
+
+       id1 = be16_to_cpu(id1);
+       id2 = be16_to_cpu(id2);
+
+       if (id1 == 0x6143) {
+               switch ((id2 & WM8350_CHIP_REV_MASK) >> 12) {
+               case WM8350_REV_E:
+                       dev_info(wm8350->dev, "Found Rev E device\n");
+                       wm8350->rev = WM8350_REV_E;
+                       break;
+               case WM8350_REV_F:
+                       dev_info(wm8350->dev, "Found Rev F device\n");
+                       wm8350->rev = WM8350_REV_F;
+                       break;
+               case WM8350_REV_G:
+                       dev_info(wm8350->dev, "Found Rev G device\n");
+                       wm8350->rev = WM8350_REV_G;
+                       break;
+               default:
+                       /* For safety we refuse to run on unknown hardware */
+                       dev_info(wm8350->dev, "Found unknown rev\n");
+                       ret = -ENODEV;
+                       goto err;
+               }
+       } else {
+               dev_info(wm8350->dev, "Device with ID %x is not a WM8350\n",
+                        id1);
+               ret = -ENODEV;
+               goto err;
+       }
+
+       mode = id2 & WM8350_CONF_STS_MASK >> 10;
+       mask = id2 & WM8350_CUST_ID_MASK;
+       dev_info(wm8350->dev, "Config mode %d, ROM mask %d\n", mode, mask);
+
+       ret = wm8350_create_cache(wm8350, mode);
+       if (ret < 0) {
+               printk(KERN_ERR "wm8350: failed to create register cache\n");
+               return ret;
+       }
+
+       if (pdata->init) {
+               ret = pdata->init(wm8350);
+               if (ret != 0) {
+                       dev_err(wm8350->dev, "Platform init() failed: %d\n",
+                               ret);
+                       goto err;
+               }
+       }
+
+       mutex_init(&wm8350->irq_mutex);
+       INIT_WORK(&wm8350->irq_work, wm8350_irq_worker);
+       if (irq != NO_IRQ) {
+               ret = request_irq(irq, wm8350_irq, 0,
+                                 "wm8350", wm8350);
+               if (ret != 0) {
+                       dev_err(wm8350->dev, "Failed to request IRQ: %d\n",
+                               ret);
+                       goto err;
+               }
+       } else {
+               dev_err(wm8350->dev, "No IRQ configured\n");
+               goto err;
+       }
+       wm8350->chip_irq = irq;
+
+       wm8350_reg_write(wm8350, WM8350_SYSTEM_INTERRUPTS_MASK, 0x0);
+
+       wm8350_client_dev_register(wm8350, "wm8350-codec",
+                                  &(wm8350->codec.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-gpio",
+                                  &(wm8350->gpio.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-power",
+                                  &(wm8350->power.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-rtc", &(wm8350->rtc.pdev));
+       wm8350_client_dev_register(wm8350, "wm8350-wdt", &(wm8350->wdt.pdev));
+
+       return 0;
+
+err:
+       kfree(wm8350->reg_cache);
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_device_init);
+
+void wm8350_device_exit(struct wm8350 *wm8350)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8350->pmic.pdev); i++)
+               platform_device_unregister(wm8350->pmic.pdev[i]);
+
+       platform_device_unregister(wm8350->wdt.pdev);
+       platform_device_unregister(wm8350->rtc.pdev);
+       platform_device_unregister(wm8350->power.pdev);
+       platform_device_unregister(wm8350->gpio.pdev);
+       platform_device_unregister(wm8350->codec.pdev);
+
+       free_irq(wm8350->chip_irq, wm8350);
+       flush_work(&wm8350->irq_work);
+       kfree(wm8350->reg_cache);
+}
+EXPORT_SYMBOL_GPL(wm8350_device_exit);
+
+MODULE_DESCRIPTION("WM8350 AudioPlus PMIC core driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/wm8350-gpio.c b/drivers/mfd/wm8350-gpio.c
new file mode 100644 (file)
index 0000000..ebf99be
--- /dev/null
@@ -0,0 +1,222 @@
+/*
+ * wm8350-core.c  --  Device access for Wolfson WM8350
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/errno.h>
+
+#include <linux/mfd/wm8350/core.h>
+#include <linux/mfd/wm8350/gpio.h>
+#include <linux/mfd/wm8350/pmic.h>
+
+static int gpio_set_dir(struct wm8350 *wm8350, int gpio, int dir)
+{
+       int ret;
+
+       wm8350_reg_unlock(wm8350);
+       if (dir == WM8350_GPIO_DIR_OUT)
+               ret = wm8350_clear_bits(wm8350,
+                                       WM8350_GPIO_CONFIGURATION_I_O,
+                                       1 << gpio);
+       else
+               ret = wm8350_set_bits(wm8350,
+                                     WM8350_GPIO_CONFIGURATION_I_O,
+                                     1 << gpio);
+       wm8350_reg_lock(wm8350);
+       return ret;
+}
+
+static int gpio_set_debounce(struct wm8350 *wm8350, int gpio, int db)
+{
+       if (db == WM8350_GPIO_DEBOUNCE_ON)
+               return wm8350_set_bits(wm8350, WM8350_GPIO_DEBOUNCE,
+                                      1 << gpio);
+       else
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_DEBOUNCE, 1 << gpio);
+}
+
+static int gpio_set_func(struct wm8350 *wm8350, int gpio, int func)
+{
+       u16 reg;
+
+       wm8350_reg_unlock(wm8350);
+       switch (gpio) {
+       case 0:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+                   & ~WM8350_GP0_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+                                reg | ((func & 0xf) << 0));
+               break;
+       case 1:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+                   & ~WM8350_GP1_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+                                reg | ((func & 0xf) << 4));
+               break;
+       case 2:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+                   & ~WM8350_GP2_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+                                reg | ((func & 0xf) << 8));
+               break;
+       case 3:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_1)
+                   & ~WM8350_GP3_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_1,
+                                reg | ((func & 0xf) << 12));
+               break;
+       case 4:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+                   & ~WM8350_GP4_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+                                reg | ((func & 0xf) << 0));
+               break;
+       case 5:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+                   & ~WM8350_GP5_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+                                reg | ((func & 0xf) << 4));
+               break;
+       case 6:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+                   & ~WM8350_GP6_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+                                reg | ((func & 0xf) << 8));
+               break;
+       case 7:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_2)
+                   & ~WM8350_GP7_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_2,
+                                reg | ((func & 0xf) << 12));
+               break;
+       case 8:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+                   & ~WM8350_GP8_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+                                reg | ((func & 0xf) << 0));
+               break;
+       case 9:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+                   & ~WM8350_GP9_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+                                reg | ((func & 0xf) << 4));
+               break;
+       case 10:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+                   & ~WM8350_GP10_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+                                reg | ((func & 0xf) << 8));
+               break;
+       case 11:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_3)
+                   & ~WM8350_GP11_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_3,
+                                reg | ((func & 0xf) << 12));
+               break;
+       case 12:
+               reg = wm8350_reg_read(wm8350, WM8350_GPIO_FUNCTION_SELECT_4)
+                   & ~WM8350_GP12_FN_MASK;
+               wm8350_reg_write(wm8350, WM8350_GPIO_FUNCTION_SELECT_4,
+                                reg | ((func & 0xf) << 0));
+               break;
+       default:
+               wm8350_reg_lock(wm8350);
+               return -EINVAL;
+       }
+
+       wm8350_reg_lock(wm8350);
+       return 0;
+}
+
+static int gpio_set_pull_up(struct wm8350 *wm8350, int gpio, int up)
+{
+       if (up)
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_PIN_PULL_UP_CONTROL,
+                                      1 << gpio);
+       else
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_PIN_PULL_UP_CONTROL,
+                                        1 << gpio);
+}
+
+static int gpio_set_pull_down(struct wm8350 *wm8350, int gpio, int down)
+{
+       if (down)
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_PULL_DOWN_CONTROL,
+                                      1 << gpio);
+       else
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_PULL_DOWN_CONTROL,
+                                        1 << gpio);
+}
+
+static int gpio_set_polarity(struct wm8350 *wm8350, int gpio, int pol)
+{
+       if (pol == WM8350_GPIO_ACTIVE_HIGH)
+               return wm8350_set_bits(wm8350,
+                                      WM8350_GPIO_PIN_POLARITY_TYPE,
+                                      1 << gpio);
+       else
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_PIN_POLARITY_TYPE,
+                                        1 << gpio);
+}
+
+static int gpio_set_invert(struct wm8350 *wm8350, int gpio, int invert)
+{
+       if (invert == WM8350_GPIO_INVERT_ON)
+               return wm8350_set_bits(wm8350, WM8350_GPIO_INT_MODE, 1 << gpio);
+       else
+               return wm8350_clear_bits(wm8350,
+                                        WM8350_GPIO_INT_MODE, 1 << gpio);
+}
+
+int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
+                      int pol, int pull, int invert, int debounce)
+{
+       /* make sure we never pull up and down at the same time */
+       if (pull == WM8350_GPIO_PULL_NONE) {
+               if (gpio_set_pull_up(wm8350, gpio, 0))
+                       goto err;
+               if (gpio_set_pull_down(wm8350, gpio, 0))
+                       goto err;
+       } else if (pull == WM8350_GPIO_PULL_UP) {
+               if (gpio_set_pull_down(wm8350, gpio, 0))
+                       goto err;
+               if (gpio_set_pull_up(wm8350, gpio, 1))
+                       goto err;
+       } else if (pull == WM8350_GPIO_PULL_DOWN) {
+               if (gpio_set_pull_up(wm8350, gpio, 0))
+                       goto err;
+               if (gpio_set_pull_down(wm8350, gpio, 1))
+                       goto err;
+       }
+
+       if (gpio_set_invert(wm8350, gpio, invert))
+               goto err;
+       if (gpio_set_polarity(wm8350, gpio, pol))
+               goto err;
+       if (gpio_set_debounce(wm8350, gpio, debounce))
+               goto err;
+       if (gpio_set_dir(wm8350, gpio, dir))
+               goto err;
+       return gpio_set_func(wm8350, gpio, func);
+
+err:
+       return -EIO;
+}
+EXPORT_SYMBOL_GPL(wm8350_gpio_config);
diff --git a/drivers/mfd/wm8350-i2c.c b/drivers/mfd/wm8350-i2c.c
new file mode 100644 (file)
index 0000000..8dfe21b
--- /dev/null
@@ -0,0 +1,120 @@
+/*
+ * wm8350-i2c.c  --  Generic I2C driver for Wolfson WM8350 PMIC
+ *
+ * This driver defines and configures the WM8350 for the Freescale i.MX32ADS.
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood
+ *         linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/i2c.h>
+#include <linux/platform_device.h>
+#include <linux/mfd/wm8350/core.h>
+
+static int wm8350_i2c_read_device(struct wm8350 *wm8350, char reg,
+                                 int bytes, void *dest)
+{
+       int ret;
+
+       ret = i2c_master_send(wm8350->i2c_client, &reg, 1);
+       if (ret < 0)
+               return ret;
+       return i2c_master_recv(wm8350->i2c_client, dest, bytes);
+}
+
+static int wm8350_i2c_write_device(struct wm8350 *wm8350, char reg,
+                                  int bytes, void *src)
+{
+       /* we add 1 byte for device register */
+       u8 msg[(WM8350_MAX_REGISTER << 1) + 1];
+
+       if (bytes > ((WM8350_MAX_REGISTER << 1) + 1))
+               return -EINVAL;
+
+       msg[0] = reg;
+       memcpy(&msg[1], src, bytes);
+       return i2c_master_send(wm8350->i2c_client, msg, bytes + 1);
+}
+
+static int wm8350_i2c_probe(struct i2c_client *i2c,
+                           const struct i2c_device_id *id)
+{
+       struct wm8350 *wm8350;
+       int ret = 0;
+
+       wm8350 = kzalloc(sizeof(struct wm8350), GFP_KERNEL);
+       if (wm8350 == NULL) {
+               kfree(i2c);
+               return -ENOMEM;
+       }
+
+       i2c_set_clientdata(i2c, wm8350);
+       wm8350->dev = &i2c->dev;
+       wm8350->i2c_client = i2c;
+       wm8350->read_dev = wm8350_i2c_read_device;
+       wm8350->write_dev = wm8350_i2c_write_device;
+
+       ret = wm8350_device_init(wm8350, i2c->irq, i2c->dev.platform_data);
+       if (ret < 0)
+               goto err;
+
+       return ret;
+
+err:
+       kfree(wm8350);
+       return ret;
+}
+
+static int wm8350_i2c_remove(struct i2c_client *i2c)
+{
+       struct wm8350 *wm8350 = i2c_get_clientdata(i2c);
+
+       wm8350_device_exit(wm8350);
+       kfree(wm8350);
+
+       return 0;
+}
+
+static const struct i2c_device_id wm8350_i2c_id[] = {
+       { "wm8350", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm8350_i2c_id);
+
+
+static struct i2c_driver wm8350_i2c_driver = {
+       .driver = {
+                  .name = "wm8350",
+                  .owner = THIS_MODULE,
+       },
+       .probe = wm8350_i2c_probe,
+       .remove = wm8350_i2c_remove,
+       .id_table = wm8350_i2c_id,
+};
+
+static int __init wm8350_i2c_init(void)
+{
+       return i2c_add_driver(&wm8350_i2c_driver);
+}
+/* init early so consumer devices can complete system boot */
+subsys_initcall(wm8350_i2c_init);
+
+static void __exit wm8350_i2c_exit(void)
+{
+       i2c_del_driver(&wm8350_i2c_driver);
+}
+module_exit(wm8350_i2c_exit);
+
+MODULE_DESCRIPTION("I2C support for the WM8350 AudioPlus PMIC");
+MODULE_LICENSE("GPL");
diff --git a/drivers/mfd/wm8350-regmap.c b/drivers/mfd/wm8350-regmap.c
new file mode 100644 (file)
index 0000000..974678d
--- /dev/null
@@ -0,0 +1,1347 @@
+/*
+ * wm8350-regmap.c  --  Wolfson Microelectronics WM8350 register map
+ *
+ * This file splits out the tables describing the defaults and access
+ * status of the WM8350 registers since they are rather large.
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include <linux/mfd/wm8350/core.h>
+
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_0
+
+#undef WM8350_HAVE_CONFIG_MODE
+#define WM8350_HAVE_CONFIG_MODE
+
+const u16 wm8350_mode0_defaults[] = {
+       0x17FF,     /* R0   - Reset/ID */
+       0x1000,     /* R1   - ID */
+       0x0000,     /* R2 */
+       0x1002,     /* R3   - System Control 1 */
+       0x0004,     /* R4   - System Control 2 */
+       0x0000,     /* R5   - System Hibernate */
+       0x8A00,     /* R6   - Interface Control */
+       0x0000,     /* R7 */
+       0x8000,     /* R8   - Power mgmt (1) */
+       0x0000,     /* R9   - Power mgmt (2) */
+       0x0000,     /* R10  - Power mgmt (3) */
+       0x2000,     /* R11  - Power mgmt (4) */
+       0x0E00,     /* R12  - Power mgmt (5) */
+       0x0000,     /* R13  - Power mgmt (6) */
+       0x0000,     /* R14  - Power mgmt (7) */
+       0x0000,     /* R15 */
+       0x0000,     /* R16  - RTC Seconds/Minutes */
+       0x0100,     /* R17  - RTC Hours/Day */
+       0x0101,     /* R18  - RTC Date/Month */
+       0x1400,     /* R19  - RTC Year */
+       0x0000,     /* R20  - Alarm Seconds/Minutes */
+       0x0000,     /* R21  - Alarm Hours/Day */
+       0x0000,     /* R22  - Alarm Date/Month */
+       0x0320,     /* R23  - RTC Time Control */
+       0x0000,     /* R24  - System Interrupts */
+       0x0000,     /* R25  - Interrupt Status 1 */
+       0x0000,     /* R26  - Interrupt Status 2 */
+       0x0000,     /* R27  - Power Up Interrupt Status */
+       0x0000,     /* R28  - Under Voltage Interrupt status */
+       0x0000,     /* R29  - Over Current Interrupt status */
+       0x0000,     /* R30  - GPIO Interrupt Status */
+       0x0000,     /* R31  - Comparator Interrupt Status */
+       0x3FFF,     /* R32  - System Interrupts Mask */
+       0x0000,     /* R33  - Interrupt Status 1 Mask */
+       0x0000,     /* R34  - Interrupt Status 2 Mask */
+       0x0000,     /* R35  - Power Up Interrupt Status Mask */
+       0x0000,     /* R36  - Under Voltage Interrupt status Mask */
+       0x0000,     /* R37  - Over Current Interrupt status Mask */
+       0x0000,     /* R38  - GPIO Interrupt Status Mask */
+       0x0000,     /* R39  - Comparator Interrupt Status Mask */
+       0x0040,     /* R40  - Clock Control 1 */
+       0x0000,     /* R41  - Clock Control 2 */
+       0x3B00,     /* R42  - FLL Control 1 */
+       0x7086,     /* R43  - FLL Control 2 */
+       0xC226,     /* R44  - FLL Control 3 */
+       0x0000,     /* R45  - FLL Control 4 */
+       0x0000,     /* R46 */
+       0x0000,     /* R47 */
+       0x0000,     /* R48  - DAC Control */
+       0x0000,     /* R49 */
+       0x00C0,     /* R50  - DAC Digital Volume L */
+       0x00C0,     /* R51  - DAC Digital Volume R */
+       0x0000,     /* R52 */
+       0x0040,     /* R53  - DAC LR Rate */
+       0x0000,     /* R54  - DAC Clock Control */
+       0x0000,     /* R55 */
+       0x0000,     /* R56 */
+       0x0000,     /* R57 */
+       0x4000,     /* R58  - DAC Mute */
+       0x0000,     /* R59  - DAC Mute Volume */
+       0x0000,     /* R60  - DAC Side */
+       0x0000,     /* R61 */
+       0x0000,     /* R62 */
+       0x0000,     /* R63 */
+       0x8000,     /* R64  - ADC Control */
+       0x0000,     /* R65 */
+       0x00C0,     /* R66  - ADC Digital Volume L */
+       0x00C0,     /* R67  - ADC Digital Volume R */
+       0x0000,     /* R68  - ADC Divider */
+       0x0000,     /* R69 */
+       0x0040,     /* R70  - ADC LR Rate */
+       0x0000,     /* R71 */
+       0x0303,     /* R72  - Input Control */
+       0x0000,     /* R73  - IN3 Input Control */
+       0x0000,     /* R74  - Mic Bias Control */
+       0x0000,     /* R75 */
+       0x0000,     /* R76  - Output Control */
+       0x0000,     /* R77  - Jack Detect */
+       0x0000,     /* R78  - Anti Pop Control */
+       0x0000,     /* R79 */
+       0x0040,     /* R80  - Left Input Volume */
+       0x0040,     /* R81  - Right Input Volume */
+       0x0000,     /* R82 */
+       0x0000,     /* R83 */
+       0x0000,     /* R84 */
+       0x0000,     /* R85 */
+       0x0000,     /* R86 */
+       0x0000,     /* R87 */
+       0x0800,     /* R88  - Left Mixer Control */
+       0x1000,     /* R89  - Right Mixer Control */
+       0x0000,     /* R90 */
+       0x0000,     /* R91 */
+       0x0000,     /* R92  - OUT3 Mixer Control */
+       0x0000,     /* R93  - OUT4 Mixer Control */
+       0x0000,     /* R94 */
+       0x0000,     /* R95 */
+       0x0000,     /* R96  - Output Left Mixer Volume */
+       0x0000,     /* R97  - Output Right Mixer Volume */
+       0x0000,     /* R98  - Input Mixer Volume L */
+       0x0000,     /* R99  - Input Mixer Volume R */
+       0x0000,     /* R100 - Input Mixer Volume */
+       0x0000,     /* R101 */
+       0x0000,     /* R102 */
+       0x0000,     /* R103 */
+       0x00E4,     /* R104 - LOUT1 Volume */
+       0x00E4,     /* R105 - ROUT1 Volume */
+       0x00E4,     /* R106 - LOUT2 Volume */
+       0x02E4,     /* R107 - ROUT2 Volume */
+       0x0000,     /* R108 */
+       0x0000,     /* R109 */
+       0x0000,     /* R110 */
+       0x0000,     /* R111 - BEEP Volume */
+       0x0A00,     /* R112 - AI Formating */
+       0x0000,     /* R113 - ADC DAC COMP */
+       0x0020,     /* R114 - AI ADC Control */
+       0x0020,     /* R115 - AI DAC Control */
+       0x0000,     /* R116 - AIF Test */
+       0x0000,     /* R117 */
+       0x0000,     /* R118 */
+       0x0000,     /* R119 */
+       0x0000,     /* R120 */
+       0x0000,     /* R121 */
+       0x0000,     /* R122 */
+       0x0000,     /* R123 */
+       0x0000,     /* R124 */
+       0x0000,     /* R125 */
+       0x0000,     /* R126 */
+       0x0000,     /* R127 */
+       0x1FFF,     /* R128 - GPIO Debounce */
+       0x0000,     /* R129 - GPIO Pin pull up Control */
+       0x03FC,     /* R130 - GPIO Pull down Control */
+       0x0000,     /* R131 - GPIO Interrupt Mode */
+       0x0000,     /* R132 */
+       0x0000,     /* R133 - GPIO Control */
+       0x0FFC,     /* R134 - GPIO Configuration (i/o) */
+       0x0FFC,     /* R135 - GPIO Pin Polarity / Type */
+       0x0000,     /* R136 */
+       0x0000,     /* R137 */
+       0x0000,     /* R138 */
+       0x0000,     /* R139 */
+       0x0013,     /* R140 - GPIO Function Select 1 */
+       0x0000,     /* R141 - GPIO Function Select 2 */
+       0x0000,     /* R142 - GPIO Function Select 3 */
+       0x0003,     /* R143 - GPIO Function Select 4 */
+       0x0000,     /* R144 - Digitiser Control (1) */
+       0x0002,     /* R145 - Digitiser Control (2) */
+       0x0000,     /* R146 */
+       0x0000,     /* R147 */
+       0x0000,     /* R148 */
+       0x0000,     /* R149 */
+       0x0000,     /* R150 */
+       0x0000,     /* R151 */
+       0x7000,     /* R152 - AUX1 Readback */
+       0x7000,     /* R153 - AUX2 Readback */
+       0x7000,     /* R154 - AUX3 Readback */
+       0x7000,     /* R155 - AUX4 Readback */
+       0x0000,     /* R156 - USB Voltage Readback */
+       0x0000,     /* R157 - LINE Voltage Readback */
+       0x0000,     /* R158 - BATT Voltage Readback */
+       0x0000,     /* R159 - Chip Temp Readback */
+       0x0000,     /* R160 */
+       0x0000,     /* R161 */
+       0x0000,     /* R162 */
+       0x0000,     /* R163 - Generic Comparator Control */
+       0x0000,     /* R164 - Generic comparator 1 */
+       0x0000,     /* R165 - Generic comparator 2 */
+       0x0000,     /* R166 - Generic comparator 3 */
+       0x0000,     /* R167 - Generic comparator 4 */
+       0xA00F,     /* R168 - Battery Charger Control 1 */
+       0x0B06,     /* R169 - Battery Charger Control 2 */
+       0x0000,     /* R170 - Battery Charger Control 3 */
+       0x0000,     /* R171 */
+       0x0000,     /* R172 - Current Sink Driver A */
+       0x0000,     /* R173 - CSA Flash control */
+       0x0000,     /* R174 - Current Sink Driver B */
+       0x0000,     /* R175 - CSB Flash control */
+       0x0000,     /* R176 - DCDC/LDO requested */
+       0x002D,     /* R177 - DCDC Active options */
+       0x0000,     /* R178 - DCDC Sleep options */
+       0x0025,     /* R179 - Power-check comparator */
+       0x000E,     /* R180 - DCDC1 Control */
+       0x0000,     /* R181 - DCDC1 Timeouts */
+       0x1006,     /* R182 - DCDC1 Low Power */
+       0x0018,     /* R183 - DCDC2 Control */
+       0x0000,     /* R184 - DCDC2 Timeouts */
+       0x0000,     /* R185 */
+       0x0000,     /* R186 - DCDC3 Control */
+       0x0000,     /* R187 - DCDC3 Timeouts */
+       0x0006,     /* R188 - DCDC3 Low Power */
+       0x0000,     /* R189 - DCDC4 Control */
+       0x0000,     /* R190 - DCDC4 Timeouts */
+       0x0006,     /* R191 - DCDC4 Low Power */
+       0x0008,     /* R192 - DCDC5 Control */
+       0x0000,     /* R193 - DCDC5 Timeouts */
+       0x0000,     /* R194 */
+       0x0000,     /* R195 - DCDC6 Control */
+       0x0000,     /* R196 - DCDC6 Timeouts */
+       0x0006,     /* R197 - DCDC6 Low Power */
+       0x0000,     /* R198 */
+       0x0003,     /* R199 - Limit Switch Control */
+       0x001C,     /* R200 - LDO1 Control */
+       0x0000,     /* R201 - LDO1 Timeouts */
+       0x001C,     /* R202 - LDO1 Low Power */
+       0x001B,     /* R203 - LDO2 Control */
+       0x0000,     /* R204 - LDO2 Timeouts */
+       0x001C,     /* R205 - LDO2 Low Power */
+       0x001B,     /* R206 - LDO3 Control */
+       0x0000,     /* R207 - LDO3 Timeouts */
+       0x001C,     /* R208 - LDO3 Low Power */
+       0x001B,     /* R209 - LDO4 Control */
+       0x0000,     /* R210 - LDO4 Timeouts */
+       0x001C,     /* R211 - LDO4 Low Power */
+       0x0000,     /* R212 */
+       0x0000,     /* R213 */
+       0x0000,     /* R214 */
+       0x0000,     /* R215 - VCC_FAULT Masks */
+       0x001F,     /* R216 - Main Bandgap Control */
+       0x0000,     /* R217 - OSC Control */
+       0x9000,     /* R218 - RTC Tick Control */
+       0x0000,     /* R219 */
+       0x4000,     /* R220 - RAM BIST 1 */
+       0x0000,     /* R221 */
+       0x0000,     /* R222 */
+       0x0000,     /* R223 */
+       0x0000,     /* R224 */
+       0x0000,     /* R225 - DCDC/LDO status */
+       0x0000,     /* R226 */
+       0x0000,     /* R227 */
+       0x0000,     /* R228 */
+       0x0000,     /* R229 */
+       0xE000,     /* R230 - GPIO Pin Status */
+       0x0000,     /* R231 */
+       0x0000,     /* R232 */
+       0x0000,     /* R233 */
+       0x0000,     /* R234 */
+       0x0000,     /* R235 */
+       0x0000,     /* R236 */
+       0x0000,     /* R237 */
+       0x0000,     /* R238 */
+       0x0000,     /* R239 */
+       0x0000,     /* R240 */
+       0x0000,     /* R241 */
+       0x0000,     /* R242 */
+       0x0000,     /* R243 */
+       0x0000,     /* R244 */
+       0x0000,     /* R245 */
+       0x0000,     /* R246 */
+       0x0000,     /* R247 */
+       0x0000,     /* R248 */
+       0x0000,     /* R249 */
+       0x0000,     /* R250 */
+       0x0000,     /* R251 */
+       0x0000,     /* R252 */
+       0x0000,     /* R253 */
+       0x0000,     /* R254 */
+       0x0000,     /* R255 */
+};
+#endif
+
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_1
+
+#undef WM8350_HAVE_CONFIG_MODE
+#define WM8350_HAVE_CONFIG_MODE
+
+const u16 wm8350_mode1_defaults[] = {
+       0x17FF,     /* R0   - Reset/ID */
+       0x1000,     /* R1   - ID */
+       0x0000,     /* R2 */
+       0x1002,     /* R3   - System Control 1 */
+       0x0014,     /* R4   - System Control 2 */
+       0x0000,     /* R5   - System Hibernate */
+       0x8A00,     /* R6   - Interface Control */
+       0x0000,     /* R7 */
+       0x8000,     /* R8   - Power mgmt (1) */
+       0x0000,     /* R9   - Power mgmt (2) */
+       0x0000,     /* R10  - Power mgmt (3) */
+       0x2000,     /* R11  - Power mgmt (4) */
+       0x0E00,     /* R12  - Power mgmt (5) */
+       0x0000,     /* R13  - Power mgmt (6) */
+       0x0000,     /* R14  - Power mgmt (7) */
+       0x0000,     /* R15 */
+       0x0000,     /* R16  - RTC Seconds/Minutes */
+       0x0100,     /* R17  - RTC Hours/Day */
+       0x0101,     /* R18  - RTC Date/Month */
+       0x1400,     /* R19  - RTC Year */
+       0x0000,     /* R20  - Alarm Seconds/Minutes */
+       0x0000,     /* R21  - Alarm Hours/Day */
+       0x0000,     /* R22  - Alarm Date/Month */
+       0x0320,     /* R23  - RTC Time Control */
+       0x0000,     /* R24  - System Interrupts */
+       0x0000,     /* R25  - Interrupt Status 1 */
+       0x0000,     /* R26  - Interrupt Status 2 */
+       0x0000,     /* R27  - Power Up Interrupt Status */
+       0x0000,     /* R28  - Under Voltage Interrupt status */
+       0x0000,     /* R29  - Over Current Interrupt status */
+       0x0000,     /* R30  - GPIO Interrupt Status */
+       0x0000,     /* R31  - Comparator Interrupt Status */
+       0x3FFF,     /* R32  - System Interrupts Mask */
+       0x0000,     /* R33  - Interrupt Status 1 Mask */
+       0x0000,     /* R34  - Interrupt Status 2 Mask */
+       0x0000,     /* R35  - Power Up Interrupt Status Mask */
+       0x0000,     /* R36  - Under Voltage Interrupt status Mask */
+       0x0000,     /* R37  - Over Current Interrupt status Mask */
+       0x0000,     /* R38  - GPIO Interrupt Status Mask */
+       0x0000,     /* R39  - Comparator Interrupt Status Mask */
+       0x0040,     /* R40  - Clock Control 1 */
+       0x0000,     /* R41  - Clock Control 2 */
+       0x3B00,     /* R42  - FLL Control 1 */
+       0x7086,     /* R43  - FLL Control 2 */
+       0xC226,     /* R44  - FLL Control 3 */
+       0x0000,     /* R45  - FLL Control 4 */
+       0x0000,     /* R46 */
+       0x0000,     /* R47 */
+       0x0000,     /* R48  - DAC Control */
+       0x0000,     /* R49 */
+       0x00C0,     /* R50  - DAC Digital Volume L */
+       0x00C0,     /* R51  - DAC Digital Volume R */
+       0x0000,     /* R52 */
+       0x0040,     /* R53  - DAC LR Rate */
+       0x0000,     /* R54  - DAC Clock Control */
+       0x0000,     /* R55 */
+       0x0000,     /* R56 */
+       0x0000,     /* R57 */
+       0x4000,     /* R58  - DAC Mute */
+       0x0000,     /* R59  - DAC Mute Volume */
+       0x0000,     /* R60  - DAC Side */
+       0x0000,     /* R61 */
+       0x0000,     /* R62 */
+       0x0000,     /* R63 */
+       0x8000,     /* R64  - ADC Control */
+       0x0000,     /* R65 */
+       0x00C0,     /* R66  - ADC Digital Volume L */
+       0x00C0,     /* R67  - ADC Digital Volume R */
+       0x0000,     /* R68  - ADC Divider */
+       0x0000,     /* R69 */
+       0x0040,     /* R70  - ADC LR Rate */
+       0x0000,     /* R71 */
+       0x0303,     /* R72  - Input Control */
+       0x0000,     /* R73  - IN3 Input Control */
+       0x0000,     /* R74  - Mic Bias Control */
+       0x0000,     /* R75 */
+       0x0000,     /* R76  - Output Control */
+       0x0000,     /* R77  - Jack Detect */
+       0x0000,     /* R78  - Anti Pop Control */
+       0x0000,     /* R79 */
+       0x0040,     /* R80  - Left Input Volume */
+       0x0040,     /* R81  - Right Input Volume */
+       0x0000,     /* R82 */
+       0x0000,     /* R83 */
+       0x0000,     /* R84 */
+       0x0000,     /* R85 */
+       0x0000,     /* R86 */
+       0x0000,     /* R87 */
+       0x0800,     /* R88  - Left Mixer Control */
+       0x1000,     /* R89  - Right Mixer Control */
+       0x0000,     /* R90 */
+       0x0000,     /* R91 */
+       0x0000,     /* R92  - OUT3 Mixer Control */
+       0x0000,     /* R93  - OUT4 Mixer Control */
+       0x0000,     /* R94 */
+       0x0000,     /* R95 */
+       0x0000,     /* R96  - Output Left Mixer Volume */
+       0x0000,     /* R97  - Output Right Mixer Volume */
+       0x0000,     /* R98  - Input Mixer Volume L */
+       0x0000,     /* R99  - Input Mixer Volume R */
+       0x0000,     /* R100 - Input Mixer Volume */
+       0x0000,     /* R101 */
+       0x0000,     /* R102 */
+       0x0000,     /* R103 */
+       0x00E4,     /* R104 - LOUT1 Volume */
+       0x00E4,     /* R105 - ROUT1 Volume */
+       0x00E4,     /* R106 - LOUT2 Volume */
+       0x02E4,     /* R107 - ROUT2 Volume */
+       0x0000,     /* R108 */
+       0x0000,     /* R109 */
+       0x0000,     /* R110 */
+       0x0000,     /* R111 - BEEP Volume */
+       0x0A00,     /* R112 - AI Formating */
+       0x0000,     /* R113 - ADC DAC COMP */
+       0x0020,     /* R114 - AI ADC Control */
+       0x0020,     /* R115 - AI DAC Control */
+       0x0000,     /* R116 - AIF Test */
+       0x0000,     /* R117 */
+       0x0000,     /* R118 */
+       0x0000,     /* R119 */
+       0x0000,     /* R120 */
+       0x0000,     /* R121 */
+       0x0000,     /* R122 */
+       0x0000,     /* R123 */
+       0x0000,     /* R124 */
+       0x0000,     /* R125 */
+       0x0000,     /* R126 */
+       0x0000,     /* R127 */
+       0x1FFF,     /* R128 - GPIO Debounce */
+       0x0000,     /* R129 - GPIO Pin pull up Control */
+       0x03FC,     /* R130 - GPIO Pull down Control */
+       0x0000,     /* R131 - GPIO Interrupt Mode */
+       0x0000,     /* R132 */
+       0x0000,     /* R133 - GPIO Control */
+       0x00FB,     /* R134 - GPIO Configuration (i/o) */
+       0x04FE,     /* R135 - GPIO Pin Polarity / Type */
+       0x0000,     /* R136 */
+       0x0000,     /* R137 */
+       0x0000,     /* R138 */
+       0x0000,     /* R139 */
+       0x0312,     /* R140 - GPIO Function Select 1 */
+       0x1003,     /* R141 - GPIO Function Select 2 */
+       0x1331,     /* R142 - GPIO Function Select 3 */
+       0x0003,     /* R143 - GPIO Function Select 4 */
+       0x0000,     /* R144 - Digitiser Control (1) */
+       0x0002,     /* R145 - Digitiser Control (2) */
+       0x0000,     /* R146 */
+       0x0000,     /* R147 */
+       0x0000,     /* R148 */
+       0x0000,     /* R149 */
+       0x0000,     /* R150 */
+       0x0000,     /* R151 */
+       0x7000,     /* R152 - AUX1 Readback */
+       0x7000,     /* R153 - AUX2 Readback */
+       0x7000,     /* R154 - AUX3 Readback */
+       0x7000,     /* R155 - AUX4 Readback */
+       0x0000,     /* R156 - USB Voltage Readback */
+       0x0000,     /* R157 - LINE Voltage Readback */
+       0x0000,     /* R158 - BATT Voltage Readback */
+       0x0000,     /* R159 - Chip Temp Readback */
+       0x0000,     /* R160 */
+       0x0000,     /* R161 */
+       0x0000,     /* R162 */
+       0x0000,     /* R163 - Generic Comparator Control */
+       0x0000,     /* R164 - Generic comparator 1 */
+       0x0000,     /* R165 - Generic comparator 2 */
+       0x0000,     /* R166 - Generic comparator 3 */
+       0x0000,     /* R167 - Generic comparator 4 */
+       0xA00F,     /* R168 - Battery Charger Control 1 */
+       0x0B06,     /* R169 - Battery Charger Control 2 */
+       0x0000,     /* R170 - Battery Charger Control 3 */
+       0x0000,     /* R171 */
+       0x0000,     /* R172 - Current Sink Driver A */
+       0x0000,     /* R173 - CSA Flash control */
+       0x0000,     /* R174 - Current Sink Driver B */
+       0x0000,     /* R175 - CSB Flash control */
+       0x0000,     /* R176 - DCDC/LDO requested */
+       0x002D,     /* R177 - DCDC Active options */
+       0x0000,     /* R178 - DCDC Sleep options */
+       0x0025,     /* R179 - Power-check comparator */
+       0x0062,     /* R180 - DCDC1 Control */
+       0x0400,     /* R181 - DCDC1 Timeouts */
+       0x1006,     /* R182 - DCDC1 Low Power */
+       0x0018,     /* R183 - DCDC2 Control */
+       0x0000,     /* R184 - DCDC2 Timeouts */
+       0x0000,     /* R185 */
+       0x0026,     /* R186 - DCDC3 Control */
+       0x0400,     /* R187 - DCDC3 Timeouts */
+       0x0006,     /* R188 - DCDC3 Low Power */
+       0x0062,     /* R189 - DCDC4 Control */
+       0x0400,     /* R190 - DCDC4 Timeouts */
+       0x0006,     /* R191 - DCDC4 Low Power */
+       0x0008,     /* R192 - DCDC5 Control */
+       0x0000,     /* R193 - DCDC5 Timeouts */
+       0x0000,     /* R194 */
+       0x0026,     /* R195 - DCDC6 Control */
+       0x0800,     /* R196 - DCDC6 Timeouts */
+       0x0006,     /* R197 - DCDC6 Low Power */
+       0x0000,     /* R198 */
+       0x0003,     /* R199 - Limit Switch Control */
+       0x0006,     /* R200 - LDO1 Control */
+       0x0400,     /* R201 - LDO1 Timeouts */
+       0x001C,     /* R202 - LDO1 Low Power */
+       0x0006,     /* R203 - LDO2 Control */
+       0x0400,     /* R204 - LDO2 Timeouts */
+       0x001C,     /* R205 - LDO2 Low Power */
+       0x001B,     /* R206 - LDO3 Control */
+       0x0000,     /* R207 - LDO3 Timeouts */
+       0x001C,     /* R208 - LDO3 Low Power */
+       0x001B,     /* R209 - LDO4 Control */
+       0x0000,     /* R210 - LDO4 Timeouts */
+       0x001C,     /* R211 - LDO4 Low Power */
+       0x0000,     /* R212 */
+       0x0000,     /* R213 */
+       0x0000,     /* R214 */
+       0x0000,     /* R215 - VCC_FAULT Masks */
+       0x001F,     /* R216 - Main Bandgap Control */
+       0x0000,     /* R217 - OSC Control */
+       0x9000,     /* R218 - RTC Tick Control */
+       0x0000,     /* R219 */
+       0x4000,     /* R220 - RAM BIST 1 */
+       0x0000,     /* R221 */
+       0x0000,     /* R222 */
+       0x0000,     /* R223 */
+       0x0000,     /* R224 */
+       0x0000,     /* R225 - DCDC/LDO status */
+       0x0000,     /* R226 */
+       0x0000,     /* R227 */
+       0x0000,     /* R228 */
+       0x0000,     /* R229 */
+       0xE000,     /* R230 - GPIO Pin Status */
+       0x0000,     /* R231 */
+       0x0000,     /* R232 */
+       0x0000,     /* R233 */
+       0x0000,     /* R234 */
+       0x0000,     /* R235 */
+       0x0000,     /* R236 */
+       0x0000,     /* R237 */
+       0x0000,     /* R238 */
+       0x0000,     /* R239 */
+       0x0000,     /* R240 */
+       0x0000,     /* R241 */
+       0x0000,     /* R242 */
+       0x0000,     /* R243 */
+       0x0000,     /* R244 */
+       0x0000,     /* R245 */
+       0x0000,     /* R246 */
+       0x0000,     /* R247 */
+       0x0000,     /* R248 */
+       0x0000,     /* R249 */
+       0x0000,     /* R250 */
+       0x0000,     /* R251 */
+       0x0000,     /* R252 */
+       0x0000,     /* R253 */
+       0x0000,     /* R254 */
+       0x0000,     /* R255 */
+};
+#endif
+
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_2
+
+#undef WM8350_HAVE_CONFIG_MODE
+#define WM8350_HAVE_CONFIG_MODE
+
+const u16 wm8350_mode2_defaults[] = {
+       0x17FF,     /* R0   - Reset/ID */
+       0x1000,     /* R1   - ID */
+       0x0000,     /* R2 */
+       0x1002,     /* R3   - System Control 1 */
+       0x0014,     /* R4   - System Control 2 */
+       0x0000,     /* R5   - System Hibernate */
+       0x8A00,     /* R6   - Interface Control */
+       0x0000,     /* R7 */
+       0x8000,     /* R8   - Power mgmt (1) */
+       0x0000,     /* R9   - Power mgmt (2) */
+       0x0000,     /* R10  - Power mgmt (3) */
+       0x2000,     /* R11  - Power mgmt (4) */
+       0x0E00,     /* R12  - Power mgmt (5) */
+       0x0000,     /* R13  - Power mgmt (6) */
+       0x0000,     /* R14  - Power mgmt (7) */
+       0x0000,     /* R15 */
+       0x0000,     /* R16  - RTC Seconds/Minutes */
+       0x0100,     /* R17  - RTC Hours/Day */
+       0x0101,     /* R18  - RTC Date/Month */
+       0x1400,     /* R19  - RTC Year */
+       0x0000,     /* R20  - Alarm Seconds/Minutes */
+       0x0000,     /* R21  - Alarm Hours/Day */
+       0x0000,     /* R22  - Alarm Date/Month */
+       0x0320,     /* R23  - RTC Time Control */
+       0x0000,     /* R24  - System Interrupts */
+       0x0000,     /* R25  - Interrupt Status 1 */
+       0x0000,     /* R26  - Interrupt Status 2 */
+       0x0000,     /* R27  - Power Up Interrupt Status */
+       0x0000,     /* R28  - Under Voltage Interrupt status */
+       0x0000,     /* R29  - Over Current Interrupt status */
+       0x0000,     /* R30  - GPIO Interrupt Status */
+       0x0000,     /* R31  - Comparator Interrupt Status */
+       0x3FFF,     /* R32  - System Interrupts Mask */
+       0x0000,     /* R33  - Interrupt Status 1 Mask */
+       0x0000,     /* R34  - Interrupt Status 2 Mask */
+       0x0000,     /* R35  - Power Up Interrupt Status Mask */
+       0x0000,     /* R36  - Under Voltage Interrupt status Mask */
+       0x0000,     /* R37  - Over Current Interrupt status Mask */
+       0x0000,     /* R38  - GPIO Interrupt Status Mask */
+       0x0000,     /* R39  - Comparator Interrupt Status Mask */
+       0x0040,     /* R40  - Clock Control 1 */
+       0x0000,     /* R41  - Clock Control 2 */
+       0x3B00,     /* R42  - FLL Control 1 */
+       0x7086,     /* R43  - FLL Control 2 */
+       0xC226,     /* R44  - FLL Control 3 */
+       0x0000,     /* R45  - FLL Control 4 */
+       0x0000,     /* R46 */
+       0x0000,     /* R47 */
+       0x0000,     /* R48  - DAC Control */
+       0x0000,     /* R49 */
+       0x00C0,     /* R50  - DAC Digital Volume L */
+       0x00C0,     /* R51  - DAC Digital Volume R */
+       0x0000,     /* R52 */
+       0x0040,     /* R53  - DAC LR Rate */
+       0x0000,     /* R54  - DAC Clock Control */
+       0x0000,     /* R55 */
+       0x0000,     /* R56 */
+       0x0000,     /* R57 */
+       0x4000,     /* R58  - DAC Mute */
+       0x0000,     /* R59  - DAC Mute Volume */
+       0x0000,     /* R60  - DAC Side */
+       0x0000,     /* R61 */
+       0x0000,     /* R62 */
+       0x0000,     /* R63 */
+       0x8000,     /* R64  - ADC Control */
+       0x0000,     /* R65 */
+       0x00C0,     /* R66  - ADC Digital Volume L */
+       0x00C0,     /* R67  - ADC Digital Volume R */
+       0x0000,     /* R68  - ADC Divider */
+       0x0000,     /* R69 */
+       0x0040,     /* R70  - ADC LR Rate */
+       0x0000,     /* R71 */
+       0x0303,     /* R72  - Input Control */
+       0x0000,     /* R73  - IN3 Input Control */
+       0x0000,     /* R74  - Mic Bias Control */
+       0x0000,     /* R75 */
+       0x0000,     /* R76  - Output Control */
+       0x0000,     /* R77  - Jack Detect */
+       0x0000,     /* R78  - Anti Pop Control */
+       0x0000,     /* R79 */
+       0x0040,     /* R80  - Left Input Volume */
+       0x0040,     /* R81  - Right Input Volume */
+       0x0000,     /* R82 */
+       0x0000,     /* R83 */
+       0x0000,     /* R84 */
+       0x0000,     /* R85 */
+       0x0000,     /* R86 */
+       0x0000,     /* R87 */
+       0x0800,     /* R88  - Left Mixer Control */
+       0x1000,     /* R89  - Right Mixer Control */
+       0x0000,     /* R90 */
+       0x0000,     /* R91 */
+       0x0000,     /* R92  - OUT3 Mixer Control */
+       0x0000,     /* R93  - OUT4 Mixer Control */
+       0x0000,     /* R94 */
+       0x0000,     /* R95 */
+       0x0000,     /* R96  - Output Left Mixer Volume */
+       0x0000,     /* R97  - Output Right Mixer Volume */
+       0x0000,     /* R98  - Input Mixer Volume L */
+       0x0000,     /* R99  - Input Mixer Volume R */
+       0x0000,     /* R100 - Input Mixer Volume */
+       0x0000,     /* R101 */
+       0x0000,     /* R102 */
+       0x0000,     /* R103 */
+       0x00E4,     /* R104 - LOUT1 Volume */
+       0x00E4,     /* R105 - ROUT1 Volume */
+       0x00E4,     /* R106 - LOUT2 Volume */
+       0x02E4,     /* R107 - ROUT2 Volume */
+       0x0000,     /* R108 */
+       0x0000,     /* R109 */
+       0x0000,     /* R110 */
+       0x0000,     /* R111 - BEEP Volume */
+       0x0A00,     /* R112 - AI Formating */
+       0x0000,     /* R113 - ADC DAC COMP */
+       0x0020,     /* R114 - AI ADC Control */
+       0x0020,     /* R115 - AI DAC Control */
+       0x0000,     /* R116 - AIF Test */
+       0x0000,     /* R117 */
+       0x0000,     /* R118 */
+       0x0000,     /* R119 */
+       0x0000,     /* R120 */
+       0x0000,     /* R121 */
+       0x0000,     /* R122 */
+       0x0000,     /* R123 */
+       0x0000,     /* R124 */
+       0x0000,     /* R125 */
+       0x0000,     /* R126 */
+       0x0000,     /* R127 */
+       0x1FFF,     /* R128 - GPIO Debounce */
+       0x0000,     /* R129 - GPIO Pin pull up Control */
+       0x03FC,     /* R130 - GPIO Pull down Control */
+       0x0000,     /* R131 - GPIO Interrupt Mode */
+       0x0000,     /* R132 */
+       0x0000,     /* R133 - GPIO Control */
+       0x08FB,     /* R134 - GPIO Configuration (i/o) */
+       0x0CFE,     /* R135 - GPIO Pin Polarity / Type */
+       0x0000,     /* R136 */
+       0x0000,     /* R137 */
+       0x0000,     /* R138 */
+       0x0000,     /* R139 */
+       0x0312,     /* R140 - GPIO Function Select 1 */
+       0x0003,     /* R141 - GPIO Function Select 2 */
+       0x2331,     /* R142 - GPIO Function Select 3 */
+       0x0003,     /* R143 - GPIO Function Select 4 */
+       0x0000,     /* R144 - Digitiser Control (1) */
+       0x0002,     /* R145 - Digitiser Control (2) */
+       0x0000,     /* R146 */
+       0x0000,     /* R147 */
+       0x0000,     /* R148 */
+       0x0000,     /* R149 */
+       0x0000,     /* R150 */
+       0x0000,     /* R151 */
+       0x7000,     /* R152 - AUX1 Readback */
+       0x7000,     /* R153 - AUX2 Readback */
+       0x7000,     /* R154 - AUX3 Readback */
+       0x7000,     /* R155 - AUX4 Readback */
+       0x0000,     /* R156 - USB Voltage Readback */
+       0x0000,     /* R157 - LINE Voltage Readback */
+       0x0000,     /* R158 - BATT Voltage Readback */
+       0x0000,     /* R159 - Chip Temp Readback */
+       0x0000,     /* R160 */
+       0x0000,     /* R161 */
+       0x0000,     /* R162 */
+       0x0000,     /* R163 - Generic Comparator Control */
+       0x0000,     /* R164 - Generic comparator 1 */
+       0x0000,     /* R165 - Generic comparator 2 */
+       0x0000,     /* R166 - Generic comparator 3 */
+       0x0000,     /* R167 - Generic comparator 4 */
+       0xA00F,     /* R168 - Battery Charger Control 1 */
+       0x0B06,     /* R169 - Battery Charger Control 2 */
+       0x0000,     /* R170 - Battery Charger Control 3 */
+       0x0000,     /* R171 */
+       0x0000,     /* R172 - Current Sink Driver A */
+       0x0000,     /* R173 - CSA Flash control */
+       0x0000,     /* R174 - Current Sink Driver B */
+       0x0000,     /* R175 - CSB Flash control */
+       0x0000,     /* R176 - DCDC/LDO requested */
+       0x002D,     /* R177 - DCDC Active options */
+       0x0000,     /* R178 - DCDC Sleep options */
+       0x0025,     /* R179 - Power-check comparator */
+       0x000E,     /* R180 - DCDC1 Control */
+       0x0400,     /* R181 - DCDC1 Timeouts */
+       0x1006,     /* R182 - DCDC1 Low Power */
+       0x0018,     /* R183 - DCDC2 Control */
+       0x0000,     /* R184 - DCDC2 Timeouts */
+       0x0000,     /* R185 */
+       0x002E,     /* R186 - DCDC3 Control */
+       0x0800,     /* R187 - DCDC3 Timeouts */
+       0x0006,     /* R188 - DCDC3 Low Power */
+       0x000E,     /* R189 - DCDC4 Control */
+       0x0800,     /* R190 - DCDC4 Timeouts */
+       0x0006,     /* R191 - DCDC4 Low Power */
+       0x0008,     /* R192 - DCDC5 Control */
+       0x0000,     /* R193 - DCDC5 Timeouts */
+       0x0000,     /* R194 */
+       0x0026,     /* R195 - DCDC6 Control */
+       0x0C00,     /* R196 - DCDC6 Timeouts */
+       0x0006,     /* R197 - DCDC6 Low Power */
+       0x0000,     /* R198 */
+       0x0003,     /* R199 - Limit Switch Control */
+       0x001A,     /* R200 - LDO1 Control */
+       0x0800,     /* R201 - LDO1 Timeouts */
+       0x001C,     /* R202 - LDO1 Low Power */
+       0x0010,     /* R203 - LDO2 Control */
+       0x0800,     /* R204 - LDO2 Timeouts */
+       0x001C,     /* R205 - LDO2 Low Power */
+       0x000A,     /* R206 - LDO3 Control */
+       0x0C00,     /* R207 - LDO3 Timeouts */
+       0x001C,     /* R208 - LDO3 Low Power */
+       0x001A,     /* R209 - LDO4 Control */
+       0x0800,     /* R210 - LDO4 Timeouts */
+       0x001C,     /* R211 - LDO4 Low Power */
+       0x0000,     /* R212 */
+       0x0000,     /* R213 */
+       0x0000,     /* R214 */
+       0x0000,     /* R215 - VCC_FAULT Masks */
+       0x001F,     /* R216 - Main Bandgap Control */
+       0x0000,     /* R217 - OSC Control */
+       0x9000,     /* R218 - RTC Tick Control */
+       0x0000,     /* R219 */
+       0x4000,     /* R220 - RAM BIST 1 */
+       0x0000,     /* R221 */
+       0x0000,     /* R222 */
+       0x0000,     /* R223 */
+       0x0000,     /* R224 */
+       0x0000,     /* R225 - DCDC/LDO status */
+       0x0000,     /* R226 */
+       0x0000,     /* R227 */
+       0x0000,     /* R228 */
+       0x0000,     /* R229 */
+       0xE000,     /* R230 - GPIO Pin Status */
+       0x0000,     /* R231 */
+       0x0000,     /* R232 */
+       0x0000,     /* R233 */
+       0x0000,     /* R234 */
+       0x0000,     /* R235 */
+       0x0000,     /* R236 */
+       0x0000,     /* R237 */
+       0x0000,     /* R238 */
+       0x0000,     /* R239 */
+       0x0000,     /* R240 */
+       0x0000,     /* R241 */
+       0x0000,     /* R242 */
+       0x0000,     /* R243 */
+       0x0000,     /* R244 */
+       0x0000,     /* R245 */
+       0x0000,     /* R246 */
+       0x0000,     /* R247 */
+       0x0000,     /* R248 */
+       0x0000,     /* R249 */
+       0x0000,     /* R250 */
+       0x0000,     /* R251 */
+       0x0000,     /* R252 */
+       0x0000,     /* R253 */
+       0x0000,     /* R254 */
+       0x0000,     /* R255 */
+};
+#endif
+
+#ifdef CONFIG_MFD_WM8350_CONFIG_MODE_3
+
+#undef WM8350_HAVE_CONFIG_MODE
+#define WM8350_HAVE_CONFIG_MODE
+
+const u16 wm8350_mode3_defaults[] = {
+       0x17FF,     /* R0   - Reset/ID */
+       0x1000,     /* R1   - ID */
+       0x0000,     /* R2 */
+       0x1000,     /* R3   - System Control 1 */
+       0x0004,     /* R4   - System Control 2 */
+       0x0000,     /* R5   - System Hibernate */
+       0x8A00,     /* R6   - Interface Control */
+       0x0000,     /* R7 */
+       0x8000,     /* R8   - Power mgmt (1) */
+       0x0000,     /* R9   - Power mgmt (2) */
+       0x0000,     /* R10  - Power mgmt (3) */
+       0x2000,     /* R11  - Power mgmt (4) */
+       0x0E00,     /* R12  - Power mgmt (5) */
+       0x0000,     /* R13  - Power mgmt (6) */
+       0x0000,     /* R14  - Power mgmt (7) */
+       0x0000,     /* R15 */
+       0x0000,     /* R16  - RTC Seconds/Minutes */
+       0x0100,     /* R17  - RTC Hours/Day */
+       0x0101,     /* R18  - RTC Date/Month */
+       0x1400,     /* R19  - RTC Year */
+       0x0000,     /* R20  - Alarm Seconds/Minutes */
+       0x0000,     /* R21  - Alarm Hours/Day */
+       0x0000,     /* R22  - Alarm Date/Month */
+       0x0320,     /* R23  - RTC Time Control */
+       0x0000,     /* R24  - System Interrupts */
+       0x0000,     /* R25  - Interrupt Status 1 */
+       0x0000,     /* R26  - Interrupt Status 2 */
+       0x0000,     /* R27  - Power Up Interrupt Status */
+       0x0000,     /* R28  - Under Voltage Interrupt status */
+       0x0000,     /* R29  - Over Current Interrupt status */
+       0x0000,     /* R30  - GPIO Interrupt Status */
+       0x0000,     /* R31  - Comparator Interrupt Status */
+       0x3FFF,     /* R32  - System Interrupts Mask */
+       0x0000,     /* R33  - Interrupt Status 1 Mask */
+       0x0000,     /* R34  - Interrupt Status 2 Mask */
+       0x0000,     /* R35  - Power Up Interrupt Status Mask */
+       0x0000,     /* R36  - Under Voltage Interrupt status Mask */
+       0x0000,     /* R37  - Over Current Interrupt status Mask */
+       0x0000,     /* R38  - GPIO Interrupt Status Mask */
+       0x0000,     /* R39  - Comparator Interrupt Status Mask */
+       0x0040,     /* R40  - Clock Control 1 */
+       0x0000,     /* R41  - Clock Control 2 */
+       0x3B00,     /* R42  - FLL Control 1 */
+       0x7086,     /* R43  - FLL Control 2 */
+       0xC226,     /* R44  - FLL Control 3 */
+       0x0000,     /* R45  - FLL Control 4 */
+       0x0000,     /* R46 */
+       0x0000,     /* R47 */
+       0x0000,     /* R48  - DAC Control */
+       0x0000,     /* R49 */
+       0x00C0,     /* R50  - DAC Digital Volume L */
+       0x00C0,     /* R51  - DAC Digital Volume R */
+       0x0000,     /* R52 */
+       0x0040,     /* R53  - DAC LR Rate */
+       0x0000,     /* R54  - DAC Clock Control */
+       0x0000,     /* R55 */
+       0x0000,     /* R56 */
+       0x0000,     /* R57 */
+       0x4000,     /* R58  - DAC Mute */
+       0x0000,     /* R59  - DAC Mute Volume */
+       0x0000,     /* R60  - DAC Side */
+       0x0000,     /* R61 */
+       0x0000,     /* R62 */
+       0x0000,     /* R63 */
+       0x8000,     /* R64  - ADC Control */
+       0x0000,     /* R65 */
+       0x00C0,     /* R66  - ADC Digital Volume L */
+       0x00C0,     /* R67  - ADC Digital Volume R */
+       0x0000,     /* R68  - ADC Divider */
+       0x0000,     /* R69 */
+       0x0040,     /* R70  - ADC LR Rate */
+       0x0000,     /* R71 */
+       0x0303,     /* R72  - Input Control */
+       0x0000,     /* R73  - IN3 Input Control */
+       0x0000,     /* R74  - Mic Bias Control */
+       0x0000,     /* R75 */
+       0x0000,     /* R76  - Output Control */
+       0x0000,     /* R77  - Jack Detect */
+       0x0000,     /* R78  - Anti Pop Control */
+       0x0000,     /* R79 */
+       0x0040,     /* R80  - Left Input Volume */
+       0x0040,     /* R81  - Right Input Volume */
+       0x0000,     /* R82 */
+       0x0000,     /* R83 */
+       0x0000,     /* R84 */
+       0x0000,     /* R85 */
+       0x0000,     /* R86 */
+       0x0000,     /* R87 */
+       0x0800,     /* R88  - Left Mixer Control */
+       0x1000,     /* R89  - Right Mixer Control */
+       0x0000,     /* R90 */
+       0x0000,     /* R91 */
+       0x0000,     /* R92  - OUT3 Mixer Control */
+       0x0000,     /* R93  - OUT4 Mixer Control */
+       0x0000,     /* R94 */
+       0x0000,     /* R95 */
+       0x0000,     /* R96  - Output Left Mixer Volume */
+       0x0000,     /* R97  - Output Right Mixer Volume */
+       0x0000,     /* R98  - Input Mixer Volume L */
+       0x0000,     /* R99  - Input Mixer Volume R */
+       0x0000,     /* R100 - Input Mixer Volume */
+       0x0000,     /* R101 */
+       0x0000,     /* R102 */
+       0x0000,     /* R103 */
+       0x00E4,     /* R104 - LOUT1 Volume */
+       0x00E4,     /* R105 - ROUT1 Volume */
+       0x00E4,     /* R106 - LOUT2 Volume */
+       0x02E4,     /* R107 - ROUT2 Volume */
+       0x0000,     /* R108 */
+       0x0000,     /* R109 */
+       0x0000,     /* R110 */
+       0x0000,     /* R111 - BEEP Volume */
+       0x0A00,     /* R112 - AI Formating */
+       0x0000,     /* R113 - ADC DAC COMP */
+       0x0020,     /* R114 - AI ADC Control */
+       0x0020,     /* R115 - AI DAC Control */
+       0x0000,     /* R116 - AIF Test */
+       0x0000,     /* R117 */
+       0x0000,     /* R118 */
+       0x0000,     /* R119 */
+       0x0000,     /* R120 */
+       0x0000,     /* R121 */
+       0x0000,     /* R122 */
+       0x0000,     /* R123 */
+       0x0000,     /* R124 */
+       0x0000,     /* R125 */
+       0x0000,     /* R126 */
+       0x0000,     /* R127 */
+       0x1FFF,     /* R128 - GPIO Debounce */
+       0x0000,     /* R129 - GPIO Pin pull up Control */
+       0x03FC,     /* R130 - GPIO Pull down Control */
+       0x0000,     /* R131 - GPIO Interrupt Mode */
+       0x0000,     /* R132 */
+       0x0000,     /* R133 - GPIO Control */
+       0x0A7B,     /* R134 - GPIO Configuration (i/o) */
+       0x06FE,     /* R135 - GPIO Pin Polarity / Type */
+       0x0000,     /* R136 */
+       0x0000,     /* R137 */
+       0x0000,     /* R138 */
+       0x0000,     /* R139 */
+       0x1312,     /* R140 - GPIO Function Select 1 */
+       0x1030,     /* R141 - GPIO Function Select 2 */
+       0x2231,     /* R142 - GPIO Function Select 3 */
+       0x0003,     /* R143 - GPIO Function Select 4 */
+       0x0000,     /* R144 - Digitiser Control (1) */
+       0x0002,     /* R145 - Digitiser Control (2) */
+       0x0000,     /* R146 */
+       0x0000,     /* R147 */
+       0x0000,     /* R148 */
+       0x0000,     /* R149 */
+       0x0000,     /* R150 */
+       0x0000,     /* R151 */
+       0x7000,     /* R152 - AUX1 Readback */
+       0x7000,     /* R153 - AUX2 Readback */
+       0x7000,     /* R154 - AUX3 Readback */
+       0x7000,     /* R155 - AUX4 Readback */
+       0x0000,     /* R156 - USB Voltage Readback */
+       0x0000,     /* R157 - LINE Voltage Readback */
+       0x0000,     /* R158 - BATT Voltage Readback */
+       0x0000,     /* R159 - Chip Temp Readback */
+       0x0000,     /* R160 */
+       0x0000,     /* R161 */
+       0x0000,     /* R162 */
+       0x0000,     /* R163 - Generic Comparator Control */
+       0x0000,     /* R164 - Generic comparator 1 */
+       0x0000,     /* R165 - Generic comparator 2 */
+       0x0000,     /* R166 - Generic comparator 3 */
+       0x0000,     /* R167 - Generic comparator 4 */
+       0xA00F,     /* R168 - Battery Charger Control 1 */
+       0x0B06,     /* R169 - Battery Charger Control 2 */
+       0x0000,     /* R170 - Battery Charger Control 3 */
+       0x0000,     /* R171 */
+       0x0000,     /* R172 - Current Sink Driver A */
+       0x0000,     /* R173 - CSA Flash control */
+       0x0000,     /* R174 - Current Sink Driver B */
+       0x0000,     /* R175 - CSB Flash control */
+       0x0000,     /* R176 - DCDC/LDO requested */
+       0x002D,     /* R177 - DCDC Active options */
+       0x0000,     /* R178 - DCDC Sleep options */
+       0x0025,     /* R179 - Power-check comparator */
+       0x000E,     /* R180 - DCDC1 Control */
+       0x0400,     /* R181 - DCDC1 Timeouts */
+       0x1006,     /* R182 - DCDC1 Low Power */
+       0x0018,     /* R183 - DCDC2 Control */
+       0x0000,     /* R184 - DCDC2 Timeouts */
+       0x0000,     /* R185 */
+       0x000E,     /* R186 - DCDC3 Control */
+       0x0400,     /* R187 - DCDC3 Timeouts */
+       0x0006,     /* R188 - DCDC3 Low Power */
+       0x0026,     /* R189 - DCDC4 Control */
+       0x0400,     /* R190 - DCDC4 Timeouts */
+       0x0006,     /* R191 - DCDC4 Low Power */
+       0x0008,     /* R192 - DCDC5 Control */
+       0x0000,     /* R193 - DCDC5 Timeouts */
+       0x0000,     /* R194 */
+       0x0026,     /* R195 - DCDC6 Control */
+       0x0400,     /* R196 - DCDC6 Timeouts */
+       0x0006,     /* R197 - DCDC6 Low Power */
+       0x0000,     /* R198 */
+       0x0003,     /* R199 - Limit Switch Control */
+       0x001C,     /* R200 - LDO1 Control */
+       0x0000,     /* R201 - LDO1 Timeouts */
+       0x001C,     /* R202 - LDO1 Low Power */
+       0x001C,     /* R203 - LDO2 Control */
+       0x0400,     /* R204 - LDO2 Timeouts */
+       0x001C,     /* R205 - LDO2 Low Power */
+       0x001C,     /* R206 - LDO3 Control */
+       0x0400,     /* R207 - LDO3 Timeouts */
+       0x001C,     /* R208 - LDO3 Low Power */
+       0x001F,     /* R209 - LDO4 Control */
+       0x0400,     /* R210 - LDO4 Timeouts */
+       0x001C,     /* R211 - LDO4 Low Power */
+       0x0000,     /* R212 */
+       0x0000,     /* R213 */
+       0x0000,     /* R214 */
+       0x0000,     /* R215 - VCC_FAULT Masks */
+       0x001F,     /* R216 - Main Bandgap Control */
+       0x0000,     /* R217 - OSC Control */
+       0x9000,     /* R218 - RTC Tick Control */
+       0x0000,     /* R219 */
+       0x4000,     /* R220 - RAM BIST 1 */
+       0x0000,     /* R221 */
+       0x0000,     /* R222 */
+       0x0000,     /* R223 */
+       0x0000,     /* R224 */
+       0x0000,     /* R225 - DCDC/LDO status */
+       0x0000,     /* R226 */
+       0x0000,     /* R227 */
+       0x0000,     /* R228 */
+       0x0000,     /* R229 */
+       0xE000,     /* R230 - GPIO Pin Status */
+       0x0000,     /* R231 */
+       0x0000,     /* R232 */
+       0x0000,     /* R233 */
+       0x0000,     /* R234 */
+       0x0000,     /* R235 */
+       0x0000,     /* R236 */
+       0x0000,     /* R237 */
+       0x0000,     /* R238 */
+       0x0000,     /* R239 */
+       0x0000,     /* R240 */
+       0x0000,     /* R241 */
+       0x0000,     /* R242 */
+       0x0000,     /* R243 */
+       0x0000,     /* R244 */
+       0x0000,     /* R245 */
+       0x0000,     /* R246 */
+       0x0000,     /* R247 */
+       0x0000,     /* R248 */
+       0x0000,     /* R249 */
+       0x0000,     /* R250 */
+       0x0000,     /* R251 */
+       0x0000,     /* R252 */
+       0x0000,     /* R253 */
+       0x0000,     /* R254 */
+       0x0000,     /* R255 */
+};
+#endif
+
+/* The register defaults for the config mode used must be compiled in but
+ * due to the impact on kernel size it is possible to disable
+ */
+#ifndef WM8350_HAVE_CONFIG_MODE
+#warning No WM8350 config modes supported - select at least one of the
+#warning MFD_WM8350_CONFIG_MODE_n options from the board driver.
+#endif
+
+/*
+ * Access masks.
+ */
+
+const struct wm8350_reg_access wm8350_reg_io_map[] = {
+       /*  read    write volatile */
+       { 0xFFFF, 0xFFFF, 0xFFFF }, /* R0   - Reset/ID */
+       { 0x7CFF, 0x0C00, 0x7FFF }, /* R1   - ID */
+       { 0x0000, 0x0000, 0x0000 }, /* R2 */
+       { 0xBE3B, 0xBE3B, 0x8000 }, /* R3   - System Control 1 */
+       { 0xFCF7, 0xFCF7, 0xF800 }, /* R4   - System Control 2 */
+       { 0x80FF, 0x80FF, 0x8000 }, /* R5   - System Hibernate */
+       { 0xFB0E, 0xFB0E, 0x0000 }, /* R6   - Interface Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R7 */
+       { 0xE537, 0xE537, 0xFFFF }, /* R8   - Power mgmt (1) */
+       { 0x0FF3, 0x0FF3, 0xFFFF }, /* R9   - Power mgmt (2) */
+       { 0x008F, 0x008F, 0xFFFF }, /* R10  - Power mgmt (3) */
+       { 0x6D3C, 0x6D3C, 0xFFFF }, /* R11  - Power mgmt (4) */
+       { 0x1F8F, 0x1F8F, 0xFFFF }, /* R12  - Power mgmt (5) */
+       { 0x8F3F, 0x8F3F, 0xFFFF }, /* R13  - Power mgmt (6) */
+       { 0x0003, 0x0003, 0xFFFF }, /* R14  - Power mgmt (7) */
+       { 0x0000, 0x0000, 0x0000 }, /* R15 */
+       { 0x7F7F, 0x7F7F, 0xFFFF }, /* R16  - RTC Seconds/Minutes */
+       { 0x073F, 0x073F, 0xFFFF }, /* R17  - RTC Hours/Day */
+       { 0x1F3F, 0x1F3F, 0xFFFF }, /* R18  - RTC Date/Month */
+       { 0x3FFF, 0x00FF, 0xFFFF }, /* R19  - RTC Year */
+       { 0x7F7F, 0x7F7F, 0x0000 }, /* R20  - Alarm Seconds/Minutes */
+       { 0x0F3F, 0x0F3F, 0x0000 }, /* R21  - Alarm Hours/Day */
+       { 0x1F3F, 0x1F3F, 0x0000 }, /* R22  - Alarm Date/Month */
+       { 0xEF7F, 0xEA7F, 0xFFFF }, /* R23  - RTC Time Control */
+       { 0x3BFF, 0x0000, 0xFFFF }, /* R24  - System Interrupts */
+       { 0xFEE7, 0x0000, 0xFFFF }, /* R25  - Interrupt Status 1 */
+       { 0x35FF, 0x0000, 0xFFFF }, /* R26  - Interrupt Status 2 */
+       { 0x0F3F, 0x0000, 0xFFFF }, /* R27  - Power Up Interrupt Status */
+       { 0x0F3F, 0x0000, 0xFFFF }, /* R28  - Under Voltage Interrupt status */
+       { 0x8000, 0x0000, 0xFFFF }, /* R29  - Over Current Interrupt status */
+       { 0x1FFF, 0x0000, 0xFFFF }, /* R30  - GPIO Interrupt Status */
+       { 0xEF7F, 0x0000, 0xFFFF }, /* R31  - Comparator Interrupt Status */
+       { 0x3FFF, 0x3FFF, 0x0000 }, /* R32  - System Interrupts Mask */
+       { 0xFEE7, 0xFEE7, 0x0000 }, /* R33  - Interrupt Status 1 Mask */
+       { 0xF5FF, 0xF5FF, 0x0000 }, /* R34  - Interrupt Status 2 Mask */
+       { 0x0F3F, 0x0F3F, 0x0000 }, /* R35  - Power Up Interrupt Status Mask */
+       { 0x0F3F, 0x0F3F, 0x0000 }, /* R36  - Under Voltage Int status Mask */
+       { 0x8000, 0x8000, 0x0000 }, /* R37  - Over Current Int status Mask */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R38  - GPIO Interrupt Status Mask */
+       { 0xEF7F, 0xEF7F, 0x0000 }, /* R39  - Comparator IntStatus Mask */
+       { 0xC9F7, 0xC9F7, 0xFFFF }, /* R40  - Clock Control 1 */
+       { 0x8001, 0x8001, 0x0000 }, /* R41  - Clock Control 2 */
+       { 0xFFF7, 0xFFF7, 0xFFFF }, /* R42  - FLL Control 1 */
+       { 0xFBFF, 0xFBFF, 0x0000 }, /* R43  - FLL Control 2 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R44  - FLL Control 3 */
+       { 0x0033, 0x0033, 0x0000 }, /* R45  - FLL Control 4 */
+       { 0x0000, 0x0000, 0x0000 }, /* R46 */
+       { 0x0000, 0x0000, 0x0000 }, /* R47 */
+       { 0x3033, 0x3033, 0x0000 }, /* R48  - DAC Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R49 */
+       { 0x81FF, 0x81FF, 0xFFFF }, /* R50  - DAC Digital Volume L */
+       { 0x81FF, 0x81FF, 0xFFFF }, /* R51  - DAC Digital Volume R */
+       { 0x0000, 0x0000, 0x0000 }, /* R52 */
+       { 0x0FFF, 0x0FFF, 0xFFFF }, /* R53  - DAC LR Rate */
+       { 0x0017, 0x0017, 0x0000 }, /* R54  - DAC Clock Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R55 */
+       { 0x0000, 0x0000, 0x0000 }, /* R56 */
+       { 0x0000, 0x0000, 0x0000 }, /* R57 */
+       { 0x4000, 0x4000, 0x0000 }, /* R58  - DAC Mute */
+       { 0x7000, 0x7000, 0x0000 }, /* R59  - DAC Mute Volume */
+       { 0x3C00, 0x3C00, 0x0000 }, /* R60  - DAC Side */
+       { 0x0000, 0x0000, 0x0000 }, /* R61 */
+       { 0x0000, 0x0000, 0x0000 }, /* R62 */
+       { 0x0000, 0x0000, 0x0000 }, /* R63 */
+       { 0x8303, 0x8303, 0xFFFF }, /* R64  - ADC Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R65 */
+       { 0x81FF, 0x81FF, 0xFFFF }, /* R66  - ADC Digital Volume L */
+       { 0x81FF, 0x81FF, 0xFFFF }, /* R67  - ADC Digital Volume R */
+       { 0x0FFF, 0x0FFF, 0x0000 }, /* R68  - ADC Divider */
+       { 0x0000, 0x0000, 0x0000 }, /* R69 */
+       { 0x0FFF, 0x0FFF, 0xFFFF }, /* R70  - ADC LR Rate */
+       { 0x0000, 0x0000, 0x0000 }, /* R71 */
+       { 0x0707, 0x0707, 0xFFFF }, /* R72  - Input Control */
+       { 0xC0C0, 0xC0C0, 0xFFFF }, /* R73  - IN3 Input Control */
+       { 0xC09F, 0xC09F, 0xFFFF }, /* R74  - Mic Bias Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R75 */
+       { 0x0F15, 0x0F15, 0xFFFF }, /* R76  - Output Control */
+       { 0xC000, 0xC000, 0xFFFF }, /* R77  - Jack Detect */
+       { 0x03FF, 0x03FF, 0x0000 }, /* R78  - Anti Pop Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R79 */
+       { 0xE1FC, 0xE1FC, 0x8000 }, /* R80  - Left Input Volume */
+       { 0xE1FC, 0xE1FC, 0x8000 }, /* R81  - Right Input Volume */
+       { 0x0000, 0x0000, 0x0000 }, /* R82 */
+       { 0x0000, 0x0000, 0x0000 }, /* R83 */
+       { 0x0000, 0x0000, 0x0000 }, /* R84 */
+       { 0x0000, 0x0000, 0x0000 }, /* R85 */
+       { 0x0000, 0x0000, 0x0000 }, /* R86 */
+       { 0x0000, 0x0000, 0x0000 }, /* R87 */
+       { 0x9807, 0x9807, 0xFFFF }, /* R88  - Left Mixer Control */
+       { 0x980B, 0x980B, 0xFFFF }, /* R89  - Right Mixer Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R90 */
+       { 0x0000, 0x0000, 0x0000 }, /* R91 */
+       { 0x8909, 0x8909, 0xFFFF }, /* R92  - OUT3 Mixer Control */
+       { 0x9E07, 0x9E07, 0xFFFF }, /* R93  - OUT4 Mixer Control */
+       { 0x0000, 0x0000, 0x0000 }, /* R94 */
+       { 0x0000, 0x0000, 0x0000 }, /* R95 */
+       { 0x0EEE, 0x0EEE, 0x0000 }, /* R96  - Output Left Mixer Volume */
+       { 0xE0EE, 0xE0EE, 0x0000 }, /* R97  - Output Right Mixer Volume */
+       { 0x0E0F, 0x0E0F, 0x0000 }, /* R98  - Input Mixer Volume L */
+       { 0xE0E1, 0xE0E1, 0x0000 }, /* R99  - Input Mixer Volume R */
+       { 0x800E, 0x800E, 0x0000 }, /* R100 - Input Mixer Volume */
+       { 0x0000, 0x0000, 0x0000 }, /* R101 */
+       { 0x0000, 0x0000, 0x0000 }, /* R102 */
+       { 0x0000, 0x0000, 0x0000 }, /* R103 */
+       { 0xE1FC, 0xE1FC, 0xFFFF }, /* R104 - LOUT1 Volume */
+       { 0xE1FC, 0xE1FC, 0xFFFF }, /* R105 - ROUT1 Volume */
+       { 0xE1FC, 0xE1FC, 0xFFFF }, /* R106 - LOUT2 Volume */
+       { 0xE7FC, 0xE7FC, 0xFFFF }, /* R107 - ROUT2 Volume */
+       { 0x0000, 0x0000, 0x0000 }, /* R108 */
+       { 0x0000, 0x0000, 0x0000 }, /* R109 */
+       { 0x0000, 0x0000, 0x0000 }, /* R110 */
+       { 0x80E0, 0x80E0, 0xFFFF }, /* R111 - BEEP Volume */
+       { 0xBF00, 0xBF00, 0x0000 }, /* R112 - AI Formating */
+       { 0x00F1, 0x00F1, 0x0000 }, /* R113 - ADC DAC COMP */
+       { 0x00F8, 0x00F8, 0x0000 }, /* R114 - AI ADC Control */
+       { 0x40FB, 0x40FB, 0x0000 }, /* R115 - AI DAC Control */
+       { 0x7C30, 0x7C30, 0x0000 }, /* R116 - AIF Test */
+       { 0x0000, 0x0000, 0x0000 }, /* R117 */
+       { 0x0000, 0x0000, 0x0000 }, /* R118 */
+       { 0x0000, 0x0000, 0x0000 }, /* R119 */
+       { 0x0000, 0x0000, 0x0000 }, /* R120 */
+       { 0x0000, 0x0000, 0x0000 }, /* R121 */
+       { 0x0000, 0x0000, 0x0000 }, /* R122 */
+       { 0x0000, 0x0000, 0x0000 }, /* R123 */
+       { 0x0000, 0x0000, 0x0000 }, /* R124 */
+       { 0x0000, 0x0000, 0x0000 }, /* R125 */
+       { 0x0000, 0x0000, 0x0000 }, /* R126 */
+       { 0x0000, 0x0000, 0x0000 }, /* R127 */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R128 - GPIO Debounce */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R129 - GPIO Pin pull up Control */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R130 - GPIO Pull down Control */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R131 - GPIO Interrupt Mode */
+       { 0x0000, 0x0000, 0x0000 }, /* R132 */
+       { 0x00C0, 0x00C0, 0x0000 }, /* R133 - GPIO Control */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R134 - GPIO Configuration (i/o) */
+       { 0x1FFF, 0x1FFF, 0x0000 }, /* R135 - GPIO Pin Polarity / Type */
+       { 0x0000, 0x0000, 0x0000 }, /* R136 */
+       { 0x0000, 0x0000, 0x0000 }, /* R137 */
+       { 0x0000, 0x0000, 0x0000 }, /* R138 */
+       { 0x0000, 0x0000, 0x0000 }, /* R139 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R140 - GPIO Function Select 1 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R141 - GPIO Function Select 2 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R142 - GPIO Function Select 3 */
+       { 0x000F, 0x000F, 0x0000 }, /* R143 - GPIO Function Select 4 */
+       { 0xF0FF, 0xF0FF, 0xA000 }, /* R144 - Digitiser Control (1) */
+       { 0x3707, 0x3707, 0x0000 }, /* R145 - Digitiser Control (2) */
+       { 0x0000, 0x0000, 0x0000 }, /* R146 */
+       { 0x0000, 0x0000, 0x0000 }, /* R147 */
+       { 0x0000, 0x0000, 0x0000 }, /* R148 */
+       { 0x0000, 0x0000, 0x0000 }, /* R149 */
+       { 0x0000, 0x0000, 0x0000 }, /* R150 */
+       { 0x0000, 0x0000, 0x0000 }, /* R151 */
+       { 0x7FFF, 0x7000, 0xFFFF }, /* R152 - AUX1 Readback */
+       { 0x7FFF, 0x7000, 0xFFFF }, /* R153 - AUX2 Readback */
+       { 0x7FFF, 0x7000, 0xFFFF }, /* R154 - AUX3 Readback */
+       { 0x7FFF, 0x7000, 0xFFFF }, /* R155 - AUX4 Readback */
+       { 0x0FFF, 0x0000, 0xFFFF }, /* R156 - USB Voltage Readback */
+       { 0x0FFF, 0x0000, 0xFFFF }, /* R157 - LINE Voltage Readback */
+       { 0x0FFF, 0x0000, 0xFFFF }, /* R158 - BATT Voltage Readback */
+       { 0x0FFF, 0x0000, 0xFFFF }, /* R159 - Chip Temp Readback */
+       { 0x0000, 0x0000, 0x0000 }, /* R160 */
+       { 0x0000, 0x0000, 0x0000 }, /* R161 */
+       { 0x0000, 0x0000, 0x0000 }, /* R162 */
+       { 0x000F, 0x000F, 0x0000 }, /* R163 - Generic Comparator Control */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R164 - Generic comparator 1 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R165 - Generic comparator 2 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R166 - Generic comparator 3 */
+       { 0xFFFF, 0xFFFF, 0x0000 }, /* R167 - Generic comparator 4 */
+       { 0xBFFF, 0xBFFF, 0x8000 }, /* R168 - Battery Charger Control 1 */
+       { 0xFFFF, 0x4FFF, 0xB000 }, /* R169 - Battery Charger Control 2 */
+       { 0x007F, 0x007F, 0x0000 }, /* R170 - Battery Charger Control 3 */
+       { 0x0000, 0x0000, 0x0000 }, /* R171 */
+       { 0x903F, 0x903F, 0xFFFF }, /* R172 - Current Sink Driver A */
+       { 0xE333, 0xE333, 0xFFFF }, /* R173 - CSA Flash control */
+       { 0x903F, 0x903F, 0xFFFF }, /* R174 - Current Sink Driver B */
+       { 0xE333, 0xE333, 0xFFFF }, /* R175 - CSB Flash control */
+       { 0x8F3F, 0x8F3F, 0xFFFF }, /* R176 - DCDC/LDO requested */
+       { 0x332D, 0x332D, 0x0000 }, /* R177 - DCDC Active options */
+       { 0x002D, 0x002D, 0x0000 }, /* R178 - DCDC Sleep options */
+       { 0x5177, 0x5177, 0x8000 }, /* R179 - Power-check comparator */
+       { 0x047F, 0x047F, 0x0000 }, /* R180 - DCDC1 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R181 - DCDC1 Timeouts */
+       { 0x737F, 0x737F, 0x0000 }, /* R182 - DCDC1 Low Power */
+       { 0x535B, 0x535B, 0x0000 }, /* R183 - DCDC2 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R184 - DCDC2 Timeouts */
+       { 0x0000, 0x0000, 0x0000 }, /* R185 */
+       { 0x047F, 0x047F, 0x0000 }, /* R186 - DCDC3 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R187 - DCDC3 Timeouts */
+       { 0x737F, 0x737F, 0x0000 }, /* R188 - DCDC3 Low Power */
+       { 0x047F, 0x047F, 0x0000 }, /* R189 - DCDC4 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R190 - DCDC4 Timeouts */
+       { 0x737F, 0x737F, 0x0000 }, /* R191 - DCDC4 Low Power */
+       { 0x535B, 0x535B, 0x0000 }, /* R192 - DCDC5 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R193 - DCDC5 Timeouts */
+       { 0x0000, 0x0000, 0x0000 }, /* R194 */
+       { 0x047F, 0x047F, 0x0000 }, /* R195 - DCDC6 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R196 - DCDC6 Timeouts */
+       { 0x737F, 0x737F, 0x0000 }, /* R197 - DCDC6 Low Power */
+       { 0x0000, 0x0000, 0x0000 }, /* R198 */
+       { 0xFFD3, 0xFFD3, 0x0000 }, /* R199 - Limit Switch Control */
+       { 0x441F, 0x441F, 0x0000 }, /* R200 - LDO1 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R201 - LDO1 Timeouts */
+       { 0x331F, 0x331F, 0x0000 }, /* R202 - LDO1 Low Power */
+       { 0x441F, 0x441F, 0x0000 }, /* R203 - LDO2 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R204 - LDO2 Timeouts */
+       { 0x331F, 0x331F, 0x0000 }, /* R205 - LDO2 Low Power */
+       { 0x441F, 0x441F, 0x0000 }, /* R206 - LDO3 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R207 - LDO3 Timeouts */
+       { 0x331F, 0x331F, 0x0000 }, /* R208 - LDO3 Low Power */
+       { 0x441F, 0x441F, 0x0000 }, /* R209 - LDO4 Control */
+       { 0xFFC0, 0xFFC0, 0x0000 }, /* R210 - LDO4 Timeouts */
+       { 0x331F, 0x331F, 0x0000 }, /* R211 - LDO4 Low Power */
+       { 0x0000, 0x0000, 0x0000 }, /* R212 */
+       { 0x0000, 0x0000, 0x0000 }, /* R213 */
+       { 0x0000, 0x0000, 0x0000 }, /* R214 */
+       { 0x8F3F, 0x8F3F, 0x0000 }, /* R215 - VCC_FAULT Masks */
+       { 0xFF3F, 0xE03F, 0x0000 }, /* R216 - Main Bandgap Control */
+       { 0xEF2F, 0xE02F, 0x0000 }, /* R217 - OSC Control */
+       { 0xF3FF, 0xB3FF, 0xc000 }, /* R218 - RTC Tick Control */
+       { 0xFFFF, 0xFFFF, 0xFFFF }, /* R219 */
+       { 0x09FF, 0x01FF, 0x0000 }, /* R220 - RAM BIST 1 */
+       { 0x0000, 0x0000, 0x0000 }, /* R221 */
+       { 0xFFFF, 0xFFFF, 0xFFFF }, /* R222 */
+       { 0xFFFF, 0xFFFF, 0xFFFF }, /* R223 */
+       { 0x0000, 0x0000, 0x0000 }, /* R224 */
+       { 0x8F3F, 0x0000, 0xFFFF }, /* R225 - DCDC/LDO status */
+       { 0x0000, 0x0000, 0x0000 }, /* R226 */
+       { 0x0000, 0x0000, 0xFFFF }, /* R227 */
+       { 0x0000, 0x0000, 0x0000 }, /* R228 */
+       { 0x0000, 0x0000, 0x0000 }, /* R229 */
+       { 0xFFFF, 0x1FFF, 0xFFFF }, /* R230 - GPIO Pin Status */
+       { 0xFFFF, 0x1FFF, 0xFFFF }, /* R231 */
+       { 0xFFFF, 0x1FFF, 0xFFFF }, /* R232 */
+       { 0xFFFF, 0x1FFF, 0xFFFF }, /* R233 */
+       { 0x0000, 0x0000, 0x0000 }, /* R234 */
+       { 0x0000, 0x0000, 0x0000 }, /* R235 */
+       { 0x0000, 0x0000, 0x0000 }, /* R236 */
+       { 0x0000, 0x0000, 0x0000 }, /* R237 */
+       { 0x0000, 0x0000, 0x0000 }, /* R238 */
+       { 0x0000, 0x0000, 0x0000 }, /* R239 */
+       { 0x0000, 0x0000, 0x0000 }, /* R240 */
+       { 0x0000, 0x0000, 0x0000 }, /* R241 */
+       { 0x0000, 0x0000, 0x0000 }, /* R242 */
+       { 0x0000, 0x0000, 0x0000 }, /* R243 */
+       { 0x0000, 0x0000, 0x0000 }, /* R244 */
+       { 0x0000, 0x0000, 0x0000 }, /* R245 */
+       { 0x0000, 0x0000, 0x0000 }, /* R246 */
+       { 0x0000, 0x0000, 0x0000 }, /* R247 */
+       { 0xFFFF, 0x0010, 0xFFFF }, /* R248 */
+       { 0x0000, 0x0000, 0x0000 }, /* R249 */
+       { 0xFFFF, 0x0010, 0xFFFF }, /* R250 */
+       { 0xFFFF, 0x0010, 0xFFFF }, /* R251 */
+       { 0x0000, 0x0000, 0x0000 }, /* R252 */
+       { 0xFFFF, 0x0010, 0xFFFF }, /* R253 */
+       { 0x0000, 0x0000, 0x0000 }, /* R254 */
+       { 0x0000, 0x0000, 0x0000 }, /* R255 */
+};
diff --git a/drivers/mfd/wm8400-core.c b/drivers/mfd/wm8400-core.c
new file mode 100644 (file)
index 0000000..6a0cedb
--- /dev/null
@@ -0,0 +1,455 @@
+/*
+ * Core driver for WM8400.
+ *
+ * Copyright 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/bug.h>
+#include <linux/i2c.h>
+#include <linux/kernel.h>
+#include <linux/mfd/wm8400-private.h>
+#include <linux/mfd/wm8400-audio.h>
+
+static struct {
+       u16  readable;    /* Mask of readable bits */
+       u16  writable;    /* Mask of writable bits */
+       u16  vol;         /* Mask of volatile bits */
+       int  is_codec;    /* Register controlled by codec reset */
+       u16  default_val; /* Value on reset */
+} reg_data[] = {
+       { 0xFFFF, 0xFFFF, 0x0000, 0, 0x6172 }, /* R0 */
+       { 0x7000, 0x0000, 0x8000, 0, 0x0000 }, /* R1 */
+       { 0xFF17, 0xFF17, 0x0000, 0, 0x0000 }, /* R2 */
+       { 0xEBF3, 0xEBF3, 0x0000, 1, 0x6000 }, /* R3 */
+       { 0x3CF3, 0x3CF3, 0x0000, 1, 0x0000 }, /* R4  */
+       { 0xF1F8, 0xF1F8, 0x0000, 1, 0x4050 }, /* R5  */
+       { 0xFC1F, 0xFC1F, 0x0000, 1, 0x4000 }, /* R6  */
+       { 0xDFDE, 0xDFDE, 0x0000, 1, 0x01C8 }, /* R7  */
+       { 0xFCFC, 0xFCFC, 0x0000, 1, 0x0000 }, /* R8  */
+       { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R9  */
+       { 0xEFFF, 0xEFFF, 0x0000, 1, 0x0040 }, /* R10 */
+       { 0x27F7, 0x27F7, 0x0000, 1, 0x0004 }, /* R11 */
+       { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R12 */
+       { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R13 */
+       { 0x1FEF, 0x1FEF, 0x0000, 1, 0x0000 }, /* R14 */
+       { 0x0163, 0x0163, 0x0000, 1, 0x0100 }, /* R15 */
+       { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R16 */
+       { 0x01FF, 0x01FF, 0x0000, 1, 0x00C0 }, /* R17 */
+       { 0x1FFF, 0x0FFF, 0x0000, 1, 0x0000 }, /* R18 */
+       { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1000 }, /* R19 */
+       { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R20 */
+       { 0xFFFF, 0xFFFF, 0x0000, 1, 0x1010 }, /* R21 */
+       { 0x0FDD, 0x0FDD, 0x0000, 1, 0x8000 }, /* R22 */
+       { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0800 }, /* R23 */
+       { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R24 */
+       { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R25 */
+       { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R26 */
+       { 0x0000, 0x01DF, 0x0000, 1, 0x008B }, /* R27 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R28 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R29 */
+       { 0x0000, 0x0077, 0x0000, 1, 0x0066 }, /* R30 */
+       { 0x0000, 0x0033, 0x0000, 1, 0x0022 }, /* R31 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R32 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0079 }, /* R33 */
+       { 0x0000, 0x0003, 0x0000, 1, 0x0003 }, /* R34 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0003 }, /* R35 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R36 */
+       { 0x0000, 0x003F, 0x0000, 1, 0x0100 }, /* R37 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R38 */
+       { 0x0000, 0x000F, 0x0000, 0, 0x0000 }, /* R39 */
+       { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R40 */
+       { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R41 */
+       { 0x0000, 0x01B7, 0x0000, 1, 0x0000 }, /* R42 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R43 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R44 */
+       { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R45 */
+       { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R46 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R47 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R48 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R49 */
+       { 0x0000, 0x01FF, 0x0000, 1, 0x0000 }, /* R50 */
+       { 0x0000, 0x01B3, 0x0000, 1, 0x0180 }, /* R51 */
+       { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R52 */
+       { 0x0000, 0x0077, 0x0000, 1, 0x0000 }, /* R53 */
+       { 0x0000, 0x00FF, 0x0000, 1, 0x0000 }, /* R54 */
+       { 0x0000, 0x0001, 0x0000, 1, 0x0000 }, /* R55 */
+       { 0x0000, 0x003F, 0x0000, 1, 0x0000 }, /* R56 */
+       { 0x0000, 0x004F, 0x0000, 1, 0x0000 }, /* R57 */
+       { 0x0000, 0x00FD, 0x0000, 1, 0x0000 }, /* R58 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R59 */
+       { 0x1FFF, 0x1FFF, 0x0000, 1, 0x0000 }, /* R60 */
+       { 0xFFFF, 0xFFFF, 0x0000, 1, 0x0000 }, /* R61 */
+       { 0x03FF, 0x03FF, 0x0000, 1, 0x0000 }, /* R62 */
+       { 0x007F, 0x007F, 0x0000, 1, 0x0000 }, /* R63 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R64 */
+       { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R65 */
+       { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R66 */
+       { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R67 */
+       { 0xDFFF, 0xDFFF, 0x0000, 0, 0x0000 }, /* R68 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R69 */
+       { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R70 */
+       { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R71 */
+       { 0xFFFF, 0xFFFF, 0x0000, 0, 0x4400 }, /* R72 */
+       { 0x23FF, 0x23FF, 0x0000, 0, 0x0000 }, /* R73 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R74 */
+       { 0x000E, 0x000E, 0x0000, 0, 0x0008 }, /* R75 */
+       { 0xE00F, 0xE00F, 0x0000, 0, 0x0000 }, /* R76 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R77 */
+       { 0x03C0, 0x03C0, 0x0000, 0, 0x02C0 }, /* R78 */
+       { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R79 */
+       { 0xFFFF, 0xFFFF, 0x0000, 0, 0x0000 }, /* R80 */
+       { 0xFFFF, 0x0000, 0xffff, 0, 0x0000 }, /* R81 */
+       { 0x2BFF, 0x0000, 0xffff, 0, 0x0000 }, /* R82 */
+       { 0x0000, 0x0000, 0x0000, 0, 0x0000 }, /* R83 */
+       { 0x80FF, 0x80FF, 0x0000, 0, 0x00ff }, /* R84 */
+};
+
+static int wm8400_read(struct wm8400 *wm8400, u8 reg, int num_regs, u16 *dest)
+{
+       int i, ret = 0;
+
+       BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
+
+       /* If there are any volatile reads then read back the entire block */
+       for (i = reg; i < reg + num_regs; i++)
+               if (reg_data[i].vol) {
+                       ret = wm8400->read_dev(wm8400->io_data, reg,
+                                              num_regs, dest);
+                       if (ret != 0)
+                               return ret;
+                       for (i = 0; i < num_regs; i++)
+                               dest[i] = be16_to_cpu(dest[i]);
+
+                       return 0;
+               }
+
+       /* Otherwise use the cache */
+       memcpy(dest, &wm8400->reg_cache[reg], num_regs * sizeof(u16));
+
+       return 0;
+}
+
+static int wm8400_write(struct wm8400 *wm8400, u8 reg, int num_regs,
+                       u16 *src)
+{
+       int ret, i;
+
+       BUG_ON(reg + num_regs - 1 > ARRAY_SIZE(wm8400->reg_cache));
+
+       for (i = 0; i < num_regs; i++) {
+               BUG_ON(!reg_data[reg + i].writable);
+               wm8400->reg_cache[reg + i] = src[i];
+               src[i] = cpu_to_be16(src[i]);
+       }
+
+       /* Do the actual I/O */
+       ret = wm8400->write_dev(wm8400->io_data, reg, num_regs, src);
+       if (ret != 0)
+               return -EIO;
+
+       return 0;
+}
+
+/**
+ * wm8400_reg_read - Single register read
+ *
+ * @wm8400: Pointer to wm8400 control structure
+ * @reg:    Register to read
+ *
+ * @return  Read value
+ */
+u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg)
+{
+       u16 val;
+
+       mutex_lock(&wm8400->io_lock);
+
+       wm8400_read(wm8400, reg, 1, &val);
+
+       mutex_unlock(&wm8400->io_lock);
+
+       return val;
+}
+EXPORT_SYMBOL_GPL(wm8400_reg_read);
+
+int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data)
+{
+       int ret;
+
+       mutex_lock(&wm8400->io_lock);
+
+       ret = wm8400_read(wm8400, reg, count, data);
+
+       mutex_unlock(&wm8400->io_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8400_block_read);
+
+/**
+ * wm8400_set_bits - Bitmask write
+ *
+ * @wm8400: Pointer to wm8400 control structure
+ * @reg:    Register to access
+ * @mask:   Mask of bits to change
+ * @val:    Value to set for masked bits
+ */
+int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val)
+{
+       u16 tmp;
+       int ret;
+
+       mutex_lock(&wm8400->io_lock);
+
+       ret = wm8400_read(wm8400, reg, 1, &tmp);
+       tmp = (tmp & ~mask) | val;
+       if (ret == 0)
+               ret = wm8400_write(wm8400, reg, 1, &tmp);
+
+       mutex_unlock(&wm8400->io_lock);
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8400_set_bits);
+
+/**
+ * wm8400_reset_codec_reg_cache - Reset cached codec registers to
+ * their default values.
+ */
+void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400)
+{
+       int i;
+
+       mutex_lock(&wm8400->io_lock);
+
+       /* Reset all codec registers to their initial value */
+       for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
+               if (reg_data[i].is_codec)
+                       wm8400->reg_cache[i] = reg_data[i].default_val;
+
+       mutex_unlock(&wm8400->io_lock);
+}
+EXPORT_SYMBOL_GPL(wm8400_reset_codec_reg_cache);
+
+/*
+ * wm8400_init - Generic initialisation
+ *
+ * The WM8400 can be configured as either an I2C or SPI device.  Probe
+ * functions for each bus set up the accessors then call into this to
+ * set up the device itself.
+ */
+static int wm8400_init(struct wm8400 *wm8400,
+                      struct wm8400_platform_data *pdata)
+{
+       u16 reg;
+       int ret, i;
+
+       mutex_init(&wm8400->io_lock);
+
+       wm8400->dev->driver_data = wm8400;
+
+       /* Check that this is actually a WM8400 */
+       ret = wm8400->read_dev(wm8400->io_data, WM8400_RESET_ID, 1, &reg);
+       if (ret != 0) {
+               dev_err(wm8400->dev, "Chip ID register read failed\n");
+               return -EIO;
+       }
+       if (be16_to_cpu(reg) != reg_data[WM8400_RESET_ID].default_val) {
+               dev_err(wm8400->dev, "Device is not a WM8400, ID is %x\n",
+                       be16_to_cpu(reg));
+               return -ENODEV;
+       }
+
+       /* We don't know what state the hardware is in and since this
+        * is a PMIC we can't reset it safely so initialise the register
+        * cache from the hardware.
+        */
+       ret = wm8400->read_dev(wm8400->io_data, 0,
+                              ARRAY_SIZE(wm8400->reg_cache),
+                              wm8400->reg_cache);
+       if (ret != 0) {
+               dev_err(wm8400->dev, "Register cache read failed\n");
+               return -EIO;
+       }
+       for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
+               wm8400->reg_cache[i] = be16_to_cpu(wm8400->reg_cache[i]);
+
+       /* If the codec is in reset use hard coded values */
+       if (!(wm8400->reg_cache[WM8400_POWER_MANAGEMENT_1] & WM8400_CODEC_ENA))
+               for (i = 0; i < ARRAY_SIZE(wm8400->reg_cache); i++)
+                       if (reg_data[i].is_codec)
+                               wm8400->reg_cache[i] = reg_data[i].default_val;
+
+       ret = wm8400_read(wm8400, WM8400_ID, 1, &reg);
+       if (ret != 0) {
+               dev_err(wm8400->dev, "ID register read failed: %d\n", ret);
+               return ret;
+       }
+       reg = (reg & WM8400_CHIP_REV_MASK) >> WM8400_CHIP_REV_SHIFT;
+       dev_info(wm8400->dev, "WM8400 revision %x\n", reg);
+
+       if (pdata && pdata->platform_init) {
+               ret = pdata->platform_init(wm8400->dev);
+               if (ret != 0)
+                       dev_err(wm8400->dev, "Platform init failed: %d\n",
+                               ret);
+       } else
+               dev_warn(wm8400->dev, "No platform initialisation supplied\n");
+
+       return ret;
+}
+
+static void wm8400_release(struct wm8400 *wm8400)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(wm8400->regulators); i++)
+               if (wm8400->regulators[i].name)
+                       platform_device_unregister(&wm8400->regulators[i]);
+}
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+static int wm8400_i2c_read(void *io_data, char reg, int count, u16 *dest)
+{
+       struct i2c_client *i2c = io_data;
+       struct i2c_msg xfer[2];
+       int ret;
+
+       /* Write register */
+       xfer[0].addr = i2c->addr;
+       xfer[0].flags = 0;
+       xfer[0].len = 1;
+       xfer[0].buf = &reg;
+
+       /* Read data */
+       xfer[1].addr = i2c->addr;
+       xfer[1].flags = I2C_M_RD;
+       xfer[1].len = count * sizeof(u16);
+       xfer[1].buf = (u8 *)dest;
+
+       ret = i2c_transfer(i2c->adapter, xfer, 2);
+       if (ret == 2)
+               ret = 0;
+       else if (ret >= 0)
+               ret = -EIO;
+
+       return ret;
+}
+
+static int wm8400_i2c_write(void *io_data, char reg, int count, const u16 *src)
+{
+       struct i2c_client *i2c = io_data;
+       u8 *msg;
+       int ret;
+
+       /* We add 1 byte for device register - ideally I2C would gather. */
+       msg = kmalloc((count * sizeof(u16)) + 1, GFP_KERNEL);
+       if (msg == NULL)
+               return -ENOMEM;
+
+       msg[0] = reg;
+       memcpy(&msg[1], src, count * sizeof(u16));
+
+       ret = i2c_master_send(i2c, msg, (count * sizeof(u16)) + 1);
+
+       if (ret == (count * 2) + 1)
+               ret = 0;
+       else if (ret >= 0)
+               ret = -EIO;
+
+       kfree(msg);
+
+       return ret;
+}
+
+static int wm8400_i2c_probe(struct i2c_client *i2c,
+                           const struct i2c_device_id *id)
+{
+       struct wm8400 *wm8400;
+       int ret;
+
+       wm8400 = kzalloc(sizeof(struct wm8400), GFP_KERNEL);
+       if (wm8400 == NULL) {
+               ret = -ENOMEM;
+               goto err;
+       }
+
+       wm8400->io_data = i2c;
+       wm8400->read_dev = wm8400_i2c_read;
+       wm8400->write_dev = wm8400_i2c_write;
+       wm8400->dev = &i2c->dev;
+       i2c_set_clientdata(i2c, wm8400);
+
+       ret = wm8400_init(wm8400, i2c->dev.platform_data);
+       if (ret != 0)
+               goto struct_err;
+
+       return 0;
+
+struct_err:
+       i2c_set_clientdata(i2c, NULL);
+       kfree(wm8400);
+err:
+       return ret;
+}
+
+static int wm8400_i2c_remove(struct i2c_client *i2c)
+{
+       struct wm8400 *wm8400 = i2c_get_clientdata(i2c);
+
+       wm8400_release(wm8400);
+       i2c_set_clientdata(i2c, NULL);
+       kfree(wm8400);
+
+       return 0;
+}
+
+static const struct i2c_device_id wm8400_i2c_id[] = {
+       { "wm8400", 0 },
+       { }
+};
+MODULE_DEVICE_TABLE(i2c, wm8400_i2c_id);
+
+static struct i2c_driver wm8400_i2c_driver = {
+       .driver = {
+               .name = "WM8400",
+               .owner = THIS_MODULE,
+       },
+       .probe    = wm8400_i2c_probe,
+       .remove   = wm8400_i2c_remove,
+       .id_table = wm8400_i2c_id,
+};
+#endif
+
+static int __init wm8400_module_init(void)
+{
+       int ret = -ENODEV;
+
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       ret = i2c_add_driver(&wm8400_i2c_driver);
+       if (ret != 0)
+               pr_err("Failed to register I2C driver: %d\n", ret);
+#endif
+
+       return ret;
+}
+module_init(wm8400_module_init);
+
+static void __exit wm8400_module_exit(void)
+{
+#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE)
+       i2c_del_driver(&wm8400_i2c_driver);
+#endif
+}
+module_exit(wm8400_module_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
index 90924fb00481eda9289716337883155326bd8130..d600c2deff73824a70edb5e36f29157f4a36e16a 100644 (file)
@@ -118,7 +118,8 @@ static caddr_t remap_window(struct map_info *map, unsigned long to)
                DEBUG(2, "Remapping window from 0x%8.8x to 0x%8.8x",
                      dev->offset, mrq.CardOffset);
                mrq.Page = 0;
-               if( (ret = pcmcia_map_mem_page(win, &mrq)) != CS_SUCCESS) {
+               ret = pcmcia_map_mem_page(win, &mrq);
+               if (ret != 0) {
                        cs_error(dev->p_dev, MapMemPage, ret);
                        return NULL;
                }
@@ -326,9 +327,8 @@ static void pcmciamtd_set_vpp(struct map_info *map, int on)
 
        DEBUG(2, "dev = %p on = %d vpp = %d\n", dev, on, dev->vpp);
        ret = pcmcia_modify_configuration(link, &mod);
-       if(ret != CS_SUCCESS) {
+       if (ret != 0)
                cs_error(link, ModifyConfiguration, ret);
-       }
 }
 
 
@@ -368,14 +368,14 @@ static void card_settings(struct pcmciamtd_dev *dev, struct pcmcia_device *link,
        tuple.DesiredTuple = RETURN_FIRST_TUPLE;
 
        rc = pcmcia_get_first_tuple(link, &tuple);
-       while(rc == CS_SUCCESS) {
+       while (rc == 0) {
                rc = pcmcia_get_tuple_data(link, &tuple);
-               if(rc != CS_SUCCESS) {
+               if (rc != 0) {
                        cs_error(link, GetTupleData, rc);
                        break;
                }
-               rc = pcmcia_parse_tuple(link, &tuple, &parse);
-               if(rc != CS_SUCCESS) {
+               rc = pcmcia_parse_tuple(&tuple, &parse);
+               if (rc != 0) {
                        cs_error(link, ParseTuple, rc);
                        break;
                }
@@ -493,18 +493,11 @@ static int pcmciamtd_config(struct pcmcia_device *link)
        int last_ret = 0, last_fn = 0;
        int ret;
        int i;
-       config_info_t t;
        static char *probes[] = { "jedec_probe", "cfi_probe" };
        int new_name = 0;
 
        DEBUG(3, "link=0x%p", link);
 
-       DEBUG(2, "Validating CIS");
-       ret = pcmcia_validate_cis(link, NULL);
-       if(ret != CS_SUCCESS) {
-               cs_error(link, GetTupleData, ret);
-       }
-
        card_settings(dev, link, &new_name);
 
        dev->pcmcia_map.phys = NO_XIP;
@@ -571,10 +564,7 @@ static int pcmciamtd_config(struct pcmcia_device *link)
        dev->pcmcia_map.map_priv_1 = (unsigned long)dev;
        dev->pcmcia_map.map_priv_2 = (unsigned long)link->win;
 
-       DEBUG(2, "Getting configuration");
-       CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &t));
-       DEBUG(2, "Vcc = %d Vpp1 = %d Vpp2 = %d", t.Vcc, t.Vpp1, t.Vpp2);
-       dev->vpp = (vpp) ? vpp : t.Vpp1;
+       dev->vpp = (vpp) ? vpp : link->socket.socket.Vpp;
        link->conf.Attributes = 0;
        if(setvpp == 2) {
                link->conf.Vpp = dev->vpp;
@@ -583,16 +573,10 @@ static int pcmciamtd_config(struct pcmcia_device *link)
        }
 
        link->conf.IntType = INT_MEMORY;
-       link->conf.ConfigBase = t.ConfigBase;
-       link->conf.Status = t.Status;
-       link->conf.Pin = t.Pin;
-       link->conf.Copy = t.Copy;
-       link->conf.ExtStatus = t.ExtStatus;
        link->conf.ConfigIndex = 0;
-       link->conf.Present = t.Present;
        DEBUG(2, "Setting Configuration");
        ret = pcmcia_request_configuration(link, &link->conf);
-       if(ret != CS_SUCCESS) {
+       if (ret != 0) {
                cs_error(link, RequestConfiguration, ret);
                if (dev->win_base) {
                        iounmap(dev->win_base);
index 5ba4bab6d43e75342e9932cd93b6207e6d0dd517..7d15e7c6bcad51f65860ff6b42e09881e8e2064a 100644 (file)
@@ -17,7 +17,7 @@
        Annapolis MD 21403
 
     Fixed (again!) the missing interrupt locking on TX/RX shifting.
-       Alan Cox <Alan.Cox@linux.org>
+       Alan Cox <alan@lxorguk.ukuu.org.uk>
 
     Removed calls to init_etherdev since they are no longer needed, and
     cleaned up modularization just a bit. The driver still allows only
     the board. Now getting 150K/second FTP with a 3c501 card. Still playing
     with a TX-TX optimisation to see if we can touch 180-200K/second as seems
     theoretically maximum.
-               19950402 Alan Cox <Alan.Cox@linux.org>
+               19950402 Alan Cox <alan@lxorguk.ukuu.org.uk>
 
     Cleaned up for 2.3.x because we broke SMP now.
-               20000208 Alan Cox <alan@redhat.com>
+               20000208 Alan Cox <alan@lxorguk.ukuu.org.uk>
 
     Check up pass for 2.5. Nothing significant changed
-               20021009 Alan Cox <alan@redhat.com>
+               20021009 Alan Cox <alan@lxorguk.ukuu.org.uk>
 
     Fixed zero fill corner case
-               20030104 Alan Cox <alan@redhat.com>
+               20030104 Alan Cox <alan@lxorguk.ukuu.org.uk>
 
 
    For the avoidance of doubt the "preferred form" of this code is one which
 
 
 static const char version[] =
-       DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@redhat.com).\n";
+       DRV_NAME ".c: " DRV_VERSION " Alan Cox (alan@lxorguk.ukuu.org.uk).\n";
 
 /*
  *     Braindamage remaining:
index e4e3241628d615bb752d99c3cfc18c2ab4e0124e..a0f8b6e2d0af80af13b5774fe40ec9c5ee132db7 100644 (file)
@@ -18,7 +18,7 @@
 
        2001/11/17 - Added ethtool support (jgarzik)
 
-       2002/10/28 - Locking updates for 2.5 (alan@redhat.com)
+       2002/10/28 - Locking updates for 2.5 (alan@lxorguk.ukuu.org.uk)
 
 */
 
index e9d529442b067e5c016195be99cfb0d5c4927dc2..1d8af334833124b3aa3660c9cb1a963814b30507 100644 (file)
@@ -2400,7 +2400,7 @@ config EHEA
          will be called ehea.
 
 config ENIC
-       tristate "E, the Cisco 10G Ethernet NIC"
+       tristate "Cisco 10G Ethernet NIC support"
        depends on PCI && INET
        select INET_LRO
        help
index a0b4c8516073d7384c4baeb2fd1064ec7dc31234..735fc9476403c4df27229298af32021ddd9f1762 100644 (file)
@@ -4,7 +4,7 @@
  *      - Jay Schulist <jschlst@samba.org>
  *
  *     With more than a little help from;
- *     - Alan Cox <Alan.Cox@linux.org> 
+ *     - Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *      Derived from:
  *      - skeleton.c: A network driver outline for linux.
index 455ef529cd626ca167626161cc6cc3a35d981fb6..bc8e2413abd25d6c5106bcc83d10098fde44489d 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 744fac0b1617643294122f6cd9027a9671e9a9d0..5c3c05da4d96338e3f80e659c3c6e09d0017121b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 593fb643a615086ff6a16cb8ed88844bf0705804..e312d315a42d4e5ded041e3c1d8c717ae6ae02a6 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 6ad92405d9a034268796aafb7ece1540aa37c6bc..1d8d46eb3c960e0efd3725d731f947abb02b438f 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 45e92164c26047765ed0aacb6cdb76025042c9b2..47e53769af5b7f074e45e07505be797263261458 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 3e8d5faec3a4a9b6dd7ab9aeebf7e6f62ef74431..b19e4376ba76ec1584b948507783f8a566c7575b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index f31985df0bb9a2646adefd39746b8f05ab89072d..1ace41a13ac360363b2857475920a014daad4e94 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 0f6fd63b28475cdf5bc0be26ebb5cf07cd88035d..265aa8a15afaed2eb5a61177917d07cd6649b476 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 7a379138b5a6ebe757da3ce5c86abfd37174fc46..d514e5019dfc36b0935bace2be32056b0ee4f272 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2006-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2006-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index b75ddd8777fe8dbd0c900e775351e9ebe753fe13..0d9b0e6dccff41f58544345b0570cd762241b0c3 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index b2c5314582aa0cb954872d29127388f8edc5645c..4407ac9bb5559e87e427c445982cfa188a975ccf 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 42ce65f76a87517904bd89b4378cace767c53580..fd3eb07e3f40a5bb093307a1dab7c21f3bef338e 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 4c4d6e877ea698baf6ed92bbfc606f1b389dc476..3b5517b8fbde74a1131d932c890d0d5e3f39ab97 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 87919419b707faf3107877181dd96ec0b8cd5938..c6480be0bc1f7ed033b9a9ed0d856d12b4490255 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 917970ed24a1cbd1369d1160889ce8a61b0f0307..852c399a8b0ae838a0c963c2b3788918626e1e02 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2004-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2004-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 4da5b09b9bc29221ec7a2eae370bb9b8832a398a..968f64be3743acb165dbe40013e5d2a4dd60ee42 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 0a21cfbd2b2135fd47aedad1803fcc5d6c446d8f..be55e9ae74d18caeadfc8f6d2e6ca663ef773692 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2006-2007 Chelsio Communications.  All rights reserved.
+ * Copyright (C) 2006-2008 Chelsio Communications.  All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 29db711303b9040070aa6c2bc54f7295ed520a24..bb8698a867545384842032a10d330c3ee785cc0b 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2003-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2003-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
@@ -35,7 +35,7 @@
 #define DRV_DESC "Chelsio T3 Network Driver"
 #define DRV_NAME "cxgb3"
 /* Driver version */
-#define DRV_VERSION "1.0-ko"
+#define DRV_VERSION "1.1.0-ko"
 
 /* Firmware version */
 #define FW_VERSION_MAJOR 7
index 306c2dc4ab34884d2687fdae9c302d80b01b2426..33f956bd6b59b8f96134c9e09cc23149f4556b77 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index ffdc0a1892bd2334ed770647ea5c82a8ba498645..9d7786937aadf4c7e806d3bec7c6c58e8dd46d04 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2005-2007 Chelsio, Inc. All rights reserved.
+ * Copyright (c) 2005-2008 Chelsio, Inc. All rights reserved.
  *
  * This software is available to you under a choice of one of two
  * licenses.  You may choose to be licensed under the terms of the GNU
index 795c594a4b7c550e1d4200206205961aff4820a5..b751c1b96cfa77e2d445e3c182a4d2003cb8de73 100644 (file)
@@ -8,7 +8,7 @@
  *
  * Many modifications, and currently maintained, by
  *  Philip Blundell <philb@gnu.org>
- * Added the Compaq LTE  Alan Cox <alan@redhat.com>
+ * Added the Compaq LTE  Alan Cox <alan@lxorguk.ukuu.org.uk>
  * Added MCA support Adam Fritzler
  *
  * Note - this driver is experimental still - it has problems on faster
index f3a47a87dbbe3206304d2827187e2561780d165a..180e968dc54d87401eaa174c30a724223425d4bf 100644 (file)
@@ -34,6 +34,7 @@
 #include <linux/ip.h>
 #include <linux/ipv6.h>
 #include <linux/tcp.h>
+#include <net/ip6_checksum.h>
 
 #include "cq_enet_desc.h"
 #include "vnic_dev.h"
index 95e3464068db540c1d2a3f530960586ee2d0cfe0..f02764725a221fdde54b43ea9be1e7d65c8e8b75 100644 (file)
@@ -71,7 +71,7 @@ History:
   June 1st, 2000
        corrected version codes, added support for the latest 2.3 changes
   Oct 28th, 2002
-       cleaned up for the 2.5 tree <alan@redhat.com>
+       cleaned up for the 2.5 tree <alan@lxorguk.ukuu.org.uk>
 
  *************************************************************************/
 
index 156f159aafbb4819ff9c88433c2efee7897767a4..81c6cdc3851f8afd54d3319df5e6e9b99d516a25 100644 (file)
@@ -37,6 +37,7 @@
 #include <linux/tcp.h>
 #include <linux/udp.h>
 #include <linux/if_vlan.h>
+#include <net/ip6_checksum.h>
 #include "jme.h"
 
 static int force_pseudohp = -1;
index 51ad3765e0750c2857555c437ed259631a5394b7..85587a6667b9f170d3b55686a6474c20754a4c15 100644 (file)
@@ -9,7 +9,7 @@
  *     2 of the License, or (at your option) any later version.
  *
  *     Copyright (C) 1996 Paul Mackerras.
- *     Copyright (C) 1998 Alan Cox <alan@redhat.com>
+ *     Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Modified heavily by Joshua M. Thompson based on Dave Huang's NetBSD driver
  *
index 7112fd5e0e1ba8f76f9f0995695aed0f7749c212..08c4dd896077b7199762821264c522cc721b065a 100644 (file)
@@ -355,9 +355,10 @@ static int tc574_config(struct pcmcia_device *link)
        for (i = j = 0; j < 0x400; j += 0x20) {
                link->io.BasePort1 = j ^ 0x300;
                i = pcmcia_request_io(link, &link->io);
-               if (i == CS_SUCCESS) break;
+               if (i == 0)
+                       break;
        }
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIO, i);
                goto failed;
        }
@@ -377,7 +378,7 @@ static int tc574_config(struct pcmcia_device *link)
        tuple.TupleDataMax = 64;
        tuple.TupleOffset = 0;
        tuple.DesiredTuple = 0x88;
-       if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
+       if (pcmcia_get_first_tuple(link, &tuple) == 0) {
                pcmcia_get_tuple_data(link, &tuple);
                for (i = 0; i < 3; i++)
                        phys_addr[i] = htons(le16_to_cpu(buf[i]));
index 549a64558420dba22d81afc96f426bfe794e9b27..c235cdba69c6384d11b83ace2b2a1aac2f4a1905 100644 (file)
@@ -15,7 +15,7 @@
     incorporated herein by reference.
     Donald Becker may be reached at becker@scyld.com
     
-    Updated for 2.5.x by Alan Cox <alan@redhat.com>
+    Updated for 2.5.x by Alan Cox <alan@lxorguk.ukuu.org.uk>
 
 ======================================================================*/
 
@@ -278,9 +278,10 @@ static int tc589_config(struct pcmcia_device *link)
        if (multi && (j & 0x80)) continue;
        link->io.BasePort1 = j ^ 0x300;
        i = pcmcia_request_io(link, &link->io);
-       if (i == CS_SUCCESS) break;
+       if (i == 0)
+               break;
     }
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        cs_error(link, RequestIO, i);
        goto failed;
     }
@@ -295,7 +296,7 @@ static int tc589_config(struct pcmcia_device *link)
     /* The 3c589 has an extra EEPROM for configuration info, including
        the hardware address.  The 3c562 puts the address in the CIS. */
     tuple.DesiredTuple = 0x88;
-    if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
+    if (pcmcia_get_first_tuple(link, &tuple) == 0) {
        pcmcia_get_tuple_data(link, &tuple);
        for (i = 0; i < 3; i++)
            phys_addr[i] = htons(le16_to_cpu(buf[i]));
index 52bf11b73c6e950e0829bed0dcee087f98c52b38..b37a498939ae7d1a16f6e1a5c0ad8545f6d32380 100644 (file)
@@ -262,7 +262,7 @@ static int try_io_port(struct pcmcia_device *link)
        if (link->io.NumPorts2 > 0) {
            /* for master/slave multifunction cards */
            link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
-           link->irq.Attributes = 
+           link->irq.Attributes =
                IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED;
        }
     } else {
@@ -276,7 +276,8 @@ static int try_io_port(struct pcmcia_device *link)
            link->io.BasePort1 = j ^ 0x300;
            link->io.BasePort2 = (j ^ 0x300) + 0x10;
            ret = pcmcia_request_io(link, &link->io);
-           if (ret == CS_SUCCESS) return ret;
+           if (ret == 0)
+                   return ret;
        }
        return ret;
     } else {
@@ -284,59 +285,50 @@ static int try_io_port(struct pcmcia_device *link)
     }
 }
 
+static int axnet_configcheck(struct pcmcia_device *p_dev,
+                            cistpl_cftable_entry_t *cfg,
+                            cistpl_cftable_entry_t *dflt,
+                            unsigned int vcc,
+                            void *priv_data)
+{
+       int i;
+       cistpl_io_t *io = &cfg->io;
+
+       if (cfg->index == 0 || cfg->io.nwin == 0)
+               return -ENODEV;
+
+       p_dev->conf.ConfigIndex = 0x05;
+       /* For multifunction cards, by convention, we configure the
+          network function with window 0, and serial with window 1 */
+       if (io->nwin > 1) {
+               i = (io->win[1].len > io->win[0].len);
+               p_dev->io.BasePort2 = io->win[1-i].base;
+               p_dev->io.NumPorts2 = io->win[1-i].len;
+       } else {
+               i = p_dev->io.NumPorts2 = 0;
+       }
+       p_dev->io.BasePort1 = io->win[i].base;
+       p_dev->io.NumPorts1 = io->win[i].len;
+       p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+       if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
+               return try_io_port(p_dev);
+
+       return -ENODEV;
+}
+
 static int axnet_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
     axnet_dev_t *info = PRIV(dev);
-    tuple_t tuple;
-    cisparse_t parse;
     int i, j, last_ret, last_fn;
-    u_short buf[64];
     DECLARE_MAC_BUF(mac);
 
     DEBUG(0, "axnet_config(0x%p)\n", link);
 
-    tuple.Attributes = 0;
-    tuple.TupleData = (cisdata_t *)buf;
-    tuple.TupleDataMax = sizeof(buf);
-    tuple.TupleOffset = 0;
-
     /* don't trust the CIS on this; Linksys got it wrong */
     link->conf.Present = 0x63;
-
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    tuple.Attributes = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (last_ret == CS_SUCCESS) {
-       cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-       cistpl_io_t *io = &(parse.cftable_entry.io);
-       
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-               pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
-               cfg->index == 0 || cfg->io.nwin == 0)
-           goto next_entry;
-       
-       link->conf.ConfigIndex = 0x05;
-       /* For multifunction cards, by convention, we configure the
-          network function with window 0, and serial with window 1 */
-       if (io->nwin > 1) {
-           i = (io->win[1].len > io->win[0].len);
-           link->io.BasePort2 = io->win[1-i].base;
-           link->io.NumPorts2 = io->win[1-i].len;
-       } else {
-           i = link->io.NumPorts2 = 0;
-       }
-       link->io.BasePort1 = io->win[i].base;
-       link->io.NumPorts1 = io->win[i].len;
-       link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-       if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
-           last_ret = try_io_port(link);
-           if (last_ret == CS_SUCCESS) break;
-       }
-    next_entry:
-       last_ret = pcmcia_get_next_tuple(link, &tuple);
-    }
-    if (last_ret != CS_SUCCESS) {
+    last_ret = pcmcia_loop_config(link, axnet_configcheck, NULL);
+    if (last_ret != 0) {
        cs_error(link, RequestIO, last_ret);
        goto failed;
     }
index ea9414c4d90000fa23ff7171b18cb84462bf6706..831090c756220fcc86743067d62eb36683517b57 100644 (file)
@@ -260,21 +260,21 @@ static int com20020_config(struct pcmcia_device *link)
     DEBUG(0, "com20020_config(0x%p)\n", link);
 
     DEBUG(1,"arcnet: baseport1 is %Xh\n", link->io.BasePort1);
-    i = !CS_SUCCESS;
+    i = -ENODEV;
     if (!link->io.BasePort1)
     {
        for (ioaddr = 0x100; ioaddr < 0x400; ioaddr += 0x10)
        {
            link->io.BasePort1 = ioaddr;
            i = pcmcia_request_io(link, &link->io);
-           if (i == CS_SUCCESS)
+           if (i == 0)
                break;
        }
     }
     else
        i = pcmcia_request_io(link, &link->io);
     
-    if (i != CS_SUCCESS)
+    if (i != 0)
     {
        DEBUG(1,"arcnet: requestIO failed totally!\n");
        goto failed;
@@ -287,7 +287,7 @@ static int com20020_config(struct pcmcia_device *link)
           link->irq.AssignedIRQ,
           link->irq.IRQInfo1, link->irq.IRQInfo2);
     i = pcmcia_request_irq(link, &link->irq);
-    if (i != CS_SUCCESS)
+    if (i != 0)
     {
        DEBUG(1,"arcnet: requestIRQ failed totally!\n");
        goto failed;
index a550c9bd126f595312e5649fec71af7599ae3b6f..69d916daa7bbb313440dbd4c2827a6779a715376 100644 (file)
@@ -309,7 +309,8 @@ static int mfc_try_io_port(struct pcmcia_device *link)
            printk(KERN_NOTICE "fmvj18x_cs: out of resource for serial\n");
        }
        ret = pcmcia_request_io(link, &link->io);
-       if (ret == CS_SUCCESS) return ret;
+       if (ret == 0)
+               return ret;
     }
     return ret;
 }
@@ -325,7 +326,7 @@ static int ungermann_try_io_port(struct pcmcia_device *link)
     for (ioaddr = 0x300; ioaddr < 0x3e0; ioaddr += 0x20) {
        link->io.BasePort1 = ioaddr;
        ret = pcmcia_request_io(link, &link->io);
-       if (ret == CS_SUCCESS) {
+       if (ret == 0) {
            /* calculate ConfigIndex value */
            link->conf.ConfigIndex = 
                ((link->io.BasePort1 & 0x0f0) >> 3) | 0x22;
@@ -356,12 +357,12 @@ static int fmvj18x_config(struct pcmcia_device *link)
     tuple.TupleOffset = 0;
     tuple.DesiredTuple = CISTPL_FUNCE;
     tuple.TupleOffset = 0;
-    if (pcmcia_get_first_tuple(link, &tuple) == CS_SUCCESS) {
+    if (pcmcia_get_first_tuple(link, &tuple) == 0) {
        /* Yes, I have CISTPL_FUNCE. Let's check CISTPL_MANFID */
        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
        CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
        CS_CHECK(GetTupleData, pcmcia_get_tuple_data(link, &tuple));
-       CS_CHECK(ParseTuple, pcmcia_parse_tuple(link, &tuple, &parse));
+       CS_CHECK(ParseTuple, pcmcia_parse_tuple(&tuple, &parse));
        link->conf.ConfigIndex = parse.cftable_entry.index;
        switch (link->manf_id) {
        case MANFID_TDK:
@@ -430,10 +431,10 @@ static int fmvj18x_config(struct pcmcia_device *link)
        link->irq.Attributes =
                IRQ_TYPE_DYNAMIC_SHARING|IRQ_FIRST_SHARED|IRQ_HANDLE_PRESENT;
        ret = mfc_try_io_port(link);
-       if (ret != CS_SUCCESS) goto cs_failed;
+       if (ret != 0) goto cs_failed;
     } else if (cardtype == UNGERMANN) {
        ret = ungermann_try_io_port(link);
-       if (ret != CS_SUCCESS) goto cs_failed;
+       if (ret != 0) goto cs_failed;
     } else { 
        CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
     }
@@ -565,7 +566,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
     req.Base = 0; req.Size = 0;
     req.AccessSpeed = 0;
     i = pcmcia_request_window(&link, &req, &link->win);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        cs_error(link, RequestWindow, i);
        return -1;
     }
@@ -599,7 +600,7 @@ static int fmvj18x_get_hwinfo(struct pcmcia_device *link, u_char *node_id)
 
     iounmap(base);
     j = pcmcia_release_window(link->win);
-    if (j != CS_SUCCESS)
+    if (j != 0)
        cs_error(link, ReleaseWindow, j);
     return (i != 0x200) ? 0 : -1;
 
@@ -620,7 +621,7 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
     req.Base = 0; req.Size = 0;
     req.AccessSpeed = 0;
     i = pcmcia_request_window(&link, &req, &link->win);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        cs_error(link, RequestWindow, i);
        return -1;
     }
@@ -642,7 +643,7 @@ static int fmvj18x_setup_mfc(struct pcmcia_device *link)
 
     iounmap(base);
     j = pcmcia_release_window(link->win);
-    if (j != CS_SUCCESS)
+    if (j != 0)
        cs_error(link, ReleaseWindow, j);
     return 0;
 
index 4eafa4f42cff5e5a01c4f8c16ea27757dbf43650..cf3cca4642f225320d9b076a9d82510c23aae493 100644 (file)
@@ -238,7 +238,7 @@ static int __devinit ibmtr_config(struct pcmcia_device *link)
     /* Try PRIMARY card at 0xA20-0xA23 */
     link->io.BasePort1 = 0xA20;
     i = pcmcia_request_io(link, &link->io);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        /* Couldn't get 0xA20-0xA23.  Try ALTERNATE at 0xA24-0xA27. */
        link->io.BasePort1 = 0xA24;
        CS_CHECK(RequestIO, pcmcia_request_io(link, &link->io));
index cfcbea9b7e2e374e36e45e986aac3d5d69af4681..448cd40aeba5ab37c2c913db34745ac87b2857fd 100644 (file)
@@ -69,7 +69,7 @@ Driver Notes and Issues
 History
 -------------------------------------------------------------------------------
 Log: nmclan_cs.c,v
- * 2.5.75-ac1 2003/07/11 Alan Cox <alan@redhat.com>
+ * 2.5.75-ac1 2003/07/11 Alan Cox <alan@lxorguk.ukuu.org.uk>
  * Fixed hang on card eject as we probe it
  * Cleaned up to use new style locking.
  *
@@ -925,7 +925,7 @@ static void mace_tx_timeout(struct net_device *dev)
   printk(KERN_NOTICE "%s: transmit timed out -- ", dev->name);
 #if RESET_ON_TIMEOUT
   printk("resetting card\n");
-  pcmcia_reset_card(link, NULL);
+  pcmcia_reset_card(link->socket);
 #else /* #if RESET_ON_TIMEOUT */
   printk("NOT resetting card\n");
 #endif /* #if RESET_ON_TIMEOUT */
index ebc1ae6bcbe5fc27f7152add5064a8dde48b9f70..e40d6301aa7aaf1084b9e0cef1bfbf7588d692c3 100644 (file)
@@ -310,7 +310,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
     req.Base = 0; req.Size = 0;
     req.AccessSpeed = 0;
     i = pcmcia_request_window(&link, &req, &link->win);
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        cs_error(link, RequestWindow, i);
        return NULL;
     }
@@ -333,7 +333,7 @@ static hw_info_t *get_hwinfo(struct pcmcia_device *link)
 
     iounmap(virt);
     j = pcmcia_release_window(link->win);
-    if (j != CS_SUCCESS)
+    if (j != 0)
        cs_error(link, ReleaseWindow, j);
     return (i < NR_INFO) ? hw_info+i : NULL;
 } /* get_hwinfo */
@@ -504,7 +504,8 @@ static int try_io_port(struct pcmcia_device *link)
            link->io.BasePort1 = j ^ 0x300;
            link->io.BasePort2 = (j ^ 0x300) + 0x10;
            ret = pcmcia_request_io(link, &link->io);
-           if (ret == CS_SUCCESS) return ret;
+           if (ret == 0)
+                   return ret;
        }
        return ret;
     } else {
@@ -512,58 +513,53 @@ static int try_io_port(struct pcmcia_device *link)
     }
 }
 
+static int pcnet_confcheck(struct pcmcia_device *p_dev,
+                          cistpl_cftable_entry_t *cfg,
+                          cistpl_cftable_entry_t *dflt,
+                          unsigned int vcc,
+                          void *priv_data)
+{
+       int *has_shmem = priv_data;
+       int i;
+       cistpl_io_t *io = &cfg->io;
+
+       if (cfg->index == 0 || cfg->io.nwin == 0)
+               return -EINVAL;
+
+       /* For multifunction cards, by convention, we configure the
+          network function with window 0, and serial with window 1 */
+       if (io->nwin > 1) {
+               i = (io->win[1].len > io->win[0].len);
+               p_dev->io.BasePort2 = io->win[1-i].base;
+               p_dev->io.NumPorts2 = io->win[1-i].len;
+       } else {
+               i = p_dev->io.NumPorts2 = 0;
+       }
+
+       *has_shmem = ((cfg->mem.nwin == 1) &&
+                     (cfg->mem.win[0].len >= 0x4000));
+       p_dev->io.BasePort1 = io->win[i].base;
+       p_dev->io.NumPorts1 = io->win[i].len;
+       p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+       if (p_dev->io.NumPorts1 + p_dev->io.NumPorts2 >= 32)
+               return try_io_port(p_dev);
+
+       return 0;
+}
+
 static int pcnet_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
     pcnet_dev_t *info = PRIV(dev);
-    tuple_t tuple;
-    cisparse_t parse;
-    int i, last_ret, last_fn, start_pg, stop_pg, cm_offset;
+    int last_ret, last_fn, start_pg, stop_pg, cm_offset;
     int has_shmem = 0;
-    u_short buf[64];
     hw_info_t *local_hw_info;
     DECLARE_MAC_BUF(mac);
 
     DEBUG(0, "pcnet_config(0x%p)\n", link);
 
-    tuple.TupleData = (cisdata_t *)buf;
-    tuple.TupleDataMax = sizeof(buf);
-    tuple.TupleOffset = 0;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    tuple.Attributes = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (last_ret == CS_SUCCESS) {
-       cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-       cistpl_io_t *io = &(parse.cftable_entry.io);
-
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                       pcmcia_parse_tuple(link, &tuple, &parse) != 0 ||
-                       cfg->index == 0 || cfg->io.nwin == 0)
-               goto next_entry;
-
-       link->conf.ConfigIndex = cfg->index;
-       /* For multifunction cards, by convention, we configure the
-          network function with window 0, and serial with window 1 */
-       if (io->nwin > 1) {
-           i = (io->win[1].len > io->win[0].len);
-           link->io.BasePort2 = io->win[1-i].base;
-           link->io.NumPorts2 = io->win[1-i].len;
-       } else {
-           i = link->io.NumPorts2 = 0;
-       }
-       has_shmem = ((cfg->mem.nwin == 1) &&
-                    (cfg->mem.win[0].len >= 0x4000));
-       link->io.BasePort1 = io->win[i].base;
-       link->io.NumPorts1 = io->win[i].len;
-       link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-       if (link->io.NumPorts1 + link->io.NumPorts2 >= 32) {
-           last_ret = try_io_port(link);
-           if (last_ret == CS_SUCCESS) break;
-       }
-    next_entry:
-       last_ret = pcmcia_get_next_tuple(link, &tuple);
-    }
-    if (last_ret != CS_SUCCESS) {
+    last_ret = pcmcia_loop_config(link, pcnet_confcheck, &has_shmem);
+    if (last_ret) {
        cs_error(link, RequestIO, last_ret);
        goto failed;
     }
index 250eb1954c342d7ecf3c77e7ef62978c18d6a5b8..c74d6656d2662bcf5b2d91dcea374c062404b4b1 100644 (file)
@@ -409,10 +409,13 @@ static int first_tuple(struct pcmcia_device *handle, tuple_t *tuple,
 {
        int i;
 
-       if ((i = pcmcia_get_first_tuple(handle, tuple)) != CS_SUCCESS ||
-                       (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
+       i = pcmcia_get_first_tuple(handle, tuple);
+       if (i != 0)
                return i;
-       return pcmcia_parse_tuple(handle, tuple, parse);
+       i = pcmcia_get_tuple_data(handle, tuple);
+       if (i != 0)
+               return i;
+       return pcmcia_parse_tuple(tuple, parse);
 }
 
 static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
@@ -420,10 +423,10 @@ static int next_tuple(struct pcmcia_device *handle, tuple_t *tuple,
 {
        int i;
 
-       if ((i = pcmcia_get_next_tuple(handle, tuple)) != CS_SUCCESS ||
-                       (i = pcmcia_get_tuple_data(handle, tuple)) != CS_SUCCESS)
+       if ((i = pcmcia_get_next_tuple(handle, tuple)) != 0 ||
+                       (i = pcmcia_get_tuple_data(handle, tuple)) != 0)
                return i;
-       return pcmcia_parse_tuple(handle, tuple, parse);
+       return pcmcia_parse_tuple(tuple, parse);
 }
 
 /*======================================================================
@@ -459,27 +462,36 @@ static int mhz_3288_power(struct pcmcia_device *link)
     return 0;
 }
 
+static int mhz_mfc_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cf,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       int k;
+       p_dev->io.BasePort2 = cf->io.win[0].base;
+       for (k = 0; k < 0x400; k += 0x10) {
+               if (k & 0x80)
+                       continue;
+               p_dev->io.BasePort1 = k ^ 0x300;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
+}
+
 static int mhz_mfc_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
     struct smc_private *smc = netdev_priv(dev);
     struct smc_cfg_mem *cfg_mem;
-    tuple_t *tuple;
-    cisparse_t *parse;
-    cistpl_cftable_entry_t *cf;
-    u_char *buf;
     win_req_t req;
     memreq_t mem;
-    int i, k;
+    int i;
 
     cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
     if (!cfg_mem)
-        return CS_OUT_OF_RESOURCE;
-
-    tuple = &cfg_mem->tuple;
-    parse = &cfg_mem->parse;
-    cf = &parse->cftable_entry;
-    buf = cfg_mem->buf;
+           return -ENOMEM;
 
     link->conf.Attributes |= CONF_ENABLE_SPKR;
     link->conf.Status = CCSR_AUDIO_ENA;
@@ -489,27 +501,9 @@ static int mhz_mfc_config(struct pcmcia_device *link)
     link->io.Attributes2 = IO_DATA_PATH_WIDTH_8;
     link->io.NumPorts2 = 8;
 
-    tuple->Attributes = tuple->TupleOffset = 0;
-    tuple->TupleData = (cisdata_t *)buf;
-    tuple->TupleDataMax = 255;
-    tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
-
-    i = first_tuple(link, tuple, parse);
     /* The Megahertz combo cards have modem-like CIS entries, so
        we have to explicitly try a bunch of port combinations. */
-    while (i == CS_SUCCESS) {
-       link->conf.ConfigIndex = cf->index;
-       link->io.BasePort2 = cf->io.win[0].base;
-       for (k = 0; k < 0x400; k += 0x10) {
-           if (k & 0x80) continue;
-           link->io.BasePort1 = k ^ 0x300;
-           i = pcmcia_request_io(link, &link->io);
-           if (i == CS_SUCCESS) break;
-       }
-       if (i == CS_SUCCESS) break;
-       i = next_tuple(link, tuple, parse);
-    }
-    if (i != CS_SUCCESS)
+    if (pcmcia_loop_config(link, mhz_mfc_config_check, NULL))
        goto free_cfg_mem;
     dev->base_addr = link->io.BasePort1;
 
@@ -518,7 +512,7 @@ static int mhz_mfc_config(struct pcmcia_device *link)
     req.Base = req.Size = 0;
     req.AccessSpeed = 0;
     i = pcmcia_request_window(&link, &req, &link->win);
-    if (i != CS_SUCCESS)
+    if (i != 0)
        goto free_cfg_mem;
     smc->base = ioremap(req.Base, req.Size);
     mem.CardOffset = mem.Page = 0;
@@ -526,14 +520,14 @@ static int mhz_mfc_config(struct pcmcia_device *link)
        mem.CardOffset = link->conf.ConfigBase;
     i = pcmcia_map_mem_page(link->win, &mem);
 
-    if ((i == CS_SUCCESS)
+    if ((i == 0)
        && (smc->manfid == MANFID_MEGAHERTZ)
        && (smc->cardid == PRODID_MEGAHERTZ_EM3288))
        mhz_3288_power(link);
 
 free_cfg_mem:
     kfree(cfg_mem);
-    return i;
+    return -ENODEV;
 }
 
 static int mhz_setup(struct pcmcia_device *link)
@@ -560,12 +554,12 @@ static int mhz_setup(struct pcmcia_device *link)
     /* Read the station address from the CIS.  It is stored as the last
        (fourth) string in the Version 1 Version/ID tuple. */
     tuple->DesiredTuple = CISTPL_VERS_1;
-    if (first_tuple(link, tuple, parse) != CS_SUCCESS) {
+    if (first_tuple(link, tuple, parse) != 0) {
        rc = -1;
        goto free_cfg_mem;
     }
     /* Ugh -- the EM1144 card has two VERS_1 tuples!?! */
-    if (next_tuple(link, tuple, parse) != CS_SUCCESS)
+    if (next_tuple(link, tuple, parse) != 0)
        first_tuple(link, tuple, parse);
     if (parse->version_1.ns > 3) {
        station_addr = parse->version_1.str + parse->version_1.ofs[3];
@@ -577,11 +571,11 @@ static int mhz_setup(struct pcmcia_device *link)
 
     /* Another possibility: for the EM3288, in a special tuple */
     tuple->DesiredTuple = 0x81;
-    if (pcmcia_get_first_tuple(link, tuple) != CS_SUCCESS) {
+    if (pcmcia_get_first_tuple(link, tuple) != 0) {
        rc = -1;
        goto free_cfg_mem;
     }
-    if (pcmcia_get_tuple_data(link, tuple) != CS_SUCCESS) {
+    if (pcmcia_get_tuple_data(link, tuple) != 0) {
        rc = -1;
        goto free_cfg_mem;
     }
@@ -660,46 +654,27 @@ static int mot_setup(struct pcmcia_device *link)
 
 /*====================================================================*/
 
+static int smc_configcheck(struct pcmcia_device *p_dev,
+                          cistpl_cftable_entry_t *cf,
+                          cistpl_cftable_entry_t *dflt,
+                          unsigned int vcc,
+                          void *priv_data)
+{
+       p_dev->io.BasePort1 = cf->io.win[0].base;
+       p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int smc_config(struct pcmcia_device *link)
 {
     struct net_device *dev = link->priv;
-    struct smc_cfg_mem *cfg_mem;
-    tuple_t *tuple;
-    cisparse_t *parse;
-    cistpl_cftable_entry_t *cf;
-    u_char *buf;
     int i;
 
-    cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
-    if (!cfg_mem)
-       return CS_OUT_OF_RESOURCE;
-
-    tuple = &cfg_mem->tuple;
-    parse = &cfg_mem->parse;
-    cf = &parse->cftable_entry;
-    buf = cfg_mem->buf;
-
-    tuple->Attributes = tuple->TupleOffset = 0;
-    tuple->TupleData = (cisdata_t *)buf;
-    tuple->TupleDataMax = 255;
-    tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
-
     link->io.NumPorts1 = 16;
-    i = first_tuple(link, tuple, parse);
-    while (i != CS_NO_MORE_ITEMS) {
-       if (i == CS_SUCCESS) {
-           link->conf.ConfigIndex = cf->index;
-           link->io.BasePort1 = cf->io.win[0].base;
-           link->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
-           i = pcmcia_request_io(link, &link->io);
-           if (i == CS_SUCCESS) break;
-       }
-       i = next_tuple(link, tuple, parse);
-    }
-    if (i == CS_SUCCESS)
-       dev->base_addr = link->io.BasePort1;
+    i = pcmcia_loop_config(link, smc_configcheck, NULL);
+    if (!i)
+           dev->base_addr = link->io.BasePort1;
 
-    kfree(cfg_mem);
     return i;
 }
 
@@ -715,7 +690,7 @@ static int smc_setup(struct pcmcia_device *link)
 
     cfg_mem = kmalloc(sizeof(struct smc_cfg_mem), GFP_KERNEL);
     if (!cfg_mem)
-       return CS_OUT_OF_RESOURCE;
+           return -ENOMEM;
 
     tuple = &cfg_mem->tuple;
     parse = &cfg_mem->parse;
@@ -728,12 +703,12 @@ static int smc_setup(struct pcmcia_device *link)
     /* Check for a LAN function extension tuple */
     tuple->DesiredTuple = CISTPL_FUNCE;
     i = first_tuple(link, tuple, parse);
-    while (i == CS_SUCCESS) {
+    while (i == 0) {
        if (parse->funce.type == CISTPL_FUNCE_LAN_NODE_ID)
            break;
        i = next_tuple(link, tuple, parse);
     }
-    if (i == CS_SUCCESS) {
+    if (i == 0) {
        node_id = (cistpl_lan_node_id_t *)parse->funce.data;
        if (node_id->nb == 6) {
            for (i = 0; i < 6; i++)
@@ -780,9 +755,10 @@ static int osi_config(struct pcmcia_device *link)
     for (i = j = 0; j < 4; j++) {
        link->io.BasePort2 = com[j];
        i = pcmcia_request_io(link, &link->io);
-       if (i == CS_SUCCESS) break;
+       if (i == 0)
+               break;
     }
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        /* Fallback: turn off hard decode */
        link->conf.ConfigIndex = 0x03;
        link->io.NumPorts2 = 0;
@@ -815,13 +791,13 @@ static int osi_setup(struct pcmcia_device *link, u_short manfid, u_short cardid)
     /* Read the station address from tuple 0x90, subtuple 0x04 */
     tuple->DesiredTuple = 0x90;
     i = pcmcia_get_first_tuple(link, tuple);
-    while (i == CS_SUCCESS) {
+    while (i == 0) {
        i = pcmcia_get_tuple_data(link, tuple);
-       if ((i != CS_SUCCESS) || (buf[0] == 0x04))
+       if ((i != 0) || (buf[0] == 0x04))
            break;
        i = pcmcia_get_next_tuple(link, tuple);
     }
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        rc = -1;
        goto free_cfg_mem;
     }
@@ -959,8 +935,11 @@ static int check_sig(struct pcmcia_device *link)
 
 ======================================================================*/
 
-#define CS_EXIT_TEST(ret, svc, label) \
-if (ret != CS_SUCCESS) { cs_error(link, svc, ret); goto label; }
+#define CS_EXIT_TEST(ret, svc, label)  \
+if (ret != 0) {                                \
+       cs_error(link, svc, ret);       \
+       goto label;                     \
+}
 
 static int smc91c92_config(struct pcmcia_device *link)
 {
index c33a3d523566194a24dfba5289a823bd87217e1a..e1fd585e71315ea15ec07a6ed9b2e675db1df4d2 100644 (file)
@@ -377,7 +377,7 @@ first_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
 
        if ((err = pcmcia_get_first_tuple(handle, tuple)) == 0 &&
                        (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
-               err = pcmcia_parse_tuple(handle, tuple, parse);
+               err = pcmcia_parse_tuple(tuple, parse);
        return err;
 }
 
@@ -388,7 +388,7 @@ next_tuple(struct pcmcia_device *handle, tuple_t *tuple, cisparse_t *parse)
 
        if ((err = pcmcia_get_next_tuple(handle, tuple)) == 0 &&
                        (err = pcmcia_get_tuple_data(handle, tuple)) == 0)
-               err = pcmcia_parse_tuple(handle, tuple, parse);
+               err = pcmcia_parse_tuple(tuple, parse);
        return err;
 }
 
@@ -715,6 +715,47 @@ has_ce2_string(struct pcmcia_device * p_dev)
        return 0;
 }
 
+static int
+xirc2ps_config_modem(struct pcmcia_device *p_dev,
+                    cistpl_cftable_entry_t *cf,
+                    cistpl_cftable_entry_t *dflt,
+                    unsigned int vcc,
+                    void *priv_data)
+{
+       unsigned int ioaddr;
+
+       if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8) {
+               for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
+                       p_dev->io.BasePort2 = cf->io.win[0].base;
+                       p_dev->io.BasePort1 = ioaddr;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
+}
+
+static int
+xirc2ps_config_check(struct pcmcia_device *p_dev,
+                    cistpl_cftable_entry_t *cf,
+                    cistpl_cftable_entry_t *dflt,
+                    unsigned int vcc,
+                    void *priv_data)
+{
+       int *pass = priv_data;
+
+       if (cf->io.nwin > 0 && (cf->io.win[0].base & 0xf) == 8) {
+               p_dev->io.BasePort2 = cf->io.win[0].base;
+               p_dev->io.BasePort1 = p_dev->io.BasePort2
+                       + (*pass ? (cf->index & 0x20 ? -24:8)
+                          : (cf->index & 0x20 ?   8:-24));
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
+
+}
+
 /****************
  * xirc2ps_config() is scheduled to run after a CARD_INSERTION event
  * is received, to configure the PCMCIA socket, and to make the
@@ -725,13 +766,12 @@ xirc2ps_config(struct pcmcia_device * link)
 {
     struct net_device *dev = link->priv;
     local_info_t *local = netdev_priv(dev);
+    unsigned int ioaddr;
     tuple_t tuple;
     cisparse_t parse;
-    unsigned int ioaddr;
     int err, i;
     u_char buf[64];
     cistpl_lan_node_id_t *node_id = (cistpl_lan_node_id_t*)parse.funce.data;
-    cistpl_cftable_entry_t *cf = &parse.cftable_entry;
     DECLARE_MAC_BUF(mac);
 
     local->dingo_ccr = NULL;
@@ -846,19 +886,8 @@ xirc2ps_config(struct pcmcia_device * link)
            /* Take the Modem IO port from the CIS and scan for a free
             * Ethernet port */
            link->io.NumPorts1 = 16; /* no Mako stuff anymore */
-           tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-           for (err = first_tuple(link, &tuple, &parse); !err;
-                                err = next_tuple(link, &tuple, &parse)) {
-               if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8) {
-                   for (ioaddr = 0x300; ioaddr < 0x400; ioaddr += 0x10) {
-                       link->conf.ConfigIndex = cf->index ;
-                       link->io.BasePort2 = cf->io.win[0].base;
-                       link->io.BasePort1 = ioaddr;
-                       if (!(err=pcmcia_request_io(link, &link->io)))
-                           goto port_found;
-                   }
-               }
-           }
+           if (!pcmcia_loop_config(link, xirc2ps_config_modem, NULL))
+                   goto port_found;
        } else {
            link->io.NumPorts1 = 18;
            /* We do 2 passes here: The first one uses the regular mapping and
@@ -866,21 +895,9 @@ xirc2ps_config(struct pcmcia_device * link)
             * mirrored every 32 bytes. Actually we use a mirrored port for
             * the Mako if (on the first pass) the COR bit 5 is set.
             */
-           for (pass=0; pass < 2; pass++) {
-               tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-               for (err = first_tuple(link, &tuple, &parse); !err;
-                                    err = next_tuple(link, &tuple, &parse)){
-                   if (cf->io.nwin > 0  &&  (cf->io.win[0].base & 0xf) == 8){
-                       link->conf.ConfigIndex = cf->index ;
-                       link->io.BasePort2 = cf->io.win[0].base;
-                       link->io.BasePort1 = link->io.BasePort2
-                                   + (pass ? (cf->index & 0x20 ? -24:8)
-                                           : (cf->index & 0x20 ?   8:-24));
-                       if (!(err=pcmcia_request_io(link, &link->io)))
+           for (pass=0; pass < 2; pass++)
+                   if (!pcmcia_loop_config(link, xirc2ps_config_check, &pass))
                            goto port_found;
-                   }
-               }
-           }
            /* if special option:
             * try to configure as Ethernet only.
             * .... */
index 6671e2da0d572c07e09bdaffaf12f3d5da9af48b..d0ed1ef284a80404510e8f169537f40e4cb678a3 100644 (file)
@@ -55,6 +55,7 @@ EXPORT_SYMBOL(mdiobus_alloc);
 
 /**
  * mdiobus_release - mii_bus device release callback
+ * @d: the target struct device that contains the mii_bus
  *
  * Description: called when the last reference to an mii_bus is
  * dropped, to free the underlying memory.
index 17162748005893a86ca206faf95c5ec194be5eb5..f11e900b437b66044b422da02e26fe4a4efdeff6 100644 (file)
@@ -557,6 +557,7 @@ int genphy_restart_aneg(struct phy_device *phydev)
 
        return ctl;
 }
+EXPORT_SYMBOL(genphy_restart_aneg);
 
 
 /**
index c37ea436c9189adebf24bb579ba68e0659eae184..38116f9d41635c7cc23ad13a4e6b618b59cf5b06 100644 (file)
@@ -58,7 +58,7 @@
  */
 #if (PAGE_SHIFT == 12) || (PAGE_SHIFT == 13)   /* 4k & 8k pages */
 #define TX_DESC_PER_OAL ((MAX_SKB_FRAGS - TX_DESC_PER_IOCB) + 2)
-#elif (PAGE_SHIFT == 16)       /* 64k pages */
+#else /* all other page sizes */
 #define TX_DESC_PER_OAL 0
 #endif
 
index 297877b68c46740e81c49af69d21cc450c7daef3..4b2caa6b7ac5eba5a01d2cc9c3ddbe0611e3a573 100644 (file)
@@ -39,6 +39,7 @@
 #include <linux/delay.h>
 #include <linux/mm.h>
 #include <linux/vmalloc.h>
+#include <net/ip6_checksum.h>
 
 #include "qlge.h"
 
index ec871f646766dc7294101fe5ad7f789b66d3f0bb..c41d68761364550ebe2d2d8376f2a8c293b5d799 100644 (file)
@@ -29,7 +29,8 @@
  *
  *     Tigran Aivazian <tigran@sco.com>:       TLan_PciProbe() now uses
  *                                             new PCI BIOS interface.
- *     Alan Cox        <alan@redhat.com>:      Fixed the out of memory
+ *     Alan Cox        <alan@lxorguk.ukuu.org.uk>:
+ *                                             Fixed the out of memory
  *                                             handling.
  *
  *     Torben Mathiasen <torben.mathiasen@compaq.com> New Maintainer!
index fa73e6eed6be52ed1c9f7972f70e26a05112ad59..ed50d288e4940a79bdefca127a6c92d5713ab45d 100644 (file)
@@ -25,7 +25,7 @@
  *  To do:
  *    1. Multicast support.
  *
- *  Initial 2.5 cleanup Alan Cox <alan@redhat.com>  2002/10/28
+ *  Initial 2.5 cleanup Alan Cox <alan@lxorguk.ukuu.org.uk>  2002/10/28
  */
 
 #include <linux/module.h>
index f54c45049d50d86c700e3f18a5c2525321a662c9..124d5d690dde2508a29b8d5ae7bd907bcd259c38 100644 (file)
@@ -1688,6 +1688,7 @@ static void __devinit de21040_get_mac_address (struct de_private *de)
        unsigned i;
 
        dw32 (ROMCmd, 0);       /* Reset the pointer with a dummy write. */
+       udelay(5);
 
        for (i = 0; i < 6; i++) {
                int value, boguscnt = 100000;
index 656200472fa17aa3e5e8e5d592c4fc2fa1ff2077..8e46a513a252a8fecf48629e064a6f220bc7c100 100644 (file)
@@ -23,7 +23,7 @@
     Marcelo Tosatti <marcelo@conectiva.com.br> :
     Made it compile in 2.3 (device to net_device)
 
-    Alan Cox <alan@redhat.com> :
+    Alan Cox <alan@lxorguk.ukuu.org.uk> :
     Cleaned up for kernel merge.
     Removed the back compatibility support
     Reformatted, fixing spelling etc as I went
@@ -49,7 +49,7 @@
     support.  Updated PCI resource allocation.  Do not
     forget to unmap PCI mapped skbs.
 
-    Alan Cox <alan@redhat.com>
+    Alan Cox <alan@lxorguk.ukuu.org.uk>
     Added new PCI identifiers provided by Clear Zhang at ALi
     for their 1563 ethernet device.
 
index ad20f96edfa11e5d597881b49795c7967ee7e2a4..2dced383bcfb8a3f93ef4cfc69569f40105cdba5 100644 (file)
@@ -12,7 +12,7 @@
  *     Scatter gather
  *     More testing
  *
- * The changes are (c) Copyright 2004, Red Hat Inc. <alan@redhat.com>
+ * The changes are (c) Copyright 2004, Red Hat Inc. <alan@lxorguk.ukuu.org.uk>
  * Additional fixes and clean up: Francois Romieu
  *
  * This source has not been verified for use in safety critical systems.
index 243bd8d918fedfdf350fce7e0a1a3c0be8451b7d..ccd9cd35ecbe9e7f82ca370739415add9e4026b3 100644 (file)
@@ -18,7 +18,8 @@
  *     DMA now uses get_free_page as kmalloc buffers may span a 64K 
  *     boundary.
  *
- *     Modified for SMP safety and SMP locking by Alan Cox <alan@redhat.com>
+ *     Modified for SMP safety and SMP locking by Alan Cox
+ *                                     <alan@lxorguk.ukuu.org.uk>
  *
  *     Performance
  *
index 4f372396c5121a29a06b970d8ac865f2ed996556..85b3e785d484f31e942d5d5a47a349f02a3a0b22 100644 (file)
@@ -2,7 +2,7 @@
  *     Description of Z8530 Z85C30 and Z85230 communications chips
  *
  * Copyright (C) 1995 David S. Miller (davem@caip.rutgers.edu)
- * Copyright (C) 1998 Alan Cox <alan@redhat.com>
+ * Copyright (C) 1998 Alan Cox <alan@lxorguk.ukuu.org.uk>
  */
 
 #ifndef _Z8530_H
index fd72e427cb2830183b729fbae965ee88b5003da2..27696c20f4c2cf4d8fd10a8abaa41d843fd0974e 100644 (file)
@@ -206,126 +206,123 @@ static void airo_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int airo_cs_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cfg,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       win_req_t *req = priv_data;
+
+       if (cfg->index == 0)
+               return -ENODEV;
+
+       /* Does this card need audio output? */
+       if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
+       }
+
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+       else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+       /* Do we need to allocate an interrupt? */
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+       }
+
+       /* This reserves IO space but doesn't actually enable it */
+       if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
+               return -ENODEV;
+
+       /*
+         Now set up a common memory window, if needed.  There is room
+         in the struct pcmcia_device structure for one memory window handle,
+         but if the base addresses need to be saved, or if multiple
+         windows are needed, the info should go in the private data
+         structure for this device.
+
+         Note that the memory window base is a physical address, and
+         needs to be mapped to virtual space with ioremap() before it
+         is used.
+       */
+       if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
+               cistpl_mem_t *mem = (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
+               memreq_t map;
+               req->Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
+               req->Base = mem->win[0].host_addr;
+               req->Size = mem->win[0].len;
+               req->AccessSpeed = 0;
+               if (pcmcia_request_window(&p_dev, req, &p_dev->win) != 0)
+                       return -ENODEV;
+               map.Page = 0;
+               map.CardOffset = mem->win[0].card_addr;
+               if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
+                       return -ENODEV;
+       }
+       /* If we got this far, we're cool! */
+       return 0;
+}
+
+
 static int airo_config(struct pcmcia_device *link)
 {
-       tuple_t tuple;
-       cisparse_t parse;
        local_info_t *dev;
+       win_req_t *req;
        int last_fn, last_ret;
-       u_char buf[64];
-       win_req_t req;
-       memreq_t map;
 
        dev = link->priv;
 
        DEBUG(0, "airo_config(0x%p)\n", link);
 
+       req = kzalloc(sizeof(win_req_t), GFP_KERNEL);
+       if (!req)
+               return -ENOMEM;
+
+       /*
+        * In this loop, we scan the CIS for configuration table
+        * entries, each of which describes a valid card
+        * configuration, including voltage, IO window, memory window,
+        * and interrupt settings.
+        *
+        * We make no assumptions about the card to be configured: we
+        * use just the information available in the CIS.  In an ideal
+        * world, this would work for any PCMCIA card, but it requires
+        * a complete and accurate CIS.  In practice, a driver usually
+        * "knows" most of these things without consulting the CIS,
+        * and most client drivers will only use the CIS to fill in
+        * implementation-defined details.
+        */
+       last_ret = pcmcia_loop_config(link, airo_cs_config_check, req);
+       if (last_ret)
+               goto failed;
+
        /*
-         In this loop, we scan the CIS for configuration table entries,
-         each of which describes a valid card configuration, including
-         voltage, IO window, memory window, and interrupt settings.
-         
-         We make no assumptions about the card to be configured: we use
-         just the information available in the CIS.  In an ideal world,
-         this would work for any PCMCIA card, but it requires a complete
-         and accurate CIS.  In practice, a driver usually "knows" most of
-         these things without consulting the CIS, and most client drivers
-         will only use the CIS to fill in implementation-defined details.
+         Allocate an interrupt line.  Note that this does not assign a
+         handler to the interrupt, unless the 'Handler' member of the
+         irq structure is initialized.
        */
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t dflt = { 0 };
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-               
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-               if (cfg->index == 0) goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-               
-               /* Does this card need audio output? */
-               if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-                       link->conf.Attributes |= CONF_ENABLE_SPKR;
-                       link->conf.Status = CCSR_AUDIO_ENA;
-               }
-               
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
-               else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-               
-               /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-               
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 = link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-               }
-               
-               /* This reserves IO space but doesn't actually enable it */
-               if (pcmcia_request_io(link, &link->io) != 0)
-                       goto next_entry;
-               
-               /*
-                 Now set up a common memory window, if needed.  There is room
-                 in the struct pcmcia_device structure for one memory window handle,
-                 but if the base addresses need to be saved, or if multiple
-                 windows are needed, the info should go in the private data
-                 structure for this device.
-                 
-                 Note that the memory window base is a physical address, and
-                 needs to be mapped to virtual space with ioremap() before it
-                 is used.
-               */
-               if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
-                       cistpl_mem_t *mem =
-                               (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
-                       req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
-                       req.Base = mem->win[0].host_addr;
-                       req.Size = mem->win[0].len;
-                       req.AccessSpeed = 0;
-                       if (pcmcia_request_window(&link, &req, &link->win) != 0)
-                               goto next_entry;
-                       map.Page = 0; map.CardOffset = mem->win[0].card_addr;
-                       if (pcmcia_map_mem_page(link->win, &map) != 0)
-                               goto next_entry;
-               }
-               /* If we got this far, we're cool! */
-               break;
-               
-       next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
-       
-    /*
-      Allocate an interrupt line.  Note that this does not assign a
-      handler to the interrupt, unless the 'Handler' member of the
-      irq structure is initialized.
-    */
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
                CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
        
@@ -362,14 +359,17 @@ static int airo_config(struct pcmcia_device *link)
                printk(" & 0x%04x-0x%04x", link->io.BasePort2,
                       link->io.BasePort2+link->io.NumPorts2-1);
        if (link->win)
-               printk(", mem 0x%06lx-0x%06lx", req.Base,
-                      req.Base+req.Size-1);
+               printk(", mem 0x%06lx-0x%06lx", req->Base,
+                      req->Base+req->Size-1);
        printk("\n");
+       kfree(req);
        return 0;
 
  cs_failed:
        cs_error(link, last_fn, last_ret);
+ failed:
        airo_release(link);
+       kfree(req);
        return -ENODEV;
 } /* airo_config */
 
index d2388e8d179a440dce544ec598d857cc3e8b5b5f..77406245dc7b8fb171f82802bd8d4e494747f20e 100644 (file)
@@ -224,13 +224,58 @@ static int card_present(void *arg)
        return 0;
 }
 
+static int atmel_config_check(struct pcmcia_device *p_dev,
+                             cistpl_cftable_entry_t *cfg,
+                             cistpl_cftable_entry_t *dflt,
+                             unsigned int vcc,
+                             void *priv_data)
+{
+       if (cfg->index == 0)
+               return -ENODEV;
+
+       /* Does this card need audio output? */
+       if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
+       }
+
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+       else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+       /* Do we need to allocate an interrupt? */
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+       }
+
+       /* This reserves IO space but doesn't actually enable it */
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int atmel_config(struct pcmcia_device *link)
 {
-       tuple_t tuple;
-       cisparse_t parse;
        local_info_t *dev;
        int last_fn, last_ret;
-       u_char buf[64];
        struct pcmcia_device_id *did;
 
        dev = link->priv;
@@ -238,11 +283,6 @@ static int atmel_config(struct pcmcia_device *link)
 
        DEBUG(0, "atmel_config(0x%p)\n", link);
 
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-
        /*
          In this loop, we scan the CIS for configuration table entries,
          each of which describes a valid card configuration, including
@@ -255,66 +295,8 @@ static int atmel_config(struct pcmcia_device *link)
          these things without consulting the CIS, and most client drivers
          will only use the CIS to fill in implementation-defined details.
        */
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t dflt = { 0 };
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-               if (cfg->index == 0) goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-
-               /* Does this card need audio output? */
-               if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-                       link->conf.Attributes |= CONF_ENABLE_SPKR;
-                       link->conf.Status = CCSR_AUDIO_ENA;
-               }
-
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
-               else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-
-               /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 = link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-               }
-
-               /* This reserves IO space but doesn't actually enable it */
-               if (pcmcia_request_io(link, &link->io) != 0)
-                       goto next_entry;
-
-               /* If we got this far, we're cool! */
-               break;
-
-       next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
+       if (pcmcia_loop_config(link, atmel_config_check, NULL))
+               goto failed;
 
        /*
          Allocate an interrupt line.  Note that this does not assign a
@@ -360,6 +342,7 @@ static int atmel_config(struct pcmcia_device *link)
 
  cs_failed:
        cs_error(link, last_fn, last_ret);
+ failed:
        atmel_release(link);
        return -ENODEV;
 }
index b8aa16307f79135c89d23268926b64c3468355cc..3cfc30307a27d33f48ed8bbffc3e2da13a2cc686 100644 (file)
@@ -82,13 +82,13 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
        tuple.TupleOffset = 0;
 
        res = pcmcia_get_first_tuple(dev, &tuple);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_kfree_ssb;
        res = pcmcia_get_tuple_data(dev, &tuple);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_kfree_ssb;
-       res = pcmcia_parse_tuple(dev, &tuple, &parse);
-       if (res != CS_SUCCESS)
+       res = pcmcia_parse_tuple(&tuple, &parse);
+       if (res != 0)
                goto err_kfree_ssb;
 
        dev->conf.ConfigBase = parse.config.base;
@@ -107,13 +107,13 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
        win.Size = SSB_CORE_SIZE;
        win.AccessSpeed = 250;
        res = pcmcia_request_window(&dev, &win, &dev->win);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_kfree_ssb;
 
        mem.CardOffset = 0;
        mem.Page = 0;
        res = pcmcia_map_mem_page(dev->win, &mem);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_disable;
 
        dev->irq.Attributes = IRQ_TYPE_DYNAMIC_SHARING;
@@ -121,11 +121,11 @@ static int __devinit b43_pcmcia_probe(struct pcmcia_device *dev)
        dev->irq.Handler = NULL; /* The handler is registered later. */
        dev->irq.Instance = NULL;
        res = pcmcia_request_irq(dev, &dev->irq);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_disable;
 
        res = pcmcia_request_configuration(dev, &dev->conf);
-       if (res != CS_SUCCESS)
+       if (res != 0)
                goto err_disable;
 
        err = ssb_bus_pcmciabus_register(ssb, dev, win.Base);
index 3b4e55cf33cd4a071b57a35144b4a3aa3b6883af..633740277352314f16ff1b995747be09d072bdb4 100644 (file)
@@ -234,7 +234,7 @@ static void sandisk_set_iobase(local_info_t *local)
        reg.Value = hw_priv->link->io.BasePort1 & 0x00ff;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 0 -"
                       " res=%d\n", res);
        }
@@ -246,7 +246,7 @@ static void sandisk_set_iobase(local_info_t *local)
        reg.Value = (hw_priv->link->io.BasePort1 & 0xff00) >> 8;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "Prism3 SanDisk - failed to set I/O base 1 -"
                       " res=%d\n", res);
        }
@@ -305,7 +305,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
        tuple.DesiredTuple = CISTPL_LONGLINK_MFC;
        if (pcmcia_get_first_tuple(hw_priv->link, &tuple) ||
            pcmcia_get_tuple_data(hw_priv->link, &tuple) ||
-           pcmcia_parse_tuple(hw_priv->link, &tuple, parse) ||
+           pcmcia_parse_tuple(&tuple, parse) ||
                parse->longlink_mfc.nfn < 2) {
                /* No multi-function links found */
                ret = -ENODEV;
@@ -322,7 +322,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
        reg.Value = COR_SOFT_RESET;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
                goto done;
@@ -339,7 +339,7 @@ static int sandisk_enable_wireless(struct net_device *dev)
        reg.Value = COR_LEVEL_REQ | 0x8 | COR_ADDR_DECODE | COR_FUNC_ENA;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "%s: SanDisk - COR sreset failed (%d)\n",
                       dev->name, res);
                goto done;
@@ -374,7 +374,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
        reg.Value = 0;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 1 (%d)\n",
                       res);
                return;
@@ -386,7 +386,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
        reg.Value |= COR_SOFT_RESET;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 2 (%d)\n",
                       res);
                return;
@@ -399,7 +399,7 @@ static void prism2_pccard_cor_sreset(local_info_t *local)
                reg.Value |= COR_IREQ_ENA;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_cor_sreset failed 3 (%d)\n",
                       res);
                return;
@@ -433,7 +433,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Value = 0;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 1 "
                       "(%d)\n", res);
                return;
@@ -446,7 +446,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Value |= COR_SOFT_RESET;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 2 "
                       "(%d)\n", res);
                return;
@@ -460,7 +460,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Offset = CISREG_CCSR;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 3 "
                       "(%d)\n", res);
                return;
@@ -472,7 +472,7 @@ static void prism2_pccard_genesis_reset(local_info_t *local, int hcr)
        reg.Value = old_cor & ~COR_SOFT_RESET;
        res = pcmcia_access_configuration_register(hw_priv->link,
                                                   &reg);
-       if (res != CS_SUCCESS) {
+       if (res != 0) {
                printk(KERN_DEBUG "prism2_pccard_genesis_sreset failed 4 "
                       "(%d)\n", res);
                return;
@@ -532,145 +532,118 @@ static void prism2_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
-#define CFG_CHECK2(fn, retf) \
-do { int _ret = (retf); \
-if (_ret != 0) { \
-       PDEBUG(DEBUG_EXTRA, "CardServices(" #fn ") returned %d\n", _ret); \
-       cs_error(link, fn, _ret); \
-       goto next_entry; \
-} \
-} while (0)
-
 
 /* run after a CARD_INSERTION event is received to configure the PCMCIA
  * socket and make the device available to the system */
+
+static int prism2_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cfg,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
+{
+       if (cfg->index == 0)
+               return -ENODEV;
+
+       PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
+              "(default 0x%02X)\n", cfg->index, dflt->index);
+
+       /* Does this card need audio output? */
+       if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
+       }
+
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
+                   10000 && !ignore_cis_vcc) {
+                       PDEBUG(DEBUG_EXTRA, "  Vcc mismatch - skipping"
+                              " this entry\n");
+                       return -ENODEV;
+               }
+       } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] /
+                   10000 && !ignore_cis_vcc) {
+                       PDEBUG(DEBUG_EXTRA, "  Vcc (default) mismatch "
+                              "- skipping this entry\n");
+                       return -ENODEV;
+               }
+       }
+
+       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp = dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       /* Do we need to allocate an interrupt? */
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       else if (!(p_dev->conf.Attributes & CONF_ENABLE_IRQ)) {
+               /* At least Compaq WL200 does not have IRQInfo1 set,
+                * but it does not work without interrupts.. */
+               printk(KERN_WARNING "Config has no IRQ info, but trying to "
+                      "enable IRQ anyway..\n");
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+       }
+
+       /* IO window settings */
+       PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
+              "dflt->io.nwin=%d\n",
+              cfg->io.nwin, dflt->io.nwin);
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
+                      "io.base=0x%04x, len=%d\n", io->flags,
+                      io->win[0].base, io->win[0].len);
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.IOAddrLines = io->flags &
+                       CISTPL_IO_LINES_MASK;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+       }
+
+       /* This reserves IO space but doesn't actually enable it */
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int prism2_config(struct pcmcia_device *link)
 {
        struct net_device *dev;
        struct hostap_interface *iface;
        local_info_t *local;
        int ret = 1;
-       tuple_t tuple;
-       cisparse_t *parse;
        int last_fn, last_ret;
-       u_char buf[64];
-       config_info_t conf;
-       cistpl_cftable_entry_t dflt = { 0 };
        struct hostap_cs_priv *hw_priv;
 
        PDEBUG(DEBUG_FLOW, "prism2_config()\n");
 
-       parse = kmalloc(sizeof(cisparse_t), GFP_KERNEL);
        hw_priv = kzalloc(sizeof(*hw_priv), GFP_KERNEL);
-       if (parse == NULL || hw_priv == NULL) {
+       if (hw_priv == NULL) {
                ret = -ENOMEM;
                goto failed;
        }
 
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-
-       CS_CHECK(GetConfigurationInfo,
-                pcmcia_get_configuration_info(link, &conf));
-
        /* Look for an appropriate configuration table entry in the CIS */
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       for (;;) {
-               cistpl_cftable_entry_t *cfg = &(parse->cftable_entry);
-               CFG_CHECK2(GetTupleData,
-                          pcmcia_get_tuple_data(link, &tuple));
-               CFG_CHECK2(ParseTuple,
-                          pcmcia_parse_tuple(link, &tuple, parse));
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       dflt = *cfg;
-               if (cfg->index == 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-               PDEBUG(DEBUG_EXTRA, "Checking CFTABLE_ENTRY 0x%02X "
-                      "(default 0x%02X)\n", cfg->index, dflt.index);
-
-               /* Does this card need audio output? */
-               if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-                       link->conf.Attributes |= CONF_ENABLE_SPKR;
-                       link->conf.Status = CCSR_AUDIO_ENA;
-               }
-
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] /
-                           10000 && !ignore_cis_vcc) {
-                               PDEBUG(DEBUG_EXTRA, "  Vcc mismatch - skipping"
-                                      " this entry\n");
-                               goto next_entry;
-                       }
-               } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] /
-                           10000 && !ignore_cis_vcc) {
-                               PDEBUG(DEBUG_EXTRA, "  Vcc (default) mismatch "
-                                      "- skipping this entry\n");
-                               goto next_entry;
-                       }
-               }
-
-               if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
-
-               /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-               else if (!(link->conf.Attributes & CONF_ENABLE_IRQ)) {
-                       /* At least Compaq WL200 does not have IRQInfo1 set,
-                        * but it does not work without interrupts.. */
-                       printk("Config has no IRQ info, but trying to enable "
-                              "IRQ anyway..\n");
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-               }
-
-               /* IO window settings */
-               PDEBUG(DEBUG_EXTRA, "IO window settings: cfg->io.nwin=%d "
-                      "dflt.io.nwin=%d\n",
-                      cfg->io.nwin, dflt.io.nwin);
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       PDEBUG(DEBUG_EXTRA, "io->flags = 0x%04X, "
-                              "io.base=0x%04x, len=%d\n", io->flags,
-                              io->win[0].base, io->win[0].len);
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.IOAddrLines = io->flags &
-                               CISTPL_IO_LINES_MASK;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 = link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-               }
-
-               /* This reserves IO space but doesn't actually enable it */
-               CFG_CHECK2(RequestIO,
-                          pcmcia_request_io(link, &link->io));
-
-               /* This configuration table entry is OK */
-               break;
-
-       next_entry:
-               CS_CHECK(GetNextTuple,
-                        pcmcia_get_next_tuple(link, &tuple));
+       last_ret = pcmcia_loop_config(link, prism2_config_check, NULL);
+       if (last_ret) {
+               if (!ignore_cis_vcc)
+                       printk(KERN_ERR "GetNextTuple(): No matching "
+                              "CIS configuration.  Maybe you need the "
+                              "ignore_cis_vcc=1 parameter.\n");
+               cs_error(link, RequestIO, last_ret);
+               goto failed;
        }
 
        /* Need to allocate net_device before requesting IRQ handler */
@@ -738,14 +711,12 @@ static int prism2_config(struct pcmcia_device *link)
                if (ret == 0 && local->ddev)
                        strcpy(hw_priv->node.dev_name, local->ddev->name);
        }
-       kfree(parse);
        return ret;
 
  cs_failed:
        cs_error(link, last_fn, last_ret);
 
  failed:
-       kfree(parse);
        kfree(hw_priv);
        prism2_release((u_long)link);
        return ret;
index e3505c110af696f2bd81ae32983c7f9e52b03762..842a08d1f1063427a1550062c436b62e2fde8701 100644 (file)
@@ -791,7 +791,7 @@ static int if_cs_probe(struct pcmcia_device *p_dev)
        tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
        if ((ret = pcmcia_get_first_tuple(p_dev, &tuple)) != 0 ||
            (ret = pcmcia_get_tuple_data(p_dev, &tuple)) != 0 ||
-           (ret = pcmcia_parse_tuple(p_dev, &tuple, &parse)) != 0)
+           (ret = pcmcia_parse_tuple(&tuple, &parse)) != 0)
        {
                lbs_pr_err("error in pcmcia_get_first_tuple etc\n");
                goto out1;
index 25bae7933aa587fa22ba5b4b402c80011f3f49bf..a670f36b5f3f3c1e3222d0e45c27491132caed7d 100644 (file)
@@ -749,9 +749,10 @@ static int netwave_pcmcia_config(struct pcmcia_device *link) {
     for (i = j = 0x0; j < 0x400; j += 0x20) {
        link->io.BasePort1 = j ^ 0x300;
        i = pcmcia_request_io(link, &link->io);
-       if (i == CS_SUCCESS) break;
+       if (i == 0)
+               break;
     }
-    if (i != CS_SUCCESS) {
+    if (i != 0) {
        cs_error(link, RequestIO, i);
        goto failed;
     }
index 9eaa252c2430b441bf6671a9a9a354ad9bbe4c0d..e585684e59a00012025c1e10990c979a8f0bf0eb 100644 (file)
@@ -80,7 +80,7 @@ orinoco_cs_hard_reset(struct orinoco_private *priv)
        /* We need atomic ops here, because we're not holding the lock */
        set_bit(0, &card->hard_reset_in_progress);
 
-       err = pcmcia_reset_card(link, NULL);
+       err = pcmcia_reset_card(link->socket);
        if (err)
                return err;
 
@@ -165,6 +165,70 @@ static void orinoco_cs_detach(struct pcmcia_device *link)
                last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; \
        } while (0)
 
+static int orinoco_cs_config_check(struct pcmcia_device *p_dev,
+                                  cistpl_cftable_entry_t *cfg,
+                                  cistpl_cftable_entry_t *dflt,
+                                  unsigned int vcc,
+                                  void *priv_data)
+{
+       if (cfg->index == 0)
+               goto next_entry;
+
+       /* Use power settings for Vcc and Vpp if present */
+       /* Note that the CIS values need to be rescaled */
+       if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                       DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n",  vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
+                       if (!ignore_cis_vcc)
+                               goto next_entry;
+               }
+       } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                       DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n",  vcc, dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
+                       if (!ignore_cis_vcc)
+                               goto next_entry;
+               }
+       }
+
+       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       /* Do we need to allocate an interrupt? */
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+
+               /* This reserves IO space but doesn't actually enable it */
+               if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
+                       goto next_entry;
+       }
+       return 0;
+
+next_entry:
+       pcmcia_disable_device(p_dev);
+       return -ENODEV;
+};
+
 static int
 orinoco_cs_config(struct pcmcia_device *link)
 {
@@ -173,16 +237,8 @@ orinoco_cs_config(struct pcmcia_device *link)
        struct orinoco_pccard *card = priv->card;
        hermes_t *hw = &priv->hw;
        int last_fn, last_ret;
-       u_char buf[64];
-       config_info_t conf;
-       tuple_t tuple;
-       cisparse_t parse;
        void __iomem *mem;
 
-       /* Look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo,
-                pcmcia_get_configuration_info(link, &conf));
-
        /*
         * In this loop, we scan the CIS for configuration table
         * entries, each of which describes a valid card
@@ -197,94 +253,14 @@ orinoco_cs_config(struct pcmcia_device *link)
         * and most client drivers will only use the CIS to fill in
         * implementation-defined details.
         */
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-               cistpl_cftable_entry_t dflt = { .index = 0 };
-
-               if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
-                   || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
-                       goto next_entry;
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       dflt = *cfg;
-               if (cfg->index == 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-
-               /* Use power settings for Vcc and Vpp if present */
-               /* Note that the CIS values need to be rescaled */
-               if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, cfg CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
-                               if (!ignore_cis_vcc)
-                                       goto next_entry;
-                       }
-               } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "orinoco_cs_config: Vcc mismatch (conf.Vcc = %d, dflt CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
-                               if(!ignore_cis_vcc)
-                                       goto next_entry;
-                       }
-               }
-
-               if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                           cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                           dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               
-               /* Do we need to allocate an interrupt? */
-               link->conf.Attributes |= CONF_ENABLE_IRQ;
-
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io =
-                           (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 =
-                                   IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 =
-                                   IO_DATA_PATH_WIDTH_8;
-                       link->io.IOAddrLines =
-                           io->flags & CISTPL_IO_LINES_MASK;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 =
-                                   link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-
-                       /* This reserves IO space but doesn't actually enable it */
-                       if (pcmcia_request_io(link, &link->io) != 0)
-                               goto next_entry;
-               }
-
-
-               /* If we got this far, we're cool! */
-
-               break;
-               
-       next_entry:
-               pcmcia_disable_device(link);
-               last_ret = pcmcia_get_next_tuple(link, &tuple);
-               if (last_ret  == CS_NO_MORE_ITEMS) {
+       last_ret = pcmcia_loop_config(link, orinoco_cs_config_check, NULL);
+       if (last_ret) {
+               if (!ignore_cis_vcc)
                        printk(KERN_ERR PFX "GetNextTuple(): No matching "
                               "CIS configuration.  Maybe you need the "
                               "ignore_cis_vcc=1 parameter.\n");
-                       goto cs_failed;
-               }
+               cs_error(link, RequestIO, last_ret);
+               goto failed;
        }
 
        /*
@@ -335,7 +311,6 @@ orinoco_cs_config(struct pcmcia_device *link)
               "0x%04x-0x%04x\n", dev->name, dev->dev.parent->bus_id,
               link->irq.AssignedIRQ, link->io.BasePort1,
               link->io.BasePort1 + link->io.NumPorts1 - 1);
-
        return 0;
 
  cs_failed:
index 44da0d19b5c8d9c0ed8a96d5996e88c5d2b452fe..1404a57175207f71d39ac28b12ad78651610d0c1 100644 (file)
@@ -798,9 +798,9 @@ static void ray_release(struct pcmcia_device *link)
     iounmap(local->amem);
     /* Do bother checking to see if these succeed or not */
     i = pcmcia_release_window(local->amem_handle);
-    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
+    if ( i != 0 ) DEBUG(0,"ReleaseWindow(local->amem) ret = %x\n",i);
     i = pcmcia_release_window(local->rmem_handle);
-    if ( i != CS_SUCCESS ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
+    if ( i != 0 ) DEBUG(0,"ReleaseWindow(local->rmem) ret = %x\n",i);
     pcmcia_disable_device(link);
 
     DEBUG(2,"ray_release ending\n");
index 67b26d3c3cd50548a1b4639ffb949b4345a98906..b0c71c3be46769f3f08318c2bb81e51dee195f87 100644 (file)
@@ -235,6 +235,70 @@ static void spectrum_cs_detach(struct pcmcia_device *link)
  * device available to the system.
  */
 
+static int spectrum_cs_config_check(struct pcmcia_device *p_dev,
+                                   cistpl_cftable_entry_t *cfg,
+                                   cistpl_cftable_entry_t *dflt,
+                                   unsigned int vcc,
+                                   void *priv_data)
+{
+       if (cfg->index == 0)
+               goto next_entry;
+
+       /* Use power settings for Vcc and Vpp if present */
+       /* Note that the CIS values need to be rescaled */
+       if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                       DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n",  vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
+                       if (!ignore_cis_vcc)
+                               goto next_entry;
+               }
+       } else if (dflt->vcc.present & (1 << CISTPL_POWER_VNOM)) {
+               if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM] / 10000) {
+                       DEBUG(2, "spectrum_cs_config: Vcc mismatch (vcc = %d, CIS = %d)\n",  vcc, dflt->vcc.param[CISTPL_POWER_VNOM] / 10000);
+                       if (!ignore_cis_vcc)
+                               goto next_entry;
+               }
+       }
+
+       if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+       else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       /* Do we need to allocate an interrupt? */
+       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               if (!(io->flags & CISTPL_IO_8BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+               if (!(io->flags & CISTPL_IO_16BIT))
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin > 1) {
+                       p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+
+               /* This reserves IO space but doesn't actually enable it */
+               if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
+                       goto next_entry;
+       }
+       return 0;
+
+next_entry:
+       pcmcia_disable_device(p_dev);
+       return -ENODEV;
+};
+
 static int
 spectrum_cs_config(struct pcmcia_device *link)
 {
@@ -243,16 +307,8 @@ spectrum_cs_config(struct pcmcia_device *link)
        struct orinoco_pccard *card = priv->card;
        hermes_t *hw = &priv->hw;
        int last_fn, last_ret;
-       u_char buf[64];
-       config_info_t conf;
-       tuple_t tuple;
-       cisparse_t parse;
        void __iomem *mem;
 
-       /* Look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo,
-                pcmcia_get_configuration_info(link, &conf));
-
        /*
         * In this loop, we scan the CIS for configuration table
         * entries, each of which describes a valid card
@@ -267,94 +323,14 @@ spectrum_cs_config(struct pcmcia_device *link)
         * and most client drivers will only use the CIS to fill in
         * implementation-defined details.
         */
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
-               cistpl_cftable_entry_t dflt = { .index = 0 };
-
-               if ( (pcmcia_get_tuple_data(link, &tuple) != 0)
-                   || (pcmcia_parse_tuple(link, &tuple, &parse) != 0))
-                       goto next_entry;
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       dflt = *cfg;
-               if (cfg->index == 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = cfg->index;
-
-               /* Use power settings for Vcc and Vpp if present */
-               /* Note that the CIS values need to be rescaled */
-               if (cfg->vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, cfg->vcc.param[CISTPL_POWER_VNOM] / 10000);
-                               if (!ignore_cis_vcc)
-                                       goto next_entry;
-                       }
-               } else if (dflt.vcc.present & (1 << CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM] / 10000) {
-                               DEBUG(2, "spectrum_cs_config: Vcc mismatch (conf.Vcc = %d, CIS = %d)\n",  conf.Vcc, dflt.vcc.param[CISTPL_POWER_VNOM] / 10000);
-                               if(!ignore_cis_vcc)
-                                       goto next_entry;
-                       }
-               }
-
-               if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                           cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                           dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               
-               /* Do we need to allocate an interrupt? */
-               link->conf.Attributes |= CONF_ENABLE_IRQ;
-
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io =
-                           (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
-                       if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 =
-                                   IO_DATA_PATH_WIDTH_16;
-                       if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 =
-                                   IO_DATA_PATH_WIDTH_8;
-                       link->io.IOAddrLines =
-                           io->flags & CISTPL_IO_LINES_MASK;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin > 1) {
-                               link->io.Attributes2 =
-                                   link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-
-                       /* This reserves IO space but doesn't actually enable it */
-                       if (pcmcia_request_io(link, &link->io) != 0)
-                               goto next_entry;
-               }
-
-
-               /* If we got this far, we're cool! */
-
-               break;
-               
-       next_entry:
-               pcmcia_disable_device(link);
-               last_ret = pcmcia_get_next_tuple(link, &tuple);
-               if (last_ret  == CS_NO_MORE_ITEMS) {
+       last_ret = pcmcia_loop_config(link, spectrum_cs_config_check, NULL);
+       if (last_ret) {
+               if (!ignore_cis_vcc)
                        printk(KERN_ERR PFX "GetNextTuple(): No matching "
                               "CIS configuration.  Maybe you need the "
                               "ignore_cis_vcc=1 parameter.\n");
-                       goto cs_failed;
-               }
+               cs_error(link, RequestIO, last_ret);
+               goto failed;
        }
 
        /*
index 136220b5ca81a389fee29bf0a28d622723c0d927..e939a73ff794a731583292d5e41e7e8a23f64d8e 100644 (file)
@@ -4387,7 +4387,7 @@ MODULE_LICENSE("GPL");
  *
  * Thanks go also to:
  *     James Ashton (jaa101@syseng.anu.edu.au),
- *     Alan Cox (alan@redhat.com),
+ *     Alan Cox (alan@lxorguk.ukuu.org.uk),
  *     Allan Creighton (allanc@cs.usyd.edu.au),
  *     Matthew Geier (matthew@cs.usyd.edu.au),
  *     Remo di Giovanni (remo@cs.usyd.edu.au),
index b33ac47dd8df710956340f9cd258e6b6e1c4cd23..44d31bbf39e49d57409b5f41a3e487040974d1e6 100644 (file)
  *
  * Thanks go also to:
  *     James Ashton <jaa101@syseng.anu.edu.au>,
- *     Alan Cox <alan@redhat.com>,
+ *     Alan Cox <alan@lxorguk.ukuu.org.uk>,
  *     Allan Creighton <allanc@cs.usyd.edu.au>,
  *     Matthew Geier <matthew@cs.usyd.edu.au>,
  *     Remo di Giovanni <remo@cs.usyd.edu.au>,
index b5de38a9b791bd3611678051e8d26d1d252e627b..e124b1d6267afa03cc5e3c149d8ab77080159b2c 100644 (file)
@@ -3702,7 +3702,7 @@ wv_pcmcia_reset(struct net_device *       dev)
 #endif
 
   i = pcmcia_access_configuration_register(link, &reg);
-  if(i != CS_SUCCESS)
+  if (i != 0)
     {
       cs_error(link, AccessConfigurationRegister, i);
       return FALSE;
@@ -3716,7 +3716,7 @@ wv_pcmcia_reset(struct net_device *       dev)
   reg.Action = CS_WRITE;
   reg.Value = reg.Value | COR_SW_RESET;
   i = pcmcia_access_configuration_register(link, &reg);
-  if(i != CS_SUCCESS)
+  if (i != 0)
     {
       cs_error(link, AccessConfigurationRegister, i);
       return FALSE;
@@ -3725,7 +3725,7 @@ wv_pcmcia_reset(struct net_device *       dev)
   reg.Action = CS_WRITE;
   reg.Value = COR_LEVEL_IRQ | COR_CONFIG;
   i = pcmcia_access_configuration_register(link, &reg);
-  if(i != CS_SUCCESS)
+  if (i != 0)
     {
       cs_error(link, AccessConfigurationRegister, i);
       return FALSE;
@@ -3903,7 +3903,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
   do
     {
       i = pcmcia_request_io(link, &link->io);
-      if(i != CS_SUCCESS)
+      if (i != 0)
        {
          cs_error(link, RequestIO, i);
          break;
@@ -3914,7 +3914,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
        * actually assign a handler to the interrupt.
        */
       i = pcmcia_request_irq(link, &link->irq);
-      if(i != CS_SUCCESS)
+      if (i != 0)
        {
          cs_error(link, RequestIRQ, i);
          break;
@@ -3926,7 +3926,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
        */
       link->conf.ConfigIndex = 1;
       i = pcmcia_request_configuration(link, &link->conf);
-      if(i != CS_SUCCESS)
+      if (i != 0)
        {
          cs_error(link, RequestConfiguration, i);
          break;
@@ -3942,7 +3942,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
       req.Base = req.Size = 0;
       req.AccessSpeed = mem_speed;
       i = pcmcia_request_window(&link, &req, &link->win);
-      if(i != CS_SUCCESS)
+      if (i != 0)
        {
          cs_error(link, RequestWindow, i);
          break;
@@ -3954,7 +3954,7 @@ wv_pcmcia_config(struct pcmcia_device *   link)
 
       mem.CardOffset = 0; mem.Page = 0;
       i = pcmcia_map_mem_page(link->win, &mem);
-      if(i != CS_SUCCESS)
+      if (i != 0)
        {
          cs_error(link, MapMemPage, i);
          break;
index 74a5ad2f1223cc23c21c7e593a3f42b8ebd3e41f..68789c6e1ce9ac96cb180b7c8a6d798719764294 100644 (file)
@@ -1977,10 +1977,10 @@ static int wl3501_config(struct pcmcia_device *link)
                link->io.BasePort1 = j;
                link->io.BasePort2 = link->io.BasePort1 + 0x10;
                i = pcmcia_request_io(link, &link->io);
-               if (i == CS_SUCCESS)
+               if (i == 0)
                        break;
        }
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIO, i);
                goto failed;
        }
index 00e1d9620f7cbca16e94f12bd932bba8f2b1b1e0..b1899e9c1f6573091309b71b68ec017e9ab53599 100644 (file)
@@ -149,52 +149,44 @@ static void parport_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int parport_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cfg,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               if (epp_mode)
+                       p_dev->conf.ConfigIndex |= FORCE_EPP_MODE;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               if (io->nwin == 2) {
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+               if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
+                       return -ENODEV;
+               return 0;
+       }
+       return -ENODEV;
+}
+
 static int parport_config(struct pcmcia_device *link)
 {
     parport_info_t *info = link->priv;
-    tuple_t tuple;
-    u_short buf[128];
-    cisparse_t parse;
-    cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
-    cistpl_cftable_entry_t dflt = { 0 };
     struct parport *p;
     int last_ret, last_fn;
-    
+
     DEBUG(0, "parport_config(0x%p)\n", link);
-    
-    tuple.TupleData = (cisdata_t *)buf;
-    tuple.TupleOffset = 0; tuple.TupleDataMax = 255;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    tuple.Attributes = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (1) {
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-           goto next_entry;
-
-       if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-           cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-           link->conf.ConfigIndex = cfg->index;
-           if (epp_mode)
-               link->conf.ConfigIndex |= FORCE_EPP_MODE;
-           link->io.BasePort1 = io->win[0].base;
-           link->io.NumPorts1 = io->win[0].len;
-           link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-           if (io->nwin == 2) {
-               link->io.BasePort2 = io->win[1].base;
-               link->io.NumPorts2 = io->win[1].len;
-           }
-           if (pcmcia_request_io(link, &link->io) != 0)
-               goto next_entry;
-           /* If we've got this far, we're done */
-           break;
-       }
-       
-    next_entry:
-       if (cfg->flags & CISTPL_CFTABLE_DEFAULT) dflt = *cfg;
-       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+
+    last_ret = pcmcia_loop_config(link, parport_config_check, NULL);
+    if (last_ret) {
+           cs_error(link, RequestIO, last_ret);
+           goto failed;
     }
-    
+
     CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
     CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
 
index a87902de8d3b9ec187b66a69c9ea97931577c504..74d1c906c5d6f61cff812db070ac3bda68e19299 100644 (file)
@@ -2,10 +2,6 @@
 # Makefile for the kernel pcmcia subsystem (c/o David Hinds)
 #
 
-ifeq ($(CONFIG_PCMCIA_DEBUG),y)
-EXTRA_CFLAGS += -DDEBUG
-endif
-
 pcmcia_core-y                                  += cs.o cistpl.o rsrc_mgr.o socket_sysfs.o
 pcmcia_core-$(CONFIG_CARDBUS)                  += cardbus.o
 obj-$(CONFIG_PCCARD)                           += pcmcia_core.o
index 75e8f8505e47230156103ccb784a606ed43b8698..fc1de46fd20a0f5317389861380c0903858fee5a 100644 (file)
@@ -292,7 +292,7 @@ au1x00_pcmcia_set_io_map(struct pcmcia_socket *sock, struct pccard_io_map *map)
                skt->spd_io[map->map] = speed;
        }
 
-       map->start=(ioaddr_t)(u32)skt->virt_io;
+       map->start=(unsigned int)(u32)skt->virt_io;
        map->stop=map->start+MAP_SIZE;
        return 0;
 
index a53ef5902518d88e7434b456a4d5b54eb0f90663..13a4fbc587116e076e34ccd981deaa36d9ac4e3f 100644 (file)
@@ -116,7 +116,7 @@ struct au1000_pcmcia_socket {
        struct resource         res_attr;
 
        void *                  virt_io;
-       ioaddr_t                phys_io;
+       unsigned int            phys_io;
        unsigned int            phys_attr;
        unsigned int            phys_mem;
        unsigned short          speed_io, speed_attr, speed_mem;
index aa1cd4d3aa292c4e840a4b09471b6068a81f9385..d6b4bd1db7d7e6b9edbb5a3117070cc0f718df58 100644 (file)
@@ -37,7 +37,6 @@
 #include <pcmcia/ss.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/bus_ops.h>
-#include "cs_internal.h"
 
 #include <asm/io.h>
 #include <asm/irq.h>
index 8a9b18cee847e980881c1f0536925fca0bbcc52f..9627390835caa2cd28b97090ec90d76cf37bf5e2 100644 (file)
@@ -41,7 +41,6 @@
 #include <pcmcia/ss.h>
 #include <pcmcia/cistpl.h>
 #include <pcmcia/bus_ops.h>
-#include "cs_internal.h"
 
 #include <asm/io.h>
 #include <asm/irq.h>
index 911ca0e8dfc29b94498fec85b10c73cb33be7aef..db77e1f3309a087a6c93c06d251284981df80311 100644 (file)
@@ -238,7 +238,7 @@ int __ref cb_alloc(struct pcmcia_socket * s)
        pci_bus_add_devices(bus);
 
        s->irq.AssignedIRQ = s->pci_irq;
-       return CS_SUCCESS;
+       return 0;
 }
 
 void cb_free(struct pcmcia_socket * s)
index 65129b54eb09c309ef87e9ebf94a3c60869efdd9..dcce9f5d84654a0612f99ed9bbe85813d53966f5 100644 (file)
@@ -92,7 +92,8 @@ set_cis_map(struct pcmcia_socket *s, unsigned int card_offset, unsigned int flag
        if (!(s->features & SS_CAP_STATIC_MAP) && (mem->res == NULL)) {
                mem->res = pcmcia_find_mem_region(0, s->map_size, s->map_size, 0, s);
                if (mem->res == NULL) {
-                       printk(KERN_NOTICE "cs: unable to map card memory!\n");
+                       dev_printk(KERN_NOTICE, &s->dev,
+                                  "cs: unable to map card memory!\n");
                        return NULL;
                }
                s->cis_virt = NULL;
@@ -265,13 +266,13 @@ EXPORT_SYMBOL(pcmcia_write_cis_mem);
 ======================================================================*/
 
 static void read_cis_cache(struct pcmcia_socket *s, int attr, u_int addr,
-                          u_int len, void *ptr)
+                          size_t len, void *ptr)
 {
     struct cis_cache_entry *cis;
     int ret;
 
     if (s->fake_cis) {
-       if (s->fake_cis_len > addr+len)
+       if (s->fake_cis_len >= addr+len)
            memcpy(ptr, s->fake_cis+addr, len);
        else
            memset(ptr, 0xff, len);
@@ -351,7 +352,9 @@ int verify_cis_cache(struct pcmcia_socket *s)
 
        buf = kmalloc(256, GFP_KERNEL);
        if (buf == NULL)
-               return -1;
+               dev_printk(KERN_WARNING, &s->dev,
+                          "no memory for verifying CIS\n");
+               return -ENOMEM;
        list_for_each_entry(cis, &s->cis_cache, node) {
                int len = cis->len;
 
@@ -380,18 +383,22 @@ int verify_cis_cache(struct pcmcia_socket *s)
     
 ======================================================================*/
 
-int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis)
+int pcmcia_replace_cis(struct pcmcia_socket *s,
+                      const u8 *data, const size_t len)
 {
-    kfree(s->fake_cis);
-    s->fake_cis = NULL;
-    if (cis->Length > CISTPL_MAX_CIS_SIZE)
-       return CS_BAD_SIZE;
-    s->fake_cis = kmalloc(cis->Length, GFP_KERNEL);
-    if (s->fake_cis == NULL)
-       return CS_OUT_OF_RESOURCE;
-    s->fake_cis_len = cis->Length;
-    memcpy(s->fake_cis, cis->Data, cis->Length);
-    return CS_SUCCESS;
+       if (len > CISTPL_MAX_CIS_SIZE) {
+               dev_printk(KERN_WARNING, &s->dev, "replacement CIS too big\n");
+               return -EINVAL;
+       }
+       kfree(s->fake_cis);
+       s->fake_cis = kmalloc(len, GFP_KERNEL);
+       if (s->fake_cis == NULL) {
+               dev_printk(KERN_WARNING, &s->dev, "no memory to replace CIS\n");
+               return -ENOMEM;
+       }
+       s->fake_cis_len = len;
+       memcpy(s->fake_cis, data, len);
+       return 0;
 }
 EXPORT_SYMBOL(pcmcia_replace_cis);
 
@@ -418,9 +425,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *t
 int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple)
 {
     if (!s)
-       return CS_BAD_HANDLE;
+       return -EINVAL;
     if (!(s->state & SOCKET_PRESENT))
-       return CS_NO_CARD;
+       return -ENODEV;
     tuple->TupleLink = tuple->Flags = 0;
 #ifdef CONFIG_CARDBUS
     if (s->state & SOCKET_CARDBUS) {
@@ -440,10 +447,10 @@ int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple
        !(tuple->Attributes & TUPLE_RETURN_COMMON)) {
        cisdata_t req = tuple->DesiredTuple;
        tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
-       if (pccard_get_next_tuple(s, function, tuple) == CS_SUCCESS) {
+       if (pccard_get_next_tuple(s, function, tuple) == 0) {
            tuple->DesiredTuple = CISTPL_LINKTARGET;
-           if (pccard_get_next_tuple(s, function, tuple) != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
+           if (pccard_get_next_tuple(s, function, tuple) != 0)
+               return -ENOSPC;
        } else
            tuple->CISOffset = tuple->TupleLink = 0;
        tuple->DesiredTuple = req;
@@ -498,9 +505,9 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
     int ofs, i, attr;
 
     if (!s)
-       return CS_BAD_HANDLE;
+       return -EINVAL;
     if (!(s->state & SOCKET_PRESENT))
-       return CS_NO_CARD;
+       return -ENODEV;
 
     link[1] = tuple->TupleLink;
     ofs = tuple->CISOffset + tuple->TupleLink;
@@ -519,7 +526,7 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
        /* End of chain?  Follow long link if possible */
        if (link[0] == CISTPL_END) {
            if ((ofs = follow_link(s, tuple)) < 0)
-               return CS_NO_MORE_ITEMS;
+               return -ENOSPC;
            attr = SPACE(tuple->Flags);
            read_cis_cache(s, attr, ofs, 2, link);
        }
@@ -577,13 +584,13 @@ int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function, tuple_
     }
     if (i == MAX_TUPLES) {
        cs_dbg(s, 1, "cs: overrun in pcmcia_get_next_tuple\n");
-       return CS_NO_MORE_ITEMS;
+       return -ENOSPC;
     }
     
     tuple->TupleCode = link[0];
     tuple->TupleLink = link[1];
     tuple->CISOffset = ofs + 2;
-    return CS_SUCCESS;
+    return 0;
 }
 EXPORT_SYMBOL(pccard_get_next_tuple);
 
@@ -596,18 +603,18 @@ int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple)
     u_int len;
 
     if (!s)
-       return CS_BAD_HANDLE;
+       return -EINVAL;
 
     if (tuple->TupleLink < tuple->TupleOffset)
-       return CS_NO_MORE_ITEMS;
+       return -ENOSPC;
     len = tuple->TupleLink - tuple->TupleOffset;
     tuple->TupleDataLen = tuple->TupleLink;
     if (len == 0)
-       return CS_SUCCESS;
+       return 0;
     read_cis_cache(s, SPACE(tuple->Flags),
                   tuple->CISOffset + tuple->TupleOffset,
                   _MIN(len, tuple->TupleDataMax), tuple->TupleData);
-    return CS_SUCCESS;
+    return 0;
 }
 EXPORT_SYMBOL(pccard_get_tuple_data);
 
@@ -640,25 +647,31 @@ static int parse_device(tuple_t *tuple, cistpl_device_t *device)
        case 3: device->dev[i].speed = 150; break;
        case 4: device->dev[i].speed = 100; break;
        case 7:
-           if (++p == q) return CS_BAD_TUPLE;
+           if (++p == q)
+                   return -EINVAL;
            device->dev[i].speed = SPEED_CVT(*p);
            while (*p & 0x80)
-               if (++p == q) return CS_BAD_TUPLE;
+               if (++p == q)
+                       return -EINVAL;
            break;
        default:
-           return CS_BAD_TUPLE;
+           return -EINVAL;
        }
 
-       if (++p == q) return CS_BAD_TUPLE;
-       if (*p == 0xff) break;
+       if (++p == q)
+               return -EINVAL;
+       if (*p == 0xff)
+               break;
        scale = *p & 7;
-       if (scale == 7) return CS_BAD_TUPLE;
+       if (scale == 7)
+               return -EINVAL;
        device->dev[i].size = ((*p >> 3) + 1) * (512 << (scale*2));
        device->ndev++;
-       if (++p == q) break;
+       if (++p == q)
+               break;
     }
     
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -667,12 +680,12 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum)
 {
     u_char *p;
     if (tuple->TupleDataLen < 5)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     p = (u_char *) tuple->TupleData;
     csum->addr = tuple->CISOffset + get_unaligned_le16(p) - 2;
     csum->len = get_unaligned_le16(p + 2);
     csum->sum = *(p + 4);
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -680,9 +693,9 @@ static int parse_checksum(tuple_t *tuple, cistpl_checksum_t *csum)
 static int parse_longlink(tuple_t *tuple, cistpl_longlink_t *link)
 {
     if (tuple->TupleDataLen < 4)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     link->addr = get_unaligned_le32(tuple->TupleData);
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -697,13 +710,13 @@ static int parse_longlink_mfc(tuple_t *tuple,
     
     link->nfn = *p; p++;
     if (tuple->TupleDataLen <= link->nfn*5)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     for (i = 0; i < link->nfn; i++) {
        link->fn[i].space = *p; p++;
        link->fn[i].addr = get_unaligned_le32(p);
        p += 4;
     }
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -713,24 +726,27 @@ static int parse_strings(u_char *p, u_char *q, int max,
 {
     int i, j, ns;
 
-    if (p == q) return CS_BAD_TUPLE;
+    if (p == q)
+           return -EINVAL;
     ns = 0; j = 0;
     for (i = 0; i < max; i++) {
-       if (*p == 0xff) break;
+       if (*p == 0xff)
+               break;
        ofs[i] = j;
        ns++;
        for (;;) {
            s[j++] = (*p == 0xff) ? '\0' : *p;
            if ((*p == '\0') || (*p == 0xff)) break;
-           if (++p == q) return CS_BAD_TUPLE;
+           if (++p == q)
+                   return -EINVAL;
        }
        if ((*p == 0xff) || (++p == q)) break;
     }
     if (found) {
        *found = ns;
-       return CS_SUCCESS;
+       return 0;
     } else {
-       return (ns == max) ? CS_SUCCESS : CS_BAD_TUPLE;
+       return (ns == max) ? 0 : -EINVAL;
     }
 }
 
@@ -745,7 +761,8 @@ static int parse_vers_1(tuple_t *tuple, cistpl_vers_1_t *vers_1)
     
     vers_1->major = *p; p++;
     vers_1->minor = *p; p++;
-    if (p >= q) return CS_BAD_TUPLE;
+    if (p >= q)
+           return -EINVAL;
 
     return parse_strings(p, q, CISTPL_VERS_1_MAX_PROD_STRINGS,
                         vers_1->str, vers_1->ofs, &vers_1->ns);
@@ -781,7 +798,7 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec)
        p += 2;
     }
     jedec->nid = nid;
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -789,10 +806,10 @@ static int parse_jedec(tuple_t *tuple, cistpl_jedec_t *jedec)
 static int parse_manfid(tuple_t *tuple, cistpl_manfid_t *m)
 {
     if (tuple->TupleDataLen < 4)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     m->manf = get_unaligned_le16(tuple->TupleData);
     m->card = get_unaligned_le16(tuple->TupleData + 2);
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -801,11 +818,11 @@ static int parse_funcid(tuple_t *tuple, cistpl_funcid_t *f)
 {
     u_char *p;
     if (tuple->TupleDataLen < 2)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     p = (u_char *)tuple->TupleData;
     f->func = p[0];
     f->sysinit = p[1];
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -815,12 +832,12 @@ static int parse_funce(tuple_t *tuple, cistpl_funce_t *f)
     u_char *p;
     int i;
     if (tuple->TupleDataLen < 1)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     p = (u_char *)tuple->TupleData;
     f->type = p[0];
     for (i = 1; i < tuple->TupleDataLen; i++)
        f->data[i-1] = p[i];
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -834,7 +851,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config)
     rasz = *p & 0x03;
     rmsz = (*p & 0x3c) >> 2;
     if (tuple->TupleDataLen < rasz+rmsz+4)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     config->last_idx = *(++p);
     p++;
     config->base = 0;
@@ -846,7 +863,7 @@ static int parse_config(tuple_t *tuple, cistpl_config_t *config)
     for (i = 0; i <= rmsz; i++)
        config->rmask[i>>2] += p[i] << (8*(i%4));
     config->subtuples = tuple->TupleDataLen - (rasz+rmsz+4);
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*======================================================================
@@ -1002,10 +1019,12 @@ static u_char *parse_mem(u_char *p, u_char *q, cistpl_mem_t *mem)
 
 static u_char *parse_irq(u_char *p, u_char *q, cistpl_irq_t *irq)
 {
-    if (p == q) return NULL;
+    if (p == q)
+           return NULL;
     irq->IRQInfo1 = *p; p++;
     if (irq->IRQInfo1 & IRQ_INFO2_VALID) {
-       if (p+2 > q) return NULL;
+       if (p+2 > q)
+               return NULL;
        irq->IRQInfo2 = (p[1]<<8) + p[0];
        p += 2;
     }
@@ -1026,7 +1045,8 @@ static int parse_cftable_entry(tuple_t *tuple,
     if (*p & 0x40)
        entry->flags |= CISTPL_CFTABLE_DEFAULT;
     if (*p & 0x80) {
-       if (++p == q) return CS_BAD_TUPLE;
+       if (++p == q)
+               return -EINVAL;
        if (*p & 0x10)
            entry->flags |= CISTPL_CFTABLE_BVDS;
        if (*p & 0x20)
@@ -1040,30 +1060,35 @@ static int parse_cftable_entry(tuple_t *tuple,
        entry->interface = 0;
 
     /* Process optional features */
-    if (++p == q) return CS_BAD_TUPLE;
+    if (++p == q)
+           return -EINVAL;
     features = *p; p++;
 
     /* Power options */
     if ((features & 3) > 0) {
        p = parse_power(p, q, &entry->vcc);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vcc.present = 0;
     if ((features & 3) > 1) {
        p = parse_power(p, q, &entry->vpp1);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vpp1.present = 0;
     if ((features & 3) > 2) {
        p = parse_power(p, q, &entry->vpp2);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vpp2.present = 0;
 
     /* Timing options */
     if (features & 0x04) {
        p = parse_timing(p, q, &entry->timing);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else {
        entry->timing.wait = 0;
        entry->timing.ready = 0;
@@ -1073,14 +1098,16 @@ static int parse_cftable_entry(tuple_t *tuple,
     /* I/O window options */
     if (features & 0x08) {
        p = parse_io(p, q, &entry->io);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->io.nwin = 0;
     
     /* Interrupt options */
     if (features & 0x10) {
        p = parse_irq(p, q, &entry->irq);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->irq.IRQInfo1 = 0;
 
@@ -1094,7 +1121,8 @@ static int parse_cftable_entry(tuple_t *tuple,
        entry->mem.win[0].card_addr = 0;
        entry->mem.win[0].host_addr = 0;
        p += 2;
-       if (p > q) return CS_BAD_TUPLE;
+       if (p > q)
+               return -EINVAL;
        break;
     case 0x40:
        entry->mem.nwin = 1;
@@ -1102,26 +1130,30 @@ static int parse_cftable_entry(tuple_t *tuple,
        entry->mem.win[0].card_addr = get_unaligned_le16(p + 2) << 8;
        entry->mem.win[0].host_addr = 0;
        p += 4;
-       if (p > q) return CS_BAD_TUPLE;
+       if (p > q)
+               return -EINVAL;
        break;
     case 0x60:
        p = parse_mem(p, q, &entry->mem);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
        break;
     }
 
     /* Misc features */
     if (features & 0x80) {
-       if (p == q) return CS_BAD_TUPLE;
+       if (p == q)
+               return -EINVAL;
        entry->flags |= (*p << 8);
        while (*p & 0x80)
-           if (++p == q) return CS_BAD_TUPLE;
+           if (++p == q)
+                   return -EINVAL;
        p++;
     }
 
     entry->subtuples = q-p;
     
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -1132,12 +1164,12 @@ static int parse_bar(tuple_t *tuple, cistpl_bar_t *bar)
 {
     u_char *p;
     if (tuple->TupleDataLen < 6)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     p = (u_char *)tuple->TupleData;
     bar->attr = *p;
     p += 2;
     bar->size = get_unaligned_le32(p);
-    return CS_SUCCESS;
+    return 0;
 }
 
 static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
@@ -1146,12 +1178,12 @@ static int parse_config_cb(tuple_t *tuple, cistpl_config_t *config)
     
     p = (u_char *)tuple->TupleData;
     if ((*p != 3) || (tuple->TupleDataLen < 6))
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     config->last_idx = *(++p);
     p++;
     config->base = get_unaligned_le32(p);
     config->subtuples = tuple->TupleDataLen - 6;
-    return CS_SUCCESS;
+    return 0;
 }
 
 static int parse_cftable_entry_cb(tuple_t *tuple,
@@ -1167,29 +1199,34 @@ static int parse_cftable_entry_cb(tuple_t *tuple,
        entry->flags |= CISTPL_CFTABLE_DEFAULT;
 
     /* Process optional features */
-    if (++p == q) return CS_BAD_TUPLE;
+    if (++p == q)
+           return -EINVAL;
     features = *p; p++;
 
     /* Power options */
     if ((features & 3) > 0) {
        p = parse_power(p, q, &entry->vcc);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vcc.present = 0;
     if ((features & 3) > 1) {
        p = parse_power(p, q, &entry->vpp1);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vpp1.present = 0;
     if ((features & 3) > 2) {
        p = parse_power(p, q, &entry->vpp2);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->vpp2.present = 0;
 
     /* I/O window options */
     if (features & 0x08) {
-       if (p == q) return CS_BAD_TUPLE;
+       if (p == q)
+               return -EINVAL;
        entry->io = *p; p++;
     } else
        entry->io = 0;
@@ -1197,32 +1234,37 @@ static int parse_cftable_entry_cb(tuple_t *tuple,
     /* Interrupt options */
     if (features & 0x10) {
        p = parse_irq(p, q, &entry->irq);
-       if (p == NULL) return CS_BAD_TUPLE;
+       if (p == NULL)
+               return -EINVAL;
     } else
        entry->irq.IRQInfo1 = 0;
 
     if (features & 0x20) {
-       if (p == q) return CS_BAD_TUPLE;
+       if (p == q)
+               return -EINVAL;
        entry->mem = *p; p++;
     } else
        entry->mem = 0;
 
     /* Misc features */
     if (features & 0x80) {
-       if (p == q) return CS_BAD_TUPLE;
+       if (p == q)
+               return -EINVAL;
        entry->flags |= (*p << 8);
        if (*p & 0x80) {
-           if (++p == q) return CS_BAD_TUPLE;
+           if (++p == q)
+                   return -EINVAL;
            entry->flags |= (*p << 16);
        }
        while (*p & 0x80)
-           if (++p == q) return CS_BAD_TUPLE;
+           if (++p == q)
+                   return -EINVAL;
        p++;
     }
 
     entry->subtuples = q-p;
     
-    return CS_SUCCESS;
+    return 0;
 }
 
 #endif
@@ -1248,7 +1290,7 @@ static int parse_device_geo(tuple_t *tuple, cistpl_device_geo_t *geo)
        p += 6;
     }
     geo->ngeo = n;
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -1258,7 +1300,7 @@ static int parse_vers_2(tuple_t *tuple, cistpl_vers_2_t *v2)
     u_char *p, *q;
 
     if (tuple->TupleDataLen < 10)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     
     p = tuple->TupleData;
     q = p + tuple->TupleDataLen;
@@ -1282,15 +1324,18 @@ static int parse_org(tuple_t *tuple, cistpl_org_t *org)
     
     p = tuple->TupleData;
     q = p + tuple->TupleDataLen;
-    if (p == q) return CS_BAD_TUPLE;
+    if (p == q)
+           return -EINVAL;
     org->data_org = *p;
-    if (++p == q) return CS_BAD_TUPLE;
+    if (++p == q)
+           return -EINVAL;
     for (i = 0; i < 30; i++) {
        org->desc[i] = *p;
        if (*p == '\0') break;
-       if (++p == q) return CS_BAD_TUPLE;
+       if (++p == q)
+               return -EINVAL;
     }
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
@@ -1300,7 +1345,7 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt)
     u_char *p;
 
     if (tuple->TupleDataLen < 10)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
 
     p = tuple->TupleData;
 
@@ -1309,17 +1354,17 @@ static int parse_format(tuple_t *tuple, cistpl_format_t *fmt)
     fmt->offset = get_unaligned_le32(p + 2);
     fmt->length = get_unaligned_le32(p + 6);
 
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*====================================================================*/
 
-int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse)
+int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse)
 {
-    int ret = CS_SUCCESS;
+    int ret = 0;
     
     if (tuple->TupleDataLen > tuple->TupleDataMax)
-       return CS_BAD_TUPLE;
+       return -EINVAL;
     switch (tuple->TupleCode) {
     case CISTPL_DEVICE:
     case CISTPL_DEVICE_A:
@@ -1387,15 +1432,17 @@ int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse)
        break;
     case CISTPL_NO_LINK:
     case CISTPL_LINKTARGET:
-       ret = CS_SUCCESS;
+       ret = 0;
        break;
     default:
-       ret = CS_UNSUPPORTED_FUNCTION;
+       ret = -EINVAL;
        break;
     }
+    if (ret)
+           __cs_dbg(0, "parse_tuple failed %d\n", ret);
     return ret;
 }
-EXPORT_SYMBOL(pccard_parse_tuple);
+EXPORT_SYMBOL(pcmcia_parse_tuple);
 
 /*======================================================================
 
@@ -1410,18 +1457,22 @@ int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t
     int ret;
 
     buf = kmalloc(256, GFP_KERNEL);
-    if (buf == NULL)
-       return CS_OUT_OF_RESOURCE;
+    if (buf == NULL) {
+           dev_printk(KERN_WARNING, &s->dev, "no memory to read tuple\n");
+           return -ENOMEM;
+    }
     tuple.DesiredTuple = code;
     tuple.Attributes = TUPLE_RETURN_COMMON;
     ret = pccard_get_first_tuple(s, function, &tuple);
-    if (ret != CS_SUCCESS) goto done;
+    if (ret != 0)
+           goto done;
     tuple.TupleData = buf;
     tuple.TupleOffset = 0;
     tuple.TupleDataMax = 255;
     ret = pccard_get_tuple_data(s, &tuple);
-    if (ret != CS_SUCCESS) goto done;
-    ret = pccard_parse_tuple(&tuple, parse);
+    if (ret != 0)
+           goto done;
+    ret = pcmcia_parse_tuple(&tuple, parse);
 done:
     kfree(buf);
     return ret;
@@ -1446,37 +1497,40 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned
     int ret, reserved, dev_ok = 0, ident_ok = 0;
 
     if (!s)
-       return CS_BAD_HANDLE;
+       return -EINVAL;
 
     tuple = kmalloc(sizeof(*tuple), GFP_KERNEL);
-    if (tuple == NULL)
-       return CS_OUT_OF_RESOURCE;
+    if (tuple == NULL) {
+           dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
+           return -ENOMEM;
+    }
     p = kmalloc(sizeof(*p), GFP_KERNEL);
     if (p == NULL) {
-       kfree(tuple);
-       return CS_OUT_OF_RESOURCE;
+           kfree(tuple);
+           dev_printk(KERN_WARNING, &s->dev, "no memory to validate CIS\n");
+           return -ENOMEM;
     }
 
     count = reserved = 0;
     tuple->DesiredTuple = RETURN_FIRST_TUPLE;
     tuple->Attributes = TUPLE_RETURN_COMMON;
     ret = pccard_get_first_tuple(s, function, tuple);
-    if (ret != CS_SUCCESS)
+    if (ret != 0)
        goto done;
 
     /* First tuple should be DEVICE; we should really have either that
        or a CFTABLE_ENTRY of some sort */
     if ((tuple->TupleCode == CISTPL_DEVICE) ||
-       (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == CS_SUCCESS) ||
-       (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == CS_SUCCESS))
+       (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY, p) == 0) ||
+       (pccard_read_tuple(s, function, CISTPL_CFTABLE_ENTRY_CB, p) == 0))
        dev_ok++;
 
     /* All cards should have a MANFID tuple, and/or a VERS_1 or VERS_2
        tuple, for card identification.  Certain old D-Link and Linksys
        cards have only a broken VERS_2 tuple; hence the bogus test. */
-    if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == CS_SUCCESS) ||
-       (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == CS_SUCCESS) ||
-       (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != CS_NO_MORE_ITEMS))
+    if ((pccard_read_tuple(s, function, CISTPL_MANFID, p) == 0) ||
+       (pccard_read_tuple(s, function, CISTPL_VERS_1, p) == 0) ||
+       (pccard_read_tuple(s, function, CISTPL_VERS_2, p) != -ENOSPC))
        ident_ok++;
 
     if (!dev_ok && !ident_ok)
@@ -1484,7 +1538,8 @@ int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned
 
     for (count = 1; count < MAX_TUPLES; count++) {
        ret = pccard_get_next_tuple(s, function, tuple);
-       if (ret != CS_SUCCESS) break;
+       if (ret != 0)
+               break;
        if (((tuple->TupleCode > 0x23) && (tuple->TupleCode < 0x40)) ||
            ((tuple->TupleCode > 0x47) && (tuple->TupleCode < 0x80)) ||
            ((tuple->TupleCode > 0x90) && (tuple->TupleCode < 0xff)))
@@ -1499,6 +1554,6 @@ done:
            *info = count;
     kfree(tuple);
     kfree(p);
-    return CS_SUCCESS;
+    return 0;
 }
 EXPORT_SYMBOL(pccard_validate_cis);
index d1207393fc3e4029a8b5f6402f82c185d517ff39..c68c5d3382859eb4af84f8d9e0278ee3ce00b8ea 100644 (file)
@@ -61,7 +61,7 @@ INT_MODULE_PARM(unreset_limit,        30);            /* unreset_check's */
 /* Access speed for attribute memory windows */
 INT_MODULE_PARM(cis_speed,     300);           /* ns */
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 static int pc_debug;
 
 module_param(pc_debug, int, 0644);
@@ -247,7 +247,8 @@ int pcmcia_register_socket(struct pcmcia_socket *socket)
 
        wait_for_completion(&socket->thread_done);
        if (!socket->thread) {
-               printk(KERN_WARNING "PCMCIA: warning: socket thread for socket %p did not start\n", socket);
+               dev_printk(KERN_WARNING, &socket->dev,
+                          "PCMCIA: warning: socket thread did not start\n");
                return -EIO;
        }
 
@@ -366,16 +367,16 @@ static int socket_reset(struct pcmcia_socket *skt)
                skt->ops->get_status(skt, &status);
 
                if (!(status & SS_DETECT))
-                       return CS_NO_CARD;
+                       return -ENODEV;
 
                if (status & SS_READY)
-                       return CS_SUCCESS;
+                       return 0;
 
                msleep(unreset_check * 10);
        }
 
        cs_err(skt, "time out after reset.\n");
-       return CS_GENERAL_FAILURE;
+       return -ETIMEDOUT;
 }
 
 /*
@@ -412,7 +413,8 @@ static void socket_shutdown(struct pcmcia_socket *s)
 
        s->ops->get_status(s, &status);
        if (status & SS_POWERON) {
-               printk(KERN_ERR "PCMCIA: socket %p: *** DANGER *** unable to remove socket power\n", s);
+               dev_printk(KERN_ERR, &s->dev,
+                          "*** DANGER *** unable to remove socket power\n");
        }
 
        cs_socket_put(s);
@@ -426,14 +428,14 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
 
        skt->ops->get_status(skt, &status);
        if (!(status & SS_DETECT))
-               return CS_NO_CARD;
+               return -ENODEV;
 
        msleep(initial_delay * 10);
 
        for (i = 0; i < 100; i++) {
                skt->ops->get_status(skt, &status);
                if (!(status & SS_DETECT))
-                       return CS_NO_CARD;
+                       return -ENODEV;
 
                if (!(status & SS_PENDING))
                        break;
@@ -443,13 +445,13 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
 
        if (status & SS_PENDING) {
                cs_err(skt, "voltage interrogation timed out.\n");
-               return CS_GENERAL_FAILURE;
+               return -ETIMEDOUT;
        }
 
        if (status & SS_CARDBUS) {
                if (!(skt->features & SS_CAP_CARDBUS)) {
                        cs_err(skt, "cardbus cards are not supported.\n");
-                       return CS_BAD_TYPE;
+                       return -EINVAL;
                }
                skt->state |= SOCKET_CARDBUS;
        }
@@ -463,7 +465,7 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
                skt->socket.Vcc = skt->socket.Vpp = 50;
        else {
                cs_err(skt, "unsupported voltage key.\n");
-               return CS_BAD_TYPE;
+               return -EIO;
        }
 
        if (skt->power_hook)
@@ -480,7 +482,7 @@ static int socket_setup(struct pcmcia_socket *skt, int initial_delay)
        skt->ops->get_status(skt, &status);
        if (!(status & SS_POWERON)) {
                cs_err(skt, "unable to apply power.\n");
-               return CS_BAD_TYPE;
+               return -EIO;
        }
 
        status = socket_reset(skt);
@@ -502,15 +504,16 @@ static int socket_insert(struct pcmcia_socket *skt)
        cs_dbg(skt, 4, "insert\n");
 
        if (!cs_socket_get(skt))
-               return CS_NO_CARD;
+               return -ENODEV;
 
        ret = socket_setup(skt, setup_delay);
-       if (ret == CS_SUCCESS) {
+       if (ret == 0) {
                skt->state |= SOCKET_PRESENT;
 
-               printk(KERN_NOTICE "pccard: %s card inserted into slot %d\n",
-                      (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
-                      skt->sock);
+               dev_printk(KERN_NOTICE, &skt->dev,
+                          "pccard: %s card inserted into slot %d\n",
+                          (skt->state & SOCKET_CARDBUS) ? "CardBus" : "PCMCIA",
+                          skt->sock);
 
 #ifdef CONFIG_CARDBUS
                if (skt->state & SOCKET_CARDBUS) {
@@ -531,7 +534,7 @@ static int socket_insert(struct pcmcia_socket *skt)
 static int socket_suspend(struct pcmcia_socket *skt)
 {
        if (skt->state & SOCKET_SUSPEND)
-               return CS_IN_USE;
+               return -EBUSY;
 
        send_event(skt, CS_EVENT_PM_SUSPEND, CS_EVENT_PRI_LOW);
        skt->socket = dead_socket;
@@ -540,7 +543,7 @@ static int socket_suspend(struct pcmcia_socket *skt)
                skt->ops->suspend(skt);
        skt->state |= SOCKET_SUSPEND;
 
-       return CS_SUCCESS;
+       return 0;
 }
 
 /*
@@ -553,7 +556,7 @@ static int socket_resume(struct pcmcia_socket *skt)
        int ret;
 
        if (!(skt->state & SOCKET_SUSPEND))
-               return CS_IN_USE;
+               return -EBUSY;
 
        skt->socket = dead_socket;
        skt->ops->init(skt);
@@ -565,7 +568,7 @@ static int socket_resume(struct pcmcia_socket *skt)
        }
 
        ret = socket_setup(skt, resume_delay);
-       if (ret == CS_SUCCESS) {
+       if (ret == 0) {
                /*
                 * FIXME: need a better check here for cardbus cards.
                 */
@@ -590,12 +593,13 @@ static int socket_resume(struct pcmcia_socket *skt)
 
        skt->state &= ~SOCKET_SUSPEND;
 
-       return CS_SUCCESS;
+       return 0;
 }
 
 static void socket_remove(struct pcmcia_socket *skt)
 {
-       printk(KERN_NOTICE "pccard: card ejected from slot %d\n", skt->sock);
+       dev_printk(KERN_NOTICE, &skt->dev,
+                  "pccard: card ejected from slot %d\n", skt->sock);
        socket_shutdown(skt);
 }
 
@@ -641,8 +645,8 @@ static int pccardd(void *__skt)
        /* register with the device core */
        ret = device_register(&skt->dev);
        if (ret) {
-               printk(KERN_WARNING "PCMCIA: unable to register socket 0x%p\n",
-                       skt);
+               dev_printk(KERN_WARNING, &skt->dev,
+                          "PCMCIA: unable to register socket\n");
                skt->thread = NULL;
                complete(&skt->thread_done);
                return 0;
@@ -748,7 +752,7 @@ EXPORT_SYMBOL(pccard_register_pcmcia);
  * CIS register.
  */
 
-int pccard_reset_card(struct pcmcia_socket *skt)
+int pcmcia_reset_card(struct pcmcia_socket *skt)
 {
        int ret;
 
@@ -757,15 +761,15 @@ int pccard_reset_card(struct pcmcia_socket *skt)
        mutex_lock(&skt->skt_mutex);
        do {
                if (!(skt->state & SOCKET_PRESENT)) {
-                       ret = CS_NO_CARD;
+                       ret = -ENODEV;
                        break;
                }
                if (skt->state & SOCKET_SUSPEND) {
-                       ret = CS_IN_USE;
+                       ret = -EBUSY;
                        break;
                }
                if (skt->state & SOCKET_CARDBUS) {
-                       ret = CS_UNSUPPORTED_FUNCTION;
+                       ret = -EPERM;
                        break;
                }
 
@@ -774,20 +778,20 @@ int pccard_reset_card(struct pcmcia_socket *skt)
                        send_event(skt, CS_EVENT_RESET_PHYSICAL, CS_EVENT_PRI_LOW);
                        if (skt->callback)
                                skt->callback->suspend(skt);
-                       if (socket_reset(skt) == CS_SUCCESS) {
+                       if (socket_reset(skt) == 0) {
                                send_event(skt, CS_EVENT_CARD_RESET, CS_EVENT_PRI_LOW);
                                if (skt->callback)
                                        skt->callback->resume(skt);
                        }
                }
 
-               ret = CS_SUCCESS;
+               ret = 0;
        } while (0);
        mutex_unlock(&skt->skt_mutex);
 
        return ret;
 } /* reset_card */
-EXPORT_SYMBOL(pccard_reset_card);
+EXPORT_SYMBOL(pcmcia_reset_card);
 
 
 /* These shut down or wake up a socket.  They are sort of user
@@ -802,11 +806,11 @@ int pcmcia_suspend_card(struct pcmcia_socket *skt)
        mutex_lock(&skt->skt_mutex);
        do {
                if (!(skt->state & SOCKET_PRESENT)) {
-                       ret = CS_NO_CARD;
+                       ret = -ENODEV;
                        break;
                }
                if (skt->state & SOCKET_CARDBUS) {
-                       ret = CS_UNSUPPORTED_FUNCTION;
+                       ret = -EPERM;
                        break;
                }
                if (skt->callback) {
@@ -832,11 +836,11 @@ int pcmcia_resume_card(struct pcmcia_socket *skt)
        mutex_lock(&skt->skt_mutex);
        do {
                if (!(skt->state & SOCKET_PRESENT)) {
-                       ret = CS_NO_CARD;
+                       ret = -ENODEV;
                        break;
                }
                if (skt->state & SOCKET_CARDBUS) {
-                       ret = CS_UNSUPPORTED_FUNCTION;
+                       ret = -EPERM;
                        break;
                }
                ret = socket_resume(skt);
@@ -892,7 +896,7 @@ int pcmcia_insert_card(struct pcmcia_socket *skt)
                        ret = -EBUSY;
                        break;
                }
-               if (socket_insert(skt) == CS_NO_CARD) {
+               if (socket_insert(skt) == -ENODEV) {
                        ret = -ENODEV;
                        break;
                }
index 63dc1a28bda2772d6f2f213656ce07223cd8dd6c..79615e6d540ba69a01573d3999340e46d001f9b5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * cs_internal.h
+ * cs_internal.h -- definitions internal to the PCMCIA core modules
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  *
  * (C) 1999            David A. Hinds
+ * (C) 2003 - 2008     Dominik Brodowski
+ *
+ *
+ * This file contains definitions _only_ needed by the PCMCIA core modules.
+ * It must not be included by PCMCIA socket drivers or by PCMCIA device
+ * drivers.
  */
 
 #ifndef _LINUX_CS_INTERNAL_H
 #include <linux/kref.h>
 
 /* Flags in client state */
-#define CLIENT_CONFIG_LOCKED   0x0001
-#define CLIENT_IRQ_REQ         0x0002
-#define CLIENT_IO_REQ          0x0004
-#define CLIENT_UNBOUND         0x0008
-#define CLIENT_STALE           0x0010
 #define CLIENT_WIN_REQ(i)      (0x1<<(i))
-#define CLIENT_CARDBUS         0x8000
 
 /* Each card function gets one of these guys */
 typedef struct config_t {
        struct kref     ref;
-    u_int              state;
-    u_int              Attributes;
-    u_int              IntType;
-    u_int              ConfigBase;
-    u_char             Status, Pin, Copy, Option, ExtStatus;
-    u_int              CardValues;
-    io_req_t           io;
-    struct {
-       u_int           Attributes;
-    } irq;
+       unsigned int    state;
+       unsigned int    Attributes;
+       unsigned int    IntType;
+       unsigned int    ConfigBase;
+       unsigned char   Status, Pin, Copy, Option, ExtStatus;
+       unsigned int    CardValues;
+       io_req_t        io;
+       struct {
+               u_int   Attributes;
+       } irq;
 } config_t;
 
+
 struct cis_cache_entry {
        struct list_head        node;
        unsigned int            addr;
@@ -49,6 +50,30 @@ struct cis_cache_entry {
        unsigned char           cache[0];
 };
 
+struct pccard_resource_ops {
+       int     (*validate_mem)         (struct pcmcia_socket *s);
+       int     (*adjust_io_region)     (struct resource *res,
+                                        unsigned long r_start,
+                                        unsigned long r_end,
+                                        struct pcmcia_socket *s);
+       struct resource* (*find_io)     (unsigned long base, int num,
+                                        unsigned long align,
+                                        struct pcmcia_socket *s);
+       struct resource* (*find_mem)    (unsigned long base, unsigned long num,
+                                        unsigned long align, int low,
+                                        struct pcmcia_socket *s);
+       int     (*add_io)               (struct pcmcia_socket *s,
+                                        unsigned int action,
+                                        unsigned long r_start,
+                                        unsigned long r_end);
+       int     (*add_mem)              (struct pcmcia_socket *s,
+                                        unsigned int action,
+                                        unsigned long r_start,
+                                        unsigned long r_end);
+       int     (*init)                 (struct pcmcia_socket *s);
+       void    (*exit)                 (struct pcmcia_socket *s);
+};
+
 /* Flags in config state */
 #define CONFIG_LOCKED          0x01
 #define CONFIG_IRQ_REQ         0x02
@@ -59,7 +84,6 @@ struct cis_cache_entry {
 #define SOCKET_INUSE           0x0010
 #define SOCKET_SUSPEND         0x0080
 #define SOCKET_WIN_REQ(i)      (0x0100<<(i))
-#define SOCKET_REGION_INFO     0x4000
 #define SOCKET_CARDBUS         0x8000
 #define SOCKET_CARDBUS_CONFIG  0x10000
 
@@ -83,69 +107,153 @@ static inline void cs_socket_put(struct pcmcia_socket *skt)
        }
 }
 
-/* In cardbus.c */
-int cb_alloc(struct pcmcia_socket *s);
-void cb_free(struct pcmcia_socket *s);
-int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len, void *ptr);
+#ifdef CONFIG_PCMCIA_DEBUG
+extern int cs_debug_level(int);
 
-/* In cistpl.c */
-int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
-                u_int addr, u_int len, void *ptr);
-void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
-                  u_int addr, u_int len, void *ptr);
-void release_cis_mem(struct pcmcia_socket *s);
-void destroy_cis_cache(struct pcmcia_socket *s);
+#define cs_dbg(skt, lvl, fmt, arg...) do {             \
+       if (cs_debug_level(lvl))                        \
+               dev_printk(KERN_DEBUG, &skt->dev,       \
+                "cs: " fmt, ## arg);                   \
+} while (0)
+#define __cs_dbg(lvl, fmt, arg...) do {                        \
+       if (cs_debug_level(lvl))                        \
+               printk(KERN_DEBUG                       \
+                "cs: " fmt, ## arg);                   \
+} while (0)
+
+#else
+#define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
+#define __cs_dbg(lvl, fmt, arg...) do { } while (0)
+#endif
+
+#define cs_err(skt, fmt, arg...) \
+       dev_printk(KERN_ERR, &skt->dev, "cs: " fmt, ## arg)
+
+
+/*
+ * Stuff internal to module "pcmcia_core":
+ */
+
+/* cistpl.c */
 int verify_cis_cache(struct pcmcia_socket *s);
-int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function, cisdata_t code, void *parse);
 
-/* In rsrc_mgr */
-int pcmcia_validate_mem(struct pcmcia_socket *s);
-struct resource *pcmcia_find_io_region(unsigned long base, int num, unsigned long align,
-                  struct pcmcia_socket *s);
-int pcmcia_adjust_io_region(struct resource *res, unsigned long r_start,
-                    unsigned long r_end, struct pcmcia_socket *s);
-struct resource *pcmcia_find_mem_region(u_long base, u_long num, u_long align,
-                   int low, struct pcmcia_socket *s);
+/* rsrc_mgr.c */
 void release_resource_db(struct pcmcia_socket *s);
 
-/* In socket_sysfs.c */
+/* socket_sysfs.c */
 extern int pccard_sysfs_add_socket(struct device *dev);
 extern void pccard_sysfs_remove_socket(struct device *dev);
 
-/* In cs.c */
-extern struct rw_semaphore pcmcia_socket_list_rwsem;
-extern struct list_head pcmcia_socket_list;
-int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle, int idx, win_req_t *req);
-int pccard_get_configuration_info(struct pcmcia_socket *s, struct pcmcia_device *p_dev, config_info_t *config);
-int pccard_reset_card(struct pcmcia_socket *skt);
+/* cardbus.c */
+int cb_alloc(struct pcmcia_socket *s);
+void cb_free(struct pcmcia_socket *s);
+int read_cb_mem(struct pcmcia_socket *s, int space, u_int addr, u_int len,
+               void *ptr);
+
 
 
+/*
+ * Stuff exported by module "pcmcia_core" to module "pcmcia"
+ */
+
 struct pcmcia_callback{
        struct module   *owner;
-       int             (*event) (struct pcmcia_socket *s, event_t event, int priority);
+       int             (*event) (struct pcmcia_socket *s,
+                                 event_t event, int priority);
        void            (*requery) (struct pcmcia_socket *s, int new_cis);
        int             (*suspend) (struct pcmcia_socket *s);
        int             (*resume) (struct pcmcia_socket *s);
 };
 
+/* cs.c */
+extern struct rw_semaphore pcmcia_socket_list_rwsem;
+extern struct list_head pcmcia_socket_list;
+extern struct class pcmcia_socket_class;
+
+int pcmcia_get_window(struct pcmcia_socket *s,
+                     window_handle_t *handle,
+                     int idx,
+                     win_req_t *req);
 int pccard_register_pcmcia(struct pcmcia_socket *s, struct pcmcia_callback *c);
+struct pcmcia_socket *pcmcia_get_socket_by_nr(unsigned int nr);
 
-#define cs_socket_name(skt)    ((skt)->dev.bus_id)
+int pcmcia_suspend_card(struct pcmcia_socket *skt);
+int pcmcia_resume_card(struct pcmcia_socket *skt);
 
-#ifdef DEBUG
-extern int cs_debug_level(int);
+int pcmcia_eject_card(struct pcmcia_socket *skt);
+int pcmcia_insert_card(struct pcmcia_socket *skt);
 
-#define cs_dbg(skt, lvl, fmt, arg...) do {             \
-       if (cs_debug_level(lvl))                        \
-               printk(KERN_DEBUG "cs: %s: " fmt,       \
-                      cs_socket_name(skt) , ## arg);   \
-} while (0)
+struct pcmcia_socket *pcmcia_get_socket(struct pcmcia_socket *skt);
+void pcmcia_put_socket(struct pcmcia_socket *skt);
 
-#else
-#define cs_dbg(skt, lvl, fmt, arg...) do { } while (0)
-#endif
+/* cistpl.c */
+int pcmcia_read_cis_mem(struct pcmcia_socket *s, int attr,
+                       u_int addr, u_int len, void *ptr);
+void pcmcia_write_cis_mem(struct pcmcia_socket *s, int attr,
+                         u_int addr, u_int len, void *ptr);
+void release_cis_mem(struct pcmcia_socket *s);
+void destroy_cis_cache(struct pcmcia_socket *s);
+int pccard_read_tuple(struct pcmcia_socket *s, unsigned int function,
+                     cisdata_t code, void *parse);
+int pcmcia_replace_cis(struct pcmcia_socket *s,
+                      const u8 *data, const size_t len);
+int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function,
+                       unsigned int *count);
 
-#define cs_err(skt, fmt, arg...) \
-       printk(KERN_ERR "cs: %s: " fmt, (skt)->dev.bus_id , ## arg)
+/* rsrc_mgr.c */
+int pcmcia_validate_mem(struct pcmcia_socket *s);
+struct resource *pcmcia_find_io_region(unsigned long base,
+                                      int num,
+                                      unsigned long align,
+                                      struct pcmcia_socket *s);
+int pcmcia_adjust_io_region(struct resource *res,
+                           unsigned long r_start,
+                           unsigned long r_end,
+                           struct pcmcia_socket *s);
+struct resource *pcmcia_find_mem_region(u_long base,
+                                       u_long num,
+                                       u_long align,
+                                       int low,
+                                       struct pcmcia_socket *s);
+
+/*
+ * Stuff internal to module "pcmcia".
+ */
+/* ds.c */
+extern struct bus_type pcmcia_bus_type;
+
+/* pcmcia_resource.c */
+extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
+
+#ifdef CONFIG_PCMCIA_IOCTL
+/* ds.c */
+extern spinlock_t pcmcia_dev_list_lock;
+
+extern struct pcmcia_device *pcmcia_get_dev(struct pcmcia_device *p_dev);
+extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
+
+struct pcmcia_device *pcmcia_device_add(struct pcmcia_socket *s,
+                                       unsigned int function);
+
+/* pcmcia_ioctl.c */
+extern void __init pcmcia_setup_ioctl(void);
+extern void __exit pcmcia_cleanup_ioctl(void);
+extern void handle_event(struct pcmcia_socket *s, event_t event);
+extern int handle_request(struct pcmcia_socket *s, event_t event);
+
+#else /* CONFIG_PCMCIA_IOCTL */
+
+static inline void __init pcmcia_setup_ioctl(void) { return; }
+static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
+static inline void handle_event(struct pcmcia_socket *s, event_t event)
+{
+       return;
+}
+static inline int handle_request(struct pcmcia_socket *s, event_t event)
+{
+       return 0;
+}
+
+#endif /* CONFIG_PCMCIA_IOCTL */
 
 #endif /* _LINUX_CS_INTERNAL_H */
index 34c83d3ca0fac69df37ece4e352a99697ae515cd..7956602554901297f86055cea142707f7eead769 100644 (file)
@@ -32,7 +32,6 @@
 #include <pcmcia/ss.h>
 
 #include "cs_internal.h"
-#include "ds_internal.h"
 
 /*====================================================================*/
 
@@ -42,17 +41,22 @@ MODULE_AUTHOR("David Hinds <dahinds@users.sourceforge.net>");
 MODULE_DESCRIPTION("PCMCIA Driver Services");
 MODULE_LICENSE("GPL");
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 int ds_pc_debug;
 
 module_param_named(pc_debug, ds_pc_debug, int, 0644);
 
 #define ds_dbg(lvl, fmt, arg...) do {                          \
-       if (ds_pc_debug > (lvl))                                        \
+       if (ds_pc_debug > (lvl))                                \
                printk(KERN_DEBUG "ds: " fmt , ## arg);         \
 } while (0)
+#define ds_dev_dbg(lvl, dev, fmt, arg...) do {                         \
+       if (ds_pc_debug > (lvl))                                        \
+               dev_printk(KERN_DEBUG, dev, "ds: " fmt , ## arg);       \
+} while (0)
 #else
 #define ds_dbg(lvl, fmt, arg...) do { } while (0)
+#define ds_dev_dbg(lvl, dev, fmt, arg...) do { } while (0)
 #endif
 
 spinlock_t pcmcia_dev_list_lock;
@@ -64,42 +68,19 @@ spinlock_t pcmcia_dev_list_lock;
 /* String tables for error messages */
 
 typedef struct lookup_t {
-    int key;
-    char *msg;
+    const int key;
+    const char *msg;
 } lookup_t;
 
 static const lookup_t error_table[] = {
-    { CS_SUCCESS,              "Operation succeeded" },
-    { CS_BAD_ADAPTER,          "Bad adapter" },
-    { CS_BAD_ATTRIBUTE,        "Bad attribute", },
-    { CS_BAD_BASE,             "Bad base address" },
-    { CS_BAD_EDC,              "Bad EDC" },
-    { CS_BAD_IRQ,              "Bad IRQ" },
-    { CS_BAD_OFFSET,           "Bad offset" },
-    { CS_BAD_PAGE,             "Bad page number" },
-    { CS_READ_FAILURE,         "Read failure" },
-    { CS_BAD_SIZE,             "Bad size" },
-    { CS_BAD_SOCKET,           "Bad socket" },
-    { CS_BAD_TYPE,             "Bad type" },
-    { CS_BAD_VCC,              "Bad Vcc" },
-    { CS_BAD_VPP,              "Bad Vpp" },
-    { CS_BAD_WINDOW,           "Bad window" },
-    { CS_WRITE_FAILURE,                "Write failure" },
-    { CS_NO_CARD,              "No card present" },
-    { CS_UNSUPPORTED_FUNCTION, "Usupported function" },
-    { CS_UNSUPPORTED_MODE,     "Unsupported mode" },
-    { CS_BAD_SPEED,            "Bad speed" },
-    { CS_BUSY,                 "Resource busy" },
-    { CS_GENERAL_FAILURE,      "General failure" },
-    { CS_WRITE_PROTECTED,      "Write protected" },
-    { CS_BAD_ARG_LENGTH,       "Bad argument length" },
-    { CS_BAD_ARGS,             "Bad arguments" },
-    { CS_CONFIGURATION_LOCKED, "Configuration locked" },
-    { CS_IN_USE,               "Resource in use" },
-    { CS_NO_MORE_ITEMS,                "No more items" },
-    { CS_OUT_OF_RESOURCE,      "Out of resource" },
-    { CS_BAD_HANDLE,           "Bad handle" },
-    { CS_BAD_TUPLE,            "Bad CIS tuple" }
+    { 0,                       "Operation succeeded" },
+    { -EIO,                    "Input/Output error" },
+    { -ENODEV,                 "No card present" },
+    { -EINVAL,                 "Bad parameter" },
+    { -EACCES,                 "Configuration locked" },
+    { -EBUSY,                  "Resource in use" },
+    { -ENOSPC,                 "No more items" },
+    { -ENOMEM,                 "Out of resource" },
 };
 
 
@@ -155,46 +136,32 @@ static const lookup_t service_table[] = {
     { ReplaceCIS,                      "ReplaceCIS" }
 };
 
-
-static int pcmcia_report_error(struct pcmcia_device *p_dev, error_info_t *err)
+const char *pcmcia_error_func(int func)
 {
        int i;
-       char *serv;
-
-       if (!p_dev)
-               printk(KERN_NOTICE);
-       else
-               printk(KERN_NOTICE "%s: ", p_dev->dev.bus_id);
 
        for (i = 0; i < ARRAY_SIZE(service_table); i++)
-               if (service_table[i].key == err->func)
-                       break;
-       if (i < ARRAY_SIZE(service_table))
-               serv = service_table[i].msg;
-       else
-               serv = "Unknown service number";
+               if (service_table[i].key == func)
+                       return service_table[i].msg;
 
-       for (i = 0; i < ARRAY_SIZE(error_table); i++)
-               if (error_table[i].key == err->retcode)
-                       break;
-       if (i < ARRAY_SIZE(error_table))
-               printk("%s: %s\n", serv, error_table[i].msg);
-       else
-               printk("%s: Unknown error code %#x\n", serv, err->retcode);
+       return "Unknown service number";
+}
+EXPORT_SYMBOL(pcmcia_error_func);
 
-       return CS_SUCCESS;
-} /* report_error */
+const char *pcmcia_error_ret(int ret)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(error_table); i++)
+               if (error_table[i].key == ret)
+                       return error_table[i].msg;
 
-/* end of code which was in cs.c before */
+       return "unknown";
+}
+EXPORT_SYMBOL(pcmcia_error_ret);
 
 /*======================================================================*/
 
-void cs_error(struct pcmcia_device *p_dev, int func, int ret)
-{
-       error_info_t err = { func, ret };
-       pcmcia_report_error(p_dev, &err);
-}
-EXPORT_SYMBOL(cs_error);
 
 
 static void pcmcia_check_driver(struct pcmcia_driver *p_drv)
@@ -391,7 +358,7 @@ static void pcmcia_release_function(struct kref *ref)
 static void pcmcia_release_dev(struct device *dev)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
-       ds_dbg(1, "releasing device %s\n", p_dev->dev.bus_id);
+       ds_dev_dbg(1, dev, "releasing device\n");
        pcmcia_put_socket(p_dev->socket);
        kfree(p_dev->devname);
        kref_put(&p_dev->function_config->ref, pcmcia_release_function);
@@ -401,7 +368,7 @@ static void pcmcia_release_dev(struct device *dev)
 static void pcmcia_add_device_later(struct pcmcia_socket *s, int mfc)
 {
        if (!s->pcmcia_state.device_add_pending) {
-               ds_dbg(1, "scheduling to add %s secondary"
+               ds_dev_dbg(1, &s->dev, "scheduling to add %s secondary"
                       " device to %d\n", mfc ? "mfc" : "pfc", s->sock);
                s->pcmcia_state.device_add_pending = 1;
                s->pcmcia_state.mfc_pfc = mfc;
@@ -439,8 +406,7 @@ static int pcmcia_device_probe(struct device * dev)
         */
        did = p_dev->dev.driver_data;
 
-       ds_dbg(1, "trying to bind %s to %s\n", p_dev->dev.bus_id,
-              p_drv->drv.name);
+       ds_dev_dbg(1, dev, "trying to bind to %s\n", p_drv->drv.name);
 
        if ((!p_drv->probe) || (!p_dev->function_config) ||
            (!try_module_get(p_drv->owner))) {
@@ -455,15 +421,16 @@ static int pcmcia_device_probe(struct device * dev)
                p_dev->conf.ConfigBase = cis_config.base;
                p_dev->conf.Present = cis_config.rmask[0];
        } else {
-               printk(KERN_INFO "pcmcia: could not parse base and rmask0 of CIS\n");
+               dev_printk(KERN_INFO, dev,
+                          "pcmcia: could not parse base and rmask0 of CIS\n");
                p_dev->conf.ConfigBase = 0;
                p_dev->conf.Present = 0;
        }
 
        ret = p_drv->probe(p_dev);
        if (ret) {
-               ds_dbg(1, "binding %s to %s failed with %d\n",
-                      p_dev->dev.bus_id, p_drv->drv.name, ret);
+               ds_dev_dbg(1, dev, "binding to %s failed with %d\n",
+                          p_drv->drv.name, ret);
                goto put_module;
        }
 
@@ -490,8 +457,9 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
        struct pcmcia_device    *tmp;
        unsigned long           flags;
 
-       ds_dbg(2, "pcmcia_card_remove(%d) %s\n", s->sock,
-              leftover ? leftover->devname : "");
+       ds_dev_dbg(2, leftover ? &leftover->dev : &s->dev,
+                  "pcmcia_card_remove(%d) %s\n", s->sock,
+                  leftover ? leftover->devname : "");
 
        if (!leftover)
                s->device_count = 0;
@@ -508,7 +476,7 @@ static void pcmcia_card_remove(struct pcmcia_socket *s, struct pcmcia_device *le
                p_dev->_removed=1;
                spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 
-               ds_dbg(2, "unregistering device %s\n", p_dev->dev.bus_id);
+               ds_dev_dbg(2, &p_dev->dev, "unregistering device\n");
                device_unregister(&p_dev->dev);
        }
 
@@ -525,7 +493,7 @@ static int pcmcia_device_remove(struct device * dev)
        p_dev = to_pcmcia_dev(dev);
        p_drv = to_pcmcia_drv(dev->driver);
 
-       ds_dbg(1, "removing device %s\n", p_dev->dev.bus_id);
+       ds_dev_dbg(1, dev, "removing device\n");
 
        /* If we're removing the primary module driving a
         * pseudo multi-function card, we need to unbind
@@ -548,13 +516,15 @@ static int pcmcia_device_remove(struct device * dev)
 
        /* check for proper unloading */
        if (p_dev->_irq || p_dev->_io || p_dev->_locked)
-               printk(KERN_INFO "pcmcia: driver %s did not release config properly\n",
-                      p_drv->drv.name);
+               dev_printk(KERN_INFO, dev,
+                       "pcmcia: driver %s did not release config properly\n",
+                       p_drv->drv.name);
 
        for (i = 0; i < MAX_WIN; i++)
                if (p_dev->_win & CLIENT_WIN_REQ(i))
-                       printk(KERN_INFO "pcmcia: driver %s did not release windows properly\n",
-                              p_drv->drv.name);
+                       dev_printk(KERN_INFO, dev,
+                         "pcmcia: driver %s did not release window properly\n",
+                          p_drv->drv.name);
 
        /* references from pcmcia_probe_device */
        pcmcia_put_dev(p_dev);
@@ -603,8 +573,9 @@ static int pcmcia_device_query(struct pcmcia_device *p_dev)
                }
                if (!pccard_read_tuple(p_dev->socket, p_dev->func,
                                      CISTPL_DEVICE_GEO, devgeo)) {
-                       ds_dbg(0, "mem device geometry probably means "
-                              "FUNCID_MEMORY\n");
+                       ds_dev_dbg(0, &p_dev->dev,
+                                  "mem device geometry probably means "
+                                  "FUNCID_MEMORY\n");
                        p_dev->func_id = CISTPL_FUNCID_MEMORY;
                        p_dev->has_func_id = 1;
                }
@@ -685,7 +656,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
        if (!p_dev->devname)
                goto err_free;
        sprintf (p_dev->devname, "pcmcia%s", p_dev->dev.bus_id);
-       ds_dbg(3, "devname is %s\n", p_dev->devname);
+       ds_dev_dbg(3, &p_dev->dev, "devname is %s\n", p_dev->devname);
 
        spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
 
@@ -706,7 +677,7 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
        spin_unlock_irqrestore(&pcmcia_dev_list_lock, flags);
 
        if (!p_dev->function_config) {
-               ds_dbg(3, "creating config_t for %s\n", p_dev->dev.bus_id);
+               ds_dev_dbg(3, &p_dev->dev, "creating config_t\n");
                p_dev->function_config = kzalloc(sizeof(struct config_t),
                                                 GFP_KERNEL);
                if (!p_dev->function_config)
@@ -714,8 +685,9 @@ struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int f
                kref_init(&p_dev->function_config->ref);
        }
 
-       printk(KERN_NOTICE "pcmcia: registering new device %s\n",
-              p_dev->devname);
+       dev_printk(KERN_NOTICE, &p_dev->dev,
+                  "pcmcia: registering new device %s\n",
+                  p_dev->devname);
 
        pcmcia_device_query(p_dev);
 
@@ -750,19 +722,20 @@ static int pcmcia_card_add(struct pcmcia_socket *s)
        int ret = 0;
 
        if (!(s->resource_setup_done)) {
-               ds_dbg(3, "no resources available, delaying card_add\n");
+               ds_dev_dbg(3, &s->dev,
+                          "no resources available, delaying card_add\n");
                return -EAGAIN; /* try again, but later... */
        }
 
        if (pcmcia_validate_mem(s)) {
-               ds_dbg(3, "validating mem resources failed, "
+               ds_dev_dbg(3, &s->dev, "validating mem resources failed, "
                       "delaying card_add\n");
                return -EAGAIN; /* try again, but later... */
        }
 
        ret = pccard_validate_cis(s, BIND_FN_ALL, &no_chains);
        if (ret || !no_chains) {
-               ds_dbg(0, "invalid CIS or invalid resources\n");
+               ds_dev_dbg(0, &s->dev, "invalid CIS or invalid resources\n");
                return -ENODEV;
        }
 
@@ -783,7 +756,7 @@ static void pcmcia_delayed_add_device(struct work_struct *work)
 {
        struct pcmcia_socket *s =
                container_of(work, struct pcmcia_socket, device_add);
-       ds_dbg(1, "adding additional device to %d\n", s->sock);
+       ds_dev_dbg(1, &s->dev, "adding additional device to %d\n", s->sock);
        pcmcia_device_add(s, s->pcmcia_state.mfc_pfc);
        s->pcmcia_state.device_add_pending = 0;
        s->pcmcia_state.mfc_pfc = 0;
@@ -793,8 +766,7 @@ static int pcmcia_requery(struct device *dev, void * _data)
 {
        struct pcmcia_device *p_dev = to_pcmcia_dev(dev);
        if (!p_dev->dev.driver) {
-               ds_dbg(1, "update device information for %s\n",
-                      p_dev->dev.bus_id);
+               ds_dev_dbg(1, dev, "update device information\n");
                pcmcia_device_query(p_dev);
        }
 
@@ -808,7 +780,7 @@ static void pcmcia_bus_rescan(struct pcmcia_socket *skt, int new_cis)
        unsigned long flags;
 
        /* must be called with skt_mutex held */
-       ds_dbg(0, "re-scanning socket %d\n", skt->sock);
+       ds_dev_dbg(0, &skt->dev, "re-scanning socket %d\n", skt->sock);
 
        spin_lock_irqsave(&pcmcia_dev_list_lock, flags);
        if (list_empty(&skt->devices_list))
@@ -859,17 +831,17 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
        int ret = -ENOMEM;
        int no_funcs;
        int old_funcs;
-       cisdump_t *cis;
        cistpl_longlink_mfc_t mfc;
 
        if (!filename)
                return -EINVAL;
 
-       ds_dbg(1, "trying to load CIS file %s\n", filename);
+       ds_dev_dbg(1, &dev->dev, "trying to load CIS file %s\n", filename);
 
        if (strlen(filename) > (FIRMWARE_NAME_MAX - 1)) {
-               printk(KERN_WARNING "pcmcia: CIS filename is too long [%s]\n",
-                       filename);
+               dev_printk(KERN_WARNING, &dev->dev,
+                          "pcmcia: CIS filename is too long [%s]\n",
+                          filename);
                return -EINVAL;
        }
 
@@ -878,23 +850,16 @@ static int pcmcia_load_firmware(struct pcmcia_device *dev, char * filename)
        if (request_firmware(&fw, path, &dev->dev) == 0) {
                if (fw->size >= CISTPL_MAX_CIS_SIZE) {
                        ret = -EINVAL;
-                       printk(KERN_ERR "pcmcia: CIS override is too big\n");
+                       dev_printk(KERN_ERR, &dev->dev,
+                                  "pcmcia: CIS override is too big\n");
                        goto release;
                }
 
-               cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL);
-               if (!cis) {
-                       ret = -ENOMEM;
-                       goto release;
-               }
-
-               cis->Length = fw->size + 1;
-               memcpy(cis->Data, fw->data, fw->size);
-
-               if (!pcmcia_replace_cis(s, cis))
+               if (!pcmcia_replace_cis(s, fw->data, fw->size))
                        ret = 0;
                else {
-                       printk(KERN_ERR "pcmcia: CIS override failed\n");
+                       dev_printk(KERN_ERR, &dev->dev,
+                                  "pcmcia: CIS override failed\n");
                        goto release;
                }
 
@@ -998,14 +963,14 @@ static inline int pcmcia_devmatch(struct pcmcia_device *dev,
                 * after it has re-checked that there is no possible module
                 * with a prod_id/manf_id/card_id match.
                 */
-               ds_dbg(0, "skipping FUNC_ID match for %s until userspace "
-                      "interaction\n", dev->dev.bus_id);
+               ds_dev_dbg(0, &dev->dev,
+                       "skipping FUNC_ID match until userspace interaction\n");
                if (!dev->allow_func_id_match)
                        return 0;
        }
 
        if (did->match_flags & PCMCIA_DEV_ID_MATCH_FAKE_CIS) {
-               ds_dbg(0, "device %s needs a fake CIS\n", dev->dev.bus_id);
+               ds_dev_dbg(0, &dev->dev, "device needs a fake CIS\n");
                if (!dev->socket->fake_cis)
                        pcmcia_load_firmware(dev, did->cisfile);
 
@@ -1037,11 +1002,9 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
        /* match dynamic devices first */
        spin_lock(&p_drv->dynids.lock);
        list_for_each_entry(dynid, &p_drv->dynids.list, node) {
-               ds_dbg(3, "trying to match %s to %s\n", dev->bus_id,
-                      drv->name);
+               ds_dev_dbg(3, dev, "trying to match to %s\n", drv->name);
                if (pcmcia_devmatch(p_dev, &dynid->id)) {
-                       ds_dbg(0, "matched %s to %s\n", dev->bus_id,
-                              drv->name);
+                       ds_dev_dbg(0, dev, "matched to %s\n", drv->name);
                        spin_unlock(&p_drv->dynids.lock);
                        return 1;
                }
@@ -1051,18 +1014,15 @@ static int pcmcia_bus_match(struct device * dev, struct device_driver * drv) {
 #ifdef CONFIG_PCMCIA_IOCTL
        /* matching by cardmgr */
        if (p_dev->cardmgr == p_drv) {
-               ds_dbg(0, "cardmgr matched %s to %s\n", dev->bus_id,
-                      drv->name);
+               ds_dev_dbg(0, dev, "cardmgr matched to %s\n", drv->name);
                return 1;
        }
 #endif
 
        while (did && did->match_flags) {
-               ds_dbg(3, "trying to match %s to %s\n", dev->bus_id,
-                      drv->name);
+               ds_dev_dbg(3, dev, "trying to match to %s\n", drv->name);
                if (pcmcia_devmatch(p_dev, did)) {
-                       ds_dbg(0, "matched %s to %s\n", dev->bus_id,
-                              drv->name);
+                       ds_dev_dbg(0, dev, "matched to %s\n", drv->name);
                        return 1;
                }
                did++;
@@ -1268,7 +1228,7 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
        if (p_dev->suspended)
                return 0;
 
-       ds_dbg(2, "suspending %s\n", dev->bus_id);
+       ds_dev_dbg(2, dev, "suspending\n");
 
        if (dev->driver)
                p_drv = to_pcmcia_drv(dev->driver);
@@ -1279,15 +1239,16 @@ static int pcmcia_dev_suspend(struct device * dev, pm_message_t state)
        if (p_drv->suspend) {
                ret = p_drv->suspend(p_dev);
                if (ret) {
-                       printk(KERN_ERR "pcmcia: device %s (driver %s) did "
-                              "not want to go to sleep (%d)\n",
-                              p_dev->devname, p_drv->drv.name, ret);
+                       dev_printk(KERN_ERR, dev,
+                                  "pcmcia: device %s (driver %s) did "
+                                  "not want to go to sleep (%d)\n",
+                                  p_dev->devname, p_drv->drv.name, ret);
                        goto out;
                }
        }
 
        if (p_dev->device_no == p_dev->func) {
-               ds_dbg(2, "releasing configuration for %s\n", dev->bus_id);
+               ds_dev_dbg(2, dev, "releasing configuration\n");
                pcmcia_release_configuration(p_dev);
        }
 
@@ -1307,7 +1268,7 @@ static int pcmcia_dev_resume(struct device * dev)
        if (!p_dev->suspended)
                return 0;
 
-       ds_dbg(2, "resuming %s\n", dev->bus_id);
+       ds_dev_dbg(2, dev, "resuming\n");
 
        if (dev->driver)
                p_drv = to_pcmcia_drv(dev->driver);
@@ -1316,7 +1277,7 @@ static int pcmcia_dev_resume(struct device * dev)
                goto out;
 
        if (p_dev->device_no == p_dev->func) {
-               ds_dbg(2, "requesting configuration for %s\n", dev->bus_id);
+               ds_dev_dbg(2, dev, "requesting configuration\n");
                ret = pcmcia_request_configuration(p_dev, &p_dev->conf);
                if (ret)
                        goto out;
@@ -1358,14 +1319,14 @@ static int pcmcia_bus_resume_callback(struct device *dev, void * _data)
 
 static int pcmcia_bus_resume(struct pcmcia_socket *skt)
 {
-       ds_dbg(2, "resuming socket %d\n", skt->sock);
+       ds_dev_dbg(2, &skt->dev, "resuming socket %d\n", skt->sock);
        bus_for_each_dev(&pcmcia_bus_type, NULL, skt, pcmcia_bus_resume_callback);
        return 0;
 }
 
 static int pcmcia_bus_suspend(struct pcmcia_socket *skt)
 {
-       ds_dbg(2, "suspending socket %d\n", skt->sock);
+       ds_dev_dbg(2, &skt->dev, "suspending socket %d\n", skt->sock);
        if (bus_for_each_dev(&pcmcia_bus_type, NULL, skt,
                             pcmcia_bus_suspend_callback)) {
                pcmcia_bus_resume(skt);
@@ -1391,13 +1352,14 @@ static int ds_event(struct pcmcia_socket *skt, event_t event, int priority)
        struct pcmcia_socket *s = pcmcia_get_socket(skt);
 
        if (!s) {
-               printk(KERN_ERR "PCMCIA obtaining reference to socket %p " \
-                       "failed, event 0x%x lost!\n", skt, event);
+               dev_printk(KERN_ERR, &skt->dev,
+                          "PCMCIA obtaining reference to socket "      \
+                          "failed, event 0x%x lost!\n", event);
                return -ENODEV;
        }
 
-       ds_dbg(1, "ds_event(0x%06x, %d, 0x%p)\n",
-              event, priority, skt);
+       ds_dev_dbg(1, &skt->dev, "ds_event(0x%06x, %d, 0x%p)\n",
+                  event, priority, skt);
 
        switch (event) {
        case CS_EVENT_CARD_REMOVAL:
@@ -1472,7 +1434,8 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
 
        socket = pcmcia_get_socket(socket);
        if (!socket) {
-               printk(KERN_ERR "PCMCIA obtaining reference to socket %p failed\n", socket);
+               dev_printk(KERN_ERR, dev,
+                          "PCMCIA obtaining reference to socket failed\n");
                return -ENODEV;
        }
 
@@ -1492,7 +1455,7 @@ static int __devinit pcmcia_bus_add_socket(struct device *dev,
 
        ret = pccard_register_pcmcia(socket, &pcmcia_bus_callback);
        if (ret) {
-               printk(KERN_ERR "PCMCIA registration PCCard core failed for socket %p\n", socket);
+               dev_printk(KERN_ERR, dev, "PCMCIA registration failed\n");
                pcmcia_put_socket(socket);
                return (ret);
        }
diff --git a/drivers/pcmcia/ds_internal.h b/drivers/pcmcia/ds_internal.h
deleted file mode 100644 (file)
index 3a2b25e..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-/* ds_internal.h - internal header for 16-bit PCMCIA devices management */
-
-extern spinlock_t pcmcia_dev_list_lock;
-extern struct bus_type pcmcia_bus_type;
-
-extern struct pcmcia_device * pcmcia_get_dev(struct pcmcia_device *p_dev);
-extern void pcmcia_put_dev(struct pcmcia_device *p_dev);
-
-struct pcmcia_device * pcmcia_device_add(struct pcmcia_socket *s, unsigned int function);
-
-extern int pcmcia_release_configuration(struct pcmcia_device *p_dev);
-
-#ifdef CONFIG_PCMCIA_IOCTL
-extern void __init pcmcia_setup_ioctl(void);
-extern void __exit pcmcia_cleanup_ioctl(void);
-extern void handle_event(struct pcmcia_socket *s, event_t event);
-extern int handle_request(struct pcmcia_socket *s, event_t event);
-#else
-static inline void __init pcmcia_setup_ioctl(void) { return; }
-static inline void __exit pcmcia_cleanup_ioctl(void) { return; }
-static inline void handle_event(struct pcmcia_socket *s, event_t event) { return; }
-static inline int handle_request(struct pcmcia_socket *s, event_t event) { return CS_SUCCESS; }
-#endif
index fb2bc1fb015d417c19d879378a4538bee57ee372..117dc12ab4380060889814b4ca0b1d8fffb317d0 100644 (file)
@@ -46,7 +46,6 @@
 #include <pcmcia/cistpl.h>
 #include <pcmcia/ds.h>
 #include <pcmcia/ss.h>
-#include "cs_internal.h"
 
 #define MODNAME "hd64465_ss"
 
index 68f6b2702bc42c66f27758c3fbbd25dcb80f83bc..71653ab8489015f768459866a4ea1ff3d23e84d2 100644 (file)
@@ -63,7 +63,7 @@
 #include "vg468.h"
 #include "ricoh.h"
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 static const char version[] =
 "i82365.c 1.265 1999/11/10 18:36:21 (David Hinds)";
 
index 3616da22715239ca658d0bd5816e01eb170d94f5..2ab4f22c21de423a7fccb64cc6562b444e6c1b59 100644 (file)
@@ -38,7 +38,7 @@
 
 #include "m32r_cfc.h"
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 static int m32r_cfc_debug;
 module_param(m32r_cfc_debug, int, 0644);
 #define debug(lvl, fmt, arg...) do {                           \
@@ -505,7 +505,7 @@ static int _pcc_set_socket(u_short sock, socket_state_t *state)
                pcc_set(sock,(unsigned int)PLD_CFBUFCR,1);
        }
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
        if(state->flags & SS_IOCARD){
                debug(3, ":IOCARD");
        }
index 2b42b7155e34a9571b89df20dd990bfb76b5ba46..2f108c23dbd98872dc474bf4e19f901fbab63378 100644 (file)
@@ -45,7 +45,7 @@
 
 #define PCC_DEBUG_DBEX
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 static int m32r_pcc_debug;
 module_param(m32r_pcc_debug, int, 0644);
 #define debug(lvl, fmt, arg...) do {                           \
@@ -460,7 +460,7 @@ static int _pcc_set_socket(u_short sock, socket_state_t *state)
 
        pcc_set(sock,PCCSIGCR,reg);
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
        if(state->flags & SS_IOCARD){
                debug(3, ":IOCARD");
        }
index ff66604e90d4d7620fe58af4c28dec12ae874be2..d1ad0966392dc5bc4fcf31b136ff8757525a2c50 100644 (file)
@@ -64,8 +64,8 @@
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
 
-#ifdef PCMCIA_DEBUG
-static int pc_debug = PCMCIA_DEBUG;
+#ifdef CONFIG_PCMCIA_DEBUG
+static int pc_debug;
 module_param(pc_debug, int, 0);
 #define dprintk(args...) printk(KERN_DEBUG "m8xx_pcmcia: " args);
 #else
index a234ce1967a3d7b4186a6a9993b7492a75d87c14..5554015a7813c74f7c84352aacc190345dde6da6 100644 (file)
@@ -140,7 +140,8 @@ static int o2micro_override(struct yenta_socket *socket)
                a = config_readb(socket, O2_RESERVED1);
                b = config_readb(socket, O2_RESERVED2);
 
-               printk(KERN_INFO "Yenta O2: res at 0x94/0xD4: %02x/%02x\n", a, b);
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "O2: res at 0x94/0xD4: %02x/%02x\n", a, b);
 
                switch (socket->dev->device) {
                /*
@@ -153,7 +154,9 @@ static int o2micro_override(struct yenta_socket *socket)
                case PCI_DEVICE_ID_O2_6812:
                case PCI_DEVICE_ID_O2_6832:
                case PCI_DEVICE_ID_O2_6836:
-                       printk(KERN_INFO "Yenta O2: old bridge, disabling read prefetch/write burst\n");
+                       dev_printk(KERN_INFO, &socket->dev->dev,
+                                  "Yenta O2: old bridge, disabling read "
+                                  "prefetch/write burst\n");
                        config_writeb(socket, O2_RESERVED1,
                                      a & ~(O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST));
                        config_writeb(socket, O2_RESERVED2,
@@ -161,7 +164,8 @@ static int o2micro_override(struct yenta_socket *socket)
                        break;
 
                default:
-                       printk(KERN_INFO "Yenta O2: enabling read prefetch/write burst\n");
+                       dev_printk(KERN_INFO , &socket->dev->dev,
+                                  "O2: enabling read prefetch/write burst\n");
                        config_writeb(socket, O2_RESERVED1,
                                      a | O2_RES_READ_PREFETCH | O2_RES_WRITE_BURST);
                        config_writeb(socket, O2_RESERVED2,
index 419f97fc9a625befbd2805ec1b0693a4bb1af6b1..1703b20cad5d215ae1a2295329d87a2b253380f1 100644 (file)
@@ -38,7 +38,6 @@
 #include <pcmcia/ss.h>
 
 #include "cs_internal.h"
-#include "ds_internal.h"
 
 static int major_dev = -1;
 
@@ -58,7 +57,7 @@ typedef struct user_info_t {
 } user_info_t;
 
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 extern int ds_pc_debug;
 
 #define ds_dbg(lvl, fmt, arg...) do {          \
@@ -149,7 +148,7 @@ static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
 
        irq = adj->resource.irq.IRQ;
        if ((irq < 0) || (irq > 15))
-               return CS_BAD_IRQ;
+               return -EINVAL;
 
        if (adj->Action != REMOVE_MANAGED_RESOURCE)
                return 0;
@@ -167,7 +166,7 @@ static int adjust_irq(struct pcmcia_socket *s, adjust_t *adj)
 #else
 
 static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
-       return CS_SUCCESS;
+       return 0;
 }
 
 #endif
@@ -175,7 +174,7 @@ static inline int adjust_irq(struct pcmcia_socket *s, adjust_t *adj) {
 static int pcmcia_adjust_resource_info(adjust_t *adj)
 {
        struct pcmcia_socket *s;
-       int ret = CS_UNSUPPORTED_FUNCTION;
+       int ret = -ENOSYS;
        unsigned long flags;
 
        down_read(&pcmcia_socket_list_rwsem);
@@ -248,7 +247,7 @@ static int pccard_get_status(struct pcmcia_socket *s,
        if (s->state & SOCKET_SUSPEND)
                status->CardState |= CS_EVENT_PM_SUSPEND;
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;
 
        c = (p_dev) ? p_dev->function_config : NULL;
 
@@ -274,7 +273,7 @@ static int pccard_get_status(struct pcmcia_socket *s,
                        status->CardState |=
                                (reg & ESR_REQ_ATTN) ? CS_EVENT_REQUEST_ATTENTION : 0;
                }
-               return CS_SUCCESS;
+               return 0;
        }
        status->CardState |=
                (val & SS_WRPROT) ? CS_EVENT_WRITE_PROTECT : 0;
@@ -284,9 +283,81 @@ static int pccard_get_status(struct pcmcia_socket *s,
                (val & SS_BATWARN) ? CS_EVENT_BATTERY_LOW : 0;
        status->CardState |=
                (val & SS_READY) ? CS_EVENT_READY_CHANGE : 0;
-       return CS_SUCCESS;
+       return 0;
 } /* pccard_get_status */
 
+int pccard_get_configuration_info(struct pcmcia_socket *s,
+                                 struct pcmcia_device *p_dev,
+                                 config_info_t *config)
+{
+       config_t *c;
+
+       if (!(s->state & SOCKET_PRESENT))
+               return -ENODEV;
+
+
+#ifdef CONFIG_CARDBUS
+       if (s->state & SOCKET_CARDBUS) {
+               memset(config, 0, sizeof(config_info_t));
+               config->Vcc = s->socket.Vcc;
+               config->Vpp1 = config->Vpp2 = s->socket.Vpp;
+               config->Option = s->cb_dev->subordinate->number;
+               if (s->state & SOCKET_CARDBUS_CONFIG) {
+                       config->Attributes = CONF_VALID_CLIENT;
+                       config->IntType = INT_CARDBUS;
+                       config->AssignedIRQ = s->irq.AssignedIRQ;
+                       if (config->AssignedIRQ)
+                               config->Attributes |= CONF_ENABLE_IRQ;
+                       if (s->io[0].res) {
+                               config->BasePort1 = s->io[0].res->start;
+                               config->NumPorts1 = s->io[0].res->end -
+                                       config->BasePort1 + 1;
+                       }
+               }
+               return 0;
+       }
+#endif
+
+       if (p_dev) {
+               c = p_dev->function_config;
+               config->Function = p_dev->func;
+       } else {
+               c = NULL;
+               config->Function = 0;
+       }
+
+       if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
+               config->Attributes = 0;
+               config->Vcc = s->socket.Vcc;
+               config->Vpp1 = config->Vpp2 = s->socket.Vpp;
+               return 0;
+       }
+
+       config->Attributes = c->Attributes | CONF_VALID_CLIENT;
+       config->Vcc = s->socket.Vcc;
+       config->Vpp1 = config->Vpp2 = s->socket.Vpp;
+       config->IntType = c->IntType;
+       config->ConfigBase = c->ConfigBase;
+       config->Status = c->Status;
+       config->Pin = c->Pin;
+       config->Copy = c->Copy;
+       config->Option = c->Option;
+       config->ExtStatus = c->ExtStatus;
+       config->Present = config->CardValues = c->CardValues;
+       config->IRQAttributes = c->irq.Attributes;
+       config->AssignedIRQ = s->irq.AssignedIRQ;
+       config->BasePort1 = c->io.BasePort1;
+       config->NumPorts1 = c->io.NumPorts1;
+       config->Attributes1 = c->io.Attributes1;
+       config->BasePort2 = c->io.BasePort2;
+       config->NumPorts2 = c->io.NumPorts2;
+       config->Attributes2 = c->io.Attributes2;
+       config->IOAddrLines = c->io.IOAddrLines;
+
+       return 0;
+} /* pccard_get_configuration_info */
+
+
 /*======================================================================
 
     These manage a ring buffer of events pending for one user process
@@ -764,7 +835,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
     case DS_GET_CONFIGURATION_INFO:
        if (buf->config.Function &&
           (buf->config.Function >= s->functions))
-           ret = CS_BAD_ARGS;
+           ret = -EINVAL;
        else {
            struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->config.Function);
            ret = pccard_get_configuration_info(s, p_dev, &buf->config);
@@ -787,15 +858,15 @@ static int ds_ioctl(struct inode * inode, struct file * file,
        break;
     case DS_PARSE_TUPLE:
        buf->tuple.TupleData = buf->tuple_parse.data;
-       ret = pccard_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
+       ret = pcmcia_parse_tuple(&buf->tuple, &buf->tuple_parse.parse);
        break;
     case DS_RESET_CARD:
-       ret = pccard_reset_card(s);
+       ret = pcmcia_reset_card(s);
        break;
     case DS_GET_STATUS:
            if (buf->status.Function &&
                (buf->status.Function >= s->functions))
-                   ret = CS_BAD_ARGS;
+                   ret = -EINVAL;
            else {
                    struct pcmcia_device *p_dev = get_pcmcia_device(s, buf->status.Function);
                    ret = pccard_get_status(s, p_dev, &buf->status);
@@ -826,7 +897,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
            goto free_out;
        }
 
-       ret = CS_BAD_ARGS;
+       ret = -EINVAL;
 
        if (!(buf->conf_reg.Function &&
             (buf->conf_reg.Function >= s->functions))) {
@@ -867,7 +938,7 @@ static int ds_ioctl(struct inode * inode, struct file * file,
                           &buf->win_info.map);
        break;
     case DS_REPLACE_CIS:
-       ret = pcmcia_replace_cis(s, &buf->cisdump);
+       ret = pcmcia_replace_cis(s, buf->cisdump.Data, buf->cisdump.Length);
        break;
     case DS_BIND_REQUEST:
        if (!capable(CAP_SYS_ADMIN)) {
@@ -889,22 +960,19 @@ static int ds_ioctl(struct inode * inode, struct file * file,
        err = -EINVAL;
     }
 
-    if ((err == 0) && (ret != CS_SUCCESS)) {
+    if ((err == 0) && (ret != 0)) {
        ds_dbg(2, "ds_ioctl: ret = %d\n", ret);
        switch (ret) {
-       case CS_BAD_SOCKET: case CS_NO_CARD:
-           err = -ENODEV; break;
-       case CS_BAD_ARGS: case CS_BAD_ATTRIBUTE: case CS_BAD_IRQ:
-       case CS_BAD_TUPLE:
-           err = -EINVAL; break;
-       case CS_IN_USE:
-           err = -EBUSY; break;
-       case CS_OUT_OF_RESOURCE:
+       case -ENODEV:
+       case -EINVAL:
+       case -EBUSY:
+       case -ENOSYS:
+           err = ret;
+           break;
+       case -ENOMEM:
            err = -ENOSPC; break;
-       case CS_NO_MORE_ITEMS:
+       case -ENOSPC:
            err = -ENODATA; break;
-       case CS_UNSUPPORTED_FUNCTION:
-           err = -ENOSYS; break;
        default:
            err = -EIO; break;
        }
index 4884a18cf9e69918c0e3371cebb5a89b944921bb..afea2b2558b5d63d3af6fe04f230011a66fdd415 100644 (file)
@@ -29,7 +29,6 @@
 #include <pcmcia/ds.h>
 
 #include "cs_internal.h"
-#include "ds_internal.h"
 
 
 /* Access speed for IO windows */
@@ -44,16 +43,17 @@ static u8 pcmcia_used_irq[NR_IRQS];
 #endif
 
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 extern int ds_pc_debug;
 
 #define ds_dbg(skt, lvl, fmt, arg...) do {                     \
        if (ds_pc_debug >= lvl)                                 \
-               printk(KERN_DEBUG "pcmcia_resource: %s: " fmt,  \
-                       cs_socket_name(skt) , ## arg);          \
+               dev_printk(KERN_DEBUG, &skt->dev,               \
+                          "pcmcia_resource: " fmt,             \
+                          ## arg);                             \
 } while (0)
 #else
-#define ds_dbg(lvl, fmt, arg...) do { } while (0)
+#define ds_dbg(skt, lvl, fmt, arg...) do { } while (0)
 #endif
 
 
@@ -168,13 +168,13 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
        u_char val;
 
        if (!p_dev || !p_dev->function_config)
-               return CS_NO_CARD;
+               return -EINVAL;
 
        s = p_dev->socket;
        c = p_dev->function_config;
 
        if (!(c->state & CONFIG_LOCKED))
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        addr = (c->ConfigBase + reg->Offset) >> 1;
 
@@ -188,93 +188,14 @@ int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
                pcmcia_write_cis_mem(s, 1, addr, 1, &val);
                break;
        default:
-               return CS_BAD_ARGS;
+               return -EINVAL;
                break;
        }
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_access_configuration_register */
 EXPORT_SYMBOL(pcmcia_access_configuration_register);
 
 
-int pccard_get_configuration_info(struct pcmcia_socket *s,
-                                 struct pcmcia_device *p_dev,
-                                 config_info_t *config)
-{
-       config_t *c;
-
-       if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
-
-
-#ifdef CONFIG_CARDBUS
-       if (s->state & SOCKET_CARDBUS) {
-               memset(config, 0, sizeof(config_info_t));
-               config->Vcc = s->socket.Vcc;
-               config->Vpp1 = config->Vpp2 = s->socket.Vpp;
-               config->Option = s->cb_dev->subordinate->number;
-               if (s->state & SOCKET_CARDBUS_CONFIG) {
-                       config->Attributes = CONF_VALID_CLIENT;
-                       config->IntType = INT_CARDBUS;
-                       config->AssignedIRQ = s->irq.AssignedIRQ;
-                       if (config->AssignedIRQ)
-                               config->Attributes |= CONF_ENABLE_IRQ;
-                       if (s->io[0].res) {
-                               config->BasePort1 = s->io[0].res->start;
-                               config->NumPorts1 = s->io[0].res->end - config->BasePort1 + 1;
-                       }
-               }
-               return CS_SUCCESS;
-       }
-#endif
-
-       if (p_dev) {
-               c = p_dev->function_config;
-               config->Function = p_dev->func;
-       } else {
-               c = NULL;
-               config->Function = 0;
-       }
-
-       if ((c == NULL) || !(c->state & CONFIG_LOCKED)) {
-               config->Attributes = 0;
-               config->Vcc = s->socket.Vcc;
-               config->Vpp1 = config->Vpp2 = s->socket.Vpp;
-               return CS_SUCCESS;
-       }
-
-       config->Attributes = c->Attributes | CONF_VALID_CLIENT;
-       config->Vcc = s->socket.Vcc;
-       config->Vpp1 = config->Vpp2 = s->socket.Vpp;
-       config->IntType = c->IntType;
-       config->ConfigBase = c->ConfigBase;
-       config->Status = c->Status;
-       config->Pin = c->Pin;
-       config->Copy = c->Copy;
-       config->Option = c->Option;
-       config->ExtStatus = c->ExtStatus;
-       config->Present = config->CardValues = c->CardValues;
-       config->IRQAttributes = c->irq.Attributes;
-       config->AssignedIRQ = s->irq.AssignedIRQ;
-       config->BasePort1 = c->io.BasePort1;
-       config->NumPorts1 = c->io.NumPorts1;
-       config->Attributes1 = c->io.Attributes1;
-       config->BasePort2 = c->io.BasePort2;
-       config->NumPorts2 = c->io.NumPorts2;
-       config->Attributes2 = c->io.Attributes2;
-       config->IOAddrLines = c->io.IOAddrLines;
-
-       return CS_SUCCESS;
-} /* pccard_get_configuration_info */
-
-int pcmcia_get_configuration_info(struct pcmcia_device *p_dev,
-                                 config_info_t *config)
-{
-       return pccard_get_configuration_info(p_dev->socket, p_dev,
-                                            config);
-}
-EXPORT_SYMBOL(pcmcia_get_configuration_info);
-
-
 /** pcmcia_get_window
  */
 int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
@@ -284,12 +205,12 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
        int w;
 
        if (!s || !(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;
        for (w = idx; w < MAX_WIN; w++)
                if (s->state & SOCKET_WIN_REQ(w))
                        break;
        if (w == MAX_WIN)
-               return CS_NO_MORE_ITEMS;
+               return -EINVAL;
        win = &s->win[w];
        req->Base = win->ctl.res->start;
        req->Size = win->ctl.res->end - win->ctl.res->start + 1;
@@ -304,7 +225,7 @@ int pcmcia_get_window(struct pcmcia_socket *s, window_handle_t *handle,
        if (win->ctl.flags & MAP_USE_WAIT)
                req->Attributes |= WIN_USE_WAIT;
        *handle = win;
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_get_window */
 EXPORT_SYMBOL(pcmcia_get_window);
 
@@ -316,10 +237,10 @@ EXPORT_SYMBOL(pcmcia_get_window);
 int pcmcia_get_mem_page(window_handle_t win, memreq_t *req)
 {
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        req->Page = 0;
        req->CardOffset = win->ctl.card_start;
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_get_mem_page */
 EXPORT_SYMBOL(pcmcia_get_mem_page);
 
@@ -328,14 +249,18 @@ int pcmcia_map_mem_page(window_handle_t win, memreq_t *req)
 {
        struct pcmcia_socket *s;
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
-       if (req->Page != 0)
-               return CS_BAD_PAGE;
+               return -EINVAL;
        s = win->sock;
+       if (req->Page != 0) {
+               ds_dbg(s, 0, "failure: requested page is zero\n");
+               return -EINVAL;
+       }
        win->ctl.card_start = req->CardOffset;
-       if (s->ops->set_mem_map(s, &win->ctl) != 0)
-               return CS_BAD_OFFSET;
-       return CS_SUCCESS;
+       if (s->ops->set_mem_map(s, &win->ctl) != 0) {
+               ds_dbg(s, 0, "failed to set_mem_map\n");
+               return -EIO;
+       }
+       return 0;
 } /* pcmcia_map_mem_page */
 EXPORT_SYMBOL(pcmcia_map_mem_page);
 
@@ -354,9 +279,9 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
        c = p_dev->function_config;
 
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;
        if (!(c->state & CONFIG_LOCKED))
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        if (mod->Attributes & CONF_IRQ_CHANGE_VALID) {
                if (mod->Attributes & CONF_ENABLE_IRQ) {
@@ -369,20 +294,28 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
                s->ops->set_socket(s, &s->socket);
        }
 
-       if (mod->Attributes & CONF_VCC_CHANGE_VALID)
-               return CS_BAD_VCC;
+       if (mod->Attributes & CONF_VCC_CHANGE_VALID) {
+               ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
+               return -EINVAL;
+       }
 
        /* We only allow changing Vpp1 and Vpp2 to the same value */
        if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) &&
            (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
                if (mod->Vpp1 != mod->Vpp2)
-                       return CS_BAD_VPP;
+                       ds_dbg(s, 0, "Vpp1 and Vpp2 must be the same\n");
+                       return -EINVAL;
                s->socket.Vpp = mod->Vpp1;
-               if (s->ops->set_socket(s, &s->socket))
-                       return CS_BAD_VPP;
+               if (s->ops->set_socket(s, &s->socket)) {
+                       dev_printk(KERN_WARNING, &s->dev,
+                                  "Unable to set VPP\n");
+                       return -EIO;
+               }
        } else if ((mod->Attributes & CONF_VPP1_CHANGE_VALID) ||
-                  (mod->Attributes & CONF_VPP2_CHANGE_VALID))
-               return CS_BAD_VPP;
+                  (mod->Attributes & CONF_VPP2_CHANGE_VALID)) {
+               ds_dbg(s, 0, "changing Vcc is not allowed at this time\n");
+               return -EINVAL;
+       }
 
        if (mod->Attributes & CONF_IO_CHANGE_WIDTH) {
                pccard_io_map io_off = { 0, 0, 0, 0, 1 };
@@ -406,7 +339,7 @@ int pcmcia_modify_configuration(struct pcmcia_device *p_dev,
                }
        }
 
-       return CS_SUCCESS;
+       return 0;
 } /* modify_configuration */
 EXPORT_SYMBOL(pcmcia_modify_configuration);
 
@@ -441,7 +374,7 @@ int pcmcia_release_configuration(struct pcmcia_device *p_dev)
                        }
        }
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_release_configuration */
 
 
@@ -459,7 +392,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
        config_t *c = p_dev->function_config;
 
        if (!p_dev->_io )
-               return CS_BAD_HANDLE;
+               return -EINVAL;
 
        p_dev->_io = 0;
 
@@ -467,7 +400,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
            (c->io.NumPorts1 != req->NumPorts1) ||
            (c->io.BasePort2 != req->BasePort2) ||
            (c->io.NumPorts2 != req->NumPorts2))
-               return CS_BAD_ARGS;
+               return -EINVAL;
 
        c->state &= ~CONFIG_IO_REQ;
 
@@ -475,7 +408,7 @@ static int pcmcia_release_io(struct pcmcia_device *p_dev, io_req_t *req)
        if (req->NumPorts2)
                release_io_space(s, req->BasePort2, req->NumPorts2);
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_release_io */
 
 
@@ -485,15 +418,19 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        config_t *c= p_dev->function_config;
 
        if (!p_dev->_irq)
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        p_dev->_irq = 0;
 
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->irq.Attributes != req->Attributes)
-               return CS_BAD_ATTRIBUTE;
-       if (s->irq.AssignedIRQ != req->AssignedIRQ)
-               return CS_BAD_IRQ;
+               return -EACCES;
+       if (c->irq.Attributes != req->Attributes) {
+               ds_dbg(s, 0, "IRQ attributes must match assigned ones\n");
+               return -EINVAL;
+       }
+       if (s->irq.AssignedIRQ != req->AssignedIRQ) {
+               ds_dbg(s, 0, "IRQ must match assigned one\n");
+               return -EINVAL;
+       }
        if (--s->irq.Config == 0) {
                c->state &= ~CONFIG_IRQ_REQ;
                s->irq.AssignedIRQ = 0;
@@ -507,7 +444,7 @@ static int pcmcia_release_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        pcmcia_used_irq[req->AssignedIRQ]--;
 #endif
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_release_irq */
 
 
@@ -516,10 +453,10 @@ int pcmcia_release_window(window_handle_t win)
        struct pcmcia_socket *s;
 
        if ((win == NULL) || (win->magic != WINDOW_MAGIC))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
        s = win->sock;
        if (!(win->handle->_win & CLIENT_WIN_REQ(win->index)))
-               return CS_BAD_HANDLE;
+               return -EINVAL;
 
        /* Shut down memory window */
        win->ctl.flags &= ~MAP_ACTIVE;
@@ -536,7 +473,7 @@ int pcmcia_release_window(window_handle_t win)
 
        win->magic = 0;
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_release_window */
 EXPORT_SYMBOL(pcmcia_release_window);
 
@@ -551,18 +488,23 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
        pccard_io_map iomap;
 
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;;
 
-       if (req->IntType & INT_CARDBUS)
-               return CS_UNSUPPORTED_MODE;
+       if (req->IntType & INT_CARDBUS) {
+               ds_dbg(p_dev->socket, 0, "IntType may not be INT_CARDBUS\n");
+               return -EINVAL;
+       }
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
+               return -EACCES;
 
        /* Do power control.  We don't allow changes in Vcc. */
        s->socket.Vpp = req->Vpp;
-       if (s->ops->set_socket(s, &s->socket))
-               return CS_BAD_VPP;
+       if (s->ops->set_socket(s, &s->socket)) {
+               dev_printk(KERN_WARNING, &s->dev,
+                          "Unable to set socket state\n");
+               return -EINVAL;
+       }
 
        /* Pick memory or I/O card, DMA mode, interrupt */
        c->IntType = req->IntType;
@@ -651,7 +593,7 @@ int pcmcia_request_configuration(struct pcmcia_device *p_dev,
 
        c->state |= CONFIG_LOCKED;
        p_dev->_locked = 1;
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_request_configuration */
 EXPORT_SYMBOL(pcmcia_request_configuration);
 
@@ -667,37 +609,48 @@ int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req)
        config_t *c;
 
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;
 
        if (!req)
-               return CS_UNSUPPORTED_MODE;
+               return -EINVAL;
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->state & CONFIG_IO_REQ)
-               return CS_IN_USE;
-       if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))
-               return CS_BAD_ATTRIBUTE;
+               return -EACCES;
+       if (c->state & CONFIG_IO_REQ) {
+               ds_dbg(s, 0, "IO already configured\n");
+               return -EBUSY;
+       }
+       if (req->Attributes1 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)) {
+               ds_dbg(s, 0, "bad attribute setting for IO region 1\n");
+               return -EINVAL;
+       }
        if ((req->NumPorts2 > 0) &&
-           (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS)))
-               return CS_BAD_ATTRIBUTE;
+           (req->Attributes2 & (IO_SHARED | IO_FORCE_ALIAS_ACCESS))) {
+               ds_dbg(s, 0, "bad attribute setting for IO region 2\n");
+               return -EINVAL;
+       }
 
+       ds_dbg(s, 1, "trying to allocate resource 1\n");
        if (alloc_io_space(s, req->Attributes1, &req->BasePort1,
-                          req->NumPorts1, req->IOAddrLines))
-               return CS_IN_USE;
+                          req->NumPorts1, req->IOAddrLines)) {
+               ds_dbg(s, 0, "allocation of resource 1 failed\n");
+               return -EBUSY;
+       }
 
        if (req->NumPorts2) {
+               ds_dbg(s, 1, "trying to allocate resource 2\n");
                if (alloc_io_space(s, req->Attributes2, &req->BasePort2,
                                   req->NumPorts2, req->IOAddrLines)) {
+                       ds_dbg(s, 0, "allocation of resource 2 failed\n");
                        release_io_space(s, req->BasePort1, req->NumPorts1);
-                       return CS_IN_USE;
+                       return -EBUSY;
                }
        }
 
        c->io = *req;
        c->state |= CONFIG_IO_REQ;
        p_dev->_io = 1;
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_request_io */
 EXPORT_SYMBOL(pcmcia_request_io);
 
@@ -723,16 +676,18 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
 {
        struct pcmcia_socket *s = p_dev->socket;
        config_t *c;
-       int ret = CS_IN_USE, irq = 0;
+       int ret = -EINVAL, irq = 0;
        int type;
 
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
+               return -ENODEV;
        c = p_dev->function_config;
        if (c->state & CONFIG_LOCKED)
-               return CS_CONFIGURATION_LOCKED;
-       if (c->state & CONFIG_IRQ_REQ)
-               return CS_IN_USE;
+               return -EACCES;
+       if (c->state & CONFIG_IRQ_REQ) {
+               ds_dbg(s, 0, "IRQ already configured\n");
+               return -EBUSY;
+       }
 
        /* Decide what type of interrupt we are registering */
        type = 0;
@@ -795,15 +750,19 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        }
 
        if (ret && (req->Attributes & IRQ_HANDLE_PRESENT)) {
-               if (request_irq(irq, req->Handler, type,  p_dev->devname, req->Instance))
-                       return CS_IN_USE;
+               ret = request_irq(irq, req->Handler, type,
+                                 p_dev->devname, req->Instance);
+               if (ret)
+                       return ret;
        }
 
        /* Make sure the fact the request type was overridden is passed back */
        if (type == IRQF_SHARED && !(req->Attributes & IRQ_TYPE_DYNAMIC_SHARING)) {
                req->Attributes |= IRQ_TYPE_DYNAMIC_SHARING;
-               printk(KERN_WARNING "pcmcia: request for exclusive IRQ could not be fulfilled.\n");
-               printk(KERN_WARNING "pcmcia: the driver needs updating to supported shared IRQ lines.\n");
+               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: "
+                       "request for exclusive IRQ could not be fulfilled.\n");
+               dev_printk(KERN_WARNING, &p_dev->dev, "pcmcia: the driver "
+                       "needs updating to supported shared IRQ lines.\n");
        }
        c->irq.Attributes = req->Attributes;
        s->irq.AssignedIRQ = req->AssignedIRQ = irq;
@@ -816,7 +775,7 @@ int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req)
        pcmcia_used_irq[irq]++;
 #endif
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_request_irq */
 EXPORT_SYMBOL(pcmcia_request_irq);
 
@@ -834,9 +793,11 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        int w;
 
        if (!(s->state & SOCKET_PRESENT))
-               return CS_NO_CARD;
-       if (req->Attributes & (WIN_PAGED | WIN_SHARED))
-               return CS_BAD_ATTRIBUTE;
+               return -ENODEV;
+       if (req->Attributes & (WIN_PAGED | WIN_SHARED)) {
+               ds_dbg(s, 0, "bad attribute setting for iomem region\n");
+               return -EINVAL;
+       }
 
        /* Window size defaults to smallest available */
        if (req->Size == 0)
@@ -844,19 +805,25 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        align = (((s->features & SS_CAP_MEM_ALIGN) ||
                  (req->Attributes & WIN_STRICT_ALIGN)) ?
                 req->Size : s->map_size);
-       if (req->Size & (s->map_size-1))
-               return CS_BAD_SIZE;
+       if (req->Size & (s->map_size-1)) {
+               ds_dbg(s, 0, "invalid map size\n");
+               return -EINVAL;
+       }
        if ((req->Base && (s->features & SS_CAP_STATIC_MAP)) ||
-           (req->Base & (align-1)))
-               return CS_BAD_BASE;
+           (req->Base & (align-1))) {
+               ds_dbg(s, 0, "invalid base address\n");
+               return -EINVAL;
+       }
        if (req->Base)
                align = 0;
 
        /* Allocate system memory window */
        for (w = 0; w < MAX_WIN; w++)
                if (!(s->state & SOCKET_WIN_REQ(w))) break;
-       if (w == MAX_WIN)
-               return CS_OUT_OF_RESOURCE;
+       if (w == MAX_WIN) {
+               ds_dbg(s, 0, "all windows are used already\n");
+               return -EINVAL;
+       }
 
        win = &s->win[w];
        win->magic = WINDOW_MAGIC;
@@ -867,8 +834,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        if (!(s->features & SS_CAP_STATIC_MAP)) {
                win->ctl.res = pcmcia_find_mem_region(req->Base, req->Size, align,
                                                      (req->Attributes & WIN_MAP_BELOW_1MB), s);
-               if (!win->ctl.res)
-                       return CS_IN_USE;
+               if (!win->ctl.res) {
+                       ds_dbg(s, 0, "allocating mem region failed\n");
+                       return -EINVAL;
+               }
        }
        (*p_dev)->_win |= CLIENT_WIN_REQ(w);
 
@@ -885,8 +854,10 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        if (req->Attributes & WIN_USE_WAIT)
                win->ctl.flags |= MAP_USE_WAIT;
        win->ctl.card_start = 0;
-       if (s->ops->set_mem_map(s, &win->ctl) != 0)
-               return CS_BAD_ARGS;
+       if (s->ops->set_mem_map(s, &win->ctl) != 0) {
+               ds_dbg(s, 0, "failed to set memory mapping\n");
+               return -EIO;
+       }
        s->state |= SOCKET_WIN_REQ(w);
 
        /* Return window handle */
@@ -897,7 +868,7 @@ int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_h
        }
        *wh = win;
 
-       return CS_SUCCESS;
+       return 0;
 } /* pcmcia_request_window */
 EXPORT_SYMBOL(pcmcia_request_window);
 
@@ -909,3 +880,79 @@ void pcmcia_disable_device(struct pcmcia_device *p_dev) {
                pcmcia_release_window(p_dev->win);
 }
 EXPORT_SYMBOL(pcmcia_disable_device);
+
+
+struct pcmcia_cfg_mem {
+       tuple_t tuple;
+       cisparse_t parse;
+       u8 buf[256];
+       cistpl_cftable_entry_t dflt;
+};
+
+/**
+ * pcmcia_loop_config() - loop over configuration options
+ * @p_dev:     the struct pcmcia_device which we need to loop for.
+ * @conf_check:        function to call for each configuration option.
+ *             It gets passed the struct pcmcia_device, the CIS data
+ *             describing the configuration option, and private data
+ *             being passed to pcmcia_loop_config()
+ * @priv_data: private data to be passed to the conf_check function.
+ *
+ * pcmcia_loop_config() loops over all configuration options, and calls
+ * the driver-specific conf_check() for each one, checking whether
+ * it is a valid one.
+ */
+int pcmcia_loop_config(struct pcmcia_device *p_dev,
+                      int      (*conf_check)   (struct pcmcia_device *p_dev,
+                                                cistpl_cftable_entry_t *cfg,
+                                                cistpl_cftable_entry_t *dflt,
+                                                unsigned int vcc,
+                                                void *priv_data),
+                      void *priv_data)
+{
+       struct pcmcia_cfg_mem *cfg_mem;
+
+       tuple_t *tuple;
+       int ret = -ENODEV;
+       unsigned int vcc;
+
+       cfg_mem = kzalloc(sizeof(struct pcmcia_cfg_mem), GFP_KERNEL);
+       if (cfg_mem == NULL)
+               return -ENOMEM;
+
+       /* get the current Vcc setting */
+       vcc = p_dev->socket->socket.Vcc;
+
+       tuple = &cfg_mem->tuple;
+       tuple->TupleData = cfg_mem->buf;
+       tuple->TupleDataMax = 255;
+       tuple->TupleOffset = 0;
+       tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
+       tuple->Attributes = 0;
+
+       ret = pcmcia_get_first_tuple(p_dev, tuple);
+       while (!ret) {
+               cistpl_cftable_entry_t *cfg = &cfg_mem->parse.cftable_entry;
+
+               if (pcmcia_get_tuple_data(p_dev, tuple))
+                       goto next_entry;
+
+               if (pcmcia_parse_tuple(tuple, &cfg_mem->parse))
+                       goto next_entry;
+
+               /* default values */
+               p_dev->conf.ConfigIndex = cfg->index;
+               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
+                       cfg_mem->dflt = *cfg;
+
+               ret = conf_check(p_dev, cfg, &cfg_mem->dflt, vcc, priv_data);
+               if (!ret)
+                       break;
+
+next_entry:
+               ret = pcmcia_get_next_tuple(p_dev, tuple);
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(pcmcia_loop_config);
index 13f1e0fd3f31cf096b5c07cf10392278e0308bdc..bb9ddb9532e35a6790aa6f50dcaa1a5a7aba7b75 100644 (file)
@@ -36,7 +36,6 @@
 #include <pcmcia/ss.h>
 #include <pcmcia/cistpl.h>
 
-#include "cs_internal.h"
 #include "soc_common.h"
 #include "pxa2xx_base.h"
 
index 203e579ebbd22e77e5413f86995bce689cc87508..17f4ecf1c0c5b214af03b7188ecedca3e516d8b5 100644 (file)
@@ -122,19 +122,22 @@ static void free_region(struct resource *res)
 
 static int add_interval(struct resource_map *map, u_long base, u_long num)
 {
-    struct resource_map *p, *q;
+       struct resource_map *p, *q;
 
-    for (p = map; ; p = p->next) {
-       if ((p != map) && (p->base+p->num-1 >= base))
-           return -1;
-       if ((p->next == map) || (p->next->base > base+num-1))
-           break;
-    }
-    q = kmalloc(sizeof(struct resource_map), GFP_KERNEL);
-    if (!q) return CS_OUT_OF_RESOURCE;
-    q->base = base; q->num = num;
-    q->next = p->next; p->next = q;
-    return CS_SUCCESS;
+       for (p = map; ; p = p->next) {
+               if ((p != map) && (p->base+p->num-1 >= base))
+                       return -1;
+               if ((p->next == map) || (p->next->base > base+num-1))
+                       break;
+       }
+       q = kmalloc(sizeof(struct resource_map), GFP_KERNEL);
+       if (!q) {
+               printk(KERN_WARNING "out of memory to update resources\n");
+               return -ENOMEM;
+       }
+       q->base = base; q->num = num;
+       q->next = p->next; p->next = q;
+       return 0;
 }
 
 /*====================================================================*/
@@ -166,7 +169,10 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num)
            } else {
                /* Split the block into two pieces */
                p = kmalloc(sizeof(struct resource_map), GFP_KERNEL);
-               if (!p) return CS_OUT_OF_RESOURCE;
+               if (!p) {
+                   printk(KERN_WARNING "out of memory to update resources\n");
+                   return -ENOMEM;
+               }
                p->base = base+num;
                p->num = q->base+q->num - p->base;
                q->num = base - q->base;
@@ -174,7 +180,7 @@ static int sub_interval(struct resource_map *map, u_long base, u_long num)
            }
        }
     }
-    return CS_SUCCESS;
+    return 0;
 }
 
 /*======================================================================
@@ -194,13 +200,14 @@ static void do_io_probe(struct pcmcia_socket *s, unsigned int base,
     int any;
     u_char *b, hole, most;
 
-    printk(KERN_INFO "cs: IO port probe %#x-%#x:",
-          base, base+num-1);
+    dev_printk(KERN_INFO, &s->dev, "cs: IO port probe %#x-%#x:",
+              base, base+num-1);
 
     /* First, what does a floating port look like? */
     b = kzalloc(256, GFP_KERNEL);
     if (!b) {
-            printk(KERN_ERR "do_io_probe: unable to kmalloc 256 bytes");
+           dev_printk(KERN_ERR, &s->dev,
+                  "do_io_probe: unable to kmalloc 256 bytes");
             return;
     }
     for (i = base, most = 0; i < base+num; i += 8) {
@@ -366,8 +373,8 @@ static int do_mem_probe(u_long base, u_long num, struct pcmcia_socket *s)
     struct socket_data *s_data = s->resource_data;
     u_long i, j, bad, fail, step;
 
-    printk(KERN_INFO "cs: memory probe 0x%06lx-0x%06lx:",
-          base, base+num-1);
+    dev_printk(KERN_INFO, &s->dev, "cs: memory probe 0x%06lx-0x%06lx:",
+              base, base+num-1);
     bad = fail = 0;
     step = (num < 0x20000) ? 0x2000 : ((num>>4) & ~0x1fff);
     /* don't allow too large steps */
@@ -431,8 +438,8 @@ static int validate_mem(struct pcmcia_socket *s, unsigned int probe_mask)
        if (probe_mask & MEM_PROBE_HIGH) {
                if (inv_probe(s_data->mem_db.next, s) > 0)
                        return 0;
-               printk(KERN_NOTICE "cs: warning: no high memory space "
-                      "available!\n");
+               dev_printk(KERN_NOTICE, &s->dev,
+                          "cs: warning: no high memory space available!\n");
                return -ENODEV;
        }
 
@@ -794,10 +801,11 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
                if (res->flags & IORESOURCE_IO) {
                        if (res == &ioport_resource)
                                continue;
-                       printk(KERN_INFO "pcmcia: parent PCI bridge I/O "
-                               "window: 0x%llx - 0x%llx\n",
-                               (unsigned long long)res->start,
-                               (unsigned long long)res->end);
+                       dev_printk(KERN_INFO, &s->cb_dev->dev,
+                                  "pcmcia: parent PCI bridge I/O "
+                                  "window: 0x%llx - 0x%llx\n",
+                                  (unsigned long long)res->start,
+                                  (unsigned long long)res->end);
                        if (!adjust_io(s, ADD_MANAGED_RESOURCE, res->start, res->end))
                                done |= IORESOURCE_IO;
 
@@ -806,10 +814,11 @@ static int nonstatic_autoadd_resources(struct pcmcia_socket *s)
                if (res->flags & IORESOURCE_MEM) {
                        if (res == &iomem_resource)
                                continue;
-                       printk(KERN_INFO "pcmcia: parent PCI bridge Memory "
-                               "window: 0x%llx - 0x%llx\n",
-                               (unsigned long long)res->start,
-                               (unsigned long long)res->end);
+                       dev_printk(KERN_INFO, &s->cb_dev->dev,
+                                  "pcmcia: parent PCI bridge Memory "
+                                  "window: 0x%llx - 0x%llx\n",
+                                  (unsigned long long)res->start,
+                                  (unsigned long long)res->end);
                        if (!adjust_memory(s, ADD_MANAGED_RESOURCE, res->start, res->end))
                                done |= IORESOURCE_MEM;
                }
index da3972153226a019c424ae98972ae8796e274f89..f49ac6666153bca4718a4813878bb5fba5f7b429 100644 (file)
@@ -54,7 +54,7 @@
 #include <mach/pxa-regs.h>
 #endif
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 
 static int pc_debug;
 module_param(pc_debug, int, 0644);
index 91ef6a0da3ab14d84893ee47129de75876d7cf4d..38c67375f363aeb9483a5656170a453e61c4101a 100644 (file)
@@ -15,7 +15,6 @@
 #include <pcmcia/cs.h>
 #include <pcmcia/ss.h>
 #include <pcmcia/cistpl.h>
-#include "cs_internal.h"
 
 
 struct device;
@@ -137,7 +136,7 @@ extern int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_lev
 extern int soc_common_drv_pcmcia_remove(struct device *dev);
 
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 
 extern void soc_pcmcia_debug(struct soc_pcmcia_socket *skt, const char *func,
                             int lvl, const char *fmt, ...);
index 006a29e91d83d58118ee8ff5a40234a45efcc85e..ff9a3bb3c88d5c26e4f619c23f444352817167d2 100644 (file)
@@ -316,27 +316,18 @@ static ssize_t pccard_store_cis(struct kobject *kobj,
                                char *buf, loff_t off, size_t count)
 {
        struct pcmcia_socket *s = to_socket(container_of(kobj, struct device, kobj));
-       cisdump_t *cis;
        int error;
 
        if (off)
                return -EINVAL;
 
-       if (count >= 0x200)
+       if (count >= CISTPL_MAX_CIS_SIZE)
                return -EINVAL;
 
        if (!(s->state & SOCKET_PRESENT))
                return -ENODEV;
 
-       cis = kzalloc(sizeof(cisdump_t), GFP_KERNEL);
-       if (!cis)
-               return -ENOMEM;
-
-       cis->Length = count + 1;
-       memcpy(cis->Data, buf, count);
-
-       error = pcmcia_replace_cis(s, cis);
-       kfree(cis);
+       error = pcmcia_replace_cis(s, buf, count);
        if (error)
                return -EIO;
 
index 5792bd5c54f93a4a3a3394d665145209b2f5c5e8..2a613e920fd4d19c4b9b802ec0ce291916c85fd8 100644 (file)
@@ -55,7 +55,7 @@
 #include <pcmcia/ss.h>
 #include "tcic.h"
 
-#ifdef DEBUG
+#ifdef CONFIG_PCMCIA_DEBUG
 static int pc_debug;
 
 module_param(pc_debug, int, 0644);
index 129db7bd06c3661e291204f893bb4c6dedbcccd6..aaa70227bfb05ee4df811a00fc11df5670d8d50c 100644 (file)
@@ -339,8 +339,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
 
        mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC);
        devctl = config_readb(socket, TI113X_DEVICE_CONTROL);
-       printk(KERN_INFO "Yenta TI: socket %s, mfunc 0x%08x, devctl 0x%02x\n",
-              pci_name(socket->dev), mfunc, devctl);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "TI: mfunc 0x%08x, devctl 0x%02x\n", mfunc, devctl);
 
        /* make sure PCI interrupts are enabled before probing */
        ti_init(socket);
@@ -354,8 +354,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
         * We're here which means PCI interrupts are _not_ delivered. try to
         * find the right setting (all serial or parallel)
         */
-       printk(KERN_INFO "Yenta TI: socket %s probing PCI interrupt failed, trying to fix\n",
-              pci_name(socket->dev));
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "TI: probing PCI interrupt failed, trying to fix\n");
 
        /* for serial PCI make sure MFUNC3 is set to IRQSER */
        if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) {
@@ -379,8 +379,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
 
                                pci_irq_status = yenta_probe_cb_irq(socket);
                                if (pci_irq_status == 1) {
-                                       printk(KERN_INFO "Yenta TI: socket %s all-serial interrupts ok\n",
-                                              pci_name(socket->dev));
+                                       dev_printk(KERN_INFO, &socket->dev->dev,
+                                           "TI: all-serial interrupts ok\n");
                                        mfunc_old = mfunc;
                                        goto out;
                                }
@@ -395,8 +395,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
                }
 
                /* serial PCI interrupts not working fall back to parallel */
-               printk(KERN_INFO "Yenta TI: socket %s falling back to parallel PCI interrupts\n",
-                      pci_name(socket->dev));
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "TI: falling back to parallel PCI interrupts\n");
                devctl &= ~TI113X_DCR_IMODE_MASK;
                devctl |= TI113X_DCR_IMODE_SERIAL; /* serial ISA could be right */
                config_writeb(socket, TI113X_DEVICE_CONTROL, devctl);
@@ -427,8 +427,8 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
        pci_irq_status = yenta_probe_cb_irq(socket);
        if (pci_irq_status == 1) {
                mfunc_old = mfunc;
-               printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts ok\n",
-                      pci_name(socket->dev));
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "TI: parallel PCI interrupts ok\n");
        } else {
                /* not working, back to old value */
                mfunc = mfunc_old;
@@ -440,8 +440,9 @@ static void ti12xx_irqroute_func0(struct yenta_socket *socket)
 out:
        if (pci_irq_status < 1) {
                socket->cb_irq = 0;
-               printk(KERN_INFO "Yenta TI: socket %s no PCI interrupts. Fish. Please report.\n",
-                      pci_name(socket->dev));
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "Yenta TI: no PCI interrupts. Fish. "
+                          "Please report.\n");
        }
 }
 
@@ -513,8 +514,9 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
 
        mfunc = mfunc_old = config_readl(socket, TI122X_MFUNC);
        devctl = config_readb(socket, TI113X_DEVICE_CONTROL);
-       printk(KERN_INFO "Yenta TI: socket %s, mfunc 0x%08x, devctl 0x%02x\n",
-              pci_name(socket->dev), mfunc, devctl);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "TI: mfunc 0x%08x, devctl 0x%02x\n",
+                  mfunc, devctl);
 
        /* if IRQs are configured as tied, align irq of func1 with func0 */
        sysctl = config_readl(socket, TI113X_SYSTEM_CONTROL);
@@ -533,9 +535,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
         * We're here which means PCI interrupts are _not_ delivered. try to
         * find the right setting
         */
-       printk(KERN_INFO "Yenta TI: socket %s probing PCI interrupt failed, trying to fix\n",
-              pci_name(socket->dev));
-
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "TI: probing PCI interrupt failed, trying to fix\n");
 
        /* if all serial: set INTRTIE, probe again */
        if ((devctl & TI113X_DCR_IMODE_MASK) == TI12XX_DCR_IMODE_ALL_SERIAL) {
@@ -544,8 +545,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
                if (ti12xx_tie_interrupts(socket, &old_irq)) {
                        pci_irq_status = yenta_probe_cb_irq(socket);
                        if (pci_irq_status == 1) {
-                               printk(KERN_INFO "Yenta TI: socket %s all-serial interrupts, tied ok\n",
-                                      pci_name(socket->dev));
+                               dev_printk(KERN_INFO, &socket->dev->dev,
+                                       "TI: all-serial interrupts, tied ok\n");
                                goto out;
                        }
 
@@ -582,8 +583,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
 
                        pci_irq_status = yenta_probe_cb_irq(socket);
                        if (pci_irq_status == 1) {
-                               printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts ok\n",
-                                      pci_name(socket->dev));
+                               dev_printk(KERN_INFO, &socket->dev->dev,
+                                          "TI: parallel PCI interrupts ok\n");
                                goto out;
                        }
 
@@ -593,13 +594,13 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
                        if (pci_irq_status == -1)
                                goto out;
                }
-               
+
                /* still nothing: set INTRTIE */
                if (ti12xx_tie_interrupts(socket, &old_irq)) {
                        pci_irq_status = yenta_probe_cb_irq(socket);
                        if (pci_irq_status == 1) {
-                               printk(KERN_INFO "Yenta TI: socket %s parallel PCI interrupts, tied ok\n",
-                                      pci_name(socket->dev));
+                               dev_printk(KERN_INFO, &socket->dev->dev,
+                                   "TI: parallel PCI interrupts, tied ok\n");
                                goto out;
                        }
 
@@ -610,8 +611,8 @@ static void ti12xx_irqroute_func1(struct yenta_socket *socket)
 out:
        if (pci_irq_status < 1) {
                socket->cb_irq = 0;
-               printk(KERN_INFO "Yenta TI: socket %s no PCI interrupts. Fish. Please report.\n",
-                      pci_name(socket->dev));
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "TI: no PCI interrupts. Fish. Please report.\n");
        }
 }
 
@@ -815,11 +816,13 @@ static int ti12xx_override(struct yenta_socket *socket)
        /* make sure that memory burst is active */
        val_orig = val = config_readl(socket, TI113X_SYSTEM_CONTROL);
        if (disable_clkrun && PCI_FUNC(socket->dev->devfn) == 0) {
-               printk(KERN_INFO "Yenta: Disabling CLKRUN feature\n");
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "Disabling CLKRUN feature\n");
                val |= TI113X_SCR_KEEPCLK;
        }
        if (!(val & TI122X_SCR_MRBURSTUP)) {
-               printk(KERN_INFO "Yenta: Enabling burst memory read transactions\n");
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "Enabling burst memory read transactions\n");
                val |= TI122X_SCR_MRBURSTUP;
        }
        if (val_orig != val)
@@ -830,10 +833,12 @@ static int ti12xx_override(struct yenta_socket *socket)
         * CSC interrupts to PCI rather than INTVAL.
         */
        val = config_readb(socket, TI1250_DIAGNOSTIC);
-       printk(KERN_INFO "Yenta: Using %s to route CSC interrupts to PCI\n",
-               (val & TI1250_DIAG_PCI_CSC) ? "CSCINT" : "INTVAL");
-       printk(KERN_INFO "Yenta: Routing CardBus interrupts to %s\n",
-               (val & TI1250_DIAG_PCI_IREQ) ? "PCI" : "ISA");
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "Using %s to route CSC interrupts to PCI\n",
+                  (val & TI1250_DIAG_PCI_CSC) ? "CSCINT" : "INTVAL");
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "Routing CardBus interrupts to %s\n",
+                  (val & TI1250_DIAG_PCI_IREQ) ? "PCI" : "ISA");
 
        /* do irqrouting, depending on function */
        if (PCI_FUNC(socket->dev->devfn) == 0)
@@ -858,8 +863,9 @@ static int ti1250_override(struct yenta_socket *socket)
                diag |= TI1250_DIAG_PCI_CSC | TI1250_DIAG_PCI_IREQ;
 
        if (diag != old) {
-               printk(KERN_INFO "Yenta: adjusting diagnostic: %02x -> %02x\n",
-                       old, diag);
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "adjusting diagnostic: %02x -> %02x\n",
+                          old, diag);
                config_writeb(socket, TI1250_DIAGNOSTIC, diag);
        }
 
@@ -924,7 +930,9 @@ static void ene_tune_bridge(struct pcmcia_socket *sock, struct pci_bus *bus)
                /* default to clear TLTEnable bit, old behaviour */
                test_c9 &= ~ENE_TEST_C9_TLTENABLE;
 
-       printk(KERN_INFO "yenta EnE: chaning testregister 0xC9, %02x -> %02x\n", old_c9, test_c9);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "EnE: chaning testregister 0xC9, %02x -> %02x\n",
+                  old_c9, test_c9);
        config_writeb(socket, ENE_TEST_C9, test_c9);
 }
 
index 0ab1fb65cdc335541ae9bb0da1668686badef607..3ecd7c99d8eb69bba960e4127037fd84886b6171 100644 (file)
@@ -38,11 +38,7 @@ static int pwr_irqs_off;
 module_param(pwr_irqs_off, bool, 0644);
 MODULE_PARM_DESC(pwr_irqs_off, "Force IRQs off during power-on of slot. Use only when seeing IRQ storms!");
 
-#if 0
-#define debug(x,args...) printk(KERN_DEBUG "%s: " x, __func__ , ##args)
-#else
-#define debug(x,args...)
-#endif
+#define debug(x, s, args...) dev_dbg(&s->dev->dev, x, ##args)
 
 /* Don't ask.. */
 #define to_cycles(ns)  ((ns)/120)
@@ -69,13 +65,13 @@ MODULE_PARM_DESC (override_bios, "yenta ignore bios resource allocation");
 static inline u32 cb_readl(struct yenta_socket *socket, unsigned reg)
 {
        u32 val = readl(socket->base + reg);
-       debug("%p %04x %08x\n", socket, reg, val);
+       debug("%04x %08x\n", socket, reg, val);
        return val;
 }
 
 static inline void cb_writel(struct yenta_socket *socket, unsigned reg, u32 val)
 {
-       debug("%p %04x %08x\n", socket, reg, val);
+       debug("%04x %08x\n", socket, reg, val);
        writel(val, socket->base + reg);
        readl(socket->base + reg); /* avoid problems with PCI write posting */
 }
@@ -84,7 +80,7 @@ static inline u8 config_readb(struct yenta_socket *socket, unsigned offset)
 {
        u8 val;
        pci_read_config_byte(socket->dev, offset, &val);
-       debug("%p %04x %02x\n", socket, offset, val);
+       debug("%04x %02x\n", socket, offset, val);
        return val;
 }
 
@@ -92,7 +88,7 @@ static inline u16 config_readw(struct yenta_socket *socket, unsigned offset)
 {
        u16 val;
        pci_read_config_word(socket->dev, offset, &val);
-       debug("%p %04x %04x\n", socket, offset, val);
+       debug("%04x %04x\n", socket, offset, val);
        return val;
 }
 
@@ -100,32 +96,32 @@ static inline u32 config_readl(struct yenta_socket *socket, unsigned offset)
 {
        u32 val;
        pci_read_config_dword(socket->dev, offset, &val);
-       debug("%p %04x %08x\n", socket, offset, val);
+       debug("%04x %08x\n", socket, offset, val);
        return val;
 }
 
 static inline void config_writeb(struct yenta_socket *socket, unsigned offset, u8 val)
 {
-       debug("%p %04x %02x\n", socket, offset, val);
+       debug("%04x %02x\n", socket, offset, val);
        pci_write_config_byte(socket->dev, offset, val);
 }
 
 static inline void config_writew(struct yenta_socket *socket, unsigned offset, u16 val)
 {
-       debug("%p %04x %04x\n", socket, offset, val);
+       debug("%04x %04x\n", socket, offset, val);
        pci_write_config_word(socket->dev, offset, val);
 }
 
 static inline void config_writel(struct yenta_socket *socket, unsigned offset, u32 val)
 {
-       debug("%p %04x %08x\n", socket, offset, val);
+       debug("%04x %08x\n", socket, offset, val);
        pci_write_config_dword(socket->dev, offset, val);
 }
 
 static inline u8 exca_readb(struct yenta_socket *socket, unsigned reg)
 {
        u8 val = readb(socket->base + 0x800 + reg);
-       debug("%p %04x %02x\n", socket, reg, val);
+       debug("%04x %02x\n", socket, reg, val);
        return val;
 }
 
@@ -134,20 +130,20 @@ static inline u8 exca_readw(struct yenta_socket *socket, unsigned reg)
        u16 val;
        val = readb(socket->base + 0x800 + reg);
        val |= readb(socket->base + 0x800 + reg + 1) << 8;
-       debug("%p %04x %04x\n", socket, reg, val);
+       debug("%04x %04x\n", socket, reg, val);
        return val;
 }
 
 static inline void exca_writeb(struct yenta_socket *socket, unsigned reg, u8 val)
 {
-       debug("%p %04x %02x\n", socket, reg, val);
+       debug("%04x %02x\n", socket, reg, val);
        writeb(val, socket->base + 0x800 + reg);
        readb(socket->base + 0x800 + reg); /* PCI write posting... */
 }
 
 static void exca_writew(struct yenta_socket *socket, unsigned reg, u16 val)
 {
-       debug("%p %04x %04x\n", socket, reg, val);
+       debug("%04x %04x\n", socket, reg, val);
        writeb(val, socket->base + 0x800 + reg);
        writeb(val >> 8, socket->base + 0x800 + reg + 1);
 
@@ -207,7 +203,7 @@ static int yenta_get_status(struct pcmcia_socket *sock, unsigned int *value)
 
 
        if (state & CB_CBCARD) {
-               val |= SS_CARDBUS;      
+               val |= SS_CARDBUS;
                val |= (state & CB_CARDSTS) ? SS_STSCHG : 0;
                val |= (state & (CB_CDETECT1 | CB_CDETECT2)) ? 0 : SS_DETECT;
                val |= (state & CB_PWRCYCLE) ? SS_POWERON | SS_READY : 0;
@@ -650,8 +646,10 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
                root = pci_find_parent_resource(socket->dev, res);
                if (root && (request_resource(root, res) == 0))
                        return 0;
-               printk(KERN_INFO "yenta %s: Preassigned resource %d busy or not available, reconfiguring...\n",
-                               pci_name(socket->dev), nr);
+               dev_printk(KERN_INFO, &socket->dev->dev,
+                          "Preassigned resource %d busy or not available, "
+                          "reconfiguring...\n",
+                          nr);
        }
 
        if (type & IORESOURCE_IO) {
@@ -674,8 +672,9 @@ static int yenta_allocate_res(struct yenta_socket *socket, int nr, unsigned type
                        return 1;
        }
 
-       printk(KERN_INFO "yenta %s: no resource of type %x available, trying to continue...\n",
-              pci_name(socket->dev), type);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "no resource of type %x available, trying to continue...\n",
+                  type);
        res->start = res->end = res->flags = 0;
        return 0;
 }
@@ -923,7 +922,8 @@ static int yenta_probe_cb_irq(struct yenta_socket *socket)
        socket->probe_status = 0;
 
        if (request_irq(socket->cb_irq, yenta_probe_handler, IRQF_SHARED, "yenta", socket)) {
-               printk(KERN_WARNING "Yenta: request_irq() in yenta_probe_cb_irq() failed!\n");
+               dev_printk(KERN_WARNING, &socket->dev->dev,
+                          "request_irq() in yenta_probe_cb_irq() failed!\n");
                return -1;
        }
 
@@ -960,8 +960,9 @@ static void yenta_get_socket_capabilities(struct yenta_socket *socket, u32 isa_i
        else
                socket->socket.irq_mask = 0;
 
-       printk(KERN_INFO "Yenta: ISA IRQ mask 0x%04x, PCI irq %d\n",
-              socket->socket.irq_mask, socket->cb_irq);
+       dev_printk(KERN_INFO, &socket->dev->dev,
+                  "ISA IRQ mask 0x%04x, PCI irq %d\n",
+                  socket->socket.irq_mask, socket->cb_irq);
 }
 
 /*
@@ -1051,8 +1052,9 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
 
        /* Show that the wanted subordinate number is not possible: */
        if (cardbus_bridge->subordinate > upper_limit)
-               printk(KERN_WARNING "Yenta: Upper limit for fixing this "
-                       "bridge's parent bridge: #%02x\n", upper_limit);
+               dev_printk(KERN_WARNING, &cardbus_bridge->dev,
+                          "Upper limit for fixing this "
+                          "bridge's parent bridge: #%02x\n", upper_limit);
 
        /* If we have room to increase the bridge's subordinate number, */
        if (bridge_to_fix->subordinate < upper_limit) {
@@ -1061,10 +1063,11 @@ static void yenta_fixup_parent_bridge(struct pci_bus *cardbus_bridge)
                unsigned char subordinate_to_assign =
                        min(cardbus_bridge->subordinate, upper_limit);
 
-               printk(KERN_INFO "Yenta: Raising subordinate bus# of parent "
-                       "bus (#%02x) from #%02x to #%02x\n",
-                       bridge_to_fix->number,
-                       bridge_to_fix->subordinate, subordinate_to_assign);
+               dev_printk(KERN_INFO, &bridge_to_fix->dev,
+                          "Raising subordinate bus# of parent "
+                          "bus (#%02x) from #%02x to #%02x\n",
+                          bridge_to_fix->number,
+                          bridge_to_fix->subordinate, subordinate_to_assign);
 
                /* Save the new subordinate in the bus struct of the bridge */
                bridge_to_fix->subordinate = subordinate_to_assign;
@@ -1091,8 +1094,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
         * Bail out if so.
         */
        if (!dev->subordinate) {
-               printk(KERN_ERR "Yenta: no bus associated with %s! "
-                       "(try 'pci=assign-busses')\n", pci_name(dev));
+               dev_printk(KERN_ERR, &dev->dev, "no bus associated! "
+                          "(try 'pci=assign-busses')\n");
                return -ENODEV;
        }
 
@@ -1127,7 +1130,7 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
                goto disable;
 
        if (!pci_resource_start(dev, 0)) {
-               printk(KERN_ERR "No cardbus resource!\n");
+               dev_printk(KERN_ERR, &dev->dev, "No cardbus resource!\n");
                ret = -ENODEV;
                goto release;
        }
@@ -1146,8 +1149,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
         * report the subsystem vendor and device for help debugging
         * the irq stuff...
         */
-       printk(KERN_INFO "Yenta: CardBus bridge found at %s [%04x:%04x]\n",
-               pci_name(dev), dev->subsystem_vendor, dev->subsystem_device);
+       dev_printk(KERN_INFO, &dev->dev, "CardBus bridge found [%04x:%04x]\n",
+                  dev->subsystem_vendor, dev->subsystem_device);
 
        yenta_config_init(socket);
 
@@ -1179,8 +1182,12 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
                socket->poll_timer.data = (unsigned long)socket;
                socket->poll_timer.expires = jiffies + HZ;
                add_timer(&socket->poll_timer);
-               printk(KERN_INFO "Yenta: no PCI IRQ, CardBus support disabled for this socket.\n"
-                      KERN_INFO "Yenta: check your BIOS CardBus, BIOS IRQ or ACPI settings.\n");
+               dev_printk(KERN_INFO, &dev->dev,
+                          "no PCI IRQ, CardBus support disabled for this "
+                          "socket.\n");
+               dev_printk(KERN_INFO, &dev->dev,
+                          "check your BIOS CardBus, BIOS IRQ or ACPI "
+                          "settings.\n");
        } else {
                socket->socket.features |= SS_CAP_CARDBUS;
        }
@@ -1188,7 +1195,8 @@ static int __devinit yenta_probe (struct pci_dev *dev, const struct pci_device_i
        /* Figure out what the dang thing can do for the PCMCIA layer... */
        yenta_interrogate(socket);
        yenta_get_socket_capabilities(socket, isa_interrupts);
-       printk(KERN_INFO "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE));
+       dev_printk(KERN_INFO, &dev->dev,
+                  "Socket status: %08x\n", cb_readl(socket, CB_SOCKET_STATE));
 
        yenta_fixup_parent_bridge(dev->subordinate);
 
index a656128f1fdd80c70f01f1ec4f128b6b2aacb954..4dada6ee1119464a7d3136bfb47d3805c605d0c4 100644 (file)
@@ -56,4 +56,28 @@ config REGULATOR_BQ24022
          charging select between 100 mA and 500 mA charging current
          limit.
 
+config REGULATOR_WM8350
+       tristate "Wolfson Microelectroncis WM8350 AudioPlus PMIC"
+       depends on MFD_WM8350
+       select REGULATOR
+       help
+         This driver provides support for the voltage and current regulators
+          of the WM8350 AudioPlus PMIC.
+
+config REGULATOR_WM8400
+       tristate "Wolfson Microelectroncis WM8400 AudioPlus PMIC"
+       depends on MFD_WM8400
+       select REGULATOR
+       help
+         This driver provides support for the voltage regulators of the
+         WM8400 AudioPlus PMIC.
+
+config REGULATOR_DA903X
+       tristate "Support regulators on Dialog Semiconductor DA9030/DA9034 PMIC"
+       depends on PMIC_DA903X
+       select REGULATOR
+       help
+         Say y here to support the BUCKs and LDOs regulators found on
+         Dialog Semiconductor DA9030/DA9034 PMIC.
+
 endmenu
index ac2c64efe65c6478a851aecb11cb9eb4f793466e..254d40c02ee8cefd29e4f332f12b6c99603d705d 100644 (file)
@@ -8,5 +8,8 @@ obj-$(CONFIG_REGULATOR_FIXED_VOLTAGE) += fixed.o
 obj-$(CONFIG_REGULATOR_VIRTUAL_CONSUMER) += virtual.o
 
 obj-$(CONFIG_REGULATOR_BQ24022) += bq24022.o
+obj-$(CONFIG_REGULATOR_WM8350) += wm8350-regulator.o
+obj-$(CONFIG_REGULATOR_WM8400) += wm8400-regulator.o
+obj-$(CONFIG_REGULATOR_DA903X) += da903x.o
 
 ccflags-$(CONFIG_REGULATOR_DEBUG) += -DDEBUG
index 263699d6152d2b662e1889df0cd37235c51c664c..366565aba865380672a3ed0e2e04e07b98d40238 100644 (file)
 #include <linux/regulator/bq24022.h>
 #include <linux/regulator/driver.h>
 
+
 static int bq24022_set_current_limit(struct regulator_dev *rdev,
                                        int min_uA, int max_uA)
 {
-       struct platform_device *pdev = rdev_get_drvdata(rdev);
-       struct bq24022_mach_info *pdata = pdev->dev.platform_data;
+       struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
 
-       dev_dbg(&pdev->dev, "setting current limit to %s mA\n",
+       dev_dbg(rdev_get_dev(rdev), "setting current limit to %s mA\n",
                max_uA >= 500000 ? "500" : "100");
 
        /* REVISIT: maybe return error if min_uA != 0 ? */
@@ -34,18 +34,16 @@ static int bq24022_set_current_limit(struct regulator_dev *rdev,
 
 static int bq24022_get_current_limit(struct regulator_dev *rdev)
 {
-       struct platform_device *pdev = rdev_get_drvdata(rdev);
-       struct bq24022_mach_info *pdata = pdev->dev.platform_data;
+       struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
 
        return gpio_get_value(pdata->gpio_iset2) ? 500000 : 100000;
 }
 
 static int bq24022_enable(struct regulator_dev *rdev)
 {
-       struct platform_device *pdev = rdev_get_drvdata(rdev);
-       struct bq24022_mach_info *pdata = pdev->dev.platform_data;
+       struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
 
-       dev_dbg(&pdev->dev, "enabling charger\n");
+       dev_dbg(rdev_get_dev(rdev), "enabling charger\n");
 
        gpio_set_value(pdata->gpio_nce, 0);
        return 0;
@@ -53,10 +51,9 @@ static int bq24022_enable(struct regulator_dev *rdev)
 
 static int bq24022_disable(struct regulator_dev *rdev)
 {
-       struct platform_device *pdev = rdev_get_drvdata(rdev);
-       struct bq24022_mach_info *pdata = pdev->dev.platform_data;
+       struct bq24022_mach_info *pdata = rdev_get_drvdata(rdev);
 
-       dev_dbg(&pdev->dev, "disabling charger\n");
+       dev_dbg(rdev_get_dev(rdev), "disabling charger\n");
 
        gpio_set_value(pdata->gpio_nce, 1);
        return 0;
@@ -108,7 +105,7 @@ static int __init bq24022_probe(struct platform_device *pdev)
        ret = gpio_direction_output(pdata->gpio_iset2, 0);
        ret = gpio_direction_output(pdata->gpio_nce, 1);
 
-       bq24022 = regulator_register(&bq24022_desc, pdev);
+       bq24022 = regulator_register(&bq24022_desc, &pdev->dev, pdata);
        if (IS_ERR(bq24022)) {
                dev_dbg(&pdev->dev, "couldn't register regulator\n");
                ret = PTR_ERR(bq24022);
index 9c79862615685d39d92f7e2b73cd2a8638bf21d7..02a774424e8de2bbade4eafeaadf6b8160fc05ef 100644 (file)
@@ -2,8 +2,9 @@
  * core.c  --  Voltage/Current Regulator framework.
  *
  * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ * Copyright 2008 SlimLogic Ltd.
  *
- * Author: Liam Girdwood <liam.girdwood@wolfsonmicro.com>
+ * Author: Liam Girdwood <lrg@slimlogic.co.uk>
  *
  *  This program is free software; you can redistribute  it and/or modify it
  *  under  the terms of  the GNU General  Public License as published by the
@@ -64,14 +65,9 @@ struct regulator_map {
        struct list_head list;
        struct device *dev;
        const char *supply;
-       const char *regulator;
+       struct regulator_dev *regulator;
 };
 
-static inline struct regulator_dev *to_rdev(struct device *d)
-{
-       return container_of(d, struct regulator_dev, dev);
-}
-
 /*
  * struct regulator
  *
@@ -227,7 +223,7 @@ static ssize_t device_requested_uA_show(struct device *dev,
 static ssize_t regulator_uV_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        ssize_t ret;
 
        mutex_lock(&rdev->mutex);
@@ -240,15 +236,31 @@ static ssize_t regulator_uV_show(struct device *dev,
 static ssize_t regulator_uA_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        return sprintf(buf, "%d\n", _regulator_get_current_limit(rdev));
 }
 
+static ssize_t regulator_name_show(struct device *dev,
+                            struct device_attribute *attr, char *buf)
+{
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
+       const char *name;
+
+       if (rdev->constraints->name)
+               name = rdev->constraints->name;
+       else if (rdev->desc->name)
+               name = rdev->desc->name;
+       else
+               name = "";
+
+       return sprintf(buf, "%s\n", name);
+}
+
 static ssize_t regulator_opmode_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        int mode = _regulator_get_mode(rdev);
 
        switch (mode) {
@@ -267,7 +279,7 @@ static ssize_t regulator_opmode_show(struct device *dev,
 static ssize_t regulator_state_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        int state = _regulator_is_enabled(rdev);
 
        if (state > 0)
@@ -281,7 +293,7 @@ static ssize_t regulator_state_show(struct device *dev,
 static ssize_t regulator_min_uA_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "constraint not defined\n");
@@ -292,7 +304,7 @@ static ssize_t regulator_min_uA_show(struct device *dev,
 static ssize_t regulator_max_uA_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "constraint not defined\n");
@@ -303,7 +315,7 @@ static ssize_t regulator_max_uA_show(struct device *dev,
 static ssize_t regulator_min_uV_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "constraint not defined\n");
@@ -314,7 +326,7 @@ static ssize_t regulator_min_uV_show(struct device *dev,
 static ssize_t regulator_max_uV_show(struct device *dev,
                                    struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "constraint not defined\n");
@@ -325,7 +337,7 @@ static ssize_t regulator_max_uV_show(struct device *dev,
 static ssize_t regulator_total_uA_show(struct device *dev,
                                      struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        struct regulator *regulator;
        int uA = 0;
 
@@ -339,14 +351,14 @@ static ssize_t regulator_total_uA_show(struct device *dev,
 static ssize_t regulator_num_users_show(struct device *dev,
                                      struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        return sprintf(buf, "%d\n", rdev->use_count);
 }
 
 static ssize_t regulator_type_show(struct device *dev,
                                  struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        switch (rdev->desc->type) {
        case REGULATOR_VOLTAGE:
@@ -360,7 +372,7 @@ static ssize_t regulator_type_show(struct device *dev,
 static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -370,7 +382,7 @@ static ssize_t regulator_suspend_mem_uV_show(struct device *dev,
 static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -380,7 +392,7 @@ static ssize_t regulator_suspend_disk_uV_show(struct device *dev,
 static ssize_t regulator_suspend_standby_uV_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -406,7 +418,7 @@ static ssize_t suspend_opmode_show(struct regulator_dev *rdev,
 static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -417,7 +429,7 @@ static ssize_t regulator_suspend_mem_mode_show(struct device *dev,
 static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -428,7 +440,7 @@ static ssize_t regulator_suspend_disk_mode_show(struct device *dev,
 static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
                                struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -439,7 +451,7 @@ static ssize_t regulator_suspend_standby_mode_show(struct device *dev,
 static ssize_t regulator_suspend_mem_state_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -453,7 +465,7 @@ static ssize_t regulator_suspend_mem_state_show(struct device *dev,
 static ssize_t regulator_suspend_disk_state_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -467,7 +479,7 @@ static ssize_t regulator_suspend_disk_state_show(struct device *dev,
 static ssize_t regulator_suspend_standby_state_show(struct device *dev,
                                   struct device_attribute *attr, char *buf)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
 
        if (!rdev->constraints)
                return sprintf(buf, "not defined\n");
@@ -477,7 +489,9 @@ static ssize_t regulator_suspend_standby_state_show(struct device *dev,
        else
                return sprintf(buf, "disabled\n");
 }
+
 static struct device_attribute regulator_dev_attrs[] = {
+       __ATTR(name, 0444, regulator_name_show, NULL),
        __ATTR(microvolts, 0444, regulator_uV_show, NULL),
        __ATTR(microamps, 0444, regulator_uA_show, NULL),
        __ATTR(opmode, 0444, regulator_opmode_show, NULL),
@@ -512,7 +526,7 @@ static struct device_attribute regulator_dev_attrs[] = {
 
 static void regulator_dev_release(struct device *dev)
 {
-       struct regulator_dev *rdev = to_rdev(dev);
+       struct regulator_dev *rdev = dev_get_drvdata(dev);
        kfree(rdev);
 }
 
@@ -569,8 +583,11 @@ static int suspend_set_state(struct regulator_dev *rdev,
 
        /* enable & disable are mandatory for suspend control */
        if (!rdev->desc->ops->set_suspend_enable ||
-               !rdev->desc->ops->set_suspend_disable)
+               !rdev->desc->ops->set_suspend_disable) {
+               printk(KERN_ERR "%s: no way to set suspend state\n",
+                       __func__);
                return -EINVAL;
+       }
 
        if (rstate->enabled)
                ret = rdev->desc->ops->set_suspend_enable(rdev);
@@ -656,6 +673,155 @@ static void print_constraints(struct regulator_dev *rdev)
        printk(KERN_INFO "regulator: %s: %s\n", rdev->desc->name, buf);
 }
 
+/**
+ * set_machine_constraints - sets regulator constraints
+ * @regulator: regulator source
+ *
+ * Allows platform initialisation code to define and constrain
+ * regulator circuits e.g. valid voltage/current ranges, etc.  NOTE:
+ * Constraints *must* be set by platform code in order for some
+ * regulator operations to proceed i.e. set_voltage, set_current_limit,
+ * set_mode.
+ */
+static int set_machine_constraints(struct regulator_dev *rdev,
+       struct regulation_constraints *constraints)
+{
+       int ret = 0;
+       const char *name;
+       struct regulator_ops *ops = rdev->desc->ops;
+
+       if (constraints->name)
+               name = constraints->name;
+       else if (rdev->desc->name)
+               name = rdev->desc->name;
+       else
+               name = "regulator";
+
+       rdev->constraints = constraints;
+
+       /* do we need to apply the constraint voltage */
+       if (rdev->constraints->apply_uV &&
+               rdev->constraints->min_uV == rdev->constraints->max_uV &&
+               ops->set_voltage) {
+               ret = ops->set_voltage(rdev,
+                       rdev->constraints->min_uV, rdev->constraints->max_uV);
+                       if (ret < 0) {
+                               printk(KERN_ERR "%s: failed to apply %duV constraint to %s\n",
+                                      __func__,
+                                      rdev->constraints->min_uV, name);
+                               rdev->constraints = NULL;
+                               goto out;
+                       }
+       }
+
+       /* are we enabled at boot time by firmware / bootloader */
+       if (rdev->constraints->boot_on)
+               rdev->use_count = 1;
+
+       /* do we need to setup our suspend state */
+       if (constraints->initial_state) {
+               ret = suspend_prepare(rdev, constraints->initial_state);
+               if (ret < 0) {
+                       printk(KERN_ERR "%s: failed to set suspend state for %s\n",
+                              __func__, name);
+                       rdev->constraints = NULL;
+                       goto out;
+               }
+       }
+
+       /* if always_on is set then turn the regulator on if it's not
+        * already on. */
+       if (constraints->always_on && ops->enable &&
+           ((ops->is_enabled && !ops->is_enabled(rdev)) ||
+            (!ops->is_enabled && !constraints->boot_on))) {
+               ret = ops->enable(rdev);
+               if (ret < 0) {
+                       printk(KERN_ERR "%s: failed to enable %s\n",
+                              __func__, name);
+                       rdev->constraints = NULL;
+                       goto out;
+               }
+       }
+
+       print_constraints(rdev);
+out:
+       return ret;
+}
+
+/**
+ * set_supply - set regulator supply regulator
+ * @regulator: regulator name
+ * @supply: supply regulator name
+ *
+ * Called by platform initialisation code to set the supply regulator for this
+ * regulator. This ensures that a regulators supply will also be enabled by the
+ * core if it's child is enabled.
+ */
+static int set_supply(struct regulator_dev *rdev,
+       struct regulator_dev *supply_rdev)
+{
+       int err;
+
+       err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
+                               "supply");
+       if (err) {
+               printk(KERN_ERR
+                      "%s: could not add device link %s err %d\n",
+                      __func__, supply_rdev->dev.kobj.name, err);
+                      goto out;
+       }
+       rdev->supply = supply_rdev;
+       list_add(&rdev->slist, &supply_rdev->supply_list);
+out:
+       return err;
+}
+
+/**
+ * set_consumer_device_supply: Bind a regulator to a symbolic supply
+ * @regulator: regulator source
+ * @dev:       device the supply applies to
+ * @supply:    symbolic name for supply
+ *
+ * Allows platform initialisation code to map physical regulator
+ * sources to symbolic names for supplies for use by devices.  Devices
+ * should use these symbolic names to request regulators, avoiding the
+ * need to provide board-specific regulator names as platform data.
+ */
+static int set_consumer_device_supply(struct regulator_dev *rdev,
+       struct device *consumer_dev, const char *supply)
+{
+       struct regulator_map *node;
+
+       if (supply == NULL)
+               return -EINVAL;
+
+       node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
+       if (node == NULL)
+               return -ENOMEM;
+
+       node->regulator = rdev;
+       node->dev = consumer_dev;
+       node->supply = supply;
+
+       list_add(&node->list, &regulator_map_list);
+       return 0;
+}
+
+static void unset_consumer_device_supply(struct regulator_dev *rdev,
+       struct device *consumer_dev)
+{
+       struct regulator_map *node, *n;
+
+       list_for_each_entry_safe(node, n, &regulator_map_list, list) {
+               if (rdev == node->regulator &&
+                       consumer_dev == node->dev) {
+                       list_del(&node->list);
+                       kfree(node);
+                       return;
+               }
+       }
+}
+
 #define REG_STR_SIZE   32
 
 static struct regulator *create_regulator(struct regulator_dev *rdev,
@@ -746,7 +912,6 @@ struct regulator *regulator_get(struct device *dev, const char *id)
        struct regulator_dev *rdev;
        struct regulator_map *map;
        struct regulator *regulator = ERR_PTR(-ENODEV);
-       const char *supply = id;
 
        if (id == NULL) {
                printk(KERN_ERR "regulator: get() with no identifier\n");
@@ -758,15 +923,9 @@ struct regulator *regulator_get(struct device *dev, const char *id)
        list_for_each_entry(map, &regulator_map_list, list) {
                if (dev == map->dev &&
                    strcmp(map->supply, id) == 0) {
-                       supply = map->regulator;
-                       break;
-               }
-       }
-
-       list_for_each_entry(rdev, &regulator_list, list) {
-               if (strcmp(supply, rdev->desc->name) == 0 &&
-                   try_module_get(rdev->owner))
+                       rdev = map->regulator;
                        goto found;
+               }
        }
        printk(KERN_ERR "regulator: Unable to get requested regulator: %s\n",
               id);
@@ -774,12 +933,16 @@ struct regulator *regulator_get(struct device *dev, const char *id)
        return regulator;
 
 found:
+       if (!try_module_get(rdev->owner))
+               goto out;
+
        regulator = create_regulator(rdev, dev, id);
        if (regulator == NULL) {
                regulator = ERR_PTR(-ENOMEM);
                module_put(rdev->owner);
        }
 
+out:
        mutex_unlock(&regulator_list_mutex);
        return regulator;
 }
@@ -1559,11 +1722,12 @@ EXPORT_SYMBOL_GPL(regulator_notifier_call_chain);
  * Returns 0 on success.
  */
 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
-                                         void *reg_data)
+       struct device *dev, void *driver_data)
 {
        static atomic_t regulator_no = ATOMIC_INIT(0);
        struct regulator_dev *rdev;
-       int ret;
+       struct regulator_init_data *init_data = dev->platform_data;
+       int ret, i;
 
        if (regulator_desc == NULL)
                return ERR_PTR(-EINVAL);
@@ -1575,6 +1739,9 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
            !regulator_desc->type == REGULATOR_CURRENT)
                return ERR_PTR(-EINVAL);
 
+       if (!init_data)
+               return ERR_PTR(-EINVAL);
+
        rdev = kzalloc(sizeof(struct regulator_dev), GFP_KERNEL);
        if (rdev == NULL)
                return ERR_PTR(-ENOMEM);
@@ -1582,7 +1749,7 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
        mutex_lock(&regulator_list_mutex);
 
        mutex_init(&rdev->mutex);
-       rdev->reg_data = reg_data;
+       rdev->reg_data = driver_data;
        rdev->owner = regulator_desc->owner;
        rdev->desc = regulator_desc;
        INIT_LIST_HEAD(&rdev->consumer_list);
@@ -1591,20 +1758,68 @@ struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
        INIT_LIST_HEAD(&rdev->slist);
        BLOCKING_INIT_NOTIFIER_HEAD(&rdev->notifier);
 
+       /* preform any regulator specific init */
+       if (init_data->regulator_init) {
+               ret = init_data->regulator_init(rdev->reg_data);
+               if (ret < 0) {
+                       kfree(rdev);
+                       rdev = ERR_PTR(ret);
+                       goto out;
+               }
+       }
+
+       /* set regulator constraints */
+       ret = set_machine_constraints(rdev, &init_data->constraints);
+       if (ret < 0) {
+               kfree(rdev);
+               rdev = ERR_PTR(ret);
+               goto out;
+       }
+
+       /* register with sysfs */
        rdev->dev.class = &regulator_class;
-       device_initialize(&rdev->dev);
+       rdev->dev.parent = dev;
        snprintf(rdev->dev.bus_id, sizeof(rdev->dev.bus_id),
-                "regulator_%ld_%s",
-                (unsigned long)atomic_inc_return(&regulator_no) - 1,
-                regulator_desc->name);
-
-       ret = device_add(&rdev->dev);
-       if (ret == 0)
-               list_add(&rdev->list, &regulator_list);
-       else {
+                "regulator.%d", atomic_inc_return(&regulator_no) - 1);
+       ret = device_register(&rdev->dev);
+       if (ret != 0) {
                kfree(rdev);
                rdev = ERR_PTR(ret);
+               goto out;
+       }
+
+       dev_set_drvdata(&rdev->dev, rdev);
+
+       /* set supply regulator if it exists */
+       if (init_data->supply_regulator_dev) {
+               ret = set_supply(rdev,
+                       dev_get_drvdata(init_data->supply_regulator_dev));
+               if (ret < 0) {
+                       device_unregister(&rdev->dev);
+                       kfree(rdev);
+                       rdev = ERR_PTR(ret);
+                       goto out;
+               }
        }
+
+       /* add consumers devices */
+       for (i = 0; i < init_data->num_consumer_supplies; i++) {
+               ret = set_consumer_device_supply(rdev,
+                       init_data->consumer_supplies[i].dev,
+                       init_data->consumer_supplies[i].supply);
+               if (ret < 0) {
+                       for (--i; i >= 0; i--)
+                               unset_consumer_device_supply(rdev,
+                                       init_data->consumer_supplies[i].dev);
+                       device_unregister(&rdev->dev);
+                       kfree(rdev);
+                       rdev = ERR_PTR(ret);
+                       goto out;
+               }
+       }
+
+       list_add(&rdev->list, &regulator_list);
+out:
        mutex_unlock(&regulator_list_mutex);
        return rdev;
 }
@@ -1630,187 +1845,6 @@ void regulator_unregister(struct regulator_dev *rdev)
 }
 EXPORT_SYMBOL_GPL(regulator_unregister);
 
-/**
- * regulator_set_supply - set regulator supply regulator
- * @regulator: regulator name
- * @supply: supply regulator name
- *
- * Called by platform initialisation code to set the supply regulator for this
- * regulator. This ensures that a regulators supply will also be enabled by the
- * core if it's child is enabled.
- */
-int regulator_set_supply(const char *regulator, const char *supply)
-{
-       struct regulator_dev *rdev, *supply_rdev;
-       int err;
-
-       if (regulator == NULL || supply == NULL)
-               return -EINVAL;
-
-       mutex_lock(&regulator_list_mutex);
-
-       list_for_each_entry(rdev, &regulator_list, list) {
-               if (!strcmp(rdev->desc->name, regulator))
-                       goto found_regulator;
-       }
-       mutex_unlock(&regulator_list_mutex);
-       return -ENODEV;
-
-found_regulator:
-       list_for_each_entry(supply_rdev, &regulator_list, list) {
-               if (!strcmp(supply_rdev->desc->name, supply))
-                       goto found_supply;
-       }
-       mutex_unlock(&regulator_list_mutex);
-       return -ENODEV;
-
-found_supply:
-       err = sysfs_create_link(&rdev->dev.kobj, &supply_rdev->dev.kobj,
-                               "supply");
-       if (err) {
-               printk(KERN_ERR
-                      "%s: could not add device link %s err %d\n",
-                      __func__, supply_rdev->dev.kobj.name, err);
-                      goto out;
-       }
-       rdev->supply = supply_rdev;
-       list_add(&rdev->slist, &supply_rdev->supply_list);
-out:
-       mutex_unlock(&regulator_list_mutex);
-       return err;
-}
-EXPORT_SYMBOL_GPL(regulator_set_supply);
-
-/**
- * regulator_get_supply - get regulator supply regulator
- * @regulator: regulator name
- *
- * Returns the supply supply regulator name or NULL if no supply regulator
- * exists (i.e the regulator is supplied directly from USB, Line, Battery, etc)
- */
-const char *regulator_get_supply(const char *regulator)
-{
-       struct regulator_dev *rdev;
-
-       if (regulator == NULL)
-               return NULL;
-
-       mutex_lock(&regulator_list_mutex);
-       list_for_each_entry(rdev, &regulator_list, list) {
-               if (!strcmp(rdev->desc->name, regulator))
-                       goto found;
-       }
-       mutex_unlock(&regulator_list_mutex);
-       return NULL;
-
-found:
-       mutex_unlock(&regulator_list_mutex);
-       if (rdev->supply)
-               return rdev->supply->desc->name;
-       else
-               return NULL;
-}
-EXPORT_SYMBOL_GPL(regulator_get_supply);
-
-/**
- * regulator_set_machine_constraints - sets regulator constraints
- * @regulator: regulator source
- *
- * Allows platform initialisation code to define and constrain
- * regulator circuits e.g. valid voltage/current ranges, etc.  NOTE:
- * Constraints *must* be set by platform code in order for some
- * regulator operations to proceed i.e. set_voltage, set_current_limit,
- * set_mode.
- */
-int regulator_set_machine_constraints(const char *regulator_name,
-       struct regulation_constraints *constraints)
-{
-       struct regulator_dev *rdev;
-       int ret = 0;
-
-       if (regulator_name == NULL)
-               return -EINVAL;
-
-       mutex_lock(&regulator_list_mutex);
-
-       list_for_each_entry(rdev, &regulator_list, list) {
-               if (!strcmp(regulator_name, rdev->desc->name))
-                       goto found;
-       }
-       ret = -ENODEV;
-       goto out;
-
-found:
-       mutex_lock(&rdev->mutex);
-       rdev->constraints = constraints;
-
-       /* do we need to apply the constraint voltage */
-       if (rdev->constraints->apply_uV &&
-               rdev->constraints->min_uV == rdev->constraints->max_uV &&
-               rdev->desc->ops->set_voltage) {
-               ret = rdev->desc->ops->set_voltage(rdev,
-                       rdev->constraints->min_uV, rdev->constraints->max_uV);
-                       if (ret < 0) {
-                               printk(KERN_ERR "%s: failed to apply %duV"
-                                       " constraint\n", __func__,
-                                       rdev->constraints->min_uV);
-                               rdev->constraints = NULL;
-                               goto out;
-                       }
-       }
-
-       /* are we enabled at boot time by firmware / bootloader */
-       if (rdev->constraints->boot_on)
-               rdev->use_count = 1;
-
-       /* do we need to setup our suspend state */
-       if (constraints->initial_state)
-               ret = suspend_prepare(rdev, constraints->initial_state);
-
-       print_constraints(rdev);
-       mutex_unlock(&rdev->mutex);
-
-out:
-       mutex_unlock(&regulator_list_mutex);
-       return ret;
-}
-EXPORT_SYMBOL_GPL(regulator_set_machine_constraints);
-
-
-/**
- * regulator_set_device_supply: Bind a regulator to a symbolic supply
- * @regulator: regulator source
- * @dev:       device the supply applies to
- * @supply:    symbolic name for supply
- *
- * Allows platform initialisation code to map physical regulator
- * sources to symbolic names for supplies for use by devices.  Devices
- * should use these symbolic names to request regulators, avoiding the
- * need to provide board-specific regulator names as platform data.
- */
-int regulator_set_device_supply(const char *regulator, struct device *dev,
-                               const char *supply)
-{
-       struct regulator_map *node;
-
-       if (regulator == NULL || supply == NULL)
-               return -EINVAL;
-
-       node = kmalloc(sizeof(struct regulator_map), GFP_KERNEL);
-       if (node == NULL)
-               return -ENOMEM;
-
-       node->regulator = regulator;
-       node->dev = dev;
-       node->supply = supply;
-
-       mutex_lock(&regulator_list_mutex);
-       list_add(&node->list, &regulator_map_list);
-       mutex_unlock(&regulator_list_mutex);
-       return 0;
-}
-EXPORT_SYMBOL_GPL(regulator_set_device_supply);
-
 /**
  * regulator_suspend_prepare: prepare regulators for system wide suspend
  * @state: system suspend state
@@ -1893,6 +1927,18 @@ int rdev_get_id(struct regulator_dev *rdev)
 }
 EXPORT_SYMBOL_GPL(rdev_get_id);
 
+struct device *rdev_get_dev(struct regulator_dev *rdev)
+{
+       return &rdev->dev;
+}
+EXPORT_SYMBOL_GPL(rdev_get_dev);
+
+void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data)
+{
+       return reg_init_data->driver_data;
+}
+EXPORT_SYMBOL_GPL(regulator_get_init_drvdata);
+
 static int __init regulator_init(void)
 {
        printk(KERN_INFO "regulator: core version %s\n", REGULATOR_VERSION);
diff --git a/drivers/regulator/da903x.c b/drivers/regulator/da903x.c
new file mode 100644 (file)
index 0000000..3688e33
--- /dev/null
@@ -0,0 +1,513 @@
+/*
+ * Regulators driver for Dialog Semiconductor DA903x
+ *
+ * Copyright (C) 2006-2008 Marvell International Ltd.
+ * Copyright (C) 2008 Compulab Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/err.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+#include <linux/mfd/da903x.h>
+
+/* DA9030 Registers */
+#define DA9030_INVAL           (-1)
+#define DA9030_LDO1011         (0x10)
+#define DA9030_LDO15           (0x11)
+#define DA9030_LDO1416         (0x12)
+#define DA9030_LDO1819         (0x13)
+#define DA9030_LDO17           (0x14)
+#define DA9030_BUCK2DVM1       (0x15)
+#define DA9030_BUCK2DVM2       (0x16)
+#define DA9030_RCTL11          (0x17)
+#define DA9030_RCTL21          (0x18)
+#define DA9030_LDO1            (0x90)
+#define DA9030_LDO23           (0x91)
+#define DA9030_LDO45           (0x92)
+#define DA9030_LDO6            (0x93)
+#define DA9030_LDO78           (0x94)
+#define DA9030_LDO912          (0x95)
+#define DA9030_BUCK            (0x96)
+#define DA9030_RCTL12          (0x97)
+#define DA9030_RCTL22          (0x98)
+#define DA9030_LDO_UNLOCK      (0xa0)
+#define DA9030_LDO_UNLOCK_MASK (0xe0)
+#define DA9034_OVER1           (0x10)
+
+/* DA9034 Registers */
+#define DA9034_INVAL           (-1)
+#define DA9034_OVER2           (0x11)
+#define DA9034_OVER3           (0x12)
+#define DA9034_LDO643          (0x13)
+#define DA9034_LDO987          (0x14)
+#define DA9034_LDO1110         (0x15)
+#define DA9034_LDO1312         (0x16)
+#define DA9034_LDO1514         (0x17)
+#define DA9034_VCC1            (0x20)
+#define DA9034_ADTV1           (0x23)
+#define DA9034_ADTV2           (0x24)
+#define DA9034_AVRC            (0x25)
+#define DA9034_CDTV1           (0x26)
+#define DA9034_CDTV2           (0x27)
+#define DA9034_CVRC            (0x28)
+#define DA9034_SDTV1           (0x29)
+#define DA9034_SDTV2           (0x2a)
+#define DA9034_SVRC            (0x2b)
+#define DA9034_MDTV1           (0x32)
+#define DA9034_MDTV2           (0x33)
+#define DA9034_MVRC            (0x34)
+
+struct da903x_regulator_info {
+       struct regulator_desc desc;
+
+       int     min_uV;
+       int     max_uV;
+       int     step_uV;
+       int     vol_reg;
+       int     vol_shift;
+       int     vol_nbits;
+       int     update_reg;
+       int     update_bit;
+       int     enable_reg;
+       int     enable_bit;
+};
+
+static inline int check_range(struct da903x_regulator_info *info,
+                               int min_uV, int max_uV)
+{
+       if (min_uV < info->min_uV || min_uV > info->max_uV)
+               return -EINVAL;
+
+       return 0;
+}
+
+/* DA9030/DA9034 common operations */
+static int da903x_set_ldo_voltage(struct regulator_dev *rdev,
+                                 int min_uV, int max_uV)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+
+       if (check_range(info, min_uV, max_uV)) {
+               pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
+               return -EINVAL;
+       }
+
+       val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
+       val <<= info->vol_shift;
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+
+       return da903x_update(da9034_dev, info->vol_reg, val, mask);
+}
+
+static int da903x_get_voltage(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int ret;
+
+       ret = da903x_read(da9034_dev, info->vol_reg, &val);
+       if (ret)
+               return ret;
+
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+       val = (val & mask) >> info->vol_shift;
+
+       return info->min_uV + info->step_uV * val;
+}
+
+static int da903x_enable(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+
+       return da903x_set_bits(da9034_dev, info->enable_reg,
+                                       1 << info->enable_bit);
+}
+
+static int da903x_disable(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+
+       return da903x_clr_bits(da9034_dev, info->enable_reg,
+                                       1 << info->enable_bit);
+}
+
+static int da903x_is_enabled(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t reg_val;
+       int ret;
+
+       ret = da903x_read(da9034_dev, info->enable_reg, &reg_val);
+       if (ret)
+               return ret;
+
+       return reg_val & (1 << info->enable_bit);
+}
+
+/* DA9030 specific operations */
+static int da9030_set_ldo1_15_voltage(struct regulator_dev *rdev,
+                                      int min_uV, int max_uV)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da903x_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int ret;
+
+       if (check_range(info, min_uV, max_uV)) {
+               pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
+               return -EINVAL;
+       }
+
+       val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
+       val <<= info->vol_shift;
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+       val |= DA9030_LDO_UNLOCK; /* have to set UNLOCK bits */
+       mask |= DA9030_LDO_UNLOCK_MASK;
+
+       /* write twice */
+       ret = da903x_update(da903x_dev, info->vol_reg, val, mask);
+       if (ret)
+               return ret;
+
+       return da903x_update(da903x_dev, info->vol_reg, val, mask);
+}
+
+static int da9030_set_ldo14_voltage(struct regulator_dev *rdev,
+                                 int min_uV, int max_uV)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da903x_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int thresh;
+
+       if (check_range(info, min_uV, max_uV)) {
+               pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
+               return -EINVAL;
+       }
+
+       thresh = (info->max_uV + info->min_uV) / 2;
+       if (min_uV < thresh) {
+               val = (thresh - min_uV + info->step_uV - 1) / info->step_uV;
+               val |= 0x4;
+       } else {
+               val = (min_uV - thresh + info->step_uV - 1) / info->step_uV;
+       }
+
+       val <<= info->vol_shift;
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+
+       return da903x_update(da903x_dev, info->vol_reg, val, mask);
+}
+
+static int da9030_get_ldo14_voltage(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da903x_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int ret;
+
+       ret = da903x_read(da903x_dev, info->vol_reg, &val);
+       if (ret)
+               return ret;
+
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+       val = (val & mask) >> info->vol_shift;
+
+       if (val & 0x4)
+               return info->min_uV + info->step_uV * (3 - (val & ~0x4));
+       else
+               return (info->max_uV + info->min_uV) / 2 +
+                       info->step_uV * (val & ~0x4);
+}
+
+/* DA9034 specific operations */
+static int da9034_set_dvc_voltage(struct regulator_dev *rdev,
+                                 int min_uV, int max_uV)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int ret;
+
+       if (check_range(info, min_uV, max_uV)) {
+               pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
+               return -EINVAL;
+       }
+
+       val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
+       val <<= info->vol_shift;
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+
+       ret = da903x_update(da9034_dev, info->vol_reg, val, mask);
+       if (ret)
+               return ret;
+
+       ret = da903x_set_bits(da9034_dev, info->update_reg,
+                                       1 << info->update_bit);
+       return ret;
+}
+
+static int da9034_set_ldo12_voltage(struct regulator_dev *rdev,
+                                   int min_uV, int max_uV)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+
+       if (check_range(info, min_uV, max_uV)) {
+               pr_err("invalid voltage range (%d, %d) uV", min_uV, max_uV);
+               return -EINVAL;
+       }
+
+       val = (min_uV - info->min_uV + info->step_uV - 1) / info->step_uV;
+       val = (val > 7 || val < 20) ? 8 : val - 12;
+       val <<= info->vol_shift;
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+
+       return da903x_update(da9034_dev, info->vol_reg, val, mask);
+}
+
+static int da9034_get_ldo12_voltage(struct regulator_dev *rdev)
+{
+       struct da903x_regulator_info *info = rdev_get_drvdata(rdev);
+       struct device *da9034_dev = rdev_get_dev(rdev)->parent;
+       uint8_t val, mask;
+       int ret;
+
+       ret = da903x_read(da9034_dev, info->vol_reg, &val);
+       if (ret)
+               return ret;
+
+       mask = ((1 << info->vol_nbits) - 1)  << info->vol_shift;
+       val = (val & mask) >> info->vol_shift;
+
+       if (val >= 8)
+               return 2700000 + info->step_uV * (val - 8);
+
+       return info->min_uV + info->step_uV * val;
+}
+
+static struct regulator_ops da903x_regulator_ldo_ops = {
+       .set_voltage    = da903x_set_ldo_voltage,
+       .get_voltage    = da903x_get_voltage,
+       .enable         = da903x_enable,
+       .disable        = da903x_disable,
+       .is_enabled     = da903x_is_enabled,
+};
+
+/* NOTE: this is dedicated for the insane DA9030 LDO14 */
+static struct regulator_ops da9030_regulator_ldo14_ops = {
+       .set_voltage    = da9030_set_ldo14_voltage,
+       .get_voltage    = da9030_get_ldo14_voltage,
+       .enable         = da903x_enable,
+       .disable        = da903x_disable,
+       .is_enabled     = da903x_is_enabled,
+};
+
+/* NOTE: this is dedicated for the DA9030 LDO1 and LDO15 that have locks  */
+static struct regulator_ops da9030_regulator_ldo1_15_ops = {
+       .set_voltage    = da9030_set_ldo1_15_voltage,
+       .get_voltage    = da903x_get_voltage,
+       .enable         = da903x_enable,
+       .disable        = da903x_disable,
+       .is_enabled     = da903x_is_enabled,
+};
+
+static struct regulator_ops da9034_regulator_dvc_ops = {
+       .set_voltage    = da9034_set_dvc_voltage,
+       .get_voltage    = da903x_get_voltage,
+       .enable         = da903x_enable,
+       .disable        = da903x_disable,
+       .is_enabled     = da903x_is_enabled,
+};
+
+/* NOTE: this is dedicated for the insane LDO12 */
+static struct regulator_ops da9034_regulator_ldo12_ops = {
+       .set_voltage    = da9034_set_ldo12_voltage,
+       .get_voltage    = da9034_get_ldo12_voltage,
+       .enable         = da903x_enable,
+       .disable        = da903x_disable,
+       .is_enabled     = da903x_is_enabled,
+};
+
+#define DA903x_LDO(_pmic, _id, min, max, step, vreg, shift, nbits, ereg, ebit) \
+{                                                                      \
+       .desc   = {                                                     \
+               .name   = "LDO" #_id,                                   \
+               .ops    = &da903x_regulator_ldo_ops,                    \
+               .type   = REGULATOR_VOLTAGE,                            \
+               .id     = _pmic##_ID_LDO##_id,                          \
+               .owner  = THIS_MODULE,                                  \
+       },                                                              \
+       .min_uV         = (min) * 1000,                                 \
+       .max_uV         = (max) * 1000,                                 \
+       .step_uV        = (step) * 1000,                                \
+       .vol_reg        = _pmic##_##vreg,                               \
+       .vol_shift      = (shift),                                      \
+       .vol_nbits      = (nbits),                                      \
+       .enable_reg     = _pmic##_##ereg,                               \
+       .enable_bit     = (ebit),                                       \
+}
+
+#define DA9034_DVC(_id, min, max, step, vreg, nbits, ureg, ubit, ereg, ebit) \
+{                                                                      \
+       .desc   = {                                                     \
+               .name   = #_id,                                         \
+               .ops    = &da9034_regulator_dvc_ops,                    \
+               .type   = REGULATOR_VOLTAGE,                            \
+               .id     = DA9034_ID_##_id,                              \
+               .owner  = THIS_MODULE,                                  \
+       },                                                              \
+       .min_uV         = (min) * 1000,                                 \
+       .max_uV         = (max) * 1000,                                 \
+       .step_uV        = (step) * 1000,                                \
+       .vol_reg        = DA9034_##vreg,                                \
+       .vol_shift      = (0),                                          \
+       .vol_nbits      = (nbits),                                      \
+       .update_reg     = DA9034_##ureg,                                \
+       .update_bit     = (ubit),                                       \
+       .enable_reg     = DA9034_##ereg,                                \
+       .enable_bit     = (ebit),                                       \
+}
+
+#define DA9034_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit)        \
+       DA903x_LDO(DA9034, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
+
+#define DA9030_LDO(_id, min, max, step, vreg, shift, nbits, ereg, ebit)        \
+       DA903x_LDO(DA9030, _id, min, max, step, vreg, shift, nbits, ereg, ebit)
+
+static struct da903x_regulator_info da903x_regulator_info[] = {
+       /* DA9030 */
+       DA9030_LDO( 1, 1200, 3200, 100,    LDO1, 0, 5, RCTL12, 1),
+       DA9030_LDO( 2, 1800, 3200, 100,   LDO23, 0, 4, RCTL12, 2),
+       DA9030_LDO( 3, 1800, 3200, 100,   LDO23, 4, 4, RCTL12, 3),
+       DA9030_LDO( 4, 1800, 3200, 100,   LDO45, 0, 4, RCTL12, 4),
+       DA9030_LDO( 5, 1800, 3200, 100,   LDO45, 4, 4, RCTL12, 5),
+       DA9030_LDO( 6, 1800, 3200, 100,    LDO6, 0, 4, RCTL12, 6),
+       DA9030_LDO( 7, 1800, 3200, 100,   LDO78, 0, 4, RCTL12, 7),
+       DA9030_LDO( 8, 1800, 3200, 100,   LDO78, 4, 4, RCTL22, 0),
+       DA9030_LDO( 9, 1800, 3200, 100,  LDO912, 0, 4, RCTL22, 1),
+       DA9030_LDO(10, 1800, 3200, 100, LDO1011, 0, 4, RCTL22, 2),
+       DA9030_LDO(11, 1800, 3200, 100, LDO1011, 4, 4, RCTL22, 3),
+       DA9030_LDO(12, 1800, 3200, 100,  LDO912, 4, 4, RCTL22, 4),
+       DA9030_LDO(14, 2760, 2940,  30, LDO1416, 0, 3, RCTL11, 4),
+       DA9030_LDO(15, 1100, 2650,  50,   LDO15, 0, 5, RCTL11, 5),
+       DA9030_LDO(16, 1100, 2650,  50, LDO1416, 3, 5, RCTL11, 6),
+       DA9030_LDO(17, 1800, 3200, 100,   LDO17, 0, 4, RCTL11, 7),
+       DA9030_LDO(18, 1800, 3200, 100, LDO1819, 0, 4, RCTL21, 2),
+       DA9030_LDO(19, 1800, 3200, 100, LDO1819, 4, 4, RCTL21, 1),
+       DA9030_LDO(13, 2100, 2100, 0, INVAL, 0, 0, RCTL11, 3), /* fixed @2.1V */
+
+       /* DA9034 */
+       DA9034_DVC(BUCK1, 725, 1500, 25, ADTV1, 5, VCC1, 0, OVER1, 0),
+       DA9034_DVC(BUCK2, 725, 1500, 25, CDTV1, 5, VCC1, 2, OVER1, 1),
+       DA9034_DVC(LDO2,  725, 1500, 25, SDTV1, 5, VCC1, 4, OVER1, 2),
+       DA9034_DVC(LDO1, 1700, 2075, 25, MDTV1, 4, VCC1, 6, OVER3, 4),
+
+       DA9034_LDO( 3, 1800, 3300, 100,  LDO643, 0, 4, OVER3, 5),
+       DA9034_LDO( 4, 1800, 2900,1100,  LDO643, 4, 1, OVER3, 6),
+       DA9034_LDO( 6, 2500, 2850,  50,  LDO643, 5, 3, OVER2, 0),
+       DA9034_LDO( 7, 2700, 3050,  50,  LDO987, 0, 3, OVER2, 1),
+       DA9034_LDO( 8, 2700, 2850,  50,  LDO987, 3, 2, OVER2, 2),
+       DA9034_LDO( 9, 2700, 3050,  50,  LDO987, 5, 3, OVER2, 3),
+       DA9034_LDO(10, 2700, 3050,  50, LDO1110, 0, 3, OVER2, 4),
+       DA9034_LDO(11, 1800, 3300, 100, LDO1110, 4, 4, OVER2, 5),
+       DA9034_LDO(12, 1700, 3050,  50, LDO1312, 0, 4, OVER3, 6),
+       DA9034_LDO(13, 1800, 3300, 100, LDO1312, 4, 4, OVER2, 7),
+       DA9034_LDO(14, 1800, 3300, 100, LDO1514, 0, 4, OVER3, 0),
+       DA9034_LDO(15, 1800, 3300, 100, LDO1514, 4, 4, OVER3, 1),
+       DA9034_LDO(5, 3100, 3100, 0, INVAL, 0, 0, OVER3, 7), /* fixed @3.1V */
+};
+
+static inline struct da903x_regulator_info *find_regulator_info(int id)
+{
+       struct da903x_regulator_info *ri;
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(da903x_regulator_info); i++) {
+               ri = &da903x_regulator_info[i];
+               if (ri->desc.id == id)
+                       return ri;
+       }
+       return NULL;
+}
+
+static int __devinit da903x_regulator_probe(struct platform_device *pdev)
+{
+       struct da903x_regulator_info *ri = NULL;
+       struct regulator_dev *rdev;
+
+       ri = find_regulator_info(pdev->id);
+       if (ri == NULL) {
+               dev_err(&pdev->dev, "invalid regulator ID specified\n");
+               return -EINVAL;
+       }
+
+       /* Workaround for the weird LDO12 voltage setting */
+       if (ri->desc.id == DA9034_ID_LDO12)
+               ri->desc.ops = &da9034_regulator_ldo12_ops;
+
+       if (ri->desc.id == DA9030_ID_LDO14)
+               ri->desc.ops = &da9030_regulator_ldo14_ops;
+
+       if (ri->desc.id == DA9030_ID_LDO1 || ri->desc.id == DA9030_ID_LDO15)
+               ri->desc.ops = &da9030_regulator_ldo1_15_ops;
+
+       rdev = regulator_register(&ri->desc, pdev->dev.parent, ri);
+       if (IS_ERR(rdev)) {
+               dev_err(&pdev->dev, "failed to register regulator %s\n",
+                               ri->desc.name);
+               return PTR_ERR(rdev);
+       }
+
+       platform_set_drvdata(pdev, rdev);
+       return 0;
+}
+
+static int __devexit da903x_regulator_remove(struct platform_device *pdev)
+{
+       struct regulator_dev *rdev = platform_get_drvdata(pdev);
+
+       regulator_unregister(rdev);
+       return 0;
+}
+
+static struct platform_driver da903x_regulator_driver = {
+       .driver = {
+               .name   = "da903x-regulator",
+               .owner  = THIS_MODULE,
+       },
+       .probe          = da903x_regulator_probe,
+       .remove         = da903x_regulator_remove,
+};
+
+static int __init da903x_regulator_init(void)
+{
+       return platform_driver_register(&da903x_regulator_driver);
+}
+module_init(da903x_regulator_init);
+
+static void __exit da903x_regulator_exit(void)
+{
+       platform_driver_unregister(&da903x_regulator_driver);
+}
+module_exit(da903x_regulator_exit);
+
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("Eric Miao <eric.miao@marvell.com>"
+             "Mike Rapoport <mike@compulab.co.il>");
+MODULE_DESCRIPTION("Regulator Driver for Dialog Semiconductor DA903X PMIC");
+MODULE_ALIAS("platform:da903x-regulator");
diff --git a/drivers/regulator/wm8350-regulator.c b/drivers/regulator/wm8350-regulator.c
new file mode 100644 (file)
index 0000000..1f44b17
--- /dev/null
@@ -0,0 +1,1431 @@
+/*
+ * wm8350.c  --  Voltage and current regulation for the Wolfson WM8350 PMIC
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Liam Girdwood
+ *         linux@wolfsonmicro.com
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#include <linux/module.h>
+#include <linux/moduleparam.h>
+#include <linux/init.h>
+#include <linux/bitops.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/mfd/wm8350/core.h>
+#include <linux/mfd/wm8350/pmic.h>
+#include <linux/platform_device.h>
+#include <linux/regulator/driver.h>
+#include <linux/regulator/machine.h>
+
+/* Microamps */
+static const int isink_cur[] = {
+       4,
+       5,
+       6,
+       7,
+       8,
+       10,
+       11,
+       14,
+       16,
+       19,
+       23,
+       27,
+       32,
+       39,
+       46,
+       54,
+       65,
+       77,
+       92,
+       109,
+       130,
+       154,
+       183,
+       218,
+       259,
+       308,
+       367,
+       436,
+       518,
+       616,
+       733,
+       872,
+       1037,
+       1233,
+       1466,
+       1744,
+       2073,
+       2466,
+       2933,
+       3487,
+       4147,
+       4932,
+       5865,
+       6975,
+       8294,
+       9864,
+       11730,
+       13949,
+       16589,
+       19728,
+       23460,
+       27899,
+       33178,
+       39455,
+       46920,
+       55798,
+       66355,
+       78910,
+       93840,
+       111596,
+       132710,
+       157820,
+       187681,
+       223191
+};
+
+static int get_isink_val(int min_uA, int max_uA, u16 *setting)
+{
+       int i;
+
+       for (i = ARRAY_SIZE(isink_cur) - 1; i >= 0; i--) {
+               if (min_uA <= isink_cur[i] && max_uA >= isink_cur[i]) {
+                       *setting = i;
+                       return 0;
+               }
+       }
+       return -EINVAL;
+}
+
+static inline int wm8350_ldo_val_to_mvolts(unsigned int val)
+{
+       if (val < 16)
+               return (val * 50) + 900;
+       else
+               return ((val - 16) * 100) + 1800;
+
+}
+
+static inline unsigned int wm8350_ldo_mvolts_to_val(int mV)
+{
+       if (mV < 1800)
+               return (mV - 900) / 50;
+       else
+               return ((mV - 1800) / 100) + 16;
+}
+
+static inline int wm8350_dcdc_val_to_mvolts(unsigned int val)
+{
+       return (val * 25) + 850;
+}
+
+static inline unsigned int wm8350_dcdc_mvolts_to_val(int mV)
+{
+       return (mV - 850) / 25;
+}
+
+static int wm8350_isink_set_current(struct regulator_dev *rdev, int min_uA,
+       int max_uA)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int isink = rdev_get_id(rdev);
+       u16 val, setting;
+       int ret;
+
+       ret = get_isink_val(min_uA, max_uA, &setting);
+       if (ret != 0)
+               return ret;
+
+       switch (isink) {
+       case WM8350_ISINK_A:
+               val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
+                   ~WM8350_CS1_ISEL_MASK;
+               wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_A,
+                                val | setting);
+               break;
+       case WM8350_ISINK_B:
+               val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
+                   ~WM8350_CS1_ISEL_MASK;
+               wm8350_reg_write(wm8350, WM8350_CURRENT_SINK_DRIVER_B,
+                                val | setting);
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wm8350_isink_get_current(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int isink = rdev_get_id(rdev);
+       u16 val;
+
+       switch (isink) {
+       case WM8350_ISINK_A:
+               val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
+                   WM8350_CS1_ISEL_MASK;
+               break;
+       case WM8350_ISINK_B:
+               val = wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
+                   WM8350_CS1_ISEL_MASK;
+               break;
+       default:
+               return 0;
+       }
+
+       return (isink_cur[val] + 50) / 100;
+}
+
+/* turn on ISINK followed by DCDC */
+static int wm8350_isink_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int isink = rdev_get_id(rdev);
+
+       switch (isink) {
+       case WM8350_ISINK_A:
+               switch (wm8350->pmic.isink_A_dcdc) {
+               case WM8350_DCDC_2:
+               case WM8350_DCDC_5:
+                       wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
+                                       WM8350_CS1_ENA);
+                       wm8350_set_bits(wm8350, WM8350_CSA_FLASH_CONTROL,
+                                       WM8350_CS1_DRIVE);
+                       wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
+                                       1 << (wm8350->pmic.isink_A_dcdc -
+                                             WM8350_DCDC_1));
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case WM8350_ISINK_B:
+               switch (wm8350->pmic.isink_B_dcdc) {
+               case WM8350_DCDC_2:
+               case WM8350_DCDC_5:
+                       wm8350_set_bits(wm8350, WM8350_POWER_MGMT_7,
+                                       WM8350_CS2_ENA);
+                       wm8350_set_bits(wm8350, WM8350_CSB_FLASH_CONTROL,
+                                       WM8350_CS2_DRIVE);
+                       wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
+                                       1 << (wm8350->pmic.isink_B_dcdc -
+                                             WM8350_DCDC_1));
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int wm8350_isink_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int isink = rdev_get_id(rdev);
+
+       switch (isink) {
+       case WM8350_ISINK_A:
+               switch (wm8350->pmic.isink_A_dcdc) {
+               case WM8350_DCDC_2:
+               case WM8350_DCDC_5:
+                       wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
+                                         1 << (wm8350->pmic.isink_A_dcdc -
+                                               WM8350_DCDC_1));
+                       wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
+                                         WM8350_CS1_ENA);
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       case WM8350_ISINK_B:
+               switch (wm8350->pmic.isink_B_dcdc) {
+               case WM8350_DCDC_2:
+               case WM8350_DCDC_5:
+                       wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED,
+                                         1 << (wm8350->pmic.isink_B_dcdc -
+                                               WM8350_DCDC_1));
+                       wm8350_clear_bits(wm8350, WM8350_POWER_MGMT_7,
+                                         WM8350_CS2_ENA);
+                       break;
+               default:
+                       return -EINVAL;
+               }
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int wm8350_isink_is_enabled(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int isink = rdev_get_id(rdev);
+
+       switch (isink) {
+       case WM8350_ISINK_A:
+               return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_A) &
+                   0x8000;
+       case WM8350_ISINK_B:
+               return wm8350_reg_read(wm8350, WM8350_CURRENT_SINK_DRIVER_B) &
+                   0x8000;
+       }
+       return -EINVAL;
+}
+
+int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
+                          u16 trigger, u16 duration, u16 on_ramp, u16 off_ramp,
+                          u16 drive)
+{
+       switch (isink) {
+       case WM8350_ISINK_A:
+               wm8350_reg_write(wm8350, WM8350_CSA_FLASH_CONTROL,
+                                (mode ? WM8350_CS1_FLASH_MODE : 0) |
+                                (trigger ? WM8350_CS1_TRIGSRC : 0) |
+                                duration | on_ramp | off_ramp | drive);
+               break;
+       case WM8350_ISINK_B:
+               wm8350_reg_write(wm8350, WM8350_CSB_FLASH_CONTROL,
+                                (mode ? WM8350_CS2_FLASH_MODE : 0) |
+                                (trigger ? WM8350_CS2_TRIGSRC : 0) |
+                                duration | on_ramp | off_ramp | drive);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_isink_set_flash);
+
+static int wm8350_dcdc_set_voltage(struct regulator_dev *rdev, int min_uV,
+       int max_uV)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, dcdc = rdev_get_id(rdev), mV,
+               min_mV = min_uV / 1000, max_mV = max_uV / 1000;
+       u16 val;
+
+       if (min_mV < 850 || min_mV > 4025)
+               return -EINVAL;
+       if (max_mV < 850 || max_mV > 4025)
+               return -EINVAL;
+
+       /* step size is 25mV */
+       mV = (min_mV - 826) / 25;
+       if (wm8350_dcdc_val_to_mvolts(mV) > max_mV)
+               return -EINVAL;
+       BUG_ON(wm8350_dcdc_val_to_mvolts(mV) < min_mV);
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               volt_reg = WM8350_DCDC1_CONTROL;
+               break;
+       case WM8350_DCDC_3:
+               volt_reg = WM8350_DCDC3_CONTROL;
+               break;
+       case WM8350_DCDC_4:
+               volt_reg = WM8350_DCDC4_CONTROL;
+               break;
+       case WM8350_DCDC_6:
+               volt_reg = WM8350_DCDC6_CONTROL;
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       /* all DCDCs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
+       wm8350_reg_write(wm8350, volt_reg, val | mV);
+       return 0;
+}
+
+static int wm8350_dcdc_get_voltage(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               volt_reg = WM8350_DCDC1_CONTROL;
+               break;
+       case WM8350_DCDC_3:
+               volt_reg = WM8350_DCDC3_CONTROL;
+               break;
+       case WM8350_DCDC_4:
+               volt_reg = WM8350_DCDC4_CONTROL;
+               break;
+       case WM8350_DCDC_6:
+               volt_reg = WM8350_DCDC6_CONTROL;
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       /* all DCDCs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & WM8350_DC1_VSEL_MASK;
+       return wm8350_dcdc_val_to_mvolts(val) * 1000;
+}
+
+static int wm8350_dcdc_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, mV = uV / 1000, dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, dcdc, mV);
+
+       if (mV && (mV < 850 || mV > 4025)) {
+               dev_err(wm8350->dev,
+                       "DCDC%d suspend voltage %d mV out of range\n",
+                       dcdc, mV);
+               return -EINVAL;
+       }
+       if (mV == 0)
+               mV = 850;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               volt_reg = WM8350_DCDC1_LOW_POWER;
+               break;
+       case WM8350_DCDC_3:
+               volt_reg = WM8350_DCDC3_LOW_POWER;
+               break;
+       case WM8350_DCDC_4:
+               volt_reg = WM8350_DCDC4_LOW_POWER;
+               break;
+       case WM8350_DCDC_6:
+               volt_reg = WM8350_DCDC6_LOW_POWER;
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       /* all DCDCs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_DC1_VSEL_MASK;
+       wm8350_reg_write(wm8350, volt_reg,
+                        val | wm8350_dcdc_mvolts_to_val(mV));
+       return 0;
+}
+
+static int wm8350_dcdc_set_suspend_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER)
+                       & ~WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
+                       wm8350->pmic.dcdc1_hib_mode);
+               break;
+       case WM8350_DCDC_3:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER)
+                       & ~WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
+                       wm8350->pmic.dcdc3_hib_mode);
+               break;
+       case WM8350_DCDC_4:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER)
+                       & ~WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
+                       wm8350->pmic.dcdc4_hib_mode);
+               break;
+       case WM8350_DCDC_6:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER)
+                       & ~WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
+                       wm8350->pmic.dcdc6_hib_mode);
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wm8350_dcdc_set_suspend_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
+               wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC1_LOW_POWER,
+                       WM8350_DCDC_HIB_MODE_DIS);
+               break;
+       case WM8350_DCDC_3:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
+               wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC3_LOW_POWER,
+                       WM8350_DCDC_HIB_MODE_DIS);
+               break;
+       case WM8350_DCDC_4:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
+               wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC4_LOW_POWER,
+                       WM8350_DCDC_HIB_MODE_DIS);
+               break;
+       case WM8350_DCDC_6:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
+               wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC6_LOW_POWER,
+                       WM8350_DCDC_HIB_MODE_DIS);
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wm8350_dcdc25_set_suspend_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       switch (dcdc) {
+       case WM8350_DCDC_2:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
+                   & ~WM8350_DC2_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
+                                WM8350_DC2_HIB_MODE_ACTIVE);
+               break;
+       case WM8350_DCDC_5:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
+                   & ~WM8350_DC2_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
+                                WM8350_DC5_HIB_MODE_ACTIVE);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int wm8350_dcdc25_set_suspend_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       switch (dcdc) {
+       case WM8350_DCDC_2:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
+                   & ~WM8350_DC2_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
+                                WM8350_DC2_HIB_MODE_DISABLE);
+               break;
+       case WM8350_DCDC_5:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
+                   & ~WM8350_DC2_HIB_MODE_MASK;
+               wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
+                                WM8350_DC2_HIB_MODE_DISABLE);
+               break;
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static int wm8350_dcdc_set_suspend_mode(struct regulator_dev *rdev,
+       unsigned int mode)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 *hib_mode;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               hib_mode = &wm8350->pmic.dcdc1_hib_mode;
+               break;
+       case WM8350_DCDC_3:
+               hib_mode = &wm8350->pmic.dcdc3_hib_mode;
+               break;
+       case WM8350_DCDC_4:
+               hib_mode = &wm8350->pmic.dcdc4_hib_mode;
+               break;
+       case WM8350_DCDC_6:
+               hib_mode = &wm8350->pmic.dcdc6_hib_mode;
+               break;
+       case WM8350_DCDC_2:
+       case WM8350_DCDC_5:
+       default:
+               return -EINVAL;
+       }
+
+       switch (mode) {
+       case REGULATOR_MODE_NORMAL:
+               *hib_mode = WM8350_DCDC_HIB_MODE_IMAGE;
+               break;
+       case REGULATOR_MODE_IDLE:
+               *hib_mode = WM8350_DCDC_HIB_MODE_STANDBY;
+               break;
+       case REGULATOR_MODE_STANDBY:
+               *hib_mode = WM8350_DCDC_HIB_MODE_LDO_IM;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
+static int wm8350_ldo_set_suspend_voltage(struct regulator_dev *rdev, int uV)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, mV = uV / 1000, ldo = rdev_get_id(rdev);
+       u16 val;
+
+       dev_dbg(wm8350->dev, "%s %d mV %d\n", __func__, ldo, mV);
+
+       if (mV < 900 || mV > 3300) {
+               dev_err(wm8350->dev, "LDO%d voltage %d mV out of range\n",
+                       ldo, mV);
+               return -EINVAL;
+       }
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               volt_reg = WM8350_LDO1_LOW_POWER;
+               break;
+       case WM8350_LDO_2:
+               volt_reg = WM8350_LDO2_LOW_POWER;
+               break;
+       case WM8350_LDO_3:
+               volt_reg = WM8350_LDO3_LOW_POWER;
+               break;
+       case WM8350_LDO_4:
+               volt_reg = WM8350_LDO4_LOW_POWER;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* all LDOs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
+       wm8350_reg_write(wm8350, volt_reg,
+                        val | wm8350_ldo_mvolts_to_val(mV));
+       return 0;
+}
+
+static int wm8350_ldo_set_suspend_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, ldo = rdev_get_id(rdev);
+       u16 val;
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               volt_reg = WM8350_LDO1_LOW_POWER;
+               break;
+       case WM8350_LDO_2:
+               volt_reg = WM8350_LDO2_LOW_POWER;
+               break;
+       case WM8350_LDO_3:
+               volt_reg = WM8350_LDO3_LOW_POWER;
+               break;
+       case WM8350_LDO_4:
+               volt_reg = WM8350_LDO4_LOW_POWER;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* all LDOs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
+       wm8350_reg_write(wm8350, volt_reg, val);
+       return 0;
+}
+
+static int wm8350_ldo_set_suspend_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, ldo = rdev_get_id(rdev);
+       u16 val;
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               volt_reg = WM8350_LDO1_LOW_POWER;
+               break;
+       case WM8350_LDO_2:
+               volt_reg = WM8350_LDO2_LOW_POWER;
+               break;
+       case WM8350_LDO_3:
+               volt_reg = WM8350_LDO3_LOW_POWER;
+               break;
+       case WM8350_LDO_4:
+               volt_reg = WM8350_LDO4_LOW_POWER;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* all LDOs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_HIB_MODE_MASK;
+       wm8350_reg_write(wm8350, volt_reg, WM8350_LDO1_HIB_MODE_DIS);
+       return 0;
+}
+
+static int wm8350_ldo_set_voltage(struct regulator_dev *rdev, int min_uV,
+       int max_uV)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, ldo = rdev_get_id(rdev), mV, min_mV = min_uV / 1000,
+               max_mV = max_uV / 1000;
+       u16 val;
+
+       if (min_mV < 900 || min_mV > 3300)
+               return -EINVAL;
+       if (max_mV < 900 || max_mV > 3300)
+               return -EINVAL;
+
+       if (min_mV < 1800) {
+               /* step size is 50mV < 1800mV */
+               mV = (min_mV - 851) / 50;
+               if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
+                       return -EINVAL;
+               BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
+       } else {
+               /* step size is 100mV > 1800mV */
+               mV = ((min_mV - 1701) / 100) + 16;
+               if (wm8350_ldo_val_to_mvolts(mV) > max_mV)
+                       return -EINVAL;
+               BUG_ON(wm8350_ldo_val_to_mvolts(mV) < min_mV);
+       }
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               volt_reg = WM8350_LDO1_CONTROL;
+               break;
+       case WM8350_LDO_2:
+               volt_reg = WM8350_LDO2_CONTROL;
+               break;
+       case WM8350_LDO_3:
+               volt_reg = WM8350_LDO3_CONTROL;
+               break;
+       case WM8350_LDO_4:
+               volt_reg = WM8350_LDO4_CONTROL;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* all LDOs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & ~WM8350_LDO1_VSEL_MASK;
+       wm8350_reg_write(wm8350, volt_reg, val | mV);
+       return 0;
+}
+
+static int wm8350_ldo_get_voltage(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int volt_reg, ldo = rdev_get_id(rdev);
+       u16 val;
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               volt_reg = WM8350_LDO1_CONTROL;
+               break;
+       case WM8350_LDO_2:
+               volt_reg = WM8350_LDO2_CONTROL;
+               break;
+       case WM8350_LDO_3:
+               volt_reg = WM8350_LDO3_CONTROL;
+               break;
+       case WM8350_LDO_4:
+               volt_reg = WM8350_LDO4_CONTROL;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       /* all LDOs have same mV bits */
+       val = wm8350_reg_read(wm8350, volt_reg) & WM8350_LDO1_VSEL_MASK;
+       return wm8350_ldo_val_to_mvolts(val) * 1000;
+}
+
+int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
+                        u16 stop, u16 fault)
+{
+       int slot_reg;
+       u16 val;
+
+       dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
+               __func__, dcdc, start, stop);
+
+       /* slot valid ? */
+       if (start > 15 || stop > 15)
+               return -EINVAL;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               slot_reg = WM8350_DCDC1_TIMEOUTS;
+               break;
+       case WM8350_DCDC_2:
+               slot_reg = WM8350_DCDC2_TIMEOUTS;
+               break;
+       case WM8350_DCDC_3:
+               slot_reg = WM8350_DCDC3_TIMEOUTS;
+               break;
+       case WM8350_DCDC_4:
+               slot_reg = WM8350_DCDC4_TIMEOUTS;
+               break;
+       case WM8350_DCDC_5:
+               slot_reg = WM8350_DCDC5_TIMEOUTS;
+               break;
+       case WM8350_DCDC_6:
+               slot_reg = WM8350_DCDC6_TIMEOUTS;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       val = wm8350_reg_read(wm8350, slot_reg) &
+           ~(WM8350_DC1_ENSLOT_MASK | WM8350_DC1_SDSLOT_MASK |
+             WM8350_DC1_ERRACT_MASK);
+       wm8350_reg_write(wm8350, slot_reg,
+                        val | (start << WM8350_DC1_ENSLOT_SHIFT) |
+                        (stop << WM8350_DC1_SDSLOT_SHIFT) |
+                        (fault << WM8350_DC1_ERRACT_SHIFT));
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_dcdc_set_slot);
+
+int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop)
+{
+       int slot_reg;
+       u16 val;
+
+       dev_dbg(wm8350->dev, "%s %d start %d stop %d\n",
+               __func__, ldo, start, stop);
+
+       /* slot valid ? */
+       if (start > 15 || stop > 15)
+               return -EINVAL;
+
+       switch (ldo) {
+       case WM8350_LDO_1:
+               slot_reg = WM8350_LDO1_TIMEOUTS;
+               break;
+       case WM8350_LDO_2:
+               slot_reg = WM8350_LDO2_TIMEOUTS;
+               break;
+       case WM8350_LDO_3:
+               slot_reg = WM8350_LDO3_TIMEOUTS;
+               break;
+       case WM8350_LDO_4:
+               slot_reg = WM8350_LDO4_TIMEOUTS;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       val = wm8350_reg_read(wm8350, slot_reg) & ~WM8350_LDO1_SDSLOT_MASK;
+       wm8350_reg_write(wm8350, slot_reg, val | ((start << 10) | (stop << 6)));
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_ldo_set_slot);
+
+int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
+                          u16 ilim, u16 ramp, u16 feedback)
+{
+       u16 val;
+
+       dev_dbg(wm8350->dev, "%s %d mode: %s %s\n", __func__, dcdc,
+               mode ? "normal" : "boost", ilim ? "low" : "normal");
+
+       switch (dcdc) {
+       case WM8350_DCDC_2:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC2_CONTROL)
+                   & ~(WM8350_DC2_MODE_MASK | WM8350_DC2_ILIM_MASK |
+                       WM8350_DC2_RMP_MASK | WM8350_DC2_FBSRC_MASK);
+               wm8350_reg_write(wm8350, WM8350_DCDC2_CONTROL, val |
+                                (mode << WM8350_DC2_MODE_SHIFT) |
+                                (ilim << WM8350_DC2_ILIM_SHIFT) |
+                                (ramp << WM8350_DC2_RMP_SHIFT) |
+                                (feedback << WM8350_DC2_FBSRC_SHIFT));
+               break;
+       case WM8350_DCDC_5:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC5_CONTROL)
+                   & ~(WM8350_DC5_MODE_MASK | WM8350_DC5_ILIM_MASK |
+                       WM8350_DC5_RMP_MASK | WM8350_DC5_FBSRC_MASK);
+               wm8350_reg_write(wm8350, WM8350_DCDC5_CONTROL, val |
+                                (mode << WM8350_DC5_MODE_SHIFT) |
+                                (ilim << WM8350_DC5_ILIM_SHIFT) |
+                                (ramp << WM8350_DC5_RMP_SHIFT) |
+                                (feedback << WM8350_DC5_FBSRC_SHIFT));
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+EXPORT_SYMBOL_GPL(wm8350_dcdc25_set_mode);
+
+static int wm8350_dcdc_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 shift;
+
+       if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
+               return -EINVAL;
+
+       shift = dcdc - WM8350_DCDC_1;
+       wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
+       return 0;
+}
+
+static int wm8350_dcdc_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 shift;
+
+       if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
+               return -EINVAL;
+
+       shift = dcdc - WM8350_DCDC_1;
+       wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
+
+       return 0;
+}
+
+static int wm8350_ldo_enable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int ldo = rdev_get_id(rdev);
+       u16 shift;
+
+       if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
+               return -EINVAL;
+
+       shift = (ldo - WM8350_LDO_1) + 8;
+       wm8350_set_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
+       return 0;
+}
+
+static int wm8350_ldo_disable(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int ldo = rdev_get_id(rdev);
+       u16 shift;
+
+       if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
+               return -EINVAL;
+
+       shift = (ldo - WM8350_LDO_1) + 8;
+       wm8350_clear_bits(wm8350, WM8350_DCDC_LDO_REQUESTED, 1 << shift);
+       return 0;
+}
+
+static int force_continuous_enable(struct wm8350 *wm8350, int dcdc, int enable)
+{
+       int reg = 0, ret;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+               reg = WM8350_DCDC1_FORCE_PWM;
+               break;
+       case WM8350_DCDC_3:
+               reg = WM8350_DCDC3_FORCE_PWM;
+               break;
+       case WM8350_DCDC_4:
+               reg = WM8350_DCDC4_FORCE_PWM;
+               break;
+       case WM8350_DCDC_6:
+               reg = WM8350_DCDC6_FORCE_PWM;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       if (enable)
+               ret = wm8350_set_bits(wm8350, reg,
+                       WM8350_DCDC1_FORCE_PWM_ENA);
+       else
+               ret = wm8350_clear_bits(wm8350, reg,
+                       WM8350_DCDC1_FORCE_PWM_ENA);
+       return ret;
+}
+
+static int wm8350_dcdc_set_mode(struct regulator_dev *rdev, unsigned int mode)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 val;
+
+       if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
+               return -EINVAL;
+
+       if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
+               return -EINVAL;
+
+       val = 1 << (dcdc - WM8350_DCDC_1);
+
+       switch (mode) {
+       case REGULATOR_MODE_FAST:
+               /* force continuous mode */
+               wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
+               wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
+               force_continuous_enable(wm8350, dcdc, 1);
+               break;
+       case REGULATOR_MODE_NORMAL:
+               /* active / pulse skipping */
+               wm8350_set_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
+               wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
+               force_continuous_enable(wm8350, dcdc, 0);
+               break;
+       case REGULATOR_MODE_IDLE:
+               /* standby mode */
+               force_continuous_enable(wm8350, dcdc, 0);
+               wm8350_clear_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
+               wm8350_clear_bits(wm8350, WM8350_DCDC_ACTIVE_OPTIONS, val);
+               break;
+       case REGULATOR_MODE_STANDBY:
+               /* LDO mode */
+               force_continuous_enable(wm8350, dcdc, 0);
+               wm8350_set_bits(wm8350, WM8350_DCDC_SLEEP_OPTIONS, val);
+               break;
+       }
+
+       return 0;
+}
+
+static unsigned int wm8350_dcdc_get_mode(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev);
+       u16 mask, sleep, active, force;
+       int mode = REGULATOR_MODE_NORMAL;
+
+       if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
+               return -EINVAL;
+
+       if (dcdc == WM8350_DCDC_2 || dcdc == WM8350_DCDC_5)
+               return -EINVAL;
+
+       mask = 1 << (dcdc - WM8350_DCDC_1);
+       active = wm8350_reg_read(wm8350, WM8350_DCDC_ACTIVE_OPTIONS) & mask;
+       sleep = wm8350_reg_read(wm8350, WM8350_DCDC_SLEEP_OPTIONS) & mask;
+       force = wm8350_reg_read(wm8350, WM8350_DCDC1_FORCE_PWM)
+           & WM8350_DCDC1_FORCE_PWM_ENA;
+       dev_dbg(wm8350->dev, "mask %x active %x sleep %x force %x",
+               mask, active, sleep, force);
+
+       if (active && !sleep) {
+               if (force)
+                       mode = REGULATOR_MODE_FAST;
+               else
+                       mode = REGULATOR_MODE_NORMAL;
+       } else if (!active && !sleep)
+               mode = REGULATOR_MODE_IDLE;
+       else if (!sleep)
+               mode = REGULATOR_MODE_STANDBY;
+
+       return mode;
+}
+
+static unsigned int wm8350_ldo_get_mode(struct regulator_dev *rdev)
+{
+       return REGULATOR_MODE_NORMAL;
+}
+
+struct wm8350_dcdc_efficiency {
+       int uA_load_min;
+       int uA_load_max;
+       unsigned int mode;
+};
+
+static const struct wm8350_dcdc_efficiency dcdc1_6_efficiency[] = {
+       {0, 10000, REGULATOR_MODE_STANDBY},       /* 0 - 10mA - LDO */
+       {10000, 100000, REGULATOR_MODE_IDLE},     /* 10mA - 100mA - Standby */
+       {100000, 1000000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
+       {-1, -1, REGULATOR_MODE_NORMAL},
+};
+
+static const struct wm8350_dcdc_efficiency dcdc3_4_efficiency[] = {
+       {0, 10000, REGULATOR_MODE_STANDBY},      /* 0 - 10mA - LDO */
+       {10000, 100000, REGULATOR_MODE_IDLE},    /* 10mA - 100mA - Standby */
+       {100000, 800000, REGULATOR_MODE_NORMAL}, /* > 100mA - Active */
+       {-1, -1, REGULATOR_MODE_NORMAL},
+};
+
+static unsigned int get_mode(int uA, const struct wm8350_dcdc_efficiency *eff)
+{
+       int i = 0;
+
+       while (eff[i].uA_load_min != -1) {
+               if (uA >= eff[i].uA_load_min && uA <= eff[i].uA_load_max)
+                       return eff[i].mode;
+       }
+       return REGULATOR_MODE_NORMAL;
+}
+
+/* Query the regulator for it's most efficient mode @ uV,uA
+ * WM8350 regulator efficiency is pretty similar over
+ * different input and output uV.
+ */
+static unsigned int wm8350_dcdc_get_optimum_mode(struct regulator_dev *rdev,
+                                                int input_uV, int output_uV,
+                                                int output_uA)
+{
+       int dcdc = rdev_get_id(rdev), mode;
+
+       switch (dcdc) {
+       case WM8350_DCDC_1:
+       case WM8350_DCDC_6:
+               mode = get_mode(output_uA, dcdc1_6_efficiency);
+               break;
+       case WM8350_DCDC_3:
+       case WM8350_DCDC_4:
+               mode = get_mode(output_uA, dcdc3_4_efficiency);
+               break;
+       default:
+               mode = REGULATOR_MODE_NORMAL;
+               break;
+       }
+       return mode;
+}
+
+static int wm8350_dcdc_is_enabled(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int dcdc = rdev_get_id(rdev), shift;
+
+       if (dcdc < WM8350_DCDC_1 || dcdc > WM8350_DCDC_6)
+               return -EINVAL;
+
+       shift = dcdc - WM8350_DCDC_1;
+       return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
+           & (1 << shift);
+}
+
+static int wm8350_ldo_is_enabled(struct regulator_dev *rdev)
+{
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+       int ldo = rdev_get_id(rdev), shift;
+
+       if (ldo < WM8350_LDO_1 || ldo > WM8350_LDO_4)
+               return -EINVAL;
+
+       shift = (ldo - WM8350_LDO_1) + 8;
+       return wm8350_reg_read(wm8350, WM8350_DCDC_LDO_REQUESTED)
+           & (1 << shift);
+}
+
+static struct regulator_ops wm8350_dcdc_ops = {
+       .set_voltage = wm8350_dcdc_set_voltage,
+       .get_voltage = wm8350_dcdc_get_voltage,
+       .enable = wm8350_dcdc_enable,
+       .disable = wm8350_dcdc_disable,
+       .get_mode = wm8350_dcdc_get_mode,
+       .set_mode = wm8350_dcdc_set_mode,
+       .get_optimum_mode = wm8350_dcdc_get_optimum_mode,
+       .is_enabled = wm8350_dcdc_is_enabled,
+       .set_suspend_voltage = wm8350_dcdc_set_suspend_voltage,
+       .set_suspend_enable = wm8350_dcdc_set_suspend_enable,
+       .set_suspend_disable = wm8350_dcdc_set_suspend_disable,
+       .set_suspend_mode = wm8350_dcdc_set_suspend_mode,
+};
+
+static struct regulator_ops wm8350_dcdc2_5_ops = {
+       .enable = wm8350_dcdc_enable,
+       .disable = wm8350_dcdc_disable,
+       .is_enabled = wm8350_dcdc_is_enabled,
+       .set_suspend_enable = wm8350_dcdc25_set_suspend_enable,
+       .set_suspend_disable = wm8350_dcdc25_set_suspend_disable,
+};
+
+static struct regulator_ops wm8350_ldo_ops = {
+       .set_voltage = wm8350_ldo_set_voltage,
+       .get_voltage = wm8350_ldo_get_voltage,
+       .enable = wm8350_ldo_enable,
+       .disable = wm8350_ldo_disable,
+       .is_enabled = wm8350_ldo_is_enabled,
+       .get_mode = wm8350_ldo_get_mode,
+       .set_suspend_voltage = wm8350_ldo_set_suspend_voltage,
+       .set_suspend_enable = wm8350_ldo_set_suspend_enable,
+       .set_suspend_disable = wm8350_ldo_set_suspend_disable,
+};
+
+static struct regulator_ops wm8350_isink_ops = {
+       .set_current_limit = wm8350_isink_set_current,
+       .get_current_limit = wm8350_isink_get_current,
+       .enable = wm8350_isink_enable,
+       .disable = wm8350_isink_disable,
+       .is_enabled = wm8350_isink_is_enabled,
+};
+
+static struct regulator_desc wm8350_reg[NUM_WM8350_REGULATORS] = {
+       {
+               .name = "DCDC1",
+               .id = WM8350_DCDC_1,
+               .ops = &wm8350_dcdc_ops,
+               .irq = WM8350_IRQ_UV_DC1,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC2",
+               .id = WM8350_DCDC_2,
+               .ops = &wm8350_dcdc2_5_ops,
+               .irq = WM8350_IRQ_UV_DC2,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC3",
+               .id = WM8350_DCDC_3,
+               .ops = &wm8350_dcdc_ops,
+               .irq = WM8350_IRQ_UV_DC3,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC4",
+               .id = WM8350_DCDC_4,
+               .ops = &wm8350_dcdc_ops,
+               .irq = WM8350_IRQ_UV_DC4,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC5",
+               .id = WM8350_DCDC_5,
+               .ops = &wm8350_dcdc2_5_ops,
+               .irq = WM8350_IRQ_UV_DC5,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+        },
+       {
+               .name = "DCDC6",
+               .id = WM8350_DCDC_6,
+               .ops = &wm8350_dcdc_ops,
+               .irq = WM8350_IRQ_UV_DC6,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO1",
+               .id = WM8350_LDO_1,
+               .ops = &wm8350_ldo_ops,
+               .irq = WM8350_IRQ_UV_LDO1,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO2",
+               .id = WM8350_LDO_2,
+               .ops = &wm8350_ldo_ops,
+               .irq = WM8350_IRQ_UV_LDO2,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO3",
+               .id = WM8350_LDO_3,
+               .ops = &wm8350_ldo_ops,
+               .irq = WM8350_IRQ_UV_LDO3,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO4",
+               .id = WM8350_LDO_4,
+               .ops = &wm8350_ldo_ops,
+               .irq = WM8350_IRQ_UV_LDO4,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "ISINKA",
+               .id = WM8350_ISINK_A,
+               .ops = &wm8350_isink_ops,
+               .irq = WM8350_IRQ_CS1,
+               .type = REGULATOR_CURRENT,
+               .owner = THIS_MODULE,
+        },
+       {
+               .name = "ISINKB",
+               .id = WM8350_ISINK_B,
+               .ops = &wm8350_isink_ops,
+               .irq = WM8350_IRQ_CS2,
+               .type = REGULATOR_CURRENT,
+               .owner = THIS_MODULE,
+        },
+};
+
+static void pmic_uv_handler(struct wm8350 *wm8350, int irq, void *data)
+{
+       struct regulator_dev *rdev = (struct regulator_dev *)data;
+
+       if (irq == WM8350_IRQ_CS1 || irq == WM8350_IRQ_CS2)
+               regulator_notifier_call_chain(rdev,
+                                             REGULATOR_EVENT_REGULATION_OUT,
+                                             wm8350);
+       else
+               regulator_notifier_call_chain(rdev,
+                                             REGULATOR_EVENT_UNDER_VOLTAGE,
+                                             wm8350);
+}
+
+static int wm8350_regulator_probe(struct platform_device *pdev)
+{
+       struct wm8350 *wm8350 = dev_get_drvdata(&pdev->dev);
+       struct regulator_dev *rdev;
+       int ret;
+       u16 val;
+
+       if (pdev->id < WM8350_DCDC_1 || pdev->id > WM8350_ISINK_B)
+               return -ENODEV;
+
+       /* do any regulatior specific init */
+       switch (pdev->id) {
+       case WM8350_DCDC_1:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC1_LOW_POWER);
+               wm8350->pmic.dcdc1_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               break;
+       case WM8350_DCDC_3:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC3_LOW_POWER);
+               wm8350->pmic.dcdc3_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               break;
+       case WM8350_DCDC_4:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC4_LOW_POWER);
+               wm8350->pmic.dcdc4_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               break;
+       case WM8350_DCDC_6:
+               val = wm8350_reg_read(wm8350, WM8350_DCDC6_LOW_POWER);
+               wm8350->pmic.dcdc6_hib_mode = val & WM8350_DCDC_HIB_MODE_MASK;
+               break;
+       }
+
+
+       /* register regulator */
+       rdev = regulator_register(&wm8350_reg[pdev->id], &pdev->dev,
+                                 dev_get_drvdata(&pdev->dev));
+       if (IS_ERR(rdev)) {
+               dev_err(&pdev->dev, "failed to register %s\n",
+                       wm8350_reg[pdev->id].name);
+               return PTR_ERR(rdev);
+       }
+
+       /* register regulator IRQ */
+       ret = wm8350_register_irq(wm8350, wm8350_reg[pdev->id].irq,
+                                 pmic_uv_handler, rdev);
+       if (ret < 0) {
+               regulator_unregister(rdev);
+               dev_err(&pdev->dev, "failed to register regulator %s IRQ\n",
+                       wm8350_reg[pdev->id].name);
+               return ret;
+       }
+
+       wm8350_unmask_irq(wm8350, wm8350_reg[pdev->id].irq);
+
+       return 0;
+}
+
+static int wm8350_regulator_remove(struct platform_device *pdev)
+{
+       struct regulator_dev *rdev = platform_get_drvdata(pdev);
+       struct wm8350 *wm8350 = rdev_get_drvdata(rdev);
+
+       wm8350_mask_irq(wm8350, wm8350_reg[pdev->id].irq);
+       wm8350_free_irq(wm8350, wm8350_reg[pdev->id].irq);
+
+       regulator_unregister(rdev);
+
+       return 0;
+}
+
+int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
+                             struct regulator_init_data *initdata)
+{
+       struct platform_device *pdev;
+       int ret;
+
+       if (wm8350->pmic.pdev[reg])
+               return -EBUSY;
+
+       pdev = platform_device_alloc("wm8350-regulator", reg);
+       if (!pdev)
+               return -ENOMEM;
+
+       wm8350->pmic.pdev[reg] = pdev;
+
+       initdata->driver_data = wm8350;
+
+       pdev->dev.platform_data = initdata;
+       pdev->dev.parent = wm8350->dev;
+       platform_set_drvdata(pdev, wm8350);
+
+       ret = platform_device_add(pdev);
+
+       if (ret != 0) {
+               dev_err(wm8350->dev, "Failed to register regulator %d: %d\n",
+                       reg, ret);
+               platform_device_del(pdev);
+               wm8350->pmic.pdev[reg] = NULL;
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL_GPL(wm8350_register_regulator);
+
+static struct platform_driver wm8350_regulator_driver = {
+       .probe = wm8350_regulator_probe,
+       .remove = wm8350_regulator_remove,
+       .driver         = {
+               .name   = "wm8350-regulator",
+       },
+};
+
+static int __init wm8350_regulator_init(void)
+{
+       return platform_driver_register(&wm8350_regulator_driver);
+}
+subsys_initcall(wm8350_regulator_init);
+
+static void __exit wm8350_regulator_exit(void)
+{
+       platform_driver_unregister(&wm8350_regulator_driver);
+}
+module_exit(wm8350_regulator_exit);
+
+/* Module information */
+MODULE_AUTHOR("Liam Girdwood");
+MODULE_DESCRIPTION("WM8350 voltage and current regulator driver");
+MODULE_LICENSE("GPL");
diff --git a/drivers/regulator/wm8400-regulator.c b/drivers/regulator/wm8400-regulator.c
new file mode 100644 (file)
index 0000000..48b372e
--- /dev/null
@@ -0,0 +1,368 @@
+/*
+ * Regulator support for WM8400
+ *
+ * Copyright 2008 Wolfson Microelectronics PLC.
+ *
+ * Author: Mark Brown <broonie@opensource.wolfsonmicro.com>
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ */
+
+#include <linux/bug.h>
+#include <linux/err.h>
+#include <linux/kernel.h>
+#include <linux/regulator/driver.h>
+#include <linux/mfd/wm8400-private.h>
+
+static int wm8400_ldo_is_enabled(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       u16 val;
+
+       val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
+       return (val & WM8400_LDO1_ENA) != 0;
+}
+
+static int wm8400_ldo_enable(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+
+       return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
+                              WM8400_LDO1_ENA, WM8400_LDO1_ENA);
+}
+
+static int wm8400_ldo_disable(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+
+       return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
+                              WM8400_LDO1_ENA, 0);
+}
+
+static int wm8400_ldo_get_voltage(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       u16 val;
+
+       val = wm8400_reg_read(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev));
+       val &= WM8400_LDO1_VSEL_MASK;
+
+       if (val < 15)
+               return 900000 + (val * 50000);
+       else
+               return 1600000 + ((val - 14) * 100000);
+}
+
+static int wm8400_ldo_set_voltage(struct regulator_dev *dev,
+                                 int min_uV, int max_uV)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       u16 val;
+
+       if (min_uV < 900000 || min_uV > 3300000)
+               return -EINVAL;
+
+       if (min_uV < 1700000) {
+               /* Steps of 50mV from 900mV;  */
+               val = (min_uV - 850001) / 50000;
+
+               if ((val * 50000) + 900000 > max_uV)
+                       return -EINVAL;
+               BUG_ON((val * 50000) + 900000 < min_uV);
+       } else {
+               /* Steps of 100mV from 1700mV */
+               val = ((min_uV - 1600001) / 100000);
+
+               if ((val * 100000) + 1700000 > max_uV)
+                       return -EINVAL;
+               BUG_ON((val * 100000) + 1700000 < min_uV);
+
+               val += 0xf;
+       }
+
+       return wm8400_set_bits(wm8400, WM8400_LDO1_CONTROL + rdev_get_id(dev),
+                              WM8400_LDO1_VSEL_MASK, val);
+}
+
+static struct regulator_ops wm8400_ldo_ops = {
+       .is_enabled = wm8400_ldo_is_enabled,
+       .enable = wm8400_ldo_enable,
+       .disable = wm8400_ldo_disable,
+       .get_voltage = wm8400_ldo_get_voltage,
+       .set_voltage = wm8400_ldo_set_voltage,
+};
+
+static int wm8400_dcdc_is_enabled(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+       u16 val;
+
+       val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
+       return (val & WM8400_DC1_ENA) != 0;
+}
+
+static int wm8400_dcdc_enable(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+
+       return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                              WM8400_DC1_ENA, WM8400_DC1_ENA);
+}
+
+static int wm8400_dcdc_disable(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+
+       return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                              WM8400_DC1_ENA, 0);
+}
+
+static int wm8400_dcdc_get_voltage(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       u16 val;
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+
+       val = wm8400_reg_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset);
+       val &= WM8400_DC1_VSEL_MASK;
+
+       return 850000 + (25000 * val);
+}
+
+static int wm8400_dcdc_set_voltage(struct regulator_dev *dev,
+                                 int min_uV, int max_uV)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       u16 val;
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+
+       if (min_uV < 850000)
+               return -EINVAL;
+
+       val = (min_uV - 825001) / 25000;
+
+       if (850000 + (25000 * val) > max_uV)
+               return -EINVAL;
+       BUG_ON(850000 + (25000 * val) < min_uV);
+
+       return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                              WM8400_DC1_VSEL_MASK, val);
+}
+
+static unsigned int wm8400_dcdc_get_mode(struct regulator_dev *dev)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+       u16 data[2];
+       int ret;
+
+       ret = wm8400_block_read(wm8400, WM8400_DCDC1_CONTROL_1 + offset, 2,
+                               data);
+       if (ret != 0)
+               return 0;
+
+       /* Datasheet: hibernate */
+       if (data[0] & WM8400_DC1_SLEEP)
+               return REGULATOR_MODE_STANDBY;
+
+       /* Datasheet: standby */
+       if (!(data[0] & WM8400_DC1_ACTIVE))
+               return REGULATOR_MODE_IDLE;
+
+       /* Datasheet: active with or without force PWM */
+       if (data[1] & WM8400_DC1_FRC_PWM)
+               return REGULATOR_MODE_FAST;
+       else
+               return REGULATOR_MODE_NORMAL;
+}
+
+static int wm8400_dcdc_set_mode(struct regulator_dev *dev, unsigned int mode)
+{
+       struct wm8400 *wm8400 = rdev_get_drvdata(dev);
+       int offset = (rdev_get_id(dev) - WM8400_DCDC1) * 2;
+       int ret;
+
+       switch (mode) {
+       case REGULATOR_MODE_FAST:
+               /* Datasheet: active with force PWM */
+               ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
+                                     WM8400_DC1_FRC_PWM, WM8400_DC1_FRC_PWM);
+               if (ret != 0)
+                       return ret;
+
+               return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                                      WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
+                                      WM8400_DC1_ACTIVE);
+
+       case REGULATOR_MODE_NORMAL:
+               /* Datasheet: active */
+               ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_2 + offset,
+                                     WM8400_DC1_FRC_PWM, 0);
+               if (ret != 0)
+                       return ret;
+
+               return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                                      WM8400_DC1_ACTIVE | WM8400_DC1_SLEEP,
+                                      WM8400_DC1_ACTIVE);
+
+       case REGULATOR_MODE_IDLE:
+               /* Datasheet: standby */
+               ret = wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                                     WM8400_DC1_ACTIVE, 0);
+               if (ret != 0)
+                       return ret;
+               return wm8400_set_bits(wm8400, WM8400_DCDC1_CONTROL_1 + offset,
+                                      WM8400_DC1_SLEEP, 0);
+
+       default:
+               return -EINVAL;
+       }
+}
+
+static unsigned int wm8400_dcdc_get_optimum_mode(struct regulator_dev *dev,
+                                                int input_uV, int output_uV,
+                                                int load_uA)
+{
+       return REGULATOR_MODE_NORMAL;
+}
+
+static struct regulator_ops wm8400_dcdc_ops = {
+       .is_enabled = wm8400_dcdc_is_enabled,
+       .enable = wm8400_dcdc_enable,
+       .disable = wm8400_dcdc_disable,
+       .get_voltage = wm8400_dcdc_get_voltage,
+       .set_voltage = wm8400_dcdc_set_voltage,
+       .get_mode = wm8400_dcdc_get_mode,
+       .set_mode = wm8400_dcdc_set_mode,
+       .get_optimum_mode = wm8400_dcdc_get_optimum_mode,
+};
+
+static struct regulator_desc regulators[] = {
+       {
+               .name = "LDO1",
+               .id = WM8400_LDO1,
+               .ops = &wm8400_ldo_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO2",
+               .id = WM8400_LDO2,
+               .ops = &wm8400_ldo_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO3",
+               .id = WM8400_LDO3,
+               .ops = &wm8400_ldo_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "LDO4",
+               .id = WM8400_LDO4,
+               .ops = &wm8400_ldo_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC1",
+               .id = WM8400_DCDC1,
+               .ops = &wm8400_dcdc_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+       {
+               .name = "DCDC2",
+               .id = WM8400_DCDC2,
+               .ops = &wm8400_dcdc_ops,
+               .type = REGULATOR_VOLTAGE,
+               .owner = THIS_MODULE,
+       },
+};
+
+static int __init wm8400_regulator_probe(struct platform_device *pdev)
+{
+       struct regulator_dev *rdev;
+
+       rdev = regulator_register(&regulators[pdev->id], &pdev->dev,
+               pdev->dev.driver_data);
+
+       if (IS_ERR(rdev))
+               return PTR_ERR(rdev);
+
+       return 0;
+}
+
+static int __devexit wm8400_regulator_remove(struct platform_device *pdev)
+{
+       struct regulator_dev *rdev = platform_get_drvdata(pdev);
+
+       regulator_unregister(rdev);
+
+       return 0;
+}
+
+static struct platform_driver wm8400_regulator_driver = {
+       .driver = {
+               .name = "wm8400-regulator",
+       },
+       .probe = wm8400_regulator_probe,
+       .remove = __devexit_p(wm8400_regulator_remove),
+};
+
+/**
+ * wm8400_register_regulator - enable software control of a WM8400 regulator
+ *
+ * This function enables software control of a WM8400 regulator via
+ * the regulator API.  It is intended to be called from the
+ * platform_init() callback of the WM8400 MFD driver.
+ *
+ * @param dev      The WM8400 device to operate on.
+ * @param reg      The regulator to control.
+ * @param initdata Regulator initdata for the regulator.
+ */
+int wm8400_register_regulator(struct device *dev, int reg,
+                             struct regulator_init_data *initdata)
+{
+       struct wm8400 *wm8400 = dev->driver_data;
+
+       if (wm8400->regulators[reg].name)
+               return -EBUSY;
+
+       initdata->driver_data = wm8400;
+
+       wm8400->regulators[reg].name = "wm8400-regulator";
+       wm8400->regulators[reg].id = reg;
+       wm8400->regulators[reg].dev.parent = dev;
+       wm8400->regulators[reg].dev.driver_data = wm8400;
+       wm8400->regulators[reg].dev.platform_data = initdata;
+
+       return platform_device_register(&wm8400->regulators[reg]);
+}
+EXPORT_SYMBOL_GPL(wm8400_register_regulator);
+
+static int __init wm8400_regulator_init(void)
+{
+       return platform_driver_register(&wm8400_regulator_driver);
+}
+module_init(wm8400_regulator_init);
+
+static void __exit wm8400_regulator_exit(void)
+{
+       platform_driver_unregister(&wm8400_regulator_driver);
+}
+module_exit(wm8400_regulator_exit);
+
+MODULE_AUTHOR("Mark Brown <broonie@opensource.wolfsonmicro.com>");
+MODULE_DESCRIPTION("WM8400 regulator driver");
+MODULE_LICENSE("GPL");
+MODULE_ALIAS("platform:wm8400-regulator");
index b23af0c2a869181e5b4fb5480546b93103d93d40..963ad0b6a4e9da64ff911cba52508e5c39b8085a 100644 (file)
@@ -913,6 +913,92 @@ static inline int cmos_poweroff(struct device *dev)
  * predate even PNPBIOS should set up platform_bus devices.
  */
 
+#ifdef CONFIG_ACPI
+
+#include <linux/acpi.h>
+
+#ifdef CONFIG_PM
+static u32 rtc_handler(void *context)
+{
+       acpi_clear_event(ACPI_EVENT_RTC);
+       acpi_disable_event(ACPI_EVENT_RTC, 0);
+       return ACPI_INTERRUPT_HANDLED;
+}
+
+static inline void rtc_wake_setup(void)
+{
+       acpi_install_fixed_event_handler(ACPI_EVENT_RTC, rtc_handler, NULL);
+       /*
+        * After the RTC handler is installed, the Fixed_RTC event should
+        * be disabled. Only when the RTC alarm is set will it be enabled.
+        */
+       acpi_clear_event(ACPI_EVENT_RTC);
+       acpi_disable_event(ACPI_EVENT_RTC, 0);
+}
+
+static void rtc_wake_on(struct device *dev)
+{
+       acpi_clear_event(ACPI_EVENT_RTC);
+       acpi_enable_event(ACPI_EVENT_RTC, 0);
+}
+
+static void rtc_wake_off(struct device *dev)
+{
+       acpi_disable_event(ACPI_EVENT_RTC, 0);
+}
+#else
+#define rtc_wake_setup()       do{}while(0)
+#define rtc_wake_on            NULL
+#define rtc_wake_off           NULL
+#endif
+
+/* Every ACPI platform has a mc146818 compatible "cmos rtc".  Here we find
+ * its device node and pass extra config data.  This helps its driver use
+ * capabilities that the now-obsolete mc146818 didn't have, and informs it
+ * that this board's RTC is wakeup-capable (per ACPI spec).
+ */
+static struct cmos_rtc_board_info acpi_rtc_info;
+
+static void __devinit
+cmos_wake_setup(struct device *dev)
+{
+       if (acpi_disabled)
+               return;
+
+       rtc_wake_setup();
+       acpi_rtc_info.wake_on = rtc_wake_on;
+       acpi_rtc_info.wake_off = rtc_wake_off;
+
+       /* workaround bug in some ACPI tables */
+       if (acpi_gbl_FADT.month_alarm && !acpi_gbl_FADT.day_alarm) {
+               dev_dbg(dev, "bogus FADT month_alarm (%d)\n",
+                       acpi_gbl_FADT.month_alarm);
+               acpi_gbl_FADT.month_alarm = 0;
+       }
+
+       acpi_rtc_info.rtc_day_alarm = acpi_gbl_FADT.day_alarm;
+       acpi_rtc_info.rtc_mon_alarm = acpi_gbl_FADT.month_alarm;
+       acpi_rtc_info.rtc_century = acpi_gbl_FADT.century;
+
+       /* NOTE:  S4_RTC_WAKE is NOT currently useful to Linux */
+       if (acpi_gbl_FADT.flags & ACPI_FADT_S4_RTC_WAKE)
+               dev_info(dev, "RTC can wake from S4\n");
+
+       dev->platform_data = &acpi_rtc_info;
+
+       /* RTC always wakes from S1/S2/S3, and often S4/STD */
+       device_init_wakeup(dev, 1);
+}
+
+#else
+
+static void __devinit
+cmos_wake_setup(struct device *dev)
+{
+}
+
+#endif
+
 #ifdef CONFIG_PNP
 
 #include <linux/pnp.h>
@@ -920,6 +1006,8 @@ static inline int cmos_poweroff(struct device *dev)
 static int __devinit
 cmos_pnp_probe(struct pnp_dev *pnp, const struct pnp_device_id *id)
 {
+       cmos_wake_setup(&pnp->dev);
+
        if (pnp_port_start(pnp,0) == 0x70 && !pnp_irq_valid(pnp,0))
                /* Some machines contain a PNP entry for the RTC, but
                 * don't define the IRQ. It should always be safe to
@@ -997,6 +1085,7 @@ static struct pnp_driver cmos_pnp_driver = {
 
 static int __init cmos_platform_probe(struct platform_device *pdev)
 {
+       cmos_wake_setup(&pdev->dev);
        return cmos_do_probe(&pdev->dev,
                        platform_get_resource(pdev, IORESOURCE_IO, 0),
                        platform_get_irq(pdev, 0));
@@ -1031,29 +1120,32 @@ static struct platform_driver cmos_platform_driver = {
 
 static int __init cmos_init(void)
 {
+       int retval = 0;
+
 #ifdef CONFIG_PNP
-       if (pnp_platform_devices)
-               return pnp_register_driver(&cmos_pnp_driver);
-       else
-               return platform_driver_probe(&cmos_platform_driver,
-                       cmos_platform_probe);
-#else
-       return platform_driver_probe(&cmos_platform_driver,
-                       cmos_platform_probe);
-#endif /* CONFIG_PNP */
+       pnp_register_driver(&cmos_pnp_driver);
+#endif
+
+       if (!cmos_rtc.dev)
+               retval = platform_driver_probe(&cmos_platform_driver,
+                                              cmos_platform_probe);
+
+       if (retval == 0)
+               return 0;
+
+#ifdef CONFIG_PNP
+       pnp_unregister_driver(&cmos_pnp_driver);
+#endif
+       return retval;
 }
 module_init(cmos_init);
 
 static void __exit cmos_exit(void)
 {
 #ifdef CONFIG_PNP
-       if (pnp_platform_devices)
-               pnp_unregister_driver(&cmos_pnp_driver);
-       else
-               platform_driver_unregister(&cmos_platform_driver);
-#else
+       pnp_unregister_driver(&cmos_pnp_driver);
+#endif
        platform_driver_unregister(&cmos_platform_driver);
-#endif /* CONFIG_PNP */
 }
 module_exit(cmos_exit);
 
index 8f83fc994f508ef6069a1a9cc67eb30b196e945d..f5e618562c5ff9b1be02d014a022ca13e98e10ef 100644 (file)
@@ -2913,7 +2913,7 @@ claw_new_device(struct ccwgroup_device *cgdev)
        if (ret != 0) {
                printk(KERN_WARNING
                        "claw: ccw_device_set_online %s WRITE failed "
-                      "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev)
+                      "with ret = %d\n", dev_name(&cgdev->cdev[WRITE]->dev),
                       ret);
                goto out;
        }
index d3b211af4e1cd259a4d38bec0193a7792090d991..403ecad48d4b95ba5bdb5897803e496862c6b09f 100644 (file)
@@ -1640,6 +1640,7 @@ config ATARI_SCSI
        tristate "Atari native SCSI support"
        depends on ATARI && SCSI
        select SCSI_SPI_ATTRS
+       select NVRAM
        ---help---
          If you have an Atari with built-in NCR5380 SCSI controller (TT,
          Falcon, ...) say Y to get it supported. Of course also, if you have
@@ -1670,14 +1671,6 @@ config ATARI_SCSI_RESET_BOOT
          boot process fractionally longer but may assist recovery from errors
          that leave the devices with SCSI operations partway completed.
 
-config TT_DMA_EMUL
-       bool "Hades SCSI DMA emulator"
-       depends on ATARI_SCSI && HADES
-       help
-         This option enables code which emulates the TT SCSI DMA chip on the
-         Hades. This increases the SCSI transfer rates at least ten times
-         compared to PIO transfers.
-
 config MAC_SCSI
        bool "Macintosh NCR5380 SCSI"
        depends on MAC && SCSI=y
diff --git a/drivers/scsi/atari_dma_emul.c b/drivers/scsi/atari_dma_emul.c
deleted file mode 100644 (file)
index cdc710e..0000000
+++ /dev/null
@@ -1,468 +0,0 @@
-/*
- * atari_dma_emul.c -- TT SCSI DMA emulator for the Hades.
- *
- * Copyright 1997 Wout Klaren <W.Klaren@inter.nl.net>
- *
- * This file is subject to the terms and conditions of the GNU General Public
- * License.  See the file COPYING in the main directory of this archive
- * for more details.
- *
- * This code was written using the Hades TOS source code as a
- * reference. This source code can be found on the home page
- * of Medusa Computer Systems.
- *
- * Version 0.1, 1997-09-24.
- * 
- * This code should be considered experimental. It has only been
- * tested on a Hades with a 68060. It might not work on a Hades
- * with a 68040. Make backups of your hard drives before using
- * this code.
- */
-
-#include <linux/compiler.h>
-#include <asm/thread_info.h>
-#include <asm/uaccess.h>
-
-#define hades_dma_ctrl         (*(unsigned char *) 0xffff8717)
-#define hades_psdm_reg         (*(unsigned char *) 0xffff8741)
-
-#define TRANSFER_SIZE          16
-
-struct m68040_frame {
-       unsigned long  effaddr;  /* effective address */
-       unsigned short ssw;      /* special status word */
-       unsigned short wb3s;     /* write back 3 status */
-       unsigned short wb2s;     /* write back 2 status */
-       unsigned short wb1s;     /* write back 1 status */
-       unsigned long  faddr;    /* fault address */
-       unsigned long  wb3a;     /* write back 3 address */
-       unsigned long  wb3d;     /* write back 3 data */
-       unsigned long  wb2a;     /* write back 2 address */
-       unsigned long  wb2d;     /* write back 2 data */
-       unsigned long  wb1a;     /* write back 1 address */
-       unsigned long  wb1dpd0;  /* write back 1 data/push data 0*/
-       unsigned long  pd1;      /* push data 1*/
-       unsigned long  pd2;      /* push data 2*/
-       unsigned long  pd3;      /* push data 3*/
-};
-
-static void writeback (unsigned short wbs, unsigned long wba,
-                      unsigned long wbd, void *old_buserr)
-{
-       mm_segment_t fs = get_fs();
-       static void *save_buserr;
-
-       __asm__ __volatile__ ("movec.l  %%vbr,%%a0\n\t"
-                             "move.l   %0,8(%%a0)\n\t"
-                             :
-                             : "r" (&&bus_error)
-                             : "a0" );
-
-       save_buserr = old_buserr;
-
-       set_fs (MAKE_MM_SEG(wbs & WBTM_040));
-
-       switch (wbs & WBSIZ_040) {
-           case BA_SIZE_BYTE:
-               put_user (wbd & 0xff, (char *)wba);
-               break;
-           case BA_SIZE_WORD:
-               put_user (wbd & 0xffff, (short *)wba);
-               break;
-           case BA_SIZE_LONG:
-               put_user (wbd, (int *)wba);
-               break;
-       }
-
-       set_fs (fs);
-       return;
-
-bus_error:
-       __asm__ __volatile__ ("cmp.l    %0,2(%%sp)\n\t"
-                             "bcs.s    .jump_old\n\t"
-                             "cmp.l    %1,2(%%sp)\n\t"
-                             "bls.s    .restore_old\n"
-                       ".jump_old:\n\t"
-                             "move.l   %2,-(%%sp)\n\t"
-                             "rts\n"
-                       ".restore_old:\n\t"
-                             "move.l   %%a0,-(%%sp)\n\t"
-                             "movec.l  %%vbr,%%a0\n\t"
-                             "move.l   %2,8(%%a0)\n\t"
-                             "move.l   (%%sp)+,%%a0\n\t"
-                             "rte\n\t"
-                             :
-                             : "i" (writeback), "i" (&&bus_error),
-                               "m" (save_buserr) );
-}
-
-/*
- * static inline void set_restdata_reg(unsigned char *cur_addr)
- *
- * Set the rest data register if necessary.
- */
-
-static inline void set_restdata_reg(unsigned char *cur_addr)
-{
-       if (((long) cur_addr & ~3) != 0)
-               tt_scsi_dma.dma_restdata =
-                       *((unsigned long *) ((long) cur_addr & ~3));
-}
-
-/*
- * void hades_dma_emulator(int irq, void *dummy)
- * 
- * This code emulates TT SCSI DMA on the Hades.
- * 
- * Note the following:
- * 
- * 1. When there is no byte available to read from the SCSI bus, or
- *    when a byte cannot yet bet written to the SCSI bus, a bus
- *    error occurs when reading or writing the pseudo DMA data
- *    register (hades_psdm_reg). We have to catch this bus error
- *    and try again to read or write the byte. If after several tries
- *    we still get a bus error, the interrupt handler is left. When
- *    the byte can be read or written, the interrupt handler is
- *    called again.
- * 
- * 2. The SCSI interrupt must be disabled in this interrupt handler.
- * 
- * 3. If we set the EOP signal, the SCSI controller still expects one
- *    byte to be read or written. Therefore the last byte is transferred
- *    separately, after setting the EOP signal.
- * 
- * 4. When this function is left, the address pointer (start_addr) is
- *    converted to a physical address. Because it points one byte
- *    further than the last transferred byte, it can point outside the
- *    current page. If virt_to_phys() is called with this address we
- *    might get an access error. Therefore virt_to_phys() is called with
- *    start_addr - 1 if the count has reached zero. The result is
- *    increased with one.
- */
-
-static irqreturn_t hades_dma_emulator(int irq, void *dummy)
-{
-       unsigned long dma_base;
-       register unsigned long dma_cnt asm ("d3");
-       static long save_buserr;
-       register unsigned long save_sp asm ("d4");
-       register int tries asm ("d5");
-       register unsigned char *start_addr asm ("a3"), *end_addr asm ("a4");
-       register unsigned char *eff_addr;
-       register unsigned char *psdm_reg;
-       unsigned long rem;
-
-       atari_disable_irq(IRQ_TT_MFP_SCSI);
-
-       /*
-        * Read the dma address and count registers.
-        */
-
-       dma_base = SCSI_DMA_READ_P(dma_addr);
-       dma_cnt = SCSI_DMA_READ_P(dma_cnt);
-
-       /*
-        * Check if DMA is still enabled.
-        */
-
-       if ((tt_scsi_dma.dma_ctrl & 2) == 0)
-       {
-               atari_enable_irq(IRQ_TT_MFP_SCSI);
-               return IRQ_HANDLED;
-       }
-
-       if (dma_cnt == 0)
-       {
-               printk(KERN_NOTICE "DMA emulation: count is zero.\n");
-               tt_scsi_dma.dma_ctrl &= 0xfd;   /* DMA ready. */
-               atari_enable_irq(IRQ_TT_MFP_SCSI);
-               return IRQ_HANDLED;
-       }
-
-       /*
-        * Install new bus error routine.
-        */
-
-       __asm__ __volatile__ ("movec.l  %%vbr,%%a0\n\t"
-                             "move.l   8(%%a0),%0\n\t"
-                             "move.l   %1,8(%%a0)\n\t"
-                             : "=&r" (save_buserr)
-                             : "r" (&&scsi_bus_error)
-                             : "a0" );
-
-       hades_dma_ctrl &= 0xfc;         /* Bus error and EOP off. */
-
-       /*
-        * Save the stack pointer.
-        */
-
-       __asm__ __volatile__ ("move.l   %%sp,%0\n\t"
-                             : "=&r" (save_sp) );
-
-       tries = 100;                    /* Maximum number of bus errors. */
-       start_addr = phys_to_virt(dma_base);
-       end_addr = start_addr + dma_cnt;
-
-scsi_loop:
-       dma_cnt--;
-       rem = dma_cnt & (TRANSFER_SIZE - 1);
-       dma_cnt &= ~(TRANSFER_SIZE - 1);
-       psdm_reg = &hades_psdm_reg;
-
-       if (tt_scsi_dma.dma_ctrl & 1)   /* Read or write? */
-       {
-               /*
-                * SCSI write. Abort when count is zero.
-                */
-
-               switch (rem)
-               {
-               case 0:
-                       while (dma_cnt > 0)
-                       {
-                               dma_cnt -= TRANSFER_SIZE;
-
-                               *psdm_reg = *start_addr++;
-               case 15:
-                               *psdm_reg = *start_addr++;
-               case 14:
-                               *psdm_reg = *start_addr++;
-               case 13:
-                               *psdm_reg = *start_addr++;
-               case 12:
-                               *psdm_reg = *start_addr++;
-               case 11:
-                               *psdm_reg = *start_addr++;
-               case 10:
-                               *psdm_reg = *start_addr++;
-               case 9:
-                               *psdm_reg = *start_addr++;
-               case 8:
-                               *psdm_reg = *start_addr++;
-               case 7:
-                               *psdm_reg = *start_addr++;
-               case 6:
-                               *psdm_reg = *start_addr++;
-               case 5:
-                               *psdm_reg = *start_addr++;
-               case 4:
-                               *psdm_reg = *start_addr++;
-               case 3:
-                               *psdm_reg = *start_addr++;
-               case 2:
-                               *psdm_reg = *start_addr++;
-               case 1:
-                               *psdm_reg = *start_addr++;
-                       }
-               }
-
-               hades_dma_ctrl |= 1;    /* Set EOP. */
-               udelay(10);
-               *psdm_reg = *start_addr++;      /* Dummy byte. */
-               tt_scsi_dma.dma_ctrl &= 0xfd;   /* DMA ready. */
-       }
-       else
-       {
-               /*
-                * SCSI read. Abort when count is zero.
-                */
-
-               switch (rem)
-               {
-               case 0:
-                       while (dma_cnt > 0)
-                       {
-                               dma_cnt -= TRANSFER_SIZE;
-
-                               *start_addr++ = *psdm_reg;
-               case 15:
-                               *start_addr++ = *psdm_reg;
-               case 14:
-                               *start_addr++ = *psdm_reg;
-               case 13:
-                               *start_addr++ = *psdm_reg;
-               case 12:
-                               *start_addr++ = *psdm_reg;
-               case 11:
-                               *start_addr++ = *psdm_reg;
-               case 10:
-                               *start_addr++ = *psdm_reg;
-               case 9:
-                               *start_addr++ = *psdm_reg;
-               case 8:
-                               *start_addr++ = *psdm_reg;
-               case 7:
-                               *start_addr++ = *psdm_reg;
-               case 6:
-                               *start_addr++ = *psdm_reg;
-               case 5:
-                               *start_addr++ = *psdm_reg;
-               case 4:
-                               *start_addr++ = *psdm_reg;
-               case 3:
-                               *start_addr++ = *psdm_reg;
-               case 2:
-                               *start_addr++ = *psdm_reg;
-               case 1:
-                               *start_addr++ = *psdm_reg;
-                       }
-               }
-
-               hades_dma_ctrl |= 1;    /* Set EOP. */
-               udelay(10);
-               *start_addr++ = *psdm_reg;
-               tt_scsi_dma.dma_ctrl &= 0xfd;   /* DMA ready. */
-
-               set_restdata_reg(start_addr);
-       }
-
-       if (start_addr != end_addr)
-               printk(KERN_CRIT "DMA emulation: FATAL: Count is not zero at end of transfer.\n");
-
-       dma_cnt = end_addr - start_addr;
-
-scsi_end:
-       dma_base = (dma_cnt == 0) ? virt_to_phys(start_addr - 1) + 1 :  
-                                   virt_to_phys(start_addr);
-
-       SCSI_DMA_WRITE_P(dma_addr, dma_base);
-       SCSI_DMA_WRITE_P(dma_cnt, dma_cnt);
-
-       /*
-        * Restore old bus error routine.
-        */
-
-       __asm__ __volatile__ ("movec.l  %%vbr,%%a0\n\t"
-                             "move.l   %0,8(%%a0)\n\t"
-                             :
-                             : "r" (save_buserr)
-                             : "a0" );
-
-       atari_enable_irq(IRQ_TT_MFP_SCSI);
-
-       return IRQ_HANDLED;
-
-scsi_bus_error:
-       /*
-        * First check if the bus error is caused by our code.
-        * If not, call the original handler.
-        */
-
-       __asm__ __volatile__ ("cmp.l    %0,2(%%sp)\n\t"
-                             "bcs.s    .old_vector\n\t"
-                             "cmp.l    %1,2(%%sp)\n\t"
-                             "bls.s    .scsi_buserr\n"
-                       ".old_vector:\n\t"
-                             "move.l   %2,-(%%sp)\n\t"
-                             "rts\n"
-                       ".scsi_buserr:\n\t"
-                             :
-                             : "i" (&&scsi_loop), "i" (&&scsi_end),
-                               "m" (save_buserr) );
-
-       if (CPU_IS_060)
-       {
-               /*
-                * Get effective address and restore the stack.
-                */
-
-               __asm__ __volatile__ ("move.l   8(%%sp),%0\n\t"
-                                     "move.l   %1,%%sp\n\t"
-                                     : "=a&" (eff_addr)
-                                     : "r" (save_sp) );
-       }
-       else
-       {
-               register struct m68040_frame *frame;
-
-               __asm__ __volatile__ ("lea      8(%%sp),%0\n\t"
-                                     : "=a&" (frame) );
-
-               if (tt_scsi_dma.dma_ctrl & 1)
-               {
-                       /*
-                        * Bus error while writing.
-                        */
-
-                       if (frame->wb3s & WBV_040)
-                       {
-                               if (frame->wb3a == (long) &hades_psdm_reg)
-                                       start_addr--;
-                               else
-                                       writeback(frame->wb3s, frame->wb3a,
-                                                 frame->wb3d, &&scsi_bus_error);
-                       }
-
-                       if (frame->wb2s & WBV_040)
-                       {
-                               if (frame->wb2a == (long) &hades_psdm_reg)
-                                       start_addr--;
-                               else
-                                       writeback(frame->wb2s, frame->wb2a,
-                                                 frame->wb2d, &&scsi_bus_error);
-                       }
-
-                       if (frame->wb1s & WBV_040)
-                       {
-                               if (frame->wb1a == (long) &hades_psdm_reg)
-                                       start_addr--;
-                       }
-               }
-               else
-               {
-                       /*
-                        * Bus error while reading.
-                        */
-
-                       if (frame->wb3s & WBV_040)
-                               writeback(frame->wb3s, frame->wb3a,
-                                         frame->wb3d, &&scsi_bus_error);
-               }
-
-               eff_addr = (unsigned char *) frame->faddr;
-
-               __asm__ __volatile__ ("move.l   %0,%%sp\n\t"
-                                     :
-                                     : "r" (save_sp) );
-       }
-
-       dma_cnt = end_addr - start_addr;
-
-       if (eff_addr == &hades_psdm_reg)
-       {
-               /*
-                * Bus error occurred while reading the pseudo
-                * DMA register. Time out.
-                */
-
-               tries--;
-
-               if (tries <= 0)
-               {
-                       if ((tt_scsi_dma.dma_ctrl & 1) == 0)    /* Read or write? */
-                               set_restdata_reg(start_addr);
-
-                       if (dma_cnt <= 1)
-                               printk(KERN_CRIT "DMA emulation: Fatal "
-                                      "error while %s the last byte.\n",
-                                      (tt_scsi_dma.dma_ctrl & 1)
-                                      ? "writing" : "reading");
-
-                       goto scsi_end;
-               }
-               else
-                       goto scsi_loop;
-       }
-       else
-       {
-               /*
-                * Bus error during pseudo DMA transfer.
-                * Terminate the DMA transfer.
-                */
-
-               hades_dma_ctrl |= 3;    /* Set EOP and bus error. */
-               if ((tt_scsi_dma.dma_ctrl & 1) == 0)    /* Read or write? */
-                       set_restdata_reg(start_addr);
-               goto scsi_end;
-       }
-}
index f5732d8f67fec793badb30948d369710e9260a55..21fe07f9df87be3ebd5222d8ce15eaea2e04d5d4 100644 (file)
@@ -249,10 +249,6 @@ static int setup_hostid = -1;
 module_param(setup_hostid, int, 0);
 
 
-#if defined(CONFIG_TT_DMA_EMUL)
-#include "atari_dma_emul.c"
-#endif
-
 #if defined(REAL_DMA)
 
 static int scsi_dma_is_ignored_buserr(unsigned char dma_stat)
@@ -695,21 +691,8 @@ int atari_scsi_detect(struct scsi_host_template *host)
 #ifdef REAL_DMA
                tt_scsi_dma.dma_ctrl = 0;
                atari_dma_residual = 0;
-#ifdef CONFIG_TT_DMA_EMUL
-               if (MACH_IS_HADES) {
-                       if (request_irq(IRQ_AUTO_2, hades_dma_emulator,
-                                        IRQ_TYPE_PRIO, "Hades DMA emulator",
-                                        hades_dma_emulator)) {
-                               printk(KERN_ERR "atari_scsi_detect: cannot allocate irq %d, aborting (MACH_IS_HADES)",IRQ_AUTO_2);
-                               free_irq(IRQ_TT_MFP_SCSI, instance);
-                               scsi_unregister(atari_scsi_host);
-                               atari_stram_free(atari_dma_buffer);
-                               atari_dma_buffer = 0;
-                               return 0;
-                       }
-               }
-#endif
-               if (MACH_IS_MEDUSA || MACH_IS_HADES) {
+
+               if (MACH_IS_MEDUSA) {
                        /* While the read overruns (described by Drew Eckhardt in
                         * NCR5380.c) never happened on TTs, they do in fact on the Medusa
                         * (This was the cause why SCSI didn't work right for so long
@@ -1007,11 +990,7 @@ static unsigned long atari_dma_xfer_len(unsigned long wanted_len,
                                        Scsi_Cmnd *cmd, int write_flag)
 {
        unsigned long   possible_len, limit;
-#ifndef CONFIG_TT_DMA_EMUL
-       if (MACH_IS_HADES)
-               /* Hades has no SCSI DMA at all :-( Always force use of PIO */
-               return 0;
-#endif
+
        if (IS_A_TT())
                /* TT SCSI DMA can transfer arbitrary #bytes */
                return wanted_len;
index 90212ac33be3f1cc39217ef88430e986f9fe6d8a..740bad435995268112883ff77c61af58e93ce8b6 100644 (file)
@@ -82,7 +82,6 @@ typedef struct ide_scsi_obj {
        struct gendisk          *disk;
        struct Scsi_Host        *host;
 
-       struct ide_atapi_pc *pc;                /* Current packet command */
        unsigned long transform;                /* SCSI cmd translation layer */
        unsigned long log;                      /* log flags */
 } idescsi_scsi_t;
@@ -137,10 +136,10 @@ static void ide_scsi_hex_dump(u8 *data, int len)
 
 static int idescsi_end_request(ide_drive_t *, int, int);
 
-static void ide_scsi_callback(ide_drive_t *drive)
+static void ide_scsi_callback(ide_drive_t *drive, int dsc)
 {
        idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       struct ide_atapi_pc *pc = scsi->pc;
+       struct ide_atapi_pc *pc = drive->pc;
 
        if (pc->flags & PC_FLAG_TIMEDOUT)
                debug_log("%s: got timed out packet %lu at %lu\n", __func__,
@@ -267,49 +266,10 @@ static int idescsi_end_request (ide_drive_t *drive, int uptodate, int nrsecs)
        spin_unlock_irqrestore(host->host_lock, flags);
        kfree(pc);
        blk_put_request(rq);
-       scsi->pc = NULL;
+       drive->pc = NULL;
        return 0;
 }
 
-static inline unsigned long get_timeout(struct ide_atapi_pc *pc)
-{
-       return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
-}
-
-static int idescsi_expiry(ide_drive_t *drive)
-{
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       struct ide_atapi_pc   *pc   = scsi->pc;
-
-       debug_log("%s called for %lu at %lu\n", __func__,
-                 pc->scsi_cmd->serial_number, jiffies);
-
-       pc->flags |= PC_FLAG_TIMEDOUT;
-
-       return 0;                                       /* we do not want the ide subsystem to retry */
-}
-
-/*
- *     Our interrupt handler.
- */
-static ide_startstop_t idescsi_pc_intr (ide_drive_t *drive)
-{
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-       struct ide_atapi_pc *pc = scsi->pc;
-
-       return ide_pc_intr(drive, pc, idescsi_pc_intr, get_timeout(pc),
-                          idescsi_expiry, NULL, NULL, NULL,
-                          ide_io_buffers);
-}
-
-static ide_startstop_t idescsi_transfer_pc(ide_drive_t *drive)
-{
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-
-       return ide_transfer_pc(drive, scsi->pc, idescsi_pc_intr,
-                              get_timeout(scsi->pc), idescsi_expiry);
-}
-
 static inline int idescsi_set_direction(struct ide_atapi_pc *pc)
 {
        switch (pc->c[0]) {
@@ -352,13 +312,10 @@ static int idescsi_map_sg(ide_drive_t *drive, struct ide_atapi_pc *pc)
 static ide_startstop_t idescsi_issue_pc(ide_drive_t *drive,
                struct ide_atapi_pc *pc)
 {
-       idescsi_scsi_t *scsi = drive_to_idescsi(drive);
-
        /* Set the current packet command */
-       scsi->pc = pc;
+       drive->pc = pc;
 
-       return ide_issue_pc(drive, pc, idescsi_transfer_pc,
-                           get_timeout(pc), idescsi_expiry);
+       return ide_issue_pc(drive, ide_scsi_get_timeout(pc), ide_scsi_expiry);
 }
 
 /*
@@ -374,7 +331,8 @@ static ide_startstop_t idescsi_do_request (ide_drive_t *drive, struct request *r
        if (blk_sense_request(rq) || blk_special_request(rq)) {
                struct ide_atapi_pc *pc = (struct ide_atapi_pc *)rq->special;
 
-               if (drive->using_dma && !idescsi_map_sg(drive, pc))
+               if ((drive->dev_flags & IDE_DFLAG_USING_DMA) &&
+                   idescsi_map_sg(drive, pc) == 0)
                        pc->flags |= PC_FLAG_DMA_OK;
 
                return idescsi_issue_pc(drive, pc);
@@ -427,14 +385,14 @@ static const struct ide_proc_devset idescsi_settings[] = {
  */
 static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi)
 {
-       if ((drive->id[ATA_ID_CONFIG] & 0x0060) == 0x20)
-               set_bit(IDE_AFLAG_DRQ_INTERRUPT, &drive->atapi_flags);
        clear_bit(IDESCSI_SG_TRANSFORM, &scsi->transform);
 #if IDESCSI_DEBUG_LOG
        set_bit(IDESCSI_LOG_CMD, &scsi->log);
 #endif /* IDESCSI_DEBUG_LOG */
 
-       drive->pc_callback = ide_scsi_callback;
+       drive->pc_callback       = ide_scsi_callback;
+       drive->pc_update_buffers = NULL;
+       drive->pc_io_buffers     = ide_io_buffers;
 
        ide_proc_register_driver(drive, scsi->driver);
 }
@@ -456,7 +414,7 @@ static void ide_scsi_remove(ide_drive_t *drive)
 
        ide_scsi_put(scsi);
 
-       drive->scsi = 0;
+       drive->dev_flags &= ~IDE_DFLAG_SCSI;
 }
 
 static int ide_scsi_probe(ide_drive_t *);
@@ -477,7 +435,6 @@ static ide_driver_t idescsi_driver = {
        .probe                  = ide_scsi_probe,
        .remove                 = ide_scsi_remove,
        .version                = IDESCSI_VERSION,
-       .media                  = ide_scsi,
        .do_request             = idescsi_do_request,
        .end_request            = idescsi_end_request,
        .error                  = idescsi_atapi_error,
@@ -622,6 +579,8 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
        int             busy;
        int             ret   = FAILED;
 
+       struct ide_atapi_pc *pc;
+
        /* In idescsi_eh_abort we try to gently pry our command from the ide subsystem */
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -642,26 +601,27 @@ static int idescsi_eh_abort (struct scsi_cmnd *cmd)
        spin_lock_irq(&ide_lock);
 
        /* If there is no pc running we're done (our interrupt took care of it) */
-       if (!scsi->pc) {
+       pc = drive->pc;
+       if (pc == NULL) {
                ret = SUCCESS;
                goto ide_unlock;
        }
 
        /* It's somewhere in flight. Does ide subsystem agree? */
-       if (scsi->pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
-           elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != scsi->pc->rq) {
+       if (pc->scsi_cmd->serial_number == cmd->serial_number && !busy &&
+           elv_queue_empty(drive->queue) && HWGROUP(drive)->rq != pc->rq) {
                /*
                 * FIXME - not sure this condition can ever occur
                 */
                printk (KERN_ERR "ide-scsi: cmd aborted!\n");
 
-               if (blk_sense_request(scsi->pc->rq))
-                       kfree(scsi->pc->buf);
+               if (blk_sense_request(pc->rq))
+                       kfree(pc->buf);
                /* we need to call blk_put_request twice. */
-               blk_put_request(scsi->pc->rq);
-               blk_put_request(scsi->pc->rq);
-               kfree(scsi->pc);
-               scsi->pc = NULL;
+               blk_put_request(pc->rq);
+               blk_put_request(pc->rq);
+               kfree(pc);
+               drive->pc = NULL;
 
                ret = SUCCESS;
        }
@@ -683,6 +643,8 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        int             ready = 0;
        int             ret   = SUCCESS;
 
+       struct ide_atapi_pc *pc;
+
        /* In idescsi_eh_reset we forcefully remove the command from the ide subsystem and reset the device. */
 
        if (test_bit(IDESCSI_LOG_CMD, &scsi->log))
@@ -697,7 +659,9 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        spin_lock_irq(cmd->device->host->host_lock);
        spin_lock(&ide_lock);
 
-       if (!scsi->pc || (req = scsi->pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) {
+       pc = drive->pc;
+
+       if (pc == NULL || (req = pc->rq) != HWGROUP(drive)->rq || !HWGROUP(drive)->handler) {
                printk (KERN_WARNING "ide-scsi: No active request in idescsi_eh_reset\n");
                spin_unlock(&ide_lock);
                spin_unlock_irq(cmd->device->host->host_lock);
@@ -708,9 +672,9 @@ static int idescsi_eh_reset (struct scsi_cmnd *cmd)
        if (__blk_end_request(req, -EIO, 0))
                BUG();
        if (blk_sense_request(req))
-               kfree(scsi->pc->buf);
-       kfree(scsi->pc);
-       scsi->pc = NULL;
+               kfree(pc->buf);
+       kfree(pc);
+       drive->pc = NULL;
        blk_put_request(req);
 
        /* now nuke the drive queue */
@@ -801,7 +765,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
            !(host = scsi_host_alloc(&idescsi_template,sizeof(idescsi_scsi_t))))
                return -ENODEV;
 
-       drive->scsi = 1;
+       drive->dev_flags |= IDE_DFLAG_SCSI;
 
        g = alloc_disk(1 << PARTN_BITS);
        if (!g)
@@ -842,7 +806,7 @@ static int ide_scsi_probe(ide_drive_t *drive)
 
        put_disk(g);
 out_host_put:
-       drive->scsi = 0;
+       drive->dev_flags &= ~IDE_DFLAG_SCSI;
        scsi_host_put(host);
        return err;
 }
index 2dd0dc9a9aedbed19fbf4169394b5a73ed376e7c..165ff884f48edeb6278dff3939695ab1ee83d361 100644 (file)
@@ -140,44 +140,41 @@ static void aha152x_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int aha152x_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cfg,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       /* For New Media T&J, look for a SCSI window */
+       if (cfg->io.win[0].len >= 0x20)
+               p_dev->io.BasePort1 = cfg->io.win[0].base;
+       else if ((cfg->io.nwin > 1) &&
+                (cfg->io.win[1].len >= 0x20))
+               p_dev->io.BasePort1 = cfg->io.win[1].base;
+       if ((cfg->io.nwin > 0) &&
+           (p_dev->io.BasePort1 < 0xffff)) {
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -EINVAL;
+}
+
 static int aha152x_config_cs(struct pcmcia_device *link)
 {
     scsi_info_t *info = link->priv;
     struct aha152x_setup s;
-    tuple_t tuple;
-    cisparse_t parse;
-    int i, last_ret, last_fn;
-    u_char tuple_data[64];
+    int last_ret, last_fn;
     struct Scsi_Host *host;
-    
+
     DEBUG(0, "aha152x_config(0x%p)\n", link);
 
-    tuple.TupleData = tuple_data;
-    tuple.TupleDataMax = 64;
-    tuple.TupleOffset = 0;
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    tuple.Attributes = 0;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (1) {
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-           goto next_entry;
-       /* For New Media T&J, look for a SCSI window */
-       if (parse.cftable_entry.io.win[0].len >= 0x20)
-           link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-       else if ((parse.cftable_entry.io.nwin > 1) &&
-                (parse.cftable_entry.io.win[1].len >= 0x20))
-           link->io.BasePort1 = parse.cftable_entry.io.win[1].base;
-       if ((parse.cftable_entry.io.nwin > 0) &&
-           (link->io.BasePort1 < 0xffff)) {
-           link->conf.ConfigIndex = parse.cftable_entry.index;
-           i = pcmcia_request_io(link, &link->io);
-           if (i == CS_SUCCESS) break;
-       }
-    next_entry:
-       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+    last_ret = pcmcia_loop_config(link, aha152x_config_check, NULL);
+    if (last_ret) {
+       cs_error(link, RequestIO, last_ret);
+       goto failed;
     }
-    
+
     CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
     CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
     
@@ -208,6 +205,7 @@ static int aha152x_config_cs(struct pcmcia_device *link)
 
 cs_failed:
     cs_error(link, last_fn, last_ret);
+failed:
     aha152x_release_cs(link);
     return -ENODEV;
 }
index d8b99351b053b256e3ad0bd4af7854ef5f77ba65..06254f46a0ddda146322e0b106faa13b90bb9882 100644 (file)
@@ -123,34 +123,30 @@ static void fdomain_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int fdomain_config_check(struct pcmcia_device *p_dev,
+                               cistpl_cftable_entry_t *cfg,
+                               cistpl_cftable_entry_t *dflt,
+                               unsigned int vcc,
+                               void *priv_data)
+{
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
+
 static int fdomain_config(struct pcmcia_device *link)
 {
     scsi_info_t *info = link->priv;
-    tuple_t tuple;
-    cisparse_t parse;
-    int i, last_ret, last_fn;
-    u_char tuple_data[64];
+    int last_ret, last_fn;
     char str[22];
     struct Scsi_Host *host;
 
     DEBUG(0, "fdomain_config(0x%p)\n", link);
 
-    tuple.TupleData = tuple_data;
-    tuple.TupleDataMax = 64;
-    tuple.TupleOffset = 0;
-
-    tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-    CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-    while (1) {
-       if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-           goto next_entry;
-       link->conf.ConfigIndex = parse.cftable_entry.index;
-       link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-       i = pcmcia_request_io(link, &link->io);
-       if (i == CS_SUCCESS) break;
-    next_entry:
-       CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+    last_ret = pcmcia_loop_config(link, fdomain_config_check, NULL);
+    if (last_ret) {
+           cs_error(link, RequestIO, last_ret);
+           goto failed;
     }
 
     CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -181,6 +177,7 @@ static int fdomain_config(struct pcmcia_device *link)
 
 cs_failed:
     cs_error(link, last_fn, last_ret);
+failed:
     fdomain_release(link);
     return -ENODEV;
 } /* fdomain_config */
index 24e6cb8396e35e9bcebe890e9352f1cddc613c80..11a61ea8d5d917d8d6e8478313885ee99cb20ad8 100644 (file)
@@ -1606,133 +1606,129 @@ static void nsp_cs_detach(struct pcmcia_device *link)
     is received, to configure the PCMCIA socket, and to make the
     ethernet device available to the system.
 ======================================================================*/
-#define CS_CHECK(fn, ret) \
-do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
-/*====================================================================*/
-static int nsp_cs_config(struct pcmcia_device *link)
-{
-       int               ret;
-       scsi_info_t      *info   = link->priv;
-       tuple_t           tuple;
-       cisparse_t        parse;
-       int               last_ret, last_fn;
-       unsigned char     tuple_data[64];
-       config_info_t     conf;
-       win_req_t         req;
-       memreq_t          map;
-       cistpl_cftable_entry_t dflt = { 0 };
-       struct Scsi_Host *host;
-       nsp_hw_data      *data = &nsp_data_base;
-
-       nsp_dbg(NSP_DEBUG_INIT, "in");
-
-       tuple.Attributes      = 0;
-       tuple.TupleData       = tuple_data;
-       tuple.TupleDataMax    = sizeof(tuple_data);
-       tuple.TupleOffset     = 0;
-
-       /* Look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo, pcmcia_get_configuration_info(link, &conf));
 
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t *cfg = &(parse.cftable_entry);
+struct nsp_cs_configdata {
+       nsp_hw_data             *data;
+       win_req_t               req;
+};
 
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
+static int nsp_cs_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cfg,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
+{
+       struct nsp_cs_configdata *cfg_mem = priv_data;
 
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT) { dflt = *cfg; }
-               if (cfg->index == 0) { goto next_entry; }
-               link->conf.ConfigIndex = cfg->index;
+       if (cfg->index == 0)
+               return -ENODEV;
 
-               /* Does this card need audio output? */
-               if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
-                       link->conf.Attributes |= CONF_ENABLE_SPKR;
-                       link->conf.Status = CCSR_AUDIO_ENA;
-               }
+       /* Does this card need audio output? */
+       if (cfg->flags & CISTPL_CFTABLE_AUDIO) {
+               p_dev->conf.Attributes |= CONF_ENABLE_SPKR;
+               p_dev->conf.Status = CCSR_AUDIO_ENA;
+       }
 
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000) {
-                               goto next_entry;
-                       }
-               } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
-                       if (conf.Vcc != dflt.vcc.param[CISTPL_POWER_VNOM]/10000) {
-                               goto next_entry;
-                       }
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
+               if (vcc != cfg->vcc.param[CISTPL_POWER_VNOM]/10000)
+                       return -ENODEV;
+               else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
+                       if (vcc != dflt->vcc.param[CISTPL_POWER_VNOM]/10000)
+                               return -ENODEV;
                }
 
                if (cfg->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
-                       link->conf.Vpp =
+                       p_dev->conf.Vpp =
                                cfg->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-               } else if (dflt.vpp1.present & (1 << CISTPL_POWER_VNOM)) {
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM] / 10000;
+               } else if (dflt->vpp1.present & (1 << CISTPL_POWER_VNOM)) {
+                       p_dev->conf.Vpp =
+                               dflt->vpp1.param[CISTPL_POWER_VNOM] / 10000;
                }
 
                /* Do we need to allocate an interrupt? */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1) {
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-               }
+               if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+                       p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
 
                /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
+               p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+               if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+                       p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_AUTO;
                        if (!(io->flags & CISTPL_IO_8BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
+                               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_16;
                        if (!(io->flags & CISTPL_IO_16BIT))
-                               link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
+                               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+                       p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+                       p_dev->io.BasePort1 = io->win[0].base;
+                       p_dev->io.NumPorts1 = io->win[0].len;
                        if (io->nwin > 1) {
-                               link->io.Attributes2 = link->io.Attributes1;
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
+                               p_dev->io.Attributes2 = p_dev->io.Attributes1;
+                               p_dev->io.BasePort2 = io->win[1].base;
+                               p_dev->io.NumPorts2 = io->win[1].len;
                        }
                        /* This reserves IO space but doesn't actually enable it */
-                       if (pcmcia_request_io(link, &link->io) != 0)
+                       if (pcmcia_request_io(p_dev, &p_dev->io) != 0)
                                goto next_entry;
                }
 
-               if ((cfg->mem.nwin > 0) || (dflt.mem.nwin > 0)) {
-                       cistpl_mem_t *mem =
-                               (cfg->mem.nwin) ? &cfg->mem : &dflt.mem;
-                       req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
-                       req.Attributes |= WIN_ENABLE;
-                       req.Base = mem->win[0].host_addr;
-                       req.Size = mem->win[0].len;
-                       if (req.Size < 0x1000) {
-                               req.Size = 0x1000;
-                       }
-                       req.AccessSpeed = 0;
-                       if (pcmcia_request_window(&link, &req, &link->win) != 0)
+               if ((cfg->mem.nwin > 0) || (dflt->mem.nwin > 0)) {
+                       memreq_t        map;
+                       cistpl_mem_t    *mem =
+                               (cfg->mem.nwin) ? &cfg->mem : &dflt->mem;
+                       cfg_mem->req.Attributes = WIN_DATA_WIDTH_16|WIN_MEMORY_TYPE_CM;
+                       cfg_mem->req.Attributes |= WIN_ENABLE;
+                       cfg_mem->req.Base = mem->win[0].host_addr;
+                       cfg_mem->req.Size = mem->win[0].len;
+                       if (cfg_mem->req.Size < 0x1000)
+                               cfg_mem->req.Size = 0x1000;
+                       cfg_mem->req.AccessSpeed = 0;
+                       if (pcmcia_request_window(&p_dev, &cfg_mem->req, &p_dev->win) != 0)
                                goto next_entry;
                        map.Page = 0; map.CardOffset = mem->win[0].card_addr;
-                       if (pcmcia_map_mem_page(link->win, &map) != 0)
+                       if (pcmcia_map_mem_page(p_dev->win, &map) != 0)
                                goto next_entry;
 
-                       data->MmioAddress = (unsigned long)ioremap_nocache(req.Base, req.Size);
-                       data->MmioLength  = req.Size;
+                       cfg_mem->data->MmioAddress = (unsigned long) ioremap_nocache(cfg_mem->req.Base, cfg_mem->req.Size);
+                       cfg_mem->data->MmioLength  = cfg_mem->req.Size;
                }
                /* If we got this far, we're cool! */
-               break;
-
-       next_entry:
-               nsp_dbg(NSP_DEBUG_INIT, "next");
-               pcmcia_disable_device(link);
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+               return 0;
        }
 
+next_entry:
+       nsp_dbg(NSP_DEBUG_INIT, "next");
+       pcmcia_disable_device(p_dev);
+       return -ENODEV;
+}
+
+static int nsp_cs_config(struct pcmcia_device *link)
+{
+       int               ret;
+       scsi_info_t      *info   = link->priv;
+       struct nsp_cs_configdata *cfg_mem;
+       struct Scsi_Host *host;
+       nsp_hw_data      *data = &nsp_data_base;
+
+       nsp_dbg(NSP_DEBUG_INIT, "in");
+
+       cfg_mem = kzalloc(sizeof(cfg_mem), GFP_KERNEL);
+       if (!cfg_mem)
+               return -ENOMEM;
+       cfg_mem->data = data;
+
+       ret = pcmcia_loop_config(link, nsp_cs_config_check, cfg_mem);
+               goto cs_failed;
+
        if (link->conf.Attributes & CONF_ENABLE_IRQ) {
-               CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
+               if (pcmcia_request_irq(link, &link->irq))
+                       goto cs_failed;
        }
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+
+       ret = pcmcia_request_configuration(link, &link->conf);
+       if (ret)
+               goto cs_failed;
 
        if (free_ports) {
                if (link->io.BasePort1) {
@@ -1790,20 +1786,20 @@ static int nsp_cs_config(struct pcmcia_device *link)
                printk(" & 0x%04x-0x%04x", link->io.BasePort2,
                       link->io.BasePort2+link->io.NumPorts2-1);
        if (link->win)
-               printk(", mem 0x%06lx-0x%06lx", req.Base,
-                      req.Base+req.Size-1);
+               printk(", mem 0x%06lx-0x%06lx", cfg_mem->req.Base,
+                      cfg_mem->req.Base+cfg_mem->req.Size-1);
        printk("\n");
 
+       kfree(cfg_mem);
        return 0;
 
  cs_failed:
        nsp_dbg(NSP_DEBUG_INIT, "config fail");
-       cs_error(link, last_fn, last_ret);
        nsp_cs_release(link);
+       kfree(cfg_mem);
 
        return -ENODEV;
 } /* nsp_cs_config */
-#undef CS_CHECK
 
 
 /*======================================================================
index 67c5a58d17df7fb11eca2c8e427a61719d57c086..20c3e5e6d88ad369fedf8f059bb6e7c597ecc826 100644 (file)
@@ -195,39 +195,33 @@ static void qlogic_detach(struct pcmcia_device *link)
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int qlogic_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cfg,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
+{
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       p_dev->io.NumPorts1 = cfg->io.win[0].len;
+
+       if (p_dev->io.BasePort1 == 0)
+               return -ENODEV;
+
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int qlogic_config(struct pcmcia_device * link)
 {
        scsi_info_t *info = link->priv;
-       tuple_t tuple;
-       cisparse_t parse;
-       int i, last_ret, last_fn;
-       unsigned short tuple_data[32];
+       int last_ret, last_fn;
        struct Scsi_Host *host;
 
        DEBUG(0, "qlogic_config(0x%p)\n", link);
 
-       info->manf_id = link->manf_id;
-
-       tuple.TupleData = (cisdata_t *) tuple_data;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = parse.cftable_entry.index;
-               link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-               link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
-               if (link->io.BasePort1 != 0) {
-                       i = pcmcia_request_io(link, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-             next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+       last_ret = pcmcia_loop_config(link, qlogic_config_check, NULL);
+       if (last_ret) {
+               cs_error(link, RequestIO, last_ret);
+               goto failed;
        }
 
        CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -262,6 +256,7 @@ static int qlogic_config(struct pcmcia_device * link)
 cs_failed:
        cs_error(link, last_fn, last_ret);
        pcmcia_disable_device(link);
+failed:
        return -ENODEV;
 
 }                              /* qlogic_config */
index 0be232b58ffb795e5d878f3aa400eee8dab5b673..b330c11a1752378e95dd831dc053646a63d3171a 100644 (file)
@@ -700,15 +700,27 @@ static struct scsi_host_template sym53c500_driver_template = {
 #define CS_CHECK(fn, ret) \
 do { last_fn = (fn); if ((last_ret = (ret)) != 0) goto cs_failed; } while (0)
 
+static int SYM53C500_config_check(struct pcmcia_device *p_dev,
+                                 cistpl_cftable_entry_t *cfg,
+                                 cistpl_cftable_entry_t *dflt,
+                                 unsigned int vcc,
+                                 void *priv_data)
+{
+       p_dev->io.BasePort1 = cfg->io.win[0].base;
+       p_dev->io.NumPorts1 = cfg->io.win[0].len;
+
+       if (p_dev->io.BasePort1 == 0)
+               return -ENODEV;
+
+       return pcmcia_request_io(p_dev, &p_dev->io);
+}
+
 static int
 SYM53C500_config(struct pcmcia_device *link)
 {
        struct scsi_info_t *info = link->priv;
-       tuple_t tuple;
-       cisparse_t parse;
-       int i, last_ret, last_fn;
+       int last_ret, last_fn;
        int irq_level, port_base;
-       unsigned short tuple_data[32];
        struct Scsi_Host *host;
        struct scsi_host_template *tpnt = &sym53c500_driver_template;
        struct sym53c500_data *data;
@@ -717,27 +729,10 @@ SYM53C500_config(struct pcmcia_device *link)
 
        info->manf_id = link->manf_id;
 
-       tuple.TupleData = (cisdata_t *)tuple_data;
-       tuple.TupleDataMax = 64;
-       tuple.TupleOffset = 0;
-
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                   pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-               link->conf.ConfigIndex = parse.cftable_entry.index;
-               link->io.BasePort1 = parse.cftable_entry.io.win[0].base;
-               link->io.NumPorts1 = parse.cftable_entry.io.win[0].len;
-
-               if (link->io.BasePort1 != 0) {
-                       i = pcmcia_request_io(link, &link->io);
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-next_entry:
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
+       last_ret = pcmcia_loop_config(link, SYM53C500_config_check, NULL);
+       if (last_ret) {
+               cs_error(link, RequestIO, last_ret);
+               goto failed;
        }
 
        CS_CHECK(RequestIRQ, pcmcia_request_irq(link, &link->irq));
@@ -831,6 +826,7 @@ err_release:
 
 cs_failed:
        cs_error(link, last_fn, last_ret);
+failed:
        SYM53C500_release(link);
        return -ENODEV;
 } /* SYM53C500_config */
index d4104a3bbe87cd7400a68f083369c41da3396d5b..d3ca7d32abe0ef654f46f9bfd8b6cd00ad977557 100644 (file)
@@ -2969,6 +2969,9 @@ static int __init serial8250_init(void)
                "%d ports, IRQ sharing %sabled\n", nr_uarts,
                share_irqs ? "en" : "dis");
 
+       for (i = 0; i < NR_IRQS; i++)
+               spin_lock_init(&irq_lists[i].lock);
+
 #ifdef CONFIG_SPARC
        ret = sunserial_register_minors(&serial8250_reg, UART_NR);
 #else
index 164d2a42eb59fe5a5a58e9ea26d13830d493a28c..7546aa887fa7565417fe3a9f14956f5e9e314e40 100644 (file)
@@ -431,131 +431,103 @@ first_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
 {
        int i;
        i = pcmcia_get_first_tuple(handle, tuple);
-       if (i != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
-       i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
+       if (i != 0)
                return i;
-       return pcmcia_parse_tuple(handle, tuple, parse);
-}
-
-static int
-next_tuple(struct pcmcia_device *handle, tuple_t * tuple, cisparse_t * parse)
-{
-       int i;
-       i = pcmcia_get_next_tuple(handle, tuple);
-       if (i != CS_SUCCESS)
-               return CS_NO_MORE_ITEMS;
        i = pcmcia_get_tuple_data(handle, tuple);
-       if (i != CS_SUCCESS)
+       if (i != 0)
                return i;
-       return pcmcia_parse_tuple(handle, tuple, parse);
+       return pcmcia_parse_tuple(tuple, parse);
 }
 
 /*====================================================================*/
 
-static int simple_config(struct pcmcia_device *link)
+static int simple_config_check(struct pcmcia_device *p_dev,
+                              cistpl_cftable_entry_t *cf,
+                              cistpl_cftable_entry_t *dflt,
+                              unsigned int vcc,
+                              void *priv_data)
 {
-       static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
        static const int size_table[2] = { 8, 16 };
-       struct serial_info *info = link->priv;
-       struct serial_cfg_mem *cfg_mem;
-       tuple_t *tuple;
-       u_char *buf;
-       cisparse_t *parse;
-       cistpl_cftable_entry_t *cf;
-       config_info_t config;
-       int i, j, try;
-       int s;
+       int *try = priv_data;
+
+       if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
+
+       if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[(*try >> 1)])
+           && (cf->io.win[0].base != 0)) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.IOAddrLines = ((*try & 0x1) == 0) ?
+                       16 : cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -EINVAL;
+}
 
-       cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL);
-       if (!cfg_mem)
-               return -1;
+static int simple_config_check_notpicky(struct pcmcia_device *p_dev,
+                                       cistpl_cftable_entry_t *cf,
+                                       cistpl_cftable_entry_t *dflt,
+                                       unsigned int vcc,
+                                       void *priv_data)
+{
+       static const unsigned int base[5] = { 0x3f8, 0x2f8, 0x3e8, 0x2e8, 0x0 };
+       int j;
+
+       if ((cf->io.nwin > 0) && ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
+               for (j = 0; j < 5; j++) {
+                       p_dev->io.BasePort1 = base[j];
+                       p_dev->io.IOAddrLines = base[j] ? 16 : 3;
+                       if (!pcmcia_request_io(p_dev, &p_dev->io))
+                               return 0;
+               }
+       }
+       return -ENODEV;
+}
 
-       tuple = &cfg_mem->tuple;
-       parse = &cfg_mem->parse;
-       cf = &parse->cftable_entry;
-       buf = cfg_mem->buf;
+static int simple_config(struct pcmcia_device *link)
+{
+       struct serial_info *info = link->priv;
+       int i = -ENODEV, try;
 
        /* If the card is already configured, look up the port and irq */
-       i = pcmcia_get_configuration_info(link, &config);
-       if ((i == CS_SUCCESS) && (config.Attributes & CONF_VALID_CLIENT)) {
+       if (link->function_config) {
                unsigned int port = 0;
-               if ((config.BasePort2 != 0) && (config.NumPorts2 == 8)) {
-                       port = config.BasePort2;
+               if ((link->io.BasePort2 != 0) &&
+                   (link->io.NumPorts2 == 8)) {
+                       port = link->io.BasePort2;
                        info->slave = 1;
                } else if ((info->manfid == MANFID_OSITECH) &&
-                          (config.NumPorts1 == 0x40)) {
-                       port = config.BasePort1 + 0x28;
+                          (link->io.NumPorts1 == 0x40)) {
+                       port = link->io.BasePort1 + 0x28;
                        info->slave = 1;
                }
                if (info->slave) {
-                       kfree(cfg_mem);
-                       return setup_serial(link, info, port, config.AssignedIRQ);
+                       return setup_serial(link, info, port,
+                                           link->irq.AssignedIRQ);
                }
        }
 
-       /* First pass: look for a config entry that looks normal. */
-       tuple->TupleData = (cisdata_t *) buf;
-       tuple->TupleOffset = 0;
-       tuple->TupleDataMax = 255;
-       tuple->Attributes = 0;
-       tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       /* Two tries: without IO aliases, then with aliases */
-       for (s = 0; s < 2; s++) {
-               for (try = 0; try < 2; try++) {
-                       i = first_tuple(link, tuple, parse);
-                       while (i != CS_NO_MORE_ITEMS) {
-                               if (i != CS_SUCCESS)
-                                       goto next_entry;
-                               if (cf->vpp1.present & (1 << CISTPL_POWER_VNOM))
-                                       link->conf.Vpp =
-                                           cf->vpp1.param[CISTPL_POWER_VNOM] / 10000;
-                               if ((cf->io.nwin > 0) && (cf->io.win[0].len == size_table[s]) &&
-                                           (cf->io.win[0].base != 0)) {
-                                       link->conf.ConfigIndex = cf->index;
-                                       link->io.BasePort1 = cf->io.win[0].base;
-                                       link->io.IOAddrLines = (try == 0) ?
-                                           16 : cf->io.flags & CISTPL_IO_LINES_MASK;
-                                       i = pcmcia_request_io(link, &link->io);
-                                       if (i == CS_SUCCESS)
-                                               goto found_port;
-                               }
-next_entry:
-                               i = next_tuple(link, tuple, parse);
-                       }
-               }
-       }
+       /* First pass: look for a config entry that looks normal.
+        * Two tries: without IO aliases, then with aliases */
+       for (try = 0; try < 4; try++)
+               if (!pcmcia_loop_config(link, simple_config_check, &try))
+                       goto found_port;
+
        /* Second pass: try to find an entry that isn't picky about
           its base address, then try to grab any standard serial port
           address, and finally try to get any free port. */
-       i = first_tuple(link, tuple, parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               if ((i == CS_SUCCESS) && (cf->io.nwin > 0) &&
-                   ((cf->io.flags & CISTPL_IO_LINES_MASK) <= 3)) {
-                       link->conf.ConfigIndex = cf->index;
-                       for (j = 0; j < 5; j++) {
-                               link->io.BasePort1 = base[j];
-                               link->io.IOAddrLines = base[j] ? 16 : 3;
-                               i = pcmcia_request_io(link, &link->io);
-                               if (i == CS_SUCCESS)
-                                       goto found_port;
-                       }
-               }
-               i = next_tuple(link, tuple, parse);
-       }
+       if (!pcmcia_loop_config(link, simple_config_check_notpicky, NULL))
+               goto found_port;
 
-      found_port:
-       if (i != CS_SUCCESS) {
-               printk(KERN_NOTICE
-                      "serial_cs: no usable port range found, giving up\n");
-               cs_error(link, RequestIO, i);
-               kfree(cfg_mem);
-               return -1;
-       }
+       printk(KERN_NOTICE
+              "serial_cs: no usable port range found, giving up\n");
+       cs_error(link, RequestIO, i);
+       return -1;
 
+found_port:
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestIRQ, i);
                link->irq.AssignedIRQ = 0;
        }
@@ -569,88 +541,76 @@ next_entry:
                info->quirk->config(link);
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
-               kfree(cfg_mem);
                return -1;
        }
-       kfree(cfg_mem);
        return setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
 }
 
-static int multi_config(struct pcmcia_device * link)
+static int multi_config_check(struct pcmcia_device *p_dev,
+                             cistpl_cftable_entry_t *cf,
+                             cistpl_cftable_entry_t *dflt,
+                             unsigned int vcc,
+                             void *priv_data)
 {
-       struct serial_info *info = link->priv;
-       struct serial_cfg_mem *cfg_mem;
-       tuple_t *tuple;
-       u_char *buf;
-       cisparse_t *parse;
-       cistpl_cftable_entry_t *cf;
-       int i, rc, base2 = 0;
+       int *base2 = priv_data;
+
+       /* The quad port cards have bad CIS's, so just look for a
+          window larger than 8 ports and assume it will be right */
+       if ((cf->io.nwin == 1) && (cf->io.win[0].len > 8)) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io)) {
+                       *base2 = p_dev->io.BasePort1 + 8;
+                       return 0;
+               }
+       }
+       return -ENODEV;
+}
 
-       cfg_mem = kmalloc(sizeof(struct serial_cfg_mem), GFP_KERNEL);
-       if (!cfg_mem)
-               return -1;
-       tuple = &cfg_mem->tuple;
-       parse = &cfg_mem->parse;
-       cf = &parse->cftable_entry;
-       buf = cfg_mem->buf;
+static int multi_config_check_notpicky(struct pcmcia_device *p_dev,
+                                      cistpl_cftable_entry_t *cf,
+                                      cistpl_cftable_entry_t *dflt,
+                                      unsigned int vcc,
+                                      void *priv_data)
+{
+       int *base2 = priv_data;
+
+       if (cf->io.nwin == 2) {
+               p_dev->io.BasePort1 = cf->io.win[0].base;
+               p_dev->io.BasePort2 = cf->io.win[1].base;
+               p_dev->io.IOAddrLines = cf->io.flags & CISTPL_IO_LINES_MASK;
+               if (!pcmcia_request_io(p_dev, &p_dev->io)) {
+                       *base2 = p_dev->io.BasePort2;
+                       return 0;
+               }
+       }
+       return -ENODEV;
+}
 
-       tuple->TupleData = (cisdata_t *) buf;
-       tuple->TupleOffset = 0;
-       tuple->TupleDataMax = 255;
-       tuple->Attributes = 0;
-       tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
+static int multi_config(struct pcmcia_device *link)
+{
+       struct serial_info *info = link->priv;
+       int i, base2 = 0;
 
        /* First, look for a generic full-sized window */
        link->io.NumPorts1 = info->multi * 8;
-       i = first_tuple(link, tuple, parse);
-       while (i != CS_NO_MORE_ITEMS) {
-               /* The quad port cards have bad CIS's, so just look for a
-                  window larger than 8 ports and assume it will be right */
-               if ((i == CS_SUCCESS) && (cf->io.nwin == 1) &&
-                   (cf->io.win[0].len > 8)) {
-                       link->conf.ConfigIndex = cf->index;
-                       link->io.BasePort1 = cf->io.win[0].base;
-                       link->io.IOAddrLines =
-                           cf->io.flags & CISTPL_IO_LINES_MASK;
-                       i = pcmcia_request_io(link, &link->io);
-                       base2 = link->io.BasePort1 + 8;
-                       if (i == CS_SUCCESS)
-                               break;
-               }
-               i = next_tuple(link, tuple, parse);
-       }
-
-       /* If that didn't work, look for two windows */
-       if (i != CS_SUCCESS) {
+       if (pcmcia_loop_config(link, multi_config_check, &base2)) {
+               /* If that didn't work, look for two windows */
                link->io.NumPorts1 = link->io.NumPorts2 = 8;
                info->multi = 2;
-               i = first_tuple(link, tuple, parse);
-               while (i != CS_NO_MORE_ITEMS) {
-                       if ((i == CS_SUCCESS) && (cf->io.nwin == 2)) {
-                               link->conf.ConfigIndex = cf->index;
-                               link->io.BasePort1 = cf->io.win[0].base;
-                               link->io.BasePort2 = cf->io.win[1].base;
-                               link->io.IOAddrLines =
-                                   cf->io.flags & CISTPL_IO_LINES_MASK;
-                               i = pcmcia_request_io(link, &link->io);
-                               base2 = link->io.BasePort2;
-                               if (i == CS_SUCCESS)
-                                       break;
-                       }
-                       i = next_tuple(link, tuple, parse);
+               if (pcmcia_loop_config(link, multi_config_check_notpicky,
+                                      &base2)) {
+                       printk(KERN_NOTICE "serial_cs: no usable port range"
+                              "found, giving up\n");
+                       return -ENODEV;
                }
        }
 
-       if (i != CS_SUCCESS) {
-               cs_error(link, RequestIO, i);
-               rc = -1;
-               goto free_cfg_mem;
-       }
-
        i = pcmcia_request_irq(link, &link->irq);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
+               /* FIXME: comment does not fit, error handling does not fit */
                printk(KERN_NOTICE
                       "serial_cs: no usable port range found, giving up\n");
                cs_error(link, RequestIRQ, i);
@@ -664,10 +624,9 @@ static int multi_config(struct pcmcia_device * link)
                info->quirk->config(link);
 
        i = pcmcia_request_configuration(link, &link->conf);
-       if (i != CS_SUCCESS) {
+       if (i != 0) {
                cs_error(link, RequestConfiguration, i);
-               rc = -1;
-               goto free_cfg_mem;
+               return -ENODEV;
        }
 
        /* The Oxford Semiconductor OXCF950 cards are in fact single-port:
@@ -678,7 +637,8 @@ static int multi_config(struct pcmcia_device * link)
                                info->prodid == PRODID_POSSIO_GCC)) {
                int err;
 
-               if (cf->index == 1 || cf->index == 3) {
+               if (link->conf.ConfigIndex == 1 ||
+                   link->conf.ConfigIndex == 3) {
                        err = setup_serial(link, info, base2,
                                        link->irq.AssignedIRQ);
                        base2 = link->io.BasePort1;
@@ -695,18 +655,14 @@ static int multi_config(struct pcmcia_device * link)
                if (info->quirk && info->quirk->wakeup)
                        info->quirk->wakeup(link);
 
-               rc = 0;
-               goto free_cfg_mem;
+               return 0;
        }
 
        setup_serial(link, info, link->io.BasePort1, link->irq.AssignedIRQ);
        for (i = 0; i < info->multi - 1; i++)
                setup_serial(link, info, base2 + (8 * i),
                                link->irq.AssignedIRQ);
-       rc = 0;
-free_cfg_mem:
-       kfree(cfg_mem);
-       return rc;
+       return 0;
 }
 
 /*======================================================================
@@ -746,7 +702,7 @@ static int serial_config(struct pcmcia_device * link)
        /* Is this a compliant multifunction card? */
        tuple->DesiredTuple = CISTPL_LONGLINK_MFC;
        tuple->Attributes = TUPLE_RETURN_COMMON | TUPLE_RETURN_LINK;
-       info->multi = (first_tuple(link, tuple, parse) == CS_SUCCESS);
+       info->multi = (first_tuple(link, tuple, parse) == 0);
 
        /* Is this a multiport card? */
        tuple->DesiredTuple = CISTPL_MANFID;
@@ -770,7 +726,7 @@ static int serial_config(struct pcmcia_device * link)
            ((link->func_id == CISTPL_FUNCID_MULTI) ||
             (link->func_id == CISTPL_FUNCID_SERIAL))) {
                tuple->DesiredTuple = CISTPL_CFTABLE_ENTRY;
-               if (first_tuple(link, tuple, parse) == CS_SUCCESS) {
+               if (first_tuple(link, tuple, parse) == 0) {
                        if ((cf->io.nwin == 1) && (cf->io.win[0].len % 8 == 0))
                                info->multi = cf->io.win[0].len >> 3;
                        if ((cf->io.nwin == 2) && (cf->io.win[0].len == 8) &&
index 24c2a46c14760cbb879f1e367aff8774e01ac7b2..fbfadbac67e887d190ac1c93b87d957cf90146fa 100644 (file)
@@ -80,7 +80,7 @@ static int ssb_pcmcia_cfg_write(struct ssb_bus *bus, u8 offset, u8 value)
        reg.Action = CS_WRITE;
        reg.Value = value;
        res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg);
-       if (unlikely(res != CS_SUCCESS))
+       if (unlikely(res != 0))
                return -EBUSY;
 
        return 0;
@@ -96,7 +96,7 @@ static int ssb_pcmcia_cfg_read(struct ssb_bus *bus, u8 offset, u8 *value)
        reg.Offset = offset;
        reg.Action = CS_READ;
        res = pcmcia_access_configuration_register(bus->host_pcmcia, &reg);
-       if (unlikely(res != CS_SUCCESS))
+       if (unlikely(res != 0))
                return -EBUSY;
        *value = reg.Value;
 
@@ -638,17 +638,17 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple);
-       GOTO_ERROR_ON(res != CS_SUCCESS, "MAC first tpl");
+       GOTO_ERROR_ON(res != 0, "MAC first tpl");
        res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
-       GOTO_ERROR_ON(res != CS_SUCCESS, "MAC first tpl data");
+       GOTO_ERROR_ON(res != 0, "MAC first tpl data");
        while (1) {
                GOTO_ERROR_ON(tuple.TupleDataLen < 1, "MAC tpl < 1");
                if (tuple.TupleData[0] == CISTPL_FUNCE_LAN_NODE_ID)
                        break;
                res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple);
-               GOTO_ERROR_ON(res != CS_SUCCESS, "MAC next tpl");
+               GOTO_ERROR_ON(res != 0, "MAC next tpl");
                res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
-               GOTO_ERROR_ON(res != CS_SUCCESS, "MAC next tpl data");
+               GOTO_ERROR_ON(res != 0, "MAC next tpl data");
        }
        GOTO_ERROR_ON(tuple.TupleDataLen != ETH_ALEN + 2, "MAC tpl size");
        memcpy(sprom->il0mac, &tuple.TupleData[2], ETH_ALEN);
@@ -659,9 +659,9 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
        tuple.TupleData = buf;
        tuple.TupleDataMax = sizeof(buf);
        res = pcmcia_get_first_tuple(bus->host_pcmcia, &tuple);
-       GOTO_ERROR_ON(res != CS_SUCCESS, "VEN first tpl");
+       GOTO_ERROR_ON(res != 0, "VEN first tpl");
        res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
-       GOTO_ERROR_ON(res != CS_SUCCESS, "VEN first tpl data");
+       GOTO_ERROR_ON(res != 0, "VEN first tpl data");
        while (1) {
                GOTO_ERROR_ON(tuple.TupleDataLen < 1, "VEN tpl < 1");
                switch (tuple.TupleData[0]) {
@@ -733,11 +733,11 @@ int ssb_pcmcia_get_invariants(struct ssb_bus *bus,
                        break;
                }
                res = pcmcia_get_next_tuple(bus->host_pcmcia, &tuple);
-               if (res == CS_NO_MORE_ITEMS)
+               if (res == -ENOSPC)
                        break;
-               GOTO_ERROR_ON(res != CS_SUCCESS, "VEN next tpl");
+               GOTO_ERROR_ON(res != 0, "VEN next tpl");
                res = pcmcia_get_tuple_data(bus->host_pcmcia, &tuple);
-               GOTO_ERROR_ON(res != CS_SUCCESS, "VEN next tpl data");
+               GOTO_ERROR_ON(res != 0, "VEN next tpl data");
        }
 
        return 0;
index ff9a29b76336335b5ad8e3e61e3b52524c607714..347c3ed1d9f15fbe1edd10944b6b44b72ace07ac 100644 (file)
@@ -124,65 +124,53 @@ static void ixj_get_serial(struct pcmcia_device * link, IXJ * j)
        return;
 }
 
+static int ixj_config_check(struct pcmcia_device *p_dev,
+                           cistpl_cftable_entry_t *cfg,
+                           cistpl_cftable_entry_t *dflt,
+                           unsigned int vcc,
+                           void *priv_data)
+{
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+               if (io->nwin == 2) {
+                       p_dev->io.BasePort2 = io->win[1].base;
+                       p_dev->io.NumPorts2 = io->win[1].len;
+               }
+               if (!pcmcia_request_io(p_dev, &p_dev->io))
+                       return 0;
+       }
+       return -ENODEV;
+}
+
 static int ixj_config(struct pcmcia_device * link)
 {
        IXJ *j;
        ixj_info_t *info;
-       tuple_t tuple;
-       u_short buf[128];
-       cisparse_t parse;
-       cistpl_cftable_entry_t *cfg = &parse.cftable_entry;
-       cistpl_cftable_entry_t dflt =
-       {
-               0
-       };
-       int last_ret, last_fn;
+       cistpl_cftable_entry_t dflt = { 0 };
+
        info = link->priv;
        DEBUG(0, "ixj_config(0x%p)\n", link);
-       tuple.TupleData = (cisdata_t *) buf;
-       tuple.TupleOffset = 0;
-       tuple.TupleDataMax = 255;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       tuple.Attributes = 0;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               if (pcmcia_get_tuple_data(link, &tuple) != 0 ||
-                               pcmcia_parse_tuple(link, &tuple, &parse) != 0)
-                       goto next_entry;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-                       link->conf.ConfigIndex = cfg->index;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-                       if (io->nwin == 2) {
-                               link->io.BasePort2 = io->win[1].base;
-                               link->io.NumPorts2 = io->win[1].len;
-                       }
-                       if (pcmcia_request_io(link, &link->io) != 0)
-                               goto next_entry;
-                       /* If we've got this far, we're done */
-                       break;
-               }
-             next_entry:
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT)
-                       dflt = *cfg;
-               CS_CHECK(GetNextTuple, pcmcia_get_next_tuple(link, &tuple));
-       }
 
-       CS_CHECK(RequestConfiguration, pcmcia_request_configuration(link, &link->conf));
+       if (pcmcia_loop_config(link, ixj_config_check, &dflt))
+               goto cs_failed;
+
+       if (pcmcia_request_configuration(link, &link->conf))
+               goto cs_failed;
 
        /*
         *      Register the card with the core.
-        */     
-       j=ixj_pcmcia_probe(link->io.BasePort1,link->io.BasePort1 + 0x10);
+        */
+       j = ixj_pcmcia_probe(link->io.BasePort1, link->io.BasePort1 + 0x10);
 
        info->ndev = 1;
        info->node.major = PHONE_MAJOR;
        link->dev_node = &info->node;
        ixj_get_serial(link, j);
        return 0;
+
       cs_failed:
-       cs_error(link, last_fn, last_ret);
        ixj_cs_release(link);
        return -ENODEV;
 }
index 5da63f5350053eed6edff1a39824580ed25e83b1..516848dd9b48b2aed0193c77d8b0cbcbc765b7a6 100644 (file)
@@ -112,7 +112,8 @@ static struct platform_device platform_dev = {
        .num_resources          = ARRAY_SIZE(resources),
 };
 
-static int sl811_hc_init(struct device *parent, ioaddr_t base_addr, int irq)
+static int sl811_hc_init(struct device *parent, resource_size_t base_addr,
+                        int irq)
 {
        if (platform_dev.dev.parent)
                return -EBUSY;
@@ -155,97 +156,72 @@ static void sl811_cs_release(struct pcmcia_device * link)
        platform_device_unregister(&platform_dev);
 }
 
+static int sl811_cs_config_check(struct pcmcia_device *p_dev,
+                                cistpl_cftable_entry_t *cfg,
+                                cistpl_cftable_entry_t *dflt,
+                                unsigned int vcc,
+                                void *priv_data)
+{
+       if (cfg->index == 0)
+               return -ENODEV;
+
+       /* Use power settings for Vcc and Vpp if present */
+       /*  Note that the CIS values need to be rescaled */
+       if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
+               if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
+                       return -ENODEV;
+       } else if (dflt->vcc.present & (1<<CISTPL_POWER_VNOM)) {
+               if (dflt->vcc.param[CISTPL_POWER_VNOM]/10000 != vcc)
+                       return -ENODEV;
+               }
+
+       if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
+       else if (dflt->vpp1.present & (1<<CISTPL_POWER_VNOM))
+               p_dev->conf.Vpp =
+                       dflt->vpp1.param[CISTPL_POWER_VNOM]/10000;
+
+       /* we need an interrupt */
+       if (cfg->irq.IRQInfo1 || dflt->irq.IRQInfo1)
+               p_dev->conf.Attributes |= CONF_ENABLE_IRQ;
+
+       /* IO window settings */
+       p_dev->io.NumPorts1 = p_dev->io.NumPorts2 = 0;
+       if ((cfg->io.nwin > 0) || (dflt->io.nwin > 0)) {
+               cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt->io;
+
+               p_dev->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
+               p_dev->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
+               p_dev->io.BasePort1 = io->win[0].base;
+               p_dev->io.NumPorts1 = io->win[0].len;
+
+               return pcmcia_request_io(p_dev, &p_dev->io);
+       }
+       pcmcia_disable_device(p_dev);
+       return -ENODEV;
+}
+
+
 static int sl811_cs_config(struct pcmcia_device *link)
 {
        struct device           *parent = &handle_to_dev(link);
        local_info_t            *dev = link->priv;
-       tuple_t                 tuple;
-       cisparse_t              parse;
        int                     last_fn, last_ret;
-       u_char                  buf[64];
-       config_info_t           conf;
-       cistpl_cftable_entry_t  dflt = { 0 };
 
        DBG(0, "sl811_cs_config(0x%p)\n", link);
 
-       /* Look up the current Vcc */
-       CS_CHECK(GetConfigurationInfo,
-                       pcmcia_get_configuration_info(link, &conf));
-
-       tuple.Attributes = 0;
-       tuple.TupleData = buf;
-       tuple.TupleDataMax = sizeof(buf);
-       tuple.TupleOffset = 0;
-       tuple.DesiredTuple = CISTPL_CFTABLE_ENTRY;
-       CS_CHECK(GetFirstTuple, pcmcia_get_first_tuple(link, &tuple));
-       while (1) {
-               cistpl_cftable_entry_t  *cfg = &(parse.cftable_entry);
-
-               if (pcmcia_get_tuple_data(link, &tuple) != 0
-                               || pcmcia_parse_tuple(link, &tuple, &parse)
-                                               != 0)
-                       goto next_entry;
-
-               if (cfg->flags & CISTPL_CFTABLE_DEFAULT) {
-                       dflt = *cfg;
-               }
-
-               if (cfg->index == 0)
-                       goto next_entry;
-
-               link->conf.ConfigIndex = cfg->index;
-
-               /* Use power settings for Vcc and Vpp if present */
-               /*  Note that the CIS values need to be rescaled */
-               if (cfg->vcc.present & (1<<CISTPL_POWER_VNOM)) {
-                       if (cfg->vcc.param[CISTPL_POWER_VNOM]/10000
-                                       != conf.Vcc)
-                               goto next_entry;
-               } else if (dflt.vcc.present & (1<<CISTPL_POWER_VNOM)) {
-                       if (dflt.vcc.param[CISTPL_POWER_VNOM]/10000
-                                       != conf.Vcc)
-                               goto next_entry;
-               }
-
-               if (cfg->vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               cfg->vpp1.param[CISTPL_POWER_VNOM]/10000;
-               else if (dflt.vpp1.present & (1<<CISTPL_POWER_VNOM))
-                       link->conf.Vpp =
-                               dflt.vpp1.param[CISTPL_POWER_VNOM]/10000;
-
-               /* we need an interrupt */
-               if (cfg->irq.IRQInfo1 || dflt.irq.IRQInfo1)
-                       link->conf.Attributes |= CONF_ENABLE_IRQ;
-
-               /* IO window settings */
-               link->io.NumPorts1 = link->io.NumPorts2 = 0;
-               if ((cfg->io.nwin > 0) || (dflt.io.nwin > 0)) {
-                       cistpl_io_t *io = (cfg->io.nwin) ? &cfg->io : &dflt.io;
-
-                       link->io.Attributes1 = IO_DATA_PATH_WIDTH_8;
-                       link->io.IOAddrLines = io->flags & CISTPL_IO_LINES_MASK;
-                       link->io.BasePort1 = io->win[0].base;
-                       link->io.NumPorts1 = io->win[0].len;
-
-                       if (pcmcia_request_io(link, &link->io) != 0)
-                               goto next_entry;
-               }
-               break;
-
-next_entry:
-               pcmcia_disable_device(link);
-               last_ret = pcmcia_get_next_tuple(link, &tuple);
-       }
+       if (pcmcia_loop_config(link, sl811_cs_config_check, NULL))
+               goto failed;
 
        /* require an IRQ and two registers */
        if (!link->io.NumPorts1 || link->io.NumPorts1 < 2)
-               goto cs_failed;
+               goto failed;
        if (link->conf.Attributes & CONF_ENABLE_IRQ)
                CS_CHECK(RequestIRQ,
                        pcmcia_request_irq(link, &link->irq));
        else
-               goto cs_failed;
+               goto failed;
 
        CS_CHECK(RequestConfiguration,
                pcmcia_request_configuration(link, &link->conf));
@@ -266,8 +242,9 @@ next_entry:
        if (sl811_hc_init(parent, link->io.BasePort1, link->irq.AssignedIRQ)
                        < 0) {
 cs_failed:
-               printk("sl811_cs_config failed\n");
                cs_error(link, last_fn, last_ret);
+failed:
+               printk(KERN_WARNING "sl811_cs_config failed\n");
                sl811_cs_release(link);
                return  -ENODEV;
        }
index 9cbff84b787d9e4cf17d8ebd7d2dc1822d628f5f..da91bb16da8a1c530b7d4e7edccaef928876fee6 100644 (file)
@@ -1855,8 +1855,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
        struct fb_info *info = registered_fb[con2fb_map[vc->vc_num]];
        struct display *p = &fb_display[vc->vc_num];
        int scroll_partial = info->flags & FBINFO_PARTIAL_PAN_OK;
-       unsigned short saved_ec;
-       int ret;
 
        if (fbcon_is_inactive(vc, info))
                return -EINVAL;
@@ -1869,11 +1867,6 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
         *           whole screen (prevents flicker).
         */
 
-       saved_ec = vc->vc_video_erase_char;
-       vc->vc_video_erase_char = vc->vc_scrl_erase_char;
-
-       ret = 0;
-
        switch (dir) {
        case SM_UP:
                if (count > vc->vc_rows)        /* Maximum realistic size */
@@ -1890,9 +1883,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        (b - count)),
-                                   vc->vc_scrl_erase_char,
+                                   vc->vc_video_erase_char,
                                    vc->vc_size_row * count);
-                       ret = 1;
+                       return 1;
                        break;
 
                case SCROLL_WRAP_MOVE:
@@ -1962,10 +1955,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        (b - count)),
-                                   vc->vc_scrl_erase_char,
+                                   vc->vc_video_erase_char,
                                    vc->vc_size_row * count);
-                       ret = 1;
-                       break;
+                       return 1;
                }
                break;
 
@@ -1982,9 +1974,9 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        t),
-                                   vc->vc_scrl_erase_char,
+                                   vc->vc_video_erase_char,
                                    vc->vc_size_row * count);
-                       ret = 1;
+                       return 1;
                        break;
 
                case SCROLL_WRAP_MOVE:
@@ -2052,15 +2044,12 @@ static int fbcon_scroll(struct vc_data *vc, int t, int b, int dir,
                        scr_memsetw((unsigned short *) (vc->vc_origin +
                                                        vc->vc_size_row *
                                                        t),
-                                   vc->vc_scrl_erase_char,
+                                   vc->vc_video_erase_char,
                                    vc->vc_size_row * count);
-                       ret = 1;
-                       break;
+                       return 1;
                }
-               break;
        }
-       vc->vc_video_erase_char = saved_ec;
-       return ret;
+       return 0;
 }
 
 
@@ -2522,9 +2511,6 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
                        c = vc->vc_video_erase_char;
                        vc->vc_video_erase_char =
                            ((c & 0xfe00) >> 1) | (c & 0xff);
-                       c = vc->vc_scrl_erase_char;
-                       vc->vc_scrl_erase_char =
-                           ((c & 0xFE00) >> 1) | (c & 0xFF);
                        vc->vc_attr >>= 1;
                }
        } else if (!vc->vc_hi_font_mask && cnt == 512) {
@@ -2555,14 +2541,9 @@ static int fbcon_do_set_font(struct vc_data *vc, int w, int h,
                        if (vc->vc_can_do_color) {
                                vc->vc_video_erase_char =
                                    ((c & 0xff00) << 1) | (c & 0xff);
-                               c = vc->vc_scrl_erase_char;
-                               vc->vc_scrl_erase_char =
-                                   ((c & 0xFF00) << 1) | (c & 0xFF);
                                vc->vc_attr <<= 1;
-                       } else {
+                       } else
                                vc->vc_video_erase_char = c & ~0x100;
-                               vc->vc_scrl_erase_char = c & ~0x100;
-                       }
                }
 
        }
index 9901064199bd165599a163deacf45737f7d210c2..dd3eaaad44417781a6cef9a1537ca055812d3d65 100644 (file)
@@ -533,7 +533,7 @@ static void mdacon_cursor(struct vc_data *c, int mode)
 
 static int mdacon_scroll(struct vc_data *c, int t, int b, int dir, int lines)
 {
-       u16 eattr = mda_convert_attr(c->vc_scrl_erase_char);
+       u16 eattr = mda_convert_attr(c->vc_video_erase_char);
 
        if (!lines)
                return 0;
index 4055dbdd1b428e0dd978704204e0b182f364301d..491c1c1baf4ccd652eadf85079544686064e3228 100644 (file)
@@ -170,12 +170,12 @@ static int sticon_scroll(struct vc_data *conp, int t, int b, int dir, int count)
     switch (dir) {
     case SM_UP:
        sti_bmove(sti, t + count, 0, t, 0, b - t - count, conp->vc_cols);
-       sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_scrl_erase_char);
+       sti_clear(sti, b - count, 0, count, conp->vc_cols, conp->vc_video_erase_char);
        break;
 
     case SM_DOWN:
        sti_bmove(sti, t, 0, t + count, 0, b - t - count, conp->vc_cols);
-       sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_scrl_erase_char);
+       sti_clear(sti, t, 0, count, conp->vc_cols, conp->vc_video_erase_char);
        break;
     }
 
index bd1f57b259d9ce50d470b192e021ad95461b8e72..6df29a62d7202552d63ced7bfc588ef8854d6c49 100644 (file)
@@ -1350,7 +1350,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
                } else
                        c->vc_origin += delta;
                scr_memsetw((u16 *) (c->vc_origin + c->vc_screenbuf_size -
-                                    delta), c->vc_scrl_erase_char,
+                                    delta), c->vc_video_erase_char,
                            delta);
        } else {
                if (oldo - delta < vga_vram_base) {
@@ -1363,7 +1363,7 @@ static int vgacon_scroll(struct vc_data *c, int t, int b, int dir,
                } else
                        c->vc_origin -= delta;
                c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
-               scr_memsetw((u16 *) (c->vc_origin), c->vc_scrl_erase_char,
+               scr_memsetw((u16 *) (c->vc_origin), c->vc_video_erase_char,
                            delta);
        }
        c->vc_scr_end = c->vc_origin + c->vc_screenbuf_size;
index 4be00d812576e264453e2223d12270ecc361a508..9e9d70c02a07c9a8876f71c3445ac5092c563810 100644 (file)
@@ -433,6 +433,14 @@ config FS_POSIX_ACL
        bool
        default n
 
+config FILE_LOCKING
+       bool "Enable POSIX file locking API" if EMBEDDED
+       default y
+       help
+         This option enables standard file locking support, required
+          for filesystems like NFS and for the flock() system
+          call. Disabling this option saves about 11k.
+
 source "fs/xfs/Kconfig"
 source "fs/gfs2/Kconfig"
 
@@ -1789,6 +1797,28 @@ config SUNRPC_XPRT_RDMA
 
          If unsure, say N.
 
+config SUNRPC_REGISTER_V4
+       bool "Register local RPC services via rpcbind v4 (EXPERIMENTAL)"
+       depends on SUNRPC && EXPERIMENTAL
+       default n
+       help
+         Sun added support for registering RPC services at an IPv6
+         address by creating two new versions of the rpcbind protocol
+         (RFC 1833).
+
+         This option enables support in the kernel RPC server for
+         registering kernel RPC services via version 4 of the rpcbind
+         protocol.  If you enable this option, you must run a portmapper
+         daemon that supports rpcbind protocol version 4.
+
+         Serving NFS over IPv6 from knfsd (the kernel's NFS server)
+         requires that you enable this option and use a portmapper that
+         supports rpcbind version 4.
+
+         If unsure, say N to get traditional behavior (register kernel
+         RPC services using only rpcbind version 2).  Distributions
+         using the legacy Linux portmapper daemon must say N here.
+
 config RPCSEC_GSS_KRB5
        tristate "Secure RPC: Kerberos V mechanism (EXPERIMENTAL)"
        depends on SUNRPC && EXPERIMENTAL
index de404b00eb0cad255e28667472d7d2d75c43635a..b6f27dc26b7254a25c4dbf5223a2d24ce67f46d4 100644 (file)
@@ -7,7 +7,7 @@
 
 obj-y :=       open.o read_write.o file_table.o super.o \
                char_dev.o stat.o exec.o pipe.o namei.o fcntl.o \
-               ioctl.o readdir.o select.o fifo.o locks.o dcache.o inode.o \
+               ioctl.o readdir.o select.o fifo.o dcache.o inode.o \
                attr.o bad_inode.o file.o filesystems.o namespace.o aio.o \
                seq_file.o xattr.o libfs.o fs-writeback.o \
                pnode.o drop_caches.o splice.o sync.o utimes.o \
@@ -27,6 +27,7 @@ obj-$(CONFIG_ANON_INODES)     += anon_inodes.o
 obj-$(CONFIG_SIGNALFD)         += signalfd.o
 obj-$(CONFIG_TIMERFD)          += timerfd.o
 obj-$(CONFIG_EVENTFD)          += eventfd.o
+obj-$(CONFIG_FILE_LOCKING)      += locks.o
 obj-$(CONFIG_COMPAT)           += compat.o compat_ioctl.o
 
 nfsd-$(CONFIG_NFSD)            := nfsctl.o
index 7725a0a9a5553bf2db33b0fc81b1f92dbe7b48fc..97f6073ab339b327d4a5448224d18886eb3f42f7 100644 (file)
@@ -5,6 +5,6 @@
 obj-$(CONFIG_LOCKD) += lockd.o
 
 lockd-objs-y := clntlock.o clntproc.o host.o svc.o svclock.o svcshare.o \
-               svcproc.o svcsubs.o mon.o xdr.o
+               svcproc.o svcsubs.o mon.o xdr.o grace.o
 lockd-objs-$(CONFIG_LOCKD_V4) += xdr4.o svc4proc.o
 lockd-objs                   := $(lockd-objs-y)
index 0b45fd3a4bfd6dfdb9e6e8d426a46489954822bb..8307dd64bf46ca746d9c973f209626de49627d17 100644 (file)
@@ -54,14 +54,13 @@ struct nlm_host *nlmclnt_init(const struct nlmclnt_initdata *nlm_init)
        u32 nlm_version = (nlm_init->nfs_version == 2) ? 1 : 4;
        int status;
 
-       status = lockd_up(nlm_init->protocol);
+       status = lockd_up();
        if (status < 0)
                return ERR_PTR(status);
 
-       host = nlmclnt_lookup_host((struct sockaddr_in *)nlm_init->address,
+       host = nlmclnt_lookup_host(nlm_init->address, nlm_init->addrlen,
                                   nlm_init->protocol, nlm_version,
-                                  nlm_init->hostname,
-                                  strlen(nlm_init->hostname));
+                                  nlm_init->hostname);
        if (host == NULL) {
                lockd_down();
                return ERR_PTR(-ENOLCK);
@@ -142,7 +141,7 @@ int nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout)
 /*
  * The server lockd has called us back to tell us the lock was granted
  */
-__be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock)
+__be32 nlmclnt_grant(const struct sockaddr *addr, const struct nlm_lock *lock)
 {
        const struct file_lock *fl = &lock->fl;
        const struct nfs_fh *fh = &lock->fh;
@@ -166,7 +165,7 @@ __be32 nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *lock
                 */
                if (fl_blocked->fl_u.nfs_fl.owner->pid != lock->svid)
                        continue;
-               if (!nlm_cmp_addr(&block->b_host->h_addr, addr))
+               if (!nlm_cmp_addr(nlm_addr(block->b_host), addr))
                        continue;
                if (nfs_compare_fh(NFS_FH(fl_blocked->fl_file->f_path.dentry->d_inode) ,fh) != 0)
                        continue;
@@ -216,7 +215,7 @@ reclaimer(void *ptr)
        /* This one ensures that our parent doesn't terminate while the
         * reclaim is in progress */
        lock_kernel();
-       lockd_up(0); /* note: this cannot fail as lockd is already running */
+       lockd_up();     /* note: this cannot fail as lockd is already running */
 
        dprintk("lockd: reclaiming locks for host %s\n", host->h_name);
 
diff --git a/fs/lockd/grace.c b/fs/lockd/grace.c
new file mode 100644 (file)
index 0000000..183cc1f
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Common code for control of lockd and nfsv4 grace periods.
+ */
+
+#include <linux/module.h>
+#include <linux/lockd/bind.h>
+
+static LIST_HEAD(grace_list);
+static DEFINE_SPINLOCK(grace_lock);
+
+/**
+ * locks_start_grace
+ * @lm: who this grace period is for
+ *
+ * A grace period is a period during which locks should not be given
+ * out.  Currently grace periods are only enforced by the two lock
+ * managers (lockd and nfsd), using the locks_in_grace() function to
+ * check when they are in a grace period.
+ *
+ * This function is called to start a grace period.
+ */
+void locks_start_grace(struct lock_manager *lm)
+{
+       spin_lock(&grace_lock);
+       list_add(&lm->list, &grace_list);
+       spin_unlock(&grace_lock);
+}
+EXPORT_SYMBOL_GPL(locks_start_grace);
+
+/**
+ * locks_end_grace
+ * @lm: who this grace period is for
+ *
+ * Call this function to state that the given lock manager is ready to
+ * resume regular locking.  The grace period will not end until all lock
+ * managers that called locks_start_grace() also call locks_end_grace().
+ * Note that callers count on it being safe to call this more than once,
+ * and the second call should be a no-op.
+ */
+void locks_end_grace(struct lock_manager *lm)
+{
+       spin_lock(&grace_lock);
+       list_del_init(&lm->list);
+       spin_unlock(&grace_lock);
+}
+EXPORT_SYMBOL_GPL(locks_end_grace);
+
+/**
+ * locks_in_grace
+ *
+ * Lock managers call this function to determine when it is OK for them
+ * to answer ordinary lock requests, and when they should accept only
+ * lock reclaims.
+ */
+int locks_in_grace(void)
+{
+       return !list_empty(&grace_list);
+}
+EXPORT_SYMBOL_GPL(locks_in_grace);
index a17664c7eacc4542ee8a27a6543c4b548f6efc62..9fd8889097b728b735150ff82b1ff123a503dac7 100644 (file)
 #include <linux/types.h>
 #include <linux/slab.h>
 #include <linux/in.h>
+#include <linux/in6.h>
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/svc.h>
 #include <linux/lockd/lockd.h>
 #include <linux/lockd/sm_inter.h>
 #include <linux/mutex.h>
 
+#include <net/ipv6.h>
 
 #define NLMDBG_FACILITY                NLMDBG_HOSTCACHE
 #define NLM_HOST_NRHASH                32
-#define NLM_ADDRHASH(addr)     (ntohl(addr) & (NLM_HOST_NRHASH-1))
 #define NLM_HOST_REBIND                (60 * HZ)
 #define NLM_HOST_EXPIRE                (300 * HZ)
 #define NLM_HOST_COLLECT       (120 * HZ)
@@ -30,42 +31,115 @@ static unsigned long               next_gc;
 static int                     nrhosts;
 static DEFINE_MUTEX(nlm_host_mutex);
 
-
 static void                    nlm_gc_hosts(void);
-static struct nsm_handle *     __nsm_find(const struct sockaddr_in *,
-                                       const char *, unsigned int, int);
-static struct nsm_handle *     nsm_find(const struct sockaddr_in *sin,
-                                        const char *hostname,
-                                        unsigned int hostname_len);
+static struct nsm_handle       *nsm_find(const struct sockaddr *sap,
+                                               const size_t salen,
+                                               const char *hostname,
+                                               const size_t hostname_len,
+                                               const int create);
+
+struct nlm_lookup_host_info {
+       const int               server;         /* search for server|client */
+       const struct sockaddr   *sap;           /* address to search for */
+       const size_t            salen;          /* it's length */
+       const unsigned short    protocol;       /* transport to search for*/
+       const u32               version;        /* NLM version to search for */
+       const char              *hostname;      /* remote's hostname */
+       const size_t            hostname_len;   /* it's length */
+       const struct sockaddr   *src_sap;       /* our address (optional) */
+       const size_t            src_len;        /* it's length */
+};
+
+/*
+ * Hash function must work well on big- and little-endian platforms
+ */
+static unsigned int __nlm_hash32(const __be32 n)
+{
+       unsigned int hash = (__force u32)n ^ ((__force u32)n >> 16);
+       return hash ^ (hash >> 8);
+}
+
+static unsigned int __nlm_hash_addr4(const struct sockaddr *sap)
+{
+       const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+       return __nlm_hash32(sin->sin_addr.s_addr);
+}
+
+static unsigned int __nlm_hash_addr6(const struct sockaddr *sap)
+{
+       const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+       const struct in6_addr addr = sin6->sin6_addr;
+       return __nlm_hash32(addr.s6_addr32[0]) ^
+              __nlm_hash32(addr.s6_addr32[1]) ^
+              __nlm_hash32(addr.s6_addr32[2]) ^
+              __nlm_hash32(addr.s6_addr32[3]);
+}
+
+static unsigned int nlm_hash_address(const struct sockaddr *sap)
+{
+       unsigned int hash;
+
+       switch (sap->sa_family) {
+       case AF_INET:
+               hash = __nlm_hash_addr4(sap);
+               break;
+       case AF_INET6:
+               hash = __nlm_hash_addr6(sap);
+               break;
+       default:
+               hash = 0;
+       }
+       return hash & (NLM_HOST_NRHASH - 1);
+}
+
+static void nlm_clear_port(struct sockaddr *sap)
+{
+       switch (sap->sa_family) {
+       case AF_INET:
+               ((struct sockaddr_in *)sap)->sin_port = 0;
+               break;
+       case AF_INET6:
+               ((struct sockaddr_in6 *)sap)->sin6_port = 0;
+               break;
+       }
+}
+
+static void nlm_display_address(const struct sockaddr *sap,
+                               char *buf, const size_t len)
+{
+       const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+       const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+
+       switch (sap->sa_family) {
+       case AF_UNSPEC:
+               snprintf(buf, len, "unspecified");
+               break;
+       case AF_INET:
+               snprintf(buf, len, NIPQUAD_FMT, NIPQUAD(sin->sin_addr.s_addr));
+               break;
+       case AF_INET6:
+               if (ipv6_addr_v4mapped(&sin6->sin6_addr))
+                       snprintf(buf, len, NIPQUAD_FMT,
+                                NIPQUAD(sin6->sin6_addr.s6_addr32[3]));
+               else
+                       snprintf(buf, len, NIP6_FMT, NIP6(sin6->sin6_addr));
+               break;
+       default:
+               snprintf(buf, len, "unsupported address family");
+               break;
+       }
+}
 
 /*
  * Common host lookup routine for server & client
  */
-static struct nlm_host *nlm_lookup_host(int server,
-                                       const struct sockaddr_in *sin,
-                                       int proto, u32 version,
-                                       const char *hostname,
-                                       unsigned int hostname_len,
-                                       const struct sockaddr_in *ssin)
+static struct nlm_host *nlm_lookup_host(struct nlm_lookup_host_info *ni)
 {
        struct hlist_head *chain;
        struct hlist_node *pos;
        struct nlm_host *host;
        struct nsm_handle *nsm = NULL;
-       int             hash;
-
-       dprintk("lockd: nlm_lookup_host("NIPQUAD_FMT"->"NIPQUAD_FMT
-                       ", p=%d, v=%u, my role=%s, name=%.*s)\n",
-                       NIPQUAD(ssin->sin_addr.s_addr),
-                       NIPQUAD(sin->sin_addr.s_addr), proto, version,
-                       server? "server" : "client",
-                       hostname_len,
-                       hostname? hostname : "<none>");
 
-
-       hash = NLM_ADDRHASH(sin->sin_addr.s_addr);
-
-       /* Lock hash table */
        mutex_lock(&nlm_host_mutex);
 
        if (time_after_eq(jiffies, next_gc))
@@ -78,22 +152,22 @@ static struct nlm_host *nlm_lookup_host(int server,
         * different NLM rpc_clients into one single nlm_host object.
         * This would allow us to have one nlm_host per address.
         */
-       chain = &nlm_hosts[hash];
+       chain = &nlm_hosts[nlm_hash_address(ni->sap)];
        hlist_for_each_entry(host, pos, chain, h_hash) {
-               if (!nlm_cmp_addr(&host->h_addr, sin))
+               if (!nlm_cmp_addr(nlm_addr(host), ni->sap))
                        continue;
 
                /* See if we have an NSM handle for this client */
                if (!nsm)
                        nsm = host->h_nsmhandle;
 
-               if (host->h_proto != proto)
+               if (host->h_proto != ni->protocol)
                        continue;
-               if (host->h_version != version)
+               if (host->h_version != ni->version)
                        continue;
-               if (host->h_server != server)
+               if (host->h_server != ni->server)
                        continue;
-               if (!nlm_cmp_addr(&host->h_saddr, ssin))
+               if (!nlm_cmp_addr(nlm_srcaddr(host), ni->src_sap))
                        continue;
 
                /* Move to head of hash chain. */
@@ -101,30 +175,41 @@ static struct nlm_host *nlm_lookup_host(int server,
                hlist_add_head(&host->h_hash, chain);
 
                nlm_get_host(host);
+               dprintk("lockd: nlm_lookup_host found host %s (%s)\n",
+                               host->h_name, host->h_addrbuf);
                goto out;
        }
-       if (nsm)
-               atomic_inc(&nsm->sm_count);
-
-       host = NULL;
 
-       /* Sadly, the host isn't in our hash table yet. See if
-        * we have an NSM handle for it. If not, create one.
+       /*
+        * The host wasn't in our hash table.  If we don't
+        * have an NSM handle for it yet, create one.
         */
-       if (!nsm && !(nsm = nsm_find(sin, hostname, hostname_len)))
-               goto out;
+       if (nsm)
+               atomic_inc(&nsm->sm_count);
+       else {
+               host = NULL;
+               nsm = nsm_find(ni->sap, ni->salen,
+                               ni->hostname, ni->hostname_len, 1);
+               if (!nsm) {
+                       dprintk("lockd: nlm_lookup_host failed; "
+                               "no nsm handle\n");
+                       goto out;
+               }
+       }
 
        host = kzalloc(sizeof(*host), GFP_KERNEL);
        if (!host) {
                nsm_release(nsm);
+               dprintk("lockd: nlm_lookup_host failed; no memory\n");
                goto out;
        }
        host->h_name       = nsm->sm_name;
-       host->h_addr       = *sin;
-       host->h_addr.sin_port = 0;      /* ouch! */
-       host->h_saddr      = *ssin;
-       host->h_version    = version;
-       host->h_proto      = proto;
+       memcpy(nlm_addr(host), ni->sap, ni->salen);
+       host->h_addrlen = ni->salen;
+       nlm_clear_port(nlm_addr(host));
+       memcpy(nlm_srcaddr(host), ni->src_sap, ni->src_len);
+       host->h_version    = ni->version;
+       host->h_proto      = ni->protocol;
        host->h_rpcclnt    = NULL;
        mutex_init(&host->h_mutex);
        host->h_nextrebind = jiffies + NLM_HOST_REBIND;
@@ -135,7 +220,7 @@ static struct nlm_host *nlm_lookup_host(int server,
        host->h_state      = 0;                 /* pseudo NSM state */
        host->h_nsmstate   = 0;                 /* real NSM state */
        host->h_nsmhandle  = nsm;
-       host->h_server     = server;
+       host->h_server     = ni->server;
        hlist_add_head(&host->h_hash, chain);
        INIT_LIST_HEAD(&host->h_lockowners);
        spin_lock_init(&host->h_lock);
@@ -143,6 +228,15 @@ static struct nlm_host *nlm_lookup_host(int server,
        INIT_LIST_HEAD(&host->h_reclaim);
 
        nrhosts++;
+
+       nlm_display_address((struct sockaddr *)&host->h_addr,
+                               host->h_addrbuf, sizeof(host->h_addrbuf));
+       nlm_display_address((struct sockaddr *)&host->h_srcaddr,
+                               host->h_srcaddrbuf, sizeof(host->h_srcaddrbuf));
+
+       dprintk("lockd: nlm_lookup_host created host %s\n",
+                       host->h_name);
+
 out:
        mutex_unlock(&nlm_host_mutex);
        return host;
@@ -170,33 +264,103 @@ nlm_destroy_host(struct nlm_host *host)
        kfree(host);
 }
 
-/*
- * Find an NLM server handle in the cache. If there is none, create it.
+/**
+ * nlmclnt_lookup_host - Find an NLM host handle matching a remote server
+ * @sap: network address of server
+ * @salen: length of server address
+ * @protocol: transport protocol to use
+ * @version: NLM protocol version
+ * @hostname: '\0'-terminated hostname of server
+ *
+ * Returns an nlm_host structure that matches the passed-in
+ * [server address, transport protocol, NLM version, server hostname].
+ * If one doesn't already exist in the host cache, a new handle is
+ * created and returned.
  */
-struct nlm_host *nlmclnt_lookup_host(const struct sockaddr_in *sin,
-                                    int proto, u32 version,
-                                    const char *hostname,
-                                    unsigned int hostname_len)
+struct nlm_host *nlmclnt_lookup_host(const struct sockaddr *sap,
+                                    const size_t salen,
+                                    const unsigned short protocol,
+                                    const u32 version, const char *hostname)
 {
-       struct sockaddr_in ssin = {0};
-
-       return nlm_lookup_host(0, sin, proto, version,
-                              hostname, hostname_len, &ssin);
+       const struct sockaddr source = {
+               .sa_family      = AF_UNSPEC,
+       };
+       struct nlm_lookup_host_info ni = {
+               .server         = 0,
+               .sap            = sap,
+               .salen          = salen,
+               .protocol       = protocol,
+               .version        = version,
+               .hostname       = hostname,
+               .hostname_len   = strlen(hostname),
+               .src_sap        = &source,
+               .src_len        = sizeof(source),
+       };
+
+       dprintk("lockd: %s(host='%s', vers=%u, proto=%s)\n", __func__,
+                       (hostname ? hostname : "<none>"), version,
+                       (protocol == IPPROTO_UDP ? "udp" : "tcp"));
+
+       return nlm_lookup_host(&ni);
 }
 
-/*
- * Find an NLM client handle in the cache. If there is none, create it.
+/**
+ * nlmsvc_lookup_host - Find an NLM host handle matching a remote client
+ * @rqstp: incoming NLM request
+ * @hostname: name of client host
+ * @hostname_len: length of client hostname
+ *
+ * Returns an nlm_host structure that matches the [client address,
+ * transport protocol, NLM version, client hostname] of the passed-in
+ * NLM request.  If one doesn't already exist in the host cache, a
+ * new handle is created and returned.
+ *
+ * Before possibly creating a new nlm_host, construct a sockaddr
+ * for a specific source address in case the local system has
+ * multiple network addresses.  The family of the address in
+ * rq_daddr is guaranteed to be the same as the family of the
+ * address in rq_addr, so it's safe to use the same family for
+ * the source address.
  */
-struct nlm_host *
-nlmsvc_lookup_host(struct svc_rqst *rqstp,
-                       const char *hostname, unsigned int hostname_len)
+struct nlm_host *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
+                                   const char *hostname,
+                                   const size_t hostname_len)
 {
-       struct sockaddr_in ssin = {0};
+       struct sockaddr_in sin = {
+               .sin_family     = AF_INET,
+       };
+       struct sockaddr_in6 sin6 = {
+               .sin6_family    = AF_INET6,
+       };
+       struct nlm_lookup_host_info ni = {
+               .server         = 1,
+               .sap            = svc_addr(rqstp),
+               .salen          = rqstp->rq_addrlen,
+               .protocol       = rqstp->rq_prot,
+               .version        = rqstp->rq_vers,
+               .hostname       = hostname,
+               .hostname_len   = hostname_len,
+               .src_len        = rqstp->rq_addrlen,
+       };
+
+       dprintk("lockd: %s(host='%*s', vers=%u, proto=%s)\n", __func__,
+                       (int)hostname_len, hostname, rqstp->rq_vers,
+                       (rqstp->rq_prot == IPPROTO_UDP ? "udp" : "tcp"));
+
+       switch (ni.sap->sa_family) {
+       case AF_INET:
+               sin.sin_addr.s_addr = rqstp->rq_daddr.addr.s_addr;
+               ni.src_sap = (struct sockaddr *)&sin;
+               break;
+       case AF_INET6:
+               ipv6_addr_copy(&sin6.sin6_addr, &rqstp->rq_daddr.addr6);
+               ni.src_sap = (struct sockaddr *)&sin6;
+               break;
+       default:
+               return NULL;
+       }
 
-       ssin.sin_addr = rqstp->rq_daddr.addr;
-       return nlm_lookup_host(1, svc_addr_in(rqstp),
-                              rqstp->rq_prot, rqstp->rq_vers,
-                              hostname, hostname_len, &ssin);
+       return nlm_lookup_host(&ni);
 }
 
 /*
@@ -207,9 +371,8 @@ nlm_bind_host(struct nlm_host *host)
 {
        struct rpc_clnt *clnt;
 
-       dprintk("lockd: nlm_bind_host("NIPQUAD_FMT"->"NIPQUAD_FMT")\n",
-                       NIPQUAD(host->h_saddr.sin_addr),
-                       NIPQUAD(host->h_addr.sin_addr));
+       dprintk("lockd: nlm_bind_host %s (%s), my addr=%s\n",
+                       host->h_name, host->h_addrbuf, host->h_srcaddrbuf);
 
        /* Lock host handle */
        mutex_lock(&host->h_mutex);
@@ -221,7 +384,7 @@ nlm_bind_host(struct nlm_host *host)
                if (time_after_eq(jiffies, host->h_nextrebind)) {
                        rpc_force_rebind(clnt);
                        host->h_nextrebind = jiffies + NLM_HOST_REBIND;
-                       dprintk("lockd: next rebind in %ld jiffies\n",
+                       dprintk("lockd: next rebind in %lu jiffies\n",
                                        host->h_nextrebind - jiffies);
                }
        } else {
@@ -234,9 +397,9 @@ nlm_bind_host(struct nlm_host *host)
                };
                struct rpc_create_args args = {
                        .protocol       = host->h_proto,
-                       .address        = (struct sockaddr *)&host->h_addr,
-                       .addrsize       = sizeof(host->h_addr),
-                       .saddress       = (struct sockaddr *)&host->h_saddr,
+                       .address        = nlm_addr(host),
+                       .addrsize       = host->h_addrlen,
+                       .saddress       = nlm_srcaddr(host),
                        .timeout        = &timeparms,
                        .servername     = host->h_name,
                        .program        = &nlm_program,
@@ -324,12 +487,16 @@ void nlm_host_rebooted(const struct sockaddr_in *sin,
        struct nsm_handle *nsm;
        struct nlm_host *host;
 
-       dprintk("lockd: nlm_host_rebooted(%s, %u.%u.%u.%u)\n",
-                       hostname, NIPQUAD(sin->sin_addr));
-
-       /* Find the NSM handle for this peer */
-       if (!(nsm = __nsm_find(sin, hostname, hostname_len, 0)))
+       nsm = nsm_find((struct sockaddr *)sin, sizeof(*sin),
+                       hostname, hostname_len, 0);
+       if (nsm == NULL) {
+               dprintk("lockd: never saw rebooted peer '%.*s' before\n",
+                               hostname_len, hostname);
                return;
+       }
+
+       dprintk("lockd: nlm_host_rebooted(%.*s, %s)\n",
+                       hostname_len, hostname, nsm->sm_addrbuf);
 
        /* When reclaiming locks on this peer, make sure that
         * we set up a new notification */
@@ -461,22 +628,23 @@ nlm_gc_hosts(void)
 static LIST_HEAD(nsm_handles);
 static DEFINE_SPINLOCK(nsm_lock);
 
-static struct nsm_handle *
-__nsm_find(const struct sockaddr_in *sin,
-               const char *hostname, unsigned int hostname_len,
-               int create)
+static struct nsm_handle *nsm_find(const struct sockaddr *sap,
+                                  const size_t salen,
+                                  const char *hostname,
+                                  const size_t hostname_len,
+                                  const int create)
 {
        struct nsm_handle *nsm = NULL;
        struct nsm_handle *pos;
 
-       if (!sin)
+       if (!sap)
                return NULL;
 
        if (hostname && memchr(hostname, '/', hostname_len) != NULL) {
                if (printk_ratelimit()) {
                        printk(KERN_WARNING "Invalid hostname \"%.*s\" "
                                            "in NFS lock request\n",
-                               hostname_len, hostname);
+                               (int)hostname_len, hostname);
                }
                return NULL;
        }
@@ -489,7 +657,7 @@ retry:
                        if (strlen(pos->sm_name) != hostname_len
                         || memcmp(pos->sm_name, hostname, hostname_len))
                                continue;
-               } else if (!nlm_cmp_addr(&pos->sm_addr, sin))
+               } else if (!nlm_cmp_addr(nsm_addr(pos), sap))
                        continue;
                atomic_inc(&pos->sm_count);
                kfree(nsm);
@@ -509,10 +677,13 @@ retry:
        if (nsm == NULL)
                return NULL;
 
-       nsm->sm_addr = *sin;
+       memcpy(nsm_addr(nsm), sap, salen);
+       nsm->sm_addrlen = salen;
        nsm->sm_name = (char *) (nsm + 1);
        memcpy(nsm->sm_name, hostname, hostname_len);
        nsm->sm_name[hostname_len] = '\0';
+       nlm_display_address((struct sockaddr *)&nsm->sm_addr,
+                               nsm->sm_addrbuf, sizeof(nsm->sm_addrbuf));
        atomic_set(&nsm->sm_count, 1);
        goto retry;
 
@@ -521,13 +692,6 @@ found:
        return nsm;
 }
 
-static struct nsm_handle *
-nsm_find(const struct sockaddr_in *sin, const char *hostname,
-        unsigned int hostname_len)
-{
-       return __nsm_find(sin, hostname, hostname_len, 1);
-}
-
 /*
  * Release an NSM handle
  */
index e4d563543b11066a1acd17a5beb7d0a8916aa520..4e7e958e8f6753236832ed9ebd82f6bae0746899 100644 (file)
@@ -51,7 +51,7 @@ nsm_mon_unmon(struct nsm_handle *nsm, u32 proc, struct nsm_res *res)
 
        memset(&args, 0, sizeof(args));
        args.mon_name = nsm->sm_name;
-       args.addr = nsm->sm_addr.sin_addr.s_addr;
+       args.addr = nsm_addr_in(nsm)->sin_addr.s_addr;
        args.prog = NLM_PROGRAM;
        args.vers = 3;
        args.proc = NLMPROC_NSM_NOTIFY;
index 5bd9bf0fa9df09121f8c190d7e47ec8ef7871ede..c631a83931cec9cd56128daf5fc494b8fac9703a 100644 (file)
@@ -51,7 +51,6 @@ static DEFINE_MUTEX(nlmsvc_mutex);
 static unsigned int            nlmsvc_users;
 static struct task_struct      *nlmsvc_task;
 static struct svc_rqst         *nlmsvc_rqst;
-int                            nlmsvc_grace_period;
 unsigned long                  nlmsvc_timeout;
 
 /*
@@ -85,27 +84,23 @@ static unsigned long get_lockd_grace_period(void)
                return nlm_timeout * 5 * HZ;
 }
 
-unsigned long get_nfs_grace_period(void)
-{
-       unsigned long lockdgrace = get_lockd_grace_period();
-       unsigned long nfsdgrace = 0;
-
-       if (nlmsvc_ops)
-               nfsdgrace = nlmsvc_ops->get_grace_period();
-
-       return max(lockdgrace, nfsdgrace);
-}
-EXPORT_SYMBOL(get_nfs_grace_period);
+static struct lock_manager lockd_manager = {
+};
 
-static unsigned long set_grace_period(void)
+static void grace_ender(struct work_struct *not_used)
 {
-       nlmsvc_grace_period = 1;
-       return get_nfs_grace_period() + jiffies;
+       locks_end_grace(&lockd_manager);
 }
 
-static inline void clear_grace_period(void)
+static DECLARE_DELAYED_WORK(grace_period_end, grace_ender);
+
+static void set_grace_period(void)
 {
-       nlmsvc_grace_period = 0;
+       unsigned long grace_period = get_lockd_grace_period();
+
+       locks_start_grace(&lockd_manager);
+       cancel_delayed_work_sync(&grace_period_end);
+       schedule_delayed_work(&grace_period_end, grace_period);
 }
 
 /*
@@ -116,7 +111,6 @@ lockd(void *vrqstp)
 {
        int             err = 0, preverr = 0;
        struct svc_rqst *rqstp = vrqstp;
-       unsigned long grace_period_expire;
 
        /* try_to_freeze() is called from svc_recv() */
        set_freezable();
@@ -139,7 +133,7 @@ lockd(void *vrqstp)
                nlm_timeout = LOCKD_DFLT_TIMEO;
        nlmsvc_timeout = nlm_timeout * HZ;
 
-       grace_period_expire = set_grace_period();
+       set_grace_period();
 
        /*
         * The main request loop. We don't terminate until the last
@@ -153,21 +147,12 @@ lockd(void *vrqstp)
                        flush_signals(current);
                        if (nlmsvc_ops) {
                                nlmsvc_invalidate_all();
-                               grace_period_expire = set_grace_period();
+                               set_grace_period();
                        }
                        continue;
                }
 
-               /*
-                * Retry any blocked locks that have been notified by
-                * the VFS. Don't do this during grace period.
-                * (Theoretically, there shouldn't even be blocked locks
-                * during grace period).
-                */
-               if (!nlmsvc_grace_period) {
-                       timeout = nlmsvc_retry_blocked();
-               } else if (time_before(grace_period_expire, jiffies))
-                       clear_grace_period();
+               timeout = nlmsvc_retry_blocked();
 
                /*
                 * Find a socket with data available and call its
@@ -195,6 +180,7 @@ lockd(void *vrqstp)
                svc_process(rqstp);
        }
        flush_signals(current);
+       cancel_delayed_work_sync(&grace_period_end);
        if (nlmsvc_ops)
                nlmsvc_invalidate_all();
        nlm_shutdown_hosts();
@@ -203,25 +189,28 @@ lockd(void *vrqstp)
 }
 
 /*
- * Make any sockets that are needed but not present.
- * If nlm_udpport or nlm_tcpport were set as module
- * options, make those sockets unconditionally
+ * Ensure there are active UDP and TCP listeners for lockd.
+ *
+ * Even if we have only TCP NFS mounts and/or TCP NFSDs, some
+ * local services (such as rpc.statd) still require UDP, and
+ * some NFS servers do not yet support NLM over TCP.
+ *
+ * Returns zero if all listeners are available; otherwise a
+ * negative errno value is returned.
  */
-static int make_socks(struct svc_serv *serv, int proto)
+static int make_socks(struct svc_serv *serv)
 {
        static int warned;
        struct svc_xprt *xprt;
        int err = 0;
 
-       if (proto == IPPROTO_UDP || nlm_udpport) {
-               xprt = svc_find_xprt(serv, "udp", 0, 0);
-               if (!xprt)
-                       err = svc_create_xprt(serv, "udp", nlm_udpport,
-                                             SVC_SOCK_DEFAULTS);
-               else
-                       svc_xprt_put(xprt);
-       }
-       if (err >= 0 && (proto == IPPROTO_TCP || nlm_tcpport)) {
+       xprt = svc_find_xprt(serv, "udp", 0, 0);
+       if (!xprt)
+               err = svc_create_xprt(serv, "udp", nlm_udpport,
+                                     SVC_SOCK_DEFAULTS);
+       else
+               svc_xprt_put(xprt);
+       if (err >= 0) {
                xprt = svc_find_xprt(serv, "tcp", 0, 0);
                if (!xprt)
                        err = svc_create_xprt(serv, "tcp", nlm_tcpport,
@@ -241,8 +230,7 @@ static int make_socks(struct svc_serv *serv, int proto)
 /*
  * Bring up the lockd process if it's not already up.
  */
-int
-lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
+int lockd_up(void)
 {
        struct svc_serv *serv;
        int             error = 0;
@@ -251,11 +239,8 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
        /*
         * Check whether we're already up and running.
         */
-       if (nlmsvc_rqst) {
-               if (proto)
-                       error = make_socks(nlmsvc_rqst->rq_server, proto);
+       if (nlmsvc_rqst)
                goto out;
-       }
 
        /*
         * Sanity check: if there's no pid,
@@ -266,13 +251,14 @@ lockd_up(int proto) /* Maybe add a 'family' option when IPv6 is supported ?? */
                        "lockd_up: no pid, %d users??\n", nlmsvc_users);
 
        error = -ENOMEM;
-       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, NULL);
+       serv = svc_create(&nlmsvc_program, LOCKD_BUFSIZE, AF_INET, NULL);
        if (!serv) {
                printk(KERN_WARNING "lockd_up: create service failed\n");
                goto out;
        }
 
-       if ((error = make_socks(serv, proto)) < 0)
+       error = make_socks(serv);
+       if (error < 0)
                goto destroy_and_out;
 
        /*
index 4a714f64515b06557704b38cf02f8ba7f36f7ea0..014f6ce48172fa73cc5d534bda12096776b39e20 100644 (file)
@@ -88,12 +88,6 @@ nlm4svc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        dprintk("lockd: TEST4        called\n");
        resp->cookie = argp->cookie;
 
-       /* Don't accept test requests during grace period */
-       if (nlmsvc_grace_period) {
-               resp->status = nlm_lck_denied_grace_period;
-               return rc;
-       }
-
        /* Obtain client and file */
        if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
                return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
@@ -122,12 +116,6 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 
        resp->cookie = argp->cookie;
 
-       /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period && !argp->reclaim) {
-               resp->status = nlm_lck_denied_grace_period;
-               return rc;
-       }
-
        /* Obtain client and file */
        if ((resp->status = nlm4svc_retrieve_args(rqstp, argp, &host, &file)))
                return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
@@ -146,7 +134,8 @@ nlm4svc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 
        /* Now try to lock the file */
        resp->status = nlmsvc_lock(rqstp, file, host, &argp->lock,
-                                       argp->block, &argp->cookie);
+                                       argp->block, &argp->cookie,
+                                       argp->reclaim);
        if (resp->status == nlm_drop_reply)
                rc = rpc_drop_reply;
        else
@@ -169,7 +158,7 @@ nlm4svc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -202,7 +191,7 @@ nlm4svc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -231,7 +220,7 @@ nlm4svc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        dprintk("lockd: GRANTED       called\n");
-       resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock);
+       resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
        dprintk("lockd: GRANTED       status %d\n", ntohl(resp->status));
        return rpc_success;
 }
@@ -341,7 +330,7 @@ nlm4svc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period && !argp->reclaim) {
+       if (locks_in_grace() && !argp->reclaim) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -374,7 +363,7 @@ nlm4svc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -432,11 +421,9 @@ nlm4svc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
 {
        struct sockaddr_in      saddr;
 
-       memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr));
-
        dprintk("lockd: SM_NOTIFY     called\n");
-       if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
-        || ntohs(saddr.sin_port) >= 1024) {
+
+       if (!nlm_privileged_requester(rqstp)) {
                char buf[RPC_MAX_ADDRBUFLEN];
                printk(KERN_WARNING "lockd: rejected NSM callback from %s\n",
                                svc_print_addr(rqstp, buf, sizeof(buf)));
index cf0d5c2c318d6002330f1bca7965b09e8a047e9d..6063a8e4b9f3223104843bce393882181b890539 100644 (file)
@@ -360,7 +360,7 @@ nlmsvc_defer_lock_rqst(struct svc_rqst *rqstp, struct nlm_block *block)
 __be32
 nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
            struct nlm_host *host, struct nlm_lock *lock, int wait,
-           struct nlm_cookie *cookie)
+           struct nlm_cookie *cookie, int reclaim)
 {
        struct nlm_block        *block = NULL;
        int                     error;
@@ -406,6 +406,15 @@ nlmsvc_lock(struct svc_rqst *rqstp, struct nlm_file *file,
                goto out;
        }
 
+       if (locks_in_grace() && !reclaim) {
+               ret = nlm_lck_denied_grace_period;
+               goto out;
+       }
+       if (reclaim && !locks_in_grace()) {
+               ret = nlm_lck_denied_grace_period;
+               goto out;
+       }
+
        if (!wait)
                lock->fl.fl_flags &= ~FL_SLEEP;
        error = vfs_lock_file(file->f_file, F_SETLK, &lock->fl, NULL);
@@ -502,6 +511,10 @@ nlmsvc_testlock(struct svc_rqst *rqstp, struct nlm_file *file,
                goto out;
        }
 
+       if (locks_in_grace()) {
+               ret = nlm_lck_denied_grace_period;
+               goto out;
+       }
        error = vfs_test_lock(file->f_file, &lock->fl);
        if (error == FILE_LOCK_DEFERRED) {
                ret = nlmsvc_defer_lock_rqst(rqstp, block);
@@ -582,6 +595,9 @@ nlmsvc_cancel_blocked(struct nlm_file *file, struct nlm_lock *lock)
                                (long long)lock->fl.fl_start,
                                (long long)lock->fl.fl_end);
 
+       if (locks_in_grace())
+               return nlm_lck_denied_grace_period;
+
        mutex_lock(&file->f_mutex);
        block = nlmsvc_lookup_block(file, lock);
        mutex_unlock(&file->f_mutex);
index 76262c1986f2d36d1f6765da9acf506736b3b30b..548b0bb2b84d1e7dccb6351bdff03980d276959e 100644 (file)
@@ -117,12 +117,6 @@ nlmsvc_proc_test(struct svc_rqst *rqstp, struct nlm_args *argp,
        dprintk("lockd: TEST          called\n");
        resp->cookie = argp->cookie;
 
-       /* Don't accept test requests during grace period */
-       if (nlmsvc_grace_period) {
-               resp->status = nlm_lck_denied_grace_period;
-               return rc;
-       }
-
        /* Obtain client and file */
        if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
                return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
@@ -152,12 +146,6 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 
        resp->cookie = argp->cookie;
 
-       /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period && !argp->reclaim) {
-               resp->status = nlm_lck_denied_grace_period;
-               return rc;
-       }
-
        /* Obtain client and file */
        if ((resp->status = nlmsvc_retrieve_args(rqstp, argp, &host, &file)))
                return resp->status == nlm_drop_reply ? rpc_drop_reply :rpc_success;
@@ -176,7 +164,8 @@ nlmsvc_proc_lock(struct svc_rqst *rqstp, struct nlm_args *argp,
 
        /* Now try to lock the file */
        resp->status = cast_status(nlmsvc_lock(rqstp, file, host, &argp->lock,
-                                              argp->block, &argp->cookie));
+                                              argp->block, &argp->cookie,
+                                              argp->reclaim));
        if (resp->status == nlm_drop_reply)
                rc = rpc_drop_reply;
        else
@@ -199,7 +188,7 @@ nlmsvc_proc_cancel(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -232,7 +221,7 @@ nlmsvc_proc_unlock(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -261,7 +250,7 @@ nlmsvc_proc_granted(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        dprintk("lockd: GRANTED       called\n");
-       resp->status = nlmclnt_grant(svc_addr_in(rqstp), &argp->lock);
+       resp->status = nlmclnt_grant(svc_addr(rqstp), &argp->lock);
        dprintk("lockd: GRANTED       status %d\n", ntohl(resp->status));
        return rpc_success;
 }
@@ -373,7 +362,7 @@ nlmsvc_proc_share(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept new lock requests during grace period */
-       if (nlmsvc_grace_period && !argp->reclaim) {
+       if (locks_in_grace() && !argp->reclaim) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -406,7 +395,7 @@ nlmsvc_proc_unshare(struct svc_rqst *rqstp, struct nlm_args *argp,
        resp->cookie = argp->cookie;
 
        /* Don't accept requests during grace period */
-       if (nlmsvc_grace_period) {
+       if (locks_in_grace()) {
                resp->status = nlm_lck_denied_grace_period;
                return rpc_success;
        }
@@ -464,11 +453,9 @@ nlmsvc_proc_sm_notify(struct svc_rqst *rqstp, struct nlm_reboot *argp,
 {
        struct sockaddr_in      saddr;
 
-       memcpy(&saddr, svc_addr_in(rqstp), sizeof(saddr));
-
        dprintk("lockd: SM_NOTIFY     called\n");
-       if (saddr.sin_addr.s_addr != htonl(INADDR_LOOPBACK)
-        || ntohs(saddr.sin_port) >= 1024) {
+
+       if (!nlm_privileged_requester(rqstp)) {
                char buf[RPC_MAX_ADDRBUFLEN];
                printk(KERN_WARNING "lockd: rejected NSM callback from %s\n",
                                svc_print_addr(rqstp, buf, sizeof(buf)));
index 198b4e55b3732523fbe569cfd927948c3ee70cb0..34c2766e27c7273138af21bdc8b65e9447c71d72 100644 (file)
@@ -418,7 +418,7 @@ EXPORT_SYMBOL_GPL(nlmsvc_unlock_all_by_sb);
 static int
 nlmsvc_match_ip(void *datap, struct nlm_host *host)
 {
-       return nlm_cmp_addr(&host->h_saddr, datap);
+       return nlm_cmp_addr(nlm_srcaddr(host), datap);
 }
 
 /**
index 3e459e18cc31ba2efeaca67dc9b40ae506604247..1f226290c67cf88a2707f08447d2e92f9a98bfbc 100644 (file)
@@ -351,8 +351,6 @@ nlmsvc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp)
        argp->state = ntohl(*p++);
        /* Preserve the address in network byte order */
        argp->addr = *p++;
-       argp->vers = *p++;
-       argp->proto = *p++;
        return xdr_argsize_check(rqstp, p);
 }
 
index 43ff9397e6c67fee3504dda5e5c3579c04212cf2..50c493a8ad8e5e1f4fcd10eaa7d2311a35c5285b 100644 (file)
@@ -358,8 +358,6 @@ nlm4svc_decode_reboot(struct svc_rqst *rqstp, __be32 *p, struct nlm_reboot *argp
        argp->state = ntohl(*p++);
        /* Preserve the address in network byte order */
        argp->addr  = *p++;
-       argp->vers  = *p++;
-       argp->proto = *p++;
        return xdr_argsize_check(rqstp, p);
 }
 
index f447f4b4476cc37b26144ffdfcef83cd80eab53e..6a09760c5960fd427935c2306f5080caa66bce3b 100644 (file)
@@ -105,7 +105,8 @@ int nfs_callback_up(void)
        mutex_lock(&nfs_callback_mutex);
        if (nfs_callback_info.users++ || nfs_callback_info.task != NULL)
                goto out;
-       serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE, NULL);
+       serv = svc_create(&nfs4_callback_program, NFS4_CALLBACK_BUFSIZE,
+                               AF_INET, NULL);
        ret = -ENOMEM;
        if (!serv)
                goto out_err;
index 15c6faeec77c118a77b11c50287a6a43828bd9a2..b2786a5f9afefaaea3573303339cd7154ad54bd7 100644 (file)
@@ -70,7 +70,6 @@ nlm_fclose(struct file *filp)
 static struct nlmsvc_binding   nfsd_nlm_ops = {
        .fopen          = nlm_fopen,            /* open file for locking */
        .fclose         = nlm_fclose,           /* close file */
-       .get_grace_period = get_nfs4_grace_period,
 };
 
 void
index 4d617ea28cfc0b699868275db4cd95202e23f989..9dbd2eb91281b14a4f3472c3ac5dad046c4525c9 100644 (file)
@@ -63,7 +63,8 @@ nfsd3_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle  *argp,
                SVCFH_fmt(&argp->fh));
 
        fh_copy(&resp->fh, &argp->fh);
-       nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
+       nfserr = fh_verify(rqstp, &resp->fh, 0,
+                       NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
        if (nfserr)
                RETURN_STATUS(nfserr);
 
@@ -530,7 +531,7 @@ nfsd3_proc_fsstat(struct svc_rqst * rqstp, struct nfsd_fhandle    *argp,
        dprintk("nfsd: FSSTAT(3)   %s\n",
                                SVCFH_fmt(&argp->fh));
 
-       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
+       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats, 0);
        fh_put(&argp->fh);
        RETURN_STATUS(nfserr);
 }
@@ -558,7 +559,8 @@ nfsd3_proc_fsinfo(struct svc_rqst * rqstp, struct nfsd_fhandle    *argp,
        resp->f_maxfilesize = ~(u32) 0;
        resp->f_properties = NFS3_FSF_DEFAULT;
 
-       nfserr = fh_verify(rqstp, &argp->fh, 0, NFSD_MAY_NOP);
+       nfserr = fh_verify(rqstp, &argp->fh, 0,
+                       NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
 
        /* Check special features of the file system. May request
         * different read/write sizes for file systems known to have
index 702fa577aa6e075a6fef3a9b31be6ffdb1d3a9c5..094747a1227c18b6ace1726d81ed97487c98169a 100644 (file)
@@ -225,7 +225,8 @@ encode_cb_recall(struct xdr_stream *xdr, struct nfs4_cb_recall *cb_rec)
 
        RESERVE_SPACE(12+sizeof(cb_rec->cbr_stateid) + len);
        WRITE32(OP_CB_RECALL);
-       WRITEMEM(&cb_rec->cbr_stateid, sizeof(stateid_t));
+       WRITE32(cb_rec->cbr_stateid.si_generation);
+       WRITEMEM(&cb_rec->cbr_stateid.si_opaque, sizeof(stateid_opaque_t));
        WRITE32(cb_rec->cbr_trunc);
        WRITE32(len);
        WRITEMEM(cb_rec->cbr_fhval, len);
@@ -379,6 +380,7 @@ static int do_probe_callback(void *data)
                .addrsize       = sizeof(addr),
                .timeout        = &timeparms,
                .program        = &cb_program,
+               .prognumber     = cb->cb_prog,
                .version        = nfs_cb_version[1]->number,
                .authflavor     = RPC_AUTH_UNIX, /* XXX: need AUTH_GSS... */
                .flags          = (RPC_CLNT_CREATE_NOPING | RPC_CLNT_CREATE_QUIET),
@@ -396,9 +398,6 @@ static int do_probe_callback(void *data)
        addr.sin_port = htons(cb->cb_port);
        addr.sin_addr.s_addr = htonl(cb->cb_addr);
 
-       /* Initialize rpc_stat */
-       memset(args.program->stats, 0, sizeof(struct rpc_stat));
-
        /* Create RPC client */
        client = rpc_create(&args);
        if (IS_ERR(client)) {
index e5b51ffafc6c2c2300fb61f3fb0c0036e0762115..669461e291aecbd7f15e2065c61e86f26cd9d2e7 100644 (file)
@@ -201,10 +201,10 @@ nfsd4_open(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        /* Openowner is now set, so sequence id will get bumped.  Now we need
         * these checks before we do any creates: */
        status = nfserr_grace;
-       if (nfs4_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
+       if (locks_in_grace() && open->op_claim_type != NFS4_OPEN_CLAIM_PREVIOUS)
                goto out;
        status = nfserr_no_grace;
-       if (!nfs4_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
+       if (!locks_in_grace() && open->op_claim_type == NFS4_OPEN_CLAIM_PREVIOUS)
                goto out;
 
        switch (open->op_claim_type) {
@@ -575,7 +575,7 @@ nfsd4_remove(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 {
        __be32 status;
 
-       if (nfs4_in_grace())
+       if (locks_in_grace())
                return nfserr_grace;
        status = nfsd_unlink(rqstp, &cstate->current_fh, 0,
                             remove->rm_name, remove->rm_namelen);
@@ -596,7 +596,7 @@ nfsd4_rename(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
 
        if (!cstate->save_fh.fh_dentry)
                return status;
-       if (nfs4_in_grace() && !(cstate->save_fh.fh_export->ex_flags
+       if (locks_in_grace() && !(cstate->save_fh.fh_export->ex_flags
                                        & NFSEXP_NOSUBTREECHECK))
                return nfserr_grace;
        status = nfsd_rename(rqstp, &cstate->save_fh, rename->rn_sname,
index 1578d7a2667ec397f3e0689d1445527cf9a38cf4..0cc7ff5d5ab53e4bf0c0c5e4646cac4012f18165 100644 (file)
@@ -61,7 +61,6 @@
 static time_t lease_time = 90;     /* default lease time */
 static time_t user_lease_time = 90;
 static time_t boot_time;
-static int in_grace = 1;
 static u32 current_ownerid = 1;
 static u32 current_fileid = 1;
 static u32 current_delegid = 1;
@@ -1640,7 +1639,7 @@ nfs4_open_delegation(struct svc_fh *fh, struct nfsd4_open *open, struct nfs4_sta
                case NFS4_OPEN_CLAIM_NULL:
                        /* Let's not give out any delegations till everyone's
                         * had the chance to reclaim theirs.... */
-                       if (nfs4_in_grace())
+                       if (locks_in_grace())
                                goto out;
                        if (!atomic_read(&cb->cb_set) || !sop->so_confirmed)
                                goto out;
@@ -1816,12 +1815,15 @@ out:
        return status;
 }
 
+struct lock_manager nfsd4_manager = {
+};
+
 static void
-end_grace(void)
+nfsd4_end_grace(void)
 {
        dprintk("NFSD: end of grace period\n");
        nfsd4_recdir_purge_old();
-       in_grace = 0;
+       locks_end_grace(&nfsd4_manager);
 }
 
 static time_t
@@ -1838,8 +1840,8 @@ nfs4_laundromat(void)
        nfs4_lock_state();
 
        dprintk("NFSD: laundromat service - starting\n");
-       if (in_grace)
-               end_grace();
+       if (locks_in_grace())
+               nfsd4_end_grace();
        list_for_each_safe(pos, next, &client_lru) {
                clp = list_entry(pos, struct nfs4_client, cl_lru);
                if (time_after((unsigned long)clp->cl_time, (unsigned long)cutoff)) {
@@ -1974,7 +1976,7 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags)
                return nfserr_bad_stateid;
        else if (ONE_STATEID(stateid) && (flags & RD_STATE))
                return nfs_ok;
-       else if (nfs4_in_grace()) {
+       else if (locks_in_grace()) {
                /* Answer in remaining cases depends on existance of
                 * conflicting state; so we must wait out the grace period. */
                return nfserr_grace;
@@ -1993,7 +1995,7 @@ check_special_stateids(svc_fh *current_fh, stateid_t *stateid, int flags)
 static inline int
 io_during_grace_disallowed(struct inode *inode, int flags)
 {
-       return nfs4_in_grace() && (flags & (RD_STATE | WR_STATE))
+       return locks_in_grace() && (flags & (RD_STATE | WR_STATE))
                && mandatory_lock(inode);
 }
 
@@ -2693,10 +2695,10 @@ nfsd4_lock(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        filp = lock_stp->st_vfs_file;
 
        status = nfserr_grace;
-       if (nfs4_in_grace() && !lock->lk_reclaim)
+       if (locks_in_grace() && !lock->lk_reclaim)
                goto out;
        status = nfserr_no_grace;
-       if (!nfs4_in_grace() && lock->lk_reclaim)
+       if (!locks_in_grace() && lock->lk_reclaim)
                goto out;
 
        locks_init_lock(&file_lock);
@@ -2779,7 +2781,7 @@ nfsd4_lockt(struct svc_rqst *rqstp, struct nfsd4_compound_state *cstate,
        int error;
        __be32 status;
 
-       if (nfs4_in_grace())
+       if (locks_in_grace())
                return nfserr_grace;
 
        if (check_lock_length(lockt->lt_offset, lockt->lt_length))
@@ -3192,9 +3194,9 @@ __nfs4_state_start(void)
        unsigned long grace_time;
 
        boot_time = get_seconds();
-       grace_time = get_nfs_grace_period();
+       grace_time = get_nfs4_grace_period();
        lease_time = user_lease_time;
-       in_grace = 1;
+       locks_start_grace(&nfsd4_manager);
        printk(KERN_INFO "NFSD: starting %ld-second grace period\n",
               grace_time/HZ);
        laundry_wq = create_singlethread_workqueue("nfsd4");
@@ -3213,12 +3215,6 @@ nfs4_state_start(void)
        return;
 }
 
-int
-nfs4_in_grace(void)
-{
-       return in_grace;
-}
-
 time_t
 nfs4_lease_time(void)
 {
index 14ba4d9b285913f8aea89eae504908eebc56f435..afcdf4b76843a7219e50c66d3d3dba4dde5ae514 100644 (file)
@@ -412,6 +412,18 @@ out_nfserr:
        goto out;
 }
 
+static __be32
+nfsd4_decode_stateid(struct nfsd4_compoundargs *argp, stateid_t *sid)
+{
+       DECODE_HEAD;
+
+       READ_BUF(sizeof(stateid_t));
+       READ32(sid->si_generation);
+       COPYMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
+
+       DECODE_TAIL;
+}
+
 static __be32
 nfsd4_decode_access(struct nfsd4_compoundargs *argp, struct nfsd4_access *access)
 {
@@ -429,10 +441,9 @@ nfsd4_decode_close(struct nfsd4_compoundargs *argp, struct nfsd4_close *close)
        DECODE_HEAD;
 
        close->cl_stateowner = NULL;
-       READ_BUF(4 + sizeof(stateid_t));
+       READ_BUF(4);
        READ32(close->cl_seqid);
-       READ32(close->cl_stateid.si_generation);
-       COPYMEM(&close->cl_stateid.si_opaque, sizeof(stateid_opaque_t));
+       return nfsd4_decode_stateid(argp, &close->cl_stateid);
 
        DECODE_TAIL;
 }
@@ -493,13 +504,7 @@ nfsd4_decode_create(struct nfsd4_compoundargs *argp, struct nfsd4_create *create
 static inline __be32
 nfsd4_decode_delegreturn(struct nfsd4_compoundargs *argp, struct nfsd4_delegreturn *dr)
 {
-       DECODE_HEAD;
-
-       READ_BUF(sizeof(stateid_t));
-       READ32(dr->dr_stateid.si_generation);
-       COPYMEM(&dr->dr_stateid.si_opaque, sizeof(stateid_opaque_t));
-
-       DECODE_TAIL;
+       return nfsd4_decode_stateid(argp, &dr->dr_stateid);
 }
 
 static inline __be32
@@ -542,20 +547,22 @@ nfsd4_decode_lock(struct nfsd4_compoundargs *argp, struct nfsd4_lock *lock)
        READ32(lock->lk_is_new);
 
        if (lock->lk_is_new) {
-               READ_BUF(36);
+               READ_BUF(4);
                READ32(lock->lk_new_open_seqid);
-               READ32(lock->lk_new_open_stateid.si_generation);
-
-               COPYMEM(&lock->lk_new_open_stateid.si_opaque, sizeof(stateid_opaque_t));
+               status = nfsd4_decode_stateid(argp, &lock->lk_new_open_stateid);
+               if (status)
+                       return status;
+               READ_BUF(8 + sizeof(clientid_t));
                READ32(lock->lk_new_lock_seqid);
                COPYMEM(&lock->lk_new_clientid, sizeof(clientid_t));
                READ32(lock->lk_new_owner.len);
                READ_BUF(lock->lk_new_owner.len);
                READMEM(lock->lk_new_owner.data, lock->lk_new_owner.len);
        } else {
-               READ_BUF(20);
-               READ32(lock->lk_old_lock_stateid.si_generation);
-               COPYMEM(&lock->lk_old_lock_stateid.si_opaque, sizeof(stateid_opaque_t));
+               status = nfsd4_decode_stateid(argp, &lock->lk_old_lock_stateid);
+               if (status)
+                       return status;
+               READ_BUF(4);
                READ32(lock->lk_old_lock_seqid);
        }
 
@@ -587,13 +594,15 @@ nfsd4_decode_locku(struct nfsd4_compoundargs *argp, struct nfsd4_locku *locku)
        DECODE_HEAD;
 
        locku->lu_stateowner = NULL;
-       READ_BUF(24 + sizeof(stateid_t));
+       READ_BUF(8);
        READ32(locku->lu_type);
        if ((locku->lu_type < NFS4_READ_LT) || (locku->lu_type > NFS4_WRITEW_LT))
                goto xdr_error;
        READ32(locku->lu_seqid);
-       READ32(locku->lu_stateid.si_generation);
-       COPYMEM(&locku->lu_stateid.si_opaque, sizeof(stateid_opaque_t));
+       status = nfsd4_decode_stateid(argp, &locku->lu_stateid);
+       if (status)
+               return status;
+       READ_BUF(16);
        READ64(locku->lu_offset);
        READ64(locku->lu_length);
 
@@ -678,8 +687,10 @@ nfsd4_decode_open(struct nfsd4_compoundargs *argp, struct nfsd4_open *open)
                READ32(open->op_delegate_type);
                break;
        case NFS4_OPEN_CLAIM_DELEGATE_CUR:
-               READ_BUF(sizeof(stateid_t) + 4);
-               COPYMEM(&open->op_delegate_stateid, sizeof(stateid_t));
+               status = nfsd4_decode_stateid(argp, &open->op_delegate_stateid);
+               if (status)
+                       return status;
+               READ_BUF(4);
                READ32(open->op_fname.len);
                READ_BUF(open->op_fname.len);
                SAVEMEM(open->op_fname.data, open->op_fname.len);
@@ -699,9 +710,10 @@ nfsd4_decode_open_confirm(struct nfsd4_compoundargs *argp, struct nfsd4_open_con
        DECODE_HEAD;
                    
        open_conf->oc_stateowner = NULL;
-       READ_BUF(4 + sizeof(stateid_t));
-       READ32(open_conf->oc_req_stateid.si_generation);
-       COPYMEM(&open_conf->oc_req_stateid.si_opaque, sizeof(stateid_opaque_t));
+       status = nfsd4_decode_stateid(argp, &open_conf->oc_req_stateid);
+       if (status)
+               return status;
+       READ_BUF(4);
        READ32(open_conf->oc_seqid);
                                                        
        DECODE_TAIL;
@@ -713,9 +725,10 @@ nfsd4_decode_open_downgrade(struct nfsd4_compoundargs *argp, struct nfsd4_open_d
        DECODE_HEAD;
                    
        open_down->od_stateowner = NULL;
-       READ_BUF(12 + sizeof(stateid_t));
-       READ32(open_down->od_stateid.si_generation);
-       COPYMEM(&open_down->od_stateid.si_opaque, sizeof(stateid_opaque_t));
+       status = nfsd4_decode_stateid(argp, &open_down->od_stateid);
+       if (status)
+               return status;
+       READ_BUF(12);
        READ32(open_down->od_seqid);
        READ32(open_down->od_share_access);
        READ32(open_down->od_share_deny);
@@ -743,9 +756,10 @@ nfsd4_decode_read(struct nfsd4_compoundargs *argp, struct nfsd4_read *read)
 {
        DECODE_HEAD;
 
-       READ_BUF(sizeof(stateid_t) + 12);
-       READ32(read->rd_stateid.si_generation);
-       COPYMEM(&read->rd_stateid.si_opaque, sizeof(stateid_opaque_t));
+       status = nfsd4_decode_stateid(argp, &read->rd_stateid);
+       if (status)
+               return status;
+       READ_BUF(12);
        READ64(read->rd_offset);
        READ32(read->rd_length);
 
@@ -834,15 +848,13 @@ nfsd4_decode_secinfo(struct nfsd4_compoundargs *argp,
 static __be32
 nfsd4_decode_setattr(struct nfsd4_compoundargs *argp, struct nfsd4_setattr *setattr)
 {
-       DECODE_HEAD;
-
-       READ_BUF(sizeof(stateid_t));
-       READ32(setattr->sa_stateid.si_generation);
-       COPYMEM(&setattr->sa_stateid.si_opaque, sizeof(stateid_opaque_t));
-       if ((status = nfsd4_decode_fattr(argp, setattr->sa_bmval, &setattr->sa_iattr, &setattr->sa_acl)))
-               goto out;
+       __be32 status;
 
-       DECODE_TAIL;
+       status = nfsd4_decode_stateid(argp, &setattr->sa_stateid);
+       if (status)
+               return status;
+       return nfsd4_decode_fattr(argp, setattr->sa_bmval,
+                                 &setattr->sa_iattr, &setattr->sa_acl);
 }
 
 static __be32
@@ -927,9 +939,10 @@ nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
        int len;
        DECODE_HEAD;
 
-       READ_BUF(sizeof(stateid_opaque_t) + 20);
-       READ32(write->wr_stateid.si_generation);
-       COPYMEM(&write->wr_stateid.si_opaque, sizeof(stateid_opaque_t));
+       status = nfsd4_decode_stateid(argp, &write->wr_stateid);
+       if (status)
+               return status;
+       READ_BUF(16);
        READ64(write->wr_offset);
        READ32(write->wr_stable_how);
        if (write->wr_stable_how > 2)
@@ -1183,7 +1196,6 @@ nfsd4_decode_compound(struct nfsd4_compoundargs *argp)
  * Header routine to setup seqid operation replay cache
  */
 #define ENCODE_SEQID_OP_HEAD                                   \
-       __be32 *p;                                              \
        __be32 *save;                                           \
                                                                \
        save = resp->p;
@@ -1950,6 +1962,17 @@ fail:
        return -EINVAL;
 }
 
+static void
+nfsd4_encode_stateid(struct nfsd4_compoundres *resp, stateid_t *sid)
+{
+       ENCODE_HEAD;
+
+       RESERVE_SPACE(sizeof(stateid_t));
+       WRITE32(sid->si_generation);
+       WRITEMEM(&sid->si_opaque, sizeof(stateid_opaque_t));
+       ADJUST_ARGS();
+}
+
 static __be32
 nfsd4_encode_access(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_access *access)
 {
@@ -1969,12 +1992,9 @@ nfsd4_encode_close(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_c
 {
        ENCODE_SEQID_OP_HEAD;
 
-       if (!nfserr) {
-               RESERVE_SPACE(sizeof(stateid_t));
-               WRITE32(close->cl_stateid.si_generation);
-               WRITEMEM(&close->cl_stateid.si_opaque, sizeof(stateid_opaque_t));
-               ADJUST_ARGS();
-       }
+       if (!nfserr)
+               nfsd4_encode_stateid(resp, &close->cl_stateid);
+
        ENCODE_SEQID_OP_TAIL(close->cl_stateowner);
        return nfserr;
 }
@@ -2074,12 +2094,9 @@ nfsd4_encode_lock(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_lo
 {
        ENCODE_SEQID_OP_HEAD;
 
-       if (!nfserr) {
-               RESERVE_SPACE(4 + sizeof(stateid_t));
-               WRITE32(lock->lk_resp_stateid.si_generation);
-               WRITEMEM(&lock->lk_resp_stateid.si_opaque, sizeof(stateid_opaque_t));
-               ADJUST_ARGS();
-       } else if (nfserr == nfserr_denied)
+       if (!nfserr)
+               nfsd4_encode_stateid(resp, &lock->lk_resp_stateid);
+       else if (nfserr == nfserr_denied)
                nfsd4_encode_lock_denied(resp, &lock->lk_denied);
 
        ENCODE_SEQID_OP_TAIL(lock->lk_replay_owner);
@@ -2099,13 +2116,9 @@ nfsd4_encode_locku(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_l
 {
        ENCODE_SEQID_OP_HEAD;
 
-       if (!nfserr) {
-               RESERVE_SPACE(sizeof(stateid_t));
-               WRITE32(locku->lu_stateid.si_generation);
-               WRITEMEM(&locku->lu_stateid.si_opaque, sizeof(stateid_opaque_t));
-               ADJUST_ARGS();
-       }
-                                       
+       if (!nfserr)
+               nfsd4_encode_stateid(resp, &locku->lu_stateid);
+
        ENCODE_SEQID_OP_TAIL(locku->lu_stateowner);
        return nfserr;
 }
@@ -2128,14 +2141,14 @@ nfsd4_encode_link(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_li
 static __be32
 nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open *open)
 {
+       ENCODE_HEAD;
        ENCODE_SEQID_OP_HEAD;
 
        if (nfserr)
                goto out;
 
-       RESERVE_SPACE(36 + sizeof(stateid_t));
-       WRITE32(open->op_stateid.si_generation);
-       WRITEMEM(&open->op_stateid.si_opaque, sizeof(stateid_opaque_t));
+       nfsd4_encode_stateid(resp, &open->op_stateid);
+       RESERVE_SPACE(40);
        WRITECINFO(open->op_cinfo);
        WRITE32(open->op_rflags);
        WRITE32(2);
@@ -2148,8 +2161,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op
        case NFS4_OPEN_DELEGATE_NONE:
                break;
        case NFS4_OPEN_DELEGATE_READ:
-               RESERVE_SPACE(20 + sizeof(stateid_t));
-               WRITEMEM(&open->op_delegate_stateid, sizeof(stateid_t));
+               nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
+               RESERVE_SPACE(20);
                WRITE32(open->op_recall);
 
                /*
@@ -2162,8 +2175,8 @@ nfsd4_encode_open(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_op
                ADJUST_ARGS();
                break;
        case NFS4_OPEN_DELEGATE_WRITE:
-               RESERVE_SPACE(32 + sizeof(stateid_t));
-               WRITEMEM(&open->op_delegate_stateid, sizeof(stateid_t));
+               nfsd4_encode_stateid(resp, &open->op_delegate_stateid);
+               RESERVE_SPACE(32);
                WRITE32(0);
 
                /*
@@ -2195,13 +2208,9 @@ static __be32
 nfsd4_encode_open_confirm(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_confirm *oc)
 {
        ENCODE_SEQID_OP_HEAD;
-                                       
-       if (!nfserr) {
-               RESERVE_SPACE(sizeof(stateid_t));
-               WRITE32(oc->oc_resp_stateid.si_generation);
-               WRITEMEM(&oc->oc_resp_stateid.si_opaque, sizeof(stateid_opaque_t));
-               ADJUST_ARGS();
-       }
+
+       if (!nfserr)
+               nfsd4_encode_stateid(resp, &oc->oc_resp_stateid);
 
        ENCODE_SEQID_OP_TAIL(oc->oc_stateowner);
        return nfserr;
@@ -2211,13 +2220,9 @@ static __be32
 nfsd4_encode_open_downgrade(struct nfsd4_compoundres *resp, __be32 nfserr, struct nfsd4_open_downgrade *od)
 {
        ENCODE_SEQID_OP_HEAD;
-                                       
-       if (!nfserr) {
-               RESERVE_SPACE(sizeof(stateid_t));
-               WRITE32(od->od_stateid.si_generation);
-               WRITEMEM(&od->od_stateid.si_opaque, sizeof(stateid_opaque_t));
-               ADJUST_ARGS();
-       }
+
+       if (!nfserr)
+               nfsd4_encode_stateid(resp, &od->od_stateid);
 
        ENCODE_SEQID_OP_TAIL(od->od_stateowner);
        return nfserr;
index c53e65f8f3a2b460d6c01424094b29c8082843a4..97543df58242f1bc54244aeac633a4fc2e139c8f 100644 (file)
@@ -614,10 +614,9 @@ static ssize_t __write_ports(struct file *file, char *buf, size_t size)
                        return -EINVAL;
                err = nfsd_create_serv();
                if (!err) {
-                       int proto = 0;
-                       err = svc_addsock(nfsd_serv, fd, buf, &proto);
+                       err = svc_addsock(nfsd_serv, fd, buf);
                        if (err >= 0) {
-                               err = lockd_up(proto);
+                               err = lockd_up();
                                if (err < 0)
                                        svc_sock_names(buf+strlen(buf)+1, nfsd_serv, buf);
                        }
index ea37c96f04454e7f1513ca1222aa4eba86f98fb0..cd25d91895a19fc0906b3e5b1891bed123cff15b 100644 (file)
@@ -302,17 +302,27 @@ fh_verify(struct svc_rqst *rqstp, struct svc_fh *fhp, int type, int access)
        if (error)
                goto out;
 
-       if (!(access & NFSD_MAY_LOCK)) {
-               /*
-                * pseudoflavor restrictions are not enforced on NLM,
-                * which clients virtually always use auth_sys for,
-                * even while using RPCSEC_GSS for NFS.
-                */
-               error = check_nfsd_access(exp, rqstp);
-               if (error)
-                       goto out;
-       }
+       /*
+        * pseudoflavor restrictions are not enforced on NLM,
+        * which clients virtually always use auth_sys for,
+        * even while using RPCSEC_GSS for NFS.
+        */
+       if (access & NFSD_MAY_LOCK)
+               goto skip_pseudoflavor_check;
+       /*
+        * Clients may expect to be able to use auth_sys during mount,
+        * even if they use gss for everything else; see section 2.3.2
+        * of rfc 2623.
+        */
+       if (access & NFSD_MAY_BYPASS_GSS_ON_ROOT
+                       && exp->ex_path.dentry == dentry)
+               goto skip_pseudoflavor_check;
+
+       error = check_nfsd_access(exp, rqstp);
+       if (error)
+               goto out;
 
+skip_pseudoflavor_check:
        /* Finally, check access permissions. */
        error = nfsd_permission(rqstp, exp, dentry, access);
 
index 0766f95d236a23cf73f247bea43e4d0b28c61844..5cffeca7acef326d87a804eeb87e26bc6c11b67e 100644 (file)
@@ -65,7 +65,8 @@ nfsd_proc_getattr(struct svc_rqst *rqstp, struct nfsd_fhandle  *argp,
        dprintk("nfsd: GETATTR  %s\n", SVCFH_fmt(&argp->fh));
 
        fh_copy(&resp->fh, &argp->fh);
-       nfserr = fh_verify(rqstp, &resp->fh, 0, NFSD_MAY_NOP);
+       nfserr = fh_verify(rqstp, &resp->fh, 0,
+                       NFSD_MAY_NOP | NFSD_MAY_BYPASS_GSS_ON_ROOT);
        return nfsd_return_attrs(nfserr, resp);
 }
 
@@ -521,7 +522,8 @@ nfsd_proc_statfs(struct svc_rqst * rqstp, struct nfsd_fhandle   *argp,
 
        dprintk("nfsd: STATFS   %s\n", SVCFH_fmt(&argp->fh));
 
-       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats);
+       nfserr = nfsd_statfs(rqstp, &argp->fh, &resp->stats,
+                       NFSD_MAY_BYPASS_GSS_ON_ROOT);
        fh_put(&argp->fh);
        return nfserr;
 }
index 80292ff5e924a15ff0130866878cf7669cfd041f..59eeb46f82c5e842c528ff63a905347c2015e15e 100644 (file)
@@ -229,6 +229,7 @@ int nfsd_create_serv(void)
 
        atomic_set(&nfsd_busy, 0);
        nfsd_serv = svc_create_pooled(&nfsd_program, nfsd_max_blksize,
+                                     AF_INET,
                                      nfsd_last_thread, nfsd, THIS_MODULE);
        if (nfsd_serv == NULL)
                err = -ENOMEM;
@@ -243,25 +244,20 @@ static int nfsd_init_socks(int port)
        if (!list_empty(&nfsd_serv->sv_permsocks))
                return 0;
 
-       error = lockd_up(IPPROTO_UDP);
-       if (error >= 0) {
-               error = svc_create_xprt(nfsd_serv, "udp", port,
+       error = svc_create_xprt(nfsd_serv, "udp", port,
                                        SVC_SOCK_DEFAULTS);
-               if (error < 0)
-                       lockd_down();
-       }
        if (error < 0)
                return error;
 
-       error = lockd_up(IPPROTO_TCP);
-       if (error >= 0) {
-               error = svc_create_xprt(nfsd_serv, "tcp", port,
+       error = svc_create_xprt(nfsd_serv, "tcp", port,
                                        SVC_SOCK_DEFAULTS);
-               if (error < 0)
-                       lockd_down();
-       }
        if (error < 0)
                return error;
+
+       error = lockd_up();
+       if (error < 0)
+               return error;
+
        return 0;
 }
 
index 18060bed5267451c005345ef19f5a270ee5143aa..aa1d0d6489a119a3e8e00aa301cc9a9719006087 100644 (file)
@@ -83,7 +83,6 @@ struct raparm_hbucket {
        spinlock_t              pb_lock;
 } ____cacheline_aligned_in_smp;
 
-static struct raparms *                raparml;
 #define RAPARM_HASH_BITS       4
 #define RAPARM_HASH_SIZE       (1<<RAPARM_HASH_BITS)
 #define RAPARM_HASH_MASK       (RAPARM_HASH_SIZE-1)
@@ -1866,9 +1865,9 @@ out:
  * N.B. After this call fhp needs an fh_put
  */
 __be32
-nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat)
+nfsd_statfs(struct svc_rqst *rqstp, struct svc_fh *fhp, struct kstatfs *stat, int access)
 {
-       __be32 err = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP);
+       __be32 err = fh_verify(rqstp, fhp, 0, NFSD_MAY_NOP | access);
        if (!err && vfs_statfs(fhp->fh_dentry,stat))
                err = nfserr_io;
        return err;
@@ -1966,11 +1965,20 @@ nfsd_permission(struct svc_rqst *rqstp, struct svc_export *exp,
 void
 nfsd_racache_shutdown(void)
 {
-       if (!raparml)
-               return;
+       struct raparms *raparm, *last_raparm;
+       unsigned int i;
+
        dprintk("nfsd: freeing readahead buffers.\n");
-       kfree(raparml);
-       raparml = NULL;
+
+       for (i = 0; i < RAPARM_HASH_SIZE; i++) {
+               raparm = raparm_hash[i].pb_head;
+               while(raparm) {
+                       last_raparm = raparm;
+                       raparm = raparm->p_next;
+                       kfree(last_raparm);
+               }
+               raparm_hash[i].pb_head = NULL;
+       }
 }
 /*
  * Initialize readahead param cache
@@ -1981,35 +1989,38 @@ nfsd_racache_init(int cache_size)
        int     i;
        int     j = 0;
        int     nperbucket;
+       struct raparms **raparm = NULL;
 
 
-       if (raparml)
+       if (raparm_hash[0].pb_head)
                return 0;
-       if (cache_size < 2*RAPARM_HASH_SIZE)
-               cache_size = 2*RAPARM_HASH_SIZE;
-       raparml = kcalloc(cache_size, sizeof(struct raparms), GFP_KERNEL);
-
-       if (!raparml) {
-               printk(KERN_WARNING
-                       "nfsd: Could not allocate memory read-ahead cache.\n");
-               return -ENOMEM;
-       }
+       nperbucket = DIV_ROUND_UP(cache_size, RAPARM_HASH_SIZE);
+       if (nperbucket < 2)
+               nperbucket = 2;
+       cache_size = nperbucket * RAPARM_HASH_SIZE;
 
        dprintk("nfsd: allocating %d readahead buffers.\n", cache_size);
-       for (i = 0 ; i < RAPARM_HASH_SIZE ; i++) {
-               raparm_hash[i].pb_head = NULL;
+
+       for (i = 0; i < RAPARM_HASH_SIZE; i++) {
                spin_lock_init(&raparm_hash[i].pb_lock);
-       }
-       nperbucket = DIV_ROUND_UP(cache_size, RAPARM_HASH_SIZE);
-       for (i = 0; i < cache_size - 1; i++) {
-               if (i % nperbucket == 0)
-                       raparm_hash[j++].pb_head = raparml + i;
-               if (i % nperbucket < nperbucket-1)
-                       raparml[i].p_next = raparml + i + 1;
+
+               raparm = &raparm_hash[i].pb_head;
+               for (j = 0; j < nperbucket; j++) {
+                       *raparm = kzalloc(sizeof(struct raparms), GFP_KERNEL);
+                       if (!*raparm)
+                               goto out_nomem;
+                       raparm = &(*raparm)->p_next;
+               }
+               *raparm = NULL;
        }
 
        nfsdstats.ra_size = cache_size;
        return 0;
+
+out_nomem:
+       dprintk("nfsd: kmalloc failed, freeing readahead buffers\n");
+       nfsd_racache_shutdown();
+       return -ENOMEM;
 }
 
 #if defined(CONFIG_NFSD_V2_ACL) || defined(CONFIG_NFSD_V3_ACL)
index 66c1ab87656c24adfe3342f702b4243d3c5f02da..b675a49c182333eb6a38c321d288ca9ae6c4f46b 100644 (file)
@@ -683,6 +683,7 @@ static int cmdline_read_proc(char *page, char **start, off_t off,
        return proc_calc_metrics(page, start, off, count, eof, len);
 }
 
+#ifdef CONFIG_FILE_LOCKING
 static int locks_open(struct inode *inode, struct file *filp)
 {
        return seq_open(filp, &locks_seq_operations);
@@ -694,6 +695,7 @@ static const struct file_operations proc_locks_operations = {
        .llseek         = seq_lseek,
        .release        = seq_release,
 };
+#endif /* CONFIG_FILE_LOCKING */
 
 static int execdomains_read_proc(char *page, char **start, off_t off,
                                 int count, int *eof, void *data)
@@ -887,7 +889,9 @@ void __init proc_misc_init(void)
 #ifdef CONFIG_PRINTK
        proc_create("kmsg", S_IRUSR, NULL, &proc_kmsg_operations);
 #endif
+#ifdef CONFIG_FILE_LOCKING
        proc_create("locks", 0, NULL, &proc_locks_operations);
+#endif
        proc_create("devices", 0, NULL, &proc_devinfo_operations);
        proc_create("cpuinfo", 0, NULL, &proc_cpuinfo_operations);
 #ifdef CONFIG_BLOCK
index ecf007df77437cb14396bcd55ad24e9439677d48..1412b4ab202f1e753324e734d42dc92bbb635e7e 100644 (file)
@@ -39,7 +39,6 @@ extern int atari_dont_touch_floppy_select;
 #define MACH_IS_TT     ((atari_mch_cookie >> 16) == ATARI_MCH_TT)
 #define MACH_IS_FALCON ((atari_mch_cookie >> 16) == ATARI_MCH_FALCON)
 #define MACH_IS_MEDUSA (atari_mch_type == ATARI_MACH_MEDUSA)
-#define MACH_IS_HADES  (atari_mch_type == ATARI_MACH_HADES)
 #define MACH_IS_AB40   (atari_mch_type == ATARI_MACH_AB40)
 
 /* values for atari_switches */
index 91f7944333d49d6ce2f861036cddf0492ce76b9c..26f505488c1197dbe004cc6486d8c41c7285ab65 100644 (file)
@@ -74,6 +74,14 @@ extern void dma_sync_single_for_device(struct device *, dma_addr_t, size_t,
 extern void dma_sync_sg_for_device(struct device *, struct scatterlist *, int,
                                   enum dma_data_direction);
 
+static inline void dma_sync_single_range_for_device(struct device *dev,
+               dma_addr_t dma_handle, unsigned long offset, size_t size,
+               enum dma_data_direction direction)
+{
+       /* just sync everything for now */
+       dma_sync_single_for_device(dev, dma_handle, offset + size, direction);
+}
+
 static inline void dma_sync_single_for_cpu(struct device *dev, dma_addr_t handle,
                                           size_t size, enum dma_data_direction dir)
 {
@@ -84,6 +92,14 @@ static inline void dma_sync_sg_for_cpu(struct device *dev, struct scatterlist *s
 {
 }
 
+static inline void dma_sync_single_range_for_cpu(struct device *dev,
+               dma_addr_t dma_handle, unsigned long offset, size_t size,
+               enum dma_data_direction direction)
+{
+       /* just sync everything for now */
+       dma_sync_single_for_cpu(dev, dma_handle, offset + size, direction);
+}
+
 static inline int dma_mapping_error(struct device *dev, dma_addr_t handle)
 {
        return 0;
index d0c9e61e57b448e5aca2f4955467c72d2b3a7758..4240fbc946f86699b4211398c6ced340c9c4a0a8 100644 (file)
 extern int request_dma(unsigned int dmanr, const char * device_id);    /* reserve a DMA channel */
 extern void free_dma(unsigned int dmanr);      /* release it again */
 
-#ifdef CONFIG_PCI
-extern int isa_dma_bridge_buggy;
-#else
 #define isa_dma_bridge_buggy    (0)
-#endif
 
 #endif /* _M68K_DMA_H */
index f8f6b185d793b16d7dfe8781098524ea991ee762..5202f5a5b420acbeaf50868cd604768bbf6f9444 100644 (file)
@@ -31,7 +31,7 @@
  */
 
 /* the following macro is used when enabling interrupts */
-#if defined(MACH_ATARI_ONLY) && !defined(CONFIG_HADES)
+#if defined(MACH_ATARI_ONLY)
        /* block out HSYNC on the atari */
 #define ALLOWINT       (~0x400)
 #define        MAX_NOINT_IPL   3
index 657187f0c7c2f0ef834817e622c330727d2bcd82..9e673e3bd4344ae2947b752deb50e0a58db8bb59 100644 (file)
@@ -7,15 +7,12 @@
  *            - added skeleton for GG-II and Amiga PCMCIA
  * 2/3/01 RZ: - moved a few more defs into raw_io.h
  *
- * inX/outX/readX/writeX should not be used by any driver unless it does
- * ISA or PCI access. Other drivers should use function defined in raw_io.h
+ * inX/outX should not be used by any driver unless it does
+ * ISA access. Other drivers should use function defined in raw_io.h
  * or define its own macros on top of these.
  *
- *    inX(),outX()              are for PCI and ISA I/O
- *    readX(),writeX()          are for PCI memory
+ *    inX(),outX()              are for ISA I/O
  *    isa_readX(),isa_writeX()  are for ISA memory
- *
- * moved mem{cpy,set}_*io inside CONFIG_PCI
  */
 
 #ifndef _IO_H
@@ -256,10 +253,7 @@ static inline void isa_delay(void)
        (ISA_SEX ? raw_outsl(isa_itl(port), (u32 *)(buf), (nr)) :  \
                   raw_outsw_swapw(isa_itw(port), (u16 *)(buf), (nr)<<1))
 
-#endif  /* CONFIG_ISA */
-
 
-#if defined(CONFIG_ISA) && !defined(CONFIG_PCI)
 #define inb     isa_inb
 #define inb_p   isa_inb_p
 #define outb    isa_outb
@@ -282,55 +276,9 @@ static inline void isa_delay(void)
 #define readw   isa_readw
 #define writeb  isa_writeb
 #define writew  isa_writew
-#endif /* CONFIG_ISA */
-
-#if defined(CONFIG_PCI)
-
-#define readl(addr)      in_le32(addr)
-#define writel(val,addr) out_le32((addr),(val))
-
-/* those can be defined for both ISA and PCI - it won't work though */
-#define readb(addr)       in_8(addr)
-#define readw(addr)       in_le16(addr)
-#define writeb(val,addr)  out_8((addr),(val))
-#define writew(val,addr)  out_le16((addr),(val))
 
-#define readb_relaxed(addr) readb(addr)
-#define readw_relaxed(addr) readw(addr)
-#define readl_relaxed(addr) readl(addr)
+#else  /* CONFIG_ISA */
 
-#ifndef CONFIG_ISA
-#define inb(port)      in_8(port)
-#define outb(val,port) out_8((port),(val))
-#define inw(port)      in_le16(port)
-#define outw(val,port) out_le16((port),(val))
-#define inl(port)      in_le32(port)
-#define outl(val,port) out_le32((port),(val))
-
-#else
-/*
- * kernel with both ISA and PCI compiled in, those have
- * conflicting defs for in/out. Simply consider port < 1024
- * ISA and everything else PCI. read,write not defined
- * in this case
- */
-#define inb(port) ((port)<1024 ? isa_inb(port) : in_8(port))
-#define inb_p(port) ((port)<1024 ? isa_inb_p(port) : in_8(port))
-#define inw(port) ((port)<1024 ? isa_inw(port) : in_le16(port))
-#define inw_p(port) ((port)<1024 ? isa_inw_p(port) : in_le16(port))
-#define inl(port) ((port)<1024 ? isa_inl(port) : in_le32(port))
-#define inl_p(port) ((port)<1024 ? isa_inl_p(port) : in_le32(port))
-
-#define outb(val,port) ((port)<1024 ? isa_outb((val),(port)) : out_8((port),(val)))
-#define outb_p(val,port) ((port)<1024 ? isa_outb_p((val),(port)) : out_8((port),(val)))
-#define outw(val,port) ((port)<1024 ? isa_outw((val),(port)) : out_le16((port),(val)))
-#define outw_p(val,port) ((port)<1024 ? isa_outw_p((val),(port)) : out_le16((port),(val)))
-#define outl(val,port) ((port)<1024 ? isa_outl((val),(port)) : out_le32((port),(val)))
-#define outl_p(val,port) ((port)<1024 ? isa_outl_p((val),(port)) : out_le32((port),(val)))
-#endif
-#endif /* CONFIG_PCI */
-
-#if !defined(CONFIG_ISA) && !defined(CONFIG_PCI)
 /*
  * We need to define dummy functions for GENERIC_IOMAP support.
  */
@@ -357,11 +305,11 @@ static inline void isa_delay(void)
 #define writeb(val,addr) out_8((addr),(val))
 #define readw(addr)      in_le16(addr)
 #define writew(val,addr) out_le16((addr),(val))
-#endif
-#if !defined(CONFIG_PCI)
+
+#endif /* CONFIG_ISA */
+
 #define readl(addr)      in_le32(addr)
 #define writel(val,addr) out_le32((addr),(val))
-#endif
 
 #define mmiowb()
 
index 678cb0b52314dac16a1cfb9fc9dbd44b5eeeed16..4ad0aea48ab4e9d2b5c96a278d09c2f3eadb3ce5 100644 (file)
@@ -1,52 +1,7 @@
 #ifndef _ASM_M68K_PCI_H
 #define _ASM_M68K_PCI_H
 
-/*
- * asm-m68k/pci_m68k.h - m68k specific PCI declarations.
- *
- * Written by Wout Klaren.
- */
-
-#include <asm/scatterlist.h>
-
-struct pci_ops;
-
-/*
- * Structure with hardware dependent information and functions of the
- * PCI bus.
- */
-
-struct pci_bus_info
-{
-       /*
-        * Resources of the PCI bus.
-        */
-
-       struct resource mem_space;
-       struct resource io_space;
-
-       /*
-        * System dependent functions.
-        */
-
-       struct pci_ops *m68k_pci_ops;
-
-       void (*fixup)(int pci_modify);
-       void (*conf_device)(struct pci_dev *dev);
-};
-
-#define pcibios_assign_all_busses()    0
-#define pcibios_scan_all_fns(a, b)     0
-
-static inline void pcibios_set_master(struct pci_dev *dev)
-{
-       /* No special bus mastering setup handling */
-}
-
-static inline void pcibios_penalize_isa_irq(int irq, int active)
-{
-       /* We don't do dynamic PCI IRQ allocation */
-}
+#include <asm-generic/pci-dma-compat.h>
 
 /* The PCI address space does equal the physical memory
  * address space.  The networking and block device layers use
index dea32fbc7e51c1c5bc995a1aa69ab57f6b1cf6f5..22ab05c9c52b707a961e456430bd13f6153224f7 100644 (file)
@@ -40,15 +40,9 @@ static inline void *phys_to_virt(unsigned long address)
 
 /*
  * IO bus memory addresses are 1:1 with the physical address,
- * except on the PCI bus of the Hades.
  */
-#ifdef CONFIG_HADES
-#define virt_to_bus(a) (virt_to_phys(a) + (MACH_IS_HADES ? 0x80000000 : 0))
-#define bus_to_virt(a) (phys_to_virt((a) - (MACH_IS_HADES ? 0x80000000 : 0)))
-#else
 #define virt_to_bus virt_to_phys
 #define bus_to_virt phys_to_virt
-#endif
 
 #endif
 #endif
index b03f80a078bee4f8d822dd90fc73545def4adcce..d71f7c0f931b34b63bfacde2b06d19ffc5001616 100644 (file)
@@ -53,7 +53,6 @@ struct vc_data {
        unsigned short  vc_hi_font_mask;        /* [#] Attribute set for upper 256 chars of font or 0 if not supported */
        struct console_font vc_font;            /* Current VC font set */
        unsigned short  vc_video_erase_char;    /* Background erase character */
-       unsigned short  vc_scrl_erase_char;     /* Erase character for scroll */
        /* VT terminal data */
        unsigned int    vc_state;               /* Escape sequence parser state */
        unsigned int    vc_npar,vc_par[NPAR];   /* Parameters of current escape sequence */
index c8cbd90ba3757ace87522db09dc63ff36fbea0a0..6e4ace27027691fa42c4920bcf5bf4e60e12494d 100644 (file)
@@ -62,6 +62,7 @@ typedef enum fe_caps {
        FE_CAN_HIERARCHY_AUTO           = 0x100000,
        FE_CAN_8VSB                     = 0x200000,
        FE_CAN_16VSB                    = 0x400000,
+       FE_HAS_EXTENDED_CAPS            = 0x800000,   // We need more bitspace for newer APIs, indicate this.
        FE_NEEDS_BENDING                = 0x20000000, // not supported anymore, don't use (frontend requires frequency bending)
        FE_CAN_RECOVER                  = 0x40000000, // frontend can recover from a cable unplug automatically
        FE_CAN_MUTE_TS                  = 0x80000000  // frontend can stop spurious TS data output
@@ -147,7 +148,9 @@ typedef enum fe_code_rate {
        FEC_6_7,
        FEC_7_8,
        FEC_8_9,
-       FEC_AUTO
+       FEC_AUTO,
+       FEC_3_5,
+       FEC_9_10,
 } fe_code_rate_t;
 
 
@@ -160,7 +163,10 @@ typedef enum fe_modulation {
        QAM_256,
        QAM_AUTO,
        VSB_8,
-       VSB_16
+       VSB_16,
+       PSK_8,
+       APSK_16,
+       DQPSK,
 } fe_modulation_t;
 
 typedef enum fe_transmit_mode {
@@ -239,6 +245,106 @@ struct dvb_frontend_event {
        struct dvb_frontend_parameters parameters;
 };
 
+/* S2API Commands */
+#define DTV_UNDEFINED          0
+#define DTV_TUNE               1
+#define DTV_CLEAR              2
+#define DTV_FREQUENCY          3
+#define DTV_MODULATION         4
+#define DTV_BANDWIDTH_HZ       5
+#define DTV_INVERSION          6
+#define DTV_DISEQC_MASTER      7
+#define DTV_SYMBOL_RATE                8
+#define DTV_INNER_FEC          9
+#define DTV_VOLTAGE            10
+#define DTV_TONE               11
+#define DTV_PILOT              12
+#define DTV_ROLLOFF            13
+#define DTV_DISEQC_SLAVE_REPLY 14
+
+/* Basic enumeration set for querying unlimited capabilities */
+#define DTV_FE_CAPABILITY_COUNT        15
+#define DTV_FE_CAPABILITY      16
+#define DTV_DELIVERY_SYSTEM    17
+
+#define DTV_API_VERSION                                35
+#define DTV_API_VERSION                                35
+#define DTV_CODE_RATE_HP                       36
+#define DTV_CODE_RATE_LP                       37
+#define DTV_GUARD_INTERVAL                     38
+#define DTV_TRANSMISSION_MODE                  39
+#define DTV_HIERARCHY                          40
+
+#define DTV_MAX_COMMAND                                DTV_HIERARCHY
+
+typedef enum fe_pilot {
+       PILOT_ON,
+       PILOT_OFF,
+       PILOT_AUTO,
+} fe_pilot_t;
+
+typedef enum fe_rolloff {
+       ROLLOFF_35, /* Implied value in DVB-S, default for DVB-S2 */
+       ROLLOFF_20,
+       ROLLOFF_25,
+       ROLLOFF_AUTO,
+} fe_rolloff_t;
+
+typedef enum fe_delivery_system {
+       SYS_UNDEFINED,
+       SYS_DVBC_ANNEX_AC,
+       SYS_DVBC_ANNEX_B,
+       SYS_DVBT,
+       SYS_DVBS,
+       SYS_DVBS2,
+       SYS_DVBH,
+       SYS_ISDBT,
+       SYS_ISDBS,
+       SYS_ISDBC,
+       SYS_ATSC,
+       SYS_ATSCMH,
+       SYS_DMBTH,
+       SYS_CMMB,
+       SYS_DAB,
+} fe_delivery_system_t;
+
+struct dtv_cmds_h {
+       char    *name;          /* A display name for debugging purposes */
+
+       __u32   cmd;            /* A unique ID */
+
+       /* Flags */
+       __u32   set:1;          /* Either a set or get property */
+       __u32   buffer:1;       /* Does this property use the buffer? */
+       __u32   reserved:30;    /* Align */
+};
+
+struct dtv_property {
+       __u32 cmd;
+       __u32 reserved[3];
+       union {
+               __u32 data;
+               struct {
+                       __u8 data[32];
+                       __u32 len;
+                       __u32 reserved1[3];
+                       void *reserved2;
+               } buffer;
+       } u;
+       int result;
+} __attribute__ ((packed));
+
+/* num of properties cannot exceed DTV_IOCTL_MAX_MSGS per ioctl */
+#define DTV_IOCTL_MAX_MSGS 64
+
+struct dtv_properties {
+       __u32 num;
+       struct dtv_property *props;
+};
+
+#define FE_SET_PROPERTY                   _IOW('o', 82, struct dtv_properties)
+#define FE_GET_PROPERTY                   _IOR('o', 83, struct dtv_properties)
+
 
 /**
  * When set, this flag will disable any zigzagging or other "normal" tuning
index 126e0c26cb091aa6a647dd0f8359662d143d3ed8..25b823b81734e969db634b384f5bc52031a4b16e 100644 (file)
@@ -23,7 +23,7 @@
 #ifndef _DVBVERSION_H_
 #define _DVBVERSION_H_
 
-#define DVB_API_VERSION 3
-#define DVB_API_VERSION_MINOR 2
+#define DVB_API_VERSION 5
+#define DVB_API_VERSION_MINOR 0
 
 #endif /*_DVBVERSION_H_*/
index 44e3cb2f1966d86b4a422fa616b97f485a150c95..a6a625be13fce0c66ca8d034ec69a2ca956be356 100644 (file)
@@ -947,6 +947,14 @@ struct lock_manager_operations {
        int (*fl_change)(struct file_lock **, int);
 };
 
+struct lock_manager {
+       struct list_head list;
+};
+
+void locks_start_grace(struct lock_manager *);
+void locks_end_grace(struct lock_manager *);
+int locks_in_grace(void);
+
 /* that will die - we need it for nfs_lock_info */
 #include <linux/nfs_fs_i.h>
 
@@ -988,6 +996,13 @@ struct file_lock {
 
 #include <linux/fcntl.h>
 
+extern void send_sigio(struct fown_struct *fown, int fd, int band);
+
+/* fs/sync.c */
+extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
+                       loff_t endbyte, unsigned int flags);
+
+#ifdef CONFIG_FILE_LOCKING
 extern int fcntl_getlk(struct file *, struct flock __user *);
 extern int fcntl_setlk(unsigned int, struct file *, unsigned int,
                        struct flock __user *);
@@ -998,14 +1013,9 @@ extern int fcntl_setlk64(unsigned int, struct file *, unsigned int,
                        struct flock64 __user *);
 #endif
 
-extern void send_sigio(struct fown_struct *fown, int fd, int band);
 extern int fcntl_setlease(unsigned int fd, struct file *filp, long arg);
 extern int fcntl_getlease(struct file *filp);
 
-/* fs/sync.c */
-extern int do_sync_mapping_range(struct address_space *mapping, loff_t offset,
-                       loff_t endbyte, unsigned int flags);
-
 /* fs/locks.c */
 extern void locks_init_lock(struct file_lock *);
 extern void locks_copy_lock(struct file_lock *, struct file_lock *);
@@ -1028,6 +1038,37 @@ extern int lease_modify(struct file_lock **, int);
 extern int lock_may_read(struct inode *, loff_t start, unsigned long count);
 extern int lock_may_write(struct inode *, loff_t start, unsigned long count);
 extern struct seq_operations locks_seq_operations;
+#else /* !CONFIG_FILE_LOCKING */
+#define fcntl_getlk(a, b) ({ -EINVAL; })
+#define fcntl_setlk(a, b, c, d) ({ -EACCES; })
+#if BITS_PER_LONG == 32
+#define fcntl_getlk64(a, b) ({ -EINVAL; })
+#define fcntl_setlk64(a, b, c, d) ({ -EACCES; })
+#endif
+#define fcntl_setlease(a, b, c) ({ 0; })
+#define fcntl_getlease(a) ({ 0; })
+#define locks_init_lock(a) ({ })
+#define __locks_copy_lock(a, b) ({ })
+#define locks_copy_lock(a, b) ({ })
+#define locks_remove_posix(a, b) ({ })
+#define locks_remove_flock(a) ({ })
+#define posix_test_lock(a, b) ({ 0; })
+#define posix_lock_file(a, b, c) ({ -ENOLCK; })
+#define posix_lock_file_wait(a, b) ({ -ENOLCK; })
+#define posix_unblock_lock(a, b) (-ENOENT)
+#define vfs_test_lock(a, b) ({ 0; })
+#define vfs_lock_file(a, b, c, d) (-ENOLCK)
+#define vfs_cancel_lock(a, b) ({ 0; })
+#define flock_lock_file_wait(a, b) ({ -ENOLCK; })
+#define __break_lease(a, b) ({ 0; })
+#define lease_get_mtime(a, b) ({ })
+#define generic_setlease(a, b, c) ({ -EINVAL; })
+#define vfs_setlease(a, b, c) ({ -EINVAL; })
+#define lease_modify(a, b) ({ -EINVAL; })
+#define lock_may_read(a, b, c) ({ 1; })
+#define lock_may_write(a, b, c) ({ 1; })
+#endif /* !CONFIG_FILE_LOCKING */
+
 
 struct fasync_struct {
        int     magic;
@@ -1575,9 +1616,12 @@ extern int vfs_statfs(struct dentry *, struct kstatfs *);
 /* /sys/fs */
 extern struct kobject *fs_kobj;
 
+extern int rw_verify_area(int, struct file *, loff_t *, size_t);
+
 #define FLOCK_VERIFY_READ  1
 #define FLOCK_VERIFY_WRITE 2
 
+#ifdef CONFIG_FILE_LOCKING
 extern int locks_mandatory_locked(struct inode *);
 extern int locks_mandatory_area(int, struct inode *, struct file *, loff_t, size_t);
 
@@ -1608,8 +1652,6 @@ static inline int locks_verify_locked(struct inode *inode)
        return 0;
 }
 
-extern int rw_verify_area(int, struct file *, loff_t *, size_t);
-
 static inline int locks_verify_truncate(struct inode *inode,
                                    struct file *filp,
                                    loff_t size)
@@ -1630,6 +1672,15 @@ static inline int break_lease(struct inode *inode, unsigned int mode)
                return __break_lease(inode, mode);
        return 0;
 }
+#else /* !CONFIG_FILE_LOCKING */
+#define locks_mandatory_locked(a) ({ 0; })
+#define locks_mandatory_area(a, b, c, d, e) ({ 0; })
+#define __mandatory_lock(a) ({ 0; })
+#define mandatory_lock(a) ({ 0; })
+#define locks_verify_locked(a) ({ 0; })
+#define locks_verify_truncate(a, b, c) ({ 0; })
+#define break_lease(a, b) ({ 0; })
+#endif /* CONFIG_FILE_LOCKING */
 
 /* fs/open.c */
 
index bf34c5f4c0511abc17c664655559918e2da01ef5..493435bcdbe52189c9e55fab95b03a614447a799 100644 (file)
@@ -41,7 +41,6 @@
 #define I2C_DRIVERID_SAA7110   22      /* video decoder                */
 #define I2C_DRIVERID_SAA5249   24      /* SAA5249 and compatibles      */
 #define I2C_DRIVERID_PCF8583   25      /* real time clock              */
-#define I2C_DRIVERID_SAB3036   26      /* SAB3036 tuner                */
 #define I2C_DRIVERID_TDA7432   27      /* Stereo sound processor       */
 #define I2C_DRIVERID_TVMIXER    28      /* Mixer driver for tv cards    */
 #define I2C_DRIVERID_TVAUDIO    29      /* Generic TV sound driver      */
index a9d82d6e6bdd68e05e0e6eb016a619d6526f6ece..c47e371554c1ccb122945ab087eb4c9914480010 100644 (file)
@@ -48,12 +48,6 @@ typedef unsigned char        byte;   /* used everywhere */
 #define ERROR_RESET    3       /* Reset controller every 4th retry */
 #define ERROR_RECAL    1       /* Recalibrate every 2nd retry */
 
-/*
- * state flags
- */
-
-#define DMA_PIO_RETRY  1       /* retrying in PIO */
-
 #define HWIF(drive)            ((ide_hwif_t *)((drive)->hwif))
 #define HWGROUP(drive)         ((ide_hwgroup_t *)(HWIF(drive)->hwgroup))
 
@@ -162,6 +156,8 @@ enum {
  */
 #define REQ_DRIVE_RESET                0x20
 #define REQ_DEVSET_EXEC                0x21
+#define REQ_PARK_HEADS         0x22
+#define REQ_UNPARK_HEADS       0x23
 
 /*
  * Check for an interrupt and acknowledge the interrupt status
@@ -268,8 +264,6 @@ static inline int __ide_default_irq(unsigned long base)
  * set_geometry        : respecify drive geometry
  * recalibrate : seek to cyl 0
  * set_multmode        : set multmode count
- * set_tune    : tune interface for drive
- * serviced    : service command
  * reserved    : unused
  */
 typedef union {
@@ -278,42 +272,10 @@ typedef union {
                unsigned set_geometry   : 1;
                unsigned recalibrate    : 1;
                unsigned set_multmode   : 1;
-               unsigned set_tune       : 1;
-               unsigned serviced       : 1;
-               unsigned reserved       : 3;
+               unsigned reserved       : 5;
        } b;
 } special_t;
 
-/*
- * ATA-IDE Select Register, aka Device-Head
- *
- * head                : always zeros here
- * unit                : drive select number: 0/1
- * bit5                : always 1
- * lba         : using LBA instead of CHS
- * bit7                : always 1
- */
-typedef union {
-       unsigned all                    : 8;
-       struct {
-#if defined(__LITTLE_ENDIAN_BITFIELD)
-               unsigned head           : 4;
-               unsigned unit           : 1;
-               unsigned bit5           : 1;
-               unsigned lba            : 1;
-               unsigned bit7           : 1;
-#elif defined(__BIG_ENDIAN_BITFIELD)
-               unsigned bit7           : 1;
-               unsigned lba            : 1;
-               unsigned bit5           : 1;
-               unsigned unit           : 1;
-               unsigned head           : 4;
-#else
-#error "Please fix <asm/byteorder.h>"
-#endif
-       } b;
-} select_t, ata_select_t;
-
 /*
  * Status returned from various ide_ functions
  */
@@ -322,6 +284,175 @@ typedef enum {
        ide_started,    /* a drive operation was started, handler was set */
 } ide_startstop_t;
 
+enum {
+       IDE_TFLAG_LBA48                 = (1 << 0),
+       IDE_TFLAG_FLAGGED               = (1 << 2),
+       IDE_TFLAG_OUT_DATA              = (1 << 3),
+       IDE_TFLAG_OUT_HOB_FEATURE       = (1 << 4),
+       IDE_TFLAG_OUT_HOB_NSECT         = (1 << 5),
+       IDE_TFLAG_OUT_HOB_LBAL          = (1 << 6),
+       IDE_TFLAG_OUT_HOB_LBAM          = (1 << 7),
+       IDE_TFLAG_OUT_HOB_LBAH          = (1 << 8),
+       IDE_TFLAG_OUT_HOB               = IDE_TFLAG_OUT_HOB_FEATURE |
+                                         IDE_TFLAG_OUT_HOB_NSECT |
+                                         IDE_TFLAG_OUT_HOB_LBAL |
+                                         IDE_TFLAG_OUT_HOB_LBAM |
+                                         IDE_TFLAG_OUT_HOB_LBAH,
+       IDE_TFLAG_OUT_FEATURE           = (1 << 9),
+       IDE_TFLAG_OUT_NSECT             = (1 << 10),
+       IDE_TFLAG_OUT_LBAL              = (1 << 11),
+       IDE_TFLAG_OUT_LBAM              = (1 << 12),
+       IDE_TFLAG_OUT_LBAH              = (1 << 13),
+       IDE_TFLAG_OUT_TF                = IDE_TFLAG_OUT_FEATURE |
+                                         IDE_TFLAG_OUT_NSECT |
+                                         IDE_TFLAG_OUT_LBAL |
+                                         IDE_TFLAG_OUT_LBAM |
+                                         IDE_TFLAG_OUT_LBAH,
+       IDE_TFLAG_OUT_DEVICE            = (1 << 14),
+       IDE_TFLAG_WRITE                 = (1 << 15),
+       IDE_TFLAG_FLAGGED_SET_IN_FLAGS  = (1 << 16),
+       IDE_TFLAG_IN_DATA               = (1 << 17),
+       IDE_TFLAG_CUSTOM_HANDLER        = (1 << 18),
+       IDE_TFLAG_DMA_PIO_FALLBACK      = (1 << 19),
+       IDE_TFLAG_IN_HOB_FEATURE        = (1 << 20),
+       IDE_TFLAG_IN_HOB_NSECT          = (1 << 21),
+       IDE_TFLAG_IN_HOB_LBAL           = (1 << 22),
+       IDE_TFLAG_IN_HOB_LBAM           = (1 << 23),
+       IDE_TFLAG_IN_HOB_LBAH           = (1 << 24),
+       IDE_TFLAG_IN_HOB_LBA            = IDE_TFLAG_IN_HOB_LBAL |
+                                         IDE_TFLAG_IN_HOB_LBAM |
+                                         IDE_TFLAG_IN_HOB_LBAH,
+       IDE_TFLAG_IN_HOB                = IDE_TFLAG_IN_HOB_FEATURE |
+                                         IDE_TFLAG_IN_HOB_NSECT |
+                                         IDE_TFLAG_IN_HOB_LBA,
+       IDE_TFLAG_IN_FEATURE            = (1 << 1),
+       IDE_TFLAG_IN_NSECT              = (1 << 25),
+       IDE_TFLAG_IN_LBAL               = (1 << 26),
+       IDE_TFLAG_IN_LBAM               = (1 << 27),
+       IDE_TFLAG_IN_LBAH               = (1 << 28),
+       IDE_TFLAG_IN_LBA                = IDE_TFLAG_IN_LBAL |
+                                         IDE_TFLAG_IN_LBAM |
+                                         IDE_TFLAG_IN_LBAH,
+       IDE_TFLAG_IN_TF                 = IDE_TFLAG_IN_NSECT |
+                                         IDE_TFLAG_IN_LBA,
+       IDE_TFLAG_IN_DEVICE             = (1 << 29),
+       IDE_TFLAG_HOB                   = IDE_TFLAG_OUT_HOB |
+                                         IDE_TFLAG_IN_HOB,
+       IDE_TFLAG_TF                    = IDE_TFLAG_OUT_TF |
+                                         IDE_TFLAG_IN_TF,
+       IDE_TFLAG_DEVICE                = IDE_TFLAG_OUT_DEVICE |
+                                         IDE_TFLAG_IN_DEVICE,
+       /* force 16-bit I/O operations */
+       IDE_TFLAG_IO_16BIT              = (1 << 30),
+       /* ide_task_t was allocated using kmalloc() */
+       IDE_TFLAG_DYN                   = (1 << 31),
+};
+
+struct ide_taskfile {
+       u8      hob_data;       /*  0: high data byte (for TASKFILE IOCTL) */
+
+       u8      hob_feature;    /*  1-5: additional data to support LBA48 */
+       u8      hob_nsect;
+       u8      hob_lbal;
+       u8      hob_lbam;
+       u8      hob_lbah;
+
+       u8      data;           /*  6: low data byte (for TASKFILE IOCTL) */
+
+       union {                 /* Â 7: */
+               u8 error;       /*   read:  error */
+               u8 feature;     /*  write: feature */
+       };
+
+       u8      nsect;          /*  8: number of sectors */
+       u8      lbal;           /*  9: LBA low */
+       u8      lbam;           /* 10: LBA mid */
+       u8      lbah;           /* 11: LBA high */
+
+       u8      device;         /* 12: device select */
+
+       union {                 /* 13: */
+               u8 status;      /* Â read: status Â */
+               u8 command;     /* write: command */
+       };
+};
+
+typedef struct ide_task_s {
+       union {
+               struct ide_taskfile     tf;
+               u8                      tf_array[14];
+       };
+       u32                     tf_flags;
+       int                     data_phase;
+       struct request          *rq;            /* copy of request */
+       void                    *special;       /* valid_t generally */
+} ide_task_t;
+
+/* ATAPI packet command flags */
+enum {
+       /* set when an error is considered normal - no retry (ide-tape) */
+       PC_FLAG_ABORT                   = (1 << 0),
+       PC_FLAG_SUPPRESS_ERROR          = (1 << 1),
+       PC_FLAG_WAIT_FOR_DSC            = (1 << 2),
+       PC_FLAG_DMA_OK                  = (1 << 3),
+       PC_FLAG_DMA_IN_PROGRESS         = (1 << 4),
+       PC_FLAG_DMA_ERROR               = (1 << 5),
+       PC_FLAG_WRITING                 = (1 << 6),
+       /* command timed out */
+       PC_FLAG_TIMEDOUT                = (1 << 7),
+};
+
+/*
+ * With each packet command, we allocate a buffer of IDE_PC_BUFFER_SIZE bytes.
+ * This is used for several packet commands (not for READ/WRITE commands).
+ */
+#define IDE_PC_BUFFER_SIZE     256
+
+struct ide_atapi_pc {
+       /* actual packet bytes */
+       u8 c[12];
+       /* incremented on each retry */
+       int retries;
+       int error;
+
+       /* bytes to transfer */
+       int req_xfer;
+       /* bytes actually transferred */
+       int xferred;
+
+       /* data buffer */
+       u8 *buf;
+       /* current buffer position */
+       u8 *cur_pos;
+       int buf_size;
+       /* missing/available data on the current buffer */
+       int b_count;
+
+       /* the corresponding request */
+       struct request *rq;
+
+       unsigned long flags;
+
+       /*
+        * those are more or less driver-specific and some of them are subject
+        * to change/removal later.
+        */
+       u8 pc_buf[IDE_PC_BUFFER_SIZE];
+
+       /* idetape only */
+       struct idetape_bh *bh;
+       char *b_data;
+
+       /* idescsi only for now */
+       struct scatterlist *sg;
+       unsigned int sg_cnt;
+
+       struct scsi_cmnd *scsi_cmd;
+       void (*done) (struct scsi_cmnd *);
+
+       unsigned long timeout;
+};
+
 struct ide_devset;
 struct ide_driver_s;
 
@@ -394,6 +525,62 @@ enum {
        IDE_AFLAG_NO_AUTOCLOSE          = (1 << 29),
 };
 
+/* device flags */
+enum {
+       /* restore settings after device reset */
+       IDE_DFLAG_KEEP_SETTINGS         = (1 << 0),
+       /* device is using DMA for read/write */
+       IDE_DFLAG_USING_DMA             = (1 << 1),
+       /* okay to unmask other IRQs */
+       IDE_DFLAG_UNMASK                = (1 << 2),
+       /* don't attempt flushes */
+       IDE_DFLAG_NOFLUSH               = (1 << 3),
+       /* DSC overlap */
+       IDE_DFLAG_DSC_OVERLAP           = (1 << 4),
+       /* give potential excess bandwidth */
+       IDE_DFLAG_NICE1                 = (1 << 5),
+       /* device is physically present */
+       IDE_DFLAG_PRESENT               = (1 << 6),
+       /* device ejected hint */
+       IDE_DFLAG_DEAD                  = (1 << 7),
+       /* id read from device (synthetic if not set) */
+       IDE_DFLAG_ID_READ               = (1 << 8),
+       IDE_DFLAG_NOPROBE               = (1 << 9),
+       /* need to do check_media_change() */
+       IDE_DFLAG_REMOVABLE             = (1 << 10),
+       /* needed for removable devices */
+       IDE_DFLAG_ATTACH                = (1 << 11),
+       IDE_DFLAG_FORCED_GEOM           = (1 << 12),
+       /* disallow setting unmask bit */
+       IDE_DFLAG_NO_UNMASK             = (1 << 13),
+       /* disallow enabling 32-bit I/O */
+       IDE_DFLAG_NO_IO_32BIT           = (1 << 14),
+       /* for removable only: door lock/unlock works */
+       IDE_DFLAG_DOORLOCKING           = (1 << 15),
+       /* disallow DMA */
+       IDE_DFLAG_NODMA                 = (1 << 16),
+       /* powermanagment told us not to do anything, so sleep nicely */
+       IDE_DFLAG_BLOCKED               = (1 << 17),
+       /* ide-scsi emulation */
+       IDE_DFLAG_SCSI                  = (1 << 18),
+       /* sleeping & sleep field valid */
+       IDE_DFLAG_SLEEPING              = (1 << 19),
+       IDE_DFLAG_POST_RESET            = (1 << 20),
+       IDE_DFLAG_UDMA33_WARNED         = (1 << 21),
+       IDE_DFLAG_LBA48                 = (1 << 22),
+       /* status of write cache */
+       IDE_DFLAG_WCACHE                = (1 << 23),
+       /* used for ignoring ATA_DF */
+       IDE_DFLAG_NOWERR                = (1 << 24),
+       /* retrying in PIO */
+       IDE_DFLAG_DMA_PIO_RETRY         = (1 << 25),
+       IDE_DFLAG_LBA                   = (1 << 26),
+       /* don't unload heads */
+       IDE_DFLAG_NO_UNLOAD             = (1 << 27),
+       /* heads unloaded, please don't reset port */
+       IDE_DFLAG_PARKED                = (1 << 28)
+};
+
 struct ide_drive_s {
        char            name[4];        /* drive name, such as "hda" */
         char            driver_req[10];        /* requests specific driver */
@@ -410,43 +597,19 @@ struct ide_drive_s {
 #endif
        struct hwif_s           *hwif;  /* actually (ide_hwif_t *) */
 
+       unsigned long dev_flags;
+
        unsigned long sleep;            /* sleep until this time */
        unsigned long service_start;    /* time we started last request */
        unsigned long service_time;     /* service time of last request */
        unsigned long timeout;          /* max time to wait for irq */
 
        special_t       special;        /* special action flags */
-       select_t        select;         /* basic drive/head select reg value */
 
+       u8      select;                 /* basic drive/head select reg value */
        u8      retry_pio;              /* retrying dma capable host in pio */
-       u8      state;                  /* retry state */
        u8      waiting_for_dma;        /* dma currently in progress */
-
-       unsigned keep_settings  : 1;    /* restore settings after drive reset */
-       unsigned using_dma      : 1;    /* disk is using dma for read/write */
-       unsigned unmask         : 1;    /* okay to unmask other irqs */
-       unsigned noflush        : 1;    /* don't attempt flushes */
-       unsigned dsc_overlap    : 1;    /* DSC overlap */
-       unsigned nice1          : 1;    /* give potential excess bandwidth */
-       unsigned present        : 1;    /* drive is physically present */
-       unsigned dead           : 1;    /* device ejected hint */
-       unsigned id_read        : 1;    /* 1=id read from disk 0 = synthetic */
-       unsigned noprobe        : 1;    /* from:  hdx=noprobe */
-       unsigned removable      : 1;    /* 1 if need to do check_media_change */
-       unsigned attach         : 1;    /* needed for removable devices */
-       unsigned forced_geom    : 1;    /* 1 if hdx=c,h,s was given at boot */
-       unsigned no_unmask      : 1;    /* disallow setting unmask bit */
-       unsigned no_io_32bit    : 1;    /* disallow enabling 32bit I/O */
-       unsigned doorlocking    : 1;    /* for removable only: door lock/unlock works */
-       unsigned nodma          : 1;    /* disallow DMA */
-       unsigned blocked        : 1;    /* 1=powermanagment told us not to do anything, so sleep nicely */
-       unsigned scsi           : 1;    /* 0=default, 1=ide-scsi emulation */
-       unsigned sleeping       : 1;    /* 1=sleeping & sleep field valid */
-       unsigned post_reset     : 1;
-       unsigned udma33_warned  : 1;
-       unsigned addressing     : 2;    /* 0=28-bit, 1=48-bit, 2=48-bit doing 28-bit */
-       unsigned wcache         : 1;    /* status of write cache */
-       unsigned nowerr         : 1;    /* used for ignoring ATA_DF */
+       u8      dma;                    /* atapi dma flag */
 
         u8     quirk_list;     /* considered quirky, set for a specific host */
         u8     init_speed;     /* transfer rate set at boot */
@@ -458,7 +621,6 @@ struct ide_drive_s {
        u8      ready_stat;     /* min status value for drive ready */
        u8      mult_count;     /* current multiple sector setting */
        u8      mult_req;       /* requested multiple sector setting */
-       u8      tune_req;       /* requested drive tuning setting */
        u8      io_32bit;       /* 0=16-bit, 1=32-bit, 2/3=32bit+sync */
        u8      bad_wstat;      /* used for ignoring ATA_DF */
        u8      head;           /* "real" number of heads */
@@ -466,6 +628,9 @@ struct ide_drive_s {
        u8      bios_head;      /* BIOS/fdisk/LILO number of heads */
        u8      bios_sect;      /* BIOS/fdisk/LILO sectors per track */
 
+       /* delay this long before sending packet command */
+       u8 pc_delay;
+
        unsigned int    bios_cyl;       /* BIOS/fdisk/LILO number of cyls */
        unsigned int    cyl;            /* "real" number of cyls */
        unsigned int    drive_data;     /* used by set_pio_mode/selectproc */
@@ -477,6 +642,9 @@ struct ide_drive_s {
 
        int             lun;            /* logical unit */
        int             crc_count;      /* crc counter to reduce drive speed */
+
+       unsigned long   debug_mask;     /* debugging levels switch */
+
 #ifdef CONFIG_BLK_DEV_IDEACPI
        struct ide_acpi_drive_link *acpidata;
 #endif
@@ -484,17 +652,32 @@ struct ide_drive_s {
        struct device   gendev;
        struct completion gendev_rel_comp;      /* to deal with device release() */
 
+       /* current packet command */
+       struct ide_atapi_pc *pc;
+
        /* callback for packet commands */
-       void (*pc_callback)(struct ide_drive_s *);
+       void (*pc_callback)(struct ide_drive_s *, int);
+
+       void (*pc_update_buffers)(struct ide_drive_s *, struct ide_atapi_pc *);
+       int  (*pc_io_buffers)(struct ide_drive_s *, struct ide_atapi_pc *,
+                             unsigned int, int);
 
        unsigned long atapi_flags;
+
+       struct ide_atapi_pc request_sense_pc;
+       struct request request_sense_rq;
 };
 
 typedef struct ide_drive_s ide_drive_t;
 
-#define to_ide_device(dev)container_of(dev, ide_drive_t, gendev)
+#define to_ide_device(dev)             container_of(dev, ide_drive_t, gendev)
+
+#define to_ide_drv(obj, cont_type)     \
+       container_of(obj, struct cont_type, kref)
+
+#define ide_drv_g(disk, cont_type)     \
+       container_of((disk)->private_data, struct cont_type, driver)
 
-struct ide_task_s;
 struct ide_port_info;
 
 struct ide_tp_ops {
@@ -528,6 +711,7 @@ extern const struct ide_tp_ops default_tp_ops;
  * @resetproc:         routine to reset controller after a disk reset
  * @maskproc:          special host masking for drive selection
  * @quirkproc:         check host's drive quirk list
+ * @clear_irq:         clear IRQ
  *
  * @mdma_filter:       filter MDMA modes
  * @udma_filter:       filter UDMA modes
@@ -544,6 +728,7 @@ struct ide_port_ops {
        void    (*resetproc)(ide_drive_t *);
        void    (*maskproc)(ide_drive_t *, int);
        void    (*quirkproc)(ide_drive_t *);
+       void    (*clear_irq)(ide_drive_t *);
 
        u8      (*mdma_filter)(ide_drive_t *);
        u8      (*udma_filter)(ide_drive_t *);
@@ -606,12 +791,16 @@ typedef struct hwif_s {
        const struct ide_port_ops       *port_ops;
        const struct ide_dma_ops        *dma_ops;
 
-       void (*ide_dma_clear_irq)(ide_drive_t *drive);
-
        /* dma physical region descriptor table (cpu view) */
        unsigned int    *dmatable_cpu;
        /* dma physical region descriptor table (dma view) */
        dma_addr_t      dmatable_dma;
+
+       /* maximum number of PRD table entries */
+       int prd_max_nents;
+       /* PRD entry size in bytes */
+       int prd_ent_size;
+
        /* Scatter-gather list used to build the above */
        struct scatterlist *sg_table;
        int sg_max_nents;               /* Maximum number of entries in it */
@@ -621,6 +810,8 @@ typedef struct hwif_s {
        /* data phase of the active command (currently only valid for PIO/DMA) */
        int             data_phase;
 
+       struct ide_task_s task;         /* current command */
+
        unsigned int nsect;
        unsigned int nleft;
        struct scatterlist *cursg;
@@ -649,15 +840,15 @@ typedef struct hwif_s {
 
        void            *hwif_data;     /* extra hwif data */
 
-       unsigned dma;
-
 #ifdef CONFIG_BLK_DEV_IDEACPI
        struct ide_acpi_hwif_link *acpidata;
 #endif
 } ____cacheline_internodealigned_in_smp ide_hwif_t;
 
+#define MAX_HOST_PORTS 4
+
 struct ide_host {
-       ide_hwif_t      *ports[MAX_HWIFS];
+       ide_hwif_t      *ports[MAX_HOST_PORTS];
        unsigned int    n_ports;
        struct device   *dev[2];
        unsigned int    (*init_chipset)(struct pci_dev *);
@@ -739,6 +930,22 @@ static int set_##name(ide_drive_t *drive, int arg) \
        return 0; \
 }
 
+#define ide_devset_get_flag(name, flag) \
+static int get_##name(ide_drive_t *drive) \
+{ \
+       return !!(drive->dev_flags & flag); \
+}
+
+#define ide_devset_set_flag(name, flag) \
+static int set_##name(ide_drive_t *drive, int arg) \
+{ \
+       if (arg) \
+               drive->dev_flags |= flag; \
+       else \
+               drive->dev_flags &= ~flag; \
+       return 0; \
+}
+
 #define __IDE_DEVSET(_name, _flags, _get, _set) \
 const struct ide_devset ide_devset_##_name = \
        __DEVSET(_flags, _get, _set)
@@ -752,8 +959,11 @@ IDE_DEVSET(_name, 0, get_##_func, set_##_func)
 #define ide_devset_w(_name, _func) \
 IDE_DEVSET(_name, 0, NULL, set_##_func)
 
-#define ide_devset_rw_sync(_name, _func) \
-IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
+#define ide_ext_devset_rw(_name, _func) \
+__IDE_DEVSET(_name, 0, get_##_func, set_##_func)
+
+#define ide_ext_devset_rw_sync(_name, _func) \
+__IDE_DEVSET(_name, DS_SYNC, get_##_func, set_##_func)
 
 #define ide_decl_devset(_name) \
 extern const struct ide_devset ide_devset_##_name
@@ -764,71 +974,6 @@ ide_decl_devset(pio_mode);
 ide_decl_devset(unmaskirq);
 ide_decl_devset(using_dma);
 
-/* ATAPI packet command flags */
-enum {
-       /* set when an error is considered normal - no retry (ide-tape) */
-       PC_FLAG_ABORT                   = (1 << 0),
-       PC_FLAG_SUPPRESS_ERROR          = (1 << 1),
-       PC_FLAG_WAIT_FOR_DSC            = (1 << 2),
-       PC_FLAG_DMA_OK                  = (1 << 3),
-       PC_FLAG_DMA_IN_PROGRESS         = (1 << 4),
-       PC_FLAG_DMA_ERROR               = (1 << 5),
-       PC_FLAG_WRITING                 = (1 << 6),
-       /* command timed out */
-       PC_FLAG_TIMEDOUT                = (1 << 7),
-};
-
-/*
- * With each packet command, we allocate a buffer of IDE_PC_BUFFER_SIZE bytes.
- * This is used for several packet commands (not for READ/WRITE commands).
- */
-#define IDE_PC_BUFFER_SIZE     256
-
-struct ide_atapi_pc {
-       /* actual packet bytes */
-       u8 c[12];
-       /* incremented on each retry */
-       int retries;
-       int error;
-
-       /* bytes to transfer */
-       int req_xfer;
-       /* bytes actually transferred */
-       int xferred;
-
-       /* data buffer */
-       u8 *buf;
-       /* current buffer position */
-       u8 *cur_pos;
-       int buf_size;
-       /* missing/available data on the current buffer */
-       int b_count;
-
-       /* the corresponding request */
-       struct request *rq;
-
-       unsigned long flags;
-
-       /*
-        * those are more or less driver-specific and some of them are subject
-        * to change/removal later.
-        */
-       u8 pc_buf[IDE_PC_BUFFER_SIZE];
-
-       /* idetape only */
-       struct idetape_bh *bh;
-       char *b_data;
-
-       /* idescsi only for now */
-       struct scatterlist *sg;
-       unsigned int sg_cnt;
-
-       struct scsi_cmnd *scsi_cmd;
-       void (*done) (struct scsi_cmnd *);
-
-       unsigned long timeout;
-};
-
 #ifdef CONFIG_IDE_PROC_FS
 /*
  * /proc/ide interface
@@ -839,6 +984,11 @@ ide_devset_get(_name, _field); \
 ide_devset_set(_name, _field); \
 IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
 
+#define ide_devset_rw_flag(_name, _field) \
+ide_devset_get_flag(_name, _field); \
+ide_devset_set_flag(_name, _field); \
+IDE_DEVSET(_name, DS_SYNC, get_##_name, set_##_name)
+
 struct ide_proc_devset {
        const char              *name;
        const struct ide_devset *setting;
@@ -905,37 +1055,55 @@ static inline void ide_proc_unregister_driver(ide_drive_t *drive, ide_driver_t *
 #define PROC_IDE_READ_RETURN(page,start,off,count,eof,len) return 0;
 #endif
 
+enum {
+       /* enter/exit functions */
+       IDE_DBG_FUNC =                  (1 << 0),
+       /* sense key/asc handling */
+       IDE_DBG_SENSE =                 (1 << 1),
+       /* packet commands handling */
+       IDE_DBG_PC =                    (1 << 2),
+       /* request handling */
+       IDE_DBG_RQ =                    (1 << 3),
+       /* driver probing/setup */
+       IDE_DBG_PROBE =                 (1 << 4),
+};
+
+/* DRV_NAME has to be defined in the driver before using the macro below */
+#define __ide_debug_log(lvl, fmt, args...)                     \
+{                                                              \
+       if (unlikely(drive->debug_mask & lvl))                  \
+               printk(KERN_INFO DRV_NAME ": " fmt, ## args);   \
+}
+
 /*
- * Power Management step value (rq->pm->pm_step).
- *
- * The step value starts at 0 (ide_pm_state_start_suspend) for a
- * suspend operation or 1000 (ide_pm_state_start_resume) for a
- * resume operation.
+ * Power Management state machine (rq->pm->pm_step).
  *
- * For each step, the core calls the subdriver start_power_step() first.
+ * For each step, the core calls ide_start_power_step() first.
  * This can return:
  *     - ide_stopped : In this case, the core calls us back again unless
  *                     step have been set to ide_power_state_completed.
  *     - ide_started : In this case, the channel is left busy until an
  *                     async event (interrupt) occurs.
- * Typically, start_power_step() will issue a taskfile request with
+ * Typically, ide_start_power_step() will issue a taskfile request with
  * do_rw_taskfile().
  *
- * Upon reception of the interrupt, the core will call complete_power_step()
+ * Upon reception of the interrupt, the core will call ide_complete_power_step()
  * with the error code if any. This routine should update the step value
  * and return. It should not start a new request. The core will call
- * start_power_step for the new step value, unless step have been set to
- * ide_power_state_completed.
- *
- * Subdrivers are expected to define their own additional power
- * steps from 1..999 for suspend and from 1001..1999 for resume,
- * other values are reserved for future use.
+ * ide_start_power_step() for the new step value, unless step have been
+ * set to IDE_PM_COMPLETED.
  */
-
 enum {
-       ide_pm_state_completed          = -1,
-       ide_pm_state_start_suspend      = 0,
-       ide_pm_state_start_resume       = 1000,
+       IDE_PM_START_SUSPEND,
+       IDE_PM_FLUSH_CACHE      = IDE_PM_START_SUSPEND,
+       IDE_PM_STANDBY,
+
+       IDE_PM_START_RESUME,
+       IDE_PM_RESTORE_PIO      = IDE_PM_START_RESUME,
+       IDE_PM_IDLE,
+       IDE_PM_RESTORE_DMA,
+
+       IDE_PM_COMPLETED,
 };
 
 /*
@@ -946,7 +1114,6 @@ enum {
  */
 struct ide_driver_s {
        const char                      *version;
-       u8                              media;
        ide_startstop_t (*do_request)(ide_drive_t *, struct request *, sector_t);
        int             (*end_request)(ide_drive_t *, int, int);
        ide_startstop_t (*error)(ide_drive_t *, struct request *rq, u8, u8);
@@ -1015,110 +1182,6 @@ extern void ide_do_drive_cmd(ide_drive_t *, struct request *);
 
 extern void ide_end_drive_cmd(ide_drive_t *, u8, u8);
 
-enum {
-       IDE_TFLAG_LBA48                 = (1 << 0),
-       IDE_TFLAG_FLAGGED               = (1 << 2),
-       IDE_TFLAG_OUT_DATA              = (1 << 3),
-       IDE_TFLAG_OUT_HOB_FEATURE       = (1 << 4),
-       IDE_TFLAG_OUT_HOB_NSECT         = (1 << 5),
-       IDE_TFLAG_OUT_HOB_LBAL          = (1 << 6),
-       IDE_TFLAG_OUT_HOB_LBAM          = (1 << 7),
-       IDE_TFLAG_OUT_HOB_LBAH          = (1 << 8),
-       IDE_TFLAG_OUT_HOB               = IDE_TFLAG_OUT_HOB_FEATURE |
-                                         IDE_TFLAG_OUT_HOB_NSECT |
-                                         IDE_TFLAG_OUT_HOB_LBAL |
-                                         IDE_TFLAG_OUT_HOB_LBAM |
-                                         IDE_TFLAG_OUT_HOB_LBAH,
-       IDE_TFLAG_OUT_FEATURE           = (1 << 9),
-       IDE_TFLAG_OUT_NSECT             = (1 << 10),
-       IDE_TFLAG_OUT_LBAL              = (1 << 11),
-       IDE_TFLAG_OUT_LBAM              = (1 << 12),
-       IDE_TFLAG_OUT_LBAH              = (1 << 13),
-       IDE_TFLAG_OUT_TF                = IDE_TFLAG_OUT_FEATURE |
-                                         IDE_TFLAG_OUT_NSECT |
-                                         IDE_TFLAG_OUT_LBAL |
-                                         IDE_TFLAG_OUT_LBAM |
-                                         IDE_TFLAG_OUT_LBAH,
-       IDE_TFLAG_OUT_DEVICE            = (1 << 14),
-       IDE_TFLAG_WRITE                 = (1 << 15),
-       IDE_TFLAG_FLAGGED_SET_IN_FLAGS  = (1 << 16),
-       IDE_TFLAG_IN_DATA               = (1 << 17),
-       IDE_TFLAG_CUSTOM_HANDLER        = (1 << 18),
-       IDE_TFLAG_DMA_PIO_FALLBACK      = (1 << 19),
-       IDE_TFLAG_IN_HOB_FEATURE        = (1 << 20),
-       IDE_TFLAG_IN_HOB_NSECT          = (1 << 21),
-       IDE_TFLAG_IN_HOB_LBAL           = (1 << 22),
-       IDE_TFLAG_IN_HOB_LBAM           = (1 << 23),
-       IDE_TFLAG_IN_HOB_LBAH           = (1 << 24),
-       IDE_TFLAG_IN_HOB_LBA            = IDE_TFLAG_IN_HOB_LBAL |
-                                         IDE_TFLAG_IN_HOB_LBAM |
-                                         IDE_TFLAG_IN_HOB_LBAH,
-       IDE_TFLAG_IN_HOB                = IDE_TFLAG_IN_HOB_FEATURE |
-                                         IDE_TFLAG_IN_HOB_NSECT |
-                                         IDE_TFLAG_IN_HOB_LBA,
-       IDE_TFLAG_IN_FEATURE            = (1 << 1),
-       IDE_TFLAG_IN_NSECT              = (1 << 25),
-       IDE_TFLAG_IN_LBAL               = (1 << 26),
-       IDE_TFLAG_IN_LBAM               = (1 << 27),
-       IDE_TFLAG_IN_LBAH               = (1 << 28),
-       IDE_TFLAG_IN_LBA                = IDE_TFLAG_IN_LBAL |
-                                         IDE_TFLAG_IN_LBAM |
-                                         IDE_TFLAG_IN_LBAH,
-       IDE_TFLAG_IN_TF                 = IDE_TFLAG_IN_NSECT |
-                                         IDE_TFLAG_IN_LBA,
-       IDE_TFLAG_IN_DEVICE             = (1 << 29),
-       IDE_TFLAG_HOB                   = IDE_TFLAG_OUT_HOB |
-                                         IDE_TFLAG_IN_HOB,
-       IDE_TFLAG_TF                    = IDE_TFLAG_OUT_TF |
-                                         IDE_TFLAG_IN_TF,
-       IDE_TFLAG_DEVICE                = IDE_TFLAG_OUT_DEVICE |
-                                         IDE_TFLAG_IN_DEVICE,
-       /* force 16-bit I/O operations */
-       IDE_TFLAG_IO_16BIT              = (1 << 30),
-       /* ide_task_t was allocated using kmalloc() */
-       IDE_TFLAG_DYN                   = (1 << 31),
-};
-
-struct ide_taskfile {
-       u8      hob_data;       /*  0: high data byte (for TASKFILE IOCTL) */
-
-       u8      hob_feature;    /*  1-5: additional data to support LBA48 */
-       u8      hob_nsect;
-       u8      hob_lbal;
-       u8      hob_lbam;
-       u8      hob_lbah;
-
-       u8      data;           /*  6: low data byte (for TASKFILE IOCTL) */
-
-       union {                 /* Â 7: */
-               u8 error;       /*   read:  error */
-               u8 feature;     /*  write: feature */
-       };
-
-       u8      nsect;          /*  8: number of sectors */
-       u8      lbal;           /*  9: LBA low */
-       u8      lbam;           /* 10: LBA mid */
-       u8      lbah;           /* 11: LBA high */
-
-       u8      device;         /* 12: device select */
-
-       union {                 /* 13: */
-               u8 status;      /* Â read: status Â */
-               u8 command;     /* write: command */
-       };
-};
-
-typedef struct ide_task_s {
-       union {
-               struct ide_taskfile     tf;
-               u8                      tf_array[14];
-       };
-       u32                     tf_flags;
-       int                     data_phase;
-       struct request          *rq;            /* copy of request */
-       void                    *special;       /* valid_t generally */
-} ide_task_t;
-
 void ide_tf_dump(const char *, struct ide_taskfile *);
 
 void ide_exec_command(ide_hwif_t *, u8);
@@ -1150,6 +1213,13 @@ int ide_check_atapi_device(ide_drive_t *, const char *);
 
 void ide_init_pc(struct ide_atapi_pc *);
 
+/* Disk head parking */
+extern wait_queue_head_t ide_park_wq;
+ssize_t ide_park_show(struct device *dev, struct device_attribute *attr,
+                     char *buf);
+ssize_t ide_park_store(struct device *dev, struct device_attribute *attr,
+                      const char *buf, size_t len);
+
 /*
  * Special requests for ide-tape block device strategy routine.
  *
@@ -1163,24 +1233,22 @@ enum {
        REQ_IDETAPE_WRITE       = (1 << 3),
 };
 
-void ide_queue_pc_head(ide_drive_t *, struct gendisk *, struct ide_atapi_pc *,
-                      struct request *);
 int ide_queue_pc_tail(ide_drive_t *, struct gendisk *, struct ide_atapi_pc *);
 
 int ide_do_test_unit_ready(ide_drive_t *, struct gendisk *);
 int ide_do_start_stop(ide_drive_t *, struct gendisk *, int);
 int ide_set_media_lock(ide_drive_t *, struct gendisk *, int);
+void ide_create_request_sense_cmd(ide_drive_t *, struct ide_atapi_pc *);
+void ide_retry_pc(ide_drive_t *, struct gendisk *);
+
+static inline unsigned long ide_scsi_get_timeout(struct ide_atapi_pc *pc)
+{
+       return max_t(unsigned long, WAIT_CMD, pc->timeout - jiffies);
+}
+
+int ide_scsi_expiry(ide_drive_t *);
 
-ide_startstop_t ide_pc_intr(ide_drive_t *drive, struct ide_atapi_pc *pc,
-       ide_handler_t *handler, unsigned int timeout, ide_expiry_t *expiry,
-       void (*update_buffers)(ide_drive_t *, struct ide_atapi_pc *),
-       void (*retry_pc)(ide_drive_t *), void (*dsc_handle)(ide_drive_t *),
-       int (*io_buffers)(ide_drive_t *, struct ide_atapi_pc *, unsigned int,
-                          int));
-ide_startstop_t ide_transfer_pc(ide_drive_t *, struct ide_atapi_pc *,
-                               ide_handler_t *, unsigned int, ide_expiry_t *);
-ide_startstop_t ide_issue_pc(ide_drive_t *, struct ide_atapi_pc *,
-                            ide_handler_t *, unsigned int, ide_expiry_t *);
+ide_startstop_t ide_issue_pc(ide_drive_t *, unsigned int, ide_expiry_t *);
 
 ide_startstop_t do_rw_taskfile(ide_drive_t *, ide_task_t *);
 
@@ -1358,6 +1426,7 @@ struct drive_list_entry {
 int ide_in_drive_list(u16 *, const struct drive_list_entry *);
 
 #ifdef CONFIG_BLK_DEV_IDEDMA
+int ide_dma_good_drive(ide_drive_t *);
 int __ide_dma_bad_drive(ide_drive_t *);
 int ide_id_dma_bug(ide_drive_t *);
 
@@ -1375,25 +1444,29 @@ int ide_set_dma(ide_drive_t *);
 void ide_check_dma_crc(ide_drive_t *);
 ide_startstop_t ide_dma_intr(ide_drive_t *);
 
+int ide_allocate_dma_engine(ide_hwif_t *);
+void ide_release_dma_engine(ide_hwif_t *);
+
 int ide_build_sglist(ide_drive_t *, struct request *);
 void ide_destroy_dmatable(ide_drive_t *);
 
 #ifdef CONFIG_BLK_DEV_IDEDMA_SFF
+int config_drive_for_dma(ide_drive_t *);
 extern int ide_build_dmatable(ide_drive_t *, struct request *);
-int ide_allocate_dma_engine(ide_hwif_t *);
-void ide_release_dma_engine(ide_hwif_t *);
-
 void ide_dma_host_set(ide_drive_t *, int);
 extern int ide_dma_setup(ide_drive_t *);
 void ide_dma_exec_cmd(ide_drive_t *, u8);
 extern void ide_dma_start(ide_drive_t *);
-extern int __ide_dma_end(ide_drive_t *);
+int ide_dma_end(ide_drive_t *);
 int ide_dma_test_irq(ide_drive_t *);
-extern void ide_dma_lost_irq(ide_drive_t *);
-extern void ide_dma_timeout(ide_drive_t *);
 extern const struct ide_dma_ops sff_dma_ops;
+#else
+static inline int config_drive_for_dma(ide_drive_t *drive) { return 0; }
 #endif /* CONFIG_BLK_DEV_IDEDMA_SFF */
 
+void ide_dma_lost_irq(ide_drive_t *);
+void ide_dma_timeout(ide_drive_t *);
+
 #else
 static inline int ide_id_dma_bug(ide_drive_t *drive) { return 0; }
 static inline u8 ide_find_dma_mode(ide_drive_t *drive, u8 speed) { return 0; }
@@ -1404,11 +1477,8 @@ static inline void ide_dma_on(ide_drive_t *drive) { ; }
 static inline void ide_dma_verbose(ide_drive_t *drive) { ; }
 static inline int ide_set_dma(ide_drive_t *drive) { return 1; }
 static inline void ide_check_dma_crc(ide_drive_t *drive) { ; }
-#endif /* CONFIG_BLK_DEV_IDEDMA */
-
-#ifndef CONFIG_BLK_DEV_IDEDMA_SFF
 static inline void ide_release_dma_engine(ide_hwif_t *hwif) { ; }
-#endif
+#endif /* CONFIG_BLK_DEV_IDEDMA */
 
 #ifdef CONFIG_BLK_DEV_IDEACPI
 extern int ide_acpi_exec_tfs(ide_drive_t *drive);
@@ -1436,7 +1506,6 @@ void ide_undecoded_slave(ide_drive_t *);
 
 void ide_port_apply_params(ide_hwif_t *);
 
-struct ide_host *ide_host_alloc_all(const struct ide_port_info *, hw_regs_t **);
 struct ide_host *ide_host_alloc(const struct ide_port_info *, hw_regs_t **);
 void ide_host_free(struct ide_host *);
 int ide_host_register(struct ide_host *, const struct ide_port_info *,
@@ -1547,6 +1616,6 @@ static inline ide_drive_t *ide_get_pair_dev(ide_drive_t *drive)
 {
        ide_drive_t *peer = &drive->hwif->drives[(drive->dn ^ 1) & 1];
 
-       return peer->present ? peer : NULL;
+       return (peer->dev_flags & IDE_DFLAG_PRESENT) ? peer : NULL;
 }
 #endif /* _IDE_H */
index bf1a53b2682ebf6e4231a679d3a857d4a21598a6..7f3c735f422bed8ff1cdeacc9450d61834f8dd19 100644 (file)
@@ -9,7 +9,7 @@
  *
  * Author:     Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Donald Becker, <becker@super.org>
- *             Alan Cox, <alan@redhat.com>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk>
  *
  *             This program is free software; you can redistribute it and/or
index ae77daed6c2feb8e1b2b41a0b1b66e03d6cd9327..45de1046dbbf76db53146961e736dde080c56946 100644 (file)
@@ -12,7 +12,7 @@
  *             if_fddi.h is based on previous if_ether.h and if_tr.h work by
  *                     Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *                     Donald Becker, <becker@super.org>
- *                     Alan Cox, <alan@redhat.com>
+ *                     Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *                     Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk>
  *                     Peter De Schrijver, <stud11@cc4.kuleuven.ac.be>
  *
index 94d31ca7d71a0936c19e066f3c899184b64eaa66..f0f23516bb5982222fcaf0b4677782137e90a5b1 100644 (file)
@@ -9,7 +9,7 @@
  *
  * Author:     Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Donald Becker, <becker@super.org>
- *             Alan Cox, <alan@redhat.com>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Steve Whitehouse, <gw7rrm@eeshack3.swan.ac.uk>
  *             Jes Sorensen, <Jes.Sorensen@cern.ch>
  *
index 7bb3c095c15b4fb33d0ffd227ac9d39f86b9d297..f734a0ba0698b2ddf7ccf58190205f0b0ac60f7c 100644 (file)
@@ -2,7 +2,7 @@
  *     Linux NET3:     Internet Group Management Protocol  [IGMP]
  *
  *     Authors:
- *             Alan Cox <Alan.Cox@linux.org>
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Extended to talk the BSD extended IGMP protocol of mrouted 3.6
  *
index 17ca64b5a66cc253f9284e51e4e8c7c3e8e50544..f2720280b9ec5e12d596baf2e4e8a63a890dc364 100644 (file)
@@ -23,6 +23,7 @@
 
 #include <linux/compiler.h>
 #include <linux/types.h>
+#include <linux/videodev2.h>
 
 /* ivtv knows several distinct output modes: MPEG streaming,
    YUV streaming, YUV updates through user DMA and the passthrough
index 3d25bcd139d166b1173e4691ffa5670c2950cdb1..e5872dc994c0a0761d601229ced0d77676756397 100644 (file)
@@ -27,7 +27,6 @@ struct nlmsvc_binding {
                                                struct nfs_fh *,
                                                struct file **);
        void                    (*fclose)(struct file *);
-       unsigned long           (*get_grace_period)(void);
 };
 
 extern struct nlmsvc_binding * nlmsvc_ops;
@@ -53,15 +52,7 @@ extern void  nlmclnt_done(struct nlm_host *host);
 
 extern int     nlmclnt_proc(struct nlm_host *host, int cmd,
                                        struct file_lock *fl);
-extern int     lockd_up(int proto);
+extern int     lockd_up(void);
 extern void    lockd_down(void);
 
-unsigned long get_nfs_grace_period(void);
-
-#ifdef CONFIG_NFSD_V4
-unsigned long get_nfs4_grace_period(void);
-#else
-static inline unsigned long get_nfs4_grace_period(void) {return 0;}
-#endif
-
 #endif /* LINUX_LOCKD_BIND_H */
index dbb87ab282e8fd55c718939cdcfa34c4adf2439b..b56d5aa9b194c0d87296b303874d331b84246413 100644 (file)
@@ -12,6 +12,8 @@
 #ifdef __KERNEL__
 
 #include <linux/in.h>
+#include <linux/in6.h>
+#include <net/ipv6.h>
 #include <linux/fs.h>
 #include <linux/kref.h>
 #include <linux/utsname.h>
@@ -38,8 +40,9 @@
  */
 struct nlm_host {
        struct hlist_node       h_hash;         /* doubly linked list */
-       struct sockaddr_in      h_addr;         /* peer address */
-       struct sockaddr_in      h_saddr;        /* our address (optional) */
+       struct sockaddr_storage h_addr;         /* peer address */
+       size_t                  h_addrlen;
+       struct sockaddr_storage h_srcaddr;      /* our address (optional) */
        struct rpc_clnt *       h_rpcclnt;      /* RPC client to talk to peer */
        char *                  h_name;         /* remote hostname */
        u32                     h_version;      /* interface version */
@@ -61,17 +64,55 @@ struct nlm_host {
        struct list_head        h_granted;      /* Locks in GRANTED state */
        struct list_head        h_reclaim;      /* Locks in RECLAIM state */
        struct nsm_handle *     h_nsmhandle;    /* NSM status handle */
+
+       char                    h_addrbuf[48],  /* address eyecatchers */
+                               h_srcaddrbuf[48];
 };
 
 struct nsm_handle {
        struct list_head        sm_link;
        atomic_t                sm_count;
        char *                  sm_name;
-       struct sockaddr_in      sm_addr;
+       struct sockaddr_storage sm_addr;
+       size_t                  sm_addrlen;
        unsigned int            sm_monitored : 1,
                                sm_sticky : 1;  /* don't unmonitor */
+       char                    sm_addrbuf[48]; /* address eyecatcher */
 };
 
+/*
+ * Rigorous type checking on sockaddr type conversions
+ */
+static inline struct sockaddr_in *nlm_addr_in(const struct nlm_host *host)
+{
+       return (struct sockaddr_in *)&host->h_addr;
+}
+
+static inline struct sockaddr *nlm_addr(const struct nlm_host *host)
+{
+       return (struct sockaddr *)&host->h_addr;
+}
+
+static inline struct sockaddr_in *nlm_srcaddr_in(const struct nlm_host *host)
+{
+       return (struct sockaddr_in *)&host->h_srcaddr;
+}
+
+static inline struct sockaddr *nlm_srcaddr(const struct nlm_host *host)
+{
+       return (struct sockaddr *)&host->h_srcaddr;
+}
+
+static inline struct sockaddr_in *nsm_addr_in(const struct nsm_handle *handle)
+{
+       return (struct sockaddr_in *)&handle->sm_addr;
+}
+
+static inline struct sockaddr *nsm_addr(const struct nsm_handle *handle)
+{
+       return (struct sockaddr *)&handle->sm_addr;
+}
+
 /*
  * Map an fl_owner_t into a unique 32-bit "pid"
  */
@@ -166,7 +207,8 @@ int           nlm_async_reply(struct nlm_rqst *, u32, const struct rpc_call_ops *);
 struct nlm_wait * nlmclnt_prepare_block(struct nlm_host *host, struct file_lock *fl);
 void             nlmclnt_finish_block(struct nlm_wait *block);
 int              nlmclnt_block(struct nlm_wait *block, struct nlm_rqst *req, long timeout);
-__be32           nlmclnt_grant(const struct sockaddr_in *addr, const struct nlm_lock *);
+__be32           nlmclnt_grant(const struct sockaddr *addr,
+                               const struct nlm_lock *lock);
 void             nlmclnt_recovery(struct nlm_host *);
 int              nlmclnt_reclaim(struct nlm_host *, struct file_lock *);
 void             nlmclnt_next_cookie(struct nlm_cookie *);
@@ -174,12 +216,14 @@ void                nlmclnt_next_cookie(struct nlm_cookie *);
 /*
  * Host cache
  */
-struct nlm_host  *nlmclnt_lookup_host(const struct sockaddr_in *sin,
-                                       int proto, u32 version,
+struct nlm_host  *nlmclnt_lookup_host(const struct sockaddr *sap,
+                                       const size_t salen,
+                                       const unsigned short protocol,
+                                       const u32 version,
+                                       const char *hostname);
+struct nlm_host  *nlmsvc_lookup_host(const struct svc_rqst *rqstp,
                                        const char *hostname,
-                                       unsigned int hostname_len);
-struct nlm_host  *nlmsvc_lookup_host(struct svc_rqst *, const char *,
-                                       unsigned int);
+                                       const size_t hostname_len);
 struct rpc_clnt * nlm_bind_host(struct nlm_host *);
 void             nlm_rebind_host(struct nlm_host *);
 struct nlm_host * nlm_get_host(struct nlm_host *);
@@ -201,7 +245,7 @@ typedef int   (*nlm_host_match_fn_t)(void *cur, struct nlm_host *ref);
  */
 __be32           nlmsvc_lock(struct svc_rqst *, struct nlm_file *,
                              struct nlm_host *, struct nlm_lock *, int,
-                             struct nlm_cookie *);
+                             struct nlm_cookie *, int);
 __be32           nlmsvc_unlock(struct nlm_file *, struct nlm_lock *);
 __be32           nlmsvc_testlock(struct svc_rqst *, struct nlm_file *,
                        struct nlm_host *, struct nlm_lock *,
@@ -233,15 +277,82 @@ static inline struct inode *nlmsvc_file_inode(struct nlm_file *file)
        return file->f_file->f_path.dentry->d_inode;
 }
 
+static inline int __nlm_privileged_request4(const struct sockaddr *sap)
+{
+       const struct sockaddr_in *sin = (struct sockaddr_in *)sap;
+       return (sin->sin_addr.s_addr == htonl(INADDR_LOOPBACK)) &&
+                       (ntohs(sin->sin_port) < 1024);
+}
+
+#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
+static inline int __nlm_privileged_request6(const struct sockaddr *sap)
+{
+       const struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sap;
+       return (ipv6_addr_type(&sin6->sin6_addr) & IPV6_ADDR_LOOPBACK) &&
+                       (ntohs(sin6->sin6_port) < 1024);
+}
+#else  /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
+static inline int __nlm_privileged_request6(const struct sockaddr *sap)
+{
+       return 0;
+}
+#endif /* defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) */
+
 /*
- * Compare two host addresses (needs modifying for ipv6)
+ * Ensure incoming requests are from local privileged callers.
+ *
+ * Return TRUE if sender is local and is connecting via a privileged port;
+ * otherwise return FALSE.
  */
-static inline int nlm_cmp_addr(const struct sockaddr_in *sin1,
-                              const struct sockaddr_in *sin2)
+static inline int nlm_privileged_requester(const struct svc_rqst *rqstp)
 {
+       const struct sockaddr *sap = svc_addr(rqstp);
+
+       switch (sap->sa_family) {
+       case AF_INET:
+               return __nlm_privileged_request4(sap);
+       case AF_INET6:
+               return __nlm_privileged_request6(sap);
+       default:
+               return 0;
+       }
+}
+
+static inline int __nlm_cmp_addr4(const struct sockaddr *sap1,
+                                 const struct sockaddr *sap2)
+{
+       const struct sockaddr_in *sin1 = (const struct sockaddr_in *)sap1;
+       const struct sockaddr_in *sin2 = (const struct sockaddr_in *)sap2;
        return sin1->sin_addr.s_addr == sin2->sin_addr.s_addr;
 }
 
+static inline int __nlm_cmp_addr6(const struct sockaddr *sap1,
+                                 const struct sockaddr *sap2)
+{
+       const struct sockaddr_in6 *sin1 = (const struct sockaddr_in6 *)sap1;
+       const struct sockaddr_in6 *sin2 = (const struct sockaddr_in6 *)sap2;
+       return ipv6_addr_equal(&sin1->sin6_addr, &sin2->sin6_addr);
+}
+
+/*
+ * Compare two host addresses
+ *
+ * Return TRUE if the addresses are the same; otherwise FALSE.
+ */
+static inline int nlm_cmp_addr(const struct sockaddr *sap1,
+                              const struct sockaddr *sap2)
+{
+       if (sap1->sa_family == sap2->sa_family) {
+               switch (sap1->sa_family) {
+               case AF_INET:
+                       return __nlm_cmp_addr4(sap1, sap2);
+               case AF_INET6:
+                       return __nlm_cmp_addr6(sap1, sap2);
+               }
+       }
+       return 0;
+}
+
 /*
  * Compare two NLM locks.
  * When the second lock is of type F_UNLCK, this acts like a wildcard.
index df18fa053bcd7d0a1e1f9665e57efa8929dafb87..d6b3a802c0469a8e65311058167b6e2d5bacd76c 100644 (file)
@@ -81,8 +81,6 @@ struct nlm_reboot {
        unsigned int    len;
        u32             state;
        __be32          addr;
-       __be32          vers;
-       __be32          proto;
 };
 
 /*
diff --git a/include/linux/mfd/wm8350/audio.h b/include/linux/mfd/wm8350/audio.h
new file mode 100644 (file)
index 0000000..217bb22
--- /dev/null
@@ -0,0 +1,598 @@
+/*
+ * audio.h  --  Audio Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __LINUX_MFD_WM8350_AUDIO_H_
+#define __LINUX_MFD_WM8350_AUDIO_H_
+
+#include <linux/platform_device.h>
+
+#define WM8350_CLOCK_CONTROL_1                  0x28
+#define WM8350_CLOCK_CONTROL_2                  0x29
+#define WM8350_FLL_CONTROL_1                    0x2A
+#define WM8350_FLL_CONTROL_2                    0x2B
+#define WM8350_FLL_CONTROL_3                    0x2C
+#define WM8350_FLL_CONTROL_4                    0x2D
+#define WM8350_DAC_CONTROL                      0x30
+#define WM8350_DAC_DIGITAL_VOLUME_L             0x32
+#define WM8350_DAC_DIGITAL_VOLUME_R             0x33
+#define WM8350_DAC_LR_RATE                      0x35
+#define WM8350_DAC_CLOCK_CONTROL                0x36
+#define WM8350_DAC_MUTE                         0x3A
+#define WM8350_DAC_MUTE_VOLUME                  0x3B
+#define WM8350_DAC_SIDE                         0x3C
+#define WM8350_ADC_CONTROL                      0x40
+#define WM8350_ADC_DIGITAL_VOLUME_L             0x42
+#define WM8350_ADC_DIGITAL_VOLUME_R             0x43
+#define WM8350_ADC_DIVIDER                      0x44
+#define WM8350_ADC_LR_RATE                      0x46
+#define WM8350_INPUT_CONTROL                    0x48
+#define WM8350_IN3_INPUT_CONTROL                0x49
+#define WM8350_MIC_BIAS_CONTROL                 0x4A
+#define WM8350_OUTPUT_CONTROL                   0x4C
+#define WM8350_JACK_DETECT                      0x4D
+#define WM8350_ANTI_POP_CONTROL                 0x4E
+#define WM8350_LEFT_INPUT_VOLUME                0x50
+#define WM8350_RIGHT_INPUT_VOLUME               0x51
+#define WM8350_LEFT_MIXER_CONTROL               0x58
+#define WM8350_RIGHT_MIXER_CONTROL              0x59
+#define WM8350_OUT3_MIXER_CONTROL               0x5C
+#define WM8350_OUT4_MIXER_CONTROL               0x5D
+#define WM8350_OUTPUT_LEFT_MIXER_VOLUME         0x60
+#define WM8350_OUTPUT_RIGHT_MIXER_VOLUME        0x61
+#define WM8350_INPUT_MIXER_VOLUME_L             0x62
+#define WM8350_INPUT_MIXER_VOLUME_R             0x63
+#define WM8350_INPUT_MIXER_VOLUME               0x64
+#define WM8350_LOUT1_VOLUME                     0x68
+#define WM8350_ROUT1_VOLUME                     0x69
+#define WM8350_LOUT2_VOLUME                     0x6A
+#define WM8350_ROUT2_VOLUME                     0x6B
+#define WM8350_BEEP_VOLUME                      0x6F
+#define WM8350_AI_FORMATING                     0x70
+#define WM8350_ADC_DAC_COMP                     0x71
+#define WM8350_AI_ADC_CONTROL                   0x72
+#define WM8350_AI_DAC_CONTROL                   0x73
+#define WM8350_AIF_TEST                         0x74
+#define WM8350_JACK_PIN_STATUS                  0xE7
+
+/* Bit values for R08 (0x08) */
+#define WM8350_CODEC_ISEL_1_5                   0      /* x1.5 */
+#define WM8350_CODEC_ISEL_1_0                   1      /* x1.0 */
+#define WM8350_CODEC_ISEL_0_75                  2      /* x0.75 */
+#define WM8350_CODEC_ISEL_0_5                   3      /* x0.5 */
+
+#define WM8350_VMID_OFF                         0
+#define WM8350_VMID_500K                        1
+#define WM8350_VMID_100K                        2
+#define WM8350_VMID_10K                         3
+
+/*
+ * R40 (0x28) - Clock Control 1
+ */
+#define WM8350_TOCLK_RATE                       0x4000
+#define WM8350_MCLK_SEL                         0x0800
+#define WM8350_MCLK_DIV_MASK                    0x0100
+#define WM8350_BCLK_DIV_MASK                    0x00F0
+#define WM8350_OPCLK_DIV_MASK                   0x0007
+
+/*
+ * R41 (0x29) - Clock Control 2
+ */
+#define WM8350_LRC_ADC_SEL                      0x8000
+#define WM8350_MCLK_DIR                         0x0001
+
+/*
+ * R42 (0x2A) - FLL Control 1
+ */
+#define WM8350_FLL_DITHER_WIDTH_MASK            0x3000
+#define WM8350_FLL_DITHER_HP                    0x0800
+#define WM8350_FLL_OUTDIV_MASK                  0x0700
+#define WM8350_FLL_RSP_RATE_MASK                0x00F0
+#define WM8350_FLL_RATE_MASK                    0x0007
+
+/*
+ * R43 (0x2B) - FLL Control 2
+ */
+#define WM8350_FLL_RATIO_MASK                   0xF800
+#define WM8350_FLL_N_MASK                       0x03FF
+
+/*
+ * R44 (0x2C) - FLL Control 3
+ */
+#define WM8350_FLL_K_MASK                       0xFFFF
+
+/*
+ * R45 (0x2D) - FLL Control 4
+ */
+#define WM8350_FLL_FRAC                         0x0020
+#define WM8350_FLL_SLOW_LOCK_REF                0x0010
+#define WM8350_FLL_CLK_SRC_MASK                 0x0003
+
+/*
+ * R48 (0x30) - DAC Control
+ */
+#define WM8350_DAC_MONO                         0x2000
+#define WM8350_AIF_LRCLKRATE                    0x1000
+#define WM8350_DEEMP_MASK                       0x0030
+#define WM8350_DACL_DATINV                      0x0002
+#define WM8350_DACR_DATINV                      0x0001
+
+/*
+ * R50 (0x32) - DAC Digital Volume L
+ */
+#define WM8350_DAC_VU                           0x0100
+#define WM8350_DACL_VOL_MASK                    0x00FF
+
+/*
+ * R51 (0x33) - DAC Digital Volume R
+ */
+#define WM8350_DAC_VU                           0x0100
+#define WM8350_DACR_VOL_MASK                    0x00FF
+
+/*
+ * R53 (0x35) - DAC LR Rate
+ */
+#define WM8350_DACLRC_ENA                       0x0800
+#define WM8350_DACLRC_RATE_MASK                 0x07FF
+
+/*
+ * R54 (0x36) - DAC Clock Control
+ */
+#define WM8350_DACCLK_POL                       0x0010
+#define WM8350_DAC_CLKDIV_MASK                  0x0007
+
+/*
+ * R58 (0x3A) - DAC Mute
+ */
+#define WM8350_DAC_MUTE_ENA                     0x4000
+
+/*
+ * R59 (0x3B) - DAC Mute Volume
+ */
+#define WM8350_DAC_MUTEMODE                     0x4000
+#define WM8350_DAC_MUTERATE                     0x2000
+#define WM8350_DAC_SB_FILT                      0x1000
+
+/*
+ * R60 (0x3C) - DAC Side
+ */
+#define WM8350_ADC_TO_DACL_MASK                 0x3000
+#define WM8350_ADC_TO_DACR_MASK                 0x0C00
+
+/*
+ * R64 (0x40) - ADC Control
+ */
+#define WM8350_ADC_HPF_CUT_MASK                 0x0300
+#define WM8350_ADCL_DATINV                      0x0002
+#define WM8350_ADCR_DATINV                      0x0001
+
+/*
+ * R66 (0x42) - ADC Digital Volume L
+ */
+#define WM8350_ADC_VU                           0x0100
+#define WM8350_ADCL_VOL_MASK                    0x00FF
+
+/*
+ * R67 (0x43) - ADC Digital Volume R
+ */
+#define WM8350_ADC_VU                           0x0100
+#define WM8350_ADCR_VOL_MASK                    0x00FF
+
+/*
+ * R68 (0x44) - ADC Divider
+ */
+#define WM8350_ADCL_DAC_SVOL_MASK               0x0F00
+#define WM8350_ADCR_DAC_SVOL_MASK               0x00F0
+#define WM8350_ADCCLK_POL                       0x0008
+#define WM8350_ADC_CLKDIV_MASK                  0x0007
+
+/*
+ * R70 (0x46) - ADC LR Rate
+ */
+#define WM8350_ADCLRC_ENA                       0x0800
+#define WM8350_ADCLRC_RATE_MASK                 0x07FF
+
+/*
+ * R72 (0x48) - Input Control
+ */
+#define WM8350_IN2R_ENA                         0x0400
+#define WM8350_IN1RN_ENA                        0x0200
+#define WM8350_IN1RP_ENA                        0x0100
+#define WM8350_IN2L_ENA                         0x0004
+#define WM8350_IN1LN_ENA                        0x0002
+#define WM8350_IN1LP_ENA                        0x0001
+
+/*
+ * R73 (0x49) - IN3 Input Control
+ */
+#define WM8350_IN3R_SHORT                       0x4000
+#define WM8350_IN3L_SHORT                       0x0040
+
+/*
+ * R74 (0x4A) - Mic Bias Control
+ */
+#define WM8350_MICBSEL                          0x4000
+#define WM8350_MCDTHR_MASK                      0x001C
+#define WM8350_MCDSCTHR_MASK                    0x0003
+
+/*
+ * R76 (0x4C) - Output Control
+ */
+#define WM8350_OUT4_VROI                        0x0800
+#define WM8350_OUT3_VROI                        0x0400
+#define WM8350_OUT2_VROI                        0x0200
+#define WM8350_OUT1_VROI                        0x0100
+#define WM8350_OUT2_FB                          0x0004
+#define WM8350_OUT1_FB                          0x0001
+
+/*
+ * R77 (0x4D) - Jack Detect
+ */
+#define WM8350_JDL_ENA                          0x8000
+#define WM8350_JDR_ENA                          0x4000
+
+/*
+ * R78 (0x4E) - Anti Pop Control
+ */
+#define WM8350_ANTI_POP_MASK                    0x0300
+#define WM8350_DIS_OP_LN4_MASK                  0x00C0
+#define WM8350_DIS_OP_LN3_MASK                  0x0030
+#define WM8350_DIS_OP_OUT2_MASK                 0x000C
+#define WM8350_DIS_OP_OUT1_MASK                 0x0003
+
+/*
+ * R80 (0x50) - Left Input Volume
+ */
+#define WM8350_INL_MUTE                         0x4000
+#define WM8350_INL_ZC                           0x2000
+#define WM8350_IN_VU                            0x0100
+#define WM8350_INL_VOL_MASK                     0x00FC
+
+/*
+ * R81 (0x51) - Right Input Volume
+ */
+#define WM8350_INR_MUTE                         0x4000
+#define WM8350_INR_ZC                           0x2000
+#define WM8350_IN_VU                            0x0100
+#define WM8350_INR_VOL_MASK                     0x00FC
+
+/*
+ * R88 (0x58) - Left Mixer Control
+ */
+#define WM8350_DACR_TO_MIXOUTL                  0x1000
+#define WM8350_DACL_TO_MIXOUTL                  0x0800
+#define WM8350_IN3L_TO_MIXOUTL                  0x0004
+#define WM8350_INR_TO_MIXOUTL                   0x0002
+#define WM8350_INL_TO_MIXOUTL                   0x0001
+
+/*
+ * R89 (0x59) - Right Mixer Control
+ */
+#define WM8350_DACR_TO_MIXOUTR                  0x1000
+#define WM8350_DACL_TO_MIXOUTR                  0x0800
+#define WM8350_IN3R_TO_MIXOUTR                  0x0008
+#define WM8350_INR_TO_MIXOUTR                   0x0002
+#define WM8350_INL_TO_MIXOUTR                   0x0001
+
+/*
+ * R92 (0x5C) - OUT3 Mixer Control
+ */
+#define WM8350_DACL_TO_OUT3                     0x0800
+#define WM8350_MIXINL_TO_OUT3                   0x0100
+#define WM8350_OUT4_TO_OUT3                     0x0008
+#define WM8350_MIXOUTL_TO_OUT3                  0x0001
+
+/*
+ * R93 (0x5D) - OUT4 Mixer Control
+ */
+#define WM8350_DACR_TO_OUT4                     0x1000
+#define WM8350_DACL_TO_OUT4                     0x0800
+#define WM8350_OUT4_ATTN                        0x0400
+#define WM8350_MIXINR_TO_OUT4                   0x0200
+#define WM8350_OUT3_TO_OUT4                     0x0004
+#define WM8350_MIXOUTR_TO_OUT4                  0x0002
+#define WM8350_MIXOUTL_TO_OUT4                  0x0001
+
+/*
+ * R96 (0x60) - Output Left Mixer Volume
+ */
+#define WM8350_IN3L_MIXOUTL_VOL_MASK            0x0E00
+#define WM8350_IN3L_MIXOUTL_VOL_SHIFT                9
+#define WM8350_INR_MIXOUTL_VOL_MASK             0x00E0
+#define WM8350_INR_MIXOUTL_VOL_SHIFT                 5
+#define WM8350_INL_MIXOUTL_VOL_MASK             0x000E
+#define WM8350_INL_MIXOUTL_VOL_SHIFT                 1
+
+/* Bit values for R96 (0x60) */
+#define WM8350_IN3L_MIXOUTL_VOL_OFF                  0
+#define WM8350_IN3L_MIXOUTL_VOL_M12DB                1
+#define WM8350_IN3L_MIXOUTL_VOL_M9DB                 2
+#define WM8350_IN3L_MIXOUTL_VOL_M6DB                 3
+#define WM8350_IN3L_MIXOUTL_VOL_M3DB                 4
+#define WM8350_IN3L_MIXOUTL_VOL_0DB                  5
+#define WM8350_IN3L_MIXOUTL_VOL_3DB                  6
+#define WM8350_IN3L_MIXOUTL_VOL_6DB                  7
+
+#define WM8350_INR_MIXOUTL_VOL_OFF                   0
+#define WM8350_INR_MIXOUTL_VOL_M12DB                 1
+#define WM8350_INR_MIXOUTL_VOL_M9DB                  2
+#define WM8350_INR_MIXOUTL_VOL_M6DB                  3
+#define WM8350_INR_MIXOUTL_VOL_M3DB                  4
+#define WM8350_INR_MIXOUTL_VOL_0DB                   5
+#define WM8350_INR_MIXOUTL_VOL_3DB                   6
+#define WM8350_INR_MIXOUTL_VOL_6DB                   7
+
+#define WM8350_INL_MIXOUTL_VOL_OFF                   0
+#define WM8350_INL_MIXOUTL_VOL_M12DB                 1
+#define WM8350_INL_MIXOUTL_VOL_M9DB                  2
+#define WM8350_INL_MIXOUTL_VOL_M6DB                  3
+#define WM8350_INL_MIXOUTL_VOL_M3DB                  4
+#define WM8350_INL_MIXOUTL_VOL_0DB                   5
+#define WM8350_INL_MIXOUTL_VOL_3DB                   6
+#define WM8350_INL_MIXOUTL_VOL_6DB                   7
+
+/*
+ * R97 (0x61) - Output Right Mixer Volume
+ */
+#define WM8350_IN3R_MIXOUTR_VOL_MASK            0xE000
+#define WM8350_IN3R_MIXOUTR_VOL_SHIFT               13
+#define WM8350_INR_MIXOUTR_VOL_MASK             0x00E0
+#define WM8350_INR_MIXOUTR_VOL_SHIFT                 5
+#define WM8350_INL_MIXOUTR_VOL_MASK             0x000E
+#define WM8350_INL_MIXOUTR_VOL_SHIFT                 1
+
+/* Bit values for R96 (0x60) */
+#define WM8350_IN3R_MIXOUTR_VOL_OFF                  0
+#define WM8350_IN3R_MIXOUTR_VOL_M12DB                1
+#define WM8350_IN3R_MIXOUTR_VOL_M9DB                 2
+#define WM8350_IN3R_MIXOUTR_VOL_M6DB                 3
+#define WM8350_IN3R_MIXOUTR_VOL_M3DB                 4
+#define WM8350_IN3R_MIXOUTR_VOL_0DB                  5
+#define WM8350_IN3R_MIXOUTR_VOL_3DB                  6
+#define WM8350_IN3R_MIXOUTR_VOL_6DB                  7
+
+#define WM8350_INR_MIXOUTR_VOL_OFF                   0
+#define WM8350_INR_MIXOUTR_VOL_M12DB                 1
+#define WM8350_INR_MIXOUTR_VOL_M9DB                  2
+#define WM8350_INR_MIXOUTR_VOL_M6DB                  3
+#define WM8350_INR_MIXOUTR_VOL_M3DB                  4
+#define WM8350_INR_MIXOUTR_VOL_0DB                   5
+#define WM8350_INR_MIXOUTR_VOL_3DB                   6
+#define WM8350_INR_MIXOUTR_VOL_6DB                   7
+
+#define WM8350_INL_MIXOUTR_VOL_OFF                   0
+#define WM8350_INL_MIXOUTR_VOL_M12DB                 1
+#define WM8350_INL_MIXOUTR_VOL_M9DB                  2
+#define WM8350_INL_MIXOUTR_VOL_M6DB                  3
+#define WM8350_INL_MIXOUTR_VOL_M3DB                  4
+#define WM8350_INL_MIXOUTR_VOL_0DB                   5
+#define WM8350_INL_MIXOUTR_VOL_3DB                   6
+#define WM8350_INL_MIXOUTR_VOL_6DB                   7
+
+/*
+ * R98 (0x62) - Input Mixer Volume L
+ */
+#define WM8350_IN3L_MIXINL_VOL_MASK             0x0E00
+#define WM8350_IN2L_MIXINL_VOL_MASK             0x000E
+#define WM8350_INL_MIXINL_VOL                   0x0001
+
+/*
+ * R99 (0x63) - Input Mixer Volume R
+ */
+#define WM8350_IN3R_MIXINR_VOL_MASK             0xE000
+#define WM8350_IN2R_MIXINR_VOL_MASK             0x00E0
+#define WM8350_INR_MIXINR_VOL                   0x0001
+
+/*
+ * R100 (0x64) - Input Mixer Volume
+ */
+#define WM8350_OUT4_MIXIN_DST                   0x8000
+#define WM8350_OUT4_MIXIN_VOL_MASK              0x000E
+
+/*
+ * R104 (0x68) - LOUT1 Volume
+ */
+#define WM8350_OUT1L_MUTE                       0x4000
+#define WM8350_OUT1L_ZC                         0x2000
+#define WM8350_OUT1_VU                          0x0100
+#define WM8350_OUT1L_VOL_MASK                   0x00FC
+#define WM8350_OUT1L_VOL_SHIFT                       2
+
+/*
+ * R105 (0x69) - ROUT1 Volume
+ */
+#define WM8350_OUT1R_MUTE                       0x4000
+#define WM8350_OUT1R_ZC                         0x2000
+#define WM8350_OUT1_VU                          0x0100
+#define WM8350_OUT1R_VOL_MASK                   0x00FC
+#define WM8350_OUT1R_VOL_SHIFT                       2
+
+/*
+ * R106 (0x6A) - LOUT2 Volume
+ */
+#define WM8350_OUT2L_MUTE                       0x4000
+#define WM8350_OUT2L_ZC                         0x2000
+#define WM8350_OUT2_VU                          0x0100
+#define WM8350_OUT2L_VOL_MASK                   0x00FC
+
+/*
+ * R107 (0x6B) - ROUT2 Volume
+ */
+#define WM8350_OUT2R_MUTE                       0x4000
+#define WM8350_OUT2R_ZC                         0x2000
+#define WM8350_OUT2R_INV                        0x0400
+#define WM8350_OUT2R_INV_MUTE                   0x0200
+#define WM8350_OUT2_VU                          0x0100
+#define WM8350_OUT2R_VOL_MASK                   0x00FC
+
+/*
+ * R111 (0x6F) - BEEP Volume
+ */
+#define WM8350_IN3R_OUT2R_VOL_MASK              0x00E0
+
+/*
+ * R112 (0x70) - AI Formating
+ */
+#define WM8350_AIF_BCLK_INV                     0x8000
+#define WM8350_AIF_TRI                          0x2000
+#define WM8350_AIF_LRCLK_INV                    0x1000
+#define WM8350_AIF_WL_MASK                      0x0C00
+#define WM8350_AIF_FMT_MASK                     0x0300
+
+/*
+ * R113 (0x71) - ADC DAC COMP
+ */
+#define WM8350_DAC_COMP                         0x0080
+#define WM8350_DAC_COMPMODE                     0x0040
+#define WM8350_ADC_COMP                         0x0020
+#define WM8350_ADC_COMPMODE                     0x0010
+#define WM8350_LOOPBACK                         0x0001
+
+/*
+ * R114 (0x72) - AI ADC Control
+ */
+#define WM8350_AIFADC_PD                        0x0080
+#define WM8350_AIFADCL_SRC                      0x0040
+#define WM8350_AIFADCR_SRC                      0x0020
+#define WM8350_AIFADC_TDM_CHAN                  0x0010
+#define WM8350_AIFADC_TDM                       0x0008
+
+/*
+ * R115 (0x73) - AI DAC Control
+ */
+#define WM8350_BCLK_MSTR                        0x4000
+#define WM8350_AIFDAC_PD                        0x0080
+#define WM8350_DACL_SRC                         0x0040
+#define WM8350_DACR_SRC                         0x0020
+#define WM8350_AIFDAC_TDM_CHAN                  0x0010
+#define WM8350_AIFDAC_TDM                       0x0008
+#define WM8350_DAC_BOOST_MASK                   0x0003
+
+/*
+ * R116 (0x74) - AIF Test
+ */
+#define WM8350_CODEC_BYP                        0x4000
+#define WM8350_AIFADC_WR_TST                    0x2000
+#define WM8350_AIFADC_RD_TST                    0x1000
+#define WM8350_AIFDAC_WR_TST                    0x0800
+#define WM8350_AIFDAC_RD_TST                    0x0400
+#define WM8350_AIFADC_ASYN                      0x0020
+#define WM8350_AIFDAC_ASYN                      0x0010
+
+/*
+ * R231 (0xE7) - Jack Status
+ */
+#define WM8350_JACK_R_LVL                       0x0400
+
+/*
+ * WM8350 Platform setup
+ */
+#define WM8350_S_CURVE_NONE                    0x0
+#define WM8350_S_CURVE_FAST                    0x1
+#define WM8350_S_CURVE_MEDIUM                  0x2
+#define WM8350_S_CURVE_SLOW                    0x3
+
+#define WM8350_DISCHARGE_OFF                   0x0
+#define WM8350_DISCHARGE_FAST                  0x1
+#define WM8350_DISCHARGE_MEDIUM                        0x2
+#define WM8350_DISCHARGE_SLOW                  0x3
+
+#define WM8350_TIE_OFF_500R                    0x0
+#define WM8350_TIE_OFF_30K                     0x1
+
+/*
+ * Clock sources & directions
+ */
+#define WM8350_SYSCLK                          0
+
+#define WM8350_MCLK_SEL_PLL_MCLK               0
+#define WM8350_MCLK_SEL_PLL_DAC                        1
+#define WM8350_MCLK_SEL_PLL_ADC                        2
+#define WM8350_MCLK_SEL_PLL_32K                        3
+#define WM8350_MCLK_SEL_MCLK                   5
+
+#define WM8350_MCLK_DIR_OUT                    0
+#define WM8350_MCLK_DIR_IN                     1
+
+/* clock divider id's */
+#define WM8350_ADC_CLKDIV                      0
+#define WM8350_DAC_CLKDIV                      1
+#define WM8350_BCLK_CLKDIV                     2
+#define WM8350_OPCLK_CLKDIV                    3
+#define WM8350_TO_CLKDIV                       4
+#define WM8350_SYS_CLKDIV                      5
+#define WM8350_DACLR_CLKDIV                    6
+#define WM8350_ADCLR_CLKDIV                    7
+
+/* ADC clock dividers */
+#define WM8350_ADCDIV_1                                0x0
+#define WM8350_ADCDIV_1_5                      0x1
+#define WM8350_ADCDIV_2                                0x2
+#define WM8350_ADCDIV_3                                0x3
+#define WM8350_ADCDIV_4                                0x4
+#define WM8350_ADCDIV_5_5                      0x5
+#define WM8350_ADCDIV_6                                0x6
+
+/* ADC clock dividers */
+#define WM8350_DACDIV_1                                0x0
+#define WM8350_DACDIV_1_5                      0x1
+#define WM8350_DACDIV_2                                0x2
+#define WM8350_DACDIV_3                                0x3
+#define WM8350_DACDIV_4                                0x4
+#define WM8350_DACDIV_5_5                      0x5
+#define WM8350_DACDIV_6                                0x6
+
+/* BCLK clock dividers */
+#define WM8350_BCLK_DIV_1                      (0x0 << 4)
+#define WM8350_BCLK_DIV_1_5                    (0x1 << 4)
+#define WM8350_BCLK_DIV_2                      (0x2 << 4)
+#define WM8350_BCLK_DIV_3                      (0x3 << 4)
+#define WM8350_BCLK_DIV_4                      (0x4 << 4)
+#define WM8350_BCLK_DIV_5_5                    (0x5 << 4)
+#define WM8350_BCLK_DIV_6                      (0x6 << 4)
+#define WM8350_BCLK_DIV_8                      (0x7 << 4)
+#define WM8350_BCLK_DIV_11                     (0x8 << 4)
+#define WM8350_BCLK_DIV_12                     (0x9 << 4)
+#define WM8350_BCLK_DIV_16                     (0xa << 4)
+#define WM8350_BCLK_DIV_22                     (0xb << 4)
+#define WM8350_BCLK_DIV_24                     (0xc << 4)
+#define WM8350_BCLK_DIV_32                     (0xd << 4)
+#define WM8350_BCLK_DIV_44                     (0xe << 4)
+#define WM8350_BCLK_DIV_48                     (0xf << 4)
+
+/* Sys (MCLK) clock dividers */
+#define WM8350_MCLK_DIV_1                      (0x0 << 8)
+#define WM8350_MCLK_DIV_2                      (0x1 << 8)
+
+/* OP clock dividers */
+#define WM8350_OPCLK_DIV_1                     0x0
+#define WM8350_OPCLK_DIV_2                     0x1
+#define WM8350_OPCLK_DIV_3                     0x2
+#define WM8350_OPCLK_DIV_4                     0x3
+#define WM8350_OPCLK_DIV_5_5                   0x4
+#define WM8350_OPCLK_DIV_6                     0x5
+
+/* DAI ID */
+#define WM8350_HIFI_DAI                                0
+
+/*
+ * Audio interrupts.
+ */
+#define WM8350_IRQ_CODEC_JCK_DET_L             39
+#define WM8350_IRQ_CODEC_JCK_DET_R             40
+#define WM8350_IRQ_CODEC_MICSCD                        41
+#define WM8350_IRQ_CODEC_MICD                  42
+
+struct wm8350_codec {
+       struct platform_device *pdev;
+};
+
+#endif
diff --git a/include/linux/mfd/wm8350/comparator.h b/include/linux/mfd/wm8350/comparator.h
new file mode 100644 (file)
index 0000000..0537886
--- /dev/null
@@ -0,0 +1,167 @@
+/*
+ * comparator.h  --  Comparator Aux ADC for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#ifndef __LINUX_MFD_WM8350_COMPARATOR_H_
+#define __LINUX_MFD_WM8350_COMPARATOR_H_
+
+/*
+ * Registers
+ */
+
+#define WM8350_DIGITISER_CONTROL_1              0x90
+#define WM8350_DIGITISER_CONTROL_2              0x91
+#define WM8350_AUX1_READBACK                    0x98
+#define WM8350_AUX2_READBACK                    0x99
+#define WM8350_AUX3_READBACK                    0x9A
+#define WM8350_AUX4_READBACK                    0x9B
+#define WM8350_CHIP_TEMP_READBACK               0x9F
+#define WM8350_GENERIC_COMPARATOR_CONTROL       0xA3
+#define WM8350_GENERIC_COMPARATOR_1             0xA4
+#define WM8350_GENERIC_COMPARATOR_2             0xA5
+#define WM8350_GENERIC_COMPARATOR_3             0xA6
+#define WM8350_GENERIC_COMPARATOR_4             0xA7
+
+/*
+ * R144 (0x90) - Digitiser Control (1)
+ */
+#define WM8350_AUXADC_CTC                       0x4000
+#define WM8350_AUXADC_POLL                      0x2000
+#define WM8350_AUXADC_HIB_MODE                  0x1000
+#define WM8350_AUXADC_SEL8                      0x0080
+#define WM8350_AUXADC_SEL7                      0x0040
+#define WM8350_AUXADC_SEL6                      0x0020
+#define WM8350_AUXADC_SEL5                      0x0010
+#define WM8350_AUXADC_SEL4                      0x0008
+#define WM8350_AUXADC_SEL3                      0x0004
+#define WM8350_AUXADC_SEL2                      0x0002
+#define WM8350_AUXADC_SEL1                      0x0001
+
+/*
+ * R145 (0x91) - Digitiser Control (2)
+ */
+#define WM8350_AUXADC_MASKMODE_MASK             0x3000
+#define WM8350_AUXADC_CRATE_MASK                0x0700
+#define WM8350_AUXADC_CAL                       0x0004
+#define WM8350_AUX_RBMODE                       0x0002
+#define WM8350_AUXADC_WAIT                      0x0001
+
+/*
+ * R152 (0x98) - AUX1 Readback
+ */
+#define WM8350_AUXADC_SCALE1_MASK               0x6000
+#define WM8350_AUXADC_REF1                      0x1000
+#define WM8350_AUXADC_DATA1_MASK                0x0FFF
+
+/*
+ * R153 (0x99) - AUX2 Readback
+ */
+#define WM8350_AUXADC_SCALE2_MASK               0x6000
+#define WM8350_AUXADC_REF2                      0x1000
+#define WM8350_AUXADC_DATA2_MASK                0x0FFF
+
+/*
+ * R154 (0x9A) - AUX3 Readback
+ */
+#define WM8350_AUXADC_SCALE3_MASK               0x6000
+#define WM8350_AUXADC_REF3                      0x1000
+#define WM8350_AUXADC_DATA3_MASK                0x0FFF
+
+/*
+ * R155 (0x9B) - AUX4 Readback
+ */
+#define WM8350_AUXADC_SCALE4_MASK               0x6000
+#define WM8350_AUXADC_REF4                      0x1000
+#define WM8350_AUXADC_DATA4_MASK                0x0FFF
+
+/*
+ * R156 (0x9C) - USB Voltage Readback
+ */
+#define WM8350_AUXADC_DATA_USB_MASK             0x0FFF
+
+/*
+ * R157 (0x9D) - LINE Voltage Readback
+ */
+#define WM8350_AUXADC_DATA_LINE_MASK            0x0FFF
+
+/*
+ * R158 (0x9E) - BATT Voltage Readback
+ */
+#define WM8350_AUXADC_DATA_BATT_MASK            0x0FFF
+
+/*
+ * R159 (0x9F) - Chip Temp Readback
+ */
+#define WM8350_AUXADC_DATA_CHIPTEMP_MASK        0x0FFF
+
+/*
+ * R163 (0xA3) - Generic Comparator Control
+ */
+#define WM8350_DCMP4_ENA                        0x0008
+#define WM8350_DCMP3_ENA                        0x0004
+#define WM8350_DCMP2_ENA                        0x0002
+#define WM8350_DCMP1_ENA                        0x0001
+
+/*
+ * R164 (0xA4) - Generic comparator 1
+ */
+#define WM8350_DCMP1_SRCSEL_MASK                0xE000
+#define WM8350_DCMP1_GT                         0x1000
+#define WM8350_DCMP1_THR_MASK                   0x0FFF
+
+/*
+ * R165 (0xA5) - Generic comparator 2
+ */
+#define WM8350_DCMP2_SRCSEL_MASK                0xE000
+#define WM8350_DCMP2_GT                         0x1000
+#define WM8350_DCMP2_THR_MASK                   0x0FFF
+
+/*
+ * R166 (0xA6) - Generic comparator 3
+ */
+#define WM8350_DCMP3_SRCSEL_MASK                0xE000
+#define WM8350_DCMP3_GT                         0x1000
+#define WM8350_DCMP3_THR_MASK                   0x0FFF
+
+/*
+ * R167 (0xA7) - Generic comparator 4
+ */
+#define WM8350_DCMP4_SRCSEL_MASK                0xE000
+#define WM8350_DCMP4_GT                         0x1000
+#define WM8350_DCMP4_THR_MASK                   0x0FFF
+
+/*
+ * Interrupts.
+ */
+#define WM8350_IRQ_AUXADC_DATARDY              16
+#define WM8350_IRQ_AUXADC_DCOMP4               17
+#define WM8350_IRQ_AUXADC_DCOMP3               18
+#define WM8350_IRQ_AUXADC_DCOMP2               19
+#define WM8350_IRQ_AUXADC_DCOMP1               20
+#define WM8350_IRQ_SYS_HYST_COMP_FAIL          21
+#define WM8350_IRQ_SYS_CHIP_GT115              22
+#define WM8350_IRQ_SYS_CHIP_GT140              23
+
+/*
+ * USB/2, LINE & BATT = ((VRTC * 2) / 4095)) * 10e6 uV
+ * Where VRTC = 2.7 V
+ */
+#define WM8350_AUX_COEFF                       1319
+
+#define WM8350_AUXADC_AUX1                     0
+#define WM8350_AUXADC_AUX2                     1
+#define WM8350_AUXADC_AUX3                     2
+#define WM8350_AUXADC_AUX4                     3
+#define WM8350_AUXADC_USB                      4
+#define WM8350_AUXADC_LINE                     5
+#define WM8350_AUXADC_BATT                     6
+#define WM8350_AUXADC_TEMP                     7
+
+#endif
diff --git a/include/linux/mfd/wm8350/core.h b/include/linux/mfd/wm8350/core.h
new file mode 100644 (file)
index 0000000..6ebf97f
--- /dev/null
@@ -0,0 +1,631 @@
+/*
+ * core.h  --  Core Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __LINUX_MFD_WM8350_CORE_H_
+#define __LINUX_MFD_WM8350_CORE_H_
+
+#include <linux/kernel.h>
+#include <linux/mutex.h>
+#include <linux/workqueue.h>
+
+#include <linux/mfd/wm8350/audio.h>
+#include <linux/mfd/wm8350/gpio.h>
+#include <linux/mfd/wm8350/pmic.h>
+#include <linux/mfd/wm8350/rtc.h>
+#include <linux/mfd/wm8350/supply.h>
+#include <linux/mfd/wm8350/wdt.h>
+
+/*
+ * Register values.
+ */
+#define WM8350_RESET_ID                         0x00
+#define WM8350_ID                               0x01
+#define WM8350_SYSTEM_CONTROL_1                 0x03
+#define WM8350_SYSTEM_CONTROL_2                 0x04
+#define WM8350_SYSTEM_HIBERNATE                 0x05
+#define WM8350_INTERFACE_CONTROL                0x06
+#define WM8350_POWER_MGMT_1                     0x08
+#define WM8350_POWER_MGMT_2                     0x09
+#define WM8350_POWER_MGMT_3                     0x0A
+#define WM8350_POWER_MGMT_4                     0x0B
+#define WM8350_POWER_MGMT_5                     0x0C
+#define WM8350_POWER_MGMT_6                     0x0D
+#define WM8350_POWER_MGMT_7                     0x0E
+
+#define WM8350_SYSTEM_INTERRUPTS                0x18
+#define WM8350_INT_STATUS_1                     0x19
+#define WM8350_INT_STATUS_2                     0x1A
+#define WM8350_POWER_UP_INT_STATUS              0x1B
+#define WM8350_UNDER_VOLTAGE_INT_STATUS         0x1C
+#define WM8350_OVER_CURRENT_INT_STATUS          0x1D
+#define WM8350_GPIO_INT_STATUS                  0x1E
+#define WM8350_COMPARATOR_INT_STATUS            0x1F
+#define WM8350_SYSTEM_INTERRUPTS_MASK           0x20
+#define WM8350_INT_STATUS_1_MASK                0x21
+#define WM8350_INT_STATUS_2_MASK                0x22
+#define WM8350_POWER_UP_INT_STATUS_MASK         0x23
+#define WM8350_UNDER_VOLTAGE_INT_STATUS_MASK    0x24
+#define WM8350_OVER_CURRENT_INT_STATUS_MASK     0x25
+#define WM8350_GPIO_INT_STATUS_MASK             0x26
+#define WM8350_COMPARATOR_INT_STATUS_MASK       0x27
+
+#define WM8350_MAX_REGISTER                     0xFF
+
+/*
+ * Field Definitions.
+ */
+
+/*
+ * R0 (0x00) - Reset/ID
+ */
+#define WM8350_SW_RESET_CHIP_ID_MASK            0xFFFF
+
+/*
+ * R1 (0x01) - ID
+ */
+#define WM8350_CHIP_REV_MASK                    0x7000
+#define WM8350_CONF_STS_MASK                    0x0C00
+#define WM8350_CUST_ID_MASK                     0x00FF
+
+/*
+ * R3 (0x03) - System Control 1
+ */
+#define WM8350_CHIP_ON                          0x8000
+#define WM8350_POWERCYCLE                       0x2000
+#define WM8350_VCC_FAULT_OV                     0x1000
+#define WM8350_REG_RSTB_TIME_MASK               0x0C00
+#define WM8350_BG_SLEEP                         0x0200
+#define WM8350_MEM_VALID                        0x0020
+#define WM8350_CHIP_SET_UP                      0x0010
+#define WM8350_ON_DEB_T                         0x0008
+#define WM8350_ON_POL                           0x0002
+#define WM8350_IRQ_POL                          0x0001
+
+/*
+ * R4 (0x04) - System Control 2
+ */
+#define WM8350_USB_SUSPEND_8MA                  0x8000
+#define WM8350_USB_SUSPEND                      0x4000
+#define WM8350_USB_MSTR                         0x2000
+#define WM8350_USB_MSTR_SRC                     0x1000
+#define WM8350_USB_500MA                        0x0800
+#define WM8350_USB_NOLIM                        0x0400
+
+/*
+ * R5 (0x05) - System Hibernate
+ */
+#define WM8350_HIBERNATE                        0x8000
+#define WM8350_WDOG_HIB_MODE                    0x0080
+#define WM8350_REG_HIB_STARTUP_SEQ              0x0040
+#define WM8350_REG_RESET_HIB_MODE               0x0020
+#define WM8350_RST_HIB_MODE                     0x0010
+#define WM8350_IRQ_HIB_MODE                     0x0008
+#define WM8350_MEMRST_HIB_MODE                  0x0004
+#define WM8350_PCCOMP_HIB_MODE                  0x0002
+#define WM8350_TEMPMON_HIB_MODE                 0x0001
+
+/*
+ * R6 (0x06) - Interface Control
+ */
+#define WM8350_USE_DEV_PINS                     0x8000
+#define WM8350_USE_DEV_PINS_MASK                0x8000
+#define WM8350_USE_DEV_PINS_SHIFT                   15
+#define WM8350_DEV_ADDR_MASK                    0x6000
+#define WM8350_DEV_ADDR_SHIFT                       13
+#define WM8350_CONFIG_DONE                      0x1000
+#define WM8350_CONFIG_DONE_MASK                 0x1000
+#define WM8350_CONFIG_DONE_SHIFT                    12
+#define WM8350_RECONFIG_AT_ON                   0x0800
+#define WM8350_RECONFIG_AT_ON_MASK              0x0800
+#define WM8350_RECONFIG_AT_ON_SHIFT                 11
+#define WM8350_AUTOINC                          0x0200
+#define WM8350_AUTOINC_MASK                     0x0200
+#define WM8350_AUTOINC_SHIFT                         9
+#define WM8350_ARA                              0x0100
+#define WM8350_ARA_MASK                         0x0100
+#define WM8350_ARA_SHIFT                             8
+#define WM8350_SPI_CFG                          0x0008
+#define WM8350_SPI_CFG_MASK                     0x0008
+#define WM8350_SPI_CFG_SHIFT                         3
+#define WM8350_SPI_4WIRE                        0x0004
+#define WM8350_SPI_4WIRE_MASK                   0x0004
+#define WM8350_SPI_4WIRE_SHIFT                       2
+#define WM8350_SPI_3WIRE                        0x0002
+#define WM8350_SPI_3WIRE_MASK                   0x0002
+#define WM8350_SPI_3WIRE_SHIFT                       1
+
+/* Bit values for R06 (0x06) */
+#define WM8350_USE_DEV_PINS_PRIMARY                  0
+#define WM8350_USE_DEV_PINS_DEV                      1
+
+#define WM8350_DEV_ADDR_34                           0
+#define WM8350_DEV_ADDR_36                           1
+#define WM8350_DEV_ADDR_3C                           2
+#define WM8350_DEV_ADDR_3E                           3
+
+#define WM8350_CONFIG_DONE_OFF                       0
+#define WM8350_CONFIG_DONE_DONE                      1
+
+#define WM8350_RECONFIG_AT_ON_OFF                    0
+#define WM8350_RECONFIG_AT_ON_ON                     1
+
+#define WM8350_AUTOINC_OFF                           0
+#define WM8350_AUTOINC_ON                            1
+
+#define WM8350_ARA_OFF                               0
+#define WM8350_ARA_ON                                1
+
+#define WM8350_SPI_CFG_CMOS                          0
+#define WM8350_SPI_CFG_OD                            1
+
+#define WM8350_SPI_4WIRE_3WIRE                       0
+#define WM8350_SPI_4WIRE_4WIRE                       1
+
+#define WM8350_SPI_3WIRE_I2C                         0
+#define WM8350_SPI_3WIRE_SPI                         1
+
+/*
+ * R8 (0x08) - Power mgmt (1)
+ */
+#define WM8350_CODEC_ISEL_MASK                  0xC000
+#define WM8350_VBUFEN                           0x2000
+#define WM8350_OUTPUT_DRAIN_EN                  0x0400
+#define WM8350_MIC_DET_ENA                      0x0100
+#define WM8350_BIASEN                           0x0020
+#define WM8350_MICBEN                           0x0010
+#define WM8350_VMIDEN                           0x0004
+#define WM8350_VMID_MASK                        0x0003
+#define WM8350_VMID_SHIFT                            0
+
+/*
+ * R9 (0x09) - Power mgmt (2)
+ */
+#define WM8350_IN3R_ENA                         0x0800
+#define WM8350_IN3L_ENA                         0x0400
+#define WM8350_INR_ENA                          0x0200
+#define WM8350_INL_ENA                          0x0100
+#define WM8350_MIXINR_ENA                       0x0080
+#define WM8350_MIXINL_ENA                       0x0040
+#define WM8350_OUT4_ENA                         0x0020
+#define WM8350_OUT3_ENA                         0x0010
+#define WM8350_MIXOUTR_ENA                      0x0002
+#define WM8350_MIXOUTL_ENA                      0x0001
+
+/*
+ * R10 (0x0A) - Power mgmt (3)
+ */
+#define WM8350_IN3R_TO_OUT2R                    0x0080
+#define WM8350_OUT2R_ENA                        0x0008
+#define WM8350_OUT2L_ENA                        0x0004
+#define WM8350_OUT1R_ENA                        0x0002
+#define WM8350_OUT1L_ENA                        0x0001
+
+/*
+ * R11 (0x0B) - Power mgmt (4)
+ */
+#define WM8350_SYSCLK_ENA                       0x4000
+#define WM8350_ADC_HPF_ENA                      0x2000
+#define WM8350_FLL_ENA                          0x0800
+#define WM8350_FLL_OSC_ENA                      0x0400
+#define WM8350_TOCLK_ENA                        0x0100
+#define WM8350_DACR_ENA                         0x0020
+#define WM8350_DACL_ENA                         0x0010
+#define WM8350_ADCR_ENA                         0x0008
+#define WM8350_ADCL_ENA                         0x0004
+
+/*
+ * R12 (0x0C) - Power mgmt (5)
+ */
+#define WM8350_CODEC_ENA                        0x1000
+#define WM8350_RTC_TICK_ENA                     0x0800
+#define WM8350_OSC32K_ENA                       0x0400
+#define WM8350_CHG_ENA                          0x0200
+#define WM8350_ACC_DET_ENA                      0x0100
+#define WM8350_AUXADC_ENA                       0x0080
+#define WM8350_DCMP4_ENA                        0x0008
+#define WM8350_DCMP3_ENA                        0x0004
+#define WM8350_DCMP2_ENA                        0x0002
+#define WM8350_DCMP1_ENA                        0x0001
+
+/*
+ * R13 (0x0D) - Power mgmt (6)
+ */
+#define WM8350_LS_ENA                           0x8000
+#define WM8350_LDO4_ENA                         0x0800
+#define WM8350_LDO3_ENA                         0x0400
+#define WM8350_LDO2_ENA                         0x0200
+#define WM8350_LDO1_ENA                         0x0100
+#define WM8350_DC6_ENA                          0x0020
+#define WM8350_DC5_ENA                          0x0010
+#define WM8350_DC4_ENA                          0x0008
+#define WM8350_DC3_ENA                          0x0004
+#define WM8350_DC2_ENA                          0x0002
+#define WM8350_DC1_ENA                          0x0001
+
+/*
+ * R14 (0x0E) - Power mgmt (7)
+ */
+#define WM8350_CS2_ENA                          0x0002
+#define WM8350_CS1_ENA                          0x0001
+
+/*
+ * R24 (0x18) - System Interrupts
+ */
+#define WM8350_OC_INT                           0x2000
+#define WM8350_UV_INT                           0x1000
+#define WM8350_PUTO_INT                         0x0800
+#define WM8350_CS_INT                           0x0200
+#define WM8350_EXT_INT                          0x0100
+#define WM8350_CODEC_INT                        0x0080
+#define WM8350_GP_INT                           0x0040
+#define WM8350_AUXADC_INT                       0x0020
+#define WM8350_RTC_INT                          0x0010
+#define WM8350_SYS_INT                          0x0008
+#define WM8350_CHG_INT                          0x0004
+#define WM8350_USB_INT                          0x0002
+#define WM8350_WKUP_INT                         0x0001
+
+/*
+ * R25 (0x19) - Interrupt Status 1
+ */
+#define WM8350_CHG_BAT_HOT_EINT                 0x8000
+#define WM8350_CHG_BAT_COLD_EINT                0x4000
+#define WM8350_CHG_BAT_FAIL_EINT                0x2000
+#define WM8350_CHG_TO_EINT                      0x1000
+#define WM8350_CHG_END_EINT                     0x0800
+#define WM8350_CHG_START_EINT                   0x0400
+#define WM8350_CHG_FAST_RDY_EINT                0x0200
+#define WM8350_RTC_PER_EINT                     0x0080
+#define WM8350_RTC_SEC_EINT                     0x0040
+#define WM8350_RTC_ALM_EINT                     0x0020
+#define WM8350_CHG_VBATT_LT_3P9_EINT            0x0004
+#define WM8350_CHG_VBATT_LT_3P1_EINT            0x0002
+#define WM8350_CHG_VBATT_LT_2P85_EINT           0x0001
+
+/*
+ * R26 (0x1A) - Interrupt Status 2
+ */
+#define WM8350_CS1_EINT                         0x2000
+#define WM8350_CS2_EINT                         0x1000
+#define WM8350_USB_LIMIT_EINT                   0x0400
+#define WM8350_AUXADC_DATARDY_EINT              0x0100
+#define WM8350_AUXADC_DCOMP4_EINT               0x0080
+#define WM8350_AUXADC_DCOMP3_EINT               0x0040
+#define WM8350_AUXADC_DCOMP2_EINT               0x0020
+#define WM8350_AUXADC_DCOMP1_EINT               0x0010
+#define WM8350_SYS_HYST_COMP_FAIL_EINT          0x0008
+#define WM8350_SYS_CHIP_GT115_EINT              0x0004
+#define WM8350_SYS_CHIP_GT140_EINT              0x0002
+#define WM8350_SYS_WDOG_TO_EINT                 0x0001
+
+/*
+ * R27 (0x1B) - Power Up Interrupt Status
+ */
+#define WM8350_PUTO_LDO4_EINT                   0x0800
+#define WM8350_PUTO_LDO3_EINT                   0x0400
+#define WM8350_PUTO_LDO2_EINT                   0x0200
+#define WM8350_PUTO_LDO1_EINT                   0x0100
+#define WM8350_PUTO_DC6_EINT                    0x0020
+#define WM8350_PUTO_DC5_EINT                    0x0010
+#define WM8350_PUTO_DC4_EINT                    0x0008
+#define WM8350_PUTO_DC3_EINT                    0x0004
+#define WM8350_PUTO_DC2_EINT                    0x0002
+#define WM8350_PUTO_DC1_EINT                    0x0001
+
+/*
+ * R28 (0x1C) - Under Voltage Interrupt status
+ */
+#define WM8350_UV_LDO4_EINT                     0x0800
+#define WM8350_UV_LDO3_EINT                     0x0400
+#define WM8350_UV_LDO2_EINT                     0x0200
+#define WM8350_UV_LDO1_EINT                     0x0100
+#define WM8350_UV_DC6_EINT                      0x0020
+#define WM8350_UV_DC5_EINT                      0x0010
+#define WM8350_UV_DC4_EINT                      0x0008
+#define WM8350_UV_DC3_EINT                      0x0004
+#define WM8350_UV_DC2_EINT                      0x0002
+#define WM8350_UV_DC1_EINT                      0x0001
+
+/*
+ * R29 (0x1D) - Over Current Interrupt status
+ */
+#define WM8350_OC_LS_EINT                       0x8000
+
+/*
+ * R30 (0x1E) - GPIO Interrupt Status
+ */
+#define WM8350_GP12_EINT                        0x1000
+#define WM8350_GP11_EINT                        0x0800
+#define WM8350_GP10_EINT                        0x0400
+#define WM8350_GP9_EINT                         0x0200
+#define WM8350_GP8_EINT                         0x0100
+#define WM8350_GP7_EINT                         0x0080
+#define WM8350_GP6_EINT                         0x0040
+#define WM8350_GP5_EINT                         0x0020
+#define WM8350_GP4_EINT                         0x0010
+#define WM8350_GP3_EINT                         0x0008
+#define WM8350_GP2_EINT                         0x0004
+#define WM8350_GP1_EINT                         0x0002
+#define WM8350_GP0_EINT                         0x0001
+
+/*
+ * R31 (0x1F) - Comparator Interrupt Status
+ */
+#define WM8350_EXT_USB_FB_EINT                  0x8000
+#define WM8350_EXT_WALL_FB_EINT                 0x4000
+#define WM8350_EXT_BAT_FB_EINT                  0x2000
+#define WM8350_CODEC_JCK_DET_L_EINT             0x0800
+#define WM8350_CODEC_JCK_DET_R_EINT             0x0400
+#define WM8350_CODEC_MICSCD_EINT                0x0200
+#define WM8350_CODEC_MICD_EINT                  0x0100
+#define WM8350_WKUP_OFF_STATE_EINT              0x0040
+#define WM8350_WKUP_HIB_STATE_EINT              0x0020
+#define WM8350_WKUP_CONV_FAULT_EINT             0x0010
+#define WM8350_WKUP_WDOG_RST_EINT               0x0008
+#define WM8350_WKUP_GP_PWR_ON_EINT              0x0004
+#define WM8350_WKUP_ONKEY_EINT                  0x0002
+#define WM8350_WKUP_GP_WAKEUP_EINT              0x0001
+
+/*
+ * R32 (0x20) - System Interrupts Mask
+ */
+#define WM8350_IM_OC_INT                        0x2000
+#define WM8350_IM_UV_INT                        0x1000
+#define WM8350_IM_PUTO_INT                      0x0800
+#define WM8350_IM_SPARE_INT                     0x0400
+#define WM8350_IM_CS_INT                        0x0200
+#define WM8350_IM_EXT_INT                       0x0100
+#define WM8350_IM_CODEC_INT                     0x0080
+#define WM8350_IM_GP_INT                        0x0040
+#define WM8350_IM_AUXADC_INT                    0x0020
+#define WM8350_IM_RTC_INT                       0x0010
+#define WM8350_IM_SYS_INT                       0x0008
+#define WM8350_IM_CHG_INT                       0x0004
+#define WM8350_IM_USB_INT                       0x0002
+#define WM8350_IM_WKUP_INT                      0x0001
+
+/*
+ * R33 (0x21) - Interrupt Status 1 Mask
+ */
+#define WM8350_IM_CHG_BAT_HOT_EINT              0x8000
+#define WM8350_IM_CHG_BAT_COLD_EINT             0x4000
+#define WM8350_IM_CHG_BAT_FAIL_EINT             0x2000
+#define WM8350_IM_CHG_TO_EINT                   0x1000
+#define WM8350_IM_CHG_END_EINT                  0x0800
+#define WM8350_IM_CHG_START_EINT                0x0400
+#define WM8350_IM_CHG_FAST_RDY_EINT             0x0200
+#define WM8350_IM_RTC_PER_EINT                  0x0080
+#define WM8350_IM_RTC_SEC_EINT                  0x0040
+#define WM8350_IM_RTC_ALM_EINT                  0x0020
+#define WM8350_IM_CHG_VBATT_LT_3P9_EINT         0x0004
+#define WM8350_IM_CHG_VBATT_LT_3P1_EINT         0x0002
+#define WM8350_IM_CHG_VBATT_LT_2P85_EINT        0x0001
+
+/*
+ * R34 (0x22) - Interrupt Status 2 Mask
+ */
+#define WM8350_IM_SPARE2_EINT                   0x8000
+#define WM8350_IM_SPARE1_EINT                   0x4000
+#define WM8350_IM_CS1_EINT                      0x2000
+#define WM8350_IM_CS2_EINT                      0x1000
+#define WM8350_IM_USB_LIMIT_EINT                0x0400
+#define WM8350_IM_AUXADC_DATARDY_EINT           0x0100
+#define WM8350_IM_AUXADC_DCOMP4_EINT            0x0080
+#define WM8350_IM_AUXADC_DCOMP3_EINT            0x0040
+#define WM8350_IM_AUXADC_DCOMP2_EINT            0x0020
+#define WM8350_IM_AUXADC_DCOMP1_EINT            0x0010
+#define WM8350_IM_SYS_HYST_COMP_FAIL_EINT       0x0008
+#define WM8350_IM_SYS_CHIP_GT115_EINT           0x0004
+#define WM8350_IM_SYS_CHIP_GT140_EINT           0x0002
+#define WM8350_IM_SYS_WDOG_TO_EINT              0x0001
+
+/*
+ * R35 (0x23) - Power Up Interrupt Status Mask
+ */
+#define WM8350_IM_PUTO_LDO4_EINT                0x0800
+#define WM8350_IM_PUTO_LDO3_EINT                0x0400
+#define WM8350_IM_PUTO_LDO2_EINT                0x0200
+#define WM8350_IM_PUTO_LDO1_EINT                0x0100
+#define WM8350_IM_PUTO_DC6_EINT                 0x0020
+#define WM8350_IM_PUTO_DC5_EINT                 0x0010
+#define WM8350_IM_PUTO_DC4_EINT                 0x0008
+#define WM8350_IM_PUTO_DC3_EINT                 0x0004
+#define WM8350_IM_PUTO_DC2_EINT                 0x0002
+#define WM8350_IM_PUTO_DC1_EINT                 0x0001
+
+/*
+ * R36 (0x24) - Under Voltage Interrupt status Mask
+ */
+#define WM8350_IM_UV_LDO4_EINT                  0x0800
+#define WM8350_IM_UV_LDO3_EINT                  0x0400
+#define WM8350_IM_UV_LDO2_EINT                  0x0200
+#define WM8350_IM_UV_LDO1_EINT                  0x0100
+#define WM8350_IM_UV_DC6_EINT                   0x0020
+#define WM8350_IM_UV_DC5_EINT                   0x0010
+#define WM8350_IM_UV_DC4_EINT                   0x0008
+#define WM8350_IM_UV_DC3_EINT                   0x0004
+#define WM8350_IM_UV_DC2_EINT                   0x0002
+#define WM8350_IM_UV_DC1_EINT                   0x0001
+
+/*
+ * R37 (0x25) - Over Current Interrupt status Mask
+ */
+#define WM8350_IM_OC_LS_EINT                    0x8000
+
+/*
+ * R38 (0x26) - GPIO Interrupt Status Mask
+ */
+#define WM8350_IM_GP12_EINT                     0x1000
+#define WM8350_IM_GP11_EINT                     0x0800
+#define WM8350_IM_GP10_EINT                     0x0400
+#define WM8350_IM_GP9_EINT                      0x0200
+#define WM8350_IM_GP8_EINT                      0x0100
+#define WM8350_IM_GP7_EINT                      0x0080
+#define WM8350_IM_GP6_EINT                      0x0040
+#define WM8350_IM_GP5_EINT                      0x0020
+#define WM8350_IM_GP4_EINT                      0x0010
+#define WM8350_IM_GP3_EINT                      0x0008
+#define WM8350_IM_GP2_EINT                      0x0004
+#define WM8350_IM_GP1_EINT                      0x0002
+#define WM8350_IM_GP0_EINT                      0x0001
+
+/*
+ * R39 (0x27) - Comparator Interrupt Status Mask
+ */
+#define WM8350_IM_EXT_USB_FB_EINT               0x8000
+#define WM8350_IM_EXT_WALL_FB_EINT              0x4000
+#define WM8350_IM_EXT_BAT_FB_EINT               0x2000
+#define WM8350_IM_CODEC_JCK_DET_L_EINT          0x0800
+#define WM8350_IM_CODEC_JCK_DET_R_EINT          0x0400
+#define WM8350_IM_CODEC_MICSCD_EINT             0x0200
+#define WM8350_IM_CODEC_MICD_EINT               0x0100
+#define WM8350_IM_WKUP_OFF_STATE_EINT           0x0040
+#define WM8350_IM_WKUP_HIB_STATE_EINT           0x0020
+#define WM8350_IM_WKUP_CONV_FAULT_EINT          0x0010
+#define WM8350_IM_WKUP_WDOG_RST_EINT            0x0008
+#define WM8350_IM_WKUP_GP_PWR_ON_EINT           0x0004
+#define WM8350_IM_WKUP_ONKEY_EINT               0x0002
+#define WM8350_IM_WKUP_GP_WAKEUP_EINT           0x0001
+
+/*
+ * R220 (0xDC) - RAM BIST 1
+ */
+#define WM8350_READ_STATUS                      0x0800
+#define WM8350_TSTRAM_CLK                       0x0100
+#define WM8350_TSTRAM_CLK_ENA                   0x0080
+#define WM8350_STARTSEQ                         0x0040
+#define WM8350_READ_SRC                         0x0020
+#define WM8350_COUNT_DIR                        0x0010
+#define WM8350_TSTRAM_MODE_MASK                 0x000E
+#define WM8350_TSTRAM_ENA                       0x0001
+
+/*
+ * R225 (0xE1) - DCDC/LDO status
+ */
+#define WM8350_LS_STS                           0x8000
+#define WM8350_LDO4_STS                         0x0800
+#define WM8350_LDO3_STS                         0x0400
+#define WM8350_LDO2_STS                         0x0200
+#define WM8350_LDO1_STS                         0x0100
+#define WM8350_DC6_STS                          0x0020
+#define WM8350_DC5_STS                          0x0010
+#define WM8350_DC4_STS                          0x0008
+#define WM8350_DC3_STS                          0x0004
+#define WM8350_DC2_STS                          0x0002
+#define WM8350_DC1_STS                          0x0001
+
+/* WM8350 wake up conditions */
+#define WM8350_IRQ_WKUP_OFF_STATE              43
+#define WM8350_IRQ_WKUP_HIB_STATE              44
+#define WM8350_IRQ_WKUP_CONV_FAULT             45
+#define WM8350_IRQ_WKUP_WDOG_RST               46
+#define WM8350_IRQ_WKUP_GP_PWR_ON              47
+#define WM8350_IRQ_WKUP_ONKEY                  48
+#define WM8350_IRQ_WKUP_GP_WAKEUP              49
+
+/* wm8350 chip revisions */
+#define WM8350_REV_E                           0x4
+#define WM8350_REV_F                           0x5
+#define WM8350_REV_G                           0x6
+
+#define WM8350_NUM_IRQ                         63
+
+struct wm8350_reg_access {
+       u16 readable;           /* Mask of readable bits */
+       u16 writable;           /* Mask of writable bits */
+       u16 vol;                /* Mask of volatile bits */
+};
+extern const struct wm8350_reg_access wm8350_reg_io_map[];
+extern const u16 wm8350_mode0_defaults[];
+extern const u16 wm8350_mode1_defaults[];
+extern const u16 wm8350_mode2_defaults[];
+extern const u16 wm8350_mode3_defaults[];
+
+struct wm8350;
+
+struct wm8350_irq {
+       void (*handler) (struct wm8350 *, int, void *);
+       void *data;
+};
+
+struct wm8350 {
+       int rev;                /* chip revision */
+
+       struct device *dev;
+
+       /* device IO */
+       union {
+               struct i2c_client *i2c_client;
+               struct spi_device *spi_device;
+       };
+       int (*read_dev)(struct wm8350 *wm8350, char reg, int size, void *dest);
+       int (*write_dev)(struct wm8350 *wm8350, char reg, int size,
+                        void *src);
+       u16 *reg_cache;
+
+       /* Interrupt handling */
+       struct work_struct irq_work;
+       struct mutex irq_mutex; /* IRQ table mutex */
+       struct wm8350_irq irq[WM8350_NUM_IRQ];
+       int chip_irq;
+
+       /* Client devices */
+       struct wm8350_codec codec;
+       struct wm8350_gpio gpio;
+       struct wm8350_pmic pmic;
+       struct wm8350_power power;
+       struct wm8350_rtc rtc;
+       struct wm8350_wdt wdt;
+};
+
+/**
+ * Data to be supplied by the platform to initialise the WM8350.
+ *
+ * @init: Function called during driver initialisation.  Should be
+ *        used by the platform to configure GPIO functions and similar.
+ */
+struct wm8350_platform_data {
+       int (*init)(struct wm8350 *wm8350);
+};
+
+
+/*
+ * WM8350 device initialisation and exit.
+ */
+int wm8350_device_init(struct wm8350 *wm8350, int irq,
+                      struct wm8350_platform_data *pdata);
+void wm8350_device_exit(struct wm8350 *wm8350);
+
+/*
+ * WM8350 device IO
+ */
+int wm8350_clear_bits(struct wm8350 *wm8350, u16 reg, u16 mask);
+int wm8350_set_bits(struct wm8350 *wm8350, u16 reg, u16 mask);
+u16 wm8350_reg_read(struct wm8350 *wm8350, int reg);
+int wm8350_reg_write(struct wm8350 *wm8350, int reg, u16 val);
+int wm8350_reg_lock(struct wm8350 *wm8350);
+int wm8350_reg_unlock(struct wm8350 *wm8350);
+int wm8350_block_read(struct wm8350 *wm8350, int reg, int size, u16 *dest);
+int wm8350_block_write(struct wm8350 *wm8350, int reg, int size, u16 *src);
+
+/*
+ * WM8350 internal interrupts
+ */
+int wm8350_register_irq(struct wm8350 *wm8350, int irq,
+                       void (*handler) (struct wm8350 *, int, void *),
+                       void *data);
+int wm8350_free_irq(struct wm8350 *wm8350, int irq);
+int wm8350_mask_irq(struct wm8350 *wm8350, int irq);
+int wm8350_unmask_irq(struct wm8350 *wm8350, int irq);
+
+
+#endif
diff --git a/include/linux/mfd/wm8350/gpio.h b/include/linux/mfd/wm8350/gpio.h
new file mode 100644 (file)
index 0000000..ed91e8f
--- /dev/null
@@ -0,0 +1,342 @@
+/*
+ * gpio.h  --  GPIO Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __LINUX_MFD_WM8350_GPIO_H_
+#define __LINUX_MFD_WM8350_GPIO_H_
+
+#include <linux/platform_device.h>
+
+/*
+ * GPIO Registers.
+ */
+#define WM8350_GPIO_DEBOUNCE                    0x80
+#define WM8350_GPIO_PIN_PULL_UP_CONTROL         0x81
+#define WM8350_GPIO_PULL_DOWN_CONTROL           0x82
+#define WM8350_GPIO_INT_MODE                    0x83
+#define WM8350_GPIO_CONTROL                     0x85
+#define WM8350_GPIO_CONFIGURATION_I_O           0x86
+#define WM8350_GPIO_PIN_POLARITY_TYPE           0x87
+#define WM8350_GPIO_FUNCTION_SELECT_1           0x8C
+#define WM8350_GPIO_FUNCTION_SELECT_2           0x8D
+#define WM8350_GPIO_FUNCTION_SELECT_3           0x8E
+#define WM8350_GPIO_FUNCTION_SELECT_4           0x8F
+
+/*
+ * GPIO Functions
+ */
+#define WM8350_GPIO0_GPIO_IN                   0x0
+#define WM8350_GPIO0_GPIO_OUT                  0x0
+#define WM8350_GPIO0_PWR_ON_IN                 0x1
+#define WM8350_GPIO0_PWR_ON_OUT                        0x1
+#define WM8350_GPIO0_LDO_EN_IN                 0x2
+#define WM8350_GPIO0_VRTC_OUT                  0x2
+#define WM8350_GPIO0_LPWR1_IN                  0x3
+#define WM8350_GPIO0_POR_B_OUT                 0x3
+
+#define WM8350_GPIO1_GPIO_IN                   0x0
+#define WM8350_GPIO1_GPIO_OUT                  0x0
+#define WM8350_GPIO1_PWR_ON_IN                 0x1
+#define WM8350_GPIO1_DO_CONF_OUT               0x1
+#define WM8350_GPIO1_LDO_EN_IN                 0x2
+#define WM8350_GPIO1_RESET_OUT                 0x2
+#define WM8350_GPIO1_LPWR2_IN                  0x3
+#define WM8350_GPIO1_MEMRST_OUT                        0x3
+
+#define WM8350_GPIO2_GPIO_IN                   0x0
+#define WM8350_GPIO2_GPIO_OUT                  0x0
+#define WM8350_GPIO2_PWR_ON_IN                 0x1
+#define WM8350_GPIO2_PWR_ON_OUT                        0x1
+#define WM8350_GPIO2_WAKE_UP_IN                        0x2
+#define WM8350_GPIO2_VRTC_OUT                  0x2
+#define WM8350_GPIO2_32KHZ_IN                  0x3
+#define WM8350_GPIO2_32KHZ_OUT                 0x3
+
+#define WM8350_GPIO3_GPIO_IN                   0x0
+#define WM8350_GPIO3_GPIO_OUT                  0x0
+#define WM8350_GPIO3_PWR_ON_IN                 0x1
+#define WM8350_GPIO3_P_CLK_OUT                 0x1
+#define WM8350_GPIO3_LDO_EN_IN                 0x2
+#define WM8350_GPIO3_VRTC_OUT                  0x2
+#define WM8350_GPIO3_PWR_OFF_IN                        0x3
+#define WM8350_GPIO3_32KHZ_OUT                 0x3
+
+#define WM8350_GPIO4_GPIO_IN                   0x0
+#define WM8350_GPIO4_GPIO_OUT                  0x0
+#define WM8350_GPIO4_MR_IN                     0x1
+#define WM8350_GPIO4_MEM_RST_OUT               0x1
+#define WM8350_GPIO4_FLASH_IN                  0x2
+#define WM8350_GPIO4_ADA_OUT                   0x2
+#define WM8350_GPIO4_HIBERNATE_IN              0x3
+#define WM8350_GPIO4_FLASH_OUT                 0x3
+#define WM8350_GPIO4_MICDET_OUT                        0x4
+#define WM8350_GPIO4_MICSHT_OUT                        0x5
+
+#define WM8350_GPIO5_GPIO_IN                   0x0
+#define WM8350_GPIO5_GPIO_OUT                  0x0
+#define WM8350_GPIO5_LPWR1_IN                  0x1
+#define WM8350_GPIO5_P_CLK_OUT                 0x1
+#define WM8350_GPIO5_ADCLRCLK_IN               0x2
+#define WM8350_GPIO5_ADCLRCLK_OUT              0x2
+#define WM8350_GPIO5_HIBERNATE_IN              0x3
+#define WM8350_GPIO5_32KHZ_OUT                 0x3
+#define WM8350_GPIO5_MICDET_OUT                        0x4
+#define WM8350_GPIO5_MICSHT_OUT                        0x5
+#define WM8350_GPIO5_ADA_OUT                   0x6
+#define WM8350_GPIO5_OPCLK_OUT                 0x7
+
+#define WM8350_GPIO6_GPIO_IN                   0x0
+#define WM8350_GPIO6_GPIO_OUT                  0x0
+#define WM8350_GPIO6_LPWR2_IN                  0x1
+#define WM8350_GPIO6_MEMRST_OUT                        0x1
+#define WM8350_GPIO6_FLASH_IN                  0x2
+#define WM8350_GPIO6_ADA_OUT                   0x2
+#define WM8350_GPIO6_HIBERNATE_IN              0x3
+#define WM8350_GPIO6_RTC_OUT                   0x3
+#define WM8350_GPIO6_MICDET_OUT                        0x4
+#define WM8350_GPIO6_MICSHT_OUT                        0x5
+#define WM8350_GPIO6_ADCLRCLKB_OUT             0x6
+#define WM8350_GPIO6_SDOUT_OUT                 0x7
+
+#define WM8350_GPIO7_GPIO_IN                   0x0
+#define WM8350_GPIO7_GPIO_OUT                  0x0
+#define WM8350_GPIO7_LPWR3_IN                  0x1
+#define WM8350_GPIO7_P_CLK_OUT                 0x1
+#define WM8350_GPIO7_MASK_IN                   0x2
+#define WM8350_GPIO7_VCC_FAULT_OUT             0x2
+#define WM8350_GPIO7_HIBERNATE_IN              0x3
+#define WM8350_GPIO7_BATT_FAULT_OUT            0x3
+#define WM8350_GPIO7_MICDET_OUT                        0x4
+#define WM8350_GPIO7_MICSHT_OUT                        0x5
+#define WM8350_GPIO7_ADA_OUT                   0x6
+#define WM8350_GPIO7_CSB_IN                    0x7
+
+#define WM8350_GPIO8_GPIO_IN                   0x0
+#define WM8350_GPIO8_GPIO_OUT                  0x0
+#define WM8350_GPIO8_MR_IN                     0x1
+#define WM8350_GPIO8_VCC_FAULT_OUT             0x1
+#define WM8350_GPIO8_ADCBCLK_IN                        0x2
+#define WM8350_GPIO8_ADCBCLK_OUT               0x2
+#define WM8350_GPIO8_PWR_OFF_IN                        0x3
+#define WM8350_GPIO8_BATT_FAULT_OUT            0x3
+#define WM8350_GPIO8_ALTSCL_IN                 0xf
+
+#define WM8350_GPIO9_GPIO_IN                   0x0
+#define WM8350_GPIO9_GPIO_OUT                  0x0
+#define WM8350_GPIO9_HEARTBEAT_IN              0x1
+#define WM8350_GPIO9_VCC_FAULT_OUT             0x1
+#define WM8350_GPIO9_MASK_IN                   0x2
+#define WM8350_GPIO9_LINE_GT_BATT_OUT          0x2
+#define WM8350_GPIO9_PWR_OFF_IN                        0x3
+#define WM8350_GPIO9_BATT_FAULT_OUT            0x3
+#define WM8350_GPIO9_ALTSDA_OUT                        0xf
+
+#define WM8350_GPIO10_GPIO_IN                  0x0
+#define WM8350_GPIO10_GPIO_OUT                 0x0
+#define WM8350_GPIO10_ISINKC_OUT               0x1
+#define WM8350_GPIO10_PWR_OFF_IN               0x2
+#define WM8350_GPIO10_LINE_GT_BATT_OUT         0x2
+#define WM8350_GPIO10_CHD_IND_IN               0x3
+
+#define WM8350_GPIO11_GPIO_IN                  0x0
+#define WM8350_GPIO11_GPIO_OUT                 0x0
+#define WM8350_GPIO11_ISINKD_OUT               0x1
+#define WM8350_GPIO11_WAKEUP_IN                        0x2
+#define WM8350_GPIO11_LINE_GT_BATT_OUT         0x2
+#define WM8350_GPIO11_CHD_IND_IN               0x3
+
+#define WM8350_GPIO12_GPIO_IN                  0x0
+#define WM8350_GPIO12_GPIO_OUT                 0x0
+#define WM8350_GPIO12_ISINKE_OUT               0x1
+#define WM8350_GPIO12_LINE_GT_BATT_OUT         0x2
+#define WM8350_GPIO12_LINE_EN_OUT              0x3
+#define WM8350_GPIO12_32KHZ_OUT                        0x4
+
+#define WM8350_GPIO_DIR_IN                     0
+#define WM8350_GPIO_DIR_OUT                    1
+#define WM8350_GPIO_ACTIVE_LOW                 0
+#define WM8350_GPIO_ACTIVE_HIGH                        1
+#define WM8350_GPIO_PULL_NONE                  0
+#define WM8350_GPIO_PULL_UP                    1
+#define WM8350_GPIO_PULL_DOWN                  2
+#define WM8350_GPIO_INVERT_OFF                 0
+#define WM8350_GPIO_INVERT_ON                  1
+#define WM8350_GPIO_DEBOUNCE_OFF               0
+#define WM8350_GPIO_DEBOUNCE_ON                        1
+
+/*
+ * R128 (0x80) - GPIO Debounce
+ */
+#define WM8350_GP12_DB                          0x1000
+#define WM8350_GP11_DB                          0x0800
+#define WM8350_GP10_DB                          0x0400
+#define WM8350_GP9_DB                           0x0200
+#define WM8350_GP8_DB                           0x0100
+#define WM8350_GP7_DB                           0x0080
+#define WM8350_GP6_DB                           0x0040
+#define WM8350_GP5_DB                           0x0020
+#define WM8350_GP4_DB                           0x0010
+#define WM8350_GP3_DB                           0x0008
+#define WM8350_GP2_DB                           0x0004
+#define WM8350_GP1_DB                           0x0002
+#define WM8350_GP0_DB                           0x0001
+
+/*
+ * R129 (0x81) - GPIO Pin pull up Control
+ */
+#define WM8350_GP12_PU                          0x1000
+#define WM8350_GP11_PU                          0x0800
+#define WM8350_GP10_PU                          0x0400
+#define WM8350_GP9_PU                           0x0200
+#define WM8350_GP8_PU                           0x0100
+#define WM8350_GP7_PU                           0x0080
+#define WM8350_GP6_PU                           0x0040
+#define WM8350_GP5_PU                           0x0020
+#define WM8350_GP4_PU                           0x0010
+#define WM8350_GP3_PU                           0x0008
+#define WM8350_GP2_PU                           0x0004
+#define WM8350_GP1_PU                           0x0002
+#define WM8350_GP0_PU                           0x0001
+
+/*
+ * R130 (0x82) - GPIO Pull down Control
+ */
+#define WM8350_GP12_PD                          0x1000
+#define WM8350_GP11_PD                          0x0800
+#define WM8350_GP10_PD                          0x0400
+#define WM8350_GP9_PD                           0x0200
+#define WM8350_GP8_PD                           0x0100
+#define WM8350_GP7_PD                           0x0080
+#define WM8350_GP6_PD                           0x0040
+#define WM8350_GP5_PD                           0x0020
+#define WM8350_GP4_PD                           0x0010
+#define WM8350_GP3_PD                           0x0008
+#define WM8350_GP2_PD                           0x0004
+#define WM8350_GP1_PD                           0x0002
+#define WM8350_GP0_PD                           0x0001
+
+/*
+ * R131 (0x83) - GPIO Interrupt Mode
+ */
+#define WM8350_GP12_INTMODE                     0x1000
+#define WM8350_GP11_INTMODE                     0x0800
+#define WM8350_GP10_INTMODE                     0x0400
+#define WM8350_GP9_INTMODE                      0x0200
+#define WM8350_GP8_INTMODE                      0x0100
+#define WM8350_GP7_INTMODE                      0x0080
+#define WM8350_GP6_INTMODE                      0x0040
+#define WM8350_GP5_INTMODE                      0x0020
+#define WM8350_GP4_INTMODE                      0x0010
+#define WM8350_GP3_INTMODE                      0x0008
+#define WM8350_GP2_INTMODE                      0x0004
+#define WM8350_GP1_INTMODE                      0x0002
+#define WM8350_GP0_INTMODE                      0x0001
+
+/*
+ * R133 (0x85) - GPIO Control
+ */
+#define WM8350_GP_DBTIME_MASK                   0x00C0
+
+/*
+ * R134 (0x86) - GPIO Configuration (i/o)
+ */
+#define WM8350_GP12_DIR                         0x1000
+#define WM8350_GP11_DIR                         0x0800
+#define WM8350_GP10_DIR                         0x0400
+#define WM8350_GP9_DIR                          0x0200
+#define WM8350_GP8_DIR                          0x0100
+#define WM8350_GP7_DIR                          0x0080
+#define WM8350_GP6_DIR                          0x0040
+#define WM8350_GP5_DIR                          0x0020
+#define WM8350_GP4_DIR                          0x0010
+#define WM8350_GP3_DIR                          0x0008
+#define WM8350_GP2_DIR                          0x0004
+#define WM8350_GP1_DIR                          0x0002
+#define WM8350_GP0_DIR                          0x0001
+
+/*
+ * R135 (0x87) - GPIO Pin Polarity / Type
+ */
+#define WM8350_GP12_CFG                         0x1000
+#define WM8350_GP11_CFG                         0x0800
+#define WM8350_GP10_CFG                         0x0400
+#define WM8350_GP9_CFG                          0x0200
+#define WM8350_GP8_CFG                          0x0100
+#define WM8350_GP7_CFG                          0x0080
+#define WM8350_GP6_CFG                          0x0040
+#define WM8350_GP5_CFG                          0x0020
+#define WM8350_GP4_CFG                          0x0010
+#define WM8350_GP3_CFG                          0x0008
+#define WM8350_GP2_CFG                          0x0004
+#define WM8350_GP1_CFG                          0x0002
+#define WM8350_GP0_CFG                          0x0001
+
+/*
+ * R140 (0x8C) - GPIO Function Select 1
+ */
+#define WM8350_GP3_FN_MASK                      0xF000
+#define WM8350_GP2_FN_MASK                      0x0F00
+#define WM8350_GP1_FN_MASK                      0x00F0
+#define WM8350_GP0_FN_MASK                      0x000F
+
+/*
+ * R141 (0x8D) - GPIO Function Select 2
+ */
+#define WM8350_GP7_FN_MASK                      0xF000
+#define WM8350_GP6_FN_MASK                      0x0F00
+#define WM8350_GP5_FN_MASK                      0x00F0
+#define WM8350_GP4_FN_MASK                      0x000F
+
+/*
+ * R142 (0x8E) - GPIO Function Select 3
+ */
+#define WM8350_GP11_FN_MASK                     0xF000
+#define WM8350_GP10_FN_MASK                     0x0F00
+#define WM8350_GP9_FN_MASK                      0x00F0
+#define WM8350_GP8_FN_MASK                      0x000F
+
+/*
+ * R143 (0x8F) - GPIO Function Select 4
+ */
+#define WM8350_GP12_FN_MASK                     0x000F
+
+/*
+ * R230 (0xE6) - GPIO Pin Status
+ */
+#define WM8350_GP12_LVL                         0x1000
+#define WM8350_GP11_LVL                         0x0800
+#define WM8350_GP10_LVL                         0x0400
+#define WM8350_GP9_LVL                          0x0200
+#define WM8350_GP8_LVL                          0x0100
+#define WM8350_GP7_LVL                          0x0080
+#define WM8350_GP6_LVL                          0x0040
+#define WM8350_GP5_LVL                          0x0020
+#define WM8350_GP4_LVL                          0x0010
+#define WM8350_GP3_LVL                          0x0008
+#define WM8350_GP2_LVL                          0x0004
+#define WM8350_GP1_LVL                          0x0002
+#define WM8350_GP0_LVL                          0x0001
+
+struct wm8350;
+
+int wm8350_gpio_config(struct wm8350 *wm8350, int gpio, int dir, int func,
+                      int pol, int pull, int invert, int debounce);
+
+struct wm8350_gpio {
+       struct platform_device *pdev;
+};
+
+/*
+ * GPIO Interrupts
+ */
+#define WM8350_IRQ_GPIO(x)                      (50 + x)
+
+#endif
diff --git a/include/linux/mfd/wm8350/pmic.h b/include/linux/mfd/wm8350/pmic.h
new file mode 100644 (file)
index 0000000..69b69e0
--- /dev/null
@@ -0,0 +1,741 @@
+/*
+ * pmic.h  --  Power Managment Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __LINUX_MFD_WM8350_PMIC_H
+#define __LINUX_MFD_WM8350_PMIC_H
+
+/*
+ * Register values.
+ */
+
+#define WM8350_CURRENT_SINK_DRIVER_A            0xAC
+#define WM8350_CSA_FLASH_CONTROL                0xAD
+#define WM8350_CURRENT_SINK_DRIVER_B            0xAE
+#define WM8350_CSB_FLASH_CONTROL                0xAF
+#define WM8350_DCDC_LDO_REQUESTED               0xB0
+#define WM8350_DCDC_ACTIVE_OPTIONS              0xB1
+#define WM8350_DCDC_SLEEP_OPTIONS               0xB2
+#define WM8350_POWER_CHECK_COMPARATOR           0xB3
+#define WM8350_DCDC1_CONTROL                    0xB4
+#define WM8350_DCDC1_TIMEOUTS                   0xB5
+#define WM8350_DCDC1_LOW_POWER                  0xB6
+#define WM8350_DCDC2_CONTROL                    0xB7
+#define WM8350_DCDC2_TIMEOUTS                   0xB8
+#define WM8350_DCDC3_CONTROL                    0xBA
+#define WM8350_DCDC3_TIMEOUTS                   0xBB
+#define WM8350_DCDC3_LOW_POWER                  0xBC
+#define WM8350_DCDC4_CONTROL                    0xBD
+#define WM8350_DCDC4_TIMEOUTS                   0xBE
+#define WM8350_DCDC4_LOW_POWER                  0xBF
+#define WM8350_DCDC5_CONTROL                    0xC0
+#define WM8350_DCDC5_TIMEOUTS                   0xC1
+#define WM8350_DCDC6_CONTROL                    0xC3
+#define WM8350_DCDC6_TIMEOUTS                   0xC4
+#define WM8350_DCDC6_LOW_POWER                  0xC5
+#define WM8350_LIMIT_SWITCH_CONTROL             0xC7
+#define WM8350_LDO1_CONTROL                     0xC8
+#define WM8350_LDO1_TIMEOUTS                    0xC9
+#define WM8350_LDO1_LOW_POWER                   0xCA
+#define WM8350_LDO2_CONTROL                     0xCB
+#define WM8350_LDO2_TIMEOUTS                    0xCC
+#define WM8350_LDO2_LOW_POWER                   0xCD
+#define WM8350_LDO3_CONTROL                     0xCE
+#define WM8350_LDO3_TIMEOUTS                    0xCF
+#define WM8350_LDO3_LOW_POWER                   0xD0
+#define WM8350_LDO4_CONTROL                     0xD1
+#define WM8350_LDO4_TIMEOUTS                    0xD2
+#define WM8350_LDO4_LOW_POWER                   0xD3
+#define WM8350_VCC_FAULT_MASKS                  0xD7
+#define WM8350_MAIN_BANDGAP_CONTROL             0xD8
+#define WM8350_OSC_CONTROL                      0xD9
+#define WM8350_RTC_TICK_CONTROL                 0xDA
+#define WM8350_SECURITY                         0xDB
+#define WM8350_RAM_BIST_1                       0xDC
+#define WM8350_DCDC_LDO_STATUS                  0xE1
+#define WM8350_GPIO_PIN_STATUS                  0xE6
+
+#define WM8350_DCDC1_FORCE_PWM                  0xF8
+#define WM8350_DCDC3_FORCE_PWM                  0xFA
+#define WM8350_DCDC4_FORCE_PWM                  0xFB
+#define WM8350_DCDC6_FORCE_PWM                  0xFD
+
+/*
+ * R172 (0xAC) - Current Sink Driver A
+ */
+#define WM8350_CS1_HIB_MODE                     0x1000
+#define WM8350_CS1_HIB_MODE_MASK                0x1000
+#define WM8350_CS1_HIB_MODE_SHIFT                   12
+#define WM8350_CS1_ISEL_MASK                    0x003F
+#define WM8350_CS1_ISEL_SHIFT                        0
+
+/* Bit values for R172 (0xAC) */
+#define WM8350_CS1_HIB_MODE_DISABLE                  0
+#define WM8350_CS1_HIB_MODE_LEAVE                    1
+
+#define WM8350_CS1_ISEL_220M                      0x3F
+
+/*
+ * R173 (0xAD) - CSA Flash control
+ */
+#define WM8350_CS1_FLASH_MODE                   0x8000
+#define WM8350_CS1_TRIGSRC                      0x4000
+#define WM8350_CS1_DRIVE                        0x2000
+#define WM8350_CS1_FLASH_DUR_MASK               0x0300
+#define WM8350_CS1_OFF_RAMP_MASK                0x0030
+#define WM8350_CS1_ON_RAMP_MASK                 0x0003
+
+/*
+ * R174 (0xAE) - Current Sink Driver B
+ */
+#define WM8350_CS2_HIB_MODE                     0x1000
+#define WM8350_CS2_ISEL_MASK                    0x003F
+
+/*
+ * R175 (0xAF) - CSB Flash control
+ */
+#define WM8350_CS2_FLASH_MODE                   0x8000
+#define WM8350_CS2_TRIGSRC                      0x4000
+#define WM8350_CS2_DRIVE                        0x2000
+#define WM8350_CS2_FLASH_DUR_MASK               0x0300
+#define WM8350_CS2_OFF_RAMP_MASK                0x0030
+#define WM8350_CS2_ON_RAMP_MASK                 0x0003
+
+/*
+ * R176 (0xB0) - DCDC/LDO requested
+ */
+#define WM8350_LS_ENA                           0x8000
+#define WM8350_LDO4_ENA                         0x0800
+#define WM8350_LDO3_ENA                         0x0400
+#define WM8350_LDO2_ENA                         0x0200
+#define WM8350_LDO1_ENA                         0x0100
+#define WM8350_DC6_ENA                          0x0020
+#define WM8350_DC5_ENA                          0x0010
+#define WM8350_DC4_ENA                          0x0008
+#define WM8350_DC3_ENA                          0x0004
+#define WM8350_DC2_ENA                          0x0002
+#define WM8350_DC1_ENA                          0x0001
+
+/*
+ * R177 (0xB1) - DCDC Active options
+ */
+#define WM8350_PUTO_MASK                        0x3000
+#define WM8350_PWRUP_DELAY_MASK                 0x0300
+#define WM8350_DC6_ACTIVE                       0x0020
+#define WM8350_DC4_ACTIVE                       0x0008
+#define WM8350_DC3_ACTIVE                       0x0004
+#define WM8350_DC1_ACTIVE                       0x0001
+
+/*
+ * R178 (0xB2) - DCDC Sleep options
+ */
+#define WM8350_DC6_SLEEP                        0x0020
+#define WM8350_DC4_SLEEP                        0x0008
+#define WM8350_DC3_SLEEP                        0x0004
+#define WM8350_DC1_SLEEP                        0x0001
+
+/*
+ * R179 (0xB3) - Power-check comparator
+ */
+#define WM8350_PCCMP_ERRACT                     0x4000
+#define WM8350_PCCMP_RAIL                       0x0100
+#define WM8350_PCCMP_OFF_THR_MASK               0x0070
+#define WM8350_PCCMP_ON_THR_MASK                0x0007
+
+/*
+ * R180 (0xB4) - DCDC1 Control
+ */
+#define WM8350_DC1_OPFLT                        0x0400
+#define WM8350_DC1_VSEL_MASK                    0x007F
+#define WM8350_DC1_VSEL_SHIFT                        0
+
+/*
+ * R181 (0xB5) - DCDC1 Timeouts
+ */
+#define WM8350_DC1_ERRACT_MASK                  0xC000
+#define WM8350_DC1_ERRACT_SHIFT                     14
+#define WM8350_DC1_ENSLOT_MASK                  0x3C00
+#define WM8350_DC1_ENSLOT_SHIFT                     10
+#define WM8350_DC1_SDSLOT_MASK                  0x03C0
+#define WM8350_DC1_UVTO_MASK                    0x0030
+#define WM8350_DC1_SDSLOT_SHIFT                      6
+
+/* Bit values for R181 (0xB5) */
+#define WM8350_DC1_ERRACT_NONE                       0
+#define WM8350_DC1_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC1_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R182 (0xB6) - DCDC1 Low Power
+ */
+#define WM8350_DC1_HIB_MODE_MASK                0x7000
+#define WM8350_DC1_HIB_TRIG_MASK                0x0300
+#define WM8350_DC1_VIMG_MASK                    0x007F
+
+/*
+ * R183 (0xB7) - DCDC2 Control
+ */
+#define WM8350_DC2_MODE                         0x4000
+#define WM8350_DC2_MODE_MASK                    0x4000
+#define WM8350_DC2_MODE_SHIFT                       14
+#define WM8350_DC2_HIB_MODE                     0x1000
+#define WM8350_DC2_HIB_MODE_MASK                0x1000
+#define WM8350_DC2_HIB_MODE_SHIFT                   12
+#define WM8350_DC2_HIB_TRIG_MASK                0x0300
+#define WM8350_DC2_HIB_TRIG_SHIFT                    8
+#define WM8350_DC2_ILIM                         0x0040
+#define WM8350_DC2_ILIM_MASK                    0x0040
+#define WM8350_DC2_ILIM_SHIFT                        6
+#define WM8350_DC2_RMP_MASK                     0x0018
+#define WM8350_DC2_RMP_SHIFT                         3
+#define WM8350_DC2_FBSRC_MASK                   0x0003
+#define WM8350_DC2_FBSRC_SHIFT                       0
+
+/* Bit values for R183 (0xB7) */
+#define WM8350_DC2_MODE_BOOST                        0
+#define WM8350_DC2_MODE_SWITCH                       1
+
+#define WM8350_DC2_HIB_MODE_ACTIVE                   1
+#define WM8350_DC2_HIB_MODE_DISABLE                  0
+
+#define WM8350_DC2_HIB_TRIG_NONE                     0
+#define WM8350_DC2_HIB_TRIG_LPWR1                    1
+#define WM8350_DC2_HIB_TRIG_LPWR2                    2
+#define WM8350_DC2_HIB_TRIG_LPWR3                    3
+
+#define WM8350_DC2_ILIM_HIGH                         0
+#define WM8350_DC2_ILIM_LOW                          1
+
+#define WM8350_DC2_RMP_30V                           0
+#define WM8350_DC2_RMP_20V                           1
+#define WM8350_DC2_RMP_10V                           2
+#define WM8350_DC2_RMP_5V                            3
+
+#define WM8350_DC2_FBSRC_FB2                         0
+#define WM8350_DC2_FBSRC_ISINKA                      1
+#define WM8350_DC2_FBSRC_ISINKB                      2
+#define WM8350_DC2_FBSRC_USB                         3
+
+/*
+ * R184 (0xB8) - DCDC2 Timeouts
+ */
+#define WM8350_DC2_ERRACT_MASK                  0xC000
+#define WM8350_DC2_ERRACT_SHIFT                     14
+#define WM8350_DC2_ENSLOT_MASK                  0x3C00
+#define WM8350_DC2_ENSLOT_SHIFT                     10
+#define WM8350_DC2_SDSLOT_MASK                  0x03C0
+#define WM8350_DC2_UVTO_MASK                    0x0030
+
+/* Bit values for R184 (0xB8) */
+#define WM8350_DC2_ERRACT_NONE                       0
+#define WM8350_DC2_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC2_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R186 (0xBA) - DCDC3 Control
+ */
+#define WM8350_DC3_OPFLT                        0x0400
+#define WM8350_DC3_VSEL_MASK                    0x007F
+#define WM8350_DC3_VSEL_SHIFT                        0
+
+/*
+ * R187 (0xBB) - DCDC3 Timeouts
+ */
+#define WM8350_DC3_ERRACT_MASK                  0xC000
+#define WM8350_DC3_ERRACT_SHIFT                     14
+#define WM8350_DC3_ENSLOT_MASK                  0x3C00
+#define WM8350_DC3_ENSLOT_SHIFT                     10
+#define WM8350_DC3_SDSLOT_MASK                  0x03C0
+#define WM8350_DC3_UVTO_MASK                    0x0030
+#define WM8350_DC3_SDSLOT_SHIFT                      6
+
+/* Bit values for R187 (0xBB) */
+#define WM8350_DC3_ERRACT_NONE                       0
+#define WM8350_DC3_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC3_ERRACT_SHUTDOWN_SYS               2
+/*
+ * R188 (0xBC) - DCDC3 Low Power
+ */
+#define WM8350_DC3_HIB_MODE_MASK                0x7000
+#define WM8350_DC3_HIB_TRIG_MASK                0x0300
+#define WM8350_DC3_VIMG_MASK                    0x007F
+
+/*
+ * R189 (0xBD) - DCDC4 Control
+ */
+#define WM8350_DC4_OPFLT                        0x0400
+#define WM8350_DC4_VSEL_MASK                    0x007F
+#define WM8350_DC4_VSEL_SHIFT                        0
+
+/*
+ * R190 (0xBE) - DCDC4 Timeouts
+ */
+#define WM8350_DC4_ERRACT_MASK                  0xC000
+#define WM8350_DC4_ERRACT_SHIFT                     14
+#define WM8350_DC4_ENSLOT_MASK                  0x3C00
+#define WM8350_DC4_ENSLOT_SHIFT                     10
+#define WM8350_DC4_SDSLOT_MASK                  0x03C0
+#define WM8350_DC4_UVTO_MASK                    0x0030
+#define WM8350_DC4_SDSLOT_SHIFT                      6
+
+/* Bit values for R190 (0xBE) */
+#define WM8350_DC4_ERRACT_NONE                       0
+#define WM8350_DC4_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC4_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R191 (0xBF) - DCDC4 Low Power
+ */
+#define WM8350_DC4_HIB_MODE_MASK                0x7000
+#define WM8350_DC4_HIB_TRIG_MASK                0x0300
+#define WM8350_DC4_VIMG_MASK                    0x007F
+
+/*
+ * R192 (0xC0) - DCDC5 Control
+ */
+#define WM8350_DC5_MODE                         0x4000
+#define WM8350_DC5_MODE_MASK                    0x4000
+#define WM8350_DC5_MODE_SHIFT                       14
+#define WM8350_DC5_HIB_MODE                     0x1000
+#define WM8350_DC5_HIB_MODE_MASK                0x1000
+#define WM8350_DC5_HIB_MODE_SHIFT                   12
+#define WM8350_DC5_HIB_TRIG_MASK                0x0300
+#define WM8350_DC5_HIB_TRIG_SHIFT                    8
+#define WM8350_DC5_ILIM                         0x0040
+#define WM8350_DC5_ILIM_MASK                    0x0040
+#define WM8350_DC5_ILIM_SHIFT                        6
+#define WM8350_DC5_RMP_MASK                     0x0018
+#define WM8350_DC5_RMP_SHIFT                         3
+#define WM8350_DC5_FBSRC_MASK                   0x0003
+#define WM8350_DC5_FBSRC_SHIFT                       0
+
+/* Bit values for R192 (0xC0) */
+#define WM8350_DC5_MODE_BOOST                        0
+#define WM8350_DC5_MODE_SWITCH                       1
+
+#define WM8350_DC5_HIB_MODE_ACTIVE                   1
+#define WM8350_DC5_HIB_MODE_DISABLE                  0
+
+#define WM8350_DC5_HIB_TRIG_NONE                     0
+#define WM8350_DC5_HIB_TRIG_LPWR1                    1
+#define WM8350_DC5_HIB_TRIG_LPWR2                    2
+#define WM8350_DC5_HIB_TRIG_LPWR3                    3
+
+#define WM8350_DC5_ILIM_HIGH                         0
+#define WM8350_DC5_ILIM_LOW                          1
+
+#define WM8350_DC5_RMP_30V                           0
+#define WM8350_DC5_RMP_20V                           1
+#define WM8350_DC5_RMP_10V                           2
+#define WM8350_DC5_RMP_5V                            3
+
+#define WM8350_DC5_FBSRC_FB2                         0
+#define WM8350_DC5_FBSRC_ISINKA                      1
+#define WM8350_DC5_FBSRC_ISINKB                      2
+#define WM8350_DC5_FBSRC_USB                         3
+
+/*
+ * R193 (0xC1) - DCDC5 Timeouts
+ */
+#define WM8350_DC5_ERRACT_MASK                  0xC000
+#define WM8350_DC5_ERRACT_SHIFT                     14
+#define WM8350_DC5_ENSLOT_MASK                  0x3C00
+#define WM8350_DC5_ENSLOT_SHIFT                     10
+#define WM8350_DC5_SDSLOT_MASK                  0x03C0
+#define WM8350_DC5_UVTO_MASK                    0x0030
+#define WM8350_DC5_SDSLOT_SHIFT                      6
+
+/* Bit values for R193 (0xC1) */
+#define WM8350_DC5_ERRACT_NONE                       0
+#define WM8350_DC5_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC5_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R195 (0xC3) - DCDC6 Control
+ */
+#define WM8350_DC6_OPFLT                        0x0400
+#define WM8350_DC6_VSEL_MASK                    0x007F
+#define WM8350_DC6_VSEL_SHIFT                        0
+
+/*
+ * R196 (0xC4) - DCDC6 Timeouts
+ */
+#define WM8350_DC6_ERRACT_MASK                  0xC000
+#define WM8350_DC6_ERRACT_SHIFT                     14
+#define WM8350_DC6_ENSLOT_MASK                  0x3C00
+#define WM8350_DC6_ENSLOT_SHIFT                     10
+#define WM8350_DC6_SDSLOT_MASK                  0x03C0
+#define WM8350_DC6_UVTO_MASK                    0x0030
+#define WM8350_DC6_SDSLOT_SHIFT                      6
+
+/* Bit values for R196 (0xC4) */
+#define WM8350_DC6_ERRACT_NONE                       0
+#define WM8350_DC6_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_DC6_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R197 (0xC5) - DCDC6 Low Power
+ */
+#define WM8350_DC6_HIB_MODE_MASK                0x7000
+#define WM8350_DC6_HIB_TRIG_MASK                0x0300
+#define WM8350_DC6_VIMG_MASK                    0x007F
+
+/*
+ * R199 (0xC7) - Limit Switch Control
+ */
+#define WM8350_LS_ERRACT_MASK                   0xC000
+#define WM8350_LS_ERRACT_SHIFT                      14
+#define WM8350_LS_ENSLOT_MASK                   0x3C00
+#define WM8350_LS_ENSLOT_SHIFT                      10
+#define WM8350_LS_SDSLOT_MASK                   0x03C0
+#define WM8350_LS_SDSLOT_SHIFT                       6
+#define WM8350_LS_HIB_MODE                      0x0010
+#define WM8350_LS_HIB_MODE_MASK                 0x0010
+#define WM8350_LS_HIB_MODE_SHIFT                     4
+#define WM8350_LS_HIB_PROT                      0x0002
+#define WM8350_LS_HIB_PROT_MASK                 0x0002
+#define WM8350_LS_HIB_PROT_SHIFT                     1
+#define WM8350_LS_PROT                          0x0001
+#define WM8350_LS_PROT_MASK                     0x0001
+#define WM8350_LS_PROT_SHIFT                         0
+
+/* Bit values for R199 (0xC7) */
+#define WM8350_LS_ERRACT_NONE                       0
+#define WM8350_LS_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_LS_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R200 (0xC8) - LDO1 Control
+ */
+#define WM8350_LDO1_SWI                         0x4000
+#define WM8350_LDO1_OPFLT                       0x0400
+#define WM8350_LDO1_VSEL_MASK                   0x001F
+#define WM8350_LDO1_VSEL_SHIFT                       0
+
+/*
+ * R201 (0xC9) - LDO1 Timeouts
+ */
+#define WM8350_LDO1_ERRACT_MASK                 0xC000
+#define WM8350_LDO1_ERRACT_SHIFT                    14
+#define WM8350_LDO1_ENSLOT_MASK                 0x3C00
+#define WM8350_LDO1_ENSLOT_SHIFT                    10
+#define WM8350_LDO1_SDSLOT_MASK                 0x03C0
+#define WM8350_LDO1_UVTO_MASK                   0x0030
+#define WM8350_LDO1_SDSLOT_SHIFT                     6
+
+/* Bit values for R201 (0xC9) */
+#define WM8350_LDO1_ERRACT_NONE                       0
+#define WM8350_LDO1_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_LDO1_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R202 (0xCA) - LDO1 Low Power
+ */
+#define WM8350_LDO1_HIB_MODE_MASK               0x3000
+#define WM8350_LDO1_HIB_TRIG_MASK               0x0300
+#define WM8350_LDO1_VIMG_MASK                   0x001F
+#define WM8350_LDO1_HIB_MODE_DIS               (0x1 << 12)
+
+
+/*
+ * R203 (0xCB) - LDO2 Control
+ */
+#define WM8350_LDO2_SWI                         0x4000
+#define WM8350_LDO2_OPFLT                       0x0400
+#define WM8350_LDO2_VSEL_MASK                   0x001F
+#define WM8350_LDO2_VSEL_SHIFT                       0
+
+/*
+ * R204 (0xCC) - LDO2 Timeouts
+ */
+#define WM8350_LDO2_ERRACT_MASK                 0xC000
+#define WM8350_LDO2_ERRACT_SHIFT                    14
+#define WM8350_LDO2_ENSLOT_MASK                 0x3C00
+#define WM8350_LDO2_ENSLOT_SHIFT                    10
+#define WM8350_LDO2_SDSLOT_MASK                 0x03C0
+#define WM8350_LDO2_SDSLOT_SHIFT                     6
+
+/* Bit values for R204 (0xCC) */
+#define WM8350_LDO2_ERRACT_NONE                       0
+#define WM8350_LDO2_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_LDO2_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R205 (0xCD) - LDO2 Low Power
+ */
+#define WM8350_LDO2_HIB_MODE_MASK               0x3000
+#define WM8350_LDO2_HIB_TRIG_MASK               0x0300
+#define WM8350_LDO2_VIMG_MASK                   0x001F
+
+/*
+ * R206 (0xCE) - LDO3 Control
+ */
+#define WM8350_LDO3_SWI                         0x4000
+#define WM8350_LDO3_OPFLT                       0x0400
+#define WM8350_LDO3_VSEL_MASK                   0x001F
+#define WM8350_LDO3_VSEL_SHIFT                       0
+
+/*
+ * R207 (0xCF) - LDO3 Timeouts
+ */
+#define WM8350_LDO3_ERRACT_MASK                 0xC000
+#define WM8350_LDO3_ERRACT_SHIFT                    14
+#define WM8350_LDO3_ENSLOT_MASK                 0x3C00
+#define WM8350_LDO3_ENSLOT_SHIFT                    10
+#define WM8350_LDO3_SDSLOT_MASK                 0x03C0
+#define WM8350_LDO3_UVTO_MASK                   0x0030
+#define WM8350_LDO3_SDSLOT_SHIFT                     6
+
+/* Bit values for R207 (0xCF) */
+#define WM8350_LDO3_ERRACT_NONE                       0
+#define WM8350_LDO3_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_LDO3_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R208 (0xD0) - LDO3 Low Power
+ */
+#define WM8350_LDO3_HIB_MODE_MASK               0x3000
+#define WM8350_LDO3_HIB_TRIG_MASK               0x0300
+#define WM8350_LDO3_VIMG_MASK                   0x001F
+
+/*
+ * R209 (0xD1) - LDO4 Control
+ */
+#define WM8350_LDO4_SWI                         0x4000
+#define WM8350_LDO4_OPFLT                       0x0400
+#define WM8350_LDO4_VSEL_MASK                   0x001F
+#define WM8350_LDO4_VSEL_SHIFT                       0
+
+/*
+ * R210 (0xD2) - LDO4 Timeouts
+ */
+#define WM8350_LDO4_ERRACT_MASK                 0xC000
+#define WM8350_LDO4_ERRACT_SHIFT                    14
+#define WM8350_LDO4_ENSLOT_MASK                 0x3C00
+#define WM8350_LDO4_ENSLOT_SHIFT                    10
+#define WM8350_LDO4_SDSLOT_MASK                 0x03C0
+#define WM8350_LDO4_UVTO_MASK                   0x0030
+#define WM8350_LDO4_SDSLOT_SHIFT                     6
+
+/* Bit values for R210 (0xD2) */
+#define WM8350_LDO4_ERRACT_NONE                       0
+#define WM8350_LDO4_ERRACT_SHUTDOWN_CONV              1
+#define WM8350_LDO4_ERRACT_SHUTDOWN_SYS               2
+
+/*
+ * R211 (0xD3) - LDO4 Low Power
+ */
+#define WM8350_LDO4_HIB_MODE_MASK               0x3000
+#define WM8350_LDO4_HIB_TRIG_MASK               0x0300
+#define WM8350_LDO4_VIMG_MASK                   0x001F
+
+/*
+ * R215 (0xD7) - VCC_FAULT Masks
+ */
+#define WM8350_LS_FAULT                         0x8000
+#define WM8350_LDO4_FAULT                       0x0800
+#define WM8350_LDO3_FAULT                       0x0400
+#define WM8350_LDO2_FAULT                       0x0200
+#define WM8350_LDO1_FAULT                       0x0100
+#define WM8350_DC6_FAULT                        0x0020
+#define WM8350_DC5_FAULT                        0x0010
+#define WM8350_DC4_FAULT                        0x0008
+#define WM8350_DC3_FAULT                        0x0004
+#define WM8350_DC2_FAULT                        0x0002
+#define WM8350_DC1_FAULT                        0x0001
+
+/*
+ * R216 (0xD8) - Main Bandgap Control
+ */
+#define WM8350_MBG_LOAD_FUSES                   0x8000
+#define WM8350_MBG_FUSE_WPREP                   0x4000
+#define WM8350_MBG_FUSE_WRITE                   0x2000
+#define WM8350_MBG_FUSE_TRIM_MASK               0x1F00
+#define WM8350_MBG_TRIM_SRC                     0x0020
+#define WM8350_MBG_USER_TRIM_MASK               0x001F
+
+/*
+ * R217 (0xD9) - OSC Control
+ */
+#define WM8350_OSC_LOAD_FUSES                   0x8000
+#define WM8350_OSC_FUSE_WPREP                   0x4000
+#define WM8350_OSC_FUSE_WRITE                   0x2000
+#define WM8350_OSC_FUSE_TRIM_MASK               0x0F00
+#define WM8350_OSC_TRIM_SRC                     0x0020
+#define WM8350_OSC_USER_TRIM_MASK               0x000F
+
+/*
+ * R248 (0xF8) - DCDC1 Force PWM
+ */
+#define WM8350_DCDC1_FORCE_PWM_ENA              0x0010
+
+/*
+ * R250 (0xFA) - DCDC3 Force PWM
+ */
+#define WM8350_DCDC3_FORCE_PWM_ENA              0x0010
+
+/*
+ * R251 (0xFB) - DCDC4 Force PWM
+ */
+#define WM8350_DCDC4_FORCE_PWM_ENA              0x0010
+
+/*
+ * R253 (0xFD) - DCDC1 Force PWM
+ */
+#define WM8350_DCDC6_FORCE_PWM_ENA              0x0010
+
+/*
+ * DCDC's
+ */
+#define WM8350_DCDC_1                          0
+#define WM8350_DCDC_2                          1
+#define WM8350_DCDC_3                          2
+#define WM8350_DCDC_4                          3
+#define WM8350_DCDC_5                          4
+#define WM8350_DCDC_6                          5
+
+/* DCDC modes */
+#define WM8350_DCDC_ACTIVE_STANDBY             0
+#define WM8350_DCDC_ACTIVE_PULSE               1
+#define WM8350_DCDC_SLEEP_NORMAL               0
+#define WM8350_DCDC_SLEEP_LOW                  1
+
+/* DCDC Low power (Hibernate) mode */
+#define WM8350_DCDC_HIB_MODE_CUR               (0 << 12)
+#define WM8350_DCDC_HIB_MODE_IMAGE             (1 << 12)
+#define WM8350_DCDC_HIB_MODE_STANDBY           (2 << 12)
+#define WM8350_DCDC_HIB_MODE_LDO               (4 << 12)
+#define WM8350_DCDC_HIB_MODE_LDO_IM            (5 << 12)
+#define WM8350_DCDC_HIB_MODE_DIS               (7 << 12)
+#define WM8350_DCDC_HIB_MODE_MASK              (7 << 12)
+
+/* DCDC Low Power (Hibernate) signal */
+#define WM8350_DCDC_HIB_SIG_REG                        (0 << 8)
+#define WM8350_DCDC_HIB_SIG_LPWR1              (1 << 8)
+#define WM8350_DCDC_HIB_SIG_LPWR2              (2 << 8)
+#define WM8350_DCDC_HIB_SIG_LPWR3              (3 << 8)
+
+/* LDO Low power (Hibernate) mode */
+#define WM8350_LDO_HIB_MODE_IMAGE              (0 << 0)
+#define WM8350_LDO_HIB_MODE_DIS                        (1 << 0)
+
+/* LDO Low Power (Hibernate) signal */
+#define WM8350_LDO_HIB_SIG_REG                 (0 << 8)
+#define WM8350_LDO_HIB_SIG_LPWR1               (1 << 8)
+#define WM8350_LDO_HIB_SIG_LPWR2               (2 << 8)
+#define WM8350_LDO_HIB_SIG_LPWR3               (3 << 8)
+
+/*
+ * LDOs
+ */
+#define WM8350_LDO_1                           6
+#define WM8350_LDO_2                           7
+#define WM8350_LDO_3                           8
+#define WM8350_LDO_4                           9
+
+/*
+ * ISINKs
+ */
+#define WM8350_ISINK_A                         10
+#define WM8350_ISINK_B                         11
+
+#define WM8350_ISINK_MODE_BOOST                        0
+#define WM8350_ISINK_MODE_SWITCH               1
+#define WM8350_ISINK_ILIM_NORMAL               0
+#define WM8350_ISINK_ILIM_LOW                  1
+
+#define WM8350_ISINK_FLASH_DISABLE             0
+#define WM8350_ISINK_FLASH_ENABLE              1
+#define WM8350_ISINK_FLASH_TRIG_BIT            0
+#define WM8350_ISINK_FLASH_TRIG_GPIO           1
+#define WM8350_ISINK_FLASH_MODE_EN             (1 << 13)
+#define WM8350_ISINK_FLASH_MODE_DIS            (0 << 13)
+#define WM8350_ISINK_FLASH_DUR_32MS            (0 << 8)
+#define WM8350_ISINK_FLASH_DUR_64MS            (1 << 8)
+#define WM8350_ISINK_FLASH_DUR_96MS            (2 << 8)
+#define WM8350_ISINK_FLASH_DUR_1024MS          (3 << 8)
+#define WM8350_ISINK_FLASH_ON_INSTANT          (0 << 4)
+#define WM8350_ISINK_FLASH_ON_0_25S            (1 << 4)
+#define WM8350_ISINK_FLASH_ON_0_50S            (2 << 4)
+#define WM8350_ISINK_FLASH_ON_1_00S            (3 << 4)
+#define WM8350_ISINK_FLASH_ON_1_95S            (1 << 4)
+#define WM8350_ISINK_FLASH_ON_3_91S            (2 << 4)
+#define WM8350_ISINK_FLASH_ON_7_80S            (3 << 4)
+#define WM8350_ISINK_FLASH_OFF_INSTANT         (0 << 0)
+#define WM8350_ISINK_FLASH_OFF_0_25S           (1 << 0)
+#define WM8350_ISINK_FLASH_OFF_0_50S           (2 << 0)
+#define WM8350_ISINK_FLASH_OFF_1_00S           (3 << 0)
+#define WM8350_ISINK_FLASH_OFF_1_95S           (1 << 0)
+#define WM8350_ISINK_FLASH_OFF_3_91S           (2 << 0)
+#define WM8350_ISINK_FLASH_OFF_7_80S           (3 << 0)
+
+/*
+ * Regulator Interrupts.
+ */
+#define WM8350_IRQ_CS1                         13
+#define WM8350_IRQ_CS2                         14
+#define WM8350_IRQ_UV_LDO4                     25
+#define WM8350_IRQ_UV_LDO3                     26
+#define WM8350_IRQ_UV_LDO2                     27
+#define WM8350_IRQ_UV_LDO1                     28
+#define WM8350_IRQ_UV_DC6                      29
+#define WM8350_IRQ_UV_DC5                      30
+#define WM8350_IRQ_UV_DC4                      31
+#define WM8350_IRQ_UV_DC3                      32
+#define WM8350_IRQ_UV_DC2                      33
+#define WM8350_IRQ_UV_DC1                      34
+#define WM8350_IRQ_OC_LS                       35
+
+#define NUM_WM8350_REGULATORS                  12
+
+struct wm8350;
+struct platform_device;
+struct regulator_init_data;
+
+struct wm8350_pmic {
+       /* ISINK to DCDC mapping */
+       int isink_A_dcdc;
+       int isink_B_dcdc;
+
+       /* hibernate configs */
+       u16 dcdc1_hib_mode;
+       u16 dcdc3_hib_mode;
+       u16 dcdc4_hib_mode;
+       u16 dcdc6_hib_mode;
+
+       /* regulator devices */
+       struct platform_device *pdev[NUM_WM8350_REGULATORS];
+};
+
+int wm8350_register_regulator(struct wm8350 *wm8350, int reg,
+                             struct regulator_init_data *initdata);
+
+/*
+ * Additional DCDC control not supported via regulator API
+ */
+int wm8350_dcdc_set_slot(struct wm8350 *wm8350, int dcdc, u16 start,
+                        u16 stop, u16 fault);
+int wm8350_dcdc25_set_mode(struct wm8350 *wm8350, int dcdc, u16 mode,
+                          u16 ilim, u16 ramp, u16 feedback);
+
+/*
+ * Additional LDO control not supported via regulator API
+ */
+int wm8350_ldo_set_slot(struct wm8350 *wm8350, int ldo, u16 start, u16 stop);
+
+/*
+ * Additional ISINK control not supported via regulator API
+ */
+int wm8350_isink_set_flash(struct wm8350 *wm8350, int isink, u16 mode,
+                          u16 trigger, u16 duration, u16 on_ramp,
+                          u16 off_ramp, u16 drive);
+
+#endif
diff --git a/include/linux/mfd/wm8350/rtc.h b/include/linux/mfd/wm8350/rtc.h
new file mode 100644 (file)
index 0000000..dfda69e
--- /dev/null
@@ -0,0 +1,266 @@
+/*
+ * rtc.h  --  RTC driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#ifndef __LINUX_MFD_WM8350_RTC_H
+#define __LINUX_MFD_WM8350_RTC_H
+
+#include <linux/platform_device.h>
+
+/*
+ * Register values.
+ */
+#define WM8350_RTC_SECONDS_MINUTES              0x10
+#define WM8350_RTC_HOURS_DAY                    0x11
+#define WM8350_RTC_DATE_MONTH                   0x12
+#define WM8350_RTC_YEAR                         0x13
+#define WM8350_ALARM_SECONDS_MINUTES            0x14
+#define WM8350_ALARM_HOURS_DAY                  0x15
+#define WM8350_ALARM_DATE_MONTH                 0x16
+#define WM8350_RTC_TIME_CONTROL                 0x17
+
+/*
+ * R16 (0x10) - RTC Seconds/Minutes
+ */
+#define WM8350_RTC_MINS_MASK                    0x7F00
+#define WM8350_RTC_MINS_SHIFT                        8
+#define WM8350_RTC_SECS_MASK                    0x007F
+#define WM8350_RTC_SECS_SHIFT                        0
+
+/*
+ * R17 (0x11) - RTC Hours/Day
+ */
+#define WM8350_RTC_DAY_MASK                     0x0700
+#define WM8350_RTC_DAY_SHIFT                         8
+#define WM8350_RTC_HPM_MASK                     0x0020
+#define WM8350_RTC_HPM_SHIFT                         5
+#define WM8350_RTC_HRS_MASK                     0x001F
+#define WM8350_RTC_HRS_SHIFT                         0
+
+/* Bit values for R21 (0x15) */
+#define WM8350_RTC_DAY_SUN                           1
+#define WM8350_RTC_DAY_MON                           2
+#define WM8350_RTC_DAY_TUE                           3
+#define WM8350_RTC_DAY_WED                           4
+#define WM8350_RTC_DAY_THU                           5
+#define WM8350_RTC_DAY_FRI                           6
+#define WM8350_RTC_DAY_SAT                           7
+
+#define WM8350_RTC_HPM_AM                            0
+#define WM8350_RTC_HPM_PM                            1
+
+/*
+ * R18 (0x12) - RTC Date/Month
+ */
+#define WM8350_RTC_MTH_MASK                     0x1F00
+#define WM8350_RTC_MTH_SHIFT                         8
+#define WM8350_RTC_DATE_MASK                    0x003F
+#define WM8350_RTC_DATE_SHIFT                        0
+
+/* Bit values for R22 (0x16) */
+#define WM8350_RTC_MTH_JAN                           1
+#define WM8350_RTC_MTH_FEB                           2
+#define WM8350_RTC_MTH_MAR                           3
+#define WM8350_RTC_MTH_APR                           4
+#define WM8350_RTC_MTH_MAY                           5
+#define WM8350_RTC_MTH_JUN                           6
+#define WM8350_RTC_MTH_JUL                           7
+#define WM8350_RTC_MTH_AUG                           8
+#define WM8350_RTC_MTH_SEP                           9
+#define WM8350_RTC_MTH_OCT                          10
+#define WM8350_RTC_MTH_NOV                          11
+#define WM8350_RTC_MTH_DEC                          12
+#define WM8350_RTC_MTH_JAN_BCD                    0x01
+#define WM8350_RTC_MTH_FEB_BCD                    0x02
+#define WM8350_RTC_MTH_MAR_BCD                    0x03
+#define WM8350_RTC_MTH_APR_BCD                    0x04
+#define WM8350_RTC_MTH_MAY_BCD                    0x05
+#define WM8350_RTC_MTH_JUN_BCD                    0x06
+#define WM8350_RTC_MTH_JUL_BCD                    0x07
+#define WM8350_RTC_MTH_AUG_BCD                    0x08
+#define WM8350_RTC_MTH_SEP_BCD                    0x09
+#define WM8350_RTC_MTH_OCT_BCD                    0x10
+#define WM8350_RTC_MTH_NOV_BCD                    0x11
+#define WM8350_RTC_MTH_DEC_BCD                    0x12
+
+/*
+ * R19 (0x13) - RTC Year
+ */
+#define WM8350_RTC_YHUNDREDS_MASK               0x3F00
+#define WM8350_RTC_YHUNDREDS_SHIFT                   8
+#define WM8350_RTC_YUNITS_MASK                  0x00FF
+#define WM8350_RTC_YUNITS_SHIFT                      0
+
+/*
+ * R20 (0x14) - Alarm Seconds/Minutes
+ */
+#define WM8350_RTC_ALMMINS_MASK                 0x7F00
+#define WM8350_RTC_ALMMINS_SHIFT                     8
+#define WM8350_RTC_ALMSECS_MASK                 0x007F
+#define WM8350_RTC_ALMSECS_SHIFT                     0
+
+/* Bit values for R20 (0x14) */
+#define WM8350_RTC_ALMMINS_DONT_CARE                -1
+#define WM8350_RTC_ALMSECS_DONT_CARE                -1
+
+/*
+ * R21 (0x15) - Alarm Hours/Day
+ */
+#define WM8350_RTC_ALMDAY_MASK                  0x0F00
+#define WM8350_RTC_ALMDAY_SHIFT                      8
+#define WM8350_RTC_ALMHPM_MASK                  0x0020
+#define WM8350_RTC_ALMHPM_SHIFT                      5
+#define WM8350_RTC_ALMHRS_MASK                  0x001F
+#define WM8350_RTC_ALMHRS_SHIFT                      0
+
+/* Bit values for R21 (0x15) */
+#define WM8350_RTC_ALMDAY_DONT_CARE                 -1
+#define WM8350_RTC_ALMDAY_SUN                        1
+#define WM8350_RTC_ALMDAY_MON                        2
+#define WM8350_RTC_ALMDAY_TUE                        3
+#define WM8350_RTC_ALMDAY_WED                        4
+#define WM8350_RTC_ALMDAY_THU                        5
+#define WM8350_RTC_ALMDAY_FRI                        6
+#define WM8350_RTC_ALMDAY_SAT                        7
+
+#define WM8350_RTC_ALMHPM_AM                         0
+#define WM8350_RTC_ALMHPM_PM                         1
+
+#define WM8350_RTC_ALMHRS_DONT_CARE                 -1
+
+/*
+ * R22 (0x16) - Alarm Date/Month
+ */
+#define WM8350_RTC_ALMMTH_MASK                  0x1F00
+#define WM8350_RTC_ALMMTH_SHIFT                      8
+#define WM8350_RTC_ALMDATE_MASK                 0x003F
+#define WM8350_RTC_ALMDATE_SHIFT                     0
+
+/* Bit values for R22 (0x16) */
+#define WM8350_RTC_ALMDATE_DONT_CARE                -1
+
+#define WM8350_RTC_ALMMTH_DONT_CARE                 -1
+#define WM8350_RTC_ALMMTH_JAN                        1
+#define WM8350_RTC_ALMMTH_FEB                        2
+#define WM8350_RTC_ALMMTH_MAR                        3
+#define WM8350_RTC_ALMMTH_APR                        4
+#define WM8350_RTC_ALMMTH_MAY                        5
+#define WM8350_RTC_ALMMTH_JUN                        6
+#define WM8350_RTC_ALMMTH_JUL                        7
+#define WM8350_RTC_ALMMTH_AUG                        8
+#define WM8350_RTC_ALMMTH_SEP                        9
+#define WM8350_RTC_ALMMTH_OCT                       10
+#define WM8350_RTC_ALMMTH_NOV                       11
+#define WM8350_RTC_ALMMTH_DEC                       12
+#define WM8350_RTC_ALMMTH_JAN_BCD                 0x01
+#define WM8350_RTC_ALMMTH_FEB_BCD                 0x02
+#define WM8350_RTC_ALMMTH_MAR_BCD                 0x03
+#define WM8350_RTC_ALMMTH_APR_BCD                 0x04
+#define WM8350_RTC_ALMMTH_MAY_BCD                 0x05
+#define WM8350_RTC_ALMMTH_JUN_BCD                 0x06
+#define WM8350_RTC_ALMMTH_JUL_BCD                 0x07
+#define WM8350_RTC_ALMMTH_AUG_BCD                 0x08
+#define WM8350_RTC_ALMMTH_SEP_BCD                 0x09
+#define WM8350_RTC_ALMMTH_OCT_BCD                 0x10
+#define WM8350_RTC_ALMMTH_NOV_BCD                 0x11
+#define WM8350_RTC_ALMMTH_DEC_BCD                 0x12
+
+/*
+ * R23 (0x17) - RTC Time Control
+ */
+#define WM8350_RTC_BCD                          0x8000
+#define WM8350_RTC_BCD_MASK                     0x8000
+#define WM8350_RTC_BCD_SHIFT                        15
+#define WM8350_RTC_12HR                         0x4000
+#define WM8350_RTC_12HR_MASK                    0x4000
+#define WM8350_RTC_12HR_SHIFT                       14
+#define WM8350_RTC_DST                          0x2000
+#define WM8350_RTC_DST_MASK                     0x2000
+#define WM8350_RTC_DST_SHIFT                        13
+#define WM8350_RTC_SET                          0x0800
+#define WM8350_RTC_SET_MASK                     0x0800
+#define WM8350_RTC_SET_SHIFT                        11
+#define WM8350_RTC_STS                          0x0400
+#define WM8350_RTC_STS_MASK                     0x0400
+#define WM8350_RTC_STS_SHIFT                        10
+#define WM8350_RTC_ALMSET                       0x0200
+#define WM8350_RTC_ALMSET_MASK                  0x0200
+#define WM8350_RTC_ALMSET_SHIFT                      9
+#define WM8350_RTC_ALMSTS                       0x0100
+#define WM8350_RTC_ALMSTS_MASK                  0x0100
+#define WM8350_RTC_ALMSTS_SHIFT                      8
+#define WM8350_RTC_PINT                         0x0070
+#define WM8350_RTC_PINT_MASK                    0x0070
+#define WM8350_RTC_PINT_SHIFT                        4
+#define WM8350_RTC_DSW                          0x000F
+#define WM8350_RTC_DSW_MASK                     0x000F
+#define WM8350_RTC_DSW_SHIFT                         0
+
+/* Bit values for R23 (0x17) */
+#define WM8350_RTC_BCD_BINARY                        0
+#define WM8350_RTC_BCD_BCD                           1
+
+#define WM8350_RTC_12HR_24HR                         0
+#define WM8350_RTC_12HR_12HR                         1
+
+#define WM8350_RTC_DST_DISABLED                      0
+#define WM8350_RTC_DST_ENABLED                       1
+
+#define WM8350_RTC_SET_RUN                           0
+#define WM8350_RTC_SET_SET                           1
+
+#define WM8350_RTC_STS_RUNNING                       0
+#define WM8350_RTC_STS_STOPPED                       1
+
+#define WM8350_RTC_ALMSET_RUN                        0
+#define WM8350_RTC_ALMSET_SET                        1
+
+#define WM8350_RTC_ALMSTS_RUNNING                    0
+#define WM8350_RTC_ALMSTS_STOPPED                    1
+
+#define WM8350_RTC_PINT_DISABLED                     0
+#define WM8350_RTC_PINT_SECS                         1
+#define WM8350_RTC_PINT_MINS                         2
+#define WM8350_RTC_PINT_HRS                          3
+#define WM8350_RTC_PINT_DAYS                         4
+#define WM8350_RTC_PINT_MTHS                         5
+
+#define WM8350_RTC_DSW_DISABLED                      0
+#define WM8350_RTC_DSW_1HZ                           1
+#define WM8350_RTC_DSW_2HZ                           2
+#define WM8350_RTC_DSW_4HZ                           3
+#define WM8350_RTC_DSW_8HZ                           4
+#define WM8350_RTC_DSW_16HZ                          5
+#define WM8350_RTC_DSW_32HZ                          6
+#define WM8350_RTC_DSW_64HZ                          7
+#define WM8350_RTC_DSW_128HZ                         8
+#define WM8350_RTC_DSW_256HZ                         9
+#define WM8350_RTC_DSW_512HZ                        10
+#define WM8350_RTC_DSW_1024HZ                       11
+
+/*
+ * R218 (0xDA) - RTC Tick Control
+ */
+#define WM8350_RTC_TICKSTS                      0x4000
+#define WM8350_RTC_CLKSRC                       0x2000
+#define WM8350_RTC_TRIM_MASK                    0x03FF
+
+/*
+ * RTC Interrupts.
+ */
+#define WM8350_IRQ_RTC_PER                     7
+#define WM8350_IRQ_RTC_SEC                     8
+#define WM8350_IRQ_RTC_ALM                     9
+
+struct wm8350_rtc {
+       struct platform_device *pdev;
+};
+
+#endif
diff --git a/include/linux/mfd/wm8350/supply.h b/include/linux/mfd/wm8350/supply.h
new file mode 100644 (file)
index 0000000..1c8f3cd
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * supply.h  --  Power Supply Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ *
+ */
+
+#ifndef __LINUX_MFD_WM8350_SUPPLY_H_
+#define __LINUX_MFD_WM8350_SUPPLY_H_
+
+#include <linux/platform_device.h>
+
+/*
+ * Charger registers
+ */
+#define WM8350_BATTERY_CHARGER_CONTROL_1        0xA8
+#define WM8350_BATTERY_CHARGER_CONTROL_2        0xA9
+#define WM8350_BATTERY_CHARGER_CONTROL_3        0xAA
+
+/*
+ * R168 (0xA8) - Battery Charger Control 1
+ */
+#define WM8350_CHG_ENA_R168                     0x8000
+#define WM8350_CHG_THR                          0x2000
+#define WM8350_CHG_EOC_SEL_MASK                 0x1C00
+#define WM8350_CHG_TRICKLE_TEMP_CHOKE           0x0200
+#define WM8350_CHG_TRICKLE_USB_CHOKE            0x0100
+#define WM8350_CHG_RECOVER_T                    0x0080
+#define WM8350_CHG_END_ACT                      0x0040
+#define WM8350_CHG_FAST                         0x0020
+#define WM8350_CHG_FAST_USB_THROTTLE            0x0010
+#define WM8350_CHG_NTC_MON                      0x0008
+#define WM8350_CHG_BATT_HOT_MON                 0x0004
+#define WM8350_CHG_BATT_COLD_MON                0x0002
+#define WM8350_CHG_CHIP_TEMP_MON                0x0001
+
+/*
+ * R169 (0xA9) - Battery Charger Control 2
+ */
+#define WM8350_CHG_ACTIVE                       0x8000
+#define WM8350_CHG_PAUSE                        0x4000
+#define WM8350_CHG_STS_MASK                     0x3000
+#define WM8350_CHG_TIME_MASK                    0x0F00
+#define WM8350_CHG_MASK_WALL_FB                 0x0080
+#define WM8350_CHG_TRICKLE_SEL                  0x0040
+#define WM8350_CHG_VSEL_MASK                    0x0030
+#define WM8350_CHG_ISEL_MASK                    0x000F
+#define WM8350_CHG_STS_OFF                      0x0000
+#define WM8350_CHG_STS_TRICKLE                  0x1000
+#define WM8350_CHG_STS_FAST                     0x2000
+
+/*
+ * R170 (0xAA) - Battery Charger Control 3
+ */
+#define WM8350_CHG_THROTTLE_T_MASK              0x0060
+#define WM8350_CHG_SMART                        0x0010
+#define WM8350_CHG_TIMER_ADJT_MASK              0x000F
+
+/*
+ * Charger Interrupts
+ */
+#define WM8350_IRQ_CHG_BAT_HOT                 0
+#define WM8350_IRQ_CHG_BAT_COLD                        1
+#define WM8350_IRQ_CHG_BAT_FAIL                        2
+#define WM8350_IRQ_CHG_TO                      3
+#define WM8350_IRQ_CHG_END                     4
+#define WM8350_IRQ_CHG_START                   5
+#define WM8350_IRQ_CHG_FAST_RDY                        6
+#define WM8350_IRQ_CHG_VBATT_LT_3P9            10
+#define WM8350_IRQ_CHG_VBATT_LT_3P1            11
+#define WM8350_IRQ_CHG_VBATT_LT_2P85           12
+
+/*
+ * Charger Policy
+ */
+#define WM8350_CHG_TRICKLE_50mA                        (0 << 6)
+#define WM8350_CHG_TRICKLE_100mA               (1 << 6)
+#define WM8350_CHG_4_05V                       (0 << 4)
+#define WM8350_CHG_4_10V                       (1 << 4)
+#define WM8350_CHG_4_15V                       (2 << 4)
+#define WM8350_CHG_4_20V                       (3 << 4)
+#define WM8350_CHG_FAST_LIMIT_mA(x)            ((x / 50) & 0xf)
+#define WM8350_CHG_EOC_mA(x)                   (((x - 10) & 0x7) << 10)
+#define WM8350_CHG_TRICKLE_3_1V                        (0 << 13)
+#define WM8350_CHG_TRICKLE_3_9V                        (1 << 13)
+
+/*
+ * Supply Registers.
+ */
+#define WM8350_USB_VOLTAGE_READBACK             0x9C
+#define WM8350_LINE_VOLTAGE_READBACK            0x9D
+#define WM8350_BATT_VOLTAGE_READBACK            0x9E
+
+/*
+ * Supply Interrupts.
+ */
+#define WM8350_IRQ_USB_LIMIT                   15
+#define WM8350_IRQ_EXT_USB_FB                  36
+#define WM8350_IRQ_EXT_WALL_FB                 37
+#define WM8350_IRQ_EXT_BAT_FB                  38
+
+struct wm8350_power {
+       struct platform_device *pdev;
+};
+
+#endif
diff --git a/include/linux/mfd/wm8350/wdt.h b/include/linux/mfd/wm8350/wdt.h
new file mode 100644 (file)
index 0000000..f6135b5
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * wdt.h  --  Watchdog Driver for Wolfson WM8350 PMIC
+ *
+ * Copyright 2007, 2008 Wolfson Microelectronics PLC
+ *
+ *  This program is free software; you can redistribute  it and/or modify it
+ *  under  the terms of  the GNU General  Public License as published by the
+ *  Free Software Foundation;  either version 2 of the  License, or (at your
+ *  option) any later version.
+ */
+
+#ifndef __LINUX_MFD_WM8350_WDT_H_
+#define __LINUX_MFD_WM8350_WDT_H_
+
+#include <linux/platform_device.h>
+
+#define WM8350_WDOG_HIB_MODE                    0x0080
+#define WM8350_WDOG_DEBUG                       0x0040
+#define WM8350_WDOG_MODE_MASK                   0x0030
+#define WM8350_WDOG_TO_MASK                     0x0007
+
+#define WM8350_IRQ_SYS_WDOG_TO                 24
+
+struct wm8350_wdt {
+       struct platform_device *pdev;
+};
+
+#endif
diff --git a/include/linux/mfd/wm8400-audio.h b/include/linux/mfd/wm8400-audio.h
new file mode 100644 (file)
index 0000000..b6640e0
--- /dev/null
@@ -0,0 +1,1186 @@
+/*
+ * wm8400 private definitions for audio
+ *
+ * Copyright 2008 Wolfson Microelectronics plc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __LINUX_MFD_WM8400_AUDIO_H
+#define __LINUX_MFD_WM8400_AUDIO_H
+
+#include <linux/mfd/wm8400-audio.h>
+
+/*
+ * R2 (0x02) - Power Management (1)
+ */
+#define WM8400_CODEC_ENA                        0x8000  /* CODEC_ENA */
+#define WM8400_CODEC_ENA_MASK                   0x8000  /* CODEC_ENA */
+#define WM8400_CODEC_ENA_SHIFT                      15  /* CODEC_ENA */
+#define WM8400_CODEC_ENA_WIDTH                       1  /* CODEC_ENA */
+#define WM8400_SYSCLK_ENA                       0x4000  /* SYSCLK_ENA */
+#define WM8400_SYSCLK_ENA_MASK                  0x4000  /* SYSCLK_ENA */
+#define WM8400_SYSCLK_ENA_SHIFT                     14  /* SYSCLK_ENA */
+#define WM8400_SYSCLK_ENA_WIDTH                      1  /* SYSCLK_ENA */
+#define WM8400_SPK_MIX_ENA                      0x2000  /* SPK_MIX_ENA */
+#define WM8400_SPK_MIX_ENA_MASK                 0x2000  /* SPK_MIX_ENA */
+#define WM8400_SPK_MIX_ENA_SHIFT                    13  /* SPK_MIX_ENA */
+#define WM8400_SPK_MIX_ENA_WIDTH                     1  /* SPK_MIX_ENA */
+#define WM8400_SPK_ENA                          0x1000  /* SPK_ENA */
+#define WM8400_SPK_ENA_MASK                     0x1000  /* SPK_ENA */
+#define WM8400_SPK_ENA_SHIFT                        12  /* SPK_ENA */
+#define WM8400_SPK_ENA_WIDTH                         1  /* SPK_ENA */
+#define WM8400_OUT3_ENA                         0x0800  /* OUT3_ENA */
+#define WM8400_OUT3_ENA_MASK                    0x0800  /* OUT3_ENA */
+#define WM8400_OUT3_ENA_SHIFT                       11  /* OUT3_ENA */
+#define WM8400_OUT3_ENA_WIDTH                        1  /* OUT3_ENA */
+#define WM8400_OUT4_ENA                         0x0400  /* OUT4_ENA */
+#define WM8400_OUT4_ENA_MASK                    0x0400  /* OUT4_ENA */
+#define WM8400_OUT4_ENA_SHIFT                       10  /* OUT4_ENA */
+#define WM8400_OUT4_ENA_WIDTH                        1  /* OUT4_ENA */
+#define WM8400_LOUT_ENA                         0x0200  /* LOUT_ENA */
+#define WM8400_LOUT_ENA_MASK                    0x0200  /* LOUT_ENA */
+#define WM8400_LOUT_ENA_SHIFT                        9  /* LOUT_ENA */
+#define WM8400_LOUT_ENA_WIDTH                        1  /* LOUT_ENA */
+#define WM8400_ROUT_ENA                         0x0100  /* ROUT_ENA */
+#define WM8400_ROUT_ENA_MASK                    0x0100  /* ROUT_ENA */
+#define WM8400_ROUT_ENA_SHIFT                        8  /* ROUT_ENA */
+#define WM8400_ROUT_ENA_WIDTH                        1  /* ROUT_ENA */
+#define WM8400_MIC1BIAS_ENA                     0x0010  /* MIC1BIAS_ENA */
+#define WM8400_MIC1BIAS_ENA_MASK                0x0010  /* MIC1BIAS_ENA */
+#define WM8400_MIC1BIAS_ENA_SHIFT                    4  /* MIC1BIAS_ENA */
+#define WM8400_MIC1BIAS_ENA_WIDTH                    1  /* MIC1BIAS_ENA */
+#define WM8400_VMID_MODE_MASK                   0x0006  /* VMID_MODE - [2:1] */
+#define WM8400_VMID_MODE_SHIFT                       1  /* VMID_MODE - [2:1] */
+#define WM8400_VMID_MODE_WIDTH                       2  /* VMID_MODE - [2:1] */
+#define WM8400_VREF_ENA                         0x0001  /* VREF_ENA */
+#define WM8400_VREF_ENA_MASK                    0x0001  /* VREF_ENA */
+#define WM8400_VREF_ENA_SHIFT                        0  /* VREF_ENA */
+#define WM8400_VREF_ENA_WIDTH                        1  /* VREF_ENA */
+
+/*
+ * R3 (0x03) - Power Management (2)
+ */
+#define WM8400_FLL_ENA                          0x8000  /* FLL_ENA */
+#define WM8400_FLL_ENA_MASK                     0x8000  /* FLL_ENA */
+#define WM8400_FLL_ENA_SHIFT                        15  /* FLL_ENA */
+#define WM8400_FLL_ENA_WIDTH                         1  /* FLL_ENA */
+#define WM8400_TSHUT_ENA                        0x4000  /* TSHUT_ENA */
+#define WM8400_TSHUT_ENA_MASK                   0x4000  /* TSHUT_ENA */
+#define WM8400_TSHUT_ENA_SHIFT                      14  /* TSHUT_ENA */
+#define WM8400_TSHUT_ENA_WIDTH                       1  /* TSHUT_ENA */
+#define WM8400_TSHUT_OPDIS                      0x2000  /* TSHUT_OPDIS */
+#define WM8400_TSHUT_OPDIS_MASK                 0x2000  /* TSHUT_OPDIS */
+#define WM8400_TSHUT_OPDIS_SHIFT                    13  /* TSHUT_OPDIS */
+#define WM8400_TSHUT_OPDIS_WIDTH                     1  /* TSHUT_OPDIS */
+#define WM8400_OPCLK_ENA                        0x0800  /* OPCLK_ENA */
+#define WM8400_OPCLK_ENA_MASK                   0x0800  /* OPCLK_ENA */
+#define WM8400_OPCLK_ENA_SHIFT                      11  /* OPCLK_ENA */
+#define WM8400_OPCLK_ENA_WIDTH                       1  /* OPCLK_ENA */
+#define WM8400_AINL_ENA                         0x0200  /* AINL_ENA */
+#define WM8400_AINL_ENA_MASK                    0x0200  /* AINL_ENA */
+#define WM8400_AINL_ENA_SHIFT                        9  /* AINL_ENA */
+#define WM8400_AINL_ENA_WIDTH                        1  /* AINL_ENA */
+#define WM8400_AINR_ENA                         0x0100  /* AINR_ENA */
+#define WM8400_AINR_ENA_MASK                    0x0100  /* AINR_ENA */
+#define WM8400_AINR_ENA_SHIFT                        8  /* AINR_ENA */
+#define WM8400_AINR_ENA_WIDTH                        1  /* AINR_ENA */
+#define WM8400_LIN34_ENA                        0x0080  /* LIN34_ENA */
+#define WM8400_LIN34_ENA_MASK                   0x0080  /* LIN34_ENA */
+#define WM8400_LIN34_ENA_SHIFT                       7  /* LIN34_ENA */
+#define WM8400_LIN34_ENA_WIDTH                       1  /* LIN34_ENA */
+#define WM8400_LIN12_ENA                        0x0040  /* LIN12_ENA */
+#define WM8400_LIN12_ENA_MASK                   0x0040  /* LIN12_ENA */
+#define WM8400_LIN12_ENA_SHIFT                       6  /* LIN12_ENA */
+#define WM8400_LIN12_ENA_WIDTH                       1  /* LIN12_ENA */
+#define WM8400_RIN34_ENA                        0x0020  /* RIN34_ENA */
+#define WM8400_RIN34_ENA_MASK                   0x0020  /* RIN34_ENA */
+#define WM8400_RIN34_ENA_SHIFT                       5  /* RIN34_ENA */
+#define WM8400_RIN34_ENA_WIDTH                       1  /* RIN34_ENA */
+#define WM8400_RIN12_ENA                        0x0010  /* RIN12_ENA */
+#define WM8400_RIN12_ENA_MASK                   0x0010  /* RIN12_ENA */
+#define WM8400_RIN12_ENA_SHIFT                       4  /* RIN12_ENA */
+#define WM8400_RIN12_ENA_WIDTH                       1  /* RIN12_ENA */
+#define WM8400_ADCL_ENA                         0x0002  /* ADCL_ENA */
+#define WM8400_ADCL_ENA_MASK                    0x0002  /* ADCL_ENA */
+#define WM8400_ADCL_ENA_SHIFT                        1  /* ADCL_ENA */
+#define WM8400_ADCL_ENA_WIDTH                        1  /* ADCL_ENA */
+#define WM8400_ADCR_ENA                         0x0001  /* ADCR_ENA */
+#define WM8400_ADCR_ENA_MASK                    0x0001  /* ADCR_ENA */
+#define WM8400_ADCR_ENA_SHIFT                        0  /* ADCR_ENA */
+#define WM8400_ADCR_ENA_WIDTH                        1  /* ADCR_ENA */
+
+/*
+ * R4 (0x04) - Power Management (3)
+ */
+#define WM8400_LON_ENA                          0x2000  /* LON_ENA */
+#define WM8400_LON_ENA_MASK                     0x2000  /* LON_ENA */
+#define WM8400_LON_ENA_SHIFT                        13  /* LON_ENA */
+#define WM8400_LON_ENA_WIDTH                         1  /* LON_ENA */
+#define WM8400_LOP_ENA                          0x1000  /* LOP_ENA */
+#define WM8400_LOP_ENA_MASK                     0x1000  /* LOP_ENA */
+#define WM8400_LOP_ENA_SHIFT                        12  /* LOP_ENA */
+#define WM8400_LOP_ENA_WIDTH                         1  /* LOP_ENA */
+#define WM8400_RON_ENA                          0x0800  /* RON_ENA */
+#define WM8400_RON_ENA_MASK                     0x0800  /* RON_ENA */
+#define WM8400_RON_ENA_SHIFT                        11  /* RON_ENA */
+#define WM8400_RON_ENA_WIDTH                         1  /* RON_ENA */
+#define WM8400_ROP_ENA                          0x0400  /* ROP_ENA */
+#define WM8400_ROP_ENA_MASK                     0x0400  /* ROP_ENA */
+#define WM8400_ROP_ENA_SHIFT                        10  /* ROP_ENA */
+#define WM8400_ROP_ENA_WIDTH                         1  /* ROP_ENA */
+#define WM8400_LOPGA_ENA                        0x0080  /* LOPGA_ENA */
+#define WM8400_LOPGA_ENA_MASK                   0x0080  /* LOPGA_ENA */
+#define WM8400_LOPGA_ENA_SHIFT                       7  /* LOPGA_ENA */
+#define WM8400_LOPGA_ENA_WIDTH                       1  /* LOPGA_ENA */
+#define WM8400_ROPGA_ENA                        0x0040  /* ROPGA_ENA */
+#define WM8400_ROPGA_ENA_MASK                   0x0040  /* ROPGA_ENA */
+#define WM8400_ROPGA_ENA_SHIFT                       6  /* ROPGA_ENA */
+#define WM8400_ROPGA_ENA_WIDTH                       1  /* ROPGA_ENA */
+#define WM8400_LOMIX_ENA                        0x0020  /* LOMIX_ENA */
+#define WM8400_LOMIX_ENA_MASK                   0x0020  /* LOMIX_ENA */
+#define WM8400_LOMIX_ENA_SHIFT                       5  /* LOMIX_ENA */
+#define WM8400_LOMIX_ENA_WIDTH                       1  /* LOMIX_ENA */
+#define WM8400_ROMIX_ENA                        0x0010  /* ROMIX_ENA */
+#define WM8400_ROMIX_ENA_MASK                   0x0010  /* ROMIX_ENA */
+#define WM8400_ROMIX_ENA_SHIFT                       4  /* ROMIX_ENA */
+#define WM8400_ROMIX_ENA_WIDTH                       1  /* ROMIX_ENA */
+#define WM8400_DACL_ENA                         0x0002  /* DACL_ENA */
+#define WM8400_DACL_ENA_MASK                    0x0002  /* DACL_ENA */
+#define WM8400_DACL_ENA_SHIFT                        1  /* DACL_ENA */
+#define WM8400_DACL_ENA_WIDTH                        1  /* DACL_ENA */
+#define WM8400_DACR_ENA                         0x0001  /* DACR_ENA */
+#define WM8400_DACR_ENA_MASK                    0x0001  /* DACR_ENA */
+#define WM8400_DACR_ENA_SHIFT                        0  /* DACR_ENA */
+#define WM8400_DACR_ENA_WIDTH                        1  /* DACR_ENA */
+
+/*
+ * R5 (0x05) - Audio Interface (1)
+ */
+#define WM8400_AIFADCL_SRC                      0x8000  /* AIFADCL_SRC */
+#define WM8400_AIFADCL_SRC_MASK                 0x8000  /* AIFADCL_SRC */
+#define WM8400_AIFADCL_SRC_SHIFT                    15  /* AIFADCL_SRC */
+#define WM8400_AIFADCL_SRC_WIDTH                     1  /* AIFADCL_SRC */
+#define WM8400_AIFADCR_SRC                      0x4000  /* AIFADCR_SRC */
+#define WM8400_AIFADCR_SRC_MASK                 0x4000  /* AIFADCR_SRC */
+#define WM8400_AIFADCR_SRC_SHIFT                    14  /* AIFADCR_SRC */
+#define WM8400_AIFADCR_SRC_WIDTH                     1  /* AIFADCR_SRC */
+#define WM8400_AIFADC_TDM                       0x2000  /* AIFADC_TDM */
+#define WM8400_AIFADC_TDM_MASK                  0x2000  /* AIFADC_TDM */
+#define WM8400_AIFADC_TDM_SHIFT                     13  /* AIFADC_TDM */
+#define WM8400_AIFADC_TDM_WIDTH                      1  /* AIFADC_TDM */
+#define WM8400_AIFADC_TDM_CHAN                  0x1000  /* AIFADC_TDM_CHAN */
+#define WM8400_AIFADC_TDM_CHAN_MASK             0x1000  /* AIFADC_TDM_CHAN */
+#define WM8400_AIFADC_TDM_CHAN_SHIFT                12  /* AIFADC_TDM_CHAN */
+#define WM8400_AIFADC_TDM_CHAN_WIDTH                 1  /* AIFADC_TDM_CHAN */
+#define WM8400_AIF_BCLK_INV                     0x0100  /* AIF_BCLK_INV */
+#define WM8400_AIF_BCLK_INV_MASK                0x0100  /* AIF_BCLK_INV */
+#define WM8400_AIF_BCLK_INV_SHIFT                    8  /* AIF_BCLK_INV */
+#define WM8400_AIF_BCLK_INV_WIDTH                    1  /* AIF_BCLK_INV */
+#define WM8400_AIF_LRCLK_INV                    0x0080  /* AIF_LRCLK_INV */
+#define WM8400_AIF_LRCLK_INV_MASK               0x0080  /* AIF_LRCLK_INV */
+#define WM8400_AIF_LRCLK_INV_SHIFT                   7  /* AIF_LRCLK_INV */
+#define WM8400_AIF_LRCLK_INV_WIDTH                   1  /* AIF_LRCLK_INV */
+#define WM8400_AIF_WL_MASK                      0x0060  /* AIF_WL - [6:5] */
+#define WM8400_AIF_WL_SHIFT                          5  /* AIF_WL - [6:5] */
+#define WM8400_AIF_WL_WIDTH                          2  /* AIF_WL - [6:5] */
+#define WM8400_AIF_WL_16BITS                   (0 << 5)
+#define WM8400_AIF_WL_20BITS                   (1 << 5)
+#define WM8400_AIF_WL_24BITS                   (2 << 5)
+#define WM8400_AIF_WL_32BITS                   (3 << 5)
+#define WM8400_AIF_FMT_MASK                     0x0018  /* AIF_FMT - [4:3] */
+#define WM8400_AIF_FMT_SHIFT                         3  /* AIF_FMT - [4:3] */
+#define WM8400_AIF_FMT_WIDTH                         2  /* AIF_FMT - [4:3] */
+#define WM8400_AIF_FMT_RIGHTJ                  (0 << 3)
+#define WM8400_AIF_FMT_LEFTJ                   (1 << 3)
+#define WM8400_AIF_FMT_I2S                     (2 << 3)
+#define WM8400_AIF_FMT_DSP                     (3 << 3)
+
+/*
+ * R6 (0x06) - Audio Interface (2)
+ */
+#define WM8400_DACL_SRC                         0x8000  /* DACL_SRC */
+#define WM8400_DACL_SRC_MASK                    0x8000  /* DACL_SRC */
+#define WM8400_DACL_SRC_SHIFT                       15  /* DACL_SRC */
+#define WM8400_DACL_SRC_WIDTH                        1  /* DACL_SRC */
+#define WM8400_DACR_SRC                         0x4000  /* DACR_SRC */
+#define WM8400_DACR_SRC_MASK                    0x4000  /* DACR_SRC */
+#define WM8400_DACR_SRC_SHIFT                       14  /* DACR_SRC */
+#define WM8400_DACR_SRC_WIDTH                        1  /* DACR_SRC */
+#define WM8400_AIFDAC_TDM                       0x2000  /* AIFDAC_TDM */
+#define WM8400_AIFDAC_TDM_MASK                  0x2000  /* AIFDAC_TDM */
+#define WM8400_AIFDAC_TDM_SHIFT                     13  /* AIFDAC_TDM */
+#define WM8400_AIFDAC_TDM_WIDTH                      1  /* AIFDAC_TDM */
+#define WM8400_AIFDAC_TDM_CHAN                  0x1000  /* AIFDAC_TDM_CHAN */
+#define WM8400_AIFDAC_TDM_CHAN_MASK             0x1000  /* AIFDAC_TDM_CHAN */
+#define WM8400_AIFDAC_TDM_CHAN_SHIFT                12  /* AIFDAC_TDM_CHAN */
+#define WM8400_AIFDAC_TDM_CHAN_WIDTH                 1  /* AIFDAC_TDM_CHAN */
+#define WM8400_DAC_BOOST_MASK                   0x0C00  /* DAC_BOOST - [11:10] */
+#define WM8400_DAC_BOOST_SHIFT                      10  /* DAC_BOOST - [11:10] */
+#define WM8400_DAC_BOOST_WIDTH                       2  /* DAC_BOOST - [11:10] */
+#define WM8400_DAC_COMP                         0x0010  /* DAC_COMP */
+#define WM8400_DAC_COMP_MASK                    0x0010  /* DAC_COMP */
+#define WM8400_DAC_COMP_SHIFT                        4  /* DAC_COMP */
+#define WM8400_DAC_COMP_WIDTH                        1  /* DAC_COMP */
+#define WM8400_DAC_COMPMODE                     0x0008  /* DAC_COMPMODE */
+#define WM8400_DAC_COMPMODE_MASK                0x0008  /* DAC_COMPMODE */
+#define WM8400_DAC_COMPMODE_SHIFT                    3  /* DAC_COMPMODE */
+#define WM8400_DAC_COMPMODE_WIDTH                    1  /* DAC_COMPMODE */
+#define WM8400_ADC_COMP                         0x0004  /* ADC_COMP */
+#define WM8400_ADC_COMP_MASK                    0x0004  /* ADC_COMP */
+#define WM8400_ADC_COMP_SHIFT                        2  /* ADC_COMP */
+#define WM8400_ADC_COMP_WIDTH                        1  /* ADC_COMP */
+#define WM8400_ADC_COMPMODE                     0x0002  /* ADC_COMPMODE */
+#define WM8400_ADC_COMPMODE_MASK                0x0002  /* ADC_COMPMODE */
+#define WM8400_ADC_COMPMODE_SHIFT                    1  /* ADC_COMPMODE */
+#define WM8400_ADC_COMPMODE_WIDTH                    1  /* ADC_COMPMODE */
+#define WM8400_LOOPBACK                         0x0001  /* LOOPBACK */
+#define WM8400_LOOPBACK_MASK                    0x0001  /* LOOPBACK */
+#define WM8400_LOOPBACK_SHIFT                        0  /* LOOPBACK */
+#define WM8400_LOOPBACK_WIDTH                        1  /* LOOPBACK */
+
+/*
+ * R7 (0x07) - Clocking (1)
+ */
+#define WM8400_TOCLK_RATE                       0x8000  /* TOCLK_RATE */
+#define WM8400_TOCLK_RATE_MASK                  0x8000  /* TOCLK_RATE */
+#define WM8400_TOCLK_RATE_SHIFT                     15  /* TOCLK_RATE */
+#define WM8400_TOCLK_RATE_WIDTH                      1  /* TOCLK_RATE */
+#define WM8400_TOCLK_ENA                        0x4000  /* TOCLK_ENA */
+#define WM8400_TOCLK_ENA_MASK                   0x4000  /* TOCLK_ENA */
+#define WM8400_TOCLK_ENA_SHIFT                      14  /* TOCLK_ENA */
+#define WM8400_TOCLK_ENA_WIDTH                       1  /* TOCLK_ENA */
+#define WM8400_OPCLKDIV_MASK                    0x1E00  /* OPCLKDIV - [12:9] */
+#define WM8400_OPCLKDIV_SHIFT                        9  /* OPCLKDIV - [12:9] */
+#define WM8400_OPCLKDIV_WIDTH                        4  /* OPCLKDIV - [12:9] */
+#define WM8400_DCLKDIV_MASK                     0x01C0  /* DCLKDIV - [8:6] */
+#define WM8400_DCLKDIV_SHIFT                         6  /* DCLKDIV - [8:6] */
+#define WM8400_DCLKDIV_WIDTH                         3  /* DCLKDIV - [8:6] */
+#define WM8400_BCLK_DIV_MASK                    0x001E  /* BCLK_DIV - [4:1] */
+#define WM8400_BCLK_DIV_SHIFT                        1  /* BCLK_DIV - [4:1] */
+#define WM8400_BCLK_DIV_WIDTH                        4  /* BCLK_DIV - [4:1] */
+
+/*
+ * R8 (0x08) - Clocking (2)
+ */
+#define WM8400_MCLK_SRC                         0x8000  /* MCLK_SRC */
+#define WM8400_MCLK_SRC_MASK                    0x8000  /* MCLK_SRC */
+#define WM8400_MCLK_SRC_SHIFT                       15  /* MCLK_SRC */
+#define WM8400_MCLK_SRC_WIDTH                        1  /* MCLK_SRC */
+#define WM8400_SYSCLK_SRC                       0x4000  /* SYSCLK_SRC */
+#define WM8400_SYSCLK_SRC_MASK                  0x4000  /* SYSCLK_SRC */
+#define WM8400_SYSCLK_SRC_SHIFT                     14  /* SYSCLK_SRC */
+#define WM8400_SYSCLK_SRC_WIDTH                      1  /* SYSCLK_SRC */
+#define WM8400_CLK_FORCE                        0x2000  /* CLK_FORCE */
+#define WM8400_CLK_FORCE_MASK                   0x2000  /* CLK_FORCE */
+#define WM8400_CLK_FORCE_SHIFT                      13  /* CLK_FORCE */
+#define WM8400_CLK_FORCE_WIDTH                       1  /* CLK_FORCE */
+#define WM8400_MCLK_DIV_MASK                    0x1800  /* MCLK_DIV - [12:11] */
+#define WM8400_MCLK_DIV_SHIFT                       11  /* MCLK_DIV - [12:11] */
+#define WM8400_MCLK_DIV_WIDTH                        2  /* MCLK_DIV - [12:11] */
+#define WM8400_MCLK_INV                         0x0400  /* MCLK_INV */
+#define WM8400_MCLK_INV_MASK                    0x0400  /* MCLK_INV */
+#define WM8400_MCLK_INV_SHIFT                       10  /* MCLK_INV */
+#define WM8400_MCLK_INV_WIDTH                        1  /* MCLK_INV */
+#define WM8400_ADC_CLKDIV_MASK                  0x00E0  /* ADC_CLKDIV - [7:5] */
+#define WM8400_ADC_CLKDIV_SHIFT                      5  /* ADC_CLKDIV - [7:5] */
+#define WM8400_ADC_CLKDIV_WIDTH                      3  /* ADC_CLKDIV - [7:5] */
+#define WM8400_DAC_CLKDIV_MASK                  0x001C  /* DAC_CLKDIV - [4:2] */
+#define WM8400_DAC_CLKDIV_SHIFT                      2  /* DAC_CLKDIV - [4:2] */
+#define WM8400_DAC_CLKDIV_WIDTH                      3  /* DAC_CLKDIV - [4:2] */
+
+/*
+ * R9 (0x09) - Audio Interface (3)
+ */
+#define WM8400_AIF_MSTR1                        0x8000  /* AIF_MSTR1 */
+#define WM8400_AIF_MSTR1_MASK                   0x8000  /* AIF_MSTR1 */
+#define WM8400_AIF_MSTR1_SHIFT                      15  /* AIF_MSTR1 */
+#define WM8400_AIF_MSTR1_WIDTH                       1  /* AIF_MSTR1 */
+#define WM8400_AIF_MSTR2                        0x4000  /* AIF_MSTR2 */
+#define WM8400_AIF_MSTR2_MASK                   0x4000  /* AIF_MSTR2 */
+#define WM8400_AIF_MSTR2_SHIFT                      14  /* AIF_MSTR2 */
+#define WM8400_AIF_MSTR2_WIDTH                       1  /* AIF_MSTR2 */
+#define WM8400_AIF_SEL                          0x2000  /* AIF_SEL */
+#define WM8400_AIF_SEL_MASK                     0x2000  /* AIF_SEL */
+#define WM8400_AIF_SEL_SHIFT                        13  /* AIF_SEL */
+#define WM8400_AIF_SEL_WIDTH                         1  /* AIF_SEL */
+#define WM8400_ADCLRC_DIR                       0x0800  /* ADCLRC_DIR */
+#define WM8400_ADCLRC_DIR_MASK                  0x0800  /* ADCLRC_DIR */
+#define WM8400_ADCLRC_DIR_SHIFT                     11  /* ADCLRC_DIR */
+#define WM8400_ADCLRC_DIR_WIDTH                      1  /* ADCLRC_DIR */
+#define WM8400_ADCLRC_RATE_MASK                 0x07FF  /* ADCLRC_RATE - [10:0] */
+#define WM8400_ADCLRC_RATE_SHIFT                     0  /* ADCLRC_RATE - [10:0] */
+#define WM8400_ADCLRC_RATE_WIDTH                    11  /* ADCLRC_RATE - [10:0] */
+
+/*
+ * R10 (0x0A) - Audio Interface (4)
+ */
+#define WM8400_ALRCGPIO1                        0x8000  /* ALRCGPIO1 */
+#define WM8400_ALRCGPIO1_MASK                   0x8000  /* ALRCGPIO1 */
+#define WM8400_ALRCGPIO1_SHIFT                      15  /* ALRCGPIO1 */
+#define WM8400_ALRCGPIO1_WIDTH                       1  /* ALRCGPIO1 */
+#define WM8400_ALRCBGPIO6                       0x4000  /* ALRCBGPIO6 */
+#define WM8400_ALRCBGPIO6_MASK                  0x4000  /* ALRCBGPIO6 */
+#define WM8400_ALRCBGPIO6_SHIFT                     14  /* ALRCBGPIO6 */
+#define WM8400_ALRCBGPIO6_WIDTH                      1  /* ALRCBGPIO6 */
+#define WM8400_AIF_TRIS                         0x2000  /* AIF_TRIS */
+#define WM8400_AIF_TRIS_MASK                    0x2000  /* AIF_TRIS */
+#define WM8400_AIF_TRIS_SHIFT                       13  /* AIF_TRIS */
+#define WM8400_AIF_TRIS_WIDTH                        1  /* AIF_TRIS */
+#define WM8400_DACLRC_DIR                       0x0800  /* DACLRC_DIR */
+#define WM8400_DACLRC_DIR_MASK                  0x0800  /* DACLRC_DIR */
+#define WM8400_DACLRC_DIR_SHIFT                     11  /* DACLRC_DIR */
+#define WM8400_DACLRC_DIR_WIDTH                      1  /* DACLRC_DIR */
+#define WM8400_DACLRC_RATE_MASK                 0x07FF  /* DACLRC_RATE - [10:0] */
+#define WM8400_DACLRC_RATE_SHIFT                     0  /* DACLRC_RATE - [10:0] */
+#define WM8400_DACLRC_RATE_WIDTH                    11  /* DACLRC_RATE - [10:0] */
+
+/*
+ * R11 (0x0B) - DAC CTRL
+ */
+#define WM8400_DAC_SDMCLK_RATE                  0x2000  /* DAC_SDMCLK_RATE */
+#define WM8400_DAC_SDMCLK_RATE_MASK             0x2000  /* DAC_SDMCLK_RATE */
+#define WM8400_DAC_SDMCLK_RATE_SHIFT                13  /* DAC_SDMCLK_RATE */
+#define WM8400_DAC_SDMCLK_RATE_WIDTH                 1  /* DAC_SDMCLK_RATE */
+#define WM8400_AIF_LRCLKRATE                    0x0400  /* AIF_LRCLKRATE */
+#define WM8400_AIF_LRCLKRATE_MASK               0x0400  /* AIF_LRCLKRATE */
+#define WM8400_AIF_LRCLKRATE_SHIFT                  10  /* AIF_LRCLKRATE */
+#define WM8400_AIF_LRCLKRATE_WIDTH                   1  /* AIF_LRCLKRATE */
+#define WM8400_DAC_MONO                         0x0200  /* DAC_MONO */
+#define WM8400_DAC_MONO_MASK                    0x0200  /* DAC_MONO */
+#define WM8400_DAC_MONO_SHIFT                        9  /* DAC_MONO */
+#define WM8400_DAC_MONO_WIDTH                        1  /* DAC_MONO */
+#define WM8400_DAC_SB_FILT                      0x0100  /* DAC_SB_FILT */
+#define WM8400_DAC_SB_FILT_MASK                 0x0100  /* DAC_SB_FILT */
+#define WM8400_DAC_SB_FILT_SHIFT                     8  /* DAC_SB_FILT */
+#define WM8400_DAC_SB_FILT_WIDTH                     1  /* DAC_SB_FILT */
+#define WM8400_DAC_MUTERATE                     0x0080  /* DAC_MUTERATE */
+#define WM8400_DAC_MUTERATE_MASK                0x0080  /* DAC_MUTERATE */
+#define WM8400_DAC_MUTERATE_SHIFT                    7  /* DAC_MUTERATE */
+#define WM8400_DAC_MUTERATE_WIDTH                    1  /* DAC_MUTERATE */
+#define WM8400_DAC_MUTEMODE                     0x0040  /* DAC_MUTEMODE */
+#define WM8400_DAC_MUTEMODE_MASK                0x0040  /* DAC_MUTEMODE */
+#define WM8400_DAC_MUTEMODE_SHIFT                    6  /* DAC_MUTEMODE */
+#define WM8400_DAC_MUTEMODE_WIDTH                    1  /* DAC_MUTEMODE */
+#define WM8400_DEEMP_MASK                       0x0030  /* DEEMP - [5:4] */
+#define WM8400_DEEMP_SHIFT                           4  /* DEEMP - [5:4] */
+#define WM8400_DEEMP_WIDTH                           2  /* DEEMP - [5:4] */
+#define WM8400_DAC_MUTE                         0x0004  /* DAC_MUTE */
+#define WM8400_DAC_MUTE_MASK                    0x0004  /* DAC_MUTE */
+#define WM8400_DAC_MUTE_SHIFT                        2  /* DAC_MUTE */
+#define WM8400_DAC_MUTE_WIDTH                        1  /* DAC_MUTE */
+#define WM8400_DACL_DATINV                      0x0002  /* DACL_DATINV */
+#define WM8400_DACL_DATINV_MASK                 0x0002  /* DACL_DATINV */
+#define WM8400_DACL_DATINV_SHIFT                     1  /* DACL_DATINV */
+#define WM8400_DACL_DATINV_WIDTH                     1  /* DACL_DATINV */
+#define WM8400_DACR_DATINV                      0x0001  /* DACR_DATINV */
+#define WM8400_DACR_DATINV_MASK                 0x0001  /* DACR_DATINV */
+#define WM8400_DACR_DATINV_SHIFT                     0  /* DACR_DATINV */
+#define WM8400_DACR_DATINV_WIDTH                     1  /* DACR_DATINV */
+
+/*
+ * R12 (0x0C) - Left DAC Digital Volume
+ */
+#define WM8400_DAC_VU                           0x0100  /* DAC_VU */
+#define WM8400_DAC_VU_MASK                      0x0100  /* DAC_VU */
+#define WM8400_DAC_VU_SHIFT                          8  /* DAC_VU */
+#define WM8400_DAC_VU_WIDTH                          1  /* DAC_VU */
+#define WM8400_DACL_VOL_MASK                    0x00FF  /* DACL_VOL - [7:0] */
+#define WM8400_DACL_VOL_SHIFT                        0  /* DACL_VOL - [7:0] */
+#define WM8400_DACL_VOL_WIDTH                        8  /* DACL_VOL - [7:0] */
+
+/*
+ * R13 (0x0D) - Right DAC Digital Volume
+ */
+#define WM8400_DAC_VU                           0x0100  /* DAC_VU */
+#define WM8400_DAC_VU_MASK                      0x0100  /* DAC_VU */
+#define WM8400_DAC_VU_SHIFT                          8  /* DAC_VU */
+#define WM8400_DAC_VU_WIDTH                          1  /* DAC_VU */
+#define WM8400_DACR_VOL_MASK                    0x00FF  /* DACR_VOL - [7:0] */
+#define WM8400_DACR_VOL_SHIFT                        0  /* DACR_VOL - [7:0] */
+#define WM8400_DACR_VOL_WIDTH                        8  /* DACR_VOL - [7:0] */
+
+/*
+ * R14 (0x0E) - Digital Side Tone
+ */
+#define WM8400_ADCL_DAC_SVOL_MASK               0x1E00  /*   ADCL_DAC_SVOL - [12:9] */
+#define WM8400_ADCL_DAC_SVOL_SHIFT                   9  /*   ADCL_DAC_SVOL - [12:9] */
+#define WM8400_ADCL_DAC_SVOL_WIDTH                   4  /*   ADCL_DAC_SVOL - [12:9] */
+#define WM8400_ADCR_DAC_SVOL_MASK               0x01E0  /* ADCR_DAC_SVOL - [8:5] */
+#define WM8400_ADCR_DAC_SVOL_SHIFT                   5  /* ADCR_DAC_SVOL - [8:5] */
+#define WM8400_ADCR_DAC_SVOL_WIDTH                   4  /* ADCR_DAC_SVOL - [8:5] */
+#define WM8400_ADC_TO_DACL_MASK                 0x000C  /* ADC_TO_DACL - [3:2] */
+#define WM8400_ADC_TO_DACL_SHIFT                     2  /* ADC_TO_DACL - [3:2] */
+#define WM8400_ADC_TO_DACL_WIDTH                     2  /* ADC_TO_DACL - [3:2] */
+#define WM8400_ADC_TO_DACR_MASK                 0x0003  /* ADC_TO_DACR - [1:0] */
+#define WM8400_ADC_TO_DACR_SHIFT                     0  /* ADC_TO_DACR - [1:0] */
+#define WM8400_ADC_TO_DACR_WIDTH                     2  /* ADC_TO_DACR - [1:0] */
+
+/*
+ * R15 (0x0F) - ADC CTRL
+ */
+#define WM8400_ADC_HPF_ENA                      0x0100  /* ADC_HPF_ENA */
+#define WM8400_ADC_HPF_ENA_MASK                 0x0100  /* ADC_HPF_ENA */
+#define WM8400_ADC_HPF_ENA_SHIFT                     8  /* ADC_HPF_ENA */
+#define WM8400_ADC_HPF_ENA_WIDTH                     1  /* ADC_HPF_ENA */
+#define WM8400_ADC_HPF_CUT_MASK                 0x0060  /* ADC_HPF_CUT - [6:5] */
+#define WM8400_ADC_HPF_CUT_SHIFT                     5  /* ADC_HPF_CUT - [6:5] */
+#define WM8400_ADC_HPF_CUT_WIDTH                     2  /* ADC_HPF_CUT - [6:5] */
+#define WM8400_ADCL_DATINV                      0x0002  /* ADCL_DATINV */
+#define WM8400_ADCL_DATINV_MASK                 0x0002  /* ADCL_DATINV */
+#define WM8400_ADCL_DATINV_SHIFT                     1  /* ADCL_DATINV */
+#define WM8400_ADCL_DATINV_WIDTH                     1  /* ADCL_DATINV */
+#define WM8400_ADCR_DATINV                      0x0001  /* ADCR_DATINV */
+#define WM8400_ADCR_DATINV_MASK                 0x0001  /* ADCR_DATINV */
+#define WM8400_ADCR_DATINV_SHIFT                     0  /* ADCR_DATINV */
+#define WM8400_ADCR_DATINV_WIDTH                     1  /* ADCR_DATINV */
+
+/*
+ * R16 (0x10) - Left ADC Digital Volume
+ */
+#define WM8400_ADC_VU                           0x0100  /* ADC_VU */
+#define WM8400_ADC_VU_MASK                      0x0100  /* ADC_VU */
+#define WM8400_ADC_VU_SHIFT                          8  /* ADC_VU */
+#define WM8400_ADC_VU_WIDTH                          1  /* ADC_VU */
+#define WM8400_ADCL_VOL_MASK                    0x00FF  /* ADCL_VOL - [7:0] */
+#define WM8400_ADCL_VOL_SHIFT                        0  /* ADCL_VOL - [7:0] */
+#define WM8400_ADCL_VOL_WIDTH                        8  /* ADCL_VOL - [7:0] */
+
+/*
+ * R17 (0x11) - Right ADC Digital Volume
+ */
+#define WM8400_ADC_VU                           0x0100  /* ADC_VU */
+#define WM8400_ADC_VU_MASK                      0x0100  /* ADC_VU */
+#define WM8400_ADC_VU_SHIFT                          8  /* ADC_VU */
+#define WM8400_ADC_VU_WIDTH                          1  /* ADC_VU */
+#define WM8400_ADCR_VOL_MASK                    0x00FF  /* ADCR_VOL - [7:0] */
+#define WM8400_ADCR_VOL_SHIFT                        0  /* ADCR_VOL - [7:0] */
+#define WM8400_ADCR_VOL_WIDTH                        8  /* ADCR_VOL - [7:0] */
+
+/*
+ * R24 (0x18) - Left Line Input 1&2 Volume
+ */
+#define WM8400_IPVU                             0x0100  /* IPVU */
+#define WM8400_IPVU_MASK                        0x0100  /* IPVU */
+#define WM8400_IPVU_SHIFT                            8  /* IPVU */
+#define WM8400_IPVU_WIDTH                            1  /* IPVU */
+#define WM8400_LI12MUTE                         0x0080  /* LI12MUTE */
+#define WM8400_LI12MUTE_MASK                    0x0080  /* LI12MUTE */
+#define WM8400_LI12MUTE_SHIFT                        7  /* LI12MUTE */
+#define WM8400_LI12MUTE_WIDTH                        1  /* LI12MUTE */
+#define WM8400_LI12ZC                           0x0040  /* LI12ZC */
+#define WM8400_LI12ZC_MASK                      0x0040  /* LI12ZC */
+#define WM8400_LI12ZC_SHIFT                          6  /* LI12ZC */
+#define WM8400_LI12ZC_WIDTH                          1  /* LI12ZC */
+#define WM8400_LIN12VOL_MASK                    0x001F  /* LIN12VOL - [4:0] */
+#define WM8400_LIN12VOL_SHIFT                        0  /* LIN12VOL - [4:0] */
+#define WM8400_LIN12VOL_WIDTH                        5  /* LIN12VOL - [4:0] */
+
+/*
+ * R25 (0x19) - Left Line Input 3&4 Volume
+ */
+#define WM8400_IPVU                             0x0100  /* IPVU */
+#define WM8400_IPVU_MASK                        0x0100  /* IPVU */
+#define WM8400_IPVU_SHIFT                            8  /* IPVU */
+#define WM8400_IPVU_WIDTH                            1  /* IPVU */
+#define WM8400_LI34MUTE                         0x0080  /* LI34MUTE */
+#define WM8400_LI34MUTE_MASK                    0x0080  /* LI34MUTE */
+#define WM8400_LI34MUTE_SHIFT                        7  /* LI34MUTE */
+#define WM8400_LI34MUTE_WIDTH                        1  /* LI34MUTE */
+#define WM8400_LI34ZC                           0x0040  /* LI34ZC */
+#define WM8400_LI34ZC_MASK                      0x0040  /* LI34ZC */
+#define WM8400_LI34ZC_SHIFT                          6  /* LI34ZC */
+#define WM8400_LI34ZC_WIDTH                          1  /* LI34ZC */
+#define WM8400_LIN34VOL_MASK                    0x001F  /* LIN34VOL - [4:0] */
+#define WM8400_LIN34VOL_SHIFT                        0  /* LIN34VOL - [4:0] */
+#define WM8400_LIN34VOL_WIDTH                        5  /* LIN34VOL - [4:0] */
+
+/*
+ * R26 (0x1A) - Right Line Input 1&2 Volume
+ */
+#define WM8400_IPVU                             0x0100  /* IPVU */
+#define WM8400_IPVU_MASK                        0x0100  /* IPVU */
+#define WM8400_IPVU_SHIFT                            8  /* IPVU */
+#define WM8400_IPVU_WIDTH                            1  /* IPVU */
+#define WM8400_RI12MUTE                         0x0080  /* RI12MUTE */
+#define WM8400_RI12MUTE_MASK                    0x0080  /* RI12MUTE */
+#define WM8400_RI12MUTE_SHIFT                        7  /* RI12MUTE */
+#define WM8400_RI12MUTE_WIDTH                        1  /* RI12MUTE */
+#define WM8400_RI12ZC                           0x0040  /* RI12ZC */
+#define WM8400_RI12ZC_MASK                      0x0040  /* RI12ZC */
+#define WM8400_RI12ZC_SHIFT                          6  /* RI12ZC */
+#define WM8400_RI12ZC_WIDTH                          1  /* RI12ZC */
+#define WM8400_RIN12VOL_MASK                    0x001F  /* RIN12VOL - [4:0] */
+#define WM8400_RIN12VOL_SHIFT                        0  /* RIN12VOL - [4:0] */
+#define WM8400_RIN12VOL_WIDTH                        5  /* RIN12VOL - [4:0] */
+
+/*
+ * R27 (0x1B) - Right Line Input 3&4 Volume
+ */
+#define WM8400_IPVU                             0x0100  /* IPVU */
+#define WM8400_IPVU_MASK                        0x0100  /* IPVU */
+#define WM8400_IPVU_SHIFT                            8  /* IPVU */
+#define WM8400_IPVU_WIDTH                            1  /* IPVU */
+#define WM8400_RI34MUTE                         0x0080  /* RI34MUTE */
+#define WM8400_RI34MUTE_MASK                    0x0080  /* RI34MUTE */
+#define WM8400_RI34MUTE_SHIFT                        7  /* RI34MUTE */
+#define WM8400_RI34MUTE_WIDTH                        1  /* RI34MUTE */
+#define WM8400_RI34ZC                           0x0040  /* RI34ZC */
+#define WM8400_RI34ZC_MASK                      0x0040  /* RI34ZC */
+#define WM8400_RI34ZC_SHIFT                          6  /* RI34ZC */
+#define WM8400_RI34ZC_WIDTH                          1  /* RI34ZC */
+#define WM8400_RIN34VOL_MASK                    0x001F  /* RIN34VOL - [4:0] */
+#define WM8400_RIN34VOL_SHIFT                        0  /* RIN34VOL - [4:0] */
+#define WM8400_RIN34VOL_WIDTH                        5  /* RIN34VOL - [4:0] */
+
+/*
+ * R28 (0x1C) - Left Output Volume
+ */
+#define WM8400_OPVU                             0x0100  /* OPVU */
+#define WM8400_OPVU_MASK                        0x0100  /* OPVU */
+#define WM8400_OPVU_SHIFT                            8  /* OPVU */
+#define WM8400_OPVU_WIDTH                            1  /* OPVU */
+#define WM8400_LOZC                             0x0080  /* LOZC */
+#define WM8400_LOZC_MASK                        0x0080  /* LOZC */
+#define WM8400_LOZC_SHIFT                            7  /* LOZC */
+#define WM8400_LOZC_WIDTH                            1  /* LOZC */
+#define WM8400_LOUTVOL_MASK                     0x007F  /* LOUTVOL - [6:0] */
+#define WM8400_LOUTVOL_SHIFT                         0  /* LOUTVOL - [6:0] */
+#define WM8400_LOUTVOL_WIDTH                         7  /* LOUTVOL - [6:0] */
+
+/*
+ * R29 (0x1D) - Right Output Volume
+ */
+#define WM8400_OPVU                             0x0100  /* OPVU */
+#define WM8400_OPVU_MASK                        0x0100  /* OPVU */
+#define WM8400_OPVU_SHIFT                            8  /* OPVU */
+#define WM8400_OPVU_WIDTH                            1  /* OPVU */
+#define WM8400_ROZC                             0x0080  /* ROZC */
+#define WM8400_ROZC_MASK                        0x0080  /* ROZC */
+#define WM8400_ROZC_SHIFT                            7  /* ROZC */
+#define WM8400_ROZC_WIDTH                            1  /* ROZC */
+#define WM8400_ROUTVOL_MASK                     0x007F  /* ROUTVOL - [6:0] */
+#define WM8400_ROUTVOL_SHIFT                         0  /* ROUTVOL - [6:0] */
+#define WM8400_ROUTVOL_WIDTH                         7  /* ROUTVOL - [6:0] */
+
+/*
+ * R30 (0x1E) - Line Outputs Volume
+ */
+#define WM8400_LONMUTE                          0x0040  /* LONMUTE */
+#define WM8400_LONMUTE_MASK                     0x0040  /* LONMUTE */
+#define WM8400_LONMUTE_SHIFT                         6  /* LONMUTE */
+#define WM8400_LONMUTE_WIDTH                         1  /* LONMUTE */
+#define WM8400_LOPMUTE                          0x0020  /* LOPMUTE */
+#define WM8400_LOPMUTE_MASK                     0x0020  /* LOPMUTE */
+#define WM8400_LOPMUTE_SHIFT                         5  /* LOPMUTE */
+#define WM8400_LOPMUTE_WIDTH                         1  /* LOPMUTE */
+#define WM8400_LOATTN                           0x0010  /* LOATTN */
+#define WM8400_LOATTN_MASK                      0x0010  /* LOATTN */
+#define WM8400_LOATTN_SHIFT                          4  /* LOATTN */
+#define WM8400_LOATTN_WIDTH                          1  /* LOATTN */
+#define WM8400_RONMUTE                          0x0004  /* RONMUTE */
+#define WM8400_RONMUTE_MASK                     0x0004  /* RONMUTE */
+#define WM8400_RONMUTE_SHIFT                         2  /* RONMUTE */
+#define WM8400_RONMUTE_WIDTH                         1  /* RONMUTE */
+#define WM8400_ROPMUTE                          0x0002  /* ROPMUTE */
+#define WM8400_ROPMUTE_MASK                     0x0002  /* ROPMUTE */
+#define WM8400_ROPMUTE_SHIFT                         1  /* ROPMUTE */
+#define WM8400_ROPMUTE_WIDTH                         1  /* ROPMUTE */
+#define WM8400_ROATTN                           0x0001  /* ROATTN */
+#define WM8400_ROATTN_MASK                      0x0001  /* ROATTN */
+#define WM8400_ROATTN_SHIFT                          0  /* ROATTN */
+#define WM8400_ROATTN_WIDTH                          1  /* ROATTN */
+
+/*
+ * R31 (0x1F) - Out3/4 Volume
+ */
+#define WM8400_OUT3MUTE                         0x0020  /* OUT3MUTE */
+#define WM8400_OUT3MUTE_MASK                    0x0020  /* OUT3MUTE */
+#define WM8400_OUT3MUTE_SHIFT                        5  /* OUT3MUTE */
+#define WM8400_OUT3MUTE_WIDTH                        1  /* OUT3MUTE */
+#define WM8400_OUT3ATTN                         0x0010  /* OUT3ATTN */
+#define WM8400_OUT3ATTN_MASK                    0x0010  /* OUT3ATTN */
+#define WM8400_OUT3ATTN_SHIFT                        4  /* OUT3ATTN */
+#define WM8400_OUT3ATTN_WIDTH                        1  /* OUT3ATTN */
+#define WM8400_OUT4MUTE                         0x0002  /* OUT4MUTE */
+#define WM8400_OUT4MUTE_MASK                    0x0002  /* OUT4MUTE */
+#define WM8400_OUT4MUTE_SHIFT                        1  /* OUT4MUTE */
+#define WM8400_OUT4MUTE_WIDTH                        1  /* OUT4MUTE */
+#define WM8400_OUT4ATTN                         0x0001  /* OUT4ATTN */
+#define WM8400_OUT4ATTN_MASK                    0x0001  /* OUT4ATTN */
+#define WM8400_OUT4ATTN_SHIFT                        0  /* OUT4ATTN */
+#define WM8400_OUT4ATTN_WIDTH                        1  /* OUT4ATTN */
+
+/*
+ * R32 (0x20) - Left OPGA Volume
+ */
+#define WM8400_OPVU                             0x0100  /* OPVU */
+#define WM8400_OPVU_MASK                        0x0100  /* OPVU */
+#define WM8400_OPVU_SHIFT                            8  /* OPVU */
+#define WM8400_OPVU_WIDTH                            1  /* OPVU */
+#define WM8400_LOPGAZC                          0x0080  /* LOPGAZC */
+#define WM8400_LOPGAZC_MASK                     0x0080  /* LOPGAZC */
+#define WM8400_LOPGAZC_SHIFT                         7  /* LOPGAZC */
+#define WM8400_LOPGAZC_WIDTH                         1  /* LOPGAZC */
+#define WM8400_LOPGAVOL_MASK                    0x007F  /* LOPGAVOL - [6:0] */
+#define WM8400_LOPGAVOL_SHIFT                        0  /* LOPGAVOL - [6:0] */
+#define WM8400_LOPGAVOL_WIDTH                        7  /* LOPGAVOL - [6:0] */
+
+/*
+ * R33 (0x21) - Right OPGA Volume
+ */
+#define WM8400_OPVU                             0x0100  /* OPVU */
+#define WM8400_OPVU_MASK                        0x0100  /* OPVU */
+#define WM8400_OPVU_SHIFT                            8  /* OPVU */
+#define WM8400_OPVU_WIDTH                            1  /* OPVU */
+#define WM8400_ROPGAZC                          0x0080  /* ROPGAZC */
+#define WM8400_ROPGAZC_MASK                     0x0080  /* ROPGAZC */
+#define WM8400_ROPGAZC_SHIFT                         7  /* ROPGAZC */
+#define WM8400_ROPGAZC_WIDTH                         1  /* ROPGAZC */
+#define WM8400_ROPGAVOL_MASK                    0x007F  /* ROPGAVOL - [6:0] */
+#define WM8400_ROPGAVOL_SHIFT                        0  /* ROPGAVOL - [6:0] */
+#define WM8400_ROPGAVOL_WIDTH                        7  /* ROPGAVOL - [6:0] */
+
+/*
+ * R34 (0x22) - Speaker Volume
+ */
+#define WM8400_SPKATTN_MASK                     0x0003  /* SPKATTN - [1:0] */
+#define WM8400_SPKATTN_SHIFT                         0  /* SPKATTN - [1:0] */
+#define WM8400_SPKATTN_WIDTH                         2  /* SPKATTN - [1:0] */
+
+/*
+ * R35 (0x23) - ClassD1
+ */
+#define WM8400_CDMODE                           0x0100  /* CDMODE */
+#define WM8400_CDMODE_MASK                      0x0100  /* CDMODE */
+#define WM8400_CDMODE_SHIFT                          8  /* CDMODE */
+#define WM8400_CDMODE_WIDTH                          1  /* CDMODE */
+#define WM8400_CLASSD_CLK_SEL                   0x0080  /* CLASSD_CLK_SEL */
+#define WM8400_CLASSD_CLK_SEL_MASK              0x0080  /* CLASSD_CLK_SEL */
+#define WM8400_CLASSD_CLK_SEL_SHIFT                  7  /* CLASSD_CLK_SEL */
+#define WM8400_CLASSD_CLK_SEL_WIDTH                  1  /* CLASSD_CLK_SEL */
+#define WM8400_CD_SRCTRL                        0x0040  /* CD_SRCTRL */
+#define WM8400_CD_SRCTRL_MASK                   0x0040  /* CD_SRCTRL */
+#define WM8400_CD_SRCTRL_SHIFT                       6  /* CD_SRCTRL */
+#define WM8400_CD_SRCTRL_WIDTH                       1  /* CD_SRCTRL */
+#define WM8400_SPKNOPOP                         0x0020  /* SPKNOPOP */
+#define WM8400_SPKNOPOP_MASK                    0x0020  /* SPKNOPOP */
+#define WM8400_SPKNOPOP_SHIFT                        5  /* SPKNOPOP */
+#define WM8400_SPKNOPOP_WIDTH                        1  /* SPKNOPOP */
+#define WM8400_DBLERATE                         0x0010  /* DBLERATE */
+#define WM8400_DBLERATE_MASK                    0x0010  /* DBLERATE */
+#define WM8400_DBLERATE_SHIFT                        4  /* DBLERATE */
+#define WM8400_DBLERATE_WIDTH                        1  /* DBLERATE */
+#define WM8400_LOOPTEST                         0x0008  /* LOOPTEST */
+#define WM8400_LOOPTEST_MASK                    0x0008  /* LOOPTEST */
+#define WM8400_LOOPTEST_SHIFT                        3  /* LOOPTEST */
+#define WM8400_LOOPTEST_WIDTH                        1  /* LOOPTEST */
+#define WM8400_HALFABBIAS                       0x0004  /* HALFABBIAS */
+#define WM8400_HALFABBIAS_MASK                  0x0004  /* HALFABBIAS */
+#define WM8400_HALFABBIAS_SHIFT                      2  /* HALFABBIAS */
+#define WM8400_HALFABBIAS_WIDTH                      1  /* HALFABBIAS */
+#define WM8400_TRIDEL_MASK                      0x0003  /* TRIDEL - [1:0] */
+#define WM8400_TRIDEL_SHIFT                          0  /* TRIDEL - [1:0] */
+#define WM8400_TRIDEL_WIDTH                          2  /* TRIDEL - [1:0] */
+
+/*
+ * R37 (0x25) - ClassD3
+ */
+#define WM8400_DCGAIN_MASK                      0x0038  /* DCGAIN - [5:3] */
+#define WM8400_DCGAIN_SHIFT                          3  /* DCGAIN - [5:3] */
+#define WM8400_DCGAIN_WIDTH                          3  /* DCGAIN - [5:3] */
+#define WM8400_ACGAIN_MASK                      0x0007  /* ACGAIN - [2:0] */
+#define WM8400_ACGAIN_SHIFT                          0  /* ACGAIN - [2:0] */
+#define WM8400_ACGAIN_WIDTH                          3  /* ACGAIN - [2:0] */
+
+/*
+ * R39 (0x27) - Input Mixer1
+ */
+#define WM8400_AINLMODE_MASK                    0x000C  /* AINLMODE - [3:2] */
+#define WM8400_AINLMODE_SHIFT                        2  /* AINLMODE - [3:2] */
+#define WM8400_AINLMODE_WIDTH                        2  /* AINLMODE - [3:2] */
+#define WM8400_AINRMODE_MASK                    0x0003  /* AINRMODE - [1:0] */
+#define WM8400_AINRMODE_SHIFT                        0  /* AINRMODE - [1:0] */
+#define WM8400_AINRMODE_WIDTH                        2  /* AINRMODE - [1:0] */
+
+/*
+ * R40 (0x28) - Input Mixer2
+ */
+#define WM8400_LMP4                             0x0080  /* LMP4 */
+#define WM8400_LMP4_MASK                        0x0080  /* LMP4 */
+#define WM8400_LMP4_SHIFT                            7  /* LMP4 */
+#define WM8400_LMP4_WIDTH                            1  /* LMP4 */
+#define WM8400_LMN3                             0x0040  /* LMN3 */
+#define WM8400_LMN3_MASK                        0x0040  /* LMN3 */
+#define WM8400_LMN3_SHIFT                            6  /* LMN3 */
+#define WM8400_LMN3_WIDTH                            1  /* LMN3 */
+#define WM8400_LMP2                             0x0020  /* LMP2 */
+#define WM8400_LMP2_MASK                        0x0020  /* LMP2 */
+#define WM8400_LMP2_SHIFT                            5  /* LMP2 */
+#define WM8400_LMP2_WIDTH                            1  /* LMP2 */
+#define WM8400_LMN1                             0x0010  /* LMN1 */
+#define WM8400_LMN1_MASK                        0x0010  /* LMN1 */
+#define WM8400_LMN1_SHIFT                            4  /* LMN1 */
+#define WM8400_LMN1_WIDTH                            1  /* LMN1 */
+#define WM8400_RMP4                             0x0008  /* RMP4 */
+#define WM8400_RMP4_MASK                        0x0008  /* RMP4 */
+#define WM8400_RMP4_SHIFT                            3  /* RMP4 */
+#define WM8400_RMP4_WIDTH                            1  /* RMP4 */
+#define WM8400_RMN3                             0x0004  /* RMN3 */
+#define WM8400_RMN3_MASK                        0x0004  /* RMN3 */
+#define WM8400_RMN3_SHIFT                            2  /* RMN3 */
+#define WM8400_RMN3_WIDTH                            1  /* RMN3 */
+#define WM8400_RMP2                             0x0002  /* RMP2 */
+#define WM8400_RMP2_MASK                        0x0002  /* RMP2 */
+#define WM8400_RMP2_SHIFT                            1  /* RMP2 */
+#define WM8400_RMP2_WIDTH                            1  /* RMP2 */
+#define WM8400_RMN1                             0x0001  /* RMN1 */
+#define WM8400_RMN1_MASK                        0x0001  /* RMN1 */
+#define WM8400_RMN1_SHIFT                            0  /* RMN1 */
+#define WM8400_RMN1_WIDTH                            1  /* RMN1 */
+
+/*
+ * R41 (0x29) - Input Mixer3
+ */
+#define WM8400_L34MNB                           0x0100  /* L34MNB */
+#define WM8400_L34MNB_MASK                      0x0100  /* L34MNB */
+#define WM8400_L34MNB_SHIFT                          8  /* L34MNB */
+#define WM8400_L34MNB_WIDTH                          1  /* L34MNB */
+#define WM8400_L34MNBST                         0x0080  /* L34MNBST */
+#define WM8400_L34MNBST_MASK                    0x0080  /* L34MNBST */
+#define WM8400_L34MNBST_SHIFT                        7  /* L34MNBST */
+#define WM8400_L34MNBST_WIDTH                        1  /* L34MNBST */
+#define WM8400_L12MNB                           0x0020  /* L12MNB */
+#define WM8400_L12MNB_MASK                      0x0020  /* L12MNB */
+#define WM8400_L12MNB_SHIFT                          5  /* L12MNB */
+#define WM8400_L12MNB_WIDTH                          1  /* L12MNB */
+#define WM8400_L12MNBST                         0x0010  /* L12MNBST */
+#define WM8400_L12MNBST_MASK                    0x0010  /* L12MNBST */
+#define WM8400_L12MNBST_SHIFT                        4  /* L12MNBST */
+#define WM8400_L12MNBST_WIDTH                        1  /* L12MNBST */
+#define WM8400_LDBVOL_MASK                      0x0007  /* LDBVOL - [2:0] */
+#define WM8400_LDBVOL_SHIFT                          0  /* LDBVOL - [2:0] */
+#define WM8400_LDBVOL_WIDTH                          3  /* LDBVOL - [2:0] */
+
+/*
+ * R42 (0x2A) - Input Mixer4
+ */
+#define WM8400_R34MNB                           0x0100  /* R34MNB */
+#define WM8400_R34MNB_MASK                      0x0100  /* R34MNB */
+#define WM8400_R34MNB_SHIFT                          8  /* R34MNB */
+#define WM8400_R34MNB_WIDTH                          1  /* R34MNB */
+#define WM8400_R34MNBST                         0x0080  /* R34MNBST */
+#define WM8400_R34MNBST_MASK                    0x0080  /* R34MNBST */
+#define WM8400_R34MNBST_SHIFT                        7  /* R34MNBST */
+#define WM8400_R34MNBST_WIDTH                        1  /* R34MNBST */
+#define WM8400_R12MNB                           0x0020  /* R12MNB */
+#define WM8400_R12MNB_MASK                      0x0020  /* R12MNB */
+#define WM8400_R12MNB_SHIFT                          5  /* R12MNB */
+#define WM8400_R12MNB_WIDTH                          1  /* R12MNB */
+#define WM8400_R12MNBST                         0x0010  /* R12MNBST */
+#define WM8400_R12MNBST_MASK                    0x0010  /* R12MNBST */
+#define WM8400_R12MNBST_SHIFT                        4  /* R12MNBST */
+#define WM8400_R12MNBST_WIDTH                        1  /* R12MNBST */
+#define WM8400_RDBVOL_MASK                      0x0007  /* RDBVOL - [2:0] */
+#define WM8400_RDBVOL_SHIFT                          0  /* RDBVOL - [2:0] */
+#define WM8400_RDBVOL_WIDTH                          3  /* RDBVOL - [2:0] */
+
+/*
+ * R43 (0x2B) - Input Mixer5
+ */
+#define WM8400_LI2BVOL_MASK                     0x01C0  /* LI2BVOL - [8:6] */
+#define WM8400_LI2BVOL_SHIFT                         6  /* LI2BVOL - [8:6] */
+#define WM8400_LI2BVOL_WIDTH                         3  /* LI2BVOL - [8:6] */
+#define WM8400_LR4BVOL_MASK                     0x0038  /* LR4BVOL - [5:3] */
+#define WM8400_LR4BVOL_SHIFT                         3  /* LR4BVOL - [5:3] */
+#define WM8400_LR4BVOL_WIDTH                         3  /* LR4BVOL - [5:3] */
+#define WM8400_LL4BVOL_MASK                     0x0007  /* LL4BVOL - [2:0] */
+#define WM8400_LL4BVOL_SHIFT                         0  /* LL4BVOL - [2:0] */
+#define WM8400_LL4BVOL_WIDTH                         3  /* LL4BVOL - [2:0] */
+
+/*
+ * R44 (0x2C) - Input Mixer6
+ */
+#define WM8400_RI2BVOL_MASK                     0x01C0  /* RI2BVOL - [8:6] */
+#define WM8400_RI2BVOL_SHIFT                         6  /* RI2BVOL - [8:6] */
+#define WM8400_RI2BVOL_WIDTH                         3  /* RI2BVOL - [8:6] */
+#define WM8400_RL4BVOL_MASK                     0x0038  /* RL4BVOL - [5:3] */
+#define WM8400_RL4BVOL_SHIFT                         3  /* RL4BVOL - [5:3] */
+#define WM8400_RL4BVOL_WIDTH                         3  /* RL4BVOL - [5:3] */
+#define WM8400_RR4BVOL_MASK                     0x0007  /* RR4BVOL - [2:0] */
+#define WM8400_RR4BVOL_SHIFT                         0  /* RR4BVOL - [2:0] */
+#define WM8400_RR4BVOL_WIDTH                         3  /* RR4BVOL - [2:0] */
+
+/*
+ * R45 (0x2D) - Output Mixer1
+ */
+#define WM8400_LRBLO                            0x0080  /* LRBLO */
+#define WM8400_LRBLO_MASK                       0x0080  /* LRBLO */
+#define WM8400_LRBLO_SHIFT                           7  /* LRBLO */
+#define WM8400_LRBLO_WIDTH                           1  /* LRBLO */
+#define WM8400_LLBLO                            0x0040  /* LLBLO */
+#define WM8400_LLBLO_MASK                       0x0040  /* LLBLO */
+#define WM8400_LLBLO_SHIFT                           6  /* LLBLO */
+#define WM8400_LLBLO_WIDTH                           1  /* LLBLO */
+#define WM8400_LRI3LO                           0x0020  /* LRI3LO */
+#define WM8400_LRI3LO_MASK                      0x0020  /* LRI3LO */
+#define WM8400_LRI3LO_SHIFT                          5  /* LRI3LO */
+#define WM8400_LRI3LO_WIDTH                          1  /* LRI3LO */
+#define WM8400_LLI3LO                           0x0010  /* LLI3LO */
+#define WM8400_LLI3LO_MASK                      0x0010  /* LLI3LO */
+#define WM8400_LLI3LO_SHIFT                          4  /* LLI3LO */
+#define WM8400_LLI3LO_WIDTH                          1  /* LLI3LO */
+#define WM8400_LR12LO                           0x0008  /* LR12LO */
+#define WM8400_LR12LO_MASK                      0x0008  /* LR12LO */
+#define WM8400_LR12LO_SHIFT                          3  /* LR12LO */
+#define WM8400_LR12LO_WIDTH                          1  /* LR12LO */
+#define WM8400_LL12LO                           0x0004  /* LL12LO */
+#define WM8400_LL12LO_MASK                      0x0004  /* LL12LO */
+#define WM8400_LL12LO_SHIFT                          2  /* LL12LO */
+#define WM8400_LL12LO_WIDTH                          1  /* LL12LO */
+#define WM8400_LDLO                             0x0001  /* LDLO */
+#define WM8400_LDLO_MASK                        0x0001  /* LDLO */
+#define WM8400_LDLO_SHIFT                            0  /* LDLO */
+#define WM8400_LDLO_WIDTH                            1  /* LDLO */
+
+/*
+ * R46 (0x2E) - Output Mixer2
+ */
+#define WM8400_RLBRO                            0x0080  /* RLBRO */
+#define WM8400_RLBRO_MASK                       0x0080  /* RLBRO */
+#define WM8400_RLBRO_SHIFT                           7  /* RLBRO */
+#define WM8400_RLBRO_WIDTH                           1  /* RLBRO */
+#define WM8400_RRBRO                            0x0040  /* RRBRO */
+#define WM8400_RRBRO_MASK                       0x0040  /* RRBRO */
+#define WM8400_RRBRO_SHIFT                           6  /* RRBRO */
+#define WM8400_RRBRO_WIDTH                           1  /* RRBRO */
+#define WM8400_RLI3RO                           0x0020  /* RLI3RO */
+#define WM8400_RLI3RO_MASK                      0x0020  /* RLI3RO */
+#define WM8400_RLI3RO_SHIFT                          5  /* RLI3RO */
+#define WM8400_RLI3RO_WIDTH                          1  /* RLI3RO */
+#define WM8400_RRI3RO                           0x0010  /* RRI3RO */
+#define WM8400_RRI3RO_MASK                      0x0010  /* RRI3RO */
+#define WM8400_RRI3RO_SHIFT                          4  /* RRI3RO */
+#define WM8400_RRI3RO_WIDTH                          1  /* RRI3RO */
+#define WM8400_RL12RO                           0x0008  /* RL12RO */
+#define WM8400_RL12RO_MASK                      0x0008  /* RL12RO */
+#define WM8400_RL12RO_SHIFT                          3  /* RL12RO */
+#define WM8400_RL12RO_WIDTH                          1  /* RL12RO */
+#define WM8400_RR12RO                           0x0004  /* RR12RO */
+#define WM8400_RR12RO_MASK                      0x0004  /* RR12RO */
+#define WM8400_RR12RO_SHIFT                          2  /* RR12RO */
+#define WM8400_RR12RO_WIDTH                          1  /* RR12RO */
+#define WM8400_RDRO                             0x0001  /* RDRO */
+#define WM8400_RDRO_MASK                        0x0001  /* RDRO */
+#define WM8400_RDRO_SHIFT                            0  /* RDRO */
+#define WM8400_RDRO_WIDTH                            1  /* RDRO */
+
+/*
+ * R47 (0x2F) - Output Mixer3
+ */
+#define WM8400_LLI3LOVOL_MASK                   0x01C0  /* LLI3LOVOL - [8:6] */
+#define WM8400_LLI3LOVOL_SHIFT                       6  /* LLI3LOVOL - [8:6] */
+#define WM8400_LLI3LOVOL_WIDTH                       3  /* LLI3LOVOL - [8:6] */
+#define WM8400_LR12LOVOL_MASK                   0x0038  /* LR12LOVOL - [5:3] */
+#define WM8400_LR12LOVOL_SHIFT                       3  /* LR12LOVOL - [5:3] */
+#define WM8400_LR12LOVOL_WIDTH                       3  /* LR12LOVOL - [5:3] */
+#define WM8400_LL12LOVOL_MASK                   0x0007  /* LL12LOVOL - [2:0] */
+#define WM8400_LL12LOVOL_SHIFT                       0  /* LL12LOVOL - [2:0] */
+#define WM8400_LL12LOVOL_WIDTH                       3  /* LL12LOVOL - [2:0] */
+
+/*
+ * R48 (0x30) - Output Mixer4
+ */
+#define WM8400_RRI3ROVOL_MASK                   0x01C0  /* RRI3ROVOL - [8:6] */
+#define WM8400_RRI3ROVOL_SHIFT                       6  /* RRI3ROVOL - [8:6] */
+#define WM8400_RRI3ROVOL_WIDTH                       3  /* RRI3ROVOL - [8:6] */
+#define WM8400_RL12ROVOL_MASK                   0x0038  /* RL12ROVOL - [5:3] */
+#define WM8400_RL12ROVOL_SHIFT                       3  /* RL12ROVOL - [5:3] */
+#define WM8400_RL12ROVOL_WIDTH                       3  /* RL12ROVOL - [5:3] */
+#define WM8400_RR12ROVOL_MASK                   0x0007  /* RR12ROVOL - [2:0] */
+#define WM8400_RR12ROVOL_SHIFT                       0  /* RR12ROVOL - [2:0] */
+#define WM8400_RR12ROVOL_WIDTH                       3  /* RR12ROVOL - [2:0] */
+
+/*
+ * R49 (0x31) - Output Mixer5
+ */
+#define WM8400_LRI3LOVOL_MASK                   0x01C0  /* LRI3LOVOL - [8:6] */
+#define WM8400_LRI3LOVOL_SHIFT                       6  /* LRI3LOVOL - [8:6] */
+#define WM8400_LRI3LOVOL_WIDTH                       3  /* LRI3LOVOL - [8:6] */
+#define WM8400_LRBLOVOL_MASK                    0x0038  /* LRBLOVOL - [5:3] */
+#define WM8400_LRBLOVOL_SHIFT                        3  /* LRBLOVOL - [5:3] */
+#define WM8400_LRBLOVOL_WIDTH                        3  /* LRBLOVOL - [5:3] */
+#define WM8400_LLBLOVOL_MASK                    0x0007  /* LLBLOVOL - [2:0] */
+#define WM8400_LLBLOVOL_SHIFT                        0  /* LLBLOVOL - [2:0] */
+#define WM8400_LLBLOVOL_WIDTH                        3  /* LLBLOVOL - [2:0] */
+
+/*
+ * R50 (0x32) - Output Mixer6
+ */
+#define WM8400_RLI3ROVOL_MASK                   0x01C0  /* RLI3ROVOL - [8:6] */
+#define WM8400_RLI3ROVOL_SHIFT                       6  /* RLI3ROVOL - [8:6] */
+#define WM8400_RLI3ROVOL_WIDTH                       3  /* RLI3ROVOL - [8:6] */
+#define WM8400_RLBROVOL_MASK                    0x0038  /* RLBROVOL - [5:3] */
+#define WM8400_RLBROVOL_SHIFT                        3  /* RLBROVOL - [5:3] */
+#define WM8400_RLBROVOL_WIDTH                        3  /* RLBROVOL - [5:3] */
+#define WM8400_RRBROVOL_MASK                    0x0007  /* RRBROVOL - [2:0] */
+#define WM8400_RRBROVOL_SHIFT                        0  /* RRBROVOL - [2:0] */
+#define WM8400_RRBROVOL_WIDTH                        3  /* RRBROVOL - [2:0] */
+
+/*
+ * R51 (0x33) - Out3/4 Mixer
+ */
+#define WM8400_VSEL_MASK                        0x0180  /* VSEL - [8:7] */
+#define WM8400_VSEL_SHIFT                            7  /* VSEL - [8:7] */
+#define WM8400_VSEL_WIDTH                            2  /* VSEL - [8:7] */
+#define WM8400_LI4O3                            0x0020  /* LI4O3 */
+#define WM8400_LI4O3_MASK                       0x0020  /* LI4O3 */
+#define WM8400_LI4O3_SHIFT                           5  /* LI4O3 */
+#define WM8400_LI4O3_WIDTH                           1  /* LI4O3 */
+#define WM8400_LPGAO3                           0x0010  /* LPGAO3 */
+#define WM8400_LPGAO3_MASK                      0x0010  /* LPGAO3 */
+#define WM8400_LPGAO3_SHIFT                          4  /* LPGAO3 */
+#define WM8400_LPGAO3_WIDTH                          1  /* LPGAO3 */
+#define WM8400_RI4O4                            0x0002  /* RI4O4 */
+#define WM8400_RI4O4_MASK                       0x0002  /* RI4O4 */
+#define WM8400_RI4O4_SHIFT                           1  /* RI4O4 */
+#define WM8400_RI4O4_WIDTH                           1  /* RI4O4 */
+#define WM8400_RPGAO4                           0x0001  /* RPGAO4 */
+#define WM8400_RPGAO4_MASK                      0x0001  /* RPGAO4 */
+#define WM8400_RPGAO4_SHIFT                          0  /* RPGAO4 */
+#define WM8400_RPGAO4_WIDTH                          1  /* RPGAO4 */
+
+/*
+ * R52 (0x34) - Line Mixer1
+ */
+#define WM8400_LLOPGALON                        0x0040  /* LLOPGALON */
+#define WM8400_LLOPGALON_MASK                   0x0040  /* LLOPGALON */
+#define WM8400_LLOPGALON_SHIFT                       6  /* LLOPGALON */
+#define WM8400_LLOPGALON_WIDTH                       1  /* LLOPGALON */
+#define WM8400_LROPGALON                        0x0020  /* LROPGALON */
+#define WM8400_LROPGALON_MASK                   0x0020  /* LROPGALON */
+#define WM8400_LROPGALON_SHIFT                       5  /* LROPGALON */
+#define WM8400_LROPGALON_WIDTH                       1  /* LROPGALON */
+#define WM8400_LOPLON                           0x0010  /* LOPLON */
+#define WM8400_LOPLON_MASK                      0x0010  /* LOPLON */
+#define WM8400_LOPLON_SHIFT                          4  /* LOPLON */
+#define WM8400_LOPLON_WIDTH                          1  /* LOPLON */
+#define WM8400_LR12LOP                          0x0004  /* LR12LOP */
+#define WM8400_LR12LOP_MASK                     0x0004  /* LR12LOP */
+#define WM8400_LR12LOP_SHIFT                         2  /* LR12LOP */
+#define WM8400_LR12LOP_WIDTH                         1  /* LR12LOP */
+#define WM8400_LL12LOP                          0x0002  /* LL12LOP */
+#define WM8400_LL12LOP_MASK                     0x0002  /* LL12LOP */
+#define WM8400_LL12LOP_SHIFT                         1  /* LL12LOP */
+#define WM8400_LL12LOP_WIDTH                         1  /* LL12LOP */
+#define WM8400_LLOPGALOP                        0x0001  /* LLOPGALOP */
+#define WM8400_LLOPGALOP_MASK                   0x0001  /* LLOPGALOP */
+#define WM8400_LLOPGALOP_SHIFT                       0  /* LLOPGALOP */
+#define WM8400_LLOPGALOP_WIDTH                       1  /* LLOPGALOP */
+
+/*
+ * R53 (0x35) - Line Mixer2
+ */
+#define WM8400_RROPGARON                        0x0040  /* RROPGARON */
+#define WM8400_RROPGARON_MASK                   0x0040  /* RROPGARON */
+#define WM8400_RROPGARON_SHIFT                       6  /* RROPGARON */
+#define WM8400_RROPGARON_WIDTH                       1  /* RROPGARON */
+#define WM8400_RLOPGARON                        0x0020  /* RLOPGARON */
+#define WM8400_RLOPGARON_MASK                   0x0020  /* RLOPGARON */
+#define WM8400_RLOPGARON_SHIFT                       5  /* RLOPGARON */
+#define WM8400_RLOPGARON_WIDTH                       1  /* RLOPGARON */
+#define WM8400_ROPRON                           0x0010  /* ROPRON */
+#define WM8400_ROPRON_MASK                      0x0010  /* ROPRON */
+#define WM8400_ROPRON_SHIFT                          4  /* ROPRON */
+#define WM8400_ROPRON_WIDTH                          1  /* ROPRON */
+#define WM8400_RL12ROP                          0x0004  /* RL12ROP */
+#define WM8400_RL12ROP_MASK                     0x0004  /* RL12ROP */
+#define WM8400_RL12ROP_SHIFT                         2  /* RL12ROP */
+#define WM8400_RL12ROP_WIDTH                         1  /* RL12ROP */
+#define WM8400_RR12ROP                          0x0002  /* RR12ROP */
+#define WM8400_RR12ROP_MASK                     0x0002  /* RR12ROP */
+#define WM8400_RR12ROP_SHIFT                         1  /* RR12ROP */
+#define WM8400_RR12ROP_WIDTH                         1  /* RR12ROP */
+#define WM8400_RROPGAROP                        0x0001  /* RROPGAROP */
+#define WM8400_RROPGAROP_MASK                   0x0001  /* RROPGAROP */
+#define WM8400_RROPGAROP_SHIFT                       0  /* RROPGAROP */
+#define WM8400_RROPGAROP_WIDTH                       1  /* RROPGAROP */
+
+/*
+ * R54 (0x36) - Speaker Mixer
+ */
+#define WM8400_LB2SPK                           0x0080  /* LB2SPK */
+#define WM8400_LB2SPK_MASK                      0x0080  /* LB2SPK */
+#define WM8400_LB2SPK_SHIFT                          7  /* LB2SPK */
+#define WM8400_LB2SPK_WIDTH                          1  /* LB2SPK */
+#define WM8400_RB2SPK                           0x0040  /* RB2SPK */
+#define WM8400_RB2SPK_MASK                      0x0040  /* RB2SPK */
+#define WM8400_RB2SPK_SHIFT                          6  /* RB2SPK */
+#define WM8400_RB2SPK_WIDTH                          1  /* RB2SPK */
+#define WM8400_LI2SPK                           0x0020  /* LI2SPK */
+#define WM8400_LI2SPK_MASK                      0x0020  /* LI2SPK */
+#define WM8400_LI2SPK_SHIFT                          5  /* LI2SPK */
+#define WM8400_LI2SPK_WIDTH                          1  /* LI2SPK */
+#define WM8400_RI2SPK                           0x0010  /* RI2SPK */
+#define WM8400_RI2SPK_MASK                      0x0010  /* RI2SPK */
+#define WM8400_RI2SPK_SHIFT                          4  /* RI2SPK */
+#define WM8400_RI2SPK_WIDTH                          1  /* RI2SPK */
+#define WM8400_LOPGASPK                         0x0008  /* LOPGASPK */
+#define WM8400_LOPGASPK_MASK                    0x0008  /* LOPGASPK */
+#define WM8400_LOPGASPK_SHIFT                        3  /* LOPGASPK */
+#define WM8400_LOPGASPK_WIDTH                        1  /* LOPGASPK */
+#define WM8400_ROPGASPK                         0x0004  /* ROPGASPK */
+#define WM8400_ROPGASPK_MASK                    0x0004  /* ROPGASPK */
+#define WM8400_ROPGASPK_SHIFT                        2  /* ROPGASPK */
+#define WM8400_ROPGASPK_WIDTH                        1  /* ROPGASPK */
+#define WM8400_LDSPK                            0x0002  /* LDSPK */
+#define WM8400_LDSPK_MASK                       0x0002  /* LDSPK */
+#define WM8400_LDSPK_SHIFT                           1  /* LDSPK */
+#define WM8400_LDSPK_WIDTH                           1  /* LDSPK */
+#define WM8400_RDSPK                            0x0001  /* RDSPK */
+#define WM8400_RDSPK_MASK                       0x0001  /* RDSPK */
+#define WM8400_RDSPK_SHIFT                           0  /* RDSPK */
+#define WM8400_RDSPK_WIDTH                           1  /* RDSPK */
+
+/*
+ * R55 (0x37) - Additional Control
+ */
+#define WM8400_VROI                             0x0001  /* VROI */
+#define WM8400_VROI_MASK                        0x0001  /* VROI */
+#define WM8400_VROI_SHIFT                            0  /* VROI */
+#define WM8400_VROI_WIDTH                            1  /* VROI */
+
+/*
+ * R56 (0x38) - AntiPOP1
+ */
+#define WM8400_DIS_LLINE                        0x0020  /* DIS_LLINE */
+#define WM8400_DIS_LLINE_MASK                   0x0020  /* DIS_LLINE */
+#define WM8400_DIS_LLINE_SHIFT                       5  /* DIS_LLINE */
+#define WM8400_DIS_LLINE_WIDTH                       1  /* DIS_LLINE */
+#define WM8400_DIS_RLINE                        0x0010  /* DIS_RLINE */
+#define WM8400_DIS_RLINE_MASK                   0x0010  /* DIS_RLINE */
+#define WM8400_DIS_RLINE_SHIFT                       4  /* DIS_RLINE */
+#define WM8400_DIS_RLINE_WIDTH                       1  /* DIS_RLINE */
+#define WM8400_DIS_OUT3                         0x0008  /* DIS_OUT3 */
+#define WM8400_DIS_OUT3_MASK                    0x0008  /* DIS_OUT3 */
+#define WM8400_DIS_OUT3_SHIFT                        3  /* DIS_OUT3 */
+#define WM8400_DIS_OUT3_WIDTH                        1  /* DIS_OUT3 */
+#define WM8400_DIS_OUT4                         0x0004  /* DIS_OUT4 */
+#define WM8400_DIS_OUT4_MASK                    0x0004  /* DIS_OUT4 */
+#define WM8400_DIS_OUT4_SHIFT                        2  /* DIS_OUT4 */
+#define WM8400_DIS_OUT4_WIDTH                        1  /* DIS_OUT4 */
+#define WM8400_DIS_LOUT                         0x0002  /* DIS_LOUT */
+#define WM8400_DIS_LOUT_MASK                    0x0002  /* DIS_LOUT */
+#define WM8400_DIS_LOUT_SHIFT                        1  /* DIS_LOUT */
+#define WM8400_DIS_LOUT_WIDTH                        1  /* DIS_LOUT */
+#define WM8400_DIS_ROUT                         0x0001  /* DIS_ROUT */
+#define WM8400_DIS_ROUT_MASK                    0x0001  /* DIS_ROUT */
+#define WM8400_DIS_ROUT_SHIFT                        0  /* DIS_ROUT */
+#define WM8400_DIS_ROUT_WIDTH                        1  /* DIS_ROUT */
+
+/*
+ * R57 (0x39) - AntiPOP2
+ */
+#define WM8400_SOFTST                           0x0040  /* SOFTST */
+#define WM8400_SOFTST_MASK                      0x0040  /* SOFTST */
+#define WM8400_SOFTST_SHIFT                          6  /* SOFTST */
+#define WM8400_SOFTST_WIDTH                          1  /* SOFTST */
+#define WM8400_BUFIOEN                          0x0008  /* BUFIOEN */
+#define WM8400_BUFIOEN_MASK                     0x0008  /* BUFIOEN */
+#define WM8400_BUFIOEN_SHIFT                         3  /* BUFIOEN */
+#define WM8400_BUFIOEN_WIDTH                         1  /* BUFIOEN */
+#define WM8400_BUFDCOPEN                        0x0004  /* BUFDCOPEN */
+#define WM8400_BUFDCOPEN_MASK                   0x0004  /* BUFDCOPEN */
+#define WM8400_BUFDCOPEN_SHIFT                       2  /* BUFDCOPEN */
+#define WM8400_BUFDCOPEN_WIDTH                       1  /* BUFDCOPEN */
+#define WM8400_POBCTRL                          0x0002  /* POBCTRL */
+#define WM8400_POBCTRL_MASK                     0x0002  /* POBCTRL */
+#define WM8400_POBCTRL_SHIFT                         1  /* POBCTRL */
+#define WM8400_POBCTRL_WIDTH                         1  /* POBCTRL */
+#define WM8400_VMIDTOG                          0x0001  /* VMIDTOG */
+#define WM8400_VMIDTOG_MASK                     0x0001  /* VMIDTOG */
+#define WM8400_VMIDTOG_SHIFT                         0  /* VMIDTOG */
+#define WM8400_VMIDTOG_WIDTH                         1  /* VMIDTOG */
+
+/*
+ * R58 (0x3A) - MICBIAS
+ */
+#define WM8400_MCDSCTH_MASK                     0x00C0  /* MCDSCTH - [7:6] */
+#define WM8400_MCDSCTH_SHIFT                         6  /* MCDSCTH - [7:6] */
+#define WM8400_MCDSCTH_WIDTH                         2  /* MCDSCTH - [7:6] */
+#define WM8400_MCDTHR_MASK                      0x0038  /* MCDTHR - [5:3] */
+#define WM8400_MCDTHR_SHIFT                          3  /* MCDTHR - [5:3] */
+#define WM8400_MCDTHR_WIDTH                          3  /* MCDTHR - [5:3] */
+#define WM8400_MCD                              0x0004  /* MCD */
+#define WM8400_MCD_MASK                         0x0004  /* MCD */
+#define WM8400_MCD_SHIFT                             2  /* MCD */
+#define WM8400_MCD_WIDTH                             1  /* MCD */
+#define WM8400_MBSEL                            0x0001  /* MBSEL */
+#define WM8400_MBSEL_MASK                       0x0001  /* MBSEL */
+#define WM8400_MBSEL_SHIFT                           0  /* MBSEL */
+#define WM8400_MBSEL_WIDTH                           1  /* MBSEL */
+
+/*
+ * R60 (0x3C) - FLL Control 1
+ */
+#define WM8400_FLL_REF_FREQ                     0x1000  /* FLL_REF_FREQ */
+#define WM8400_FLL_REF_FREQ_MASK                0x1000  /* FLL_REF_FREQ */
+#define WM8400_FLL_REF_FREQ_SHIFT                   12  /* FLL_REF_FREQ */
+#define WM8400_FLL_REF_FREQ_WIDTH                    1  /* FLL_REF_FREQ */
+#define WM8400_FLL_CLK_SRC_MASK                 0x0C00  /* FLL_CLK_SRC - [11:10] */
+#define WM8400_FLL_CLK_SRC_SHIFT                    10  /* FLL_CLK_SRC - [11:10] */
+#define WM8400_FLL_CLK_SRC_WIDTH                     2  /* FLL_CLK_SRC - [11:10] */
+#define WM8400_FLL_FRAC                         0x0200  /* FLL_FRAC */
+#define WM8400_FLL_FRAC_MASK                    0x0200  /* FLL_FRAC */
+#define WM8400_FLL_FRAC_SHIFT                        9  /* FLL_FRAC */
+#define WM8400_FLL_FRAC_WIDTH                        1  /* FLL_FRAC */
+#define WM8400_FLL_OSC_ENA                      0x0100  /* FLL_OSC_ENA */
+#define WM8400_FLL_OSC_ENA_MASK                 0x0100  /* FLL_OSC_ENA */
+#define WM8400_FLL_OSC_ENA_SHIFT                     8  /* FLL_OSC_ENA */
+#define WM8400_FLL_OSC_ENA_WIDTH                     1  /* FLL_OSC_ENA */
+#define WM8400_FLL_CTRL_RATE_MASK               0x00E0  /* FLL_CTRL_RATE - [7:5] */
+#define WM8400_FLL_CTRL_RATE_SHIFT                   5  /* FLL_CTRL_RATE - [7:5] */
+#define WM8400_FLL_CTRL_RATE_WIDTH                   3  /* FLL_CTRL_RATE - [7:5] */
+#define WM8400_FLL_FRATIO_MASK                  0x001F  /* FLL_FRATIO - [4:0] */
+#define WM8400_FLL_FRATIO_SHIFT                      0  /* FLL_FRATIO - [4:0] */
+#define WM8400_FLL_FRATIO_WIDTH                      5  /* FLL_FRATIO - [4:0] */
+
+/*
+ * R61 (0x3D) - FLL Control 2
+ */
+#define WM8400_FLL_K_MASK                       0xFFFF  /* FLL_K - [15:0] */
+#define WM8400_FLL_K_SHIFT                           0  /* FLL_K - [15:0] */
+#define WM8400_FLL_K_WIDTH                          16  /* FLL_K - [15:0] */
+
+/*
+ * R62 (0x3E) - FLL Control 3
+ */
+#define WM8400_FLL_N_MASK                       0x03FF  /* FLL_N - [9:0] */
+#define WM8400_FLL_N_SHIFT                           0  /* FLL_N - [9:0] */
+#define WM8400_FLL_N_WIDTH                          10  /* FLL_N - [9:0] */
+
+/*
+ * R63 (0x3F) - FLL Control 4
+ */
+#define WM8400_FLL_TRK_GAIN_MASK                0x0078  /* FLL_TRK_GAIN - [6:3] */
+#define WM8400_FLL_TRK_GAIN_SHIFT                    3  /* FLL_TRK_GAIN - [6:3] */
+#define WM8400_FLL_TRK_GAIN_WIDTH                    4  /* FLL_TRK_GAIN - [6:3] */
+#define WM8400_FLL_OUTDIV_MASK                  0x0007  /* FLL_OUTDIV - [2:0] */
+#define WM8400_FLL_OUTDIV_SHIFT                      0  /* FLL_OUTDIV - [2:0] */
+#define WM8400_FLL_OUTDIV_WIDTH                      3  /* FLL_OUTDIV - [2:0] */
+
+void wm8400_reset_codec_reg_cache(struct wm8400 *wm8400);
+
+#endif
diff --git a/include/linux/mfd/wm8400-private.h b/include/linux/mfd/wm8400-private.h
new file mode 100644 (file)
index 0000000..2aab4e9
--- /dev/null
@@ -0,0 +1,936 @@
+/*
+ * wm8400 private definitions.
+ *
+ * Copyright 2008 Wolfson Microelectronics plc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __LINUX_MFD_WM8400_PRIV_H
+#define __LINUX_MFD_WM8400_PRIV_H
+
+#include <linux/mfd/wm8400.h>
+#include <linux/mutex.h>
+#include <linux/platform_device.h>
+
+#define WM8400_REGISTER_COUNT 0x55
+
+struct wm8400 {
+       struct device *dev;
+
+       int (*read_dev)(void *data, char reg, int count, u16 *dst);
+       int (*write_dev)(void *data, char reg, int count, const u16 *src);
+
+       struct mutex io_lock;
+       void *io_data;
+
+       u16 reg_cache[WM8400_REGISTER_COUNT];
+
+       struct platform_device regulators[6];
+};
+
+/*
+ * Register values.
+ */
+#define WM8400_RESET_ID                         0x00
+#define WM8400_ID                               0x01
+#define WM8400_POWER_MANAGEMENT_1               0x02
+#define WM8400_POWER_MANAGEMENT_2               0x03
+#define WM8400_POWER_MANAGEMENT_3               0x04
+#define WM8400_AUDIO_INTERFACE_1                0x05
+#define WM8400_AUDIO_INTERFACE_2                0x06
+#define WM8400_CLOCKING_1                       0x07
+#define WM8400_CLOCKING_2                       0x08
+#define WM8400_AUDIO_INTERFACE_3                0x09
+#define WM8400_AUDIO_INTERFACE_4                0x0A
+#define WM8400_DAC_CTRL                         0x0B
+#define WM8400_LEFT_DAC_DIGITAL_VOLUME          0x0C
+#define WM8400_RIGHT_DAC_DIGITAL_VOLUME         0x0D
+#define WM8400_DIGITAL_SIDE_TONE                0x0E
+#define WM8400_ADC_CTRL                         0x0F
+#define WM8400_LEFT_ADC_DIGITAL_VOLUME          0x10
+#define WM8400_RIGHT_ADC_DIGITAL_VOLUME         0x11
+#define WM8400_GPIO_CTRL_1                      0x12
+#define WM8400_GPIO1_GPIO2                      0x13
+#define WM8400_GPIO3_GPIO4                      0x14
+#define WM8400_GPIO5_GPIO6                      0x15
+#define WM8400_GPIOCTRL_2                       0x16
+#define WM8400_GPIO_POL                         0x17
+#define WM8400_LEFT_LINE_INPUT_1_2_VOLUME       0x18
+#define WM8400_LEFT_LINE_INPUT_3_4_VOLUME       0x19
+#define WM8400_RIGHT_LINE_INPUT_1_2_VOLUME      0x1A
+#define WM8400_RIGHT_LINE_INPUT_3_4_VOLUME      0x1B
+#define WM8400_LEFT_OUTPUT_VOLUME               0x1C
+#define WM8400_RIGHT_OUTPUT_VOLUME              0x1D
+#define WM8400_LINE_OUTPUTS_VOLUME              0x1E
+#define WM8400_OUT3_4_VOLUME                    0x1F
+#define WM8400_LEFT_OPGA_VOLUME                 0x20
+#define WM8400_RIGHT_OPGA_VOLUME                0x21
+#define WM8400_SPEAKER_VOLUME                   0x22
+#define WM8400_CLASSD1                          0x23
+#define WM8400_CLASSD3                          0x25
+#define WM8400_INPUT_MIXER1                     0x27
+#define WM8400_INPUT_MIXER2                     0x28
+#define WM8400_INPUT_MIXER3                     0x29
+#define WM8400_INPUT_MIXER4                     0x2A
+#define WM8400_INPUT_MIXER5                     0x2B
+#define WM8400_INPUT_MIXER6                     0x2C
+#define WM8400_OUTPUT_MIXER1                    0x2D
+#define WM8400_OUTPUT_MIXER2                    0x2E
+#define WM8400_OUTPUT_MIXER3                    0x2F
+#define WM8400_OUTPUT_MIXER4                    0x30
+#define WM8400_OUTPUT_MIXER5                    0x31
+#define WM8400_OUTPUT_MIXER6                    0x32
+#define WM8400_OUT3_4_MIXER                     0x33
+#define WM8400_LINE_MIXER1                      0x34
+#define WM8400_LINE_MIXER2                      0x35
+#define WM8400_SPEAKER_MIXER                    0x36
+#define WM8400_ADDITIONAL_CONTROL               0x37
+#define WM8400_ANTIPOP1                         0x38
+#define WM8400_ANTIPOP2                         0x39
+#define WM8400_MICBIAS                          0x3A
+#define WM8400_FLL_CONTROL_1                    0x3C
+#define WM8400_FLL_CONTROL_2                    0x3D
+#define WM8400_FLL_CONTROL_3                    0x3E
+#define WM8400_FLL_CONTROL_4                    0x3F
+#define WM8400_LDO1_CONTROL                     0x41
+#define WM8400_LDO2_CONTROL                     0x42
+#define WM8400_LDO3_CONTROL                     0x43
+#define WM8400_LDO4_CONTROL                     0x44
+#define WM8400_DCDC1_CONTROL_1                  0x46
+#define WM8400_DCDC1_CONTROL_2                  0x47
+#define WM8400_DCDC2_CONTROL_1                  0x48
+#define WM8400_DCDC2_CONTROL_2                  0x49
+#define WM8400_INTERFACE                        0x4B
+#define WM8400_PM_GENERAL                       0x4C
+#define WM8400_PM_SHUTDOWN_CONTROL              0x4E
+#define WM8400_INTERRUPT_STATUS_1               0x4F
+#define WM8400_INTERRUPT_STATUS_1_MASK          0x50
+#define WM8400_INTERRUPT_LEVELS                 0x51
+#define WM8400_SHUTDOWN_REASON                  0x52
+#define WM8400_LINE_CIRCUITS                    0x54
+
+/*
+ * Field Definitions.
+ */
+
+/*
+ * R0 (0x00) - Reset/ID
+ */
+#define WM8400_SW_RESET_CHIP_ID_MASK            0xFFFF  /* SW_RESET/CHIP_ID - [15:0] */
+#define WM8400_SW_RESET_CHIP_ID_SHIFT                0  /* SW_RESET/CHIP_ID - [15:0] */
+#define WM8400_SW_RESET_CHIP_ID_WIDTH               16  /* SW_RESET/CHIP_ID - [15:0] */
+
+/*
+ * R1 (0x01) - ID
+ */
+#define WM8400_CHIP_REV_MASK                    0x7000  /* CHIP_REV - [14:12] */
+#define WM8400_CHIP_REV_SHIFT                       12  /* CHIP_REV - [14:12] */
+#define WM8400_CHIP_REV_WIDTH                        3  /* CHIP_REV - [14:12] */
+
+/*
+ * R18 (0x12) - GPIO CTRL 1
+ */
+#define WM8400_IRQ                              0x1000  /* IRQ */
+#define WM8400_IRQ_MASK                         0x1000  /* IRQ */
+#define WM8400_IRQ_SHIFT                            12  /* IRQ */
+#define WM8400_IRQ_WIDTH                             1  /* IRQ */
+#define WM8400_TEMPOK                           0x0800  /* TEMPOK */
+#define WM8400_TEMPOK_MASK                      0x0800  /* TEMPOK */
+#define WM8400_TEMPOK_SHIFT                         11  /* TEMPOK */
+#define WM8400_TEMPOK_WIDTH                          1  /* TEMPOK */
+#define WM8400_MIC1SHRT                         0x0400  /* MIC1SHRT */
+#define WM8400_MIC1SHRT_MASK                    0x0400  /* MIC1SHRT */
+#define WM8400_MIC1SHRT_SHIFT                       10  /* MIC1SHRT */
+#define WM8400_MIC1SHRT_WIDTH                        1  /* MIC1SHRT */
+#define WM8400_MIC1DET                          0x0200  /* MIC1DET */
+#define WM8400_MIC1DET_MASK                     0x0200  /* MIC1DET */
+#define WM8400_MIC1DET_SHIFT                         9  /* MIC1DET */
+#define WM8400_MIC1DET_WIDTH                         1  /* MIC1DET */
+#define WM8400_FLL_LCK                          0x0100  /* FLL_LCK */
+#define WM8400_FLL_LCK_MASK                     0x0100  /* FLL_LCK */
+#define WM8400_FLL_LCK_SHIFT                         8  /* FLL_LCK */
+#define WM8400_FLL_LCK_WIDTH                         1  /* FLL_LCK */
+#define WM8400_GPIO_STATUS_MASK                 0x00FF  /* GPIO_STATUS - [7:0] */
+#define WM8400_GPIO_STATUS_SHIFT                     0  /* GPIO_STATUS - [7:0] */
+#define WM8400_GPIO_STATUS_WIDTH                     8  /* GPIO_STATUS - [7:0] */
+
+/*
+ * R19 (0x13) - GPIO1 & GPIO2
+ */
+#define WM8400_GPIO2_DEB_ENA                    0x8000  /* GPIO2_DEB_ENA */
+#define WM8400_GPIO2_DEB_ENA_MASK               0x8000  /* GPIO2_DEB_ENA */
+#define WM8400_GPIO2_DEB_ENA_SHIFT                  15  /* GPIO2_DEB_ENA */
+#define WM8400_GPIO2_DEB_ENA_WIDTH                   1  /* GPIO2_DEB_ENA */
+#define WM8400_GPIO2_IRQ_ENA                    0x4000  /* GPIO2_IRQ_ENA */
+#define WM8400_GPIO2_IRQ_ENA_MASK               0x4000  /* GPIO2_IRQ_ENA */
+#define WM8400_GPIO2_IRQ_ENA_SHIFT                  14  /* GPIO2_IRQ_ENA */
+#define WM8400_GPIO2_IRQ_ENA_WIDTH                   1  /* GPIO2_IRQ_ENA */
+#define WM8400_GPIO2_PU                         0x2000  /* GPIO2_PU */
+#define WM8400_GPIO2_PU_MASK                    0x2000  /* GPIO2_PU */
+#define WM8400_GPIO2_PU_SHIFT                       13  /* GPIO2_PU */
+#define WM8400_GPIO2_PU_WIDTH                        1  /* GPIO2_PU */
+#define WM8400_GPIO2_PD                         0x1000  /* GPIO2_PD */
+#define WM8400_GPIO2_PD_MASK                    0x1000  /* GPIO2_PD */
+#define WM8400_GPIO2_PD_SHIFT                       12  /* GPIO2_PD */
+#define WM8400_GPIO2_PD_WIDTH                        1  /* GPIO2_PD */
+#define WM8400_GPIO2_SEL_MASK                   0x0F00  /* GPIO2_SEL - [11:8] */
+#define WM8400_GPIO2_SEL_SHIFT                       8  /* GPIO2_SEL - [11:8] */
+#define WM8400_GPIO2_SEL_WIDTH                       4  /* GPIO2_SEL - [11:8] */
+#define WM8400_GPIO1_DEB_ENA                    0x0080  /* GPIO1_DEB_ENA */
+#define WM8400_GPIO1_DEB_ENA_MASK               0x0080  /* GPIO1_DEB_ENA */
+#define WM8400_GPIO1_DEB_ENA_SHIFT                   7  /* GPIO1_DEB_ENA */
+#define WM8400_GPIO1_DEB_ENA_WIDTH                   1  /* GPIO1_DEB_ENA */
+#define WM8400_GPIO1_IRQ_ENA                    0x0040  /* GPIO1_IRQ_ENA */
+#define WM8400_GPIO1_IRQ_ENA_MASK               0x0040  /* GPIO1_IRQ_ENA */
+#define WM8400_GPIO1_IRQ_ENA_SHIFT                   6  /* GPIO1_IRQ_ENA */
+#define WM8400_GPIO1_IRQ_ENA_WIDTH                   1  /* GPIO1_IRQ_ENA */
+#define WM8400_GPIO1_PU                         0x0020  /* GPIO1_PU */
+#define WM8400_GPIO1_PU_MASK                    0x0020  /* GPIO1_PU */
+#define WM8400_GPIO1_PU_SHIFT                        5  /* GPIO1_PU */
+#define WM8400_GPIO1_PU_WIDTH                        1  /* GPIO1_PU */
+#define WM8400_GPIO1_PD                         0x0010  /* GPIO1_PD */
+#define WM8400_GPIO1_PD_MASK                    0x0010  /* GPIO1_PD */
+#define WM8400_GPIO1_PD_SHIFT                        4  /* GPIO1_PD */
+#define WM8400_GPIO1_PD_WIDTH                        1  /* GPIO1_PD */
+#define WM8400_GPIO1_SEL_MASK                   0x000F  /* GPIO1_SEL - [3:0] */
+#define WM8400_GPIO1_SEL_SHIFT                       0  /* GPIO1_SEL - [3:0] */
+#define WM8400_GPIO1_SEL_WIDTH                       4  /* GPIO1_SEL - [3:0] */
+
+/*
+ * R20 (0x14) - GPIO3 & GPIO4
+ */
+#define WM8400_GPIO4_DEB_ENA                    0x8000  /* GPIO4_DEB_ENA */
+#define WM8400_GPIO4_DEB_ENA_MASK               0x8000  /* GPIO4_DEB_ENA */
+#define WM8400_GPIO4_DEB_ENA_SHIFT                  15  /* GPIO4_DEB_ENA */
+#define WM8400_GPIO4_DEB_ENA_WIDTH                   1  /* GPIO4_DEB_ENA */
+#define WM8400_GPIO4_IRQ_ENA                    0x4000  /* GPIO4_IRQ_ENA */
+#define WM8400_GPIO4_IRQ_ENA_MASK               0x4000  /* GPIO4_IRQ_ENA */
+#define WM8400_GPIO4_IRQ_ENA_SHIFT                  14  /* GPIO4_IRQ_ENA */
+#define WM8400_GPIO4_IRQ_ENA_WIDTH                   1  /* GPIO4_IRQ_ENA */
+#define WM8400_GPIO4_PU                         0x2000  /* GPIO4_PU */
+#define WM8400_GPIO4_PU_MASK                    0x2000  /* GPIO4_PU */
+#define WM8400_GPIO4_PU_SHIFT                       13  /* GPIO4_PU */
+#define WM8400_GPIO4_PU_WIDTH                        1  /* GPIO4_PU */
+#define WM8400_GPIO4_PD                         0x1000  /* GPIO4_PD */
+#define WM8400_GPIO4_PD_MASK                    0x1000  /* GPIO4_PD */
+#define WM8400_GPIO4_PD_SHIFT                       12  /* GPIO4_PD */
+#define WM8400_GPIO4_PD_WIDTH                        1  /* GPIO4_PD */
+#define WM8400_GPIO4_SEL_MASK                   0x0F00  /* GPIO4_SEL - [11:8] */
+#define WM8400_GPIO4_SEL_SHIFT                       8  /* GPIO4_SEL - [11:8] */
+#define WM8400_GPIO4_SEL_WIDTH                       4  /* GPIO4_SEL - [11:8] */
+#define WM8400_GPIO3_DEB_ENA                    0x0080  /* GPIO3_DEB_ENA */
+#define WM8400_GPIO3_DEB_ENA_MASK               0x0080  /* GPIO3_DEB_ENA */
+#define WM8400_GPIO3_DEB_ENA_SHIFT                   7  /* GPIO3_DEB_ENA */
+#define WM8400_GPIO3_DEB_ENA_WIDTH                   1  /* GPIO3_DEB_ENA */
+#define WM8400_GPIO3_IRQ_ENA                    0x0040  /* GPIO3_IRQ_ENA */
+#define WM8400_GPIO3_IRQ_ENA_MASK               0x0040  /* GPIO3_IRQ_ENA */
+#define WM8400_GPIO3_IRQ_ENA_SHIFT                   6  /* GPIO3_IRQ_ENA */
+#define WM8400_GPIO3_IRQ_ENA_WIDTH                   1  /* GPIO3_IRQ_ENA */
+#define WM8400_GPIO3_PU                         0x0020  /* GPIO3_PU */
+#define WM8400_GPIO3_PU_MASK                    0x0020  /* GPIO3_PU */
+#define WM8400_GPIO3_PU_SHIFT                        5  /* GPIO3_PU */
+#define WM8400_GPIO3_PU_WIDTH                        1  /* GPIO3_PU */
+#define WM8400_GPIO3_PD                         0x0010  /* GPIO3_PD */
+#define WM8400_GPIO3_PD_MASK                    0x0010  /* GPIO3_PD */
+#define WM8400_GPIO3_PD_SHIFT                        4  /* GPIO3_PD */
+#define WM8400_GPIO3_PD_WIDTH                        1  /* GPIO3_PD */
+#define WM8400_GPIO3_SEL_MASK                   0x000F  /* GPIO3_SEL - [3:0] */
+#define WM8400_GPIO3_SEL_SHIFT                       0  /* GPIO3_SEL - [3:0] */
+#define WM8400_GPIO3_SEL_WIDTH                       4  /* GPIO3_SEL - [3:0] */
+
+/*
+ * R21 (0x15) - GPIO5 & GPIO6
+ */
+#define WM8400_GPIO6_DEB_ENA                    0x8000  /* GPIO6_DEB_ENA */
+#define WM8400_GPIO6_DEB_ENA_MASK               0x8000  /* GPIO6_DEB_ENA */
+#define WM8400_GPIO6_DEB_ENA_SHIFT                  15  /* GPIO6_DEB_ENA */
+#define WM8400_GPIO6_DEB_ENA_WIDTH                   1  /* GPIO6_DEB_ENA */
+#define WM8400_GPIO6_IRQ_ENA                    0x4000  /* GPIO6_IRQ_ENA */
+#define WM8400_GPIO6_IRQ_ENA_MASK               0x4000  /* GPIO6_IRQ_ENA */
+#define WM8400_GPIO6_IRQ_ENA_SHIFT                  14  /* GPIO6_IRQ_ENA */
+#define WM8400_GPIO6_IRQ_ENA_WIDTH                   1  /* GPIO6_IRQ_ENA */
+#define WM8400_GPIO6_PU                         0x2000  /* GPIO6_PU */
+#define WM8400_GPIO6_PU_MASK                    0x2000  /* GPIO6_PU */
+#define WM8400_GPIO6_PU_SHIFT                       13  /* GPIO6_PU */
+#define WM8400_GPIO6_PU_WIDTH                        1  /* GPIO6_PU */
+#define WM8400_GPIO6_PD                         0x1000  /* GPIO6_PD */
+#define WM8400_GPIO6_PD_MASK                    0x1000  /* GPIO6_PD */
+#define WM8400_GPIO6_PD_SHIFT                       12  /* GPIO6_PD */
+#define WM8400_GPIO6_PD_WIDTH                        1  /* GPIO6_PD */
+#define WM8400_GPIO6_SEL_MASK                   0x0F00  /* GPIO6_SEL - [11:8] */
+#define WM8400_GPIO6_SEL_SHIFT                       8  /* GPIO6_SEL - [11:8] */
+#define WM8400_GPIO6_SEL_WIDTH                       4  /* GPIO6_SEL - [11:8] */
+#define WM8400_GPIO5_DEB_ENA                    0x0080  /* GPIO5_DEB_ENA */
+#define WM8400_GPIO5_DEB_ENA_MASK               0x0080  /* GPIO5_DEB_ENA */
+#define WM8400_GPIO5_DEB_ENA_SHIFT                   7  /* GPIO5_DEB_ENA */
+#define WM8400_GPIO5_DEB_ENA_WIDTH                   1  /* GPIO5_DEB_ENA */
+#define WM8400_GPIO5_IRQ_ENA                    0x0040  /* GPIO5_IRQ_ENA */
+#define WM8400_GPIO5_IRQ_ENA_MASK               0x0040  /* GPIO5_IRQ_ENA */
+#define WM8400_GPIO5_IRQ_ENA_SHIFT                   6  /* GPIO5_IRQ_ENA */
+#define WM8400_GPIO5_IRQ_ENA_WIDTH                   1  /* GPIO5_IRQ_ENA */
+#define WM8400_GPIO5_PU                         0x0020  /* GPIO5_PU */
+#define WM8400_GPIO5_PU_MASK                    0x0020  /* GPIO5_PU */
+#define WM8400_GPIO5_PU_SHIFT                        5  /* GPIO5_PU */
+#define WM8400_GPIO5_PU_WIDTH                        1  /* GPIO5_PU */
+#define WM8400_GPIO5_PD                         0x0010  /* GPIO5_PD */
+#define WM8400_GPIO5_PD_MASK                    0x0010  /* GPIO5_PD */
+#define WM8400_GPIO5_PD_SHIFT                        4  /* GPIO5_PD */
+#define WM8400_GPIO5_PD_WIDTH                        1  /* GPIO5_PD */
+#define WM8400_GPIO5_SEL_MASK                   0x000F  /* GPIO5_SEL - [3:0] */
+#define WM8400_GPIO5_SEL_SHIFT                       0  /* GPIO5_SEL - [3:0] */
+#define WM8400_GPIO5_SEL_WIDTH                       4  /* GPIO5_SEL - [3:0] */
+
+/*
+ * R22 (0x16) - GPIOCTRL 2
+ */
+#define WM8400_TEMPOK_IRQ_ENA                   0x0800  /* TEMPOK_IRQ_ENA */
+#define WM8400_TEMPOK_IRQ_ENA_MASK              0x0800  /* TEMPOK_IRQ_ENA */
+#define WM8400_TEMPOK_IRQ_ENA_SHIFT                 11  /* TEMPOK_IRQ_ENA */
+#define WM8400_TEMPOK_IRQ_ENA_WIDTH                  1  /* TEMPOK_IRQ_ENA */
+#define WM8400_MIC1SHRT_IRQ_ENA                 0x0400  /* MIC1SHRT_IRQ_ENA */
+#define WM8400_MIC1SHRT_IRQ_ENA_MASK            0x0400  /* MIC1SHRT_IRQ_ENA */
+#define WM8400_MIC1SHRT_IRQ_ENA_SHIFT               10  /* MIC1SHRT_IRQ_ENA */
+#define WM8400_MIC1SHRT_IRQ_ENA_WIDTH                1  /* MIC1SHRT_IRQ_ENA */
+#define WM8400_MIC1DET_IRQ_ENA                  0x0200  /* MIC1DET_IRQ_ENA */
+#define WM8400_MIC1DET_IRQ_ENA_MASK             0x0200  /* MIC1DET_IRQ_ENA */
+#define WM8400_MIC1DET_IRQ_ENA_SHIFT                 9  /* MIC1DET_IRQ_ENA */
+#define WM8400_MIC1DET_IRQ_ENA_WIDTH                 1  /* MIC1DET_IRQ_ENA */
+#define WM8400_FLL_LCK_IRQ_ENA                  0x0100  /* FLL_LCK_IRQ_ENA */
+#define WM8400_FLL_LCK_IRQ_ENA_MASK             0x0100  /* FLL_LCK_IRQ_ENA */
+#define WM8400_FLL_LCK_IRQ_ENA_SHIFT                 8  /* FLL_LCK_IRQ_ENA */
+#define WM8400_FLL_LCK_IRQ_ENA_WIDTH                 1  /* FLL_LCK_IRQ_ENA */
+#define WM8400_GPI8_DEB_ENA                     0x0080  /* GPI8_DEB_ENA */
+#define WM8400_GPI8_DEB_ENA_MASK                0x0080  /* GPI8_DEB_ENA */
+#define WM8400_GPI8_DEB_ENA_SHIFT                    7  /* GPI8_DEB_ENA */
+#define WM8400_GPI8_DEB_ENA_WIDTH                    1  /* GPI8_DEB_ENA */
+#define WM8400_GPI8_IRQ_ENA                     0x0040  /* GPI8_IRQ_ENA */
+#define WM8400_GPI8_IRQ_ENA_MASK                0x0040  /* GPI8_IRQ_ENA */
+#define WM8400_GPI8_IRQ_ENA_SHIFT                    6  /* GPI8_IRQ_ENA */
+#define WM8400_GPI8_IRQ_ENA_WIDTH                    1  /* GPI8_IRQ_ENA */
+#define WM8400_GPI8_ENA                         0x0010  /* GPI8_ENA */
+#define WM8400_GPI8_ENA_MASK                    0x0010  /* GPI8_ENA */
+#define WM8400_GPI8_ENA_SHIFT                        4  /* GPI8_ENA */
+#define WM8400_GPI8_ENA_WIDTH                        1  /* GPI8_ENA */
+#define WM8400_GPI7_DEB_ENA                     0x0008  /* GPI7_DEB_ENA */
+#define WM8400_GPI7_DEB_ENA_MASK                0x0008  /* GPI7_DEB_ENA */
+#define WM8400_GPI7_DEB_ENA_SHIFT                    3  /* GPI7_DEB_ENA */
+#define WM8400_GPI7_DEB_ENA_WIDTH                    1  /* GPI7_DEB_ENA */
+#define WM8400_GPI7_IRQ_ENA                     0x0004  /* GPI7_IRQ_ENA */
+#define WM8400_GPI7_IRQ_ENA_MASK                0x0004  /* GPI7_IRQ_ENA */
+#define WM8400_GPI7_IRQ_ENA_SHIFT                    2  /* GPI7_IRQ_ENA */
+#define WM8400_GPI7_IRQ_ENA_WIDTH                    1  /* GPI7_IRQ_ENA */
+#define WM8400_GPI7_ENA                         0x0001  /* GPI7_ENA */
+#define WM8400_GPI7_ENA_MASK                    0x0001  /* GPI7_ENA */
+#define WM8400_GPI7_ENA_SHIFT                        0  /* GPI7_ENA */
+#define WM8400_GPI7_ENA_WIDTH                        1  /* GPI7_ENA */
+
+/*
+ * R23 (0x17) - GPIO_POL
+ */
+#define WM8400_IRQ_INV                          0x1000  /* IRQ_INV */
+#define WM8400_IRQ_INV_MASK                     0x1000  /* IRQ_INV */
+#define WM8400_IRQ_INV_SHIFT                        12  /* IRQ_INV */
+#define WM8400_IRQ_INV_WIDTH                         1  /* IRQ_INV */
+#define WM8400_TEMPOK_POL                       0x0800  /* TEMPOK_POL */
+#define WM8400_TEMPOK_POL_MASK                  0x0800  /* TEMPOK_POL */
+#define WM8400_TEMPOK_POL_SHIFT                     11  /* TEMPOK_POL */
+#define WM8400_TEMPOK_POL_WIDTH                      1  /* TEMPOK_POL */
+#define WM8400_MIC1SHRT_POL                     0x0400  /* MIC1SHRT_POL */
+#define WM8400_MIC1SHRT_POL_MASK                0x0400  /* MIC1SHRT_POL */
+#define WM8400_MIC1SHRT_POL_SHIFT                   10  /* MIC1SHRT_POL */
+#define WM8400_MIC1SHRT_POL_WIDTH                    1  /* MIC1SHRT_POL */
+#define WM8400_MIC1DET_POL                      0x0200  /* MIC1DET_POL */
+#define WM8400_MIC1DET_POL_MASK                 0x0200  /* MIC1DET_POL */
+#define WM8400_MIC1DET_POL_SHIFT                     9  /* MIC1DET_POL */
+#define WM8400_MIC1DET_POL_WIDTH                     1  /* MIC1DET_POL */
+#define WM8400_FLL_LCK_POL                      0x0100  /* FLL_LCK_POL */
+#define WM8400_FLL_LCK_POL_MASK                 0x0100  /* FLL_LCK_POL */
+#define WM8400_FLL_LCK_POL_SHIFT                     8  /* FLL_LCK_POL */
+#define WM8400_FLL_LCK_POL_WIDTH                     1  /* FLL_LCK_POL */
+#define WM8400_GPIO_POL_MASK                    0x00FF  /* GPIO_POL - [7:0] */
+#define WM8400_GPIO_POL_SHIFT                        0  /* GPIO_POL - [7:0] */
+#define WM8400_GPIO_POL_WIDTH                        8  /* GPIO_POL - [7:0] */
+
+/*
+ * R65 (0x41) - LDO 1 Control
+ */
+#define WM8400_LDO1_ENA                         0x8000  /* LDO1_ENA */
+#define WM8400_LDO1_ENA_MASK                    0x8000  /* LDO1_ENA */
+#define WM8400_LDO1_ENA_SHIFT                       15  /* LDO1_ENA */
+#define WM8400_LDO1_ENA_WIDTH                        1  /* LDO1_ENA */
+#define WM8400_LDO1_SWI                         0x4000  /* LDO1_SWI */
+#define WM8400_LDO1_SWI_MASK                    0x4000  /* LDO1_SWI */
+#define WM8400_LDO1_SWI_SHIFT                       14  /* LDO1_SWI */
+#define WM8400_LDO1_SWI_WIDTH                        1  /* LDO1_SWI */
+#define WM8400_LDO1_OPFLT                       0x1000  /* LDO1_OPFLT */
+#define WM8400_LDO1_OPFLT_MASK                  0x1000  /* LDO1_OPFLT */
+#define WM8400_LDO1_OPFLT_SHIFT                     12  /* LDO1_OPFLT */
+#define WM8400_LDO1_OPFLT_WIDTH                      1  /* LDO1_OPFLT */
+#define WM8400_LDO1_ERRACT                      0x0800  /* LDO1_ERRACT */
+#define WM8400_LDO1_ERRACT_MASK                 0x0800  /* LDO1_ERRACT */
+#define WM8400_LDO1_ERRACT_SHIFT                    11  /* LDO1_ERRACT */
+#define WM8400_LDO1_ERRACT_WIDTH                     1  /* LDO1_ERRACT */
+#define WM8400_LDO1_HIB_MODE                    0x0400  /* LDO1_HIB_MODE */
+#define WM8400_LDO1_HIB_MODE_MASK               0x0400  /* LDO1_HIB_MODE */
+#define WM8400_LDO1_HIB_MODE_SHIFT                  10  /* LDO1_HIB_MODE */
+#define WM8400_LDO1_HIB_MODE_WIDTH                   1  /* LDO1_HIB_MODE */
+#define WM8400_LDO1_VIMG_MASK                   0x03E0  /* LDO1_VIMG - [9:5] */
+#define WM8400_LDO1_VIMG_SHIFT                       5  /* LDO1_VIMG - [9:5] */
+#define WM8400_LDO1_VIMG_WIDTH                       5  /* LDO1_VIMG - [9:5] */
+#define WM8400_LDO1_VSEL_MASK                   0x001F  /* LDO1_VSEL - [4:0] */
+#define WM8400_LDO1_VSEL_SHIFT                       0  /* LDO1_VSEL - [4:0] */
+#define WM8400_LDO1_VSEL_WIDTH                       5  /* LDO1_VSEL - [4:0] */
+
+/*
+ * R66 (0x42) - LDO 2 Control
+ */
+#define WM8400_LDO2_ENA                         0x8000  /* LDO2_ENA */
+#define WM8400_LDO2_ENA_MASK                    0x8000  /* LDO2_ENA */
+#define WM8400_LDO2_ENA_SHIFT                       15  /* LDO2_ENA */
+#define WM8400_LDO2_ENA_WIDTH                        1  /* LDO2_ENA */
+#define WM8400_LDO2_SWI                         0x4000  /* LDO2_SWI */
+#define WM8400_LDO2_SWI_MASK                    0x4000  /* LDO2_SWI */
+#define WM8400_LDO2_SWI_SHIFT                       14  /* LDO2_SWI */
+#define WM8400_LDO2_SWI_WIDTH                        1  /* LDO2_SWI */
+#define WM8400_LDO2_OPFLT                       0x1000  /* LDO2_OPFLT */
+#define WM8400_LDO2_OPFLT_MASK                  0x1000  /* LDO2_OPFLT */
+#define WM8400_LDO2_OPFLT_SHIFT                     12  /* LDO2_OPFLT */
+#define WM8400_LDO2_OPFLT_WIDTH                      1  /* LDO2_OPFLT */
+#define WM8400_LDO2_ERRACT                      0x0800  /* LDO2_ERRACT */
+#define WM8400_LDO2_ERRACT_MASK                 0x0800  /* LDO2_ERRACT */
+#define WM8400_LDO2_ERRACT_SHIFT                    11  /* LDO2_ERRACT */
+#define WM8400_LDO2_ERRACT_WIDTH                     1  /* LDO2_ERRACT */
+#define WM8400_LDO2_HIB_MODE                    0x0400  /* LDO2_HIB_MODE */
+#define WM8400_LDO2_HIB_MODE_MASK               0x0400  /* LDO2_HIB_MODE */
+#define WM8400_LDO2_HIB_MODE_SHIFT                  10  /* LDO2_HIB_MODE */
+#define WM8400_LDO2_HIB_MODE_WIDTH                   1  /* LDO2_HIB_MODE */
+#define WM8400_LDO2_VIMG_MASK                   0x03E0  /* LDO2_VIMG - [9:5] */
+#define WM8400_LDO2_VIMG_SHIFT                       5  /* LDO2_VIMG - [9:5] */
+#define WM8400_LDO2_VIMG_WIDTH                       5  /* LDO2_VIMG - [9:5] */
+#define WM8400_LDO2_VSEL_MASK                   0x001F  /* LDO2_VSEL - [4:0] */
+#define WM8400_LDO2_VSEL_SHIFT                       0  /* LDO2_VSEL - [4:0] */
+#define WM8400_LDO2_VSEL_WIDTH                       5  /* LDO2_VSEL - [4:0] */
+
+/*
+ * R67 (0x43) - LDO 3 Control
+ */
+#define WM8400_LDO3_ENA                         0x8000  /* LDO3_ENA */
+#define WM8400_LDO3_ENA_MASK                    0x8000  /* LDO3_ENA */
+#define WM8400_LDO3_ENA_SHIFT                       15  /* LDO3_ENA */
+#define WM8400_LDO3_ENA_WIDTH                        1  /* LDO3_ENA */
+#define WM8400_LDO3_SWI                         0x4000  /* LDO3_SWI */
+#define WM8400_LDO3_SWI_MASK                    0x4000  /* LDO3_SWI */
+#define WM8400_LDO3_SWI_SHIFT                       14  /* LDO3_SWI */
+#define WM8400_LDO3_SWI_WIDTH                        1  /* LDO3_SWI */
+#define WM8400_LDO3_OPFLT                       0x1000  /* LDO3_OPFLT */
+#define WM8400_LDO3_OPFLT_MASK                  0x1000  /* LDO3_OPFLT */
+#define WM8400_LDO3_OPFLT_SHIFT                     12  /* LDO3_OPFLT */
+#define WM8400_LDO3_OPFLT_WIDTH                      1  /* LDO3_OPFLT */
+#define WM8400_LDO3_ERRACT                      0x0800  /* LDO3_ERRACT */
+#define WM8400_LDO3_ERRACT_MASK                 0x0800  /* LDO3_ERRACT */
+#define WM8400_LDO3_ERRACT_SHIFT                    11  /* LDO3_ERRACT */
+#define WM8400_LDO3_ERRACT_WIDTH                     1  /* LDO3_ERRACT */
+#define WM8400_LDO3_HIB_MODE                    0x0400  /* LDO3_HIB_MODE */
+#define WM8400_LDO3_HIB_MODE_MASK               0x0400  /* LDO3_HIB_MODE */
+#define WM8400_LDO3_HIB_MODE_SHIFT                  10  /* LDO3_HIB_MODE */
+#define WM8400_LDO3_HIB_MODE_WIDTH                   1  /* LDO3_HIB_MODE */
+#define WM8400_LDO3_VIMG_MASK                   0x03E0  /* LDO3_VIMG - [9:5] */
+#define WM8400_LDO3_VIMG_SHIFT                       5  /* LDO3_VIMG - [9:5] */
+#define WM8400_LDO3_VIMG_WIDTH                       5  /* LDO3_VIMG - [9:5] */
+#define WM8400_LDO3_VSEL_MASK                   0x001F  /* LDO3_VSEL - [4:0] */
+#define WM8400_LDO3_VSEL_SHIFT                       0  /* LDO3_VSEL - [4:0] */
+#define WM8400_LDO3_VSEL_WIDTH                       5  /* LDO3_VSEL - [4:0] */
+
+/*
+ * R68 (0x44) - LDO 4 Control
+ */
+#define WM8400_LDO4_ENA                         0x8000  /* LDO4_ENA */
+#define WM8400_LDO4_ENA_MASK                    0x8000  /* LDO4_ENA */
+#define WM8400_LDO4_ENA_SHIFT                       15  /* LDO4_ENA */
+#define WM8400_LDO4_ENA_WIDTH                        1  /* LDO4_ENA */
+#define WM8400_LDO4_SWI                         0x4000  /* LDO4_SWI */
+#define WM8400_LDO4_SWI_MASK                    0x4000  /* LDO4_SWI */
+#define WM8400_LDO4_SWI_SHIFT                       14  /* LDO4_SWI */
+#define WM8400_LDO4_SWI_WIDTH                        1  /* LDO4_SWI */
+#define WM8400_LDO4_OPFLT                       0x1000  /* LDO4_OPFLT */
+#define WM8400_LDO4_OPFLT_MASK                  0x1000  /* LDO4_OPFLT */
+#define WM8400_LDO4_OPFLT_SHIFT                     12  /* LDO4_OPFLT */
+#define WM8400_LDO4_OPFLT_WIDTH                      1  /* LDO4_OPFLT */
+#define WM8400_LDO4_ERRACT                      0x0800  /* LDO4_ERRACT */
+#define WM8400_LDO4_ERRACT_MASK                 0x0800  /* LDO4_ERRACT */
+#define WM8400_LDO4_ERRACT_SHIFT                    11  /* LDO4_ERRACT */
+#define WM8400_LDO4_ERRACT_WIDTH                     1  /* LDO4_ERRACT */
+#define WM8400_LDO4_HIB_MODE                    0x0400  /* LDO4_HIB_MODE */
+#define WM8400_LDO4_HIB_MODE_MASK               0x0400  /* LDO4_HIB_MODE */
+#define WM8400_LDO4_HIB_MODE_SHIFT                  10  /* LDO4_HIB_MODE */
+#define WM8400_LDO4_HIB_MODE_WIDTH                   1  /* LDO4_HIB_MODE */
+#define WM8400_LDO4_VIMG_MASK                   0x03E0  /* LDO4_VIMG - [9:5] */
+#define WM8400_LDO4_VIMG_SHIFT                       5  /* LDO4_VIMG - [9:5] */
+#define WM8400_LDO4_VIMG_WIDTH                       5  /* LDO4_VIMG - [9:5] */
+#define WM8400_LDO4_VSEL_MASK                   0x001F  /* LDO4_VSEL - [4:0] */
+#define WM8400_LDO4_VSEL_SHIFT                       0  /* LDO4_VSEL - [4:0] */
+#define WM8400_LDO4_VSEL_WIDTH                       5  /* LDO4_VSEL - [4:0] */
+
+/*
+ * R70 (0x46) - DCDC1 Control 1
+ */
+#define WM8400_DC1_ENA                          0x8000  /* DC1_ENA */
+#define WM8400_DC1_ENA_MASK                     0x8000  /* DC1_ENA */
+#define WM8400_DC1_ENA_SHIFT                        15  /* DC1_ENA */
+#define WM8400_DC1_ENA_WIDTH                         1  /* DC1_ENA */
+#define WM8400_DC1_ACTIVE                       0x4000  /* DC1_ACTIVE */
+#define WM8400_DC1_ACTIVE_MASK                  0x4000  /* DC1_ACTIVE */
+#define WM8400_DC1_ACTIVE_SHIFT                     14  /* DC1_ACTIVE */
+#define WM8400_DC1_ACTIVE_WIDTH                      1  /* DC1_ACTIVE */
+#define WM8400_DC1_SLEEP                        0x2000  /* DC1_SLEEP */
+#define WM8400_DC1_SLEEP_MASK                   0x2000  /* DC1_SLEEP */
+#define WM8400_DC1_SLEEP_SHIFT                      13  /* DC1_SLEEP */
+#define WM8400_DC1_SLEEP_WIDTH                       1  /* DC1_SLEEP */
+#define WM8400_DC1_OPFLT                        0x1000  /* DC1_OPFLT */
+#define WM8400_DC1_OPFLT_MASK                   0x1000  /* DC1_OPFLT */
+#define WM8400_DC1_OPFLT_SHIFT                      12  /* DC1_OPFLT */
+#define WM8400_DC1_OPFLT_WIDTH                       1  /* DC1_OPFLT */
+#define WM8400_DC1_ERRACT                       0x0800  /* DC1_ERRACT */
+#define WM8400_DC1_ERRACT_MASK                  0x0800  /* DC1_ERRACT */
+#define WM8400_DC1_ERRACT_SHIFT                     11  /* DC1_ERRACT */
+#define WM8400_DC1_ERRACT_WIDTH                      1  /* DC1_ERRACT */
+#define WM8400_DC1_HIB_MODE                     0x0400  /* DC1_HIB_MODE */
+#define WM8400_DC1_HIB_MODE_MASK                0x0400  /* DC1_HIB_MODE */
+#define WM8400_DC1_HIB_MODE_SHIFT                   10  /* DC1_HIB_MODE */
+#define WM8400_DC1_HIB_MODE_WIDTH                    1  /* DC1_HIB_MODE */
+#define WM8400_DC1_SOFTST_MASK                  0x0300  /* DC1_SOFTST - [9:8] */
+#define WM8400_DC1_SOFTST_SHIFT                      8  /* DC1_SOFTST - [9:8] */
+#define WM8400_DC1_SOFTST_WIDTH                      2  /* DC1_SOFTST - [9:8] */
+#define WM8400_DC1_OV_PROT                      0x0080  /* DC1_OV_PROT */
+#define WM8400_DC1_OV_PROT_MASK                 0x0080  /* DC1_OV_PROT */
+#define WM8400_DC1_OV_PROT_SHIFT                     7  /* DC1_OV_PROT */
+#define WM8400_DC1_OV_PROT_WIDTH                     1  /* DC1_OV_PROT */
+#define WM8400_DC1_VSEL_MASK                    0x007F  /* DC1_VSEL - [6:0] */
+#define WM8400_DC1_VSEL_SHIFT                        0  /* DC1_VSEL - [6:0] */
+#define WM8400_DC1_VSEL_WIDTH                        7  /* DC1_VSEL - [6:0] */
+
+/*
+ * R71 (0x47) - DCDC1 Control 2
+ */
+#define WM8400_DC1_FRC_PWM                      0x2000  /* DC1_FRC_PWM */
+#define WM8400_DC1_FRC_PWM_MASK                 0x2000  /* DC1_FRC_PWM */
+#define WM8400_DC1_FRC_PWM_SHIFT                    13  /* DC1_FRC_PWM */
+#define WM8400_DC1_FRC_PWM_WIDTH                     1  /* DC1_FRC_PWM */
+#define WM8400_DC1_STBY_LIM_MASK                0x0300  /* DC1_STBY_LIM - [9:8] */
+#define WM8400_DC1_STBY_LIM_SHIFT                    8  /* DC1_STBY_LIM - [9:8] */
+#define WM8400_DC1_STBY_LIM_WIDTH                    2  /* DC1_STBY_LIM - [9:8] */
+#define WM8400_DC1_ACT_LIM                      0x0080  /* DC1_ACT_LIM */
+#define WM8400_DC1_ACT_LIM_MASK                 0x0080  /* DC1_ACT_LIM */
+#define WM8400_DC1_ACT_LIM_SHIFT                     7  /* DC1_ACT_LIM */
+#define WM8400_DC1_ACT_LIM_WIDTH                     1  /* DC1_ACT_LIM */
+#define WM8400_DC1_VIMG_MASK                    0x007F  /* DC1_VIMG - [6:0] */
+#define WM8400_DC1_VIMG_SHIFT                        0  /* DC1_VIMG - [6:0] */
+#define WM8400_DC1_VIMG_WIDTH                        7  /* DC1_VIMG - [6:0] */
+
+/*
+ * R72 (0x48) - DCDC2 Control 1
+ */
+#define WM8400_DC2_ENA                          0x8000  /* DC2_ENA */
+#define WM8400_DC2_ENA_MASK                     0x8000  /* DC2_ENA */
+#define WM8400_DC2_ENA_SHIFT                        15  /* DC2_ENA */
+#define WM8400_DC2_ENA_WIDTH                         1  /* DC2_ENA */
+#define WM8400_DC2_ACTIVE                       0x4000  /* DC2_ACTIVE */
+#define WM8400_DC2_ACTIVE_MASK                  0x4000  /* DC2_ACTIVE */
+#define WM8400_DC2_ACTIVE_SHIFT                     14  /* DC2_ACTIVE */
+#define WM8400_DC2_ACTIVE_WIDTH                      1  /* DC2_ACTIVE */
+#define WM8400_DC2_SLEEP                        0x2000  /* DC2_SLEEP */
+#define WM8400_DC2_SLEEP_MASK                   0x2000  /* DC2_SLEEP */
+#define WM8400_DC2_SLEEP_SHIFT                      13  /* DC2_SLEEP */
+#define WM8400_DC2_SLEEP_WIDTH                       1  /* DC2_SLEEP */
+#define WM8400_DC2_OPFLT                        0x1000  /* DC2_OPFLT */
+#define WM8400_DC2_OPFLT_MASK                   0x1000  /* DC2_OPFLT */
+#define WM8400_DC2_OPFLT_SHIFT                      12  /* DC2_OPFLT */
+#define WM8400_DC2_OPFLT_WIDTH                       1  /* DC2_OPFLT */
+#define WM8400_DC2_ERRACT                       0x0800  /* DC2_ERRACT */
+#define WM8400_DC2_ERRACT_MASK                  0x0800  /* DC2_ERRACT */
+#define WM8400_DC2_ERRACT_SHIFT                     11  /* DC2_ERRACT */
+#define WM8400_DC2_ERRACT_WIDTH                      1  /* DC2_ERRACT */
+#define WM8400_DC2_HIB_MODE                     0x0400  /* DC2_HIB_MODE */
+#define WM8400_DC2_HIB_MODE_MASK                0x0400  /* DC2_HIB_MODE */
+#define WM8400_DC2_HIB_MODE_SHIFT                   10  /* DC2_HIB_MODE */
+#define WM8400_DC2_HIB_MODE_WIDTH                    1  /* DC2_HIB_MODE */
+#define WM8400_DC2_SOFTST_MASK                  0x0300  /* DC2_SOFTST - [9:8] */
+#define WM8400_DC2_SOFTST_SHIFT                      8  /* DC2_SOFTST - [9:8] */
+#define WM8400_DC2_SOFTST_WIDTH                      2  /* DC2_SOFTST - [9:8] */
+#define WM8400_DC2_OV_PROT                      0x0080  /* DC2_OV_PROT */
+#define WM8400_DC2_OV_PROT_MASK                 0x0080  /* DC2_OV_PROT */
+#define WM8400_DC2_OV_PROT_SHIFT                     7  /* DC2_OV_PROT */
+#define WM8400_DC2_OV_PROT_WIDTH                     1  /* DC2_OV_PROT */
+#define WM8400_DC2_VSEL_MASK                    0x007F  /* DC2_VSEL - [6:0] */
+#define WM8400_DC2_VSEL_SHIFT                        0  /* DC2_VSEL - [6:0] */
+#define WM8400_DC2_VSEL_WIDTH                        7  /* DC2_VSEL - [6:0] */
+
+/*
+ * R73 (0x49) - DCDC2 Control 2
+ */
+#define WM8400_DC2_FRC_PWM                      0x2000  /* DC2_FRC_PWM */
+#define WM8400_DC2_FRC_PWM_MASK                 0x2000  /* DC2_FRC_PWM */
+#define WM8400_DC2_FRC_PWM_SHIFT                    13  /* DC2_FRC_PWM */
+#define WM8400_DC2_FRC_PWM_WIDTH                     1  /* DC2_FRC_PWM */
+#define WM8400_DC2_STBY_LIM_MASK                0x0300  /* DC2_STBY_LIM - [9:8] */
+#define WM8400_DC2_STBY_LIM_SHIFT                    8  /* DC2_STBY_LIM - [9:8] */
+#define WM8400_DC2_STBY_LIM_WIDTH                    2  /* DC2_STBY_LIM - [9:8] */
+#define WM8400_DC2_ACT_LIM                      0x0080  /* DC2_ACT_LIM */
+#define WM8400_DC2_ACT_LIM_MASK                 0x0080  /* DC2_ACT_LIM */
+#define WM8400_DC2_ACT_LIM_SHIFT                     7  /* DC2_ACT_LIM */
+#define WM8400_DC2_ACT_LIM_WIDTH                     1  /* DC2_ACT_LIM */
+#define WM8400_DC2_VIMG_MASK                    0x007F  /* DC2_VIMG - [6:0] */
+#define WM8400_DC2_VIMG_SHIFT                        0  /* DC2_VIMG - [6:0] */
+#define WM8400_DC2_VIMG_WIDTH                        7  /* DC2_VIMG - [6:0] */
+
+/*
+ * R75 (0x4B) - Interface
+ */
+#define WM8400_AUTOINC                          0x0008  /* AUTOINC */
+#define WM8400_AUTOINC_MASK                     0x0008  /* AUTOINC */
+#define WM8400_AUTOINC_SHIFT                         3  /* AUTOINC */
+#define WM8400_AUTOINC_WIDTH                         1  /* AUTOINC */
+#define WM8400_ARA_ENA                          0x0004  /* ARA_ENA */
+#define WM8400_ARA_ENA_MASK                     0x0004  /* ARA_ENA */
+#define WM8400_ARA_ENA_SHIFT                         2  /* ARA_ENA */
+#define WM8400_ARA_ENA_WIDTH                         1  /* ARA_ENA */
+#define WM8400_SPI_CFG                          0x0002  /* SPI_CFG */
+#define WM8400_SPI_CFG_MASK                     0x0002  /* SPI_CFG */
+#define WM8400_SPI_CFG_SHIFT                         1  /* SPI_CFG */
+#define WM8400_SPI_CFG_WIDTH                         1  /* SPI_CFG */
+
+/*
+ * R76 (0x4C) - PM GENERAL
+ */
+#define WM8400_CODEC_SOFTST                     0x8000  /* CODEC_SOFTST */
+#define WM8400_CODEC_SOFTST_MASK                0x8000  /* CODEC_SOFTST */
+#define WM8400_CODEC_SOFTST_SHIFT                   15  /* CODEC_SOFTST */
+#define WM8400_CODEC_SOFTST_WIDTH                    1  /* CODEC_SOFTST */
+#define WM8400_CODEC_SOFTSD                     0x4000  /* CODEC_SOFTSD */
+#define WM8400_CODEC_SOFTSD_MASK                0x4000  /* CODEC_SOFTSD */
+#define WM8400_CODEC_SOFTSD_SHIFT                   14  /* CODEC_SOFTSD */
+#define WM8400_CODEC_SOFTSD_WIDTH                    1  /* CODEC_SOFTSD */
+#define WM8400_CHIP_SOFTSD                      0x2000  /* CHIP_SOFTSD */
+#define WM8400_CHIP_SOFTSD_MASK                 0x2000  /* CHIP_SOFTSD */
+#define WM8400_CHIP_SOFTSD_SHIFT                    13  /* CHIP_SOFTSD */
+#define WM8400_CHIP_SOFTSD_WIDTH                     1  /* CHIP_SOFTSD */
+#define WM8400_DSLEEP1_POL                      0x0008  /* DSLEEP1_POL */
+#define WM8400_DSLEEP1_POL_MASK                 0x0008  /* DSLEEP1_POL */
+#define WM8400_DSLEEP1_POL_SHIFT                     3  /* DSLEEP1_POL */
+#define WM8400_DSLEEP1_POL_WIDTH                     1  /* DSLEEP1_POL */
+#define WM8400_DSLEEP2_POL                      0x0004  /* DSLEEP2_POL */
+#define WM8400_DSLEEP2_POL_MASK                 0x0004  /* DSLEEP2_POL */
+#define WM8400_DSLEEP2_POL_SHIFT                     2  /* DSLEEP2_POL */
+#define WM8400_DSLEEP2_POL_WIDTH                     1  /* DSLEEP2_POL */
+#define WM8400_PWR_STATE_MASK                   0x0003  /* PWR_STATE - [1:0] */
+#define WM8400_PWR_STATE_SHIFT                       0  /* PWR_STATE - [1:0] */
+#define WM8400_PWR_STATE_WIDTH                       2  /* PWR_STATE - [1:0] */
+
+/*
+ * R78 (0x4E) - PM Shutdown Control
+ */
+#define WM8400_CHIP_GT150_ERRACT                0x0200  /* CHIP_GT150_ERRACT */
+#define WM8400_CHIP_GT150_ERRACT_MASK           0x0200  /* CHIP_GT150_ERRACT */
+#define WM8400_CHIP_GT150_ERRACT_SHIFT               9  /* CHIP_GT150_ERRACT */
+#define WM8400_CHIP_GT150_ERRACT_WIDTH               1  /* CHIP_GT150_ERRACT */
+#define WM8400_CHIP_GT115_ERRACT                0x0100  /* CHIP_GT115_ERRACT */
+#define WM8400_CHIP_GT115_ERRACT_MASK           0x0100  /* CHIP_GT115_ERRACT */
+#define WM8400_CHIP_GT115_ERRACT_SHIFT               8  /* CHIP_GT115_ERRACT */
+#define WM8400_CHIP_GT115_ERRACT_WIDTH               1  /* CHIP_GT115_ERRACT */
+#define WM8400_LINE_CMP_ERRACT                  0x0080  /* LINE_CMP_ERRACT */
+#define WM8400_LINE_CMP_ERRACT_MASK             0x0080  /* LINE_CMP_ERRACT */
+#define WM8400_LINE_CMP_ERRACT_SHIFT                 7  /* LINE_CMP_ERRACT */
+#define WM8400_LINE_CMP_ERRACT_WIDTH                 1  /* LINE_CMP_ERRACT */
+#define WM8400_UVLO_ERRACT                      0x0040  /* UVLO_ERRACT */
+#define WM8400_UVLO_ERRACT_MASK                 0x0040  /* UVLO_ERRACT */
+#define WM8400_UVLO_ERRACT_SHIFT                     6  /* UVLO_ERRACT */
+#define WM8400_UVLO_ERRACT_WIDTH                     1  /* UVLO_ERRACT */
+
+/*
+ * R79 (0x4F) - Interrupt Status 1
+ */
+#define WM8400_MICD_CINT                        0x8000  /* MICD_CINT */
+#define WM8400_MICD_CINT_MASK                   0x8000  /* MICD_CINT */
+#define WM8400_MICD_CINT_SHIFT                      15  /* MICD_CINT */
+#define WM8400_MICD_CINT_WIDTH                       1  /* MICD_CINT */
+#define WM8400_MICSCD_CINT                      0x4000  /* MICSCD_CINT */
+#define WM8400_MICSCD_CINT_MASK                 0x4000  /* MICSCD_CINT */
+#define WM8400_MICSCD_CINT_SHIFT                    14  /* MICSCD_CINT */
+#define WM8400_MICSCD_CINT_WIDTH                     1  /* MICSCD_CINT */
+#define WM8400_JDL_CINT                         0x2000  /* JDL_CINT */
+#define WM8400_JDL_CINT_MASK                    0x2000  /* JDL_CINT */
+#define WM8400_JDL_CINT_SHIFT                       13  /* JDL_CINT */
+#define WM8400_JDL_CINT_WIDTH                        1  /* JDL_CINT */
+#define WM8400_JDR_CINT                         0x1000  /* JDR_CINT */
+#define WM8400_JDR_CINT_MASK                    0x1000  /* JDR_CINT */
+#define WM8400_JDR_CINT_SHIFT                       12  /* JDR_CINT */
+#define WM8400_JDR_CINT_WIDTH                        1  /* JDR_CINT */
+#define WM8400_CODEC_SEQ_END_EINT               0x0800  /* CODEC_SEQ_END_EINT */
+#define WM8400_CODEC_SEQ_END_EINT_MASK          0x0800  /* CODEC_SEQ_END_EINT */
+#define WM8400_CODEC_SEQ_END_EINT_SHIFT             11  /* CODEC_SEQ_END_EINT */
+#define WM8400_CODEC_SEQ_END_EINT_WIDTH              1  /* CODEC_SEQ_END_EINT */
+#define WM8400_CDEL_TO_EINT                     0x0400  /* CDEL_TO_EINT */
+#define WM8400_CDEL_TO_EINT_MASK                0x0400  /* CDEL_TO_EINT */
+#define WM8400_CDEL_TO_EINT_SHIFT                   10  /* CDEL_TO_EINT */
+#define WM8400_CDEL_TO_EINT_WIDTH                    1  /* CDEL_TO_EINT */
+#define WM8400_CHIP_GT150_EINT                  0x0200  /* CHIP_GT150_EINT */
+#define WM8400_CHIP_GT150_EINT_MASK             0x0200  /* CHIP_GT150_EINT */
+#define WM8400_CHIP_GT150_EINT_SHIFT                 9  /* CHIP_GT150_EINT */
+#define WM8400_CHIP_GT150_EINT_WIDTH                 1  /* CHIP_GT150_EINT */
+#define WM8400_CHIP_GT115_EINT                  0x0100  /* CHIP_GT115_EINT */
+#define WM8400_CHIP_GT115_EINT_MASK             0x0100  /* CHIP_GT115_EINT */
+#define WM8400_CHIP_GT115_EINT_SHIFT                 8  /* CHIP_GT115_EINT */
+#define WM8400_CHIP_GT115_EINT_WIDTH                 1  /* CHIP_GT115_EINT */
+#define WM8400_LINE_CMP_EINT                    0x0080  /* LINE_CMP_EINT */
+#define WM8400_LINE_CMP_EINT_MASK               0x0080  /* LINE_CMP_EINT */
+#define WM8400_LINE_CMP_EINT_SHIFT                   7  /* LINE_CMP_EINT */
+#define WM8400_LINE_CMP_EINT_WIDTH                   1  /* LINE_CMP_EINT */
+#define WM8400_UVLO_EINT                        0x0040  /* UVLO_EINT */
+#define WM8400_UVLO_EINT_MASK                   0x0040  /* UVLO_EINT */
+#define WM8400_UVLO_EINT_SHIFT                       6  /* UVLO_EINT */
+#define WM8400_UVLO_EINT_WIDTH                       1  /* UVLO_EINT */
+#define WM8400_DC2_UV_EINT                      0x0020  /* DC2_UV_EINT */
+#define WM8400_DC2_UV_EINT_MASK                 0x0020  /* DC2_UV_EINT */
+#define WM8400_DC2_UV_EINT_SHIFT                     5  /* DC2_UV_EINT */
+#define WM8400_DC2_UV_EINT_WIDTH                     1  /* DC2_UV_EINT */
+#define WM8400_DC1_UV_EINT                      0x0010  /* DC1_UV_EINT */
+#define WM8400_DC1_UV_EINT_MASK                 0x0010  /* DC1_UV_EINT */
+#define WM8400_DC1_UV_EINT_SHIFT                     4  /* DC1_UV_EINT */
+#define WM8400_DC1_UV_EINT_WIDTH                     1  /* DC1_UV_EINT */
+#define WM8400_LDO4_UV_EINT                     0x0008  /* LDO4_UV_EINT */
+#define WM8400_LDO4_UV_EINT_MASK                0x0008  /* LDO4_UV_EINT */
+#define WM8400_LDO4_UV_EINT_SHIFT                    3  /* LDO4_UV_EINT */
+#define WM8400_LDO4_UV_EINT_WIDTH                    1  /* LDO4_UV_EINT */
+#define WM8400_LDO3_UV_EINT                     0x0004  /* LDO3_UV_EINT */
+#define WM8400_LDO3_UV_EINT_MASK                0x0004  /* LDO3_UV_EINT */
+#define WM8400_LDO3_UV_EINT_SHIFT                    2  /* LDO3_UV_EINT */
+#define WM8400_LDO3_UV_EINT_WIDTH                    1  /* LDO3_UV_EINT */
+#define WM8400_LDO2_UV_EINT                     0x0002  /* LDO2_UV_EINT */
+#define WM8400_LDO2_UV_EINT_MASK                0x0002  /* LDO2_UV_EINT */
+#define WM8400_LDO2_UV_EINT_SHIFT                    1  /* LDO2_UV_EINT */
+#define WM8400_LDO2_UV_EINT_WIDTH                    1  /* LDO2_UV_EINT */
+#define WM8400_LDO1_UV_EINT                     0x0001  /* LDO1_UV_EINT */
+#define WM8400_LDO1_UV_EINT_MASK                0x0001  /* LDO1_UV_EINT */
+#define WM8400_LDO1_UV_EINT_SHIFT                    0  /* LDO1_UV_EINT */
+#define WM8400_LDO1_UV_EINT_WIDTH                    1  /* LDO1_UV_EINT */
+
+/*
+ * R80 (0x50) - Interrupt Status 1 Mask
+ */
+#define WM8400_IM_MICD_CINT                     0x8000  /* IM_MICD_CINT */
+#define WM8400_IM_MICD_CINT_MASK                0x8000  /* IM_MICD_CINT */
+#define WM8400_IM_MICD_CINT_SHIFT                   15  /* IM_MICD_CINT */
+#define WM8400_IM_MICD_CINT_WIDTH                    1  /* IM_MICD_CINT */
+#define WM8400_IM_MICSCD_CINT                   0x4000  /* IM_MICSCD_CINT */
+#define WM8400_IM_MICSCD_CINT_MASK              0x4000  /* IM_MICSCD_CINT */
+#define WM8400_IM_MICSCD_CINT_SHIFT                 14  /* IM_MICSCD_CINT */
+#define WM8400_IM_MICSCD_CINT_WIDTH                  1  /* IM_MICSCD_CINT */
+#define WM8400_IM_JDL_CINT                      0x2000  /* IM_JDL_CINT */
+#define WM8400_IM_JDL_CINT_MASK                 0x2000  /* IM_JDL_CINT */
+#define WM8400_IM_JDL_CINT_SHIFT                    13  /* IM_JDL_CINT */
+#define WM8400_IM_JDL_CINT_WIDTH                     1  /* IM_JDL_CINT */
+#define WM8400_IM_JDR_CINT                      0x1000  /* IM_JDR_CINT */
+#define WM8400_IM_JDR_CINT_MASK                 0x1000  /* IM_JDR_CINT */
+#define WM8400_IM_JDR_CINT_SHIFT                    12  /* IM_JDR_CINT */
+#define WM8400_IM_JDR_CINT_WIDTH                     1  /* IM_JDR_CINT */
+#define WM8400_IM_CODEC_SEQ_END_EINT            0x0800  /* IM_CODEC_SEQ_END_EINT */
+#define WM8400_IM_CODEC_SEQ_END_EINT_MASK       0x0800  /* IM_CODEC_SEQ_END_EINT */
+#define WM8400_IM_CODEC_SEQ_END_EINT_SHIFT          11  /* IM_CODEC_SEQ_END_EINT */
+#define WM8400_IM_CODEC_SEQ_END_EINT_WIDTH           1  /* IM_CODEC_SEQ_END_EINT */
+#define WM8400_IM_CDEL_TO_EINT                  0x0400  /* IM_CDEL_TO_EINT */
+#define WM8400_IM_CDEL_TO_EINT_MASK             0x0400  /* IM_CDEL_TO_EINT */
+#define WM8400_IM_CDEL_TO_EINT_SHIFT                10  /* IM_CDEL_TO_EINT */
+#define WM8400_IM_CDEL_TO_EINT_WIDTH                 1  /* IM_CDEL_TO_EINT */
+#define WM8400_IM_CHIP_GT150_EINT               0x0200  /* IM_CHIP_GT150_EINT */
+#define WM8400_IM_CHIP_GT150_EINT_MASK          0x0200  /* IM_CHIP_GT150_EINT */
+#define WM8400_IM_CHIP_GT150_EINT_SHIFT              9  /* IM_CHIP_GT150_EINT */
+#define WM8400_IM_CHIP_GT150_EINT_WIDTH              1  /* IM_CHIP_GT150_EINT */
+#define WM8400_IM_CHIP_GT115_EINT               0x0100  /* IM_CHIP_GT115_EINT */
+#define WM8400_IM_CHIP_GT115_EINT_MASK          0x0100  /* IM_CHIP_GT115_EINT */
+#define WM8400_IM_CHIP_GT115_EINT_SHIFT              8  /* IM_CHIP_GT115_EINT */
+#define WM8400_IM_CHIP_GT115_EINT_WIDTH              1  /* IM_CHIP_GT115_EINT */
+#define WM8400_IM_LINE_CMP_EINT                 0x0080  /* IM_LINE_CMP_EINT */
+#define WM8400_IM_LINE_CMP_EINT_MASK            0x0080  /* IM_LINE_CMP_EINT */
+#define WM8400_IM_LINE_CMP_EINT_SHIFT                7  /* IM_LINE_CMP_EINT */
+#define WM8400_IM_LINE_CMP_EINT_WIDTH                1  /* IM_LINE_CMP_EINT */
+#define WM8400_IM_UVLO_EINT                     0x0040  /* IM_UVLO_EINT */
+#define WM8400_IM_UVLO_EINT_MASK                0x0040  /* IM_UVLO_EINT */
+#define WM8400_IM_UVLO_EINT_SHIFT                    6  /* IM_UVLO_EINT */
+#define WM8400_IM_UVLO_EINT_WIDTH                    1  /* IM_UVLO_EINT */
+#define WM8400_IM_DC2_UV_EINT                   0x0020  /* IM_DC2_UV_EINT */
+#define WM8400_IM_DC2_UV_EINT_MASK              0x0020  /* IM_DC2_UV_EINT */
+#define WM8400_IM_DC2_UV_EINT_SHIFT                  5  /* IM_DC2_UV_EINT */
+#define WM8400_IM_DC2_UV_EINT_WIDTH                  1  /* IM_DC2_UV_EINT */
+#define WM8400_IM_DC1_UV_EINT                   0x0010  /* IM_DC1_UV_EINT */
+#define WM8400_IM_DC1_UV_EINT_MASK              0x0010  /* IM_DC1_UV_EINT */
+#define WM8400_IM_DC1_UV_EINT_SHIFT                  4  /* IM_DC1_UV_EINT */
+#define WM8400_IM_DC1_UV_EINT_WIDTH                  1  /* IM_DC1_UV_EINT */
+#define WM8400_IM_LDO4_UV_EINT                  0x0008  /* IM_LDO4_UV_EINT */
+#define WM8400_IM_LDO4_UV_EINT_MASK             0x0008  /* IM_LDO4_UV_EINT */
+#define WM8400_IM_LDO4_UV_EINT_SHIFT                 3  /* IM_LDO4_UV_EINT */
+#define WM8400_IM_LDO4_UV_EINT_WIDTH                 1  /* IM_LDO4_UV_EINT */
+#define WM8400_IM_LDO3_UV_EINT                  0x0004  /* IM_LDO3_UV_EINT */
+#define WM8400_IM_LDO3_UV_EINT_MASK             0x0004  /* IM_LDO3_UV_EINT */
+#define WM8400_IM_LDO3_UV_EINT_SHIFT                 2  /* IM_LDO3_UV_EINT */
+#define WM8400_IM_LDO3_UV_EINT_WIDTH                 1  /* IM_LDO3_UV_EINT */
+#define WM8400_IM_LDO2_UV_EINT                  0x0002  /* IM_LDO2_UV_EINT */
+#define WM8400_IM_LDO2_UV_EINT_MASK             0x0002  /* IM_LDO2_UV_EINT */
+#define WM8400_IM_LDO2_UV_EINT_SHIFT                 1  /* IM_LDO2_UV_EINT */
+#define WM8400_IM_LDO2_UV_EINT_WIDTH                 1  /* IM_LDO2_UV_EINT */
+#define WM8400_IM_LDO1_UV_EINT                  0x0001  /* IM_LDO1_UV_EINT */
+#define WM8400_IM_LDO1_UV_EINT_MASK             0x0001  /* IM_LDO1_UV_EINT */
+#define WM8400_IM_LDO1_UV_EINT_SHIFT                 0  /* IM_LDO1_UV_EINT */
+#define WM8400_IM_LDO1_UV_EINT_WIDTH                 1  /* IM_LDO1_UV_EINT */
+
+/*
+ * R81 (0x51) - Interrupt Levels
+ */
+#define WM8400_MICD_LVL                         0x8000  /* MICD_LVL */
+#define WM8400_MICD_LVL_MASK                    0x8000  /* MICD_LVL */
+#define WM8400_MICD_LVL_SHIFT                       15  /* MICD_LVL */
+#define WM8400_MICD_LVL_WIDTH                        1  /* MICD_LVL */
+#define WM8400_MICSCD_LVL                       0x4000  /* MICSCD_LVL */
+#define WM8400_MICSCD_LVL_MASK                  0x4000  /* MICSCD_LVL */
+#define WM8400_MICSCD_LVL_SHIFT                     14  /* MICSCD_LVL */
+#define WM8400_MICSCD_LVL_WIDTH                      1  /* MICSCD_LVL */
+#define WM8400_JDL_LVL                          0x2000  /* JDL_LVL */
+#define WM8400_JDL_LVL_MASK                     0x2000  /* JDL_LVL */
+#define WM8400_JDL_LVL_SHIFT                        13  /* JDL_LVL */
+#define WM8400_JDL_LVL_WIDTH                         1  /* JDL_LVL */
+#define WM8400_JDR_LVL                          0x1000  /* JDR_LVL */
+#define WM8400_JDR_LVL_MASK                     0x1000  /* JDR_LVL */
+#define WM8400_JDR_LVL_SHIFT                        12  /* JDR_LVL */
+#define WM8400_JDR_LVL_WIDTH                         1  /* JDR_LVL */
+#define WM8400_CODEC_SEQ_END_LVL                0x0800  /* CODEC_SEQ_END_LVL */
+#define WM8400_CODEC_SEQ_END_LVL_MASK           0x0800  /* CODEC_SEQ_END_LVL */
+#define WM8400_CODEC_SEQ_END_LVL_SHIFT              11  /* CODEC_SEQ_END_LVL */
+#define WM8400_CODEC_SEQ_END_LVL_WIDTH               1  /* CODEC_SEQ_END_LVL */
+#define WM8400_CDEL_TO_LVL                      0x0400  /* CDEL_TO_LVL */
+#define WM8400_CDEL_TO_LVL_MASK                 0x0400  /* CDEL_TO_LVL */
+#define WM8400_CDEL_TO_LVL_SHIFT                    10  /* CDEL_TO_LVL */
+#define WM8400_CDEL_TO_LVL_WIDTH                     1  /* CDEL_TO_LVL */
+#define WM8400_CHIP_GT150_LVL                   0x0200  /* CHIP_GT150_LVL */
+#define WM8400_CHIP_GT150_LVL_MASK              0x0200  /* CHIP_GT150_LVL */
+#define WM8400_CHIP_GT150_LVL_SHIFT                  9  /* CHIP_GT150_LVL */
+#define WM8400_CHIP_GT150_LVL_WIDTH                  1  /* CHIP_GT150_LVL */
+#define WM8400_CHIP_GT115_LVL                   0x0100  /* CHIP_GT115_LVL */
+#define WM8400_CHIP_GT115_LVL_MASK              0x0100  /* CHIP_GT115_LVL */
+#define WM8400_CHIP_GT115_LVL_SHIFT                  8  /* CHIP_GT115_LVL */
+#define WM8400_CHIP_GT115_LVL_WIDTH                  1  /* CHIP_GT115_LVL */
+#define WM8400_LINE_CMP_LVL                     0x0080  /* LINE_CMP_LVL */
+#define WM8400_LINE_CMP_LVL_MASK                0x0080  /* LINE_CMP_LVL */
+#define WM8400_LINE_CMP_LVL_SHIFT                    7  /* LINE_CMP_LVL */
+#define WM8400_LINE_CMP_LVL_WIDTH                    1  /* LINE_CMP_LVL */
+#define WM8400_UVLO_LVL                         0x0040  /* UVLO_LVL */
+#define WM8400_UVLO_LVL_MASK                    0x0040  /* UVLO_LVL */
+#define WM8400_UVLO_LVL_SHIFT                        6  /* UVLO_LVL */
+#define WM8400_UVLO_LVL_WIDTH                        1  /* UVLO_LVL */
+#define WM8400_DC2_UV_LVL                       0x0020  /* DC2_UV_LVL */
+#define WM8400_DC2_UV_LVL_MASK                  0x0020  /* DC2_UV_LVL */
+#define WM8400_DC2_UV_LVL_SHIFT                      5  /* DC2_UV_LVL */
+#define WM8400_DC2_UV_LVL_WIDTH                      1  /* DC2_UV_LVL */
+#define WM8400_DC1_UV_LVL                       0x0010  /* DC1_UV_LVL */
+#define WM8400_DC1_UV_LVL_MASK                  0x0010  /* DC1_UV_LVL */
+#define WM8400_DC1_UV_LVL_SHIFT                      4  /* DC1_UV_LVL */
+#define WM8400_DC1_UV_LVL_WIDTH                      1  /* DC1_UV_LVL */
+#define WM8400_LDO4_UV_LVL                      0x0008  /* LDO4_UV_LVL */
+#define WM8400_LDO4_UV_LVL_MASK                 0x0008  /* LDO4_UV_LVL */
+#define WM8400_LDO4_UV_LVL_SHIFT                     3  /* LDO4_UV_LVL */
+#define WM8400_LDO4_UV_LVL_WIDTH                     1  /* LDO4_UV_LVL */
+#define WM8400_LDO3_UV_LVL                      0x0004  /* LDO3_UV_LVL */
+#define WM8400_LDO3_UV_LVL_MASK                 0x0004  /* LDO3_UV_LVL */
+#define WM8400_LDO3_UV_LVL_SHIFT                     2  /* LDO3_UV_LVL */
+#define WM8400_LDO3_UV_LVL_WIDTH                     1  /* LDO3_UV_LVL */
+#define WM8400_LDO2_UV_LVL                      0x0002  /* LDO2_UV_LVL */
+#define WM8400_LDO2_UV_LVL_MASK                 0x0002  /* LDO2_UV_LVL */
+#define WM8400_LDO2_UV_LVL_SHIFT                     1  /* LDO2_UV_LVL */
+#define WM8400_LDO2_UV_LVL_WIDTH                     1  /* LDO2_UV_LVL */
+#define WM8400_LDO1_UV_LVL                      0x0001  /* LDO1_UV_LVL */
+#define WM8400_LDO1_UV_LVL_MASK                 0x0001  /* LDO1_UV_LVL */
+#define WM8400_LDO1_UV_LVL_SHIFT                     0  /* LDO1_UV_LVL */
+#define WM8400_LDO1_UV_LVL_WIDTH                     1  /* LDO1_UV_LVL */
+
+/*
+ * R82 (0x52) - Shutdown Reason
+ */
+#define WM8400_SDR_CHIP_SOFTSD                  0x2000  /* SDR_CHIP_SOFTSD */
+#define WM8400_SDR_CHIP_SOFTSD_MASK             0x2000  /* SDR_CHIP_SOFTSD */
+#define WM8400_SDR_CHIP_SOFTSD_SHIFT                13  /* SDR_CHIP_SOFTSD */
+#define WM8400_SDR_CHIP_SOFTSD_WIDTH                 1  /* SDR_CHIP_SOFTSD */
+#define WM8400_SDR_NPDN                         0x0800  /* SDR_NPDN */
+#define WM8400_SDR_NPDN_MASK                    0x0800  /* SDR_NPDN */
+#define WM8400_SDR_NPDN_SHIFT                       11  /* SDR_NPDN */
+#define WM8400_SDR_NPDN_WIDTH                        1  /* SDR_NPDN */
+#define WM8400_SDR_CHIP_GT150                   0x0200  /* SDR_CHIP_GT150 */
+#define WM8400_SDR_CHIP_GT150_MASK              0x0200  /* SDR_CHIP_GT150 */
+#define WM8400_SDR_CHIP_GT150_SHIFT                  9  /* SDR_CHIP_GT150 */
+#define WM8400_SDR_CHIP_GT150_WIDTH                  1  /* SDR_CHIP_GT150 */
+#define WM8400_SDR_CHIP_GT115                   0x0100  /* SDR_CHIP_GT115 */
+#define WM8400_SDR_CHIP_GT115_MASK              0x0100  /* SDR_CHIP_GT115 */
+#define WM8400_SDR_CHIP_GT115_SHIFT                  8  /* SDR_CHIP_GT115 */
+#define WM8400_SDR_CHIP_GT115_WIDTH                  1  /* SDR_CHIP_GT115 */
+#define WM8400_SDR_LINE_CMP                     0x0080  /* SDR_LINE_CMP */
+#define WM8400_SDR_LINE_CMP_MASK                0x0080  /* SDR_LINE_CMP */
+#define WM8400_SDR_LINE_CMP_SHIFT                    7  /* SDR_LINE_CMP */
+#define WM8400_SDR_LINE_CMP_WIDTH                    1  /* SDR_LINE_CMP */
+#define WM8400_SDR_UVLO                         0x0040  /* SDR_UVLO */
+#define WM8400_SDR_UVLO_MASK                    0x0040  /* SDR_UVLO */
+#define WM8400_SDR_UVLO_SHIFT                        6  /* SDR_UVLO */
+#define WM8400_SDR_UVLO_WIDTH                        1  /* SDR_UVLO */
+#define WM8400_SDR_DC2_UV                       0x0020  /* SDR_DC2_UV */
+#define WM8400_SDR_DC2_UV_MASK                  0x0020  /* SDR_DC2_UV */
+#define WM8400_SDR_DC2_UV_SHIFT                      5  /* SDR_DC2_UV */
+#define WM8400_SDR_DC2_UV_WIDTH                      1  /* SDR_DC2_UV */
+#define WM8400_SDR_DC1_UV                       0x0010  /* SDR_DC1_UV */
+#define WM8400_SDR_DC1_UV_MASK                  0x0010  /* SDR_DC1_UV */
+#define WM8400_SDR_DC1_UV_SHIFT                      4  /* SDR_DC1_UV */
+#define WM8400_SDR_DC1_UV_WIDTH                      1  /* SDR_DC1_UV */
+#define WM8400_SDR_LDO4_UV                      0x0008  /* SDR_LDO4_UV */
+#define WM8400_SDR_LDO4_UV_MASK                 0x0008  /* SDR_LDO4_UV */
+#define WM8400_SDR_LDO4_UV_SHIFT                     3  /* SDR_LDO4_UV */
+#define WM8400_SDR_LDO4_UV_WIDTH                     1  /* SDR_LDO4_UV */
+#define WM8400_SDR_LDO3_UV                      0x0004  /* SDR_LDO3_UV */
+#define WM8400_SDR_LDO3_UV_MASK                 0x0004  /* SDR_LDO3_UV */
+#define WM8400_SDR_LDO3_UV_SHIFT                     2  /* SDR_LDO3_UV */
+#define WM8400_SDR_LDO3_UV_WIDTH                     1  /* SDR_LDO3_UV */
+#define WM8400_SDR_LDO2_UV                      0x0002  /* SDR_LDO2_UV */
+#define WM8400_SDR_LDO2_UV_MASK                 0x0002  /* SDR_LDO2_UV */
+#define WM8400_SDR_LDO2_UV_SHIFT                     1  /* SDR_LDO2_UV */
+#define WM8400_SDR_LDO2_UV_WIDTH                     1  /* SDR_LDO2_UV */
+#define WM8400_SDR_LDO1_UV                      0x0001  /* SDR_LDO1_UV */
+#define WM8400_SDR_LDO1_UV_MASK                 0x0001  /* SDR_LDO1_UV */
+#define WM8400_SDR_LDO1_UV_SHIFT                     0  /* SDR_LDO1_UV */
+#define WM8400_SDR_LDO1_UV_WIDTH                     1  /* SDR_LDO1_UV */
+
+/*
+ * R84 (0x54) - Line Circuits
+ */
+#define WM8400_BG_LINE_COMP                     0x8000  /* BG_LINE_COMP */
+#define WM8400_BG_LINE_COMP_MASK                0x8000  /* BG_LINE_COMP */
+#define WM8400_BG_LINE_COMP_SHIFT                   15  /* BG_LINE_COMP */
+#define WM8400_BG_LINE_COMP_WIDTH                    1  /* BG_LINE_COMP */
+#define WM8400_LINE_CMP_VTHI_MASK               0x00F0  /* LINE_CMP_VTHI - [7:4] */
+#define WM8400_LINE_CMP_VTHI_SHIFT                   4  /* LINE_CMP_VTHI - [7:4] */
+#define WM8400_LINE_CMP_VTHI_WIDTH                   4  /* LINE_CMP_VTHI - [7:4] */
+#define WM8400_LINE_CMP_VTHD_MASK               0x000F  /* LINE_CMP_VTHD - [3:0] */
+#define WM8400_LINE_CMP_VTHD_SHIFT                   0  /* LINE_CMP_VTHD - [3:0] */
+#define WM8400_LINE_CMP_VTHD_WIDTH                   4  /* LINE_CMP_VTHD - [3:0] */
+
+u16 wm8400_reg_read(struct wm8400 *wm8400, u8 reg);
+int wm8400_block_read(struct wm8400 *wm8400, u8 reg, int count, u16 *data);
+int wm8400_set_bits(struct wm8400 *wm8400, u8 reg, u16 mask, u16 val);
+
+#endif
diff --git a/include/linux/mfd/wm8400.h b/include/linux/mfd/wm8400.h
new file mode 100644 (file)
index 0000000..b46b566
--- /dev/null
@@ -0,0 +1,40 @@
+/*
+ * wm8400 client interface
+ *
+ * Copyright 2008 Wolfson Microelectronics plc
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef __LINUX_MFD_WM8400_H
+#define __LINUX_MFD_WM8400_H
+
+#include <linux/regulator/machine.h>
+
+#define WM8400_LDO1  0
+#define WM8400_LDO2  1
+#define WM8400_LDO3  2
+#define WM8400_LDO4  3
+#define WM8400_DCDC1 4
+#define WM8400_DCDC2 5
+
+struct wm8400_platform_data {
+       int (*platform_init)(struct device *dev);
+};
+
+int wm8400_register_regulator(struct device *dev, int reg,
+                             struct regulator_init_data *initdata);
+
+#endif
index d3ea3de70a8a54afde98014602504ebd48437624..64875859d6542ffc0a40b23f371a586074d5292e 100644 (file)
@@ -11,7 +11,7 @@
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Corey Minyard <wf-rch!minyard@relay.EU.net>
  *             Donald J. Becker, <becker@cesdis.gsfc.nasa.gov>
- *             Alan Cox, <Alan.Cox@linux.org>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Bjorn Ekwall. <bj0rn@blox.se>
  *              Pekka Riikonen <priikone@poseidon.pspt.fi>
  *
index 108f47e5fd9511796516d758dca90b1232321bea..21269405ffe27a503209dbb096293221dee65231 100644 (file)
@@ -38,6 +38,7 @@
 #define NFSD_MAY_LOCK          32
 #define NFSD_MAY_OWNER_OVERRIDE        64
 #define NFSD_MAY_LOCAL_ACCESS  128 /* IRIX doing local access check on device special file*/
+#define NFSD_MAY_BYPASS_GSS_ON_ROOT 256
 
 #define NFSD_MAY_CREATE                (NFSD_MAY_EXEC|NFSD_MAY_WRITE)
 #define NFSD_MAY_REMOVE                (NFSD_MAY_EXEC|NFSD_MAY_WRITE|NFSD_MAY_TRUNC)
@@ -125,7 +126,7 @@ int         nfsd_truncate(struct svc_rqst *, struct svc_fh *,
 __be32         nfsd_readdir(struct svc_rqst *, struct svc_fh *,
                             loff_t *, struct readdir_cd *, filldir_t);
 __be32         nfsd_statfs(struct svc_rqst *, struct svc_fh *,
-                               struct kstatfs *);
+                               struct kstatfs *, int access);
 
 int            nfsd_notify_change(struct inode *, struct iattr *);
 __be32         nfsd_permission(struct svc_rqst *, struct svc_export *,
index 1d712c7172a234094b95a24923e7706672ae591a..e37d80561985df64f9497e0aa26a4718e5c24ab5 100644 (file)
@@ -18,8 +18,8 @@
 #include <linux/device.h>
 #include <linux/regulator/consumer.h>
 
-struct regulator_constraints;
 struct regulator_dev;
+struct regulator_init_data;
 
 /**
  * struct regulator_ops - regulator operations.
@@ -51,7 +51,7 @@ struct regulator_ops {
                                          int output_uV, int load_uA);
 
        /* the operations below are for configuration of regulator state when
-        * it's parent PMIC enters a global STANBY/HIBERNATE state */
+        * its parent PMIC enters a global STANDBY/HIBERNATE state */
 
        /* set regulator suspend voltage */
        int (*set_suspend_voltage) (struct regulator_dev *, int uV);
@@ -85,15 +85,17 @@ struct regulator_desc {
        struct module *owner;
 };
 
-
 struct regulator_dev *regulator_register(struct regulator_desc *regulator_desc,
-                                         void *reg_data);
+       struct device *dev, void *driver_data);
 void regulator_unregister(struct regulator_dev *rdev);
 
 int regulator_notifier_call_chain(struct regulator_dev *rdev,
                                  unsigned long event, void *data);
 
 void *rdev_get_drvdata(struct regulator_dev *rdev);
+struct device *rdev_get_dev(struct regulator_dev *rdev);
 int rdev_get_id(struct regulator_dev *rdev);
 
+void *regulator_get_init_drvdata(struct regulator_init_data *reg_init_data);
+
 #endif
index 11e737dbfcf21d32fd29cd1c561e03be2c1c373f..c6d69331a81ef4c78fd6dd6797307d3388cb0a41 100644 (file)
@@ -89,15 +89,33 @@ struct regulation_constraints {
        unsigned apply_uV:1;    /* apply uV constraint iff min == max */
 };
 
-int regulator_set_supply(const char *regulator, const char *regulator_supply);
+/**
+ * struct regulator_consumer_supply - supply -> device mapping
+ *
+ * This maps a supply name to a device.
+ */
+struct regulator_consumer_supply {
+       struct device *dev;     /* consumer */
+       const char *supply;     /* consumer supply - e.g. "vcc" */
+};
 
-const char *regulator_get_supply(const char *regulator);
+/**
+ * struct regulator_init_data - regulator platform initialisation data.
+ *
+ * Initialisation constraints, our supply and consumers supplies.
+ */
+struct regulator_init_data {
+       struct device *supply_regulator_dev; /* or NULL for LINE */
 
-int regulator_set_machine_constraints(const char *regulator,
-       struct regulation_constraints *constraints);
+       struct regulation_constraints constraints;
 
-int regulator_set_device_supply(const char *regulator, struct device *dev,
-                               const char *supply);
+       int num_consumer_supplies;
+       struct regulator_consumer_supply *consumer_supplies;
+
+       /* optional regulator machine specific init */
+       int (*regulator_init)(void *driver_data);
+       void *driver_data;      /* core does not touch this */
+};
 
 int regulator_suspend_prepare(suspend_state_t state);
 
index e5bfe01ee305feb20e70845fb7e7f14e108bd345..6f0ee1b84a4f5f64903f4c74af1004381c3d9dd1 100644 (file)
@@ -104,6 +104,7 @@ struct rpc_create_args {
        const struct rpc_timeout *timeout;
        char                    *servername;
        struct rpc_program      *program;
+       u32                     prognumber;     /* overrides program->number */
        u32                     version;
        rpc_authflavor_t        authflavor;
        unsigned long           flags;
@@ -124,10 +125,10 @@ struct rpc_clnt *rpc_clone_client(struct rpc_clnt *);
 void           rpc_shutdown_client(struct rpc_clnt *);
 void           rpc_release_client(struct rpc_clnt *);
 
-int            rpcb_register(u32, u32, int, unsigned short, int *);
+int            rpcb_register(u32, u32, int, unsigned short);
 int            rpcb_v4_register(const u32 program, const u32 version,
                                 const struct sockaddr *address,
-                                const char *netid, int *result);
+                                const char *netid);
 int            rpcb_getport_sync(struct sockaddr_in *, u32, u32, int);
 void           rpcb_getport_async(struct rpc_task *);
 
index dc69068d94c7e070c9c9758c17efd8eb7d0ccb5f..3afe7fb403b2733877a199485e4c804a8fc116ef 100644 (file)
@@ -66,6 +66,7 @@ struct svc_serv {
        struct list_head        sv_tempsocks;   /* all temporary sockets */
        int                     sv_tmpcnt;      /* count of temporary sockets */
        struct timer_list       sv_temptimer;   /* timer for aging temporary sockets */
+       sa_family_t             sv_family;      /* listener's address family */
 
        char *                  sv_name;        /* service name */
 
@@ -265,17 +266,17 @@ struct svc_rqst {
 /*
  * Rigorous type checking on sockaddr type conversions
  */
-static inline struct sockaddr_in *svc_addr_in(struct svc_rqst *rqst)
+static inline struct sockaddr_in *svc_addr_in(const struct svc_rqst *rqst)
 {
        return (struct sockaddr_in *) &rqst->rq_addr;
 }
 
-static inline struct sockaddr_in6 *svc_addr_in6(struct svc_rqst *rqst)
+static inline struct sockaddr_in6 *svc_addr_in6(const struct svc_rqst *rqst)
 {
        return (struct sockaddr_in6 *) &rqst->rq_addr;
 }
 
-static inline struct sockaddr *svc_addr(struct svc_rqst *rqst)
+static inline struct sockaddr *svc_addr(const struct svc_rqst *rqst)
 {
        return (struct sockaddr *) &rqst->rq_addr;
 }
@@ -381,18 +382,20 @@ struct svc_procedure {
 /*
  * Function prototypes.
  */
-struct svc_serv *  svc_create(struct svc_program *, unsigned int,
-                             void (*shutdown)(struct svc_serv*));
+struct svc_serv *svc_create(struct svc_program *, unsigned int, sa_family_t,
+                           void (*shutdown)(struct svc_serv *));
 struct svc_rqst *svc_prepare_thread(struct svc_serv *serv,
                                        struct svc_pool *pool);
 void              svc_exit_thread(struct svc_rqst *);
 struct svc_serv *  svc_create_pooled(struct svc_program *, unsigned int,
-                       void (*shutdown)(struct svc_serv*), svc_thread_fn,
-                       struct module *);
+                       sa_family_t, void (*shutdown)(struct svc_serv *),
+                       svc_thread_fn, struct module *);
 int               svc_set_num_threads(struct svc_serv *, struct svc_pool *, int);
 void              svc_destroy(struct svc_serv *);
 int               svc_process(struct svc_rqst *);
-int               svc_register(struct svc_serv *, int, unsigned short);
+int               svc_register(const struct svc_serv *, const unsigned short,
+                               const unsigned short);
+
 void              svc_wake_up(struct svc_serv *);
 void              svc_reserve(struct svc_rqst *rqstp, int space);
 struct svc_pool *  svc_pool_for_cpu(struct svc_serv *serv, int cpu);
index dc05b54bd3a3c4f7d7b0e167e219844c0f163f73..c14fe86dac594f069a08342f1790c03909586c41 100644 (file)
@@ -72,6 +72,7 @@ extern atomic_t rdma_stat_sq_prod;
  */
 struct svc_rdma_op_ctxt {
        struct svc_rdma_op_ctxt *read_hdr;
+       struct svc_rdma_fastreg_mr *frmr;
        int hdr_count;
        struct xdr_buf arg;
        struct list_head dto_q;
@@ -103,16 +104,30 @@ struct svc_rdma_chunk_sge {
        int start;              /* sge no for this chunk */
        int count;              /* sge count for this chunk */
 };
+struct svc_rdma_fastreg_mr {
+       struct ib_mr *mr;
+       void *kva;
+       struct ib_fast_reg_page_list *page_list;
+       int page_list_len;
+       unsigned long access_flags;
+       unsigned long map_len;
+       enum dma_data_direction direction;
+       struct list_head frmr_list;
+};
 struct svc_rdma_req_map {
+       struct svc_rdma_fastreg_mr *frmr;
        unsigned long count;
        union {
                struct kvec sge[RPCSVC_MAXPAGES];
                struct svc_rdma_chunk_sge ch[RPCSVC_MAXPAGES];
        };
 };
-
+#define RDMACTXT_F_FAST_UNREG  1
 #define RDMACTXT_F_LAST_CTXT   2
 
+#define        SVCRDMA_DEVCAP_FAST_REG         1       /* fast mr registration */
+#define        SVCRDMA_DEVCAP_READ_W_INV       2       /* read w/ invalidate */
+
 struct svcxprt_rdma {
        struct svc_xprt      sc_xprt;           /* SVC transport structure */
        struct rdma_cm_id    *sc_cm_id;         /* RDMA connection id */
@@ -136,6 +151,11 @@ struct svcxprt_rdma {
        struct ib_cq         *sc_rq_cq;
        struct ib_cq         *sc_sq_cq;
        struct ib_mr         *sc_phys_mr;       /* MR for server memory */
+       u32                  sc_dev_caps;       /* distilled device caps */
+       u32                  sc_dma_lkey;       /* local dma key */
+       unsigned int         sc_frmr_pg_list_len;
+       struct list_head     sc_frmr_q;
+       spinlock_t           sc_frmr_q_lock;
 
        spinlock_t           sc_lock;           /* transport lock */
 
@@ -192,8 +212,13 @@ extern int svc_rdma_post_recv(struct svcxprt_rdma *);
 extern int svc_rdma_create_listen(struct svc_serv *, int, struct sockaddr *);
 extern struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *);
 extern void svc_rdma_put_context(struct svc_rdma_op_ctxt *, int);
+extern void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt);
 extern struct svc_rdma_req_map *svc_rdma_get_req_map(void);
 extern void svc_rdma_put_req_map(struct svc_rdma_req_map *);
+extern int svc_rdma_fastreg(struct svcxprt_rdma *, struct svc_rdma_fastreg_mr *);
+extern struct svc_rdma_fastreg_mr *svc_rdma_get_frmr(struct svcxprt_rdma *);
+extern void svc_rdma_put_frmr(struct svcxprt_rdma *,
+                             struct svc_rdma_fastreg_mr *);
 extern void svc_sq_reap(struct svcxprt_rdma *);
 extern void svc_rq_reap(struct svcxprt_rdma *);
 extern struct svc_xprt_class svc_rdma_class;
index 8cff696dedf58413dac70ab00294c19ba898bcba..483e10380aae45429b8ad7aba5a930aa8e4f3695 100644 (file)
@@ -39,10 +39,7 @@ int          svc_send(struct svc_rqst *);
 void           svc_drop(struct svc_rqst *);
 void           svc_sock_update_bufs(struct svc_serv *serv);
 int            svc_sock_names(char *buf, struct svc_serv *serv, char *toclose);
-int            svc_addsock(struct svc_serv *serv,
-                           int fd,
-                           char *name_return,
-                           int *proto);
+int            svc_addsock(struct svc_serv *serv, int fd, char *name_return);
 void           svc_init_xprt_sock(void);
 void           svc_cleanup_xprt_sock(void);
 
index 303d93ffd6b23c2ccdf42bb676799f8ee295ef23..d4b03034ee73af53507e2ec15bb68235139b029d 100644 (file)
@@ -910,6 +910,8 @@ enum v4l2_mpeg_audio_encoding {
        V4L2_MPEG_AUDIO_ENCODING_LAYER_1 = 0,
        V4L2_MPEG_AUDIO_ENCODING_LAYER_2 = 1,
        V4L2_MPEG_AUDIO_ENCODING_LAYER_3 = 2,
+       V4L2_MPEG_AUDIO_ENCODING_AAC     = 3,
+       V4L2_MPEG_AUDIO_ENCODING_AC3     = 4,
 };
 #define V4L2_CID_MPEG_AUDIO_L1_BITRATE                 (V4L2_CID_MPEG_BASE+102)
 enum v4l2_mpeg_audio_l1_bitrate {
@@ -988,12 +990,36 @@ enum v4l2_mpeg_audio_crc {
        V4L2_MPEG_AUDIO_CRC_CRC16 = 1,
 };
 #define V4L2_CID_MPEG_AUDIO_MUTE               (V4L2_CID_MPEG_BASE+109)
+#define V4L2_CID_MPEG_AUDIO_AAC_BITRATE                (V4L2_CID_MPEG_BASE+110)
+#define V4L2_CID_MPEG_AUDIO_AC3_BITRATE                (V4L2_CID_MPEG_BASE+111)
+enum v4l2_mpeg_audio_ac3_bitrate {
+       V4L2_MPEG_AUDIO_AC3_BITRATE_32K  = 0,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_40K  = 1,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_48K  = 2,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_56K  = 3,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_64K  = 4,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_80K  = 5,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_96K  = 6,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_112K = 7,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_128K = 8,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_160K = 9,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_192K = 10,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_224K = 11,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_256K = 12,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_320K = 13,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_384K = 14,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_448K = 15,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_512K = 16,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_576K = 17,
+       V4L2_MPEG_AUDIO_AC3_BITRATE_640K = 18,
+};
 
 /*  MPEG video */
 #define V4L2_CID_MPEG_VIDEO_ENCODING           (V4L2_CID_MPEG_BASE+200)
 enum v4l2_mpeg_video_encoding {
-       V4L2_MPEG_VIDEO_ENCODING_MPEG_1 = 0,
-       V4L2_MPEG_VIDEO_ENCODING_MPEG_2 = 1,
+       V4L2_MPEG_VIDEO_ENCODING_MPEG_1     = 0,
+       V4L2_MPEG_VIDEO_ENCODING_MPEG_2     = 1,
+       V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC = 2,
 };
 #define V4L2_CID_MPEG_VIDEO_ASPECT             (V4L2_CID_MPEG_BASE+201)
 enum v4l2_mpeg_video_aspect {
index b8e8aa91905a4450bf3ff9c431e2ba7168092f1a..38f2d93c3957014ed5431b61caae60bc3ab4c50d 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <linux/input.h>
 #include <linux/workqueue.h>
+#include <linux/interrupt.h>
 
 #define IR_TYPE_RC5     1
 #define IR_TYPE_PD      2 /* Pulse distance encoded IR */
@@ -85,6 +86,10 @@ struct card_ir {
        u32 code;                       /* raw code under construction */
        struct timeval base_time;       /* time of last seen code */
        int active;                     /* building raw code */
+
+       /* NEC decoding */
+       u32                     nec_gpio;
+       struct tasklet_struct   tlet;
 };
 
 void ir_input_init(struct input_dev *dev, struct ir_input_state *ir,
@@ -105,6 +110,7 @@ void ir_rc5_timer_keyup(unsigned long data);
 extern IR_KEYTAB_TYPE ir_codes_empty[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_avermedia[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_avermedia_dvbt[IR_KEYTAB_SIZE];
+extern IR_KEYTAB_TYPE ir_codes_avermedia_m135a[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_apac_viewcomp[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_pixelview[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_pixelview_new[IR_KEYTAB_SIZE];
@@ -139,6 +145,7 @@ extern IR_KEYTAB_TYPE ir_codes_proteus_2309[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_budget_ci_old[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_asus_pc39[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_encore_enltv[IR_KEYTAB_SIZE];
+extern IR_KEYTAB_TYPE ir_codes_encore_enltv2[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_tt_1500[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_fusionhdtv_mce[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_behold[IR_KEYTAB_SIZE];
@@ -147,7 +154,9 @@ extern IR_KEYTAB_TYPE ir_codes_pinnacle_pctv_hd[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_genius_tvgo_a11mce[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_powercolor_real_angel[IR_KEYTAB_SIZE];
 extern IR_KEYTAB_TYPE ir_codes_avermedia_a16d[IR_KEYTAB_SIZE];
-
+extern IR_KEYTAB_TYPE ir_codes_encore_enltv_fm53[IR_KEYTAB_SIZE];
+extern IR_KEYTAB_TYPE ir_codes_real_audio_220_32_keys[IR_KEYTAB_SIZE];
+extern IR_KEYTAB_TYPE ir_codes_msi_tvanywhere_plus[IR_KEYTAB_SIZE];
 #endif
 
 /*
index f677dfb9d373d7f87364ae8fd0b6d881c78bc8d3..bab2127195911254fb3ae6087d2106921afb5b90 100644 (file)
@@ -1,5 +1,5 @@
 /*
-    saa7115.h - definition for saa7113/4/5 inputs and frequency flags
+    saa7115.h - definition for saa7111/3/4/5 inputs and frequency flags
 
     Copyright (C) 2006 Hans Verkuil (hverkuil@xs4all.nl)
 
 #ifndef _SAA7115_H_
 #define _SAA7115_H_
 
-/* SAA7113/4/5 HW inputs */
+/* SAA7111/3/4/5 HW inputs */
 #define SAA7115_COMPOSITE0 0
 #define SAA7115_COMPOSITE1 1
 #define SAA7115_COMPOSITE2 2
 #define SAA7115_COMPOSITE3 3
-#define SAA7115_COMPOSITE4 4 /* not available for the saa7113 */
-#define SAA7115_COMPOSITE5 5 /* not available for the saa7113 */
+#define SAA7115_COMPOSITE4 4 /* not available for the saa7111/3 */
+#define SAA7115_COMPOSITE5 5 /* not available for the saa7111/3 */
 #define SAA7115_SVIDEO0    6
 #define SAA7115_SVIDEO1    7
 #define SAA7115_SVIDEO2    8
 #define SAA7115_FREQ_FL_CGCDIV (1 << 1)           /* SA 3A[6], CGCDIV, SAA7115 only */
 #define SAA7115_FREQ_FL_APLL   (1 << 2)           /* SA 3A[3], APLL, SAA7114/5 only */
 
-#define SAA7115_IPORT_ON    1
-#define SAA7115_IPORT_OFF   0
+#define SAA7115_IPORT_ON       1
+#define SAA7115_IPORT_OFF      0
+
+/* SAA7111 specific output flags */
+#define SAA7111_VBI_BYPASS     2
+#define SAA7111_FMT_YUV422      0x00
+#define SAA7111_FMT_RGB        0x40
+#define SAA7111_FMT_CCIR       0x80
+#define SAA7111_FMT_YUV411     0xc0
 
 #endif
 
index 2f68f4cd00377ac06b7543f084d93f99219b7f49..64a2ec746a3e151779ca9ee00aac3db6cd4ca7da 100644 (file)
@@ -30,7 +30,7 @@ extern unsigned int saa7146_debug;
        #define DEBUG_VARIABLE saa7146_debug
 #endif
 
-#define DEBUG_PROLOG printk("%s: %s(): ",KBUILD_MODNAME,__FUNCTION__)
+#define DEBUG_PROLOG printk("%s: %s(): ",KBUILD_MODNAME, __func__)
 #define INFO(x) { printk("%s: ",KBUILD_MODNAME); printk x; }
 
 #define ERR(x) { DEBUG_PROLOG; printk x; }
index 234a4711d2ec9026d010a434d7fab11c992a3127..b5dbefea3740c65b7ae87e8f7964e6c8764e3c83 100644 (file)
@@ -5,8 +5,6 @@
 
 struct sh_mobile_ceu_info {
        unsigned long flags; /* SOCAM_... */
-       void (*enable_camera)(void);
-       void (*disable_camera)(void);
 };
 
 #endif /* __ASM_SH_MOBILE_CEU_H__ */
index d548de326722a657ae8a257fe35e214f6585f432..c5de7bb19fda759febc5a35aca76cf738a7afcc8 100644 (file)
@@ -83,6 +83,9 @@ struct soc_camera_link {
        int bus_id;
        /* GPIO number to switch between 8 and 10 bit modes */
        unsigned int gpio;
+       /* Optional callbacks to power on or off and reset the sensor */
+       int (*power)(struct device *, int);
+       int (*reset)(struct device *);
 };
 
 static inline struct soc_camera_device *to_soc_camera_dev(struct device *dev)
index 77068fcc86bd9cb60a801732b24b67e28fc75103..67c1f514d0e297884a914b2c5c065f5996deea78 100644 (file)
 #define TUNER_TDA9887                   74      /* This tuner should be used only internally */
 #define TUNER_TEA5761                  75      /* Only FM Radio Tuner */
 #define TUNER_XC5000                   76      /* Xceive Silicon Tuner */
+#define TUNER_TCL_MF02GIP_5N           77      /* TCL MF02GIP_5N */
 
 /* tv card specific */
 #define TDA9887_PRESENT                (1<<0)
@@ -178,7 +179,7 @@ struct tuner_setup {
        unsigned int    type;   /* Tuner type */
        unsigned int    mode_mask;  /* Allowed tuner modes */
        unsigned int    config; /* configuraion for more complex tuners */
-       int (*tuner_callback) (void *dev, int command,int arg);
+       int (*tuner_callback) (void *dev, int component, int cmd, int arg);
 };
 
 #endif /* __KERNEL__ */
index 41b509babf3f4e895878118fd799b1b4d8e664cd..d73a8e9028a56f425e60eb1ecaddf642e5d34e66 100644 (file)
@@ -72,6 +72,10 @@ enum {
        /* module cs5345: just ident 5345 */
        V4L2_IDENT_CS5345 = 5345,
 
+       /* module saa6752hs: reserved range 6750-6759 */
+       V4L2_IDENT_SAA6752HS = 6752,
+       V4L2_IDENT_SAA6752HS_AC3 = 6753,
+
        /* module wm8739: just ident 8739 */
        V4L2_IDENT_WM8739 = 8739,
 
@@ -161,6 +165,7 @@ enum {
        /* Micron CMOS sensor chips: 45000-45099 */
        V4L2_IDENT_MT9M001C12ST         = 45000,
        V4L2_IDENT_MT9M001C12STM        = 45005,
+       V4L2_IDENT_MT9M111              = 45007,
        V4L2_IDENT_MT9V022IX7ATC        = 45010, /* No way to detect "normal" I77ATx */
        V4L2_IDENT_MT9V022IX7ATM        = 45015, /* and "lead free" IA7ATx chips */
 };
index 07d3a9a575d1422c1d1b1cb16b7cf58e137111f2..2f8719abf5cb84fa363ce22fcb33309cb69897ed 100644 (file)
@@ -76,11 +76,14 @@ int v4l2_prio_check(struct v4l2_prio_state *global, enum v4l2_priority *local);
 
 int v4l2_ctrl_check(struct v4l2_ext_control *ctrl, struct v4l2_queryctrl *qctrl,
                const char **menu_items);
+const char *v4l2_ctrl_get_name(u32 id);
 const char **v4l2_ctrl_get_menu(u32 id);
 int v4l2_ctrl_query_fill(struct v4l2_queryctrl *qctrl, s32 min, s32 max, s32 step, s32 def);
 int v4l2_ctrl_query_fill_std(struct v4l2_queryctrl *qctrl);
 int v4l2_ctrl_query_menu(struct v4l2_querymenu *qmenu,
                struct v4l2_queryctrl *qctrl, const char **menu_items);
+#define V4L2_CTRL_MENU_IDS_END (0xffffffff)
+int v4l2_ctrl_query_menu_valid_items(struct v4l2_querymenu *qmenu, const u32 *ids);
 u32 v4l2_ctrl_next(const u32 * const *ctrl_classes, u32 id);
 
 /* ------------------------------------------------------------------------- */
@@ -222,18 +225,22 @@ struct v4l2_crystal_freq {
    An extra flags field allows device specific configuration regarding
    clock frequency dividers, etc. If not used, then set flags to 0.
    If the frequency is not supported, then -EINVAL is returned. */
-#define VIDIOC_INT_S_CRYSTAL_FREQ      _IOW ('d', 113, struct v4l2_crystal_freq)
+#define VIDIOC_INT_S_CRYSTAL_FREQ      _IOW('d', 113, struct v4l2_crystal_freq)
 
 /* Initialize the sensor registors to some sort of reasonable
    default values. */
-#define VIDIOC_INT_INIT                        _IOW ('d', 114, u32)
+#define VIDIOC_INT_INIT                        _IOW('d', 114, u32)
 
 /* Set v4l2_std_id for video OUTPUT devices. This is ignored by
    video input devices. */
-#define VIDIOC_INT_S_STD_OUTPUT                _IOW  ('d', 115, v4l2_std_id)
+#define VIDIOC_INT_S_STD_OUTPUT                _IOW('d', 115, v4l2_std_id)
 
 /* Get v4l2_std_id for video OUTPUT devices. This is ignored by
    video input devices. */
-#define VIDIOC_INT_G_STD_OUTPUT                _IOW  ('d', 116, v4l2_std_id)
+#define VIDIOC_INT_G_STD_OUTPUT                _IOW('d', 116, v4l2_std_id)
+
+/* Set GPIO pins. Very simple right now, might need to be extended with
+   a v4l2_gpio struct if a direction is also needed. */
+#define VIDIOC_INT_S_GPIO              _IOW('d', 117, u32)
 
 #endif /* V4L2_COMMON_H_ */
index 2745e1afc72267f7be541e7c52ea05371d33d451..a0a6b41c5e0944e3e655e51151e5a60e3abf2db4 100644 (file)
@@ -9,30 +9,20 @@
 #ifndef _V4L2_DEV_H
 #define _V4L2_DEV_H
 
-#define OBSOLETE_DEVDATA 1 /* to be removed soon */
-
 #include <linux/poll.h>
 #include <linux/fs.h>
 #include <linux/device.h>
+#include <linux/cdev.h>
 #include <linux/mutex.h>
-#include <linux/compiler.h> /* need __user */
 #include <linux/videodev2.h>
 
 #define VIDEO_MAJOR    81
-/* Minor device allocation */
-#define MINOR_VFL_TYPE_GRABBER_MIN   0
-#define MINOR_VFL_TYPE_GRABBER_MAX  63
-#define MINOR_VFL_TYPE_RADIO_MIN    64
-#define MINOR_VFL_TYPE_RADIO_MAX   127
-#define MINOR_VFL_TYPE_VTX_MIN     192
-#define MINOR_VFL_TYPE_VTX_MAX     223
-#define MINOR_VFL_TYPE_VBI_MIN     224
-#define MINOR_VFL_TYPE_VBI_MAX     255
 
 #define VFL_TYPE_GRABBER       0
 #define VFL_TYPE_VBI           1
 #define VFL_TYPE_RADIO         2
 #define VFL_TYPE_VTX           3
+#define VFL_TYPE_MAX           4
 
 struct v4l2_ioctl_callbacks;
 
@@ -49,12 +39,15 @@ struct video_device
 
        /* sysfs */
        struct device dev;              /* v4l device */
+       struct cdev cdev;               /* character device */
+       void (*cdev_release)(struct kobject *kobj);
        struct device *parent;          /* device parent */
 
        /* device info */
        char name[32];
        int vfl_type;
        int minor;
+       u16 num;
        /* attribute to differentiate multiple indices on one physical device */
        int index;
 
@@ -69,50 +62,50 @@ struct video_device
 
        /* ioctl callbacks */
        const struct v4l2_ioctl_ops *ioctl_ops;
-
-#ifdef OBSOLETE_DEVDATA /* to be removed soon */
-       /* dev->driver_data will be used instead some day.
-        * Use the video_{get|set}_drvdata() helper functions,
-        * so the switch over will be transparent for you.
-        * Or use {pci|usb}_{get|set}_drvdata() directly. */
-       void *priv;
-#endif
-
-       /* for videodev.c internal usage -- please don't touch */
-       int users;                     /* video_exclusive_{open|close} ... */
-       struct mutex lock;             /* ... helper function uses these   */
 };
 
-/* Class-dev to video-device */
+/* dev to video-device */
 #define to_video_device(cd) container_of(cd, struct video_device, dev)
 
-/* Version 2 functions */
-extern int video_register_device(struct video_device *vfd, int type, int nr);
-int video_register_device_index(struct video_device *vfd, int type, int nr,
-                                       int index);
-void video_unregister_device(struct video_device *);
+/* Register and unregister devices. Note that if video_register_device fails,
+   the release() callback of the video_device structure is *not* called, so
+   the caller is responsible for freeing any data. Usually that means that
+   you call video_device_release() on failure. */
+int __must_check video_register_device(struct video_device *vfd, int type, int nr);
+int __must_check video_register_device_index(struct video_device *vfd,
+                                               int type, int nr, int index);
+void video_unregister_device(struct video_device *vfd);
 
-/* helper functions to alloc / release struct video_device, the
-   later can be used for video_device->release() */
-struct video_device *video_device_alloc(void);
+/* helper functions to alloc/release struct video_device, the
+   latter can also be used for video_device->release(). */
+struct video_device * __must_check video_device_alloc(void);
+
+/* this release function frees the vfd pointer */
 void video_device_release(struct video_device *vfd);
 
-#ifdef OBSOLETE_DEVDATA /* to be removed soon */
+/* this release function does nothing, use when the video_device is a
+   static global struct. Note that having a static video_device is
+   a dubious construction at best. */
+void video_device_release_empty(struct video_device *vfd);
+
 /* helper functions to access driver private data. */
 static inline void *video_get_drvdata(struct video_device *dev)
 {
-       return dev->priv;
+       return dev_get_drvdata(&dev->dev);
 }
 
 static inline void video_set_drvdata(struct video_device *dev, void *data)
 {
-       dev->priv = data;
+       dev_set_drvdata(&dev->dev, data);
 }
 
-/* Obsolete stuff - Still needed for radio devices and obsolete drivers */
-extern struct video_device* video_devdata(struct file*);
-extern int video_exclusive_open(struct inode *inode, struct file *file);
-extern int video_exclusive_release(struct inode *inode, struct file *file);
-#endif
+struct video_device *video_devdata(struct file *file);
+
+/* Combine video_get_drvdata and video_devdata as this is
+   used very often. */
+static inline void *video_drvdata(struct file *file)
+{
+       return video_get_drvdata(video_devdata(file));
+}
 
 #endif /* _V4L2_DEV_H */
index dc6404618555a7250b79810519ce34d4b6e92b69..0bef03add7968c1b26053be42b52ffbc5da132d3 100644 (file)
@@ -39,11 +39,6 @@ struct v4l2_ioctl_ops {
                                            struct v4l2_fmtdesc *f);
        int (*vidioc_enum_fmt_vid_out)     (struct file *file, void *fh,
                                            struct v4l2_fmtdesc *f);
-#if 1
-       /* deprecated, will be removed in 2.6.28 */
-       int (*vidioc_enum_fmt_vbi_cap)     (struct file *file, void *fh,
-                                           struct v4l2_fmtdesc *f);
-#endif
        int (*vidioc_enum_fmt_type_private)(struct file *file, void *fh,
                                            struct v4l2_fmtdesc *f);
 
index ad6e278ba7f2df6e11c347840a8175ea2dc25930..b417985708f238dc0dff70c7700da1408dbdd9d4 100644 (file)
 
 #define MANFID_TOSHIBA                 0x0098
 
-#define MANFID_UNGERMANN 0x02c0
+#define MANFID_UNGERMANN               0x02c0
 
 #define MANFID_XIRCOM                  0x0105
 
index e2e10c1e9a0615fc9844419ed9995f40f2d9f732..cfdd5af77dcc92d49eaada6ad6726c24e52cc81a 100644 (file)
@@ -573,44 +573,6 @@ typedef struct tuple_t {
 #define TUPLE_RETURN_LINK      0x01
 #define TUPLE_RETURN_COMMON    0x02
 
-/* For ValidateCIS */
-typedef struct cisinfo_t {
-    u_int      Chains;
-} cisinfo_t;
-
 #define CISTPL_MAX_CIS_SIZE    0x200
 
-/* For ReplaceCIS */
-typedef struct cisdump_t {
-    u_int      Length;
-    cisdata_t  Data[CISTPL_MAX_CIS_SIZE];
-} cisdump_t;
-
-
-int pcmcia_replace_cis(struct pcmcia_socket *s, cisdump_t *cis);
-
-/* don't use outside of PCMCIA core yet */
-int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int func, tuple_t *tuple);
-int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function, tuple_t *tuple);
-int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
-int pccard_parse_tuple(tuple_t *tuple, cisparse_t *parse);
-
-int pccard_validate_cis(struct pcmcia_socket *s, unsigned int function, unsigned int *count);
-
-/* ... but use these wrappers instead */
-#define pcmcia_get_first_tuple(p_dev, tuple) \
-               pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple)
-
-#define pcmcia_get_next_tuple(p_dev, tuple) \
-               pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple)
-
-#define pcmcia_get_tuple_data(p_dev, tuple) \
-               pccard_get_tuple_data(p_dev->socket, tuple)
-
-#define pcmcia_parse_tuple(p_dev, tuple, parse) \
-               pccard_parse_tuple(tuple, parse)
-
-#define pcmcia_validate_cis(p_dev, info) \
-               pccard_validate_cis(p_dev->socket, p_dev->func, info)
-
 #endif /* LINUX_CISTPL_H */
index 45d84b275789e3e138536bcac9ffff52e81a0df9..904468a191ef43c46c8a7fa091967a4f9f09e1c5 100644 (file)
@@ -28,72 +28,16 @@ typedef struct conf_reg_t {
 #define CS_WRITE       2
 
 /* for AdjustResourceInfo */
-typedef struct adjust_t {
-    u_int      Action;
-    u_int      Resource;
-    u_int      Attributes;
-    union {
-       struct memory {
-           u_long      Base;
-           u_long      Size;
-       } memory;
-       struct io {
-           ioaddr_t    BasePort;
-           ioaddr_t    NumPorts;
-           u_int       IOAddrLines;
-       } io;
-       struct irq {
-           u_int       IRQ;
-       } irq;
-    } resource;
-} adjust_t;
-
 /* Action field */
 #define REMOVE_MANAGED_RESOURCE                1
 #define ADD_MANAGED_RESOURCE           2
-#define GET_FIRST_MANAGED_RESOURCE     3
-#define GET_NEXT_MANAGED_RESOURCE      4
-/* Resource field */
-#define RES_MEMORY_RANGE               1
-#define RES_IO_RANGE                   2
-#define RES_IRQ                                3
-/* Attribute field */
-#define RES_IRQ_TYPE                   0x03
-#define RES_IRQ_TYPE_EXCLUSIVE         0
-#define RES_IRQ_TYPE_TIME              1
-#define RES_IRQ_TYPE_DYNAMIC           2
-#define RES_IRQ_CSC                    0x04
-#define RES_SHARED                     0x08
-#define RES_RESERVED                   0x10
-#define RES_ALLOCATED                  0x20
-#define RES_REMOVED                    0x40
+
 
 typedef struct event_callback_args_t {
        struct pcmcia_device    *client_handle;
        void                    *client_data;
 } event_callback_args_t;
 
-/* for GetConfigurationInfo */
-typedef struct config_info_t {
-    u_char     Function;
-    u_int      Attributes;
-    u_int      Vcc, Vpp1, Vpp2;
-    u_int      IntType;
-    u_int      ConfigBase;
-    u_char     Status, Pin, Copy, Option, ExtStatus;
-    u_int      Present;
-    u_int      CardValues;
-    u_int      AssignedIRQ;
-    u_int      IRQAttributes;
-    ioaddr_t   BasePort1;
-    ioaddr_t   NumPorts1;
-    u_int      Attributes1;
-    ioaddr_t   BasePort2;
-    ioaddr_t   NumPorts2;
-    u_int      Attributes2;
-    u_int      IOAddrLines;
-} config_info_t;
-
 /* For CardValues field */
 #define CV_OPTION_VALUE                0x01
 #define CV_STATUS_VALUE                0x02
@@ -257,22 +201,6 @@ typedef struct win_req_t {
 #define WIN_BAR_MASK           0xe000
 #define WIN_BAR_SHIFT          13
 
-/* Attributes for RegisterClient -- UNUSED -- */
-#define INFO_MASTER_CLIENT     0x01
-#define INFO_IO_CLIENT         0x02
-#define INFO_MTD_CLIENT                0x04
-#define INFO_MEM_CLIENT                0x08
-#define MAX_NUM_CLIENTS                3
-
-#define INFO_CARD_SHARE                0x10
-#define INFO_CARD_EXCL         0x20
-
-typedef struct cs_status_t {
-    u_char     Function;
-    event_t    CardState;
-    event_t    SocketState;
-} cs_status_t;
-
 typedef struct error_info_t {
     int                func;
     int                retcode;
@@ -308,95 +236,4 @@ typedef struct error_info_t {
 #define CS_EVENT_3VCARD                        0x200000
 #define CS_EVENT_XVCARD                        0x400000
 
-/* Return codes */
-#define CS_SUCCESS             0x00
-#define CS_BAD_ADAPTER         0x01
-#define CS_BAD_ATTRIBUTE       0x02
-#define CS_BAD_BASE            0x03
-#define CS_BAD_EDC             0x04
-#define CS_BAD_IRQ             0x06
-#define CS_BAD_OFFSET          0x07
-#define CS_BAD_PAGE            0x08
-#define CS_READ_FAILURE                0x09
-#define CS_BAD_SIZE            0x0a
-#define CS_BAD_SOCKET          0x0b
-#define CS_BAD_TYPE            0x0d
-#define CS_BAD_VCC             0x0e
-#define CS_BAD_VPP             0x0f
-#define CS_BAD_WINDOW          0x11
-#define CS_WRITE_FAILURE       0x12
-#define CS_NO_CARD             0x14
-#define CS_UNSUPPORTED_FUNCTION        0x15
-#define CS_UNSUPPORTED_MODE    0x16
-#define CS_BAD_SPEED           0x17
-#define CS_BUSY                        0x18
-#define CS_GENERAL_FAILURE     0x19
-#define CS_WRITE_PROTECTED     0x1a
-#define CS_BAD_ARG_LENGTH      0x1b
-#define CS_BAD_ARGS            0x1c
-#define CS_CONFIGURATION_LOCKED        0x1d
-#define CS_IN_USE              0x1e
-#define CS_NO_MORE_ITEMS       0x1f
-#define CS_OUT_OF_RESOURCE     0x20
-#define CS_BAD_HANDLE          0x21
-
-#define CS_BAD_TUPLE           0x40
-
-#ifdef __KERNEL__
-
-/*
- *  The main Card Services entry point
- */
-
-enum service {
-    AccessConfigurationRegister, AddSocketServices,
-    AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
-    DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
-    GetClientInfo, GetConfigurationInfo, GetEventMask,
-    GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
-    GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
-    GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
-    MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
-    OpenMemory, ParseTuple, ReadMemory, RegisterClient,
-    RegisterEraseQueue, RegisterMTD, RegisterTimer,
-    ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
-    ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
-    RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
-    RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
-    SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
-    WriteMemory, BindDevice, BindMTD, ReportError,
-    SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
-    GetFirstWindow, GetNextWindow, GetMemPage
-};
-
-struct pcmcia_socket;
-
-int pcmcia_access_configuration_register(struct pcmcia_device *p_dev, conf_reg_t *reg);
-int pcmcia_get_configuration_info(struct pcmcia_device *p_dev, config_info_t *config);
-int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
-int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
-int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
-int pcmcia_release_window(window_handle_t win);
-int pcmcia_request_configuration(struct pcmcia_device *p_dev, config_req_t *req);
-int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
-int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
-int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req, window_handle_t *wh);
-int pcmcia_suspend_card(struct pcmcia_socket *skt);
-int pcmcia_resume_card(struct pcmcia_socket *skt);
-int pcmcia_eject_card(struct pcmcia_socket *skt);
-int pcmcia_insert_card(struct pcmcia_socket *skt);
-int pccard_reset_card(struct pcmcia_socket *skt);
-
-struct pcmcia_device * pcmcia_dev_present(struct pcmcia_device *p_dev);
-void pcmcia_disable_device(struct pcmcia_device *p_dev);
-
-struct pcmcia_socket * pcmcia_get_socket(struct pcmcia_socket *skt);
-void pcmcia_put_socket(struct pcmcia_socket *skt);
-
-/* compatibility functions */
-#define pcmcia_reset_card(p_dev, req) \
-               pccard_reset_card(p_dev->socket)
-
-#endif /* __KERNEL__ */
-
 #endif /* _LINUX_CS_H */
index f402a0f435b451ce6843a4e9fa7faaf4620ede61..315965a37930099f6ffed2a672b303ba694b9bc6 100644 (file)
 #include <sys/types.h>
 #endif
 
-#if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
-       defined(__bfin__)
-/* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
-typedef u_int   ioaddr_t;
-#else
-typedef u_short        ioaddr_t;
-#endif
-
 typedef u_short        socket_t;
 typedef u_int  event_t;
 typedef u_char cisdata_t;
index e04e0b0d9a25a5b0c4903f3a51cab2af33de6d90..c33ea08352b8a5447ce37ed89f49cfb1d1efd265 100644 (file)
@@ -1,10 +1,19 @@
 /*
- * Copyright (2003-2004)       Dominik Brodowski <linux@brodo.de>
- *                             David Woodhouse
+ * device_id.h -- PCMCIA driver matching helpers
  *
- * License: GPL v2
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ * (C) 2003 - 2004     David Woodhouse
+ * (C) 2003 - 2004     Dominik Brodowski
  */
 
+#ifndef _LINUX_PCMCIA_DEVICE_ID_H
+#define _LINUX_PCMCIA_DEVICE_ID_H
+
+#ifdef __KERNEL__
+
 #define PCMCIA_DEVICE_MANF_CARD(manf, card) { \
        .match_flags = PCMCIA_DEV_ID_MATCH_MANF_ID| \
                        PCMCIA_DEV_ID_MATCH_CARD_ID, \
 
 
 #define PCMCIA_DEVICE_NULL { .match_flags = 0, }
+
+#endif /* __KERNEL__ */
+#endif /* _LINUX_PCMCIA_DEVICE_ID_H */
index b316027c853d7845dc374591b5a3f4c155f8f03d..a2be80b9a095fcd1bb955af8d2eacd75eafdddec 100644 (file)
@@ -10,7 +10,7 @@
  * are Copyright (C) 1999 David A. Hinds.  All Rights Reserved.
  *
  * (C) 1999            David A. Hinds
- * (C) 2003 - 2004     Dominik Brodowski
+ * (C) 2003 - 2008     Dominik Brodowski
  */
 
 #ifndef _LINUX_DS_H
 #include <pcmcia/cs_types.h>
 #include <pcmcia/device_id.h>
 
-typedef struct tuple_parse_t {
-    tuple_t            tuple;
-    cisdata_t          data[255];
-    cisparse_t         parse;
-} tuple_parse_t;
-
-typedef struct win_info_t {
-    window_handle_t    handle;
-    win_req_t          window;
-    memreq_t           map;
-} win_info_t;
-    
-typedef struct bind_info_t {
-    dev_info_t         dev_info;
-    u_char             function;
-    struct pcmcia_device *instance;
-    char               name[DEV_NAME_LEN];
-    u_short            major, minor;
-    void               *next;
-} bind_info_t;
-
-typedef struct mtd_info_t {
-    dev_info_t         dev_info;
-    u_int              Attributes;
-    u_int              CardOffset;
-} mtd_info_t;
-
-typedef struct region_info_t {
-    u_int              Attributes;
-    u_int              CardOffset;
-    u_int              RegionSize;
-    u_int              AccessSpeed;
-    u_int              BlockSize;
-    u_int              PartMultiple;
-    u_char             JedecMfr, JedecInfo;
-    memory_handle_t    next;
-} region_info_t;
-#define REGION_TYPE            0x0001
-#define REGION_TYPE_CM         0x0000
-#define REGION_TYPE_AM         0x0001
-#define REGION_PREFETCH                0x0008
-#define REGION_CACHEABLE       0x0010
-#define REGION_BAR_MASK                0xe000
-#define REGION_BAR_SHIFT       13
-
-typedef union ds_ioctl_arg_t {
-    adjust_t           adjust;
-    config_info_t      config;
-    tuple_t            tuple;
-    tuple_parse_t      tuple_parse;
-    client_req_t       client_req;
-    cs_status_t                status;
-    conf_reg_t         conf_reg;
-    cisinfo_t          cisinfo;
-    region_info_t      region;
-    bind_info_t                bind_info;
-    mtd_info_t         mtd_info;
-    win_info_t         win_info;
-    cisdump_t          cisdump;
-} ds_ioctl_arg_t;
-
-#define DS_ADJUST_RESOURCE_INFO                _IOWR('d', 2, adjust_t)
-#define DS_GET_CONFIGURATION_INFO      _IOWR('d', 3, config_info_t)
-#define DS_GET_FIRST_TUPLE             _IOWR('d', 4, tuple_t)
-#define DS_GET_NEXT_TUPLE              _IOWR('d', 5, tuple_t)
-#define DS_GET_TUPLE_DATA              _IOWR('d', 6, tuple_parse_t)
-#define DS_PARSE_TUPLE                 _IOWR('d', 7, tuple_parse_t)
-#define DS_RESET_CARD                  _IO  ('d', 8)
-#define DS_GET_STATUS                  _IOWR('d', 9, cs_status_t)
-#define DS_ACCESS_CONFIGURATION_REGISTER _IOWR('d', 10, conf_reg_t)
-#define DS_VALIDATE_CIS                        _IOR ('d', 11, cisinfo_t)
-#define DS_SUSPEND_CARD                        _IO  ('d', 12)
-#define DS_RESUME_CARD                 _IO  ('d', 13)
-#define DS_EJECT_CARD                  _IO  ('d', 14)
-#define DS_INSERT_CARD                 _IO  ('d', 15)
-#define DS_GET_FIRST_REGION            _IOWR('d', 16, region_info_t)
-#define DS_GET_NEXT_REGION             _IOWR('d', 17, region_info_t)
-#define DS_REPLACE_CIS                 _IOWR('d', 18, cisdump_t)
-#define DS_GET_FIRST_WINDOW            _IOR ('d', 19, win_info_t)
-#define DS_GET_NEXT_WINDOW             _IOWR('d', 20, win_info_t)
-#define DS_GET_MEM_PAGE                        _IOWR('d', 21, win_info_t)
-
-#define DS_BIND_REQUEST                        _IOWR('d', 60, bind_info_t)
-#define DS_GET_DEVICE_INFO             _IOWR('d', 61, bind_info_t) 
-#define DS_GET_NEXT_DEVICE             _IOWR('d', 62, bind_info_t) 
-#define DS_UNBIND_REQUEST              _IOW ('d', 63, bind_info_t)
-#define DS_BIND_MTD                    _IOWR('d', 64, mtd_info_t)
-
 #ifdef __KERNEL__
 #include <linux/device.h>
 #include <pcmcia/ss.h>
 
-typedef struct dev_node_t {
-    char               dev_name[DEV_NAME_LEN];
-    u_short            major, minor;
-    struct dev_node_t  *next;
-} dev_node_t;
-
-
+/*
+ * PCMCIA device drivers (16-bit cards only; 32-bit cards require CardBus
+ * a.k.a. PCI drivers
+ */
 struct pcmcia_socket;
+struct pcmcia_device;
 struct config_t;
 
+/* dynamic device IDs for PCMCIA device drivers. See
+ * Documentation/pcmcia/driver.txt for details.
+*/
 struct pcmcia_dynids {
        spinlock_t              lock;
        struct list_head        list;
@@ -147,6 +60,14 @@ struct pcmcia_driver {
 int pcmcia_register_driver(struct pcmcia_driver *driver);
 void pcmcia_unregister_driver(struct pcmcia_driver *driver);
 
+/* Some drivers use dev_node_t to store char or block device information.
+ * Don't use this in new drivers, though.
+ */
+typedef struct dev_node_t {
+       char                    dev_name[DEV_NAME_LEN];
+       u_short                 major, minor;
+       struct dev_node_t       *next;
+} dev_node_t;
 
 struct pcmcia_device {
        /* the socket and the device_no [for multifunction devices]
@@ -216,10 +137,304 @@ struct pcmcia_device {
 #define to_pcmcia_dev(n) container_of(n, struct pcmcia_device, dev)
 #define to_pcmcia_drv(n) container_of(n, struct pcmcia_driver, drv)
 
+/* deprecated -- don't use! */
 #define handle_to_dev(handle) (handle->dev)
 
-/* error reporting */
-void cs_error(struct pcmcia_device *handle, int func, int ret);
+
+/* (deprecated) error reporting by PCMCIA devices. Use dev_printk()
+ * or dev_dbg() directly in the driver, without referring to pcmcia_error_func()
+ * and/or pcmcia_error_ret() for those functions will go away soon.
+ */
+enum service {
+    AccessConfigurationRegister, AddSocketServices,
+    AdjustResourceInfo, CheckEraseQueue, CloseMemory, CopyMemory,
+    DeregisterClient, DeregisterEraseQueue, GetCardServicesInfo,
+    GetClientInfo, GetConfigurationInfo, GetEventMask,
+    GetFirstClient, GetFirstPartion, GetFirstRegion, GetFirstTuple,
+    GetNextClient, GetNextPartition, GetNextRegion, GetNextTuple,
+    GetStatus, GetTupleData, MapLogSocket, MapLogWindow, MapMemPage,
+    MapPhySocket, MapPhyWindow, ModifyConfiguration, ModifyWindow,
+    OpenMemory, ParseTuple, ReadMemory, RegisterClient,
+    RegisterEraseQueue, RegisterMTD, RegisterTimer,
+    ReleaseConfiguration, ReleaseExclusive, ReleaseIO, ReleaseIRQ,
+    ReleaseSocketMask, ReleaseWindow, ReplaceSocketServices,
+    RequestConfiguration, RequestExclusive, RequestIO, RequestIRQ,
+    RequestSocketMask, RequestWindow, ResetCard, ReturnSSEntry,
+    SetEventMask, SetRegion, ValidateCIS, VendorSpecific,
+    WriteMemory, BindDevice, BindMTD, ReportError,
+    SuspendCard, ResumeCard, EjectCard, InsertCard, ReplaceCIS,
+    GetFirstWindow, GetNextWindow, GetMemPage
+};
+const char *pcmcia_error_func(int func);
+const char *pcmcia_error_ret(int ret);
+
+#define cs_error(p_dev, func, ret)                     \
+       {                                               \
+               dev_printk(KERN_NOTICE, &p_dev->dev,    \
+                          "%s : %s\n",                 \
+                          pcmcia_error_func(func),     \
+                          pcmcia_error_ret(ret));      \
+       }
+
+/* CIS access.
+ * Use the pcmcia_* versions in PCMCIA drivers
+ */
+int pcmcia_parse_tuple(tuple_t *tuple, cisparse_t *parse);
+
+int pccard_get_first_tuple(struct pcmcia_socket *s, unsigned int function,
+                          tuple_t *tuple);
+#define pcmcia_get_first_tuple(p_dev, tuple) \
+               pccard_get_first_tuple(p_dev->socket, p_dev->func, tuple)
+
+int pccard_get_next_tuple(struct pcmcia_socket *s, unsigned int function,
+                         tuple_t *tuple);
+#define pcmcia_get_next_tuple(p_dev, tuple) \
+               pccard_get_next_tuple(p_dev->socket, p_dev->func, tuple)
+
+int pccard_get_tuple_data(struct pcmcia_socket *s, tuple_t *tuple);
+#define pcmcia_get_tuple_data(p_dev, tuple) \
+               pccard_get_tuple_data(p_dev->socket, tuple)
+
+
+/* loop CIS entries for valid configuration */
+int pcmcia_loop_config(struct pcmcia_device *p_dev,
+                      int      (*conf_check)   (struct pcmcia_device *p_dev,
+                                                cistpl_cftable_entry_t *cf,
+                                                cistpl_cftable_entry_t *dflt,
+                                                unsigned int vcc,
+                                                void *priv_data),
+                      void *priv_data);
+
+/* is the device still there? */
+struct pcmcia_device *pcmcia_dev_present(struct pcmcia_device *p_dev);
+
+/* low-level interface reset */
+int pcmcia_reset_card(struct pcmcia_socket *skt);
+
+/* CIS config */
+int pcmcia_access_configuration_register(struct pcmcia_device *p_dev,
+                                        conf_reg_t *reg);
+
+/* device configuration */
+int pcmcia_request_io(struct pcmcia_device *p_dev, io_req_t *req);
+int pcmcia_request_irq(struct pcmcia_device *p_dev, irq_req_t *req);
+int pcmcia_request_configuration(struct pcmcia_device *p_dev,
+                                config_req_t *req);
+
+int pcmcia_request_window(struct pcmcia_device **p_dev, win_req_t *req,
+                         window_handle_t *wh);
+int pcmcia_release_window(window_handle_t win);
+
+int pcmcia_get_mem_page(window_handle_t win, memreq_t *req);
+int pcmcia_map_mem_page(window_handle_t win, memreq_t *req);
+
+int pcmcia_modify_configuration(struct pcmcia_device *p_dev, modconf_t *mod);
+void pcmcia_disable_device(struct pcmcia_device *p_dev);
 
 #endif /* __KERNEL__ */
+
+
+
+/* Below, there are only definitions which are used by
+ * - the PCMCIA ioctl
+ * - deprecated PCMCIA userspace tools only
+ *
+ * here be dragons ... here be dragons ... here be dragons ... here be drag
+ */
+
+#if defined(CONFIG_PCMCIA_IOCTL) || !defined(__KERNEL__)
+
+#if defined(__arm__) || defined(__mips__) || defined(__avr32__) || \
+       defined(__bfin__)
+/* This (ioaddr_t) is exposed to userspace & hence cannot be changed. */
+typedef u_int   ioaddr_t;
+#else
+typedef u_short        ioaddr_t;
+#endif
+
+/* for AdjustResourceInfo */
+typedef struct adjust_t {
+       u_int                   Action;
+       u_int                   Resource;
+       u_int                   Attributes;
+       union {
+               struct memory {
+                       u_long          Base;
+                       u_long          Size;
+               } memory;
+               struct io {
+                       ioaddr_t        BasePort;
+                       ioaddr_t        NumPorts;
+                       u_int           IOAddrLines;
+               } io;
+               struct irq {
+                       u_int           IRQ;
+               } irq;
+       } resource;
+} adjust_t;
+
+/* Action field */
+#define REMOVE_MANAGED_RESOURCE                1
+#define ADD_MANAGED_RESOURCE           2
+#define GET_FIRST_MANAGED_RESOURCE     3
+#define GET_NEXT_MANAGED_RESOURCE      4
+/* Resource field */
+#define RES_MEMORY_RANGE               1
+#define RES_IO_RANGE                   2
+#define RES_IRQ                                3
+/* Attribute field */
+#define RES_IRQ_TYPE                   0x03
+#define RES_IRQ_TYPE_EXCLUSIVE         0
+#define RES_IRQ_TYPE_TIME              1
+#define RES_IRQ_TYPE_DYNAMIC           2
+#define RES_IRQ_CSC                    0x04
+#define RES_SHARED                     0x08
+#define RES_RESERVED                   0x10
+#define RES_ALLOCATED                  0x20
+#define RES_REMOVED                    0x40
+
+
+typedef struct tuple_parse_t {
+       tuple_t                 tuple;
+       cisdata_t               data[255];
+       cisparse_t              parse;
+} tuple_parse_t;
+
+typedef struct win_info_t {
+       window_handle_t         handle;
+       win_req_t               window;
+       memreq_t                map;
+} win_info_t;
+
+typedef struct bind_info_t {
+       dev_info_t              dev_info;
+       u_char                  function;
+       struct pcmcia_device    *instance;
+       char                    name[DEV_NAME_LEN];
+       u_short                 major, minor;
+       void                    *next;
+} bind_info_t;
+
+typedef struct mtd_info_t {
+       dev_info_t              dev_info;
+       u_int                   Attributes;
+       u_int                   CardOffset;
+} mtd_info_t;
+
+typedef struct region_info_t {
+       u_int                   Attributes;
+       u_int                   CardOffset;
+       u_int                   RegionSize;
+       u_int                   AccessSpeed;
+       u_int                   BlockSize;
+       u_int                   PartMultiple;
+       u_char                  JedecMfr, JedecInfo;
+       memory_handle_t         next;
+} region_info_t;
+
+#define REGION_TYPE            0x0001
+#define REGION_TYPE_CM         0x0000
+#define REGION_TYPE_AM         0x0001
+#define REGION_PREFETCH                0x0008
+#define REGION_CACHEABLE       0x0010
+#define REGION_BAR_MASK                0xe000
+#define REGION_BAR_SHIFT       13
+
+/* For ReplaceCIS */
+typedef struct cisdump_t {
+       u_int                   Length;
+       cisdata_t               Data[CISTPL_MAX_CIS_SIZE];
+} cisdump_t;
+
+/* for GetConfigurationInfo */
+typedef struct config_info_t {
+       u_char                  Function;
+       u_int                   Attributes;
+       u_int                   Vcc, Vpp1, Vpp2;
+       u_int                   IntType;
+       u_int                   ConfigBase;
+       u_char                  Status, Pin, Copy, Option, ExtStatus;
+       u_int                   Present;
+       u_int                   CardValues;
+       u_int                   AssignedIRQ;
+       u_int                   IRQAttributes;
+       ioaddr_t                BasePort1;
+       ioaddr_t                NumPorts1;
+       u_int                   Attributes1;
+       ioaddr_t                BasePort2;
+       ioaddr_t                NumPorts2;
+       u_int                   Attributes2;
+       u_int                   IOAddrLines;
+} config_info_t;
+
+/* For ValidateCIS */
+typedef struct cisinfo_t {
+       u_int                   Chains;
+} cisinfo_t;
+
+typedef struct cs_status_t {
+       u_char                  Function;
+       event_t                 CardState;
+       event_t                 SocketState;
+} cs_status_t;
+
+typedef union ds_ioctl_arg_t {
+       adjust_t                adjust;
+       config_info_t           config;
+       tuple_t                 tuple;
+       tuple_parse_t           tuple_parse;
+       client_req_t            client_req;
+       cs_status_t             status;
+       conf_reg_t              conf_reg;
+       cisinfo_t               cisinfo;
+       region_info_t           region;
+       bind_info_t             bind_info;
+       mtd_info_t              mtd_info;
+       win_info_t              win_info;
+       cisdump_t               cisdump;
+} ds_ioctl_arg_t;
+
+#define DS_ADJUST_RESOURCE_INFO                        _IOWR('d',  2, adjust_t)
+#define DS_GET_CONFIGURATION_INFO              _IOWR('d',  3, config_info_t)
+#define DS_GET_FIRST_TUPLE                     _IOWR('d',  4, tuple_t)
+#define DS_GET_NEXT_TUPLE                      _IOWR('d',  5, tuple_t)
+#define DS_GET_TUPLE_DATA                      _IOWR('d',  6, tuple_parse_t)
+#define DS_PARSE_TUPLE                         _IOWR('d',  7, tuple_parse_t)
+#define DS_RESET_CARD                          _IO  ('d',  8)
+#define DS_GET_STATUS                          _IOWR('d',  9, cs_status_t)
+#define DS_ACCESS_CONFIGURATION_REGISTER       _IOWR('d', 10, conf_reg_t)
+#define DS_VALIDATE_CIS                                _IOR ('d', 11, cisinfo_t)
+#define DS_SUSPEND_CARD                                _IO  ('d', 12)
+#define DS_RESUME_CARD                         _IO  ('d', 13)
+#define DS_EJECT_CARD                          _IO  ('d', 14)
+#define DS_INSERT_CARD                         _IO  ('d', 15)
+#define DS_GET_FIRST_REGION                    _IOWR('d', 16, region_info_t)
+#define DS_GET_NEXT_REGION                     _IOWR('d', 17, region_info_t)
+#define DS_REPLACE_CIS                         _IOWR('d', 18, cisdump_t)
+#define DS_GET_FIRST_WINDOW                    _IOR ('d', 19, win_info_t)
+#define DS_GET_NEXT_WINDOW                     _IOWR('d', 20, win_info_t)
+#define DS_GET_MEM_PAGE                                _IOWR('d', 21, win_info_t)
+
+#define DS_BIND_REQUEST                                _IOWR('d', 60, bind_info_t)
+#define DS_GET_DEVICE_INFO                     _IOWR('d', 61, bind_info_t)
+#define DS_GET_NEXT_DEVICE                     _IOWR('d', 62, bind_info_t)
+#define DS_UNBIND_REQUEST                      _IOW ('d', 63, bind_info_t)
+#define DS_BIND_MTD                            _IOWR('d', 64, mtd_info_t)
+
+
+/* used in userspace only */
+#define CS_IN_USE                      0x1e
+
+#define INFO_MASTER_CLIENT     0x01
+#define INFO_IO_CLIENT         0x02
+#define INFO_MTD_CLIENT                0x04
+#define INFO_MEM_CLIENT                0x08
+#define MAX_NUM_CLIENTS                3
+
+#define INFO_CARD_SHARE                0x10
+#define INFO_CARD_EXCL         0x20
+
+
+#endif /* !defined(__KERNEL__) || defined(CONFIG_PCMCIA_IOCTL) */
+
 #endif /* _LINUX_DS_H */
index ed919dd9bb5c29debac61ce496baa06ae6408c4f..9b4ac9385f5d094a07dcaae9daad1c04b6bfb2bd 100644 (file)
 
 /* for GetSocket, SetSocket */
 typedef struct socket_state_t {
-    u_int      flags;
-    u_int      csc_mask;
-    u_char     Vcc, Vpp;
-    u_char     io_irq;
+       u_int   flags;
+       u_int   csc_mask;
+       u_char  Vcc, Vpp;
+       u_char  io_irq;
 } socket_state_t;
 
 extern socket_state_t dead_socket;
@@ -86,79 +86,22 @@ extern socket_state_t dead_socket;
 #define HOOK_POWER_PRE 0x01
 #define HOOK_POWER_POST        0x02
 
-
 typedef struct pccard_io_map {
-    u_char     map;
-    u_char     flags;
-    u_short    speed;
-    u_int      start, stop;
+       u_char  map;
+       u_char  flags;
+       u_short speed;
+       u_int   start, stop;
 } pccard_io_map;
 
 typedef struct pccard_mem_map {
-    u_char     map;
-    u_char     flags;
-    u_short    speed;
-    u_long     static_start;
-    u_int      card_start;
-    struct resource *res;
+       u_char          map;
+       u_char          flags;
+       u_short         speed;
+       u_long          static_start;
+       u_int           card_start;
+       struct resource *res;
 } pccard_mem_map;
 
-typedef struct cb_bridge_map {
-    u_char     map;
-    u_char     flags;
-    u_int      start, stop;
-} cb_bridge_map;
-
-/*
- * Socket operations.
- */
-struct pcmcia_socket;
-
-struct pccard_operations {
-       int (*init)(struct pcmcia_socket *sock);
-       int (*suspend)(struct pcmcia_socket *sock);
-       int (*get_status)(struct pcmcia_socket *sock, u_int *value);
-       int (*set_socket)(struct pcmcia_socket *sock, socket_state_t *state);
-       int (*set_io_map)(struct pcmcia_socket *sock, struct pccard_io_map *io);
-       int (*set_mem_map)(struct pcmcia_socket *sock, struct pccard_mem_map *mem);
-};
-
-struct pccard_resource_ops {
-       int     (*validate_mem)         (struct pcmcia_socket *s);
-       int     (*adjust_io_region)     (struct resource *res,
-                                        unsigned long r_start,
-                                        unsigned long r_end,
-                                        struct pcmcia_socket *s);
-       struct resource* (*find_io)     (unsigned long base, int num,
-                                        unsigned long align,
-                                        struct pcmcia_socket *s);
-       struct resource* (*find_mem)    (unsigned long base, unsigned long num,
-                                        unsigned long align, int low,
-                                        struct pcmcia_socket *s);
-       int     (*add_io)               (struct pcmcia_socket *s,
-                                        unsigned int action,
-                                        unsigned long r_start,
-                                        unsigned long r_end);
-       int     (*add_mem)              (struct pcmcia_socket *s,
-                                        unsigned int action,
-                                        unsigned long r_start,
-                                        unsigned long r_end);
-       int     (*init)                 (struct pcmcia_socket *s);
-       void    (*exit)                 (struct pcmcia_socket *s);
-};
-/* SS_CAP_STATIC_MAP */
-extern struct pccard_resource_ops pccard_static_ops;
-/* !SS_CAP_STATIC_MAP */
-extern struct pccard_resource_ops pccard_nonstatic_ops;
-
-/* static mem, dynamic IO sockets */
-extern struct pccard_resource_ops pccard_iodyn_ops;
-
-/*
- *  Calls to set up low-level "Socket Services" drivers
- */
-struct pcmcia_socket;
-
 typedef struct io_window_t {
        u_int                   InUse, Config;
        struct resource         *res;
@@ -179,10 +122,25 @@ typedef struct window_t {
 /* Maximum number of memory windows per socket */
 #define MAX_WIN 4
 
+
+/*
+ * Socket operations.
+ */
+struct pcmcia_socket;
+struct pccard_resource_ops;
 struct config_t;
 struct pcmcia_callback;
 struct user_info_t;
 
+struct pccard_operations {
+       int (*init)(struct pcmcia_socket *s);
+       int (*suspend)(struct pcmcia_socket *s);
+       int (*get_status)(struct pcmcia_socket *s, u_int *value);
+       int (*set_socket)(struct pcmcia_socket *s, socket_state_t *state);
+       int (*set_io_map)(struct pcmcia_socket *s, struct pccard_io_map *io);
+       int (*set_mem_map)(struct pcmcia_socket *s, struct pccard_mem_map *mem);
+};
+
 struct pcmcia_socket {
        struct module                   *owner;
        spinlock_t                      lock;
@@ -199,8 +157,8 @@ struct pcmcia_socket {
        io_window_t                     io[MAX_IO_WIN];
        window_t                        win[MAX_WIN];
        struct list_head                cis_cache;
-       u_int                           fake_cis_len;
-       char                            *fake_cis;
+       size_t                          fake_cis_len;
+       u8                              *fake_cis;
 
        struct list_head                socket_list;
        struct completion               socket_released;
@@ -218,12 +176,12 @@ struct pcmcia_socket {
        struct pci_dev *                cb_dev;
 
 
-       /* socket setup is done so resources should be able to be allocated. Only
-        * if set to 1, calls to find_{io,mem}_region are handled, and insertion
-        * events are actually managed by the PCMCIA layer.*/
+       /* socket setup is done so resources should be able to be allocated.
+        * Only if set to 1, calls to find_{io,mem}_region are handled, and
+        * insertio events are actually managed by the PCMCIA layer.*/
        u8                              resource_setup_done:1;
 
-       /* is set to one if resource setup is done using adjust_resource_info() */
+       /* It's old if resource setup is done using adjust_resource_info() */
        u8                              resource_setup_old:1;
        u8                              resource_setup_new:1;
 
@@ -236,75 +194,101 @@ struct pcmcia_socket {
 
        /* Zoom video behaviour is so chip specific its not worth adding
           this to _ops */
-       void                            (*zoom_video)(struct pcmcia_socket *, int);
+       void                            (*zoom_video)(struct pcmcia_socket *,
+                                                     int);
 
        /* so is power hook */
        int (*power_hook)(struct pcmcia_socket *sock, int operation);
-#ifdef CONFIG_CARDBUS
+
        /* allows tuning the CB bridge before loading driver for the CB card */
+#ifdef CONFIG_CARDBUS
        void (*tune_bridge)(struct pcmcia_socket *sock, struct pci_bus *bus);
 #endif
 
        /* state thread */
-       struct mutex                    skt_mutex;      /* protects socket h/w state */
-
        struct task_struct              *thread;
        struct completion               thread_done;
-       spinlock_t                      thread_lock;    /* protects thread_events */
        unsigned int                    thread_events;
+       /* protects socket h/w state */
+       struct mutex                    skt_mutex;
+       /* protects thread_events */
+       spinlock_t                      thread_lock;
 
        /* pcmcia (16-bit) */
        struct pcmcia_callback          *callback;
 
 #if defined(CONFIG_PCMCIA) || defined(CONFIG_PCMCIA_MODULE)
-       struct list_head                devices_list;   /*  PCMCIA devices */
-       u8                              device_count;   /* the number of devices, used
-                                                        * only internally and subject
-                                                        * to incorrectness and change */
+       /* The following elements refer to 16-bit PCMCIA devices inserted
+        * into the socket */
+       struct list_head                devices_list;
+
+       /* the number of devices, used only internally and subject to
+        * incorrectness and change */
+       u8                              device_count;
 
+       /* 16-bit state: */
        struct {
-               u8                      present:1,      /* PCMCIA card is present in socket */
-                                       busy:1,         /* "master" ioctl is used */
-                                       dead:1,         /* pcmcia module is being unloaded */
-                                       device_add_pending:1, /* a multifunction-device
-                                                              * add event is pending */
-                                       mfc_pfc:1,      /* the pending event adds a mfc (1) or pfc (0) */
-                                       reserved:3;
-       }                               pcmcia_state;
-
-       struct work_struct              device_add;     /* for adding further pseudo-multifunction
-                                                        * devices */
+               /* PCMCIA card is present in socket */
+               u8                      present:1;
+               /* "master" ioctl is used */
+               u8                      busy:1;
+               /* pcmcia module is being unloaded */
+               u8                      dead:1;
+               /* a multifunction-device add event is pending */
+               u8                      device_add_pending:1;
+               /* the pending event adds a mfc (1) or pfc (0) */
+               u8                      mfc_pfc:1;
+
+               u8                      reserved:3;
+       } pcmcia_state;
+
+
+       /* for adding further pseudo-multifunction devices */
+       struct work_struct              device_add;
 
 #ifdef CONFIG_PCMCIA_IOCTL
        struct user_info_t              *user;
        wait_queue_head_t               queue;
-#endif
-#endif
+#endif /* CONFIG_PCMCIA_IOCTL */
+#endif /* CONFIG_PCMCIA */
 
        /* cardbus (32-bit) */
 #ifdef CONFIG_CARDBUS
        struct resource *               cb_cis_res;
        void __iomem                    *cb_cis_virt;
-#endif
+#endif /* CONFIG_CARDBUS */
 
        /* socket device */
        struct device                   dev;
-       void                            *driver_data;   /* data internal to the socket driver */
-
+       /* data internal to the socket driver */
+       void                            *driver_data;
 };
 
-struct pcmcia_socket * pcmcia_get_socket_by_nr(unsigned int nr);
 
+/* socket drivers must define the resource operations type they use. There
+ * are three options:
+ * - pccard_static_ops         iomem and ioport areas are assigned statically
+ * - pccard_iodyn_ops          iomem areas is assigned statically, ioport
+ *                             areas dynamically
+ * - pccard_nonstatic_ops      iomem and ioport areas are assigned dynamically.
+ *                             If this option is selected, use
+ *                             "select PCCARD_NONSTATIC" in Kconfig.
+ */
+extern struct pccard_resource_ops pccard_static_ops;
+extern struct pccard_resource_ops pccard_iodyn_ops;
+extern struct pccard_resource_ops pccard_nonstatic_ops;
 
+/* socket drivers are expected to use these callbacks in their .drv struct */
+extern int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state);
+extern int pcmcia_socket_dev_resume(struct device *dev);
+
+/* socket drivers use this callback in their IRQ handler */
+extern void pcmcia_parse_events(struct pcmcia_socket *socket,
+                               unsigned int events);
 
-extern void pcmcia_parse_events(struct pcmcia_socket *socket, unsigned int events);
+/* to register and unregister a socket */
 extern int pcmcia_register_socket(struct pcmcia_socket *socket);
 extern void pcmcia_unregister_socket(struct pcmcia_socket *socket);
 
-extern struct class pcmcia_socket_class;
-
-/* socket drivers are expected to use these callbacks in their .drv struct */
-extern int pcmcia_socket_dev_suspend(struct device *dev, pm_message_t state);
-extern int pcmcia_socket_dev_resume(struct device *dev);
 
 #endif /* _LINUX_SS_H */
index b62ce3e077f9176274b80156afdafcd027edfe0c..b6870cbaf2b38812e6bc77c24ce7a7e416eadd3f 100644 (file)
@@ -43,6 +43,7 @@ struct snd_tea575x {
        unsigned int freq_fixup;        /* crystal onboard */
        unsigned int val;               /* hw value */
        unsigned long freq;             /* frequency */
+       unsigned long in_use;           /* set if the device is in use */
        struct snd_tea575x_ops *ops;
        void *private_data;
 };
index 693d24694a6c9f1839a4f7f2f7828f4671d16459..48b3fadd83ed90f846555079d02e87e9d708af0c 100644 (file)
  * The code for that is here.
  */
 
-static int __initdata raid_noautodetect, raid_autopart;
+#ifdef CONFIG_MD_AUTODETECT
+static int __initdata raid_noautodetect;
+#else
+static int __initdata raid_noautodetect=1;
+#endif
+static int __initdata raid_autopart;
 
 static struct {
        int minor;
@@ -252,6 +257,8 @@ static int __init raid_setup(char *str)
 
                if (!strncmp(str, "noautodetect", wlen))
                        raid_noautodetect = 1;
+               if (!strncmp(str, "autodetect", wlen))
+                       raid_noautodetect = 0;
                if (strncmp(str, "partitionable", wlen)==0)
                        raid_autopart = 1;
                if (strncmp(str, "part", wlen)==0)
@@ -264,17 +271,32 @@ static int __init raid_setup(char *str)
 __setup("raid=", raid_setup);
 __setup("md=", md_setup);
 
+static void autodetect_raid(void)
+{
+       int fd;
+
+       /*
+        * Since we don't want to detect and use half a raid array, we need to
+        * wait for the known devices to complete their probing
+        */
+       printk(KERN_INFO "md: Waiting for all devices to be available before autodetect\n");
+       printk(KERN_INFO "md: If you don't use raid, use raid=noautodetect\n");
+       while (driver_probe_done() < 0)
+               msleep(100);
+       fd = sys_open("/dev/md0", 0, 0);
+       if (fd >= 0) {
+               sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
+               sys_close(fd);
+       }
+}
+
 void __init md_run_setup(void)
 {
        create_dev("/dev/md0", MKDEV(MD_MAJOR, 0));
+
        if (raid_noautodetect)
-               printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=noautodetect)\n");
-       else {
-               int fd = sys_open("/dev/md0", 0, 0);
-               if (fd >= 0) {
-                       sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
-                       sys_close(fd);
-               }
-       }
+               printk(KERN_INFO "md: Skipping autodetection of RAID arrays. (raid=autodetect will force)\n");
+       else
+               autodetect_raid();
        md_setup_drive();
 }
index 3820323c4c8467c07831a8844532fb85976e9a9f..27f6bf6108e96908b10df5b20e0011aaebb3266c 100644 (file)
@@ -708,7 +708,7 @@ int do_one_initcall(initcall_t fn)
        int result;
 
        if (initcall_debug) {
-               printk("calling  %pF\n", fn);
+               printk("calling  %pF @ %i\n", fn, task_pid_nr(current));
                t0 = ktime_get();
        }
 
index 08d6e1bb99ac351f28bfe768acf49c17e04b0593..503d8d4eb80acb5bc272e6dcb2be7d403955dab3 100644 (file)
@@ -125,6 +125,7 @@ cond_syscall(sys_vm86old);
 cond_syscall(sys_vm86);
 cond_syscall(compat_sys_ipc);
 cond_syscall(compat_sys_sysctl);
+cond_syscall(sys_flock);
 
 /* arch-specific weak syscall entries */
 cond_syscall(sys_pciconfig_read);
index c468c3c6dfc525e0c413eae9f90a8b77d77887f0..cfc5295f1e82bc10b86b6ec6fc861b9fe4bd5ec1 100644 (file)
@@ -96,7 +96,7 @@ static int sixty = 60;
 static int neg_one = -1;
 #endif
 
-#ifdef CONFIG_MMU
+#if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
 static int two = 2;
 #endif
 
@@ -1248,6 +1248,7 @@ static struct ctl_table fs_table[] = {
                .extra1         = &minolduid,
                .extra2         = &maxolduid,
        },
+#ifdef CONFIG_FILE_LOCKING
        {
                .ctl_name       = FS_LEASES,
                .procname       = "leases-enable",
@@ -1256,6 +1257,7 @@ static struct ctl_table fs_table[] = {
                .mode           = 0644,
                .proc_handler   = &proc_dointvec,
        },
+#endif
 #ifdef CONFIG_DNOTIFY
        {
                .ctl_name       = FS_DIR_NOTIFY,
@@ -1267,6 +1269,7 @@ static struct ctl_table fs_table[] = {
        },
 #endif
 #ifdef CONFIG_MMU
+#ifdef CONFIG_FILE_LOCKING
        {
                .ctl_name       = FS_LEASE_TIME,
                .procname       = "lease-break-time",
@@ -1278,6 +1281,7 @@ static struct ctl_table fs_table[] = {
                .extra1         = &zero,
                .extra2         = &two,
        },
+#endif
        {
                .procname       = "aio-nr",
                .data           = &aio_nr,
index b3cfe5a14fcaee0cfb56401286574d1a2e94a74b..70980baeb68297bdc629b27f8ea63f68b0a9e04a 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     SNAP data link layer. Derived from 802.2
  *
- *             Alan Cox <Alan.Cox@linux.org>,
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>,
  *             from the 802.2 layer by Greg Page.
  *             Merged in additions from Greg Page's psnap.c.
  *
index 0c850427a85b437e4e82e80b6c5f7f5bc52e06d0..d3134e7e6ee8e3a6960806259ce4266fabdb6a82 100644 (file)
@@ -2,7 +2,7 @@
  *     DDP:    An implementation of the AppleTalk DDP protocol for
  *             Ethernet 'ELAP'.
  *
- *             Alan Cox  <Alan.Cox@linux.org>
+ *             Alan Cox  <alan@lxorguk.ukuu.org.uk>
  *
  *             With more than a little assistance from
  *
@@ -1934,6 +1934,6 @@ static void __exit atalk_exit(void)
 module_exit(atalk_exit);
 
 MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Alan Cox <Alan.Cox@linux.org>");
+MODULE_AUTHOR("Alan Cox <alan@lxorguk.ukuu.org.uk>");
 MODULE_DESCRIPTION("AppleTalk 0.20\n");
 MODULE_ALIAS_NETPROTO(PF_APPLETALK);
index 52f577a0f5440c32b17488c630cfc619ede5c49a..ee631843c2f533de37101e92d05d447f85cf4d1f 100644 (file)
@@ -9,7 +9,7 @@
  *     identical recvmsg() code. So we share it here. The poll was
  *     shared before but buried in udp.c so I moved it.
  *
- *     Authors:        Alan Cox <alan@redhat.com>. (datagram_poll() from old
+ *     Authors:        Alan Cox <alan@lxorguk.ukuu.org.uk>. (datagram_poll() from old
  *                                                  udp.c code)
  *
  *     Fixes:
index 5402b3b38e0d230f9858adb0889b11746d90e2f5..9e2fa39f22a300e1fc46502aac39f305751e69c5 100644 (file)
@@ -6,7 +6,7 @@
  *             Richard Underwood <richard@wuzz.demon.co.uk>
  *
  *     Stir fried together from the IP multicast and CAP patches above
- *             Alan Cox <Alan.Cox@linux.org>
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     Fixes:
  *             Alan Cox        :       Update the device on a real delete
index a756847e3814e5fc9e425f105acfd2984eccb33a..99f656d35b4f5556be314cbb3ec4c732228f5709 100644 (file)
@@ -2474,7 +2474,7 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev,
                                if (ret < 0) {
                                        printk(KERN_ERR "Error expanding "
                                               "ipsec packet %d\n",ret);
-                                       return 0;
+                                       goto err;
                                }
                        }
 
@@ -2484,8 +2484,7 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev,
                        if (ret) {
                                printk(KERN_ERR "Error creating ipsec "
                                       "packet %d\n",ret);
-                               kfree_skb(skb);
-                               return 0;
+                               goto err;
                        }
                        /* restore ll */
                        eth = (__u8 *) skb_push(skb, ETH_HLEN);
@@ -2494,6 +2493,9 @@ static inline int process_ipsec(struct pktgen_dev *pkt_dev,
                }
        }
        return 1;
+err:
+       kfree_skb(skb);
+       return 0;
 }
 #endif
 
index 7f7bb1a636d935eb4a825d440605e1d35fde3994..4e22e3a35359169f172320337b91bf25ee7e3da7 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     Routines having to do with the 'struct sk_buff' memory handlers.
  *
- *     Authors:        Alan Cox <iiitac@pyr.swan.ac.uk>
+ *     Authors:        Alan Cox <alan@lxorguk.ukuu.org.uk>
  *                     Florian La Roche <rzsfl@rz.uni-sb.de>
  *
  *     Fixes:
index a6b3437ff082d9cf98b59bb754b409817f3b4597..8727cead64ad5f55bd4980d4964ede930d3242a9 100644 (file)
@@ -9,7 +9,7 @@
  *
  *     Authors:        Arnaldo Carvalho de Melo <acme@conectiva.com.br>
  *                     (from old tcp.c code)
- *                     Alan Cox <alan@redhat.com> (Borrowed comments 8-))
+ *                     Alan Cox <alan@lxorguk.ukuu.org.uk> (Borrowed comments 8-))
  */
 
 #include <linux/module.h>
index cdce4c6c672a03d884ad597fb3b20a4b0af17eb5..49211b35725ba74c5661717522075e7b968f303f 100644 (file)
@@ -1,7 +1,7 @@
 menuconfig NET_DSA
        bool "Distributed Switch Architecture support"
        default n
-       depends on EXPERIMENTAL
+       depends on EXPERIMENTAL && !S390
        select PHYLIB
        ---help---
          This allows you to use hardware switch chips that use
index 55c355e632345c9d3b07b263beea4332e2d36904..72b2de76f1cd1683b9dc33c957597a4556d9b36b 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     NET3:   Implementation of the ICMP protocol layer.
  *
- *             Alan Cox, <alan@redhat.com>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *
  *     This program is free software; you can redistribute it and/or
  *     modify it under the terms of the GNU General Public License
index 7f9e337e3908c9f643d00f020484f142f52bb6ef..a0d86455c53e3a69fc24adc90fcfcc2e1d293571 100644 (file)
@@ -9,7 +9,7 @@
  *     seems to fall out with gcc 2.6.2.
  *
  *     Authors:
- *             Alan Cox <Alan.Cox@linux.org>
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  *     This program is free software; you can redistribute it and/or
  *     modify it under the terms of the GNU General Public License
index 2152d222b954b3eca22bba260e30a5a551316da0..e4f81f54befee04ad398f6e5a6e3877d388d65bf 100644 (file)
@@ -6,7 +6,7 @@
  *             The IP fragmentation functionality.
  *
  * Authors:    Fred N. van Kempen <waltje@uWalt.NL.Mugnet.ORG>
- *             Alan Cox <Alan.Cox@linux.org>
+ *             Alan Cox <alan@lxorguk.ukuu.org.uk>
  *
  * Fixes:
  *             Alan Cox        :       Split from ip.c , see ip_input.c for history.
index e0bed56c51f1952d9d20d75729f01e83e31e2eed..861978a4f1a8b2f92a79baf34318beb808589a64 100644 (file)
@@ -8,7 +8,7 @@
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Donald Becker, <becker@super.org>
- *             Alan Cox, <Alan.Cox@linux.org>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Richard Underwood
  *             Stefan Becker, <stefanb@yello.ping.de>
  *             Jorge Cwik, <jorge@laser.satlink.net>
index 4c6d2caf92032c4fef47b2cb042e531eae0aa193..29609d29df769350e9d1683209b372a422e9cd3d 100644 (file)
@@ -41,7 +41,7 @@
                Made the tunnels use dev->name not tunnel: when error reporting.
                Added tx_dropped stat
 
-               -Alan Cox       (Alan.Cox@linux.org) 21 March 95
+               -Alan Cox       (alan@lxorguk.ukuu.org.uk) 21 March 95
 
        Reworked:
                Changed to tunnel to destination gateway in addition to the
index c519b8d30eee5c46f4547c3a014b3832d5a090ab..b42e082cc17048ddcdee7103f933c6123c663111 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *     IP multicast routing support for mrouted 3.6/3.8
  *
- *             (c) 1995 Alan Cox, <alan@redhat.com>
+ *             (c) 1995 Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *       Linux Consultancy and Custom Driver Development
  *
  *     This program is free software; you can redistribute it and/or
index eacf4cfef146dc445eef300b852c70545c584574..2095abc3caba90e2883febab41a9b792d405ba5f 100644 (file)
@@ -8,7 +8,7 @@
  * Authors:    Ross Biro
  *             Fred N. van Kempen, <waltje@uWalt.NL.Mugnet.ORG>
  *             Arnt Gulbrandsen, <agulbra@nvg.unit.no>
- *             Alan Cox, <Alan.Cox@linux.org>
+ *             Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *             Hirokazu Takahashi, <taka@valinux.co.jp>
  *
  * Fixes:
index 050e14b7f7014a2f61854af31defd1483a7eb234..01edac888510cb7f4efb0c1ff994c4978a11bfaf 100644 (file)
@@ -834,7 +834,7 @@ static void __net_exit ipv6_cleanup_mibs(struct net *net)
        snmp_mib_free((void **)net->mib.icmpv6msg_statistics);
 }
 
-static int inet6_net_init(struct net *net)
+static int __net_init inet6_net_init(struct net *net)
 {
        int err = 0;
 
index b0eacc0007cc39b1c19ccf0c38800e0e50a8d608..2fd8afac5f7126955e70152b1f4c4315583ecba1 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * NETLINK      Kernel-user communication protocol.
  *
- *             Authors:        Alan Cox <alan@redhat.com>
+ *             Authors:        Alan Cox <alan@lxorguk.ukuu.org.uk>
  *                             Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
  *
  *             This program is free software; you can redistribute it and/or
index e5b69556bb5b270f5d0b1250d5c01825ba27ea43..21124ec0a73d64d8b4f937b6a7d93d37a6f81a69 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/workqueue.h>
 #include <linux/init.h>
 #include <linux/rfkill.h>
+#include <linux/sched.h>
 
 #include "rfkill-input.h"
 
index 76739e928d0da5ff99b748ac61538e2bfc03fbf4..da0789fa1b88876e785e2f8c233fd8f2f3950dbd 100644 (file)
@@ -174,7 +174,7 @@ static struct rpc_clnt * rpc_new_client(const struct rpc_create_args *args, stru
        clnt->cl_procinfo = version->procs;
        clnt->cl_maxproc  = version->nrprocs;
        clnt->cl_protname = program->name;
-       clnt->cl_prog     = program->number;
+       clnt->cl_prog     = args->prognumber ? : program->number;
        clnt->cl_vers     = version->number;
        clnt->cl_stats    = program->stats;
        clnt->cl_metrics  = rpc_alloc_iostats(clnt);
index 24db2b4d12d3e43b3faf944262a10105ecaca898..34abc91058d84ebe5dd89ed481d9542b548c24a7 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/in6.h>
 #include <linux/kernel.h>
 #include <linux/errno.h>
+#include <net/ipv6.h>
 
 #include <linux/sunrpc/clnt.h>
 #include <linux/sunrpc/sched.h>
@@ -176,13 +177,12 @@ static struct rpc_clnt *rpcb_create(char *hostname, struct sockaddr *srvaddr,
 }
 
 static int rpcb_register_call(struct sockaddr *addr, size_t addrlen,
-                             u32 version, struct rpc_message *msg,
-                             int *result)
+                             u32 version, struct rpc_message *msg)
 {
        struct rpc_clnt *rpcb_clnt;
-       int error = 0;
+       int result, error = 0;
 
-       *result = 0;
+       msg->rpc_resp = &result;
 
        rpcb_clnt = rpcb_create_local(addr, addrlen, version);
        if (!IS_ERR(rpcb_clnt)) {
@@ -191,12 +191,15 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen,
        } else
                error = PTR_ERR(rpcb_clnt);
 
-       if (error < 0)
+       if (error < 0) {
                printk(KERN_WARNING "RPC: failed to contact local rpcbind "
                                "server (errno %d).\n", -error);
-       dprintk("RPC:       registration status %d/%d\n", error, *result);
+               return error;
+       }
 
-       return error;
+       if (!result)
+               return -EACCES;
+       return 0;
 }
 
 /**
@@ -205,7 +208,11 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen,
  * @vers: RPC version number to bind
  * @prot: transport protocol to register
  * @port: port value to register
- * @okay: OUT: result code
+ *
+ * Returns zero if the registration request was dispatched successfully
+ * and the rpcbind daemon returned success.  Otherwise, returns an errno
+ * value that reflects the nature of the error (request could not be
+ * dispatched, timed out, or rpcbind returned an error).
  *
  * RPC services invoke this function to advertise their contact
  * information via the system's rpcbind daemon.  RPC services
@@ -217,15 +224,6 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen,
  * all registered transports for [program, version] from the local
  * rpcbind database.
  *
- * Returns zero if the registration request was dispatched
- * successfully and a reply was received.  The rpcbind daemon's
- * boolean result code is stored in *okay.
- *
- * Returns an errno value and sets *result to zero if there was
- * some problem that prevented the rpcbind request from being
- * dispatched, or if the rpcbind daemon did not respond within
- * the timeout.
- *
  * This function uses rpcbind protocol version 2 to contact the
  * local rpcbind daemon.
  *
@@ -236,7 +234,7 @@ static int rpcb_register_call(struct sockaddr *addr, size_t addrlen,
  * IN6ADDR_ANY (ie available for all AF_INET and AF_INET6
  * addresses).
  */
-int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
+int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port)
 {
        struct rpcbind_args map = {
                .r_prog         = prog,
@@ -246,7 +244,6 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
        };
        struct rpc_message msg = {
                .rpc_argp       = &map,
-               .rpc_resp       = okay,
        };
 
        dprintk("RPC:       %sregistering (%u, %u, %d, %u) with local "
@@ -259,7 +256,7 @@ int rpcb_register(u32 prog, u32 vers, int prot, unsigned short port, int *okay)
 
        return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback,
                                        sizeof(rpcb_inaddr_loopback),
-                                       RPCBVERS_2, &msg, okay);
+                                       RPCBVERS_2, &msg);
 }
 
 /*
@@ -290,7 +287,7 @@ static int rpcb_register_netid4(struct sockaddr_in *address_to_register,
 
        return rpcb_register_call((struct sockaddr *)&rpcb_inaddr_loopback,
                                        sizeof(rpcb_inaddr_loopback),
-                                       RPCBVERS_4, msg, msg->rpc_resp);
+                                       RPCBVERS_4, msg);
 }
 
 /*
@@ -304,10 +301,13 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
        char buf[64];
 
        /* Construct AF_INET6 universal address */
-       snprintf(buf, sizeof(buf),
-                       NIP6_FMT".%u.%u",
-                       NIP6(address_to_register->sin6_addr),
-                       port >> 8, port & 0xff);
+       if (ipv6_addr_any(&address_to_register->sin6_addr))
+               snprintf(buf, sizeof(buf), "::.%u.%u",
+                               port >> 8, port & 0xff);
+       else
+               snprintf(buf, sizeof(buf), NIP6_FMT".%u.%u",
+                               NIP6(address_to_register->sin6_addr),
+                               port >> 8, port & 0xff);
        map->r_addr = buf;
 
        dprintk("RPC:       %sregistering [%u, %u, %s, '%s'] with "
@@ -321,7 +321,7 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
 
        return rpcb_register_call((struct sockaddr *)&rpcb_in6addr_loopback,
                                        sizeof(rpcb_in6addr_loopback),
-                                       RPCBVERS_4, msg, msg->rpc_resp);
+                                       RPCBVERS_4, msg);
 }
 
 /**
@@ -330,7 +330,11 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
  * @version: RPC version number of service to (un)register
  * @address: address family, IP address, and port to (un)register
  * @netid: netid of transport protocol to (un)register
- * @result: result code from rpcbind RPC call
+ *
+ * Returns zero if the registration request was dispatched successfully
+ * and the rpcbind daemon returned success.  Otherwise, returns an errno
+ * value that reflects the nature of the error (request could not be
+ * dispatched, timed out, or rpcbind returned an error).
  *
  * RPC services invoke this function to advertise their contact
  * information via the system's rpcbind daemon.  RPC services
@@ -342,15 +346,6 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
  * to zero.  Callers pass a netid of "" to unregister all
  * transport netids associated with [program, version, address].
  *
- * Returns zero if the registration request was dispatched
- * successfully and a reply was received.  The rpcbind daemon's
- * result code is stored in *result.
- *
- * Returns an errno value and sets *result to zero if there was
- * some problem that prevented the rpcbind request from being
- * dispatched, or if the rpcbind daemon did not respond within
- * the timeout.
- *
  * This function uses rpcbind protocol version 4 to contact the
  * local rpcbind daemon.  The local rpcbind daemon must support
  * version 4 of the rpcbind protocol in order for these functions
@@ -372,8 +367,7 @@ static int rpcb_register_netid6(struct sockaddr_in6 *address_to_register,
  * advertises the service on all IPv4 and IPv6 addresses.
  */
 int rpcb_v4_register(const u32 program, const u32 version,
-                    const struct sockaddr *address, const char *netid,
-                    int *result)
+                    const struct sockaddr *address, const char *netid)
 {
        struct rpcbind_args map = {
                .r_prog         = program,
@@ -383,11 +377,8 @@ int rpcb_v4_register(const u32 program, const u32 version,
        };
        struct rpc_message msg = {
                .rpc_argp       = &map,
-               .rpc_resp       = result,
        };
 
-       *result = 0;
-
        switch (address->sa_family) {
        case AF_INET:
                return rpcb_register_netid4((struct sockaddr_in *)address,
@@ -633,7 +624,7 @@ static void rpcb_getport_done(struct rpc_task *child, void *data)
 static int rpcb_encode_mapping(struct rpc_rqst *req, __be32 *p,
                               struct rpcbind_args *rpcb)
 {
-       dprintk("RPC:       rpcb_encode_mapping(%u, %u, %d, %u)\n",
+       dprintk("RPC:       encoding rpcb request (%u, %u, %d, %u)\n",
                        rpcb->r_prog, rpcb->r_vers, rpcb->r_prot, rpcb->r_port);
        *p++ = htonl(rpcb->r_prog);
        *p++ = htonl(rpcb->r_vers);
@@ -648,7 +639,7 @@ static int rpcb_decode_getport(struct rpc_rqst *req, __be32 *p,
                               unsigned short *portp)
 {
        *portp = (unsigned short) ntohl(*p++);
-       dprintk("RPC:       rpcb_decode_getport result %u\n",
+       dprintk("RPC:       rpcb getport result: %u\n",
                        *portp);
        return 0;
 }
@@ -657,7 +648,7 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p,
                           unsigned int *boolp)
 {
        *boolp = (unsigned int) ntohl(*p++);
-       dprintk("RPC:       rpcb_decode_set: call %s\n",
+       dprintk("RPC:       rpcb set/unset call %s\n",
                        (*boolp ? "succeeded" : "failed"));
        return 0;
 }
@@ -665,7 +656,7 @@ static int rpcb_decode_set(struct rpc_rqst *req, __be32 *p,
 static int rpcb_encode_getaddr(struct rpc_rqst *req, __be32 *p,
                               struct rpcbind_args *rpcb)
 {
-       dprintk("RPC:       rpcb_encode_getaddr(%u, %u, %s)\n",
+       dprintk("RPC:       encoding rpcb request (%u, %u, %s)\n",
                        rpcb->r_prog, rpcb->r_vers, rpcb->r_addr);
        *p++ = htonl(rpcb->r_prog);
        *p++ = htonl(rpcb->r_vers);
index 5a32cb7c4bb486267a03d15892adc7ce5db93c93..54c98d8768472f8a8442b024d5ef47c913c99511 100644 (file)
@@ -28,6 +28,8 @@
 
 #define RPCDBG_FACILITY        RPCDBG_SVCDSP
 
+static void svc_unregister(const struct svc_serv *serv);
+
 #define svc_serv_is_pooled(serv)    ((serv)->sv_function)
 
 /*
@@ -357,7 +359,7 @@ svc_pool_for_cpu(struct svc_serv *serv, int cpu)
  */
 static struct svc_serv *
 __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
-          void (*shutdown)(struct svc_serv *serv))
+          sa_family_t family, void (*shutdown)(struct svc_serv *serv))
 {
        struct svc_serv *serv;
        unsigned int vers;
@@ -366,6 +368,7 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
 
        if (!(serv = kzalloc(sizeof(*serv), GFP_KERNEL)))
                return NULL;
+       serv->sv_family    = family;
        serv->sv_name      = prog->pg_name;
        serv->sv_program   = prog;
        serv->sv_nrthreads = 1;
@@ -416,30 +419,29 @@ __svc_create(struct svc_program *prog, unsigned int bufsize, int npools,
                spin_lock_init(&pool->sp_lock);
        }
 
-
        /* Remove any stale portmap registrations */
-       svc_register(serv, 0, 0);
+       svc_unregister(serv);
 
        return serv;
 }
 
 struct svc_serv *
 svc_create(struct svc_program *prog, unsigned int bufsize,
-               void (*shutdown)(struct svc_serv *serv))
+               sa_family_t family, void (*shutdown)(struct svc_serv *serv))
 {
-       return __svc_create(prog, bufsize, /*npools*/1, shutdown);
+       return __svc_create(prog, bufsize, /*npools*/1, family, shutdown);
 }
 EXPORT_SYMBOL(svc_create);
 
 struct svc_serv *
 svc_create_pooled(struct svc_program *prog, unsigned int bufsize,
-               void (*shutdown)(struct svc_serv *serv),
+                 sa_family_t family, void (*shutdown)(struct svc_serv *serv),
                  svc_thread_fn func, struct module *mod)
 {
        struct svc_serv *serv;
        unsigned int npools = svc_pool_map_get();
 
-       serv = __svc_create(prog, bufsize, npools, shutdown);
+       serv = __svc_create(prog, bufsize, npools, family, shutdown);
 
        if (serv != NULL) {
                serv->sv_function = func;
@@ -486,8 +488,7 @@ svc_destroy(struct svc_serv *serv)
        if (svc_serv_is_pooled(serv))
                svc_pool_map_put();
 
-       /* Unregister service with the portmapper */
-       svc_register(serv, 0, 0);
+       svc_unregister(serv);
        kfree(serv->sv_pools);
        kfree(serv);
 }
@@ -718,55 +719,245 @@ svc_exit_thread(struct svc_rqst *rqstp)
 }
 EXPORT_SYMBOL(svc_exit_thread);
 
+#ifdef CONFIG_SUNRPC_REGISTER_V4
+
 /*
- * Register an RPC service with the local portmapper.
- * To unregister a service, call this routine with
- * proto and port == 0.
+ * Register an "inet" protocol family netid with the local
+ * rpcbind daemon via an rpcbind v4 SET request.
+ *
+ * No netconfig infrastructure is available in the kernel, so
+ * we map IP_ protocol numbers to netids by hand.
+ *
+ * Returns zero on success; a negative errno value is returned
+ * if any error occurs.
  */
-int
-svc_register(struct svc_serv *serv, int proto, unsigned short port)
+static int __svc_rpcb_register4(const u32 program, const u32 version,
+                               const unsigned short protocol,
+                               const unsigned short port)
+{
+       struct sockaddr_in sin = {
+               .sin_family             = AF_INET,
+               .sin_addr.s_addr        = htonl(INADDR_ANY),
+               .sin_port               = htons(port),
+       };
+       char *netid;
+
+       switch (protocol) {
+       case IPPROTO_UDP:
+               netid = RPCBIND_NETID_UDP;
+               break;
+       case IPPROTO_TCP:
+               netid = RPCBIND_NETID_TCP;
+               break;
+       default:
+               return -EPROTONOSUPPORT;
+       }
+
+       return rpcb_v4_register(program, version,
+                               (struct sockaddr *)&sin, netid);
+}
+
+/*
+ * Register an "inet6" protocol family netid with the local
+ * rpcbind daemon via an rpcbind v4 SET request.
+ *
+ * No netconfig infrastructure is available in the kernel, so
+ * we map IP_ protocol numbers to netids by hand.
+ *
+ * Returns zero on success; a negative errno value is returned
+ * if any error occurs.
+ */
+static int __svc_rpcb_register6(const u32 program, const u32 version,
+                               const unsigned short protocol,
+                               const unsigned short port)
+{
+       struct sockaddr_in6 sin6 = {
+               .sin6_family            = AF_INET6,
+               .sin6_addr              = IN6ADDR_ANY_INIT,
+               .sin6_port              = htons(port),
+       };
+       char *netid;
+
+       switch (protocol) {
+       case IPPROTO_UDP:
+               netid = RPCBIND_NETID_UDP6;
+               break;
+       case IPPROTO_TCP:
+               netid = RPCBIND_NETID_TCP6;
+               break;
+       default:
+               return -EPROTONOSUPPORT;
+       }
+
+       return rpcb_v4_register(program, version,
+                               (struct sockaddr *)&sin6, netid);
+}
+
+/*
+ * Register a kernel RPC service via rpcbind version 4.
+ *
+ * Returns zero on success; a negative errno value is returned
+ * if any error occurs.
+ */
+static int __svc_register(const u32 program, const u32 version,
+                         const sa_family_t family,
+                         const unsigned short protocol,
+                         const unsigned short port)
+{
+       int error;
+
+       switch (family) {
+       case AF_INET:
+               return __svc_rpcb_register4(program, version,
+                                               protocol, port);
+       case AF_INET6:
+               error = __svc_rpcb_register6(program, version,
+                                               protocol, port);
+               if (error < 0)
+                       return error;
+
+               /*
+                * Work around bug in some versions of Linux rpcbind
+                * which don't allow registration of both inet and
+                * inet6 netids.
+                *
+                * Error return ignored for now.
+                */
+               __svc_rpcb_register4(program, version,
+                                               protocol, port);
+               return 0;
+       }
+
+       return -EAFNOSUPPORT;
+}
+
+#else  /* CONFIG_SUNRPC_REGISTER_V4 */
+
+/*
+ * Register a kernel RPC service via rpcbind version 2.
+ *
+ * Returns zero on success; a negative errno value is returned
+ * if any error occurs.
+ */
+static int __svc_register(const u32 program, const u32 version,
+                         sa_family_t family,
+                         const unsigned short protocol,
+                         const unsigned short port)
+{
+       if (family != AF_INET)
+               return -EAFNOSUPPORT;
+
+       return rpcb_register(program, version, protocol, port);
+}
+
+#endif /* CONFIG_SUNRPC_REGISTER_V4 */
+
+/**
+ * svc_register - register an RPC service with the local portmapper
+ * @serv: svc_serv struct for the service to register
+ * @proto: transport protocol number to advertise
+ * @port: port to advertise
+ *
+ * Service is registered for any address in serv's address family
+ */
+int svc_register(const struct svc_serv *serv, const unsigned short proto,
+                const unsigned short port)
 {
        struct svc_program      *progp;
-       unsigned long           flags;
        unsigned int            i;
-       int                     error = 0, dummy;
+       int                     error = 0;
 
-       if (!port)
-               clear_thread_flag(TIF_SIGPENDING);
+       BUG_ON(proto == 0 && port == 0);
 
        for (progp = serv->sv_program; progp; progp = progp->pg_next) {
                for (i = 0; i < progp->pg_nvers; i++) {
                        if (progp->pg_vers[i] == NULL)
                                continue;
 
-                       dprintk("svc: svc_register(%s, %s, %d, %d)%s\n",
+                       dprintk("svc: svc_register(%sv%d, %s, %u, %u)%s\n",
                                        progp->pg_name,
+                                       i,
                                        proto == IPPROTO_UDP?  "udp" : "tcp",
                                        port,
-                                       i,
+                                       serv->sv_family,
                                        progp->pg_vers[i]->vs_hidden?
                                                " (but not telling portmap)" : "");
 
                        if (progp->pg_vers[i]->vs_hidden)
                                continue;
 
-                       error = rpcb_register(progp->pg_prog, i, proto, port, &dummy);
+                       error = __svc_register(progp->pg_prog, i,
+                                               serv->sv_family, proto, port);
                        if (error < 0)
                                break;
-                       if (port && !dummy) {
-                               error = -EACCES;
-                               break;
-                       }
                }
        }
 
-       if (!port) {
-               spin_lock_irqsave(&current->sighand->siglock, flags);
-               recalc_sigpending();
-               spin_unlock_irqrestore(&current->sighand->siglock, flags);
+       return error;
+}
+
+#ifdef CONFIG_SUNRPC_REGISTER_V4
+
+static void __svc_unregister(const u32 program, const u32 version,
+                            const char *progname)
+{
+       struct sockaddr_in6 sin6 = {
+               .sin6_family            = AF_INET6,
+               .sin6_addr              = IN6ADDR_ANY_INIT,
+               .sin6_port              = 0,
+       };
+       int error;
+
+       error = rpcb_v4_register(program, version,
+                               (struct sockaddr *)&sin6, "");
+       dprintk("svc: %s(%sv%u), error %d\n",
+                       __func__, progname, version, error);
+}
+
+#else  /* CONFIG_SUNRPC_REGISTER_V4 */
+
+static void __svc_unregister(const u32 program, const u32 version,
+                            const char *progname)
+{
+       int error;
+
+       error = rpcb_register(program, version, 0, 0);
+       dprintk("svc: %s(%sv%u), error %d\n",
+                       __func__, progname, version, error);
+}
+
+#endif /* CONFIG_SUNRPC_REGISTER_V4 */
+
+/*
+ * All netids, bind addresses and ports registered for [program, version]
+ * are removed from the local rpcbind database (if the service is not
+ * hidden) to make way for a new instance of the service.
+ *
+ * The result of unregistration is reported via dprintk for those who want
+ * verification of the result, but is otherwise not important.
+ */
+static void svc_unregister(const struct svc_serv *serv)
+{
+       struct svc_program *progp;
+       unsigned long flags;
+       unsigned int i;
+
+       clear_thread_flag(TIF_SIGPENDING);
+
+       for (progp = serv->sv_program; progp; progp = progp->pg_next) {
+               for (i = 0; i < progp->pg_nvers; i++) {
+                       if (progp->pg_vers[i] == NULL)
+                               continue;
+                       if (progp->pg_vers[i]->vs_hidden)
+                               continue;
+
+                       __svc_unregister(progp->pg_prog, i, progp->pg_name);
+               }
        }
 
-       return error;
+       spin_lock_irqsave(&current->sighand->siglock, flags);
+       recalc_sigpending();
+       spin_unlock_irqrestore(&current->sighand->siglock, flags);
 }
 
 /*
index e46c825f49548923f79f1363d4a7712ef4ead513..bf5b5cdafebfcc82866369bdb3d895c83379a4e3 100644 (file)
@@ -159,15 +159,44 @@ void svc_xprt_init(struct svc_xprt_class *xcl, struct svc_xprt *xprt,
 }
 EXPORT_SYMBOL_GPL(svc_xprt_init);
 
-int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,
-                   int flags)
+static struct svc_xprt *__svc_xpo_create(struct svc_xprt_class *xcl,
+                                        struct svc_serv *serv,
+                                        unsigned short port, int flags)
 {
-       struct svc_xprt_class *xcl;
        struct sockaddr_in sin = {
                .sin_family             = AF_INET,
                .sin_addr.s_addr        = htonl(INADDR_ANY),
                .sin_port               = htons(port),
        };
+       struct sockaddr_in6 sin6 = {
+               .sin6_family            = AF_INET6,
+               .sin6_addr              = IN6ADDR_ANY_INIT,
+               .sin6_port              = htons(port),
+       };
+       struct sockaddr *sap;
+       size_t len;
+
+       switch (serv->sv_family) {
+       case AF_INET:
+               sap = (struct sockaddr *)&sin;
+               len = sizeof(sin);
+               break;
+       case AF_INET6:
+               sap = (struct sockaddr *)&sin6;
+               len = sizeof(sin6);
+               break;
+       default:
+               return ERR_PTR(-EAFNOSUPPORT);
+       }
+
+       return xcl->xcl_ops->xpo_create(serv, sap, len, flags);
+}
+
+int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,
+                   int flags)
+{
+       struct svc_xprt_class *xcl;
+
        dprintk("svc: creating transport %s[%d]\n", xprt_name, port);
        spin_lock(&svc_xprt_class_lock);
        list_for_each_entry(xcl, &svc_xprt_class_list, xcl_list) {
@@ -180,9 +209,7 @@ int svc_create_xprt(struct svc_serv *serv, char *xprt_name, unsigned short port,
                        goto err;
 
                spin_unlock(&svc_xprt_class_lock);
-               newxprt = xcl->xcl_ops->
-                       xpo_create(serv, (struct sockaddr *)&sin, sizeof(sin),
-                                  flags);
+               newxprt = __svc_xpo_create(xcl, serv, port, flags);
                if (IS_ERR(newxprt)) {
                        module_put(xcl->xcl_owner);
                        return PTR_ERR(newxprt);
index 3e65719f1ef698891d8e81ebea6c57e72b212717..95293f549e9c2b371b82ce32af4ca43be00b5ada 100644 (file)
@@ -1114,6 +1114,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
        struct svc_sock *svsk;
        struct sock     *inet;
        int             pmap_register = !(flags & SVC_SOCK_ANONYMOUS);
+       int             val;
 
        dprintk("svc: svc_setup_socket %p\n", sock);
        if (!(svsk = kzalloc(sizeof(*svsk), GFP_KERNEL))) {
@@ -1146,6 +1147,18 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
        else
                svc_tcp_init(svsk, serv);
 
+       /*
+        * We start one listener per sv_serv.  We want AF_INET
+        * requests to be automatically shunted to our AF_INET6
+        * listener using a mapped IPv4 address.  Make sure
+        * no-one starts an equivalent IPv4 listener, which
+        * would steal our incoming connections.
+        */
+       val = 0;
+       if (serv->sv_family == AF_INET6)
+               kernel_setsockopt(sock, SOL_IPV6, IPV6_V6ONLY,
+                                       (char *)&val, sizeof(val));
+
        dprintk("svc: svc_setup_socket created %p (inet %p)\n",
                                svsk, svsk->sk_sk);
 
@@ -1154,8 +1167,7 @@ static struct svc_sock *svc_setup_socket(struct svc_serv *serv,
 
 int svc_addsock(struct svc_serv *serv,
                int fd,
-               char *name_return,
-               int *proto)
+               char *name_return)
 {
        int err = 0;
        struct socket *so = sockfd_lookup(fd, &err);
@@ -1190,7 +1202,6 @@ int svc_addsock(struct svc_serv *serv,
                sockfd_put(so);
                return err;
        }
-       if (proto) *proto = so->sk->sk_protocol;
        return one_sock_name(name_return, svsk);
 }
 EXPORT_SYMBOL_GPL(svc_addsock);
index 74de31a066168509db7dba7ab559b29d17dae413..a4756576d68794a1106c4404b39ad9adf510a906 100644 (file)
@@ -116,7 +116,7 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
  *
  * Assumptions:
  * - chunk[0]->position points to pages[0] at an offset of 0
- * - pages[] is not physically or virtually contigous and consists of
+ * - pages[] is not physically or virtually contiguous and consists of
  *   PAGE_SIZE elements.
  *
  * Output:
@@ -125,7 +125,7 @@ static void rdma_build_arg_xdr(struct svc_rqst *rqstp,
  *   chunk in the read list
  *
  */
-static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt,
+static int map_read_chunks(struct svcxprt_rdma *xprt,
                           struct svc_rqst *rqstp,
                           struct svc_rdma_op_ctxt *head,
                           struct rpcrdma_msg *rmsgp,
@@ -211,26 +211,128 @@ static int rdma_rcl_to_sge(struct svcxprt_rdma *xprt,
        return sge_no;
 }
 
-static void rdma_set_ctxt_sge(struct svcxprt_rdma *xprt,
-                             struct svc_rdma_op_ctxt *ctxt,
-                             struct kvec *vec,
-                             u64 *sgl_offset,
-                             int count)
+/* Map a read-chunk-list to an XDR and fast register the page-list.
+ *
+ * Assumptions:
+ * - chunk[0]  position points to pages[0] at an offset of 0
+ * - pages[]   will be made physically contiguous by creating a one-off memory
+ *             region using the fastreg verb.
+ * - byte_count is # of bytes in read-chunk-list
+ * - ch_count  is # of chunks in read-chunk-list
+ *
+ * Output:
+ * - sge array pointing into pages[] array.
+ * - chunk_sge array specifying sge index and count for each
+ *   chunk in the read list
+ */
+static int fast_reg_read_chunks(struct svcxprt_rdma *xprt,
+                               struct svc_rqst *rqstp,
+                               struct svc_rdma_op_ctxt *head,
+                               struct rpcrdma_msg *rmsgp,
+                               struct svc_rdma_req_map *rpl_map,
+                               struct svc_rdma_req_map *chl_map,
+                               int ch_count,
+                               int byte_count)
+{
+       int page_no;
+       int ch_no;
+       u32 offset;
+       struct rpcrdma_read_chunk *ch;
+       struct svc_rdma_fastreg_mr *frmr;
+       int ret = 0;
+
+       frmr = svc_rdma_get_frmr(xprt);
+       if (IS_ERR(frmr))
+               return -ENOMEM;
+
+       head->frmr = frmr;
+       head->arg.head[0] = rqstp->rq_arg.head[0];
+       head->arg.tail[0] = rqstp->rq_arg.tail[0];
+       head->arg.pages = &head->pages[head->count];
+       head->hdr_count = head->count; /* save count of hdr pages */
+       head->arg.page_base = 0;
+       head->arg.page_len = byte_count;
+       head->arg.len = rqstp->rq_arg.len + byte_count;
+       head->arg.buflen = rqstp->rq_arg.buflen + byte_count;
+
+       /* Fast register the page list */
+       frmr->kva = page_address(rqstp->rq_arg.pages[0]);
+       frmr->direction = DMA_FROM_DEVICE;
+       frmr->access_flags = (IB_ACCESS_LOCAL_WRITE|IB_ACCESS_REMOTE_WRITE);
+       frmr->map_len = byte_count;
+       frmr->page_list_len = PAGE_ALIGN(byte_count) >> PAGE_SHIFT;
+       for (page_no = 0; page_no < frmr->page_list_len; page_no++) {
+               frmr->page_list->page_list[page_no] =
+                       ib_dma_map_single(xprt->sc_cm_id->device,
+                                         page_address(rqstp->rq_arg.pages[page_no]),
+                                         PAGE_SIZE, DMA_TO_DEVICE);
+               if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                        frmr->page_list->page_list[page_no]))
+                       goto fatal_err;
+               atomic_inc(&xprt->sc_dma_used);
+               head->arg.pages[page_no] = rqstp->rq_arg.pages[page_no];
+       }
+       head->count += page_no;
+
+       /* rq_respages points one past arg pages */
+       rqstp->rq_respages = &rqstp->rq_arg.pages[page_no];
+
+       /* Create the reply and chunk maps */
+       offset = 0;
+       ch = (struct rpcrdma_read_chunk *)&rmsgp->rm_body.rm_chunks[0];
+       for (ch_no = 0; ch_no < ch_count; ch_no++) {
+               rpl_map->sge[ch_no].iov_base = frmr->kva + offset;
+               rpl_map->sge[ch_no].iov_len = ch->rc_target.rs_length;
+               chl_map->ch[ch_no].count = 1;
+               chl_map->ch[ch_no].start = ch_no;
+               offset += ch->rc_target.rs_length;
+               ch++;
+       }
+
+       ret = svc_rdma_fastreg(xprt, frmr);
+       if (ret)
+               goto fatal_err;
+
+       return ch_no;
+
+ fatal_err:
+       printk("svcrdma: error fast registering xdr for xprt %p", xprt);
+       svc_rdma_put_frmr(xprt, frmr);
+       return -EIO;
+}
+
+static int rdma_set_ctxt_sge(struct svcxprt_rdma *xprt,
+                            struct svc_rdma_op_ctxt *ctxt,
+                            struct svc_rdma_fastreg_mr *frmr,
+                            struct kvec *vec,
+                            u64 *sgl_offset,
+                            int count)
 {
        int i;
 
        ctxt->count = count;
        ctxt->direction = DMA_FROM_DEVICE;
        for (i = 0; i < count; i++) {
-               atomic_inc(&xprt->sc_dma_used);
-               ctxt->sge[i].addr =
-                       ib_dma_map_single(xprt->sc_cm_id->device,
-                                         vec[i].iov_base, vec[i].iov_len,
-                                         DMA_FROM_DEVICE);
+               ctxt->sge[i].length = 0; /* in case map fails */
+               if (!frmr) {
+                       ctxt->sge[i].addr =
+                               ib_dma_map_single(xprt->sc_cm_id->device,
+                                                 vec[i].iov_base,
+                                                 vec[i].iov_len,
+                                                 DMA_FROM_DEVICE);
+                       if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                                ctxt->sge[i].addr))
+                               return -EINVAL;
+                       ctxt->sge[i].lkey = xprt->sc_dma_lkey;
+                       atomic_inc(&xprt->sc_dma_used);
+               } else {
+                       ctxt->sge[i].addr = (unsigned long)vec[i].iov_base;
+                       ctxt->sge[i].lkey = frmr->mr->lkey;
+               }
                ctxt->sge[i].length = vec[i].iov_len;
-               ctxt->sge[i].lkey = xprt->sc_phys_mr->lkey;
                *sgl_offset = *sgl_offset + vec[i].iov_len;
        }
+       return 0;
 }
 
 static int rdma_read_max_sge(struct svcxprt_rdma *xprt, int sge_count)
@@ -278,6 +380,7 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt,
                         struct svc_rdma_op_ctxt *hdr_ctxt)
 {
        struct ib_send_wr read_wr;
+       struct ib_send_wr inv_wr;
        int err = 0;
        int ch_no;
        int ch_count;
@@ -301,9 +404,20 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt,
        svc_rdma_rcl_chunk_counts(ch, &ch_count, &byte_count);
        if (ch_count > RPCSVC_MAXPAGES)
                return -EINVAL;
-       sge_count = rdma_rcl_to_sge(xprt, rqstp, hdr_ctxt, rmsgp,
-                                   rpl_map, chl_map,
-                                   ch_count, byte_count);
+
+       if (!xprt->sc_frmr_pg_list_len)
+               sge_count = map_read_chunks(xprt, rqstp, hdr_ctxt, rmsgp,
+                                           rpl_map, chl_map, ch_count,
+                                           byte_count);
+       else
+               sge_count = fast_reg_read_chunks(xprt, rqstp, hdr_ctxt, rmsgp,
+                                                rpl_map, chl_map, ch_count,
+                                                byte_count);
+       if (sge_count < 0) {
+               err = -EIO;
+               goto out;
+       }
+
        sgl_offset = 0;
        ch_no = 0;
 
@@ -312,13 +426,16 @@ static int rdma_read_xdr(struct svcxprt_rdma *xprt,
 next_sge:
                ctxt = svc_rdma_get_context(xprt);
                ctxt->direction = DMA_FROM_DEVICE;
+               ctxt->frmr = hdr_ctxt->frmr;
+               ctxt->read_hdr = NULL;
                clear_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
+               clear_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags);
 
                /* Prepare READ WR */
                memset(&read_wr, 0, sizeof read_wr);
-               ctxt->wr_op = IB_WR_RDMA_READ;
                read_wr.wr_id = (unsigned long)ctxt;
                read_wr.opcode = IB_WR_RDMA_READ;
+               ctxt->wr_op = read_wr.opcode;
                read_wr.send_flags = IB_SEND_SIGNALED;
                read_wr.wr.rdma.rkey = ch->rc_target.rs_handle;
                read_wr.wr.rdma.remote_addr =
@@ -327,10 +444,15 @@ next_sge:
                read_wr.sg_list = ctxt->sge;
                read_wr.num_sge =
                        rdma_read_max_sge(xprt, chl_map->ch[ch_no].count);
-               rdma_set_ctxt_sge(xprt, ctxt,
-                                 &rpl_map->sge[chl_map->ch[ch_no].start],
-                                 &sgl_offset,
-                                 read_wr.num_sge);
+               err = rdma_set_ctxt_sge(xprt, ctxt, hdr_ctxt->frmr,
+                                       &rpl_map->sge[chl_map->ch[ch_no].start],
+                                       &sgl_offset,
+                                       read_wr.num_sge);
+               if (err) {
+                       svc_rdma_unmap_dma(ctxt);
+                       svc_rdma_put_context(ctxt, 0);
+                       goto out;
+               }
                if (((ch+1)->rc_discrim == 0) &&
                    (read_wr.num_sge == chl_map->ch[ch_no].count)) {
                        /*
@@ -339,6 +461,29 @@ next_sge:
                         * the client and the RPC needs to be enqueued.
                         */
                        set_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags);
+                       if (hdr_ctxt->frmr) {
+                               set_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags);
+                               /*
+                                * Invalidate the local MR used to map the data
+                                * sink.
+                                */
+                               if (xprt->sc_dev_caps &
+                                   SVCRDMA_DEVCAP_READ_W_INV) {
+                                       read_wr.opcode =
+                                               IB_WR_RDMA_READ_WITH_INV;
+                                       ctxt->wr_op = read_wr.opcode;
+                                       read_wr.ex.invalidate_rkey =
+                                               ctxt->frmr->mr->lkey;
+                               } else {
+                                       /* Prepare INVALIDATE WR */
+                                       memset(&inv_wr, 0, sizeof inv_wr);
+                                       inv_wr.opcode = IB_WR_LOCAL_INV;
+                                       inv_wr.send_flags = IB_SEND_SIGNALED;
+                                       inv_wr.ex.invalidate_rkey =
+                                               hdr_ctxt->frmr->mr->lkey;
+                                       read_wr.next = &inv_wr;
+                               }
+                       }
                        ctxt->read_hdr = hdr_ctxt;
                }
                /* Post the read */
index 84d328329d98575d624557fa75a7e159436ece85..9a7a8e7ae038fbb255dd34880e7882feb8eff322 100644 (file)
  * array is only concerned with the reply we are assured that we have
  * on extra page for the RPCRMDA header.
  */
-static void xdr_to_sge(struct svcxprt_rdma *xprt,
-                      struct xdr_buf *xdr,
-                      struct svc_rdma_req_map *vec)
+int fast_reg_xdr(struct svcxprt_rdma *xprt,
+                struct xdr_buf *xdr,
+                struct svc_rdma_req_map *vec)
+{
+       int sge_no;
+       u32 sge_bytes;
+       u32 page_bytes;
+       u32 page_off;
+       int page_no = 0;
+       u8 *frva;
+       struct svc_rdma_fastreg_mr *frmr;
+
+       frmr = svc_rdma_get_frmr(xprt);
+       if (IS_ERR(frmr))
+               return -ENOMEM;
+       vec->frmr = frmr;
+
+       /* Skip the RPCRDMA header */
+       sge_no = 1;
+
+       /* Map the head. */
+       frva = (void *)((unsigned long)(xdr->head[0].iov_base) & PAGE_MASK);
+       vec->sge[sge_no].iov_base = xdr->head[0].iov_base;
+       vec->sge[sge_no].iov_len = xdr->head[0].iov_len;
+       vec->count = 2;
+       sge_no++;
+
+       /* Build the FRMR */
+       frmr->kva = frva;
+       frmr->direction = DMA_TO_DEVICE;
+       frmr->access_flags = 0;
+       frmr->map_len = PAGE_SIZE;
+       frmr->page_list_len = 1;
+       frmr->page_list->page_list[page_no] =
+               ib_dma_map_single(xprt->sc_cm_id->device,
+                                 (void *)xdr->head[0].iov_base,
+                                 PAGE_SIZE, DMA_TO_DEVICE);
+       if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                frmr->page_list->page_list[page_no]))
+               goto fatal_err;
+       atomic_inc(&xprt->sc_dma_used);
+
+       page_off = xdr->page_base;
+       page_bytes = xdr->page_len + page_off;
+       if (!page_bytes)
+               goto encode_tail;
+
+       /* Map the pages */
+       vec->sge[sge_no].iov_base = frva + frmr->map_len + page_off;
+       vec->sge[sge_no].iov_len = page_bytes;
+       sge_no++;
+       while (page_bytes) {
+               struct page *page;
+
+               page = xdr->pages[page_no++];
+               sge_bytes = min_t(u32, page_bytes, (PAGE_SIZE - page_off));
+               page_bytes -= sge_bytes;
+
+               frmr->page_list->page_list[page_no] =
+                       ib_dma_map_page(xprt->sc_cm_id->device, page, 0,
+                                         PAGE_SIZE, DMA_TO_DEVICE);
+               if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                        frmr->page_list->page_list[page_no]))
+                       goto fatal_err;
+
+               atomic_inc(&xprt->sc_dma_used);
+               page_off = 0; /* reset for next time through loop */
+               frmr->map_len += PAGE_SIZE;
+               frmr->page_list_len++;
+       }
+       vec->count++;
+
+ encode_tail:
+       /* Map tail */
+       if (0 == xdr->tail[0].iov_len)
+               goto done;
+
+       vec->count++;
+       vec->sge[sge_no].iov_len = xdr->tail[0].iov_len;
+
+       if (((unsigned long)xdr->tail[0].iov_base & PAGE_MASK) ==
+           ((unsigned long)xdr->head[0].iov_base & PAGE_MASK)) {
+               /*
+                * If head and tail use the same page, we don't need
+                * to map it again.
+                */
+               vec->sge[sge_no].iov_base = xdr->tail[0].iov_base;
+       } else {
+               void *va;
+
+               /* Map another page for the tail */
+               page_off = (unsigned long)xdr->tail[0].iov_base & ~PAGE_MASK;
+               va = (void *)((unsigned long)xdr->tail[0].iov_base & PAGE_MASK);
+               vec->sge[sge_no].iov_base = frva + frmr->map_len + page_off;
+
+               frmr->page_list->page_list[page_no] =
+                       ib_dma_map_single(xprt->sc_cm_id->device, va, PAGE_SIZE,
+                                         DMA_TO_DEVICE);
+               if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                        frmr->page_list->page_list[page_no]))
+                       goto fatal_err;
+               atomic_inc(&xprt->sc_dma_used);
+               frmr->map_len += PAGE_SIZE;
+               frmr->page_list_len++;
+       }
+
+ done:
+       if (svc_rdma_fastreg(xprt, frmr))
+               goto fatal_err;
+
+       return 0;
+
+ fatal_err:
+       printk("svcrdma: Error fast registering memory for xprt %p\n", xprt);
+       svc_rdma_put_frmr(xprt, frmr);
+       return -EIO;
+}
+
+static int map_xdr(struct svcxprt_rdma *xprt,
+                  struct xdr_buf *xdr,
+                  struct svc_rdma_req_map *vec)
 {
        int sge_max = (xdr->len+PAGE_SIZE-1) / PAGE_SIZE + 3;
        int sge_no;
@@ -83,6 +201,9 @@ static void xdr_to_sge(struct svcxprt_rdma *xprt,
        BUG_ON(xdr->len !=
               (xdr->head[0].iov_len + xdr->page_len + xdr->tail[0].iov_len));
 
+       if (xprt->sc_frmr_pg_list_len)
+               return fast_reg_xdr(xprt, xdr, vec);
+
        /* Skip the first sge, this is for the RPCRDMA header */
        sge_no = 1;
 
@@ -116,9 +237,12 @@ static void xdr_to_sge(struct svcxprt_rdma *xprt,
 
        BUG_ON(sge_no > sge_max);
        vec->count = sge_no;
+       return 0;
 }
 
 /* Assumptions:
+ * - We are using FRMR
+ *     - or -
  * - The specified write_len can be represented in sc_max_sge * PAGE_SIZE
  */
 static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
@@ -158,30 +282,35 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
        sge_no = 0;
 
        /* Copy the remaining SGE */
-       while (bc != 0 && xdr_sge_no < vec->count) {
-               sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
-               sge_bytes = min((size_t)bc,
-                               (size_t)(vec->sge[xdr_sge_no].iov_len-sge_off));
+       while (bc != 0) {
+               sge_bytes = min_t(size_t,
+                         bc, vec->sge[xdr_sge_no].iov_len-sge_off);
                sge[sge_no].length = sge_bytes;
-               atomic_inc(&xprt->sc_dma_used);
-               sge[sge_no].addr =
-                       ib_dma_map_single(xprt->sc_cm_id->device,
-                                         (void *)
-                                         vec->sge[xdr_sge_no].iov_base + sge_off,
-                                         sge_bytes, DMA_TO_DEVICE);
-               if (dma_mapping_error(xprt->sc_cm_id->device->dma_device,
-                                       sge[sge_no].addr))
-                       goto err;
+               if (!vec->frmr) {
+                       sge[sge_no].addr =
+                               ib_dma_map_single(xprt->sc_cm_id->device,
+                                                 (void *)
+                                                 vec->sge[xdr_sge_no].iov_base + sge_off,
+                                                 sge_bytes, DMA_TO_DEVICE);
+                       if (ib_dma_mapping_error(xprt->sc_cm_id->device,
+                                                sge[sge_no].addr))
+                               goto err;
+                       atomic_inc(&xprt->sc_dma_used);
+                       sge[sge_no].lkey = xprt->sc_dma_lkey;
+               } else {
+                       sge[sge_no].addr = (unsigned long)
+                               vec->sge[xdr_sge_no].iov_base + sge_off;
+                       sge[sge_no].lkey = vec->frmr->mr->lkey;
+               }
+               ctxt->count++;
+               ctxt->frmr = vec->frmr;
                sge_off = 0;
                sge_no++;
-               ctxt->count++;
                xdr_sge_no++;
+               BUG_ON(xdr_sge_no > vec->count);
                bc -= sge_bytes;
        }
 
-       BUG_ON(bc != 0);
-       BUG_ON(xdr_sge_no > vec->count);
-
        /* Prepare WRITE WR */
        memset(&write_wr, 0, sizeof write_wr);
        ctxt->wr_op = IB_WR_RDMA_WRITE;
@@ -226,7 +355,10 @@ static int send_write_chunks(struct svcxprt_rdma *xprt,
        res_ary = (struct rpcrdma_write_array *)
                &rdma_resp->rm_body.rm_chunks[1];
 
-       max_write = xprt->sc_max_sge * PAGE_SIZE;
+       if (vec->frmr)
+               max_write = vec->frmr->map_len;
+       else
+               max_write = xprt->sc_max_sge * PAGE_SIZE;
 
        /* Write chunks start at the pagelist */
        for (xdr_off = rqstp->rq_res.head[0].iov_len, chunk_no = 0;
@@ -297,7 +429,10 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt,
        res_ary = (struct rpcrdma_write_array *)
                &rdma_resp->rm_body.rm_chunks[2];
 
-       max_write = xprt->sc_max_sge * PAGE_SIZE;
+       if (vec->frmr)
+               max_write = vec->frmr->map_len;
+       else
+               max_write = xprt->sc_max_sge * PAGE_SIZE;
 
        /* xdr offset starts at RPC message */
        for (xdr_off = 0, chunk_no = 0;
@@ -307,7 +442,6 @@ static int send_reply_chunks(struct svcxprt_rdma *xprt,
                ch = &arg_ary->wc_array[chunk_no].wc_target;
                write_len = min(xfer_len, ch->rs_length);
 
-
                /* Prepare the reply chunk given the length actually
                 * written */
                rs_offset = get_unaligned(&(ch->rs_offset));
@@ -366,6 +500,7 @@ static int send_reply(struct svcxprt_rdma *rdma,
                      int byte_count)
 {
        struct ib_send_wr send_wr;
+       struct ib_send_wr inv_wr;
        int sge_no;
        int sge_bytes;
        int page_no;
@@ -385,27 +520,45 @@ static int send_reply(struct svcxprt_rdma *rdma,
        /* Prepare the context */
        ctxt->pages[0] = page;
        ctxt->count = 1;
+       ctxt->frmr = vec->frmr;
+       if (vec->frmr)
+               set_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags);
+       else
+               clear_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags);
 
        /* Prepare the SGE for the RPCRDMA Header */
-       atomic_inc(&rdma->sc_dma_used);
        ctxt->sge[0].addr =
                ib_dma_map_page(rdma->sc_cm_id->device,
                                page, 0, PAGE_SIZE, DMA_TO_DEVICE);
+       if (ib_dma_mapping_error(rdma->sc_cm_id->device, ctxt->sge[0].addr))
+               goto err;
+       atomic_inc(&rdma->sc_dma_used);
+
        ctxt->direction = DMA_TO_DEVICE;
+
        ctxt->sge[0].length = svc_rdma_xdr_get_reply_hdr_len(rdma_resp);
-       ctxt->sge[0].lkey = rdma->sc_phys_mr->lkey;
+       ctxt->sge[0].lkey = rdma->sc_dma_lkey;
 
        /* Determine how many of our SGE are to be transmitted */
        for (sge_no = 1; byte_count && sge_no < vec->count; sge_no++) {
                sge_bytes = min_t(size_t, vec->sge[sge_no].iov_len, byte_count);
                byte_count -= sge_bytes;
-               atomic_inc(&rdma->sc_dma_used);
-               ctxt->sge[sge_no].addr =
-                       ib_dma_map_single(rdma->sc_cm_id->device,
-                                         vec->sge[sge_no].iov_base,
-                                         sge_bytes, DMA_TO_DEVICE);
+               if (!vec->frmr) {
+                       ctxt->sge[sge_no].addr =
+                               ib_dma_map_single(rdma->sc_cm_id->device,
+                                                 vec->sge[sge_no].iov_base,
+                                                 sge_bytes, DMA_TO_DEVICE);
+                       if (ib_dma_mapping_error(rdma->sc_cm_id->device,
+                                                ctxt->sge[sge_no].addr))
+                               goto err;
+                       atomic_inc(&rdma->sc_dma_used);
+                       ctxt->sge[sge_no].lkey = rdma->sc_dma_lkey;
+               } else {
+                       ctxt->sge[sge_no].addr = (unsigned long)
+                               vec->sge[sge_no].iov_base;
+                       ctxt->sge[sge_no].lkey = vec->frmr->mr->lkey;
+               }
                ctxt->sge[sge_no].length = sge_bytes;
-               ctxt->sge[sge_no].lkey = rdma->sc_phys_mr->lkey;
        }
        BUG_ON(byte_count != 0);
 
@@ -417,11 +570,16 @@ static int send_reply(struct svcxprt_rdma *rdma,
                ctxt->pages[page_no+1] = rqstp->rq_respages[page_no];
                ctxt->count++;
                rqstp->rq_respages[page_no] = NULL;
-               /* If there are more pages than SGE, terminate SGE list */
+               /*
+                * If there are more pages than SGE, terminate SGE
+                * list so that svc_rdma_unmap_dma doesn't attempt to
+                * unmap garbage.
+                */
                if (page_no+1 >= sge_no)
                        ctxt->sge[page_no+1].length = 0;
        }
        BUG_ON(sge_no > rdma->sc_max_sge);
+       BUG_ON(sge_no > ctxt->count);
        memset(&send_wr, 0, sizeof send_wr);
        ctxt->wr_op = IB_WR_SEND;
        send_wr.wr_id = (unsigned long)ctxt;
@@ -429,12 +587,26 @@ static int send_reply(struct svcxprt_rdma *rdma,
        send_wr.num_sge = sge_no;
        send_wr.opcode = IB_WR_SEND;
        send_wr.send_flags =  IB_SEND_SIGNALED;
+       if (vec->frmr) {
+               /* Prepare INVALIDATE WR */
+               memset(&inv_wr, 0, sizeof inv_wr);
+               inv_wr.opcode = IB_WR_LOCAL_INV;
+               inv_wr.send_flags = IB_SEND_SIGNALED;
+               inv_wr.ex.invalidate_rkey =
+                       vec->frmr->mr->lkey;
+               send_wr.next = &inv_wr;
+       }
 
        ret = svc_rdma_send(rdma, &send_wr);
        if (ret)
-               svc_rdma_put_context(ctxt, 1);
+               goto err;
 
-       return ret;
+       return 0;
+
+ err:
+       svc_rdma_put_frmr(rdma, vec->frmr);
+       svc_rdma_put_context(ctxt, 1);
+       return -EIO;
 }
 
 void svc_rdma_prep_reply_hdr(struct svc_rqst *rqstp)
@@ -477,8 +649,9 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        ctxt = svc_rdma_get_context(rdma);
        ctxt->direction = DMA_TO_DEVICE;
        vec = svc_rdma_get_req_map();
-       xdr_to_sge(rdma, &rqstp->rq_res, vec);
-
+       ret = map_xdr(rdma, &rqstp->rq_res, vec);
+       if (ret)
+               goto err0;
        inline_bytes = rqstp->rq_res.len;
 
        /* Create the RDMA response header */
@@ -498,7 +671,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        if (ret < 0) {
                printk(KERN_ERR "svcrdma: failed to send write chunks, rc=%d\n",
                       ret);
-               goto error;
+               goto err1;
        }
        inline_bytes -= ret;
 
@@ -508,7 +681,7 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        if (ret < 0) {
                printk(KERN_ERR "svcrdma: failed to send reply chunks, rc=%d\n",
                       ret);
-               goto error;
+               goto err1;
        }
        inline_bytes -= ret;
 
@@ -517,9 +690,11 @@ int svc_rdma_sendto(struct svc_rqst *rqstp)
        svc_rdma_put_req_map(vec);
        dprintk("svcrdma: send_reply returns %d\n", ret);
        return ret;
- error:
+
+ err1:
+       put_page(res_page);
+ err0:
        svc_rdma_put_req_map(vec);
        svc_rdma_put_context(ctxt, 0);
-       put_page(res_page);
        return ret;
 }
index 900cb69728c691537e14e85e6f4618c0b0f79cfe..6fb493cbd29fcd2786479965bb526ba343e1b70f 100644 (file)
@@ -100,20 +100,29 @@ struct svc_rdma_op_ctxt *svc_rdma_get_context(struct svcxprt_rdma *xprt)
        ctxt->xprt = xprt;
        INIT_LIST_HEAD(&ctxt->dto_q);
        ctxt->count = 0;
+       ctxt->frmr = NULL;
        atomic_inc(&xprt->sc_ctxt_used);
        return ctxt;
 }
 
-static void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt)
+void svc_rdma_unmap_dma(struct svc_rdma_op_ctxt *ctxt)
 {
        struct svcxprt_rdma *xprt = ctxt->xprt;
        int i;
        for (i = 0; i < ctxt->count && ctxt->sge[i].length; i++) {
-               atomic_dec(&xprt->sc_dma_used);
-               ib_dma_unmap_single(xprt->sc_cm_id->device,
-                                   ctxt->sge[i].addr,
-                                   ctxt->sge[i].length,
-                                   ctxt->direction);
+               /*
+                * Unmap the DMA addr in the SGE if the lkey matches
+                * the sc_dma_lkey, otherwise, ignore it since it is
+                * an FRMR lkey and will be unmapped later when the
+                * last WR that uses it completes.
+                */
+               if (ctxt->sge[i].lkey == xprt->sc_dma_lkey) {
+                       atomic_dec(&xprt->sc_dma_used);
+                       ib_dma_unmap_single(xprt->sc_cm_id->device,
+                                           ctxt->sge[i].addr,
+                                           ctxt->sge[i].length,
+                                           ctxt->direction);
+               }
        }
 }
 
@@ -150,6 +159,7 @@ struct svc_rdma_req_map *svc_rdma_get_req_map(void)
                schedule_timeout_uninterruptible(msecs_to_jiffies(500));
        }
        map->count = 0;
+       map->frmr = NULL;
        return map;
 }
 
@@ -315,6 +325,50 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
                svc_xprt_enqueue(&xprt->sc_xprt);
 }
 
+/*
+ * Processs a completion context
+ */
+static void process_context(struct svcxprt_rdma *xprt,
+                           struct svc_rdma_op_ctxt *ctxt)
+{
+       svc_rdma_unmap_dma(ctxt);
+
+       switch (ctxt->wr_op) {
+       case IB_WR_SEND:
+               if (test_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags))
+                       svc_rdma_put_frmr(xprt, ctxt->frmr);
+               svc_rdma_put_context(ctxt, 1);
+               break;
+
+       case IB_WR_RDMA_WRITE:
+               svc_rdma_put_context(ctxt, 0);
+               break;
+
+       case IB_WR_RDMA_READ:
+       case IB_WR_RDMA_READ_WITH_INV:
+               if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) {
+                       struct svc_rdma_op_ctxt *read_hdr = ctxt->read_hdr;
+                       BUG_ON(!read_hdr);
+                       if (test_bit(RDMACTXT_F_FAST_UNREG, &ctxt->flags))
+                               svc_rdma_put_frmr(xprt, ctxt->frmr);
+                       spin_lock_bh(&xprt->sc_rq_dto_lock);
+                       set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
+                       list_add_tail(&read_hdr->dto_q,
+                                     &xprt->sc_read_complete_q);
+                       spin_unlock_bh(&xprt->sc_rq_dto_lock);
+                       svc_xprt_enqueue(&xprt->sc_xprt);
+               }
+               svc_rdma_put_context(ctxt, 0);
+               break;
+
+       default:
+               printk(KERN_ERR "svcrdma: unexpected completion type, "
+                      "opcode=%d\n",
+                      ctxt->wr_op);
+               break;
+       }
+}
+
 /*
  * Send Queue Completion Handler - potentially called on interrupt context.
  *
@@ -327,17 +381,12 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
        struct ib_cq *cq = xprt->sc_sq_cq;
        int ret;
 
-
        if (!test_and_clear_bit(RDMAXPRT_SQ_PENDING, &xprt->sc_flags))
                return;
 
        ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
        atomic_inc(&rdma_stat_sq_poll);
        while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
-               ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
-               xprt = ctxt->xprt;
-
-               svc_rdma_unmap_dma(ctxt);
                if (wc.status != IB_WC_SUCCESS)
                        /* Close the transport */
                        set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
@@ -346,35 +395,10 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
                atomic_dec(&xprt->sc_sq_count);
                wake_up(&xprt->sc_send_wait);
 
-               switch (ctxt->wr_op) {
-               case IB_WR_SEND:
-                       svc_rdma_put_context(ctxt, 1);
-                       break;
-
-               case IB_WR_RDMA_WRITE:
-                       svc_rdma_put_context(ctxt, 0);
-                       break;
-
-               case IB_WR_RDMA_READ:
-                       if (test_bit(RDMACTXT_F_LAST_CTXT, &ctxt->flags)) {
-                               struct svc_rdma_op_ctxt *read_hdr = ctxt->read_hdr;
-                               BUG_ON(!read_hdr);
-                               spin_lock_bh(&xprt->sc_rq_dto_lock);
-                               set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
-                               list_add_tail(&read_hdr->dto_q,
-                                             &xprt->sc_read_complete_q);
-                               spin_unlock_bh(&xprt->sc_rq_dto_lock);
-                               svc_xprt_enqueue(&xprt->sc_xprt);
-                       }
-                       svc_rdma_put_context(ctxt, 0);
-                       break;
+               ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
+               if (ctxt)
+                       process_context(xprt, ctxt);
 
-               default:
-                       printk(KERN_ERR "svcrdma: unexpected completion type, "
-                              "opcode=%d, status=%d\n",
-                              wc.opcode, wc.status);
-                       break;
-               }
                svc_xprt_put(&xprt->sc_xprt);
        }
 
@@ -425,10 +449,12 @@ static struct svcxprt_rdma *rdma_create_xprt(struct svc_serv *serv,
        INIT_LIST_HEAD(&cma_xprt->sc_dto_q);
        INIT_LIST_HEAD(&cma_xprt->sc_rq_dto_q);
        INIT_LIST_HEAD(&cma_xprt->sc_read_complete_q);
+       INIT_LIST_HEAD(&cma_xprt->sc_frmr_q);
        init_waitqueue_head(&cma_xprt->sc_send_wait);
 
        spin_lock_init(&cma_xprt->sc_lock);
        spin_lock_init(&cma_xprt->sc_rq_dto_lock);
+       spin_lock_init(&cma_xprt->sc_frmr_q_lock);
 
        cma_xprt->sc_ord = svcrdma_ord;
 
@@ -462,7 +488,7 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
        struct ib_recv_wr recv_wr, *bad_recv_wr;
        struct svc_rdma_op_ctxt *ctxt;
        struct page *page;
-       unsigned long pa;
+       dma_addr_t pa;
        int sge_no;
        int buflen;
        int ret;
@@ -474,13 +500,15 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
                BUG_ON(sge_no >= xprt->sc_max_sge);
                page = svc_rdma_get_page();
                ctxt->pages[sge_no] = page;
-               atomic_inc(&xprt->sc_dma_used);
                pa = ib_dma_map_page(xprt->sc_cm_id->device,
                                     page, 0, PAGE_SIZE,
                                     DMA_FROM_DEVICE);
+               if (ib_dma_mapping_error(xprt->sc_cm_id->device, pa))
+                       goto err_put_ctxt;
+               atomic_inc(&xprt->sc_dma_used);
                ctxt->sge[sge_no].addr = pa;
                ctxt->sge[sge_no].length = PAGE_SIZE;
-               ctxt->sge[sge_no].lkey = xprt->sc_phys_mr->lkey;
+               ctxt->sge[sge_no].lkey = xprt->sc_dma_lkey;
                buflen += PAGE_SIZE;
        }
        ctxt->count = sge_no;
@@ -496,6 +524,10 @@ int svc_rdma_post_recv(struct svcxprt_rdma *xprt)
                svc_rdma_put_context(ctxt, 1);
        }
        return ret;
+
+ err_put_ctxt:
+       svc_rdma_put_context(ctxt, 1);
+       return -ENOMEM;
 }
 
 /*
@@ -566,7 +598,7 @@ static int rdma_listen_handler(struct rdma_cm_id *cma_id,
                dprintk("svcrdma: Connect request on cma_id=%p, xprt = %p, "
                        "event=%d\n", cma_id, cma_id->context, event->event);
                handle_connect_req(cma_id,
-                                  event->param.conn.responder_resources);
+                                  event->param.conn.initiator_depth);
                break;
 
        case RDMA_CM_EVENT_ESTABLISHED:
@@ -686,6 +718,97 @@ static struct svc_xprt *svc_rdma_create(struct svc_serv *serv,
        return ERR_PTR(ret);
 }
 
+static struct svc_rdma_fastreg_mr *rdma_alloc_frmr(struct svcxprt_rdma *xprt)
+{
+       struct ib_mr *mr;
+       struct ib_fast_reg_page_list *pl;
+       struct svc_rdma_fastreg_mr *frmr;
+
+       frmr = kmalloc(sizeof(*frmr), GFP_KERNEL);
+       if (!frmr)
+               goto err;
+
+       mr = ib_alloc_fast_reg_mr(xprt->sc_pd, RPCSVC_MAXPAGES);
+       if (!mr)
+               goto err_free_frmr;
+
+       pl = ib_alloc_fast_reg_page_list(xprt->sc_cm_id->device,
+                                        RPCSVC_MAXPAGES);
+       if (!pl)
+               goto err_free_mr;
+
+       frmr->mr = mr;
+       frmr->page_list = pl;
+       INIT_LIST_HEAD(&frmr->frmr_list);
+       return frmr;
+
+ err_free_mr:
+       ib_dereg_mr(mr);
+ err_free_frmr:
+       kfree(frmr);
+ err:
+       return ERR_PTR(-ENOMEM);
+}
+
+static void rdma_dealloc_frmr_q(struct svcxprt_rdma *xprt)
+{
+       struct svc_rdma_fastreg_mr *frmr;
+
+       while (!list_empty(&xprt->sc_frmr_q)) {
+               frmr = list_entry(xprt->sc_frmr_q.next,
+                                 struct svc_rdma_fastreg_mr, frmr_list);
+               list_del_init(&frmr->frmr_list);
+               ib_dereg_mr(frmr->mr);
+               ib_free_fast_reg_page_list(frmr->page_list);
+               kfree(frmr);
+       }
+}
+
+struct svc_rdma_fastreg_mr *svc_rdma_get_frmr(struct svcxprt_rdma *rdma)
+{
+       struct svc_rdma_fastreg_mr *frmr = NULL;
+
+       spin_lock_bh(&rdma->sc_frmr_q_lock);
+       if (!list_empty(&rdma->sc_frmr_q)) {
+               frmr = list_entry(rdma->sc_frmr_q.next,
+                                 struct svc_rdma_fastreg_mr, frmr_list);
+               list_del_init(&frmr->frmr_list);
+               frmr->map_len = 0;
+               frmr->page_list_len = 0;
+       }
+       spin_unlock_bh(&rdma->sc_frmr_q_lock);
+       if (frmr)
+               return frmr;
+
+       return rdma_alloc_frmr(rdma);
+}
+
+static void frmr_unmap_dma(struct svcxprt_rdma *xprt,
+                          struct svc_rdma_fastreg_mr *frmr)
+{
+       int page_no;
+       for (page_no = 0; page_no < frmr->page_list_len; page_no++) {
+               dma_addr_t addr = frmr->page_list->page_list[page_no];
+               if (ib_dma_mapping_error(frmr->mr->device, addr))
+                       continue;
+               atomic_dec(&xprt->sc_dma_used);
+               ib_dma_unmap_single(frmr->mr->device, addr, PAGE_SIZE,
+                                   frmr->direction);
+       }
+}
+
+void svc_rdma_put_frmr(struct svcxprt_rdma *rdma,
+                      struct svc_rdma_fastreg_mr *frmr)
+{
+       if (frmr) {
+               frmr_unmap_dma(rdma, frmr);
+               spin_lock_bh(&rdma->sc_frmr_q_lock);
+               BUG_ON(!list_empty(&frmr->frmr_list));
+               list_add(&frmr->frmr_list, &rdma->sc_frmr_q);
+               spin_unlock_bh(&rdma->sc_frmr_q_lock);
+       }
+}
+
 /*
  * This is the xpo_recvfrom function for listening endpoints. Its
  * purpose is to accept incoming connections. The CMA callback handler
@@ -704,6 +827,8 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
        struct rdma_conn_param conn_param;
        struct ib_qp_init_attr qp_attr;
        struct ib_device_attr devattr;
+       int dma_mr_acc;
+       int need_dma_mr;
        int ret;
        int i;
 
@@ -819,15 +944,77 @@ static struct svc_xprt *svc_rdma_accept(struct svc_xprt *xprt)
        }
        newxprt->sc_qp = newxprt->sc_cm_id->qp;
 
-       /* Register all of physical memory */
-       newxprt->sc_phys_mr = ib_get_dma_mr(newxprt->sc_pd,
-                                           IB_ACCESS_LOCAL_WRITE |
-                                           IB_ACCESS_REMOTE_WRITE);
-       if (IS_ERR(newxprt->sc_phys_mr)) {
-               dprintk("svcrdma: Failed to create DMA MR ret=%d\n", ret);
+       /*
+        * Use the most secure set of MR resources based on the
+        * transport type and available memory management features in
+        * the device. Here's the table implemented below:
+        *
+        *              Fast    Global  DMA     Remote WR
+        *              Reg     LKEY    MR      Access
+        *              Sup'd   Sup'd   Needed  Needed
+        *
+        * IWARP        N       N       Y       Y
+        *              N       Y       Y       Y
+        *              Y       N       Y       N
+        *              Y       Y       N       -
+        *
+        * IB           N       N       Y       N
+        *              N       Y       N       -
+        *              Y       N       Y       N
+        *              Y       Y       N       -
+        *
+        * NB:  iWARP requires remote write access for the data sink
+        *      of an RDMA_READ. IB does not.
+        */
+       if (devattr.device_cap_flags & IB_DEVICE_MEM_MGT_EXTENSIONS) {
+               newxprt->sc_frmr_pg_list_len =
+                       devattr.max_fast_reg_page_list_len;
+               newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_FAST_REG;
+       }
+
+       /*
+        * Determine if a DMA MR is required and if so, what privs are required
+        */
+       switch (rdma_node_get_transport(newxprt->sc_cm_id->device->node_type)) {
+       case RDMA_TRANSPORT_IWARP:
+               newxprt->sc_dev_caps |= SVCRDMA_DEVCAP_READ_W_INV;
+               if (!(newxprt->sc_dev_caps & SVCRDMA_DEVCAP_FAST_REG)) {
+                       need_dma_mr = 1;
+                       dma_mr_acc =
+                               (IB_ACCESS_LOCAL_WRITE |
+                                IB_ACCESS_REMOTE_WRITE);
+               } else if (!(devattr.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)) {
+                       need_dma_mr = 1;
+                       dma_mr_acc = IB_ACCESS_LOCAL_WRITE;
+               } else
+                       need_dma_mr = 0;
+               break;
+       case RDMA_TRANSPORT_IB:
+               if (!(devattr.device_cap_flags & IB_DEVICE_LOCAL_DMA_LKEY)) {
+                       need_dma_mr = 1;
+                       dma_mr_acc = IB_ACCESS_LOCAL_WRITE;
+               } else
+                       need_dma_mr = 0;
+               break;
+       default:
                goto errout;
        }
 
+       /* Create the DMA MR if needed, otherwise, use the DMA LKEY */
+       if (need_dma_mr) {
+               /* Register all of physical memory */
+               newxprt->sc_phys_mr =
+                       ib_get_dma_mr(newxprt->sc_pd, dma_mr_acc);
+               if (IS_ERR(newxprt->sc_phys_mr)) {
+                       dprintk("svcrdma: Failed to create DMA MR ret=%d\n",
+                               ret);
+                       goto errout;
+               }
+               newxprt->sc_dma_lkey = newxprt->sc_phys_mr->lkey;
+       } else
+               newxprt->sc_dma_lkey =
+                       newxprt->sc_cm_id->device->local_dma_lkey;
+
        /* Post receive buffers */
        for (i = 0; i < newxprt->sc_max_requests; i++) {
                ret = svc_rdma_post_recv(newxprt);
@@ -961,6 +1148,9 @@ static void __svc_rdma_free(struct work_struct *work)
        WARN_ON(atomic_read(&rdma->sc_ctxt_used) != 0);
        WARN_ON(atomic_read(&rdma->sc_dma_used) != 0);
 
+       /* De-allocate fastreg mr */
+       rdma_dealloc_frmr_q(rdma);
+
        /* Destroy the QP if present (not a listener) */
        if (rdma->sc_qp && !IS_ERR(rdma->sc_qp))
                ib_destroy_qp(rdma->sc_qp);
@@ -1014,21 +1204,59 @@ static int svc_rdma_has_wspace(struct svc_xprt *xprt)
        return 1;
 }
 
+/*
+ * Attempt to register the kvec representing the RPC memory with the
+ * device.
+ *
+ * Returns:
+ *  NULL : The device does not support fastreg or there were no more
+ *         fastreg mr.
+ *  frmr : The kvec register request was successfully posted.
+ *    <0 : An error was encountered attempting to register the kvec.
+ */
+int svc_rdma_fastreg(struct svcxprt_rdma *xprt,
+                    struct svc_rdma_fastreg_mr *frmr)
+{
+       struct ib_send_wr fastreg_wr;
+       u8 key;
+
+       /* Bump the key */
+       key = (u8)(frmr->mr->lkey & 0x000000FF);
+       ib_update_fast_reg_key(frmr->mr, ++key);
+
+       /* Prepare FASTREG WR */
+       memset(&fastreg_wr, 0, sizeof fastreg_wr);
+       fastreg_wr.opcode = IB_WR_FAST_REG_MR;
+       fastreg_wr.send_flags = IB_SEND_SIGNALED;
+       fastreg_wr.wr.fast_reg.iova_start = (unsigned long)frmr->kva;
+       fastreg_wr.wr.fast_reg.page_list = frmr->page_list;
+       fastreg_wr.wr.fast_reg.page_list_len = frmr->page_list_len;
+       fastreg_wr.wr.fast_reg.page_shift = PAGE_SHIFT;
+       fastreg_wr.wr.fast_reg.length = frmr->map_len;
+       fastreg_wr.wr.fast_reg.access_flags = frmr->access_flags;
+       fastreg_wr.wr.fast_reg.rkey = frmr->mr->lkey;
+       return svc_rdma_send(xprt, &fastreg_wr);
+}
+
 int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
 {
-       struct ib_send_wr *bad_wr;
+       struct ib_send_wr *bad_wr, *n_wr;
+       int wr_count;
+       int i;
        int ret;
 
        if (test_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags))
                return -ENOTCONN;
 
        BUG_ON(wr->send_flags != IB_SEND_SIGNALED);
-       BUG_ON(((struct svc_rdma_op_ctxt *)(unsigned long)wr->wr_id)->wr_op !=
-               wr->opcode);
+       wr_count = 1;
+       for (n_wr = wr->next; n_wr; n_wr = n_wr->next)
+               wr_count++;
+
        /* If the SQ is full, wait until an SQ entry is available */
        while (1) {
                spin_lock_bh(&xprt->sc_lock);
-               if (xprt->sc_sq_depth == atomic_read(&xprt->sc_sq_count)) {
+               if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
                        spin_unlock_bh(&xprt->sc_lock);
                        atomic_inc(&rdma_stat_sq_starve);
 
@@ -1043,19 +1271,26 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
                                return 0;
                        continue;
                }
-               /* Bumped used SQ WR count and post */
-               svc_xprt_get(&xprt->sc_xprt);
+               /* Take a transport ref for each WR posted */
+               for (i = 0; i < wr_count; i++)
+                       svc_xprt_get(&xprt->sc_xprt);
+
+               /* Bump used SQ WR count and post */
+               atomic_add(wr_count, &xprt->sc_sq_count);
                ret = ib_post_send(xprt->sc_qp, wr, &bad_wr);
-               if (!ret)
-                       atomic_inc(&xprt->sc_sq_count);
-               else {
-                       svc_xprt_put(&xprt->sc_xprt);
+               if (ret) {
+                       set_bit(XPT_CLOSE, &xprt->sc_xprt.xpt_flags);
+                       atomic_sub(wr_count, &xprt->sc_sq_count);
+                       for (i = 0; i < wr_count; i ++)
+                               svc_xprt_put(&xprt->sc_xprt);
                        dprintk("svcrdma: failed to post SQ WR rc=%d, "
                               "sc_sq_count=%d, sc_sq_depth=%d\n",
                               ret, atomic_read(&xprt->sc_sq_count),
                               xprt->sc_sq_depth);
                }
                spin_unlock_bh(&xprt->sc_lock);
+               if (ret)
+                       wake_up(&xprt->sc_send_wait);
                break;
        }
        return ret;
@@ -1079,10 +1314,14 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,
        length = svc_rdma_xdr_encode_error(xprt, rmsgp, err, va);
 
        /* Prepare SGE for local address */
-       atomic_inc(&xprt->sc_dma_used);
        sge.addr = ib_dma_map_page(xprt->sc_cm_id->device,
                                   p, 0, PAGE_SIZE, DMA_FROM_DEVICE);
-       sge.lkey = xprt->sc_phys_mr->lkey;
+       if (ib_dma_mapping_error(xprt->sc_cm_id->device, sge.addr)) {
+               put_page(p);
+               return;
+       }
+       atomic_inc(&xprt->sc_dma_used);
+       sge.lkey = xprt->sc_dma_lkey;
        sge.length = length;
 
        ctxt = svc_rdma_get_context(xprt);
@@ -1103,6 +1342,9 @@ void svc_rdma_send_error(struct svcxprt_rdma *xprt, struct rpcrdma_msg *rmsgp,
        if (ret) {
                dprintk("svcrdma: Error %d posting send for protocol error\n",
                        ret);
+               ib_dma_unmap_page(xprt->sc_cm_id->device,
+                                 sge.addr, PAGE_SIZE,
+                                 DMA_FROM_DEVICE);
                svc_rdma_put_context(ctxt, 1);
        }
 }
index 4486c59c3aca87d6102a372255246a326b9efdc6..9a288d5eea646e65953bf92b015f2e557d15239e 100644 (file)
@@ -3,8 +3,8 @@
  *
  * Client-side transport implementation for sockets.
  *
- * TCP callback races fixes (C) 1998 Red Hat Software <alan@redhat.com>
- * TCP send fixes (C) 1998 Red Hat Software <alan@redhat.com>
+ * TCP callback races fixes (C) 1998 Red Hat
+ * TCP send fixes (C) 1998 Red Hat
  * TCP NFS related read + write fixes
  *  (C) 1999 Dave Airlie, University of Limerick, Ireland <airlied@linux.ie>
  *
index 015606b54d9b28325aad62a71ea4fc160b686cd8..c647aab8d418c508c9088789c847fae59745c049 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * NET4:       Implementation of BSD Unix domain sockets.
  *
- * Authors:    Alan Cox, <alan.cox@linux.org>
+ * Authors:    Alan Cox, <alan@lxorguk.ukuu.org.uk>
  *
  *             This program is free software; you can redistribute it and/or
  *             modify it under the terms of the GNU General Public License
diff --git a/scripts/bootgraph.pl b/scripts/bootgraph.pl
new file mode 100644 (file)
index 0000000..2243353
--- /dev/null
@@ -0,0 +1,147 @@
+#!/usr/bin/perl
+
+# Copyright 2008, Intel Corporation
+#
+# This file is part of the Linux kernel
+#
+# This program file is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation; version 2 of the License.
+#
+# This program is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+# for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program in a file named COPYING; if not, write to the
+# Free Software Foundation, Inc.,
+# 51 Franklin Street, Fifth Floor,
+# Boston, MA 02110-1301 USA
+#
+# Authors:
+#      Arjan van de Ven <arjan@linux.intel.com>
+
+
+#
+# This script turns a dmesg output into a SVG graphic that shows which
+# functions take how much time. You can view SVG graphics with various
+# programs, including Inkscape, The Gimp and Firefox.
+#
+#
+# For this script to work, the kernel needs to be compiled with the
+# CONFIG_PRINTK_TIME configuration option enabled, and with
+# "initcall_debug" passed on the kernel command line.
+#
+# usage:
+#      dmesg | perl scripts/bootgraph.pl > output.svg
+#
+
+my @rows;
+my %start, %end, %row;
+my $done = 0;
+my $rowcount = 0;
+my $maxtime = 0;
+my $firsttime = 100;
+my $count = 0;
+while (<>) {
+       my $line = $_;
+       if ($line =~ /([0-9\.]+)\] calling  ([a-zA-Z0-9\_]+)\+/) {
+               my $func = $2;
+               if ($done == 0) {
+                       $start{$func} = $1;
+                       if ($1 < $firsttime) {
+                               $firsttime = $1;
+                       }
+               }
+               $row{$func} = 1;
+               if ($line =~ /\@ ([0-9]+)/) {
+                       my $pid = $1;
+                       if (!defined($rows[$pid])) {
+                               $rowcount = $rowcount + 1;
+                               $rows[$pid] = $rowcount;
+                       }
+                       $row{$func} = $rows[$pid];
+               }
+               $count = $count + 1;
+       }
+
+       if ($line =~ /([0-9\.]+)\] initcall ([a-zA-Z0-9\_]+)\+.*returned/) {
+               if ($done == 0) {
+                       $end{$2} = $1;
+                       $maxtime = $1;
+               }
+       }
+       if ($line =~ /Write protecting the/) {
+               $done = 1;
+       }
+       if ($line =~ /Freeing unused kernel memory/) {
+               $done = 1;
+       }
+}
+
+if ($count == 0) {
+       print "No data found in the dmesg. Make sure that 'printk.time=1' and\n";
+       print "'initcall_debug' are passed on the kernel command line.\n\n";
+       print "Usage: \n";
+       print "      dmesg | perl scripts/bootgraph.pl > output.svg\n\n";
+       exit;
+}
+
+print "<?xml version=\"1.0\" standalone=\"no\"?> \n";
+print "<svg width=\"1000\" height=\"100%\" version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\">\n";
+
+my @styles;
+
+$styles[0] = "fill:rgb(0,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[1] = "fill:rgb(0,255,0);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[2] = "fill:rgb(255,0,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[3] = "fill:rgb(255,255,20);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[4] = "fill:rgb(255,0,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[5] = "fill:rgb(0,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[6] = "fill:rgb(0,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[7] = "fill:rgb(0,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[8] = "fill:rgb(255,0,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[9] = "fill:rgb(255,255,128);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[10] = "fill:rgb(255,128,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+$styles[11] = "fill:rgb(128,255,255);fill-opacity:0.5;stroke-width:1;stroke:rgb(0,0,0)";
+
+my $mult = 950.0 / ($maxtime - $firsttime);
+my $threshold = ($maxtime - $firsttime) / 60.0;
+my $stylecounter = 0;
+while (($key,$value) = each %start) {
+       my $duration = $end{$key} - $start{$key};
+
+       if ($duration >= $threshold) {
+               my $s, $s2, $e, $y;
+               $s = ($value - $firsttime) * $mult;
+               $s2 = $s + 6;
+               $e = ($end{$key} - $firsttime) * $mult;
+               $w = $e - $s;
+
+               $y = $row{$key} * 150;
+               $y2 = $y + 4;
+
+               $style = $styles[$stylecounter];
+               $stylecounter = $stylecounter + 1;
+               if ($stylecounter > 11) {
+                       $stylecounter = 0;
+               };
+
+               print "<rect x=\"$s\" width=\"$w\" y=\"$y\" height=\"145\" style=\"$style\"/>\n";
+               print "<text transform=\"translate($s2,$y2) rotate(90)\">$key</text>\n";
+       }
+}
+
+
+# print the time line on top
+my $time = $firsttime;
+my $step = ($maxtime - $firsttime) / 15;
+while ($time < $maxtime) {
+       my $s2 = ($time - $firsttime) * $mult;
+       my $tm = int($time * 100) / 100.0;
+       print "<text transform=\"translate($s2,89) rotate(90)\">$tm</text>\n";
+       $time = $time + $step;
+}
+
+print "</svg>\n";
index 83e90057270ead89f272ffe34fd6c3515a2b8a28..c13a178383ba0215e3edf14fca8d902973c88cc6 100644 (file)
@@ -87,8 +87,7 @@ static void snd_tea575x_set_freq(struct snd_tea575x *tea)
 static int snd_tea575x_ioctl(struct inode *inode, struct file *file,
                             unsigned int cmd, unsigned long data)
 {
-       struct video_device *dev = video_devdata(file);
-       struct snd_tea575x *tea = video_get_drvdata(dev);
+       struct snd_tea575x *tea = video_drvdata(file);
        void __user *arg = (void __user *)data;
        
        switch(cmd) {
@@ -175,6 +174,21 @@ static void snd_tea575x_release(struct video_device *vfd)
 {
 }
 
+static int snd_tea575x_exclusive_open(struct inode *inode, struct file *file)
+{
+       struct snd_tea575x *tea = video_drvdata(file);
+
+       return test_and_set_bit(0, &tea->in_use) ? -EBUSY : 0;
+}
+
+static int snd_tea575x_exclusive_release(struct inode *inode, struct file *file)
+{
+       struct snd_tea575x *tea = video_drvdata(file);
+
+       clear_bit(0, &tea->in_use);
+       return 0;
+}
+
 /*
  * initialize all the tea575x chips
  */
@@ -193,9 +207,10 @@ void snd_tea575x_init(struct snd_tea575x *tea)
        tea->vd.release = snd_tea575x_release;
        video_set_drvdata(&tea->vd, tea);
        tea->vd.fops = &tea->fops;
+       tea->in_use = 0;
        tea->fops.owner = tea->card->module;
-       tea->fops.open = video_exclusive_open;
-       tea->fops.release = video_exclusive_release;
+       tea->fops.open = snd_tea575x_exclusive_open;
+       tea->fops.release = snd_tea575x_exclusive_release;
        tea->fops.ioctl = snd_tea575x_ioctl;
        if (video_register_device(&tea->vd, VFL_TYPE_RADIO, tea->dev_nr - 1) < 0) {
                snd_printk(KERN_ERR "unable to register tea575x tuner\n");