summaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/media/common/Kconfig4
-rw-r--r--drivers/media/common/Makefile1
-rw-r--r--drivers/media/common/btcx-risc.h6
-rw-r--r--drivers/media/dvb-core/dvb_net.c88
-rw-r--r--drivers/media/dvb-frontends/Kconfig4
-rw-r--r--drivers/media/dvb-frontends/au8522.h5
-rw-r--r--drivers/media/dvb-frontends/dib8000.c3
-rw-r--r--drivers/media/dvb-frontends/hd29l2.c10
-rw-r--r--drivers/media/dvb-frontends/lg2160.c6
-rw-r--r--drivers/media/dvb-frontends/lgdt3305.c23
-rw-r--r--drivers/media/dvb-frontends/lgdt3305.h6
-rw-r--r--drivers/media/dvb-frontends/lgdt330x.c6
-rw-r--r--drivers/media/dvb-frontends/lgdt330x.h6
-rw-r--r--drivers/media/dvb-frontends/lgdt330x_priv.h6
-rw-r--r--drivers/media/dvb-frontends/mb86a20s.c4
-rw-r--r--drivers/media/dvb-frontends/mn88472.h6
-rw-r--r--drivers/media/dvb-frontends/nxt200x.h6
-rw-r--r--drivers/media/dvb-frontends/or51132.c6
-rw-r--r--drivers/media/dvb-frontends/or51132.h6
-rw-r--r--drivers/media/dvb-frontends/rtl2830.c944
-rw-r--r--drivers/media/dvb-frontends/rtl2830.h79
-rw-r--r--drivers/media/dvb-frontends/rtl2830_priv.h24
-rw-r--r--drivers/media/dvb-frontends/rtl2832.c1336
-rw-r--r--drivers/media/dvb-frontends/rtl2832.h99
-rw-r--r--drivers/media/dvb-frontends/rtl2832_priv.h32
-rw-r--r--drivers/media/dvb-frontends/rtl2832_sdr.c1189
-rw-r--r--drivers/media/dvb-frontends/rtl2832_sdr.h57
-rw-r--r--drivers/media/dvb-frontends/s5h1409.c6
-rw-r--r--drivers/media/dvb-frontends/s5h1409.h5
-rw-r--r--drivers/media/dvb-frontends/s5h1411.c5
-rw-r--r--drivers/media/dvb-frontends/s5h1411.h5
-rw-r--r--drivers/media/dvb-frontends/si2168.c317
-rw-r--r--drivers/media/dvb-frontends/si2168.h6
-rw-r--r--drivers/media/dvb-frontends/si2168_priv.h3
-rw-r--r--drivers/media/dvb-frontends/stb0899_algo.c5
-rw-r--r--drivers/media/dvb-frontends/stb0899_drv.c7
-rw-r--r--drivers/media/dvb-frontends/tc90522.c1
-rw-r--r--drivers/media/i2c/Kconfig9
-rw-r--r--drivers/media/i2c/adv7180.c1010
-rw-r--r--drivers/media/i2c/adv7604.c76
-rw-r--r--drivers/media/i2c/adv7842.c184
-rw-r--r--drivers/media/i2c/m5mols/m5mols_core.c9
-rw-r--r--drivers/media/i2c/msp3400-driver.c8
-rw-r--r--drivers/media/i2c/mt9m032.c42
-rw-r--r--drivers/media/i2c/mt9p031.c41
-rw-r--r--drivers/media/i2c/mt9t001.c41
-rw-r--r--drivers/media/i2c/mt9v032.c43
-rw-r--r--drivers/media/i2c/s5k4ecgx.c11
-rw-r--r--drivers/media/i2c/s5k5baf.c13
-rw-r--r--drivers/media/i2c/s5k6aa.c46
-rw-r--r--drivers/media/i2c/smiapp-pll.c7
-rw-r--r--drivers/media/i2c/smiapp-pll.h8
-rw-r--r--drivers/media/i2c/smiapp/smiapp-core.c386
-rw-r--r--drivers/media/i2c/smiapp/smiapp-limits.c6
-rw-r--r--drivers/media/i2c/smiapp/smiapp-limits.h6
-rw-r--r--drivers/media/i2c/smiapp/smiapp-quirk.c14
-rw-r--r--drivers/media/i2c/smiapp/smiapp-quirk.h24
-rw-r--r--drivers/media/i2c/smiapp/smiapp-reg-defs.h6
-rw-r--r--drivers/media/i2c/smiapp/smiapp-reg.h6
-rw-r--r--drivers/media/i2c/smiapp/smiapp-regs.c6
-rw-r--r--drivers/media/i2c/smiapp/smiapp-regs.h6
-rw-r--r--drivers/media/i2c/smiapp/smiapp.h7
-rw-r--r--drivers/media/i2c/soc_camera/ov2640.c82
-rw-r--r--drivers/media/i2c/ths8200.c10
-rw-r--r--drivers/media/mmc/siano/Kconfig2
-rw-r--r--drivers/media/pci/bt8xx/Kconfig4
-rw-r--r--drivers/media/pci/bt8xx/Makefile2
-rw-r--r--drivers/media/pci/bt8xx/bt878.c6
-rw-r--r--drivers/media/pci/bt8xx/btcx-risc.c (renamed from drivers/media/common/btcx-risc.c)36
-rw-r--r--drivers/media/pci/bt8xx/btcx-risc.h26
-rw-r--r--drivers/media/pci/bt8xx/bttv-cards.c324
-rw-r--r--drivers/media/pci/bt8xx/bttv-driver.c44
-rw-r--r--drivers/media/pci/bt8xx/bttv-gpio.c6
-rw-r--r--drivers/media/pci/bt8xx/bttv-if.c6
-rw-r--r--drivers/media/pci/bt8xx/bttv-risc.c6
-rw-r--r--drivers/media/pci/bt8xx/bttv-vbi.c7
-rw-r--r--drivers/media/pci/bt8xx/bttv.h5
-rw-r--r--drivers/media/pci/bt8xx/bttvp.h20
-rw-r--r--drivers/media/pci/cx23885/Kconfig1
-rw-r--r--drivers/media/pci/cx23885/cx23885-cards.c43
-rw-r--r--drivers/media/pci/cx23885/cx23885-dvb.c376
-rw-r--r--drivers/media/pci/cx23885/cx23885-i2c.c4
-rw-r--r--drivers/media/pci/cx23885/cx23885.h3
-rw-r--r--drivers/media/pci/cx25821/Kconfig3
-rw-r--r--drivers/media/pci/cx25821/Makefile3
-rw-r--r--drivers/media/pci/cx25821/cx25821-alsa.c113
-rw-r--r--drivers/media/pci/cx25821/cx25821-core.c112
-rw-r--r--drivers/media/pci/cx25821/cx25821-video.c685
-rw-r--r--drivers/media/pci/cx25821/cx25821.h48
-rw-r--r--drivers/media/pci/cx88/cx88-blackbird.c3
-rw-r--r--drivers/media/pci/cx88/cx88-core.c7
-rw-r--r--drivers/media/pci/cx88/cx88-dvb.c4
-rw-r--r--drivers/media/pci/cx88/cx88-mpeg.c7
-rw-r--r--drivers/media/pci/cx88/cx88-tvaudio.c7
-rw-r--r--drivers/media/pci/ivtv/ivtv-irq.c22
-rw-r--r--drivers/media/pci/mantis/mantis_core.c23
-rw-r--r--drivers/media/pci/saa7134/saa7134-video.c5
-rw-r--r--drivers/media/pci/smipcie/smipcie.c12
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-core.c4
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-eeprom.c2
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-enc.c6
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-g723.c4
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-jpeg.h4
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-tw28.c4
-rw-r--r--drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c48
-rw-r--r--drivers/media/pci/solo6x10/solo6x10.h6
-rw-r--r--drivers/media/pci/sta2x11/Kconfig1
-rw-r--r--drivers/media/pci/ttpci/av7110.c5
-rw-r--r--drivers/media/pci/ttpci/budget-core.c89
-rw-r--r--drivers/media/pci/tw68/tw68.h1
-rw-r--r--drivers/media/platform/Kconfig11
-rw-r--r--drivers/media/platform/Makefile2
-rw-r--r--drivers/media/platform/am437x/Kconfig11
-rw-r--r--drivers/media/platform/am437x/Makefile3
-rw-r--r--drivers/media/platform/am437x/am437x-vpfe.c2776
-rw-r--r--drivers/media/platform/am437x/am437x-vpfe.h283
-rw-r--r--drivers/media/platform/am437x/am437x-vpfe_regs.h140
-rw-r--r--drivers/media/platform/coda/coda-bit.c25
-rw-r--r--drivers/media/platform/coda/coda-common.c165
-rw-r--r--drivers/media/platform/coda/coda.h2
-rw-r--r--drivers/media/platform/coda/coda_regs.h4
-rw-r--r--drivers/media/platform/davinci/Kconfig6
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-core.h12
-rw-r--r--drivers/media/platform/exynos-gsc/gsc-m2m.c6
-rw-r--r--drivers/media/platform/marvell-ccic/Kconfig3
-rw-r--r--drivers/media/platform/marvell-ccic/mcam-core.c1
-rw-r--r--drivers/media/platform/omap3isp/isp.c3
-rw-r--r--drivers/media/platform/s3c-camif/camif-capture.c17
-rw-r--r--drivers/media/platform/s5p-g2d/g2d.c1
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc.c1
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_dec.c23
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_enc.c21
-rw-r--r--drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c6
-rw-r--r--drivers/media/platform/s5p-tv/mixer_video.c21
-rw-r--r--drivers/media/platform/sh_veu.c35
-rw-r--r--drivers/media/platform/soc_camera/atmel-isi.c7
-rw-r--r--drivers/media/platform/soc_camera/mx3_camera.c7
-rw-r--r--drivers/media/platform/soc_camera/rcar_vin.c94
-rw-r--r--drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c7
-rw-r--r--drivers/media/platform/soc_camera/soc_camera.c18
-rw-r--r--drivers/media/platform/ti-vpe/vpe.c162
-rw-r--r--drivers/media/platform/vivid/vivid-ctrls.c4
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.c10
-rw-r--r--drivers/media/platform/vivid/vivid-tpg.h1
-rw-r--r--drivers/media/platform/vsp1/vsp1.h14
-rw-r--r--drivers/media/platform/vsp1/vsp1_bru.c2
-rw-r--r--drivers/media/platform/vsp1/vsp1_drv.c81
-rw-r--r--drivers/media/platform/vsp1/vsp1_hsit.c5
-rw-r--r--drivers/media/platform/vsp1/vsp1_regs.h4
-rw-r--r--drivers/media/platform/vsp1/vsp1_rpf.c18
-rw-r--r--drivers/media/platform/vsp1/vsp1_rwpf.h1
-rw-r--r--drivers/media/platform/vsp1/vsp1_wpf.c13
-rw-r--r--drivers/media/radio/radio-aimslab.c4
-rw-r--r--drivers/media/radio/tea575x.c41
-rw-r--r--drivers/media/radio/wl128x/fmdrv_rx.c16
-rw-r--r--drivers/media/radio/wl128x/fmdrv_rx.h1
-rw-r--r--drivers/media/rc/img-ir/Kconfig15
-rw-r--r--drivers/media/rc/img-ir/Makefile2
-rw-r--r--drivers/media/rc/img-ir/img-ir-hw.c84
-rw-r--r--drivers/media/rc/img-ir/img-ir-hw.h24
-rw-r--r--drivers/media/rc/img-ir/img-ir-jvc.c8
-rw-r--r--drivers/media/rc/img-ir/img-ir-nec.c24
-rw-r--r--drivers/media/rc/img-ir/img-ir-rc5.c88
-rw-r--r--drivers/media/rc/img-ir/img-ir-rc6.c117
-rw-r--r--drivers/media/rc/img-ir/img-ir-sanyo.c8
-rw-r--r--drivers/media/rc/img-ir/img-ir-sharp.c8
-rw-r--r--drivers/media/rc/img-ir/img-ir-sony.c12
-rw-r--r--drivers/media/rc/lirc_dev.c6
-rw-r--r--drivers/media/rc/rc-main.c14
-rw-r--r--drivers/media/rc/sunxi-cir.c46
-rw-r--r--drivers/media/tuners/mt20xx.c8
-rw-r--r--drivers/media/tuners/mt2131.c5
-rw-r--r--drivers/media/tuners/mt2131.h5
-rw-r--r--drivers/media/tuners/mt2131_priv.h5
-rw-r--r--drivers/media/tuners/mxl5007t.c8
-rw-r--r--drivers/media/tuners/mxl5007t.h9
-rw-r--r--drivers/media/tuners/si2157.c189
-rw-r--r--drivers/media/tuners/si2157_priv.h3
-rw-r--r--drivers/media/tuners/tda18271-fe.c8
-rw-r--r--drivers/media/tuners/tda18271-maps.c8
-rw-r--r--drivers/media/tuners/tda18271-priv.h8
-rw-r--r--drivers/media/tuners/tda827x.c8
-rw-r--r--drivers/media/tuners/tda8290.c8
-rw-r--r--drivers/media/tuners/tda9887.c8
-rw-r--r--drivers/media/tuners/tuner-simple.c8
-rw-r--r--drivers/media/usb/au0828/Kconfig2
-rw-r--r--drivers/media/usb/au0828/au0828-cards.c2
-rw-r--r--drivers/media/usb/au0828/au0828-vbi.c122
-rw-r--r--drivers/media/usb/au0828/au0828-video.c976
-rw-r--r--drivers/media/usb/au0828/au0828.h61
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-cards.c9
-rw-r--r--drivers/media/usb/cx231xx/cx231xx-video.c1
-rw-r--r--drivers/media/usb/cx231xx/cx231xx.h10
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb.h2
-rw-r--r--drivers/media/usb/dvb-usb-v2/dvb_usb_core.c1
-rw-r--r--drivers/media/usb/dvb-usb-v2/lmedm04.c336
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c8
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h9
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.c6
-rw-r--r--drivers/media/usb/dvb-usb-v2/mxl111sf.h6
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.c940
-rw-r--r--drivers/media/usb/dvb-usb-v2/rtl28xxu.h27
-rw-r--r--drivers/media/usb/dvb-usb/m920x.c5
-rw-r--r--drivers/media/usb/em28xx/em28xx-audio.c8
-rw-r--r--drivers/media/usb/em28xx/em28xx-core.c4
-rw-r--r--drivers/media/usb/em28xx/em28xx-dvb.c14
-rw-r--r--drivers/media/usb/em28xx/em28xx-input.c9
-rw-r--r--drivers/media/usb/em28xx/em28xx-video.c7
-rw-r--r--drivers/media/usb/gspca/Kconfig10
-rw-r--r--drivers/media/usb/gspca/Makefile2
-rw-r--r--drivers/media/usb/gspca/gspca.c2
-rw-r--r--drivers/media/usb/gspca/ov534.c10
-rw-r--r--drivers/media/usb/gspca/stv06xx/stv06xx.c4
-rw-r--r--drivers/media/usb/gspca/touptek.c731
-rw-r--r--drivers/media/usb/gspca/vc032x.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-audio.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-audio.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-context.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-context.h9
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-ctrl.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-ctrl.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c12
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-debug.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-debugifc.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-debugifc.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-devattr.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-devattr.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-eeprom.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-eeprom.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-encoder.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-encoder.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-fx2-cmd.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.c50
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-hdw.h13
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-i2c-core.h11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-io.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-io.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-ioread.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-ioread.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-main.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-std.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-std.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-sysfs.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-sysfs.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-util.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-v4l2.c10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-v4l2.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-video-v4l.c11
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-video-v4l.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-wm8775.c12
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2-wm8775.h10
-rw-r--r--drivers/media/usb/pvrusb2/pvrusb2.h10
-rw-r--r--drivers/media/usb/pwc/pwc-if.c12
-rw-r--r--drivers/media/usb/s2255/s2255drv.c4
-rw-r--r--drivers/media/usb/siano/Kconfig2
-rw-r--r--drivers/media/usb/stk1160/stk1160-v4l.c5
-rw-r--r--drivers/media/usb/stkwebcam/stk-webcam.c1
-rw-r--r--drivers/media/usb/tm6000/tm6000-video.c3
-rw-r--r--drivers/media/usb/usbvision/usbvision-core.c13
-rw-r--r--drivers/media/usb/usbvision/usbvision-i2c.c8
-rw-r--r--drivers/media/usb/usbvision/usbvision-video.c8
-rw-r--r--drivers/media/usb/usbvision/usbvision.h8
-rw-r--r--drivers/media/usb/uvc/uvc_driver.c5
-rw-r--r--drivers/media/usb/uvc/uvc_queue.c19
-rw-r--r--drivers/media/usb/uvc/uvc_v4l2.c1
-rw-r--r--drivers/media/usb/uvc/uvc_video.c6
-rw-r--r--drivers/media/usb/uvc/uvcvideo.h3
-rw-r--r--drivers/media/usb/zr364xx/zr364xx.c2
-rw-r--r--drivers/media/v4l2-core/v4l2-dev.c35
-rw-r--r--drivers/media/v4l2-core/v4l2-ioctl.c10
-rw-r--r--drivers/media/v4l2-core/v4l2-subdev.c8
-rw-r--r--drivers/media/v4l2-core/videobuf-dma-sg.c15
-rw-r--r--drivers/media/v4l2-core/videobuf2-vmalloc.c9
-rw-r--r--drivers/staging/media/Kconfig6
-rw-r--r--drivers/staging/media/Makefile4
-rw-r--r--drivers/staging/media/bcm2048/radio-bcm2048.c6
-rw-r--r--drivers/staging/media/davinci_vpfe/dm365_isif.c69
-rw-r--r--drivers/staging/media/lirc/lirc_serial.c10
-rw-r--r--drivers/staging/media/lirc/lirc_zilog.c118
-rw-r--r--drivers/staging/media/mn88472/mn88472.c63
-rw-r--r--drivers/staging/media/mn88472/mn88472_priv.h1
-rw-r--r--drivers/staging/media/omap4iss/iss.c111
-rw-r--r--drivers/staging/media/omap4iss/iss_csi2.c43
-rw-r--r--drivers/staging/media/omap4iss/iss_csi2.h2
-rw-r--r--drivers/staging/media/omap4iss/iss_ipipeif.c22
-rw-r--r--drivers/staging/media/omap4iss/iss_regs.h2
-rw-r--r--drivers/staging/media/omap4iss/iss_resizer.c18
-rw-r--r--drivers/staging/media/omap4iss/iss_video.c16
-rw-r--r--drivers/staging/media/parport/Kconfig69
-rw-r--r--drivers/staging/media/parport/Makefile4
-rw-r--r--drivers/staging/media/parport/bw-qcam.c1177
-rw-r--r--drivers/staging/media/parport/c-qcam.c882
-rw-r--r--drivers/staging/media/parport/pms.c1156
-rw-r--r--drivers/staging/media/parport/w9966.c980
-rw-r--r--drivers/staging/media/tlg2300/Kconfig21
-rw-r--r--drivers/staging/media/tlg2300/Makefile9
-rw-r--r--drivers/staging/media/tlg2300/pd-alsa.c337
-rw-r--r--drivers/staging/media/tlg2300/pd-common.h271
-rw-r--r--drivers/staging/media/tlg2300/pd-dvb.c597
-rw-r--r--drivers/staging/media/tlg2300/pd-main.c553
-rw-r--r--drivers/staging/media/tlg2300/pd-radio.c339
-rw-r--r--drivers/staging/media/tlg2300/pd-video.c1570
-rw-r--r--drivers/staging/media/tlg2300/vendorcmds.h243
-rw-r--r--drivers/staging/media/vino/Kconfig24
-rw-r--r--drivers/staging/media/vino/Makefile3
-rw-r--r--drivers/staging/media/vino/indycam.c378
-rw-r--r--drivers/staging/media/vino/indycam.h93
-rw-r--r--drivers/staging/media/vino/saa7191.c649
-rw-r--r--drivers/staging/media/vino/saa7191.h245
-rw-r--r--drivers/staging/media/vino/vino.c4345
-rw-r--r--drivers/staging/media/vino/vino.h138
-rw-r--r--drivers/video/hdmi.c822
326 files changed, 11580 insertions, 21269 deletions
diff --git a/drivers/media/common/Kconfig b/drivers/media/common/Kconfig
index b85f88c8ddbd..21154dd87b0b 100644
--- a/drivers/media/common/Kconfig
+++ b/drivers/media/common/Kconfig
@@ -8,10 +8,6 @@ comment "common driver options"
8config VIDEO_CX2341X 8config VIDEO_CX2341X
9 tristate 9 tristate
10 10
11config VIDEO_BTCX
12 depends on PCI
13 tristate
14
15config VIDEO_TVEEPROM 11config VIDEO_TVEEPROM
16 tristate 12 tristate
17 depends on I2C 13 depends on I2C
diff --git a/drivers/media/common/Makefile b/drivers/media/common/Makefile
index d208de3b7cc0..89b795df2cdd 100644
--- a/drivers/media/common/Makefile
+++ b/drivers/media/common/Makefile
@@ -1,5 +1,4 @@
1obj-y += b2c2/ saa7146/ siano/ 1obj-y += b2c2/ saa7146/ siano/
2obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o 2obj-$(CONFIG_VIDEO_CX2341X) += cx2341x.o
3obj-$(CONFIG_VIDEO_BTCX) += btcx-risc.o
4obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o 3obj-$(CONFIG_VIDEO_TVEEPROM) += tveeprom.o
5obj-$(CONFIG_CYPRESS_FIRMWARE) += cypress_firmware.o 4obj-$(CONFIG_CYPRESS_FIRMWARE) += cypress_firmware.o
diff --git a/drivers/media/common/btcx-risc.h b/drivers/media/common/btcx-risc.h
index f8bc6e8e7b51..03583ef90506 100644
--- a/drivers/media/common/btcx-risc.h
+++ b/drivers/media/common/btcx-risc.h
@@ -26,9 +26,3 @@ void btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips);
26void btcx_calc_skips(int line, int width, int *maxy, 26void btcx_calc_skips(int line, int width, int *maxy,
27 struct btcx_skiplist *skips, unsigned int *nskips, 27 struct btcx_skiplist *skips, unsigned int *nskips,
28 const struct v4l2_clip *clips, unsigned int nclips); 28 const struct v4l2_clip *clips, unsigned int nclips);
29
30/*
31 * Local variables:
32 * c-basic-offset: 8
33 * End:
34 */
diff --git a/drivers/media/dvb-core/dvb_net.c b/drivers/media/dvb-core/dvb_net.c
index e4041f074909..686d3277dad1 100644
--- a/drivers/media/dvb-core/dvb_net.c
+++ b/drivers/media/dvb-core/dvb_net.c
@@ -68,13 +68,6 @@
68#include "dvb_demux.h" 68#include "dvb_demux.h"
69#include "dvb_net.h" 69#include "dvb_net.h"
70 70
71static int dvb_net_debug;
72module_param(dvb_net_debug, int, 0444);
73MODULE_PARM_DESC(dvb_net_debug, "enable debug messages");
74
75#define dprintk(x...) do { if (dvb_net_debug) printk(x); } while (0)
76
77
78static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt ) 71static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt )
79{ 72{
80 unsigned int j; 73 unsigned int j;
@@ -90,36 +83,9 @@ static inline __u32 iov_crc32( __u32 c, struct kvec *iov, unsigned int cnt )
90 83
91#ifdef ULE_DEBUG 84#ifdef ULE_DEBUG
92 85
93#define MAC_ADDR_PRINTFMT "%.2x:%.2x:%.2x:%.2x:%.2x:%.2x" 86static void hexdump(const unsigned char *buf, unsigned short len)
94#define MAX_ADDR_PRINTFMT_ARGS(macap) (macap)[0],(macap)[1],(macap)[2],(macap)[3],(macap)[4],(macap)[5]
95
96#define isprint(c) ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z') || (c >= '0' && c <= '9'))
97
98static void hexdump( const unsigned char *buf, unsigned short len )
99{ 87{
100 char str[80], octet[10]; 88 print_hex_dump_debug("", DUMP_PREFIX_OFFSET, 16, 1, buf, len, true);
101 int ofs, i, l;
102
103 for (ofs = 0; ofs < len; ofs += 16) {
104 sprintf( str, "%03d: ", ofs );
105
106 for (i = 0; i < 16; i++) {
107 if ((i + ofs) < len)
108 sprintf( octet, "%02x ", buf[ofs + i] );
109 else
110 strcpy( octet, " " );
111
112 strcat( str, octet );
113 }
114 strcat( str, " " );
115 l = strlen( str );
116
117 for (i = 0; (i < 16) && ((i + ofs) < len); i++)
118 str[l++] = isprint( buf[ofs + i] ) ? buf[ofs + i] : '.';
119
120 str[l] = '\0';
121 printk( KERN_WARNING "%s\n", str );
122 }
123} 89}
124 90
125#endif 91#endif
@@ -315,9 +281,9 @@ static int handle_ule_extensions( struct dvb_net_priv *p )
315 return l; /* Stop extension header processing and discard SNDU. */ 281 return l; /* Stop extension header processing and discard SNDU. */
316 total_ext_len += l; 282 total_ext_len += l;
317#ifdef ULE_DEBUG 283#ifdef ULE_DEBUG
318 dprintk("handle_ule_extensions: ule_next_hdr=%p, ule_sndu_type=%i, " 284 pr_debug("ule_next_hdr=%p, ule_sndu_type=%i, l=%i, total_ext_len=%i\n",
319 "l=%i, total_ext_len=%i\n", p->ule_next_hdr, 285 p->ule_next_hdr, (int)p->ule_sndu_type,
320 (int) p->ule_sndu_type, l, total_ext_len); 286 l, total_ext_len);
321#endif 287#endif
322 288
323 } while (p->ule_sndu_type < ETH_P_802_3_MIN); 289 } while (p->ule_sndu_type < ETH_P_802_3_MIN);
@@ -700,8 +666,8 @@ static void dvb_net_ule( struct net_device *dev, const u8 *buf, size_t buf_len )
700 666
701 if (drop) { 667 if (drop) {
702#ifdef ULE_DEBUG 668#ifdef ULE_DEBUG
703 dprintk("Dropping SNDU: MAC destination address does not match: dest addr: "MAC_ADDR_PRINTFMT", dev addr: "MAC_ADDR_PRINTFMT"\n", 669 netdev_dbg(dev, "Dropping SNDU: MAC destination address does not match: dest addr: %pM, dev addr: %pM\n",
704 MAX_ADDR_PRINTFMT_ARGS(priv->ule_skb->data), MAX_ADDR_PRINTFMT_ARGS(dev->dev_addr)); 670 priv->ule_skb->data, dev->dev_addr);
705#endif 671#endif
706 dev_kfree_skb(priv->ule_skb); 672 dev_kfree_skb(priv->ule_skb);
707 goto sndu_done; 673 goto sndu_done;
@@ -964,8 +930,7 @@ static int dvb_net_filter_sec_set(struct net_device *dev,
964 (*secfilter)->filter_mask[10] = mac_mask[1]; 930 (*secfilter)->filter_mask[10] = mac_mask[1];
965 (*secfilter)->filter_mask[11]=mac_mask[0]; 931 (*secfilter)->filter_mask[11]=mac_mask[0];
966 932
967 dprintk("%s: filter mac=%pM\n", dev->name, mac); 933 netdev_dbg(dev, "filter mac=%pM mask=%pM\n", mac, mac_mask);
968 dprintk("%s: filter mask=%pM\n", dev->name, mac_mask);
969 934
970 return 0; 935 return 0;
971} 936}
@@ -977,7 +942,7 @@ static int dvb_net_feed_start(struct net_device *dev)
977 struct dmx_demux *demux = priv->demux; 942 struct dmx_demux *demux = priv->demux;
978 unsigned char *mac = (unsigned char *) dev->dev_addr; 943 unsigned char *mac = (unsigned char *) dev->dev_addr;
979 944
980 dprintk("%s: rx_mode %i\n", __func__, priv->rx_mode); 945 netdev_dbg(dev, "rx_mode %i\n", priv->rx_mode);
981 mutex_lock(&priv->mutex); 946 mutex_lock(&priv->mutex);
982 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0]) 947 if (priv->tsfeed || priv->secfeed || priv->secfilter || priv->multi_secfilter[0])
983 printk("%s: BUG %d\n", __func__, __LINE__); 948 printk("%s: BUG %d\n", __func__, __LINE__);
@@ -987,7 +952,7 @@ static int dvb_net_feed_start(struct net_device *dev)
987 priv->tsfeed = NULL; 952 priv->tsfeed = NULL;
988 953
989 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { 954 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
990 dprintk("%s: alloc secfeed\n", __func__); 955 netdev_dbg(dev, "alloc secfeed\n");
991 ret=demux->allocate_section_feed(demux, &priv->secfeed, 956 ret=demux->allocate_section_feed(demux, &priv->secfeed,
992 dvb_net_sec_callback); 957 dvb_net_sec_callback);
993 if (ret<0) { 958 if (ret<0) {
@@ -1005,38 +970,38 @@ static int dvb_net_feed_start(struct net_device *dev)
1005 } 970 }
1006 971
1007 if (priv->rx_mode != RX_MODE_PROMISC) { 972 if (priv->rx_mode != RX_MODE_PROMISC) {
1008 dprintk("%s: set secfilter\n", __func__); 973 netdev_dbg(dev, "set secfilter\n");
1009 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal); 974 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_normal);
1010 } 975 }
1011 976
1012 switch (priv->rx_mode) { 977 switch (priv->rx_mode) {
1013 case RX_MODE_MULTI: 978 case RX_MODE_MULTI:
1014 for (i = 0; i < priv->multi_num; i++) { 979 for (i = 0; i < priv->multi_num; i++) {
1015 dprintk("%s: set multi_secfilter[%d]\n", __func__, i); 980 netdev_dbg(dev, "set multi_secfilter[%d]\n", i);
1016 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i], 981 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[i],
1017 priv->multi_macs[i], mask_normal); 982 priv->multi_macs[i], mask_normal);
1018 } 983 }
1019 break; 984 break;
1020 case RX_MODE_ALL_MULTI: 985 case RX_MODE_ALL_MULTI:
1021 priv->multi_num=1; 986 priv->multi_num=1;
1022 dprintk("%s: set multi_secfilter[0]\n", __func__); 987 netdev_dbg(dev, "set multi_secfilter[0]\n");
1023 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0], 988 dvb_net_filter_sec_set(dev, &priv->multi_secfilter[0],
1024 mac_allmulti, mask_allmulti); 989 mac_allmulti, mask_allmulti);
1025 break; 990 break;
1026 case RX_MODE_PROMISC: 991 case RX_MODE_PROMISC:
1027 priv->multi_num=0; 992 priv->multi_num=0;
1028 dprintk("%s: set secfilter\n", __func__); 993 netdev_dbg(dev, "set secfilter\n");
1029 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc); 994 dvb_net_filter_sec_set(dev, &priv->secfilter, mac, mask_promisc);
1030 break; 995 break;
1031 } 996 }
1032 997
1033 dprintk("%s: start filtering\n", __func__); 998 netdev_dbg(dev, "start filtering\n");
1034 priv->secfeed->start_filtering(priv->secfeed); 999 priv->secfeed->start_filtering(priv->secfeed);
1035 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { 1000 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
1036 struct timespec timeout = { 0, 10000000 }; // 10 msec 1001 struct timespec timeout = { 0, 10000000 }; // 10 msec
1037 1002
1038 /* we have payloads encapsulated in TS */ 1003 /* we have payloads encapsulated in TS */
1039 dprintk("%s: alloc tsfeed\n", __func__); 1004 netdev_dbg(dev, "alloc tsfeed\n");
1040 ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback); 1005 ret = demux->allocate_ts_feed(demux, &priv->tsfeed, dvb_net_ts_callback);
1041 if (ret < 0) { 1006 if (ret < 0) {
1042 printk("%s: could not allocate ts feed\n", dev->name); 1007 printk("%s: could not allocate ts feed\n", dev->name);
@@ -1060,7 +1025,7 @@ static int dvb_net_feed_start(struct net_device *dev)
1060 goto error; 1025 goto error;
1061 } 1026 }
1062 1027
1063 dprintk("%s: start filtering\n", __func__); 1028 netdev_dbg(dev, "start filtering\n");
1064 priv->tsfeed->start_filtering(priv->tsfeed); 1029 priv->tsfeed->start_filtering(priv->tsfeed);
1065 } else 1030 } else
1066 ret = -EINVAL; 1031 ret = -EINVAL;
@@ -1075,17 +1040,16 @@ static int dvb_net_feed_stop(struct net_device *dev)
1075 struct dvb_net_priv *priv = netdev_priv(dev); 1040 struct dvb_net_priv *priv = netdev_priv(dev);
1076 int i, ret = 0; 1041 int i, ret = 0;
1077 1042
1078 dprintk("%s\n", __func__);
1079 mutex_lock(&priv->mutex); 1043 mutex_lock(&priv->mutex);
1080 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) { 1044 if (priv->feedtype == DVB_NET_FEEDTYPE_MPE) {
1081 if (priv->secfeed) { 1045 if (priv->secfeed) {
1082 if (priv->secfeed->is_filtering) { 1046 if (priv->secfeed->is_filtering) {
1083 dprintk("%s: stop secfeed\n", __func__); 1047 netdev_dbg(dev, "stop secfeed\n");
1084 priv->secfeed->stop_filtering(priv->secfeed); 1048 priv->secfeed->stop_filtering(priv->secfeed);
1085 } 1049 }
1086 1050
1087 if (priv->secfilter) { 1051 if (priv->secfilter) {
1088 dprintk("%s: release secfilter\n", __func__); 1052 netdev_dbg(dev, "release secfilter\n");
1089 priv->secfeed->release_filter(priv->secfeed, 1053 priv->secfeed->release_filter(priv->secfeed,
1090 priv->secfilter); 1054 priv->secfilter);
1091 priv->secfilter=NULL; 1055 priv->secfilter=NULL;
@@ -1093,8 +1057,8 @@ static int dvb_net_feed_stop(struct net_device *dev)
1093 1057
1094 for (i=0; i<priv->multi_num; i++) { 1058 for (i=0; i<priv->multi_num; i++) {
1095 if (priv->multi_secfilter[i]) { 1059 if (priv->multi_secfilter[i]) {
1096 dprintk("%s: release multi_filter[%d]\n", 1060 netdev_dbg(dev, "release multi_filter[%d]\n",
1097 __func__, i); 1061 i);
1098 priv->secfeed->release_filter(priv->secfeed, 1062 priv->secfeed->release_filter(priv->secfeed,
1099 priv->multi_secfilter[i]); 1063 priv->multi_secfilter[i]);
1100 priv->multi_secfilter[i] = NULL; 1064 priv->multi_secfilter[i] = NULL;
@@ -1108,7 +1072,7 @@ static int dvb_net_feed_stop(struct net_device *dev)
1108 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) { 1072 } else if (priv->feedtype == DVB_NET_FEEDTYPE_ULE) {
1109 if (priv->tsfeed) { 1073 if (priv->tsfeed) {
1110 if (priv->tsfeed->is_filtering) { 1074 if (priv->tsfeed->is_filtering) {
1111 dprintk("%s: stop tsfeed\n", __func__); 1075 netdev_dbg(dev, "stop tsfeed\n");
1112 priv->tsfeed->stop_filtering(priv->tsfeed); 1076 priv->tsfeed->stop_filtering(priv->tsfeed);
1113 } 1077 }
1114 priv->demux->release_ts_feed(priv->demux, priv->tsfeed); 1078 priv->demux->release_ts_feed(priv->demux, priv->tsfeed);
@@ -1148,16 +1112,16 @@ static void wq_set_multicast_list (struct work_struct *work)
1148 netif_addr_lock_bh(dev); 1112 netif_addr_lock_bh(dev);
1149 1113
1150 if (dev->flags & IFF_PROMISC) { 1114 if (dev->flags & IFF_PROMISC) {
1151 dprintk("%s: promiscuous mode\n", dev->name); 1115 netdev_dbg(dev, "promiscuous mode\n");
1152 priv->rx_mode = RX_MODE_PROMISC; 1116 priv->rx_mode = RX_MODE_PROMISC;
1153 } else if ((dev->flags & IFF_ALLMULTI)) { 1117 } else if ((dev->flags & IFF_ALLMULTI)) {
1154 dprintk("%s: allmulti mode\n", dev->name); 1118 netdev_dbg(dev, "allmulti mode\n");
1155 priv->rx_mode = RX_MODE_ALL_MULTI; 1119 priv->rx_mode = RX_MODE_ALL_MULTI;
1156 } else if (!netdev_mc_empty(dev)) { 1120 } else if (!netdev_mc_empty(dev)) {
1157 struct netdev_hw_addr *ha; 1121 struct netdev_hw_addr *ha;
1158 1122
1159 dprintk("%s: set_mc_list, %d entries\n", 1123 netdev_dbg(dev, "set_mc_list, %d entries\n",
1160 dev->name, netdev_mc_count(dev)); 1124 netdev_mc_count(dev));
1161 1125
1162 priv->rx_mode = RX_MODE_MULTI; 1126 priv->rx_mode = RX_MODE_MULTI;
1163 priv->multi_num = 0; 1127 priv->multi_num = 0;
diff --git a/drivers/media/dvb-frontends/Kconfig b/drivers/media/dvb-frontends/Kconfig
index 6c75418222e2..bb76727d924e 100644
--- a/drivers/media/dvb-frontends/Kconfig
+++ b/drivers/media/dvb-frontends/Kconfig
@@ -443,7 +443,8 @@ config DVB_CXD2820R
443 443
444config DVB_RTL2830 444config DVB_RTL2830
445 tristate "Realtek RTL2830 DVB-T" 445 tristate "Realtek RTL2830 DVB-T"
446 depends on DVB_CORE && I2C 446 depends on DVB_CORE && I2C && I2C_MUX
447 select REGMAP
447 default m if !MEDIA_SUBDRV_AUTOSELECT 448 default m if !MEDIA_SUBDRV_AUTOSELECT
448 help 449 help
449 Say Y when you want to support this frontend. 450 Say Y when you want to support this frontend.
@@ -451,6 +452,7 @@ config DVB_RTL2830
451config DVB_RTL2832 452config DVB_RTL2832
452 tristate "Realtek RTL2832 DVB-T" 453 tristate "Realtek RTL2832 DVB-T"
453 depends on DVB_CORE && I2C && I2C_MUX 454 depends on DVB_CORE && I2C && I2C_MUX
455 select REGMAP
454 default m if !MEDIA_SUBDRV_AUTOSELECT 456 default m if !MEDIA_SUBDRV_AUTOSELECT
455 help 457 help
456 Say Y when you want to support this frontend. 458 Say Y when you want to support this frontend.
diff --git a/drivers/media/dvb-frontends/au8522.h b/drivers/media/dvb-frontends/au8522.h
index 83fe9a615619..612251958855 100644
--- a/drivers/media/dvb-frontends/au8522.h
+++ b/drivers/media/dvb-frontends/au8522.h
@@ -91,8 +91,3 @@ enum au8522_audio_input {
91}; 91};
92 92
93#endif /* __AU8522_H__ */ 93#endif /* __AU8522_H__ */
94
95/*
96 * Local variables:
97 * c-basic-offset: 8
98 */
diff --git a/drivers/media/dvb-frontends/dib8000.c b/drivers/media/dvb-frontends/dib8000.c
index 61e31f2d2f71..8c6663b6399d 100644
--- a/drivers/media/dvb-frontends/dib8000.c
+++ b/drivers/media/dvb-frontends/dib8000.c
@@ -1263,7 +1263,8 @@ static int dib8000_agc_startup(struct dvb_frontend *fe)
1263 struct dib8000_state *state = fe->demodulator_priv; 1263 struct dib8000_state *state = fe->demodulator_priv;
1264 enum frontend_tune_state *tune_state = &state->tune_state; 1264 enum frontend_tune_state *tune_state = &state->tune_state;
1265 int ret = 0; 1265 int ret = 0;
1266 u16 reg, upd_demod_gain_period = 0x8000; 1266 u16 reg;
1267 u32 upd_demod_gain_period = 0x8000;
1267 1268
1268 switch (*tune_state) { 1269 switch (*tune_state) {
1269 case CT_AGC_START: 1270 case CT_AGC_START:
diff --git a/drivers/media/dvb-frontends/hd29l2.c b/drivers/media/dvb-frontends/hd29l2.c
index d7b9d549156d..67c8e6df42e8 100644
--- a/drivers/media/dvb-frontends/hd29l2.c
+++ b/drivers/media/dvb-frontends/hd29l2.c
@@ -22,20 +22,24 @@
22 22
23#include "hd29l2_priv.h" 23#include "hd29l2_priv.h"
24 24
25#define HD29L2_MAX_LEN (3)
26
25/* write multiple registers */ 27/* write multiple registers */
26static int hd29l2_wr_regs(struct hd29l2_priv *priv, u8 reg, u8 *val, int len) 28static int hd29l2_wr_regs(struct hd29l2_priv *priv, u8 reg, u8 *val, int len)
27{ 29{
28 int ret; 30 int ret;
29 u8 buf[2 + len]; 31 u8 buf[2 + HD29L2_MAX_LEN];
30 struct i2c_msg msg[1] = { 32 struct i2c_msg msg[1] = {
31 { 33 {
32 .addr = priv->cfg.i2c_addr, 34 .addr = priv->cfg.i2c_addr,
33 .flags = 0, 35 .flags = 0,
34 .len = sizeof(buf), 36 .len = 2 + len,
35 .buf = buf, 37 .buf = buf,
36 } 38 }
37 }; 39 };
38 40
41 if (len > HD29L2_MAX_LEN)
42 return -EINVAL;
39 buf[0] = 0x00; 43 buf[0] = 0x00;
40 buf[1] = reg; 44 buf[1] = reg;
41 memcpy(&buf[2], val, len); 45 memcpy(&buf[2], val, len);
@@ -118,7 +122,7 @@ static int hd29l2_wr_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 val, u8 mask)
118} 122}
119 123
120/* read single register with mask */ 124/* read single register with mask */
121int hd29l2_rd_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 *val, u8 mask) 125static int hd29l2_rd_reg_mask(struct hd29l2_priv *priv, u8 reg, u8 *val, u8 mask)
122{ 126{
123 int ret, i; 127 int ret, i;
124 u8 tmp; 128 u8 tmp;
diff --git a/drivers/media/dvb-frontends/lg2160.c b/drivers/media/dvb-frontends/lg2160.c
index 5fd14f840ab0..99efeba3c31a 100644
--- a/drivers/media/dvb-frontends/lg2160.c
+++ b/drivers/media/dvb-frontends/lg2160.c
@@ -1456,9 +1456,3 @@ MODULE_DESCRIPTION("LG Electronics LG216x ATSC/MH Demodulator Driver");
1456MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1456MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1457MODULE_LICENSE("GPL"); 1457MODULE_LICENSE("GPL");
1458MODULE_VERSION("0.3"); 1458MODULE_VERSION("0.3");
1459
1460/*
1461 * Local variables:
1462 * c-basic-offset: 8
1463 * End:
1464 */
diff --git a/drivers/media/dvb-frontends/lgdt3305.c b/drivers/media/dvb-frontends/lgdt3305.c
index 92c891a571ab..d08570af1c10 100644
--- a/drivers/media/dvb-frontends/lgdt3305.c
+++ b/drivers/media/dvb-frontends/lgdt3305.c
@@ -236,12 +236,13 @@ static inline int lgdt3305_mpeg_mode(struct lgdt3305_state *state,
236 return lgdt3305_set_reg_bit(state, LGDT3305_TP_CTRL_1, 5, mode); 236 return lgdt3305_set_reg_bit(state, LGDT3305_TP_CTRL_1, 5, mode);
237} 237}
238 238
239static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state, 239static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state)
240 enum lgdt3305_tp_clock_edge edge,
241 enum lgdt3305_tp_valid_polarity valid)
242{ 240{
243 u8 val; 241 u8 val;
244 int ret; 242 int ret;
243 enum lgdt3305_tp_clock_edge edge = state->cfg->tpclk_edge;
244 enum lgdt3305_tp_clock_mode mode = state->cfg->tpclk_mode;
245 enum lgdt3305_tp_valid_polarity valid = state->cfg->tpvalid_polarity;
245 246
246 lg_dbg("edge = %d, valid = %d\n", edge, valid); 247 lg_dbg("edge = %d, valid = %d\n", edge, valid);
247 248
@@ -253,6 +254,8 @@ static int lgdt3305_mpeg_mode_polarity(struct lgdt3305_state *state,
253 254
254 if (edge) 255 if (edge)
255 val |= 0x08; 256 val |= 0x08;
257 if (mode)
258 val |= 0x40;
256 if (valid) 259 if (valid)
257 val |= 0x01; 260 val |= 0x01;
258 261
@@ -740,9 +743,7 @@ static int lgdt3304_set_parameters(struct dvb_frontend *fe)
740 goto fail; 743 goto fail;
741 744
742 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */ 745 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */
743 ret = lgdt3305_mpeg_mode_polarity(state, 746 ret = lgdt3305_mpeg_mode_polarity(state);
744 state->cfg->tpclk_edge,
745 state->cfg->tpvalid_polarity);
746fail: 747fail:
747 return ret; 748 return ret;
748} 749}
@@ -806,9 +807,7 @@ static int lgdt3305_set_parameters(struct dvb_frontend *fe)
806 goto fail; 807 goto fail;
807 808
808 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */ 809 /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */
809 ret = lgdt3305_mpeg_mode_polarity(state, 810 ret = lgdt3305_mpeg_mode_polarity(state);
810 state->cfg->tpclk_edge,
811 state->cfg->tpvalid_polarity);
812fail: 811fail:
813 return ret; 812 return ret;
814} 813}
@@ -1215,9 +1214,3 @@ MODULE_DESCRIPTION("LG Electronics LGDT3304/5 ATSC/QAM-B Demodulator Driver");
1215MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1214MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1216MODULE_LICENSE("GPL"); 1215MODULE_LICENSE("GPL");
1217MODULE_VERSION("0.2"); 1216MODULE_VERSION("0.2");
1218
1219/*
1220 * Local variables:
1221 * c-basic-offset: 8
1222 * End:
1223 */
diff --git a/drivers/media/dvb-frontends/lgdt3305.h b/drivers/media/dvb-frontends/lgdt3305.h
index d9ab556c1b27..9c03e530e01b 100644
--- a/drivers/media/dvb-frontends/lgdt3305.h
+++ b/drivers/media/dvb-frontends/lgdt3305.h
@@ -37,6 +37,11 @@ enum lgdt3305_tp_clock_edge {
37 LGDT3305_TPCLK_FALLING_EDGE = 1, 37 LGDT3305_TPCLK_FALLING_EDGE = 1,
38}; 38};
39 39
40enum lgdt3305_tp_clock_mode {
41 LGDT3305_TPCLK_GATED = 0,
42 LGDT3305_TPCLK_FIXED = 1,
43};
44
40enum lgdt3305_tp_valid_polarity { 45enum lgdt3305_tp_valid_polarity {
41 LGDT3305_TP_VALID_LOW = 0, 46 LGDT3305_TP_VALID_LOW = 0,
42 LGDT3305_TP_VALID_HIGH = 1, 47 LGDT3305_TP_VALID_HIGH = 1,
@@ -70,6 +75,7 @@ struct lgdt3305_config {
70 75
71 enum lgdt3305_mpeg_mode mpeg_mode; 76 enum lgdt3305_mpeg_mode mpeg_mode;
72 enum lgdt3305_tp_clock_edge tpclk_edge; 77 enum lgdt3305_tp_clock_edge tpclk_edge;
78 enum lgdt3305_tp_clock_mode tpclk_mode;
73 enum lgdt3305_tp_valid_polarity tpvalid_polarity; 79 enum lgdt3305_tp_valid_polarity tpvalid_polarity;
74 enum lgdt_demod_chip_type demod_chip; 80 enum lgdt_demod_chip_type demod_chip;
75}; 81};
diff --git a/drivers/media/dvb-frontends/lgdt330x.c b/drivers/media/dvb-frontends/lgdt330x.c
index e046622df0e4..2e1a61893fc1 100644
--- a/drivers/media/dvb-frontends/lgdt330x.c
+++ b/drivers/media/dvb-frontends/lgdt330x.c
@@ -823,9 +823,3 @@ MODULE_AUTHOR("Wilson Michaels");
823MODULE_LICENSE("GPL"); 823MODULE_LICENSE("GPL");
824 824
825EXPORT_SYMBOL(lgdt330x_attach); 825EXPORT_SYMBOL(lgdt330x_attach);
826
827/*
828 * Local variables:
829 * c-basic-offset: 8
830 * End:
831 */
diff --git a/drivers/media/dvb-frontends/lgdt330x.h b/drivers/media/dvb-frontends/lgdt330x.h
index ca0eab562e1e..8bb332219fc4 100644
--- a/drivers/media/dvb-frontends/lgdt330x.h
+++ b/drivers/media/dvb-frontends/lgdt330x.h
@@ -65,9 +65,3 @@ static inline struct dvb_frontend* lgdt330x_attach(const struct lgdt330x_config*
65#endif // CONFIG_DVB_LGDT330X 65#endif // CONFIG_DVB_LGDT330X
66 66
67#endif /* LGDT330X_H */ 67#endif /* LGDT330X_H */
68
69/*
70 * Local variables:
71 * c-basic-offset: 8
72 * End:
73 */
diff --git a/drivers/media/dvb-frontends/lgdt330x_priv.h b/drivers/media/dvb-frontends/lgdt330x_priv.h
index 38c76695abfe..1922f09a02d0 100644
--- a/drivers/media/dvb-frontends/lgdt330x_priv.h
+++ b/drivers/media/dvb-frontends/lgdt330x_priv.h
@@ -69,9 +69,3 @@ enum I2C_REG {
69}; 69};
70 70
71#endif /* _LGDT330X_PRIV_ */ 71#endif /* _LGDT330X_PRIV_ */
72
73/*
74 * Local variables:
75 * c-basic-offset: 8
76 * End:
77 */
diff --git a/drivers/media/dvb-frontends/mb86a20s.c b/drivers/media/dvb-frontends/mb86a20s.c
index e6f165a5b90d..8f54c39ca63f 100644
--- a/drivers/media/dvb-frontends/mb86a20s.c
+++ b/drivers/media/dvb-frontends/mb86a20s.c
@@ -22,10 +22,6 @@
22 22
23#define NUM_LAYERS 3 23#define NUM_LAYERS 3
24 24
25static int debug = 1;
26module_param(debug, int, 0644);
27MODULE_PARM_DESC(debug, "Activates frontend debugging (default:0)");
28
29enum mb86a20s_bandwidth { 25enum mb86a20s_bandwidth {
30 MB86A20S_13SEG = 0, 26 MB86A20S_13SEG = 0,
31 MB86A20S_13SEG_PARTIAL = 1, 27 MB86A20S_13SEG_PARTIAL = 1,
diff --git a/drivers/media/dvb-frontends/mn88472.h b/drivers/media/dvb-frontends/mn88472.h
index da4558bce60f..e4e0b80d3091 100644
--- a/drivers/media/dvb-frontends/mn88472.h
+++ b/drivers/media/dvb-frontends/mn88472.h
@@ -33,6 +33,12 @@ struct mn88472_config {
33 * DVB frontend. 33 * DVB frontend.
34 */ 34 */
35 struct dvb_frontend **fe; 35 struct dvb_frontend **fe;
36
37 /*
38 * Xtal frequency.
39 * Hz
40 */
41 u32 xtal;
36}; 42};
37 43
38#endif 44#endif
diff --git a/drivers/media/dvb-frontends/nxt200x.h b/drivers/media/dvb-frontends/nxt200x.h
index b518d545609e..e38d01fb6c2b 100644
--- a/drivers/media/dvb-frontends/nxt200x.h
+++ b/drivers/media/dvb-frontends/nxt200x.h
@@ -55,9 +55,3 @@ static inline struct dvb_frontend* nxt200x_attach(const struct nxt200x_config* c
55#endif // CONFIG_DVB_NXT200X 55#endif // CONFIG_DVB_NXT200X
56 56
57#endif /* NXT200X_H */ 57#endif /* NXT200X_H */
58
59/*
60 * Local variables:
61 * c-basic-offset: 8
62 * End:
63 */
diff --git a/drivers/media/dvb-frontends/or51132.c b/drivers/media/dvb-frontends/or51132.c
index 5ef921823c15..cbbd259eacfe 100644
--- a/drivers/media/dvb-frontends/or51132.c
+++ b/drivers/media/dvb-frontends/or51132.c
@@ -623,9 +623,3 @@ MODULE_AUTHOR("Trent Piepho");
623MODULE_LICENSE("GPL"); 623MODULE_LICENSE("GPL");
624 624
625EXPORT_SYMBOL(or51132_attach); 625EXPORT_SYMBOL(or51132_attach);
626
627/*
628 * Local variables:
629 * c-basic-offset: 8
630 * End:
631 */
diff --git a/drivers/media/dvb-frontends/or51132.h b/drivers/media/dvb-frontends/or51132.h
index 938958386cb1..cdb5be3c65d6 100644
--- a/drivers/media/dvb-frontends/or51132.h
+++ b/drivers/media/dvb-frontends/or51132.h
@@ -47,9 +47,3 @@ static inline struct dvb_frontend* or51132_attach(const struct or51132_config* c
47#endif // CONFIG_DVB_OR51132 47#endif // CONFIG_DVB_OR51132
48 48
49#endif // OR51132_H 49#endif // OR51132_H
50
51/*
52 * Local variables:
53 * c-basic-offset: 8
54 * End:
55 */
diff --git a/drivers/media/dvb-frontends/rtl2830.c b/drivers/media/dvb-frontends/rtl2830.c
index 50e8b63e5169..e1b8df62bd59 100644
--- a/drivers/media/dvb-frontends/rtl2830.c
+++ b/drivers/media/dvb-frontends/rtl2830.c
@@ -13,261 +13,154 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */
20
21
22/*
23 * Driver implements own I2C-adapter for tuner I2C access. That's since chip
24 * have unusual I2C-gate control which closes gate automatically after each
25 * I2C transfer. Using own I2C adapter we can workaround that.
26 */ 16 */
27 17
28#include "rtl2830_priv.h" 18#include "rtl2830_priv.h"
29 19
30/* Max transfer size done by I2C transfer functions */ 20/* Our regmap is bypassing I2C adapter lock, thus we do it! */
31#define MAX_XFER_SIZE 64 21static int rtl2830_bulk_write(struct i2c_client *client, unsigned int reg,
32 22 const void *val, size_t val_count)
33/* write multiple hardware registers */
34static int rtl2830_wr(struct rtl2830_priv *priv, u8 reg, const u8 *val, int len)
35{ 23{
24 struct rtl2830_dev *dev = i2c_get_clientdata(client);
36 int ret; 25 int ret;
37 u8 buf[MAX_XFER_SIZE];
38 struct i2c_msg msg[1] = {
39 {
40 .addr = priv->cfg.i2c_addr,
41 .flags = 0,
42 .len = 1 + len,
43 .buf = buf,
44 }
45 };
46
47 if (1 + len > sizeof(buf)) {
48 dev_warn(&priv->i2c->dev,
49 "%s: i2c wr reg=%04x: len=%d is too big!\n",
50 KBUILD_MODNAME, reg, len);
51 return -EINVAL;
52 }
53
54 buf[0] = reg;
55 memcpy(&buf[1], val, len);
56 26
57 ret = i2c_transfer(priv->i2c, msg, 1); 27 i2c_lock_adapter(client->adapter);
58 if (ret == 1) { 28 ret = regmap_bulk_write(dev->regmap, reg, val, val_count);
59 ret = 0; 29 i2c_unlock_adapter(client->adapter);
60 } else {
61 dev_warn(&priv->i2c->dev, "%s: i2c wr failed=%d reg=%02x " \
62 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
63 ret = -EREMOTEIO;
64 }
65 return ret; 30 return ret;
66} 31}
67 32
68/* read multiple hardware registers */ 33static int rtl2830_update_bits(struct i2c_client *client, unsigned int reg,
69static int rtl2830_rd(struct rtl2830_priv *priv, u8 reg, u8 *val, int len) 34 unsigned int mask, unsigned int val)
70{ 35{
36 struct rtl2830_dev *dev = i2c_get_clientdata(client);
71 int ret; 37 int ret;
72 struct i2c_msg msg[2] = {
73 {
74 .addr = priv->cfg.i2c_addr,
75 .flags = 0,
76 .len = 1,
77 .buf = &reg,
78 }, {
79 .addr = priv->cfg.i2c_addr,
80 .flags = I2C_M_RD,
81 .len = len,
82 .buf = val,
83 }
84 };
85 38
86 ret = i2c_transfer(priv->i2c, msg, 2); 39 i2c_lock_adapter(client->adapter);
87 if (ret == 2) { 40 ret = regmap_update_bits(dev->regmap, reg, mask, val);
88 ret = 0; 41 i2c_unlock_adapter(client->adapter);
89 } else {
90 dev_warn(&priv->i2c->dev, "%s: i2c rd failed=%d reg=%02x " \
91 "len=%d\n", KBUILD_MODNAME, ret, reg, len);
92 ret = -EREMOTEIO;
93 }
94 return ret; 42 return ret;
95} 43}
96 44
97/* write multiple registers */ 45static int rtl2830_bulk_read(struct i2c_client *client, unsigned int reg,
98static int rtl2830_wr_regs(struct rtl2830_priv *priv, u16 reg, const u8 *val, 46 void *val, size_t val_count)
99 int len)
100{ 47{
48 struct rtl2830_dev *dev = i2c_get_clientdata(client);
101 int ret; 49 int ret;
102 u8 reg2 = (reg >> 0) & 0xff;
103 u8 page = (reg >> 8) & 0xff;
104
105 /* switch bank if needed */
106 if (page != priv->page) {
107 ret = rtl2830_wr(priv, 0x00, &page, 1);
108 if (ret)
109 return ret;
110
111 priv->page = page;
112 }
113
114 return rtl2830_wr(priv, reg2, val, len);
115}
116
117/* read multiple registers */
118static int rtl2830_rd_regs(struct rtl2830_priv *priv, u16 reg, u8 *val, int len)
119{
120 int ret;
121 u8 reg2 = (reg >> 0) & 0xff;
122 u8 page = (reg >> 8) & 0xff;
123
124 /* switch bank if needed */
125 if (page != priv->page) {
126 ret = rtl2830_wr(priv, 0x00, &page, 1);
127 if (ret)
128 return ret;
129
130 priv->page = page;
131 }
132 50
133 return rtl2830_rd(priv, reg2, val, len); 51 i2c_lock_adapter(client->adapter);
134} 52 ret = regmap_bulk_read(dev->regmap, reg, val, val_count);
135 53 i2c_unlock_adapter(client->adapter);
136/* read single register */ 54 return ret;
137static int rtl2830_rd_reg(struct rtl2830_priv *priv, u16 reg, u8 *val)
138{
139 return rtl2830_rd_regs(priv, reg, val, 1);
140}
141
142/* write single register with mask */
143static int rtl2830_wr_reg_mask(struct rtl2830_priv *priv, u16 reg, u8 val, u8 mask)
144{
145 int ret;
146 u8 tmp;
147
148 /* no need for read if whole reg is written */
149 if (mask != 0xff) {
150 ret = rtl2830_rd_regs(priv, reg, &tmp, 1);
151 if (ret)
152 return ret;
153
154 val &= mask;
155 tmp &= ~mask;
156 val |= tmp;
157 }
158
159 return rtl2830_wr_regs(priv, reg, &val, 1);
160}
161
162/* read single register with mask */
163static int rtl2830_rd_reg_mask(struct rtl2830_priv *priv, u16 reg, u8 *val, u8 mask)
164{
165 int ret, i;
166 u8 tmp;
167
168 ret = rtl2830_rd_regs(priv, reg, &tmp, 1);
169 if (ret)
170 return ret;
171
172 tmp &= mask;
173
174 /* find position of the first bit */
175 for (i = 0; i < 8; i++) {
176 if ((mask >> i) & 0x01)
177 break;
178 }
179 *val = tmp >> i;
180
181 return 0;
182} 55}
183 56
184static int rtl2830_init(struct dvb_frontend *fe) 57static int rtl2830_init(struct dvb_frontend *fe)
185{ 58{
186 struct rtl2830_priv *priv = fe->demodulator_priv; 59 struct i2c_client *client = fe->demodulator_priv;
60 struct rtl2830_dev *dev = i2c_get_clientdata(client);
61 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
187 int ret, i; 62 int ret, i;
188 struct rtl2830_reg_val_mask tab[] = { 63 struct rtl2830_reg_val_mask tab[] = {
189 { 0x00d, 0x01, 0x03 }, 64 {0x00d, 0x01, 0x03},
190 { 0x00d, 0x10, 0x10 }, 65 {0x00d, 0x10, 0x10},
191 { 0x104, 0x00, 0x1e }, 66 {0x104, 0x00, 0x1e},
192 { 0x105, 0x80, 0x80 }, 67 {0x105, 0x80, 0x80},
193 { 0x110, 0x02, 0x03 }, 68 {0x110, 0x02, 0x03},
194 { 0x110, 0x08, 0x0c }, 69 {0x110, 0x08, 0x0c},
195 { 0x17b, 0x00, 0x40 }, 70 {0x17b, 0x00, 0x40},
196 { 0x17d, 0x05, 0x0f }, 71 {0x17d, 0x05, 0x0f},
197 { 0x17d, 0x50, 0xf0 }, 72 {0x17d, 0x50, 0xf0},
198 { 0x18c, 0x08, 0x0f }, 73 {0x18c, 0x08, 0x0f},
199 { 0x18d, 0x00, 0xc0 }, 74 {0x18d, 0x00, 0xc0},
200 { 0x188, 0x05, 0x0f }, 75 {0x188, 0x05, 0x0f},
201 { 0x189, 0x00, 0xfc }, 76 {0x189, 0x00, 0xfc},
202 { 0x2d5, 0x02, 0x02 }, 77 {0x2d5, 0x02, 0x02},
203 { 0x2f1, 0x02, 0x06 }, 78 {0x2f1, 0x02, 0x06},
204 { 0x2f1, 0x20, 0xf8 }, 79 {0x2f1, 0x20, 0xf8},
205 { 0x16d, 0x00, 0x01 }, 80 {0x16d, 0x00, 0x01},
206 { 0x1a6, 0x00, 0x80 }, 81 {0x1a6, 0x00, 0x80},
207 { 0x106, priv->cfg.vtop, 0x3f }, 82 {0x106, dev->pdata->vtop, 0x3f},
208 { 0x107, priv->cfg.krf, 0x3f }, 83 {0x107, dev->pdata->krf, 0x3f},
209 { 0x112, 0x28, 0xff }, 84 {0x112, 0x28, 0xff},
210 { 0x103, priv->cfg.agc_targ_val, 0xff }, 85 {0x103, dev->pdata->agc_targ_val, 0xff},
211 { 0x00a, 0x02, 0x07 }, 86 {0x00a, 0x02, 0x07},
212 { 0x140, 0x0c, 0x3c }, 87 {0x140, 0x0c, 0x3c},
213 { 0x140, 0x40, 0xc0 }, 88 {0x140, 0x40, 0xc0},
214 { 0x15b, 0x05, 0x07 }, 89 {0x15b, 0x05, 0x07},
215 { 0x15b, 0x28, 0x38 }, 90 {0x15b, 0x28, 0x38},
216 { 0x15c, 0x05, 0x07 }, 91 {0x15c, 0x05, 0x07},
217 { 0x15c, 0x28, 0x38 }, 92 {0x15c, 0x28, 0x38},
218 { 0x115, priv->cfg.spec_inv, 0x01 }, 93 {0x115, dev->pdata->spec_inv, 0x01},
219 { 0x16f, 0x01, 0x07 }, 94 {0x16f, 0x01, 0x07},
220 { 0x170, 0x18, 0x38 }, 95 {0x170, 0x18, 0x38},
221 { 0x172, 0x0f, 0x0f }, 96 {0x172, 0x0f, 0x0f},
222 { 0x173, 0x08, 0x38 }, 97 {0x173, 0x08, 0x38},
223 { 0x175, 0x01, 0x07 }, 98 {0x175, 0x01, 0x07},
224 { 0x176, 0x00, 0xc0 }, 99 {0x176, 0x00, 0xc0},
225 }; 100 };
226 101
227 for (i = 0; i < ARRAY_SIZE(tab); i++) { 102 for (i = 0; i < ARRAY_SIZE(tab); i++) {
228 ret = rtl2830_wr_reg_mask(priv, tab[i].reg, tab[i].val, 103 ret = rtl2830_update_bits(client, tab[i].reg, tab[i].mask,
229 tab[i].mask); 104 tab[i].val);
230 if (ret) 105 if (ret)
231 goto err; 106 goto err;
232 } 107 }
233 108
234 ret = rtl2830_wr_regs(priv, 0x18f, "\x28\x00", 2); 109 ret = rtl2830_bulk_write(client, 0x18f, "\x28\x00", 2);
235 if (ret) 110 if (ret)
236 goto err; 111 goto err;
237 112
238 ret = rtl2830_wr_regs(priv, 0x195, 113 ret = rtl2830_bulk_write(client, 0x195,
239 "\x04\x06\x0a\x12\x0a\x12\x1e\x28", 8); 114 "\x04\x06\x0a\x12\x0a\x12\x1e\x28", 8);
240 if (ret) 115 if (ret)
241 goto err; 116 goto err;
242 117
243 /* TODO: spec init */ 118 /* TODO: spec init */
244 119
245 /* soft reset */ 120 /* soft reset */
246 ret = rtl2830_wr_reg_mask(priv, 0x101, 0x04, 0x04); 121 ret = rtl2830_update_bits(client, 0x101, 0x04, 0x04);
247 if (ret) 122 if (ret)
248 goto err; 123 goto err;
249 124
250 ret = rtl2830_wr_reg_mask(priv, 0x101, 0x00, 0x04); 125 ret = rtl2830_update_bits(client, 0x101, 0x04, 0x00);
251 if (ret) 126 if (ret)
252 goto err; 127 goto err;
253 128
254 priv->sleeping = false; 129 /* init stats here in order signal app which stats are supported */
130 c->strength.len = 1;
131 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
132 c->cnr.len = 1;
133 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
134 c->post_bit_error.len = 1;
135 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
136 c->post_bit_count.len = 1;
137 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
138 /* start statistics polling */
139 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
140
141 dev->sleeping = false;
255 142
256 return ret; 143 return ret;
257err: 144err:
258 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 145 dev_dbg(&client->dev, "failed=%d\n", ret);
259 return ret; 146 return ret;
260} 147}
261 148
262static int rtl2830_sleep(struct dvb_frontend *fe) 149static int rtl2830_sleep(struct dvb_frontend *fe)
263{ 150{
264 struct rtl2830_priv *priv = fe->demodulator_priv; 151 struct i2c_client *client = fe->demodulator_priv;
265 priv->sleeping = true; 152 struct rtl2830_dev *dev = i2c_get_clientdata(client);
153
154 dev->sleeping = true;
155 /* stop statistics polling */
156 cancel_delayed_work_sync(&dev->stat_work);
157 dev->fe_status = 0;
158
266 return 0; 159 return 0;
267} 160}
268 161
269static int rtl2830_get_tune_settings(struct dvb_frontend *fe, 162static int rtl2830_get_tune_settings(struct dvb_frontend *fe,
270 struct dvb_frontend_tune_settings *s) 163 struct dvb_frontend_tune_settings *s)
271{ 164{
272 s->min_delay_ms = 500; 165 s->min_delay_ms = 500;
273 s->step_size = fe->ops.info.frequency_stepsize * 2; 166 s->step_size = fe->ops.info.frequency_stepsize * 2;
@@ -278,11 +171,12 @@ static int rtl2830_get_tune_settings(struct dvb_frontend *fe,
278 171
279static int rtl2830_set_frontend(struct dvb_frontend *fe) 172static int rtl2830_set_frontend(struct dvb_frontend *fe)
280{ 173{
281 struct rtl2830_priv *priv = fe->demodulator_priv; 174 struct i2c_client *client = fe->demodulator_priv;
175 struct rtl2830_dev *dev = i2c_get_clientdata(client);
282 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 176 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
283 int ret, i; 177 int ret, i;
284 u64 num; 178 u64 num;
285 u8 buf[3], tmp; 179 u8 buf[3], u8tmp;
286 u32 if_ctl, if_frequency; 180 u32 if_ctl, if_frequency;
287 static const u8 bw_params1[3][34] = { 181 static const u8 bw_params1[3][34] = {
288 { 182 {
@@ -308,9 +202,8 @@ static int rtl2830_set_frontend(struct dvb_frontend *fe)
308 {0xae, 0xba, 0xf3, 0x26, 0x66, 0x64}, /* 8 MHz */ 202 {0xae, 0xba, 0xf3, 0x26, 0x66, 0x64}, /* 8 MHz */
309 }; 203 };
310 204
311 dev_dbg(&priv->i2c->dev, 205 dev_dbg(&client->dev, "frequency=%u bandwidth_hz=%u inversion=%u\n",
312 "%s: frequency=%d bandwidth_hz=%d inversion=%d\n", 206 c->frequency, c->bandwidth_hz, c->inversion);
313 __func__, c->frequency, c->bandwidth_hz, c->inversion);
314 207
315 /* program tuner */ 208 /* program tuner */
316 if (fe->ops.tuner_ops.set_params) 209 if (fe->ops.tuner_ops.set_params)
@@ -327,11 +220,12 @@ static int rtl2830_set_frontend(struct dvb_frontend *fe)
327 i = 2; 220 i = 2;
328 break; 221 break;
329 default: 222 default:
330 dev_dbg(&priv->i2c->dev, "%s: invalid bandwidth\n", __func__); 223 dev_err(&client->dev, "invalid bandwidth_hz %u\n",
224 c->bandwidth_hz);
331 return -EINVAL; 225 return -EINVAL;
332 } 226 }
333 227
334 ret = rtl2830_wr_reg_mask(priv, 0x008, i << 1, 0x06); 228 ret = rtl2830_update_bits(client, 0x008, 0x06, i << 1);
335 if (ret) 229 if (ret)
336 goto err; 230 goto err;
337 231
@@ -340,70 +234,71 @@ static int rtl2830_set_frontend(struct dvb_frontend *fe)
340 ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency); 234 ret = fe->ops.tuner_ops.get_if_frequency(fe, &if_frequency);
341 else 235 else
342 ret = -EINVAL; 236 ret = -EINVAL;
343 237 if (ret)
344 if (ret < 0)
345 goto err; 238 goto err;
346 239
347 num = if_frequency % priv->cfg.xtal; 240 num = if_frequency % dev->pdata->clk;
348 num *= 0x400000; 241 num *= 0x400000;
349 num = div_u64(num, priv->cfg.xtal); 242 num = div_u64(num, dev->pdata->clk);
350 num = -num; 243 num = -num;
351 if_ctl = num & 0x3fffff; 244 if_ctl = num & 0x3fffff;
352 dev_dbg(&priv->i2c->dev, "%s: if_frequency=%d if_ctl=%08x\n", 245 dev_dbg(&client->dev, "if_frequency=%d if_ctl=%08x\n",
353 __func__, if_frequency, if_ctl); 246 if_frequency, if_ctl);
354 247
355 ret = rtl2830_rd_reg_mask(priv, 0x119, &tmp, 0xc0); /* b[7:6] */ 248 buf[0] = (if_ctl >> 16) & 0x3f;
249 buf[1] = (if_ctl >> 8) & 0xff;
250 buf[2] = (if_ctl >> 0) & 0xff;
251
252 ret = rtl2830_bulk_read(client, 0x119, &u8tmp, 1);
356 if (ret) 253 if (ret)
357 goto err; 254 goto err;
358 255
359 buf[0] = tmp << 6; 256 buf[0] |= u8tmp & 0xc0; /* [7:6] */
360 buf[0] |= (if_ctl >> 16) & 0x3f;
361 buf[1] = (if_ctl >> 8) & 0xff;
362 buf[2] = (if_ctl >> 0) & 0xff;
363 257
364 ret = rtl2830_wr_regs(priv, 0x119, buf, 3); 258 ret = rtl2830_bulk_write(client, 0x119, buf, 3);
365 if (ret) 259 if (ret)
366 goto err; 260 goto err;
367 261
368 /* 1/2 split I2C write */ 262 /* 1/2 split I2C write */
369 ret = rtl2830_wr_regs(priv, 0x11c, &bw_params1[i][0], 17); 263 ret = rtl2830_bulk_write(client, 0x11c, &bw_params1[i][0], 17);
370 if (ret) 264 if (ret)
371 goto err; 265 goto err;
372 266
373 /* 2/2 split I2C write */ 267 /* 2/2 split I2C write */
374 ret = rtl2830_wr_regs(priv, 0x12d, &bw_params1[i][17], 17); 268 ret = rtl2830_bulk_write(client, 0x12d, &bw_params1[i][17], 17);
375 if (ret) 269 if (ret)
376 goto err; 270 goto err;
377 271
378 ret = rtl2830_wr_regs(priv, 0x19d, bw_params2[i], 6); 272 ret = rtl2830_bulk_write(client, 0x19d, bw_params2[i], 6);
379 if (ret) 273 if (ret)
380 goto err; 274 goto err;
381 275
382 return ret; 276 return ret;
383err: 277err:
384 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 278 dev_dbg(&client->dev, "failed=%d\n", ret);
385 return ret; 279 return ret;
386} 280}
387 281
388static int rtl2830_get_frontend(struct dvb_frontend *fe) 282static int rtl2830_get_frontend(struct dvb_frontend *fe)
389{ 283{
390 struct rtl2830_priv *priv = fe->demodulator_priv; 284 struct i2c_client *client = fe->demodulator_priv;
285 struct rtl2830_dev *dev = i2c_get_clientdata(client);
391 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 286 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
392 int ret; 287 int ret;
393 u8 buf[3]; 288 u8 buf[3];
394 289
395 if (priv->sleeping) 290 if (dev->sleeping)
396 return 0; 291 return 0;
397 292
398 ret = rtl2830_rd_regs(priv, 0x33c, buf, 2); 293 ret = rtl2830_bulk_read(client, 0x33c, buf, 2);
399 if (ret) 294 if (ret)
400 goto err; 295 goto err;
401 296
402 ret = rtl2830_rd_reg(priv, 0x351, &buf[2]); 297 ret = rtl2830_bulk_read(client, 0x351, &buf[2], 1);
403 if (ret) 298 if (ret)
404 goto err; 299 goto err;
405 300
406 dev_dbg(&priv->i2c->dev, "%s: TPS=%*ph\n", __func__, 3, buf); 301 dev_dbg(&client->dev, "TPS=%*ph\n", 3, buf);
407 302
408 switch ((buf[0] >> 2) & 3) { 303 switch ((buf[0] >> 2) & 3) {
409 case 0: 304 case 0:
@@ -493,280 +388,543 @@ static int rtl2830_get_frontend(struct dvb_frontend *fe)
493 388
494 return 0; 389 return 0;
495err: 390err:
496 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 391 dev_dbg(&client->dev, "failed=%d\n", ret);
497 return ret; 392 return ret;
498} 393}
499 394
500static int rtl2830_read_status(struct dvb_frontend *fe, fe_status_t *status) 395static int rtl2830_read_status(struct dvb_frontend *fe, fe_status_t *status)
501{ 396{
502 struct rtl2830_priv *priv = fe->demodulator_priv; 397 struct i2c_client *client = fe->demodulator_priv;
398 struct rtl2830_dev *dev = i2c_get_clientdata(client);
503 int ret; 399 int ret;
504 u8 tmp; 400 u8 u8tmp;
401
505 *status = 0; 402 *status = 0;
506 403
507 if (priv->sleeping) 404 if (dev->sleeping)
508 return 0; 405 return 0;
509 406
510 ret = rtl2830_rd_reg_mask(priv, 0x351, &tmp, 0x78); /* [6:3] */ 407 ret = rtl2830_bulk_read(client, 0x351, &u8tmp, 1);
511 if (ret) 408 if (ret)
512 goto err; 409 goto err;
513 410
514 if (tmp == 11) { 411 u8tmp = (u8tmp >> 3) & 0x0f; /* [6:3] */
412 if (u8tmp == 11) {
515 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | 413 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
516 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 414 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
517 } else if (tmp == 10) { 415 } else if (u8tmp == 10) {
518 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | 416 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
519 FE_HAS_VITERBI; 417 FE_HAS_VITERBI;
520 } 418 }
521 419
420 dev->fe_status = *status;
421
522 return ret; 422 return ret;
523err: 423err:
524 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 424 dev_dbg(&client->dev, "failed=%d\n", ret);
525 return ret; 425 return ret;
526} 426}
527 427
528static int rtl2830_read_snr(struct dvb_frontend *fe, u16 *snr) 428static int rtl2830_read_snr(struct dvb_frontend *fe, u16 *snr)
529{ 429{
530 struct rtl2830_priv *priv = fe->demodulator_priv; 430 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
531 int ret, hierarchy, constellation;
532 u8 buf[2], tmp;
533 u16 tmp16;
534#define CONSTELLATION_NUM 3
535#define HIERARCHY_NUM 4
536 static const u32 snr_constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
537 { 70705899, 70705899, 70705899, 70705899 },
538 { 82433173, 82433173, 87483115, 94445660 },
539 { 92888734, 92888734, 95487525, 99770748 },
540 };
541 431
542 if (priv->sleeping) 432 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
543 return 0; 433 *snr = div_s64(c->cnr.stat[0].svalue, 100);
434 else
435 *snr = 0;
544 436
545 /* reports SNR in resolution of 0.1 dB */ 437 return 0;
438}
546 439
547 ret = rtl2830_rd_reg(priv, 0x33c, &tmp); 440static int rtl2830_read_ber(struct dvb_frontend *fe, u32 *ber)
548 if (ret) 441{
549 goto err; 442 struct i2c_client *client = fe->demodulator_priv;
443 struct rtl2830_dev *dev = i2c_get_clientdata(client);
550 444
551 constellation = (tmp >> 2) & 0x03; /* [3:2] */ 445 *ber = (dev->post_bit_error - dev->post_bit_error_prev);
552 if (constellation > CONSTELLATION_NUM - 1) 446 dev->post_bit_error_prev = dev->post_bit_error;
553 goto err;
554 447
555 hierarchy = (tmp >> 4) & 0x07; /* [6:4] */ 448 return 0;
556 if (hierarchy > HIERARCHY_NUM - 1) 449}
557 goto err;
558 450
559 ret = rtl2830_rd_regs(priv, 0x40c, buf, 2); 451static int rtl2830_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
560 if (ret) 452{
561 goto err; 453 *ucblocks = 0;
562 454
563 tmp16 = buf[0] << 8 | buf[1]; 455 return 0;
456}
457
458static int rtl2830_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
459{
460 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
564 461
565 if (tmp16) 462 if (c->strength.stat[0].scale == FE_SCALE_RELATIVE)
566 *snr = (snr_constant[constellation][hierarchy] - 463 *strength = c->strength.stat[0].uvalue;
567 intlog10(tmp16)) / ((1 << 24) / 100);
568 else 464 else
569 *snr = 0; 465 *strength = 0;
570 466
571 return 0; 467 return 0;
468}
469
470static struct dvb_frontend_ops rtl2830_ops = {
471 .delsys = {SYS_DVBT},
472 .info = {
473 .name = "Realtek RTL2830 (DVB-T)",
474 .caps = FE_CAN_FEC_1_2 |
475 FE_CAN_FEC_2_3 |
476 FE_CAN_FEC_3_4 |
477 FE_CAN_FEC_5_6 |
478 FE_CAN_FEC_7_8 |
479 FE_CAN_FEC_AUTO |
480 FE_CAN_QPSK |
481 FE_CAN_QAM_16 |
482 FE_CAN_QAM_64 |
483 FE_CAN_QAM_AUTO |
484 FE_CAN_TRANSMISSION_MODE_AUTO |
485 FE_CAN_GUARD_INTERVAL_AUTO |
486 FE_CAN_HIERARCHY_AUTO |
487 FE_CAN_RECOVER |
488 FE_CAN_MUTE_TS
489 },
490
491 .init = rtl2830_init,
492 .sleep = rtl2830_sleep,
493
494 .get_tune_settings = rtl2830_get_tune_settings,
495
496 .set_frontend = rtl2830_set_frontend,
497 .get_frontend = rtl2830_get_frontend,
498
499 .read_status = rtl2830_read_status,
500 .read_snr = rtl2830_read_snr,
501 .read_ber = rtl2830_read_ber,
502 .read_ucblocks = rtl2830_read_ucblocks,
503 .read_signal_strength = rtl2830_read_signal_strength,
504};
505
506static void rtl2830_stat_work(struct work_struct *work)
507{
508 struct rtl2830_dev *dev = container_of(work, struct rtl2830_dev, stat_work.work);
509 struct i2c_client *client = dev->client;
510 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
511 int ret, tmp;
512 u8 u8tmp, buf[2];
513 u16 u16tmp;
514
515 dev_dbg(&client->dev, "\n");
516
517 /* signal strength */
518 if (dev->fe_status & FE_HAS_SIGNAL) {
519 struct {signed int x:14; } s;
520
521 /* read IF AGC */
522 ret = rtl2830_bulk_read(client, 0x359, buf, 2);
523 if (ret)
524 goto err;
525
526 u16tmp = buf[0] << 8 | buf[1] << 0;
527 u16tmp &= 0x3fff; /* [13:0] */
528 tmp = s.x = u16tmp; /* 14-bit bin to 2 complement */
529 u16tmp = clamp_val(-4 * tmp + 32767, 0x0000, 0xffff);
530
531 dev_dbg(&client->dev, "IF AGC=%d\n", tmp);
532
533 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
534 c->strength.stat[0].uvalue = u16tmp;
535 } else {
536 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
537 }
538
539 /* CNR */
540 if (dev->fe_status & FE_HAS_VITERBI) {
541 unsigned hierarchy, constellation;
542 #define CONSTELLATION_NUM 3
543 #define HIERARCHY_NUM 4
544 static const u32 constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
545 {70705899, 70705899, 70705899, 70705899},
546 {82433173, 82433173, 87483115, 94445660},
547 {92888734, 92888734, 95487525, 99770748},
548 };
549
550 ret = rtl2830_bulk_read(client, 0x33c, &u8tmp, 1);
551 if (ret)
552 goto err;
553
554 constellation = (u8tmp >> 2) & 0x03; /* [3:2] */
555 if (constellation > CONSTELLATION_NUM - 1)
556 goto err_schedule_delayed_work;
557
558 hierarchy = (u8tmp >> 4) & 0x07; /* [6:4] */
559 if (hierarchy > HIERARCHY_NUM - 1)
560 goto err_schedule_delayed_work;
561
562 ret = rtl2830_bulk_read(client, 0x40c, buf, 2);
563 if (ret)
564 goto err;
565
566 u16tmp = buf[0] << 8 | buf[1] << 0;
567 if (u16tmp)
568 tmp = (constant[constellation][hierarchy] -
569 intlog10(u16tmp)) / ((1 << 24) / 10000);
570 else
571 tmp = 0;
572
573 dev_dbg(&client->dev, "CNR raw=%u\n", u16tmp);
574
575 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
576 c->cnr.stat[0].svalue = tmp;
577 } else {
578 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
579 }
580
581 /* BER */
582 if (dev->fe_status & FE_HAS_LOCK) {
583 ret = rtl2830_bulk_read(client, 0x34e, buf, 2);
584 if (ret)
585 goto err;
586
587 u16tmp = buf[0] << 8 | buf[1] << 0;
588 dev->post_bit_error += u16tmp;
589 dev->post_bit_count += 1000000;
590
591 dev_dbg(&client->dev, "BER errors=%u total=1000000\n", u16tmp);
592
593 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
594 c->post_bit_error.stat[0].uvalue = dev->post_bit_error;
595 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
596 c->post_bit_count.stat[0].uvalue = dev->post_bit_count;
597 } else {
598 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
599 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
600 }
601
602err_schedule_delayed_work:
603 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
604 return;
572err: 605err:
573 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 606 dev_dbg(&client->dev, "failed=%d\n", ret);
574 return ret;
575} 607}
576 608
577static int rtl2830_read_ber(struct dvb_frontend *fe, u32 *ber) 609static int rtl2830_pid_filter_ctrl(struct dvb_frontend *fe, int onoff)
578{ 610{
579 struct rtl2830_priv *priv = fe->demodulator_priv; 611 struct i2c_client *client = fe->demodulator_priv;
580 int ret; 612 int ret;
581 u8 buf[2]; 613 u8 u8tmp;
582 614
583 if (priv->sleeping) 615 dev_dbg(&client->dev, "onoff=%d\n", onoff);
584 return 0; 616
617 /* enable / disable PID filter */
618 if (onoff)
619 u8tmp = 0x80;
620 else
621 u8tmp = 0x00;
585 622
586 ret = rtl2830_rd_regs(priv, 0x34e, buf, 2); 623 ret = rtl2830_update_bits(client, 0x061, 0x80, u8tmp);
587 if (ret) 624 if (ret)
588 goto err; 625 goto err;
589 626
590 *ber = buf[0] << 8 | buf[1];
591
592 return 0; 627 return 0;
593err: 628err:
594 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 629 dev_dbg(&client->dev, "failed=%d\n", ret);
595 return ret; 630 return ret;
596} 631}
597 632
598static int rtl2830_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 633static int rtl2830_pid_filter(struct dvb_frontend *fe, u8 index, u16 pid, int onoff)
599{ 634{
600 *ucblocks = 0; 635 struct i2c_client *client = fe->demodulator_priv;
601 return 0; 636 struct rtl2830_dev *dev = i2c_get_clientdata(client);
602}
603
604static int rtl2830_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
605{
606 struct rtl2830_priv *priv = fe->demodulator_priv;
607 int ret; 637 int ret;
608 u8 buf[2]; 638 u8 buf[4];
609 u16 if_agc_raw, if_agc;
610 639
611 if (priv->sleeping) 640 dev_dbg(&client->dev, "index=%d pid=%04x onoff=%d\n",
641 index, pid, onoff);
642
643 /* skip invalid PIDs (0x2000) */
644 if (pid > 0x1fff || index > 32)
612 return 0; 645 return 0;
613 646
614 ret = rtl2830_rd_regs(priv, 0x359, buf, 2); 647 if (onoff)
648 set_bit(index, &dev->filters);
649 else
650 clear_bit(index, &dev->filters);
651
652 /* enable / disable PIDs */
653 buf[0] = (dev->filters >> 0) & 0xff;
654 buf[1] = (dev->filters >> 8) & 0xff;
655 buf[2] = (dev->filters >> 16) & 0xff;
656 buf[3] = (dev->filters >> 24) & 0xff;
657 ret = rtl2830_bulk_write(client, 0x062, buf, 4);
615 if (ret) 658 if (ret)
616 goto err; 659 goto err;
617 660
618 if_agc_raw = (buf[0] << 8 | buf[1]) & 0x3fff; 661 /* add PID */
619 662 buf[0] = (pid >> 8) & 0xff;
620 if (if_agc_raw & (1 << 9)) 663 buf[1] = (pid >> 0) & 0xff;
621 if_agc = -(~(if_agc_raw - 1) & 0x1ff); 664 ret = rtl2830_bulk_write(client, 0x066 + 2 * index, buf, 2);
622 else 665 if (ret)
623 if_agc = if_agc_raw; 666 goto err;
624
625 *strength = (u8) (55 - if_agc / 182);
626 *strength |= *strength << 8;
627 667
628 return 0; 668 return 0;
629err: 669err:
630 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 670 dev_dbg(&client->dev, "failed=%d\n", ret);
631 return ret; 671 return ret;
632} 672}
633 673
634static struct dvb_frontend_ops rtl2830_ops; 674/*
635 675 * I2C gate/mux/repeater logic
636static u32 rtl2830_tuner_i2c_func(struct i2c_adapter *adapter) 676 * We must use unlocked __i2c_transfer() here (through regmap) because of I2C
637{ 677 * adapter lock is already taken by tuner driver.
638 return I2C_FUNC_I2C; 678 * Gate is closed automatically after single I2C transfer.
639} 679 */
640 680static int rtl2830_select(struct i2c_adapter *adap, void *mux_priv, u32 chan_id)
641static int rtl2830_tuner_i2c_xfer(struct i2c_adapter *i2c_adap,
642 struct i2c_msg msg[], int num)
643{ 681{
644 struct rtl2830_priv *priv = i2c_get_adapdata(i2c_adap); 682 struct i2c_client *client = mux_priv;
683 struct rtl2830_dev *dev = i2c_get_clientdata(client);
645 int ret; 684 int ret;
646 685
647 /* open i2c-gate */ 686 dev_dbg(&client->dev, "\n");
648 ret = rtl2830_wr_reg_mask(priv, 0x101, 0x08, 0x08); 687
688 /* open I2C repeater for 1 transfer, closes automatically */
689 /* XXX: regmap_update_bits() does not lock I2C adapter */
690 ret = regmap_update_bits(dev->regmap, 0x101, 0x08, 0x08);
649 if (ret) 691 if (ret)
650 goto err; 692 goto err;
651 693
652 ret = i2c_transfer(priv->i2c, msg, num); 694 return 0;
653 if (ret < 0)
654 dev_warn(&priv->i2c->dev, "%s: tuner i2c failed=%d\n",
655 KBUILD_MODNAME, ret);
656
657 return ret;
658err: 695err:
659 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 696 dev_dbg(&client->dev, "failed=%d\n", ret);
660 return ret; 697 return ret;
661} 698}
662 699
663static struct i2c_algorithm rtl2830_tuner_i2c_algo = { 700static struct dvb_frontend *rtl2830_get_dvb_frontend(struct i2c_client *client)
664 .master_xfer = rtl2830_tuner_i2c_xfer, 701{
665 .functionality = rtl2830_tuner_i2c_func, 702 struct rtl2830_dev *dev = i2c_get_clientdata(client);
666};
667 703
668struct i2c_adapter *rtl2830_get_tuner_i2c_adapter(struct dvb_frontend *fe) 704 dev_dbg(&client->dev, "\n");
705
706 return &dev->fe;
707}
708
709static struct i2c_adapter *rtl2830_get_i2c_adapter(struct i2c_client *client)
669{ 710{
670 struct rtl2830_priv *priv = fe->demodulator_priv; 711 struct rtl2830_dev *dev = i2c_get_clientdata(client);
671 return &priv->tuner_i2c_adapter; 712
713 dev_dbg(&client->dev, "\n");
714
715 return dev->adapter;
672} 716}
673EXPORT_SYMBOL(rtl2830_get_tuner_i2c_adapter);
674 717
675static void rtl2830_release(struct dvb_frontend *fe) 718/*
719 * We implement own I2C access routines for regmap in order to get manual access
720 * to I2C adapter lock, which is needed for I2C mux adapter.
721 */
722static int rtl2830_regmap_read(void *context, const void *reg_buf,
723 size_t reg_size, void *val_buf, size_t val_size)
676{ 724{
677 struct rtl2830_priv *priv = fe->demodulator_priv; 725 struct i2c_client *client = context;
726 int ret;
727 struct i2c_msg msg[2] = {
728 {
729 .addr = client->addr,
730 .flags = 0,
731 .len = reg_size,
732 .buf = (u8 *)reg_buf,
733 }, {
734 .addr = client->addr,
735 .flags = I2C_M_RD,
736 .len = val_size,
737 .buf = val_buf,
738 }
739 };
678 740
679 i2c_del_adapter(&priv->tuner_i2c_adapter); 741 ret = __i2c_transfer(client->adapter, msg, 2);
680 kfree(priv); 742 if (ret != 2) {
743 dev_warn(&client->dev, "i2c reg read failed %d\n", ret);
744 if (ret >= 0)
745 ret = -EREMOTEIO;
746 return ret;
747 }
748 return 0;
681} 749}
682 750
683struct dvb_frontend *rtl2830_attach(const struct rtl2830_config *cfg, 751static int rtl2830_regmap_write(void *context, const void *data, size_t count)
684 struct i2c_adapter *i2c)
685{ 752{
686 struct rtl2830_priv *priv = NULL; 753 struct i2c_client *client = context;
687 int ret = 0; 754 int ret;
688 u8 tmp; 755 struct i2c_msg msg[1] = {
756 {
757 .addr = client->addr,
758 .flags = 0,
759 .len = count,
760 .buf = (u8 *)data,
761 }
762 };
763
764 ret = __i2c_transfer(client->adapter, msg, 1);
765 if (ret != 1) {
766 dev_warn(&client->dev, "i2c reg write failed %d\n", ret);
767 if (ret >= 0)
768 ret = -EREMOTEIO;
769 return ret;
770 }
771 return 0;
772}
773
774static int rtl2830_regmap_gather_write(void *context, const void *reg,
775 size_t reg_len, const void *val,
776 size_t val_len)
777{
778 struct i2c_client *client = context;
779 int ret;
780 u8 buf[256];
781 struct i2c_msg msg[1] = {
782 {
783 .addr = client->addr,
784 .flags = 0,
785 .len = 1 + val_len,
786 .buf = buf,
787 }
788 };
789
790 buf[0] = *(u8 const *)reg;
791 memcpy(&buf[1], val, val_len);
792
793 ret = __i2c_transfer(client->adapter, msg, 1);
794 if (ret != 1) {
795 dev_warn(&client->dev, "i2c reg write failed %d\n", ret);
796 if (ret >= 0)
797 ret = -EREMOTEIO;
798 return ret;
799 }
800 return 0;
801}
802
803static int rtl2830_probe(struct i2c_client *client,
804 const struct i2c_device_id *id)
805{
806 struct rtl2830_platform_data *pdata = client->dev.platform_data;
807 struct rtl2830_dev *dev;
808 int ret;
809 u8 u8tmp;
810 static const struct regmap_bus regmap_bus = {
811 .read = rtl2830_regmap_read,
812 .write = rtl2830_regmap_write,
813 .gather_write = rtl2830_regmap_gather_write,
814 .val_format_endian_default = REGMAP_ENDIAN_NATIVE,
815 };
816 static const struct regmap_range_cfg regmap_range_cfg[] = {
817 {
818 .selector_reg = 0x00,
819 .selector_mask = 0xff,
820 .selector_shift = 0,
821 .window_start = 0,
822 .window_len = 0x100,
823 .range_min = 0 * 0x100,
824 .range_max = 5 * 0x100,
825 },
826 };
827 static const struct regmap_config regmap_config = {
828 .reg_bits = 8,
829 .val_bits = 8,
830 .max_register = 5 * 0x100,
831 .ranges = regmap_range_cfg,
832 .num_ranges = ARRAY_SIZE(regmap_range_cfg),
833 };
834
835 dev_dbg(&client->dev, "\n");
836
837 if (pdata == NULL) {
838 ret = -EINVAL;
839 goto err;
840 }
689 841
690 /* allocate memory for the internal state */ 842 /* allocate memory for the internal state */
691 priv = kzalloc(sizeof(struct rtl2830_priv), GFP_KERNEL); 843 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
692 if (priv == NULL) 844 if (dev == NULL) {
845 ret = -ENOMEM;
693 goto err; 846 goto err;
847 }
694 848
695 /* setup the priv */ 849 /* setup the state */
696 priv->i2c = i2c; 850 i2c_set_clientdata(client, dev);
697 memcpy(&priv->cfg, cfg, sizeof(struct rtl2830_config)); 851 dev->client = client;
852 dev->pdata = client->dev.platform_data;
853 dev->sleeping = true;
854 INIT_DELAYED_WORK(&dev->stat_work, rtl2830_stat_work);
855 dev->regmap = regmap_init(&client->dev, &regmap_bus, client,
856 &regmap_config);
857 if (IS_ERR(dev->regmap)) {
858 ret = PTR_ERR(dev->regmap);
859 goto err_kfree;
860 }
698 861
699 /* check if the demod is there */ 862 /* check if the demod is there */
700 ret = rtl2830_rd_reg(priv, 0x000, &tmp); 863 ret = rtl2830_bulk_read(client, 0x000, &u8tmp, 1);
701 if (ret) 864 if (ret)
702 goto err; 865 goto err_regmap_exit;
703 866
704 /* create dvb_frontend */ 867 /* create muxed i2c adapter for tuner */
705 memcpy(&priv->fe.ops, &rtl2830_ops, sizeof(struct dvb_frontend_ops)); 868 dev->adapter = i2c_add_mux_adapter(client->adapter, &client->dev,
706 priv->fe.demodulator_priv = priv; 869 client, 0, 0, 0, rtl2830_select, NULL);
707 870 if (dev->adapter == NULL) {
708 /* create tuner i2c adapter */ 871 ret = -ENODEV;
709 strlcpy(priv->tuner_i2c_adapter.name, "RTL2830 tuner I2C adapter", 872 goto err_regmap_exit;
710 sizeof(priv->tuner_i2c_adapter.name));
711 priv->tuner_i2c_adapter.algo = &rtl2830_tuner_i2c_algo;
712 priv->tuner_i2c_adapter.algo_data = NULL;
713 priv->tuner_i2c_adapter.dev.parent = &i2c->dev;
714 i2c_set_adapdata(&priv->tuner_i2c_adapter, priv);
715 if (i2c_add_adapter(&priv->tuner_i2c_adapter) < 0) {
716 dev_err(&i2c->dev,
717 "%s: tuner i2c bus could not be initialized\n",
718 KBUILD_MODNAME);
719 goto err;
720 } 873 }
721 874
722 priv->sleeping = true; 875 /* create dvb frontend */
876 memcpy(&dev->fe.ops, &rtl2830_ops, sizeof(dev->fe.ops));
877 dev->fe.demodulator_priv = client;
878
879 /* setup callbacks */
880 pdata->get_dvb_frontend = rtl2830_get_dvb_frontend;
881 pdata->get_i2c_adapter = rtl2830_get_i2c_adapter;
882 pdata->pid_filter = rtl2830_pid_filter;
883 pdata->pid_filter_ctrl = rtl2830_pid_filter_ctrl;
723 884
724 return &priv->fe; 885 dev_info(&client->dev, "Realtek RTL2830 successfully attached\n");
886
887 return 0;
888err_regmap_exit:
889 regmap_exit(dev->regmap);
890err_kfree:
891 kfree(dev);
725err: 892err:
726 dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 893 dev_dbg(&client->dev, "failed=%d\n", ret);
727 kfree(priv); 894 return ret;
728 return NULL;
729} 895}
730EXPORT_SYMBOL(rtl2830_attach);
731 896
732static struct dvb_frontend_ops rtl2830_ops = { 897static int rtl2830_remove(struct i2c_client *client)
733 .delsys = { SYS_DVBT }, 898{
734 .info = { 899 struct rtl2830_dev *dev = i2c_get_clientdata(client);
735 .name = "Realtek RTL2830 (DVB-T)",
736 .caps = FE_CAN_FEC_1_2 |
737 FE_CAN_FEC_2_3 |
738 FE_CAN_FEC_3_4 |
739 FE_CAN_FEC_5_6 |
740 FE_CAN_FEC_7_8 |
741 FE_CAN_FEC_AUTO |
742 FE_CAN_QPSK |
743 FE_CAN_QAM_16 |
744 FE_CAN_QAM_64 |
745 FE_CAN_QAM_AUTO |
746 FE_CAN_TRANSMISSION_MODE_AUTO |
747 FE_CAN_GUARD_INTERVAL_AUTO |
748 FE_CAN_HIERARCHY_AUTO |
749 FE_CAN_RECOVER |
750 FE_CAN_MUTE_TS
751 },
752 900
753 .release = rtl2830_release, 901 dev_dbg(&client->dev, "\n");
754 902
755 .init = rtl2830_init, 903 i2c_del_mux_adapter(dev->adapter);
756 .sleep = rtl2830_sleep, 904 regmap_exit(dev->regmap);
905 kfree(dev);
757 906
758 .get_tune_settings = rtl2830_get_tune_settings, 907 return 0;
908}
759 909
760 .set_frontend = rtl2830_set_frontend, 910static const struct i2c_device_id rtl2830_id_table[] = {
761 .get_frontend = rtl2830_get_frontend, 911 {"rtl2830", 0},
912 {}
913};
914MODULE_DEVICE_TABLE(i2c, rtl2830_id_table);
762 915
763 .read_status = rtl2830_read_status, 916static struct i2c_driver rtl2830_driver = {
764 .read_snr = rtl2830_read_snr, 917 .driver = {
765 .read_ber = rtl2830_read_ber, 918 .owner = THIS_MODULE,
766 .read_ucblocks = rtl2830_read_ucblocks, 919 .name = "rtl2830",
767 .read_signal_strength = rtl2830_read_signal_strength, 920 },
921 .probe = rtl2830_probe,
922 .remove = rtl2830_remove,
923 .id_table = rtl2830_id_table,
768}; 924};
769 925
926module_i2c_driver(rtl2830_driver);
927
770MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 928MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
771MODULE_DESCRIPTION("Realtek RTL2830 DVB-T demodulator driver"); 929MODULE_DESCRIPTION("Realtek RTL2830 DVB-T demodulator driver");
772MODULE_LICENSE("GPL"); 930MODULE_LICENSE("GPL");
diff --git a/drivers/media/dvb-frontends/rtl2830.h b/drivers/media/dvb-frontends/rtl2830.h
index 3313847fb0be..0cde151e6608 100644
--- a/drivers/media/dvb-frontends/rtl2830.h
+++ b/drivers/media/dvb-frontends/rtl2830.h
@@ -13,78 +13,37 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */ 16 */
20 17
21#ifndef RTL2830_H 18#ifndef RTL2830_H
22#define RTL2830_H 19#define RTL2830_H
23 20
24#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 21#include <linux/dvb/frontend.h>
26 22
27struct rtl2830_config { 23/**
28 /* 24 * struct rtl2830_platform_data - Platform data for the rtl2830 driver
29 * Demodulator I2C address. 25 * @clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
30 */ 26 * @spec_inv: Spectrum inversion.
31 u8 i2c_addr; 27 * @vtop: AGC take-over point.
32 28 * @krf: AGC ratio.
33 /* 29 * @agc_targ_val: AGC.
34 * Xtal frequency. 30 * @get_dvb_frontend: Get DVB frontend.
35 * Hz 31 * @get_i2c_adapter: Get I2C adapter.
36 * 4000000, 16000000, 25000000, 28800000 32 * @pid_filter: Set PID to PID filter.
37 */ 33 * @pid_filter_ctrl: Control PID filter.
38 u32 xtal; 34 */
39
40 /*
41 * TS output mode.
42 */
43 u8 ts_mode;
44 35
45 /* 36struct rtl2830_platform_data {
46 * Spectrum inversion. 37 u32 clk;
47 */
48 bool spec_inv; 38 bool spec_inv;
49
50 /*
51 */
52 u8 vtop; 39 u8 vtop;
53
54 /*
55 */
56 u8 krf; 40 u8 krf;
57
58 /*
59 */
60 u8 agc_targ_val; 41 u8 agc_targ_val;
61};
62
63#if IS_ENABLED(CONFIG_DVB_RTL2830)
64extern struct dvb_frontend *rtl2830_attach(
65 const struct rtl2830_config *config,
66 struct i2c_adapter *i2c
67);
68 42
69extern struct i2c_adapter *rtl2830_get_tuner_i2c_adapter( 43 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
70 struct dvb_frontend *fe 44 struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
71); 45 int (*pid_filter)(struct dvb_frontend *, u8, u16, int);
72#else 46 int (*pid_filter_ctrl)(struct dvb_frontend *, int);
73static inline struct dvb_frontend *rtl2830_attach( 47};
74 const struct rtl2830_config *config,
75 struct i2c_adapter *i2c
76)
77{
78 pr_warn("%s: driver disabled by Kconfig\n", __func__);
79 return NULL;
80}
81
82static inline struct i2c_adapter *rtl2830_get_tuner_i2c_adapter(
83 struct dvb_frontend *fe
84)
85{
86 return NULL;
87}
88#endif
89 48
90#endif /* RTL2830_H */ 49#endif /* RTL2830_H */
diff --git a/drivers/media/dvb-frontends/rtl2830_priv.h b/drivers/media/dvb-frontends/rtl2830_priv.h
index fab10ecb3c3b..d50d5376c9c5 100644
--- a/drivers/media/dvb-frontends/rtl2830_priv.h
+++ b/drivers/media/dvb-frontends/rtl2830_priv.h
@@ -13,9 +13,6 @@
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details. 14 * GNU General Public License for more details.
15 * 15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 */ 16 */
20 17
21#ifndef RTL2830_PRIV_H 18#ifndef RTL2830_PRIV_H
@@ -24,16 +21,23 @@
24#include "dvb_frontend.h" 21#include "dvb_frontend.h"
25#include "dvb_math.h" 22#include "dvb_math.h"
26#include "rtl2830.h" 23#include "rtl2830.h"
24#include <linux/i2c-mux.h>
25#include <linux/math64.h>
26#include <linux/regmap.h>
27 27
28struct rtl2830_priv { 28struct rtl2830_dev {
29 struct i2c_adapter *i2c; 29 struct rtl2830_platform_data *pdata;
30 struct i2c_client *client;
31 struct regmap *regmap;
32 struct i2c_adapter *adapter;
30 struct dvb_frontend fe; 33 struct dvb_frontend fe;
31 struct rtl2830_config cfg;
32 struct i2c_adapter tuner_i2c_adapter;
33
34 bool sleeping; 34 bool sleeping;
35 35 unsigned long filters;
36 u8 page; /* active register page */ 36 struct delayed_work stat_work;
37 fe_status_t fe_status;
38 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
39 u64 post_bit_error;
40 u64 post_bit_count;
37}; 41};
38 42
39struct rtl2830_reg_val_mask { 43struct rtl2830_reg_val_mask {
diff --git a/drivers/media/dvb-frontends/rtl2832.c b/drivers/media/dvb-frontends/rtl2832.c
index 9026e1aee163..5d2d8f45b4b6 100644
--- a/drivers/media/dvb-frontends/rtl2832.c
+++ b/drivers/media/dvb-frontends/rtl2832.c
@@ -2,6 +2,7 @@
2 * Realtek RTL2832 DVB-T demodulator driver 2 * Realtek RTL2832 DVB-T demodulator driver
3 * 3 *
4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com> 4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
5 * Copyright (C) 2012-2014 Antti Palosaari <crope@iki.fi>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -19,280 +20,191 @@
19 */ 20 */
20 21
21#include "rtl2832_priv.h" 22#include "rtl2832_priv.h"
22#include "dvb_math.h"
23#include <linux/bitops.h>
24 23
25/* Max transfer size done by I2C transfer functions */
26#define MAX_XFER_SIZE 64
27#define REG_MASK(b) (BIT(b + 1) - 1) 24#define REG_MASK(b) (BIT(b + 1) - 1)
28 25
29static const struct rtl2832_reg_entry registers[] = { 26static const struct rtl2832_reg_entry registers[] = {
30 [DVBT_SOFT_RST] = {0x1, 0x1, 2, 2}, 27 [DVBT_SOFT_RST] = {0x101, 2, 2},
31 [DVBT_IIC_REPEAT] = {0x1, 0x1, 3, 3}, 28 [DVBT_IIC_REPEAT] = {0x101, 3, 3},
32 [DVBT_TR_WAIT_MIN_8K] = {0x1, 0x88, 11, 2}, 29 [DVBT_TR_WAIT_MIN_8K] = {0x188, 11, 2},
33 [DVBT_RSD_BER_FAIL_VAL] = {0x1, 0x8f, 15, 0}, 30 [DVBT_RSD_BER_FAIL_VAL] = {0x18f, 15, 0},
34 [DVBT_EN_BK_TRK] = {0x1, 0xa6, 7, 7}, 31 [DVBT_EN_BK_TRK] = {0x1a6, 7, 7},
35 [DVBT_AD_EN_REG] = {0x0, 0x8, 7, 7}, 32 [DVBT_AD_EN_REG] = {0x008, 7, 7},
36 [DVBT_AD_EN_REG1] = {0x0, 0x8, 6, 6}, 33 [DVBT_AD_EN_REG1] = {0x008, 6, 6},
37 [DVBT_EN_BBIN] = {0x1, 0xb1, 0, 0}, 34 [DVBT_EN_BBIN] = {0x1b1, 0, 0},
38 [DVBT_MGD_THD0] = {0x1, 0x95, 7, 0}, 35 [DVBT_MGD_THD0] = {0x195, 7, 0},
39 [DVBT_MGD_THD1] = {0x1, 0x96, 7, 0}, 36 [DVBT_MGD_THD1] = {0x196, 7, 0},
40 [DVBT_MGD_THD2] = {0x1, 0x97, 7, 0}, 37 [DVBT_MGD_THD2] = {0x197, 7, 0},
41 [DVBT_MGD_THD3] = {0x1, 0x98, 7, 0}, 38 [DVBT_MGD_THD3] = {0x198, 7, 0},
42 [DVBT_MGD_THD4] = {0x1, 0x99, 7, 0}, 39 [DVBT_MGD_THD4] = {0x199, 7, 0},
43 [DVBT_MGD_THD5] = {0x1, 0x9a, 7, 0}, 40 [DVBT_MGD_THD5] = {0x19a, 7, 0},
44 [DVBT_MGD_THD6] = {0x1, 0x9b, 7, 0}, 41 [DVBT_MGD_THD6] = {0x19b, 7, 0},
45 [DVBT_MGD_THD7] = {0x1, 0x9c, 7, 0}, 42 [DVBT_MGD_THD7] = {0x19c, 7, 0},
46 [DVBT_EN_CACQ_NOTCH] = {0x1, 0x61, 4, 4}, 43 [DVBT_EN_CACQ_NOTCH] = {0x161, 4, 4},
47 [DVBT_AD_AV_REF] = {0x0, 0x9, 6, 0}, 44 [DVBT_AD_AV_REF] = {0x009, 6, 0},
48 [DVBT_REG_PI] = {0x0, 0xa, 2, 0}, 45 [DVBT_REG_PI] = {0x00a, 2, 0},
49 [DVBT_PIP_ON] = {0x0, 0x21, 3, 3}, 46 [DVBT_PIP_ON] = {0x021, 3, 3},
50 [DVBT_SCALE1_B92] = {0x2, 0x92, 7, 0}, 47 [DVBT_SCALE1_B92] = {0x292, 7, 0},
51 [DVBT_SCALE1_B93] = {0x2, 0x93, 7, 0}, 48 [DVBT_SCALE1_B93] = {0x293, 7, 0},
52 [DVBT_SCALE1_BA7] = {0x2, 0xa7, 7, 0}, 49 [DVBT_SCALE1_BA7] = {0x2a7, 7, 0},
53 [DVBT_SCALE1_BA9] = {0x2, 0xa9, 7, 0}, 50 [DVBT_SCALE1_BA9] = {0x2a9, 7, 0},
54 [DVBT_SCALE1_BAA] = {0x2, 0xaa, 7, 0}, 51 [DVBT_SCALE1_BAA] = {0x2aa, 7, 0},
55 [DVBT_SCALE1_BAB] = {0x2, 0xab, 7, 0}, 52 [DVBT_SCALE1_BAB] = {0x2ab, 7, 0},
56 [DVBT_SCALE1_BAC] = {0x2, 0xac, 7, 0}, 53 [DVBT_SCALE1_BAC] = {0x2ac, 7, 0},
57 [DVBT_SCALE1_BB0] = {0x2, 0xb0, 7, 0}, 54 [DVBT_SCALE1_BB0] = {0x2b0, 7, 0},
58 [DVBT_SCALE1_BB1] = {0x2, 0xb1, 7, 0}, 55 [DVBT_SCALE1_BB1] = {0x2b1, 7, 0},
59 [DVBT_KB_P1] = {0x1, 0x64, 3, 1}, 56 [DVBT_KB_P1] = {0x164, 3, 1},
60 [DVBT_KB_P2] = {0x1, 0x64, 6, 4}, 57 [DVBT_KB_P2] = {0x164, 6, 4},
61 [DVBT_KB_P3] = {0x1, 0x65, 2, 0}, 58 [DVBT_KB_P3] = {0x165, 2, 0},
62 [DVBT_OPT_ADC_IQ] = {0x0, 0x6, 5, 4}, 59 [DVBT_OPT_ADC_IQ] = {0x006, 5, 4},
63 [DVBT_AD_AVI] = {0x0, 0x9, 1, 0}, 60 [DVBT_AD_AVI] = {0x009, 1, 0},
64 [DVBT_AD_AVQ] = {0x0, 0x9, 3, 2}, 61 [DVBT_AD_AVQ] = {0x009, 3, 2},
65 [DVBT_K1_CR_STEP12] = {0x2, 0xad, 9, 4}, 62 [DVBT_K1_CR_STEP12] = {0x2ad, 9, 4},
66 [DVBT_TRK_KS_P2] = {0x1, 0x6f, 2, 0}, 63 [DVBT_TRK_KS_P2] = {0x16f, 2, 0},
67 [DVBT_TRK_KS_I2] = {0x1, 0x70, 5, 3}, 64 [DVBT_TRK_KS_I2] = {0x170, 5, 3},
68 [DVBT_TR_THD_SET2] = {0x1, 0x72, 3, 0}, 65 [DVBT_TR_THD_SET2] = {0x172, 3, 0},
69 [DVBT_TRK_KC_P2] = {0x1, 0x73, 5, 3}, 66 [DVBT_TRK_KC_P2] = {0x173, 5, 3},
70 [DVBT_TRK_KC_I2] = {0x1, 0x75, 2, 0}, 67 [DVBT_TRK_KC_I2] = {0x175, 2, 0},
71 [DVBT_CR_THD_SET2] = {0x1, 0x76, 7, 6}, 68 [DVBT_CR_THD_SET2] = {0x176, 7, 6},
72 [DVBT_PSET_IFFREQ] = {0x1, 0x19, 21, 0}, 69 [DVBT_PSET_IFFREQ] = {0x119, 21, 0},
73 [DVBT_SPEC_INV] = {0x1, 0x15, 0, 0}, 70 [DVBT_SPEC_INV] = {0x115, 0, 0},
74 [DVBT_RSAMP_RATIO] = {0x1, 0x9f, 27, 2}, 71 [DVBT_RSAMP_RATIO] = {0x19f, 27, 2},
75 [DVBT_CFREQ_OFF_RATIO] = {0x1, 0x9d, 23, 4}, 72 [DVBT_CFREQ_OFF_RATIO] = {0x19d, 23, 4},
76 [DVBT_FSM_STAGE] = {0x3, 0x51, 6, 3}, 73 [DVBT_FSM_STAGE] = {0x351, 6, 3},
77 [DVBT_RX_CONSTEL] = {0x3, 0x3c, 3, 2}, 74 [DVBT_RX_CONSTEL] = {0x33c, 3, 2},
78 [DVBT_RX_HIER] = {0x3, 0x3c, 6, 4}, 75 [DVBT_RX_HIER] = {0x33c, 6, 4},
79 [DVBT_RX_C_RATE_LP] = {0x3, 0x3d, 2, 0}, 76 [DVBT_RX_C_RATE_LP] = {0x33d, 2, 0},
80 [DVBT_RX_C_RATE_HP] = {0x3, 0x3d, 5, 3}, 77 [DVBT_RX_C_RATE_HP] = {0x33d, 5, 3},
81 [DVBT_GI_IDX] = {0x3, 0x51, 1, 0}, 78 [DVBT_GI_IDX] = {0x351, 1, 0},
82 [DVBT_FFT_MODE_IDX] = {0x3, 0x51, 2, 2}, 79 [DVBT_FFT_MODE_IDX] = {0x351, 2, 2},
83 [DVBT_RSD_BER_EST] = {0x3, 0x4e, 15, 0}, 80 [DVBT_RSD_BER_EST] = {0x34e, 15, 0},
84 [DVBT_CE_EST_EVM] = {0x4, 0xc, 15, 0}, 81 [DVBT_CE_EST_EVM] = {0x40c, 15, 0},
85 [DVBT_RF_AGC_VAL] = {0x3, 0x5b, 13, 0}, 82 [DVBT_RF_AGC_VAL] = {0x35b, 13, 0},
86 [DVBT_IF_AGC_VAL] = {0x3, 0x59, 13, 0}, 83 [DVBT_IF_AGC_VAL] = {0x359, 13, 0},
87 [DVBT_DAGC_VAL] = {0x3, 0x5, 7, 0}, 84 [DVBT_DAGC_VAL] = {0x305, 7, 0},
88 [DVBT_SFREQ_OFF] = {0x3, 0x18, 13, 0}, 85 [DVBT_SFREQ_OFF] = {0x318, 13, 0},
89 [DVBT_CFREQ_OFF] = {0x3, 0x5f, 17, 0}, 86 [DVBT_CFREQ_OFF] = {0x35f, 17, 0},
90 [DVBT_POLAR_RF_AGC] = {0x0, 0xe, 1, 1}, 87 [DVBT_POLAR_RF_AGC] = {0x00e, 1, 1},
91 [DVBT_POLAR_IF_AGC] = {0x0, 0xe, 0, 0}, 88 [DVBT_POLAR_IF_AGC] = {0x00e, 0, 0},
92 [DVBT_AAGC_HOLD] = {0x1, 0x4, 5, 5}, 89 [DVBT_AAGC_HOLD] = {0x104, 5, 5},
93 [DVBT_EN_RF_AGC] = {0x1, 0x4, 6, 6}, 90 [DVBT_EN_RF_AGC] = {0x104, 6, 6},
94 [DVBT_EN_IF_AGC] = {0x1, 0x4, 7, 7}, 91 [DVBT_EN_IF_AGC] = {0x104, 7, 7},
95 [DVBT_IF_AGC_MIN] = {0x1, 0x8, 7, 0}, 92 [DVBT_IF_AGC_MIN] = {0x108, 7, 0},
96 [DVBT_IF_AGC_MAX] = {0x1, 0x9, 7, 0}, 93 [DVBT_IF_AGC_MAX] = {0x109, 7, 0},
97 [DVBT_RF_AGC_MIN] = {0x1, 0xa, 7, 0}, 94 [DVBT_RF_AGC_MIN] = {0x10a, 7, 0},
98 [DVBT_RF_AGC_MAX] = {0x1, 0xb, 7, 0}, 95 [DVBT_RF_AGC_MAX] = {0x10b, 7, 0},
99 [DVBT_IF_AGC_MAN] = {0x1, 0xc, 6, 6}, 96 [DVBT_IF_AGC_MAN] = {0x10c, 6, 6},
100 [DVBT_IF_AGC_MAN_VAL] = {0x1, 0xc, 13, 0}, 97 [DVBT_IF_AGC_MAN_VAL] = {0x10c, 13, 0},
101 [DVBT_RF_AGC_MAN] = {0x1, 0xe, 6, 6}, 98 [DVBT_RF_AGC_MAN] = {0x10e, 6, 6},
102 [DVBT_RF_AGC_MAN_VAL] = {0x1, 0xe, 13, 0}, 99 [DVBT_RF_AGC_MAN_VAL] = {0x10e, 13, 0},
103 [DVBT_DAGC_TRG_VAL] = {0x1, 0x12, 7, 0}, 100 [DVBT_DAGC_TRG_VAL] = {0x112, 7, 0},
104 [DVBT_AGC_TARG_VAL_0] = {0x1, 0x2, 0, 0}, 101 [DVBT_AGC_TARG_VAL_0] = {0x102, 0, 0},
105 [DVBT_AGC_TARG_VAL_8_1] = {0x1, 0x3, 7, 0}, 102 [DVBT_AGC_TARG_VAL_8_1] = {0x103, 7, 0},
106 [DVBT_AAGC_LOOP_GAIN] = {0x1, 0xc7, 5, 1}, 103 [DVBT_AAGC_LOOP_GAIN] = {0x1c7, 5, 1},
107 [DVBT_LOOP_GAIN2_3_0] = {0x1, 0x4, 4, 1}, 104 [DVBT_LOOP_GAIN2_3_0] = {0x104, 4, 1},
108 [DVBT_LOOP_GAIN2_4] = {0x1, 0x5, 7, 7}, 105 [DVBT_LOOP_GAIN2_4] = {0x105, 7, 7},
109 [DVBT_LOOP_GAIN3] = {0x1, 0xc8, 4, 0}, 106 [DVBT_LOOP_GAIN3] = {0x1c8, 4, 0},
110 [DVBT_VTOP1] = {0x1, 0x6, 5, 0}, 107 [DVBT_VTOP1] = {0x106, 5, 0},
111 [DVBT_VTOP2] = {0x1, 0xc9, 5, 0}, 108 [DVBT_VTOP2] = {0x1c9, 5, 0},
112 [DVBT_VTOP3] = {0x1, 0xca, 5, 0}, 109 [DVBT_VTOP3] = {0x1ca, 5, 0},
113 [DVBT_KRF1] = {0x1, 0xcb, 7, 0}, 110 [DVBT_KRF1] = {0x1cb, 7, 0},
114 [DVBT_KRF2] = {0x1, 0x7, 7, 0}, 111 [DVBT_KRF2] = {0x107, 7, 0},
115 [DVBT_KRF3] = {0x1, 0xcd, 7, 0}, 112 [DVBT_KRF3] = {0x1cd, 7, 0},
116 [DVBT_KRF4] = {0x1, 0xce, 7, 0}, 113 [DVBT_KRF4] = {0x1ce, 7, 0},
117 [DVBT_EN_GI_PGA] = {0x1, 0xe5, 0, 0}, 114 [DVBT_EN_GI_PGA] = {0x1e5, 0, 0},
118 [DVBT_THD_LOCK_UP] = {0x1, 0xd9, 8, 0}, 115 [DVBT_THD_LOCK_UP] = {0x1d9, 8, 0},
119 [DVBT_THD_LOCK_DW] = {0x1, 0xdb, 8, 0}, 116 [DVBT_THD_LOCK_DW] = {0x1db, 8, 0},
120 [DVBT_THD_UP1] = {0x1, 0xdd, 7, 0}, 117 [DVBT_THD_UP1] = {0x1dd, 7, 0},
121 [DVBT_THD_DW1] = {0x1, 0xde, 7, 0}, 118 [DVBT_THD_DW1] = {0x1de, 7, 0},
122 [DVBT_INTER_CNT_LEN] = {0x1, 0xd8, 3, 0}, 119 [DVBT_INTER_CNT_LEN] = {0x1d8, 3, 0},
123 [DVBT_GI_PGA_STATE] = {0x1, 0xe6, 3, 3}, 120 [DVBT_GI_PGA_STATE] = {0x1e6, 3, 3},
124 [DVBT_EN_AGC_PGA] = {0x1, 0xd7, 0, 0}, 121 [DVBT_EN_AGC_PGA] = {0x1d7, 0, 0},
125 [DVBT_CKOUTPAR] = {0x1, 0x7b, 5, 5}, 122 [DVBT_CKOUTPAR] = {0x17b, 5, 5},
126 [DVBT_CKOUT_PWR] = {0x1, 0x7b, 6, 6}, 123 [DVBT_CKOUT_PWR] = {0x17b, 6, 6},
127 [DVBT_SYNC_DUR] = {0x1, 0x7b, 7, 7}, 124 [DVBT_SYNC_DUR] = {0x17b, 7, 7},
128 [DVBT_ERR_DUR] = {0x1, 0x7c, 0, 0}, 125 [DVBT_ERR_DUR] = {0x17c, 0, 0},
129 [DVBT_SYNC_LVL] = {0x1, 0x7c, 1, 1}, 126 [DVBT_SYNC_LVL] = {0x17c, 1, 1},
130 [DVBT_ERR_LVL] = {0x1, 0x7c, 2, 2}, 127 [DVBT_ERR_LVL] = {0x17c, 2, 2},
131 [DVBT_VAL_LVL] = {0x1, 0x7c, 3, 3}, 128 [DVBT_VAL_LVL] = {0x17c, 3, 3},
132 [DVBT_SERIAL] = {0x1, 0x7c, 4, 4}, 129 [DVBT_SERIAL] = {0x17c, 4, 4},
133 [DVBT_SER_LSB] = {0x1, 0x7c, 5, 5}, 130 [DVBT_SER_LSB] = {0x17c, 5, 5},
134 [DVBT_CDIV_PH0] = {0x1, 0x7d, 3, 0}, 131 [DVBT_CDIV_PH0] = {0x17d, 3, 0},
135 [DVBT_CDIV_PH1] = {0x1, 0x7d, 7, 4}, 132 [DVBT_CDIV_PH1] = {0x17d, 7, 4},
136 [DVBT_MPEG_IO_OPT_2_2] = {0x0, 0x6, 7, 7}, 133 [DVBT_MPEG_IO_OPT_2_2] = {0x006, 7, 7},
137 [DVBT_MPEG_IO_OPT_1_0] = {0x0, 0x7, 7, 6}, 134 [DVBT_MPEG_IO_OPT_1_0] = {0x007, 7, 6},
138 [DVBT_CKOUTPAR_PIP] = {0x0, 0xb7, 4, 4}, 135 [DVBT_CKOUTPAR_PIP] = {0x0b7, 4, 4},
139 [DVBT_CKOUT_PWR_PIP] = {0x0, 0xb7, 3, 3}, 136 [DVBT_CKOUT_PWR_PIP] = {0x0b7, 3, 3},
140 [DVBT_SYNC_LVL_PIP] = {0x0, 0xb7, 2, 2}, 137 [DVBT_SYNC_LVL_PIP] = {0x0b7, 2, 2},
141 [DVBT_ERR_LVL_PIP] = {0x0, 0xb7, 1, 1}, 138 [DVBT_ERR_LVL_PIP] = {0x0b7, 1, 1},
142 [DVBT_VAL_LVL_PIP] = {0x0, 0xb7, 0, 0}, 139 [DVBT_VAL_LVL_PIP] = {0x0b7, 0, 0},
143 [DVBT_CKOUTPAR_PID] = {0x0, 0xb9, 4, 4}, 140 [DVBT_CKOUTPAR_PID] = {0x0b9, 4, 4},
144 [DVBT_CKOUT_PWR_PID] = {0x0, 0xb9, 3, 3}, 141 [DVBT_CKOUT_PWR_PID] = {0x0b9, 3, 3},
145 [DVBT_SYNC_LVL_PID] = {0x0, 0xb9, 2, 2}, 142 [DVBT_SYNC_LVL_PID] = {0x0b9, 2, 2},
146 [DVBT_ERR_LVL_PID] = {0x0, 0xb9, 1, 1}, 143 [DVBT_ERR_LVL_PID] = {0x0b9, 1, 1},
147 [DVBT_VAL_LVL_PID] = {0x0, 0xb9, 0, 0}, 144 [DVBT_VAL_LVL_PID] = {0x0b9, 0, 0},
148 [DVBT_SM_PASS] = {0x1, 0x93, 11, 0}, 145 [DVBT_SM_PASS] = {0x193, 11, 0},
149 [DVBT_AD7_SETTING] = {0x0, 0x11, 15, 0}, 146 [DVBT_AD7_SETTING] = {0x011, 15, 0},
150 [DVBT_RSSI_R] = {0x3, 0x1, 6, 0}, 147 [DVBT_RSSI_R] = {0x301, 6, 0},
151 [DVBT_ACI_DET_IND] = {0x3, 0x12, 0, 0}, 148 [DVBT_ACI_DET_IND] = {0x312, 0, 0},
152 [DVBT_REG_MON] = {0x0, 0xd, 1, 0}, 149 [DVBT_REG_MON] = {0x00d, 1, 0},
153 [DVBT_REG_MONSEL] = {0x0, 0xd, 2, 2}, 150 [DVBT_REG_MONSEL] = {0x00d, 2, 2},
154 [DVBT_REG_GPE] = {0x0, 0xd, 7, 7}, 151 [DVBT_REG_GPE] = {0x00d, 7, 7},
155 [DVBT_REG_GPO] = {0x0, 0x10, 0, 0}, 152 [DVBT_REG_GPO] = {0x010, 0, 0},
156 [DVBT_REG_4MSEL] = {0x0, 0x13, 0, 0}, 153 [DVBT_REG_4MSEL] = {0x013, 0, 0},
157}; 154};
158 155
159/* write multiple hardware registers */ 156/* Our regmap is bypassing I2C adapter lock, thus we do it! */
160static int rtl2832_wr(struct rtl2832_priv *priv, u8 reg, u8 *val, int len) 157static int rtl2832_bulk_write(struct i2c_client *client, unsigned int reg,
158 const void *val, size_t val_count)
161{ 159{
160 struct rtl2832_dev *dev = i2c_get_clientdata(client);
162 int ret; 161 int ret;
163 u8 buf[MAX_XFER_SIZE];
164 struct i2c_msg msg[1] = {
165 {
166 .addr = priv->cfg.i2c_addr,
167 .flags = 0,
168 .len = 1 + len,
169 .buf = buf,
170 }
171 };
172 162
173 if (1 + len > sizeof(buf)) { 163 i2c_lock_adapter(client->adapter);
174 dev_warn(&priv->i2c->dev, 164 ret = regmap_bulk_write(dev->regmap, reg, val, val_count);
175 "%s: i2c wr reg=%04x: len=%d is too big!\n", 165 i2c_unlock_adapter(client->adapter);
176 KBUILD_MODNAME, reg, len);
177 return -EINVAL;
178 }
179
180 buf[0] = reg;
181 memcpy(&buf[1], val, len);
182
183 ret = i2c_transfer(priv->i2c_adapter, msg, 1);
184 if (ret == 1) {
185 ret = 0;
186 } else {
187 dev_warn(&priv->i2c->dev,
188 "%s: i2c wr failed=%d reg=%02x len=%d\n",
189 KBUILD_MODNAME, ret, reg, len);
190 ret = -EREMOTEIO;
191 }
192 return ret; 166 return ret;
193} 167}
194 168
195/* read multiple hardware registers */ 169static int rtl2832_update_bits(struct i2c_client *client, unsigned int reg,
196static int rtl2832_rd(struct rtl2832_priv *priv, u8 reg, u8 *val, int len) 170 unsigned int mask, unsigned int val)
197{ 171{
172 struct rtl2832_dev *dev = i2c_get_clientdata(client);
198 int ret; 173 int ret;
199 struct i2c_msg msg[2] = {
200 {
201 .addr = priv->cfg.i2c_addr,
202 .flags = 0,
203 .len = 1,
204 .buf = &reg,
205 }, {
206 .addr = priv->cfg.i2c_addr,
207 .flags = I2C_M_RD,
208 .len = len,
209 .buf = val,
210 }
211 };
212 174
213 ret = i2c_transfer(priv->i2c_adapter, msg, 2); 175 i2c_lock_adapter(client->adapter);
214 if (ret == 2) { 176 ret = regmap_update_bits(dev->regmap, reg, mask, val);
215 ret = 0; 177 i2c_unlock_adapter(client->adapter);
216 } else {
217 dev_warn(&priv->i2c->dev,
218 "%s: i2c rd failed=%d reg=%02x len=%d\n",
219 KBUILD_MODNAME, ret, reg, len);
220 ret = -EREMOTEIO;
221 }
222 return ret; 178 return ret;
223} 179}
224 180
225/* write multiple registers */ 181static int rtl2832_bulk_read(struct i2c_client *client, unsigned int reg,
226static int rtl2832_wr_regs(struct rtl2832_priv *priv, u8 reg, u8 page, u8 *val, 182 void *val, size_t val_count)
227 int len)
228{
229 int ret;
230
231 /* switch bank if needed */
232 if (page != priv->page) {
233 ret = rtl2832_wr(priv, 0x00, &page, 1);
234 if (ret)
235 return ret;
236
237 priv->page = page;
238}
239
240return rtl2832_wr(priv, reg, val, len);
241}
242
243/* read multiple registers */
244static int rtl2832_rd_regs(struct rtl2832_priv *priv, u8 reg, u8 page, u8 *val,
245 int len)
246{ 183{
184 struct rtl2832_dev *dev = i2c_get_clientdata(client);
247 int ret; 185 int ret;
248 186
249 /* switch bank if needed */ 187 i2c_lock_adapter(client->adapter);
250 if (page != priv->page) { 188 ret = regmap_bulk_read(dev->regmap, reg, val, val_count);
251 ret = rtl2832_wr(priv, 0x00, &page, 1); 189 i2c_unlock_adapter(client->adapter);
252 if (ret) 190 return ret;
253 return ret;
254
255 priv->page = page;
256 }
257
258 return rtl2832_rd(priv, reg, val, len);
259}
260
261/* write single register */
262static int rtl2832_wr_reg(struct rtl2832_priv *priv, u8 reg, u8 page, u8 val)
263{
264 return rtl2832_wr_regs(priv, reg, page, &val, 1);
265}
266
267/* read single register */
268static int rtl2832_rd_reg(struct rtl2832_priv *priv, u8 reg, u8 page, u8 *val)
269{
270 return rtl2832_rd_regs(priv, reg, page, val, 1);
271} 191}
272 192
273static int rtl2832_rd_demod_reg(struct rtl2832_priv *priv, int reg, u32 *val) 193static int rtl2832_rd_demod_reg(struct rtl2832_dev *dev, int reg, u32 *val)
274{ 194{
275 int ret; 195 struct i2c_client *client = dev->client;
276 196 int ret, i;
277 u8 reg_start_addr; 197 u16 reg_start_addr;
278 u8 msb, lsb; 198 u8 msb, lsb, reading[4], len;
279 u8 page; 199 u32 reading_tmp, mask;
280 u8 reading[4];
281 u32 reading_tmp;
282 int i;
283
284 u8 len;
285 u32 mask;
286 200
287 reg_start_addr = registers[reg].start_address; 201 reg_start_addr = registers[reg].start_address;
288 msb = registers[reg].msb; 202 msb = registers[reg].msb;
289 lsb = registers[reg].lsb; 203 lsb = registers[reg].lsb;
290 page = registers[reg].page;
291
292 len = (msb >> 3) + 1; 204 len = (msb >> 3) + 1;
293 mask = REG_MASK(msb - lsb); 205 mask = REG_MASK(msb - lsb);
294 206
295 ret = rtl2832_rd_regs(priv, reg_start_addr, page, &reading[0], len); 207 ret = rtl2832_bulk_read(client, reg_start_addr, reading, len);
296 if (ret) 208 if (ret)
297 goto err; 209 goto err;
298 210
@@ -302,40 +214,27 @@ static int rtl2832_rd_demod_reg(struct rtl2832_priv *priv, int reg, u32 *val)
302 214
303 *val = (reading_tmp >> lsb) & mask; 215 *val = (reading_tmp >> lsb) & mask;
304 216
305 return ret; 217 return 0;
306
307err: 218err:
308 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 219 dev_dbg(&client->dev, "failed=%d\n", ret);
309 return ret; 220 return ret;
310
311} 221}
312 222
313static int rtl2832_wr_demod_reg(struct rtl2832_priv *priv, int reg, u32 val) 223static int rtl2832_wr_demod_reg(struct rtl2832_dev *dev, int reg, u32 val)
314{ 224{
225 struct i2c_client *client = dev->client;
315 int ret, i; 226 int ret, i;
316 u8 len; 227 u16 reg_start_addr;
317 u8 reg_start_addr; 228 u8 msb, lsb, reading[4], writing[4], len;
318 u8 msb, lsb; 229 u32 reading_tmp, writing_tmp, mask;
319 u8 page;
320 u32 mask;
321
322
323 u8 reading[4];
324 u8 writing[4];
325 u32 reading_tmp;
326 u32 writing_tmp;
327
328 230
329 reg_start_addr = registers[reg].start_address; 231 reg_start_addr = registers[reg].start_address;
330 msb = registers[reg].msb; 232 msb = registers[reg].msb;
331 lsb = registers[reg].lsb; 233 lsb = registers[reg].lsb;
332 page = registers[reg].page;
333
334 len = (msb >> 3) + 1; 234 len = (msb >> 3) + 1;
335 mask = REG_MASK(msb - lsb); 235 mask = REG_MASK(msb - lsb);
336 236
337 237 ret = rtl2832_bulk_read(client, reg_start_addr, reading, len);
338 ret = rtl2832_rd_regs(priv, reg_start_addr, page, &reading[0], len);
339 if (ret) 238 if (ret)
340 goto err; 239 goto err;
341 240
@@ -346,49 +245,23 @@ static int rtl2832_wr_demod_reg(struct rtl2832_priv *priv, int reg, u32 val)
346 writing_tmp = reading_tmp & ~(mask << lsb); 245 writing_tmp = reading_tmp & ~(mask << lsb);
347 writing_tmp |= ((val & mask) << lsb); 246 writing_tmp |= ((val & mask) << lsb);
348 247
349
350 for (i = 0; i < len; i++) 248 for (i = 0; i < len; i++)
351 writing[i] = (writing_tmp >> ((len - 1 - i) * 8)) & 0xff; 249 writing[i] = (writing_tmp >> ((len - 1 - i) * 8)) & 0xff;
352 250
353 ret = rtl2832_wr_regs(priv, reg_start_addr, page, &writing[0], len); 251 ret = rtl2832_bulk_write(client, reg_start_addr, writing, len);
354 if (ret)
355 goto err;
356
357 return ret;
358
359err:
360 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
361 return ret;
362
363}
364
365static int rtl2832_i2c_gate_ctrl(struct dvb_frontend *fe, int enable)
366{
367 int ret;
368 struct rtl2832_priv *priv = fe->demodulator_priv;
369
370 dev_dbg(&priv->i2c->dev, "%s: enable=%d\n", __func__, enable);
371
372 /* gate already open or close */
373 if (priv->i2c_gate_state == enable)
374 return 0;
375
376 ret = rtl2832_wr_demod_reg(priv, DVBT_IIC_REPEAT, (enable ? 0x1 : 0x0));
377 if (ret) 252 if (ret)
378 goto err; 253 goto err;
379 254
380 priv->i2c_gate_state = enable; 255 return 0;
381
382 return ret;
383err: 256err:
384 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 257 dev_dbg(&client->dev, "failed=%d\n", ret);
385 return ret; 258 return ret;
386} 259}
387 260
388
389static int rtl2832_set_if(struct dvb_frontend *fe, u32 if_freq) 261static int rtl2832_set_if(struct dvb_frontend *fe, u32 if_freq)
390{ 262{
391 struct rtl2832_priv *priv = fe->demodulator_priv; 263 struct rtl2832_dev *dev = fe->demodulator_priv;
264 struct i2c_client *client = dev->client;
392 int ret; 265 int ret;
393 u64 pset_iffreq; 266 u64 pset_iffreq;
394 u8 en_bbin = (if_freq == 0 ? 0x1 : 0x0); 267 u8 en_bbin = (if_freq == 0 ? 0x1 : 0x0);
@@ -397,30 +270,35 @@ static int rtl2832_set_if(struct dvb_frontend *fe, u32 if_freq)
397 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22) 270 * PSET_IFFREQ = - floor((IfFreqHz % CrystalFreqHz) * pow(2, 22)
398 * / CrystalFreqHz) 271 * / CrystalFreqHz)
399 */ 272 */
400 273 pset_iffreq = if_freq % dev->pdata->clk;
401 pset_iffreq = if_freq % priv->cfg.xtal;
402 pset_iffreq *= 0x400000; 274 pset_iffreq *= 0x400000;
403 pset_iffreq = div_u64(pset_iffreq, priv->cfg.xtal); 275 pset_iffreq = div_u64(pset_iffreq, dev->pdata->clk);
404 pset_iffreq = -pset_iffreq; 276 pset_iffreq = -pset_iffreq;
405 pset_iffreq = pset_iffreq & 0x3fffff; 277 pset_iffreq = pset_iffreq & 0x3fffff;
406 dev_dbg(&priv->i2c->dev, "%s: if_frequency=%d pset_iffreq=%08x\n", 278 dev_dbg(&client->dev, "if_frequency=%d pset_iffreq=%08x\n",
407 __func__, if_freq, (unsigned)pset_iffreq); 279 if_freq, (unsigned)pset_iffreq);
408 280
409 ret = rtl2832_wr_demod_reg(priv, DVBT_EN_BBIN, en_bbin); 281 ret = rtl2832_wr_demod_reg(dev, DVBT_EN_BBIN, en_bbin);
410 if (ret) 282 if (ret)
411 return ret; 283 goto err;
412 284
413 ret = rtl2832_wr_demod_reg(priv, DVBT_PSET_IFFREQ, pset_iffreq); 285 ret = rtl2832_wr_demod_reg(dev, DVBT_PSET_IFFREQ, pset_iffreq);
286 if (ret)
287 goto err;
414 288
289 return 0;
290err:
291 dev_dbg(&client->dev, "failed=%d\n", ret);
415 return ret; 292 return ret;
416} 293}
417 294
418static int rtl2832_init(struct dvb_frontend *fe) 295static int rtl2832_init(struct dvb_frontend *fe)
419{ 296{
420 struct rtl2832_priv *priv = fe->demodulator_priv; 297 struct rtl2832_dev *dev = fe->demodulator_priv;
298 struct i2c_client *client = dev->client;
299 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
421 const struct rtl2832_reg_value *init; 300 const struct rtl2832_reg_value *init;
422 int i, ret, len; 301 int i, ret, len;
423
424 /* initialization values for the demodulator registers */ 302 /* initialization values for the demodulator registers */
425 struct rtl2832_reg_value rtl2832_initial_regs[] = { 303 struct rtl2832_reg_value rtl2832_initial_regs[] = {
426 {DVBT_AD_EN_REG, 0x1}, 304 {DVBT_AD_EN_REG, 0x1},
@@ -467,19 +345,19 @@ static int rtl2832_init(struct dvb_frontend *fe)
467 {DVBT_CR_THD_SET2, 0x1}, 345 {DVBT_CR_THD_SET2, 0x1},
468 }; 346 };
469 347
470 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 348 dev_dbg(&client->dev, "\n");
471 349
472 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) { 350 for (i = 0; i < ARRAY_SIZE(rtl2832_initial_regs); i++) {
473 ret = rtl2832_wr_demod_reg(priv, rtl2832_initial_regs[i].reg, 351 ret = rtl2832_wr_demod_reg(dev, rtl2832_initial_regs[i].reg,
474 rtl2832_initial_regs[i].value); 352 rtl2832_initial_regs[i].value);
475 if (ret) 353 if (ret)
476 goto err; 354 goto err;
477 } 355 }
478 356
479 /* load tuner specific settings */ 357 /* load tuner specific settings */
480 dev_dbg(&priv->i2c->dev, "%s: load settings for tuner=%02x\n", 358 dev_dbg(&client->dev, "load settings for tuner=%02x\n",
481 __func__, priv->cfg.tuner); 359 dev->pdata->tuner);
482 switch (priv->cfg.tuner) { 360 switch (dev->pdata->tuner) {
483 case RTL2832_TUNER_FC0012: 361 case RTL2832_TUNER_FC0012:
484 case RTL2832_TUNER_FC0013: 362 case RTL2832_TUNER_FC0013:
485 len = ARRAY_SIZE(rtl2832_tuner_init_fc0012); 363 len = ARRAY_SIZE(rtl2832_tuner_init_fc0012);
@@ -504,51 +382,60 @@ static int rtl2832_init(struct dvb_frontend *fe)
504 } 382 }
505 383
506 for (i = 0; i < len; i++) { 384 for (i = 0; i < len; i++) {
507 ret = rtl2832_wr_demod_reg(priv, init[i].reg, init[i].value); 385 ret = rtl2832_wr_demod_reg(dev, init[i].reg, init[i].value);
508 if (ret) 386 if (ret)
509 goto err; 387 goto err;
510 } 388 }
511 389
512 /* 390 /* init stats here in order signal app which stats are supported */
513 * r820t NIM code does a software reset here at the demod - 391 c->strength.len = 1;
514 * may not be needed, as there's already a software reset at 392 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
515 * set_params() 393 c->cnr.len = 1;
516 */ 394 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
517#if 1 395 c->post_bit_error.len = 1;
518 /* soft reset */ 396 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
519 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x1); 397 c->post_bit_count.len = 1;
520 if (ret) 398 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
521 goto err; 399 /* start statistics polling */
522 400 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
523 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x0); 401 dev->sleeping = false;
524 if (ret)
525 goto err;
526#endif
527
528 priv->sleeping = false;
529
530 return ret;
531 402
403 return 0;
532err: 404err:
533 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 405 dev_dbg(&client->dev, "failed=%d\n", ret);
534 return ret; 406 return ret;
535} 407}
536 408
537static int rtl2832_sleep(struct dvb_frontend *fe) 409static int rtl2832_sleep(struct dvb_frontend *fe)
538{ 410{
539 struct rtl2832_priv *priv = fe->demodulator_priv; 411 struct rtl2832_dev *dev = fe->demodulator_priv;
412 struct i2c_client *client = dev->client;
413 int ret;
414
415 dev_dbg(&client->dev, "\n");
416
417 dev->sleeping = true;
418 /* stop statistics polling */
419 cancel_delayed_work_sync(&dev->stat_work);
420 dev->fe_status = 0;
421
422 ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x1);
423 if (ret)
424 goto err;
540 425
541 dev_dbg(&priv->i2c->dev, "%s:\n", __func__);
542 priv->sleeping = true;
543 return 0; 426 return 0;
427err:
428 dev_dbg(&client->dev, "failed=%d\n", ret);
429 return ret;
544} 430}
545 431
546static int rtl2832_get_tune_settings(struct dvb_frontend *fe, 432static int rtl2832_get_tune_settings(struct dvb_frontend *fe,
547 struct dvb_frontend_tune_settings *s) 433 struct dvb_frontend_tune_settings *s)
548{ 434{
549 struct rtl2832_priv *priv = fe->demodulator_priv; 435 struct rtl2832_dev *dev = fe->demodulator_priv;
436 struct i2c_client *client = dev->client;
550 437
551 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 438 dev_dbg(&client->dev, "\n");
552 s->min_delay_ms = 1000; 439 s->min_delay_ms = 1000;
553 s->step_size = fe->ops.info.frequency_stepsize * 2; 440 s->step_size = fe->ops.info.frequency_stepsize * 2;
554 s->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1; 441 s->max_drift = (fe->ops.info.frequency_stepsize * 2) + 1;
@@ -557,7 +444,8 @@ static int rtl2832_get_tune_settings(struct dvb_frontend *fe,
557 444
558static int rtl2832_set_frontend(struct dvb_frontend *fe) 445static int rtl2832_set_frontend(struct dvb_frontend *fe)
559{ 446{
560 struct rtl2832_priv *priv = fe->demodulator_priv; 447 struct rtl2832_dev *dev = fe->demodulator_priv;
448 struct i2c_client *client = dev->client;
561 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 449 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
562 int ret, i, j; 450 int ret, i, j;
563 u64 bw_mode, num, num2; 451 u64 bw_mode, num, num2;
@@ -588,17 +476,15 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
588 }, 476 },
589 }; 477 };
590 478
591 479 dev_dbg(&client->dev, "frequency=%u bandwidth_hz=%u inversion=%u\n",
592 dev_dbg(&priv->i2c->dev, 480 c->frequency, c->bandwidth_hz, c->inversion);
593 "%s: frequency=%d bandwidth_hz=%d inversion=%d\n",
594 __func__, c->frequency, c->bandwidth_hz, c->inversion);
595 481
596 /* program tuner */ 482 /* program tuner */
597 if (fe->ops.tuner_ops.set_params) 483 if (fe->ops.tuner_ops.set_params)
598 fe->ops.tuner_ops.set_params(fe); 484 fe->ops.tuner_ops.set_params(fe);
599 485
600 /* PIP mode related */ 486 /* PIP mode related */
601 ret = rtl2832_wr_regs(priv, 0x92, 1, "\x00\x0f\xff", 3); 487 ret = rtl2832_bulk_write(client, 0x192, "\x00\x0f\xff", 3);
602 if (ret) 488 if (ret)
603 goto err; 489 goto err;
604 490
@@ -629,12 +515,14 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
629 bw_mode = 64000000; 515 bw_mode = 64000000;
630 break; 516 break;
631 default: 517 default:
632 dev_dbg(&priv->i2c->dev, "%s: invalid bandwidth\n", __func__); 518 dev_err(&client->dev, "invalid bandwidth_hz %u\n",
633 return -EINVAL; 519 c->bandwidth_hz);
520 ret = -EINVAL;
521 goto err;
634 } 522 }
635 523
636 for (j = 0; j < sizeof(bw_params[0]); j++) { 524 for (j = 0; j < sizeof(bw_params[0]); j++) {
637 ret = rtl2832_wr_regs(priv, 0x1c+j, 1, &bw_params[i][j], 1); 525 ret = rtl2832_bulk_write(client, 0x11c + j, &bw_params[i][j], 1);
638 if (ret) 526 if (ret)
639 goto err; 527 goto err;
640 } 528 }
@@ -643,11 +531,11 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
643 * RSAMP_RATIO = floor(CrystalFreqHz * 7 * pow(2, 22) 531 * RSAMP_RATIO = floor(CrystalFreqHz * 7 * pow(2, 22)
644 * / ConstWithBandwidthMode) 532 * / ConstWithBandwidthMode)
645 */ 533 */
646 num = priv->cfg.xtal * 7; 534 num = dev->pdata->clk * 7;
647 num *= 0x400000; 535 num *= 0x400000;
648 num = div_u64(num, bw_mode); 536 num = div_u64(num, bw_mode);
649 resamp_ratio = num & 0x3ffffff; 537 resamp_ratio = num & 0x3ffffff;
650 ret = rtl2832_wr_demod_reg(priv, DVBT_RSAMP_RATIO, resamp_ratio); 538 ret = rtl2832_wr_demod_reg(dev, DVBT_RSAMP_RATIO, resamp_ratio);
651 if (ret) 539 if (ret)
652 goto err; 540 goto err;
653 541
@@ -656,48 +544,49 @@ static int rtl2832_set_frontend(struct dvb_frontend *fe)
656 * / (CrystalFreqHz * 7)) 544 * / (CrystalFreqHz * 7))
657 */ 545 */
658 num = bw_mode << 20; 546 num = bw_mode << 20;
659 num2 = priv->cfg.xtal * 7; 547 num2 = dev->pdata->clk * 7;
660 num = div_u64(num, num2); 548 num = div_u64(num, num2);
661 num = -num; 549 num = -num;
662 cfreq_off_ratio = num & 0xfffff; 550 cfreq_off_ratio = num & 0xfffff;
663 ret = rtl2832_wr_demod_reg(priv, DVBT_CFREQ_OFF_RATIO, cfreq_off_ratio); 551 ret = rtl2832_wr_demod_reg(dev, DVBT_CFREQ_OFF_RATIO, cfreq_off_ratio);
664 if (ret) 552 if (ret)
665 goto err; 553 goto err;
666 554
667 /* soft reset */ 555 /* soft reset */
668 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x1); 556 ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x1);
669 if (ret) 557 if (ret)
670 goto err; 558 goto err;
671 559
672 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x0); 560 ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x0);
673 if (ret) 561 if (ret)
674 goto err; 562 goto err;
675 563
676 return ret; 564 return 0;
677err: 565err:
678 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 566 dev_dbg(&client->dev, "failed=%d\n", ret);
679 return ret; 567 return ret;
680} 568}
681 569
682static int rtl2832_get_frontend(struct dvb_frontend *fe) 570static int rtl2832_get_frontend(struct dvb_frontend *fe)
683{ 571{
684 struct rtl2832_priv *priv = fe->demodulator_priv; 572 struct rtl2832_dev *dev = fe->demodulator_priv;
573 struct i2c_client *client = dev->client;
685 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 574 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
686 int ret; 575 int ret;
687 u8 buf[3]; 576 u8 buf[3];
688 577
689 if (priv->sleeping) 578 if (dev->sleeping)
690 return 0; 579 return 0;
691 580
692 ret = rtl2832_rd_regs(priv, 0x3c, 3, buf, 2); 581 ret = rtl2832_bulk_read(client, 0x33c, buf, 2);
693 if (ret) 582 if (ret)
694 goto err; 583 goto err;
695 584
696 ret = rtl2832_rd_reg(priv, 0x51, 3, &buf[2]); 585 ret = rtl2832_bulk_read(client, 0x351, &buf[2], 1);
697 if (ret) 586 if (ret)
698 goto err; 587 goto err;
699 588
700 dev_dbg(&priv->i2c->dev, "%s: TPS=%*ph\n", __func__, 3, buf); 589 dev_dbg(&client->dev, "TPS=%*ph\n", 3, buf);
701 590
702 switch ((buf[0] >> 2) & 3) { 591 switch ((buf[0] >> 2) & 3) {
703 case 0: 592 case 0:
@@ -787,403 +676,652 @@ static int rtl2832_get_frontend(struct dvb_frontend *fe)
787 676
788 return 0; 677 return 0;
789err: 678err:
790 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 679 dev_dbg(&client->dev, "failed=%d\n", ret);
791 return ret; 680 return ret;
792} 681}
793 682
794static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status) 683static int rtl2832_read_status(struct dvb_frontend *fe, fe_status_t *status)
795{ 684{
796 struct rtl2832_priv *priv = fe->demodulator_priv; 685 struct rtl2832_dev *dev = fe->demodulator_priv;
686 struct i2c_client *client = dev->client;
797 int ret; 687 int ret;
798 u32 tmp; 688 u32 tmp;
799 *status = 0;
800 689
801 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 690 dev_dbg(&client->dev, "\n");
802 if (priv->sleeping) 691
692 *status = 0;
693 if (dev->sleeping)
803 return 0; 694 return 0;
804 695
805 ret = rtl2832_rd_demod_reg(priv, DVBT_FSM_STAGE, &tmp); 696 ret = rtl2832_rd_demod_reg(dev, DVBT_FSM_STAGE, &tmp);
806 if (ret) 697 if (ret)
807 goto err; 698 goto err;
808 699
809 if (tmp == 11) { 700 if (tmp == 11) {
810 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | 701 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
811 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK; 702 FE_HAS_VITERBI | FE_HAS_SYNC | FE_HAS_LOCK;
812 } 703 } else if (tmp == 10) {
813 /* TODO find out if this is also true for rtl2832? */
814 /*else if (tmp == 10) {
815 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER | 704 *status |= FE_HAS_SIGNAL | FE_HAS_CARRIER |
816 FE_HAS_VITERBI; 705 FE_HAS_VITERBI;
817 }*/ 706 }
818 707
819 return ret; 708 dev->fe_status = *status;
709 return 0;
820err: 710err:
821 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 711 dev_dbg(&client->dev, "failed=%d\n", ret);
822 return ret; 712 return ret;
823} 713}
824 714
825static int rtl2832_read_snr(struct dvb_frontend *fe, u16 *snr) 715static int rtl2832_read_snr(struct dvb_frontend *fe, u16 *snr)
826{ 716{
827 struct rtl2832_priv *priv = fe->demodulator_priv; 717 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
828 int ret, hierarchy, constellation;
829 u8 buf[2], tmp;
830 u16 tmp16;
831#define CONSTELLATION_NUM 3
832#define HIERARCHY_NUM 4
833 static const u32 snr_constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
834 { 85387325, 85387325, 85387325, 85387325 },
835 { 86676178, 86676178, 87167949, 87795660 },
836 { 87659938, 87659938, 87885178, 88241743 },
837 };
838 718
839 /* reports SNR in resolution of 0.1 dB */ 719 /* report SNR in resolution of 0.1 dB */
720 if (c->cnr.stat[0].scale == FE_SCALE_DECIBEL)
721 *snr = div_s64(c->cnr.stat[0].svalue, 100);
722 else
723 *snr = 0;
840 724
841 ret = rtl2832_rd_reg(priv, 0x3c, 3, &tmp); 725 return 0;
842 if (ret) 726}
843 goto err;
844 727
845 constellation = (tmp >> 2) & 0x03; /* [3:2] */ 728static int rtl2832_read_ber(struct dvb_frontend *fe, u32 *ber)
846 if (constellation > CONSTELLATION_NUM - 1) 729{
847 goto err; 730 struct rtl2832_dev *dev = fe->demodulator_priv;
848 731
849 hierarchy = (tmp >> 4) & 0x07; /* [6:4] */ 732 *ber = (dev->post_bit_error - dev->post_bit_error_prev);
850 if (hierarchy > HIERARCHY_NUM - 1) 733 dev->post_bit_error_prev = dev->post_bit_error;
851 goto err;
852 734
853 ret = rtl2832_rd_regs(priv, 0x0c, 4, buf, 2); 735 return 0;
854 if (ret) 736}
855 goto err;
856 737
857 tmp16 = buf[0] << 8 | buf[1]; 738static void rtl2832_stat_work(struct work_struct *work)
739{
740 struct rtl2832_dev *dev = container_of(work, struct rtl2832_dev, stat_work.work);
741 struct i2c_client *client = dev->client;
742 struct dtv_frontend_properties *c = &dev->fe.dtv_property_cache;
743 int ret, tmp;
744 u8 u8tmp, buf[2];
745 u16 u16tmp;
746
747 dev_dbg(&client->dev, "\n");
748
749 /* signal strength */
750 if (dev->fe_status & FE_HAS_SIGNAL) {
751 /* read digital AGC */
752 ret = rtl2832_bulk_read(client, 0x305, &u8tmp, 1);
753 if (ret)
754 goto err;
858 755
859 if (tmp16) 756 dev_dbg(&client->dev, "digital agc=%02x", u8tmp);
860 *snr = (snr_constant[constellation][hierarchy] -
861 intlog10(tmp16)) / ((1 << 24) / 100);
862 else
863 *snr = 0;
864 757
865 return 0; 758 u8tmp = ~u8tmp;
759 u16tmp = u8tmp << 8 | u8tmp << 0;
760
761 c->strength.stat[0].scale = FE_SCALE_RELATIVE;
762 c->strength.stat[0].uvalue = u16tmp;
763 } else {
764 c->strength.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
765 }
766
767 /* CNR */
768 if (dev->fe_status & FE_HAS_VITERBI) {
769 unsigned hierarchy, constellation;
770 #define CONSTELLATION_NUM 3
771 #define HIERARCHY_NUM 4
772 static const u32 constant[CONSTELLATION_NUM][HIERARCHY_NUM] = {
773 {85387325, 85387325, 85387325, 85387325},
774 {86676178, 86676178, 87167949, 87795660},
775 {87659938, 87659938, 87885178, 88241743},
776 };
777
778 ret = rtl2832_bulk_read(client, 0x33c, &u8tmp, 1);
779 if (ret)
780 goto err;
781
782 constellation = (u8tmp >> 2) & 0x03; /* [3:2] */
783 if (constellation > CONSTELLATION_NUM - 1)
784 goto err_schedule_delayed_work;
785
786 hierarchy = (u8tmp >> 4) & 0x07; /* [6:4] */
787 if (hierarchy > HIERARCHY_NUM - 1)
788 goto err_schedule_delayed_work;
789
790 ret = rtl2832_bulk_read(client, 0x40c, buf, 2);
791 if (ret)
792 goto err;
793
794 u16tmp = buf[0] << 8 | buf[1] << 0;
795 if (u16tmp)
796 tmp = (constant[constellation][hierarchy] -
797 intlog10(u16tmp)) / ((1 << 24) / 10000);
798 else
799 tmp = 0;
800
801 dev_dbg(&client->dev, "cnr raw=%u\n", u16tmp);
802
803 c->cnr.stat[0].scale = FE_SCALE_DECIBEL;
804 c->cnr.stat[0].svalue = tmp;
805 } else {
806 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
807 }
808
809 /* BER */
810 if (dev->fe_status & FE_HAS_LOCK) {
811 ret = rtl2832_bulk_read(client, 0x34e, buf, 2);
812 if (ret)
813 goto err;
814
815 u16tmp = buf[0] << 8 | buf[1] << 0;
816 dev->post_bit_error += u16tmp;
817 dev->post_bit_count += 1000000;
818
819 dev_dbg(&client->dev, "ber errors=%u total=1000000\n", u16tmp);
820
821 c->post_bit_error.stat[0].scale = FE_SCALE_COUNTER;
822 c->post_bit_error.stat[0].uvalue = dev->post_bit_error;
823 c->post_bit_count.stat[0].scale = FE_SCALE_COUNTER;
824 c->post_bit_count.stat[0].uvalue = dev->post_bit_count;
825 } else {
826 c->post_bit_error.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
827 c->post_bit_count.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
828 }
829
830err_schedule_delayed_work:
831 schedule_delayed_work(&dev->stat_work, msecs_to_jiffies(2000));
832 return;
866err: 833err:
867 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 834 dev_dbg(&client->dev, "failed=%d\n", ret);
868 return ret;
869} 835}
870 836
871static int rtl2832_read_ber(struct dvb_frontend *fe, u32 *ber) 837/*
838 * I2C gate/mux/repeater logic
839 * We must use unlocked __i2c_transfer() here (through regmap) because of I2C
840 * adapter lock is already taken by tuner driver.
841 * There is delay mechanism to avoid unneeded I2C gate open / close. Gate close
842 * is delayed here a little bit in order to see if there is sequence of I2C
843 * messages sent to same I2C bus.
844 */
845static void rtl2832_i2c_gate_work(struct work_struct *work)
872{ 846{
873 struct rtl2832_priv *priv = fe->demodulator_priv; 847 struct rtl2832_dev *dev = container_of(work, struct rtl2832_dev, i2c_gate_work.work);
848 struct i2c_client *client = dev->client;
874 int ret; 849 int ret;
875 u8 buf[2];
876 850
877 ret = rtl2832_rd_regs(priv, 0x4e, 3, buf, 2); 851 /* close gate */
852 ret = rtl2832_update_bits(dev->client, 0x101, 0x08, 0x00);
878 if (ret) 853 if (ret)
879 goto err; 854 goto err;
880 855
881 *ber = buf[0] << 8 | buf[1]; 856 return;
857err:
858 dev_dbg(&client->dev, "failed=%d\n", ret);
859}
860
861static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 chan_id)
862{
863 struct rtl2832_dev *dev = mux_priv;
864 struct i2c_client *client = dev->client;
865 int ret;
866
867 /* terminate possible gate closing */
868 cancel_delayed_work(&dev->i2c_gate_work);
869
870 /*
871 * I2C adapter lock is already taken and due to that we will use
872 * regmap_update_bits() which does not lock again I2C adapter.
873 */
874 ret = regmap_update_bits(dev->regmap, 0x101, 0x08, 0x08);
875 if (ret)
876 goto err;
882 877
883 return 0; 878 return 0;
884err: 879err:
885 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 880 dev_dbg(&client->dev, "failed=%d\n", ret);
886 return ret; 881 return ret;
887} 882}
888 883
889static struct dvb_frontend_ops rtl2832_ops; 884static int rtl2832_deselect(struct i2c_adapter *adap, void *mux_priv,
885 u32 chan_id)
886{
887 struct rtl2832_dev *dev = mux_priv;
888
889 schedule_delayed_work(&dev->i2c_gate_work, usecs_to_jiffies(100));
890 return 0;
891}
892
893static struct dvb_frontend_ops rtl2832_ops = {
894 .delsys = { SYS_DVBT },
895 .info = {
896 .name = "Realtek RTL2832 (DVB-T)",
897 .frequency_min = 174000000,
898 .frequency_max = 862000000,
899 .frequency_stepsize = 166667,
900 .caps = FE_CAN_FEC_1_2 |
901 FE_CAN_FEC_2_3 |
902 FE_CAN_FEC_3_4 |
903 FE_CAN_FEC_5_6 |
904 FE_CAN_FEC_7_8 |
905 FE_CAN_FEC_AUTO |
906 FE_CAN_QPSK |
907 FE_CAN_QAM_16 |
908 FE_CAN_QAM_64 |
909 FE_CAN_QAM_AUTO |
910 FE_CAN_TRANSMISSION_MODE_AUTO |
911 FE_CAN_GUARD_INTERVAL_AUTO |
912 FE_CAN_HIERARCHY_AUTO |
913 FE_CAN_RECOVER |
914 FE_CAN_MUTE_TS
915 },
890 916
891static void rtl2832_release(struct dvb_frontend *fe) 917 .init = rtl2832_init,
918 .sleep = rtl2832_sleep,
919
920 .get_tune_settings = rtl2832_get_tune_settings,
921
922 .set_frontend = rtl2832_set_frontend,
923 .get_frontend = rtl2832_get_frontend,
924
925 .read_status = rtl2832_read_status,
926 .read_snr = rtl2832_read_snr,
927 .read_ber = rtl2832_read_ber,
928};
929
930static bool rtl2832_volatile_reg(struct device *dev, unsigned int reg)
892{ 931{
893 struct rtl2832_priv *priv = fe->demodulator_priv; 932 switch (reg) {
933 case 0x305:
934 case 0x33c:
935 case 0x34e:
936 case 0x351:
937 case 0x40c ... 0x40d:
938 return true;
939 default:
940 break;
941 }
894 942
895 dev_dbg(&priv->i2c->dev, "%s:\n", __func__); 943 return false;
896 cancel_delayed_work_sync(&priv->i2c_gate_work);
897 i2c_del_mux_adapter(priv->i2c_adapter_tuner);
898 i2c_del_mux_adapter(priv->i2c_adapter);
899 kfree(priv);
900} 944}
901 945
902/* 946/*
903 * Delay mechanism to avoid unneeded I2C gate open / close. Gate close is 947 * We implement own I2C access routines for regmap in order to get manual access
904 * delayed here a little bit in order to see if there is sequence of I2C 948 * to I2C adapter lock, which is needed for I2C mux adapter.
905 * messages sent to same I2C bus.
906 * We must use unlocked version of __i2c_transfer() in order to avoid deadlock
907 * as lock is already taken by calling muxed i2c_transfer().
908 */ 949 */
909static void rtl2832_i2c_gate_work(struct work_struct *work) 950static int rtl2832_regmap_read(void *context, const void *reg_buf,
951 size_t reg_size, void *val_buf, size_t val_size)
910{ 952{
911 struct rtl2832_priv *priv = container_of(work, 953 struct i2c_client *client = context;
912 struct rtl2832_priv, i2c_gate_work.work);
913 struct i2c_adapter *adap = priv->i2c;
914 int ret; 954 int ret;
915 u8 buf[2]; 955 struct i2c_msg msg[2] = {
916 struct i2c_msg msg[1] = {
917 { 956 {
918 .addr = priv->cfg.i2c_addr, 957 .addr = client->addr,
919 .flags = 0, 958 .flags = 0,
920 .len = sizeof(buf), 959 .len = reg_size,
921 .buf = buf, 960 .buf = (u8 *)reg_buf,
961 }, {
962 .addr = client->addr,
963 .flags = I2C_M_RD,
964 .len = val_size,
965 .buf = val_buf,
922 } 966 }
923 }; 967 };
924 968
925 /* select reg bank 1 */ 969 ret = __i2c_transfer(client->adapter, msg, 2);
926 buf[0] = 0x00; 970 if (ret != 2) {
927 buf[1] = 0x01; 971 dev_warn(&client->dev, "i2c reg read failed %d\n", ret);
928 ret = __i2c_transfer(adap, msg, 1); 972 if (ret >= 0)
929 if (ret != 1) 973 ret = -EREMOTEIO;
930 goto err; 974 return ret;
931 975 }
932 priv->page = 1; 976 return 0;
933
934 /* close I2C repeater gate */
935 buf[0] = 0x01;
936 buf[1] = 0x10;
937 ret = __i2c_transfer(adap, msg, 1);
938 if (ret != 1)
939 goto err;
940
941 priv->i2c_gate_state = false;
942
943 return;
944err:
945 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret);
946
947 return;
948} 977}
949 978
950static int rtl2832_select(struct i2c_adapter *adap, void *mux_priv, u32 chan_id) 979static int rtl2832_regmap_write(void *context, const void *data, size_t count)
951{ 980{
952 struct rtl2832_priv *priv = mux_priv; 981 struct i2c_client *client = context;
953 int ret; 982 int ret;
954 u8 buf[2], val;
955 struct i2c_msg msg[1] = { 983 struct i2c_msg msg[1] = {
956 { 984 {
957 .addr = priv->cfg.i2c_addr, 985 .addr = client->addr,
958 .flags = 0, 986 .flags = 0,
959 .len = sizeof(buf), 987 .len = count,
960 .buf = buf, 988 .buf = (u8 *)data,
961 } 989 }
962 }; 990 };
963 struct i2c_msg msg_rd[2] = { 991
992 ret = __i2c_transfer(client->adapter, msg, 1);
993 if (ret != 1) {
994 dev_warn(&client->dev, "i2c reg write failed %d\n", ret);
995 if (ret >= 0)
996 ret = -EREMOTEIO;
997 return ret;
998 }
999 return 0;
1000}
1001
1002static int rtl2832_regmap_gather_write(void *context, const void *reg,
1003 size_t reg_len, const void *val,
1004 size_t val_len)
1005{
1006 struct i2c_client *client = context;
1007 int ret;
1008 u8 buf[256];
1009 struct i2c_msg msg[1] = {
964 { 1010 {
965 .addr = priv->cfg.i2c_addr, 1011 .addr = client->addr,
966 .flags = 0, 1012 .flags = 0,
967 .len = 1, 1013 .len = 1 + val_len,
968 .buf = "\x01", 1014 .buf = buf,
969 }, {
970 .addr = priv->cfg.i2c_addr,
971 .flags = I2C_M_RD,
972 .len = 1,
973 .buf = &val,
974 } 1015 }
975 }; 1016 };
976 1017
977 /* terminate possible gate closing */ 1018 buf[0] = *(u8 const *)reg;
978 cancel_delayed_work_sync(&priv->i2c_gate_work); 1019 memcpy(&buf[1], val, val_len);
979 1020
980 if (priv->i2c_gate_state == chan_id) 1021 ret = __i2c_transfer(client->adapter, msg, 1);
981 return 0; 1022 if (ret != 1) {
982 1023 dev_warn(&client->dev, "i2c reg write failed %d\n", ret);
983 /* select reg bank 1 */ 1024 if (ret >= 0)
984 buf[0] = 0x00; 1025 ret = -EREMOTEIO;
985 buf[1] = 0x01; 1026 return ret;
986 ret = __i2c_transfer(adap, msg, 1); 1027 }
987 if (ret != 1) 1028 return 0;
988 goto err; 1029}
989
990 priv->page = 1;
991 1030
992 /* we must read that register, otherwise there will be errors */ 1031/*
993 ret = __i2c_transfer(adap, msg_rd, 2); 1032 * FIXME: Hack. Implement own regmap locking in order to silence lockdep
994 if (ret != 2) 1033 * recursive lock warning. That happens when regmap I2C client calls I2C mux
995 goto err; 1034 * adapter, which leads demod I2C repeater enable via demod regmap. Operation
1035 * takes two regmap locks recursively - but those are different regmap instances
1036 * in a two different I2C drivers, so it is not deadlock. Proper fix is to make
1037 * regmap aware of lockdep.
1038 */
1039static void rtl2832_regmap_lock(void *__dev)
1040{
1041 struct rtl2832_dev *dev = __dev;
1042 struct i2c_client *client = dev->client;
996 1043
997 /* open or close I2C repeater gate */ 1044 dev_dbg(&client->dev, "\n");
998 buf[0] = 0x01; 1045 mutex_lock(&dev->regmap_mutex);
999 if (chan_id == 1) 1046}
1000 buf[1] = 0x18; /* open */
1001 else
1002 buf[1] = 0x10; /* close */
1003 1047
1004 ret = __i2c_transfer(adap, msg, 1); 1048static void rtl2832_regmap_unlock(void *__dev)
1005 if (ret != 1) 1049{
1006 goto err; 1050 struct rtl2832_dev *dev = __dev;
1051 struct i2c_client *client = dev->client;
1007 1052
1008 priv->i2c_gate_state = chan_id; 1053 dev_dbg(&client->dev, "\n");
1054 mutex_unlock(&dev->regmap_mutex);
1055}
1009 1056
1010 return 0; 1057static struct dvb_frontend *rtl2832_get_dvb_frontend(struct i2c_client *client)
1011err: 1058{
1012 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1059 struct rtl2832_dev *dev = i2c_get_clientdata(client);
1013 1060
1014 return -EREMOTEIO; 1061 dev_dbg(&client->dev, "\n");
1062 return &dev->fe;
1015} 1063}
1016 1064
1017static int rtl2832_deselect(struct i2c_adapter *adap, void *mux_priv, 1065static struct i2c_adapter *rtl2832_get_i2c_adapter(struct i2c_client *client)
1018 u32 chan_id)
1019{ 1066{
1020 struct rtl2832_priv *priv = mux_priv; 1067 struct rtl2832_dev *dev = i2c_get_clientdata(client);
1021 schedule_delayed_work(&priv->i2c_gate_work, usecs_to_jiffies(100)); 1068
1022 return 0; 1069 dev_dbg(&client->dev, "\n");
1070 return dev->i2c_adapter_tuner;
1023} 1071}
1024 1072
1025int rtl2832_enable_external_ts_if(struct dvb_frontend *fe) 1073static int rtl2832_enable_slave_ts(struct i2c_client *client)
1026{ 1074{
1027 struct rtl2832_priv *priv = fe->demodulator_priv; 1075 struct rtl2832_dev *dev = i2c_get_clientdata(client);
1028 int ret; 1076 int ret;
1029 1077
1030 dev_dbg(&priv->i2c->dev, "%s: setting PIP mode\n", __func__); 1078 dev_dbg(&client->dev, "\n");
1031 1079
1032 ret = rtl2832_wr_regs(priv, 0x0c, 1, "\x5f\xff", 2); 1080 ret = rtl2832_bulk_write(client, 0x10c, "\x5f\xff", 2);
1033 if (ret) 1081 if (ret)
1034 goto err; 1082 goto err;
1035 1083
1036 ret = rtl2832_wr_demod_reg(priv, DVBT_PIP_ON, 0x1); 1084 ret = rtl2832_wr_demod_reg(dev, DVBT_PIP_ON, 0x1);
1037 if (ret) 1085 if (ret)
1038 goto err; 1086 goto err;
1039 1087
1040 ret = rtl2832_wr_reg(priv, 0xbc, 0, 0x18); 1088 ret = rtl2832_bulk_write(client, 0x0bc, "\x18", 1);
1041 if (ret) 1089 if (ret)
1042 goto err; 1090 goto err;
1043 1091
1044 ret = rtl2832_wr_reg(priv, 0x22, 0, 0x01); 1092 ret = rtl2832_bulk_write(client, 0x022, "\x01", 1);
1045 if (ret) 1093 if (ret)
1046 goto err; 1094 goto err;
1047 1095
1048 ret = rtl2832_wr_reg(priv, 0x26, 0, 0x1f); 1096 ret = rtl2832_bulk_write(client, 0x026, "\x1f", 1);
1049 if (ret) 1097 if (ret)
1050 goto err; 1098 goto err;
1051 1099
1052 ret = rtl2832_wr_reg(priv, 0x27, 0, 0xff); 1100 ret = rtl2832_bulk_write(client, 0x027, "\xff", 1);
1053 if (ret) 1101 if (ret)
1054 goto err; 1102 goto err;
1055 1103
1056 ret = rtl2832_wr_regs(priv, 0x92, 1, "\x7f\xf7\xff", 3); 1104 ret = rtl2832_bulk_write(client, 0x192, "\x7f\xf7\xff", 3);
1057 if (ret) 1105 if (ret)
1058 goto err; 1106 goto err;
1059 1107
1060 /* soft reset */ 1108 /* soft reset */
1061 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x1); 1109 ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x1);
1062 if (ret) 1110 if (ret)
1063 goto err; 1111 goto err;
1064 1112
1065 ret = rtl2832_wr_demod_reg(priv, DVBT_SOFT_RST, 0x0); 1113 ret = rtl2832_wr_demod_reg(dev, DVBT_SOFT_RST, 0x0);
1066 if (ret) 1114 if (ret)
1067 goto err; 1115 goto err;
1068 1116
1069 return 0; 1117 return 0;
1070err: 1118err:
1071 dev_dbg(&priv->i2c->dev, "%s: failed=%d\n", __func__, ret); 1119 dev_dbg(&client->dev, "failed=%d\n", ret);
1072 return ret; 1120 return ret;
1073
1074} 1121}
1075EXPORT_SYMBOL(rtl2832_enable_external_ts_if);
1076 1122
1077struct i2c_adapter *rtl2832_get_i2c_adapter(struct dvb_frontend *fe) 1123static int rtl2832_pid_filter_ctrl(struct dvb_frontend *fe, int onoff)
1078{ 1124{
1079 struct rtl2832_priv *priv = fe->demodulator_priv; 1125 struct rtl2832_dev *dev = fe->demodulator_priv;
1080 return priv->i2c_adapter_tuner; 1126 struct i2c_client *client = dev->client;
1127 int ret;
1128 u8 u8tmp;
1129
1130 dev_dbg(&client->dev, "onoff=%d\n", onoff);
1131
1132 /* enable / disable PID filter */
1133 if (onoff)
1134 u8tmp = 0x80;
1135 else
1136 u8tmp = 0x00;
1137
1138 ret = rtl2832_update_bits(client, 0x061, 0xc0, u8tmp);
1139 if (ret)
1140 goto err;
1141
1142 return 0;
1143err:
1144 dev_dbg(&client->dev, "failed=%d\n", ret);
1145 return ret;
1081} 1146}
1082EXPORT_SYMBOL(rtl2832_get_i2c_adapter);
1083 1147
1084struct i2c_adapter *rtl2832_get_private_i2c_adapter(struct dvb_frontend *fe) 1148static int rtl2832_pid_filter(struct dvb_frontend *fe, u8 index, u16 pid,
1149 int onoff)
1085{ 1150{
1086 struct rtl2832_priv *priv = fe->demodulator_priv; 1151 struct rtl2832_dev *dev = fe->demodulator_priv;
1087 return priv->i2c_adapter; 1152 struct i2c_client *client = dev->client;
1153 int ret;
1154 u8 buf[4];
1155
1156 dev_dbg(&client->dev, "index=%d pid=%04x onoff=%d\n",
1157 index, pid, onoff);
1158
1159 /* skip invalid PIDs (0x2000) */
1160 if (pid > 0x1fff || index > 32)
1161 return 0;
1162
1163 if (onoff)
1164 set_bit(index, &dev->filters);
1165 else
1166 clear_bit(index, &dev->filters);
1167
1168 /* enable / disable PIDs */
1169 buf[0] = (dev->filters >> 0) & 0xff;
1170 buf[1] = (dev->filters >> 8) & 0xff;
1171 buf[2] = (dev->filters >> 16) & 0xff;
1172 buf[3] = (dev->filters >> 24) & 0xff;
1173 ret = rtl2832_bulk_write(client, 0x062, buf, 4);
1174 if (ret)
1175 goto err;
1176
1177 /* add PID */
1178 buf[0] = (pid >> 8) & 0xff;
1179 buf[1] = (pid >> 0) & 0xff;
1180 ret = rtl2832_bulk_write(client, 0x066 + 2 * index, buf, 2);
1181 if (ret)
1182 goto err;
1183
1184 return 0;
1185err:
1186 dev_dbg(&client->dev, "failed=%d\n", ret);
1187 return ret;
1088} 1188}
1089EXPORT_SYMBOL(rtl2832_get_private_i2c_adapter);
1090 1189
1091struct dvb_frontend *rtl2832_attach(const struct rtl2832_config *cfg, 1190static int rtl2832_probe(struct i2c_client *client,
1092 struct i2c_adapter *i2c) 1191 const struct i2c_device_id *id)
1093{ 1192{
1094 struct rtl2832_priv *priv = NULL; 1193 struct rtl2832_platform_data *pdata = client->dev.platform_data;
1095 int ret = 0; 1194 struct i2c_adapter *i2c = client->adapter;
1195 struct rtl2832_dev *dev;
1196 int ret;
1096 u8 tmp; 1197 u8 tmp;
1198 static const struct regmap_bus regmap_bus = {
1199 .read = rtl2832_regmap_read,
1200 .write = rtl2832_regmap_write,
1201 .gather_write = rtl2832_regmap_gather_write,
1202 .val_format_endian_default = REGMAP_ENDIAN_NATIVE,
1203 };
1204 static const struct regmap_range_cfg regmap_range_cfg[] = {
1205 {
1206 .selector_reg = 0x00,
1207 .selector_mask = 0xff,
1208 .selector_shift = 0,
1209 .window_start = 0,
1210 .window_len = 0x100,
1211 .range_min = 0 * 0x100,
1212 .range_max = 5 * 0x100,
1213 },
1214 };
1097 1215
1098 dev_dbg(&i2c->dev, "%s:\n", __func__); 1216 dev_dbg(&client->dev, "\n");
1099 1217
1100 /* allocate memory for the internal state */ 1218 /* allocate memory for the internal state */
1101 priv = kzalloc(sizeof(struct rtl2832_priv), GFP_KERNEL); 1219 dev = kzalloc(sizeof(struct rtl2832_dev), GFP_KERNEL);
1102 if (priv == NULL) 1220 if (dev == NULL) {
1221 ret = -ENOMEM;
1103 goto err; 1222 goto err;
1223 }
1104 1224
1105 /* setup the priv */ 1225 /* setup the state */
1106 priv->i2c = i2c; 1226 i2c_set_clientdata(client, dev);
1107 priv->tuner = cfg->tuner; 1227 dev->client = client;
1108 memcpy(&priv->cfg, cfg, sizeof(struct rtl2832_config)); 1228 dev->pdata = client->dev.platform_data;
1109 INIT_DELAYED_WORK(&priv->i2c_gate_work, rtl2832_i2c_gate_work); 1229 dev->sleeping = true;
1110 1230 INIT_DELAYED_WORK(&dev->i2c_gate_work, rtl2832_i2c_gate_work);
1111 /* create muxed i2c adapter for demod itself */ 1231 INIT_DELAYED_WORK(&dev->stat_work, rtl2832_stat_work);
1112 priv->i2c_adapter = i2c_add_mux_adapter(i2c, &i2c->dev, priv, 0, 0, 0, 1232 /* create regmap */
1113 rtl2832_select, NULL); 1233 mutex_init(&dev->regmap_mutex);
1114 if (priv->i2c_adapter == NULL) 1234 dev->regmap_config.reg_bits = 8,
1115 goto err; 1235 dev->regmap_config.val_bits = 8,
1236 dev->regmap_config.lock = rtl2832_regmap_lock,
1237 dev->regmap_config.unlock = rtl2832_regmap_unlock,
1238 dev->regmap_config.lock_arg = dev,
1239 dev->regmap_config.volatile_reg = rtl2832_volatile_reg,
1240 dev->regmap_config.max_register = 5 * 0x100,
1241 dev->regmap_config.ranges = regmap_range_cfg,
1242 dev->regmap_config.num_ranges = ARRAY_SIZE(regmap_range_cfg),
1243 dev->regmap_config.cache_type = REGCACHE_RBTREE,
1244 dev->regmap = regmap_init(&client->dev, &regmap_bus, client,
1245 &dev->regmap_config);
1246 if (IS_ERR(dev->regmap)) {
1247 ret = PTR_ERR(dev->regmap);
1248 goto err_kfree;
1249 }
1116 1250
1117 /* check if the demod is there */ 1251 /* check if the demod is there */
1118 ret = rtl2832_rd_reg(priv, 0x00, 0x0, &tmp); 1252 ret = rtl2832_bulk_read(client, 0x000, &tmp, 1);
1119 if (ret) 1253 if (ret)
1120 goto err; 1254 goto err_regmap_exit;
1121 1255
1122 /* create muxed i2c adapter for demod tuner bus */ 1256 /* create muxed i2c adapter for demod tuner bus */
1123 priv->i2c_adapter_tuner = i2c_add_mux_adapter(i2c, &i2c->dev, priv, 1257 dev->i2c_adapter_tuner = i2c_add_mux_adapter(i2c, &i2c->dev, dev,
1124 0, 1, 0, rtl2832_select, rtl2832_deselect); 1258 0, 0, 0, rtl2832_select, rtl2832_deselect);
1125 if (priv->i2c_adapter_tuner == NULL) 1259 if (dev->i2c_adapter_tuner == NULL) {
1126 goto err; 1260 ret = -ENODEV;
1261 goto err_regmap_exit;
1262 }
1127 1263
1128 /* create dvb_frontend */ 1264 /* create dvb_frontend */
1129 memcpy(&priv->fe.ops, &rtl2832_ops, sizeof(struct dvb_frontend_ops)); 1265 memcpy(&dev->fe.ops, &rtl2832_ops, sizeof(struct dvb_frontend_ops));
1130 priv->fe.demodulator_priv = priv; 1266 dev->fe.demodulator_priv = dev;
1131 1267
1132 /* TODO implement sleep mode */ 1268 /* setup callbacks */
1133 priv->sleeping = true; 1269 pdata->get_dvb_frontend = rtl2832_get_dvb_frontend;
1134 1270 pdata->get_i2c_adapter = rtl2832_get_i2c_adapter;
1135 return &priv->fe; 1271 pdata->enable_slave_ts = rtl2832_enable_slave_ts;
1272 pdata->pid_filter = rtl2832_pid_filter;
1273 pdata->pid_filter_ctrl = rtl2832_pid_filter_ctrl;
1274 pdata->bulk_read = rtl2832_bulk_read;
1275 pdata->bulk_write = rtl2832_bulk_write;
1276 pdata->update_bits = rtl2832_update_bits;
1277
1278 dev_info(&client->dev, "Realtek RTL2832 successfully attached\n");
1279 return 0;
1280err_regmap_exit:
1281 regmap_exit(dev->regmap);
1282err_kfree:
1283 kfree(dev);
1136err: 1284err:
1137 dev_dbg(&i2c->dev, "%s: failed=%d\n", __func__, ret); 1285 dev_dbg(&client->dev, "failed=%d\n", ret);
1138 if (priv && priv->i2c_adapter) 1286 return ret;
1139 i2c_del_mux_adapter(priv->i2c_adapter);
1140 kfree(priv);
1141 return NULL;
1142} 1287}
1143EXPORT_SYMBOL(rtl2832_attach);
1144 1288
1145static struct dvb_frontend_ops rtl2832_ops = { 1289static int rtl2832_remove(struct i2c_client *client)
1146 .delsys = { SYS_DVBT }, 1290{
1147 .info = { 1291 struct rtl2832_dev *dev = i2c_get_clientdata(client);
1148 .name = "Realtek RTL2832 (DVB-T)",
1149 .frequency_min = 174000000,
1150 .frequency_max = 862000000,
1151 .frequency_stepsize = 166667,
1152 .caps = FE_CAN_FEC_1_2 |
1153 FE_CAN_FEC_2_3 |
1154 FE_CAN_FEC_3_4 |
1155 FE_CAN_FEC_5_6 |
1156 FE_CAN_FEC_7_8 |
1157 FE_CAN_FEC_AUTO |
1158 FE_CAN_QPSK |
1159 FE_CAN_QAM_16 |
1160 FE_CAN_QAM_64 |
1161 FE_CAN_QAM_AUTO |
1162 FE_CAN_TRANSMISSION_MODE_AUTO |
1163 FE_CAN_GUARD_INTERVAL_AUTO |
1164 FE_CAN_HIERARCHY_AUTO |
1165 FE_CAN_RECOVER |
1166 FE_CAN_MUTE_TS
1167 },
1168 1292
1169 .release = rtl2832_release, 1293 dev_dbg(&client->dev, "\n");
1170 1294
1171 .init = rtl2832_init, 1295 cancel_delayed_work_sync(&dev->i2c_gate_work);
1172 .sleep = rtl2832_sleep,
1173 1296
1174 .get_tune_settings = rtl2832_get_tune_settings, 1297 i2c_del_mux_adapter(dev->i2c_adapter_tuner);
1175 1298
1176 .set_frontend = rtl2832_set_frontend, 1299 regmap_exit(dev->regmap);
1177 .get_frontend = rtl2832_get_frontend,
1178 1300
1179 .read_status = rtl2832_read_status, 1301 kfree(dev);
1180 .read_snr = rtl2832_read_snr,
1181 .read_ber = rtl2832_read_ber,
1182 1302
1183 .i2c_gate_ctrl = rtl2832_i2c_gate_ctrl, 1303 return 0;
1304}
1305
1306static const struct i2c_device_id rtl2832_id_table[] = {
1307 {"rtl2832", 0},
1308 {}
1184}; 1309};
1310MODULE_DEVICE_TABLE(i2c, rtl2832_id_table);
1311
1312static struct i2c_driver rtl2832_driver = {
1313 .driver = {
1314 .owner = THIS_MODULE,
1315 .name = "rtl2832",
1316 },
1317 .probe = rtl2832_probe,
1318 .remove = rtl2832_remove,
1319 .id_table = rtl2832_id_table,
1320};
1321
1322module_i2c_driver(rtl2832_driver);
1185 1323
1186MODULE_AUTHOR("Thomas Mair <mair.thomas86@gmail.com>"); 1324MODULE_AUTHOR("Thomas Mair <mair.thomas86@gmail.com>");
1325MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1187MODULE_DESCRIPTION("Realtek RTL2832 DVB-T demodulator driver"); 1326MODULE_DESCRIPTION("Realtek RTL2832 DVB-T demodulator driver");
1188MODULE_LICENSE("GPL"); 1327MODULE_LICENSE("GPL");
1189MODULE_VERSION("0.5");
diff --git a/drivers/media/dvb-frontends/rtl2832.h b/drivers/media/dvb-frontends/rtl2832.h
index 5254c1dfc8de..a8e912e679a5 100644
--- a/drivers/media/dvb-frontends/rtl2832.h
+++ b/drivers/media/dvb-frontends/rtl2832.h
@@ -2,6 +2,7 @@
2 * Realtek RTL2832 DVB-T demodulator driver 2 * Realtek RTL2832 DVB-T demodulator driver
3 * 3 *
4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com> 4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
5 * Copyright (C) 2012-2014 Antti Palosaari <crope@iki.fi>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -21,86 +22,42 @@
21#ifndef RTL2832_H 22#ifndef RTL2832_H
22#define RTL2832_H 23#define RTL2832_H
23 24
24#include <linux/kconfig.h>
25#include <linux/dvb/frontend.h> 25#include <linux/dvb/frontend.h>
26#include <linux/i2c-mux.h>
27
28/**
29 * struct rtl2832_platform_data - Platform data for the rtl2832 driver
30 * @clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
31 * @tuner: Used tuner model.
32 * @get_dvb_frontend: Get DVB frontend.
33 * @get_i2c_adapter: Get I2C adapter.
34 * @enable_slave_ts: Enable slave TS IF.
35 * @pid_filter: Set PID to PID filter.
36 * @pid_filter_ctrl: Control PID filter.
37 */
26 38
27struct rtl2832_config { 39struct rtl2832_platform_data {
28 /* 40 u32 clk;
29 * Demodulator I2C address.
30 */
31 u8 i2c_addr;
32
33 /*
34 * Xtal frequency.
35 * Hz
36 * 4000000, 16000000, 25000000, 28800000
37 */
38 u32 xtal;
39
40 /* 41 /*
41 * tuner 42 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver.
42 * XXX: This must be keep sync with dvb_usb_rtl28xxu demod driver.
43 */ 43 */
44#define RTL2832_TUNER_TUA9001 0x24 44#define RTL2832_TUNER_TUA9001 0x24
45#define RTL2832_TUNER_FC0012 0x26 45#define RTL2832_TUNER_FC0012 0x26
46#define RTL2832_TUNER_E4000 0x27 46#define RTL2832_TUNER_E4000 0x27
47#define RTL2832_TUNER_FC0013 0x29 47#define RTL2832_TUNER_FC0013 0x29
48#define RTL2832_TUNER_R820T 0x2a 48#define RTL2832_TUNER_R820T 0x2a
49#define RTL2832_TUNER_R828D 0x2b 49#define RTL2832_TUNER_R828D 0x2b
50 u8 tuner; 50 u8 tuner;
51};
52
53#if IS_ENABLED(CONFIG_DVB_RTL2832)
54struct dvb_frontend *rtl2832_attach(
55 const struct rtl2832_config *cfg,
56 struct i2c_adapter *i2c
57);
58
59extern struct i2c_adapter *rtl2832_get_i2c_adapter(
60 struct dvb_frontend *fe
61);
62
63extern struct i2c_adapter *rtl2832_get_private_i2c_adapter(
64 struct dvb_frontend *fe
65);
66
67extern int rtl2832_enable_external_ts_if(
68 struct dvb_frontend *fe
69);
70
71#else
72
73static inline struct dvb_frontend *rtl2832_attach(
74 const struct rtl2832_config *config,
75 struct i2c_adapter *i2c
76)
77{
78 pr_warn("%s: driver disabled by Kconfig\n", __func__);
79 return NULL;
80}
81
82static inline struct i2c_adapter *rtl2832_get_i2c_adapter(
83 struct dvb_frontend *fe
84)
85{
86 return NULL;
87}
88
89static inline struct i2c_adapter *rtl2832_get_private_i2c_adapter(
90 struct dvb_frontend *fe
91)
92{
93 return NULL;
94}
95
96static inline int rtl2832_enable_external_ts_if(
97 struct dvb_frontend *fe
98)
99{
100 return -ENODEV;
101}
102
103#endif
104 51
52 struct dvb_frontend* (*get_dvb_frontend)(struct i2c_client *);
53 struct i2c_adapter* (*get_i2c_adapter)(struct i2c_client *);
54 int (*enable_slave_ts)(struct i2c_client *);
55 int (*pid_filter)(struct dvb_frontend *, u8, u16, int);
56 int (*pid_filter_ctrl)(struct dvb_frontend *, int);
57/* private: Register access for SDR module use only */
58 int (*bulk_read)(struct i2c_client *, unsigned int, void *, size_t);
59 int (*bulk_write)(struct i2c_client *, unsigned int, const void *, size_t);
60 int (*update_bits)(struct i2c_client *, unsigned int, unsigned int, unsigned int);
61};
105 62
106#endif /* RTL2832_H */ 63#endif /* RTL2832_H */
diff --git a/drivers/media/dvb-frontends/rtl2832_priv.h b/drivers/media/dvb-frontends/rtl2832_priv.h
index ae469f032fe6..c3a922c37903 100644
--- a/drivers/media/dvb-frontends/rtl2832_priv.h
+++ b/drivers/media/dvb-frontends/rtl2832_priv.h
@@ -2,6 +2,7 @@
2 * Realtek RTL2832 DVB-T demodulator driver 2 * Realtek RTL2832 DVB-T demodulator driver
3 * 3 *
4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com> 4 * Copyright (C) 2012 Thomas Mair <thomas.mair86@gmail.com>
5 * Copyright (C) 2012-2014 Antti Palosaari <crope@iki.fi>
5 * 6 *
6 * This program is free software; you can redistribute it and/or modify 7 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by 8 * it under the terms of the GNU General Public License as published by
@@ -21,28 +22,34 @@
21#ifndef RTL2832_PRIV_H 22#ifndef RTL2832_PRIV_H
22#define RTL2832_PRIV_H 23#define RTL2832_PRIV_H
23 24
25#include <linux/regmap.h>
26#include <linux/math64.h>
27#include <linux/bitops.h>
28
24#include "dvb_frontend.h" 29#include "dvb_frontend.h"
30#include "dvb_math.h"
25#include "rtl2832.h" 31#include "rtl2832.h"
26#include <linux/i2c-mux.h>
27 32
28struct rtl2832_priv { 33struct rtl2832_dev {
29 struct i2c_adapter *i2c; 34 struct rtl2832_platform_data *pdata;
30 struct i2c_adapter *i2c_adapter; 35 struct i2c_client *client;
36 struct mutex regmap_mutex;
37 struct regmap_config regmap_config;
38 struct regmap *regmap;
31 struct i2c_adapter *i2c_adapter_tuner; 39 struct i2c_adapter *i2c_adapter_tuner;
32 struct dvb_frontend fe; 40 struct dvb_frontend fe;
33 struct rtl2832_config cfg; 41 struct delayed_work stat_work;
34 42 fe_status_t fe_status;
35 bool i2c_gate_state; 43 u64 post_bit_error_prev; /* for old DVBv3 read_ber() calculation */
44 u64 post_bit_error;
45 u64 post_bit_count;
36 bool sleeping; 46 bool sleeping;
37
38 u8 tuner;
39 u8 page; /* active register page */
40 struct delayed_work i2c_gate_work; 47 struct delayed_work i2c_gate_work;
48 unsigned long filters; /* PID filter */
41}; 49};
42 50
43struct rtl2832_reg_entry { 51struct rtl2832_reg_entry {
44 u8 page; 52 u16 start_address;
45 u8 start_address;
46 u8 msb; 53 u8 msb;
47 u8 lsb; 54 u8 lsb;
48}; 55};
@@ -52,7 +59,6 @@ struct rtl2832_reg_value {
52 u32 value; 59 u32 value;
53}; 60};
54 61
55
56/* Demod register bit names */ 62/* Demod register bit names */
57enum DVBT_REG_BIT_NAME { 63enum DVBT_REG_BIT_NAME {
58 DVBT_SOFT_RST, 64 DVBT_SOFT_RST,
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.c b/drivers/media/dvb-frontends/rtl2832_sdr.c
index 2896b47c29d8..3ff8806ca584 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.c
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.c
@@ -22,7 +22,6 @@
22 * 22 *
23 */ 23 */
24 24
25#include "dvb_frontend.h"
26#include "rtl2832_sdr.h" 25#include "rtl2832_sdr.h"
27#include "dvb_usb.h" 26#include "dvb_usb.h"
28 27
@@ -32,6 +31,7 @@
32#include <media/v4l2-event.h> 31#include <media/v4l2-event.h>
33#include <media/videobuf2-vmalloc.h> 32#include <media/videobuf2-vmalloc.h>
34 33
34#include <linux/platform_device.h>
35#include <linux/jiffies.h> 35#include <linux/jiffies.h>
36#include <linux/math64.h> 36#include <linux/math64.h>
37 37
@@ -107,16 +107,12 @@ struct rtl2832_sdr_frame_buf {
107 struct list_head list; 107 struct list_head list;
108}; 108};
109 109
110struct rtl2832_sdr_state { 110struct rtl2832_sdr_dev {
111#define POWER_ON (1 << 1) 111#define POWER_ON (1 << 1)
112#define URB_BUF (1 << 2) 112#define URB_BUF (1 << 2)
113 unsigned long flags; 113 unsigned long flags;
114 114
115 const struct rtl2832_config *cfg; 115 struct platform_device *pdev;
116 struct dvb_frontend *fe;
117 struct dvb_usb_device *d;
118 struct i2c_adapter *i2c;
119 u8 bank;
120 116
121 struct video_device vdev; 117 struct video_device vdev;
122 struct v4l2_device v4l2_dev; 118 struct v4l2_device v4l2_dev;
@@ -160,200 +156,77 @@ struct rtl2832_sdr_state {
160 unsigned long jiffies_next; 156 unsigned long jiffies_next;
161}; 157};
162 158
163/* write multiple hardware registers */
164static int rtl2832_sdr_wr(struct rtl2832_sdr_state *s, u8 reg, const u8 *val,
165 int len)
166{
167 int ret;
168#define MAX_WR_LEN 24
169#define MAX_WR_XFER_LEN (MAX_WR_LEN + 1)
170 u8 buf[MAX_WR_XFER_LEN];
171 struct i2c_msg msg[1] = {
172 {
173 .addr = s->cfg->i2c_addr,
174 .flags = 0,
175 .len = 1 + len,
176 .buf = buf,
177 }
178 };
179
180 if (WARN_ON(len > MAX_WR_LEN))
181 return -EINVAL;
182
183 buf[0] = reg;
184 memcpy(&buf[1], val, len);
185
186 ret = i2c_transfer(s->i2c, msg, 1);
187 if (ret == 1) {
188 ret = 0;
189 } else {
190 dev_err(&s->i2c->dev,
191 "%s: I2C wr failed=%d reg=%02x len=%d\n",
192 KBUILD_MODNAME, ret, reg, len);
193 ret = -EREMOTEIO;
194 }
195 return ret;
196}
197
198/* read multiple hardware registers */
199static int rtl2832_sdr_rd(struct rtl2832_sdr_state *s, u8 reg, u8 *val, int len)
200{
201 int ret;
202 struct i2c_msg msg[2] = {
203 {
204 .addr = s->cfg->i2c_addr,
205 .flags = 0,
206 .len = 1,
207 .buf = &reg,
208 }, {
209 .addr = s->cfg->i2c_addr,
210 .flags = I2C_M_RD,
211 .len = len,
212 .buf = val,
213 }
214 };
215
216 ret = i2c_transfer(s->i2c, msg, 2);
217 if (ret == 2) {
218 ret = 0;
219 } else {
220 dev_err(&s->i2c->dev,
221 "%s: I2C rd failed=%d reg=%02x len=%d\n",
222 KBUILD_MODNAME, ret, reg, len);
223 ret = -EREMOTEIO;
224 }
225 return ret;
226}
227
228/* write multiple registers */ 159/* write multiple registers */
229static int rtl2832_sdr_wr_regs(struct rtl2832_sdr_state *s, u16 reg, 160static int rtl2832_sdr_wr_regs(struct rtl2832_sdr_dev *dev, u16 reg,
230 const u8 *val, int len) 161 const u8 *val, int len)
231{ 162{
232 int ret; 163 struct platform_device *pdev = dev->pdev;
233 u8 reg2 = (reg >> 0) & 0xff; 164 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
234 u8 bank = (reg >> 8) & 0xff; 165 struct i2c_client *client = pdata->i2c_client;
235 166
236 /* switch bank if needed */ 167 return pdata->bulk_write(client, reg, val, len);
237 if (bank != s->bank) {
238 ret = rtl2832_sdr_wr(s, 0x00, &bank, 1);
239 if (ret)
240 return ret;
241
242 s->bank = bank;
243 }
244
245 return rtl2832_sdr_wr(s, reg2, val, len);
246} 168}
247 169
170#if 0
248/* read multiple registers */ 171/* read multiple registers */
249static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_state *s, u16 reg, u8 *val, 172static int rtl2832_sdr_rd_regs(struct rtl2832_sdr_dev *dev, u16 reg, u8 *val,
250 int len) 173 int len)
251{ 174{
252 int ret; 175 struct platform_device *pdev = dev->pdev;
253 u8 reg2 = (reg >> 0) & 0xff; 176 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
254 u8 bank = (reg >> 8) & 0xff; 177 struct i2c_client *client = pdata->i2c_client;
255
256 /* switch bank if needed */
257 if (bank != s->bank) {
258 ret = rtl2832_sdr_wr(s, 0x00, &bank, 1);
259 if (ret)
260 return ret;
261
262 s->bank = bank;
263 }
264 178
265 return rtl2832_sdr_rd(s, reg2, val, len); 179 return pdata->bulk_read(client, reg, val, len);
266} 180}
181#endif
267 182
268/* write single register */ 183/* write single register */
269static int rtl2832_sdr_wr_reg(struct rtl2832_sdr_state *s, u16 reg, u8 val) 184static int rtl2832_sdr_wr_reg(struct rtl2832_sdr_dev *dev, u16 reg, u8 val)
270{ 185{
271 return rtl2832_sdr_wr_regs(s, reg, &val, 1); 186 return rtl2832_sdr_wr_regs(dev, reg, &val, 1);
272} 187}
273 188
274#if 0
275/* read single register */
276static int rtl2832_sdr_rd_reg(struct rtl2832_sdr_state *s, u16 reg, u8 *val)
277{
278 return rtl2832_sdr_rd_regs(s, reg, val, 1);
279}
280#endif
281
282/* write single register with mask */ 189/* write single register with mask */
283static int rtl2832_sdr_wr_reg_mask(struct rtl2832_sdr_state *s, u16 reg, 190static int rtl2832_sdr_wr_reg_mask(struct rtl2832_sdr_dev *dev, u16 reg,
284 u8 val, u8 mask) 191 u8 val, u8 mask)
285{ 192{
286 int ret; 193 struct platform_device *pdev = dev->pdev;
287 u8 tmp; 194 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
288 195 struct i2c_client *client = pdata->i2c_client;
289 /* no need for read if whole reg is written */
290 if (mask != 0xff) {
291 ret = rtl2832_sdr_rd_regs(s, reg, &tmp, 1);
292 if (ret)
293 return ret;
294
295 val &= mask;
296 tmp &= ~mask;
297 val |= tmp;
298 }
299
300 return rtl2832_sdr_wr_regs(s, reg, &val, 1);
301}
302
303#if 0
304/* read single register with mask */
305static int rtl2832_sdr_rd_reg_mask(struct rtl2832_sdr_state *s, u16 reg,
306 u8 *val, u8 mask)
307{
308 int ret, i;
309 u8 tmp;
310
311 ret = rtl2832_sdr_rd_regs(s, reg, &tmp, 1);
312 if (ret)
313 return ret;
314
315 tmp &= mask;
316
317 /* find position of the first bit */
318 for (i = 0; i < 8; i++) {
319 if ((mask >> i) & 0x01)
320 break;
321 }
322 *val = tmp >> i;
323 196
324 return 0; 197 return pdata->update_bits(client, reg, mask, val);
325} 198}
326#endif
327 199
328/* Private functions */ 200/* Private functions */
329static struct rtl2832_sdr_frame_buf *rtl2832_sdr_get_next_fill_buf( 201static struct rtl2832_sdr_frame_buf *rtl2832_sdr_get_next_fill_buf(
330 struct rtl2832_sdr_state *s) 202 struct rtl2832_sdr_dev *dev)
331{ 203{
332 unsigned long flags; 204 unsigned long flags;
333 struct rtl2832_sdr_frame_buf *buf = NULL; 205 struct rtl2832_sdr_frame_buf *buf = NULL;
334 206
335 spin_lock_irqsave(&s->queued_bufs_lock, flags); 207 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
336 if (list_empty(&s->queued_bufs)) 208 if (list_empty(&dev->queued_bufs))
337 goto leave; 209 goto leave;
338 210
339 buf = list_entry(s->queued_bufs.next, 211 buf = list_entry(dev->queued_bufs.next,
340 struct rtl2832_sdr_frame_buf, list); 212 struct rtl2832_sdr_frame_buf, list);
341 list_del(&buf->list); 213 list_del(&buf->list);
342leave: 214leave:
343 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 215 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
344 return buf; 216 return buf;
345} 217}
346 218
347static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_state *s, 219static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_dev *dev,
348 void *dst, const u8 *src, unsigned int src_len) 220 void *dst, const u8 *src, unsigned int src_len)
349{ 221{
222 struct platform_device *pdev = dev->pdev;
350 unsigned int dst_len; 223 unsigned int dst_len;
351 224
352 if (s->pixelformat == V4L2_SDR_FMT_CU8) { 225 if (dev->pixelformat == V4L2_SDR_FMT_CU8) {
353 /* native stream, no need to convert */ 226 /* native stream, no need to convert */
354 memcpy(dst, src, src_len); 227 memcpy(dst, src, src_len);
355 dst_len = src_len; 228 dst_len = src_len;
356 } else if (s->pixelformat == V4L2_SDR_FMT_CU16LE) { 229 } else if (dev->pixelformat == V4L2_SDR_FMT_CU16LE) {
357 /* convert u8 to u16 */ 230 /* convert u8 to u16 */
358 unsigned int i; 231 unsigned int i;
359 u16 *u16dst = dst; 232 u16 *u16dst = dst;
@@ -366,22 +239,21 @@ static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_state *s,
366 } 239 }
367 240
368 /* calculate sample rate and output it in 10 seconds intervals */ 241 /* calculate sample rate and output it in 10 seconds intervals */
369 if (unlikely(time_is_before_jiffies(s->jiffies_next))) { 242 if (unlikely(time_is_before_jiffies(dev->jiffies_next))) {
370 #define MSECS 10000UL 243 #define MSECS 10000UL
371 unsigned int msecs = jiffies_to_msecs(jiffies - 244 unsigned int msecs = jiffies_to_msecs(jiffies -
372 s->jiffies_next + msecs_to_jiffies(MSECS)); 245 dev->jiffies_next + msecs_to_jiffies(MSECS));
373 unsigned int samples = s->sample - s->sample_measured; 246 unsigned int samples = dev->sample - dev->sample_measured;
374 247
375 s->jiffies_next = jiffies + msecs_to_jiffies(MSECS); 248 dev->jiffies_next = jiffies + msecs_to_jiffies(MSECS);
376 s->sample_measured = s->sample; 249 dev->sample_measured = dev->sample;
377 dev_dbg(&s->udev->dev, 250 dev_dbg(&pdev->dev,
378 "slen=%u samples=%u msecs=%u sample rate=%lu\n", 251 "slen=%u samples=%u msecs=%u sample rate=%lu\n",
379 src_len, samples, msecs, 252 src_len, samples, msecs, samples * 1000UL / msecs);
380 samples * 1000UL / msecs);
381 } 253 }
382 254
383 /* total number of I+Q pairs */ 255 /* total number of I+Q pairs */
384 s->sample += src_len / 2; 256 dev->sample += src_len / 2;
385 257
386 return dst_len; 258 return dst_len;
387} 259}
@@ -392,13 +264,13 @@ static unsigned int rtl2832_sdr_convert_stream(struct rtl2832_sdr_state *s,
392 */ 264 */
393static void rtl2832_sdr_urb_complete(struct urb *urb) 265static void rtl2832_sdr_urb_complete(struct urb *urb)
394{ 266{
395 struct rtl2832_sdr_state *s = urb->context; 267 struct rtl2832_sdr_dev *dev = urb->context;
268 struct platform_device *pdev = dev->pdev;
396 struct rtl2832_sdr_frame_buf *fbuf; 269 struct rtl2832_sdr_frame_buf *fbuf;
397 270
398 dev_dbg_ratelimited(&s->udev->dev, 271 dev_dbg_ratelimited(&pdev->dev, "status=%d length=%d/%d errors=%d\n",
399 "status=%d length=%d/%d errors=%d\n", 272 urb->status, urb->actual_length,
400 urb->status, urb->actual_length, 273 urb->transfer_buffer_length, urb->error_count);
401 urb->transfer_buffer_length, urb->error_count);
402 274
403 switch (urb->status) { 275 switch (urb->status) {
404 case 0: /* success */ 276 case 0: /* success */
@@ -409,8 +281,7 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
409 case -ESHUTDOWN: 281 case -ESHUTDOWN:
410 return; 282 return;
411 default: /* error */ 283 default: /* error */
412 dev_err_ratelimited(&s->udev->dev, "urb failed=%d\n", 284 dev_err_ratelimited(&pdev->dev, "urb failed=%d\n", urb->status);
413 urb->status);
414 break; 285 break;
415 } 286 }
416 287
@@ -418,204 +289,192 @@ static void rtl2832_sdr_urb_complete(struct urb *urb)
418 void *ptr; 289 void *ptr;
419 unsigned int len; 290 unsigned int len;
420 /* get free framebuffer */ 291 /* get free framebuffer */
421 fbuf = rtl2832_sdr_get_next_fill_buf(s); 292 fbuf = rtl2832_sdr_get_next_fill_buf(dev);
422 if (unlikely(fbuf == NULL)) { 293 if (unlikely(fbuf == NULL)) {
423 s->vb_full++; 294 dev->vb_full++;
424 dev_notice_ratelimited(&s->udev->dev, 295 dev_notice_ratelimited(&pdev->dev,
425 "videobuf is full, %d packets dropped\n", 296 "videobuf is full, %d packets dropped\n",
426 s->vb_full); 297 dev->vb_full);
427 goto skip; 298 goto skip;
428 } 299 }
429 300
430 /* fill framebuffer */ 301 /* fill framebuffer */
431 ptr = vb2_plane_vaddr(&fbuf->vb, 0); 302 ptr = vb2_plane_vaddr(&fbuf->vb, 0);
432 len = rtl2832_sdr_convert_stream(s, ptr, urb->transfer_buffer, 303 len = rtl2832_sdr_convert_stream(dev, ptr, urb->transfer_buffer,
433 urb->actual_length); 304 urb->actual_length);
434 vb2_set_plane_payload(&fbuf->vb, 0, len); 305 vb2_set_plane_payload(&fbuf->vb, 0, len);
435 v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp); 306 v4l2_get_timestamp(&fbuf->vb.v4l2_buf.timestamp);
436 fbuf->vb.v4l2_buf.sequence = s->sequence++; 307 fbuf->vb.v4l2_buf.sequence = dev->sequence++;
437 vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE); 308 vb2_buffer_done(&fbuf->vb, VB2_BUF_STATE_DONE);
438 } 309 }
439skip: 310skip:
440 usb_submit_urb(urb, GFP_ATOMIC); 311 usb_submit_urb(urb, GFP_ATOMIC);
441} 312}
442 313
443static int rtl2832_sdr_kill_urbs(struct rtl2832_sdr_state *s) 314static int rtl2832_sdr_kill_urbs(struct rtl2832_sdr_dev *dev)
444{ 315{
316 struct platform_device *pdev = dev->pdev;
445 int i; 317 int i;
446 318
447 for (i = s->urbs_submitted - 1; i >= 0; i--) { 319 for (i = dev->urbs_submitted - 1; i >= 0; i--) {
448 dev_dbg(&s->udev->dev, "kill urb=%d\n", i); 320 dev_dbg(&pdev->dev, "kill urb=%d\n", i);
449 /* stop the URB */ 321 /* stop the URB */
450 usb_kill_urb(s->urb_list[i]); 322 usb_kill_urb(dev->urb_list[i]);
451 } 323 }
452 s->urbs_submitted = 0; 324 dev->urbs_submitted = 0;
453 325
454 return 0; 326 return 0;
455} 327}
456 328
457static int rtl2832_sdr_submit_urbs(struct rtl2832_sdr_state *s) 329static int rtl2832_sdr_submit_urbs(struct rtl2832_sdr_dev *dev)
458{ 330{
331 struct platform_device *pdev = dev->pdev;
459 int i, ret; 332 int i, ret;
460 333
461 for (i = 0; i < s->urbs_initialized; i++) { 334 for (i = 0; i < dev->urbs_initialized; i++) {
462 dev_dbg(&s->udev->dev, "submit urb=%d\n", i); 335 dev_dbg(&pdev->dev, "submit urb=%d\n", i);
463 ret = usb_submit_urb(s->urb_list[i], GFP_ATOMIC); 336 ret = usb_submit_urb(dev->urb_list[i], GFP_ATOMIC);
464 if (ret) { 337 if (ret) {
465 dev_err(&s->udev->dev, 338 dev_err(&pdev->dev,
466 "Could not submit urb no. %d - get them all back\n", 339 "Could not submit urb no. %d - get them all back\n",
467 i); 340 i);
468 rtl2832_sdr_kill_urbs(s); 341 rtl2832_sdr_kill_urbs(dev);
469 return ret; 342 return ret;
470 } 343 }
471 s->urbs_submitted++; 344 dev->urbs_submitted++;
472 } 345 }
473 346
474 return 0; 347 return 0;
475} 348}
476 349
477static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_state *s) 350static int rtl2832_sdr_free_stream_bufs(struct rtl2832_sdr_dev *dev)
478{ 351{
479 if (s->flags & USB_STATE_URB_BUF) { 352 struct platform_device *pdev = dev->pdev;
480 while (s->buf_num) { 353
481 s->buf_num--; 354 if (dev->flags & USB_STATE_URB_BUF) {
482 dev_dbg(&s->udev->dev, "free buf=%d\n", s->buf_num); 355 while (dev->buf_num) {
483 usb_free_coherent(s->udev, s->buf_size, 356 dev->buf_num--;
484 s->buf_list[s->buf_num], 357 dev_dbg(&pdev->dev, "free buf=%d\n", dev->buf_num);
485 s->dma_addr[s->buf_num]); 358 usb_free_coherent(dev->udev, dev->buf_size,
359 dev->buf_list[dev->buf_num],
360 dev->dma_addr[dev->buf_num]);
486 } 361 }
487 } 362 }
488 s->flags &= ~USB_STATE_URB_BUF; 363 dev->flags &= ~USB_STATE_URB_BUF;
489 364
490 return 0; 365 return 0;
491} 366}
492 367
493static int rtl2832_sdr_alloc_stream_bufs(struct rtl2832_sdr_state *s) 368static int rtl2832_sdr_alloc_stream_bufs(struct rtl2832_sdr_dev *dev)
494{ 369{
495 s->buf_num = 0; 370 struct platform_device *pdev = dev->pdev;
496 s->buf_size = BULK_BUFFER_SIZE;
497 371
498 dev_dbg(&s->udev->dev, "all in all I will use %u bytes for streaming\n", 372 dev->buf_num = 0;
499 MAX_BULK_BUFS * BULK_BUFFER_SIZE); 373 dev->buf_size = BULK_BUFFER_SIZE;
500 374
501 for (s->buf_num = 0; s->buf_num < MAX_BULK_BUFS; s->buf_num++) { 375 dev_dbg(&pdev->dev, "all in all I will use %u bytes for streaming\n",
502 s->buf_list[s->buf_num] = usb_alloc_coherent(s->udev, 376 MAX_BULK_BUFS * BULK_BUFFER_SIZE);
377
378 for (dev->buf_num = 0; dev->buf_num < MAX_BULK_BUFS; dev->buf_num++) {
379 dev->buf_list[dev->buf_num] = usb_alloc_coherent(dev->udev,
503 BULK_BUFFER_SIZE, GFP_ATOMIC, 380 BULK_BUFFER_SIZE, GFP_ATOMIC,
504 &s->dma_addr[s->buf_num]); 381 &dev->dma_addr[dev->buf_num]);
505 if (!s->buf_list[s->buf_num]) { 382 if (!dev->buf_list[dev->buf_num]) {
506 dev_dbg(&s->udev->dev, "alloc buf=%d failed\n", 383 dev_dbg(&pdev->dev, "alloc buf=%d failed\n",
507 s->buf_num); 384 dev->buf_num);
508 rtl2832_sdr_free_stream_bufs(s); 385 rtl2832_sdr_free_stream_bufs(dev);
509 return -ENOMEM; 386 return -ENOMEM;
510 } 387 }
511 388
512 dev_dbg(&s->udev->dev, "alloc buf=%d %p (dma %llu)\n", 389 dev_dbg(&pdev->dev, "alloc buf=%d %p (dma %llu)\n",
513 s->buf_num, s->buf_list[s->buf_num], 390 dev->buf_num, dev->buf_list[dev->buf_num],
514 (long long)s->dma_addr[s->buf_num]); 391 (long long)dev->dma_addr[dev->buf_num]);
515 s->flags |= USB_STATE_URB_BUF; 392 dev->flags |= USB_STATE_URB_BUF;
516 } 393 }
517 394
518 return 0; 395 return 0;
519} 396}
520 397
521static int rtl2832_sdr_free_urbs(struct rtl2832_sdr_state *s) 398static int rtl2832_sdr_free_urbs(struct rtl2832_sdr_dev *dev)
522{ 399{
400 struct platform_device *pdev = dev->pdev;
523 int i; 401 int i;
524 402
525 rtl2832_sdr_kill_urbs(s); 403 rtl2832_sdr_kill_urbs(dev);
526 404
527 for (i = s->urbs_initialized - 1; i >= 0; i--) { 405 for (i = dev->urbs_initialized - 1; i >= 0; i--) {
528 if (s->urb_list[i]) { 406 if (dev->urb_list[i]) {
529 dev_dbg(&s->udev->dev, "free urb=%d\n", i); 407 dev_dbg(&pdev->dev, "free urb=%d\n", i);
530 /* free the URBs */ 408 /* free the URBs */
531 usb_free_urb(s->urb_list[i]); 409 usb_free_urb(dev->urb_list[i]);
532 } 410 }
533 } 411 }
534 s->urbs_initialized = 0; 412 dev->urbs_initialized = 0;
535 413
536 return 0; 414 return 0;
537} 415}
538 416
539static int rtl2832_sdr_alloc_urbs(struct rtl2832_sdr_state *s) 417static int rtl2832_sdr_alloc_urbs(struct rtl2832_sdr_dev *dev)
540{ 418{
419 struct platform_device *pdev = dev->pdev;
541 int i, j; 420 int i, j;
542 421
543 /* allocate the URBs */ 422 /* allocate the URBs */
544 for (i = 0; i < MAX_BULK_BUFS; i++) { 423 for (i = 0; i < MAX_BULK_BUFS; i++) {
545 dev_dbg(&s->udev->dev, "alloc urb=%d\n", i); 424 dev_dbg(&pdev->dev, "alloc urb=%d\n", i);
546 s->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC); 425 dev->urb_list[i] = usb_alloc_urb(0, GFP_ATOMIC);
547 if (!s->urb_list[i]) { 426 if (!dev->urb_list[i]) {
548 dev_dbg(&s->udev->dev, "failed\n"); 427 dev_dbg(&pdev->dev, "failed\n");
549 for (j = 0; j < i; j++) 428 for (j = 0; j < i; j++)
550 usb_free_urb(s->urb_list[j]); 429 usb_free_urb(dev->urb_list[j]);
551 return -ENOMEM; 430 return -ENOMEM;
552 } 431 }
553 usb_fill_bulk_urb(s->urb_list[i], 432 usb_fill_bulk_urb(dev->urb_list[i],
554 s->udev, 433 dev->udev,
555 usb_rcvbulkpipe(s->udev, 0x81), 434 usb_rcvbulkpipe(dev->udev, 0x81),
556 s->buf_list[i], 435 dev->buf_list[i],
557 BULK_BUFFER_SIZE, 436 BULK_BUFFER_SIZE,
558 rtl2832_sdr_urb_complete, s); 437 rtl2832_sdr_urb_complete, dev);
559 438
560 s->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP; 439 dev->urb_list[i]->transfer_flags = URB_NO_TRANSFER_DMA_MAP;
561 s->urb_list[i]->transfer_dma = s->dma_addr[i]; 440 dev->urb_list[i]->transfer_dma = dev->dma_addr[i];
562 s->urbs_initialized++; 441 dev->urbs_initialized++;
563 } 442 }
564 443
565 return 0; 444 return 0;
566} 445}
567 446
568/* Must be called with vb_queue_lock hold */ 447/* Must be called with vb_queue_lock hold */
569static void rtl2832_sdr_cleanup_queued_bufs(struct rtl2832_sdr_state *s) 448static void rtl2832_sdr_cleanup_queued_bufs(struct rtl2832_sdr_dev *dev)
570{ 449{
450 struct platform_device *pdev = dev->pdev;
571 unsigned long flags; 451 unsigned long flags;
572 452
573 dev_dbg(&s->udev->dev, "\n"); 453 dev_dbg(&pdev->dev, "\n");
574 454
575 spin_lock_irqsave(&s->queued_bufs_lock, flags); 455 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
576 while (!list_empty(&s->queued_bufs)) { 456 while (!list_empty(&dev->queued_bufs)) {
577 struct rtl2832_sdr_frame_buf *buf; 457 struct rtl2832_sdr_frame_buf *buf;
578 458
579 buf = list_entry(s->queued_bufs.next, 459 buf = list_entry(dev->queued_bufs.next,
580 struct rtl2832_sdr_frame_buf, list); 460 struct rtl2832_sdr_frame_buf, list);
581 list_del(&buf->list); 461 list_del(&buf->list);
582 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 462 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
583 } 463 }
584 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 464 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
585}
586
587/* The user yanked out the cable... */
588static void rtl2832_sdr_release_sec(struct dvb_frontend *fe)
589{
590 struct rtl2832_sdr_state *s = fe->sec_priv;
591
592 dev_dbg(&s->udev->dev, "\n");
593
594 mutex_lock(&s->vb_queue_lock);
595 mutex_lock(&s->v4l2_lock);
596 /* No need to keep the urbs around after disconnection */
597 s->udev = NULL;
598
599 v4l2_device_disconnect(&s->v4l2_dev);
600 video_unregister_device(&s->vdev);
601 mutex_unlock(&s->v4l2_lock);
602 mutex_unlock(&s->vb_queue_lock);
603
604 v4l2_device_put(&s->v4l2_dev);
605
606 fe->sec_priv = NULL;
607} 465}
608 466
609static int rtl2832_sdr_querycap(struct file *file, void *fh, 467static int rtl2832_sdr_querycap(struct file *file, void *fh,
610 struct v4l2_capability *cap) 468 struct v4l2_capability *cap)
611{ 469{
612 struct rtl2832_sdr_state *s = video_drvdata(file); 470 struct rtl2832_sdr_dev *dev = video_drvdata(file);
471 struct platform_device *pdev = dev->pdev;
613 472
614 dev_dbg(&s->udev->dev, "\n"); 473 dev_dbg(&pdev->dev, "\n");
615 474
616 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver)); 475 strlcpy(cap->driver, KBUILD_MODNAME, sizeof(cap->driver));
617 strlcpy(cap->card, s->vdev.name, sizeof(cap->card)); 476 strlcpy(cap->card, dev->vdev.name, sizeof(cap->card));
618 usb_make_path(s->udev, cap->bus_info, sizeof(cap->bus_info)); 477 usb_make_path(dev->udev, cap->bus_info, sizeof(cap->bus_info));
619 cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING | 478 cap->device_caps = V4L2_CAP_SDR_CAPTURE | V4L2_CAP_STREAMING |
620 V4L2_CAP_READWRITE | V4L2_CAP_TUNER; 479 V4L2_CAP_READWRITE | V4L2_CAP_TUNER;
621 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS; 480 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
@@ -627,26 +486,26 @@ static int rtl2832_sdr_queue_setup(struct vb2_queue *vq,
627 const struct v4l2_format *fmt, unsigned int *nbuffers, 486 const struct v4l2_format *fmt, unsigned int *nbuffers,
628 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[]) 487 unsigned int *nplanes, unsigned int sizes[], void *alloc_ctxs[])
629{ 488{
630 struct rtl2832_sdr_state *s = vb2_get_drv_priv(vq); 489 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
490 struct platform_device *pdev = dev->pdev;
631 491
632 dev_dbg(&s->udev->dev, "nbuffers=%d\n", *nbuffers); 492 dev_dbg(&pdev->dev, "nbuffers=%d\n", *nbuffers);
633 493
634 /* Need at least 8 buffers */ 494 /* Need at least 8 buffers */
635 if (vq->num_buffers + *nbuffers < 8) 495 if (vq->num_buffers + *nbuffers < 8)
636 *nbuffers = 8 - vq->num_buffers; 496 *nbuffers = 8 - vq->num_buffers;
637 *nplanes = 1; 497 *nplanes = 1;
638 sizes[0] = PAGE_ALIGN(s->buffersize); 498 sizes[0] = PAGE_ALIGN(dev->buffersize);
639 dev_dbg(&s->udev->dev, "nbuffers=%d sizes[0]=%d\n", 499 dev_dbg(&pdev->dev, "nbuffers=%d sizes[0]=%d\n", *nbuffers, sizes[0]);
640 *nbuffers, sizes[0]);
641 return 0; 500 return 0;
642} 501}
643 502
644static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb) 503static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)
645{ 504{
646 struct rtl2832_sdr_state *s = vb2_get_drv_priv(vb->vb2_queue); 505 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
647 506
648 /* Don't allow queing new buffers after device disconnection */ 507 /* Don't allow queing new buffers after device disconnection */
649 if (!s->udev) 508 if (!dev->udev)
650 return -ENODEV; 509 return -ENODEV;
651 510
652 return 0; 511 return 0;
@@ -654,46 +513,48 @@ static int rtl2832_sdr_buf_prepare(struct vb2_buffer *vb)
654 513
655static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb) 514static void rtl2832_sdr_buf_queue(struct vb2_buffer *vb)
656{ 515{
657 struct rtl2832_sdr_state *s = vb2_get_drv_priv(vb->vb2_queue); 516 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
658 struct rtl2832_sdr_frame_buf *buf = 517 struct rtl2832_sdr_frame_buf *buf =
659 container_of(vb, struct rtl2832_sdr_frame_buf, vb); 518 container_of(vb, struct rtl2832_sdr_frame_buf, vb);
660 unsigned long flags; 519 unsigned long flags;
661 520
662 /* Check the device has not disconnected between prep and queuing */ 521 /* Check the device has not disconnected between prep and queuing */
663 if (!s->udev) { 522 if (!dev->udev) {
664 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 523 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
665 return; 524 return;
666 } 525 }
667 526
668 spin_lock_irqsave(&s->queued_bufs_lock, flags); 527 spin_lock_irqsave(&dev->queued_bufs_lock, flags);
669 list_add_tail(&buf->list, &s->queued_bufs); 528 list_add_tail(&buf->list, &dev->queued_bufs);
670 spin_unlock_irqrestore(&s->queued_bufs_lock, flags); 529 spin_unlock_irqrestore(&dev->queued_bufs_lock, flags);
671} 530}
672 531
673static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s) 532static int rtl2832_sdr_set_adc(struct rtl2832_sdr_dev *dev)
674{ 533{
675 struct dvb_frontend *fe = s->fe; 534 struct platform_device *pdev = dev->pdev;
535 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
536 struct dvb_frontend *fe = pdata->dvb_frontend;
676 int ret; 537 int ret;
677 unsigned int f_sr, f_if; 538 unsigned int f_sr, f_if;
678 u8 buf[4], u8tmp1, u8tmp2; 539 u8 buf[4], u8tmp1, u8tmp2;
679 u64 u64tmp; 540 u64 u64tmp;
680 u32 u32tmp; 541 u32 u32tmp;
681 542
682 dev_dbg(&s->udev->dev, "f_adc=%u\n", s->f_adc); 543 dev_dbg(&pdev->dev, "f_adc=%u\n", dev->f_adc);
683 544
684 if (!test_bit(POWER_ON, &s->flags)) 545 if (!test_bit(POWER_ON, &dev->flags))
685 return 0; 546 return 0;
686 547
687 if (s->f_adc == 0) 548 if (dev->f_adc == 0)
688 return 0; 549 return 0;
689 550
690 f_sr = s->f_adc; 551 f_sr = dev->f_adc;
691 552
692 ret = rtl2832_sdr_wr_regs(s, 0x13e, "\x00\x00", 2); 553 ret = rtl2832_sdr_wr_regs(dev, 0x13e, "\x00\x00", 2);
693 if (ret) 554 if (ret)
694 goto err; 555 goto err;
695 556
696 ret = rtl2832_sdr_wr_regs(s, 0x115, "\x00\x00\x00\x00", 4); 557 ret = rtl2832_sdr_wr_regs(dev, 0x115, "\x00\x00\x00\x00", 4);
697 if (ret) 558 if (ret)
698 goto err; 559 goto err;
699 560
@@ -707,19 +568,19 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
707 goto err; 568 goto err;
708 569
709 /* program IF */ 570 /* program IF */
710 u64tmp = f_if % s->cfg->xtal; 571 u64tmp = f_if % pdata->clk;
711 u64tmp *= 0x400000; 572 u64tmp *= 0x400000;
712 u64tmp = div_u64(u64tmp, s->cfg->xtal); 573 u64tmp = div_u64(u64tmp, pdata->clk);
713 u64tmp = -u64tmp; 574 u64tmp = -u64tmp;
714 u32tmp = u64tmp & 0x3fffff; 575 u32tmp = u64tmp & 0x3fffff;
715 576
716 dev_dbg(&s->udev->dev, "f_if=%u if_ctl=%08x\n", f_if, u32tmp); 577 dev_dbg(&pdev->dev, "f_if=%u if_ctl=%08x\n", f_if, u32tmp);
717 578
718 buf[0] = (u32tmp >> 16) & 0xff; 579 buf[0] = (u32tmp >> 16) & 0xff;
719 buf[1] = (u32tmp >> 8) & 0xff; 580 buf[1] = (u32tmp >> 8) & 0xff;
720 buf[2] = (u32tmp >> 0) & 0xff; 581 buf[2] = (u32tmp >> 0) & 0xff;
721 582
722 ret = rtl2832_sdr_wr_regs(s, 0x119, buf, 3); 583 ret = rtl2832_sdr_wr_regs(dev, 0x119, buf, 3);
723 if (ret) 584 if (ret)
724 goto err; 585 goto err;
725 586
@@ -733,208 +594,212 @@ static int rtl2832_sdr_set_adc(struct rtl2832_sdr_state *s)
733 u8tmp2 = 0xcd; /* enable ADC I, ADC Q */ 594 u8tmp2 = 0xcd; /* enable ADC I, ADC Q */
734 } 595 }
735 596
736 ret = rtl2832_sdr_wr_reg(s, 0x1b1, u8tmp1); 597 ret = rtl2832_sdr_wr_reg(dev, 0x1b1, u8tmp1);
737 if (ret) 598 if (ret)
738 goto err; 599 goto err;
739 600
740 ret = rtl2832_sdr_wr_reg(s, 0x008, u8tmp2); 601 ret = rtl2832_sdr_wr_reg(dev, 0x008, u8tmp2);
741 if (ret) 602 if (ret)
742 goto err; 603 goto err;
743 604
744 ret = rtl2832_sdr_wr_reg(s, 0x006, 0x80); 605 ret = rtl2832_sdr_wr_reg(dev, 0x006, 0x80);
745 if (ret) 606 if (ret)
746 goto err; 607 goto err;
747 608
748 /* program sampling rate (resampling down) */ 609 /* program sampling rate (resampling down) */
749 u32tmp = div_u64(s->cfg->xtal * 0x400000ULL, f_sr * 4U); 610 u32tmp = div_u64(pdata->clk * 0x400000ULL, f_sr * 4U);
750 u32tmp <<= 2; 611 u32tmp <<= 2;
751 buf[0] = (u32tmp >> 24) & 0xff; 612 buf[0] = (u32tmp >> 24) & 0xff;
752 buf[1] = (u32tmp >> 16) & 0xff; 613 buf[1] = (u32tmp >> 16) & 0xff;
753 buf[2] = (u32tmp >> 8) & 0xff; 614 buf[2] = (u32tmp >> 8) & 0xff;
754 buf[3] = (u32tmp >> 0) & 0xff; 615 buf[3] = (u32tmp >> 0) & 0xff;
755 ret = rtl2832_sdr_wr_regs(s, 0x19f, buf, 4); 616 ret = rtl2832_sdr_wr_regs(dev, 0x19f, buf, 4);
756 if (ret) 617 if (ret)
757 goto err; 618 goto err;
758 619
759 /* low-pass filter */ 620 /* low-pass filter */
760 ret = rtl2832_sdr_wr_regs(s, 0x11c, 621 ret = rtl2832_sdr_wr_regs(dev, 0x11c,
761 "\xca\xdc\xd7\xd8\xe0\xf2\x0e\x35\x06\x50\x9c\x0d\x71\x11\x14\x71\x74\x19\x41\xa5", 622 "\xca\xdc\xd7\xd8\xe0\xf2\x0e\x35\x06\x50\x9c\x0d\x71\x11\x14\x71\x74\x19\x41\xa5",
762 20); 623 20);
763 if (ret) 624 if (ret)
764 goto err; 625 goto err;
765 626
766 ret = rtl2832_sdr_wr_regs(s, 0x017, "\x11\x10", 2); 627 ret = rtl2832_sdr_wr_regs(dev, 0x017, "\x11\x10", 2);
767 if (ret) 628 if (ret)
768 goto err; 629 goto err;
769 630
770 /* mode */ 631 /* mode */
771 ret = rtl2832_sdr_wr_regs(s, 0x019, "\x05", 1); 632 ret = rtl2832_sdr_wr_regs(dev, 0x019, "\x05", 1);
772 if (ret) 633 if (ret)
773 goto err; 634 goto err;
774 635
775 ret = rtl2832_sdr_wr_regs(s, 0x01a, "\x1b\x16\x0d\x06\x01\xff", 6); 636 ret = rtl2832_sdr_wr_regs(dev, 0x01a, "\x1b\x16\x0d\x06\x01\xff", 6);
776 if (ret) 637 if (ret)
777 goto err; 638 goto err;
778 639
779 /* FSM */ 640 /* FSM */
780 ret = rtl2832_sdr_wr_regs(s, 0x192, "\x00\xf0\x0f", 3); 641 ret = rtl2832_sdr_wr_regs(dev, 0x192, "\x00\xf0\x0f", 3);
781 if (ret) 642 if (ret)
782 goto err; 643 goto err;
783 644
784 /* PID filter */ 645 /* PID filter */
785 ret = rtl2832_sdr_wr_regs(s, 0x061, "\x60", 1); 646 ret = rtl2832_sdr_wr_regs(dev, 0x061, "\x60", 1);
786 if (ret) 647 if (ret)
787 goto err; 648 goto err;
788 649
789 /* used RF tuner based settings */ 650 /* used RF tuner based settings */
790 switch (s->cfg->tuner) { 651 switch (pdata->tuner) {
791 case RTL2832_TUNER_E4000: 652 case RTL2832_SDR_TUNER_E4000:
792 ret = rtl2832_sdr_wr_regs(s, 0x112, "\x5a", 1); 653 ret = rtl2832_sdr_wr_regs(dev, 0x112, "\x5a", 1);
793 ret = rtl2832_sdr_wr_regs(s, 0x102, "\x40", 1); 654 ret = rtl2832_sdr_wr_regs(dev, 0x102, "\x40", 1);
794 ret = rtl2832_sdr_wr_regs(s, 0x103, "\x5a", 1); 655 ret = rtl2832_sdr_wr_regs(dev, 0x103, "\x5a", 1);
795 ret = rtl2832_sdr_wr_regs(s, 0x1c7, "\x30", 1); 656 ret = rtl2832_sdr_wr_regs(dev, 0x1c7, "\x30", 1);
796 ret = rtl2832_sdr_wr_regs(s, 0x104, "\xd0", 1); 657 ret = rtl2832_sdr_wr_regs(dev, 0x104, "\xd0", 1);
797 ret = rtl2832_sdr_wr_regs(s, 0x105, "\xbe", 1); 658 ret = rtl2832_sdr_wr_regs(dev, 0x105, "\xbe", 1);
798 ret = rtl2832_sdr_wr_regs(s, 0x1c8, "\x18", 1); 659 ret = rtl2832_sdr_wr_regs(dev, 0x1c8, "\x18", 1);
799 ret = rtl2832_sdr_wr_regs(s, 0x106, "\x35", 1); 660 ret = rtl2832_sdr_wr_regs(dev, 0x106, "\x35", 1);
800 ret = rtl2832_sdr_wr_regs(s, 0x1c9, "\x21", 1); 661 ret = rtl2832_sdr_wr_regs(dev, 0x1c9, "\x21", 1);
801 ret = rtl2832_sdr_wr_regs(s, 0x1ca, "\x21", 1); 662 ret = rtl2832_sdr_wr_regs(dev, 0x1ca, "\x21", 1);
802 ret = rtl2832_sdr_wr_regs(s, 0x1cb, "\x00", 1); 663 ret = rtl2832_sdr_wr_regs(dev, 0x1cb, "\x00", 1);
803 ret = rtl2832_sdr_wr_regs(s, 0x107, "\x40", 1); 664 ret = rtl2832_sdr_wr_regs(dev, 0x107, "\x40", 1);
804 ret = rtl2832_sdr_wr_regs(s, 0x1cd, "\x10", 1); 665 ret = rtl2832_sdr_wr_regs(dev, 0x1cd, "\x10", 1);
805 ret = rtl2832_sdr_wr_regs(s, 0x1ce, "\x10", 1); 666 ret = rtl2832_sdr_wr_regs(dev, 0x1ce, "\x10", 1);
806 ret = rtl2832_sdr_wr_regs(s, 0x108, "\x80", 1); 667 ret = rtl2832_sdr_wr_regs(dev, 0x108, "\x80", 1);
807 ret = rtl2832_sdr_wr_regs(s, 0x109, "\x7f", 1); 668 ret = rtl2832_sdr_wr_regs(dev, 0x109, "\x7f", 1);
808 ret = rtl2832_sdr_wr_regs(s, 0x10a, "\x80", 1); 669 ret = rtl2832_sdr_wr_regs(dev, 0x10a, "\x80", 1);
809 ret = rtl2832_sdr_wr_regs(s, 0x10b, "\x7f", 1); 670 ret = rtl2832_sdr_wr_regs(dev, 0x10b, "\x7f", 1);
810 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 671 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
811 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 672 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
812 ret = rtl2832_sdr_wr_regs(s, 0x011, "\xd4", 1); 673 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xd4", 1);
813 ret = rtl2832_sdr_wr_regs(s, 0x1e5, "\xf0", 1); 674 ret = rtl2832_sdr_wr_regs(dev, 0x1e5, "\xf0", 1);
814 ret = rtl2832_sdr_wr_regs(s, 0x1d9, "\x00", 1); 675 ret = rtl2832_sdr_wr_regs(dev, 0x1d9, "\x00", 1);
815 ret = rtl2832_sdr_wr_regs(s, 0x1db, "\x00", 1); 676 ret = rtl2832_sdr_wr_regs(dev, 0x1db, "\x00", 1);
816 ret = rtl2832_sdr_wr_regs(s, 0x1dd, "\x14", 1); 677 ret = rtl2832_sdr_wr_regs(dev, 0x1dd, "\x14", 1);
817 ret = rtl2832_sdr_wr_regs(s, 0x1de, "\xec", 1); 678 ret = rtl2832_sdr_wr_regs(dev, 0x1de, "\xec", 1);
818 ret = rtl2832_sdr_wr_regs(s, 0x1d8, "\x0c", 1); 679 ret = rtl2832_sdr_wr_regs(dev, 0x1d8, "\x0c", 1);
819 ret = rtl2832_sdr_wr_regs(s, 0x1e6, "\x02", 1); 680 ret = rtl2832_sdr_wr_regs(dev, 0x1e6, "\x02", 1);
820 ret = rtl2832_sdr_wr_regs(s, 0x1d7, "\x09", 1); 681 ret = rtl2832_sdr_wr_regs(dev, 0x1d7, "\x09", 1);
821 ret = rtl2832_sdr_wr_regs(s, 0x00d, "\x83", 1); 682 ret = rtl2832_sdr_wr_regs(dev, 0x00d, "\x83", 1);
822 ret = rtl2832_sdr_wr_regs(s, 0x010, "\x49", 1); 683 ret = rtl2832_sdr_wr_regs(dev, 0x010, "\x49", 1);
823 ret = rtl2832_sdr_wr_regs(s, 0x00d, "\x87", 1); 684 ret = rtl2832_sdr_wr_regs(dev, 0x00d, "\x87", 1);
824 ret = rtl2832_sdr_wr_regs(s, 0x00d, "\x85", 1); 685 ret = rtl2832_sdr_wr_regs(dev, 0x00d, "\x85", 1);
825 ret = rtl2832_sdr_wr_regs(s, 0x013, "\x02", 1); 686 ret = rtl2832_sdr_wr_regs(dev, 0x013, "\x02", 1);
826 break; 687 break;
827 case RTL2832_TUNER_FC0012: 688 case RTL2832_SDR_TUNER_FC0012:
828 case RTL2832_TUNER_FC0013: 689 case RTL2832_SDR_TUNER_FC0013:
829 ret = rtl2832_sdr_wr_regs(s, 0x112, "\x5a", 1); 690 ret = rtl2832_sdr_wr_regs(dev, 0x112, "\x5a", 1);
830 ret = rtl2832_sdr_wr_regs(s, 0x102, "\x40", 1); 691 ret = rtl2832_sdr_wr_regs(dev, 0x102, "\x40", 1);
831 ret = rtl2832_sdr_wr_regs(s, 0x103, "\x5a", 1); 692 ret = rtl2832_sdr_wr_regs(dev, 0x103, "\x5a", 1);
832 ret = rtl2832_sdr_wr_regs(s, 0x1c7, "\x2c", 1); 693 ret = rtl2832_sdr_wr_regs(dev, 0x1c7, "\x2c", 1);
833 ret = rtl2832_sdr_wr_regs(s, 0x104, "\xcc", 1); 694 ret = rtl2832_sdr_wr_regs(dev, 0x104, "\xcc", 1);
834 ret = rtl2832_sdr_wr_regs(s, 0x105, "\xbe", 1); 695 ret = rtl2832_sdr_wr_regs(dev, 0x105, "\xbe", 1);
835 ret = rtl2832_sdr_wr_regs(s, 0x1c8, "\x16", 1); 696 ret = rtl2832_sdr_wr_regs(dev, 0x1c8, "\x16", 1);
836 ret = rtl2832_sdr_wr_regs(s, 0x106, "\x35", 1); 697 ret = rtl2832_sdr_wr_regs(dev, 0x106, "\x35", 1);
837 ret = rtl2832_sdr_wr_regs(s, 0x1c9, "\x21", 1); 698 ret = rtl2832_sdr_wr_regs(dev, 0x1c9, "\x21", 1);
838 ret = rtl2832_sdr_wr_regs(s, 0x1ca, "\x21", 1); 699 ret = rtl2832_sdr_wr_regs(dev, 0x1ca, "\x21", 1);
839 ret = rtl2832_sdr_wr_regs(s, 0x1cb, "\x00", 1); 700 ret = rtl2832_sdr_wr_regs(dev, 0x1cb, "\x00", 1);
840 ret = rtl2832_sdr_wr_regs(s, 0x107, "\x40", 1); 701 ret = rtl2832_sdr_wr_regs(dev, 0x107, "\x40", 1);
841 ret = rtl2832_sdr_wr_regs(s, 0x1cd, "\x10", 1); 702 ret = rtl2832_sdr_wr_regs(dev, 0x1cd, "\x10", 1);
842 ret = rtl2832_sdr_wr_regs(s, 0x1ce, "\x10", 1); 703 ret = rtl2832_sdr_wr_regs(dev, 0x1ce, "\x10", 1);
843 ret = rtl2832_sdr_wr_regs(s, 0x108, "\x80", 1); 704 ret = rtl2832_sdr_wr_regs(dev, 0x108, "\x80", 1);
844 ret = rtl2832_sdr_wr_regs(s, 0x109, "\x7f", 1); 705 ret = rtl2832_sdr_wr_regs(dev, 0x109, "\x7f", 1);
845 ret = rtl2832_sdr_wr_regs(s, 0x10a, "\x80", 1); 706 ret = rtl2832_sdr_wr_regs(dev, 0x10a, "\x80", 1);
846 ret = rtl2832_sdr_wr_regs(s, 0x10b, "\x7f", 1); 707 ret = rtl2832_sdr_wr_regs(dev, 0x10b, "\x7f", 1);
847 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 708 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
848 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 709 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
849 ret = rtl2832_sdr_wr_regs(s, 0x011, "\xe9\xbf", 2); 710 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xe9\xbf", 2);
850 ret = rtl2832_sdr_wr_regs(s, 0x1e5, "\xf0", 1); 711 ret = rtl2832_sdr_wr_regs(dev, 0x1e5, "\xf0", 1);
851 ret = rtl2832_sdr_wr_regs(s, 0x1d9, "\x00", 1); 712 ret = rtl2832_sdr_wr_regs(dev, 0x1d9, "\x00", 1);
852 ret = rtl2832_sdr_wr_regs(s, 0x1db, "\x00", 1); 713 ret = rtl2832_sdr_wr_regs(dev, 0x1db, "\x00", 1);
853 ret = rtl2832_sdr_wr_regs(s, 0x1dd, "\x11", 1); 714 ret = rtl2832_sdr_wr_regs(dev, 0x1dd, "\x11", 1);
854 ret = rtl2832_sdr_wr_regs(s, 0x1de, "\xef", 1); 715 ret = rtl2832_sdr_wr_regs(dev, 0x1de, "\xef", 1);
855 ret = rtl2832_sdr_wr_regs(s, 0x1d8, "\x0c", 1); 716 ret = rtl2832_sdr_wr_regs(dev, 0x1d8, "\x0c", 1);
856 ret = rtl2832_sdr_wr_regs(s, 0x1e6, "\x02", 1); 717 ret = rtl2832_sdr_wr_regs(dev, 0x1e6, "\x02", 1);
857 ret = rtl2832_sdr_wr_regs(s, 0x1d7, "\x09", 1); 718 ret = rtl2832_sdr_wr_regs(dev, 0x1d7, "\x09", 1);
858 break; 719 break;
859 case RTL2832_TUNER_R820T: 720 case RTL2832_SDR_TUNER_R820T:
860 ret = rtl2832_sdr_wr_regs(s, 0x112, "\x5a", 1); 721 case RTL2832_SDR_TUNER_R828D:
861 ret = rtl2832_sdr_wr_regs(s, 0x102, "\x40", 1); 722 ret = rtl2832_sdr_wr_regs(dev, 0x112, "\x5a", 1);
862 ret = rtl2832_sdr_wr_regs(s, 0x115, "\x01", 1); 723 ret = rtl2832_sdr_wr_regs(dev, 0x102, "\x40", 1);
863 ret = rtl2832_sdr_wr_regs(s, 0x103, "\x80", 1); 724 ret = rtl2832_sdr_wr_regs(dev, 0x115, "\x01", 1);
864 ret = rtl2832_sdr_wr_regs(s, 0x1c7, "\x24", 1); 725 ret = rtl2832_sdr_wr_regs(dev, 0x103, "\x80", 1);
865 ret = rtl2832_sdr_wr_regs(s, 0x104, "\xcc", 1); 726 ret = rtl2832_sdr_wr_regs(dev, 0x1c7, "\x24", 1);
866 ret = rtl2832_sdr_wr_regs(s, 0x105, "\xbe", 1); 727 ret = rtl2832_sdr_wr_regs(dev, 0x104, "\xcc", 1);
867 ret = rtl2832_sdr_wr_regs(s, 0x1c8, "\x14", 1); 728 ret = rtl2832_sdr_wr_regs(dev, 0x105, "\xbe", 1);
868 ret = rtl2832_sdr_wr_regs(s, 0x106, "\x35", 1); 729 ret = rtl2832_sdr_wr_regs(dev, 0x1c8, "\x14", 1);
869 ret = rtl2832_sdr_wr_regs(s, 0x1c9, "\x21", 1); 730 ret = rtl2832_sdr_wr_regs(dev, 0x106, "\x35", 1);
870 ret = rtl2832_sdr_wr_regs(s, 0x1ca, "\x21", 1); 731 ret = rtl2832_sdr_wr_regs(dev, 0x1c9, "\x21", 1);
871 ret = rtl2832_sdr_wr_regs(s, 0x1cb, "\x00", 1); 732 ret = rtl2832_sdr_wr_regs(dev, 0x1ca, "\x21", 1);
872 ret = rtl2832_sdr_wr_regs(s, 0x107, "\x40", 1); 733 ret = rtl2832_sdr_wr_regs(dev, 0x1cb, "\x00", 1);
873 ret = rtl2832_sdr_wr_regs(s, 0x1cd, "\x10", 1); 734 ret = rtl2832_sdr_wr_regs(dev, 0x107, "\x40", 1);
874 ret = rtl2832_sdr_wr_regs(s, 0x1ce, "\x10", 1); 735 ret = rtl2832_sdr_wr_regs(dev, 0x1cd, "\x10", 1);
875 ret = rtl2832_sdr_wr_regs(s, 0x108, "\x80", 1); 736 ret = rtl2832_sdr_wr_regs(dev, 0x1ce, "\x10", 1);
876 ret = rtl2832_sdr_wr_regs(s, 0x109, "\x7f", 1); 737 ret = rtl2832_sdr_wr_regs(dev, 0x108, "\x80", 1);
877 ret = rtl2832_sdr_wr_regs(s, 0x10a, "\x80", 1); 738 ret = rtl2832_sdr_wr_regs(dev, 0x109, "\x7f", 1);
878 ret = rtl2832_sdr_wr_regs(s, 0x10b, "\x7f", 1); 739 ret = rtl2832_sdr_wr_regs(dev, 0x10a, "\x80", 1);
879 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 740 ret = rtl2832_sdr_wr_regs(dev, 0x10b, "\x7f", 1);
880 ret = rtl2832_sdr_wr_regs(s, 0x00e, "\xfc", 1); 741 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
881 ret = rtl2832_sdr_wr_regs(s, 0x011, "\xf4", 1); 742 ret = rtl2832_sdr_wr_regs(dev, 0x00e, "\xfc", 1);
743 ret = rtl2832_sdr_wr_regs(dev, 0x011, "\xf4", 1);
882 break; 744 break;
883 default: 745 default:
884 dev_notice(&s->udev->dev, "Unsupported tuner\n"); 746 dev_notice(&pdev->dev, "Unsupported tuner\n");
885 } 747 }
886 748
887 /* software reset */ 749 /* software reset */
888 ret = rtl2832_sdr_wr_reg_mask(s, 0x101, 0x04, 0x04); 750 ret = rtl2832_sdr_wr_reg_mask(dev, 0x101, 0x04, 0x04);
889 if (ret) 751 if (ret)
890 goto err; 752 goto err;
891 753
892 ret = rtl2832_sdr_wr_reg_mask(s, 0x101, 0x00, 0x04); 754 ret = rtl2832_sdr_wr_reg_mask(dev, 0x101, 0x00, 0x04);
893 if (ret) 755 if (ret)
894 goto err; 756 goto err;
895err: 757err:
896 return ret; 758 return ret;
897}; 759};
898 760
899static void rtl2832_sdr_unset_adc(struct rtl2832_sdr_state *s) 761static void rtl2832_sdr_unset_adc(struct rtl2832_sdr_dev *dev)
900{ 762{
763 struct platform_device *pdev = dev->pdev;
901 int ret; 764 int ret;
902 765
903 dev_dbg(&s->udev->dev, "\n"); 766 dev_dbg(&pdev->dev, "\n");
904 767
905 /* PID filter */ 768 /* PID filter */
906 ret = rtl2832_sdr_wr_regs(s, 0x061, "\xe0", 1); 769 ret = rtl2832_sdr_wr_regs(dev, 0x061, "\xe0", 1);
907 if (ret) 770 if (ret)
908 goto err; 771 goto err;
909 772
910 /* mode */ 773 /* mode */
911 ret = rtl2832_sdr_wr_regs(s, 0x019, "\x20", 1); 774 ret = rtl2832_sdr_wr_regs(dev, 0x019, "\x20", 1);
912 if (ret) 775 if (ret)
913 goto err; 776 goto err;
914 777
915 ret = rtl2832_sdr_wr_regs(s, 0x017, "\x11\x10", 2); 778 ret = rtl2832_sdr_wr_regs(dev, 0x017, "\x11\x10", 2);
916 if (ret) 779 if (ret)
917 goto err; 780 goto err;
918 781
919 /* FSM */ 782 /* FSM */
920 ret = rtl2832_sdr_wr_regs(s, 0x192, "\x00\x0f\xff", 3); 783 ret = rtl2832_sdr_wr_regs(dev, 0x192, "\x00\x0f\xff", 3);
921 if (ret) 784 if (ret)
922 goto err; 785 goto err;
923 786
924 ret = rtl2832_sdr_wr_regs(s, 0x13e, "\x40\x00", 2); 787 ret = rtl2832_sdr_wr_regs(dev, 0x13e, "\x40\x00", 2);
925 if (ret) 788 if (ret)
926 goto err; 789 goto err;
927 790
928 ret = rtl2832_sdr_wr_regs(s, 0x115, "\x06\x3f\xce\xcc", 4); 791 ret = rtl2832_sdr_wr_regs(dev, 0x115, "\x06\x3f\xce\xcc", 4);
929 if (ret) 792 if (ret)
930 goto err; 793 goto err;
931err: 794err:
932 return; 795 return;
933}; 796};
934 797
935static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_state *s) 798static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_dev *dev)
936{ 799{
937 struct dvb_frontend *fe = s->fe; 800 struct platform_device *pdev = dev->pdev;
801 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
802 struct dvb_frontend *fe = pdata->dvb_frontend;
938 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 803 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
939 struct v4l2_ctrl *bandwidth_auto; 804 struct v4l2_ctrl *bandwidth_auto;
940 struct v4l2_ctrl *bandwidth; 805 struct v4l2_ctrl *bandwidth;
@@ -942,29 +807,29 @@ static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_state *s)
942 /* 807 /*
943 * tuner RF (Hz) 808 * tuner RF (Hz)
944 */ 809 */
945 if (s->f_tuner == 0) 810 if (dev->f_tuner == 0)
946 return 0; 811 return 0;
947 812
948 /* 813 /*
949 * bandwidth (Hz) 814 * bandwidth (Hz)
950 */ 815 */
951 bandwidth_auto = v4l2_ctrl_find(&s->hdl, 816 bandwidth_auto = v4l2_ctrl_find(&dev->hdl,
952 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO); 817 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO);
953 bandwidth = v4l2_ctrl_find(&s->hdl, V4L2_CID_RF_TUNER_BANDWIDTH); 818 bandwidth = v4l2_ctrl_find(&dev->hdl, V4L2_CID_RF_TUNER_BANDWIDTH);
954 if (v4l2_ctrl_g_ctrl(bandwidth_auto)) { 819 if (v4l2_ctrl_g_ctrl(bandwidth_auto)) {
955 c->bandwidth_hz = s->f_adc; 820 c->bandwidth_hz = dev->f_adc;
956 v4l2_ctrl_s_ctrl(bandwidth, s->f_adc); 821 v4l2_ctrl_s_ctrl(bandwidth, dev->f_adc);
957 } else { 822 } else {
958 c->bandwidth_hz = v4l2_ctrl_g_ctrl(bandwidth); 823 c->bandwidth_hz = v4l2_ctrl_g_ctrl(bandwidth);
959 } 824 }
960 825
961 c->frequency = s->f_tuner; 826 c->frequency = dev->f_tuner;
962 c->delivery_system = SYS_DVBT; 827 c->delivery_system = SYS_DVBT;
963 828
964 dev_dbg(&s->udev->dev, "frequency=%u bandwidth=%d\n", 829 dev_dbg(&pdev->dev, "frequency=%u bandwidth=%d\n",
965 c->frequency, c->bandwidth_hz); 830 c->frequency, c->bandwidth_hz);
966 831
967 if (!test_bit(POWER_ON, &s->flags)) 832 if (!test_bit(POWER_ON, &dev->flags))
968 return 0; 833 return 0;
969 834
970 if (fe->ops.tuner_ops.set_params) 835 if (fe->ops.tuner_ops.set_params)
@@ -973,11 +838,13 @@ static int rtl2832_sdr_set_tuner_freq(struct rtl2832_sdr_state *s)
973 return 0; 838 return 0;
974}; 839};
975 840
976static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state *s) 841static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_dev *dev)
977{ 842{
978 struct dvb_frontend *fe = s->fe; 843 struct platform_device *pdev = dev->pdev;
844 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
845 struct dvb_frontend *fe = pdata->dvb_frontend;
979 846
980 dev_dbg(&s->udev->dev, "\n"); 847 dev_dbg(&pdev->dev, "\n");
981 848
982 if (fe->ops.tuner_ops.init) 849 if (fe->ops.tuner_ops.init)
983 fe->ops.tuner_ops.init(fe); 850 fe->ops.tuner_ops.init(fe);
@@ -985,11 +852,13 @@ static int rtl2832_sdr_set_tuner(struct rtl2832_sdr_state *s)
985 return 0; 852 return 0;
986}; 853};
987 854
988static void rtl2832_sdr_unset_tuner(struct rtl2832_sdr_state *s) 855static void rtl2832_sdr_unset_tuner(struct rtl2832_sdr_dev *dev)
989{ 856{
990 struct dvb_frontend *fe = s->fe; 857 struct platform_device *pdev = dev->pdev;
858 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
859 struct dvb_frontend *fe = pdata->dvb_frontend;
991 860
992 dev_dbg(&s->udev->dev, "\n"); 861 dev_dbg(&pdev->dev, "\n");
993 862
994 if (fe->ops.tuner_ops.sleep) 863 if (fe->ops.tuner_ops.sleep)
995 fe->ops.tuner_ops.sleep(fe); 864 fe->ops.tuner_ops.sleep(fe);
@@ -999,83 +868,89 @@ static void rtl2832_sdr_unset_tuner(struct rtl2832_sdr_state *s)
999 868
1000static int rtl2832_sdr_start_streaming(struct vb2_queue *vq, unsigned int count) 869static int rtl2832_sdr_start_streaming(struct vb2_queue *vq, unsigned int count)
1001{ 870{
1002 struct rtl2832_sdr_state *s = vb2_get_drv_priv(vq); 871 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
872 struct platform_device *pdev = dev->pdev;
873 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
874 struct dvb_usb_device *d = pdata->dvb_usb_device;
1003 int ret; 875 int ret;
1004 876
1005 dev_dbg(&s->udev->dev, "\n"); 877 dev_dbg(&pdev->dev, "\n");
1006 878
1007 if (!s->udev) 879 if (!dev->udev)
1008 return -ENODEV; 880 return -ENODEV;
1009 881
1010 if (mutex_lock_interruptible(&s->v4l2_lock)) 882 if (mutex_lock_interruptible(&dev->v4l2_lock))
1011 return -ERESTARTSYS; 883 return -ERESTARTSYS;
1012 884
1013 if (s->d->props->power_ctrl) 885 if (d->props->power_ctrl)
1014 s->d->props->power_ctrl(s->d, 1); 886 d->props->power_ctrl(d, 1);
1015 887
1016 /* enable ADC */ 888 /* enable ADC */
1017 if (s->d->props->frontend_ctrl) 889 if (d->props->frontend_ctrl)
1018 s->d->props->frontend_ctrl(s->fe, 1); 890 d->props->frontend_ctrl(pdata->dvb_frontend, 1);
1019 891
1020 set_bit(POWER_ON, &s->flags); 892 set_bit(POWER_ON, &dev->flags);
1021 893
1022 ret = rtl2832_sdr_set_tuner(s); 894 ret = rtl2832_sdr_set_tuner(dev);
1023 if (ret) 895 if (ret)
1024 goto err; 896 goto err;
1025 897
1026 ret = rtl2832_sdr_set_tuner_freq(s); 898 ret = rtl2832_sdr_set_tuner_freq(dev);
1027 if (ret) 899 if (ret)
1028 goto err; 900 goto err;
1029 901
1030 ret = rtl2832_sdr_set_adc(s); 902 ret = rtl2832_sdr_set_adc(dev);
1031 if (ret) 903 if (ret)
1032 goto err; 904 goto err;
1033 905
1034 ret = rtl2832_sdr_alloc_stream_bufs(s); 906 ret = rtl2832_sdr_alloc_stream_bufs(dev);
1035 if (ret) 907 if (ret)
1036 goto err; 908 goto err;
1037 909
1038 ret = rtl2832_sdr_alloc_urbs(s); 910 ret = rtl2832_sdr_alloc_urbs(dev);
1039 if (ret) 911 if (ret)
1040 goto err; 912 goto err;
1041 913
1042 s->sequence = 0; 914 dev->sequence = 0;
1043 915
1044 ret = rtl2832_sdr_submit_urbs(s); 916 ret = rtl2832_sdr_submit_urbs(dev);
1045 if (ret) 917 if (ret)
1046 goto err; 918 goto err;
1047 919
1048err: 920err:
1049 mutex_unlock(&s->v4l2_lock); 921 mutex_unlock(&dev->v4l2_lock);
1050 922
1051 return ret; 923 return ret;
1052} 924}
1053 925
1054static void rtl2832_sdr_stop_streaming(struct vb2_queue *vq) 926static void rtl2832_sdr_stop_streaming(struct vb2_queue *vq)
1055{ 927{
1056 struct rtl2832_sdr_state *s = vb2_get_drv_priv(vq); 928 struct rtl2832_sdr_dev *dev = vb2_get_drv_priv(vq);
929 struct platform_device *pdev = dev->pdev;
930 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
931 struct dvb_usb_device *d = pdata->dvb_usb_device;
1057 932
1058 dev_dbg(&s->udev->dev, "\n"); 933 dev_dbg(&pdev->dev, "\n");
1059 934
1060 mutex_lock(&s->v4l2_lock); 935 mutex_lock(&dev->v4l2_lock);
1061 936
1062 rtl2832_sdr_kill_urbs(s); 937 rtl2832_sdr_kill_urbs(dev);
1063 rtl2832_sdr_free_urbs(s); 938 rtl2832_sdr_free_urbs(dev);
1064 rtl2832_sdr_free_stream_bufs(s); 939 rtl2832_sdr_free_stream_bufs(dev);
1065 rtl2832_sdr_cleanup_queued_bufs(s); 940 rtl2832_sdr_cleanup_queued_bufs(dev);
1066 rtl2832_sdr_unset_adc(s); 941 rtl2832_sdr_unset_adc(dev);
1067 rtl2832_sdr_unset_tuner(s); 942 rtl2832_sdr_unset_tuner(dev);
1068 943
1069 clear_bit(POWER_ON, &s->flags); 944 clear_bit(POWER_ON, &dev->flags);
1070 945
1071 /* disable ADC */ 946 /* disable ADC */
1072 if (s->d->props->frontend_ctrl) 947 if (d->props->frontend_ctrl)
1073 s->d->props->frontend_ctrl(s->fe, 0); 948 d->props->frontend_ctrl(pdata->dvb_frontend, 0);
1074 949
1075 if (s->d->props->power_ctrl) 950 if (d->props->power_ctrl)
1076 s->d->props->power_ctrl(s->d, 0); 951 d->props->power_ctrl(d, 0);
1077 952
1078 mutex_unlock(&s->v4l2_lock); 953 mutex_unlock(&dev->v4l2_lock);
1079} 954}
1080 955
1081static struct vb2_ops rtl2832_sdr_vb2_ops = { 956static struct vb2_ops rtl2832_sdr_vb2_ops = {
@@ -1091,9 +966,10 @@ static struct vb2_ops rtl2832_sdr_vb2_ops = {
1091static int rtl2832_sdr_g_tuner(struct file *file, void *priv, 966static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
1092 struct v4l2_tuner *v) 967 struct v4l2_tuner *v)
1093{ 968{
1094 struct rtl2832_sdr_state *s = video_drvdata(file); 969 struct rtl2832_sdr_dev *dev = video_drvdata(file);
970 struct platform_device *pdev = dev->pdev;
1095 971
1096 dev_dbg(&s->udev->dev, "index=%d type=%d\n", v->index, v->type); 972 dev_dbg(&pdev->dev, "index=%d type=%d\n", v->index, v->type);
1097 973
1098 if (v->index == 0) { 974 if (v->index == 0) {
1099 strlcpy(v->name, "ADC: Realtek RTL2832", sizeof(v->name)); 975 strlcpy(v->name, "ADC: Realtek RTL2832", sizeof(v->name));
@@ -1117,9 +993,10 @@ static int rtl2832_sdr_g_tuner(struct file *file, void *priv,
1117static int rtl2832_sdr_s_tuner(struct file *file, void *priv, 993static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
1118 const struct v4l2_tuner *v) 994 const struct v4l2_tuner *v)
1119{ 995{
1120 struct rtl2832_sdr_state *s = video_drvdata(file); 996 struct rtl2832_sdr_dev *dev = video_drvdata(file);
997 struct platform_device *pdev = dev->pdev;
1121 998
1122 dev_dbg(&s->udev->dev, "\n"); 999 dev_dbg(&pdev->dev, "\n");
1123 1000
1124 if (v->index > 1) 1001 if (v->index > 1)
1125 return -EINVAL; 1002 return -EINVAL;
@@ -1129,10 +1006,11 @@ static int rtl2832_sdr_s_tuner(struct file *file, void *priv,
1129static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv, 1006static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
1130 struct v4l2_frequency_band *band) 1007 struct v4l2_frequency_band *band)
1131{ 1008{
1132 struct rtl2832_sdr_state *s = video_drvdata(file); 1009 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1010 struct platform_device *pdev = dev->pdev;
1133 1011
1134 dev_dbg(&s->udev->dev, "tuner=%d type=%d index=%d\n", 1012 dev_dbg(&pdev->dev, "tuner=%d type=%d index=%d\n",
1135 band->tuner, band->type, band->index); 1013 band->tuner, band->type, band->index);
1136 1014
1137 if (band->tuner == 0) { 1015 if (band->tuner == 0) {
1138 if (band->index >= ARRAY_SIZE(bands_adc)) 1016 if (band->index >= ARRAY_SIZE(bands_adc))
@@ -1154,17 +1032,17 @@ static int rtl2832_sdr_enum_freq_bands(struct file *file, void *priv,
1154static int rtl2832_sdr_g_frequency(struct file *file, void *priv, 1032static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
1155 struct v4l2_frequency *f) 1033 struct v4l2_frequency *f)
1156{ 1034{
1157 struct rtl2832_sdr_state *s = video_drvdata(file); 1035 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1036 struct platform_device *pdev = dev->pdev;
1158 int ret = 0; 1037 int ret = 0;
1159 1038
1160 dev_dbg(&s->udev->dev, "tuner=%d type=%d\n", 1039 dev_dbg(&pdev->dev, "tuner=%d type=%d\n", f->tuner, f->type);
1161 f->tuner, f->type);
1162 1040
1163 if (f->tuner == 0) { 1041 if (f->tuner == 0) {
1164 f->frequency = s->f_adc; 1042 f->frequency = dev->f_adc;
1165 f->type = V4L2_TUNER_ADC; 1043 f->type = V4L2_TUNER_ADC;
1166 } else if (f->tuner == 1) { 1044 } else if (f->tuner == 1) {
1167 f->frequency = s->f_tuner; 1045 f->frequency = dev->f_tuner;
1168 f->type = V4L2_TUNER_RF; 1046 f->type = V4L2_TUNER_RF;
1169 } else { 1047 } else {
1170 return -EINVAL; 1048 return -EINVAL;
@@ -1176,11 +1054,12 @@ static int rtl2832_sdr_g_frequency(struct file *file, void *priv,
1176static int rtl2832_sdr_s_frequency(struct file *file, void *priv, 1054static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
1177 const struct v4l2_frequency *f) 1055 const struct v4l2_frequency *f)
1178{ 1056{
1179 struct rtl2832_sdr_state *s = video_drvdata(file); 1057 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1058 struct platform_device *pdev = dev->pdev;
1180 int ret, band; 1059 int ret, band;
1181 1060
1182 dev_dbg(&s->udev->dev, "tuner=%d type=%d frequency=%u\n", 1061 dev_dbg(&pdev->dev, "tuner=%d type=%d frequency=%u\n",
1183 f->tuner, f->type, f->frequency); 1062 f->tuner, f->type, f->frequency);
1184 1063
1185 /* ADC band midpoints */ 1064 /* ADC band midpoints */
1186 #define BAND_ADC_0 ((bands_adc[0].rangehigh + bands_adc[1].rangelow) / 2) 1065 #define BAND_ADC_0 ((bands_adc[0].rangehigh + bands_adc[1].rangelow) / 2)
@@ -1194,19 +1073,19 @@ static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
1194 else 1073 else
1195 band = 2; 1074 band = 2;
1196 1075
1197 s->f_adc = clamp_t(unsigned int, f->frequency, 1076 dev->f_adc = clamp_t(unsigned int, f->frequency,
1198 bands_adc[band].rangelow, 1077 bands_adc[band].rangelow,
1199 bands_adc[band].rangehigh); 1078 bands_adc[band].rangehigh);
1200 1079
1201 dev_dbg(&s->udev->dev, "ADC frequency=%u Hz\n", s->f_adc); 1080 dev_dbg(&pdev->dev, "ADC frequency=%u Hz\n", dev->f_adc);
1202 ret = rtl2832_sdr_set_adc(s); 1081 ret = rtl2832_sdr_set_adc(dev);
1203 } else if (f->tuner == 1) { 1082 } else if (f->tuner == 1) {
1204 s->f_tuner = clamp_t(unsigned int, f->frequency, 1083 dev->f_tuner = clamp_t(unsigned int, f->frequency,
1205 bands_fm[0].rangelow, 1084 bands_fm[0].rangelow,
1206 bands_fm[0].rangehigh); 1085 bands_fm[0].rangehigh);
1207 dev_dbg(&s->udev->dev, "RF frequency=%u Hz\n", f->frequency); 1086 dev_dbg(&pdev->dev, "RF frequency=%u Hz\n", f->frequency);
1208 1087
1209 ret = rtl2832_sdr_set_tuner_freq(s); 1088 ret = rtl2832_sdr_set_tuner_freq(dev);
1210 } else { 1089 } else {
1211 ret = -EINVAL; 1090 ret = -EINVAL;
1212 } 1091 }
@@ -1217,11 +1096,12 @@ static int rtl2832_sdr_s_frequency(struct file *file, void *priv,
1217static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file, void *priv, 1096static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file, void *priv,
1218 struct v4l2_fmtdesc *f) 1097 struct v4l2_fmtdesc *f)
1219{ 1098{
1220 struct rtl2832_sdr_state *s = video_drvdata(file); 1099 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1100 struct platform_device *pdev = dev->pdev;
1221 1101
1222 dev_dbg(&s->udev->dev, "\n"); 1102 dev_dbg(&pdev->dev, "\n");
1223 1103
1224 if (f->index >= s->num_formats) 1104 if (f->index >= dev->num_formats)
1225 return -EINVAL; 1105 return -EINVAL;
1226 1106
1227 strlcpy(f->description, formats[f->index].name, sizeof(f->description)); 1107 strlcpy(f->description, formats[f->index].name, sizeof(f->description));
@@ -1233,12 +1113,13 @@ static int rtl2832_sdr_enum_fmt_sdr_cap(struct file *file, void *priv,
1233static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, void *priv, 1113static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, void *priv,
1234 struct v4l2_format *f) 1114 struct v4l2_format *f)
1235{ 1115{
1236 struct rtl2832_sdr_state *s = video_drvdata(file); 1116 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1117 struct platform_device *pdev = dev->pdev;
1237 1118
1238 dev_dbg(&s->udev->dev, "\n"); 1119 dev_dbg(&pdev->dev, "\n");
1239 1120
1240 f->fmt.sdr.pixelformat = s->pixelformat; 1121 f->fmt.sdr.pixelformat = dev->pixelformat;
1241 f->fmt.sdr.buffersize = s->buffersize; 1122 f->fmt.sdr.buffersize = dev->buffersize;
1242 1123
1243 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 1124 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
1244 1125
@@ -1248,28 +1129,29 @@ static int rtl2832_sdr_g_fmt_sdr_cap(struct file *file, void *priv,
1248static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, void *priv, 1129static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, void *priv,
1249 struct v4l2_format *f) 1130 struct v4l2_format *f)
1250{ 1131{
1251 struct rtl2832_sdr_state *s = video_drvdata(file); 1132 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1252 struct vb2_queue *q = &s->vb_queue; 1133 struct platform_device *pdev = dev->pdev;
1134 struct vb2_queue *q = &dev->vb_queue;
1253 int i; 1135 int i;
1254 1136
1255 dev_dbg(&s->udev->dev, "pixelformat fourcc %4.4s\n", 1137 dev_dbg(&pdev->dev, "pixelformat fourcc %4.4s\n",
1256 (char *)&f->fmt.sdr.pixelformat); 1138 (char *)&f->fmt.sdr.pixelformat);
1257 1139
1258 if (vb2_is_busy(q)) 1140 if (vb2_is_busy(q))
1259 return -EBUSY; 1141 return -EBUSY;
1260 1142
1261 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 1143 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
1262 for (i = 0; i < s->num_formats; i++) { 1144 for (i = 0; i < dev->num_formats; i++) {
1263 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 1145 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
1264 s->pixelformat = formats[i].pixelformat; 1146 dev->pixelformat = formats[i].pixelformat;
1265 s->buffersize = formats[i].buffersize; 1147 dev->buffersize = formats[i].buffersize;
1266 f->fmt.sdr.buffersize = formats[i].buffersize; 1148 f->fmt.sdr.buffersize = formats[i].buffersize;
1267 return 0; 1149 return 0;
1268 } 1150 }
1269 } 1151 }
1270 1152
1271 s->pixelformat = formats[0].pixelformat; 1153 dev->pixelformat = formats[0].pixelformat;
1272 s->buffersize = formats[0].buffersize; 1154 dev->buffersize = formats[0].buffersize;
1273 f->fmt.sdr.pixelformat = formats[0].pixelformat; 1155 f->fmt.sdr.pixelformat = formats[0].pixelformat;
1274 f->fmt.sdr.buffersize = formats[0].buffersize; 1156 f->fmt.sdr.buffersize = formats[0].buffersize;
1275 1157
@@ -1279,14 +1161,15 @@ static int rtl2832_sdr_s_fmt_sdr_cap(struct file *file, void *priv,
1279static int rtl2832_sdr_try_fmt_sdr_cap(struct file *file, void *priv, 1161static int rtl2832_sdr_try_fmt_sdr_cap(struct file *file, void *priv,
1280 struct v4l2_format *f) 1162 struct v4l2_format *f)
1281{ 1163{
1282 struct rtl2832_sdr_state *s = video_drvdata(file); 1164 struct rtl2832_sdr_dev *dev = video_drvdata(file);
1165 struct platform_device *pdev = dev->pdev;
1283 int i; 1166 int i;
1284 1167
1285 dev_dbg(&s->udev->dev, "pixelformat fourcc %4.4s\n", 1168 dev_dbg(&pdev->dev, "pixelformat fourcc %4.4s\n",
1286 (char *)&f->fmt.sdr.pixelformat); 1169 (char *)&f->fmt.sdr.pixelformat);
1287 1170
1288 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved)); 1171 memset(f->fmt.sdr.reserved, 0, sizeof(f->fmt.sdr.reserved));
1289 for (i = 0; i < s->num_formats; i++) { 1172 for (i = 0; i < dev->num_formats; i++) {
1290 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) { 1173 if (formats[i].pixelformat == f->fmt.sdr.pixelformat) {
1291 f->fmt.sdr.buffersize = formats[i].buffersize; 1174 f->fmt.sdr.buffersize = formats[i].buffersize;
1292 return 0; 1175 return 0;
@@ -1348,37 +1231,38 @@ static struct video_device rtl2832_sdr_template = {
1348 1231
1349static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl) 1232static int rtl2832_sdr_s_ctrl(struct v4l2_ctrl *ctrl)
1350{ 1233{
1351 struct rtl2832_sdr_state *s = 1234 struct rtl2832_sdr_dev *dev =
1352 container_of(ctrl->handler, struct rtl2832_sdr_state, 1235 container_of(ctrl->handler, struct rtl2832_sdr_dev,
1353 hdl); 1236 hdl);
1354 struct dvb_frontend *fe = s->fe; 1237 struct platform_device *pdev = dev->pdev;
1238 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
1239 struct dvb_frontend *fe = pdata->dvb_frontend;
1355 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 1240 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
1356 int ret; 1241 int ret;
1357 1242
1358 dev_dbg(&s->udev->dev, 1243 dev_dbg(&pdev->dev, "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n",
1359 "id=%d name=%s val=%d min=%lld max=%lld step=%lld\n", 1244 ctrl->id, ctrl->name, ctrl->val, ctrl->minimum, ctrl->maximum,
1360 ctrl->id, ctrl->name, ctrl->val, 1245 ctrl->step);
1361 ctrl->minimum, ctrl->maximum, ctrl->step);
1362 1246
1363 switch (ctrl->id) { 1247 switch (ctrl->id) {
1364 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO: 1248 case V4L2_CID_RF_TUNER_BANDWIDTH_AUTO:
1365 case V4L2_CID_RF_TUNER_BANDWIDTH: 1249 case V4L2_CID_RF_TUNER_BANDWIDTH:
1366 /* TODO: these controls should be moved to tuner drivers */ 1250 /* TODO: these controls should be moved to tuner drivers */
1367 if (s->bandwidth_auto->val) { 1251 if (dev->bandwidth_auto->val) {
1368 /* Round towards the closest legal value */ 1252 /* Round towards the closest legal value */
1369 s32 val = s->f_adc + div_u64(s->bandwidth->step, 2); 1253 s32 val = dev->f_adc + div_u64(dev->bandwidth->step, 2);
1370 u32 offset; 1254 u32 offset;
1371 1255
1372 val = clamp_t(s32, val, s->bandwidth->minimum, 1256 val = clamp_t(s32, val, dev->bandwidth->minimum,
1373 s->bandwidth->maximum); 1257 dev->bandwidth->maximum);
1374 offset = val - s->bandwidth->minimum; 1258 offset = val - dev->bandwidth->minimum;
1375 offset = s->bandwidth->step * 1259 offset = dev->bandwidth->step *
1376 div_u64(offset, s->bandwidth->step); 1260 div_u64(offset, dev->bandwidth->step);
1377 s->bandwidth->val = s->bandwidth->minimum + offset; 1261 dev->bandwidth->val = dev->bandwidth->minimum + offset;
1378 } 1262 }
1379 c->bandwidth_hz = s->bandwidth->val; 1263 c->bandwidth_hz = dev->bandwidth->val;
1380 1264
1381 if (!test_bit(POWER_ON, &s->flags)) 1265 if (!test_bit(POWER_ON, &dev->flags))
1382 return 0; 1266 return 0;
1383 1267
1384 if (fe->ops.tuner_ops.set_params) 1268 if (fe->ops.tuner_ops.set_params)
@@ -1399,154 +1283,195 @@ static const struct v4l2_ctrl_ops rtl2832_sdr_ctrl_ops = {
1399 1283
1400static void rtl2832_sdr_video_release(struct v4l2_device *v) 1284static void rtl2832_sdr_video_release(struct v4l2_device *v)
1401{ 1285{
1402 struct rtl2832_sdr_state *s = 1286 struct rtl2832_sdr_dev *dev =
1403 container_of(v, struct rtl2832_sdr_state, v4l2_dev); 1287 container_of(v, struct rtl2832_sdr_dev, v4l2_dev);
1288 struct platform_device *pdev = dev->pdev;
1289
1290 dev_dbg(&pdev->dev, "\n");
1404 1291
1405 v4l2_ctrl_handler_free(&s->hdl); 1292 v4l2_ctrl_handler_free(&dev->hdl);
1406 v4l2_device_unregister(&s->v4l2_dev); 1293 v4l2_device_unregister(&dev->v4l2_dev);
1407 kfree(s); 1294 kfree(dev);
1408} 1295}
1409 1296
1410struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe, 1297/* Platform driver interface */
1411 struct i2c_adapter *i2c, const struct rtl2832_config *cfg, 1298static int rtl2832_sdr_probe(struct platform_device *pdev)
1412 struct v4l2_subdev *sd)
1413{ 1299{
1414 int ret; 1300 struct rtl2832_sdr_dev *dev;
1415 struct rtl2832_sdr_state *s; 1301 struct rtl2832_sdr_platform_data *pdata = pdev->dev.platform_data;
1416 const struct v4l2_ctrl_ops *ops = &rtl2832_sdr_ctrl_ops; 1302 const struct v4l2_ctrl_ops *ops = &rtl2832_sdr_ctrl_ops;
1417 struct dvb_usb_device *d = i2c_get_adapdata(i2c); 1303 struct v4l2_subdev *subdev;
1304 int ret;
1305
1306 dev_dbg(&pdev->dev, "\n");
1418 1307
1419 s = kzalloc(sizeof(struct rtl2832_sdr_state), GFP_KERNEL); 1308 if (!pdata) {
1420 if (s == NULL) { 1309 dev_err(&pdev->dev, "Cannot proceed without platform data\n");
1421 dev_err(&d->udev->dev, 1310 ret = -EINVAL;
1422 "Could not allocate memory for rtl2832_sdr_state\n"); 1311 goto err;
1423 return NULL; 1312 }
1313 if (!pdev->dev.parent->driver) {
1314 dev_dbg(&pdev->dev, "No parent device\n");
1315 ret = -EINVAL;
1316 goto err;
1317 }
1318 /* try to refcount host drv since we are the consumer */
1319 if (!try_module_get(pdev->dev.parent->driver->owner)) {
1320 dev_err(&pdev->dev, "Refcount fail");
1321 ret = -EINVAL;
1322 goto err;
1323 }
1324 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1325 if (dev == NULL) {
1326 ret = -ENOMEM;
1327 goto err_module_put;
1424 } 1328 }
1425 1329
1426 /* setup the state */ 1330 /* setup the state */
1427 s->fe = fe; 1331 subdev = pdata->v4l2_subdev;
1428 s->d = d; 1332 dev->pdev = pdev;
1429 s->udev = d->udev; 1333 dev->udev = pdata->dvb_usb_device->udev;
1430 s->i2c = i2c; 1334 dev->f_adc = bands_adc[0].rangelow;
1431 s->cfg = cfg; 1335 dev->f_tuner = bands_fm[0].rangelow;
1432 s->f_adc = bands_adc[0].rangelow; 1336 dev->pixelformat = formats[0].pixelformat;
1433 s->f_tuner = bands_fm[0].rangelow; 1337 dev->buffersize = formats[0].buffersize;
1434 s->pixelformat = formats[0].pixelformat; 1338 dev->num_formats = NUM_FORMATS;
1435 s->buffersize = formats[0].buffersize;
1436 s->num_formats = NUM_FORMATS;
1437 if (!rtl2832_sdr_emulated_fmt) 1339 if (!rtl2832_sdr_emulated_fmt)
1438 s->num_formats -= 1; 1340 dev->num_formats -= 1;
1439 1341
1440 mutex_init(&s->v4l2_lock); 1342 mutex_init(&dev->v4l2_lock);
1441 mutex_init(&s->vb_queue_lock); 1343 mutex_init(&dev->vb_queue_lock);
1442 spin_lock_init(&s->queued_bufs_lock); 1344 spin_lock_init(&dev->queued_bufs_lock);
1443 INIT_LIST_HEAD(&s->queued_bufs); 1345 INIT_LIST_HEAD(&dev->queued_bufs);
1444 1346
1445 /* Init videobuf2 queue structure */ 1347 /* Init videobuf2 queue structure */
1446 s->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE; 1348 dev->vb_queue.type = V4L2_BUF_TYPE_SDR_CAPTURE;
1447 s->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ; 1349 dev->vb_queue.io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
1448 s->vb_queue.drv_priv = s; 1350 dev->vb_queue.drv_priv = dev;
1449 s->vb_queue.buf_struct_size = sizeof(struct rtl2832_sdr_frame_buf); 1351 dev->vb_queue.buf_struct_size = sizeof(struct rtl2832_sdr_frame_buf);
1450 s->vb_queue.ops = &rtl2832_sdr_vb2_ops; 1352 dev->vb_queue.ops = &rtl2832_sdr_vb2_ops;
1451 s->vb_queue.mem_ops = &vb2_vmalloc_memops; 1353 dev->vb_queue.mem_ops = &vb2_vmalloc_memops;
1452 s->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1354 dev->vb_queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1453 ret = vb2_queue_init(&s->vb_queue); 1355 ret = vb2_queue_init(&dev->vb_queue);
1454 if (ret) { 1356 if (ret) {
1455 dev_err(&s->udev->dev, "Could not initialize vb2 queue\n"); 1357 dev_err(&pdev->dev, "Could not initialize vb2 queue\n");
1456 goto err_free_mem; 1358 goto err_kfree;
1457 } 1359 }
1458 1360
1459 /* Register controls */ 1361 /* Register controls */
1460 switch (s->cfg->tuner) { 1362 switch (pdata->tuner) {
1461 case RTL2832_TUNER_E4000: 1363 case RTL2832_SDR_TUNER_E4000:
1462 v4l2_ctrl_handler_init(&s->hdl, 9); 1364 v4l2_ctrl_handler_init(&dev->hdl, 9);
1463 if (sd) 1365 if (subdev)
1464 v4l2_ctrl_add_handler(&s->hdl, sd->ctrl_handler, NULL); 1366 v4l2_ctrl_add_handler(&dev->hdl, subdev->ctrl_handler, NULL);
1465 break; 1367 break;
1466 case RTL2832_TUNER_R820T: 1368 case RTL2832_SDR_TUNER_R820T:
1467 v4l2_ctrl_handler_init(&s->hdl, 2); 1369 case RTL2832_SDR_TUNER_R828D:
1468 s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, ops, 1370 v4l2_ctrl_handler_init(&dev->hdl, 2);
1469 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 1371 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, ops,
1470 0, 1, 1, 1); 1372 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
1471 s->bandwidth = v4l2_ctrl_new_std(&s->hdl, ops, 1373 0, 1, 1, 1);
1472 V4L2_CID_RF_TUNER_BANDWIDTH, 1374 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, ops,
1473 0, 8000000, 100000, 0); 1375 V4L2_CID_RF_TUNER_BANDWIDTH,
1474 v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); 1376 0, 8000000, 100000, 0);
1377 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
1475 break; 1378 break;
1476 case RTL2832_TUNER_FC0012: 1379 case RTL2832_SDR_TUNER_FC0012:
1477 case RTL2832_TUNER_FC0013: 1380 case RTL2832_SDR_TUNER_FC0013:
1478 v4l2_ctrl_handler_init(&s->hdl, 2); 1381 v4l2_ctrl_handler_init(&dev->hdl, 2);
1479 s->bandwidth_auto = v4l2_ctrl_new_std(&s->hdl, ops, 1382 dev->bandwidth_auto = v4l2_ctrl_new_std(&dev->hdl, ops,
1480 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO, 1383 V4L2_CID_RF_TUNER_BANDWIDTH_AUTO,
1481 0, 1, 1, 1); 1384 0, 1, 1, 1);
1482 s->bandwidth = v4l2_ctrl_new_std(&s->hdl, ops, 1385 dev->bandwidth = v4l2_ctrl_new_std(&dev->hdl, ops,
1483 V4L2_CID_RF_TUNER_BANDWIDTH, 1386 V4L2_CID_RF_TUNER_BANDWIDTH,
1484 6000000, 8000000, 1000000, 1387 6000000, 8000000, 1000000,
1485 6000000); 1388 6000000);
1486 v4l2_ctrl_auto_cluster(2, &s->bandwidth_auto, 0, false); 1389 v4l2_ctrl_auto_cluster(2, &dev->bandwidth_auto, 0, false);
1487 break; 1390 break;
1488 default: 1391 default:
1489 v4l2_ctrl_handler_init(&s->hdl, 0); 1392 v4l2_ctrl_handler_init(&dev->hdl, 0);
1490 dev_notice(&s->udev->dev, "%s: Unsupported tuner\n", 1393 dev_err(&pdev->dev, "Unsupported tuner\n");
1491 KBUILD_MODNAME); 1394 goto err_v4l2_ctrl_handler_free;
1492 goto err_free_controls;
1493 } 1395 }
1494 1396 if (dev->hdl.error) {
1495 if (s->hdl.error) { 1397 ret = dev->hdl.error;
1496 ret = s->hdl.error; 1398 dev_err(&pdev->dev, "Could not initialize controls\n");
1497 dev_err(&s->udev->dev, "Could not initialize controls\n"); 1399 goto err_v4l2_ctrl_handler_free;
1498 goto err_free_controls;
1499 } 1400 }
1500 1401
1501 /* Init video_device structure */ 1402 /* Init video_device structure */
1502 s->vdev = rtl2832_sdr_template; 1403 dev->vdev = rtl2832_sdr_template;
1503 s->vdev.queue = &s->vb_queue; 1404 dev->vdev.queue = &dev->vb_queue;
1504 s->vdev.queue->lock = &s->vb_queue_lock; 1405 dev->vdev.queue->lock = &dev->vb_queue_lock;
1505 video_set_drvdata(&s->vdev, s); 1406 video_set_drvdata(&dev->vdev, dev);
1506 1407
1507 /* Register the v4l2_device structure */ 1408 /* Register the v4l2_device structure */
1508 s->v4l2_dev.release = rtl2832_sdr_video_release; 1409 dev->v4l2_dev.release = rtl2832_sdr_video_release;
1509 ret = v4l2_device_register(&s->udev->dev, &s->v4l2_dev); 1410 ret = v4l2_device_register(&pdev->dev, &dev->v4l2_dev);
1510 if (ret) { 1411 if (ret) {
1511 dev_err(&s->udev->dev, 1412 dev_err(&pdev->dev, "Failed to register v4l2-device %d\n", ret);
1512 "Failed to register v4l2-device (%d)\n", ret); 1413 goto err_v4l2_ctrl_handler_free;
1513 goto err_free_controls;
1514 } 1414 }
1515 1415
1516 s->v4l2_dev.ctrl_handler = &s->hdl; 1416 dev->v4l2_dev.ctrl_handler = &dev->hdl;
1517 s->vdev.v4l2_dev = &s->v4l2_dev; 1417 dev->vdev.v4l2_dev = &dev->v4l2_dev;
1518 s->vdev.lock = &s->v4l2_lock; 1418 dev->vdev.lock = &dev->v4l2_lock;
1519 s->vdev.vfl_dir = VFL_DIR_RX; 1419 dev->vdev.vfl_dir = VFL_DIR_RX;
1520 1420
1521 ret = video_register_device(&s->vdev, VFL_TYPE_SDR, -1); 1421 ret = video_register_device(&dev->vdev, VFL_TYPE_SDR, -1);
1522 if (ret) { 1422 if (ret) {
1523 dev_err(&s->udev->dev, 1423 dev_err(&pdev->dev, "Failed to register as video device %d\n",
1524 "Failed to register as video device (%d)\n", 1424 ret);
1525 ret); 1425 goto err_v4l2_device_unregister;
1526 goto err_unregister_v4l2_dev;
1527 } 1426 }
1528 dev_info(&s->udev->dev, "Registered as %s\n", 1427 dev_info(&pdev->dev, "Registered as %s\n",
1529 video_device_node_name(&s->vdev)); 1428 video_device_node_name(&dev->vdev));
1530 1429 dev_info(&pdev->dev, "Realtek RTL2832 SDR attached\n");
1531 fe->sec_priv = s; 1430 dev_notice(&pdev->dev,
1532 fe->ops.release_sec = rtl2832_sdr_release_sec; 1431 "SDR API is still slightly experimental and functionality changes may follow\n");
1533 1432 platform_set_drvdata(pdev, dev);
1534 dev_info(&s->i2c->dev, "%s: Realtek RTL2832 SDR attached\n", 1433 return 0;
1535 KBUILD_MODNAME); 1434err_v4l2_device_unregister:
1536 dev_notice(&s->udev->dev, 1435 v4l2_device_unregister(&dev->v4l2_dev);
1537 "%s: SDR API is still slightly experimental and functionality changes may follow\n", 1436err_v4l2_ctrl_handler_free:
1538 KBUILD_MODNAME); 1437 v4l2_ctrl_handler_free(&dev->hdl);
1539 return fe; 1438err_kfree:
1540 1439 kfree(dev);
1541err_unregister_v4l2_dev: 1440err_module_put:
1542 v4l2_device_unregister(&s->v4l2_dev); 1441 module_put(pdev->dev.parent->driver->owner);
1543err_free_controls: 1442err:
1544 v4l2_ctrl_handler_free(&s->hdl); 1443 return ret;
1545err_free_mem:
1546 kfree(s);
1547 return NULL;
1548} 1444}
1549EXPORT_SYMBOL(rtl2832_sdr_attach); 1445
1446static int rtl2832_sdr_remove(struct platform_device *pdev)
1447{
1448 struct rtl2832_sdr_dev *dev = platform_get_drvdata(pdev);
1449
1450 dev_dbg(&pdev->dev, "\n");
1451
1452 mutex_lock(&dev->vb_queue_lock);
1453 mutex_lock(&dev->v4l2_lock);
1454 /* No need to keep the urbs around after disconnection */
1455 dev->udev = NULL;
1456 v4l2_device_disconnect(&dev->v4l2_dev);
1457 video_unregister_device(&dev->vdev);
1458 mutex_unlock(&dev->v4l2_lock);
1459 mutex_unlock(&dev->vb_queue_lock);
1460 v4l2_device_put(&dev->v4l2_dev);
1461 module_put(pdev->dev.parent->driver->owner);
1462
1463 return 0;
1464}
1465
1466static struct platform_driver rtl2832_sdr_driver = {
1467 .driver = {
1468 .name = "rtl2832_sdr",
1469 .owner = THIS_MODULE,
1470 },
1471 .probe = rtl2832_sdr_probe,
1472 .remove = rtl2832_sdr_remove,
1473};
1474module_platform_driver(rtl2832_sdr_driver);
1550 1475
1551MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>"); 1476MODULE_AUTHOR("Antti Palosaari <crope@iki.fi>");
1552MODULE_DESCRIPTION("Realtek RTL2832 SDR driver"); 1477MODULE_DESCRIPTION("Realtek RTL2832 SDR driver");
diff --git a/drivers/media/dvb-frontends/rtl2832_sdr.h b/drivers/media/dvb-frontends/rtl2832_sdr.h
index b865fadf184f..d2594768bff2 100644
--- a/drivers/media/dvb-frontends/rtl2832_sdr.h
+++ b/drivers/media/dvb-frontends/rtl2832_sdr.h
@@ -20,35 +20,48 @@
20 * GNU Radio plugin "gr-kernel" for device usage will be on: 20 * GNU Radio plugin "gr-kernel" for device usage will be on:
21 * http://git.linuxtv.org/anttip/gr-kernel.git 21 * http://git.linuxtv.org/anttip/gr-kernel.git
22 * 22 *
23 * TODO:
24 * Help is very highly welcome for these + all the others you could imagine:
25 * - move controls to V4L2 API
26 * - use libv4l2 for stream format conversions
27 * - gr-kernel: switch to v4l2_mmap (current read eats a lot of cpu)
28 * - SDRSharp support
29 */ 23 */
30 24
31#ifndef RTL2832_SDR_H 25#ifndef RTL2832_SDR_H
32#define RTL2832_SDR_H 26#define RTL2832_SDR_H
33 27
34#include <linux/kconfig.h> 28#include <linux/i2c.h>
35#include <media/v4l2-subdev.h> 29#include <media/v4l2-subdev.h>
30#include "dvb_frontend.h"
36 31
37/* for config struct */ 32/**
38#include "rtl2832.h" 33 * struct rtl2832_sdr_platform_data - Platform data for the rtl2832_sdr driver
34 * @clk: Clock frequency (4000000, 16000000, 25000000, 28800000).
35 * @tuner: Used tuner model.
36 * @i2c_client: rtl2832 demod driver I2C client.
37 * @bulk_read: rtl2832 driver private I/O interface.
38 * @bulk_write: rtl2832 driver private I/O interface.
39 * @update_bits: rtl2832 driver private I/O interface.
40 * @dvb_frontend: rtl2832 DVB frontend.
41 * @v4l2_subdev: Tuner v4l2 controls.
42 * @dvb_usb_device: DVB USB interface for USB streaming.
43 */
44
45struct rtl2832_sdr_platform_data {
46 u32 clk;
47 /*
48 * XXX: This list must be kept sync with dvb_usb_rtl28xxu USB IF driver.
49 */
50#define RTL2832_SDR_TUNER_TUA9001 0x24
51#define RTL2832_SDR_TUNER_FC0012 0x26
52#define RTL2832_SDR_TUNER_E4000 0x27
53#define RTL2832_SDR_TUNER_FC0013 0x29
54#define RTL2832_SDR_TUNER_R820T 0x2a
55#define RTL2832_SDR_TUNER_R828D 0x2b
56 u8 tuner;
39 57
40#if IS_ENABLED(CONFIG_DVB_RTL2832_SDR) 58 struct i2c_client *i2c_client;
41extern struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe, 59 int (*bulk_read)(struct i2c_client *, unsigned int, void *, size_t);
42 struct i2c_adapter *i2c, const struct rtl2832_config *cfg, 60 int (*bulk_write)(struct i2c_client *, unsigned int, const void *, size_t);
43 struct v4l2_subdev *sd); 61 int (*update_bits)(struct i2c_client *, unsigned int, unsigned int, unsigned int);
44#else 62 struct dvb_frontend *dvb_frontend;
45static inline struct dvb_frontend *rtl2832_sdr_attach(struct dvb_frontend *fe, 63 struct v4l2_subdev *v4l2_subdev;
46 struct i2c_adapter *i2c, const struct rtl2832_config *cfg, 64 struct dvb_usb_device *dvb_usb_device;
47 struct v4l2_subdev *sd) 65};
48{
49 dev_warn(&i2c->dev, "%s: driver disabled by Kconfig\n", __func__);
50 return NULL;
51}
52#endif
53 66
54#endif /* RTL2832_SDR_H */ 67#endif /* RTL2832_SDR_H */
diff --git a/drivers/media/dvb-frontends/s5h1409.c b/drivers/media/dvb-frontends/s5h1409.c
index f71b06221e14..5ff474a7ff29 100644
--- a/drivers/media/dvb-frontends/s5h1409.c
+++ b/drivers/media/dvb-frontends/s5h1409.c
@@ -1021,9 +1021,3 @@ static struct dvb_frontend_ops s5h1409_ops = {
1021MODULE_DESCRIPTION("Samsung S5H1409 QAM-B/ATSC Demodulator driver"); 1021MODULE_DESCRIPTION("Samsung S5H1409 QAM-B/ATSC Demodulator driver");
1022MODULE_AUTHOR("Steven Toth"); 1022MODULE_AUTHOR("Steven Toth");
1023MODULE_LICENSE("GPL"); 1023MODULE_LICENSE("GPL");
1024
1025
1026/*
1027 * Local variables:
1028 * c-basic-offset: 8
1029 */
diff --git a/drivers/media/dvb-frontends/s5h1409.h b/drivers/media/dvb-frontends/s5h1409.h
index 63b1e0a34e4e..9e143f5c8107 100644
--- a/drivers/media/dvb-frontends/s5h1409.h
+++ b/drivers/media/dvb-frontends/s5h1409.h
@@ -81,8 +81,3 @@ static inline struct dvb_frontend *s5h1409_attach(
81#endif /* CONFIG_DVB_S5H1409 */ 81#endif /* CONFIG_DVB_S5H1409 */
82 82
83#endif /* __S5H1409_H__ */ 83#endif /* __S5H1409_H__ */
84
85/*
86 * Local variables:
87 * c-basic-offset: 8
88 */
diff --git a/drivers/media/dvb-frontends/s5h1411.c b/drivers/media/dvb-frontends/s5h1411.c
index 6cc4b7a9dd60..64f35fed7ae1 100644
--- a/drivers/media/dvb-frontends/s5h1411.c
+++ b/drivers/media/dvb-frontends/s5h1411.c
@@ -944,8 +944,3 @@ MODULE_PARM_DESC(debug, "Enable verbose debug messages");
944MODULE_DESCRIPTION("Samsung S5H1411 QAM-B/ATSC Demodulator driver"); 944MODULE_DESCRIPTION("Samsung S5H1411 QAM-B/ATSC Demodulator driver");
945MODULE_AUTHOR("Steven Toth"); 945MODULE_AUTHOR("Steven Toth");
946MODULE_LICENSE("GPL"); 946MODULE_LICENSE("GPL");
947
948/*
949 * Local variables:
950 * c-basic-offset: 8
951 */
diff --git a/drivers/media/dvb-frontends/s5h1411.h b/drivers/media/dvb-frontends/s5h1411.h
index e4f56871f982..1d7deb615674 100644
--- a/drivers/media/dvb-frontends/s5h1411.h
+++ b/drivers/media/dvb-frontends/s5h1411.h
@@ -83,8 +83,3 @@ static inline struct dvb_frontend *s5h1411_attach(
83#endif /* CONFIG_DVB_S5H1411 */ 83#endif /* CONFIG_DVB_S5H1411 */
84 84
85#endif /* __S5H1411_H__ */ 85#endif /* __S5H1411_H__ */
86
87/*
88 * Local variables:
89 * c-basic-offset: 8
90 */
diff --git a/drivers/media/dvb-frontends/si2168.c b/drivers/media/dvb-frontends/si2168.c
index ce9ab442b4b6..5db588ebfc24 100644
--- a/drivers/media/dvb-frontends/si2168.c
+++ b/drivers/media/dvb-frontends/si2168.c
@@ -19,16 +19,17 @@
19static const struct dvb_frontend_ops si2168_ops; 19static const struct dvb_frontend_ops si2168_ops;
20 20
21/* execute firmware command */ 21/* execute firmware command */
22static int si2168_cmd_execute(struct si2168 *s, struct si2168_cmd *cmd) 22static int si2168_cmd_execute(struct i2c_client *client, struct si2168_cmd *cmd)
23{ 23{
24 struct si2168_dev *dev = i2c_get_clientdata(client);
24 int ret; 25 int ret;
25 unsigned long timeout; 26 unsigned long timeout;
26 27
27 mutex_lock(&s->i2c_mutex); 28 mutex_lock(&dev->i2c_mutex);
28 29
29 if (cmd->wlen) { 30 if (cmd->wlen) {
30 /* write cmd and args for firmware */ 31 /* write cmd and args for firmware */
31 ret = i2c_master_send(s->client, cmd->args, cmd->wlen); 32 ret = i2c_master_send(client, cmd->args, cmd->wlen);
32 if (ret < 0) { 33 if (ret < 0) {
33 goto err_mutex_unlock; 34 goto err_mutex_unlock;
34 } else if (ret != cmd->wlen) { 35 } else if (ret != cmd->wlen) {
@@ -39,10 +40,10 @@ static int si2168_cmd_execute(struct si2168 *s, struct si2168_cmd *cmd)
39 40
40 if (cmd->rlen) { 41 if (cmd->rlen) {
41 /* wait cmd execution terminate */ 42 /* wait cmd execution terminate */
42 #define TIMEOUT 50 43 #define TIMEOUT 70
43 timeout = jiffies + msecs_to_jiffies(TIMEOUT); 44 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
44 while (!time_after(jiffies, timeout)) { 45 while (!time_after(jiffies, timeout)) {
45 ret = i2c_master_recv(s->client, cmd->args, cmd->rlen); 46 ret = i2c_master_recv(client, cmd->args, cmd->rlen);
46 if (ret < 0) { 47 if (ret < 0) {
47 goto err_mutex_unlock; 48 goto err_mutex_unlock;
48 } else if (ret != cmd->rlen) { 49 } else if (ret != cmd->rlen) {
@@ -55,7 +56,7 @@ static int si2168_cmd_execute(struct si2168 *s, struct si2168_cmd *cmd)
55 break; 56 break;
56 } 57 }
57 58
58 dev_dbg(&s->client->dev, "cmd execution took %d ms\n", 59 dev_dbg(&client->dev, "cmd execution took %d ms\n",
59 jiffies_to_msecs(jiffies) - 60 jiffies_to_msecs(jiffies) -
60 (jiffies_to_msecs(timeout) - TIMEOUT)); 61 (jiffies_to_msecs(timeout) - TIMEOUT));
61 62
@@ -65,29 +66,26 @@ static int si2168_cmd_execute(struct si2168 *s, struct si2168_cmd *cmd)
65 } 66 }
66 } 67 }
67 68
68 ret = 0; 69 mutex_unlock(&dev->i2c_mutex);
70 return 0;
69 71
70err_mutex_unlock: 72err_mutex_unlock:
71 mutex_unlock(&s->i2c_mutex); 73 mutex_unlock(&dev->i2c_mutex);
72 if (ret) 74 dev_dbg(&client->dev, "failed=%d\n", ret);
73 goto err;
74
75 return 0;
76err:
77 dev_dbg(&s->client->dev, "failed=%d\n", ret);
78 return ret; 75 return ret;
79} 76}
80 77
81static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status) 78static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status)
82{ 79{
83 struct si2168 *s = fe->demodulator_priv; 80 struct i2c_client *client = fe->demodulator_priv;
81 struct si2168_dev *dev = i2c_get_clientdata(client);
84 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 82 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
85 int ret; 83 int ret;
86 struct si2168_cmd cmd; 84 struct si2168_cmd cmd;
87 85
88 *status = 0; 86 *status = 0;
89 87
90 if (!s->active) { 88 if (!dev->active) {
91 ret = -EAGAIN; 89 ret = -EAGAIN;
92 goto err; 90 goto err;
93 } 91 }
@@ -113,21 +111,10 @@ static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status)
113 goto err; 111 goto err;
114 } 112 }
115 113
116 ret = si2168_cmd_execute(s, &cmd); 114 ret = si2168_cmd_execute(client, &cmd);
117 if (ret) 115 if (ret)
118 goto err; 116 goto err;
119 117
120 /*
121 * Possible values seen, in order from strong signal to weak:
122 * 16 0001 0110 full lock
123 * 1e 0001 1110 partial lock
124 * 1a 0001 1010 partial lock
125 * 18 0001 1000 no lock
126 *
127 * [b3:b1] lock bits
128 * [b4] statistics ready? Set in a few secs after lock is gained.
129 */
130
131 switch ((cmd.args[2] >> 1) & 0x03) { 118 switch ((cmd.args[2] >> 1) & 0x03) {
132 case 0x01: 119 case 0x01:
133 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER; 120 *status = FE_HAS_SIGNAL | FE_HAS_CARRIER;
@@ -138,7 +125,7 @@ static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status)
138 break; 125 break;
139 } 126 }
140 127
141 s->fe_status = *status; 128 dev->fe_status = *status;
142 129
143 if (*status & FE_HAS_LOCK) { 130 if (*status & FE_HAS_LOCK) {
144 c->cnr.len = 1; 131 c->cnr.len = 1;
@@ -149,30 +136,31 @@ static int si2168_read_status(struct dvb_frontend *fe, fe_status_t *status)
149 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE; 136 c->cnr.stat[0].scale = FE_SCALE_NOT_AVAILABLE;
150 } 137 }
151 138
152 dev_dbg(&s->client->dev, "status=%02x args=%*ph\n", 139 dev_dbg(&client->dev, "status=%02x args=%*ph\n",
153 *status, cmd.rlen, cmd.args); 140 *status, cmd.rlen, cmd.args);
154 141
155 return 0; 142 return 0;
156err: 143err:
157 dev_dbg(&s->client->dev, "failed=%d\n", ret); 144 dev_dbg(&client->dev, "failed=%d\n", ret);
158 return ret; 145 return ret;
159} 146}
160 147
161static int si2168_set_frontend(struct dvb_frontend *fe) 148static int si2168_set_frontend(struct dvb_frontend *fe)
162{ 149{
163 struct si2168 *s = fe->demodulator_priv; 150 struct i2c_client *client = fe->demodulator_priv;
151 struct si2168_dev *dev = i2c_get_clientdata(client);
164 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 152 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
165 int ret; 153 int ret;
166 struct si2168_cmd cmd; 154 struct si2168_cmd cmd;
167 u8 bandwidth, delivery_system; 155 u8 bandwidth, delivery_system;
168 156
169 dev_dbg(&s->client->dev, 157 dev_dbg(&client->dev,
170 "delivery_system=%u modulation=%u frequency=%u bandwidth_hz=%u symbol_rate=%u inversion=%u, stream_id=%d\n", 158 "delivery_system=%u modulation=%u frequency=%u bandwidth_hz=%u symbol_rate=%u inversion=%u stream_id=%u\n",
171 c->delivery_system, c->modulation, 159 c->delivery_system, c->modulation, c->frequency,
172 c->frequency, c->bandwidth_hz, c->symbol_rate, 160 c->bandwidth_hz, c->symbol_rate, c->inversion,
173 c->inversion, c->stream_id); 161 c->stream_id);
174 162
175 if (!s->active) { 163 if (!dev->active) {
176 ret = -EAGAIN; 164 ret = -EAGAIN;
177 goto err; 165 goto err;
178 } 166 }
@@ -192,7 +180,12 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
192 goto err; 180 goto err;
193 } 181 }
194 182
195 if (c->bandwidth_hz <= 5000000) 183 if (c->bandwidth_hz == 0) {
184 ret = -EINVAL;
185 goto err;
186 } else if (c->bandwidth_hz <= 2000000)
187 bandwidth = 0x02;
188 else if (c->bandwidth_hz <= 5000000)
196 bandwidth = 0x05; 189 bandwidth = 0x05;
197 else if (c->bandwidth_hz <= 6000000) 190 else if (c->bandwidth_hz <= 6000000)
198 bandwidth = 0x06; 191 bandwidth = 0x06;
@@ -217,7 +210,7 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
217 memcpy(cmd.args, "\x88\x02\x02\x02\x02", 5); 210 memcpy(cmd.args, "\x88\x02\x02\x02\x02", 5);
218 cmd.wlen = 5; 211 cmd.wlen = 5;
219 cmd.rlen = 5; 212 cmd.rlen = 5;
220 ret = si2168_cmd_execute(s, &cmd); 213 ret = si2168_cmd_execute(client, &cmd);
221 if (ret) 214 if (ret)
222 goto err; 215 goto err;
223 216
@@ -230,7 +223,7 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
230 memcpy(cmd.args, "\x89\x21\x06\x11\x89\x20", 6); 223 memcpy(cmd.args, "\x89\x21\x06\x11\x89\x20", 6);
231 cmd.wlen = 6; 224 cmd.wlen = 6;
232 cmd.rlen = 3; 225 cmd.rlen = 3;
233 ret = si2168_cmd_execute(s, &cmd); 226 ret = si2168_cmd_execute(client, &cmd);
234 if (ret) 227 if (ret)
235 goto err; 228 goto err;
236 229
@@ -241,7 +234,7 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
241 cmd.args[2] = c->stream_id == NO_STREAM_ID_FILTER ? 0 : 1; 234 cmd.args[2] = c->stream_id == NO_STREAM_ID_FILTER ? 0 : 1;
242 cmd.wlen = 3; 235 cmd.wlen = 3;
243 cmd.rlen = 1; 236 cmd.rlen = 1;
244 ret = si2168_cmd_execute(s, &cmd); 237 ret = si2168_cmd_execute(client, &cmd);
245 if (ret) 238 if (ret)
246 goto err; 239 goto err;
247 } 240 }
@@ -249,35 +242,35 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
249 memcpy(cmd.args, "\x51\x03", 2); 242 memcpy(cmd.args, "\x51\x03", 2);
250 cmd.wlen = 2; 243 cmd.wlen = 2;
251 cmd.rlen = 12; 244 cmd.rlen = 12;
252 ret = si2168_cmd_execute(s, &cmd); 245 ret = si2168_cmd_execute(client, &cmd);
253 if (ret) 246 if (ret)
254 goto err; 247 goto err;
255 248
256 memcpy(cmd.args, "\x12\x08\x04", 3); 249 memcpy(cmd.args, "\x12\x08\x04", 3);
257 cmd.wlen = 3; 250 cmd.wlen = 3;
258 cmd.rlen = 3; 251 cmd.rlen = 3;
259 ret = si2168_cmd_execute(s, &cmd); 252 ret = si2168_cmd_execute(client, &cmd);
260 if (ret) 253 if (ret)
261 goto err; 254 goto err;
262 255
263 memcpy(cmd.args, "\x14\x00\x0c\x10\x12\x00", 6); 256 memcpy(cmd.args, "\x14\x00\x0c\x10\x12\x00", 6);
264 cmd.wlen = 6; 257 cmd.wlen = 6;
265 cmd.rlen = 4; 258 cmd.rlen = 4;
266 ret = si2168_cmd_execute(s, &cmd); 259 ret = si2168_cmd_execute(client, &cmd);
267 if (ret) 260 if (ret)
268 goto err; 261 goto err;
269 262
270 memcpy(cmd.args, "\x14\x00\x06\x10\x24\x00", 6); 263 memcpy(cmd.args, "\x14\x00\x06\x10\x24\x00", 6);
271 cmd.wlen = 6; 264 cmd.wlen = 6;
272 cmd.rlen = 4; 265 cmd.rlen = 4;
273 ret = si2168_cmd_execute(s, &cmd); 266 ret = si2168_cmd_execute(client, &cmd);
274 if (ret) 267 if (ret)
275 goto err; 268 goto err;
276 269
277 memcpy(cmd.args, "\x14\x00\x07\x10\x00\x24", 6); 270 memcpy(cmd.args, "\x14\x00\x07\x10\x00\x24", 6);
278 cmd.wlen = 6; 271 cmd.wlen = 6;
279 cmd.rlen = 4; 272 cmd.rlen = 4;
280 ret = si2168_cmd_execute(s, &cmd); 273 ret = si2168_cmd_execute(client, &cmd);
281 if (ret) 274 if (ret)
282 goto err; 275 goto err;
283 276
@@ -285,18 +278,18 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
285 cmd.args[4] = delivery_system | bandwidth; 278 cmd.args[4] = delivery_system | bandwidth;
286 cmd.wlen = 6; 279 cmd.wlen = 6;
287 cmd.rlen = 4; 280 cmd.rlen = 4;
288 ret = si2168_cmd_execute(s, &cmd); 281 ret = si2168_cmd_execute(client, &cmd);
289 if (ret) 282 if (ret)
290 goto err; 283 goto err;
291 284
292 /* set DVB-C symbol rate */ 285 /* set DVB-C symbol rate */
293 if (c->delivery_system == SYS_DVBC_ANNEX_A) { 286 if (c->delivery_system == SYS_DVBC_ANNEX_A) {
294 memcpy(cmd.args, "\x14\x00\x02\x11", 4); 287 memcpy(cmd.args, "\x14\x00\x02\x11", 4);
295 cmd.args[4] = (c->symbol_rate / 1000) & 0xff; 288 cmd.args[4] = ((c->symbol_rate / 1000) >> 0) & 0xff;
296 cmd.args[5] = ((c->symbol_rate / 1000) >> 8) & 0xff; 289 cmd.args[5] = ((c->symbol_rate / 1000) >> 8) & 0xff;
297 cmd.wlen = 6; 290 cmd.wlen = 6;
298 cmd.rlen = 4; 291 cmd.rlen = 4;
299 ret = si2168_cmd_execute(s, &cmd); 292 ret = si2168_cmd_execute(client, &cmd);
300 if (ret) 293 if (ret)
301 goto err; 294 goto err;
302 } 295 }
@@ -304,88 +297,88 @@ static int si2168_set_frontend(struct dvb_frontend *fe)
304 memcpy(cmd.args, "\x14\x00\x0f\x10\x10\x00", 6); 297 memcpy(cmd.args, "\x14\x00\x0f\x10\x10\x00", 6);
305 cmd.wlen = 6; 298 cmd.wlen = 6;
306 cmd.rlen = 4; 299 cmd.rlen = 4;
307 ret = si2168_cmd_execute(s, &cmd); 300 ret = si2168_cmd_execute(client, &cmd);
308 if (ret) 301 if (ret)
309 goto err; 302 goto err;
310 303
311 memcpy(cmd.args, "\x14\x00\x09\x10\xe3\x08", 6); 304 memcpy(cmd.args, "\x14\x00\x09\x10\xe3\x08", 6);
312 cmd.args[5] |= s->ts_clock_inv ? 0x00 : 0x10; 305 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
313 cmd.wlen = 6; 306 cmd.wlen = 6;
314 cmd.rlen = 4; 307 cmd.rlen = 4;
315 ret = si2168_cmd_execute(s, &cmd); 308 ret = si2168_cmd_execute(client, &cmd);
316 if (ret) 309 if (ret)
317 goto err; 310 goto err;
318 311
319 memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6); 312 memcpy(cmd.args, "\x14\x00\x08\x10\xd7\x05", 6);
320 cmd.args[5] |= s->ts_clock_inv ? 0x00 : 0x10; 313 cmd.args[5] |= dev->ts_clock_inv ? 0x00 : 0x10;
321 cmd.wlen = 6; 314 cmd.wlen = 6;
322 cmd.rlen = 4; 315 cmd.rlen = 4;
323 ret = si2168_cmd_execute(s, &cmd); 316 ret = si2168_cmd_execute(client, &cmd);
324 if (ret) 317 if (ret)
325 goto err; 318 goto err;
326 319
327 memcpy(cmd.args, "\x14\x00\x01\x12\x00\x00", 6); 320 memcpy(cmd.args, "\x14\x00\x01\x12\x00\x00", 6);
328 cmd.wlen = 6; 321 cmd.wlen = 6;
329 cmd.rlen = 4; 322 cmd.rlen = 4;
330 ret = si2168_cmd_execute(s, &cmd); 323 ret = si2168_cmd_execute(client, &cmd);
331 if (ret) 324 if (ret)
332 goto err; 325 goto err;
333 326
334 memcpy(cmd.args, "\x14\x00\x01\x03\x0c\x00", 6); 327 memcpy(cmd.args, "\x14\x00\x01\x03\x0c\x00", 6);
335 cmd.wlen = 6; 328 cmd.wlen = 6;
336 cmd.rlen = 4; 329 cmd.rlen = 4;
337 ret = si2168_cmd_execute(s, &cmd); 330 ret = si2168_cmd_execute(client, &cmd);
338 if (ret) 331 if (ret)
339 goto err; 332 goto err;
340 333
341 memcpy(cmd.args, "\x85", 1); 334 memcpy(cmd.args, "\x85", 1);
342 cmd.wlen = 1; 335 cmd.wlen = 1;
343 cmd.rlen = 1; 336 cmd.rlen = 1;
344 ret = si2168_cmd_execute(s, &cmd); 337 ret = si2168_cmd_execute(client, &cmd);
345 if (ret) 338 if (ret)
346 goto err; 339 goto err;
347 340
348 s->delivery_system = c->delivery_system; 341 dev->delivery_system = c->delivery_system;
349 342
350 return 0; 343 return 0;
351err: 344err:
352 dev_dbg(&s->client->dev, "failed=%d\n", ret); 345 dev_dbg(&client->dev, "failed=%d\n", ret);
353 return ret; 346 return ret;
354} 347}
355 348
356static int si2168_init(struct dvb_frontend *fe) 349static int si2168_init(struct dvb_frontend *fe)
357{ 350{
358 struct si2168 *s = fe->demodulator_priv; 351 struct i2c_client *client = fe->demodulator_priv;
352 struct si2168_dev *dev = i2c_get_clientdata(client);
359 int ret, len, remaining; 353 int ret, len, remaining;
360 const struct firmware *fw = NULL; 354 const struct firmware *fw;
361 u8 *fw_file; 355 const char *fw_name;
362 const unsigned int i2c_wr_max = 8;
363 struct si2168_cmd cmd; 356 struct si2168_cmd cmd;
364 unsigned int chip_id; 357 unsigned int chip_id;
365 358
366 dev_dbg(&s->client->dev, "\n"); 359 dev_dbg(&client->dev, "\n");
367 360
368 /* initialize */ 361 /* initialize */
369 memcpy(cmd.args, "\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00", 13); 362 memcpy(cmd.args, "\xc0\x12\x00\x0c\x00\x0d\x16\x00\x00\x00\x00\x00\x00", 13);
370 cmd.wlen = 13; 363 cmd.wlen = 13;
371 cmd.rlen = 0; 364 cmd.rlen = 0;
372 ret = si2168_cmd_execute(s, &cmd); 365 ret = si2168_cmd_execute(client, &cmd);
373 if (ret) 366 if (ret)
374 goto err; 367 goto err;
375 368
376 if (s->fw_loaded) { 369 if (dev->fw_loaded) {
377 /* resume */ 370 /* resume */
378 memcpy(cmd.args, "\xc0\x06\x08\x0f\x00\x20\x21\x01", 8); 371 memcpy(cmd.args, "\xc0\x06\x08\x0f\x00\x20\x21\x01", 8);
379 cmd.wlen = 8; 372 cmd.wlen = 8;
380 cmd.rlen = 1; 373 cmd.rlen = 1;
381 ret = si2168_cmd_execute(s, &cmd); 374 ret = si2168_cmd_execute(client, &cmd);
382 if (ret) 375 if (ret)
383 goto err; 376 goto err;
384 377
385 memcpy(cmd.args, "\x85", 1); 378 memcpy(cmd.args, "\x85", 1);
386 cmd.wlen = 1; 379 cmd.wlen = 1;
387 cmd.rlen = 1; 380 cmd.rlen = 1;
388 ret = si2168_cmd_execute(s, &cmd); 381 ret = si2168_cmd_execute(client, &cmd);
389 if (ret) 382 if (ret)
390 goto err; 383 goto err;
391 384
@@ -396,7 +389,7 @@ static int si2168_init(struct dvb_frontend *fe)
396 memcpy(cmd.args, "\xc0\x06\x01\x0f\x00\x20\x20\x01", 8); 389 memcpy(cmd.args, "\xc0\x06\x01\x0f\x00\x20\x20\x01", 8);
397 cmd.wlen = 8; 390 cmd.wlen = 8;
398 cmd.rlen = 1; 391 cmd.rlen = 1;
399 ret = si2168_cmd_execute(s, &cmd); 392 ret = si2168_cmd_execute(client, &cmd);
400 if (ret) 393 if (ret)
401 goto err; 394 goto err;
402 395
@@ -404,7 +397,7 @@ static int si2168_init(struct dvb_frontend *fe)
404 memcpy(cmd.args, "\x02", 1); 397 memcpy(cmd.args, "\x02", 1);
405 cmd.wlen = 1; 398 cmd.wlen = 1;
406 cmd.rlen = 13; 399 cmd.rlen = 13;
407 ret = si2168_cmd_execute(s, &cmd); 400 ret = si2168_cmd_execute(client, &cmd);
408 if (ret) 401 if (ret)
409 goto err; 402 goto err;
410 403
@@ -417,50 +410,48 @@ static int si2168_init(struct dvb_frontend *fe)
417 410
418 switch (chip_id) { 411 switch (chip_id) {
419 case SI2168_A20: 412 case SI2168_A20:
420 fw_file = SI2168_A20_FIRMWARE; 413 fw_name = SI2168_A20_FIRMWARE;
421 break; 414 break;
422 case SI2168_A30: 415 case SI2168_A30:
423 fw_file = SI2168_A30_FIRMWARE; 416 fw_name = SI2168_A30_FIRMWARE;
424 break; 417 break;
425 case SI2168_B40: 418 case SI2168_B40:
426 fw_file = SI2168_B40_FIRMWARE; 419 fw_name = SI2168_B40_FIRMWARE;
427 break; 420 break;
428 default: 421 default:
429 dev_err(&s->client->dev, 422 dev_err(&client->dev, "unknown chip version Si21%d-%c%c%c\n",
430 "unknown chip version Si21%d-%c%c%c\n",
431 cmd.args[2], cmd.args[1], 423 cmd.args[2], cmd.args[1],
432 cmd.args[3], cmd.args[4]); 424 cmd.args[3], cmd.args[4]);
433 ret = -EINVAL; 425 ret = -EINVAL;
434 goto err; 426 goto err;
435 } 427 }
436 428
437 /* cold state - try to download firmware */ 429 dev_info(&client->dev, "found a 'Silicon Labs Si21%d-%c%c%c'\n",
438 dev_info(&s->client->dev, "found a '%s' in cold state\n", 430 cmd.args[2], cmd.args[1], cmd.args[3], cmd.args[4]);
439 si2168_ops.info.name);
440 431
441 /* request the firmware, this will block and timeout */ 432 /* request the firmware, this will block and timeout */
442 ret = request_firmware(&fw, fw_file, &s->client->dev); 433 ret = request_firmware(&fw, fw_name, &client->dev);
443 if (ret) { 434 if (ret) {
444 /* fallback mechanism to handle old name for Si2168 B40 fw */ 435 /* fallback mechanism to handle old name for Si2168 B40 fw */
445 if (chip_id == SI2168_B40) { 436 if (chip_id == SI2168_B40) {
446 fw_file = SI2168_B40_FIRMWARE_FALLBACK; 437 fw_name = SI2168_B40_FIRMWARE_FALLBACK;
447 ret = request_firmware(&fw, fw_file, &s->client->dev); 438 ret = request_firmware(&fw, fw_name, &client->dev);
448 } 439 }
449 440
450 if (ret == 0) { 441 if (ret == 0) {
451 dev_notice(&s->client->dev, 442 dev_notice(&client->dev,
452 "please install firmware file '%s'\n", 443 "please install firmware file '%s'\n",
453 SI2168_B40_FIRMWARE); 444 SI2168_B40_FIRMWARE);
454 } else { 445 } else {
455 dev_err(&s->client->dev, 446 dev_err(&client->dev,
456 "firmware file '%s' not found\n", 447 "firmware file '%s' not found\n",
457 fw_file); 448 fw_name);
458 goto error_fw_release; 449 goto err_release_firmware;
459 } 450 }
460 } 451 }
461 452
462 dev_info(&s->client->dev, "downloading firmware from file '%s'\n", 453 dev_info(&client->dev, "downloading firmware from file '%s'\n",
463 fw_file); 454 fw_name);
464 455
465 if ((fw->size % 17 == 0) && (fw->data[0] > 5)) { 456 if ((fw->size % 17 == 0) && (fw->data[0] > 5)) {
466 /* firmware is in the new format */ 457 /* firmware is in the new format */
@@ -469,41 +460,37 @@ static int si2168_init(struct dvb_frontend *fe)
469 memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len); 460 memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len);
470 cmd.wlen = len; 461 cmd.wlen = len;
471 cmd.rlen = 1; 462 cmd.rlen = 1;
472 ret = si2168_cmd_execute(s, &cmd); 463 ret = si2168_cmd_execute(client, &cmd);
473 if (ret) { 464 if (ret)
474 dev_err(&s->client->dev, 465 break;
475 "firmware download failed=%d\n",
476 ret);
477 goto error_fw_release;
478 }
479 } 466 }
480 } else { 467 } else if (fw->size % 8 == 0) {
481 /* firmware is in the old format */ 468 /* firmware is in the old format */
482 for (remaining = fw->size; remaining > 0; remaining -= i2c_wr_max) { 469 for (remaining = fw->size; remaining > 0; remaining -= 8) {
483 len = remaining; 470 len = 8;
484 if (len > i2c_wr_max)
485 len = i2c_wr_max;
486
487 memcpy(cmd.args, &fw->data[fw->size - remaining], len); 471 memcpy(cmd.args, &fw->data[fw->size - remaining], len);
488 cmd.wlen = len; 472 cmd.wlen = len;
489 cmd.rlen = 1; 473 cmd.rlen = 1;
490 ret = si2168_cmd_execute(s, &cmd); 474 ret = si2168_cmd_execute(client, &cmd);
491 if (ret) { 475 if (ret)
492 dev_err(&s->client->dev, 476 break;
493 "firmware download failed=%d\n",
494 ret);
495 goto error_fw_release;
496 }
497 } 477 }
478 } else {
479 /* bad or unknown firmware format */
480 ret = -EINVAL;
481 }
482
483 if (ret) {
484 dev_err(&client->dev, "firmware download failed %d\n", ret);
485 goto err_release_firmware;
498 } 486 }
499 487
500 release_firmware(fw); 488 release_firmware(fw);
501 fw = NULL;
502 489
503 memcpy(cmd.args, "\x01\x01", 2); 490 memcpy(cmd.args, "\x01\x01", 2);
504 cmd.wlen = 2; 491 cmd.wlen = 2;
505 cmd.rlen = 1; 492 cmd.rlen = 1;
506 ret = si2168_cmd_execute(s, &cmd); 493 ret = si2168_cmd_execute(client, &cmd);
507 if (ret) 494 if (ret)
508 goto err; 495 goto err;
509 496
@@ -511,58 +498,56 @@ static int si2168_init(struct dvb_frontend *fe)
511 memcpy(cmd.args, "\x11", 1); 498 memcpy(cmd.args, "\x11", 1);
512 cmd.wlen = 1; 499 cmd.wlen = 1;
513 cmd.rlen = 10; 500 cmd.rlen = 10;
514 ret = si2168_cmd_execute(s, &cmd); 501 ret = si2168_cmd_execute(client, &cmd);
515 if (ret) 502 if (ret)
516 goto err; 503 goto err;
517 504
518 dev_dbg(&s->client->dev, "firmware version: %c.%c.%d\n", 505 dev_info(&client->dev, "firmware version: %c.%c.%d\n",
519 cmd.args[6], cmd.args[7], cmd.args[8]); 506 cmd.args[6], cmd.args[7], cmd.args[8]);
520 507
521 /* set ts mode */ 508 /* set ts mode */
522 memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6); 509 memcpy(cmd.args, "\x14\x00\x01\x10\x10\x00", 6);
523 cmd.args[4] |= s->ts_mode; 510 cmd.args[4] |= dev->ts_mode;
524 cmd.wlen = 6; 511 cmd.wlen = 6;
525 cmd.rlen = 4; 512 cmd.rlen = 4;
526 ret = si2168_cmd_execute(s, &cmd); 513 ret = si2168_cmd_execute(client, &cmd);
527 if (ret) 514 if (ret)
528 goto err; 515 goto err;
529 516
530 s->fw_loaded = true; 517 dev->fw_loaded = true;
531
532 dev_info(&s->client->dev, "found a '%s' in warm state\n",
533 si2168_ops.info.name);
534warm: 518warm:
535 s->active = true; 519 dev->active = true;
536 520
537 return 0; 521 return 0;
538 522
539error_fw_release: 523err_release_firmware:
540 release_firmware(fw); 524 release_firmware(fw);
541err: 525err:
542 dev_dbg(&s->client->dev, "failed=%d\n", ret); 526 dev_dbg(&client->dev, "failed=%d\n", ret);
543 return ret; 527 return ret;
544} 528}
545 529
546static int si2168_sleep(struct dvb_frontend *fe) 530static int si2168_sleep(struct dvb_frontend *fe)
547{ 531{
548 struct si2168 *s = fe->demodulator_priv; 532 struct i2c_client *client = fe->demodulator_priv;
533 struct si2168_dev *dev = i2c_get_clientdata(client);
549 int ret; 534 int ret;
550 struct si2168_cmd cmd; 535 struct si2168_cmd cmd;
551 536
552 dev_dbg(&s->client->dev, "\n"); 537 dev_dbg(&client->dev, "\n");
553 538
554 s->active = false; 539 dev->active = false;
555 540
556 memcpy(cmd.args, "\x13", 1); 541 memcpy(cmd.args, "\x13", 1);
557 cmd.wlen = 1; 542 cmd.wlen = 1;
558 cmd.rlen = 0; 543 cmd.rlen = 0;
559 ret = si2168_cmd_execute(s, &cmd); 544 ret = si2168_cmd_execute(client, &cmd);
560 if (ret) 545 if (ret)
561 goto err; 546 goto err;
562 547
563 return 0; 548 return 0;
564err: 549err:
565 dev_dbg(&s->client->dev, "failed=%d\n", ret); 550 dev_dbg(&client->dev, "failed=%d\n", ret);
566 return ret; 551 return ret;
567} 552}
568 553
@@ -581,21 +566,22 @@ static int si2168_get_tune_settings(struct dvb_frontend *fe,
581 */ 566 */
582static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan) 567static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
583{ 568{
584 struct si2168 *s = mux_priv; 569 struct i2c_client *client = mux_priv;
570 struct si2168_dev *dev = i2c_get_clientdata(client);
585 int ret; 571 int ret;
586 struct i2c_msg gate_open_msg = { 572 struct i2c_msg gate_open_msg = {
587 .addr = s->client->addr, 573 .addr = client->addr,
588 .flags = 0, 574 .flags = 0,
589 .len = 3, 575 .len = 3,
590 .buf = "\xc0\x0d\x01", 576 .buf = "\xc0\x0d\x01",
591 }; 577 };
592 578
593 mutex_lock(&s->i2c_mutex); 579 mutex_lock(&dev->i2c_mutex);
594 580
595 /* open tuner I2C gate */ 581 /* open tuner I2C gate */
596 ret = __i2c_transfer(s->client->adapter, &gate_open_msg, 1); 582 ret = __i2c_transfer(client->adapter, &gate_open_msg, 1);
597 if (ret != 1) { 583 if (ret != 1) {
598 dev_warn(&s->client->dev, "i2c write failed=%d\n", ret); 584 dev_warn(&client->dev, "i2c write failed=%d\n", ret);
599 if (ret >= 0) 585 if (ret >= 0)
600 ret = -EREMOTEIO; 586 ret = -EREMOTEIO;
601 } else { 587 } else {
@@ -607,26 +593,27 @@ static int si2168_select(struct i2c_adapter *adap, void *mux_priv, u32 chan)
607 593
608static int si2168_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan) 594static int si2168_deselect(struct i2c_adapter *adap, void *mux_priv, u32 chan)
609{ 595{
610 struct si2168 *s = mux_priv; 596 struct i2c_client *client = mux_priv;
597 struct si2168_dev *dev = i2c_get_clientdata(client);
611 int ret; 598 int ret;
612 struct i2c_msg gate_close_msg = { 599 struct i2c_msg gate_close_msg = {
613 .addr = s->client->addr, 600 .addr = client->addr,
614 .flags = 0, 601 .flags = 0,
615 .len = 3, 602 .len = 3,
616 .buf = "\xc0\x0d\x00", 603 .buf = "\xc0\x0d\x00",
617 }; 604 };
618 605
619 /* close tuner I2C gate */ 606 /* close tuner I2C gate */
620 ret = __i2c_transfer(s->client->adapter, &gate_close_msg, 1); 607 ret = __i2c_transfer(client->adapter, &gate_close_msg, 1);
621 if (ret != 1) { 608 if (ret != 1) {
622 dev_warn(&s->client->dev, "i2c write failed=%d\n", ret); 609 dev_warn(&client->dev, "i2c write failed=%d\n", ret);
623 if (ret >= 0) 610 if (ret >= 0)
624 ret = -EREMOTEIO; 611 ret = -EREMOTEIO;
625 } else { 612 } else {
626 ret = 0; 613 ret = 0;
627 } 614 }
628 615
629 mutex_unlock(&s->i2c_mutex); 616 mutex_unlock(&dev->i2c_mutex);
630 617
631 return ret; 618 return ret;
632} 619}
@@ -635,6 +622,8 @@ static const struct dvb_frontend_ops si2168_ops = {
635 .delsys = {SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A}, 622 .delsys = {SYS_DVBT, SYS_DVBT2, SYS_DVBC_ANNEX_A},
636 .info = { 623 .info = {
637 .name = "Silicon Labs Si2168", 624 .name = "Silicon Labs Si2168",
625 .symbol_rate_min = 1000000,
626 .symbol_rate_max = 7200000,
638 .caps = FE_CAN_FEC_1_2 | 627 .caps = FE_CAN_FEC_1_2 |
639 FE_CAN_FEC_2_3 | 628 FE_CAN_FEC_2_3 |
640 FE_CAN_FEC_3_4 | 629 FE_CAN_FEC_3_4 |
@@ -670,71 +659,69 @@ static int si2168_probe(struct i2c_client *client,
670 const struct i2c_device_id *id) 659 const struct i2c_device_id *id)
671{ 660{
672 struct si2168_config *config = client->dev.platform_data; 661 struct si2168_config *config = client->dev.platform_data;
673 struct si2168 *s; 662 struct si2168_dev *dev;
674 int ret; 663 int ret;
675 664
676 dev_dbg(&client->dev, "\n"); 665 dev_dbg(&client->dev, "\n");
677 666
678 s = kzalloc(sizeof(struct si2168), GFP_KERNEL); 667 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
679 if (!s) { 668 if (!dev) {
680 ret = -ENOMEM; 669 ret = -ENOMEM;
681 dev_err(&client->dev, "kzalloc() failed\n"); 670 dev_err(&client->dev, "kzalloc() failed\n");
682 goto err; 671 goto err;
683 } 672 }
684 673
685 s->client = client; 674 mutex_init(&dev->i2c_mutex);
686 mutex_init(&s->i2c_mutex);
687 675
688 /* create mux i2c adapter for tuner */ 676 /* create mux i2c adapter for tuner */
689 s->adapter = i2c_add_mux_adapter(client->adapter, &client->dev, s, 677 dev->adapter = i2c_add_mux_adapter(client->adapter, &client->dev,
690 0, 0, 0, si2168_select, si2168_deselect); 678 client, 0, 0, 0, si2168_select, si2168_deselect);
691 if (s->adapter == NULL) { 679 if (dev->adapter == NULL) {
692 ret = -ENODEV; 680 ret = -ENODEV;
693 goto err; 681 goto err_kfree;
694 } 682 }
695 683
696 /* create dvb_frontend */ 684 /* create dvb_frontend */
697 memcpy(&s->fe.ops, &si2168_ops, sizeof(struct dvb_frontend_ops)); 685 memcpy(&dev->fe.ops, &si2168_ops, sizeof(struct dvb_frontend_ops));
698 s->fe.demodulator_priv = s; 686 dev->fe.demodulator_priv = client;
699 687 *config->i2c_adapter = dev->adapter;
700 *config->i2c_adapter = s->adapter; 688 *config->fe = &dev->fe;
701 *config->fe = &s->fe; 689 dev->ts_mode = config->ts_mode;
702 s->ts_mode = config->ts_mode; 690 dev->ts_clock_inv = config->ts_clock_inv;
703 s->ts_clock_inv = config->ts_clock_inv; 691 dev->fw_loaded = false;
704 s->fw_loaded = false;
705 692
706 i2c_set_clientdata(client, s); 693 i2c_set_clientdata(client, dev);
707 694
708 dev_info(&s->client->dev, 695 dev_info(&client->dev, "Silicon Labs Si2168 successfully attached\n");
709 "Silicon Labs Si2168 successfully attached\n");
710 return 0; 696 return 0;
697err_kfree:
698 kfree(dev);
711err: 699err:
712 kfree(s);
713 dev_dbg(&client->dev, "failed=%d\n", ret); 700 dev_dbg(&client->dev, "failed=%d\n", ret);
714 return ret; 701 return ret;
715} 702}
716 703
717static int si2168_remove(struct i2c_client *client) 704static int si2168_remove(struct i2c_client *client)
718{ 705{
719 struct si2168 *s = i2c_get_clientdata(client); 706 struct si2168_dev *dev = i2c_get_clientdata(client);
720 707
721 dev_dbg(&client->dev, "\n"); 708 dev_dbg(&client->dev, "\n");
722 709
723 i2c_del_mux_adapter(s->adapter); 710 i2c_del_mux_adapter(dev->adapter);
724 711
725 s->fe.ops.release = NULL; 712 dev->fe.ops.release = NULL;
726 s->fe.demodulator_priv = NULL; 713 dev->fe.demodulator_priv = NULL;
727 714
728 kfree(s); 715 kfree(dev);
729 716
730 return 0; 717 return 0;
731} 718}
732 719
733static const struct i2c_device_id si2168_id[] = { 720static const struct i2c_device_id si2168_id_table[] = {
734 {"si2168", 0}, 721 {"si2168", 0},
735 {} 722 {}
736}; 723};
737MODULE_DEVICE_TABLE(i2c, si2168_id); 724MODULE_DEVICE_TABLE(i2c, si2168_id_table);
738 725
739static struct i2c_driver si2168_driver = { 726static struct i2c_driver si2168_driver = {
740 .driver = { 727 .driver = {
@@ -743,7 +730,7 @@ static struct i2c_driver si2168_driver = {
743 }, 730 },
744 .probe = si2168_probe, 731 .probe = si2168_probe,
745 .remove = si2168_remove, 732 .remove = si2168_remove,
746 .id_table = si2168_id, 733 .id_table = si2168_id_table,
747}; 734};
748 735
749module_i2c_driver(si2168_driver); 736module_i2c_driver(si2168_driver);
diff --git a/drivers/media/dvb-frontends/si2168.h b/drivers/media/dvb-frontends/si2168.h
index 87bc12146667..70d702ae6f49 100644
--- a/drivers/media/dvb-frontends/si2168.h
+++ b/drivers/media/dvb-frontends/si2168.h
@@ -36,14 +36,12 @@ struct si2168_config {
36 struct i2c_adapter **i2c_adapter; 36 struct i2c_adapter **i2c_adapter;
37 37
38 /* TS mode */ 38 /* TS mode */
39#define SI2168_TS_PARALLEL 0x06
40#define SI2168_TS_SERIAL 0x03
39 u8 ts_mode; 41 u8 ts_mode;
40 42
41 /* TS clock inverted */ 43 /* TS clock inverted */
42 bool ts_clock_inv; 44 bool ts_clock_inv;
43
44}; 45};
45 46
46#define SI2168_TS_PARALLEL 0x06
47#define SI2168_TS_SERIAL 0x03
48
49#endif 47#endif
diff --git a/drivers/media/dvb-frontends/si2168_priv.h b/drivers/media/dvb-frontends/si2168_priv.h
index 60bc3349b6c3..aadd1367673f 100644
--- a/drivers/media/dvb-frontends/si2168_priv.h
+++ b/drivers/media/dvb-frontends/si2168_priv.h
@@ -28,8 +28,7 @@
28#define SI2168_B40_FIRMWARE_FALLBACK "dvb-demod-si2168-02.fw" 28#define SI2168_B40_FIRMWARE_FALLBACK "dvb-demod-si2168-02.fw"
29 29
30/* state struct */ 30/* state struct */
31struct si2168 { 31struct si2168_dev {
32 struct i2c_client *client;
33 struct i2c_adapter *adapter; 32 struct i2c_adapter *adapter;
34 struct mutex i2c_mutex; 33 struct mutex i2c_mutex;
35 struct dvb_frontend fe; 34 struct dvb_frontend fe;
diff --git a/drivers/media/dvb-frontends/stb0899_algo.c b/drivers/media/dvb-frontends/stb0899_algo.c
index 93596e0e640b..3012f196e9bd 100644
--- a/drivers/media/dvb-frontends/stb0899_algo.c
+++ b/drivers/media/dvb-frontends/stb0899_algo.c
@@ -19,6 +19,7 @@
19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 19 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20*/ 20*/
21 21
22#include <linux/bitops.h>
22#include "stb0899_drv.h" 23#include "stb0899_drv.h"
23#include "stb0899_priv.h" 24#include "stb0899_priv.h"
24#include "stb0899_reg.h" 25#include "stb0899_reg.h"
@@ -1490,9 +1491,7 @@ enum stb0899_status stb0899_dvbs2_algo(struct stb0899_state *state)
1490 /* Store signal parameters */ 1491 /* Store signal parameters */
1491 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ); 1492 offsetfreq = STB0899_READ_S2REG(STB0899_S2DEMOD, CRL_FREQ);
1492 1493
1493 /* sign extend 30 bit value before using it in calculations */ 1494 offsetfreq = sign_extend32(offsetfreq, 29);
1494 if (offsetfreq & (1 << 29))
1495 offsetfreq |= -1 << 30;
1496 1495
1497 offsetfreq = offsetfreq / ((1 << 30) / 1000); 1496 offsetfreq = offsetfreq / ((1 << 30) / 1000);
1498 offsetfreq *= (internal->master_clk / 1000000); 1497 offsetfreq *= (internal->master_clk / 1000000);
diff --git a/drivers/media/dvb-frontends/stb0899_drv.c b/drivers/media/dvb-frontends/stb0899_drv.c
index 19646fbb061d..c73899d3a53d 100644
--- a/drivers/media/dvb-frontends/stb0899_drv.c
+++ b/drivers/media/dvb-frontends/stb0899_drv.c
@@ -20,6 +20,7 @@
20*/ 20*/
21 21
22#include <linux/init.h> 22#include <linux/init.h>
23#include <linux/jiffies.h>
23#include <linux/kernel.h> 24#include <linux/kernel.h>
24#include <linux/module.h> 25#include <linux/module.h>
25#include <linux/slab.h> 26#include <linux/slab.h>
@@ -691,7 +692,7 @@ static int stb0899_wait_diseqc_fifo_empty(struct stb0899_state *state, int timeo
691 reg = stb0899_read_reg(state, STB0899_DISSTATUS); 692 reg = stb0899_read_reg(state, STB0899_DISSTATUS);
692 if (!STB0899_GETFIELD(FIFOFULL, reg)) 693 if (!STB0899_GETFIELD(FIFOFULL, reg))
693 break; 694 break;
694 if ((jiffies - start) > timeout) { 695 if (time_after(jiffies, start + timeout)) {
695 dprintk(state->verbose, FE_ERROR, 1, "timed out !!"); 696 dprintk(state->verbose, FE_ERROR, 1, "timed out !!");
696 return -ETIMEDOUT; 697 return -ETIMEDOUT;
697 } 698 }
@@ -733,7 +734,7 @@ static int stb0899_wait_diseqc_rxidle(struct stb0899_state *state, int timeout)
733 734
734 while (!STB0899_GETFIELD(RXEND, reg)) { 735 while (!STB0899_GETFIELD(RXEND, reg)) {
735 reg = stb0899_read_reg(state, STB0899_DISRX_ST0); 736 reg = stb0899_read_reg(state, STB0899_DISRX_ST0);
736 if (jiffies - start > timeout) { 737 if (time_after(jiffies, start + timeout)) {
737 dprintk(state->verbose, FE_ERROR, 1, "timed out!!"); 738 dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
738 return -ETIMEDOUT; 739 return -ETIMEDOUT;
739 } 740 }
@@ -782,7 +783,7 @@ static int stb0899_wait_diseqc_txidle(struct stb0899_state *state, int timeout)
782 783
783 while (!STB0899_GETFIELD(TXIDLE, reg)) { 784 while (!STB0899_GETFIELD(TXIDLE, reg)) {
784 reg = stb0899_read_reg(state, STB0899_DISSTATUS); 785 reg = stb0899_read_reg(state, STB0899_DISSTATUS);
785 if (jiffies - start > timeout) { 786 if (time_after(jiffies, start + timeout)) {
786 dprintk(state->verbose, FE_ERROR, 1, "timed out!!"); 787 dprintk(state->verbose, FE_ERROR, 1, "timed out!!");
787 return -ETIMEDOUT; 788 return -ETIMEDOUT;
788 } 789 }
diff --git a/drivers/media/dvb-frontends/tc90522.c b/drivers/media/dvb-frontends/tc90522.c
index b35d65c9cc05..dce22ce35d20 100644
--- a/drivers/media/dvb-frontends/tc90522.c
+++ b/drivers/media/dvb-frontends/tc90522.c
@@ -214,6 +214,7 @@ static int tc90522s_get_frontend(struct dvb_frontend *fe)
214 state = fe->demodulator_priv; 214 state = fe->demodulator_priv;
215 c = &fe->dtv_property_cache; 215 c = &fe->dtv_property_cache;
216 c->delivery_system = SYS_ISDBS; 216 c->delivery_system = SYS_ISDBS;
217 c->symbol_rate = 28860000;
217 218
218 layers = 0; 219 layers = 0;
219 ret = reg_read(state, 0xe6, val, 5); 220 ret = reg_read(state, 0xe6, val, 5);
diff --git a/drivers/media/i2c/Kconfig b/drivers/media/i2c/Kconfig
index 205d71364343..da58c9bb67c2 100644
--- a/drivers/media/i2c/Kconfig
+++ b/drivers/media/i2c/Kconfig
@@ -177,7 +177,7 @@ comment "Video decoders"
177 177
178config VIDEO_ADV7180 178config VIDEO_ADV7180
179 tristate "Analog Devices ADV7180 decoder" 179 tristate "Analog Devices ADV7180 decoder"
180 depends on VIDEO_V4L2 && I2C 180 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
181 ---help--- 181 ---help---
182 Support for the Analog Devices ADV7180 video decoder. 182 Support for the Analog Devices ADV7180 video decoder.
183 183
@@ -196,7 +196,7 @@ config VIDEO_ADV7183
196 196
197config VIDEO_ADV7604 197config VIDEO_ADV7604
198 tristate "Analog Devices ADV7604 decoder" 198 tristate "Analog Devices ADV7604 decoder"
199 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER 199 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
200 ---help--- 200 ---help---
201 Support for the Analog Devices ADV7604 video decoder. 201 Support for the Analog Devices ADV7604 video decoder.
202 202
@@ -208,7 +208,8 @@ config VIDEO_ADV7604
208 208
209config VIDEO_ADV7842 209config VIDEO_ADV7842
210 tristate "Analog Devices ADV7842 decoder" 210 tristate "Analog Devices ADV7842 decoder"
211 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER 211 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
212 select HDMI
212 ---help--- 213 ---help---
213 Support for the Analog Devices ADV7842 video decoder. 214 Support for the Analog Devices ADV7842 video decoder.
214 215
@@ -422,7 +423,7 @@ config VIDEO_ADV7393
422 423
423config VIDEO_ADV7511 424config VIDEO_ADV7511
424 tristate "Analog Devices ADV7511 encoder" 425 tristate "Analog Devices ADV7511 encoder"
425 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API && MEDIA_CONTROLLER 426 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
426 ---help--- 427 ---help---
427 Support for the Analog Devices ADV7511 video encoder. 428 Support for the Analog Devices ADV7511 video encoder.
428 429
diff --git a/drivers/media/i2c/adv7180.c b/drivers/media/i2c/adv7180.c
index bffe6eb528a3..b75878c27c2a 100644
--- a/drivers/media/i2c/adv7180.c
+++ b/drivers/media/i2c/adv7180.c
@@ -30,56 +30,60 @@
30#include <media/v4l2-device.h> 30#include <media/v4l2-device.h>
31#include <media/v4l2-ctrls.h> 31#include <media/v4l2-ctrls.h>
32#include <linux/mutex.h> 32#include <linux/mutex.h>
33 33#include <linux/delay.h>
34#define ADV7180_INPUT_CONTROL_REG 0x00 34
35#define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM 0x00 35#define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM 0x0
36#define ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM_PED 0x10 36#define ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM_PED 0x1
37#define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_J_SECAM 0x20 37#define ADV7180_STD_AD_PAL_N_NTSC_J_SECAM 0x2
38#define ADV7180_INPUT_CONTROL_AD_PAL_N_NTSC_M_SECAM 0x30 38#define ADV7180_STD_AD_PAL_N_NTSC_M_SECAM 0x3
39#define ADV7180_INPUT_CONTROL_NTSC_J 0x40 39#define ADV7180_STD_NTSC_J 0x4
40#define ADV7180_INPUT_CONTROL_NTSC_M 0x50 40#define ADV7180_STD_NTSC_M 0x5
41#define ADV7180_INPUT_CONTROL_PAL60 0x60 41#define ADV7180_STD_PAL60 0x6
42#define ADV7180_INPUT_CONTROL_NTSC_443 0x70 42#define ADV7180_STD_NTSC_443 0x7
43#define ADV7180_INPUT_CONTROL_PAL_BG 0x80 43#define ADV7180_STD_PAL_BG 0x8
44#define ADV7180_INPUT_CONTROL_PAL_N 0x90 44#define ADV7180_STD_PAL_N 0x9
45#define ADV7180_INPUT_CONTROL_PAL_M 0xa0 45#define ADV7180_STD_PAL_M 0xa
46#define ADV7180_INPUT_CONTROL_PAL_M_PED 0xb0 46#define ADV7180_STD_PAL_M_PED 0xb
47#define ADV7180_INPUT_CONTROL_PAL_COMB_N 0xc0 47#define ADV7180_STD_PAL_COMB_N 0xc
48#define ADV7180_INPUT_CONTROL_PAL_COMB_N_PED 0xd0 48#define ADV7180_STD_PAL_COMB_N_PED 0xd
49#define ADV7180_INPUT_CONTROL_PAL_SECAM 0xe0 49#define ADV7180_STD_PAL_SECAM 0xe
50#define ADV7180_INPUT_CONTROL_PAL_SECAM_PED 0xf0 50#define ADV7180_STD_PAL_SECAM_PED 0xf
51
52#define ADV7180_REG_INPUT_CONTROL 0x0000
51#define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f 53#define ADV7180_INPUT_CONTROL_INSEL_MASK 0x0f
52 54
53#define ADV7180_EXTENDED_OUTPUT_CONTROL_REG 0x04 55#define ADV7182_REG_INPUT_VIDSEL 0x0002
56
57#define ADV7180_REG_EXTENDED_OUTPUT_CONTROL 0x0004
54#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5 58#define ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS 0xC5
55 59
56#define ADV7180_AUTODETECT_ENABLE_REG 0x07 60#define ADV7180_REG_AUTODETECT_ENABLE 0x07
57#define ADV7180_AUTODETECT_DEFAULT 0x7f 61#define ADV7180_AUTODETECT_DEFAULT 0x7f
58/* Contrast */ 62/* Contrast */
59#define ADV7180_CON_REG 0x08 /*Unsigned */ 63#define ADV7180_REG_CON 0x0008 /*Unsigned */
60#define ADV7180_CON_MIN 0 64#define ADV7180_CON_MIN 0
61#define ADV7180_CON_DEF 128 65#define ADV7180_CON_DEF 128
62#define ADV7180_CON_MAX 255 66#define ADV7180_CON_MAX 255
63/* Brightness*/ 67/* Brightness*/
64#define ADV7180_BRI_REG 0x0a /*Signed */ 68#define ADV7180_REG_BRI 0x000a /*Signed */
65#define ADV7180_BRI_MIN -128 69#define ADV7180_BRI_MIN -128
66#define ADV7180_BRI_DEF 0 70#define ADV7180_BRI_DEF 0
67#define ADV7180_BRI_MAX 127 71#define ADV7180_BRI_MAX 127
68/* Hue */ 72/* Hue */
69#define ADV7180_HUE_REG 0x0b /*Signed, inverted */ 73#define ADV7180_REG_HUE 0x000b /*Signed, inverted */
70#define ADV7180_HUE_MIN -127 74#define ADV7180_HUE_MIN -127
71#define ADV7180_HUE_DEF 0 75#define ADV7180_HUE_DEF 0
72#define ADV7180_HUE_MAX 128 76#define ADV7180_HUE_MAX 128
73 77
74#define ADV7180_ADI_CTRL_REG 0x0e 78#define ADV7180_REG_CTRL 0x000e
75#define ADV7180_ADI_CTRL_IRQ_SPACE 0x20 79#define ADV7180_CTRL_IRQ_SPACE 0x20
76 80
77#define ADV7180_PWR_MAN_REG 0x0f 81#define ADV7180_REG_PWR_MAN 0x0f
78#define ADV7180_PWR_MAN_ON 0x04 82#define ADV7180_PWR_MAN_ON 0x04
79#define ADV7180_PWR_MAN_OFF 0x24 83#define ADV7180_PWR_MAN_OFF 0x24
80#define ADV7180_PWR_MAN_RES 0x80 84#define ADV7180_PWR_MAN_RES 0x80
81 85
82#define ADV7180_STATUS1_REG 0x10 86#define ADV7180_REG_STATUS1 0x0010
83#define ADV7180_STATUS1_IN_LOCK 0x01 87#define ADV7180_STATUS1_IN_LOCK 0x01
84#define ADV7180_STATUS1_AUTOD_MASK 0x70 88#define ADV7180_STATUS1_AUTOD_MASK 0x70
85#define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00 89#define ADV7180_STATUS1_AUTOD_NTSM_M_J 0x00
@@ -91,49 +95,161 @@
91#define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60 95#define ADV7180_STATUS1_AUTOD_PAL_COMB 0x60
92#define ADV7180_STATUS1_AUTOD_SECAM_525 0x70 96#define ADV7180_STATUS1_AUTOD_SECAM_525 0x70
93 97
94#define ADV7180_IDENT_REG 0x11 98#define ADV7180_REG_IDENT 0x0011
95#define ADV7180_ID_7180 0x18 99#define ADV7180_ID_7180 0x18
96 100
97#define ADV7180_ICONF1_ADI 0x40 101#define ADV7180_REG_ICONF1 0x0040
98#define ADV7180_ICONF1_ACTIVE_LOW 0x01 102#define ADV7180_ICONF1_ACTIVE_LOW 0x01
99#define ADV7180_ICONF1_PSYNC_ONLY 0x10 103#define ADV7180_ICONF1_PSYNC_ONLY 0x10
100#define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0 104#define ADV7180_ICONF1_ACTIVE_TO_CLR 0xC0
101/* Saturation */ 105/* Saturation */
102#define ADV7180_SD_SAT_CB_REG 0xe3 /*Unsigned */ 106#define ADV7180_REG_SD_SAT_CB 0x00e3 /*Unsigned */
103#define ADV7180_SD_SAT_CR_REG 0xe4 /*Unsigned */ 107#define ADV7180_REG_SD_SAT_CR 0x00e4 /*Unsigned */
104#define ADV7180_SAT_MIN 0 108#define ADV7180_SAT_MIN 0
105#define ADV7180_SAT_DEF 128 109#define ADV7180_SAT_DEF 128
106#define ADV7180_SAT_MAX 255 110#define ADV7180_SAT_MAX 255
107 111
108#define ADV7180_IRQ1_LOCK 0x01 112#define ADV7180_IRQ1_LOCK 0x01
109#define ADV7180_IRQ1_UNLOCK 0x02 113#define ADV7180_IRQ1_UNLOCK 0x02
110#define ADV7180_ISR1_ADI 0x42 114#define ADV7180_REG_ISR1 0x0042
111#define ADV7180_ICR1_ADI 0x43 115#define ADV7180_REG_ICR1 0x0043
112#define ADV7180_IMR1_ADI 0x44 116#define ADV7180_REG_IMR1 0x0044
113#define ADV7180_IMR2_ADI 0x48 117#define ADV7180_REG_IMR2 0x0048
114#define ADV7180_IRQ3_AD_CHANGE 0x08 118#define ADV7180_IRQ3_AD_CHANGE 0x08
115#define ADV7180_ISR3_ADI 0x4A 119#define ADV7180_REG_ISR3 0x004A
116#define ADV7180_ICR3_ADI 0x4B 120#define ADV7180_REG_ICR3 0x004B
117#define ADV7180_IMR3_ADI 0x4C 121#define ADV7180_REG_IMR3 0x004C
118#define ADV7180_IMR4_ADI 0x50 122#define ADV7180_REG_IMR4 0x50
119 123
120#define ADV7180_NTSC_V_BIT_END_REG 0xE6 124#define ADV7180_REG_NTSC_V_BIT_END 0x00E6
121#define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F 125#define ADV7180_NTSC_V_BIT_END_MANUAL_NVEND 0x4F
122 126
127#define ADV7180_REG_VPP_SLAVE_ADDR 0xFD
128#define ADV7180_REG_CSI_SLAVE_ADDR 0xFE
129
130#define ADV7180_REG_FLCONTROL 0x40e0
131#define ADV7180_FLCONTROL_FL_ENABLE 0x1
132
133#define ADV7180_CSI_REG_PWRDN 0x00
134#define ADV7180_CSI_PWRDN 0x80
135
136#define ADV7180_INPUT_CVBS_AIN1 0x00
137#define ADV7180_INPUT_CVBS_AIN2 0x01
138#define ADV7180_INPUT_CVBS_AIN3 0x02
139#define ADV7180_INPUT_CVBS_AIN4 0x03
140#define ADV7180_INPUT_CVBS_AIN5 0x04
141#define ADV7180_INPUT_CVBS_AIN6 0x05
142#define ADV7180_INPUT_SVIDEO_AIN1_AIN2 0x06
143#define ADV7180_INPUT_SVIDEO_AIN3_AIN4 0x07
144#define ADV7180_INPUT_SVIDEO_AIN5_AIN6 0x08
145#define ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3 0x09
146#define ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0a
147
148#define ADV7182_INPUT_CVBS_AIN1 0x00
149#define ADV7182_INPUT_CVBS_AIN2 0x01
150#define ADV7182_INPUT_CVBS_AIN3 0x02
151#define ADV7182_INPUT_CVBS_AIN4 0x03
152#define ADV7182_INPUT_CVBS_AIN5 0x04
153#define ADV7182_INPUT_CVBS_AIN6 0x05
154#define ADV7182_INPUT_CVBS_AIN7 0x06
155#define ADV7182_INPUT_CVBS_AIN8 0x07
156#define ADV7182_INPUT_SVIDEO_AIN1_AIN2 0x08
157#define ADV7182_INPUT_SVIDEO_AIN3_AIN4 0x09
158#define ADV7182_INPUT_SVIDEO_AIN5_AIN6 0x0a
159#define ADV7182_INPUT_SVIDEO_AIN7_AIN8 0x0b
160#define ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3 0x0c
161#define ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6 0x0d
162#define ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2 0x0e
163#define ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4 0x0f
164#define ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6 0x10
165#define ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8 0x11
166
167#define ADV7180_DEFAULT_CSI_I2C_ADDR 0x44
168#define ADV7180_DEFAULT_VPP_I2C_ADDR 0x42
169
170#define V4L2_CID_ADV_FAST_SWITCH (V4L2_CID_USER_ADV7180_BASE + 0x00)
171
172struct adv7180_state;
173
174#define ADV7180_FLAG_RESET_POWERED BIT(0)
175#define ADV7180_FLAG_V2 BIT(1)
176#define ADV7180_FLAG_MIPI_CSI2 BIT(2)
177#define ADV7180_FLAG_I2P BIT(3)
178
179struct adv7180_chip_info {
180 unsigned int flags;
181 unsigned int valid_input_mask;
182 int (*set_std)(struct adv7180_state *st, unsigned int std);
183 int (*select_input)(struct adv7180_state *st, unsigned int input);
184 int (*init)(struct adv7180_state *state);
185};
186
123struct adv7180_state { 187struct adv7180_state {
124 struct v4l2_ctrl_handler ctrl_hdl; 188 struct v4l2_ctrl_handler ctrl_hdl;
125 struct v4l2_subdev sd; 189 struct v4l2_subdev sd;
190 struct media_pad pad;
126 struct mutex mutex; /* mutual excl. when accessing chip */ 191 struct mutex mutex; /* mutual excl. when accessing chip */
127 int irq; 192 int irq;
128 v4l2_std_id curr_norm; 193 v4l2_std_id curr_norm;
129 bool autodetect; 194 bool autodetect;
130 bool powered; 195 bool powered;
131 u8 input; 196 u8 input;
197
198 struct i2c_client *client;
199 unsigned int register_page;
200 struct i2c_client *csi_client;
201 struct i2c_client *vpp_client;
202 const struct adv7180_chip_info *chip_info;
203 enum v4l2_field field;
132}; 204};
133#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \ 205#define to_adv7180_sd(_ctrl) (&container_of(_ctrl->handler, \
134 struct adv7180_state, \ 206 struct adv7180_state, \
135 ctrl_hdl)->sd) 207 ctrl_hdl)->sd)
136 208
209static int adv7180_select_page(struct adv7180_state *state, unsigned int page)
210{
211 if (state->register_page != page) {
212 i2c_smbus_write_byte_data(state->client, ADV7180_REG_CTRL,
213 page);
214 state->register_page = page;
215 }
216
217 return 0;
218}
219
220static int adv7180_write(struct adv7180_state *state, unsigned int reg,
221 unsigned int value)
222{
223 lockdep_assert_held(&state->mutex);
224 adv7180_select_page(state, reg >> 8);
225 return i2c_smbus_write_byte_data(state->client, reg & 0xff, value);
226}
227
228static int adv7180_read(struct adv7180_state *state, unsigned int reg)
229{
230 lockdep_assert_held(&state->mutex);
231 adv7180_select_page(state, reg >> 8);
232 return i2c_smbus_read_byte_data(state->client, reg & 0xff);
233}
234
235static int adv7180_csi_write(struct adv7180_state *state, unsigned int reg,
236 unsigned int value)
237{
238 return i2c_smbus_write_byte_data(state->csi_client, reg, value);
239}
240
241static int adv7180_set_video_standard(struct adv7180_state *state,
242 unsigned int std)
243{
244 return state->chip_info->set_std(state, std);
245}
246
247static int adv7180_vpp_write(struct adv7180_state *state, unsigned int reg,
248 unsigned int value)
249{
250 return i2c_smbus_write_byte_data(state->vpp_client, reg, value);
251}
252
137static v4l2_std_id adv7180_std_to_v4l2(u8 status1) 253static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
138{ 254{
139 /* in case V4L2_IN_ST_NO_SIGNAL */ 255 /* in case V4L2_IN_ST_NO_SIGNAL */
@@ -165,22 +281,22 @@ static v4l2_std_id adv7180_std_to_v4l2(u8 status1)
165static int v4l2_std_to_adv7180(v4l2_std_id std) 281static int v4l2_std_to_adv7180(v4l2_std_id std)
166{ 282{
167 if (std == V4L2_STD_PAL_60) 283 if (std == V4L2_STD_PAL_60)
168 return ADV7180_INPUT_CONTROL_PAL60; 284 return ADV7180_STD_PAL60;
169 if (std == V4L2_STD_NTSC_443) 285 if (std == V4L2_STD_NTSC_443)
170 return ADV7180_INPUT_CONTROL_NTSC_443; 286 return ADV7180_STD_NTSC_443;
171 if (std == V4L2_STD_PAL_N) 287 if (std == V4L2_STD_PAL_N)
172 return ADV7180_INPUT_CONTROL_PAL_N; 288 return ADV7180_STD_PAL_N;
173 if (std == V4L2_STD_PAL_M) 289 if (std == V4L2_STD_PAL_M)
174 return ADV7180_INPUT_CONTROL_PAL_M; 290 return ADV7180_STD_PAL_M;
175 if (std == V4L2_STD_PAL_Nc) 291 if (std == V4L2_STD_PAL_Nc)
176 return ADV7180_INPUT_CONTROL_PAL_COMB_N; 292 return ADV7180_STD_PAL_COMB_N;
177 293
178 if (std & V4L2_STD_PAL) 294 if (std & V4L2_STD_PAL)
179 return ADV7180_INPUT_CONTROL_PAL_BG; 295 return ADV7180_STD_PAL_BG;
180 if (std & V4L2_STD_NTSC) 296 if (std & V4L2_STD_NTSC)
181 return ADV7180_INPUT_CONTROL_NTSC_M; 297 return ADV7180_STD_NTSC_M;
182 if (std & V4L2_STD_SECAM) 298 if (std & V4L2_STD_SECAM)
183 return ADV7180_INPUT_CONTROL_PAL_SECAM; 299 return ADV7180_STD_PAL_SECAM;
184 300
185 return -EINVAL; 301 return -EINVAL;
186} 302}
@@ -193,10 +309,10 @@ static u32 adv7180_status_to_v4l2(u8 status1)
193 return 0; 309 return 0;
194} 310}
195 311
196static int __adv7180_status(struct i2c_client *client, u32 *status, 312static int __adv7180_status(struct adv7180_state *state, u32 *status,
197 v4l2_std_id *std) 313 v4l2_std_id *std)
198{ 314{
199 int status1 = i2c_smbus_read_byte_data(client, ADV7180_STATUS1_REG); 315 int status1 = adv7180_read(state, ADV7180_REG_STATUS1);
200 316
201 if (status1 < 0) 317 if (status1 < 0)
202 return status1; 318 return status1;
@@ -225,7 +341,7 @@ static int adv7180_querystd(struct v4l2_subdev *sd, v4l2_std_id *std)
225 if (!state->autodetect || state->irq > 0) 341 if (!state->autodetect || state->irq > 0)
226 *std = state->curr_norm; 342 *std = state->curr_norm;
227 else 343 else
228 err = __adv7180_status(v4l2_get_subdevdata(sd), NULL, std); 344 err = __adv7180_status(state, NULL, std);
229 345
230 mutex_unlock(&state->mutex); 346 mutex_unlock(&state->mutex);
231 return err; 347 return err;
@@ -236,26 +352,19 @@ static int adv7180_s_routing(struct v4l2_subdev *sd, u32 input,
236{ 352{
237 struct adv7180_state *state = to_state(sd); 353 struct adv7180_state *state = to_state(sd);
238 int ret = mutex_lock_interruptible(&state->mutex); 354 int ret = mutex_lock_interruptible(&state->mutex);
239 struct i2c_client *client = v4l2_get_subdevdata(sd);
240 355
241 if (ret) 356 if (ret)
242 return ret; 357 return ret;
243 358
244 /* We cannot discriminate between LQFP and 40-pin LFCSP, so accept 359 if (input > 31 || !(BIT(input) & state->chip_info->valid_input_mask)) {
245 * all inputs and let the card driver take care of validation 360 ret = -EINVAL;
246 */
247 if ((input & ADV7180_INPUT_CONTROL_INSEL_MASK) != input)
248 goto out; 361 goto out;
362 }
249 363
250 ret = i2c_smbus_read_byte_data(client, ADV7180_INPUT_CONTROL_REG); 364 ret = state->chip_info->select_input(state, input);
251
252 if (ret < 0)
253 goto out;
254 365
255 ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK; 366 if (ret == 0)
256 ret = i2c_smbus_write_byte_data(client, 367 state->input = input;
257 ADV7180_INPUT_CONTROL_REG, ret | input);
258 state->input = input;
259out: 368out:
260 mutex_unlock(&state->mutex); 369 mutex_unlock(&state->mutex);
261 return ret; 370 return ret;
@@ -268,74 +377,104 @@ static int adv7180_g_input_status(struct v4l2_subdev *sd, u32 *status)
268 if (ret) 377 if (ret)
269 return ret; 378 return ret;
270 379
271 ret = __adv7180_status(v4l2_get_subdevdata(sd), status, NULL); 380 ret = __adv7180_status(state, status, NULL);
272 mutex_unlock(&state->mutex); 381 mutex_unlock(&state->mutex);
273 return ret; 382 return ret;
274} 383}
275 384
385static int adv7180_program_std(struct adv7180_state *state)
386{
387 int ret;
388
389 if (state->autodetect) {
390 ret = adv7180_set_video_standard(state,
391 ADV7180_STD_AD_PAL_BG_NTSC_J_SECAM);
392 if (ret < 0)
393 return ret;
394
395 __adv7180_status(state, NULL, &state->curr_norm);
396 } else {
397 ret = v4l2_std_to_adv7180(state->curr_norm);
398 if (ret < 0)
399 return ret;
400
401 ret = adv7180_set_video_standard(state, ret);
402 if (ret < 0)
403 return ret;
404 }
405
406 return 0;
407}
408
276static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std) 409static int adv7180_s_std(struct v4l2_subdev *sd, v4l2_std_id std)
277{ 410{
278 struct adv7180_state *state = to_state(sd); 411 struct adv7180_state *state = to_state(sd);
279 struct i2c_client *client = v4l2_get_subdevdata(sd);
280 int ret = mutex_lock_interruptible(&state->mutex); 412 int ret = mutex_lock_interruptible(&state->mutex);
413
281 if (ret) 414 if (ret)
282 return ret; 415 return ret;
283 416
284 /* all standards -> autodetect */ 417 /* all standards -> autodetect */
285 if (std == V4L2_STD_ALL) { 418 if (std == V4L2_STD_ALL) {
286 ret =
287 i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
288 ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
289 | state->input);
290 if (ret < 0)
291 goto out;
292
293 __adv7180_status(client, NULL, &state->curr_norm);
294 state->autodetect = true; 419 state->autodetect = true;
295 } else { 420 } else {
421 /* Make sure we can support this std */
296 ret = v4l2_std_to_adv7180(std); 422 ret = v4l2_std_to_adv7180(std);
297 if (ret < 0) 423 if (ret < 0)
298 goto out; 424 goto out;
299 425
300 ret = i2c_smbus_write_byte_data(client,
301 ADV7180_INPUT_CONTROL_REG,
302 ret | state->input);
303 if (ret < 0)
304 goto out;
305
306 state->curr_norm = std; 426 state->curr_norm = std;
307 state->autodetect = false; 427 state->autodetect = false;
308 } 428 }
309 ret = 0; 429
430 ret = adv7180_program_std(state);
310out: 431out:
311 mutex_unlock(&state->mutex); 432 mutex_unlock(&state->mutex);
312 return ret; 433 return ret;
313} 434}
314 435
315static int adv7180_set_power(struct adv7180_state *state, 436static int adv7180_set_power(struct adv7180_state *state, bool on)
316 struct i2c_client *client, bool on)
317{ 437{
318 u8 val; 438 u8 val;
439 int ret;
319 440
320 if (on) 441 if (on)
321 val = ADV7180_PWR_MAN_ON; 442 val = ADV7180_PWR_MAN_ON;
322 else 443 else
323 val = ADV7180_PWR_MAN_OFF; 444 val = ADV7180_PWR_MAN_OFF;
324 445
325 return i2c_smbus_write_byte_data(client, ADV7180_PWR_MAN_REG, val); 446 ret = adv7180_write(state, ADV7180_REG_PWR_MAN, val);
447 if (ret)
448 return ret;
449
450 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
451 if (on) {
452 adv7180_csi_write(state, 0xDE, 0x02);
453 adv7180_csi_write(state, 0xD2, 0xF7);
454 adv7180_csi_write(state, 0xD8, 0x65);
455 adv7180_csi_write(state, 0xE0, 0x09);
456 adv7180_csi_write(state, 0x2C, 0x00);
457 if (state->field == V4L2_FIELD_NONE)
458 adv7180_csi_write(state, 0x1D, 0x80);
459 adv7180_csi_write(state, 0x00, 0x00);
460 } else {
461 adv7180_csi_write(state, 0x00, 0x80);
462 }
463 }
464
465 return 0;
326} 466}
327 467
328static int adv7180_s_power(struct v4l2_subdev *sd, int on) 468static int adv7180_s_power(struct v4l2_subdev *sd, int on)
329{ 469{
330 struct adv7180_state *state = to_state(sd); 470 struct adv7180_state *state = to_state(sd);
331 struct i2c_client *client = v4l2_get_subdevdata(sd);
332 int ret; 471 int ret;
333 472
334 ret = mutex_lock_interruptible(&state->mutex); 473 ret = mutex_lock_interruptible(&state->mutex);
335 if (ret) 474 if (ret)
336 return ret; 475 return ret;
337 476
338 ret = adv7180_set_power(state, client, on); 477 ret = adv7180_set_power(state, on);
339 if (ret == 0) 478 if (ret == 0)
340 state->powered = on; 479 state->powered = on;
341 480
@@ -347,7 +486,6 @@ static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
347{ 486{
348 struct v4l2_subdev *sd = to_adv7180_sd(ctrl); 487 struct v4l2_subdev *sd = to_adv7180_sd(ctrl);
349 struct adv7180_state *state = to_state(sd); 488 struct adv7180_state *state = to_state(sd);
350 struct i2c_client *client = v4l2_get_subdevdata(sd);
351 int ret = mutex_lock_interruptible(&state->mutex); 489 int ret = mutex_lock_interruptible(&state->mutex);
352 int val; 490 int val;
353 491
@@ -356,26 +494,36 @@ static int adv7180_s_ctrl(struct v4l2_ctrl *ctrl)
356 val = ctrl->val; 494 val = ctrl->val;
357 switch (ctrl->id) { 495 switch (ctrl->id) {
358 case V4L2_CID_BRIGHTNESS: 496 case V4L2_CID_BRIGHTNESS:
359 ret = i2c_smbus_write_byte_data(client, ADV7180_BRI_REG, val); 497 ret = adv7180_write(state, ADV7180_REG_BRI, val);
360 break; 498 break;
361 case V4L2_CID_HUE: 499 case V4L2_CID_HUE:
362 /*Hue is inverted according to HSL chart */ 500 /*Hue is inverted according to HSL chart */
363 ret = i2c_smbus_write_byte_data(client, ADV7180_HUE_REG, -val); 501 ret = adv7180_write(state, ADV7180_REG_HUE, -val);
364 break; 502 break;
365 case V4L2_CID_CONTRAST: 503 case V4L2_CID_CONTRAST:
366 ret = i2c_smbus_write_byte_data(client, ADV7180_CON_REG, val); 504 ret = adv7180_write(state, ADV7180_REG_CON, val);
367 break; 505 break;
368 case V4L2_CID_SATURATION: 506 case V4L2_CID_SATURATION:
369 /* 507 /*
370 *This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE 508 *This could be V4L2_CID_BLUE_BALANCE/V4L2_CID_RED_BALANCE
371 *Let's not confuse the user, everybody understands saturation 509 *Let's not confuse the user, everybody understands saturation
372 */ 510 */
373 ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CB_REG, 511 ret = adv7180_write(state, ADV7180_REG_SD_SAT_CB, val);
374 val);
375 if (ret < 0) 512 if (ret < 0)
376 break; 513 break;
377 ret = i2c_smbus_write_byte_data(client, ADV7180_SD_SAT_CR_REG, 514 ret = adv7180_write(state, ADV7180_REG_SD_SAT_CR, val);
378 val); 515 break;
516 case V4L2_CID_ADV_FAST_SWITCH:
517 if (ctrl->val) {
518 /* ADI required write */
519 adv7180_write(state, 0x80d9, 0x44);
520 adv7180_write(state, ADV7180_REG_FLCONTROL,
521 ADV7180_FLCONTROL_FL_ENABLE);
522 } else {
523 /* ADI required write */
524 adv7180_write(state, 0x80d9, 0xc4);
525 adv7180_write(state, ADV7180_REG_FLCONTROL, 0x00);
526 }
379 break; 527 break;
380 default: 528 default:
381 ret = -EINVAL; 529 ret = -EINVAL;
@@ -389,6 +537,16 @@ static const struct v4l2_ctrl_ops adv7180_ctrl_ops = {
389 .s_ctrl = adv7180_s_ctrl, 537 .s_ctrl = adv7180_s_ctrl,
390}; 538};
391 539
540static const struct v4l2_ctrl_config adv7180_ctrl_fast_switch = {
541 .ops = &adv7180_ctrl_ops,
542 .id = V4L2_CID_ADV_FAST_SWITCH,
543 .name = "Fast Switching",
544 .type = V4L2_CTRL_TYPE_BOOLEAN,
545 .min = 0,
546 .max = 1,
547 .step = 1,
548};
549
392static int adv7180_init_controls(struct adv7180_state *state) 550static int adv7180_init_controls(struct adv7180_state *state)
393{ 551{
394 v4l2_ctrl_handler_init(&state->ctrl_hdl, 4); 552 v4l2_ctrl_handler_init(&state->ctrl_hdl, 4);
@@ -405,6 +563,8 @@ static int adv7180_init_controls(struct adv7180_state *state)
405 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops, 563 v4l2_ctrl_new_std(&state->ctrl_hdl, &adv7180_ctrl_ops,
406 V4L2_CID_HUE, ADV7180_HUE_MIN, 564 V4L2_CID_HUE, ADV7180_HUE_MIN,
407 ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF); 565 ADV7180_HUE_MAX, 1, ADV7180_HUE_DEF);
566 v4l2_ctrl_new_custom(&state->ctrl_hdl, &adv7180_ctrl_fast_switch, NULL);
567
408 state->sd.ctrl_handler = &state->ctrl_hdl; 568 state->sd.ctrl_handler = &state->ctrl_hdl;
409 if (state->ctrl_hdl.error) { 569 if (state->ctrl_hdl.error) {
410 int err = state->ctrl_hdl.error; 570 int err = state->ctrl_hdl.error;
@@ -421,13 +581,14 @@ static void adv7180_exit_controls(struct adv7180_state *state)
421 v4l2_ctrl_handler_free(&state->ctrl_hdl); 581 v4l2_ctrl_handler_free(&state->ctrl_hdl);
422} 582}
423 583
424static int adv7180_enum_mbus_fmt(struct v4l2_subdev *sd, unsigned int index, 584static int adv7180_enum_mbus_code(struct v4l2_subdev *sd,
425 u32 *code) 585 struct v4l2_subdev_fh *fh,
586 struct v4l2_subdev_mbus_code_enum *code)
426{ 587{
427 if (index > 0) 588 if (code->index != 0)
428 return -EINVAL; 589 return -EINVAL;
429 590
430 *code = MEDIA_BUS_FMT_YUYV8_2X8; 591 code->code = MEDIA_BUS_FMT_YUYV8_2X8;
431 592
432 return 0; 593 return 0;
433} 594}
@@ -439,23 +600,118 @@ static int adv7180_mbus_fmt(struct v4l2_subdev *sd,
439 600
440 fmt->code = MEDIA_BUS_FMT_YUYV8_2X8; 601 fmt->code = MEDIA_BUS_FMT_YUYV8_2X8;
441 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M; 602 fmt->colorspace = V4L2_COLORSPACE_SMPTE170M;
442 fmt->field = V4L2_FIELD_INTERLACED;
443 fmt->width = 720; 603 fmt->width = 720;
444 fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576; 604 fmt->height = state->curr_norm & V4L2_STD_525_60 ? 480 : 576;
445 605
446 return 0; 606 return 0;
447} 607}
448 608
609static int adv7180_set_field_mode(struct adv7180_state *state)
610{
611 if (!(state->chip_info->flags & ADV7180_FLAG_I2P))
612 return 0;
613
614 if (state->field == V4L2_FIELD_NONE) {
615 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
616 adv7180_csi_write(state, 0x01, 0x20);
617 adv7180_csi_write(state, 0x02, 0x28);
618 adv7180_csi_write(state, 0x03, 0x38);
619 adv7180_csi_write(state, 0x04, 0x30);
620 adv7180_csi_write(state, 0x05, 0x30);
621 adv7180_csi_write(state, 0x06, 0x80);
622 adv7180_csi_write(state, 0x07, 0x70);
623 adv7180_csi_write(state, 0x08, 0x50);
624 }
625 adv7180_vpp_write(state, 0xa3, 0x00);
626 adv7180_vpp_write(state, 0x5b, 0x00);
627 adv7180_vpp_write(state, 0x55, 0x80);
628 } else {
629 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
630 adv7180_csi_write(state, 0x01, 0x18);
631 adv7180_csi_write(state, 0x02, 0x18);
632 adv7180_csi_write(state, 0x03, 0x30);
633 adv7180_csi_write(state, 0x04, 0x20);
634 adv7180_csi_write(state, 0x05, 0x28);
635 adv7180_csi_write(state, 0x06, 0x40);
636 adv7180_csi_write(state, 0x07, 0x58);
637 adv7180_csi_write(state, 0x08, 0x30);
638 }
639 adv7180_vpp_write(state, 0xa3, 0x70);
640 adv7180_vpp_write(state, 0x5b, 0x80);
641 adv7180_vpp_write(state, 0x55, 0x00);
642 }
643
644 return 0;
645}
646
647static int adv7180_get_pad_format(struct v4l2_subdev *sd,
648 struct v4l2_subdev_fh *fh,
649 struct v4l2_subdev_format *format)
650{
651 struct adv7180_state *state = to_state(sd);
652
653 if (format->which == V4L2_SUBDEV_FORMAT_TRY) {
654 format->format = *v4l2_subdev_get_try_format(fh, 0);
655 } else {
656 adv7180_mbus_fmt(sd, &format->format);
657 format->format.field = state->field;
658 }
659
660 return 0;
661}
662
663static int adv7180_set_pad_format(struct v4l2_subdev *sd,
664 struct v4l2_subdev_fh *fh,
665 struct v4l2_subdev_format *format)
666{
667 struct adv7180_state *state = to_state(sd);
668 struct v4l2_mbus_framefmt *framefmt;
669
670 switch (format->format.field) {
671 case V4L2_FIELD_NONE:
672 if (!(state->chip_info->flags & ADV7180_FLAG_I2P))
673 format->format.field = V4L2_FIELD_INTERLACED;
674 break;
675 default:
676 format->format.field = V4L2_FIELD_INTERLACED;
677 break;
678 }
679
680 if (format->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
681 framefmt = &format->format;
682 if (state->field != format->format.field) {
683 state->field = format->format.field;
684 adv7180_set_power(state, false);
685 adv7180_set_field_mode(state);
686 adv7180_set_power(state, true);
687 }
688 } else {
689 framefmt = v4l2_subdev_get_try_format(fh, 0);
690 *framefmt = format->format;
691 }
692
693 return adv7180_mbus_fmt(sd, framefmt);
694}
695
449static int adv7180_g_mbus_config(struct v4l2_subdev *sd, 696static int adv7180_g_mbus_config(struct v4l2_subdev *sd,
450 struct v4l2_mbus_config *cfg) 697 struct v4l2_mbus_config *cfg)
451{ 698{
452 /* 699 struct adv7180_state *state = to_state(sd);
453 * The ADV7180 sensor supports BT.601/656 output modes. 700
454 * The BT.656 is default and not yet configurable by s/w. 701 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
455 */ 702 cfg->type = V4L2_MBUS_CSI2;
456 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING | 703 cfg->flags = V4L2_MBUS_CSI2_1_LANE |
457 V4L2_MBUS_DATA_ACTIVE_HIGH; 704 V4L2_MBUS_CSI2_CHANNEL_0 |
458 cfg->type = V4L2_MBUS_BT656; 705 V4L2_MBUS_CSI2_CONTINUOUS_CLOCK;
706 } else {
707 /*
708 * The ADV7180 sensor supports BT.601/656 output modes.
709 * The BT.656 is default and not yet configurable by s/w.
710 */
711 cfg->flags = V4L2_MBUS_MASTER | V4L2_MBUS_PCLK_SAMPLE_RISING |
712 V4L2_MBUS_DATA_ACTIVE_HIGH;
713 cfg->type = V4L2_MBUS_BT656;
714 }
459 715
460 return 0; 716 return 0;
461} 717}
@@ -465,139 +721,439 @@ static const struct v4l2_subdev_video_ops adv7180_video_ops = {
465 .querystd = adv7180_querystd, 721 .querystd = adv7180_querystd,
466 .g_input_status = adv7180_g_input_status, 722 .g_input_status = adv7180_g_input_status,
467 .s_routing = adv7180_s_routing, 723 .s_routing = adv7180_s_routing,
468 .enum_mbus_fmt = adv7180_enum_mbus_fmt,
469 .try_mbus_fmt = adv7180_mbus_fmt,
470 .g_mbus_fmt = adv7180_mbus_fmt,
471 .s_mbus_fmt = adv7180_mbus_fmt,
472 .g_mbus_config = adv7180_g_mbus_config, 724 .g_mbus_config = adv7180_g_mbus_config,
473}; 725};
474 726
727
475static const struct v4l2_subdev_core_ops adv7180_core_ops = { 728static const struct v4l2_subdev_core_ops adv7180_core_ops = {
476 .s_power = adv7180_s_power, 729 .s_power = adv7180_s_power,
477}; 730};
478 731
732static const struct v4l2_subdev_pad_ops adv7180_pad_ops = {
733 .enum_mbus_code = adv7180_enum_mbus_code,
734 .set_fmt = adv7180_set_pad_format,
735 .get_fmt = adv7180_get_pad_format,
736};
737
479static const struct v4l2_subdev_ops adv7180_ops = { 738static const struct v4l2_subdev_ops adv7180_ops = {
480 .core = &adv7180_core_ops, 739 .core = &adv7180_core_ops,
481 .video = &adv7180_video_ops, 740 .video = &adv7180_video_ops,
741 .pad = &adv7180_pad_ops,
482}; 742};
483 743
484static irqreturn_t adv7180_irq(int irq, void *devid) 744static irqreturn_t adv7180_irq(int irq, void *devid)
485{ 745{
486 struct adv7180_state *state = devid; 746 struct adv7180_state *state = devid;
487 struct i2c_client *client = v4l2_get_subdevdata(&state->sd);
488 u8 isr3; 747 u8 isr3;
489 748
490 mutex_lock(&state->mutex); 749 mutex_lock(&state->mutex);
491 i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 750 isr3 = adv7180_read(state, ADV7180_REG_ISR3);
492 ADV7180_ADI_CTRL_IRQ_SPACE);
493 isr3 = i2c_smbus_read_byte_data(client, ADV7180_ISR3_ADI);
494 /* clear */ 751 /* clear */
495 i2c_smbus_write_byte_data(client, ADV7180_ICR3_ADI, isr3); 752 adv7180_write(state, ADV7180_REG_ICR3, isr3);
496 i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 0);
497 753
498 if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect) 754 if (isr3 & ADV7180_IRQ3_AD_CHANGE && state->autodetect)
499 __adv7180_status(client, NULL, &state->curr_norm); 755 __adv7180_status(state, NULL, &state->curr_norm);
500 mutex_unlock(&state->mutex); 756 mutex_unlock(&state->mutex);
501 757
502 return IRQ_HANDLED; 758 return IRQ_HANDLED;
503} 759}
504 760
505static int init_device(struct i2c_client *client, struct adv7180_state *state) 761static int adv7180_init(struct adv7180_state *state)
506{ 762{
507 int ret; 763 int ret;
508 764
509 /* Initialize adv7180 */
510 /* Enable autodetection */
511 if (state->autodetect) {
512 ret =
513 i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
514 ADV7180_INPUT_CONTROL_AD_PAL_BG_NTSC_J_SECAM
515 | state->input);
516 if (ret < 0)
517 return ret;
518
519 ret =
520 i2c_smbus_write_byte_data(client,
521 ADV7180_AUTODETECT_ENABLE_REG,
522 ADV7180_AUTODETECT_DEFAULT);
523 if (ret < 0)
524 return ret;
525 } else {
526 ret = v4l2_std_to_adv7180(state->curr_norm);
527 if (ret < 0)
528 return ret;
529
530 ret =
531 i2c_smbus_write_byte_data(client, ADV7180_INPUT_CONTROL_REG,
532 ret | state->input);
533 if (ret < 0)
534 return ret;
535
536 }
537 /* ITU-R BT.656-4 compatible */ 765 /* ITU-R BT.656-4 compatible */
538 ret = i2c_smbus_write_byte_data(client, 766 ret = adv7180_write(state, ADV7180_REG_EXTENDED_OUTPUT_CONTROL,
539 ADV7180_EXTENDED_OUTPUT_CONTROL_REG,
540 ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS); 767 ADV7180_EXTENDED_OUTPUT_CONTROL_NTSCDIS);
541 if (ret < 0) 768 if (ret < 0)
542 return ret; 769 return ret;
543 770
544 /* Manually set V bit end position in NTSC mode */ 771 /* Manually set V bit end position in NTSC mode */
545 ret = i2c_smbus_write_byte_data(client, 772 return adv7180_write(state, ADV7180_REG_NTSC_V_BIT_END,
546 ADV7180_NTSC_V_BIT_END_REG,
547 ADV7180_NTSC_V_BIT_END_MANUAL_NVEND); 773 ADV7180_NTSC_V_BIT_END_MANUAL_NVEND);
774}
775
776static int adv7180_set_std(struct adv7180_state *state, unsigned int std)
777{
778 return adv7180_write(state, ADV7180_REG_INPUT_CONTROL,
779 (std << 4) | state->input);
780}
781
782static int adv7180_select_input(struct adv7180_state *state, unsigned int input)
783{
784 int ret;
785
786 ret = adv7180_read(state, ADV7180_REG_INPUT_CONTROL);
548 if (ret < 0) 787 if (ret < 0)
549 return ret; 788 return ret;
550 789
551 /* read current norm */ 790 ret &= ~ADV7180_INPUT_CONTROL_INSEL_MASK;
552 __adv7180_status(client, NULL, &state->curr_norm); 791 ret |= input;
792 return adv7180_write(state, ADV7180_REG_INPUT_CONTROL, ret);
793}
553 794
554 /* register for interrupts */ 795static int adv7182_init(struct adv7180_state *state)
555 if (state->irq > 0) { 796{
556 ret = request_threaded_irq(state->irq, NULL, adv7180_irq, 797 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
557 IRQF_ONESHOT, KBUILD_MODNAME, state); 798 adv7180_write(state, ADV7180_REG_CSI_SLAVE_ADDR,
558 if (ret) 799 ADV7180_DEFAULT_CSI_I2C_ADDR << 1);
559 return ret; 800
801 if (state->chip_info->flags & ADV7180_FLAG_I2P)
802 adv7180_write(state, ADV7180_REG_VPP_SLAVE_ADDR,
803 ADV7180_DEFAULT_VPP_I2C_ADDR << 1);
804
805 if (state->chip_info->flags & ADV7180_FLAG_V2) {
806 /* ADI recommended writes for improved video quality */
807 adv7180_write(state, 0x0080, 0x51);
808 adv7180_write(state, 0x0081, 0x51);
809 adv7180_write(state, 0x0082, 0x68);
810 }
560 811
561 ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG, 812 /* ADI required writes */
562 ADV7180_ADI_CTRL_IRQ_SPACE); 813 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
563 if (ret < 0) 814 adv7180_write(state, 0x0003, 0x4e);
564 goto err; 815 adv7180_write(state, 0x0004, 0x57);
816 adv7180_write(state, 0x001d, 0xc0);
817 } else {
818 if (state->chip_info->flags & ADV7180_FLAG_V2)
819 adv7180_write(state, 0x0004, 0x17);
820 else
821 adv7180_write(state, 0x0004, 0x07);
822 adv7180_write(state, 0x0003, 0x0c);
823 adv7180_write(state, 0x001d, 0x40);
824 }
825
826 adv7180_write(state, 0x0013, 0x00);
827
828 return 0;
829}
830
831static int adv7182_set_std(struct adv7180_state *state, unsigned int std)
832{
833 return adv7180_write(state, ADV7182_REG_INPUT_VIDSEL, std << 4);
834}
835
836enum adv7182_input_type {
837 ADV7182_INPUT_TYPE_CVBS,
838 ADV7182_INPUT_TYPE_DIFF_CVBS,
839 ADV7182_INPUT_TYPE_SVIDEO,
840 ADV7182_INPUT_TYPE_YPBPR,
841};
842
843static enum adv7182_input_type adv7182_get_input_type(unsigned int input)
844{
845 switch (input) {
846 case ADV7182_INPUT_CVBS_AIN1:
847 case ADV7182_INPUT_CVBS_AIN2:
848 case ADV7182_INPUT_CVBS_AIN3:
849 case ADV7182_INPUT_CVBS_AIN4:
850 case ADV7182_INPUT_CVBS_AIN5:
851 case ADV7182_INPUT_CVBS_AIN6:
852 case ADV7182_INPUT_CVBS_AIN7:
853 case ADV7182_INPUT_CVBS_AIN8:
854 return ADV7182_INPUT_TYPE_CVBS;
855 case ADV7182_INPUT_SVIDEO_AIN1_AIN2:
856 case ADV7182_INPUT_SVIDEO_AIN3_AIN4:
857 case ADV7182_INPUT_SVIDEO_AIN5_AIN6:
858 case ADV7182_INPUT_SVIDEO_AIN7_AIN8:
859 return ADV7182_INPUT_TYPE_SVIDEO;
860 case ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3:
861 case ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6:
862 return ADV7182_INPUT_TYPE_YPBPR;
863 case ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2:
864 case ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4:
865 case ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6:
866 case ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8:
867 return ADV7182_INPUT_TYPE_DIFF_CVBS;
868 default: /* Will never happen */
869 return 0;
870 }
871}
872
873/* ADI recommended writes to registers 0x52, 0x53, 0x54 */
874static unsigned int adv7182_lbias_settings[][3] = {
875 [ADV7182_INPUT_TYPE_CVBS] = { 0xCB, 0x4E, 0x80 },
876 [ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 },
877 [ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 },
878 [ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 },
879};
880
881static unsigned int adv7280_lbias_settings[][3] = {
882 [ADV7182_INPUT_TYPE_CVBS] = { 0xCD, 0x4E, 0x80 },
883 [ADV7182_INPUT_TYPE_DIFF_CVBS] = { 0xC0, 0x4E, 0x80 },
884 [ADV7182_INPUT_TYPE_SVIDEO] = { 0x0B, 0xCE, 0x80 },
885 [ADV7182_INPUT_TYPE_YPBPR] = { 0x0B, 0x4E, 0xC0 },
886};
887
888static int adv7182_select_input(struct adv7180_state *state, unsigned int input)
889{
890 enum adv7182_input_type input_type;
891 unsigned int *lbias;
892 unsigned int i;
893 int ret;
894
895 ret = adv7180_write(state, ADV7180_REG_INPUT_CONTROL, input);
896 if (ret)
897 return ret;
898
899 /* Reset clamp circuitry - ADI recommended writes */
900 adv7180_write(state, 0x809c, 0x00);
901 adv7180_write(state, 0x809c, 0xff);
902
903 input_type = adv7182_get_input_type(input);
904
905 switch (input_type) {
906 case ADV7182_INPUT_TYPE_CVBS:
907 case ADV7182_INPUT_TYPE_DIFF_CVBS:
908 /* ADI recommends to use the SH1 filter */
909 adv7180_write(state, 0x0017, 0x41);
910 break;
911 default:
912 adv7180_write(state, 0x0017, 0x01);
913 break;
914 }
915
916 if (state->chip_info->flags & ADV7180_FLAG_V2)
917 lbias = adv7280_lbias_settings[input_type];
918 else
919 lbias = adv7182_lbias_settings[input_type];
920
921 for (i = 0; i < ARRAY_SIZE(adv7182_lbias_settings[0]); i++)
922 adv7180_write(state, 0x0052 + i, lbias[i]);
923
924 if (input_type == ADV7182_INPUT_TYPE_DIFF_CVBS) {
925 /* ADI required writes to make differential CVBS work */
926 adv7180_write(state, 0x005f, 0xa8);
927 adv7180_write(state, 0x005a, 0x90);
928 adv7180_write(state, 0x0060, 0xb0);
929 adv7180_write(state, 0x80b6, 0x08);
930 adv7180_write(state, 0x80c0, 0xa0);
931 } else {
932 adv7180_write(state, 0x005f, 0xf0);
933 adv7180_write(state, 0x005a, 0xd0);
934 adv7180_write(state, 0x0060, 0x10);
935 adv7180_write(state, 0x80b6, 0x9c);
936 adv7180_write(state, 0x80c0, 0x00);
937 }
938
939 return 0;
940}
941
942static const struct adv7180_chip_info adv7180_info = {
943 .flags = ADV7180_FLAG_RESET_POWERED,
944 /* We cannot discriminate between LQFP and 40-pin LFCSP, so accept
945 * all inputs and let the card driver take care of validation
946 */
947 .valid_input_mask = BIT(ADV7180_INPUT_CVBS_AIN1) |
948 BIT(ADV7180_INPUT_CVBS_AIN2) |
949 BIT(ADV7180_INPUT_CVBS_AIN3) |
950 BIT(ADV7180_INPUT_CVBS_AIN4) |
951 BIT(ADV7180_INPUT_CVBS_AIN5) |
952 BIT(ADV7180_INPUT_CVBS_AIN6) |
953 BIT(ADV7180_INPUT_SVIDEO_AIN1_AIN2) |
954 BIT(ADV7180_INPUT_SVIDEO_AIN3_AIN4) |
955 BIT(ADV7180_INPUT_SVIDEO_AIN5_AIN6) |
956 BIT(ADV7180_INPUT_YPRPB_AIN1_AIN2_AIN3) |
957 BIT(ADV7180_INPUT_YPRPB_AIN4_AIN5_AIN6),
958 .init = adv7180_init,
959 .set_std = adv7180_set_std,
960 .select_input = adv7180_select_input,
961};
962
963static const struct adv7180_chip_info adv7182_info = {
964 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
965 BIT(ADV7182_INPUT_CVBS_AIN2) |
966 BIT(ADV7182_INPUT_CVBS_AIN3) |
967 BIT(ADV7182_INPUT_CVBS_AIN4) |
968 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
969 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
970 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
971 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
972 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4),
973 .init = adv7182_init,
974 .set_std = adv7182_set_std,
975 .select_input = adv7182_select_input,
976};
977
978static const struct adv7180_chip_info adv7280_info = {
979 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P,
980 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
981 BIT(ADV7182_INPUT_CVBS_AIN2) |
982 BIT(ADV7182_INPUT_CVBS_AIN3) |
983 BIT(ADV7182_INPUT_CVBS_AIN4) |
984 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
985 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
986 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3),
987 .init = adv7182_init,
988 .set_std = adv7182_set_std,
989 .select_input = adv7182_select_input,
990};
991
992static const struct adv7180_chip_info adv7280_m_info = {
993 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P,
994 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
995 BIT(ADV7182_INPUT_CVBS_AIN2) |
996 BIT(ADV7182_INPUT_CVBS_AIN3) |
997 BIT(ADV7182_INPUT_CVBS_AIN4) |
998 BIT(ADV7182_INPUT_CVBS_AIN5) |
999 BIT(ADV7182_INPUT_CVBS_AIN6) |
1000 BIT(ADV7182_INPUT_CVBS_AIN7) |
1001 BIT(ADV7182_INPUT_CVBS_AIN8) |
1002 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1003 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
1004 BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) |
1005 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1006 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
1007 BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6),
1008 .init = adv7182_init,
1009 .set_std = adv7182_set_std,
1010 .select_input = adv7182_select_input,
1011};
1012
1013static const struct adv7180_chip_info adv7281_info = {
1014 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
1015 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
1016 BIT(ADV7182_INPUT_CVBS_AIN2) |
1017 BIT(ADV7182_INPUT_CVBS_AIN7) |
1018 BIT(ADV7182_INPUT_CVBS_AIN8) |
1019 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1020 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1021 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
1022 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
1023 .init = adv7182_init,
1024 .set_std = adv7182_set_std,
1025 .select_input = adv7182_select_input,
1026};
1027
1028static const struct adv7180_chip_info adv7281_m_info = {
1029 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
1030 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
1031 BIT(ADV7182_INPUT_CVBS_AIN2) |
1032 BIT(ADV7182_INPUT_CVBS_AIN3) |
1033 BIT(ADV7182_INPUT_CVBS_AIN4) |
1034 BIT(ADV7182_INPUT_CVBS_AIN7) |
1035 BIT(ADV7182_INPUT_CVBS_AIN8) |
1036 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1037 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
1038 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1039 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
1040 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
1041 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
1042 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
1043 .init = adv7182_init,
1044 .set_std = adv7182_set_std,
1045 .select_input = adv7182_select_input,
1046};
565 1047
1048static const struct adv7180_chip_info adv7281_ma_info = {
1049 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2,
1050 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
1051 BIT(ADV7182_INPUT_CVBS_AIN2) |
1052 BIT(ADV7182_INPUT_CVBS_AIN3) |
1053 BIT(ADV7182_INPUT_CVBS_AIN4) |
1054 BIT(ADV7182_INPUT_CVBS_AIN5) |
1055 BIT(ADV7182_INPUT_CVBS_AIN6) |
1056 BIT(ADV7182_INPUT_CVBS_AIN7) |
1057 BIT(ADV7182_INPUT_CVBS_AIN8) |
1058 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1059 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
1060 BIT(ADV7182_INPUT_SVIDEO_AIN5_AIN6) |
1061 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1062 BIT(ADV7182_INPUT_YPRPB_AIN1_AIN2_AIN3) |
1063 BIT(ADV7182_INPUT_YPRPB_AIN4_AIN5_AIN6) |
1064 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
1065 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
1066 BIT(ADV7182_INPUT_DIFF_CVBS_AIN5_AIN6) |
1067 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
1068 .init = adv7182_init,
1069 .set_std = adv7182_set_std,
1070 .select_input = adv7182_select_input,
1071};
1072
1073static const struct adv7180_chip_info adv7282_info = {
1074 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_I2P,
1075 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
1076 BIT(ADV7182_INPUT_CVBS_AIN2) |
1077 BIT(ADV7182_INPUT_CVBS_AIN7) |
1078 BIT(ADV7182_INPUT_CVBS_AIN8) |
1079 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1080 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1081 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
1082 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
1083 .init = adv7182_init,
1084 .set_std = adv7182_set_std,
1085 .select_input = adv7182_select_input,
1086};
1087
1088static const struct adv7180_chip_info adv7282_m_info = {
1089 .flags = ADV7180_FLAG_V2 | ADV7180_FLAG_MIPI_CSI2 | ADV7180_FLAG_I2P,
1090 .valid_input_mask = BIT(ADV7182_INPUT_CVBS_AIN1) |
1091 BIT(ADV7182_INPUT_CVBS_AIN2) |
1092 BIT(ADV7182_INPUT_CVBS_AIN3) |
1093 BIT(ADV7182_INPUT_CVBS_AIN4) |
1094 BIT(ADV7182_INPUT_CVBS_AIN7) |
1095 BIT(ADV7182_INPUT_CVBS_AIN8) |
1096 BIT(ADV7182_INPUT_SVIDEO_AIN1_AIN2) |
1097 BIT(ADV7182_INPUT_SVIDEO_AIN3_AIN4) |
1098 BIT(ADV7182_INPUT_SVIDEO_AIN7_AIN8) |
1099 BIT(ADV7182_INPUT_DIFF_CVBS_AIN1_AIN2) |
1100 BIT(ADV7182_INPUT_DIFF_CVBS_AIN3_AIN4) |
1101 BIT(ADV7182_INPUT_DIFF_CVBS_AIN7_AIN8),
1102 .init = adv7182_init,
1103 .set_std = adv7182_set_std,
1104 .select_input = adv7182_select_input,
1105};
1106
1107static int init_device(struct adv7180_state *state)
1108{
1109 int ret;
1110
1111 mutex_lock(&state->mutex);
1112
1113 adv7180_write(state, ADV7180_REG_PWR_MAN, ADV7180_PWR_MAN_RES);
1114 usleep_range(2000, 10000);
1115
1116 ret = state->chip_info->init(state);
1117 if (ret)
1118 goto out_unlock;
1119
1120 ret = adv7180_program_std(state);
1121 if (ret)
1122 goto out_unlock;
1123
1124 adv7180_set_field_mode(state);
1125
1126 /* register for interrupts */
1127 if (state->irq > 0) {
566 /* config the Interrupt pin to be active low */ 1128 /* config the Interrupt pin to be active low */
567 ret = i2c_smbus_write_byte_data(client, ADV7180_ICONF1_ADI, 1129 ret = adv7180_write(state, ADV7180_REG_ICONF1,
568 ADV7180_ICONF1_ACTIVE_LOW | 1130 ADV7180_ICONF1_ACTIVE_LOW |
569 ADV7180_ICONF1_PSYNC_ONLY); 1131 ADV7180_ICONF1_PSYNC_ONLY);
570 if (ret < 0) 1132 if (ret < 0)
571 goto err; 1133 goto out_unlock;
572 1134
573 ret = i2c_smbus_write_byte_data(client, ADV7180_IMR1_ADI, 0); 1135 ret = adv7180_write(state, ADV7180_REG_IMR1, 0);
574 if (ret < 0) 1136 if (ret < 0)
575 goto err; 1137 goto out_unlock;
576 1138
577 ret = i2c_smbus_write_byte_data(client, ADV7180_IMR2_ADI, 0); 1139 ret = adv7180_write(state, ADV7180_REG_IMR2, 0);
578 if (ret < 0) 1140 if (ret < 0)
579 goto err; 1141 goto out_unlock;
580 1142
581 /* enable AD change interrupts interrupts */ 1143 /* enable AD change interrupts interrupts */
582 ret = i2c_smbus_write_byte_data(client, ADV7180_IMR3_ADI, 1144 ret = adv7180_write(state, ADV7180_REG_IMR3,
583 ADV7180_IRQ3_AD_CHANGE); 1145 ADV7180_IRQ3_AD_CHANGE);
584 if (ret < 0) 1146 if (ret < 0)
585 goto err; 1147 goto out_unlock;
586 1148
587 ret = i2c_smbus_write_byte_data(client, ADV7180_IMR4_ADI, 0); 1149 ret = adv7180_write(state, ADV7180_REG_IMR4, 0);
588 if (ret < 0) 1150 if (ret < 0)
589 goto err; 1151 goto out_unlock;
590
591 ret = i2c_smbus_write_byte_data(client, ADV7180_ADI_CTRL_REG,
592 0);
593 if (ret < 0)
594 goto err;
595 } 1152 }
596 1153
597 return 0; 1154out_unlock:
1155 mutex_unlock(&state->mutex);
598 1156
599err:
600 free_irq(state->irq, state);
601 return ret; 1157 return ret;
602} 1158}
603 1159
@@ -616,26 +1172,63 @@ static int adv7180_probe(struct i2c_client *client,
616 client->addr, client->adapter->name); 1172 client->addr, client->adapter->name);
617 1173
618 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL); 1174 state = devm_kzalloc(&client->dev, sizeof(*state), GFP_KERNEL);
619 if (state == NULL) { 1175 if (state == NULL)
620 ret = -ENOMEM; 1176 return -ENOMEM;
621 goto err; 1177
1178 state->client = client;
1179 state->field = V4L2_FIELD_INTERLACED;
1180 state->chip_info = (struct adv7180_chip_info *)id->driver_data;
1181
1182 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2) {
1183 state->csi_client = i2c_new_dummy(client->adapter,
1184 ADV7180_DEFAULT_CSI_I2C_ADDR);
1185 if (!state->csi_client)
1186 return -ENOMEM;
1187 }
1188
1189 if (state->chip_info->flags & ADV7180_FLAG_I2P) {
1190 state->vpp_client = i2c_new_dummy(client->adapter,
1191 ADV7180_DEFAULT_VPP_I2C_ADDR);
1192 if (!state->vpp_client) {
1193 ret = -ENOMEM;
1194 goto err_unregister_csi_client;
1195 }
622 } 1196 }
623 1197
624 state->irq = client->irq; 1198 state->irq = client->irq;
625 mutex_init(&state->mutex); 1199 mutex_init(&state->mutex);
626 state->autodetect = true; 1200 state->autodetect = true;
627 state->powered = true; 1201 if (state->chip_info->flags & ADV7180_FLAG_RESET_POWERED)
1202 state->powered = true;
1203 else
1204 state->powered = false;
628 state->input = 0; 1205 state->input = 0;
629 sd = &state->sd; 1206 sd = &state->sd;
630 v4l2_i2c_subdev_init(sd, client, &adv7180_ops); 1207 v4l2_i2c_subdev_init(sd, client, &adv7180_ops);
1208 sd->flags = V4L2_SUBDEV_FL_HAS_DEVNODE;
631 1209
632 ret = adv7180_init_controls(state); 1210 ret = adv7180_init_controls(state);
633 if (ret) 1211 if (ret)
634 goto err_unreg_subdev; 1212 goto err_unregister_vpp_client;
635 ret = init_device(client, state); 1213
1214 state->pad.flags = MEDIA_PAD_FL_SOURCE;
1215 sd->entity.flags |= MEDIA_ENT_T_V4L2_SUBDEV_DECODER;
1216 ret = media_entity_init(&sd->entity, 1, &state->pad, 0);
636 if (ret) 1217 if (ret)
637 goto err_free_ctrl; 1218 goto err_free_ctrl;
638 1219
1220 ret = init_device(state);
1221 if (ret)
1222 goto err_media_entity_cleanup;
1223
1224 if (state->irq) {
1225 ret = request_threaded_irq(client->irq, NULL, adv7180_irq,
1226 IRQF_ONESHOT | IRQF_TRIGGER_FALLING,
1227 KBUILD_MODNAME, state);
1228 if (ret)
1229 goto err_media_entity_cleanup;
1230 }
1231
639 ret = v4l2_async_register_subdev(sd); 1232 ret = v4l2_async_register_subdev(sd);
640 if (ret) 1233 if (ret)
641 goto err_free_irq; 1234 goto err_free_irq;
@@ -645,11 +1238,17 @@ static int adv7180_probe(struct i2c_client *client,
645err_free_irq: 1238err_free_irq:
646 if (state->irq > 0) 1239 if (state->irq > 0)
647 free_irq(client->irq, state); 1240 free_irq(client->irq, state);
1241err_media_entity_cleanup:
1242 media_entity_cleanup(&sd->entity);
648err_free_ctrl: 1243err_free_ctrl:
649 adv7180_exit_controls(state); 1244 adv7180_exit_controls(state);
650err_unreg_subdev: 1245err_unregister_vpp_client:
1246 if (state->chip_info->flags & ADV7180_FLAG_I2P)
1247 i2c_unregister_device(state->vpp_client);
1248err_unregister_csi_client:
1249 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
1250 i2c_unregister_device(state->csi_client);
651 mutex_destroy(&state->mutex); 1251 mutex_destroy(&state->mutex);
652err:
653 return ret; 1252 return ret;
654} 1253}
655 1254
@@ -663,15 +1262,32 @@ static int adv7180_remove(struct i2c_client *client)
663 if (state->irq > 0) 1262 if (state->irq > 0)
664 free_irq(client->irq, state); 1263 free_irq(client->irq, state);
665 1264
1265 media_entity_cleanup(&sd->entity);
666 adv7180_exit_controls(state); 1266 adv7180_exit_controls(state);
1267
1268 if (state->chip_info->flags & ADV7180_FLAG_I2P)
1269 i2c_unregister_device(state->vpp_client);
1270 if (state->chip_info->flags & ADV7180_FLAG_MIPI_CSI2)
1271 i2c_unregister_device(state->csi_client);
1272
667 mutex_destroy(&state->mutex); 1273 mutex_destroy(&state->mutex);
1274
668 return 0; 1275 return 0;
669} 1276}
670 1277
671static const struct i2c_device_id adv7180_id[] = { 1278static const struct i2c_device_id adv7180_id[] = {
672 {KBUILD_MODNAME, 0}, 1279 { "adv7180", (kernel_ulong_t)&adv7180_info },
1280 { "adv7182", (kernel_ulong_t)&adv7182_info },
1281 { "adv7280", (kernel_ulong_t)&adv7280_info },
1282 { "adv7280-m", (kernel_ulong_t)&adv7280_m_info },
1283 { "adv7281", (kernel_ulong_t)&adv7281_info },
1284 { "adv7281-m", (kernel_ulong_t)&adv7281_m_info },
1285 { "adv7281-ma", (kernel_ulong_t)&adv7281_ma_info },
1286 { "adv7282", (kernel_ulong_t)&adv7282_info },
1287 { "adv7282-m", (kernel_ulong_t)&adv7282_m_info },
673 {}, 1288 {},
674}; 1289};
1290MODULE_DEVICE_TABLE(i2c, adv7180_id);
675 1291
676#ifdef CONFIG_PM_SLEEP 1292#ifdef CONFIG_PM_SLEEP
677static int adv7180_suspend(struct device *dev) 1293static int adv7180_suspend(struct device *dev)
@@ -680,7 +1296,7 @@ static int adv7180_suspend(struct device *dev)
680 struct v4l2_subdev *sd = i2c_get_clientdata(client); 1296 struct v4l2_subdev *sd = i2c_get_clientdata(client);
681 struct adv7180_state *state = to_state(sd); 1297 struct adv7180_state *state = to_state(sd);
682 1298
683 return adv7180_set_power(state, client, false); 1299 return adv7180_set_power(state, false);
684} 1300}
685 1301
686static int adv7180_resume(struct device *dev) 1302static int adv7180_resume(struct device *dev)
@@ -690,14 +1306,14 @@ static int adv7180_resume(struct device *dev)
690 struct adv7180_state *state = to_state(sd); 1306 struct adv7180_state *state = to_state(sd);
691 int ret; 1307 int ret;
692 1308
693 if (state->powered) { 1309 ret = init_device(state);
694 ret = adv7180_set_power(state, client, true);
695 if (ret)
696 return ret;
697 }
698 ret = init_device(client, state);
699 if (ret < 0) 1310 if (ret < 0)
700 return ret; 1311 return ret;
1312
1313 ret = adv7180_set_power(state, state->powered);
1314 if (ret)
1315 return ret;
1316
701 return 0; 1317 return 0;
702} 1318}
703 1319
@@ -708,8 +1324,6 @@ static SIMPLE_DEV_PM_OPS(adv7180_pm_ops, adv7180_suspend, adv7180_resume);
708#define ADV7180_PM_OPS NULL 1324#define ADV7180_PM_OPS NULL
709#endif 1325#endif
710 1326
711MODULE_DEVICE_TABLE(i2c, adv7180_id);
712
713static struct i2c_driver adv7180_driver = { 1327static struct i2c_driver adv7180_driver = {
714 .driver = { 1328 .driver = {
715 .owner = THIS_MODULE, 1329 .owner = THIS_MODULE,
diff --git a/drivers/media/i2c/adv7604.c b/drivers/media/i2c/adv7604.c
index e43dd2e2a38a..d228b7c82310 100644
--- a/drivers/media/i2c/adv7604.c
+++ b/drivers/media/i2c/adv7604.c
@@ -333,21 +333,11 @@ static inline struct adv7604_state *to_state(struct v4l2_subdev *sd)
333 return container_of(sd, struct adv7604_state, sd); 333 return container_of(sd, struct adv7604_state, sd);
334} 334}
335 335
336static inline unsigned hblanking(const struct v4l2_bt_timings *t)
337{
338 return V4L2_DV_BT_BLANKING_WIDTH(t);
339}
340
341static inline unsigned htotal(const struct v4l2_bt_timings *t) 336static inline unsigned htotal(const struct v4l2_bt_timings *t)
342{ 337{
343 return V4L2_DV_BT_FRAME_WIDTH(t); 338 return V4L2_DV_BT_FRAME_WIDTH(t);
344} 339}
345 340
346static inline unsigned vblanking(const struct v4l2_bt_timings *t)
347{
348 return V4L2_DV_BT_BLANKING_HEIGHT(t);
349}
350
351static inline unsigned vtotal(const struct v4l2_bt_timings *t) 341static inline unsigned vtotal(const struct v4l2_bt_timings *t)
352{ 342{
353 return V4L2_DV_BT_FRAME_HEIGHT(t); 343 return V4L2_DV_BT_FRAME_HEIGHT(t);
@@ -466,11 +456,6 @@ static inline int cec_write(struct v4l2_subdev *sd, u8 reg, u8 val)
466 return adv_smbus_write_byte_data(state, ADV7604_PAGE_CEC, reg, val); 456 return adv_smbus_write_byte_data(state, ADV7604_PAGE_CEC, reg, val);
467} 457}
468 458
469static inline int cec_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8 val)
470{
471 return cec_write(sd, reg, (cec_read(sd, reg) & ~mask) | val);
472}
473
474static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg) 459static inline int infoframe_read(struct v4l2_subdev *sd, u8 reg)
475{ 460{
476 struct adv7604_state *state = to_state(sd); 461 struct adv7604_state *state = to_state(sd);
@@ -486,34 +471,6 @@ static inline int infoframe_write(struct v4l2_subdev *sd, u8 reg, u8 val)
486 reg, val); 471 reg, val);
487} 472}
488 473
489static inline int esdp_read(struct v4l2_subdev *sd, u8 reg)
490{
491 struct adv7604_state *state = to_state(sd);
492
493 return adv_smbus_read_byte_data(state, ADV7604_PAGE_ESDP, reg);
494}
495
496static inline int esdp_write(struct v4l2_subdev *sd, u8 reg, u8 val)
497{
498 struct adv7604_state *state = to_state(sd);
499
500 return adv_smbus_write_byte_data(state, ADV7604_PAGE_ESDP, reg, val);
501}
502
503static inline int dpp_read(struct v4l2_subdev *sd, u8 reg)
504{
505 struct adv7604_state *state = to_state(sd);
506
507 return adv_smbus_read_byte_data(state, ADV7604_PAGE_DPP, reg);
508}
509
510static inline int dpp_write(struct v4l2_subdev *sd, u8 reg, u8 val)
511{
512 struct adv7604_state *state = to_state(sd);
513
514 return adv_smbus_write_byte_data(state, ADV7604_PAGE_DPP, reg, val);
515}
516
517static inline int afe_read(struct v4l2_subdev *sd, u8 reg) 474static inline int afe_read(struct v4l2_subdev *sd, u8 reg)
518{ 475{
519 struct adv7604_state *state = to_state(sd); 476 struct adv7604_state *state = to_state(sd);
@@ -561,32 +518,6 @@ static inline int edid_write(struct v4l2_subdev *sd, u8 reg, u8 val)
561 return adv_smbus_write_byte_data(state, ADV7604_PAGE_EDID, reg, val); 518 return adv_smbus_write_byte_data(state, ADV7604_PAGE_EDID, reg, val);
562} 519}
563 520
564static inline int edid_read_block(struct v4l2_subdev *sd, unsigned len, u8 *val)
565{
566 struct adv7604_state *state = to_state(sd);
567 struct i2c_client *client = state->i2c_clients[ADV7604_PAGE_EDID];
568 u8 msgbuf0[1] = { 0 };
569 u8 msgbuf1[256];
570 struct i2c_msg msg[2] = {
571 {
572 .addr = client->addr,
573 .len = 1,
574 .buf = msgbuf0
575 },
576 {
577 .addr = client->addr,
578 .flags = I2C_M_RD,
579 .len = len,
580 .buf = msgbuf1
581 },
582 };
583
584 if (i2c_transfer(client->adapter, msg, 2) < 0)
585 return -EIO;
586 memcpy(val, msgbuf1, len);
587 return 0;
588}
589
590static inline int edid_write_block(struct v4l2_subdev *sd, 521static inline int edid_write_block(struct v4l2_subdev *sd,
591 unsigned len, const u8 *val) 522 unsigned len, const u8 *val)
592{ 523{
@@ -652,13 +583,6 @@ static inline int hdmi_write_clr_set(struct v4l2_subdev *sd, u8 reg, u8 mask, u8
652 return hdmi_write(sd, reg, (hdmi_read(sd, reg) & ~mask) | val); 583 return hdmi_write(sd, reg, (hdmi_read(sd, reg) & ~mask) | val);
653} 584}
654 585
655static inline int test_read(struct v4l2_subdev *sd, u8 reg)
656{
657 struct adv7604_state *state = to_state(sd);
658
659 return adv_smbus_read_byte_data(state, ADV7604_PAGE_TEST, reg);
660}
661
662static inline int test_write(struct v4l2_subdev *sd, u8 reg, u8 val) 586static inline int test_write(struct v4l2_subdev *sd, u8 reg, u8 val)
663{ 587{
664 struct adv7604_state *state = to_state(sd); 588 struct adv7604_state *state = to_state(sd);
diff --git a/drivers/media/i2c/adv7842.c b/drivers/media/i2c/adv7842.c
index 75d26dfd0939..7c215ee142c4 100644
--- a/drivers/media/i2c/adv7842.c
+++ b/drivers/media/i2c/adv7842.c
@@ -38,6 +38,7 @@
38#include <linux/videodev2.h> 38#include <linux/videodev2.h>
39#include <linux/workqueue.h> 39#include <linux/workqueue.h>
40#include <linux/v4l2-dv-timings.h> 40#include <linux/v4l2-dv-timings.h>
41#include <linux/hdmi.h>
41#include <media/v4l2-device.h> 42#include <media/v4l2-device.h>
42#include <media/v4l2-ctrls.h> 43#include <media/v4l2-ctrls.h>
43#include <media/v4l2-dv-timings.h> 44#include <media/v4l2-dv-timings.h>
@@ -220,21 +221,11 @@ static inline struct v4l2_subdev *to_sd(struct v4l2_ctrl *ctrl)
220 return &container_of(ctrl->handler, struct adv7842_state, hdl)->sd; 221 return &container_of(ctrl->handler, struct adv7842_state, hdl)->sd;
221} 222}
222 223
223static inline unsigned hblanking(const struct v4l2_bt_timings *t)
224{
225 return V4L2_DV_BT_BLANKING_WIDTH(t);
226}
227
228static inline unsigned htotal(const struct v4l2_bt_timings *t) 224static inline unsigned htotal(const struct v4l2_bt_timings *t)
229{ 225{
230 return V4L2_DV_BT_FRAME_WIDTH(t); 226 return V4L2_DV_BT_FRAME_WIDTH(t);
231} 227}
232 228
233static inline unsigned vblanking(const struct v4l2_bt_timings *t)
234{
235 return V4L2_DV_BT_BLANKING_HEIGHT(t);
236}
237
238static inline unsigned vtotal(const struct v4l2_bt_timings *t) 229static inline unsigned vtotal(const struct v4l2_bt_timings *t)
239{ 230{
240 return V4L2_DV_BT_FRAME_HEIGHT(t); 231 return V4L2_DV_BT_FRAME_HEIGHT(t);
@@ -2108,149 +2099,65 @@ static int adv7842_set_edid(struct v4l2_subdev *sd, struct v4l2_edid *e)
2108 return err; 2099 return err;
2109} 2100}
2110 2101
2111/*********** avi info frame CEA-861-E **************/ 2102struct adv7842_cfg_read_infoframe {
2112/* TODO move to common library */ 2103 const char *desc;
2113 2104 u8 present_mask;
2114struct avi_info_frame { 2105 u8 head_addr;
2115 uint8_t f17; 2106 u8 payload_addr;
2116 uint8_t y10;
2117 uint8_t a0;
2118 uint8_t b10;
2119 uint8_t s10;
2120 uint8_t c10;
2121 uint8_t m10;
2122 uint8_t r3210;
2123 uint8_t itc;
2124 uint8_t ec210;
2125 uint8_t q10;
2126 uint8_t sc10;
2127 uint8_t f47;
2128 uint8_t vic;
2129 uint8_t yq10;
2130 uint8_t cn10;
2131 uint8_t pr3210;
2132 uint16_t etb;
2133 uint16_t sbb;
2134 uint16_t elb;
2135 uint16_t srb;
2136};
2137
2138static const char *y10_txt[4] = {
2139 "RGB",
2140 "YCbCr 4:2:2",
2141 "YCbCr 4:4:4",
2142 "Future",
2143};
2144
2145static const char *c10_txt[4] = {
2146 "No Data",
2147 "SMPTE 170M",
2148 "ITU-R 709",
2149 "Extended Colorimetry information valied",
2150};
2151
2152static const char *itc_txt[2] = {
2153 "No Data",
2154 "IT content",
2155};
2156
2157static const char *ec210_txt[8] = {
2158 "xvYCC601",
2159 "xvYCC709",
2160 "sYCC601",
2161 "AdobeYCC601",
2162 "AdobeRGB",
2163 "5 reserved",
2164 "6 reserved",
2165 "7 reserved",
2166}; 2107};
2167 2108
2168static const char *q10_txt[4] = { 2109static void log_infoframe(struct v4l2_subdev *sd, struct adv7842_cfg_read_infoframe *cri)
2169 "Default",
2170 "Limited Range",
2171 "Full Range",
2172 "Reserved",
2173};
2174
2175static void parse_avi_infoframe(struct v4l2_subdev *sd, uint8_t *buf,
2176 struct avi_info_frame *avi)
2177{
2178 avi->f17 = (buf[1] >> 7) & 0x1;
2179 avi->y10 = (buf[1] >> 5) & 0x3;
2180 avi->a0 = (buf[1] >> 4) & 0x1;
2181 avi->b10 = (buf[1] >> 2) & 0x3;
2182 avi->s10 = buf[1] & 0x3;
2183 avi->c10 = (buf[2] >> 6) & 0x3;
2184 avi->m10 = (buf[2] >> 4) & 0x3;
2185 avi->r3210 = buf[2] & 0xf;
2186 avi->itc = (buf[3] >> 7) & 0x1;
2187 avi->ec210 = (buf[3] >> 4) & 0x7;
2188 avi->q10 = (buf[3] >> 2) & 0x3;
2189 avi->sc10 = buf[3] & 0x3;
2190 avi->f47 = (buf[4] >> 7) & 0x1;
2191 avi->vic = buf[4] & 0x7f;
2192 avi->yq10 = (buf[5] >> 6) & 0x3;
2193 avi->cn10 = (buf[5] >> 4) & 0x3;
2194 avi->pr3210 = buf[5] & 0xf;
2195 avi->etb = buf[6] + 256*buf[7];
2196 avi->sbb = buf[8] + 256*buf[9];
2197 avi->elb = buf[10] + 256*buf[11];
2198 avi->srb = buf[12] + 256*buf[13];
2199}
2200
2201static void print_avi_infoframe(struct v4l2_subdev *sd)
2202{ 2110{
2203 int i; 2111 int i;
2204 uint8_t buf[14]; 2112 uint8_t buffer[32];
2205 u8 avi_len; 2113 union hdmi_infoframe frame;
2206 u8 avi_ver; 2114 u8 len;
2207 struct avi_info_frame avi; 2115 struct i2c_client *client = v4l2_get_subdevdata(sd);
2116 struct device *dev = &client->dev;
2208 2117
2209 if (!(hdmi_read(sd, 0x05) & 0x80)) { 2118 if (!(io_read(sd, 0x60) & cri->present_mask)) {
2210 v4l2_info(sd, "receive DVI-D signal (AVI infoframe not supported)\n"); 2119 v4l2_info(sd, "%s infoframe not received\n", cri->desc);
2211 return;
2212 }
2213 if (!(io_read(sd, 0x60) & 0x01)) {
2214 v4l2_info(sd, "AVI infoframe not received\n");
2215 return; 2120 return;
2216 } 2121 }
2217 2122
2218 if (io_read(sd, 0x88) & 0x10) { 2123 for (i = 0; i < 3; i++)
2219 v4l2_info(sd, "AVI infoframe checksum error has occurred earlier\n"); 2124 buffer[i] = infoframe_read(sd, cri->head_addr + i);
2220 io_write(sd, 0x8a, 0x10); /* clear AVI_INF_CKS_ERR_RAW */
2221 if (io_read(sd, 0x88) & 0x10) {
2222 v4l2_info(sd, "AVI infoframe checksum error still present\n");
2223 io_write(sd, 0x8a, 0x10); /* clear AVI_INF_CKS_ERR_RAW */
2224 }
2225 }
2226 2125
2227 avi_len = infoframe_read(sd, 0xe2); 2126 len = buffer[2] + 1;
2228 avi_ver = infoframe_read(sd, 0xe1);
2229 v4l2_info(sd, "AVI infoframe version %d (%d byte)\n",
2230 avi_ver, avi_len);
2231 2127
2232 if (avi_ver != 0x02) 2128 if (len + 3 > sizeof(buffer)) {
2129 v4l2_err(sd, "%s: invalid %s infoframe length %d\n", __func__, cri->desc, len);
2233 return; 2130 return;
2131 }
2132
2133 for (i = 0; i < len; i++)
2134 buffer[i + 3] = infoframe_read(sd, cri->payload_addr + i);
2234 2135
2235 for (i = 0; i < 14; i++) 2136 if (hdmi_infoframe_unpack(&frame, buffer) < 0) {
2236 buf[i] = infoframe_read(sd, i); 2137 v4l2_err(sd, "%s: unpack of %s infoframe failed\n", __func__, cri->desc);
2138 return;
2139 }
2237 2140
2238 v4l2_info(sd, "\t%02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x %02x\n", 2141 hdmi_infoframe_log(KERN_INFO, dev, &frame);
2239 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], buf[6], buf[7], 2142}
2240 buf[8], buf[9], buf[10], buf[11], buf[12], buf[13]);
2241 2143
2242 parse_avi_infoframe(sd, buf, &avi); 2144static void adv7842_log_infoframes(struct v4l2_subdev *sd)
2145{
2146 int i;
2147 struct adv7842_cfg_read_infoframe cri[] = {
2148 { "AVI", 0x01, 0xe0, 0x00 },
2149 { "Audio", 0x02, 0xe3, 0x1c },
2150 { "SDP", 0x04, 0xe6, 0x2a },
2151 { "Vendor", 0x10, 0xec, 0x54 }
2152 };
2243 2153
2244 if (avi.vic) 2154 if (!(hdmi_read(sd, 0x05) & 0x80)) {
2245 v4l2_info(sd, "\tVIC: %d\n", avi.vic); 2155 v4l2_info(sd, "receive DVI-D signal, no infoframes\n");
2246 if (avi.itc) 2156 return;
2247 v4l2_info(sd, "\t%s\n", itc_txt[avi.itc]); 2157 }
2248 2158
2249 if (avi.y10) 2159 for (i = 0; i < ARRAY_SIZE(cri); i++)
2250 v4l2_info(sd, "\t%s %s\n", y10_txt[avi.y10], !avi.c10 ? "" : 2160 log_infoframe(sd, &cri[i]);
2251 (avi.c10 == 0x3 ? ec210_txt[avi.ec210] : c10_txt[avi.c10]));
2252 else
2253 v4l2_info(sd, "\t%s %s\n", y10_txt[avi.y10], q10_txt[avi.q10]);
2254} 2161}
2255 2162
2256static const char * const prim_mode_txt[] = { 2163static const char * const prim_mode_txt[] = {
@@ -2464,7 +2371,8 @@ static int adv7842_cp_log_status(struct v4l2_subdev *sd)
2464 v4l2_info(sd, "Deep color mode: %s\n", 2371 v4l2_info(sd, "Deep color mode: %s\n",
2465 deep_color_mode_txt[hdmi_read(sd, 0x0b) >> 6]); 2372 deep_color_mode_txt[hdmi_read(sd, 0x0b) >> 6]);
2466 2373
2467 print_avi_infoframe(sd); 2374 adv7842_log_infoframes(sd);
2375
2468 return 0; 2376 return 0;
2469} 2377}
2470 2378
diff --git a/drivers/media/i2c/m5mols/m5mols_core.c b/drivers/media/i2c/m5mols/m5mols_core.c
index 2820f7c38cba..6ed16e569bbf 100644
--- a/drivers/media/i2c/m5mols/m5mols_core.c
+++ b/drivers/media/i2c/m5mols/m5mols_core.c
@@ -125,9 +125,9 @@ static u32 m5mols_swap_byte(u8 *data, u8 length)
125 if (length == 1) 125 if (length == 1)
126 return *data; 126 return *data;
127 else if (length == 2) 127 else if (length == 2)
128 return be16_to_cpu(*((u16 *)data)); 128 return be16_to_cpu(*((__be16 *)data));
129 else 129 else
130 return be32_to_cpu(*((u32 *)data)); 130 return be32_to_cpu(*((__be32 *)data));
131} 131}
132 132
133/** 133/**
@@ -454,11 +454,6 @@ static int m5mols_get_version(struct v4l2_subdev *sd)
454 return ret; 454 return ret;
455 } 455 }
456 456
457 ver->fw = be16_to_cpu(ver->fw);
458 ver->hw = be16_to_cpu(ver->hw);
459 ver->param = be16_to_cpu(ver->param);
460 ver->awb = be16_to_cpu(ver->awb);
461
462 v4l2_info(sd, "Manufacturer\t[%s]\n", 457 v4l2_info(sd, "Manufacturer\t[%s]\n",
463 is_manufacturer(info, REG_SAMSUNG_ELECTRO) ? 458 is_manufacturer(info, REG_SAMSUNG_ELECTRO) ?
464 "Samsung Electro-Machanics" : 459 "Samsung Electro-Machanics" :
diff --git a/drivers/media/i2c/msp3400-driver.c b/drivers/media/i2c/msp3400-driver.c
index 4d9c6bc34265..dcc68ec71732 100644
--- a/drivers/media/i2c/msp3400-driver.c
+++ b/drivers/media/i2c/msp3400-driver.c
@@ -904,11 +904,3 @@ static struct i2c_driver msp_driver = {
904}; 904};
905 905
906module_i2c_driver(msp_driver); 906module_i2c_driver(msp_driver);
907
908/*
909 * Overrides for Emacs so that we follow Linus's tabbing style.
910 * ---------------------------------------------------------------------------
911 * Local variables:
912 * c-basic-offset: 8
913 * End:
914 */
diff --git a/drivers/media/i2c/mt9m032.c b/drivers/media/i2c/mt9m032.c
index 45b3fca188ca..76431223f0ff 100644
--- a/drivers/media/i2c/mt9m032.c
+++ b/drivers/media/i2c/mt9m032.c
@@ -422,22 +422,25 @@ done:
422 return ret; 422 return ret;
423} 423}
424 424
425static int mt9m032_get_pad_crop(struct v4l2_subdev *subdev, 425static int mt9m032_get_pad_selection(struct v4l2_subdev *subdev,
426 struct v4l2_subdev_fh *fh, 426 struct v4l2_subdev_fh *fh,
427 struct v4l2_subdev_crop *crop) 427 struct v4l2_subdev_selection *sel)
428{ 428{
429 struct mt9m032 *sensor = to_mt9m032(subdev); 429 struct mt9m032 *sensor = to_mt9m032(subdev);
430 430
431 if (sel->target != V4L2_SEL_TGT_CROP)
432 return -EINVAL;
433
431 mutex_lock(&sensor->lock); 434 mutex_lock(&sensor->lock);
432 crop->rect = *__mt9m032_get_pad_crop(sensor, fh, crop->which); 435 sel->r = *__mt9m032_get_pad_crop(sensor, fh, sel->which);
433 mutex_unlock(&sensor->lock); 436 mutex_unlock(&sensor->lock);
434 437
435 return 0; 438 return 0;
436} 439}
437 440
438static int mt9m032_set_pad_crop(struct v4l2_subdev *subdev, 441static int mt9m032_set_pad_selection(struct v4l2_subdev *subdev,
439 struct v4l2_subdev_fh *fh, 442 struct v4l2_subdev_fh *fh,
440 struct v4l2_subdev_crop *crop) 443 struct v4l2_subdev_selection *sel)
441{ 444{
442 struct mt9m032 *sensor = to_mt9m032(subdev); 445 struct mt9m032 *sensor = to_mt9m032(subdev);
443 struct v4l2_mbus_framefmt *format; 446 struct v4l2_mbus_framefmt *format;
@@ -445,9 +448,12 @@ static int mt9m032_set_pad_crop(struct v4l2_subdev *subdev,
445 struct v4l2_rect rect; 448 struct v4l2_rect rect;
446 int ret = 0; 449 int ret = 0;
447 450
451 if (sel->target != V4L2_SEL_TGT_CROP)
452 return -EINVAL;
453
448 mutex_lock(&sensor->lock); 454 mutex_lock(&sensor->lock);
449 455
450 if (sensor->streaming && crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) { 456 if (sensor->streaming && sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
451 ret = -EBUSY; 457 ret = -EBUSY;
452 goto done; 458 goto done;
453 } 459 }
@@ -455,13 +461,13 @@ static int mt9m032_set_pad_crop(struct v4l2_subdev *subdev,
455 /* Clamp the crop rectangle boundaries and align them to a multiple of 2 461 /* Clamp the crop rectangle boundaries and align them to a multiple of 2
456 * pixels to ensure a GRBG Bayer pattern. 462 * pixels to ensure a GRBG Bayer pattern.
457 */ 463 */
458 rect.left = clamp(ALIGN(crop->rect.left, 2), MT9M032_COLUMN_START_MIN, 464 rect.left = clamp(ALIGN(sel->r.left, 2), MT9M032_COLUMN_START_MIN,
459 MT9M032_COLUMN_START_MAX); 465 MT9M032_COLUMN_START_MAX);
460 rect.top = clamp(ALIGN(crop->rect.top, 2), MT9M032_ROW_START_MIN, 466 rect.top = clamp(ALIGN(sel->r.top, 2), MT9M032_ROW_START_MIN,
461 MT9M032_ROW_START_MAX); 467 MT9M032_ROW_START_MAX);
462 rect.width = clamp_t(unsigned int, ALIGN(crop->rect.width, 2), 468 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
463 MT9M032_COLUMN_SIZE_MIN, MT9M032_COLUMN_SIZE_MAX); 469 MT9M032_COLUMN_SIZE_MIN, MT9M032_COLUMN_SIZE_MAX);
464 rect.height = clamp_t(unsigned int, ALIGN(crop->rect.height, 2), 470 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
465 MT9M032_ROW_SIZE_MIN, MT9M032_ROW_SIZE_MAX); 471 MT9M032_ROW_SIZE_MIN, MT9M032_ROW_SIZE_MAX);
466 472
467 rect.width = min_t(unsigned int, rect.width, 473 rect.width = min_t(unsigned int, rect.width,
@@ -469,21 +475,21 @@ static int mt9m032_set_pad_crop(struct v4l2_subdev *subdev,
469 rect.height = min_t(unsigned int, rect.height, 475 rect.height = min_t(unsigned int, rect.height,
470 MT9M032_PIXEL_ARRAY_HEIGHT - rect.top); 476 MT9M032_PIXEL_ARRAY_HEIGHT - rect.top);
471 477
472 __crop = __mt9m032_get_pad_crop(sensor, fh, crop->which); 478 __crop = __mt9m032_get_pad_crop(sensor, fh, sel->which);
473 479
474 if (rect.width != __crop->width || rect.height != __crop->height) { 480 if (rect.width != __crop->width || rect.height != __crop->height) {
475 /* Reset the output image size if the crop rectangle size has 481 /* Reset the output image size if the crop rectangle size has
476 * been modified. 482 * been modified.
477 */ 483 */
478 format = __mt9m032_get_pad_format(sensor, fh, crop->which); 484 format = __mt9m032_get_pad_format(sensor, fh, sel->which);
479 format->width = rect.width; 485 format->width = rect.width;
480 format->height = rect.height; 486 format->height = rect.height;
481 } 487 }
482 488
483 *__crop = rect; 489 *__crop = rect;
484 crop->rect = rect; 490 sel->r = rect;
485 491
486 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) 492 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE)
487 ret = mt9m032_update_geom_timing(sensor); 493 ret = mt9m032_update_geom_timing(sensor);
488 494
489done: 495done:
@@ -690,8 +696,8 @@ static const struct v4l2_subdev_pad_ops mt9m032_pad_ops = {
690 .enum_frame_size = mt9m032_enum_frame_size, 696 .enum_frame_size = mt9m032_enum_frame_size,
691 .get_fmt = mt9m032_get_pad_format, 697 .get_fmt = mt9m032_get_pad_format,
692 .set_fmt = mt9m032_set_pad_format, 698 .set_fmt = mt9m032_set_pad_format,
693 .set_crop = mt9m032_set_pad_crop, 699 .set_selection = mt9m032_set_pad_selection,
694 .get_crop = mt9m032_get_pad_crop, 700 .get_selection = mt9m032_get_pad_selection,
695}; 701};
696 702
697static const struct v4l2_subdev_ops mt9m032_ops = { 703static const struct v4l2_subdev_ops mt9m032_ops = {
diff --git a/drivers/media/i2c/mt9p031.c b/drivers/media/i2c/mt9p031.c
index edb76bd33d16..e3acae9a2ec3 100644
--- a/drivers/media/i2c/mt9p031.c
+++ b/drivers/media/i2c/mt9p031.c
@@ -581,37 +581,42 @@ static int mt9p031_set_format(struct v4l2_subdev *subdev,
581 return 0; 581 return 0;
582} 582}
583 583
584static int mt9p031_get_crop(struct v4l2_subdev *subdev, 584static int mt9p031_get_selection(struct v4l2_subdev *subdev,
585 struct v4l2_subdev_fh *fh, 585 struct v4l2_subdev_fh *fh,
586 struct v4l2_subdev_crop *crop) 586 struct v4l2_subdev_selection *sel)
587{ 587{
588 struct mt9p031 *mt9p031 = to_mt9p031(subdev); 588 struct mt9p031 *mt9p031 = to_mt9p031(subdev);
589 589
590 crop->rect = *__mt9p031_get_pad_crop(mt9p031, fh, crop->pad, 590 if (sel->target != V4L2_SEL_TGT_CROP)
591 crop->which); 591 return -EINVAL;
592
593 sel->r = *__mt9p031_get_pad_crop(mt9p031, fh, sel->pad, sel->which);
592 return 0; 594 return 0;
593} 595}
594 596
595static int mt9p031_set_crop(struct v4l2_subdev *subdev, 597static int mt9p031_set_selection(struct v4l2_subdev *subdev,
596 struct v4l2_subdev_fh *fh, 598 struct v4l2_subdev_fh *fh,
597 struct v4l2_subdev_crop *crop) 599 struct v4l2_subdev_selection *sel)
598{ 600{
599 struct mt9p031 *mt9p031 = to_mt9p031(subdev); 601 struct mt9p031 *mt9p031 = to_mt9p031(subdev);
600 struct v4l2_mbus_framefmt *__format; 602 struct v4l2_mbus_framefmt *__format;
601 struct v4l2_rect *__crop; 603 struct v4l2_rect *__crop;
602 struct v4l2_rect rect; 604 struct v4l2_rect rect;
603 605
606 if (sel->target != V4L2_SEL_TGT_CROP)
607 return -EINVAL;
608
604 /* Clamp the crop rectangle boundaries and align them to a multiple of 2 609 /* Clamp the crop rectangle boundaries and align them to a multiple of 2
605 * pixels to ensure a GRBG Bayer pattern. 610 * pixels to ensure a GRBG Bayer pattern.
606 */ 611 */
607 rect.left = clamp(ALIGN(crop->rect.left, 2), MT9P031_COLUMN_START_MIN, 612 rect.left = clamp(ALIGN(sel->r.left, 2), MT9P031_COLUMN_START_MIN,
608 MT9P031_COLUMN_START_MAX); 613 MT9P031_COLUMN_START_MAX);
609 rect.top = clamp(ALIGN(crop->rect.top, 2), MT9P031_ROW_START_MIN, 614 rect.top = clamp(ALIGN(sel->r.top, 2), MT9P031_ROW_START_MIN,
610 MT9P031_ROW_START_MAX); 615 MT9P031_ROW_START_MAX);
611 rect.width = clamp_t(unsigned int, ALIGN(crop->rect.width, 2), 616 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
612 MT9P031_WINDOW_WIDTH_MIN, 617 MT9P031_WINDOW_WIDTH_MIN,
613 MT9P031_WINDOW_WIDTH_MAX); 618 MT9P031_WINDOW_WIDTH_MAX);
614 rect.height = clamp_t(unsigned int, ALIGN(crop->rect.height, 2), 619 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
615 MT9P031_WINDOW_HEIGHT_MIN, 620 MT9P031_WINDOW_HEIGHT_MIN,
616 MT9P031_WINDOW_HEIGHT_MAX); 621 MT9P031_WINDOW_HEIGHT_MAX);
617 622
@@ -620,20 +625,20 @@ static int mt9p031_set_crop(struct v4l2_subdev *subdev,
620 rect.height = min_t(unsigned int, rect.height, 625 rect.height = min_t(unsigned int, rect.height,
621 MT9P031_PIXEL_ARRAY_HEIGHT - rect.top); 626 MT9P031_PIXEL_ARRAY_HEIGHT - rect.top);
622 627
623 __crop = __mt9p031_get_pad_crop(mt9p031, fh, crop->pad, crop->which); 628 __crop = __mt9p031_get_pad_crop(mt9p031, fh, sel->pad, sel->which);
624 629
625 if (rect.width != __crop->width || rect.height != __crop->height) { 630 if (rect.width != __crop->width || rect.height != __crop->height) {
626 /* Reset the output image size if the crop rectangle size has 631 /* Reset the output image size if the crop rectangle size has
627 * been modified. 632 * been modified.
628 */ 633 */
629 __format = __mt9p031_get_pad_format(mt9p031, fh, crop->pad, 634 __format = __mt9p031_get_pad_format(mt9p031, fh, sel->pad,
630 crop->which); 635 sel->which);
631 __format->width = rect.width; 636 __format->width = rect.width;
632 __format->height = rect.height; 637 __format->height = rect.height;
633 } 638 }
634 639
635 *__crop = rect; 640 *__crop = rect;
636 crop->rect = rect; 641 sel->r = rect;
637 642
638 return 0; 643 return 0;
639} 644}
@@ -980,8 +985,8 @@ static struct v4l2_subdev_pad_ops mt9p031_subdev_pad_ops = {
980 .enum_frame_size = mt9p031_enum_frame_size, 985 .enum_frame_size = mt9p031_enum_frame_size,
981 .get_fmt = mt9p031_get_format, 986 .get_fmt = mt9p031_get_format,
982 .set_fmt = mt9p031_set_format, 987 .set_fmt = mt9p031_set_format,
983 .get_crop = mt9p031_get_crop, 988 .get_selection = mt9p031_get_selection,
984 .set_crop = mt9p031_set_crop, 989 .set_selection = mt9p031_set_selection,
985}; 990};
986 991
987static struct v4l2_subdev_ops mt9p031_subdev_ops = { 992static struct v4l2_subdev_ops mt9p031_subdev_ops = {
diff --git a/drivers/media/i2c/mt9t001.c b/drivers/media/i2c/mt9t001.c
index d9e9889b579f..f6ca636b538d 100644
--- a/drivers/media/i2c/mt9t001.c
+++ b/drivers/media/i2c/mt9t001.c
@@ -401,39 +401,44 @@ static int mt9t001_set_format(struct v4l2_subdev *subdev,
401 return 0; 401 return 0;
402} 402}
403 403
404static int mt9t001_get_crop(struct v4l2_subdev *subdev, 404static int mt9t001_get_selection(struct v4l2_subdev *subdev,
405 struct v4l2_subdev_fh *fh, 405 struct v4l2_subdev_fh *fh,
406 struct v4l2_subdev_crop *crop) 406 struct v4l2_subdev_selection *sel)
407{ 407{
408 struct mt9t001 *mt9t001 = to_mt9t001(subdev); 408 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
409 409
410 crop->rect = *__mt9t001_get_pad_crop(mt9t001, fh, crop->pad, 410 if (sel->target != V4L2_SEL_TGT_CROP)
411 crop->which); 411 return -EINVAL;
412
413 sel->r = *__mt9t001_get_pad_crop(mt9t001, fh, sel->pad, sel->which);
412 return 0; 414 return 0;
413} 415}
414 416
415static int mt9t001_set_crop(struct v4l2_subdev *subdev, 417static int mt9t001_set_selection(struct v4l2_subdev *subdev,
416 struct v4l2_subdev_fh *fh, 418 struct v4l2_subdev_fh *fh,
417 struct v4l2_subdev_crop *crop) 419 struct v4l2_subdev_selection *sel)
418{ 420{
419 struct mt9t001 *mt9t001 = to_mt9t001(subdev); 421 struct mt9t001 *mt9t001 = to_mt9t001(subdev);
420 struct v4l2_mbus_framefmt *__format; 422 struct v4l2_mbus_framefmt *__format;
421 struct v4l2_rect *__crop; 423 struct v4l2_rect *__crop;
422 struct v4l2_rect rect; 424 struct v4l2_rect rect;
423 425
426 if (sel->target != V4L2_SEL_TGT_CROP)
427 return -EINVAL;
428
424 /* Clamp the crop rectangle boundaries and align them to a multiple of 2 429 /* Clamp the crop rectangle boundaries and align them to a multiple of 2
425 * pixels. 430 * pixels.
426 */ 431 */
427 rect.left = clamp(ALIGN(crop->rect.left, 2), 432 rect.left = clamp(ALIGN(sel->r.left, 2),
428 MT9T001_COLUMN_START_MIN, 433 MT9T001_COLUMN_START_MIN,
429 MT9T001_COLUMN_START_MAX); 434 MT9T001_COLUMN_START_MAX);
430 rect.top = clamp(ALIGN(crop->rect.top, 2), 435 rect.top = clamp(ALIGN(sel->r.top, 2),
431 MT9T001_ROW_START_MIN, 436 MT9T001_ROW_START_MIN,
432 MT9T001_ROW_START_MAX); 437 MT9T001_ROW_START_MAX);
433 rect.width = clamp_t(unsigned int, ALIGN(crop->rect.width, 2), 438 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
434 MT9T001_WINDOW_WIDTH_MIN + 1, 439 MT9T001_WINDOW_WIDTH_MIN + 1,
435 MT9T001_WINDOW_WIDTH_MAX + 1); 440 MT9T001_WINDOW_WIDTH_MAX + 1);
436 rect.height = clamp_t(unsigned int, ALIGN(crop->rect.height, 2), 441 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
437 MT9T001_WINDOW_HEIGHT_MIN + 1, 442 MT9T001_WINDOW_HEIGHT_MIN + 1,
438 MT9T001_WINDOW_HEIGHT_MAX + 1); 443 MT9T001_WINDOW_HEIGHT_MAX + 1);
439 444
@@ -442,20 +447,20 @@ static int mt9t001_set_crop(struct v4l2_subdev *subdev,
442 rect.height = min_t(unsigned int, rect.height, 447 rect.height = min_t(unsigned int, rect.height,
443 MT9T001_PIXEL_ARRAY_HEIGHT - rect.top); 448 MT9T001_PIXEL_ARRAY_HEIGHT - rect.top);
444 449
445 __crop = __mt9t001_get_pad_crop(mt9t001, fh, crop->pad, crop->which); 450 __crop = __mt9t001_get_pad_crop(mt9t001, fh, sel->pad, sel->which);
446 451
447 if (rect.width != __crop->width || rect.height != __crop->height) { 452 if (rect.width != __crop->width || rect.height != __crop->height) {
448 /* Reset the output image size if the crop rectangle size has 453 /* Reset the output image size if the crop rectangle size has
449 * been modified. 454 * been modified.
450 */ 455 */
451 __format = __mt9t001_get_pad_format(mt9t001, fh, crop->pad, 456 __format = __mt9t001_get_pad_format(mt9t001, fh, sel->pad,
452 crop->which); 457 sel->which);
453 __format->width = rect.width; 458 __format->width = rect.width;
454 __format->height = rect.height; 459 __format->height = rect.height;
455 } 460 }
456 461
457 *__crop = rect; 462 *__crop = rect;
458 crop->rect = rect; 463 sel->r = rect;
459 464
460 return 0; 465 return 0;
461} 466}
@@ -819,8 +824,8 @@ static struct v4l2_subdev_pad_ops mt9t001_subdev_pad_ops = {
819 .enum_frame_size = mt9t001_enum_frame_size, 824 .enum_frame_size = mt9t001_enum_frame_size,
820 .get_fmt = mt9t001_get_format, 825 .get_fmt = mt9t001_get_format,
821 .set_fmt = mt9t001_set_format, 826 .set_fmt = mt9t001_set_format,
822 .get_crop = mt9t001_get_crop, 827 .get_selection = mt9t001_get_selection,
823 .set_crop = mt9t001_set_crop, 828 .set_selection = mt9t001_set_selection,
824}; 829};
825 830
826static struct v4l2_subdev_ops mt9t001_subdev_ops = { 831static struct v4l2_subdev_ops mt9t001_subdev_ops = {
diff --git a/drivers/media/i2c/mt9v032.c b/drivers/media/i2c/mt9v032.c
index 93687c1e4097..bd3f979a4d49 100644
--- a/drivers/media/i2c/mt9v032.c
+++ b/drivers/media/i2c/mt9v032.c
@@ -552,39 +552,44 @@ static int mt9v032_set_format(struct v4l2_subdev *subdev,
552 return 0; 552 return 0;
553} 553}
554 554
555static int mt9v032_get_crop(struct v4l2_subdev *subdev, 555static int mt9v032_get_selection(struct v4l2_subdev *subdev,
556 struct v4l2_subdev_fh *fh, 556 struct v4l2_subdev_fh *fh,
557 struct v4l2_subdev_crop *crop) 557 struct v4l2_subdev_selection *sel)
558{ 558{
559 struct mt9v032 *mt9v032 = to_mt9v032(subdev); 559 struct mt9v032 *mt9v032 = to_mt9v032(subdev);
560 560
561 crop->rect = *__mt9v032_get_pad_crop(mt9v032, fh, crop->pad, 561 if (sel->target != V4L2_SEL_TGT_CROP)
562 crop->which); 562 return -EINVAL;
563
564 sel->r = *__mt9v032_get_pad_crop(mt9v032, fh, sel->pad, sel->which);
563 return 0; 565 return 0;
564} 566}
565 567
566static int mt9v032_set_crop(struct v4l2_subdev *subdev, 568static int mt9v032_set_selection(struct v4l2_subdev *subdev,
567 struct v4l2_subdev_fh *fh, 569 struct v4l2_subdev_fh *fh,
568 struct v4l2_subdev_crop *crop) 570 struct v4l2_subdev_selection *sel)
569{ 571{
570 struct mt9v032 *mt9v032 = to_mt9v032(subdev); 572 struct mt9v032 *mt9v032 = to_mt9v032(subdev);
571 struct v4l2_mbus_framefmt *__format; 573 struct v4l2_mbus_framefmt *__format;
572 struct v4l2_rect *__crop; 574 struct v4l2_rect *__crop;
573 struct v4l2_rect rect; 575 struct v4l2_rect rect;
574 576
577 if (sel->target != V4L2_SEL_TGT_CROP)
578 return -EINVAL;
579
575 /* Clamp the crop rectangle boundaries and align them to a non multiple 580 /* Clamp the crop rectangle boundaries and align them to a non multiple
576 * of 2 pixels to ensure a GRBG Bayer pattern. 581 * of 2 pixels to ensure a GRBG Bayer pattern.
577 */ 582 */
578 rect.left = clamp(ALIGN(crop->rect.left + 1, 2) - 1, 583 rect.left = clamp(ALIGN(sel->r.left + 1, 2) - 1,
579 MT9V032_COLUMN_START_MIN, 584 MT9V032_COLUMN_START_MIN,
580 MT9V032_COLUMN_START_MAX); 585 MT9V032_COLUMN_START_MAX);
581 rect.top = clamp(ALIGN(crop->rect.top + 1, 2) - 1, 586 rect.top = clamp(ALIGN(sel->r.top + 1, 2) - 1,
582 MT9V032_ROW_START_MIN, 587 MT9V032_ROW_START_MIN,
583 MT9V032_ROW_START_MAX); 588 MT9V032_ROW_START_MAX);
584 rect.width = clamp_t(unsigned int, ALIGN(crop->rect.width, 2), 589 rect.width = clamp_t(unsigned int, ALIGN(sel->r.width, 2),
585 MT9V032_WINDOW_WIDTH_MIN, 590 MT9V032_WINDOW_WIDTH_MIN,
586 MT9V032_WINDOW_WIDTH_MAX); 591 MT9V032_WINDOW_WIDTH_MAX);
587 rect.height = clamp_t(unsigned int, ALIGN(crop->rect.height, 2), 592 rect.height = clamp_t(unsigned int, ALIGN(sel->r.height, 2),
588 MT9V032_WINDOW_HEIGHT_MIN, 593 MT9V032_WINDOW_HEIGHT_MIN,
589 MT9V032_WINDOW_HEIGHT_MAX); 594 MT9V032_WINDOW_HEIGHT_MAX);
590 595
@@ -593,17 +598,17 @@ static int mt9v032_set_crop(struct v4l2_subdev *subdev,
593 rect.height = min_t(unsigned int, 598 rect.height = min_t(unsigned int,
594 rect.height, MT9V032_PIXEL_ARRAY_HEIGHT - rect.top); 599 rect.height, MT9V032_PIXEL_ARRAY_HEIGHT - rect.top);
595 600
596 __crop = __mt9v032_get_pad_crop(mt9v032, fh, crop->pad, crop->which); 601 __crop = __mt9v032_get_pad_crop(mt9v032, fh, sel->pad, sel->which);
597 602
598 if (rect.width != __crop->width || rect.height != __crop->height) { 603 if (rect.width != __crop->width || rect.height != __crop->height) {
599 /* Reset the output image size if the crop rectangle size has 604 /* Reset the output image size if the crop rectangle size has
600 * been modified. 605 * been modified.
601 */ 606 */
602 __format = __mt9v032_get_pad_format(mt9v032, fh, crop->pad, 607 __format = __mt9v032_get_pad_format(mt9v032, fh, sel->pad,
603 crop->which); 608 sel->which);
604 __format->width = rect.width; 609 __format->width = rect.width;
605 __format->height = rect.height; 610 __format->height = rect.height;
606 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) { 611 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
607 mt9v032->hratio = 1; 612 mt9v032->hratio = 1;
608 mt9v032->vratio = 1; 613 mt9v032->vratio = 1;
609 mt9v032_configure_pixel_rate(mt9v032); 614 mt9v032_configure_pixel_rate(mt9v032);
@@ -611,7 +616,7 @@ static int mt9v032_set_crop(struct v4l2_subdev *subdev,
611 } 616 }
612 617
613 *__crop = rect; 618 *__crop = rect;
614 crop->rect = rect; 619 sel->r = rect;
615 620
616 return 0; 621 return 0;
617} 622}
@@ -844,8 +849,8 @@ static struct v4l2_subdev_pad_ops mt9v032_subdev_pad_ops = {
844 .enum_frame_size = mt9v032_enum_frame_size, 849 .enum_frame_size = mt9v032_enum_frame_size,
845 .get_fmt = mt9v032_get_format, 850 .get_fmt = mt9v032_get_format,
846 .set_fmt = mt9v032_set_format, 851 .set_fmt = mt9v032_set_format,
847 .get_crop = mt9v032_get_crop, 852 .get_selection = mt9v032_get_selection,
848 .set_crop = mt9v032_set_crop, 853 .set_selection = mt9v032_set_selection,
849}; 854};
850 855
851static struct v4l2_subdev_ops mt9v032_subdev_ops = { 856static struct v4l2_subdev_ops mt9v032_subdev_ops = {
diff --git a/drivers/media/i2c/s5k4ecgx.c b/drivers/media/i2c/s5k4ecgx.c
index d1c50c9d43ae..70071314789e 100644
--- a/drivers/media/i2c/s5k4ecgx.c
+++ b/drivers/media/i2c/s5k4ecgx.c
@@ -220,7 +220,7 @@ static int s5k4ecgx_i2c_read(struct i2c_client *client, u16 addr, u16 *val)
220 msg[1].buf = rbuf; 220 msg[1].buf = rbuf;
221 221
222 ret = i2c_transfer(client->adapter, msg, 2); 222 ret = i2c_transfer(client->adapter, msg, 2);
223 *val = be16_to_cpu(*((u16 *)rbuf)); 223 *val = be16_to_cpu(*((__be16 *)rbuf));
224 224
225 v4l2_dbg(4, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val); 225 v4l2_dbg(4, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val);
226 226
@@ -341,7 +341,7 @@ static int s5k4ecgx_load_firmware(struct v4l2_subdev *sd)
341 v4l2_err(sd, "Failed to read firmware %s\n", S5K4ECGX_FIRMWARE); 341 v4l2_err(sd, "Failed to read firmware %s\n", S5K4ECGX_FIRMWARE);
342 return err; 342 return err;
343 } 343 }
344 regs_num = le32_to_cpu(get_unaligned_le32(fw->data)); 344 regs_num = get_unaligned_le32(fw->data);
345 345
346 v4l2_dbg(3, debug, sd, "FW: %s size %zu register sets %d\n", 346 v4l2_dbg(3, debug, sd, "FW: %s size %zu register sets %d\n",
347 S5K4ECGX_FIRMWARE, fw->size, regs_num); 347 S5K4ECGX_FIRMWARE, fw->size, regs_num);
@@ -351,8 +351,7 @@ static int s5k4ecgx_load_firmware(struct v4l2_subdev *sd)
351 err = -EINVAL; 351 err = -EINVAL;
352 goto fw_out; 352 goto fw_out;
353 } 353 }
354 crc_file = le32_to_cpu(get_unaligned_le32(fw->data + 354 crc_file = get_unaligned_le32(fw->data + regs_num * FW_RECORD_SIZE);
355 regs_num * FW_RECORD_SIZE));
356 crc = crc32_le(~0, fw->data, regs_num * FW_RECORD_SIZE); 355 crc = crc32_le(~0, fw->data, regs_num * FW_RECORD_SIZE);
357 if (crc != crc_file) { 356 if (crc != crc_file) {
358 v4l2_err(sd, "FW: invalid crc (%#x:%#x)\n", crc, crc_file); 357 v4l2_err(sd, "FW: invalid crc (%#x:%#x)\n", crc, crc_file);
@@ -361,9 +360,9 @@ static int s5k4ecgx_load_firmware(struct v4l2_subdev *sd)
361 } 360 }
362 ptr = fw->data + FW_RECORD_SIZE; 361 ptr = fw->data + FW_RECORD_SIZE;
363 for (i = 1; i < regs_num; i++) { 362 for (i = 1; i < regs_num; i++) {
364 addr = le32_to_cpu(get_unaligned_le32(ptr)); 363 addr = get_unaligned_le32(ptr);
365 ptr += sizeof(u32); 364 ptr += sizeof(u32);
366 val = le16_to_cpu(get_unaligned_le16(ptr)); 365 val = get_unaligned_le16(ptr);
367 ptr += sizeof(u16); 366 ptr += sizeof(u16);
368 if (addr - addr_inc != 2) 367 if (addr - addr_inc != 2)
369 err = s5k4ecgx_write(client, addr, val); 368 err = s5k4ecgx_write(client, addr, val);
diff --git a/drivers/media/i2c/s5k5baf.c b/drivers/media/i2c/s5k5baf.c
index 60a74d8d38d5..a3d7d0391302 100644
--- a/drivers/media/i2c/s5k5baf.c
+++ b/drivers/media/i2c/s5k5baf.c
@@ -353,7 +353,7 @@ static struct v4l2_rect s5k5baf_cis_rect = {
353 * 353 *
354 */ 354 */
355static int s5k5baf_fw_parse(struct device *dev, struct s5k5baf_fw **fw, 355static int s5k5baf_fw_parse(struct device *dev, struct s5k5baf_fw **fw,
356 size_t count, const u16 *data) 356 size_t count, const __le16 *data)
357{ 357{
358 struct s5k5baf_fw *f; 358 struct s5k5baf_fw *f;
359 u16 *d, i, *end; 359 u16 *d, i, *end;
@@ -421,6 +421,7 @@ static u16 s5k5baf_i2c_read(struct s5k5baf *state, u16 addr)
421{ 421{
422 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); 422 struct i2c_client *c = v4l2_get_subdevdata(&state->sd);
423 __be16 w, r; 423 __be16 w, r;
424 u16 res;
424 struct i2c_msg msg[] = { 425 struct i2c_msg msg[] = {
425 { .addr = c->addr, .flags = 0, 426 { .addr = c->addr, .flags = 0,
426 .len = 2, .buf = (u8 *)&w }, 427 .len = 2, .buf = (u8 *)&w },
@@ -434,15 +435,15 @@ static u16 s5k5baf_i2c_read(struct s5k5baf *state, u16 addr)
434 435
435 w = cpu_to_be16(addr); 436 w = cpu_to_be16(addr);
436 ret = i2c_transfer(c->adapter, msg, 2); 437 ret = i2c_transfer(c->adapter, msg, 2);
437 r = be16_to_cpu(r); 438 res = be16_to_cpu(r);
438 439
439 v4l2_dbg(3, debug, c, "i2c_read: 0x%04x : 0x%04x\n", addr, r); 440 v4l2_dbg(3, debug, c, "i2c_read: 0x%04x : 0x%04x\n", addr, res);
440 441
441 if (ret != 2) { 442 if (ret != 2) {
442 v4l2_err(c, "i2c_read: error during transfer (%d)\n", ret); 443 v4l2_err(c, "i2c_read: error during transfer (%d)\n", ret);
443 state->error = ret; 444 state->error = ret;
444 } 445 }
445 return r; 446 return res;
446} 447}
447 448
448static void s5k5baf_i2c_write(struct s5k5baf *state, u16 addr, u16 val) 449static void s5k5baf_i2c_write(struct s5k5baf *state, u16 addr, u16 val)
@@ -1037,7 +1038,7 @@ static int s5k5baf_load_setfile(struct s5k5baf *state)
1037 } 1038 }
1038 1039
1039 ret = s5k5baf_fw_parse(&c->dev, &state->fw, fw->size / 2, 1040 ret = s5k5baf_fw_parse(&c->dev, &state->fw, fw->size / 2,
1040 (u16 *)fw->data); 1041 (__le16 *)fw->data);
1041 1042
1042 release_firmware(fw); 1043 release_firmware(fw);
1043 1044
@@ -1793,7 +1794,7 @@ static const struct v4l2_subdev_ops s5k5baf_subdev_ops = {
1793 1794
1794static int s5k5baf_configure_gpios(struct s5k5baf *state) 1795static int s5k5baf_configure_gpios(struct s5k5baf *state)
1795{ 1796{
1796 static const char const *name[] = { "S5K5BAF_STBY", "S5K5BAF_RST" }; 1797 static const char * const name[] = { "S5K5BAF_STBY", "S5K5BAF_RST" };
1797 struct i2c_client *c = v4l2_get_subdevdata(&state->sd); 1798 struct i2c_client *c = v4l2_get_subdevdata(&state->sd);
1798 struct s5k5baf_gpio *g = state->gpios; 1799 struct s5k5baf_gpio *g = state->gpios;
1799 int ret, i; 1800 int ret, i;
diff --git a/drivers/media/i2c/s5k6aa.c b/drivers/media/i2c/s5k6aa.c
index 2851581e0061..b1c583239dab 100644
--- a/drivers/media/i2c/s5k6aa.c
+++ b/drivers/media/i2c/s5k6aa.c
@@ -348,7 +348,7 @@ static int s5k6aa_i2c_read(struct i2c_client *client, u16 addr, u16 *val)
348 msg[1].buf = rbuf; 348 msg[1].buf = rbuf;
349 349
350 ret = i2c_transfer(client->adapter, msg, 2); 350 ret = i2c_transfer(client->adapter, msg, 2);
351 *val = be16_to_cpu(*((u16 *)rbuf)); 351 *val = be16_to_cpu(*((__be16 *)rbuf));
352 352
353 v4l2_dbg(3, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val); 353 v4l2_dbg(3, debug, client, "i2c_read: 0x%04X : 0x%04x\n", addr, *val);
354 354
@@ -1161,17 +1161,21 @@ static int s5k6aa_set_fmt(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1161 return ret; 1161 return ret;
1162} 1162}
1163 1163
1164static int s5k6aa_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, 1164static int s5k6aa_get_selection(struct v4l2_subdev *sd,
1165 struct v4l2_subdev_crop *crop) 1165 struct v4l2_subdev_fh *fh,
1166 struct v4l2_subdev_selection *sel)
1166{ 1167{
1167 struct s5k6aa *s5k6aa = to_s5k6aa(sd); 1168 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1168 struct v4l2_rect *rect; 1169 struct v4l2_rect *rect;
1169 1170
1170 memset(crop->reserved, 0, sizeof(crop->reserved)); 1171 if (sel->target != V4L2_SEL_TGT_CROP)
1172 return -EINVAL;
1173
1174 memset(sel->reserved, 0, sizeof(sel->reserved));
1171 1175
1172 mutex_lock(&s5k6aa->lock); 1176 mutex_lock(&s5k6aa->lock);
1173 rect = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which); 1177 rect = __s5k6aa_get_crop_rect(s5k6aa, fh, sel->which);
1174 crop->rect = *rect; 1178 sel->r = *rect;
1175 mutex_unlock(&s5k6aa->lock); 1179 mutex_unlock(&s5k6aa->lock);
1176 1180
1177 v4l2_dbg(1, debug, sd, "Current crop rectangle: (%d,%d)/%dx%d\n", 1181 v4l2_dbg(1, debug, sd, "Current crop rectangle: (%d,%d)/%dx%d\n",
@@ -1180,35 +1184,39 @@ static int s5k6aa_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1180 return 0; 1184 return 0;
1181} 1185}
1182 1186
1183static int s5k6aa_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, 1187static int s5k6aa_set_selection(struct v4l2_subdev *sd,
1184 struct v4l2_subdev_crop *crop) 1188 struct v4l2_subdev_fh *fh,
1189 struct v4l2_subdev_selection *sel)
1185{ 1190{
1186 struct s5k6aa *s5k6aa = to_s5k6aa(sd); 1191 struct s5k6aa *s5k6aa = to_s5k6aa(sd);
1187 struct v4l2_mbus_framefmt *mf; 1192 struct v4l2_mbus_framefmt *mf;
1188 unsigned int max_x, max_y; 1193 unsigned int max_x, max_y;
1189 struct v4l2_rect *crop_r; 1194 struct v4l2_rect *crop_r;
1190 1195
1196 if (sel->target != V4L2_SEL_TGT_CROP)
1197 return -EINVAL;
1198
1191 mutex_lock(&s5k6aa->lock); 1199 mutex_lock(&s5k6aa->lock);
1192 crop_r = __s5k6aa_get_crop_rect(s5k6aa, fh, crop->which); 1200 crop_r = __s5k6aa_get_crop_rect(s5k6aa, fh, sel->which);
1193 1201
1194 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) { 1202 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1195 mf = &s5k6aa->preset->mbus_fmt; 1203 mf = &s5k6aa->preset->mbus_fmt;
1196 s5k6aa->apply_crop = 1; 1204 s5k6aa->apply_crop = 1;
1197 } else { 1205 } else {
1198 mf = v4l2_subdev_get_try_format(fh, 0); 1206 mf = v4l2_subdev_get_try_format(fh, 0);
1199 } 1207 }
1200 v4l_bound_align_image(&crop->rect.width, mf->width, 1208 v4l_bound_align_image(&sel->r.width, mf->width,
1201 S5K6AA_WIN_WIDTH_MAX, 1, 1209 S5K6AA_WIN_WIDTH_MAX, 1,
1202 &crop->rect.height, mf->height, 1210 &sel->r.height, mf->height,
1203 S5K6AA_WIN_HEIGHT_MAX, 1, 0); 1211 S5K6AA_WIN_HEIGHT_MAX, 1, 0);
1204 1212
1205 max_x = (S5K6AA_WIN_WIDTH_MAX - crop->rect.width) & ~1; 1213 max_x = (S5K6AA_WIN_WIDTH_MAX - sel->r.width) & ~1;
1206 max_y = (S5K6AA_WIN_HEIGHT_MAX - crop->rect.height) & ~1; 1214 max_y = (S5K6AA_WIN_HEIGHT_MAX - sel->r.height) & ~1;
1207 1215
1208 crop->rect.left = clamp_t(unsigned int, crop->rect.left, 0, max_x); 1216 sel->r.left = clamp_t(unsigned int, sel->r.left, 0, max_x);
1209 crop->rect.top = clamp_t(unsigned int, crop->rect.top, 0, max_y); 1217 sel->r.top = clamp_t(unsigned int, sel->r.top, 0, max_y);
1210 1218
1211 *crop_r = crop->rect; 1219 *crop_r = sel->r;
1212 1220
1213 mutex_unlock(&s5k6aa->lock); 1221 mutex_unlock(&s5k6aa->lock);
1214 1222
@@ -1224,8 +1232,8 @@ static const struct v4l2_subdev_pad_ops s5k6aa_pad_ops = {
1224 .enum_frame_interval = s5k6aa_enum_frame_interval, 1232 .enum_frame_interval = s5k6aa_enum_frame_interval,
1225 .get_fmt = s5k6aa_get_fmt, 1233 .get_fmt = s5k6aa_get_fmt,
1226 .set_fmt = s5k6aa_set_fmt, 1234 .set_fmt = s5k6aa_set_fmt,
1227 .get_crop = s5k6aa_get_crop, 1235 .get_selection = s5k6aa_get_selection,
1228 .set_crop = s5k6aa_set_crop, 1236 .set_selection = s5k6aa_set_selection,
1229}; 1237};
1230 1238
1231static const struct v4l2_subdev_video_ops s5k6aa_video_ops = { 1239static const struct v4l2_subdev_video_ops s5k6aa_video_ops = {
diff --git a/drivers/media/i2c/smiapp-pll.c b/drivers/media/i2c/smiapp-pll.c
index e40d9027df3d..e3348db56c46 100644
--- a/drivers/media/i2c/smiapp-pll.c
+++ b/drivers/media/i2c/smiapp-pll.c
@@ -14,14 +14,9 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
19#include <linux/device.h>
25#include <linux/gcd.h> 20#include <linux/gcd.h>
26#include <linux/lcm.h> 21#include <linux/lcm.h>
27#include <linux/module.h> 22#include <linux/module.h>
diff --git a/drivers/media/i2c/smiapp-pll.h b/drivers/media/i2c/smiapp-pll.h
index e8f035a50c76..b98d143b64e1 100644
--- a/drivers/media/i2c/smiapp-pll.h
+++ b/drivers/media/i2c/smiapp-pll.h
@@ -14,19 +14,11 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#ifndef SMIAPP_PLL_H 19#ifndef SMIAPP_PLL_H
26#define SMIAPP_PLL_H 20#define SMIAPP_PLL_H
27 21
28#include <linux/device.h>
29
30/* CSI-2 or CCP-2 */ 22/* CSI-2 or CCP-2 */
31#define SMIAPP_PLL_BUS_TYPE_CSI2 0x00 23#define SMIAPP_PLL_BUS_TYPE_CSI2 0x00
32#define SMIAPP_PLL_BUS_TYPE_PARALLEL 0x01 24#define SMIAPP_PLL_BUS_TYPE_PARALLEL 0x01
diff --git a/drivers/media/i2c/smiapp/smiapp-core.c b/drivers/media/i2c/smiapp/smiapp-core.c
index 0df5070e73c7..d47eff5d3101 100644
--- a/drivers/media/i2c/smiapp/smiapp-core.c
+++ b/drivers/media/i2c/smiapp/smiapp-core.c
@@ -18,12 +18,6 @@
18 * WITHOUT ANY WARRANTY; without even the implied warranty of 18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details. 20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
25 * 02110-1301 USA
26 *
27 */ 21 */
28 22
29#include <linux/clk.h> 23#include <linux/clk.h>
@@ -31,11 +25,13 @@
31#include <linux/device.h> 25#include <linux/device.h>
32#include <linux/gpio.h> 26#include <linux/gpio.h>
33#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/of_gpio.h>
34#include <linux/regulator/consumer.h> 29#include <linux/regulator/consumer.h>
35#include <linux/slab.h> 30#include <linux/slab.h>
36#include <linux/smiapp.h> 31#include <linux/smiapp.h>
37#include <linux/v4l2-mediabus.h> 32#include <linux/v4l2-mediabus.h>
38#include <media/v4l2-device.h> 33#include <media/v4l2-device.h>
34#include <media/v4l2-of.h>
39 35
40#include "smiapp.h" 36#include "smiapp.h"
41 37
@@ -523,14 +519,12 @@ static const struct v4l2_ctrl_ops smiapp_ctrl_ops = {
523static int smiapp_init_controls(struct smiapp_sensor *sensor) 519static int smiapp_init_controls(struct smiapp_sensor *sensor)
524{ 520{
525 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd); 521 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
526 unsigned long *valid_link_freqs = &sensor->valid_link_freqs[
527 sensor->csi_format->compressed - SMIAPP_COMPRESSED_BASE];
528 unsigned int max, i;
529 int rval; 522 int rval;
530 523
531 rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 12); 524 rval = v4l2_ctrl_handler_init(&sensor->pixel_array->ctrl_handler, 12);
532 if (rval) 525 if (rval)
533 return rval; 526 return rval;
527
534 sensor->pixel_array->ctrl_handler.lock = &sensor->mutex; 528 sensor->pixel_array->ctrl_handler.lock = &sensor->mutex;
535 529
536 sensor->analog_gain = v4l2_ctrl_new_std( 530 sensor->analog_gain = v4l2_ctrl_new_std(
@@ -576,21 +570,11 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
576 ARRAY_SIZE(smiapp_test_patterns) - 1, 570 ARRAY_SIZE(smiapp_test_patterns) - 1,
577 0, 0, smiapp_test_patterns); 571 0, 0, smiapp_test_patterns);
578 572
579 for (i = 0; i < ARRAY_SIZE(sensor->test_data); i++) {
580 int max_value = (1 << sensor->csi_format->width) - 1;
581 sensor->test_data[i] =
582 v4l2_ctrl_new_std(
583 &sensor->pixel_array->ctrl_handler,
584 &smiapp_ctrl_ops, V4L2_CID_TEST_PATTERN_RED + i,
585 0, max_value, 1, max_value);
586 }
587
588 if (sensor->pixel_array->ctrl_handler.error) { 573 if (sensor->pixel_array->ctrl_handler.error) {
589 dev_err(&client->dev, 574 dev_err(&client->dev,
590 "pixel array controls initialization failed (%d)\n", 575 "pixel array controls initialization failed (%d)\n",
591 sensor->pixel_array->ctrl_handler.error); 576 sensor->pixel_array->ctrl_handler.error);
592 rval = sensor->pixel_array->ctrl_handler.error; 577 return sensor->pixel_array->ctrl_handler.error;
593 goto error;
594 } 578 }
595 579
596 sensor->pixel_array->sd.ctrl_handler = 580 sensor->pixel_array->sd.ctrl_handler =
@@ -600,15 +584,9 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
600 584
601 rval = v4l2_ctrl_handler_init(&sensor->src->ctrl_handler, 0); 585 rval = v4l2_ctrl_handler_init(&sensor->src->ctrl_handler, 0);
602 if (rval) 586 if (rval)
603 goto error; 587 return rval;
604 sensor->src->ctrl_handler.lock = &sensor->mutex;
605
606 for (max = 0; sensor->platform_data->op_sys_clock[max + 1]; max++);
607 588
608 sensor->link_freq = v4l2_ctrl_new_int_menu( 589 sensor->src->ctrl_handler.lock = &sensor->mutex;
609 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
610 V4L2_CID_LINK_FREQ, __fls(*valid_link_freqs),
611 __ffs(*valid_link_freqs), sensor->platform_data->op_sys_clock);
612 590
613 sensor->pixel_rate_csi = v4l2_ctrl_new_std( 591 sensor->pixel_rate_csi = v4l2_ctrl_new_std(
614 &sensor->src->ctrl_handler, &smiapp_ctrl_ops, 592 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
@@ -618,20 +596,41 @@ static int smiapp_init_controls(struct smiapp_sensor *sensor)
618 dev_err(&client->dev, 596 dev_err(&client->dev,
619 "src controls initialization failed (%d)\n", 597 "src controls initialization failed (%d)\n",
620 sensor->src->ctrl_handler.error); 598 sensor->src->ctrl_handler.error);
621 rval = sensor->src->ctrl_handler.error; 599 return sensor->src->ctrl_handler.error;
622 goto error;
623 } 600 }
624 601
625 sensor->src->sd.ctrl_handler = 602 sensor->src->sd.ctrl_handler = &sensor->src->ctrl_handler;
626 &sensor->src->ctrl_handler;
627 603
628 return 0; 604 return 0;
605}
606
607/*
608 * For controls that require information on available media bus codes
609 * and linke frequencies.
610 */
611static int smiapp_init_late_controls(struct smiapp_sensor *sensor)
612{
613 unsigned long *valid_link_freqs = &sensor->valid_link_freqs[
614 sensor->csi_format->compressed - SMIAPP_COMPRESSED_BASE];
615 unsigned int max, i;
629 616
630error: 617 for (i = 0; i < ARRAY_SIZE(sensor->test_data); i++) {
631 v4l2_ctrl_handler_free(&sensor->pixel_array->ctrl_handler); 618 int max_value = (1 << sensor->csi_format->width) - 1;
632 v4l2_ctrl_handler_free(&sensor->src->ctrl_handler);
633 619
634 return rval; 620 sensor->test_data[i] = v4l2_ctrl_new_std(
621 &sensor->pixel_array->ctrl_handler,
622 &smiapp_ctrl_ops, V4L2_CID_TEST_PATTERN_RED + i,
623 0, max_value, 1, max_value);
624 }
625
626 for (max = 0; sensor->platform_data->op_sys_clock[max + 1]; max++);
627
628 sensor->link_freq = v4l2_ctrl_new_int_menu(
629 &sensor->src->ctrl_handler, &smiapp_ctrl_ops,
630 V4L2_CID_LINK_FREQ, __fls(*valid_link_freqs),
631 __ffs(*valid_link_freqs), sensor->platform_data->op_sys_clock);
632
633 return sensor->src->ctrl_handler.error;
635} 634}
636 635
637static void smiapp_free_controls(struct smiapp_sensor *sensor) 636static void smiapp_free_controls(struct smiapp_sensor *sensor)
@@ -1487,7 +1486,7 @@ static int smiapp_start_streaming(struct smiapp_sensor *sensor)
1487 if (rval < 0) 1486 if (rval < 0)
1488 goto out; 1487 goto out;
1489 1488
1490 if ((sensor->flash_capability & 1489 if ((sensor->limits[SMIAPP_LIMIT_FLASH_MODE_CAPABILITY] &
1491 (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE | 1490 (SMIAPP_FLASH_MODE_CAPABILITY_SINGLE_STROBE |
1492 SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) && 1491 SMIAPP_FLASH_MODE_CAPABILITY_MULTIPLE_STROBE)) &&
1493 sensor->platform_data->strobe_setup != NULL && 1492 sensor->platform_data->strobe_setup != NULL &&
@@ -2338,10 +2337,9 @@ static DEVICE_ATTR(ident, S_IRUGO, smiapp_sysfs_ident_read, NULL);
2338 * V4L2 subdev core operations 2337 * V4L2 subdev core operations
2339 */ 2338 */
2340 2339
2341static int smiapp_identify_module(struct v4l2_subdev *subdev) 2340static int smiapp_identify_module(struct smiapp_sensor *sensor)
2342{ 2341{
2343 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev); 2342 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
2344 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2345 struct smiapp_module_info *minfo = &sensor->minfo; 2343 struct smiapp_module_info *minfo = &sensor->minfo;
2346 unsigned int i; 2344 unsigned int i;
2347 int rval = 0; 2345 int rval = 0;
@@ -2464,8 +2462,6 @@ static int smiapp_identify_module(struct v4l2_subdev *subdev)
2464 minfo->name, minfo->manufacturer_id, minfo->model_id, 2462 minfo->name, minfo->manufacturer_id, minfo->model_id,
2465 minfo->revision_number_major); 2463 minfo->revision_number_major);
2466 2464
2467 strlcpy(subdev->name, sensor->minfo.name, sizeof(subdev->name));
2468
2469 return 0; 2465 return 0;
2470} 2466}
2471 2467
@@ -2473,13 +2469,71 @@ static const struct v4l2_subdev_ops smiapp_ops;
2473static const struct v4l2_subdev_internal_ops smiapp_internal_ops; 2469static const struct v4l2_subdev_internal_ops smiapp_internal_ops;
2474static const struct media_entity_operations smiapp_entity_ops; 2470static const struct media_entity_operations smiapp_entity_ops;
2475 2471
2476static int smiapp_registered(struct v4l2_subdev *subdev) 2472static int smiapp_register_subdevs(struct smiapp_sensor *sensor)
2477{ 2473{
2478 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev); 2474 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
2479 struct i2c_client *client = v4l2_get_subdevdata(subdev); 2475 struct smiapp_subdev *ssds[] = {
2476 sensor->scaler,
2477 sensor->binner,
2478 sensor->pixel_array,
2479 };
2480 unsigned int i;
2481 int rval;
2482
2483 for (i = 0; i < SMIAPP_SUBDEVS - 1; i++) {
2484 struct smiapp_subdev *this = ssds[i + 1];
2485 struct smiapp_subdev *last = ssds[i];
2486
2487 if (!last)
2488 continue;
2489
2490 rval = media_entity_init(&this->sd.entity,
2491 this->npads, this->pads, 0);
2492 if (rval) {
2493 dev_err(&client->dev,
2494 "media_entity_init failed\n");
2495 return rval;
2496 }
2497
2498 rval = media_entity_create_link(&this->sd.entity,
2499 this->source_pad,
2500 &last->sd.entity,
2501 last->sink_pad,
2502 MEDIA_LNK_FL_ENABLED |
2503 MEDIA_LNK_FL_IMMUTABLE);
2504 if (rval) {
2505 dev_err(&client->dev,
2506 "media_entity_create_link failed\n");
2507 return rval;
2508 }
2509
2510 rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
2511 &this->sd);
2512 if (rval) {
2513 dev_err(&client->dev,
2514 "v4l2_device_register_subdev failed\n");
2515 return rval;
2516 }
2517 }
2518
2519 return 0;
2520}
2521
2522static void smiapp_cleanup(struct smiapp_sensor *sensor)
2523{
2524 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
2525
2526 device_remove_file(&client->dev, &dev_attr_nvm);
2527 device_remove_file(&client->dev, &dev_attr_ident);
2528
2529 smiapp_free_controls(sensor);
2530}
2531
2532static int smiapp_init(struct smiapp_sensor *sensor)
2533{
2534 struct i2c_client *client = v4l2_get_subdevdata(&sensor->src->sd);
2480 struct smiapp_pll *pll = &sensor->pll; 2535 struct smiapp_pll *pll = &sensor->pll;
2481 struct smiapp_subdev *last = NULL; 2536 struct smiapp_subdev *last = NULL;
2482 u32 tmp;
2483 unsigned int i; 2537 unsigned int i;
2484 int rval; 2538 int rval;
2485 2539
@@ -2490,7 +2544,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2490 } 2544 }
2491 2545
2492 if (!sensor->platform_data->set_xclk) { 2546 if (!sensor->platform_data->set_xclk) {
2493 sensor->ext_clk = devm_clk_get(&client->dev, "ext_clk"); 2547 sensor->ext_clk = devm_clk_get(&client->dev, NULL);
2494 if (IS_ERR(sensor->ext_clk)) { 2548 if (IS_ERR(sensor->ext_clk)) {
2495 dev_err(&client->dev, "could not get clock\n"); 2549 dev_err(&client->dev, "could not get clock\n");
2496 return PTR_ERR(sensor->ext_clk); 2550 return PTR_ERR(sensor->ext_clk);
@@ -2522,7 +2576,7 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2522 if (rval) 2576 if (rval)
2523 return -ENODEV; 2577 return -ENODEV;
2524 2578
2525 rval = smiapp_identify_module(subdev); 2579 rval = smiapp_identify_module(sensor);
2526 if (rval) { 2580 if (rval) {
2527 rval = -ENODEV; 2581 rval = -ENODEV;
2528 goto out_power_off; 2582 goto out_power_off;
@@ -2602,13 +2656,13 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2602 if (sensor->nvm == NULL) { 2656 if (sensor->nvm == NULL) {
2603 dev_err(&client->dev, "nvm buf allocation failed\n"); 2657 dev_err(&client->dev, "nvm buf allocation failed\n");
2604 rval = -ENOMEM; 2658 rval = -ENOMEM;
2605 goto out_ident_release; 2659 goto out_cleanup;
2606 } 2660 }
2607 2661
2608 if (device_create_file(&client->dev, &dev_attr_nvm) != 0) { 2662 if (device_create_file(&client->dev, &dev_attr_nvm) != 0) {
2609 dev_err(&client->dev, "sysfs nvm entry failed\n"); 2663 dev_err(&client->dev, "sysfs nvm entry failed\n");
2610 rval = -EBUSY; 2664 rval = -EBUSY;
2611 goto out_ident_release; 2665 goto out_cleanup;
2612 } 2666 }
2613 } 2667 }
2614 2668
@@ -2643,18 +2697,11 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2643 pll->bus_type = SMIAPP_PLL_BUS_TYPE_CSI2; 2697 pll->bus_type = SMIAPP_PLL_BUS_TYPE_CSI2;
2644 pll->csi2.lanes = sensor->platform_data->lanes; 2698 pll->csi2.lanes = sensor->platform_data->lanes;
2645 pll->ext_clk_freq_hz = sensor->platform_data->ext_clk; 2699 pll->ext_clk_freq_hz = sensor->platform_data->ext_clk;
2646 pll->flags = smiapp_call_quirk(sensor, pll_flags);
2647 pll->scale_n = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN]; 2700 pll->scale_n = sensor->limits[SMIAPP_LIMIT_SCALER_N_MIN];
2648 /* Profile 0 sensors have no separate OP clock branch. */ 2701 /* Profile 0 sensors have no separate OP clock branch. */
2649 if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0) 2702 if (sensor->minfo.smiapp_profile == SMIAPP_PROFILE_0)
2650 pll->flags |= SMIAPP_PLL_FLAG_NO_OP_CLOCKS; 2703 pll->flags |= SMIAPP_PLL_FLAG_NO_OP_CLOCKS;
2651 2704
2652 rval = smiapp_get_mbus_formats(sensor);
2653 if (rval) {
2654 rval = -ENODEV;
2655 goto out_nvm_release;
2656 }
2657
2658 for (i = 0; i < SMIAPP_SUBDEVS; i++) { 2705 for (i = 0; i < SMIAPP_SUBDEVS; i++) {
2659 struct { 2706 struct {
2660 struct smiapp_subdev *ssd; 2707 struct smiapp_subdev *ssd;
@@ -2711,34 +2758,6 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2711 this->sd.owner = THIS_MODULE; 2758 this->sd.owner = THIS_MODULE;
2712 v4l2_set_subdevdata(&this->sd, client); 2759 v4l2_set_subdevdata(&this->sd, client);
2713 2760
2714 rval = media_entity_init(&this->sd.entity,
2715 this->npads, this->pads, 0);
2716 if (rval) {
2717 dev_err(&client->dev,
2718 "media_entity_init failed\n");
2719 goto out_nvm_release;
2720 }
2721
2722 rval = media_entity_create_link(&this->sd.entity,
2723 this->source_pad,
2724 &last->sd.entity,
2725 last->sink_pad,
2726 MEDIA_LNK_FL_ENABLED |
2727 MEDIA_LNK_FL_IMMUTABLE);
2728 if (rval) {
2729 dev_err(&client->dev,
2730 "media_entity_create_link failed\n");
2731 goto out_nvm_release;
2732 }
2733
2734 rval = v4l2_device_register_subdev(sensor->src->sd.v4l2_dev,
2735 &this->sd);
2736 if (rval) {
2737 dev_err(&client->dev,
2738 "v4l2_device_register_subdev failed\n");
2739 goto out_nvm_release;
2740 }
2741
2742 last = this; 2761 last = this;
2743 } 2762 }
2744 2763
@@ -2750,40 +2769,66 @@ static int smiapp_registered(struct v4l2_subdev *subdev)
2750 smiapp_read_frame_fmt(sensor); 2769 smiapp_read_frame_fmt(sensor);
2751 rval = smiapp_init_controls(sensor); 2770 rval = smiapp_init_controls(sensor);
2752 if (rval < 0) 2771 if (rval < 0)
2753 goto out_nvm_release; 2772 goto out_cleanup;
2773
2774 rval = smiapp_call_quirk(sensor, init);
2775 if (rval)
2776 goto out_cleanup;
2777
2778 rval = smiapp_get_mbus_formats(sensor);
2779 if (rval) {
2780 rval = -ENODEV;
2781 goto out_cleanup;
2782 }
2783
2784 rval = smiapp_init_late_controls(sensor);
2785 if (rval) {
2786 rval = -ENODEV;
2787 goto out_cleanup;
2788 }
2754 2789
2755 mutex_lock(&sensor->mutex); 2790 mutex_lock(&sensor->mutex);
2756 rval = smiapp_update_mode(sensor); 2791 rval = smiapp_update_mode(sensor);
2757 mutex_unlock(&sensor->mutex); 2792 mutex_unlock(&sensor->mutex);
2758 if (rval) { 2793 if (rval) {
2759 dev_err(&client->dev, "update mode failed\n"); 2794 dev_err(&client->dev, "update mode failed\n");
2760 goto out_nvm_release; 2795 goto out_cleanup;
2761 } 2796 }
2762 2797
2763 sensor->streaming = false; 2798 sensor->streaming = false;
2764 sensor->dev_init_done = true; 2799 sensor->dev_init_done = true;
2765 2800
2766 /* check flash capability */
2767 rval = smiapp_read(sensor, SMIAPP_REG_U8_FLASH_MODE_CAPABILITY, &tmp);
2768 sensor->flash_capability = tmp;
2769 if (rval)
2770 goto out_nvm_release;
2771
2772 smiapp_power_off(sensor); 2801 smiapp_power_off(sensor);
2773 2802
2774 return 0; 2803 return 0;
2775 2804
2776out_nvm_release: 2805out_cleanup:
2777 device_remove_file(&client->dev, &dev_attr_nvm); 2806 smiapp_cleanup(sensor);
2778
2779out_ident_release:
2780 device_remove_file(&client->dev, &dev_attr_ident);
2781 2807
2782out_power_off: 2808out_power_off:
2783 smiapp_power_off(sensor); 2809 smiapp_power_off(sensor);
2784 return rval; 2810 return rval;
2785} 2811}
2786 2812
2813static int smiapp_registered(struct v4l2_subdev *subdev)
2814{
2815 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2816 struct i2c_client *client = v4l2_get_subdevdata(subdev);
2817 int rval;
2818
2819 if (!client->dev.of_node) {
2820 rval = smiapp_init(sensor);
2821 if (rval)
2822 return rval;
2823 }
2824
2825 rval = smiapp_register_subdevs(sensor);
2826 if (rval)
2827 smiapp_cleanup(sensor);
2828
2829 return rval;
2830}
2831
2787static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh) 2832static int smiapp_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
2788{ 2833{
2789 struct smiapp_subdev *ssd = to_smiapp_subdev(sd); 2834 struct smiapp_subdev *ssd = to_smiapp_subdev(sd);
@@ -2927,19 +2972,125 @@ static int smiapp_resume(struct device *dev)
2927 2972
2928#endif /* CONFIG_PM */ 2973#endif /* CONFIG_PM */
2929 2974
2975static struct smiapp_platform_data *smiapp_get_pdata(struct device *dev)
2976{
2977 struct smiapp_platform_data *pdata;
2978 struct v4l2_of_endpoint bus_cfg;
2979 struct device_node *ep;
2980 struct property *prop;
2981 __be32 *val;
2982 uint32_t asize;
2983#ifdef CONFIG_OF
2984 unsigned int i;
2985#endif
2986 int rval;
2987
2988 if (!dev->of_node)
2989 return dev->platform_data;
2990
2991 ep = of_graph_get_next_endpoint(dev->of_node, NULL);
2992 if (!ep)
2993 return NULL;
2994
2995 pdata = devm_kzalloc(dev, sizeof(*pdata), GFP_KERNEL);
2996 if (!pdata) {
2997 rval = -ENOMEM;
2998 goto out_err;
2999 }
3000
3001 v4l2_of_parse_endpoint(ep, &bus_cfg);
3002
3003 switch (bus_cfg.bus_type) {
3004 case V4L2_MBUS_CSI2:
3005 pdata->csi_signalling_mode = SMIAPP_CSI_SIGNALLING_MODE_CSI2;
3006 break;
3007 /* FIXME: add CCP2 support. */
3008 default:
3009 rval = -EINVAL;
3010 goto out_err;
3011 }
3012
3013 pdata->lanes = bus_cfg.bus.mipi_csi2.num_data_lanes;
3014 dev_dbg(dev, "lanes %u\n", pdata->lanes);
3015
3016 /* xshutdown GPIO is optional */
3017 pdata->xshutdown = of_get_named_gpio(dev->of_node, "reset-gpios", 0);
3018
3019 /* NVM size is not mandatory */
3020 of_property_read_u32(dev->of_node, "nokia,nvm-size",
3021 &pdata->nvm_size);
3022
3023 rval = of_property_read_u32(dev->of_node, "clock-frequency",
3024 &pdata->ext_clk);
3025 if (rval) {
3026 dev_warn(dev, "can't get clock-frequency\n");
3027 goto out_err;
3028 }
3029
3030 dev_dbg(dev, "reset %d, nvm %d, clk %d, csi %d\n", pdata->xshutdown,
3031 pdata->nvm_size, pdata->ext_clk, pdata->csi_signalling_mode);
3032
3033 rval = of_get_property(
3034 dev->of_node, "link-frequencies", &asize) ? 0 : -ENOENT;
3035 if (rval) {
3036 dev_warn(dev, "can't get link-frequencies array size\n");
3037 goto out_err;
3038 }
3039
3040 pdata->op_sys_clock = devm_kzalloc(dev, asize, GFP_KERNEL);
3041 if (!pdata->op_sys_clock) {
3042 rval = -ENOMEM;
3043 goto out_err;
3044 }
3045
3046 asize /= sizeof(*pdata->op_sys_clock);
3047 /*
3048 * Read a 64-bit array --- this will be replaced with a
3049 * of_property_read_u64_array() once it's merged.
3050 */
3051 prop = of_find_property(dev->of_node, "link-frequencies", NULL);
3052 if (!prop)
3053 goto out_err;
3054 if (!prop->value)
3055 goto out_err;
3056 if (asize * sizeof(*pdata->op_sys_clock) > prop->length)
3057 goto out_err;
3058 val = prop->value;
3059 if (IS_ERR(val))
3060 goto out_err;
3061
3062#ifdef CONFIG_OF
3063 for (i = 0; i < asize; i++)
3064 pdata->op_sys_clock[i] = of_read_number(val + i * 2, 2);
3065#endif
3066
3067 for (; asize > 0; asize--)
3068 dev_dbg(dev, "freq %d: %lld\n", asize - 1,
3069 pdata->op_sys_clock[asize - 1]);
3070
3071 of_node_put(ep);
3072 return pdata;
3073
3074out_err:
3075 of_node_put(ep);
3076 return NULL;
3077}
3078
2930static int smiapp_probe(struct i2c_client *client, 3079static int smiapp_probe(struct i2c_client *client,
2931 const struct i2c_device_id *devid) 3080 const struct i2c_device_id *devid)
2932{ 3081{
2933 struct smiapp_sensor *sensor; 3082 struct smiapp_sensor *sensor;
3083 struct smiapp_platform_data *pdata = smiapp_get_pdata(&client->dev);
3084 int rval;
2934 3085
2935 if (client->dev.platform_data == NULL) 3086 if (pdata == NULL)
2936 return -ENODEV; 3087 return -ENODEV;
2937 3088
2938 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL); 3089 sensor = devm_kzalloc(&client->dev, sizeof(*sensor), GFP_KERNEL);
2939 if (sensor == NULL) 3090 if (sensor == NULL)
2940 return -ENOMEM; 3091 return -ENOMEM;
2941 3092
2942 sensor->platform_data = client->dev.platform_data; 3093 sensor->platform_data = pdata;
2943 mutex_init(&sensor->mutex); 3094 mutex_init(&sensor->mutex);
2944 mutex_init(&sensor->power_mutex); 3095 mutex_init(&sensor->power_mutex);
2945 sensor->src = &sensor->ssds[sensor->ssds_used]; 3096 sensor->src = &sensor->ssds[sensor->ssds_used];
@@ -2950,8 +3101,27 @@ static int smiapp_probe(struct i2c_client *client,
2950 sensor->src->sensor = sensor; 3101 sensor->src->sensor = sensor;
2951 3102
2952 sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE; 3103 sensor->src->pads[0].flags = MEDIA_PAD_FL_SOURCE;
2953 return media_entity_init(&sensor->src->sd.entity, 2, 3104 rval = media_entity_init(&sensor->src->sd.entity, 2,
2954 sensor->src->pads, 0); 3105 sensor->src->pads, 0);
3106 if (rval < 0)
3107 return rval;
3108
3109 if (client->dev.of_node) {
3110 rval = smiapp_init(sensor);
3111 if (rval)
3112 goto out_media_entity_cleanup;
3113 }
3114
3115 rval = v4l2_async_register_subdev(&sensor->src->sd);
3116 if (rval < 0)
3117 goto out_media_entity_cleanup;
3118
3119 return 0;
3120
3121out_media_entity_cleanup:
3122 media_entity_cleanup(&sensor->src->sd.entity);
3123
3124 return rval;
2955} 3125}
2956 3126
2957static int smiapp_remove(struct i2c_client *client) 3127static int smiapp_remove(struct i2c_client *client)
@@ -2960,6 +3130,8 @@ static int smiapp_remove(struct i2c_client *client)
2960 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev); 3130 struct smiapp_sensor *sensor = to_smiapp_sensor(subdev);
2961 unsigned int i; 3131 unsigned int i;
2962 3132
3133 v4l2_async_unregister_subdev(subdev);
3134
2963 if (sensor->power_count) { 3135 if (sensor->power_count) {
2964 if (gpio_is_valid(sensor->platform_data->xshutdown)) 3136 if (gpio_is_valid(sensor->platform_data->xshutdown))
2965 gpio_set_value(sensor->platform_data->xshutdown, 0); 3137 gpio_set_value(sensor->platform_data->xshutdown, 0);
@@ -2970,19 +3142,20 @@ static int smiapp_remove(struct i2c_client *client)
2970 sensor->power_count = 0; 3142 sensor->power_count = 0;
2971 } 3143 }
2972 3144
2973 device_remove_file(&client->dev, &dev_attr_ident);
2974 if (sensor->nvm)
2975 device_remove_file(&client->dev, &dev_attr_nvm);
2976
2977 for (i = 0; i < sensor->ssds_used; i++) { 3145 for (i = 0; i < sensor->ssds_used; i++) {
2978 v4l2_device_unregister_subdev(&sensor->ssds[i].sd); 3146 v4l2_device_unregister_subdev(&sensor->ssds[i].sd);
2979 media_entity_cleanup(&sensor->ssds[i].sd.entity); 3147 media_entity_cleanup(&sensor->ssds[i].sd.entity);
2980 } 3148 }
2981 smiapp_free_controls(sensor); 3149 smiapp_cleanup(sensor);
2982 3150
2983 return 0; 3151 return 0;
2984} 3152}
2985 3153
3154static const struct of_device_id smiapp_of_table[] = {
3155 { .compatible = "nokia,smia" },
3156 { },
3157};
3158
2986static const struct i2c_device_id smiapp_id_table[] = { 3159static const struct i2c_device_id smiapp_id_table[] = {
2987 { SMIAPP_NAME, 0 }, 3160 { SMIAPP_NAME, 0 },
2988 { }, 3161 { },
@@ -2996,6 +3169,7 @@ static const struct dev_pm_ops smiapp_pm_ops = {
2996 3169
2997static struct i2c_driver smiapp_i2c_driver = { 3170static struct i2c_driver smiapp_i2c_driver = {
2998 .driver = { 3171 .driver = {
3172 .of_match_table = smiapp_of_table,
2999 .name = SMIAPP_NAME, 3173 .name = SMIAPP_NAME,
3000 .pm = &smiapp_pm_ops, 3174 .pm = &smiapp_pm_ops,
3001 }, 3175 },
diff --git a/drivers/media/i2c/smiapp/smiapp-limits.c b/drivers/media/i2c/smiapp/smiapp-limits.c
index 847cb235e198..784b114d3f8b 100644
--- a/drivers/media/i2c/smiapp/smiapp-limits.c
+++ b/drivers/media/i2c/smiapp/smiapp-limits.c
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#include "smiapp.h" 19#include "smiapp.h"
diff --git a/drivers/media/i2c/smiapp/smiapp-limits.h b/drivers/media/i2c/smiapp/smiapp-limits.h
index 343e9c3827fc..b20124862a14 100644
--- a/drivers/media/i2c/smiapp/smiapp-limits.h
+++ b/drivers/media/i2c/smiapp/smiapp-limits.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#define SMIAPP_LIMIT_ANALOGUE_GAIN_CAPABILITY 0 19#define SMIAPP_LIMIT_ANALOGUE_GAIN_CAPABILITY 0
diff --git a/drivers/media/i2c/smiapp/smiapp-quirk.c b/drivers/media/i2c/smiapp/smiapp-quirk.c
index e0bee8752122..abf9ea7a0fb7 100644
--- a/drivers/media/i2c/smiapp/smiapp-quirk.c
+++ b/drivers/media/i2c/smiapp/smiapp-quirk.c
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#include <linux/delay.h> 19#include <linux/delay.h>
@@ -220,9 +214,11 @@ static int jt8ev1_post_streamoff(struct smiapp_sensor *sensor)
220 return smiapp_write_8(sensor, 0x3328, 0x80); 214 return smiapp_write_8(sensor, 0x3328, 0x80);
221} 215}
222 216
223static unsigned long jt8ev1_pll_flags(struct smiapp_sensor *sensor) 217static int jt8ev1_init(struct smiapp_sensor *sensor)
224{ 218{
225 return SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE; 219 sensor->pll.flags |= SMIAPP_PLL_FLAG_OP_PIX_CLOCK_PER_LANE;
220
221 return 0;
226} 222}
227 223
228const struct smiapp_quirk smiapp_jt8ev1_quirk = { 224const struct smiapp_quirk smiapp_jt8ev1_quirk = {
@@ -230,7 +226,7 @@ const struct smiapp_quirk smiapp_jt8ev1_quirk = {
230 .post_poweron = jt8ev1_post_poweron, 226 .post_poweron = jt8ev1_post_poweron,
231 .pre_streamon = jt8ev1_pre_streamon, 227 .pre_streamon = jt8ev1_pre_streamon,
232 .post_streamoff = jt8ev1_post_streamoff, 228 .post_streamoff = jt8ev1_post_streamoff,
233 .pll_flags = jt8ev1_pll_flags, 229 .init = jt8ev1_init,
234}; 230};
235 231
236static int tcm8500md_limits(struct smiapp_sensor *sensor) 232static int tcm8500md_limits(struct smiapp_sensor *sensor)
diff --git a/drivers/media/i2c/smiapp/smiapp-quirk.h b/drivers/media/i2c/smiapp/smiapp-quirk.h
index 46e9ea8bfa08..dac5566a2f7a 100644
--- a/drivers/media/i2c/smiapp/smiapp-quirk.h
+++ b/drivers/media/i2c/smiapp/smiapp-quirk.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#ifndef __SMIAPP_QUIRK__ 19#ifndef __SMIAPP_QUIRK__
@@ -35,6 +29,9 @@ struct smiapp_sensor;
35 * @post_poweron: Called always after the sensor has been fully powered on. 29 * @post_poweron: Called always after the sensor has been fully powered on.
36 * @pre_streamon: Called just before streaming is enabled. 30 * @pre_streamon: Called just before streaming is enabled.
37 * @post_streamon: Called right after stopping streaming. 31 * @post_streamon: Called right after stopping streaming.
32 * @pll_flags: Return flags for the PLL calculator.
33 * @init: Quirk initialisation, called the last in probe(). This is
34 * also appropriate for adding sensor specific controls, for instance.
38 * @reg_access: Register access quirk. The quirk may divert the access 35 * @reg_access: Register access quirk. The quirk may divert the access
39 * to another register, or no register at all. 36 * to another register, or no register at all.
40 * 37 *
@@ -53,6 +50,7 @@ struct smiapp_quirk {
53 int (*pre_streamon)(struct smiapp_sensor *sensor); 50 int (*pre_streamon)(struct smiapp_sensor *sensor);
54 int (*post_streamoff)(struct smiapp_sensor *sensor); 51 int (*post_streamoff)(struct smiapp_sensor *sensor);
55 unsigned long (*pll_flags)(struct smiapp_sensor *sensor); 52 unsigned long (*pll_flags)(struct smiapp_sensor *sensor);
53 int (*init)(struct smiapp_sensor *sensor);
56 int (*reg_access)(struct smiapp_sensor *sensor, bool write, u32 *reg, 54 int (*reg_access)(struct smiapp_sensor *sensor, bool write, u32 *reg,
57 u32 *val); 55 u32 *val);
58 unsigned long flags; 56 unsigned long flags;
@@ -74,14 +72,14 @@ void smiapp_replace_limit(struct smiapp_sensor *sensor,
74 .val = _val, \ 72 .val = _val, \
75 } 73 }
76 74
77#define smiapp_call_quirk(_sensor, _quirk, ...) \ 75#define smiapp_call_quirk(sensor, _quirk, ...) \
78 (_sensor->minfo.quirk && \ 76 ((sensor)->minfo.quirk && \
79 _sensor->minfo.quirk->_quirk ? \ 77 (sensor)->minfo.quirk->_quirk ? \
80 _sensor->minfo.quirk->_quirk(_sensor, ##__VA_ARGS__) : 0) 78 (sensor)->minfo.quirk->_quirk(sensor, ##__VA_ARGS__) : 0)
81 79
82#define smiapp_needs_quirk(_sensor, _quirk) \ 80#define smiapp_needs_quirk(sensor, _quirk) \
83 (_sensor->minfo.quirk ? \ 81 ((sensor)->minfo.quirk ? \
84 _sensor->minfo.quirk->flags & _quirk : 0) 82 (sensor)->minfo.quirk->flags & _quirk : 0)
85 83
86extern const struct smiapp_quirk smiapp_jt8ev1_quirk; 84extern const struct smiapp_quirk smiapp_jt8ev1_quirk;
87extern const struct smiapp_quirk smiapp_imx125es_quirk; 85extern const struct smiapp_quirk smiapp_imx125es_quirk;
diff --git a/drivers/media/i2c/smiapp/smiapp-reg-defs.h b/drivers/media/i2c/smiapp/smiapp-reg-defs.h
index c488ef028074..f928d4cc8e26 100644
--- a/drivers/media/i2c/smiapp/smiapp-reg-defs.h
+++ b/drivers/media/i2c/smiapp/smiapp-reg-defs.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24#define SMIAPP_REG_MK_U8(r) ((SMIAPP_REG_8BIT << 16) | (r)) 18#define SMIAPP_REG_MK_U8(r) ((SMIAPP_REG_8BIT << 16) | (r))
25#define SMIAPP_REG_MK_U16(r) ((SMIAPP_REG_16BIT << 16) | (r)) 19#define SMIAPP_REG_MK_U16(r) ((SMIAPP_REG_16BIT << 16) | (r))
diff --git a/drivers/media/i2c/smiapp/smiapp-reg.h b/drivers/media/i2c/smiapp/smiapp-reg.h
index b0dcbb8fa5e2..4c8b40614969 100644
--- a/drivers/media/i2c/smiapp/smiapp-reg.h
+++ b/drivers/media/i2c/smiapp/smiapp-reg.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#ifndef __SMIAPP_REG_H_ 19#ifndef __SMIAPP_REG_H_
diff --git a/drivers/media/i2c/smiapp/smiapp-regs.c b/drivers/media/i2c/smiapp/smiapp-regs.c
index a2098007fb70..6b6c20b61397 100644
--- a/drivers/media/i2c/smiapp/smiapp-regs.c
+++ b/drivers/media/i2c/smiapp/smiapp-regs.c
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#include <linux/delay.h> 19#include <linux/delay.h>
diff --git a/drivers/media/i2c/smiapp/smiapp-regs.h b/drivers/media/i2c/smiapp/smiapp-regs.h
index 35521125a2cc..6dd0e499c845 100644
--- a/drivers/media/i2c/smiapp/smiapp-regs.h
+++ b/drivers/media/i2c/smiapp/smiapp-regs.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#ifndef SMIAPP_REGS_H 19#ifndef SMIAPP_REGS_H
diff --git a/drivers/media/i2c/smiapp/smiapp.h b/drivers/media/i2c/smiapp/smiapp.h
index f88f8ec344d3..ed010a8a49d7 100644
--- a/drivers/media/i2c/smiapp/smiapp.h
+++ b/drivers/media/i2c/smiapp/smiapp.h
@@ -14,12 +14,6 @@
14 * WITHOUT ANY WARRANTY; without even the implied warranty of 14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details. 16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21 * 02110-1301 USA
22 *
23 */ 17 */
24 18
25#ifndef __SMIAPP_PRIV_H_ 19#ifndef __SMIAPP_PRIV_H_
@@ -222,7 +216,6 @@ struct smiapp_sensor {
222 u8 scaling_mode; 216 u8 scaling_mode;
223 217
224 u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */ 218 u8 hvflip_inv_mask; /* H/VFLIP inversion due to sensor orientation */
225 u8 flash_capability;
226 u8 frame_skip; 219 u8 frame_skip;
227 220
228 int power_count; 221 int power_count;
diff --git a/drivers/media/i2c/soc_camera/ov2640.c b/drivers/media/i2c/soc_camera/ov2640.c
index 6f2dd9093d94..1fdce2f6f880 100644
--- a/drivers/media/i2c/soc_camera/ov2640.c
+++ b/drivers/media/i2c/soc_camera/ov2640.c
@@ -25,6 +25,7 @@
25#include <media/v4l2-clk.h> 25#include <media/v4l2-clk.h>
26#include <media/v4l2-subdev.h> 26#include <media/v4l2-subdev.h>
27#include <media/v4l2-ctrls.h> 27#include <media/v4l2-ctrls.h>
28#include <media/v4l2-image-sizes.h>
28 29
29#define VAL_SET(x, mask, rshift, lshift) \ 30#define VAL_SET(x, mask, rshift, lshift) \
30 ((((x) >> rshift) & mask) << lshift) 31 ((((x) >> rshift) & mask) << lshift)
@@ -268,33 +269,10 @@ struct regval_list {
268 u8 value; 269 u8 value;
269}; 270};
270 271
271/* Supported resolutions */
272enum ov2640_width {
273 W_QCIF = 176,
274 W_QVGA = 320,
275 W_CIF = 352,
276 W_VGA = 640,
277 W_SVGA = 800,
278 W_XGA = 1024,
279 W_SXGA = 1280,
280 W_UXGA = 1600,
281};
282
283enum ov2640_height {
284 H_QCIF = 144,
285 H_QVGA = 240,
286 H_CIF = 288,
287 H_VGA = 480,
288 H_SVGA = 600,
289 H_XGA = 768,
290 H_SXGA = 1024,
291 H_UXGA = 1200,
292};
293
294struct ov2640_win_size { 272struct ov2640_win_size {
295 char *name; 273 char *name;
296 enum ov2640_width width; 274 u32 width;
297 enum ov2640_height height; 275 u32 height;
298 const struct regval_list *regs; 276 const struct regval_list *regs;
299}; 277};
300 278
@@ -495,17 +473,17 @@ static const struct regval_list ov2640_init_regs[] = {
495static const struct regval_list ov2640_size_change_preamble_regs[] = { 473static const struct regval_list ov2640_size_change_preamble_regs[] = {
496 { BANK_SEL, BANK_SEL_DSP }, 474 { BANK_SEL, BANK_SEL_DSP },
497 { RESET, RESET_DVP }, 475 { RESET, RESET_DVP },
498 { HSIZE8, HSIZE8_SET(W_UXGA) }, 476 { HSIZE8, HSIZE8_SET(UXGA_WIDTH) },
499 { VSIZE8, VSIZE8_SET(H_UXGA) }, 477 { VSIZE8, VSIZE8_SET(UXGA_HEIGHT) },
500 { CTRL2, CTRL2_DCW_EN | CTRL2_SDE_EN | 478 { CTRL2, CTRL2_DCW_EN | CTRL2_SDE_EN |
501 CTRL2_UV_AVG_EN | CTRL2_CMX_EN | CTRL2_UV_ADJ_EN }, 479 CTRL2_UV_AVG_EN | CTRL2_CMX_EN | CTRL2_UV_ADJ_EN },
502 { HSIZE, HSIZE_SET(W_UXGA) }, 480 { HSIZE, HSIZE_SET(UXGA_WIDTH) },
503 { VSIZE, VSIZE_SET(H_UXGA) }, 481 { VSIZE, VSIZE_SET(UXGA_HEIGHT) },
504 { XOFFL, XOFFL_SET(0) }, 482 { XOFFL, XOFFL_SET(0) },
505 { YOFFL, YOFFL_SET(0) }, 483 { YOFFL, YOFFL_SET(0) },
506 { VHYX, VHYX_HSIZE_SET(W_UXGA) | VHYX_VSIZE_SET(H_UXGA) | 484 { VHYX, VHYX_HSIZE_SET(UXGA_WIDTH) | VHYX_VSIZE_SET(UXGA_HEIGHT) |
507 VHYX_XOFF_SET(0) | VHYX_YOFF_SET(0)}, 485 VHYX_XOFF_SET(0) | VHYX_YOFF_SET(0)},
508 { TEST, TEST_HSIZE_SET(W_UXGA) }, 486 { TEST, TEST_HSIZE_SET(UXGA_WIDTH) },
509 ENDMARKER, 487 ENDMARKER,
510}; 488};
511 489
@@ -519,45 +497,45 @@ static const struct regval_list ov2640_size_change_preamble_regs[] = {
519 { RESET, 0x00} 497 { RESET, 0x00}
520 498
521static const struct regval_list ov2640_qcif_regs[] = { 499static const struct regval_list ov2640_qcif_regs[] = {
522 PER_SIZE_REG_SEQ(W_QCIF, H_QCIF, 3, 3, 4), 500 PER_SIZE_REG_SEQ(QCIF_WIDTH, QCIF_HEIGHT, 3, 3, 4),
523 ENDMARKER, 501 ENDMARKER,
524}; 502};
525 503
526static const struct regval_list ov2640_qvga_regs[] = { 504static const struct regval_list ov2640_qvga_regs[] = {
527 PER_SIZE_REG_SEQ(W_QVGA, H_QVGA, 2, 2, 4), 505 PER_SIZE_REG_SEQ(QVGA_WIDTH, QVGA_HEIGHT, 2, 2, 4),
528 ENDMARKER, 506 ENDMARKER,
529}; 507};
530 508
531static const struct regval_list ov2640_cif_regs[] = { 509static const struct regval_list ov2640_cif_regs[] = {
532 PER_SIZE_REG_SEQ(W_CIF, H_CIF, 2, 2, 8), 510 PER_SIZE_REG_SEQ(CIF_WIDTH, CIF_HEIGHT, 2, 2, 8),
533 ENDMARKER, 511 ENDMARKER,
534}; 512};
535 513
536static const struct regval_list ov2640_vga_regs[] = { 514static const struct regval_list ov2640_vga_regs[] = {
537 PER_SIZE_REG_SEQ(W_VGA, H_VGA, 0, 0, 2), 515 PER_SIZE_REG_SEQ(VGA_WIDTH, VGA_HEIGHT, 0, 0, 2),
538 ENDMARKER, 516 ENDMARKER,
539}; 517};
540 518
541static const struct regval_list ov2640_svga_regs[] = { 519static const struct regval_list ov2640_svga_regs[] = {
542 PER_SIZE_REG_SEQ(W_SVGA, H_SVGA, 1, 1, 2), 520 PER_SIZE_REG_SEQ(SVGA_WIDTH, SVGA_HEIGHT, 1, 1, 2),
543 ENDMARKER, 521 ENDMARKER,
544}; 522};
545 523
546static const struct regval_list ov2640_xga_regs[] = { 524static const struct regval_list ov2640_xga_regs[] = {
547 PER_SIZE_REG_SEQ(W_XGA, H_XGA, 0, 0, 2), 525 PER_SIZE_REG_SEQ(XGA_WIDTH, XGA_HEIGHT, 0, 0, 2),
548 { CTRLI, 0x00}, 526 { CTRLI, 0x00},
549 ENDMARKER, 527 ENDMARKER,
550}; 528};
551 529
552static const struct regval_list ov2640_sxga_regs[] = { 530static const struct regval_list ov2640_sxga_regs[] = {
553 PER_SIZE_REG_SEQ(W_SXGA, H_SXGA, 0, 0, 2), 531 PER_SIZE_REG_SEQ(SXGA_WIDTH, SXGA_HEIGHT, 0, 0, 2),
554 { CTRLI, 0x00}, 532 { CTRLI, 0x00},
555 { R_DVP_SP, 2 | R_DVP_SP_AUTO_MODE }, 533 { R_DVP_SP, 2 | R_DVP_SP_AUTO_MODE },
556 ENDMARKER, 534 ENDMARKER,
557}; 535};
558 536
559static const struct regval_list ov2640_uxga_regs[] = { 537static const struct regval_list ov2640_uxga_regs[] = {
560 PER_SIZE_REG_SEQ(W_UXGA, H_UXGA, 0, 0, 0), 538 PER_SIZE_REG_SEQ(UXGA_WIDTH, UXGA_HEIGHT, 0, 0, 0),
561 { CTRLI, 0x00}, 539 { CTRLI, 0x00},
562 { R_DVP_SP, 0 | R_DVP_SP_AUTO_MODE }, 540 { R_DVP_SP, 0 | R_DVP_SP_AUTO_MODE },
563 ENDMARKER, 541 ENDMARKER,
@@ -567,14 +545,14 @@ static const struct regval_list ov2640_uxga_regs[] = {
567 {.name = n, .width = w , .height = h, .regs = r } 545 {.name = n, .width = w , .height = h, .regs = r }
568 546
569static const struct ov2640_win_size ov2640_supported_win_sizes[] = { 547static const struct ov2640_win_size ov2640_supported_win_sizes[] = {
570 OV2640_SIZE("QCIF", W_QCIF, H_QCIF, ov2640_qcif_regs), 548 OV2640_SIZE("QCIF", QCIF_WIDTH, QCIF_HEIGHT, ov2640_qcif_regs),
571 OV2640_SIZE("QVGA", W_QVGA, H_QVGA, ov2640_qvga_regs), 549 OV2640_SIZE("QVGA", QVGA_WIDTH, QVGA_HEIGHT, ov2640_qvga_regs),
572 OV2640_SIZE("CIF", W_CIF, H_CIF, ov2640_cif_regs), 550 OV2640_SIZE("CIF", CIF_WIDTH, CIF_HEIGHT, ov2640_cif_regs),
573 OV2640_SIZE("VGA", W_VGA, H_VGA, ov2640_vga_regs), 551 OV2640_SIZE("VGA", VGA_WIDTH, VGA_HEIGHT, ov2640_vga_regs),
574 OV2640_SIZE("SVGA", W_SVGA, H_SVGA, ov2640_svga_regs), 552 OV2640_SIZE("SVGA", SVGA_WIDTH, SVGA_HEIGHT, ov2640_svga_regs),
575 OV2640_SIZE("XGA", W_XGA, H_XGA, ov2640_xga_regs), 553 OV2640_SIZE("XGA", XGA_WIDTH, XGA_HEIGHT, ov2640_xga_regs),
576 OV2640_SIZE("SXGA", W_SXGA, H_SXGA, ov2640_sxga_regs), 554 OV2640_SIZE("SXGA", SXGA_WIDTH, SXGA_HEIGHT, ov2640_sxga_regs),
577 OV2640_SIZE("UXGA", W_UXGA, H_UXGA, ov2640_uxga_regs), 555 OV2640_SIZE("UXGA", UXGA_WIDTH, UXGA_HEIGHT, ov2640_uxga_regs),
578}; 556};
579 557
580/* 558/*
@@ -867,7 +845,7 @@ static int ov2640_g_fmt(struct v4l2_subdev *sd,
867 struct ov2640_priv *priv = to_ov2640(client); 845 struct ov2640_priv *priv = to_ov2640(client);
868 846
869 if (!priv->win) { 847 if (!priv->win) {
870 u32 width = W_SVGA, height = H_SVGA; 848 u32 width = SVGA_WIDTH, height = SVGA_HEIGHT;
871 priv->win = ov2640_select_win(&width, &height); 849 priv->win = ov2640_select_win(&width, &height);
872 priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8; 850 priv->cfmt_code = MEDIA_BUS_FMT_UYVY8_2X8;
873 } 851 }
@@ -954,8 +932,8 @@ static int ov2640_g_crop(struct v4l2_subdev *sd, struct v4l2_crop *a)
954{ 932{
955 a->c.left = 0; 933 a->c.left = 0;
956 a->c.top = 0; 934 a->c.top = 0;
957 a->c.width = W_UXGA; 935 a->c.width = UXGA_WIDTH;
958 a->c.height = H_UXGA; 936 a->c.height = UXGA_HEIGHT;
959 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 937 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
960 938
961 return 0; 939 return 0;
@@ -965,8 +943,8 @@ static int ov2640_cropcap(struct v4l2_subdev *sd, struct v4l2_cropcap *a)
965{ 943{
966 a->bounds.left = 0; 944 a->bounds.left = 0;
967 a->bounds.top = 0; 945 a->bounds.top = 0;
968 a->bounds.width = W_UXGA; 946 a->bounds.width = UXGA_WIDTH;
969 a->bounds.height = H_UXGA; 947 a->bounds.height = UXGA_HEIGHT;
970 a->defrect = a->bounds; 948 a->defrect = a->bounds;
971 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 949 a->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
972 a->pixelaspect.numerator = 1; 950 a->pixelaspect.numerator = 1;
diff --git a/drivers/media/i2c/ths8200.c b/drivers/media/i2c/ths8200.c
index 656d889c1c79..4ebd329d7b42 100644
--- a/drivers/media/i2c/ths8200.c
+++ b/drivers/media/i2c/ths8200.c
@@ -58,21 +58,11 @@ static inline struct ths8200_state *to_state(struct v4l2_subdev *sd)
58 return container_of(sd, struct ths8200_state, sd); 58 return container_of(sd, struct ths8200_state, sd);
59} 59}
60 60
61static inline unsigned hblanking(const struct v4l2_bt_timings *t)
62{
63 return V4L2_DV_BT_BLANKING_WIDTH(t);
64}
65
66static inline unsigned htotal(const struct v4l2_bt_timings *t) 61static inline unsigned htotal(const struct v4l2_bt_timings *t)
67{ 62{
68 return V4L2_DV_BT_FRAME_WIDTH(t); 63 return V4L2_DV_BT_FRAME_WIDTH(t);
69} 64}
70 65
71static inline unsigned vblanking(const struct v4l2_bt_timings *t)
72{
73 return V4L2_DV_BT_BLANKING_HEIGHT(t);
74}
75
76static inline unsigned vtotal(const struct v4l2_bt_timings *t) 66static inline unsigned vtotal(const struct v4l2_bt_timings *t)
77{ 67{
78 return V4L2_DV_BT_FRAME_HEIGHT(t); 68 return V4L2_DV_BT_FRAME_HEIGHT(t);
diff --git a/drivers/media/mmc/siano/Kconfig b/drivers/media/mmc/siano/Kconfig
index aa05ad3c1ccb..7693487e2f63 100644
--- a/drivers/media/mmc/siano/Kconfig
+++ b/drivers/media/mmc/siano/Kconfig
@@ -6,6 +6,8 @@ config SMS_SDIO_DRV
6 tristate "Siano SMS1xxx based MDTV via SDIO interface" 6 tristate "Siano SMS1xxx based MDTV via SDIO interface"
7 depends on DVB_CORE && HAS_DMA 7 depends on DVB_CORE && HAS_DMA
8 depends on MMC 8 depends on MMC
9 depends on !RC_CORE || RC_CORE
9 select MEDIA_COMMON_OPTIONS 10 select MEDIA_COMMON_OPTIONS
11 select SMS_SIANO_MDTV
10 ---help--- 12 ---help---
11 Choose if you would like to have Siano's support for SDIO interface 13 Choose if you would like to have Siano's support for SDIO interface
diff --git a/drivers/media/pci/bt8xx/Kconfig b/drivers/media/pci/bt8xx/Kconfig
index 61d09e010814..4a93f6ded100 100644
--- a/drivers/media/pci/bt8xx/Kconfig
+++ b/drivers/media/pci/bt8xx/Kconfig
@@ -2,15 +2,17 @@ config VIDEO_BT848
2 tristate "BT848 Video For Linux" 2 tristate "BT848 Video For Linux"
3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2 3 depends on VIDEO_DEV && PCI && I2C && VIDEO_V4L2
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX
6 select VIDEOBUF_DMA_SG 5 select VIDEOBUF_DMA_SG
7 depends on RC_CORE 6 depends on RC_CORE
7 depends on MEDIA_RADIO_SUPPORT
8 select VIDEO_TUNER 8 select VIDEO_TUNER
9 select VIDEO_TVEEPROM 9 select VIDEO_TVEEPROM
10 select VIDEO_MSP3400 if MEDIA_SUBDRV_AUTOSELECT 10 select VIDEO_MSP3400 if MEDIA_SUBDRV_AUTOSELECT
11 select VIDEO_TVAUDIO if MEDIA_SUBDRV_AUTOSELECT 11 select VIDEO_TVAUDIO if MEDIA_SUBDRV_AUTOSELECT
12 select VIDEO_TDA7432 if MEDIA_SUBDRV_AUTOSELECT 12 select VIDEO_TDA7432 if MEDIA_SUBDRV_AUTOSELECT
13 select VIDEO_SAA6588 if MEDIA_SUBDRV_AUTOSELECT 13 select VIDEO_SAA6588 if MEDIA_SUBDRV_AUTOSELECT
14 select RADIO_ADAPTERS
15 select RADIO_TEA575X
14 ---help--- 16 ---help---
15 Support for BT848 based frame grabber/overlay boards. This includes 17 Support for BT848 based frame grabber/overlay boards. This includes
16 the Miro, Hauppauge and STB boards. Please read the material in 18 the Miro, Hauppauge and STB boards. Please read the material in
diff --git a/drivers/media/pci/bt8xx/Makefile b/drivers/media/pci/bt8xx/Makefile
index f9fe7c4e7d53..2d4c3dd88be1 100644
--- a/drivers/media/pci/bt8xx/Makefile
+++ b/drivers/media/pci/bt8xx/Makefile
@@ -1,6 +1,6 @@
1bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \ 1bttv-objs := bttv-driver.o bttv-cards.o bttv-if.o \
2 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \ 2 bttv-risc.o bttv-vbi.o bttv-i2c.o bttv-gpio.o \
3 bttv-input.o bttv-audio-hook.o 3 bttv-input.o bttv-audio-hook.o btcx-risc.o
4 4
5obj-$(CONFIG_VIDEO_BT848) += bttv.o 5obj-$(CONFIG_VIDEO_BT848) += bttv.o
6obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o 6obj-$(CONFIG_DVB_BT8XX) += bt878.o dvb-bt8xx.o dst.o dst_ca.o
diff --git a/drivers/media/pci/bt8xx/bt878.c b/drivers/media/pci/bt8xx/bt878.c
index 11765835d7b2..0939d399b774 100644
--- a/drivers/media/pci/bt8xx/bt878.c
+++ b/drivers/media/pci/bt8xx/bt878.c
@@ -590,9 +590,3 @@ module_init(bt878_init_module);
590module_exit(bt878_cleanup_module); 590module_exit(bt878_cleanup_module);
591 591
592MODULE_LICENSE("GPL"); 592MODULE_LICENSE("GPL");
593
594/*
595 * Local variables:
596 * c-basic-offset: 8
597 * End:
598 */
diff --git a/drivers/media/common/btcx-risc.c b/drivers/media/pci/bt8xx/btcx-risc.c
index ac1b2687a20d..00f0880b6d66 100644
--- a/drivers/media/common/btcx-risc.c
+++ b/drivers/media/pci/bt8xx/btcx-risc.c
@@ -32,13 +32,9 @@
32 32
33#include "btcx-risc.h" 33#include "btcx-risc.h"
34 34
35MODULE_DESCRIPTION("some code shared by bttv and cx88xx drivers"); 35static unsigned int btcx_debug;
36MODULE_AUTHOR("Gerd Knorr"); 36module_param(btcx_debug, int, 0644);
37MODULE_LICENSE("GPL"); 37MODULE_PARM_DESC(btcx_debug,"debug messages, default is 0 (no)");
38
39static unsigned int debug;
40module_param(debug, int, 0644);
41MODULE_PARM_DESC(debug,"debug messages, default is 0 (no)");
42 38
43/* ---------------------------------------------------------- */ 39/* ---------------------------------------------------------- */
44/* allocate/free risc memory */ 40/* allocate/free risc memory */
@@ -50,7 +46,7 @@ void btcx_riscmem_free(struct pci_dev *pci,
50{ 46{
51 if (NULL == risc->cpu) 47 if (NULL == risc->cpu)
52 return; 48 return;
53 if (debug) { 49 if (btcx_debug) {
54 memcnt--; 50 memcnt--;
55 printk("btcx: riscmem free [%d] dma=%lx\n", 51 printk("btcx: riscmem free [%d] dma=%lx\n",
56 memcnt, (unsigned long)risc->dma); 52 memcnt, (unsigned long)risc->dma);
@@ -75,7 +71,7 @@ int btcx_riscmem_alloc(struct pci_dev *pci,
75 risc->cpu = cpu; 71 risc->cpu = cpu;
76 risc->dma = dma; 72 risc->dma = dma;
77 risc->size = size; 73 risc->size = size;
78 if (debug) { 74 if (btcx_debug) {
79 memcnt++; 75 memcnt++;
80 printk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n", 76 printk("btcx: riscmem alloc [%d] dma=%lx cpu=%p size=%d\n",
81 memcnt, (unsigned long)dma, cpu, size); 77 memcnt, (unsigned long)dma, cpu, size);
@@ -141,7 +137,7 @@ btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips, unsigned int n, int m
141 dx = nx - win->left; 137 dx = nx - win->left;
142 win->left = nx; 138 win->left = nx;
143 win->width = nw; 139 win->width = nw;
144 if (debug) 140 if (btcx_debug)
145 printk(KERN_DEBUG "btcx: window align %dx%d+%d+%d [dx=%d]\n", 141 printk(KERN_DEBUG "btcx: window align %dx%d+%d+%d [dx=%d]\n",
146 win->width, win->height, win->left, win->top, dx); 142 win->width, win->height, win->left, win->top, dx);
147 143
@@ -153,7 +149,7 @@ btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips, unsigned int n, int m
153 nw += mask+1; 149 nw += mask+1;
154 clips[i].c.left = nx; 150 clips[i].c.left = nx;
155 clips[i].c.width = nw; 151 clips[i].c.width = nw;
156 if (debug) 152 if (btcx_debug)
157 printk(KERN_DEBUG "btcx: clip align %dx%d+%d+%d\n", 153 printk(KERN_DEBUG "btcx: clip align %dx%d+%d+%d\n",
158 clips[i].c.width, clips[i].c.height, 154 clips[i].c.width, clips[i].c.height,
159 clips[i].c.left, clips[i].c.top); 155 clips[i].c.left, clips[i].c.top);
@@ -234,7 +230,7 @@ btcx_calc_skips(int line, int width, int *maxy,
234 *nskips = skip; 230 *nskips = skip;
235 *maxy = maxline; 231 *maxy = maxline;
236 232
237 if (debug) { 233 if (btcx_debug) {
238 printk(KERN_DEBUG "btcx: skips line %d-%d:",line,maxline); 234 printk(KERN_DEBUG "btcx: skips line %d-%d:",line,maxline);
239 for (skip = 0; skip < *nskips; skip++) { 235 for (skip = 0; skip < *nskips; skip++) {
240 printk(" %d-%d",skips[skip].start,skips[skip].end); 236 printk(" %d-%d",skips[skip].start,skips[skip].end);
@@ -242,19 +238,3 @@ btcx_calc_skips(int line, int width, int *maxy,
242 printk("\n"); 238 printk("\n");
243 } 239 }
244} 240}
245
246/* ---------------------------------------------------------- */
247
248EXPORT_SYMBOL(btcx_riscmem_alloc);
249EXPORT_SYMBOL(btcx_riscmem_free);
250
251EXPORT_SYMBOL(btcx_screen_clips);
252EXPORT_SYMBOL(btcx_align);
253EXPORT_SYMBOL(btcx_sort_clips);
254EXPORT_SYMBOL(btcx_calc_skips);
255
256/*
257 * Local variables:
258 * c-basic-offset: 8
259 * End:
260 */
diff --git a/drivers/media/pci/bt8xx/btcx-risc.h b/drivers/media/pci/bt8xx/btcx-risc.h
new file mode 100644
index 000000000000..1ed7a000160a
--- /dev/null
+++ b/drivers/media/pci/bt8xx/btcx-risc.h
@@ -0,0 +1,26 @@
1struct btcx_riscmem {
2 unsigned int size;
3 __le32 *cpu;
4 __le32 *jmp;
5 dma_addr_t dma;
6};
7
8struct btcx_skiplist {
9 int start;
10 int end;
11};
12
13int btcx_riscmem_alloc(struct pci_dev *pci,
14 struct btcx_riscmem *risc,
15 unsigned int size);
16void btcx_riscmem_free(struct pci_dev *pci,
17 struct btcx_riscmem *risc);
18
19int btcx_screen_clips(int swidth, int sheight, struct v4l2_rect *win,
20 struct v4l2_clip *clips, unsigned int n);
21int btcx_align(struct v4l2_rect *win, struct v4l2_clip *clips,
22 unsigned int n, int mask);
23void btcx_sort_clips(struct v4l2_clip *clips, unsigned int nclips);
24void btcx_calc_skips(int line, int width, int *maxy,
25 struct btcx_skiplist *skips, unsigned int *nskips,
26 const struct v4l2_clip *clips, unsigned int nclips);
diff --git a/drivers/media/pci/bt8xx/bttv-cards.c b/drivers/media/pci/bt8xx/bttv-cards.c
index 41055606b969..4654fb65ca21 100644
--- a/drivers/media/pci/bt8xx/bttv-cards.c
+++ b/drivers/media/pci/bt8xx/bttv-cards.c
@@ -84,8 +84,7 @@ static void gv800s_init(struct bttv *btv);
84static void td3116_muxsel(struct bttv *btv, unsigned int input); 84static void td3116_muxsel(struct bttv *btv, unsigned int input);
85 85
86static int terratec_active_radio_upgrade(struct bttv *btv); 86static int terratec_active_radio_upgrade(struct bttv *btv);
87static int tea5757_read(struct bttv *btv); 87static int tea575x_init(struct bttv *btv);
88static int tea5757_write(struct bttv *btv, int value);
89static void identify_by_eeprom(struct bttv *btv, 88static void identify_by_eeprom(struct bttv *btv,
90 unsigned char eeprom_data[256]); 89 unsigned char eeprom_data[256]);
91static int pvr_boot(struct bttv *btv); 90static int pvr_boot(struct bttv *btv);
@@ -3085,12 +3084,12 @@ static void miro_pinnacle_gpio(struct bttv *btv)
3085 if (0 == (gpio & 0x20)) { 3084 if (0 == (gpio & 0x20)) {
3086 btv->has_radio = 1; 3085 btv->has_radio = 1;
3087 if (!miro_fmtuner[id]) { 3086 if (!miro_fmtuner[id]) {
3088 btv->has_matchbox = 1; 3087 btv->has_tea575x = 1;
3089 btv->mbox_we = (1<<6); 3088 btv->tea_gpio.wren = 6;
3090 btv->mbox_most = (1<<7); 3089 btv->tea_gpio.most = 7;
3091 btv->mbox_clk = (1<<8); 3090 btv->tea_gpio.clk = 8;
3092 btv->mbox_data = (1<<9); 3091 btv->tea_gpio.data = 9;
3093 btv->mbox_mask = (1<<6)|(1<<7)|(1<<8)|(1<<9); 3092 tea575x_init(btv);
3094 } 3093 }
3095 } else { 3094 } else {
3096 btv->has_radio = 0; 3095 btv->has_radio = 0;
@@ -3104,7 +3103,7 @@ static void miro_pinnacle_gpio(struct bttv *btv)
3104 pr_info("%d: miro: id=%d tuner=%d radio=%s stereo=%s\n", 3103 pr_info("%d: miro: id=%d tuner=%d radio=%s stereo=%s\n",
3105 btv->c.nr, id+1, btv->tuner_type, 3104 btv->c.nr, id+1, btv->tuner_type,
3106 !btv->has_radio ? "no" : 3105 !btv->has_radio ? "no" :
3107 (btv->has_matchbox ? "matchbox" : "fmtuner"), 3106 (btv->has_tea575x ? "tea575x" : "fmtuner"),
3108 (-1 == msp) ? "no" : "yes"); 3107 (-1 == msp) ? "no" : "yes");
3109 } else { 3108 } else {
3110 /* new cards with microtune tuner */ 3109 /* new cards with microtune tuner */
@@ -3382,12 +3381,12 @@ void bttv_init_card2(struct bttv *btv)
3382 break; 3381 break;
3383 case BTTV_BOARD_VHX: 3382 case BTTV_BOARD_VHX:
3384 btv->has_radio = 1; 3383 btv->has_radio = 1;
3385 btv->has_matchbox = 1; 3384 btv->has_tea575x = 1;
3386 btv->mbox_we = 0x20; 3385 btv->tea_gpio.wren = 5;
3387 btv->mbox_most = 0; 3386 btv->tea_gpio.most = 6;
3388 btv->mbox_clk = 0x08; 3387 btv->tea_gpio.clk = 3;
3389 btv->mbox_data = 0x10; 3388 btv->tea_gpio.data = 4;
3390 btv->mbox_mask = 0x38; 3389 tea575x_init(btv);
3391 break; 3390 break;
3392 case BTTV_BOARD_VOBIS_BOOSTAR: 3391 case BTTV_BOARD_VOBIS_BOOSTAR:
3393 case BTTV_BOARD_TERRATV: 3392 case BTTV_BOARD_TERRATV:
@@ -3745,33 +3744,112 @@ static void hauppauge_eeprom(struct bttv *btv)
3745 btv->radio_uses_msp_demodulator = 1; 3744 btv->radio_uses_msp_demodulator = 1;
3746} 3745}
3747 3746
3748static int terratec_active_radio_upgrade(struct bttv *btv) 3747/* ----------------------------------------------------------------------- */
3748
3749static void bttv_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
3750{
3751 struct bttv *btv = tea->private_data;
3752 struct bttv_tea575x_gpio gpio = btv->tea_gpio;
3753 u16 val = 0;
3754
3755 val |= (pins & TEA575X_DATA) ? (1 << gpio.data) : 0;
3756 val |= (pins & TEA575X_CLK) ? (1 << gpio.clk) : 0;
3757 val |= (pins & TEA575X_WREN) ? (1 << gpio.wren) : 0;
3758
3759 gpio_bits((1 << gpio.data) | (1 << gpio.clk) | (1 << gpio.wren), val);
3760 if (btv->mbox_ior) {
3761 /* IOW and CSEL active */
3762 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
3763 udelay(5);
3764 /* all inactive */
3765 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3766 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3767 }
3768}
3769
3770static u8 bttv_tea575x_get_pins(struct snd_tea575x *tea)
3771{
3772 struct bttv *btv = tea->private_data;
3773 struct bttv_tea575x_gpio gpio = btv->tea_gpio;
3774 u8 ret = 0;
3775 u16 val;
3776
3777 if (btv->mbox_ior) {
3778 /* IOR and CSEL active */
3779 gpio_bits(btv->mbox_ior | btv->mbox_csel, 0);
3780 udelay(5);
3781 }
3782 val = gpio_read();
3783 if (btv->mbox_ior) {
3784 /* all inactive */
3785 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
3786 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
3787 }
3788
3789 if (val & (1 << gpio.data))
3790 ret |= TEA575X_DATA;
3791 if (val & (1 << gpio.most))
3792 ret |= TEA575X_MOST;
3793
3794 return ret;
3795}
3796
3797static void bttv_tea575x_set_direction(struct snd_tea575x *tea, bool output)
3749{ 3798{
3750 int freq; 3799 struct bttv *btv = tea->private_data;
3800 struct bttv_tea575x_gpio gpio = btv->tea_gpio;
3801 u32 mask = (1 << gpio.clk) | (1 << gpio.wren) | (1 << gpio.data) |
3802 (1 << gpio.most);
3803
3804 if (output)
3805 gpio_inout(mask, (1 << gpio.data) | (1 << gpio.clk) |
3806 (1 << gpio.wren));
3807 else
3808 gpio_inout(mask, (1 << gpio.clk) | (1 << gpio.wren));
3809}
3810
3811static struct snd_tea575x_ops bttv_tea_ops = {
3812 .set_pins = bttv_tea575x_set_pins,
3813 .get_pins = bttv_tea575x_get_pins,
3814 .set_direction = bttv_tea575x_set_direction,
3815};
3816
3817static int tea575x_init(struct bttv *btv)
3818{
3819 btv->tea.private_data = btv;
3820 btv->tea.ops = &bttv_tea_ops;
3821 if (!snd_tea575x_hw_init(&btv->tea)) {
3822 pr_info("%d: detected TEA575x radio\n", btv->c.nr);
3823 btv->tea.mute = false;
3824 return 0;
3825 }
3826
3827 btv->has_tea575x = 0;
3828 btv->has_radio = 0;
3751 3829
3830 return -ENODEV;
3831}
3832
3833/* ----------------------------------------------------------------------- */
3834
3835static int terratec_active_radio_upgrade(struct bttv *btv)
3836{
3752 btv->has_radio = 1; 3837 btv->has_radio = 1;
3753 btv->has_matchbox = 1; 3838 btv->has_tea575x = 1;
3754 btv->mbox_we = 0x10; 3839 btv->tea_gpio.wren = 4;
3755 btv->mbox_most = 0x20; 3840 btv->tea_gpio.most = 5;
3756 btv->mbox_clk = 0x08; 3841 btv->tea_gpio.clk = 3;
3757 btv->mbox_data = 0x04; 3842 btv->tea_gpio.data = 2;
3758 btv->mbox_mask = 0x3c;
3759 3843
3760 btv->mbox_iow = 1 << 8; 3844 btv->mbox_iow = 1 << 8;
3761 btv->mbox_ior = 1 << 9; 3845 btv->mbox_ior = 1 << 9;
3762 btv->mbox_csel = 1 << 10; 3846 btv->mbox_csel = 1 << 10;
3763 3847
3764 freq=88000/62.5; 3848 if (!tea575x_init(btv)) {
3765 tea5757_write(btv, 5 * freq + 0x358); /* write 0x1ed8 */
3766 if (0x1ed8 == tea5757_read(btv)) {
3767 pr_info("%d: Terratec Active Radio Upgrade found\n", btv->c.nr); 3849 pr_info("%d: Terratec Active Radio Upgrade found\n", btv->c.nr);
3768 btv->has_radio = 1; 3850 btv->has_saa6588 = 1;
3769 btv->has_saa6588 = 1;
3770 btv->has_matchbox = 1;
3771 } else {
3772 btv->has_radio = 0;
3773 btv->has_matchbox = 0;
3774 } 3851 }
3852
3775 return 0; 3853 return 0;
3776} 3854}
3777 3855
@@ -4292,181 +4370,6 @@ init_PCI8604PW(struct bttv *btv)
4292 } 4370 }
4293} 4371}
4294 4372
4295
4296
4297/* ----------------------------------------------------------------------- */
4298/* Miro Pro radio stuff -- the tea5757 is connected to some GPIO ports */
4299/*
4300 * Copyright (c) 1999 Csaba Halasz <qgehali@uni-miskolc.hu>
4301 * This code is placed under the terms of the GNU General Public License
4302 *
4303 * Brutally hacked by Dan Sheridan <dan.sheridan@contact.org.uk> djs52 8/3/00
4304 */
4305
4306static void bus_low(struct bttv *btv, int bit)
4307{
4308 if (btv->mbox_ior) {
4309 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4310 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4311 udelay(5);
4312 }
4313
4314 gpio_bits(bit,0);
4315 udelay(5);
4316
4317 if (btv->mbox_ior) {
4318 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4319 udelay(5);
4320 }
4321}
4322
4323static void bus_high(struct bttv *btv, int bit)
4324{
4325 if (btv->mbox_ior) {
4326 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4327 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4328 udelay(5);
4329 }
4330
4331 gpio_bits(bit,bit);
4332 udelay(5);
4333
4334 if (btv->mbox_ior) {
4335 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4336 udelay(5);
4337 }
4338}
4339
4340static int bus_in(struct bttv *btv, int bit)
4341{
4342 if (btv->mbox_ior) {
4343 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4344 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4345 udelay(5);
4346
4347 gpio_bits(btv->mbox_iow | btv->mbox_csel, 0);
4348 udelay(5);
4349 }
4350 return gpio_read() & (bit);
4351}
4352
4353/* TEA5757 register bits */
4354#define TEA_FREQ 0:14
4355#define TEA_BUFFER 15:15
4356
4357#define TEA_SIGNAL_STRENGTH 16:17
4358
4359#define TEA_PORT1 18:18
4360#define TEA_PORT0 19:19
4361
4362#define TEA_BAND 20:21
4363#define TEA_BAND_FM 0
4364#define TEA_BAND_MW 1
4365#define TEA_BAND_LW 2
4366#define TEA_BAND_SW 3
4367
4368#define TEA_MONO 22:22
4369#define TEA_ALLOW_STEREO 0
4370#define TEA_FORCE_MONO 1
4371
4372#define TEA_SEARCH_DIRECTION 23:23
4373#define TEA_SEARCH_DOWN 0
4374#define TEA_SEARCH_UP 1
4375
4376#define TEA_STATUS 24:24
4377#define TEA_STATUS_TUNED 0
4378#define TEA_STATUS_SEARCHING 1
4379
4380/* Low-level stuff */
4381static int tea5757_read(struct bttv *btv)
4382{
4383 unsigned long timeout;
4384 int value = 0;
4385 int i;
4386
4387 /* better safe than sorry */
4388 gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we);
4389
4390 if (btv->mbox_ior) {
4391 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4392 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4393 udelay(5);
4394 }
4395
4396 if (bttv_gpio)
4397 bttv_gpio_tracking(btv,"tea5757 read");
4398
4399 bus_low(btv,btv->mbox_we);
4400 bus_low(btv,btv->mbox_clk);
4401
4402 udelay(10);
4403 timeout= jiffies + msecs_to_jiffies(1000);
4404
4405 /* wait for DATA line to go low; error if it doesn't */
4406 while (bus_in(btv,btv->mbox_data) && time_before(jiffies, timeout))
4407 schedule();
4408 if (bus_in(btv,btv->mbox_data)) {
4409 pr_warn("%d: tea5757: read timeout\n", btv->c.nr);
4410 return -1;
4411 }
4412
4413 dprintk("%d: tea5757:", btv->c.nr);
4414 for (i = 0; i < 24; i++) {
4415 udelay(5);
4416 bus_high(btv,btv->mbox_clk);
4417 udelay(5);
4418 dprintk_cont("%c",
4419 bus_in(btv, btv->mbox_most) == 0 ? 'T' : '-');
4420 bus_low(btv,btv->mbox_clk);
4421 value <<= 1;
4422 value |= (bus_in(btv,btv->mbox_data) == 0)?0:1; /* MSB first */
4423 dprintk_cont("%c",
4424 bus_in(btv, btv->mbox_most) == 0 ? 'S' : 'M');
4425 }
4426 dprintk_cont("\n");
4427 dprintk("%d: tea5757: read 0x%X\n", btv->c.nr, value);
4428 return value;
4429}
4430
4431static int tea5757_write(struct bttv *btv, int value)
4432{
4433 int i;
4434 int reg = value;
4435
4436 gpio_inout(btv->mbox_mask, btv->mbox_clk | btv->mbox_we | btv->mbox_data);
4437
4438 if (btv->mbox_ior) {
4439 gpio_bits(btv->mbox_ior | btv->mbox_iow | btv->mbox_csel,
4440 btv->mbox_ior | btv->mbox_iow | btv->mbox_csel);
4441 udelay(5);
4442 }
4443 if (bttv_gpio)
4444 bttv_gpio_tracking(btv,"tea5757 write");
4445
4446 dprintk("%d: tea5757: write 0x%X\n", btv->c.nr, value);
4447 bus_low(btv,btv->mbox_clk);
4448 bus_high(btv,btv->mbox_we);
4449 for (i = 0; i < 25; i++) {
4450 if (reg & 0x1000000)
4451 bus_high(btv,btv->mbox_data);
4452 else
4453 bus_low(btv,btv->mbox_data);
4454 reg <<= 1;
4455 bus_high(btv,btv->mbox_clk);
4456 udelay(10);
4457 bus_low(btv,btv->mbox_clk);
4458 udelay(10);
4459 }
4460 bus_low(btv,btv->mbox_we); /* unmute !!! */
4461 return 0;
4462}
4463
4464void tea5757_set_freq(struct bttv *btv, unsigned short freq)
4465{
4466 dprintk("tea5757_set_freq %d\n",freq);
4467 tea5757_write(btv, 5 * freq + 0x358); /* add 10.7MHz (see docs) */
4468}
4469
4470/* RemoteVision MX (rv605) muxsel helper [Miguel Freitas] 4373/* RemoteVision MX (rv605) muxsel helper [Miguel Freitas]
4471 * 4374 *
4472 * This is needed because rv605 don't use a normal multiplex, but a crosspoint 4375 * This is needed because rv605 don't use a normal multiplex, but a crosspoint
@@ -5048,10 +4951,3 @@ int bttv_handle_chipset(struct bttv *btv)
5048 pci_write_config_byte(btv->c.pci, PCI_LATENCY_TIMER, latency); 4951 pci_write_config_byte(btv->c.pci, PCI_LATENCY_TIMER, latency);
5049 return 0; 4952 return 0;
5050} 4953}
5051
5052
5053/*
5054 * Local variables:
5055 * c-basic-offset: 8
5056 * End:
5057 */
diff --git a/drivers/media/pci/bt8xx/bttv-driver.c b/drivers/media/pci/bt8xx/bttv-driver.c
index 4a8176c09fc9..4ec2a3c3f23c 100644
--- a/drivers/media/pci/bt8xx/bttv-driver.c
+++ b/drivers/media/pci/bt8xx/bttv-driver.c
@@ -1874,8 +1874,10 @@ static void bttv_set_frequency(struct bttv *btv, const struct v4l2_frequency *f)
1874 if (new_freq.type == V4L2_TUNER_RADIO) { 1874 if (new_freq.type == V4L2_TUNER_RADIO) {
1875 radio_enable(btv); 1875 radio_enable(btv);
1876 btv->radio_freq = new_freq.frequency; 1876 btv->radio_freq = new_freq.frequency;
1877 if (btv->has_matchbox) 1877 if (btv->has_tea575x) {
1878 tea5757_set_freq(btv, btv->radio_freq); 1878 btv->tea.freq = btv->radio_freq;
1879 snd_tea575x_set_freq(&btv->tea);
1880 }
1879 } else { 1881 } else {
1880 btv->tv_freq = new_freq.frequency; 1882 btv->tv_freq = new_freq.frequency;
1881 } 1883 }
@@ -2513,6 +2515,8 @@ static int bttv_querycap(struct file *file, void *priv,
2513 if (btv->has_saa6588) 2515 if (btv->has_saa6588)
2514 cap->device_caps |= V4L2_CAP_READWRITE | 2516 cap->device_caps |= V4L2_CAP_READWRITE |
2515 V4L2_CAP_RDS_CAPTURE; 2517 V4L2_CAP_RDS_CAPTURE;
2518 if (btv->has_tea575x)
2519 cap->device_caps |= V4L2_CAP_HW_FREQ_SEEK;
2516 } 2520 }
2517 return 0; 2521 return 0;
2518} 2522}
@@ -3242,6 +3246,9 @@ static int radio_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
3242 if (btv->audio_mode_gpio) 3246 if (btv->audio_mode_gpio)
3243 btv->audio_mode_gpio(btv, t, 0); 3247 btv->audio_mode_gpio(btv, t, 0);
3244 3248
3249 if (btv->has_tea575x)
3250 return snd_tea575x_g_tuner(&btv->tea, t);
3251
3245 return 0; 3252 return 0;
3246} 3253}
3247 3254
@@ -3259,6 +3266,30 @@ static int radio_s_tuner(struct file *file, void *priv,
3259 return 0; 3266 return 0;
3260} 3267}
3261 3268
3269static int radio_s_hw_freq_seek(struct file *file, void *priv,
3270 const struct v4l2_hw_freq_seek *a)
3271{
3272 struct bttv_fh *fh = priv;
3273 struct bttv *btv = fh->btv;
3274
3275 if (btv->has_tea575x)
3276 return snd_tea575x_s_hw_freq_seek(file, &btv->tea, a);
3277
3278 return -ENOTTY;
3279}
3280
3281static int radio_enum_freq_bands(struct file *file, void *priv,
3282 struct v4l2_frequency_band *band)
3283{
3284 struct bttv_fh *fh = priv;
3285 struct bttv *btv = fh->btv;
3286
3287 if (btv->has_tea575x)
3288 return snd_tea575x_enum_freq_bands(&btv->tea, band);
3289
3290 return -ENOTTY;
3291}
3292
3262static ssize_t radio_read(struct file *file, char __user *data, 3293static ssize_t radio_read(struct file *file, char __user *data,
3263 size_t count, loff_t *ppos) 3294 size_t count, loff_t *ppos)
3264{ 3295{
@@ -3316,6 +3347,8 @@ static const struct v4l2_ioctl_ops radio_ioctl_ops = {
3316 .vidioc_s_tuner = radio_s_tuner, 3347 .vidioc_s_tuner = radio_s_tuner,
3317 .vidioc_g_frequency = bttv_g_frequency, 3348 .vidioc_g_frequency = bttv_g_frequency,
3318 .vidioc_s_frequency = bttv_s_frequency, 3349 .vidioc_s_frequency = bttv_s_frequency,
3350 .vidioc_s_hw_freq_seek = radio_s_hw_freq_seek,
3351 .vidioc_enum_freq_bands = radio_enum_freq_bands,
3319 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 3352 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
3320 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 3353 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
3321}; 3354};
@@ -3884,7 +3917,6 @@ static struct video_device *vdev_init(struct bttv *btv,
3884 *vfd = *template; 3917 *vfd = *template;
3885 vfd->v4l2_dev = &btv->c.v4l2_dev; 3918 vfd->v4l2_dev = &btv->c.v4l2_dev;
3886 vfd->release = video_device_release; 3919 vfd->release = video_device_release;
3887 vfd->debug = bttv_debug;
3888 video_set_drvdata(vfd, btv); 3920 video_set_drvdata(vfd, btv);
3889 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)", 3921 snprintf(vfd->name, sizeof(vfd->name), "BT%d%s %s (%s)",
3890 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "", 3922 btv->id, (btv->id==848 && btv->revision==0x12) ? "A" : "",
@@ -4429,9 +4461,3 @@ static void __exit bttv_cleanup_module(void)
4429 4461
4430module_init(bttv_init_module); 4462module_init(bttv_init_module);
4431module_exit(bttv_cleanup_module); 4463module_exit(bttv_cleanup_module);
4432
4433/*
4434 * Local variables:
4435 * c-basic-offset: 8
4436 * End:
4437 */
diff --git a/drivers/media/pci/bt8xx/bttv-gpio.c b/drivers/media/pci/bt8xx/bttv-gpio.c
index 3f364b7062b9..25b9916906d5 100644
--- a/drivers/media/pci/bt8xx/bttv-gpio.c
+++ b/drivers/media/pci/bt8xx/bttv-gpio.c
@@ -181,9 +181,3 @@ void bttv_gpio_bits(struct bttv_core *core, u32 mask, u32 bits)
181 btwrite(data,BT848_GPIO_DATA); 181 btwrite(data,BT848_GPIO_DATA);
182 spin_unlock_irqrestore(&btv->gpio_lock,flags); 182 spin_unlock_irqrestore(&btv->gpio_lock,flags);
183} 183}
184
185/*
186 * Local variables:
187 * c-basic-offset: 8
188 * End:
189 */
diff --git a/drivers/media/pci/bt8xx/bttv-if.c b/drivers/media/pci/bt8xx/bttv-if.c
index a6a540dc9e4b..538652e16a5c 100644
--- a/drivers/media/pci/bt8xx/bttv-if.c
+++ b/drivers/media/pci/bt8xx/bttv-if.c
@@ -113,9 +113,3 @@ int bttv_write_gpio(unsigned int card, unsigned long mask, unsigned long data)
113 bttv_gpio_tracking(btv,"extern write"); 113 bttv_gpio_tracking(btv,"extern write");
114 return 0; 114 return 0;
115} 115}
116
117/*
118 * Local variables:
119 * c-basic-offset: 8
120 * End:
121 */
diff --git a/drivers/media/pci/bt8xx/bttv-risc.c b/drivers/media/pci/bt8xx/bttv-risc.c
index 4d3f05a19af3..3859dde98be2 100644
--- a/drivers/media/pci/bt8xx/bttv-risc.c
+++ b/drivers/media/pci/bt8xx/bttv-risc.c
@@ -901,9 +901,3 @@ bttv_overlay_risc(struct bttv *btv,
901 buf->vb.field = ov->field; 901 buf->vb.field = ov->field;
902 return 0; 902 return 0;
903} 903}
904
905/*
906 * Local variables:
907 * c-basic-offset: 8
908 * End:
909 */
diff --git a/drivers/media/pci/bt8xx/bttv-vbi.c b/drivers/media/pci/bt8xx/bttv-vbi.c
index b433267d9aa9..e77129c92fa0 100644
--- a/drivers/media/pci/bt8xx/bttv-vbi.c
+++ b/drivers/media/pci/bt8xx/bttv-vbi.c
@@ -450,10 +450,3 @@ void bttv_vbi_fmt_reset(struct bttv_vbi_fmt *f, unsigned int norm)
450 /* See bttv_vbi_fmt_set(). */ 450 /* See bttv_vbi_fmt_set(). */
451 f->end = tvnorm->vbistart[0] * 2 + 2; 451 f->end = tvnorm->vbistart[0] * 2 + 2;
452} 452}
453
454/* ----------------------------------------------------------------------- */
455/*
456 * Local variables:
457 * c-basic-offset: 8
458 * End:
459 */
diff --git a/drivers/media/pci/bt8xx/bttv.h b/drivers/media/pci/bt8xx/bttv.h
index f08126244662..91301c3cad1e 100644
--- a/drivers/media/pci/bt8xx/bttv.h
+++ b/drivers/media/pci/bt8xx/bttv.h
@@ -378,8 +378,3 @@ extern void bttv_input_fini(struct bttv *dev);
378extern void bttv_input_irq(struct bttv *dev); 378extern void bttv_input_irq(struct bttv *dev);
379 379
380#endif /* _BTTV_H_ */ 380#endif /* _BTTV_H_ */
381/*
382 * Local variables:
383 * c-basic-offset: 8
384 * End:
385 */
diff --git a/drivers/media/pci/bt8xx/bttvp.h b/drivers/media/pci/bt8xx/bttvp.h
index 9fe19488b30b..bc048c586b1f 100644
--- a/drivers/media/pci/bt8xx/bttvp.h
+++ b/drivers/media/pci/bt8xx/bttvp.h
@@ -42,6 +42,7 @@
42#include <media/tveeprom.h> 42#include <media/tveeprom.h>
43#include <media/rc-core.h> 43#include <media/rc-core.h>
44#include <media/ir-kbd-i2c.h> 44#include <media/ir-kbd-i2c.h>
45#include <media/tea575x.h>
45 46
46#include "bt848.h" 47#include "bt848.h"
47#include "bttv.h" 48#include "bttv.h"
@@ -359,6 +360,10 @@ struct bttv_suspend_state {
359 struct bttv_buffer *vbi; 360 struct bttv_buffer *vbi;
360}; 361};
361 362
363struct bttv_tea575x_gpio {
364 u8 data, clk, wren, most;
365};
366
362struct bttv { 367struct bttv {
363 struct bttv_core c; 368 struct bttv_core c;
364 369
@@ -445,12 +450,9 @@ struct bttv {
445 450
446 /* miro/pinnacle + Aimslab VHX 451 /* miro/pinnacle + Aimslab VHX
447 philips matchbox (tea5757 radio tuner) support */ 452 philips matchbox (tea5757 radio tuner) support */
448 int has_matchbox; 453 int has_tea575x;
449 int mbox_we; 454 struct bttv_tea575x_gpio tea_gpio;
450 int mbox_data; 455 struct snd_tea575x tea;
451 int mbox_clk;
452 int mbox_most;
453 int mbox_mask;
454 456
455 /* ISA stuff (Terratec Active Radio Upgrade) */ 457 /* ISA stuff (Terratec Active Radio Upgrade) */
456 int mbox_ior; 458 int mbox_ior;
@@ -531,9 +533,3 @@ static inline unsigned int bttv_muxsel(const struct bttv *btv,
531#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr) 533#define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
532 534
533#endif /* _BTTVP_H_ */ 535#endif /* _BTTVP_H_ */
534
535/*
536 * Local variables:
537 * c-basic-offset: 8
538 * End:
539 */
diff --git a/drivers/media/pci/cx23885/Kconfig b/drivers/media/pci/cx23885/Kconfig
index f613314b360b..74d774e5227b 100644
--- a/drivers/media/pci/cx23885/Kconfig
+++ b/drivers/media/pci/cx23885/Kconfig
@@ -41,6 +41,7 @@ config VIDEO_CX23885
41 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT 41 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
42 select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT 42 select MEDIA_TUNER_SI2157 if MEDIA_SUBDRV_AUTOSELECT
43 select MEDIA_TUNER_M88TS2022 if MEDIA_SUBDRV_AUTOSELECT 43 select MEDIA_TUNER_M88TS2022 if MEDIA_SUBDRV_AUTOSELECT
44 select MEDIA_TUNER_M88RS6000T if MEDIA_SUBDRV_AUTOSELECT
44 select DVB_TUNER_DIB0070 if MEDIA_SUBDRV_AUTOSELECT 45 select DVB_TUNER_DIB0070 if MEDIA_SUBDRV_AUTOSELECT
45 ---help--- 46 ---help---
46 This is a video4linux driver for Conexant 23885 based 47 This is a video4linux driver for Conexant 23885 based
diff --git a/drivers/media/pci/cx23885/cx23885-cards.c b/drivers/media/pci/cx23885/cx23885-cards.c
index 06931f6fa26c..f384f295676e 100644
--- a/drivers/media/pci/cx23885/cx23885-cards.c
+++ b/drivers/media/pci/cx23885/cx23885-cards.c
@@ -710,6 +710,11 @@ struct cx23885_board cx23885_boards[] = {
710 .portb = CX23885_MPEG_DVB, 710 .portb = CX23885_MPEG_DVB,
711 .portc = CX23885_MPEG_DVB, 711 .portc = CX23885_MPEG_DVB,
712 }, 712 },
713 [CX23885_BOARD_HAUPPAUGE_HVR5525] = {
714 .name = "Hauppauge WinTV-HVR5525",
715 .portb = CX23885_MPEG_DVB,
716 .portc = CX23885_MPEG_DVB,
717 },
713}; 718};
714const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards); 719const unsigned int cx23885_bcount = ARRAY_SIZE(cx23885_boards);
715 720
@@ -993,6 +998,10 @@ struct cx23885_subid cx23885_subids[] = {
993 .subvendor = 0x4254, 998 .subvendor = 0x4254,
994 .subdevice = 0x0982, 999 .subdevice = 0x0982,
995 .card = CX23885_BOARD_DVBSKY_T982, 1000 .card = CX23885_BOARD_DVBSKY_T982,
1001 }, {
1002 .subvendor = 0x0070,
1003 .subdevice = 0xf038,
1004 .card = CX23885_BOARD_HAUPPAUGE_HVR5525,
996 }, 1005 },
997}; 1006};
998const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids); 1007const unsigned int cx23885_idcount = ARRAY_SIZE(cx23885_subids);
@@ -1165,6 +1174,8 @@ static void hauppauge_eeprom(struct cx23885_dev *dev, u8 *eeprom_data)
1165 case 85721: 1174 case 85721:
1166 /* WinTV-HVR1290 (PCIe, OEM, RCA in, IR, 1175 /* WinTV-HVR1290 (PCIe, OEM, RCA in, IR,
1167 Dual channel ATSC and Basic analog */ 1176 Dual channel ATSC and Basic analog */
1177 case 150329:
1178 /* WinTV-HVR5525 (PCIe, DVB-S/S2, DVB-T/T2/C) */
1168 break; 1179 break;
1169 default: 1180 default:
1170 printk(KERN_WARNING "%s: warning: " 1181 printk(KERN_WARNING "%s: warning: "
@@ -1637,6 +1648,29 @@ void cx23885_gpio_setup(struct cx23885_dev *dev)
1637 msleep(100); 1648 msleep(100);
1638 cx23885_gpio_set(dev, GPIO_2); 1649 cx23885_gpio_set(dev, GPIO_2);
1639 break; 1650 break;
1651 case CX23885_BOARD_HAUPPAUGE_HVR5525:
1652 /*
1653 * GPIO-00 IR_WIDE
1654 * GPIO-02 wake#
1655 * GPIO-03 VAUX Pres.
1656 * GPIO-07 PROG#
1657 * GPIO-08 SAT_RESN
1658 * GPIO-09 TER_RESN
1659 * GPIO-10 B2_SENSE
1660 * GPIO-11 B1_SENSE
1661 * GPIO-15 IR_LED_STATUS
1662 * GPIO-19 IR_NARROW
1663 * GPIO-20 Blauster1
1664 * ALTGPIO VAUX_SWITCH
1665 * AUX_PLL_CLK : Blaster2
1666 */
1667 /* Put the parts into reset and back */
1668 cx23885_gpio_enable(dev, GPIO_8 | GPIO_9, 1);
1669 cx23885_gpio_clear(dev, GPIO_8 | GPIO_9);
1670 msleep(100);
1671 cx23885_gpio_set(dev, GPIO_8 | GPIO_9);
1672 msleep(100);
1673 break;
1640 } 1674 }
1641} 1675}
1642 1676
@@ -1879,6 +1913,7 @@ void cx23885_card_setup(struct cx23885_dev *dev)
1879 case CX23885_BOARD_HAUPPAUGE_HVR4400: 1913 case CX23885_BOARD_HAUPPAUGE_HVR4400:
1880 case CX23885_BOARD_HAUPPAUGE_STARBURST: 1914 case CX23885_BOARD_HAUPPAUGE_STARBURST:
1881 case CX23885_BOARD_HAUPPAUGE_IMPACTVCBE: 1915 case CX23885_BOARD_HAUPPAUGE_IMPACTVCBE:
1916 case CX23885_BOARD_HAUPPAUGE_HVR5525:
1882 if (dev->i2c_bus[0].i2c_rc == 0) 1917 if (dev->i2c_bus[0].i2c_rc == 0)
1883 hauppauge_eeprom(dev, eeprom+0xc0); 1918 hauppauge_eeprom(dev, eeprom+0xc0);
1884 break; 1919 break;
@@ -2008,6 +2043,14 @@ void cx23885_card_setup(struct cx23885_dev *dev)
2008 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */ 2043 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
2009 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO; 2044 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
2010 break; 2045 break;
2046 case CX23885_BOARD_HAUPPAUGE_HVR5525:
2047 ts1->gen_ctrl_val = 0x5; /* Parallel */
2048 ts1->ts_clk_en_val = 0x1; /* Enable TS_CLK */
2049 ts1->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
2050 ts2->gen_ctrl_val = 0xc; /* Serial bus + punctured clock */
2051 ts2->ts_clk_en_val = 0x1; /* Enable TS_CLK */
2052 ts2->src_sel_val = CX23885_SRC_SEL_PARALLEL_MPEG_VIDEO;
2053 break;
2011 case CX23885_BOARD_HAUPPAUGE_HVR1250: 2054 case CX23885_BOARD_HAUPPAUGE_HVR1250:
2012 case CX23885_BOARD_HAUPPAUGE_HVR1500: 2055 case CX23885_BOARD_HAUPPAUGE_HVR1500:
2013 case CX23885_BOARD_HAUPPAUGE_HVR1500Q: 2056 case CX23885_BOARD_HAUPPAUGE_HVR1500Q:
diff --git a/drivers/media/pci/cx23885/cx23885-dvb.c b/drivers/media/pci/cx23885/cx23885-dvb.c
index a9c450d4b54e..45fbe1e4d2d0 100644
--- a/drivers/media/pci/cx23885/cx23885-dvb.c
+++ b/drivers/media/pci/cx23885/cx23885-dvb.c
@@ -74,6 +74,7 @@
74#include "sp2.h" 74#include "sp2.h"
75#include "m88ds3103.h" 75#include "m88ds3103.h"
76#include "m88ts2022.h" 76#include "m88ts2022.h"
77#include "m88rs6000t.h"
77 78
78static unsigned int debug; 79static unsigned int debug;
79 80
@@ -915,6 +916,16 @@ static const struct m88ds3103_config dvbsky_s952_portc_m88ds3103_config = {
915 .agc = 0x99, 916 .agc = 0x99,
916}; 917};
917 918
919static const struct m88ds3103_config hauppauge_hvr5525_m88ds3103_config = {
920 .i2c_addr = 0x69,
921 .clock = 27000000,
922 .i2c_wr_max = 33,
923 .ts_mode = M88DS3103_TS_PARALLEL,
924 .ts_clk = 16000,
925 .ts_clk_pol = 1,
926 .agc = 0x99,
927};
928
918static int netup_altera_fpga_rw(void *device, int flag, int data, int read) 929static int netup_altera_fpga_rw(void *device, int flag, int data, int read)
919{ 930{
920 struct cx23885_dev *dev = (struct cx23885_dev *)device; 931 struct cx23885_dev *dev = (struct cx23885_dev *)device;
@@ -1058,6 +1069,116 @@ static struct dib7000p_config dib7070p_dib7000p_config = {
1058 .hostbus_diversity = 1, 1069 .hostbus_diversity = 1,
1059}; 1070};
1060 1071
1072static int dvb_register_ci_mac(struct cx23885_tsport *port)
1073{
1074 struct cx23885_dev *dev = port->dev;
1075 struct i2c_client *client_ci = NULL;
1076 struct vb2_dvb_frontend *fe0;
1077
1078 fe0 = vb2_dvb_get_frontend(&port->frontends, 1);
1079 if (!fe0)
1080 return -EINVAL;
1081
1082 switch (dev->board) {
1083 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: {
1084 static struct netup_card_info cinfo;
1085
1086 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
1087 memcpy(port->frontends.adapter.proposed_mac,
1088 cinfo.port[port->nr - 1].mac, 6);
1089 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
1090 port->nr, port->frontends.adapter.proposed_mac);
1091
1092 netup_ci_init(port);
1093 return 0;
1094 }
1095 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
1096 struct altera_ci_config netup_ci_cfg = {
1097 .dev = dev,/* magic number to identify*/
1098 .adapter = &port->frontends.adapter,/* for CI */
1099 .demux = &fe0->dvb.demux,/* for hw pid filter */
1100 .fpga_rw = netup_altera_fpga_rw,
1101 };
1102
1103 altera_ci_init(&netup_ci_cfg, port->nr);
1104 return 0;
1105 }
1106 case CX23885_BOARD_TEVII_S470: {
1107 u8 eeprom[256]; /* 24C02 i2c eeprom */
1108
1109 if (port->nr != 1)
1110 return 0;
1111
1112 /* Read entire EEPROM */
1113 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1114 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
1115 printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
1116 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
1117 return 0;
1118 }
1119 case CX23885_BOARD_DVBSKY_T9580:
1120 case CX23885_BOARD_DVBSKY_S950:
1121 case CX23885_BOARD_DVBSKY_S952:
1122 case CX23885_BOARD_DVBSKY_T982: {
1123 u8 eeprom[256]; /* 24C02 i2c eeprom */
1124
1125 if (port->nr > 2)
1126 return 0;
1127
1128 /* Read entire EEPROM */
1129 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1130 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1131 sizeof(eeprom));
1132 printk(KERN_INFO "%s port %d MAC address: %pM\n",
1133 cx23885_boards[dev->board].name, port->nr,
1134 eeprom + 0xc0 + (port->nr-1) * 8);
1135 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
1136 (port->nr-1) * 8, 6);
1137 return 0;
1138 }
1139 case CX23885_BOARD_DVBSKY_S950C:
1140 case CX23885_BOARD_DVBSKY_T980C:
1141 case CX23885_BOARD_TT_CT2_4500_CI: {
1142 u8 eeprom[256]; /* 24C02 i2c eeprom */
1143 struct sp2_config sp2_config;
1144 struct i2c_board_info info;
1145 struct cx23885_i2c *i2c_bus2 = &dev->i2c_bus[1];
1146
1147 /* attach CI */
1148 memset(&sp2_config, 0, sizeof(sp2_config));
1149 sp2_config.dvb_adap = &port->frontends.adapter;
1150 sp2_config.priv = port;
1151 sp2_config.ci_control = cx23885_sp2_ci_ctrl;
1152 memset(&info, 0, sizeof(struct i2c_board_info));
1153 strlcpy(info.type, "sp2", I2C_NAME_SIZE);
1154 info.addr = 0x40;
1155 info.platform_data = &sp2_config;
1156 request_module(info.type);
1157 client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info);
1158 if (client_ci == NULL || client_ci->dev.driver == NULL)
1159 return -ENODEV;
1160 if (!try_module_get(client_ci->dev.driver->owner)) {
1161 i2c_unregister_device(client_ci);
1162 return -ENODEV;
1163 }
1164 port->i2c_client_ci = client_ci;
1165
1166 if (port->nr != 1)
1167 return 0;
1168
1169 /* Read entire EEPROM */
1170 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
1171 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
1172 sizeof(eeprom));
1173 printk(KERN_INFO "%s MAC address: %pM\n",
1174 cx23885_boards[dev->board].name, eeprom + 0xc0);
1175 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6);
1176 return 0;
1177 }
1178 }
1179 return 0;
1180}
1181
1061static int dvb_register(struct cx23885_tsport *port) 1182static int dvb_register(struct cx23885_tsport *port)
1062{ 1183{
1063 struct dib7000p_ops dib7000p_ops; 1184 struct dib7000p_ops dib7000p_ops;
@@ -1066,11 +1187,10 @@ static int dvb_register(struct cx23885_tsport *port)
1066 struct vb2_dvb_frontend *fe0, *fe1 = NULL; 1187 struct vb2_dvb_frontend *fe0, *fe1 = NULL;
1067 struct si2168_config si2168_config; 1188 struct si2168_config si2168_config;
1068 struct si2157_config si2157_config; 1189 struct si2157_config si2157_config;
1069 struct sp2_config sp2_config;
1070 struct m88ts2022_config m88ts2022_config; 1190 struct m88ts2022_config m88ts2022_config;
1071 struct i2c_board_info info; 1191 struct i2c_board_info info;
1072 struct i2c_adapter *adapter; 1192 struct i2c_adapter *adapter;
1073 struct i2c_client *client_demod = NULL, *client_tuner = NULL, *client_ci = NULL; 1193 struct i2c_client *client_demod = NULL, *client_tuner = NULL;
1074 const struct m88ds3103_config *p_m88ds3103_config = NULL; 1194 const struct m88ds3103_config *p_m88ds3103_config = NULL;
1075 int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL; 1195 int (*p_set_voltage)(struct dvb_frontend *fe, fe_sec_voltage_t voltage) = NULL;
1076 int mfe_shared = 0; /* bus not shared by default */ 1196 int mfe_shared = 0; /* bus not shared by default */
@@ -1801,15 +1921,11 @@ static int dvb_register(struct cx23885_tsport *port)
1801 request_module(info.type); 1921 request_module(info.type);
1802 client_tuner = i2c_new_device(adapter, &info); 1922 client_tuner = i2c_new_device(adapter, &info);
1803 if (client_tuner == NULL || 1923 if (client_tuner == NULL ||
1804 client_tuner->dev.driver == NULL) { 1924 client_tuner->dev.driver == NULL)
1805 module_put(client_demod->dev.driver->owner);
1806 i2c_unregister_device(client_demod);
1807 goto frontend_detach; 1925 goto frontend_detach;
1808 } 1926
1809 if (!try_module_get(client_tuner->dev.driver->owner)) { 1927 if (!try_module_get(client_tuner->dev.driver->owner)) {
1810 i2c_unregister_device(client_tuner); 1928 i2c_unregister_device(client_tuner);
1811 module_put(client_demod->dev.driver->owner);
1812 i2c_unregister_device(client_demod);
1813 goto frontend_detach; 1929 goto frontend_detach;
1814 } 1930 }
1815 port->i2c_client_tuner = client_tuner; 1931 port->i2c_client_tuner = client_tuner;
@@ -1832,8 +1948,7 @@ static int dvb_register(struct cx23885_tsport *port)
1832 info.platform_data = &si2168_config; 1948 info.platform_data = &si2168_config;
1833 request_module(info.type); 1949 request_module(info.type);
1834 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 1950 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1835 if (client_demod == NULL || 1951 if (client_demod == NULL || client_demod->dev.driver == NULL)
1836 client_demod->dev.driver == NULL)
1837 goto frontend_detach; 1952 goto frontend_detach;
1838 if (!try_module_get(client_demod->dev.driver->owner)) { 1953 if (!try_module_get(client_demod->dev.driver->owner)) {
1839 i2c_unregister_device(client_demod); 1954 i2c_unregister_device(client_demod);
@@ -1851,15 +1966,10 @@ static int dvb_register(struct cx23885_tsport *port)
1851 request_module(info.type); 1966 request_module(info.type);
1852 client_tuner = i2c_new_device(adapter, &info); 1967 client_tuner = i2c_new_device(adapter, &info);
1853 if (client_tuner == NULL || 1968 if (client_tuner == NULL ||
1854 client_tuner->dev.driver == NULL) { 1969 client_tuner->dev.driver == NULL)
1855 module_put(client_demod->dev.driver->owner);
1856 i2c_unregister_device(client_demod);
1857 goto frontend_detach; 1970 goto frontend_detach;
1858 }
1859 if (!try_module_get(client_tuner->dev.driver->owner)) { 1971 if (!try_module_get(client_tuner->dev.driver->owner)) {
1860 i2c_unregister_device(client_tuner); 1972 i2c_unregister_device(client_tuner);
1861 module_put(client_demod->dev.driver->owner);
1862 i2c_unregister_device(client_demod);
1863 goto frontend_detach; 1973 goto frontend_detach;
1864 } 1974 }
1865 port->i2c_client_tuner = client_tuner; 1975 port->i2c_client_tuner = client_tuner;
@@ -1885,8 +1995,7 @@ static int dvb_register(struct cx23885_tsport *port)
1885 info.platform_data = &m88ts2022_config; 1995 info.platform_data = &m88ts2022_config;
1886 request_module(info.type); 1996 request_module(info.type);
1887 client_tuner = i2c_new_device(adapter, &info); 1997 client_tuner = i2c_new_device(adapter, &info);
1888 if (client_tuner == NULL || 1998 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
1889 client_tuner->dev.driver == NULL)
1890 goto frontend_detach; 1999 goto frontend_detach;
1891 if (!try_module_get(client_tuner->dev.driver->owner)) { 2000 if (!try_module_get(client_tuner->dev.driver->owner)) {
1892 i2c_unregister_device(client_tuner); 2001 i2c_unregister_device(client_tuner);
@@ -1932,8 +2041,7 @@ static int dvb_register(struct cx23885_tsport *port)
1932 info.platform_data = &m88ts2022_config; 2041 info.platform_data = &m88ts2022_config;
1933 request_module(info.type); 2042 request_module(info.type);
1934 client_tuner = i2c_new_device(adapter, &info); 2043 client_tuner = i2c_new_device(adapter, &info);
1935 if (client_tuner == NULL || 2044 if (client_tuner == NULL || client_tuner->dev.driver == NULL)
1936 client_tuner->dev.driver == NULL)
1937 goto frontend_detach; 2045 goto frontend_detach;
1938 if (!try_module_get(client_tuner->dev.driver->owner)) { 2046 if (!try_module_get(client_tuner->dev.driver->owner)) {
1939 i2c_unregister_device(client_tuner); 2047 i2c_unregister_device(client_tuner);
@@ -1978,8 +2086,7 @@ static int dvb_register(struct cx23885_tsport *port)
1978 info.platform_data = &si2168_config; 2086 info.platform_data = &si2168_config;
1979 request_module(info.type); 2087 request_module(info.type);
1980 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info); 2088 client_demod = i2c_new_device(&i2c_bus->i2c_adap, &info);
1981 if (client_demod == NULL || 2089 if (client_demod == NULL || client_demod->dev.driver == NULL)
1982 client_demod->dev.driver == NULL)
1983 goto frontend_detach; 2090 goto frontend_detach;
1984 if (!try_module_get(client_demod->dev.driver->owner)) { 2091 if (!try_module_get(client_demod->dev.driver->owner)) {
1985 i2c_unregister_device(client_demod); 2092 i2c_unregister_device(client_demod);
@@ -1997,20 +2104,101 @@ static int dvb_register(struct cx23885_tsport *port)
1997 request_module(info.type); 2104 request_module(info.type);
1998 client_tuner = i2c_new_device(adapter, &info); 2105 client_tuner = i2c_new_device(adapter, &info);
1999 if (client_tuner == NULL || 2106 if (client_tuner == NULL ||
2000 client_tuner->dev.driver == NULL) { 2107 client_tuner->dev.driver == NULL)
2001 module_put(client_demod->dev.driver->owner);
2002 i2c_unregister_device(client_demod);
2003 goto frontend_detach; 2108 goto frontend_detach;
2004 }
2005 if (!try_module_get(client_tuner->dev.driver->owner)) { 2109 if (!try_module_get(client_tuner->dev.driver->owner)) {
2006 i2c_unregister_device(client_tuner); 2110 i2c_unregister_device(client_tuner);
2007 module_put(client_demod->dev.driver->owner);
2008 i2c_unregister_device(client_demod);
2009 port->i2c_client_demod = NULL;
2010 goto frontend_detach; 2111 goto frontend_detach;
2011 } 2112 }
2012 port->i2c_client_tuner = client_tuner; 2113 port->i2c_client_tuner = client_tuner;
2013 break; 2114 break;
2115 case CX23885_BOARD_HAUPPAUGE_HVR5525:
2116 switch (port->nr) {
2117 struct m88rs6000t_config m88rs6000t_config;
2118
2119 /* port b - satellite */
2120 case 1:
2121 /* attach frontend */
2122 fe0->dvb.frontend = dvb_attach(m88ds3103_attach,
2123 &hauppauge_hvr5525_m88ds3103_config,
2124 &dev->i2c_bus[0].i2c_adap, &adapter);
2125 if (fe0->dvb.frontend == NULL)
2126 break;
2127
2128 /* attach SEC */
2129 if (!dvb_attach(a8293_attach, fe0->dvb.frontend,
2130 &dev->i2c_bus[0].i2c_adap,
2131 &hauppauge_a8293_config))
2132 goto frontend_detach;
2133
2134 /* attach tuner */
2135 memset(&m88rs6000t_config, 0, sizeof(m88rs6000t_config));
2136 m88rs6000t_config.fe = fe0->dvb.frontend;
2137 memset(&info, 0, sizeof(struct i2c_board_info));
2138 strlcpy(info.type, "m88rs6000t", I2C_NAME_SIZE);
2139 info.addr = 0x21;
2140 info.platform_data = &m88rs6000t_config;
2141 request_module("%s", info.type);
2142 client_tuner = i2c_new_device(adapter, &info);
2143 if (!client_tuner || !client_tuner->dev.driver)
2144 goto frontend_detach;
2145 if (!try_module_get(client_tuner->dev.driver->owner)) {
2146 i2c_unregister_device(client_tuner);
2147 goto frontend_detach;
2148 }
2149 port->i2c_client_tuner = client_tuner;
2150
2151 /* delegate signal strength measurement to tuner */
2152 fe0->dvb.frontend->ops.read_signal_strength =
2153 fe0->dvb.frontend->ops.tuner_ops.get_rf_strength;
2154 break;
2155 /* port c - terrestrial/cable */
2156 case 2:
2157 /* attach frontend */
2158 memset(&si2168_config, 0, sizeof(si2168_config));
2159 si2168_config.i2c_adapter = &adapter;
2160 si2168_config.fe = &fe0->dvb.frontend;
2161 si2168_config.ts_mode = SI2168_TS_SERIAL;
2162 memset(&info, 0, sizeof(struct i2c_board_info));
2163 strlcpy(info.type, "si2168", I2C_NAME_SIZE);
2164 info.addr = 0x64;
2165 info.platform_data = &si2168_config;
2166 request_module("%s", info.type);
2167 client_demod = i2c_new_device(&dev->i2c_bus[0].i2c_adap, &info);
2168 if (!client_demod || !client_demod->dev.driver)
2169 goto frontend_detach;
2170 if (!try_module_get(client_demod->dev.driver->owner)) {
2171 i2c_unregister_device(client_demod);
2172 goto frontend_detach;
2173 }
2174 port->i2c_client_demod = client_demod;
2175
2176 /* attach tuner */
2177 memset(&si2157_config, 0, sizeof(si2157_config));
2178 si2157_config.fe = fe0->dvb.frontend;
2179 memset(&info, 0, sizeof(struct i2c_board_info));
2180 strlcpy(info.type, "si2157", I2C_NAME_SIZE);
2181 info.addr = 0x60;
2182 info.platform_data = &si2157_config;
2183 request_module("%s", info.type);
2184 client_tuner = i2c_new_device(&dev->i2c_bus[1].i2c_adap, &info);
2185 if (!client_tuner || !client_tuner->dev.driver) {
2186 module_put(client_demod->dev.driver->owner);
2187 i2c_unregister_device(client_demod);
2188 port->i2c_client_demod = NULL;
2189 goto frontend_detach;
2190 }
2191 if (!try_module_get(client_tuner->dev.driver->owner)) {
2192 i2c_unregister_device(client_tuner);
2193 module_put(client_demod->dev.driver->owner);
2194 i2c_unregister_device(client_demod);
2195 port->i2c_client_demod = NULL;
2196 goto frontend_detach;
2197 }
2198 port->i2c_client_tuner = client_tuner;
2199 break;
2200 }
2201 break;
2014 default: 2202 default:
2015 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card " 2203 printk(KERN_INFO "%s: The frontend of your DVB/ATSC card "
2016 " isn't supported yet\n", 2204 " isn't supported yet\n",
@@ -2047,123 +2235,29 @@ static int dvb_register(struct cx23885_tsport *port)
2047 if (ret) 2235 if (ret)
2048 goto frontend_detach; 2236 goto frontend_detach;
2049 2237
2050 /* init CI & MAC */ 2238 ret = dvb_register_ci_mac(port);
2051 switch (dev->board) { 2239 if (ret)
2052 case CX23885_BOARD_NETUP_DUAL_DVBS2_CI: { 2240 goto frontend_detach;
2053 static struct netup_card_info cinfo;
2054
2055 netup_get_card_info(&dev->i2c_bus[0].i2c_adap, &cinfo);
2056 memcpy(port->frontends.adapter.proposed_mac,
2057 cinfo.port[port->nr - 1].mac, 6);
2058 printk(KERN_INFO "NetUP Dual DVB-S2 CI card port%d MAC=%pM\n",
2059 port->nr, port->frontends.adapter.proposed_mac);
2060
2061 netup_ci_init(port);
2062 break;
2063 }
2064 case CX23885_BOARD_NETUP_DUAL_DVB_T_C_CI_RF: {
2065 struct altera_ci_config netup_ci_cfg = {
2066 .dev = dev,/* magic number to identify*/
2067 .adapter = &port->frontends.adapter,/* for CI */
2068 .demux = &fe0->dvb.demux,/* for hw pid filter */
2069 .fpga_rw = netup_altera_fpga_rw,
2070 };
2071
2072 altera_ci_init(&netup_ci_cfg, port->nr);
2073 break;
2074 }
2075 case CX23885_BOARD_TEVII_S470: {
2076 u8 eeprom[256]; /* 24C02 i2c eeprom */
2077
2078 if (port->nr != 1)
2079 break;
2080
2081 /* Read entire EEPROM */
2082 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
2083 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, sizeof(eeprom));
2084 printk(KERN_INFO "TeVii S470 MAC= %pM\n", eeprom + 0xa0);
2085 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xa0, 6);
2086 break;
2087 }
2088 case CX23885_BOARD_DVBSKY_T9580:
2089 case CX23885_BOARD_DVBSKY_S950:
2090 case CX23885_BOARD_DVBSKY_S952:
2091 case CX23885_BOARD_DVBSKY_T982: {
2092 u8 eeprom[256]; /* 24C02 i2c eeprom */
2093
2094 if (port->nr > 2)
2095 break;
2096
2097 /* Read entire EEPROM */
2098 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1;
2099 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom,
2100 sizeof(eeprom));
2101 printk(KERN_INFO "%s port %d MAC address: %pM\n",
2102 cx23885_boards[dev->board].name, port->nr,
2103 eeprom + 0xc0 + (port->nr-1) * 8);
2104 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0 +
2105 (port->nr-1) * 8, 6);
2106 break;
2107 }
2108 case CX23885_BOARD_DVBSKY_S950C:
2109 case CX23885_BOARD_DVBSKY_T980C:
2110 case CX23885_BOARD_TT_CT2_4500_CI: {
2111 u8 eeprom[256]; /* 24C02 i2c eeprom */
2112
2113 /* attach CI */
2114 memset(&sp2_config, 0, sizeof(sp2_config));
2115 sp2_config.dvb_adap = &port->frontends.adapter;
2116 sp2_config.priv = port;
2117 sp2_config.ci_control = cx23885_sp2_ci_ctrl;
2118 memset(&info, 0, sizeof(struct i2c_board_info));
2119 strlcpy(info.type, "sp2", I2C_NAME_SIZE);
2120 info.addr = 0x40;
2121 info.platform_data = &sp2_config;
2122 request_module(info.type);
2123 client_ci = i2c_new_device(&i2c_bus2->i2c_adap, &info);
2124 if (client_ci == NULL ||
2125 client_ci->dev.driver == NULL) {
2126 if (client_tuner) {
2127 module_put(client_tuner->dev.driver->owner);
2128 i2c_unregister_device(client_tuner);
2129 }
2130 if (client_demod) {
2131 module_put(client_demod->dev.driver->owner);
2132 i2c_unregister_device(client_demod);
2133 }
2134 goto frontend_detach;
2135 }
2136 if (!try_module_get(client_ci->dev.driver->owner)) {
2137 i2c_unregister_device(client_ci);
2138 if (client_tuner) {
2139 module_put(client_tuner->dev.driver->owner);
2140 i2c_unregister_device(client_tuner);
2141 }
2142 if (client_demod) {
2143 module_put(client_demod->dev.driver->owner);
2144 i2c_unregister_device(client_demod);
2145 }
2146 goto frontend_detach;
2147 }
2148 port->i2c_client_ci = client_ci;
2149 2241
2150 if (port->nr != 1) 2242 return 0;
2151 break;
2152 2243
2153 /* Read entire EEPROM */ 2244frontend_detach:
2154 dev->i2c_bus[0].i2c_client.addr = 0xa0 >> 1; 2245 /* remove I2C client for tuner */
2155 tveeprom_read(&dev->i2c_bus[0].i2c_client, eeprom, 2246 client_tuner = port->i2c_client_tuner;
2156 sizeof(eeprom)); 2247 if (client_tuner) {
2157 printk(KERN_INFO "%s MAC address: %pM\n", 2248 module_put(client_tuner->dev.driver->owner);
2158 cx23885_boards[dev->board].name, eeprom + 0xc0); 2249 i2c_unregister_device(client_tuner);
2159 memcpy(port->frontends.adapter.proposed_mac, eeprom + 0xc0, 6); 2250 port->i2c_client_tuner = NULL;
2160 break;
2161 }
2162 } 2251 }
2163 2252
2164 return ret; 2253 /* remove I2C client for demodulator */
2254 client_demod = port->i2c_client_demod;
2255 if (client_demod) {
2256 module_put(client_demod->dev.driver->owner);
2257 i2c_unregister_device(client_demod);
2258 port->i2c_client_demod = NULL;
2259 }
2165 2260
2166frontend_detach:
2167 port->gate_ctrl = NULL; 2261 port->gate_ctrl = NULL;
2168 vb2_dvb_dealloc_frontends(&port->frontends); 2262 vb2_dvb_dealloc_frontends(&port->frontends);
2169 return -EINVAL; 2263 return -EINVAL;
diff --git a/drivers/media/pci/cx23885/cx23885-i2c.c b/drivers/media/pci/cx23885/cx23885-i2c.c
index fd71306af6e2..1135ea3f6ce5 100644
--- a/drivers/media/pci/cx23885/cx23885-i2c.c
+++ b/drivers/media/pci/cx23885/cx23885-i2c.c
@@ -300,8 +300,8 @@ static void do_i2c_scan(char *name, struct i2c_client *c)
300 rc = i2c_master_recv(c, &buf, 0); 300 rc = i2c_master_recv(c, &buf, 0);
301 if (rc < 0) 301 if (rc < 0)
302 continue; 302 continue;
303 printk(KERN_INFO "%s: i2c scan: found device @ 0x%x [%s]\n", 303 printk(KERN_INFO "%s: i2c scan: found device @ 0x%04x [%s]\n",
304 name, i << 1, i2c_devs[i] ? i2c_devs[i] : "???"); 304 name, i, i2c_devs[i] ? i2c_devs[i] : "???");
305 } 305 }
306} 306}
307 307
diff --git a/drivers/media/pci/cx23885/cx23885.h b/drivers/media/pci/cx23885/cx23885.h
index 36f2f96c40e4..aeda8d3990ae 100644
--- a/drivers/media/pci/cx23885/cx23885.h
+++ b/drivers/media/pci/cx23885/cx23885.h
@@ -99,7 +99,8 @@
99#define CX23885_BOARD_DVBSKY_S950 49 99#define CX23885_BOARD_DVBSKY_S950 49
100#define CX23885_BOARD_DVBSKY_S952 50 100#define CX23885_BOARD_DVBSKY_S952 50
101#define CX23885_BOARD_DVBSKY_T982 51 101#define CX23885_BOARD_DVBSKY_T982 51
102#define CX23885_BOARD_HAUPPAUGE_STARBURST 52 102#define CX23885_BOARD_HAUPPAUGE_HVR5525 52
103#define CX23885_BOARD_HAUPPAUGE_STARBURST 53
103 104
104#define GPIO_0 0x00000001 105#define GPIO_0 0x00000001
105#define GPIO_1 0x00000002 106#define GPIO_1 0x00000002
diff --git a/drivers/media/pci/cx25821/Kconfig b/drivers/media/pci/cx25821/Kconfig
index 6439a847680c..1755d3d2feaa 100644
--- a/drivers/media/pci/cx25821/Kconfig
+++ b/drivers/media/pci/cx25821/Kconfig
@@ -2,8 +2,7 @@ config VIDEO_CX25821
2 tristate "Conexant cx25821 support" 2 tristate "Conexant cx25821 support"
3 depends on VIDEO_DEV && PCI && I2C 3 depends on VIDEO_DEV && PCI && I2C
4 select I2C_ALGOBIT 4 select I2C_ALGOBIT
5 select VIDEO_BTCX 5 select VIDEOBUF2_DMA_SG
6 select VIDEOBUF_DMA_SG
7 ---help--- 6 ---help---
8 This is a video4linux driver for Conexant 25821 based 7 This is a video4linux driver for Conexant 25821 based
9 TV cards. 8 TV cards.
diff --git a/drivers/media/pci/cx25821/Makefile b/drivers/media/pci/cx25821/Makefile
index fb76c3d3713a..c8f8598a2b86 100644
--- a/drivers/media/pci/cx25821/Makefile
+++ b/drivers/media/pci/cx25821/Makefile
@@ -1,9 +1,8 @@
1cx25821-y := cx25821-core.o cx25821-cards.o cx25821-i2c.o \ 1cx25821-y := cx25821-core.o cx25821-cards.o cx25821-i2c.o \
2 cx25821-gpio.o cx25821-medusa-video.o \ 2 cx25821-gpio.o cx25821-medusa-video.o \
3 cx25821-video.o cx25821-video-upstream.o 3 cx25821-video.o
4 4
5obj-$(CONFIG_VIDEO_CX25821) += cx25821.o 5obj-$(CONFIG_VIDEO_CX25821) += cx25821.o
6obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o 6obj-$(CONFIG_VIDEO_CX25821_ALSA) += cx25821-alsa.o
7 7
8ccflags-y += -Idrivers/media/i2c 8ccflags-y += -Idrivers/media/i2c
9ccflags-y += -Idrivers/media/common
diff --git a/drivers/media/pci/cx25821/cx25821-alsa.c b/drivers/media/pci/cx25821/cx25821-alsa.c
index 2dd5bcaa7e53..24f964bcc53a 100644
--- a/drivers/media/pci/cx25821/cx25821-alsa.c
+++ b/drivers/media/pci/cx25821/cx25821-alsa.c
@@ -63,8 +63,11 @@ static int devno;
63 63
64struct cx25821_audio_buffer { 64struct cx25821_audio_buffer {
65 unsigned int bpl; 65 unsigned int bpl;
66 struct btcx_riscmem risc; 66 struct cx25821_riscmem risc;
67 struct videobuf_dmabuf dma; 67 void *vaddr;
68 struct scatterlist *sglist;
69 int sglen;
70 int nr_pages;
68}; 71};
69 72
70struct cx25821_audio_dev { 73struct cx25821_audio_dev {
@@ -87,8 +90,6 @@ struct cx25821_audio_dev {
87 unsigned int period_size; 90 unsigned int period_size;
88 unsigned int num_periods; 91 unsigned int num_periods;
89 92
90 struct videobuf_dmabuf *dma_risc;
91
92 struct cx25821_audio_buffer *buf; 93 struct cx25821_audio_buffer *buf;
93 94
94 struct snd_pcm_substream *substream; 95 struct snd_pcm_substream *substream;
@@ -142,6 +143,83 @@ MODULE_PARM_DESC(debug, "enable debug messages");
142 143
143#define PCI_MSK_AUD_EXT (1 << 4) 144#define PCI_MSK_AUD_EXT (1 << 4)
144#define PCI_MSK_AUD_INT (1 << 3) 145#define PCI_MSK_AUD_INT (1 << 3)
146
147static int cx25821_alsa_dma_init(struct cx25821_audio_dev *chip, int nr_pages)
148{
149 struct cx25821_audio_buffer *buf = chip->buf;
150 struct page *pg;
151 int i;
152
153 buf->vaddr = vmalloc_32(nr_pages << PAGE_SHIFT);
154 if (NULL == buf->vaddr) {
155 dprintk(1, "vmalloc_32(%d pages) failed\n", nr_pages);
156 return -ENOMEM;
157 }
158
159 dprintk(1, "vmalloc is at addr 0x%08lx, size=%d\n",
160 (unsigned long)buf->vaddr,
161 nr_pages << PAGE_SHIFT);
162
163 memset(buf->vaddr, 0, nr_pages << PAGE_SHIFT);
164 buf->nr_pages = nr_pages;
165
166 buf->sglist = vzalloc(buf->nr_pages * sizeof(*buf->sglist));
167 if (NULL == buf->sglist)
168 goto vzalloc_err;
169
170 sg_init_table(buf->sglist, buf->nr_pages);
171 for (i = 0; i < buf->nr_pages; i++) {
172 pg = vmalloc_to_page(buf->vaddr + i * PAGE_SIZE);
173 if (NULL == pg)
174 goto vmalloc_to_page_err;
175 sg_set_page(&buf->sglist[i], pg, PAGE_SIZE, 0);
176 }
177 return 0;
178
179vmalloc_to_page_err:
180 vfree(buf->sglist);
181 buf->sglist = NULL;
182vzalloc_err:
183 vfree(buf->vaddr);
184 buf->vaddr = NULL;
185 return -ENOMEM;
186}
187
188static int cx25821_alsa_dma_map(struct cx25821_audio_dev *dev)
189{
190 struct cx25821_audio_buffer *buf = dev->buf;
191
192 buf->sglen = dma_map_sg(&dev->pci->dev, buf->sglist,
193 buf->nr_pages, PCI_DMA_FROMDEVICE);
194
195 if (0 == buf->sglen) {
196 pr_warn("%s: cx25821_alsa_map_sg failed\n", __func__);
197 return -ENOMEM;
198 }
199 return 0;
200}
201
202static int cx25821_alsa_dma_unmap(struct cx25821_audio_dev *dev)
203{
204 struct cx25821_audio_buffer *buf = dev->buf;
205
206 if (!buf->sglen)
207 return 0;
208
209 dma_unmap_sg(&dev->pci->dev, buf->sglist, buf->sglen, PCI_DMA_FROMDEVICE);
210 buf->sglen = 0;
211 return 0;
212}
213
214static int cx25821_alsa_dma_free(struct cx25821_audio_buffer *buf)
215{
216 vfree(buf->sglist);
217 buf->sglist = NULL;
218 vfree(buf->vaddr);
219 buf->vaddr = NULL;
220 return 0;
221}
222
145/* 223/*
146 * BOARD Specific: Sets audio DMA 224 * BOARD Specific: Sets audio DMA
147 */ 225 */
@@ -330,15 +408,17 @@ out:
330 408
331static int dsp_buffer_free(struct cx25821_audio_dev *chip) 409static int dsp_buffer_free(struct cx25821_audio_dev *chip)
332{ 410{
411 struct cx25821_riscmem *risc = &chip->buf->risc;
412
333 BUG_ON(!chip->dma_size); 413 BUG_ON(!chip->dma_size);
334 414
335 dprintk(2, "Freeing buffer\n"); 415 dprintk(2, "Freeing buffer\n");
336 videobuf_dma_unmap(&chip->pci->dev, chip->dma_risc); 416 cx25821_alsa_dma_unmap(chip);
337 videobuf_dma_free(chip->dma_risc); 417 cx25821_alsa_dma_free(chip->buf);
338 btcx_riscmem_free(chip->pci, &chip->buf->risc); 418 pci_free_consistent(chip->pci, risc->size, risc->cpu, risc->dma);
339 kfree(chip->buf); 419 kfree(chip->buf);
340 420
341 chip->dma_risc = NULL; 421 chip->buf = NULL;
342 chip->dma_size = 0; 422 chip->dma_size = 0;
343 423
344 return 0; 424 return 0;
@@ -430,8 +510,6 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
430 struct snd_pcm_hw_params *hw_params) 510 struct snd_pcm_hw_params *hw_params)
431{ 511{
432 struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream); 512 struct cx25821_audio_dev *chip = snd_pcm_substream_chip(substream);
433 struct videobuf_dmabuf *dma;
434
435 struct cx25821_audio_buffer *buf; 513 struct cx25821_audio_buffer *buf;
436 int ret; 514 int ret;
437 515
@@ -455,19 +533,18 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
455 chip->period_size = AUDIO_LINE_SIZE; 533 chip->period_size = AUDIO_LINE_SIZE;
456 534
457 buf->bpl = chip->period_size; 535 buf->bpl = chip->period_size;
536 chip->buf = buf;
458 537
459 dma = &buf->dma; 538 ret = cx25821_alsa_dma_init(chip,
460 videobuf_dma_init(dma);
461 ret = videobuf_dma_init_kernel(dma, PCI_DMA_FROMDEVICE,
462 (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT)); 539 (PAGE_ALIGN(chip->dma_size) >> PAGE_SHIFT));
463 if (ret < 0) 540 if (ret < 0)
464 goto error; 541 goto error;
465 542
466 ret = videobuf_dma_map(&chip->pci->dev, dma); 543 ret = cx25821_alsa_dma_map(chip);
467 if (ret < 0) 544 if (ret < 0)
468 goto error; 545 goto error;
469 546
470 ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, dma->sglist, 547 ret = cx25821_risc_databuffer_audio(chip->pci, &buf->risc, buf->sglist,
471 chip->period_size, chip->num_periods, 1); 548 chip->period_size, chip->num_periods, 1);
472 if (ret < 0) { 549 if (ret < 0) {
473 pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n"); 550 pr_info("DEBUG: ERROR after cx25821_risc_databuffer_audio()\n");
@@ -479,16 +556,14 @@ static int snd_cx25821_hw_params(struct snd_pcm_substream *substream,
479 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma); 556 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
480 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ 557 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
481 558
482 chip->buf = buf; 559 substream->runtime->dma_area = chip->buf->vaddr;
483 chip->dma_risc = dma;
484
485 substream->runtime->dma_area = chip->dma_risc->vaddr;
486 substream->runtime->dma_bytes = chip->dma_size; 560 substream->runtime->dma_bytes = chip->dma_size;
487 substream->runtime->dma_addr = 0; 561 substream->runtime->dma_addr = 0;
488 562
489 return 0; 563 return 0;
490 564
491error: 565error:
566 chip->buf = NULL;
492 kfree(buf); 567 kfree(buf);
493 return ret; 568 return ret;
494} 569}
diff --git a/drivers/media/pci/cx25821/cx25821-core.c b/drivers/media/pci/cx25821/cx25821-core.c
index 389fffd2f36f..559f8293c53a 100644
--- a/drivers/media/pci/cx25821/cx25821-core.c
+++ b/drivers/media/pci/cx25821/cx25821-core.c
@@ -874,10 +874,9 @@ static int cx25821_dev_setup(struct cx25821_dev *dev)
874 if (dev->pci->device != 0x8210) { 874 if (dev->pci->device != 0x8210) {
875 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n", 875 pr_info("%s(): Exiting. Incorrect Hardware device = 0x%02x\n",
876 __func__, dev->pci->device); 876 __func__, dev->pci->device);
877 return -1; 877 return -ENODEV;
878 } else {
879 pr_info("Athena Hardware device = 0x%02x\n", dev->pci->device);
880 } 878 }
879 pr_info("Athena Hardware device = 0x%02x\n", dev->pci->device);
881 880
882 /* Apply a sensible clock frequency for the PCIe bridge */ 881 /* Apply a sensible clock frequency for the PCIe bridge */
883 dev->clk_freq = 28000000; 882 dev->clk_freq = 28000000;
@@ -966,11 +965,15 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
966 965
967 release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0)); 966 release_mem_region(dev->base_io_addr, pci_resource_len(dev->pci, 0));
968 967
969 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; i++) { 968 for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; i++) {
970 if (i == SRAM_CH08) /* audio channel */ 969 if (i == SRAM_CH08) /* audio channel */
971 continue; 970 continue;
971 /*
972 * TODO: enable when video output is properly
973 * supported.
972 if (i == SRAM_CH09 || i == SRAM_CH10) 974 if (i == SRAM_CH09 || i == SRAM_CH10)
973 cx25821_free_mem_upstream(&dev->channels[i]); 975 cx25821_free_mem_upstream(&dev->channels[i]);
976 */
974 cx25821_video_unregister(dev, i); 977 cx25821_video_unregister(dev, i);
975 } 978 }
976 979
@@ -979,14 +982,41 @@ void cx25821_dev_unregister(struct cx25821_dev *dev)
979} 982}
980EXPORT_SYMBOL(cx25821_dev_unregister); 983EXPORT_SYMBOL(cx25821_dev_unregister);
981 984
985int cx25821_riscmem_alloc(struct pci_dev *pci,
986 struct cx25821_riscmem *risc,
987 unsigned int size)
988{
989 __le32 *cpu;
990 dma_addr_t dma = 0;
991
992 if (NULL != risc->cpu && risc->size < size)
993 pci_free_consistent(pci, risc->size, risc->cpu, risc->dma);
994 if (NULL == risc->cpu) {
995 cpu = pci_zalloc_consistent(pci, size, &dma);
996 if (NULL == cpu)
997 return -ENOMEM;
998 risc->cpu = cpu;
999 risc->dma = dma;
1000 risc->size = size;
1001 }
1002 return 0;
1003}
1004EXPORT_SYMBOL(cx25821_riscmem_alloc);
1005
982static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist, 1006static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist,
983 unsigned int offset, u32 sync_line, 1007 unsigned int offset, u32 sync_line,
984 unsigned int bpl, unsigned int padding, 1008 unsigned int bpl, unsigned int padding,
985 unsigned int lines) 1009 unsigned int lines, bool jump)
986{ 1010{
987 struct scatterlist *sg; 1011 struct scatterlist *sg;
988 unsigned int line, todo; 1012 unsigned int line, todo;
989 1013
1014 if (jump) {
1015 *(rp++) = cpu_to_le32(RISC_JUMP);
1016 *(rp++) = cpu_to_le32(0);
1017 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1018 }
1019
990 /* sync instruction */ 1020 /* sync instruction */
991 if (sync_line != NO_SYNC_LINE) 1021 if (sync_line != NO_SYNC_LINE)
992 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line); 1022 *(rp++) = cpu_to_le32(RISC_RESYNC | sync_line);
@@ -1035,7 +1065,7 @@ static __le32 *cx25821_risc_field(__le32 * rp, struct scatterlist *sglist,
1035 return rp; 1065 return rp;
1036} 1066}
1037 1067
1038int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, 1068int cx25821_risc_buffer(struct pci_dev *pci, struct cx25821_riscmem *risc,
1039 struct scatterlist *sglist, unsigned int top_offset, 1069 struct scatterlist *sglist, unsigned int top_offset,
1040 unsigned int bottom_offset, unsigned int bpl, 1070 unsigned int bottom_offset, unsigned int bpl,
1041 unsigned int padding, unsigned int lines) 1071 unsigned int padding, unsigned int lines)
@@ -1052,14 +1082,14 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
1052 fields++; 1082 fields++;
1053 1083
1054 /* estimate risc mem: worst case is one write per page border + 1084 /* estimate risc mem: worst case is one write per page border +
1055 one write per scan line + syncs + jump (all 2 dwords). Padding 1085 one write per scan line + syncs + jump (all 3 dwords). Padding
1056 can cause next bpl to start close to a page border. First DMA 1086 can cause next bpl to start close to a page border. First DMA
1057 region may be smaller than PAGE_SIZE */ 1087 region may be smaller than PAGE_SIZE */
1058 /* write and jump need and extra dword */ 1088 /* write and jump need and extra dword */
1059 instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE + 1089 instructions = fields * (1 + ((bpl + padding) * lines) / PAGE_SIZE +
1060 lines); 1090 lines);
1061 instructions += 2; 1091 instructions += 5;
1062 rc = btcx_riscmem_alloc(pci, risc, instructions * 12); 1092 rc = cx25821_riscmem_alloc(pci, risc, instructions * 12);
1063 1093
1064 if (rc < 0) 1094 if (rc < 0)
1065 return rc; 1095 return rc;
@@ -1069,17 +1099,17 @@ int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc,
1069 1099
1070 if (UNSET != top_offset) { 1100 if (UNSET != top_offset) {
1071 rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding, 1101 rp = cx25821_risc_field(rp, sglist, top_offset, 0, bpl, padding,
1072 lines); 1102 lines, true);
1073 } 1103 }
1074 1104
1075 if (UNSET != bottom_offset) { 1105 if (UNSET != bottom_offset) {
1076 rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl, 1106 rp = cx25821_risc_field(rp, sglist, bottom_offset, 0x200, bpl,
1077 padding, lines); 1107 padding, lines, UNSET == top_offset);
1078 } 1108 }
1079 1109
1080 /* save pointer to jmp instruction address */ 1110 /* save pointer to jmp instruction address */
1081 risc->jmp = rp; 1111 risc->jmp = rp;
1082 BUG_ON((risc->jmp - risc->cpu + 2) * sizeof(*risc->cpu) > risc->size); 1112 BUG_ON((risc->jmp - risc->cpu + 3) * sizeof(*risc->cpu) > risc->size);
1083 1113
1084 return 0; 1114 return 0;
1085} 1115}
@@ -1146,7 +1176,7 @@ static __le32 *cx25821_risc_field_audio(__le32 * rp, struct scatterlist *sglist,
1146} 1176}
1147 1177
1148int cx25821_risc_databuffer_audio(struct pci_dev *pci, 1178int cx25821_risc_databuffer_audio(struct pci_dev *pci,
1149 struct btcx_riscmem *risc, 1179 struct cx25821_riscmem *risc,
1150 struct scatterlist *sglist, 1180 struct scatterlist *sglist,
1151 unsigned int bpl, 1181 unsigned int bpl,
1152 unsigned int lines, unsigned int lpi) 1182 unsigned int lines, unsigned int lpi)
@@ -1163,7 +1193,7 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
1163 instructions = 1 + (bpl * lines) / PAGE_SIZE + lines; 1193 instructions = 1 + (bpl * lines) / PAGE_SIZE + lines;
1164 instructions += 1; 1194 instructions += 1;
1165 1195
1166 rc = btcx_riscmem_alloc(pci, risc, instructions * 12); 1196 rc = cx25821_riscmem_alloc(pci, risc, instructions * 12);
1167 if (rc < 0) 1197 if (rc < 0)
1168 return rc; 1198 return rc;
1169 1199
@@ -1179,40 +1209,14 @@ int cx25821_risc_databuffer_audio(struct pci_dev *pci,
1179} 1209}
1180EXPORT_SYMBOL(cx25821_risc_databuffer_audio); 1210EXPORT_SYMBOL(cx25821_risc_databuffer_audio);
1181 1211
1182int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc, 1212void cx25821_free_buffer(struct cx25821_dev *dev, struct cx25821_buffer *buf)
1183 u32 reg, u32 mask, u32 value)
1184{
1185 __le32 *rp;
1186 int rc;
1187
1188 rc = btcx_riscmem_alloc(pci, risc, 4 * 16);
1189
1190 if (rc < 0)
1191 return rc;
1192
1193 /* write risc instructions */
1194 rp = risc->cpu;
1195
1196 *(rp++) = cpu_to_le32(RISC_WRITECR | RISC_IRQ1);
1197 *(rp++) = cpu_to_le32(reg);
1198 *(rp++) = cpu_to_le32(value);
1199 *(rp++) = cpu_to_le32(mask);
1200 *(rp++) = cpu_to_le32(RISC_JUMP);
1201 *(rp++) = cpu_to_le32(risc->dma);
1202 *(rp++) = cpu_to_le32(0); /* bits 63-32 */
1203 return 0;
1204}
1205
1206void cx25821_free_buffer(struct videobuf_queue *q, struct cx25821_buffer *buf)
1207{ 1213{
1208 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
1209
1210 BUG_ON(in_interrupt()); 1214 BUG_ON(in_interrupt());
1211 videobuf_waiton(q, &buf->vb, 0, 0); 1215 if (WARN_ON(buf->risc.size == 0))
1212 videobuf_dma_unmap(q->dev, dma); 1216 return;
1213 videobuf_dma_free(dma); 1217 pci_free_consistent(dev->pci,
1214 btcx_riscmem_free(to_pci_dev(q->dev), &buf->risc); 1218 buf->risc.size, buf->risc.cpu, buf->risc.dma);
1215 buf->vb.state = VIDEOBUF_NEEDS_INIT; 1219 memset(&buf->risc, 0, sizeof(buf->risc));
1216} 1220}
1217 1221
1218static irqreturn_t cx25821_irq(int irq, void *dev_id) 1222static irqreturn_t cx25821_irq(int irq, void *dev_id)
@@ -1297,14 +1301,15 @@ static int cx25821_initdev(struct pci_dev *pci_dev,
1297 1301
1298 goto fail_unregister_device; 1302 goto fail_unregister_device;
1299 } 1303 }
1304 dev->alloc_ctx = vb2_dma_sg_init_ctx(&pci_dev->dev);
1305 if (IS_ERR(dev->alloc_ctx)) {
1306 err = PTR_ERR(dev->alloc_ctx);
1307 goto fail_unregister_pci;
1308 }
1300 1309
1301 err = cx25821_dev_setup(dev); 1310 err = cx25821_dev_setup(dev);
1302 if (err) { 1311 if (err)
1303 if (err == -EBUSY) 1312 goto fail_free_ctx;
1304 goto fail_unregister_device;
1305 else
1306 goto fail_unregister_pci;
1307 }
1308 1313
1309 /* print pci info */ 1314 /* print pci info */
1310 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev); 1315 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &dev->pci_rev);
@@ -1334,6 +1339,8 @@ fail_irq:
1334 pr_info("cx25821_initdev() can't get IRQ !\n"); 1339 pr_info("cx25821_initdev() can't get IRQ !\n");
1335 cx25821_dev_unregister(dev); 1340 cx25821_dev_unregister(dev);
1336 1341
1342fail_free_ctx:
1343 vb2_dma_sg_cleanup_ctx(dev->alloc_ctx);
1337fail_unregister_pci: 1344fail_unregister_pci:
1338 pci_disable_device(pci_dev); 1345 pci_disable_device(pci_dev);
1339fail_unregister_device: 1346fail_unregister_device:
@@ -1357,6 +1364,7 @@ static void cx25821_finidev(struct pci_dev *pci_dev)
1357 free_irq(pci_dev->irq, dev); 1364 free_irq(pci_dev->irq, dev);
1358 1365
1359 cx25821_dev_unregister(dev); 1366 cx25821_dev_unregister(dev);
1367 vb2_dma_sg_cleanup_ctx(dev->alloc_ctx);
1360 v4l2_device_unregister(v4l2_dev); 1368 v4l2_device_unregister(v4l2_dev);
1361 kfree(dev); 1369 kfree(dev);
1362} 1370}
diff --git a/drivers/media/pci/cx25821/cx25821-video.c b/drivers/media/pci/cx25821/cx25821-video.c
index 3a419f134584..7bc495e4ece2 100644
--- a/drivers/media/pci/cx25821/cx25821-video.c
+++ b/drivers/media/pci/cx25821/cx25821-video.c
@@ -3,7 +3,7 @@
3 * 3 *
4 * Copyright (C) 2009 Conexant Systems Inc. 4 * Copyright (C) 2009 Conexant Systems Inc.
5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com> 5 * Authors <shu.lin@conexant.com>, <hiep.huynh@conexant.com>
6 * Based on Steven Toth <stoth@linuxtv.org> cx23885 driver 6 * Based on Steven Toth <stoth@linuxtv.org> cx25821 driver
7 * Parts adapted/taken from Eduardo Moscoso Rubino 7 * Parts adapted/taken from Eduardo Moscoso Rubino
8 * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com> 8 * Copyright (C) 2009 Eduardo Moscoso Rubino <moscoso@TopoLogica.com>
9 * 9 *
@@ -46,10 +46,6 @@ static unsigned int irq_debug;
46module_param(irq_debug, int, 0644); 46module_param(irq_debug, int, 0644);
47MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]"); 47MODULE_PARM_DESC(irq_debug, "enable debug messages [IRQ handler]");
48 48
49static unsigned int vid_limit = 16;
50module_param(vid_limit, int, 0644);
51MODULE_PARM_DESC(vid_limit, "capture memory limit in megabytes");
52
53#define FORMAT_FLAGS_PACKED 0x01 49#define FORMAT_FLAGS_PACKED 0x01
54 50
55static const struct cx25821_fmt formats[] = { 51static const struct cx25821_fmt formats[] = {
@@ -76,41 +72,6 @@ static const struct cx25821_fmt *cx25821_format_by_fourcc(unsigned int fourcc)
76 return NULL; 72 return NULL;
77} 73}
78 74
79void cx25821_video_wakeup(struct cx25821_dev *dev, struct cx25821_dmaqueue *q,
80 u32 count)
81{
82 struct cx25821_buffer *buf;
83 int bc;
84
85 for (bc = 0;; bc++) {
86 if (list_empty(&q->active)) {
87 dprintk(1, "bc=%d (=0: active empty)\n", bc);
88 break;
89 }
90
91 buf = list_entry(q->active.next, struct cx25821_buffer,
92 vb.queue);
93
94 /* count comes from the hw and it is 16bit wide --
95 * this trick handles wrap-arounds correctly for
96 * up to 32767 buffers in flight... */
97 if ((s16) (count - buf->count) < 0)
98 break;
99
100 v4l2_get_timestamp(&buf->vb.ts);
101 buf->vb.state = VIDEOBUF_DONE;
102 list_del(&buf->vb.queue);
103 wake_up(&buf->vb.done);
104 }
105
106 if (list_empty(&q->active))
107 del_timer(&q->timeout);
108 else
109 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
110 if (bc != 1)
111 pr_err("%s: %d buffers handled (should be 1)\n", __func__, bc);
112}
113
114int cx25821_start_video_dma(struct cx25821_dev *dev, 75int cx25821_start_video_dma(struct cx25821_dev *dev,
115 struct cx25821_dmaqueue *q, 76 struct cx25821_dmaqueue *q,
116 struct cx25821_buffer *buf, 77 struct cx25821_buffer *buf,
@@ -123,7 +84,6 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
123 84
124 /* reset counter */ 85 /* reset counter */
125 cx_write(channel->gpcnt_ctl, 3); 86 cx_write(channel->gpcnt_ctl, 3);
126 q->count = 1;
127 87
128 /* enable irq */ 88 /* enable irq */
129 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i)); 89 cx_set(PCI_INT_MSK, cx_read(PCI_INT_MSK) | (1 << channel->i));
@@ -139,86 +99,8 @@ int cx25821_start_video_dma(struct cx25821_dev *dev,
139 return 0; 99 return 0;
140} 100}
141 101
142static int cx25821_restart_video_queue(struct cx25821_dev *dev,
143 struct cx25821_dmaqueue *q,
144 const struct sram_channel *channel)
145{
146 struct cx25821_buffer *buf, *prev;
147 struct list_head *item;
148
149 if (!list_empty(&q->active)) {
150 buf = list_entry(q->active.next, struct cx25821_buffer,
151 vb.queue);
152
153 cx25821_start_video_dma(dev, q, buf, channel);
154
155 list_for_each(item, &q->active) {
156 buf = list_entry(item, struct cx25821_buffer, vb.queue);
157 buf->count = q->count++;
158 }
159
160 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
161 return 0;
162 }
163
164 prev = NULL;
165 for (;;) {
166 if (list_empty(&q->queued))
167 return 0;
168
169 buf = list_entry(q->queued.next, struct cx25821_buffer,
170 vb.queue);
171
172 if (NULL == prev) {
173 list_move_tail(&buf->vb.queue, &q->active);
174 cx25821_start_video_dma(dev, q, buf, channel);
175 buf->vb.state = VIDEOBUF_ACTIVE;
176 buf->count = q->count++;
177 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
178 } else if (prev->vb.width == buf->vb.width &&
179 prev->vb.height == buf->vb.height &&
180 prev->fmt == buf->fmt) {
181 list_move_tail(&buf->vb.queue, &q->active);
182 buf->vb.state = VIDEOBUF_ACTIVE;
183 buf->count = q->count++;
184 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
185 prev->risc.jmp[2] = cpu_to_le32(0); /* Bits 63 - 32 */
186 } else {
187 return 0;
188 }
189 prev = buf;
190 }
191}
192
193static void cx25821_vid_timeout(unsigned long data)
194{
195 struct cx25821_data *timeout_data = (struct cx25821_data *)data;
196 struct cx25821_dev *dev = timeout_data->dev;
197 const struct sram_channel *channel = timeout_data->channel;
198 struct cx25821_dmaqueue *q = &dev->channels[channel->i].dma_vidq;
199 struct cx25821_buffer *buf;
200 unsigned long flags;
201
202 /* cx25821_sram_channel_dump(dev, channel); */
203 cx_clear(channel->dma_ctl, 0x11);
204
205 spin_lock_irqsave(&dev->slock, flags);
206 while (!list_empty(&q->active)) {
207 buf = list_entry(q->active.next, struct cx25821_buffer,
208 vb.queue);
209 list_del(&buf->vb.queue);
210
211 buf->vb.state = VIDEOBUF_ERROR;
212 wake_up(&buf->vb.done);
213 }
214
215 cx25821_restart_video_queue(dev, q, channel);
216 spin_unlock_irqrestore(&dev->slock, flags);
217}
218
219int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status) 102int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
220{ 103{
221 u32 count = 0;
222 int handled = 0; 104 int handled = 0;
223 u32 mask; 105 u32 mask;
224 const struct sram_channel *channel = dev->channels[chan_num].sram_channels; 106 const struct sram_channel *channel = dev->channels[chan_num].sram_channels;
@@ -239,317 +121,201 @@ int cx25821_video_irq(struct cx25821_dev *dev, int chan_num, u32 status)
239 121
240 /* risc1 y */ 122 /* risc1 y */
241 if (status & FLD_VID_DST_RISC1) { 123 if (status & FLD_VID_DST_RISC1) {
242 spin_lock(&dev->slock); 124 struct cx25821_dmaqueue *dmaq =
243 count = cx_read(channel->gpcnt); 125 &dev->channels[channel->i].dma_vidq;
244 cx25821_video_wakeup(dev, &dev->channels[channel->i].dma_vidq, 126 struct cx25821_buffer *buf;
245 count);
246 spin_unlock(&dev->slock);
247 handled++;
248 }
249 127
250 /* risc2 y */
251 if (status & 0x10) {
252 dprintk(2, "stopper video\n");
253 spin_lock(&dev->slock); 128 spin_lock(&dev->slock);
254 cx25821_restart_video_queue(dev, 129 if (!list_empty(&dmaq->active)) {
255 &dev->channels[channel->i].dma_vidq, channel); 130 buf = list_entry(dmaq->active.next,
131 struct cx25821_buffer, queue);
132
133 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
134 buf->vb.v4l2_buf.sequence = dmaq->count++;
135 list_del(&buf->queue);
136 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
137 }
256 spin_unlock(&dev->slock); 138 spin_unlock(&dev->slock);
257 handled++; 139 handled++;
258 } 140 }
259 return handled; 141 return handled;
260} 142}
261 143
262static int cx25821_buffer_setup(struct videobuf_queue *q, unsigned int *count, 144static int cx25821_queue_setup(struct vb2_queue *q, const struct v4l2_format *fmt,
263 unsigned int *size) 145 unsigned int *num_buffers, unsigned int *num_planes,
146 unsigned int sizes[], void *alloc_ctxs[])
264{ 147{
265 struct cx25821_channel *chan = q->priv_data; 148 struct cx25821_channel *chan = q->drv_priv;
266 149 unsigned size = (chan->fmt->depth * chan->width * chan->height) >> 3;
267 *size = chan->fmt->depth * chan->width * chan->height >> 3;
268 150
269 if (0 == *count) 151 if (fmt && fmt->fmt.pix.sizeimage < size)
270 *count = 32; 152 return -EINVAL;
271
272 if (*size * *count > vid_limit * 1024 * 1024)
273 *count = (vid_limit * 1024 * 1024) / *size;
274 153
154 *num_planes = 1;
155 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : size;
156 alloc_ctxs[0] = chan->dev->alloc_ctx;
275 return 0; 157 return 0;
276} 158}
277 159
278static int cx25821_buffer_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb, 160static int cx25821_buffer_prepare(struct vb2_buffer *vb)
279 enum v4l2_field field)
280{ 161{
281 struct cx25821_channel *chan = q->priv_data; 162 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
282 struct cx25821_dev *dev = chan->dev; 163 struct cx25821_dev *dev = chan->dev;
283 struct cx25821_buffer *buf = 164 struct cx25821_buffer *buf =
284 container_of(vb, struct cx25821_buffer, vb); 165 container_of(vb, struct cx25821_buffer, vb);
285 int rc, init_buffer = 0; 166 struct sg_table *sgt = vb2_dma_sg_plane_desc(vb, 0);
286 u32 line0_offset; 167 u32 line0_offset;
287 struct videobuf_dmabuf *dma = videobuf_to_dma(&buf->vb);
288 int bpl_local = LINE_SIZE_D1; 168 int bpl_local = LINE_SIZE_D1;
169 int ret;
289 170
290 BUG_ON(NULL == chan->fmt); 171 if (chan->pixel_formats == PIXEL_FRMT_411)
291 if (chan->width < 48 || chan->width > 720 || 172 buf->bpl = (chan->fmt->depth * chan->width) >> 3;
292 chan->height < 32 || chan->height > 576) 173 else
293 return -EINVAL; 174 buf->bpl = (chan->fmt->depth >> 3) * chan->width;
294
295 buf->vb.size = (chan->width * chan->height * chan->fmt->depth) >> 3;
296 175
297 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 176 if (vb2_plane_size(vb, 0) < chan->height * buf->bpl)
298 return -EINVAL; 177 return -EINVAL;
178 vb2_set_plane_payload(vb, 0, chan->height * buf->bpl);
179 buf->vb.v4l2_buf.field = chan->field;
299 180
300 if (buf->fmt != chan->fmt || 181 if (chan->pixel_formats == PIXEL_FRMT_411) {
301 buf->vb.width != chan->width || 182 bpl_local = buf->bpl;
302 buf->vb.height != chan->height || buf->vb.field != field) { 183 } else {
303 buf->fmt = chan->fmt; 184 bpl_local = buf->bpl; /* Default */
304 buf->vb.width = chan->width;
305 buf->vb.height = chan->height;
306 buf->vb.field = field;
307 init_buffer = 1;
308 }
309 185
310 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) { 186 if (chan->use_cif_resolution) {
311 init_buffer = 1; 187 if (dev->tvnorm & V4L2_STD_625_50)
312 rc = videobuf_iolock(q, &buf->vb, NULL); 188 bpl_local = 352 << 1;
313 if (0 != rc) { 189 else
314 printk(KERN_DEBUG pr_fmt("videobuf_iolock failed!\n")); 190 bpl_local = chan->cif_width << 1;
315 goto fail;
316 } 191 }
317 } 192 }
318 193
319 dprintk(1, "init_buffer=%d\n", init_buffer); 194 switch (chan->field) {
320 195 case V4L2_FIELD_TOP:
321 if (init_buffer) { 196 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
322 if (chan->pixel_formats == PIXEL_FRMT_411) 197 sgt->sgl, 0, UNSET,
323 buf->bpl = (buf->fmt->depth * buf->vb.width) >> 3; 198 buf->bpl, 0, chan->height);
324 else 199 break;
325 buf->bpl = (buf->fmt->depth >> 3) * (buf->vb.width); 200 case V4L2_FIELD_BOTTOM:
326 201 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
327 if (chan->pixel_formats == PIXEL_FRMT_411) { 202 sgt->sgl, UNSET, 0,
328 bpl_local = buf->bpl; 203 buf->bpl, 0, chan->height);
329 } else { 204 break;
330 bpl_local = buf->bpl; /* Default */ 205 case V4L2_FIELD_INTERLACED:
331 206 /* All other formats are top field first */
332 if (chan->use_cif_resolution) { 207 line0_offset = 0;
333 if (dev->tvnorm & V4L2_STD_625_50) 208 dprintk(1, "top field first\n");
334 bpl_local = 352 << 1; 209
335 else 210 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
336 bpl_local = chan->cif_width << 1; 211 sgt->sgl, line0_offset,
337 } 212 bpl_local, bpl_local, bpl_local,
338 } 213 chan->height >> 1);
339 214 break;
340 switch (buf->vb.field) { 215 case V4L2_FIELD_SEQ_TB:
341 case V4L2_FIELD_TOP: 216 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
342 cx25821_risc_buffer(dev->pci, &buf->risc, 217 sgt->sgl,
343 dma->sglist, 0, UNSET, 218 0, buf->bpl * (chan->height >> 1),
344 buf->bpl, 0, buf->vb.height); 219 buf->bpl, 0, chan->height >> 1);
345 break; 220 break;
346 case V4L2_FIELD_BOTTOM: 221 case V4L2_FIELD_SEQ_BT:
347 cx25821_risc_buffer(dev->pci, &buf->risc, 222 ret = cx25821_risc_buffer(dev->pci, &buf->risc,
348 dma->sglist, UNSET, 0, 223 sgt->sgl,
349 buf->bpl, 0, buf->vb.height); 224 buf->bpl * (chan->height >> 1), 0,
350 break; 225 buf->bpl, 0, chan->height >> 1);
351 case V4L2_FIELD_INTERLACED: 226 break;
352 /* All other formats are top field first */ 227 default:
353 line0_offset = 0; 228 WARN_ON(1);
354 dprintk(1, "top field first\n"); 229 ret = -EINVAL;
355 230 break;
356 cx25821_risc_buffer(dev->pci, &buf->risc,
357 dma->sglist, line0_offset,
358 bpl_local, bpl_local, bpl_local,
359 buf->vb.height >> 1);
360 break;
361 case V4L2_FIELD_SEQ_TB:
362 cx25821_risc_buffer(dev->pci, &buf->risc,
363 dma->sglist,
364 0, buf->bpl * (buf->vb.height >> 1),
365 buf->bpl, 0, buf->vb.height >> 1);
366 break;
367 case V4L2_FIELD_SEQ_BT:
368 cx25821_risc_buffer(dev->pci, &buf->risc,
369 dma->sglist,
370 buf->bpl * (buf->vb.height >> 1), 0,
371 buf->bpl, 0, buf->vb.height >> 1);
372 break;
373 default:
374 BUG();
375 }
376 } 231 }
377 232
378 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n", 233 dprintk(2, "[%p/%d] buffer_prep - %dx%d %dbpp \"%s\" - dma=0x%08lx\n",
379 buf, buf->vb.i, chan->width, chan->height, chan->fmt->depth, 234 buf, buf->vb.v4l2_buf.index, chan->width, chan->height,
380 chan->fmt->name, (unsigned long)buf->risc.dma); 235 chan->fmt->depth, chan->fmt->name,
381 236 (unsigned long)buf->risc.dma);
382 buf->vb.state = VIDEOBUF_PREPARED;
383
384 return 0;
385 237
386fail: 238 return ret;
387 cx25821_free_buffer(q, buf);
388 return rc;
389} 239}
390 240
391static void cx25821_buffer_release(struct videobuf_queue *q, 241static void cx25821_buffer_finish(struct vb2_buffer *vb)
392 struct videobuf_buffer *vb)
393{ 242{
394 struct cx25821_buffer *buf = 243 struct cx25821_buffer *buf =
395 container_of(vb, struct cx25821_buffer, vb); 244 container_of(vb, struct cx25821_buffer, vb);
245 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
246 struct cx25821_dev *dev = chan->dev;
396 247
397 cx25821_free_buffer(q, buf); 248 cx25821_free_buffer(dev, buf);
398}
399
400static int cx25821_video_mmap(struct file *file, struct vm_area_struct *vma)
401{
402 struct cx25821_channel *chan = video_drvdata(file);
403
404 return videobuf_mmap_mapper(&chan->vidq, vma);
405} 249}
406 250
407 251static void cx25821_buffer_queue(struct vb2_buffer *vb)
408static void buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb)
409{ 252{
410 struct cx25821_buffer *buf = 253 struct cx25821_buffer *buf =
411 container_of(vb, struct cx25821_buffer, vb); 254 container_of(vb, struct cx25821_buffer, vb);
412 struct cx25821_buffer *prev; 255 struct cx25821_channel *chan = vb->vb2_queue->drv_priv;
413 struct cx25821_channel *chan = vq->priv_data;
414 struct cx25821_dev *dev = chan->dev; 256 struct cx25821_dev *dev = chan->dev;
257 struct cx25821_buffer *prev;
415 struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq; 258 struct cx25821_dmaqueue *q = &dev->channels[chan->id].dma_vidq;
416 259
417 /* add jump to stopper */ 260 buf->risc.cpu[1] = cpu_to_le32(buf->risc.dma + 12);
418 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_IRQ1 | RISC_CNT_INC); 261 buf->risc.jmp[0] = cpu_to_le32(RISC_JUMP | RISC_CNT_INC);
419 buf->risc.jmp[1] = cpu_to_le32(q->stopper.dma); 262 buf->risc.jmp[1] = cpu_to_le32(buf->risc.dma + 12);
420 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */ 263 buf->risc.jmp[2] = cpu_to_le32(0); /* bits 63-32 */
421 264
422 dprintk(2, "jmp to stopper (0x%x)\n", buf->risc.jmp[1]); 265 if (list_empty(&q->active)) {
423 266 list_add_tail(&buf->queue, &q->active);
424 if (!list_empty(&q->queued)) {
425 list_add_tail(&buf->vb.queue, &q->queued);
426 buf->vb.state = VIDEOBUF_QUEUED;
427 dprintk(2, "[%p/%d] buffer_queue - append to queued\n", buf,
428 buf->vb.i);
429
430 } else if (list_empty(&q->active)) {
431 list_add_tail(&buf->vb.queue, &q->active);
432 cx25821_start_video_dma(dev, q, buf, chan->sram_channels);
433 buf->vb.state = VIDEOBUF_ACTIVE;
434 buf->count = q->count++;
435 mod_timer(&q->timeout, jiffies + BUFFER_TIMEOUT);
436 dprintk(2, "[%p/%d] buffer_queue - first active, buf cnt = %d, q->count = %d\n",
437 buf, buf->vb.i, buf->count, q->count);
438 } else { 267 } else {
268 buf->risc.cpu[0] |= cpu_to_le32(RISC_IRQ1);
439 prev = list_entry(q->active.prev, struct cx25821_buffer, 269 prev = list_entry(q->active.prev, struct cx25821_buffer,
440 vb.queue); 270 queue);
441 if (prev->vb.width == buf->vb.width 271 list_add_tail(&buf->queue, &q->active);
442 && prev->vb.height == buf->vb.height 272 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
443 && prev->fmt == buf->fmt) {
444 list_add_tail(&buf->vb.queue, &q->active);
445 buf->vb.state = VIDEOBUF_ACTIVE;
446 buf->count = q->count++;
447 prev->risc.jmp[1] = cpu_to_le32(buf->risc.dma);
448
449 /* 64 bit bits 63-32 */
450 prev->risc.jmp[2] = cpu_to_le32(0);
451 dprintk(2, "[%p/%d] buffer_queue - append to active, buf->count=%d\n",
452 buf, buf->vb.i, buf->count);
453
454 } else {
455 list_add_tail(&buf->vb.queue, &q->queued);
456 buf->vb.state = VIDEOBUF_QUEUED;
457 dprintk(2, "[%p/%d] buffer_queue - first queued\n", buf,
458 buf->vb.i);
459 }
460 } 273 }
461
462 if (list_empty(&q->active))
463 dprintk(2, "active queue empty!\n");
464} 274}
465 275
466static struct videobuf_queue_ops cx25821_video_qops = { 276static int cx25821_start_streaming(struct vb2_queue *q, unsigned int count)
467 .buf_setup = cx25821_buffer_setup,
468 .buf_prepare = cx25821_buffer_prepare,
469 .buf_queue = buffer_queue,
470 .buf_release = cx25821_buffer_release,
471};
472
473static ssize_t video_read(struct file *file, char __user * data, size_t count,
474 loff_t *ppos)
475{ 277{
476 struct v4l2_fh *fh = file->private_data; 278 struct cx25821_channel *chan = q->drv_priv;
477 struct cx25821_channel *chan = video_drvdata(file);
478 struct cx25821_dev *dev = chan->dev; 279 struct cx25821_dev *dev = chan->dev;
479 int err = 0; 280 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq;
480 281 struct cx25821_buffer *buf = list_entry(dmaq->active.next,
481 if (mutex_lock_interruptible(&dev->lock)) 282 struct cx25821_buffer, queue);
482 return -ERESTARTSYS;
483 if (chan->streaming_fh && chan->streaming_fh != fh) {
484 err = -EBUSY;
485 goto unlock;
486 }
487 chan->streaming_fh = fh;
488 283
489 err = videobuf_read_one(&chan->vidq, data, count, ppos, 284 dmaq->count = 0;
490 file->f_flags & O_NONBLOCK); 285 cx25821_start_video_dma(dev, dmaq, buf, chan->sram_channels);
491unlock: 286 return 0;
492 mutex_unlock(&dev->lock);
493 return err;
494}
495
496static unsigned int video_poll(struct file *file,
497 struct poll_table_struct *wait)
498{
499 struct cx25821_channel *chan = video_drvdata(file);
500 unsigned long req_events = poll_requested_events(wait);
501 unsigned int res = v4l2_ctrl_poll(file, wait);
502
503 if (req_events & (POLLIN | POLLRDNORM))
504 res |= videobuf_poll_stream(file, &chan->vidq, wait);
505 return res;
506
507 /* This doesn't belong in poll(). This can be done
508 * much better with vb2. We keep this code here as a
509 * reminder.
510 if ((res & POLLIN) && buf->vb.state == VIDEOBUF_DONE) {
511 struct cx25821_dev *dev = chan->dev;
512
513 if (dev && chan->use_cif_resolution) {
514 u8 cam_id = *((char *)buf->vb.baddr + 3);
515 memcpy((char *)buf->vb.baddr,
516 (char *)buf->vb.baddr + (chan->width * 2),
517 (chan->width * 2));
518 *((char *)buf->vb.baddr + 3) = cam_id;
519 }
520 }
521 */
522} 287}
523 288
524static int video_release(struct file *file) 289static void cx25821_stop_streaming(struct vb2_queue *q)
525{ 290{
526 struct cx25821_channel *chan = video_drvdata(file); 291 struct cx25821_channel *chan = q->drv_priv;
527 struct v4l2_fh *fh = file->private_data;
528 struct cx25821_dev *dev = chan->dev; 292 struct cx25821_dev *dev = chan->dev;
529 const struct sram_channel *sram_ch = 293 struct cx25821_dmaqueue *dmaq = &dev->channels[chan->id].dma_vidq;
530 dev->channels[0].sram_channels; 294 unsigned long flags;
531
532 mutex_lock(&dev->lock);
533 /* stop the risc engine and fifo */
534 cx_write(sram_ch->dma_ctl, 0); /* FIFO and RISC disable */
535 295
536 /* stop video capture */ 296 cx_write(chan->sram_channels->dma_ctl, 0); /* FIFO and RISC disable */
537 if (chan->streaming_fh == fh) { 297 spin_lock_irqsave(&dev->slock, flags);
538 videobuf_queue_cancel(&chan->vidq); 298 while (!list_empty(&dmaq->active)) {
539 chan->streaming_fh = NULL; 299 struct cx25821_buffer *buf = list_entry(dmaq->active.next,
540 } 300 struct cx25821_buffer, queue);
541 301
542 if (chan->vidq.read_buf) { 302 list_del(&buf->queue);
543 cx25821_buffer_release(&chan->vidq, chan->vidq.read_buf); 303 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
544 kfree(chan->vidq.read_buf);
545 } 304 }
546 305 spin_unlock_irqrestore(&dev->slock, flags);
547 videobuf_mmap_free(&chan->vidq);
548 mutex_unlock(&dev->lock);
549
550 return v4l2_fh_release(file);
551} 306}
552 307
308static struct vb2_ops cx25821_video_qops = {
309 .queue_setup = cx25821_queue_setup,
310 .buf_prepare = cx25821_buffer_prepare,
311 .buf_finish = cx25821_buffer_finish,
312 .buf_queue = cx25821_buffer_queue,
313 .wait_prepare = vb2_ops_wait_prepare,
314 .wait_finish = vb2_ops_wait_finish,
315 .start_streaming = cx25821_start_streaming,
316 .stop_streaming = cx25821_stop_streaming,
317};
318
553/* VIDEO IOCTLS */ 319/* VIDEO IOCTLS */
554 320
555static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv, 321static int cx25821_vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
@@ -571,7 +337,7 @@ static int cx25821_vidioc_g_fmt_vid_cap(struct file *file, void *priv,
571 337
572 f->fmt.pix.width = chan->width; 338 f->fmt.pix.width = chan->width;
573 f->fmt.pix.height = chan->height; 339 f->fmt.pix.height = chan->height;
574 f->fmt.pix.field = chan->vidq.field; 340 f->fmt.pix.field = chan->field;
575 f->fmt.pix.pixelformat = chan->fmt->fourcc; 341 f->fmt.pix.pixelformat = chan->fmt->fourcc;
576 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3; 342 f->fmt.pix.bytesperline = (chan->width * chan->fmt->depth) >> 3;
577 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline; 343 f->fmt.pix.sizeimage = chan->height * f->fmt.pix.bytesperline;
@@ -632,7 +398,7 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
632 return err; 398 return err;
633 399
634 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); 400 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
635 chan->vidq.field = f->fmt.pix.field; 401 chan->field = f->fmt.pix.field;
636 chan->width = f->fmt.pix.width; 402 chan->width = f->fmt.pix.width;
637 chan->height = f->fmt.pix.height; 403 chan->height = f->fmt.pix.height;
638 404
@@ -654,47 +420,6 @@ static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
654 return 0; 420 return 0;
655} 421}
656 422
657static int vidioc_streamon(struct file *file, void *priv, enum v4l2_buf_type i)
658{
659 struct cx25821_channel *chan = video_drvdata(file);
660
661 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
662 return -EINVAL;
663
664 if (chan->streaming_fh && chan->streaming_fh != priv)
665 return -EBUSY;
666 chan->streaming_fh = priv;
667
668 return videobuf_streamon(&chan->vidq);
669}
670
671static int vidioc_streamoff(struct file *file, void *priv, enum v4l2_buf_type i)
672{
673 struct cx25821_channel *chan = video_drvdata(file);
674
675 if (i != V4L2_BUF_TYPE_VIDEO_CAPTURE)
676 return -EINVAL;
677
678 if (chan->streaming_fh && chan->streaming_fh != priv)
679 return -EBUSY;
680 if (chan->streaming_fh == NULL)
681 return 0;
682
683 chan->streaming_fh = NULL;
684 return videobuf_streamoff(&chan->vidq);
685}
686
687static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *p)
688{
689 int ret_val = 0;
690 struct cx25821_channel *chan = video_drvdata(file);
691
692 ret_val = videobuf_dqbuf(&chan->vidq, p, file->f_flags & O_NONBLOCK);
693 p->sequence = chan->dma_vidq.count;
694
695 return ret_val;
696}
697
698static int vidioc_log_status(struct file *file, void *priv) 423static int vidioc_log_status(struct file *file, void *priv)
699{ 424{
700 struct cx25821_channel *chan = video_drvdata(file); 425 struct cx25821_channel *chan = video_drvdata(file);
@@ -729,29 +454,6 @@ static int cx25821_vidioc_querycap(struct file *file, void *priv,
729 return 0; 454 return 0;
730} 455}
731 456
732static int cx25821_vidioc_reqbufs(struct file *file, void *priv,
733 struct v4l2_requestbuffers *p)
734{
735 struct cx25821_channel *chan = video_drvdata(file);
736
737 return videobuf_reqbufs(&chan->vidq, p);
738}
739
740static int cx25821_vidioc_querybuf(struct file *file, void *priv,
741 struct v4l2_buffer *p)
742{
743 struct cx25821_channel *chan = video_drvdata(file);
744
745 return videobuf_querybuf(&chan->vidq, p);
746}
747
748static int cx25821_vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *p)
749{
750 struct cx25821_channel *chan = video_drvdata(file);
751
752 return videobuf_qbuf(&chan->vidq, p);
753}
754
755static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms) 457static int cx25821_vidioc_g_std(struct file *file, void *priv, v4l2_std_id *tvnorms)
756{ 458{
757 struct cx25821_channel *chan = video_drvdata(file); 459 struct cx25821_channel *chan = video_drvdata(file);
@@ -880,7 +582,7 @@ static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
880 return err; 582 return err;
881 583
882 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat); 584 chan->fmt = cx25821_format_by_fourcc(f->fmt.pix.pixelformat);
883 chan->vidq.field = f->fmt.pix.field; 585 chan->field = f->fmt.pix.field;
884 chan->width = f->fmt.pix.width; 586 chan->width = f->fmt.pix.width;
885 chan->height = f->fmt.pix.height; 587 chan->height = f->fmt.pix.height;
886 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P) 588 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_Y41P)
@@ -890,52 +592,6 @@ static int vidioc_s_fmt_vid_out(struct file *file, void *priv,
890 return 0; 592 return 0;
891} 593}
892 594
893static ssize_t video_write(struct file *file, const char __user *data, size_t count,
894 loff_t *ppos)
895{
896 struct cx25821_channel *chan = video_drvdata(file);
897 struct cx25821_dev *dev = chan->dev;
898 struct v4l2_fh *fh = file->private_data;
899 int err = 0;
900
901 if (mutex_lock_interruptible(&dev->lock))
902 return -ERESTARTSYS;
903 if (chan->streaming_fh && chan->streaming_fh != fh) {
904 err = -EBUSY;
905 goto unlock;
906 }
907 if (!chan->streaming_fh) {
908 err = cx25821_vidupstream_init(chan, chan->pixel_formats);
909 if (err)
910 goto unlock;
911 chan->streaming_fh = fh;
912 }
913
914 err = cx25821_write_frame(chan, data, count);
915 count -= err;
916 *ppos += err;
917
918unlock:
919 mutex_unlock(&dev->lock);
920 return err;
921}
922
923static int video_out_release(struct file *file)
924{
925 struct cx25821_channel *chan = video_drvdata(file);
926 struct cx25821_dev *dev = chan->dev;
927 struct v4l2_fh *fh = file->private_data;
928
929 mutex_lock(&dev->lock);
930 if (chan->streaming_fh == fh) {
931 cx25821_stop_upstream_video(chan);
932 chan->streaming_fh = NULL;
933 }
934 mutex_unlock(&dev->lock);
935
936 return v4l2_fh_release(file);
937}
938
939static const struct v4l2_ctrl_ops cx25821_ctrl_ops = { 595static const struct v4l2_ctrl_ops cx25821_ctrl_ops = {
940 .s_ctrl = cx25821_s_ctrl, 596 .s_ctrl = cx25821_s_ctrl,
941}; 597};
@@ -943,11 +599,11 @@ static const struct v4l2_ctrl_ops cx25821_ctrl_ops = {
943static const struct v4l2_file_operations video_fops = { 599static const struct v4l2_file_operations video_fops = {
944 .owner = THIS_MODULE, 600 .owner = THIS_MODULE,
945 .open = v4l2_fh_open, 601 .open = v4l2_fh_open,
946 .release = video_release, 602 .release = vb2_fop_release,
947 .read = video_read, 603 .read = vb2_fop_read,
948 .poll = video_poll, 604 .poll = vb2_fop_poll,
949 .mmap = cx25821_video_mmap,
950 .unlocked_ioctl = video_ioctl2, 605 .unlocked_ioctl = video_ioctl2,
606 .mmap = vb2_fop_mmap,
951}; 607};
952 608
953static const struct v4l2_ioctl_ops video_ioctl_ops = { 609static const struct v4l2_ioctl_ops video_ioctl_ops = {
@@ -956,17 +612,19 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
956 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap, 612 .vidioc_g_fmt_vid_cap = cx25821_vidioc_g_fmt_vid_cap,
957 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap, 613 .vidioc_try_fmt_vid_cap = cx25821_vidioc_try_fmt_vid_cap,
958 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap, 614 .vidioc_s_fmt_vid_cap = vidioc_s_fmt_vid_cap,
959 .vidioc_reqbufs = cx25821_vidioc_reqbufs, 615 .vidioc_reqbufs = vb2_ioctl_reqbufs,
960 .vidioc_querybuf = cx25821_vidioc_querybuf, 616 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
961 .vidioc_qbuf = cx25821_vidioc_qbuf, 617 .vidioc_create_bufs = vb2_ioctl_create_bufs,
962 .vidioc_dqbuf = vidioc_dqbuf, 618 .vidioc_querybuf = vb2_ioctl_querybuf,
619 .vidioc_qbuf = vb2_ioctl_qbuf,
620 .vidioc_dqbuf = vb2_ioctl_dqbuf,
621 .vidioc_streamon = vb2_ioctl_streamon,
622 .vidioc_streamoff = vb2_ioctl_streamoff,
963 .vidioc_g_std = cx25821_vidioc_g_std, 623 .vidioc_g_std = cx25821_vidioc_g_std,
964 .vidioc_s_std = cx25821_vidioc_s_std, 624 .vidioc_s_std = cx25821_vidioc_s_std,
965 .vidioc_enum_input = cx25821_vidioc_enum_input, 625 .vidioc_enum_input = cx25821_vidioc_enum_input,
966 .vidioc_g_input = cx25821_vidioc_g_input, 626 .vidioc_g_input = cx25821_vidioc_g_input,
967 .vidioc_s_input = cx25821_vidioc_s_input, 627 .vidioc_s_input = cx25821_vidioc_s_input,
968 .vidioc_streamon = vidioc_streamon,
969 .vidioc_streamoff = vidioc_streamoff,
970 .vidioc_log_status = vidioc_log_status, 628 .vidioc_log_status = vidioc_log_status,
971 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event, 629 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
972 .vidioc_unsubscribe_event = v4l2_event_unsubscribe, 630 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
@@ -984,9 +642,11 @@ static const struct video_device cx25821_video_device = {
984static const struct v4l2_file_operations video_out_fops = { 642static const struct v4l2_file_operations video_out_fops = {
985 .owner = THIS_MODULE, 643 .owner = THIS_MODULE,
986 .open = v4l2_fh_open, 644 .open = v4l2_fh_open,
987 .write = video_write, 645 .release = vb2_fop_release,
988 .release = video_out_release, 646 .write = vb2_fop_write,
647 .poll = vb2_fop_poll,
989 .unlocked_ioctl = video_ioctl2, 648 .unlocked_ioctl = video_ioctl2,
649 .mmap = vb2_fop_mmap,
990}; 650};
991 651
992static const struct v4l2_ioctl_ops video_out_ioctl_ops = { 652static const struct v4l2_ioctl_ops video_out_ioctl_ops = {
@@ -1019,9 +679,6 @@ void cx25821_video_unregister(struct cx25821_dev *dev, int chan_num)
1019 if (video_is_registered(&dev->channels[chan_num].vdev)) { 679 if (video_is_registered(&dev->channels[chan_num].vdev)) {
1020 video_unregister_device(&dev->channels[chan_num].vdev); 680 video_unregister_device(&dev->channels[chan_num].vdev);
1021 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl); 681 v4l2_ctrl_handler_free(&dev->channels[chan_num].hdl);
1022
1023 btcx_riscmem_free(dev->pci,
1024 &dev->channels[chan_num].dma_vidq.stopper);
1025 } 682 }
1026} 683}
1027 684
@@ -1035,10 +692,11 @@ int cx25821_video_register(struct cx25821_dev *dev)
1035 692
1036 spin_lock_init(&dev->slock); 693 spin_lock_init(&dev->slock);
1037 694
1038 for (i = 0; i < MAX_VID_CHANNEL_NUM - 1; ++i) { 695 for (i = 0; i < MAX_VID_CAP_CHANNEL_NUM - 1; ++i) {
1039 struct cx25821_channel *chan = &dev->channels[i]; 696 struct cx25821_channel *chan = &dev->channels[i];
1040 struct video_device *vdev = &chan->vdev; 697 struct video_device *vdev = &chan->vdev;
1041 struct v4l2_ctrl_handler *hdl = &chan->hdl; 698 struct v4l2_ctrl_handler *hdl = &chan->hdl;
699 struct vb2_queue *q;
1042 bool is_output = i > SRAM_CH08; 700 bool is_output = i > SRAM_CH08;
1043 701
1044 if (i == SRAM_CH08) /* audio channel */ 702 if (i == SRAM_CH08) /* audio channel */
@@ -1066,11 +724,9 @@ int cx25821_video_register(struct cx25821_dev *dev)
1066 chan->out->chan = chan; 724 chan->out->chan = chan;
1067 } 725 }
1068 726
1069 cx25821_risc_stopper(dev->pci, &chan->dma_vidq.stopper,
1070 chan->sram_channels->dma_ctl, 0x11, 0);
1071
1072 chan->sram_channels = &cx25821_sram_channels[i]; 727 chan->sram_channels = &cx25821_sram_channels[i];
1073 chan->width = 720; 728 chan->width = 720;
729 chan->field = V4L2_FIELD_INTERLACED;
1074 if (dev->tvnorm & V4L2_STD_625_50) 730 if (dev->tvnorm & V4L2_STD_625_50)
1075 chan->height = 576; 731 chan->height = 576;
1076 else 732 else
@@ -1084,19 +740,27 @@ int cx25821_video_register(struct cx25821_dev *dev)
1084 cx_write(chan->sram_channels->int_stat, 0xffffffff); 740 cx_write(chan->sram_channels->int_stat, 0xffffffff);
1085 741
1086 INIT_LIST_HEAD(&chan->dma_vidq.active); 742 INIT_LIST_HEAD(&chan->dma_vidq.active);
1087 INIT_LIST_HEAD(&chan->dma_vidq.queued);
1088 743
1089 chan->timeout_data.dev = dev; 744 q = &chan->vidq;
1090 chan->timeout_data.channel = &cx25821_sram_channels[i]; 745
1091 chan->dma_vidq.timeout.function = cx25821_vid_timeout; 746 q->type = is_output ? V4L2_BUF_TYPE_VIDEO_OUTPUT :
1092 chan->dma_vidq.timeout.data = (unsigned long)&chan->timeout_data; 747 V4L2_BUF_TYPE_VIDEO_CAPTURE;
1093 init_timer(&chan->dma_vidq.timeout); 748 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
749 q->io_modes |= is_output ? VB2_WRITE : VB2_READ;
750 q->gfp_flags = GFP_DMA32;
751 q->min_buffers_needed = 2;
752 q->drv_priv = chan;
753 q->buf_struct_size = sizeof(struct cx25821_buffer);
754 q->ops = &cx25821_video_qops;
755 q->mem_ops = &vb2_dma_sg_memops;
756 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
757 q->lock = &dev->lock;
1094 758
1095 if (!is_output) 759 if (!is_output) {
1096 videobuf_queue_sg_init(&chan->vidq, &cx25821_video_qops, &dev->pci->dev, 760 err = vb2_queue_init(q);
1097 &dev->slock, V4L2_BUF_TYPE_VIDEO_CAPTURE, 761 if (err < 0)
1098 V4L2_FIELD_INTERLACED, sizeof(struct cx25821_buffer), 762 goto fail_unreg;
1099 chan, &dev->lock); 763 }
1100 764
1101 /* register v4l devices */ 765 /* register v4l devices */
1102 *vdev = is_output ? cx25821_video_out_device : cx25821_video_device; 766 *vdev = is_output ? cx25821_video_out_device : cx25821_video_device;
@@ -1106,6 +770,7 @@ int cx25821_video_register(struct cx25821_dev *dev)
1106 else 770 else
1107 vdev->vfl_dir = VFL_DIR_TX; 771 vdev->vfl_dir = VFL_DIR_TX;
1108 vdev->lock = &dev->lock; 772 vdev->lock = &dev->lock;
773 vdev->queue = q;
1109 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i); 774 snprintf(vdev->name, sizeof(vdev->name), "%s #%d", dev->name, i);
1110 video_set_drvdata(vdev, chan); 775 video_set_drvdata(vdev, chan);
1111 776
diff --git a/drivers/media/pci/cx25821/cx25821.h b/drivers/media/pci/cx25821/cx25821.h
index 90bdc196929f..d81a08a2df4f 100644
--- a/drivers/media/pci/cx25821/cx25821.h
+++ b/drivers/media/pci/cx25821/cx25821.h
@@ -34,9 +34,8 @@
34#include <media/v4l2-common.h> 34#include <media/v4l2-common.h>
35#include <media/v4l2-device.h> 35#include <media/v4l2-device.h>
36#include <media/v4l2-ctrls.h> 36#include <media/v4l2-ctrls.h>
37#include <media/videobuf-dma-sg.h> 37#include <media/videobuf2-dma-sg.h>
38 38
39#include "btcx-risc.h"
40#include "cx25821-reg.h" 39#include "cx25821-reg.h"
41#include "cx25821-medusa-reg.h" 40#include "cx25821-medusa-reg.h"
42#include "cx25821-sram.h" 41#include "cx25821-sram.h"
@@ -89,6 +88,13 @@
89 88
90#define CX25821_BOARD_CONEXANT_ATHENA10 1 89#define CX25821_BOARD_CONEXANT_ATHENA10 1
91#define MAX_VID_CHANNEL_NUM 12 90#define MAX_VID_CHANNEL_NUM 12
91
92/*
93 * Maximum capture-only channels. This can go away once video/audio output
94 * is fully supported in this driver.
95 */
96#define MAX_VID_CAP_CHANNEL_NUM 10
97
92#define VID_CHANNEL_NUM 8 98#define VID_CHANNEL_NUM 8
93 99
94struct cx25821_fmt { 100struct cx25821_fmt {
@@ -111,16 +117,23 @@ enum cx25821_src_sel_type {
111 CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO 117 CX25821_SRC_SEL_PARALLEL_MPEG_VIDEO
112}; 118};
113 119
120struct cx25821_riscmem {
121 unsigned int size;
122 __le32 *cpu;
123 __le32 *jmp;
124 dma_addr_t dma;
125};
126
114/* buffer for one video frame */ 127/* buffer for one video frame */
115struct cx25821_buffer { 128struct cx25821_buffer {
116 /* common v4l buffer stuff -- must be first */ 129 /* common v4l buffer stuff -- must be first */
117 struct videobuf_buffer vb; 130 struct vb2_buffer vb;
131 struct list_head queue;
118 132
119 /* cx25821 specific */ 133 /* cx25821 specific */
120 unsigned int bpl; 134 unsigned int bpl;
121 struct btcx_riscmem risc; 135 struct cx25821_riscmem risc;
122 const struct cx25821_fmt *fmt; 136 const struct cx25821_fmt *fmt;
123 u32 count;
124}; 137};
125 138
126enum port { 139enum port {
@@ -159,17 +172,9 @@ struct cx25821_i2c {
159 172
160struct cx25821_dmaqueue { 173struct cx25821_dmaqueue {
161 struct list_head active; 174 struct list_head active;
162 struct list_head queued;
163 struct timer_list timeout;
164 struct btcx_riscmem stopper;
165 u32 count; 175 u32 count;
166}; 176};
167 177
168struct cx25821_data {
169 struct cx25821_dev *dev;
170 const struct sram_channel *channel;
171};
172
173struct cx25821_dev; 178struct cx25821_dev;
174 179
175struct cx25821_channel; 180struct cx25821_channel;
@@ -207,18 +212,17 @@ struct cx25821_video_out_data {
207struct cx25821_channel { 212struct cx25821_channel {
208 unsigned id; 213 unsigned id;
209 struct cx25821_dev *dev; 214 struct cx25821_dev *dev;
210 struct v4l2_fh *streaming_fh;
211 215
212 struct v4l2_ctrl_handler hdl; 216 struct v4l2_ctrl_handler hdl;
213 struct cx25821_data timeout_data;
214 217
215 struct video_device vdev; 218 struct video_device vdev;
216 struct cx25821_dmaqueue dma_vidq; 219 struct cx25821_dmaqueue dma_vidq;
217 struct videobuf_queue vidq; 220 struct vb2_queue vidq;
218 221
219 const struct sram_channel *sram_channels; 222 const struct sram_channel *sram_channels;
220 223
221 const struct cx25821_fmt *fmt; 224 const struct cx25821_fmt *fmt;
225 unsigned field;
222 unsigned int width, height; 226 unsigned int width, height;
223 int pixel_formats; 227 int pixel_formats;
224 int use_cif_resolution; 228 int use_cif_resolution;
@@ -244,6 +248,7 @@ struct cx25821_dev {
244 int hwrevision; 248 int hwrevision;
245 /* used by cx25821-alsa */ 249 /* used by cx25821-alsa */
246 struct snd_card *card; 250 struct snd_card *card;
251 void *alloc_ctx;
247 252
248 u32 clk_freq; 253 u32 clk_freq;
249 254
@@ -405,21 +410,22 @@ extern int cx25821_sram_channel_setup(struct cx25821_dev *dev,
405 const struct sram_channel *ch, unsigned int bpl, 410 const struct sram_channel *ch, unsigned int bpl,
406 u32 risc); 411 u32 risc);
407 412
408extern int cx25821_risc_buffer(struct pci_dev *pci, struct btcx_riscmem *risc, 413extern int cx25821_riscmem_alloc(struct pci_dev *pci,
414 struct cx25821_riscmem *risc,
415 unsigned int size);
416extern int cx25821_risc_buffer(struct pci_dev *pci, struct cx25821_riscmem *risc,
409 struct scatterlist *sglist, 417 struct scatterlist *sglist,
410 unsigned int top_offset, 418 unsigned int top_offset,
411 unsigned int bottom_offset, 419 unsigned int bottom_offset,
412 unsigned int bpl, 420 unsigned int bpl,
413 unsigned int padding, unsigned int lines); 421 unsigned int padding, unsigned int lines);
414extern int cx25821_risc_databuffer_audio(struct pci_dev *pci, 422extern int cx25821_risc_databuffer_audio(struct pci_dev *pci,
415 struct btcx_riscmem *risc, 423 struct cx25821_riscmem *risc,
416 struct scatterlist *sglist, 424 struct scatterlist *sglist,
417 unsigned int bpl, 425 unsigned int bpl,
418 unsigned int lines, unsigned int lpi); 426 unsigned int lines, unsigned int lpi);
419extern void cx25821_free_buffer(struct videobuf_queue *q, 427extern void cx25821_free_buffer(struct cx25821_dev *dev,
420 struct cx25821_buffer *buf); 428 struct cx25821_buffer *buf);
421extern int cx25821_risc_stopper(struct pci_dev *pci, struct btcx_riscmem *risc,
422 u32 reg, u32 mask, u32 value);
423extern void cx25821_sram_channel_dump(struct cx25821_dev *dev, 429extern void cx25821_sram_channel_dump(struct cx25821_dev *dev,
424 const struct sram_channel *ch); 430 const struct sram_channel *ch);
425extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev, 431extern void cx25821_sram_channel_dump_audio(struct cx25821_dev *dev,
diff --git a/drivers/media/pci/cx88/cx88-blackbird.c b/drivers/media/pci/cx88/cx88-blackbird.c
index d3c79d964f2c..b6be46e94289 100644
--- a/drivers/media/pci/cx88/cx88-blackbird.c
+++ b/drivers/media/pci/cx88/cx88-blackbird.c
@@ -1234,6 +1234,3 @@ static void __exit blackbird_fini(void)
1234 1234
1235module_init(blackbird_init); 1235module_init(blackbird_init);
1236module_exit(blackbird_fini); 1236module_exit(blackbird_fini);
1237
1238module_param_named(video_debug,cx8802_mpeg_template.debug, int, 0644);
1239MODULE_PARM_DESC(debug,"enable debug messages [video]");
diff --git a/drivers/media/pci/cx88/cx88-core.c b/drivers/media/pci/cx88/cx88-core.c
index dee177ed5fe9..c38d5a12e277 100644
--- a/drivers/media/pci/cx88/cx88-core.c
+++ b/drivers/media/pci/cx88/cx88-core.c
@@ -1091,10 +1091,3 @@ EXPORT_SYMBOL(cx88_core_put);
1091 1091
1092EXPORT_SYMBOL(cx88_ir_start); 1092EXPORT_SYMBOL(cx88_ir_start);
1093EXPORT_SYMBOL(cx88_ir_stop); 1093EXPORT_SYMBOL(cx88_ir_stop);
1094
1095/*
1096 * Local variables:
1097 * c-basic-offset: 8
1098 * End:
1099 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
1100 */
diff --git a/drivers/media/pci/cx88/cx88-dvb.c b/drivers/media/pci/cx88/cx88-dvb.c
index 5780e2f013b4..1b2ed238cdb6 100644
--- a/drivers/media/pci/cx88/cx88-dvb.c
+++ b/drivers/media/pci/cx88/cx88-dvb.c
@@ -1504,8 +1504,8 @@ static int dvb_register(struct cx8802_dev *dev)
1504 fe0->dvb.frontend = dvb_attach(stv0288_attach, 1504 fe0->dvb.frontend = dvb_attach(stv0288_attach,
1505 &tevii_tuner_earda_config, 1505 &tevii_tuner_earda_config,
1506 &core->i2c_adap); 1506 &core->i2c_adap);
1507 if (fe0->dvb.frontend != NULL) { 1507 if (fe0->dvb.frontend != NULL) {
1508 if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61, 1508 if (!dvb_attach(stb6000_attach, fe0->dvb.frontend, 0x61,
1509 &core->i2c_adap)) 1509 &core->i2c_adap))
1510 goto frontend_detach; 1510 goto frontend_detach;
1511 core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage; 1511 core->prev_set_voltage = fe0->dvb.frontend->ops.set_voltage;
diff --git a/drivers/media/pci/cx88/cx88-mpeg.c b/drivers/media/pci/cx88/cx88-mpeg.c
index 1c1f69e6b0b9..a369b0840acf 100644
--- a/drivers/media/pci/cx88/cx88-mpeg.c
+++ b/drivers/media/pci/cx88/cx88-mpeg.c
@@ -833,10 +833,3 @@ EXPORT_SYMBOL(cx8802_start_dma);
833EXPORT_SYMBOL(cx8802_register_driver); 833EXPORT_SYMBOL(cx8802_register_driver);
834EXPORT_SYMBOL(cx8802_unregister_driver); 834EXPORT_SYMBOL(cx8802_unregister_driver);
835EXPORT_SYMBOL(cx8802_get_driver); 835EXPORT_SYMBOL(cx8802_get_driver);
836/* ----------------------------------------------------------- */
837/*
838 * Local variables:
839 * c-basic-offset: 8
840 * End:
841 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
842 */
diff --git a/drivers/media/pci/cx88/cx88-tvaudio.c b/drivers/media/pci/cx88/cx88-tvaudio.c
index 424fd97495dc..6bbce6ad6295 100644
--- a/drivers/media/pci/cx88/cx88-tvaudio.c
+++ b/drivers/media/pci/cx88/cx88-tvaudio.c
@@ -1050,10 +1050,3 @@ EXPORT_SYMBOL(cx88_newstation);
1050EXPORT_SYMBOL(cx88_set_stereo); 1050EXPORT_SYMBOL(cx88_set_stereo);
1051EXPORT_SYMBOL(cx88_get_stereo); 1051EXPORT_SYMBOL(cx88_get_stereo);
1052EXPORT_SYMBOL(cx88_audio_thread); 1052EXPORT_SYMBOL(cx88_audio_thread);
1053
1054/*
1055 * Local variables:
1056 * c-basic-offset: 8
1057 * End:
1058 * kate: eol "unix"; indent-width 3; remove-trailing-space on; replace-trailing-space-save on; tab-width 8; replace-tabs off; space-indent off; mixed-indent off
1059 */
diff --git a/drivers/media/pci/ivtv/ivtv-irq.c b/drivers/media/pci/ivtv/ivtv-irq.c
index ab6d5d25aa6f..e7d701777e53 100644
--- a/drivers/media/pci/ivtv/ivtv-irq.c
+++ b/drivers/media/pci/ivtv/ivtv-irq.c
@@ -357,7 +357,6 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
357 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET; 357 u32 uv_offset = offset + IVTV_YUV_BUFFER_UV_OFFSET;
358 int y_done = 0; 358 int y_done = 0;
359 int bytes_written = 0; 359 int bytes_written = 0;
360 unsigned long flags = 0;
361 int idx = 0; 360 int idx = 0;
362 361
363 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset); 362 IVTV_DEBUG_HI_DMA("DEC PREPARE DMA %s: %08x %08x\n", s->name, s->q_predma.bytesused, offset);
@@ -407,16 +406,21 @@ void ivtv_dma_stream_dec_prepare(struct ivtv_stream *s, u32 offset, int lock)
407 406
408 /* Sync Hardware SG List of buffers */ 407 /* Sync Hardware SG List of buffers */
409 ivtv_stream_sync_for_device(s); 408 ivtv_stream_sync_for_device(s);
410 if (lock) 409 if (lock) {
410 unsigned long flags = 0;
411
411 spin_lock_irqsave(&itv->dma_reg_lock, flags); 412 spin_lock_irqsave(&itv->dma_reg_lock, flags);
412 if (!test_bit(IVTV_F_I_DMA, &itv->i_flags)) { 413 if (!test_bit(IVTV_F_I_DMA, &itv->i_flags))
413 ivtv_dma_dec_start(s); 414 ivtv_dma_dec_start(s);
414 } 415 else
415 else { 416 set_bit(IVTV_F_S_DMA_PENDING, &s->s_flags);
416 set_bit(IVTV_F_S_DMA_PENDING, &s->s_flags);
417 }
418 if (lock)
419 spin_unlock_irqrestore(&itv->dma_reg_lock, flags); 417 spin_unlock_irqrestore(&itv->dma_reg_lock, flags);
418 } else {
419 if (!test_bit(IVTV_F_I_DMA, &itv->i_flags))
420 ivtv_dma_dec_start(s);
421 else
422 set_bit(IVTV_F_S_DMA_PENDING, &s->s_flags);
423 }
420} 424}
421 425
422static void ivtv_dma_enc_start_xfer(struct ivtv_stream *s) 426static void ivtv_dma_enc_start_xfer(struct ivtv_stream *s)
diff --git a/drivers/media/pci/mantis/mantis_core.c b/drivers/media/pci/mantis/mantis_core.c
index 684d9061fe2a..82220ea72dd3 100644
--- a/drivers/media/pci/mantis/mantis_core.c
+++ b/drivers/media/pci/mantis/mantis_core.c
@@ -56,29 +56,6 @@ static int read_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
56 return 0; 56 return 0;
57} 57}
58 58
59static int write_eeprom_byte(struct mantis_pci *mantis, u8 *data, u8 length)
60{
61 int err;
62
63 struct i2c_msg msg = {
64 .addr = 0x50,
65 .flags = 0,
66 .buf = data,
67 .len = length
68 };
69
70 err = i2c_transfer(&mantis->adapter, &msg, 1);
71 if (err < 0) {
72 dprintk(verbose, MANTIS_ERROR, 1,
73 "ERROR: i2c write: < err=%i length=0x%02x d0=0x%02x, d1=0x%02x >",
74 err, length, data[0], data[1]);
75
76 return err;
77 }
78
79 return 0;
80}
81
82static int get_mac_address(struct mantis_pci *mantis) 59static int get_mac_address(struct mantis_pci *mantis)
83{ 60{
84 int err; 61 int err;
diff --git a/drivers/media/pci/saa7134/saa7134-video.c b/drivers/media/pci/saa7134/saa7134-video.c
index 701b52f34689..99d09a7566d3 100644
--- a/drivers/media/pci/saa7134/saa7134-video.c
+++ b/drivers/media/pci/saa7134/saa7134-video.c
@@ -1084,11 +1084,6 @@ static int saa7134_s_ctrl(struct v4l2_ctrl *ctrl)
1084 1084
1085/* ------------------------------------------------------------------ */ 1085/* ------------------------------------------------------------------ */
1086 1086
1087static inline struct vb2_queue *saa7134_queue(struct file *file)
1088{
1089 return video_devdata(file)->queue;
1090}
1091
1092static int video_open(struct file *file) 1087static int video_open(struct file *file)
1093{ 1088{
1094 struct video_device *vdev = video_devdata(file); 1089 struct video_device *vdev = video_devdata(file);
diff --git a/drivers/media/pci/smipcie/smipcie.c b/drivers/media/pci/smipcie/smipcie.c
index f773350e67b9..36c8ed77309c 100644
--- a/drivers/media/pci/smipcie/smipcie.c
+++ b/drivers/media/pci/smipcie/smipcie.c
@@ -448,16 +448,19 @@ static void smi_port_exit(struct smi_port *port)
448 port->enable = 0; 448 port->enable = 0;
449} 449}
450 450
451static void smi_port_irq(struct smi_port *port, u32 int_status) 451static int smi_port_irq(struct smi_port *port, u32 int_status)
452{ 452{
453 u32 port_req_irq = port->_dmaInterruptCH0 | port->_dmaInterruptCH1; 453 u32 port_req_irq = port->_dmaInterruptCH0 | port->_dmaInterruptCH1;
454 int handled = 0;
454 455
455 if (int_status & port_req_irq) { 456 if (int_status & port_req_irq) {
456 smi_port_disableInterrupt(port); 457 smi_port_disableInterrupt(port);
457 port->_int_status = int_status; 458 port->_int_status = int_status;
458 smi_port_clearInterrupt(port); 459 smi_port_clearInterrupt(port);
459 tasklet_schedule(&port->tasklet); 460 tasklet_schedule(&port->tasklet);
461 handled = 1;
460 } 462 }
463 return handled;
461} 464}
462 465
463static irqreturn_t smi_irq_handler(int irq, void *dev_id) 466static irqreturn_t smi_irq_handler(int irq, void *dev_id)
@@ -465,18 +468,19 @@ static irqreturn_t smi_irq_handler(int irq, void *dev_id)
465 struct smi_dev *dev = dev_id; 468 struct smi_dev *dev = dev_id;
466 struct smi_port *port0 = &dev->ts_port[0]; 469 struct smi_port *port0 = &dev->ts_port[0];
467 struct smi_port *port1 = &dev->ts_port[1]; 470 struct smi_port *port1 = &dev->ts_port[1];
471 int handled = 0;
468 472
469 u32 intr_status = smi_read(MSI_INT_STATUS); 473 u32 intr_status = smi_read(MSI_INT_STATUS);
470 474
471 /* ts0 interrupt.*/ 475 /* ts0 interrupt.*/
472 if (dev->info->ts_0) 476 if (dev->info->ts_0)
473 smi_port_irq(port0, intr_status); 477 handled += smi_port_irq(port0, intr_status);
474 478
475 /* ts1 interrupt.*/ 479 /* ts1 interrupt.*/
476 if (dev->info->ts_1) 480 if (dev->info->ts_1)
477 smi_port_irq(port1, intr_status); 481 handled += smi_port_irq(port1, intr_status);
478 482
479 return IRQ_HANDLED; 483 return IRQ_RETVAL(handled);
480} 484}
481 485
482static struct i2c_client *smi_add_i2c_client(struct i2c_adapter *adapter, 486static struct i2c_client *smi_add_i2c_client(struct i2c_adapter *adapter,
diff --git a/drivers/media/pci/solo6x10/solo6x10-core.c b/drivers/media/pci/solo6x10/solo6x10-core.c
index 8cbe6b49f4c2..570d119ea18b 100644
--- a/drivers/media/pci/solo6x10/solo6x10-core.c
+++ b/drivers/media/pci/solo6x10/solo6x10-core.c
@@ -182,7 +182,7 @@ static ssize_t eeprom_store(struct device *dev, struct device_attribute *attr,
182{ 182{
183 struct solo_dev *solo_dev = 183 struct solo_dev *solo_dev =
184 container_of(dev, struct solo_dev, dev); 184 container_of(dev, struct solo_dev, dev);
185 unsigned short *p = (unsigned short *)buf; 185 u16 *p = (u16 *)buf;
186 int i; 186 int i;
187 187
188 if (count & 0x1) 188 if (count & 0x1)
@@ -212,7 +212,7 @@ static ssize_t eeprom_show(struct device *dev, struct device_attribute *attr,
212{ 212{
213 struct solo_dev *solo_dev = 213 struct solo_dev *solo_dev =
214 container_of(dev, struct solo_dev, dev); 214 container_of(dev, struct solo_dev, dev);
215 unsigned short *p = (unsigned short *)buf; 215 u16 *p = (u16 *)buf;
216 int count = (full_eeprom ? 128 : 64); 216 int count = (full_eeprom ? 128 : 64);
217 int i; 217 int i;
218 218
diff --git a/drivers/media/pci/solo6x10/solo6x10-eeprom.c b/drivers/media/pci/solo6x10/solo6x10-eeprom.c
index da25ce4a6952..8e81186dc785 100644
--- a/drivers/media/pci/solo6x10/solo6x10-eeprom.c
+++ b/drivers/media/pci/solo6x10/solo6x10-eeprom.c
@@ -103,7 +103,7 @@ unsigned int solo_eeprom_ewen(struct solo_dev *solo_dev, int w_en)
103__be16 solo_eeprom_read(struct solo_dev *solo_dev, int loc) 103__be16 solo_eeprom_read(struct solo_dev *solo_dev, int loc)
104{ 104{
105 int read_cmd = loc | (EE_READ_CMD << ADDR_LEN); 105 int read_cmd = loc | (EE_READ_CMD << ADDR_LEN);
106 unsigned short retval = 0; 106 u16 retval = 0;
107 int i; 107 int i;
108 108
109 solo_eeprom_cmd(solo_dev, read_cmd); 109 solo_eeprom_cmd(solo_dev, read_cmd);
diff --git a/drivers/media/pci/solo6x10/solo6x10-enc.c b/drivers/media/pci/solo6x10/solo6x10-enc.c
index d19c0aef5abc..d28211bb9674 100644
--- a/drivers/media/pci/solo6x10/solo6x10-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-enc.c
@@ -136,11 +136,11 @@ static void solo_capture_config(struct solo_dev *solo_dev)
136int solo_osd_print(struct solo_enc_dev *solo_enc) 136int solo_osd_print(struct solo_enc_dev *solo_enc)
137{ 137{
138 struct solo_dev *solo_dev = solo_enc->solo_dev; 138 struct solo_dev *solo_dev = solo_enc->solo_dev;
139 unsigned char *str = solo_enc->osd_text; 139 u8 *str = solo_enc->osd_text;
140 u8 *buf = solo_enc->osd_buf; 140 u8 *buf = solo_enc->osd_buf;
141 u32 reg; 141 u32 reg;
142 const struct font_desc *vga = find_font("VGA8x16"); 142 const struct font_desc *vga = find_font("VGA8x16");
143 const unsigned char *vga_data; 143 const u8 *vga_data;
144 int i, j; 144 int i, j;
145 145
146 if (WARN_ON_ONCE(!vga)) 146 if (WARN_ON_ONCE(!vga))
@@ -154,7 +154,7 @@ int solo_osd_print(struct solo_enc_dev *solo_enc)
154 } 154 }
155 155
156 memset(buf, 0, SOLO_OSD_WRITE_SIZE); 156 memset(buf, 0, SOLO_OSD_WRITE_SIZE);
157 vga_data = (const unsigned char *)vga->data; 157 vga_data = (const u8 *)vga->data;
158 158
159 for (i = 0; *str; i++, str++) { 159 for (i = 0; *str; i++, str++) {
160 for (j = 0; j < 16; j++) { 160 for (j = 0; j < 16; j++) {
diff --git a/drivers/media/pci/solo6x10/solo6x10-g723.c b/drivers/media/pci/solo6x10/solo6x10-g723.c
index c7141f2e63bd..7ddc76709caa 100644
--- a/drivers/media/pci/solo6x10/solo6x10-g723.c
+++ b/drivers/media/pci/solo6x10/solo6x10-g723.c
@@ -56,8 +56,8 @@
56struct solo_snd_pcm { 56struct solo_snd_pcm {
57 int on; 57 int on;
58 spinlock_t lock; 58 spinlock_t lock;
59 struct solo_dev *solo_dev; 59 struct solo_dev *solo_dev;
60 unsigned char *g723_buf; 60 u8 *g723_buf;
61 dma_addr_t g723_dma; 61 dma_addr_t g723_dma;
62}; 62};
63 63
diff --git a/drivers/media/pci/solo6x10/solo6x10-jpeg.h b/drivers/media/pci/solo6x10/solo6x10-jpeg.h
index 1c66a46da514..3c611bd3f2d8 100644
--- a/drivers/media/pci/solo6x10/solo6x10-jpeg.h
+++ b/drivers/media/pci/solo6x10/solo6x10-jpeg.h
@@ -21,7 +21,7 @@
21#ifndef __SOLO6X10_JPEG_H 21#ifndef __SOLO6X10_JPEG_H
22#define __SOLO6X10_JPEG_H 22#define __SOLO6X10_JPEG_H
23 23
24static const unsigned char jpeg_header[] = { 24static const u8 jpeg_header[] = {
25 0xff, 0xd8, 0xff, 0xfe, 0x00, 0x0d, 0x42, 0x6c, 25 0xff, 0xd8, 0xff, 0xfe, 0x00, 0x0d, 0x42, 0x6c,
26 0x75, 0x65, 0x63, 0x68, 0x65, 0x72, 0x72, 0x79, 26 0x75, 0x65, 0x63, 0x68, 0x65, 0x72, 0x72, 0x79,
27 0x20, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x20, 0x16, 27 0x20, 0xff, 0xdb, 0x00, 0x43, 0x00, 0x20, 0x16,
@@ -106,7 +106,7 @@ static const unsigned char jpeg_header[] = {
106/* This is the byte marker for the start of the DQT */ 106/* This is the byte marker for the start of the DQT */
107#define DQT_START 17 107#define DQT_START 17
108#define DQT_LEN 138 108#define DQT_LEN 138
109static const unsigned char jpeg_dqt[4][DQT_LEN] = { 109static const u8 jpeg_dqt[4][DQT_LEN] = {
110 { 110 {
111 0xff, 0xdb, 0x00, 0x43, 0x00, 111 0xff, 0xdb, 0x00, 0x43, 0x00,
112 0x08, 0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07, 112 0x08, 0x06, 0x06, 0x07, 0x06, 0x05, 0x08, 0x07,
diff --git a/drivers/media/pci/solo6x10/solo6x10-tw28.c b/drivers/media/pci/solo6x10/solo6x10-tw28.c
index edd0781ee4b5..0632d3f7c73c 100644
--- a/drivers/media/pci/solo6x10/solo6x10-tw28.c
+++ b/drivers/media/pci/solo6x10/solo6x10-tw28.c
@@ -510,7 +510,7 @@ static int tw2815_setup(struct solo_dev *solo_dev, u8 dev_addr)
510#define FIRST_ACTIVE_LINE 0x0008 510#define FIRST_ACTIVE_LINE 0x0008
511#define LAST_ACTIVE_LINE 0x0102 511#define LAST_ACTIVE_LINE 0x0102
512 512
513static void saa712x_write_regs(struct solo_dev *dev, const uint8_t *vals, 513static void saa712x_write_regs(struct solo_dev *dev, const u8 *vals,
514 int start, int n) 514 int start, int n)
515{ 515{
516 for (; start < n; start++, vals++) { 516 for (; start < n; start++, vals++) {
@@ -532,7 +532,7 @@ static void saa712x_write_regs(struct solo_dev *dev, const uint8_t *vals,
532static void saa712x_setup(struct solo_dev *dev) 532static void saa712x_setup(struct solo_dev *dev)
533{ 533{
534 const int reg_start = 0x26; 534 const int reg_start = 0x26;
535 const uint8_t saa7128_regs_ntsc[] = { 535 const u8 saa7128_regs_ntsc[] = {
536 /* :0x26 */ 536 /* :0x26 */
537 0x0d, 0x00, 537 0x0d, 0x00,
538 /* :0x28 */ 538 /* :0x28 */
diff --git a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
index 6e933d383fa2..53fff5425c13 100644
--- a/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
+++ b/drivers/media/pci/solo6x10/solo6x10-v4l2-enc.c
@@ -38,28 +38,28 @@
38#define DMA_ALIGN 4096 38#define DMA_ALIGN 4096
39 39
40/* 6010 M4V */ 40/* 6010 M4V */
41static unsigned char vop_6010_ntsc_d1[] = { 41static u8 vop_6010_ntsc_d1[] = {
42 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 42 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
43 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40, 43 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
44 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04, 44 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
45 0x1f, 0x4c, 0x58, 0x10, 0xf0, 0x71, 0x18, 0x3f, 45 0x1f, 0x4c, 0x58, 0x10, 0xf0, 0x71, 0x18, 0x3f,
46}; 46};
47 47
48static unsigned char vop_6010_ntsc_cif[] = { 48static u8 vop_6010_ntsc_cif[] = {
49 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 49 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
50 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40, 50 0x02, 0x48, 0x1d, 0xc0, 0x00, 0x40, 0x00, 0x40,
51 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04, 51 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
52 0x1f, 0x4c, 0x2c, 0x10, 0x78, 0x51, 0x18, 0x3f, 52 0x1f, 0x4c, 0x2c, 0x10, 0x78, 0x51, 0x18, 0x3f,
53}; 53};
54 54
55static unsigned char vop_6010_pal_d1[] = { 55static u8 vop_6010_pal_d1[] = {
56 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 56 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
57 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40, 57 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
58 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04, 58 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
59 0x1f, 0x4c, 0x58, 0x11, 0x20, 0x71, 0x18, 0x3f, 59 0x1f, 0x4c, 0x58, 0x11, 0x20, 0x71, 0x18, 0x3f,
60}; 60};
61 61
62static unsigned char vop_6010_pal_cif[] = { 62static u8 vop_6010_pal_cif[] = {
63 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20, 63 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x20,
64 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40, 64 0x02, 0x48, 0x15, 0xc0, 0x00, 0x40, 0x00, 0x40,
65 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04, 65 0x00, 0x40, 0x00, 0x80, 0x00, 0x97, 0x53, 0x04,
@@ -67,25 +67,25 @@ static unsigned char vop_6010_pal_cif[] = {
67}; 67};
68 68
69/* 6110 h.264 */ 69/* 6110 h.264 */
70static unsigned char vop_6110_ntsc_d1[] = { 70static u8 vop_6110_ntsc_d1[] = {
71 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e, 71 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
72 0x9a, 0x74, 0x05, 0x81, 0xec, 0x80, 0x00, 0x00, 72 0x9a, 0x74, 0x05, 0x81, 0xec, 0x80, 0x00, 0x00,
73 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 73 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
74}; 74};
75 75
76static unsigned char vop_6110_ntsc_cif[] = { 76static u8 vop_6110_ntsc_cif[] = {
77 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e, 77 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
78 0x9a, 0x74, 0x0b, 0x0f, 0xc8, 0x00, 0x00, 0x00, 78 0x9a, 0x74, 0x0b, 0x0f, 0xc8, 0x00, 0x00, 0x00,
79 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00, 79 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
80}; 80};
81 81
82static unsigned char vop_6110_pal_d1[] = { 82static u8 vop_6110_pal_d1[] = {
83 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e, 83 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
84 0x9a, 0x74, 0x05, 0x80, 0x93, 0x20, 0x00, 0x00, 84 0x9a, 0x74, 0x05, 0x80, 0x93, 0x20, 0x00, 0x00,
85 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 85 0x00, 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00,
86}; 86};
87 87
88static unsigned char vop_6110_pal_cif[] = { 88static u8 vop_6110_pal_cif[] = {
89 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e, 89 0x00, 0x00, 0x00, 0x01, 0x67, 0x42, 0x00, 0x1e,
90 0x9a, 0x74, 0x0b, 0x04, 0xb2, 0x00, 0x00, 0x00, 90 0x9a, 0x74, 0x0b, 0x04, 0xb2, 0x00, 0x00, 0x00,
91 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00, 91 0x01, 0x68, 0xce, 0x32, 0x28, 0x00, 0x00, 0x00,
@@ -149,7 +149,7 @@ void solo_update_mode(struct solo_enc_dev *solo_enc)
149{ 149{
150 struct solo_dev *solo_dev = solo_enc->solo_dev; 150 struct solo_dev *solo_dev = solo_enc->solo_dev;
151 int vop_len; 151 int vop_len;
152 unsigned char *vop; 152 u8 *vop;
153 153
154 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0; 154 solo_enc->interlaced = (solo_enc->mode & 0x08) ? 1 : 0;
155 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1); 155 solo_enc->bw_weight = max(solo_dev->fps / solo_enc->interval, 1);
@@ -239,8 +239,6 @@ static int solo_enc_on(struct solo_enc_dev *solo_enc)
239 if (solo_enc->bw_weight > solo_dev->enc_bw_remain) 239 if (solo_enc->bw_weight > solo_dev->enc_bw_remain)
240 return -EBUSY; 240 return -EBUSY;
241 solo_enc->sequence = 0; 241 solo_enc->sequence = 0;
242 solo_enc->motion_last_state = false;
243 solo_enc->frames_since_last_motion = 0;
244 solo_dev->enc_bw_remain -= solo_enc->bw_weight; 242 solo_dev->enc_bw_remain -= solo_enc->bw_weight;
245 243
246 if (solo_enc->type == SOLO_ENC_TYPE_EXT) 244 if (solo_enc->type == SOLO_ENC_TYPE_EXT)
@@ -529,36 +527,12 @@ static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
529 } 527 }
530 528
531 if (!ret) { 529 if (!ret) {
532 bool send_event = false;
533
534 vb->v4l2_buf.sequence = solo_enc->sequence++; 530 vb->v4l2_buf.sequence = solo_enc->sequence++;
535 vb->v4l2_buf.timestamp.tv_sec = vop_sec(vh); 531 vb->v4l2_buf.timestamp.tv_sec = vop_sec(vh);
536 vb->v4l2_buf.timestamp.tv_usec = vop_usec(vh); 532 vb->v4l2_buf.timestamp.tv_usec = vop_usec(vh);
537 533
538 /* Check for motion flags */ 534 /* Check for motion flags */
539 if (solo_is_motion_on(solo_enc)) { 535 if (solo_is_motion_on(solo_enc) && enc_buf->motion) {
540 /* It takes a few frames for the hardware to detect
541 * motion. Once it does it clears the motion detection
542 * register and it takes again a few frames before
543 * motion is seen. This means in practice that when the
544 * motion field is 1, it will go back to 0 for the next
545 * frame. This leads to motion detection event being
546 * sent all the time, which is not what we want.
547 * Instead wait a few frames before deciding that the
548 * motion has halted. After some experimentation it
549 * turns out that waiting for 5 frames works well.
550 */
551 if (enc_buf->motion == 0 &&
552 solo_enc->motion_last_state &&
553 solo_enc->frames_since_last_motion++ > 5)
554 send_event = true;
555 else if (enc_buf->motion) {
556 solo_enc->frames_since_last_motion = 0;
557 send_event = !solo_enc->motion_last_state;
558 }
559 }
560
561 if (send_event) {
562 struct v4l2_event ev = { 536 struct v4l2_event ev = {
563 .type = V4L2_EVENT_MOTION_DET, 537 .type = V4L2_EVENT_MOTION_DET,
564 .u.motion_det = { 538 .u.motion_det = {
@@ -568,8 +542,6 @@ static int solo_enc_fillbuf(struct solo_enc_dev *solo_enc,
568 }, 542 },
569 }; 543 };
570 544
571 solo_enc->motion_last_state = enc_buf->motion;
572 solo_enc->frames_since_last_motion = 0;
573 v4l2_event_queue(solo_enc->vfd, &ev); 545 v4l2_event_queue(solo_enc->vfd, &ev);
574 } 546 }
575 } 547 }
diff --git a/drivers/media/pci/solo6x10/solo6x10.h b/drivers/media/pci/solo6x10/solo6x10.h
index bd8edfa319b8..1ca54b08b3aa 100644
--- a/drivers/media/pci/solo6x10/solo6x10.h
+++ b/drivers/media/pci/solo6x10/solo6x10.h
@@ -159,8 +159,6 @@ struct solo_enc_dev {
159 u16 motion_thresh; 159 u16 motion_thresh;
160 bool motion_global; 160 bool motion_global;
161 bool motion_enabled; 161 bool motion_enabled;
162 bool motion_last_state;
163 u8 frames_since_last_motion;
164 u16 width; 162 u16 width;
165 u16 height; 163 u16 height;
166 164
@@ -170,9 +168,9 @@ struct solo_enc_dev {
170 __aligned(4); 168 __aligned(4);
171 169
172 /* VOP stuff */ 170 /* VOP stuff */
173 unsigned char vop[64]; 171 u8 vop[64];
174 int vop_len; 172 int vop_len;
175 unsigned char jpeg_header[1024]; 173 u8 jpeg_header[1024];
176 int jpeg_len; 174 int jpeg_len;
177 175
178 u32 fmt; 176 u32 fmt;
diff --git a/drivers/media/pci/sta2x11/Kconfig b/drivers/media/pci/sta2x11/Kconfig
index f6f30abc088b..e03587b1af71 100644
--- a/drivers/media/pci/sta2x11/Kconfig
+++ b/drivers/media/pci/sta2x11/Kconfig
@@ -5,6 +5,7 @@ config STA2X11_VIP
5 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT 5 select VIDEO_ADV7180 if MEDIA_SUBDRV_AUTOSELECT
6 select VIDEOBUF2_DMA_CONTIG 6 select VIDEOBUF2_DMA_CONTIG
7 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS 7 depends on PCI && VIDEO_V4L2 && VIRT_TO_BUS
8 depends on VIDEO_V4L2_SUBDEV_API
8 depends on I2C 9 depends on I2C
9 help 10 help
10 Say Y for support for STA2X11 VIP (Video Input Port) capture 11 Say Y for support for STA2X11 VIP (Video Input Port) capture
diff --git a/drivers/media/pci/ttpci/av7110.c b/drivers/media/pci/ttpci/av7110.c
index c1f0617a6973..45199a12b9d9 100644
--- a/drivers/media/pci/ttpci/av7110.c
+++ b/drivers/media/pci/ttpci/av7110.c
@@ -1219,11 +1219,14 @@ static int stop_ts_capture(struct av7110 *budget)
1219 1219
1220static int start_ts_capture(struct av7110 *budget) 1220static int start_ts_capture(struct av7110 *budget)
1221{ 1221{
1222 unsigned y;
1223
1222 dprintk(2, "budget: %p\n", budget); 1224 dprintk(2, "budget: %p\n", budget);
1223 1225
1224 if (budget->feeding1) 1226 if (budget->feeding1)
1225 return ++budget->feeding1; 1227 return ++budget->feeding1;
1226 memset(budget->grabbing, 0x00, TS_BUFLEN); 1228 for (y = 0; y < TS_HEIGHT; y++)
1229 memset(budget->grabbing + y * TS_WIDTH, 0x00, TS_WIDTH);
1227 budget->ttbp = 0; 1230 budget->ttbp = 0;
1228 SAA7146_ISR_CLEAR(budget->dev, MASK_10); /* VPE */ 1231 SAA7146_ISR_CLEAR(budget->dev, MASK_10); /* VPE */
1229 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */ 1232 SAA7146_IER_ENABLE(budget->dev, MASK_10); /* VPE */
diff --git a/drivers/media/pci/ttpci/budget-core.c b/drivers/media/pci/ttpci/budget-core.c
index 37d02fe09137..23e05499b509 100644
--- a/drivers/media/pci/ttpci/budget-core.c
+++ b/drivers/media/pci/ttpci/budget-core.c
@@ -231,63 +231,59 @@ static void vpeirq(unsigned long data)
231} 231}
232 232
233 233
234int ttpci_budget_debiread(struct budget *budget, u32 config, int addr, int count, 234static int ttpci_budget_debiread_nolock(struct budget *budget, u32 config,
235 int uselocks, int nobusyloop) 235 int addr, int count, int nobusyloop)
236{ 236{
237 struct saa7146_dev *saa = budget->dev; 237 struct saa7146_dev *saa = budget->dev;
238 int result = 0; 238 int result;
239 unsigned long flags = 0;
240
241 if (count > 4 || count <= 0)
242 return 0;
243
244 if (uselocks)
245 spin_lock_irqsave(&budget->debilock, flags);
246 239
247 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) { 240 result = saa7146_wait_for_debi_done(saa, nobusyloop);
248 if (uselocks) 241 if (result < 0)
249 spin_unlock_irqrestore(&budget->debilock, flags);
250 return result; 242 return result;
251 }
252 243
253 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff)); 244 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x10000 | (addr & 0xffff));
254 saa7146_write(saa, DEBI_CONFIG, config); 245 saa7146_write(saa, DEBI_CONFIG, config);
255 saa7146_write(saa, DEBI_PAGE, 0); 246 saa7146_write(saa, DEBI_PAGE, 0);
256 saa7146_write(saa, MC2, (2 << 16) | 2); 247 saa7146_write(saa, MC2, (2 << 16) | 2);
257 248
258 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) { 249 result = saa7146_wait_for_debi_done(saa, nobusyloop);
259 if (uselocks) 250 if (result < 0)
260 spin_unlock_irqrestore(&budget->debilock, flags);
261 return result; 251 return result;
262 }
263 252
264 result = saa7146_read(saa, DEBI_AD); 253 result = saa7146_read(saa, DEBI_AD);
265 result &= (0xffffffffUL >> ((4 - count) * 8)); 254 result &= (0xffffffffUL >> ((4 - count) * 8));
266
267 if (uselocks)
268 spin_unlock_irqrestore(&budget->debilock, flags);
269
270 return result; 255 return result;
271} 256}
272 257
273int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr, 258int ttpci_budget_debiread(struct budget *budget, u32 config, int addr, int count,
274 int count, u32 value, int uselocks, int nobusyloop) 259 int uselocks, int nobusyloop)
275{ 260{
276 struct saa7146_dev *saa = budget->dev;
277 unsigned long flags = 0;
278 int result;
279
280 if (count > 4 || count <= 0) 261 if (count > 4 || count <= 0)
281 return 0; 262 return 0;
282 263
283 if (uselocks) 264 if (uselocks) {
284 spin_lock_irqsave(&budget->debilock, flags); 265 unsigned long flags;
266 int result;
285 267
286 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) { 268 spin_lock_irqsave(&budget->debilock, flags);
287 if (uselocks) 269 result = ttpci_budget_debiread_nolock(budget, config, addr,
288 spin_unlock_irqrestore(&budget->debilock, flags); 270 count, nobusyloop);
271 spin_unlock_irqrestore(&budget->debilock, flags);
289 return result; 272 return result;
290 } 273 }
274 return ttpci_budget_debiread_nolock(budget, config, addr,
275 count, nobusyloop);
276}
277
278static int ttpci_budget_debiwrite_nolock(struct budget *budget, u32 config,
279 int addr, int count, u32 value, int nobusyloop)
280{
281 struct saa7146_dev *saa = budget->dev;
282 int result;
283
284 result = saa7146_wait_for_debi_done(saa, nobusyloop);
285 if (result < 0)
286 return result;
291 287
292 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x00000 | (addr & 0xffff)); 288 saa7146_write(saa, DEBI_COMMAND, (count << 17) | 0x00000 | (addr & 0xffff));
293 saa7146_write(saa, DEBI_CONFIG, config); 289 saa7146_write(saa, DEBI_CONFIG, config);
@@ -295,15 +291,28 @@ int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr,
295 saa7146_write(saa, DEBI_AD, value); 291 saa7146_write(saa, DEBI_AD, value);
296 saa7146_write(saa, MC2, (2 << 16) | 2); 292 saa7146_write(saa, MC2, (2 << 16) | 2);
297 293
298 if ((result = saa7146_wait_for_debi_done(saa, nobusyloop)) < 0) { 294 result = saa7146_wait_for_debi_done(saa, nobusyloop);
299 if (uselocks) 295 return result < 0 ? result : 0;
300 spin_unlock_irqrestore(&budget->debilock, flags); 296}
301 return result;
302 }
303 297
304 if (uselocks) 298int ttpci_budget_debiwrite(struct budget *budget, u32 config, int addr,
299 int count, u32 value, int uselocks, int nobusyloop)
300{
301 if (count > 4 || count <= 0)
302 return 0;
303
304 if (uselocks) {
305 unsigned long flags;
306 int result;
307
308 spin_lock_irqsave(&budget->debilock, flags);
309 result = ttpci_budget_debiwrite_nolock(budget, config, addr,
310 count, value, nobusyloop);
305 spin_unlock_irqrestore(&budget->debilock, flags); 311 spin_unlock_irqrestore(&budget->debilock, flags);
306 return 0; 312 return result;
313 }
314 return ttpci_budget_debiwrite_nolock(budget, config, addr,
315 count, value, nobusyloop);
307} 316}
308 317
309 318
diff --git a/drivers/media/pci/tw68/tw68.h b/drivers/media/pci/tw68/tw68.h
index 7a7501bd165f..93f2335e004b 100644
--- a/drivers/media/pci/tw68/tw68.h
+++ b/drivers/media/pci/tw68/tw68.h
@@ -25,7 +25,6 @@
25 * GNU General Public License for more details. 25 * GNU General Public License for more details.
26 */ 26 */
27 27
28#include <linux/version.h>
29#include <linux/pci.h> 28#include <linux/pci.h>
30#include <linux/videodev2.h> 29#include <linux/videodev2.h>
31#include <linux/notifier.h> 30#include <linux/notifier.h>
diff --git a/drivers/media/platform/Kconfig b/drivers/media/platform/Kconfig
index 765bffb49a72..d9b872b9285a 100644
--- a/drivers/media/platform/Kconfig
+++ b/drivers/media/platform/Kconfig
@@ -56,10 +56,8 @@ config VIDEO_VIU
56 56
57config VIDEO_TIMBERDALE 57config VIDEO_TIMBERDALE
58 tristate "Support for timberdale Video In/LogiWIN" 58 tristate "Support for timberdale Video In/LogiWIN"
59 depends on VIDEO_V4L2 && I2C && DMADEVICES 59 depends on VIDEO_V4L2 && I2C && VIDEO_V4L2_SUBDEV_API
60 depends on MFD_TIMBERDALE || COMPILE_TEST 60 depends on (MFD_TIMBERDALE && TIMB_DMA) || COMPILE_TEST
61 select DMA_ENGINE
62 select TIMB_DMA
63 select VIDEO_ADV7180 61 select VIDEO_ADV7180
64 select VIDEOBUF_DMA_CONTIG 62 select VIDEOBUF_DMA_CONTIG
65 ---help--- 63 ---help---
@@ -118,6 +116,7 @@ config VIDEO_S3C_CAMIF
118source "drivers/media/platform/soc_camera/Kconfig" 116source "drivers/media/platform/soc_camera/Kconfig"
119source "drivers/media/platform/exynos4-is/Kconfig" 117source "drivers/media/platform/exynos4-is/Kconfig"
120source "drivers/media/platform/s5p-tv/Kconfig" 118source "drivers/media/platform/s5p-tv/Kconfig"
119source "drivers/media/platform/am437x/Kconfig"
121 120
122endif # V4L_PLATFORM_DRIVERS 121endif # V4L_PLATFORM_DRIVERS
123 122
@@ -140,6 +139,7 @@ config VIDEO_CODA
140 depends on HAS_DMA 139 depends on HAS_DMA
141 select SRAM 140 select SRAM
142 select VIDEOBUF2_DMA_CONTIG 141 select VIDEOBUF2_DMA_CONTIG
142 select VIDEOBUF2_VMALLOC
143 select V4L2_MEM2MEM_DEV 143 select V4L2_MEM2MEM_DEV
144 select GENERIC_ALLOCATOR 144 select GENERIC_ALLOCATOR
145 ---help--- 145 ---help---
@@ -213,7 +213,6 @@ config VIDEO_SAMSUNG_EXYNOS_GSC
213config VIDEO_SH_VEU 213config VIDEO_SH_VEU
214 tristate "SuperH VEU mem2mem video processing driver" 214 tristate "SuperH VEU mem2mem video processing driver"
215 depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA 215 depends on VIDEO_DEV && VIDEO_V4L2 && HAS_DMA
216 depends on HAS_DMA
217 select VIDEOBUF2_DMA_CONTIG 216 select VIDEOBUF2_DMA_CONTIG
218 select V4L2_MEM2MEM_DEV 217 select V4L2_MEM2MEM_DEV
219 help 218 help
@@ -223,7 +222,7 @@ config VIDEO_SH_VEU
223config VIDEO_RENESAS_VSP1 222config VIDEO_RENESAS_VSP1
224 tristate "Renesas VSP1 Video Processing Engine" 223 tristate "Renesas VSP1 Video Processing Engine"
225 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && HAS_DMA 224 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API && HAS_DMA
226 depends on ARCH_SHMOBILE || COMPILE_TEST 225 depends on (ARCH_SHMOBILE && OF) || COMPILE_TEST
227 select VIDEOBUF2_DMA_CONTIG 226 select VIDEOBUF2_DMA_CONTIG
228 ---help--- 227 ---help---
229 This is a V4L2 driver for the Renesas VSP1 video processing engine. 228 This is a V4L2 driver for the Renesas VSP1 video processing engine.
diff --git a/drivers/media/platform/Makefile b/drivers/media/platform/Makefile
index a49936b8ce8a..3ec154742083 100644
--- a/drivers/media/platform/Makefile
+++ b/drivers/media/platform/Makefile
@@ -46,4 +46,6 @@ obj-$(CONFIG_VIDEO_RENESAS_VSP1) += vsp1/
46 46
47obj-y += omap/ 47obj-y += omap/
48 48
49obj-$(CONFIG_VIDEO_AM437X_VPFE) += am437x/
50
49ccflags-y += -I$(srctree)/drivers/media/i2c 51ccflags-y += -I$(srctree)/drivers/media/i2c
diff --git a/drivers/media/platform/am437x/Kconfig b/drivers/media/platform/am437x/Kconfig
new file mode 100644
index 000000000000..7b023a76e32e
--- /dev/null
+++ b/drivers/media/platform/am437x/Kconfig
@@ -0,0 +1,11 @@
1config VIDEO_AM437X_VPFE
2 tristate "TI AM437x VPFE video capture driver"
3 depends on VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
4 depends on SOC_AM43XX || COMPILE_TEST
5 select VIDEOBUF2_DMA_CONTIG
6 help
7 Support for AM437x Video Processing Front End based Video
8 Capture Driver.
9
10 To compile this driver as a module, choose M here. The module
11 will be called am437x-vpfe.
diff --git a/drivers/media/platform/am437x/Makefile b/drivers/media/platform/am437x/Makefile
new file mode 100644
index 000000000000..d11fff16f260
--- /dev/null
+++ b/drivers/media/platform/am437x/Makefile
@@ -0,0 +1,3 @@
1# Makefile for AM437x VPFE driver
2
3obj-$(CONFIG_VIDEO_AM437X_VPFE) += am437x-vpfe.o
diff --git a/drivers/media/platform/am437x/am437x-vpfe.c b/drivers/media/platform/am437x/am437x-vpfe.c
new file mode 100644
index 000000000000..56a5cb0d2152
--- /dev/null
+++ b/drivers/media/platform/am437x/am437x-vpfe.c
@@ -0,0 +1,2776 @@
1/*
2 * TI VPFE capture Driver
3 *
4 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
5 *
6 * Benoit Parrot <bparrot@ti.com>
7 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
8 *
9 * This program is free software; you may redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
12 *
13 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
14 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
15 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
16 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
17 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
18 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
19 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23#include <linux/delay.h>
24#include <linux/err.h>
25#include <linux/init.h>
26#include <linux/interrupt.h>
27#include <linux/io.h>
28#include <linux/module.h>
29#include <linux/pinctrl/consumer.h>
30#include <linux/platform_device.h>
31#include <linux/pm_runtime.h>
32#include <linux/slab.h>
33#include <linux/uaccess.h>
34#include <linux/videodev2.h>
35
36#include <media/v4l2-common.h>
37#include <media/v4l2-ctrls.h>
38#include <media/v4l2-event.h>
39#include <media/v4l2-of.h>
40
41#include "am437x-vpfe.h"
42
43#define VPFE_MODULE_NAME "vpfe"
44#define VPFE_VERSION "0.1.0"
45
46static int debug;
47module_param(debug, int, 0644);
48MODULE_PARM_DESC(debug, "Debug level 0-8");
49
50#define vpfe_dbg(level, dev, fmt, arg...) \
51 v4l2_dbg(level, debug, &dev->v4l2_dev, fmt, ##arg)
52#define vpfe_info(dev, fmt, arg...) \
53 v4l2_info(&dev->v4l2_dev, fmt, ##arg)
54#define vpfe_err(dev, fmt, arg...) \
55 v4l2_err(&dev->v4l2_dev, fmt, ##arg)
56
57/* standard information */
58struct vpfe_standard {
59 v4l2_std_id std_id;
60 unsigned int width;
61 unsigned int height;
62 struct v4l2_fract pixelaspect;
63 int frame_format;
64};
65
66static const struct vpfe_standard vpfe_standards[] = {
67 {V4L2_STD_525_60, 720, 480, {11, 10}, 1},
68 {V4L2_STD_625_50, 720, 576, {54, 59}, 1},
69};
70
71struct bus_format {
72 unsigned int width;
73 unsigned int bpp;
74};
75
76/*
77 * struct vpfe_fmt - VPFE media bus format information
78 * @name: V4L2 format description
79 * @code: V4L2 media bus format code
80 * @shifted: V4L2 media bus format code for the same pixel layout but
81 * shifted to be 8 bits per pixel. =0 if format is not shiftable.
82 * @pixelformat: V4L2 pixel format FCC identifier
83 * @width: Bits per pixel (when transferred over a bus)
84 * @bpp: Bytes per pixel (when stored in memory)
85 * @supported: Indicates format supported by subdev
86 */
87struct vpfe_fmt {
88 const char *name;
89 u32 fourcc;
90 u32 code;
91 struct bus_format l;
92 struct bus_format s;
93 bool supported;
94 u32 index;
95};
96
97static struct vpfe_fmt formats[] = {
98 {
99 .name = "YUV 4:2:2 packed, YCbYCr",
100 .fourcc = V4L2_PIX_FMT_YUYV,
101 .code = MEDIA_BUS_FMT_YUYV8_2X8,
102 .l.width = 10,
103 .l.bpp = 4,
104 .s.width = 8,
105 .s.bpp = 2,
106 .supported = false,
107 }, {
108 .name = "YUV 4:2:2 packed, CbYCrY",
109 .fourcc = V4L2_PIX_FMT_UYVY,
110 .code = MEDIA_BUS_FMT_UYVY8_2X8,
111 .l.width = 10,
112 .l.bpp = 4,
113 .s.width = 8,
114 .s.bpp = 2,
115 .supported = false,
116 }, {
117 .name = "YUV 4:2:2 packed, YCrYCb",
118 .fourcc = V4L2_PIX_FMT_YVYU,
119 .code = MEDIA_BUS_FMT_YVYU8_2X8,
120 .l.width = 10,
121 .l.bpp = 4,
122 .s.width = 8,
123 .s.bpp = 2,
124 .supported = false,
125 }, {
126 .name = "YUV 4:2:2 packed, CrYCbY",
127 .fourcc = V4L2_PIX_FMT_VYUY,
128 .code = MEDIA_BUS_FMT_VYUY8_2X8,
129 .l.width = 10,
130 .l.bpp = 4,
131 .s.width = 8,
132 .s.bpp = 2,
133 .supported = false,
134 }, {
135 .name = "RAW8 BGGR",
136 .fourcc = V4L2_PIX_FMT_SBGGR8,
137 .code = MEDIA_BUS_FMT_SBGGR8_1X8,
138 .l.width = 10,
139 .l.bpp = 2,
140 .s.width = 8,
141 .s.bpp = 1,
142 .supported = false,
143 }, {
144 .name = "RAW8 GBRG",
145 .fourcc = V4L2_PIX_FMT_SGBRG8,
146 .code = MEDIA_BUS_FMT_SGBRG8_1X8,
147 .l.width = 10,
148 .l.bpp = 2,
149 .s.width = 8,
150 .s.bpp = 1,
151 .supported = false,
152 }, {
153 .name = "RAW8 GRBG",
154 .fourcc = V4L2_PIX_FMT_SGRBG8,
155 .code = MEDIA_BUS_FMT_SGRBG8_1X8,
156 .l.width = 10,
157 .l.bpp = 2,
158 .s.width = 8,
159 .s.bpp = 1,
160 .supported = false,
161 }, {
162 .name = "RAW8 RGGB",
163 .fourcc = V4L2_PIX_FMT_SRGGB8,
164 .code = MEDIA_BUS_FMT_SRGGB8_1X8,
165 .l.width = 10,
166 .l.bpp = 2,
167 .s.width = 8,
168 .s.bpp = 1,
169 .supported = false,
170 }, {
171 .name = "RGB565 (LE)",
172 .fourcc = V4L2_PIX_FMT_RGB565,
173 .code = MEDIA_BUS_FMT_RGB565_2X8_LE,
174 .l.width = 10,
175 .l.bpp = 4,
176 .s.width = 8,
177 .s.bpp = 2,
178 .supported = false,
179 }, {
180 .name = "RGB565 (BE)",
181 .fourcc = V4L2_PIX_FMT_RGB565X,
182 .code = MEDIA_BUS_FMT_RGB565_2X8_BE,
183 .l.width = 10,
184 .l.bpp = 4,
185 .s.width = 8,
186 .s.bpp = 2,
187 .supported = false,
188 },
189};
190
191static int
192__vpfe_get_format(struct vpfe_device *vpfe,
193 struct v4l2_format *format, unsigned int *bpp);
194
195static struct vpfe_fmt *find_format_by_code(unsigned int code)
196{
197 struct vpfe_fmt *fmt;
198 unsigned int k;
199
200 for (k = 0; k < ARRAY_SIZE(formats); k++) {
201 fmt = &formats[k];
202 if (fmt->code == code)
203 return fmt;
204 }
205
206 return NULL;
207}
208
209static struct vpfe_fmt *find_format_by_pix(unsigned int pixelformat)
210{
211 struct vpfe_fmt *fmt;
212 unsigned int k;
213
214 for (k = 0; k < ARRAY_SIZE(formats); k++) {
215 fmt = &formats[k];
216 if (fmt->fourcc == pixelformat)
217 return fmt;
218 }
219
220 return NULL;
221}
222
223static void
224mbus_to_pix(struct vpfe_device *vpfe,
225 const struct v4l2_mbus_framefmt *mbus,
226 struct v4l2_pix_format *pix, unsigned int *bpp)
227{
228 struct vpfe_subdev_info *sdinfo = vpfe->current_subdev;
229 unsigned int bus_width = sdinfo->vpfe_param.bus_width;
230 struct vpfe_fmt *fmt;
231
232 fmt = find_format_by_code(mbus->code);
233 if (WARN_ON(fmt == NULL)) {
234 pr_err("Invalid mbus code set\n");
235 *bpp = 1;
236 return;
237 }
238
239 memset(pix, 0, sizeof(*pix));
240 v4l2_fill_pix_format(pix, mbus);
241 pix->pixelformat = fmt->fourcc;
242 *bpp = (bus_width == 10) ? fmt->l.bpp : fmt->s.bpp;
243
244 /* pitch should be 32 bytes aligned */
245 pix->bytesperline = ALIGN(pix->width * *bpp, 32);
246 pix->sizeimage = pix->bytesperline * pix->height;
247}
248
249static void pix_to_mbus(struct vpfe_device *vpfe,
250 struct v4l2_pix_format *pix_fmt,
251 struct v4l2_mbus_framefmt *mbus_fmt)
252{
253 struct vpfe_fmt *fmt;
254
255 fmt = find_format_by_pix(pix_fmt->pixelformat);
256 if (!fmt) {
257 /* default to first entry */
258 vpfe_dbg(3, vpfe, "Invalid pixel code: %x, default used instead\n",
259 pix_fmt->pixelformat);
260 fmt = &formats[0];
261 }
262
263 memset(mbus_fmt, 0, sizeof(*mbus_fmt));
264 v4l2_fill_mbus_format(mbus_fmt, pix_fmt, fmt->code);
265}
266
267/* Print Four-character-code (FOURCC) */
268static char *print_fourcc(u32 fmt)
269{
270 static char code[5];
271
272 code[0] = (unsigned char)(fmt & 0xff);
273 code[1] = (unsigned char)((fmt >> 8) & 0xff);
274 code[2] = (unsigned char)((fmt >> 16) & 0xff);
275 code[3] = (unsigned char)((fmt >> 24) & 0xff);
276 code[4] = '\0';
277
278 return code;
279}
280
281static int
282cmp_v4l2_format(const struct v4l2_format *lhs, const struct v4l2_format *rhs)
283{
284 return lhs->type == rhs->type &&
285 lhs->fmt.pix.width == rhs->fmt.pix.width &&
286 lhs->fmt.pix.height == rhs->fmt.pix.height &&
287 lhs->fmt.pix.pixelformat == rhs->fmt.pix.pixelformat &&
288 lhs->fmt.pix.field == rhs->fmt.pix.field &&
289 lhs->fmt.pix.colorspace == rhs->fmt.pix.colorspace &&
290 lhs->fmt.pix.ycbcr_enc == rhs->fmt.pix.ycbcr_enc &&
291 lhs->fmt.pix.quantization == rhs->fmt.pix.quantization;
292}
293
294static inline u32 vpfe_reg_read(struct vpfe_ccdc *ccdc, u32 offset)
295{
296 return ioread32(ccdc->ccdc_cfg.base_addr + offset);
297}
298
299static inline void vpfe_reg_write(struct vpfe_ccdc *ccdc, u32 val, u32 offset)
300{
301 iowrite32(val, ccdc->ccdc_cfg.base_addr + offset);
302}
303
304static inline struct vpfe_device *to_vpfe(struct vpfe_ccdc *ccdc)
305{
306 return container_of(ccdc, struct vpfe_device, ccdc);
307}
308
309static inline struct vpfe_cap_buffer *to_vpfe_buffer(struct vb2_buffer *vb)
310{
311 return container_of(vb, struct vpfe_cap_buffer, vb);
312}
313
314static inline void vpfe_pcr_enable(struct vpfe_ccdc *ccdc, int flag)
315{
316 vpfe_reg_write(ccdc, !!flag, VPFE_PCR);
317}
318
319static void vpfe_config_enable(struct vpfe_ccdc *ccdc, int flag)
320{
321 unsigned int cfg;
322
323 if (!flag) {
324 cfg = vpfe_reg_read(ccdc, VPFE_CONFIG);
325 cfg &= ~(VPFE_CONFIG_EN_ENABLE << VPFE_CONFIG_EN_SHIFT);
326 } else {
327 cfg = VPFE_CONFIG_EN_ENABLE << VPFE_CONFIG_EN_SHIFT;
328 }
329
330 vpfe_reg_write(ccdc, cfg, VPFE_CONFIG);
331}
332
333static void vpfe_ccdc_setwin(struct vpfe_ccdc *ccdc,
334 struct v4l2_rect *image_win,
335 enum ccdc_frmfmt frm_fmt,
336 int bpp)
337{
338 int horz_start, horz_nr_pixels;
339 int vert_start, vert_nr_lines;
340 int val, mid_img;
341
342 /*
343 * ppc - per pixel count. indicates how many pixels per cell
344 * output to SDRAM. example, for ycbcr, it is one y and one c, so 2.
345 * raw capture this is 1
346 */
347 horz_start = image_win->left * bpp;
348 horz_nr_pixels = (image_win->width * bpp) - 1;
349 vpfe_reg_write(ccdc, (horz_start << VPFE_HORZ_INFO_SPH_SHIFT) |
350 horz_nr_pixels, VPFE_HORZ_INFO);
351
352 vert_start = image_win->top;
353
354 if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
355 vert_nr_lines = (image_win->height >> 1) - 1;
356 vert_start >>= 1;
357 /* Since first line doesn't have any data */
358 vert_start += 1;
359 /* configure VDINT0 */
360 val = (vert_start << VPFE_VDINT_VDINT0_SHIFT);
361 } else {
362 /* Since first line doesn't have any data */
363 vert_start += 1;
364 vert_nr_lines = image_win->height - 1;
365 /*
366 * configure VDINT0 and VDINT1. VDINT1 will be at half
367 * of image height
368 */
369 mid_img = vert_start + (image_win->height / 2);
370 val = (vert_start << VPFE_VDINT_VDINT0_SHIFT) |
371 (mid_img & VPFE_VDINT_VDINT1_MASK);
372 }
373
374 vpfe_reg_write(ccdc, val, VPFE_VDINT);
375
376 vpfe_reg_write(ccdc, (vert_start << VPFE_VERT_START_SLV0_SHIFT) |
377 vert_start, VPFE_VERT_START);
378 vpfe_reg_write(ccdc, vert_nr_lines, VPFE_VERT_LINES);
379}
380
381static void vpfe_reg_dump(struct vpfe_ccdc *ccdc)
382{
383 struct vpfe_device *vpfe = to_vpfe(ccdc);
384
385 vpfe_dbg(3, vpfe, "ALAW: 0x%x\n", vpfe_reg_read(ccdc, VPFE_ALAW));
386 vpfe_dbg(3, vpfe, "CLAMP: 0x%x\n", vpfe_reg_read(ccdc, VPFE_CLAMP));
387 vpfe_dbg(3, vpfe, "DCSUB: 0x%x\n", vpfe_reg_read(ccdc, VPFE_DCSUB));
388 vpfe_dbg(3, vpfe, "BLKCMP: 0x%x\n", vpfe_reg_read(ccdc, VPFE_BLKCMP));
389 vpfe_dbg(3, vpfe, "COLPTN: 0x%x\n", vpfe_reg_read(ccdc, VPFE_COLPTN));
390 vpfe_dbg(3, vpfe, "SDOFST: 0x%x\n", vpfe_reg_read(ccdc, VPFE_SDOFST));
391 vpfe_dbg(3, vpfe, "SYN_MODE: 0x%x\n",
392 vpfe_reg_read(ccdc, VPFE_SYNMODE));
393 vpfe_dbg(3, vpfe, "HSIZE_OFF: 0x%x\n",
394 vpfe_reg_read(ccdc, VPFE_HSIZE_OFF));
395 vpfe_dbg(3, vpfe, "HORZ_INFO: 0x%x\n",
396 vpfe_reg_read(ccdc, VPFE_HORZ_INFO));
397 vpfe_dbg(3, vpfe, "VERT_START: 0x%x\n",
398 vpfe_reg_read(ccdc, VPFE_VERT_START));
399 vpfe_dbg(3, vpfe, "VERT_LINES: 0x%x\n",
400 vpfe_reg_read(ccdc, VPFE_VERT_LINES));
401}
402
403static int
404vpfe_ccdc_validate_param(struct vpfe_ccdc *ccdc,
405 struct vpfe_ccdc_config_params_raw *ccdcparam)
406{
407 struct vpfe_device *vpfe = to_vpfe(ccdc);
408 u8 max_gamma, max_data;
409
410 if (!ccdcparam->alaw.enable)
411 return 0;
412
413 max_gamma = ccdc_gamma_width_max_bit(ccdcparam->alaw.gamma_wd);
414 max_data = ccdc_data_size_max_bit(ccdcparam->data_sz);
415
416 if (ccdcparam->alaw.gamma_wd > VPFE_CCDC_GAMMA_BITS_09_0 ||
417 ccdcparam->alaw.gamma_wd < VPFE_CCDC_GAMMA_BITS_15_6 ||
418 max_gamma > max_data) {
419 vpfe_dbg(1, vpfe, "Invalid data line select\n");
420 return -EINVAL;
421 }
422
423 return 0;
424}
425
426static void
427vpfe_ccdc_update_raw_params(struct vpfe_ccdc *ccdc,
428 struct vpfe_ccdc_config_params_raw *raw_params)
429{
430 struct vpfe_ccdc_config_params_raw *config_params =
431 &ccdc->ccdc_cfg.bayer.config_params;
432
433 config_params = raw_params;
434}
435
436/*
437 * vpfe_ccdc_restore_defaults()
438 * This function will write defaults to all CCDC registers
439 */
440static void vpfe_ccdc_restore_defaults(struct vpfe_ccdc *ccdc)
441{
442 int i;
443
444 /* Disable CCDC */
445 vpfe_pcr_enable(ccdc, 0);
446
447 /* set all registers to default value */
448 for (i = 4; i <= 0x94; i += 4)
449 vpfe_reg_write(ccdc, 0, i);
450
451 vpfe_reg_write(ccdc, VPFE_NO_CULLING, VPFE_CULLING);
452 vpfe_reg_write(ccdc, VPFE_CCDC_GAMMA_BITS_11_2, VPFE_ALAW);
453}
454
455static int vpfe_ccdc_close(struct vpfe_ccdc *ccdc, struct device *dev)
456{
457 int dma_cntl, i, pcr;
458
459 /* If the CCDC module is still busy wait for it to be done */
460 for (i = 0; i < 10; i++) {
461 usleep_range(5000, 6000);
462 pcr = vpfe_reg_read(ccdc, VPFE_PCR);
463 if (!pcr)
464 break;
465
466 /* make sure it it is disabled */
467 vpfe_pcr_enable(ccdc, 0);
468 }
469
470 /* Disable CCDC by resetting all register to default POR values */
471 vpfe_ccdc_restore_defaults(ccdc);
472
473 /* if DMA_CNTL overflow bit is set. Clear it
474 * It appears to take a while for this to become quiescent ~20ms
475 */
476 for (i = 0; i < 10; i++) {
477 dma_cntl = vpfe_reg_read(ccdc, VPFE_DMA_CNTL);
478 if (!(dma_cntl & VPFE_DMA_CNTL_OVERFLOW))
479 break;
480
481 /* Clear the overflow bit */
482 vpfe_reg_write(ccdc, dma_cntl, VPFE_DMA_CNTL);
483 usleep_range(5000, 6000);
484 }
485
486 /* Disabled the module at the CONFIG level */
487 vpfe_config_enable(ccdc, 0);
488
489 pm_runtime_put_sync(dev);
490
491 return 0;
492}
493
494static int vpfe_ccdc_set_params(struct vpfe_ccdc *ccdc, void __user *params)
495{
496 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
497 struct vpfe_ccdc_config_params_raw raw_params;
498 int x;
499
500 if (ccdc->ccdc_cfg.if_type != VPFE_RAW_BAYER)
501 return -EINVAL;
502
503 x = copy_from_user(&raw_params, params, sizeof(raw_params));
504 if (x) {
505 vpfe_dbg(1, vpfe,
506 "vpfe_ccdc_set_params: error in copying ccdc params, %d\n",
507 x);
508 return -EFAULT;
509 }
510
511 if (!vpfe_ccdc_validate_param(ccdc, &raw_params)) {
512 vpfe_ccdc_update_raw_params(ccdc, &raw_params);
513 return 0;
514 }
515
516 return -EINVAL;
517}
518
519/*
520 * vpfe_ccdc_config_ycbcr()
521 * This function will configure CCDC for YCbCr video capture
522 */
523static void vpfe_ccdc_config_ycbcr(struct vpfe_ccdc *ccdc)
524{
525 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
526 struct ccdc_params_ycbcr *params = &ccdc->ccdc_cfg.ycbcr;
527 u32 syn_mode;
528
529 vpfe_dbg(3, vpfe, "vpfe_ccdc_config_ycbcr:\n");
530 /*
531 * first restore the CCDC registers to default values
532 * This is important since we assume default values to be set in
533 * a lot of registers that we didn't touch
534 */
535 vpfe_ccdc_restore_defaults(ccdc);
536
537 /*
538 * configure pixel format, frame format, configure video frame
539 * format, enable output to SDRAM, enable internal timing generator
540 * and 8bit pack mode
541 */
542 syn_mode = (((params->pix_fmt & VPFE_SYN_MODE_INPMOD_MASK) <<
543 VPFE_SYN_MODE_INPMOD_SHIFT) |
544 ((params->frm_fmt & VPFE_SYN_FLDMODE_MASK) <<
545 VPFE_SYN_FLDMODE_SHIFT) | VPFE_VDHDEN_ENABLE |
546 VPFE_WEN_ENABLE | VPFE_DATA_PACK_ENABLE);
547
548 /* setup BT.656 sync mode */
549 if (params->bt656_enable) {
550 vpfe_reg_write(ccdc, VPFE_REC656IF_BT656_EN, VPFE_REC656IF);
551
552 /*
553 * configure the FID, VD, HD pin polarity,
554 * fld,hd pol positive, vd negative, 8-bit data
555 */
556 syn_mode |= VPFE_SYN_MODE_VD_POL_NEGATIVE;
557 if (ccdc->ccdc_cfg.if_type == VPFE_BT656_10BIT)
558 syn_mode |= VPFE_SYN_MODE_10BITS;
559 else
560 syn_mode |= VPFE_SYN_MODE_8BITS;
561 } else {
562 /* y/c external sync mode */
563 syn_mode |= (((params->fid_pol & VPFE_FID_POL_MASK) <<
564 VPFE_FID_POL_SHIFT) |
565 ((params->hd_pol & VPFE_HD_POL_MASK) <<
566 VPFE_HD_POL_SHIFT) |
567 ((params->vd_pol & VPFE_VD_POL_MASK) <<
568 VPFE_VD_POL_SHIFT));
569 }
570 vpfe_reg_write(ccdc, syn_mode, VPFE_SYNMODE);
571
572 /* configure video window */
573 vpfe_ccdc_setwin(ccdc, &params->win,
574 params->frm_fmt, params->bytesperpixel);
575
576 /*
577 * configure the order of y cb cr in SDRAM, and disable latch
578 * internal register on vsync
579 */
580 if (ccdc->ccdc_cfg.if_type == VPFE_BT656_10BIT)
581 vpfe_reg_write(ccdc,
582 (params->pix_order << VPFE_CCDCFG_Y8POS_SHIFT) |
583 VPFE_LATCH_ON_VSYNC_DISABLE |
584 VPFE_CCDCFG_BW656_10BIT, VPFE_CCDCFG);
585 else
586 vpfe_reg_write(ccdc,
587 (params->pix_order << VPFE_CCDCFG_Y8POS_SHIFT) |
588 VPFE_LATCH_ON_VSYNC_DISABLE, VPFE_CCDCFG);
589
590 /*
591 * configure the horizontal line offset. This should be a
592 * on 32 byte boundary. So clear LSB 5 bits
593 */
594 vpfe_reg_write(ccdc, params->bytesperline, VPFE_HSIZE_OFF);
595
596 /* configure the memory line offset */
597 if (params->buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED)
598 /* two fields are interleaved in memory */
599 vpfe_reg_write(ccdc, VPFE_SDOFST_FIELD_INTERLEAVED,
600 VPFE_SDOFST);
601}
602
603static void
604vpfe_ccdc_config_black_clamp(struct vpfe_ccdc *ccdc,
605 struct vpfe_ccdc_black_clamp *bclamp)
606{
607 u32 val;
608
609 if (!bclamp->enable) {
610 /* configure DCSub */
611 val = (bclamp->dc_sub) & VPFE_BLK_DC_SUB_MASK;
612 vpfe_reg_write(ccdc, val, VPFE_DCSUB);
613 vpfe_reg_write(ccdc, VPFE_CLAMP_DEFAULT_VAL, VPFE_CLAMP);
614 return;
615 }
616 /*
617 * Configure gain, Start pixel, No of line to be avg,
618 * No of pixel/line to be avg, & Enable the Black clamping
619 */
620 val = ((bclamp->sgain & VPFE_BLK_SGAIN_MASK) |
621 ((bclamp->start_pixel & VPFE_BLK_ST_PXL_MASK) <<
622 VPFE_BLK_ST_PXL_SHIFT) |
623 ((bclamp->sample_ln & VPFE_BLK_SAMPLE_LINE_MASK) <<
624 VPFE_BLK_SAMPLE_LINE_SHIFT) |
625 ((bclamp->sample_pixel & VPFE_BLK_SAMPLE_LN_MASK) <<
626 VPFE_BLK_SAMPLE_LN_SHIFT) | VPFE_BLK_CLAMP_ENABLE);
627 vpfe_reg_write(ccdc, val, VPFE_CLAMP);
628 /* If Black clamping is enable then make dcsub 0 */
629 vpfe_reg_write(ccdc, VPFE_DCSUB_DEFAULT_VAL, VPFE_DCSUB);
630}
631
632static void
633vpfe_ccdc_config_black_compense(struct vpfe_ccdc *ccdc,
634 struct vpfe_ccdc_black_compensation *bcomp)
635{
636 u32 val;
637
638 val = ((bcomp->b & VPFE_BLK_COMP_MASK) |
639 ((bcomp->gb & VPFE_BLK_COMP_MASK) <<
640 VPFE_BLK_COMP_GB_COMP_SHIFT) |
641 ((bcomp->gr & VPFE_BLK_COMP_MASK) <<
642 VPFE_BLK_COMP_GR_COMP_SHIFT) |
643 ((bcomp->r & VPFE_BLK_COMP_MASK) <<
644 VPFE_BLK_COMP_R_COMP_SHIFT));
645 vpfe_reg_write(ccdc, val, VPFE_BLKCMP);
646}
647
648/*
649 * vpfe_ccdc_config_raw()
650 * This function will configure CCDC for Raw capture mode
651 */
652static void vpfe_ccdc_config_raw(struct vpfe_ccdc *ccdc)
653{
654 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
655 struct vpfe_ccdc_config_params_raw *config_params =
656 &ccdc->ccdc_cfg.bayer.config_params;
657 struct ccdc_params_raw *params = &ccdc->ccdc_cfg.bayer;
658 unsigned int syn_mode;
659 unsigned int val;
660
661 vpfe_dbg(3, vpfe, "vpfe_ccdc_config_raw:\n");
662
663 /* Reset CCDC */
664 vpfe_ccdc_restore_defaults(ccdc);
665
666 /* Disable latching function registers on VSYNC */
667 vpfe_reg_write(ccdc, VPFE_LATCH_ON_VSYNC_DISABLE, VPFE_CCDCFG);
668
669 /*
670 * Configure the vertical sync polarity(SYN_MODE.VDPOL),
671 * horizontal sync polarity (SYN_MODE.HDPOL), frame id polarity
672 * (SYN_MODE.FLDPOL), frame format(progressive or interlace),
673 * data size(SYNMODE.DATSIZ), &pixel format (Input mode), output
674 * SDRAM, enable internal timing generator
675 */
676 syn_mode = (((params->vd_pol & VPFE_VD_POL_MASK) << VPFE_VD_POL_SHIFT) |
677 ((params->hd_pol & VPFE_HD_POL_MASK) << VPFE_HD_POL_SHIFT) |
678 ((params->fid_pol & VPFE_FID_POL_MASK) <<
679 VPFE_FID_POL_SHIFT) | ((params->frm_fmt &
680 VPFE_FRM_FMT_MASK) << VPFE_FRM_FMT_SHIFT) |
681 ((config_params->data_sz & VPFE_DATA_SZ_MASK) <<
682 VPFE_DATA_SZ_SHIFT) | ((params->pix_fmt &
683 VPFE_PIX_FMT_MASK) << VPFE_PIX_FMT_SHIFT) |
684 VPFE_WEN_ENABLE | VPFE_VDHDEN_ENABLE);
685
686 /* Enable and configure aLaw register if needed */
687 if (config_params->alaw.enable) {
688 val = ((config_params->alaw.gamma_wd &
689 VPFE_ALAW_GAMMA_WD_MASK) | VPFE_ALAW_ENABLE);
690 vpfe_reg_write(ccdc, val, VPFE_ALAW);
691 vpfe_dbg(3, vpfe, "\nWriting 0x%x to ALAW...\n", val);
692 }
693
694 /* Configure video window */
695 vpfe_ccdc_setwin(ccdc, &params->win, params->frm_fmt,
696 params->bytesperpixel);
697
698 /* Configure Black Clamp */
699 vpfe_ccdc_config_black_clamp(ccdc, &config_params->blk_clamp);
700
701 /* Configure Black level compensation */
702 vpfe_ccdc_config_black_compense(ccdc, &config_params->blk_comp);
703
704 /* If data size is 8 bit then pack the data */
705 if ((config_params->data_sz == VPFE_CCDC_DATA_8BITS) ||
706 config_params->alaw.enable)
707 syn_mode |= VPFE_DATA_PACK_ENABLE;
708
709 /*
710 * Configure Horizontal offset register. If pack 8 is enabled then
711 * 1 pixel will take 1 byte
712 */
713 vpfe_reg_write(ccdc, params->bytesperline, VPFE_HSIZE_OFF);
714
715 vpfe_dbg(3, vpfe, "Writing %d (%x) to HSIZE_OFF\n",
716 params->bytesperline, params->bytesperline);
717
718 /* Set value for SDOFST */
719 if (params->frm_fmt == CCDC_FRMFMT_INTERLACED) {
720 if (params->image_invert_enable) {
721 /* For interlace inverse mode */
722 vpfe_reg_write(ccdc, VPFE_INTERLACED_IMAGE_INVERT,
723 VPFE_SDOFST);
724 } else {
725 /* For interlace non inverse mode */
726 vpfe_reg_write(ccdc, VPFE_INTERLACED_NO_IMAGE_INVERT,
727 VPFE_SDOFST);
728 }
729 } else if (params->frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
730 vpfe_reg_write(ccdc, VPFE_PROGRESSIVE_NO_IMAGE_INVERT,
731 VPFE_SDOFST);
732 }
733
734 vpfe_reg_write(ccdc, syn_mode, VPFE_SYNMODE);
735
736 vpfe_reg_dump(ccdc);
737}
738
739static inline int
740vpfe_ccdc_set_buftype(struct vpfe_ccdc *ccdc,
741 enum ccdc_buftype buf_type)
742{
743 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
744 ccdc->ccdc_cfg.bayer.buf_type = buf_type;
745 else
746 ccdc->ccdc_cfg.ycbcr.buf_type = buf_type;
747
748 return 0;
749}
750
751static inline enum ccdc_buftype vpfe_ccdc_get_buftype(struct vpfe_ccdc *ccdc)
752{
753 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
754 return ccdc->ccdc_cfg.bayer.buf_type;
755
756 return ccdc->ccdc_cfg.ycbcr.buf_type;
757}
758
759static int vpfe_ccdc_set_pixel_format(struct vpfe_ccdc *ccdc, u32 pixfmt)
760{
761 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
762
763 vpfe_dbg(1, vpfe, "vpfe_ccdc_set_pixel_format: if_type: %d, pixfmt:%s\n",
764 ccdc->ccdc_cfg.if_type, print_fourcc(pixfmt));
765
766 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
767 ccdc->ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
768 /*
769 * Need to clear it in case it was left on
770 * after the last capture.
771 */
772 ccdc->ccdc_cfg.bayer.config_params.alaw.enable = 0;
773
774 switch (pixfmt) {
775 case V4L2_PIX_FMT_SBGGR8:
776 ccdc->ccdc_cfg.bayer.config_params.alaw.enable = 1;
777 break;
778
779 case V4L2_PIX_FMT_YUYV:
780 case V4L2_PIX_FMT_UYVY:
781 case V4L2_PIX_FMT_YUV420:
782 case V4L2_PIX_FMT_NV12:
783 case V4L2_PIX_FMT_RGB565X:
784 break;
785
786 case V4L2_PIX_FMT_SBGGR16:
787 default:
788 return -EINVAL;
789 }
790 } else {
791 switch (pixfmt) {
792 case V4L2_PIX_FMT_YUYV:
793 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_YCBYCR;
794 break;
795
796 case V4L2_PIX_FMT_UYVY:
797 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
798 break;
799
800 default:
801 return -EINVAL;
802 }
803 }
804
805 return 0;
806}
807
808static u32 vpfe_ccdc_get_pixel_format(struct vpfe_ccdc *ccdc)
809{
810 u32 pixfmt;
811
812 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
813 pixfmt = V4L2_PIX_FMT_YUYV;
814 } else {
815 if (ccdc->ccdc_cfg.ycbcr.pix_order == CCDC_PIXORDER_YCBYCR)
816 pixfmt = V4L2_PIX_FMT_YUYV;
817 else
818 pixfmt = V4L2_PIX_FMT_UYVY;
819 }
820
821 return pixfmt;
822}
823
824static int
825vpfe_ccdc_set_image_window(struct vpfe_ccdc *ccdc,
826 struct v4l2_rect *win, unsigned int bpp)
827{
828 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER) {
829 ccdc->ccdc_cfg.bayer.win = *win;
830 ccdc->ccdc_cfg.bayer.bytesperpixel = bpp;
831 ccdc->ccdc_cfg.bayer.bytesperline = ALIGN(win->width * bpp, 32);
832 } else {
833 ccdc->ccdc_cfg.ycbcr.win = *win;
834 ccdc->ccdc_cfg.ycbcr.bytesperpixel = bpp;
835 ccdc->ccdc_cfg.ycbcr.bytesperline = ALIGN(win->width * bpp, 32);
836 }
837
838 return 0;
839}
840
841static inline void
842vpfe_ccdc_get_image_window(struct vpfe_ccdc *ccdc,
843 struct v4l2_rect *win)
844{
845 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
846 *win = ccdc->ccdc_cfg.bayer.win;
847 else
848 *win = ccdc->ccdc_cfg.ycbcr.win;
849}
850
851static inline unsigned int vpfe_ccdc_get_line_length(struct vpfe_ccdc *ccdc)
852{
853 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
854 return ccdc->ccdc_cfg.bayer.bytesperline;
855
856 return ccdc->ccdc_cfg.ycbcr.bytesperline;
857}
858
859static inline int
860vpfe_ccdc_set_frame_format(struct vpfe_ccdc *ccdc,
861 enum ccdc_frmfmt frm_fmt)
862{
863 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
864 ccdc->ccdc_cfg.bayer.frm_fmt = frm_fmt;
865 else
866 ccdc->ccdc_cfg.ycbcr.frm_fmt = frm_fmt;
867
868 return 0;
869}
870
871static inline enum ccdc_frmfmt
872vpfe_ccdc_get_frame_format(struct vpfe_ccdc *ccdc)
873{
874 if (ccdc->ccdc_cfg.if_type == VPFE_RAW_BAYER)
875 return ccdc->ccdc_cfg.bayer.frm_fmt;
876
877 return ccdc->ccdc_cfg.ycbcr.frm_fmt;
878}
879
880static inline int vpfe_ccdc_getfid(struct vpfe_ccdc *ccdc)
881{
882 return (vpfe_reg_read(ccdc, VPFE_SYNMODE) >> 15) & 1;
883}
884
885static inline void vpfe_set_sdr_addr(struct vpfe_ccdc *ccdc, unsigned long addr)
886{
887 vpfe_reg_write(ccdc, addr & 0xffffffe0, VPFE_SDR_ADDR);
888}
889
890static int vpfe_ccdc_set_hw_if_params(struct vpfe_ccdc *ccdc,
891 struct vpfe_hw_if_param *params)
892{
893 struct vpfe_device *vpfe = container_of(ccdc, struct vpfe_device, ccdc);
894
895 ccdc->ccdc_cfg.if_type = params->if_type;
896
897 switch (params->if_type) {
898 case VPFE_BT656:
899 case VPFE_YCBCR_SYNC_16:
900 case VPFE_YCBCR_SYNC_8:
901 case VPFE_BT656_10BIT:
902 ccdc->ccdc_cfg.ycbcr.vd_pol = params->vdpol;
903 ccdc->ccdc_cfg.ycbcr.hd_pol = params->hdpol;
904 break;
905
906 case VPFE_RAW_BAYER:
907 ccdc->ccdc_cfg.bayer.vd_pol = params->vdpol;
908 ccdc->ccdc_cfg.bayer.hd_pol = params->hdpol;
909 if (params->bus_width == 10)
910 ccdc->ccdc_cfg.bayer.config_params.data_sz =
911 VPFE_CCDC_DATA_10BITS;
912 else
913 ccdc->ccdc_cfg.bayer.config_params.data_sz =
914 VPFE_CCDC_DATA_8BITS;
915 vpfe_dbg(1, vpfe, "params.bus_width: %d\n",
916 params->bus_width);
917 vpfe_dbg(1, vpfe, "config_params.data_sz: %d\n",
918 ccdc->ccdc_cfg.bayer.config_params.data_sz);
919 break;
920
921 default:
922 return -EINVAL;
923 }
924
925 return 0;
926}
927
928static void vpfe_clear_intr(struct vpfe_ccdc *ccdc, int vdint)
929{
930 unsigned int vpfe_int_status;
931
932 vpfe_int_status = vpfe_reg_read(ccdc, VPFE_IRQ_STS);
933
934 switch (vdint) {
935 /* VD0 interrupt */
936 case VPFE_VDINT0:
937 vpfe_int_status &= ~VPFE_VDINT0;
938 vpfe_int_status |= VPFE_VDINT0;
939 break;
940
941 /* VD1 interrupt */
942 case VPFE_VDINT1:
943 vpfe_int_status &= ~VPFE_VDINT1;
944 vpfe_int_status |= VPFE_VDINT1;
945 break;
946
947 /* VD2 interrupt */
948 case VPFE_VDINT2:
949 vpfe_int_status &= ~VPFE_VDINT2;
950 vpfe_int_status |= VPFE_VDINT2;
951 break;
952
953 /* Clear all interrupts */
954 default:
955 vpfe_int_status &= ~(VPFE_VDINT0 |
956 VPFE_VDINT1 |
957 VPFE_VDINT2);
958 vpfe_int_status |= (VPFE_VDINT0 |
959 VPFE_VDINT1 |
960 VPFE_VDINT2);
961 break;
962 }
963 /* Clear specific VDINT from the status register */
964 vpfe_reg_write(ccdc, vpfe_int_status, VPFE_IRQ_STS);
965
966 vpfe_int_status = vpfe_reg_read(ccdc, VPFE_IRQ_STS);
967
968 /* Acknowledge that we are done with all interrupts */
969 vpfe_reg_write(ccdc, 1, VPFE_IRQ_EOI);
970}
971
972static void vpfe_ccdc_config_defaults(struct vpfe_ccdc *ccdc)
973{
974 ccdc->ccdc_cfg.if_type = VPFE_RAW_BAYER;
975
976 ccdc->ccdc_cfg.ycbcr.pix_fmt = CCDC_PIXFMT_YCBCR_8BIT;
977 ccdc->ccdc_cfg.ycbcr.frm_fmt = CCDC_FRMFMT_INTERLACED;
978 ccdc->ccdc_cfg.ycbcr.fid_pol = VPFE_PINPOL_POSITIVE;
979 ccdc->ccdc_cfg.ycbcr.vd_pol = VPFE_PINPOL_POSITIVE;
980 ccdc->ccdc_cfg.ycbcr.hd_pol = VPFE_PINPOL_POSITIVE;
981 ccdc->ccdc_cfg.ycbcr.pix_order = CCDC_PIXORDER_CBYCRY;
982 ccdc->ccdc_cfg.ycbcr.buf_type = CCDC_BUFTYPE_FLD_INTERLEAVED;
983
984 ccdc->ccdc_cfg.ycbcr.win.left = 0;
985 ccdc->ccdc_cfg.ycbcr.win.top = 0;
986 ccdc->ccdc_cfg.ycbcr.win.width = 720;
987 ccdc->ccdc_cfg.ycbcr.win.height = 576;
988 ccdc->ccdc_cfg.ycbcr.bt656_enable = 1;
989
990 ccdc->ccdc_cfg.bayer.pix_fmt = CCDC_PIXFMT_RAW;
991 ccdc->ccdc_cfg.bayer.frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
992 ccdc->ccdc_cfg.bayer.fid_pol = VPFE_PINPOL_POSITIVE;
993 ccdc->ccdc_cfg.bayer.vd_pol = VPFE_PINPOL_POSITIVE;
994 ccdc->ccdc_cfg.bayer.hd_pol = VPFE_PINPOL_POSITIVE;
995
996 ccdc->ccdc_cfg.bayer.win.left = 0;
997 ccdc->ccdc_cfg.bayer.win.top = 0;
998 ccdc->ccdc_cfg.bayer.win.width = 800;
999 ccdc->ccdc_cfg.bayer.win.height = 600;
1000 ccdc->ccdc_cfg.bayer.config_params.data_sz = VPFE_CCDC_DATA_8BITS;
1001 ccdc->ccdc_cfg.bayer.config_params.alaw.gamma_wd =
1002 VPFE_CCDC_GAMMA_BITS_09_0;
1003}
1004
1005/*
1006 * vpfe_get_ccdc_image_format - Get image parameters based on CCDC settings
1007 */
1008static int vpfe_get_ccdc_image_format(struct vpfe_device *vpfe,
1009 struct v4l2_format *f)
1010{
1011 struct v4l2_rect image_win;
1012 enum ccdc_buftype buf_type;
1013 enum ccdc_frmfmt frm_fmt;
1014
1015 memset(f, 0, sizeof(*f));
1016 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1017 vpfe_ccdc_get_image_window(&vpfe->ccdc, &image_win);
1018 f->fmt.pix.width = image_win.width;
1019 f->fmt.pix.height = image_win.height;
1020 f->fmt.pix.bytesperline = vpfe_ccdc_get_line_length(&vpfe->ccdc);
1021 f->fmt.pix.sizeimage = f->fmt.pix.bytesperline *
1022 f->fmt.pix.height;
1023 buf_type = vpfe_ccdc_get_buftype(&vpfe->ccdc);
1024 f->fmt.pix.pixelformat = vpfe_ccdc_get_pixel_format(&vpfe->ccdc);
1025 frm_fmt = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1026
1027 if (frm_fmt == CCDC_FRMFMT_PROGRESSIVE) {
1028 f->fmt.pix.field = V4L2_FIELD_NONE;
1029 } else if (frm_fmt == CCDC_FRMFMT_INTERLACED) {
1030 if (buf_type == CCDC_BUFTYPE_FLD_INTERLEAVED) {
1031 f->fmt.pix.field = V4L2_FIELD_INTERLACED;
1032 } else if (buf_type == CCDC_BUFTYPE_FLD_SEPARATED) {
1033 f->fmt.pix.field = V4L2_FIELD_SEQ_TB;
1034 } else {
1035 vpfe_err(vpfe, "Invalid buf_type\n");
1036 return -EINVAL;
1037 }
1038 } else {
1039 vpfe_err(vpfe, "Invalid frm_fmt\n");
1040 return -EINVAL;
1041 }
1042 return 0;
1043}
1044
1045static int vpfe_config_ccdc_image_format(struct vpfe_device *vpfe)
1046{
1047 enum ccdc_frmfmt frm_fmt = CCDC_FRMFMT_INTERLACED;
1048 int ret;
1049
1050 vpfe_dbg(2, vpfe, "vpfe_config_ccdc_image_format\n");
1051
1052 vpfe_dbg(1, vpfe, "pixelformat: %s\n",
1053 print_fourcc(vpfe->fmt.fmt.pix.pixelformat));
1054
1055 if (vpfe_ccdc_set_pixel_format(&vpfe->ccdc,
1056 vpfe->fmt.fmt.pix.pixelformat) < 0) {
1057 vpfe_err(vpfe, "couldn't set pix format in ccdc\n");
1058 return -EINVAL;
1059 }
1060
1061 /* configure the image window */
1062 vpfe_ccdc_set_image_window(&vpfe->ccdc, &vpfe->crop, vpfe->bpp);
1063
1064 switch (vpfe->fmt.fmt.pix.field) {
1065 case V4L2_FIELD_INTERLACED:
1066 /* do nothing, since it is default */
1067 ret = vpfe_ccdc_set_buftype(
1068 &vpfe->ccdc,
1069 CCDC_BUFTYPE_FLD_INTERLEAVED);
1070 break;
1071
1072 case V4L2_FIELD_NONE:
1073 frm_fmt = CCDC_FRMFMT_PROGRESSIVE;
1074 /* buffer type only applicable for interlaced scan */
1075 break;
1076
1077 case V4L2_FIELD_SEQ_TB:
1078 ret = vpfe_ccdc_set_buftype(
1079 &vpfe->ccdc,
1080 CCDC_BUFTYPE_FLD_SEPARATED);
1081 break;
1082
1083 default:
1084 return -EINVAL;
1085 }
1086
1087 if (ret)
1088 return ret;
1089
1090 return vpfe_ccdc_set_frame_format(&vpfe->ccdc, frm_fmt);
1091}
1092
1093/*
1094 * vpfe_config_image_format()
1095 * For a given standard, this functions sets up the default
1096 * pix format & crop values in the vpfe device and ccdc. It first
1097 * starts with defaults based values from the standard table.
1098 * It then checks if sub device support g_mbus_fmt and then override the
1099 * values based on that.Sets crop values to match with scan resolution
1100 * starting at 0,0. It calls vpfe_config_ccdc_image_format() set the
1101 * values in ccdc
1102 */
1103static int vpfe_config_image_format(struct vpfe_device *vpfe,
1104 v4l2_std_id std_id)
1105{
1106 struct v4l2_pix_format *pix = &vpfe->fmt.fmt.pix;
1107 int i, ret;
1108
1109 for (i = 0; i < ARRAY_SIZE(vpfe_standards); i++) {
1110 if (vpfe_standards[i].std_id & std_id) {
1111 vpfe->std_info.active_pixels =
1112 vpfe_standards[i].width;
1113 vpfe->std_info.active_lines =
1114 vpfe_standards[i].height;
1115 vpfe->std_info.frame_format =
1116 vpfe_standards[i].frame_format;
1117 vpfe->std_index = i;
1118
1119 break;
1120 }
1121 }
1122
1123 if (i == ARRAY_SIZE(vpfe_standards)) {
1124 vpfe_err(vpfe, "standard not supported\n");
1125 return -EINVAL;
1126 }
1127
1128 vpfe->crop.top = vpfe->crop.left = 0;
1129 vpfe->crop.width = vpfe->std_info.active_pixels;
1130 vpfe->crop.height = vpfe->std_info.active_lines;
1131 pix->width = vpfe->crop.width;
1132 pix->height = vpfe->crop.height;
1133 pix->pixelformat = V4L2_PIX_FMT_YUYV;
1134
1135 /* first field and frame format based on standard frame format */
1136 if (vpfe->std_info.frame_format)
1137 pix->field = V4L2_FIELD_INTERLACED;
1138 else
1139 pix->field = V4L2_FIELD_NONE;
1140
1141 ret = __vpfe_get_format(vpfe, &vpfe->fmt, &vpfe->bpp);
1142 if (ret)
1143 return ret;
1144
1145 /* Update the crop window based on found values */
1146 vpfe->crop.width = pix->width;
1147 vpfe->crop.height = pix->height;
1148
1149 return vpfe_config_ccdc_image_format(vpfe);
1150}
1151
1152static int vpfe_initialize_device(struct vpfe_device *vpfe)
1153{
1154 struct vpfe_subdev_info *sdinfo;
1155 int ret;
1156
1157 sdinfo = &vpfe->cfg->sub_devs[0];
1158 sdinfo->sd = vpfe->sd[0];
1159 vpfe->current_input = 0;
1160 vpfe->std_index = 0;
1161 /* Configure the default format information */
1162 ret = vpfe_config_image_format(vpfe,
1163 vpfe_standards[vpfe->std_index].std_id);
1164 if (ret)
1165 return ret;
1166
1167 pm_runtime_get_sync(vpfe->pdev);
1168
1169 vpfe_config_enable(&vpfe->ccdc, 1);
1170
1171 vpfe_ccdc_restore_defaults(&vpfe->ccdc);
1172
1173 /* Clear all VPFE interrupts */
1174 vpfe_clear_intr(&vpfe->ccdc, -1);
1175
1176 return ret;
1177}
1178
1179/*
1180 * vpfe_release : This function is based on the vb2_fop_release
1181 * helper function.
1182 * It has been augmented to handle module power management,
1183 * by disabling/enabling h/w module fcntl clock when necessary.
1184 */
1185static int vpfe_release(struct file *file)
1186{
1187 struct vpfe_device *vpfe = video_drvdata(file);
1188 int ret;
1189
1190 mutex_lock(&vpfe->lock);
1191
1192 if (v4l2_fh_is_singular_file(file))
1193 vpfe_ccdc_close(&vpfe->ccdc, vpfe->pdev);
1194 ret = _vb2_fop_release(file, NULL);
1195
1196 mutex_unlock(&vpfe->lock);
1197
1198 return ret;
1199}
1200
1201/*
1202 * vpfe_open : This function is based on the v4l2_fh_open helper function.
1203 * It has been augmented to handle module power management,
1204 * by disabling/enabling h/w module fcntl clock when necessary.
1205 */
1206static int vpfe_open(struct file *file)
1207{
1208 struct vpfe_device *vpfe = video_drvdata(file);
1209 int ret;
1210
1211 mutex_lock(&vpfe->lock);
1212
1213 ret = v4l2_fh_open(file);
1214 if (ret) {
1215 vpfe_err(vpfe, "v4l2_fh_open failed\n");
1216 goto unlock;
1217 }
1218
1219 if (!v4l2_fh_is_singular_file(file))
1220 goto unlock;
1221
1222 if (vpfe_initialize_device(vpfe)) {
1223 v4l2_fh_release(file);
1224 ret = -ENODEV;
1225 }
1226
1227unlock:
1228 mutex_unlock(&vpfe->lock);
1229 return ret;
1230}
1231
1232/**
1233 * vpfe_schedule_next_buffer: set next buffer address for capture
1234 * @vpfe : ptr to vpfe device
1235 *
1236 * This function will get next buffer from the dma queue and
1237 * set the buffer address in the vpfe register for capture.
1238 * the buffer is marked active
1239 *
1240 * Assumes caller is holding vpfe->dma_queue_lock already
1241 */
1242static inline void vpfe_schedule_next_buffer(struct vpfe_device *vpfe)
1243{
1244 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
1245 struct vpfe_cap_buffer, list);
1246 list_del(&vpfe->next_frm->list);
1247
1248 vpfe_set_sdr_addr(&vpfe->ccdc,
1249 vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0));
1250}
1251
1252static inline void vpfe_schedule_bottom_field(struct vpfe_device *vpfe)
1253{
1254 unsigned long addr;
1255
1256 addr = vb2_dma_contig_plane_dma_addr(&vpfe->next_frm->vb, 0) +
1257 vpfe->field_off;
1258
1259 vpfe_set_sdr_addr(&vpfe->ccdc, addr);
1260}
1261
1262/*
1263 * vpfe_process_buffer_complete: process a completed buffer
1264 * @vpfe : ptr to vpfe device
1265 *
1266 * This function time stamp the buffer and mark it as DONE. It also
1267 * wake up any process waiting on the QUEUE and set the next buffer
1268 * as current
1269 */
1270static inline void vpfe_process_buffer_complete(struct vpfe_device *vpfe)
1271{
1272 v4l2_get_timestamp(&vpfe->cur_frm->vb.v4l2_buf.timestamp);
1273 vpfe->cur_frm->vb.v4l2_buf.field = vpfe->fmt.fmt.pix.field;
1274 vpfe->cur_frm->vb.v4l2_buf.sequence = vpfe->sequence++;
1275 vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_DONE);
1276 vpfe->cur_frm = vpfe->next_frm;
1277}
1278
1279/*
1280 * vpfe_isr : ISR handler for vpfe capture (VINT0)
1281 * @irq: irq number
1282 * @dev_id: dev_id ptr
1283 *
1284 * It changes status of the captured buffer, takes next buffer from the queue
1285 * and sets its address in VPFE registers
1286 */
1287static irqreturn_t vpfe_isr(int irq, void *dev)
1288{
1289 struct vpfe_device *vpfe = (struct vpfe_device *)dev;
1290 enum v4l2_field field;
1291 int intr_status;
1292 int fid;
1293
1294 intr_status = vpfe_reg_read(&vpfe->ccdc, VPFE_IRQ_STS);
1295
1296 if (intr_status & VPFE_VDINT0) {
1297 field = vpfe->fmt.fmt.pix.field;
1298
1299 if (field == V4L2_FIELD_NONE) {
1300 /* handle progressive frame capture */
1301 if (vpfe->cur_frm != vpfe->next_frm)
1302 vpfe_process_buffer_complete(vpfe);
1303 goto next_intr;
1304 }
1305
1306 /* interlaced or TB capture check which field
1307 we are in hardware */
1308 fid = vpfe_ccdc_getfid(&vpfe->ccdc);
1309
1310 /* switch the software maintained field id */
1311 vpfe->field ^= 1;
1312 if (fid == vpfe->field) {
1313 /* we are in-sync here,continue */
1314 if (fid == 0) {
1315 /*
1316 * One frame is just being captured. If the
1317 * next frame is available, release the
1318 * current frame and move on
1319 */
1320 if (vpfe->cur_frm != vpfe->next_frm)
1321 vpfe_process_buffer_complete(vpfe);
1322 /*
1323 * based on whether the two fields are stored
1324 * interleave or separately in memory,
1325 * reconfigure the CCDC memory address
1326 */
1327 if (field == V4L2_FIELD_SEQ_TB)
1328 vpfe_schedule_bottom_field(vpfe);
1329
1330 goto next_intr;
1331 }
1332 /*
1333 * if one field is just being captured configure
1334 * the next frame get the next frame from the empty
1335 * queue if no frame is available hold on to the
1336 * current buffer
1337 */
1338 spin_lock(&vpfe->dma_queue_lock);
1339 if (!list_empty(&vpfe->dma_queue) &&
1340 vpfe->cur_frm == vpfe->next_frm)
1341 vpfe_schedule_next_buffer(vpfe);
1342 spin_unlock(&vpfe->dma_queue_lock);
1343 } else if (fid == 0) {
1344 /*
1345 * out of sync. Recover from any hardware out-of-sync.
1346 * May loose one frame
1347 */
1348 vpfe->field = fid;
1349 }
1350 }
1351
1352next_intr:
1353 if (intr_status & VPFE_VDINT1) {
1354 spin_lock(&vpfe->dma_queue_lock);
1355 if (vpfe->fmt.fmt.pix.field == V4L2_FIELD_NONE &&
1356 !list_empty(&vpfe->dma_queue) &&
1357 vpfe->cur_frm == vpfe->next_frm)
1358 vpfe_schedule_next_buffer(vpfe);
1359 spin_unlock(&vpfe->dma_queue_lock);
1360 }
1361
1362 vpfe_clear_intr(&vpfe->ccdc, intr_status);
1363
1364 return IRQ_HANDLED;
1365}
1366
1367static inline void vpfe_detach_irq(struct vpfe_device *vpfe)
1368{
1369 unsigned int intr = VPFE_VDINT0;
1370 enum ccdc_frmfmt frame_format;
1371
1372 frame_format = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1373 if (frame_format == CCDC_FRMFMT_PROGRESSIVE)
1374 intr |= VPFE_VDINT1;
1375
1376 vpfe_reg_write(&vpfe->ccdc, intr, VPFE_IRQ_EN_CLR);
1377}
1378
1379static inline void vpfe_attach_irq(struct vpfe_device *vpfe)
1380{
1381 unsigned int intr = VPFE_VDINT0;
1382 enum ccdc_frmfmt frame_format;
1383
1384 frame_format = vpfe_ccdc_get_frame_format(&vpfe->ccdc);
1385 if (frame_format == CCDC_FRMFMT_PROGRESSIVE)
1386 intr |= VPFE_VDINT1;
1387
1388 vpfe_reg_write(&vpfe->ccdc, intr, VPFE_IRQ_EN_SET);
1389}
1390
1391static int vpfe_querycap(struct file *file, void *priv,
1392 struct v4l2_capability *cap)
1393{
1394 struct vpfe_device *vpfe = video_drvdata(file);
1395
1396 vpfe_dbg(2, vpfe, "vpfe_querycap\n");
1397
1398 strlcpy(cap->driver, VPFE_MODULE_NAME, sizeof(cap->driver));
1399 strlcpy(cap->card, "TI AM437x VPFE", sizeof(cap->card));
1400 snprintf(cap->bus_info, sizeof(cap->bus_info),
1401 "platform:%s", vpfe->v4l2_dev.name);
1402 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING |
1403 V4L2_CAP_READWRITE;
1404 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
1405
1406 return 0;
1407}
1408
1409/* get the format set at output pad of the adjacent subdev */
1410static int __vpfe_get_format(struct vpfe_device *vpfe,
1411 struct v4l2_format *format, unsigned int *bpp)
1412{
1413 struct v4l2_mbus_framefmt mbus_fmt;
1414 struct vpfe_subdev_info *sdinfo;
1415 struct v4l2_subdev_format fmt;
1416 int ret;
1417
1418 sdinfo = vpfe->current_subdev;
1419 if (!sdinfo->sd)
1420 return -EINVAL;
1421
1422 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1423 fmt.pad = 0;
1424
1425 ret = v4l2_subdev_call(sdinfo->sd, pad, get_fmt, NULL, &fmt);
1426 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1427 return ret;
1428
1429 if (!ret) {
1430 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
1431 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1432 } else {
1433 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1434 sdinfo->grp_id,
1435 video, g_mbus_fmt,
1436 &mbus_fmt);
1437 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1438 return ret;
1439 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
1440 mbus_to_pix(vpfe, &mbus_fmt, &format->fmt.pix, bpp);
1441 }
1442
1443 format->type = vpfe->fmt.type;
1444
1445 vpfe_dbg(1, vpfe,
1446 "%s size %dx%d (%s) bytesperline = %d, size = %d, bpp = %d\n",
1447 __func__, format->fmt.pix.width, format->fmt.pix.height,
1448 print_fourcc(format->fmt.pix.pixelformat),
1449 format->fmt.pix.bytesperline, format->fmt.pix.sizeimage, *bpp);
1450
1451 return 0;
1452}
1453
1454/* set the format at output pad of the adjacent subdev */
1455static int __vpfe_set_format(struct vpfe_device *vpfe,
1456 struct v4l2_format *format, unsigned int *bpp)
1457{
1458 struct v4l2_mbus_framefmt mbus_fmt;
1459 struct vpfe_subdev_info *sdinfo;
1460 struct v4l2_subdev_format fmt;
1461 int ret;
1462
1463 vpfe_dbg(2, vpfe, "__vpfe_set_format\n");
1464
1465 sdinfo = vpfe->current_subdev;
1466 if (!sdinfo->sd)
1467 return -EINVAL;
1468
1469 fmt.which = V4L2_SUBDEV_FORMAT_ACTIVE;
1470 fmt.pad = 0;
1471
1472 pix_to_mbus(vpfe, &format->fmt.pix, &fmt.format);
1473
1474 ret = v4l2_subdev_call(sdinfo->sd, pad, set_fmt, NULL, &fmt);
1475 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1476 return ret;
1477
1478 if (!ret) {
1479 v4l2_fill_pix_format(&format->fmt.pix, &fmt.format);
1480 mbus_to_pix(vpfe, &fmt.format, &format->fmt.pix, bpp);
1481 } else {
1482 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev,
1483 sdinfo->grp_id,
1484 video, s_mbus_fmt,
1485 &mbus_fmt);
1486 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
1487 return ret;
1488
1489 v4l2_fill_pix_format(&format->fmt.pix, &mbus_fmt);
1490 mbus_to_pix(vpfe, &mbus_fmt, &format->fmt.pix, bpp);
1491 }
1492
1493 format->type = vpfe->fmt.type;
1494
1495 vpfe_dbg(1, vpfe,
1496 "%s size %dx%d (%s) bytesperline = %d, size = %d, bpp = %d\n",
1497 __func__, format->fmt.pix.width, format->fmt.pix.height,
1498 print_fourcc(format->fmt.pix.pixelformat),
1499 format->fmt.pix.bytesperline, format->fmt.pix.sizeimage, *bpp);
1500
1501 return 0;
1502}
1503
1504static int vpfe_g_fmt(struct file *file, void *priv,
1505 struct v4l2_format *fmt)
1506{
1507 struct vpfe_device *vpfe = video_drvdata(file);
1508
1509 vpfe_dbg(2, vpfe, "vpfe_g_fmt\n");
1510
1511 *fmt = vpfe->fmt;
1512
1513 return 0;
1514}
1515
1516static int vpfe_enum_fmt(struct file *file, void *priv,
1517 struct v4l2_fmtdesc *f)
1518{
1519 struct vpfe_device *vpfe = video_drvdata(file);
1520 struct vpfe_subdev_info *sdinfo;
1521 struct vpfe_fmt *fmt = NULL;
1522 unsigned int k;
1523
1524 vpfe_dbg(2, vpfe, "vpfe_enum_format index:%d\n",
1525 f->index);
1526
1527 sdinfo = vpfe->current_subdev;
1528 if (!sdinfo->sd)
1529 return -EINVAL;
1530
1531 if (f->index > ARRAY_SIZE(formats))
1532 return -EINVAL;
1533
1534 for (k = 0; k < ARRAY_SIZE(formats); k++) {
1535 if (formats[k].index == f->index) {
1536 fmt = &formats[k];
1537 break;
1538 }
1539 }
1540 if (!fmt)
1541 return -EINVAL;
1542
1543 strncpy(f->description, fmt->name, sizeof(f->description) - 1);
1544 f->pixelformat = fmt->fourcc;
1545 f->type = vpfe->fmt.type;
1546
1547 vpfe_dbg(1, vpfe, "vpfe_enum_format: mbus index: %d code: %x pixelformat: %s [%s]\n",
1548 f->index, fmt->code, print_fourcc(fmt->fourcc), fmt->name);
1549
1550 return 0;
1551}
1552
1553static int vpfe_try_fmt(struct file *file, void *priv,
1554 struct v4l2_format *fmt)
1555{
1556 struct vpfe_device *vpfe = video_drvdata(file);
1557 unsigned int bpp;
1558
1559 vpfe_dbg(2, vpfe, "vpfe_try_fmt\n");
1560
1561 return __vpfe_get_format(vpfe, fmt, &bpp);
1562}
1563
1564static int vpfe_s_fmt(struct file *file, void *priv,
1565 struct v4l2_format *fmt)
1566{
1567 struct vpfe_device *vpfe = video_drvdata(file);
1568 struct v4l2_format format;
1569 unsigned int bpp;
1570 int ret;
1571
1572 vpfe_dbg(2, vpfe, "vpfe_s_fmt\n");
1573
1574 /* If streaming is started, return error */
1575 if (vb2_is_busy(&vpfe->buffer_queue)) {
1576 vpfe_err(vpfe, "%s device busy\n", __func__);
1577 return -EBUSY;
1578 }
1579
1580 ret = vpfe_try_fmt(file, priv, fmt);
1581 if (ret)
1582 return ret;
1583
1584
1585 if (!cmp_v4l2_format(fmt, &format)) {
1586 /* Sensor format is different from the requested format
1587 * so we need to change it
1588 */
1589 ret = __vpfe_set_format(vpfe, fmt, &bpp);
1590 if (ret)
1591 return ret;
1592 } else /* Just make sure all of the fields are consistent */
1593 *fmt = format;
1594
1595 /* First detach any IRQ if currently attached */
1596 vpfe_detach_irq(vpfe);
1597 vpfe->fmt = *fmt;
1598 vpfe->bpp = bpp;
1599
1600 /* Update the crop window based on found values */
1601 vpfe->crop.width = fmt->fmt.pix.width;
1602 vpfe->crop.height = fmt->fmt.pix.height;
1603
1604 /* set image capture parameters in the ccdc */
1605 return vpfe_config_ccdc_image_format(vpfe);
1606}
1607
1608static int vpfe_enum_size(struct file *file, void *priv,
1609 struct v4l2_frmsizeenum *fsize)
1610{
1611 struct vpfe_device *vpfe = video_drvdata(file);
1612 struct v4l2_subdev_frame_size_enum fse;
1613 struct vpfe_subdev_info *sdinfo;
1614 struct v4l2_mbus_framefmt mbus;
1615 struct v4l2_pix_format pix;
1616 struct vpfe_fmt *fmt;
1617 int ret;
1618
1619 vpfe_dbg(2, vpfe, "vpfe_enum_size\n");
1620
1621 /* check for valid format */
1622 fmt = find_format_by_pix(fsize->pixel_format);
1623 if (!fmt) {
1624 vpfe_dbg(3, vpfe, "Invalid pixel code: %x, default used instead\n",
1625 fsize->pixel_format);
1626 return -EINVAL;
1627 }
1628
1629 memset(fsize->reserved, 0x0, sizeof(fsize->reserved));
1630
1631 sdinfo = vpfe->current_subdev;
1632 if (!sdinfo->sd)
1633 return -EINVAL;
1634
1635 memset(&pix, 0x0, sizeof(pix));
1636 /* Construct pix from parameter and use default for the rest */
1637 pix.pixelformat = fsize->pixel_format;
1638 pix.width = 640;
1639 pix.height = 480;
1640 pix.colorspace = V4L2_COLORSPACE_SRGB;
1641 pix.field = V4L2_FIELD_NONE;
1642 pix_to_mbus(vpfe, &pix, &mbus);
1643
1644 memset(&fse, 0x0, sizeof(fse));
1645 fse.index = fsize->index;
1646 fse.pad = 0;
1647 fse.code = mbus.code;
1648 ret = v4l2_subdev_call(sdinfo->sd, pad, enum_frame_size, NULL, &fse);
1649 if (ret)
1650 return -EINVAL;
1651
1652 vpfe_dbg(1, vpfe, "vpfe_enum_size: index: %d code: %x W:[%d,%d] H:[%d,%d]\n",
1653 fse.index, fse.code, fse.min_width, fse.max_width,
1654 fse.min_height, fse.max_height);
1655
1656 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
1657 fsize->discrete.width = fse.max_width;
1658 fsize->discrete.height = fse.max_height;
1659
1660 vpfe_dbg(1, vpfe, "vpfe_enum_size: index: %d pixformat: %s size: %dx%d\n",
1661 fsize->index, print_fourcc(fsize->pixel_format),
1662 fsize->discrete.width, fsize->discrete.height);
1663
1664 return 0;
1665}
1666
1667/*
1668 * vpfe_get_subdev_input_index - Get subdev index and subdev input index for a
1669 * given app input index
1670 */
1671static int
1672vpfe_get_subdev_input_index(struct vpfe_device *vpfe,
1673 int *subdev_index,
1674 int *subdev_input_index,
1675 int app_input_index)
1676{
1677 struct vpfe_config *cfg = vpfe->cfg;
1678 struct vpfe_subdev_info *sdinfo;
1679 int i, j = 0;
1680
1681 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
1682 sdinfo = &cfg->sub_devs[i];
1683 if (app_input_index < (j + 1)) {
1684 *subdev_index = i;
1685 *subdev_input_index = app_input_index - j;
1686 return 0;
1687 }
1688 j++;
1689 }
1690 return -EINVAL;
1691}
1692
1693/*
1694 * vpfe_get_app_input - Get app input index for a given subdev input index
1695 * driver stores the input index of the current sub device and translate it
1696 * when application request the current input
1697 */
1698static int vpfe_get_app_input_index(struct vpfe_device *vpfe,
1699 int *app_input_index)
1700{
1701 struct vpfe_config *cfg = vpfe->cfg;
1702 struct vpfe_subdev_info *sdinfo;
1703 int i, j = 0;
1704
1705 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
1706 sdinfo = &cfg->sub_devs[i];
1707 if (!strcmp(sdinfo->name, vpfe->current_subdev->name)) {
1708 if (vpfe->current_input >= 1)
1709 return -1;
1710 *app_input_index = j + vpfe->current_input;
1711 return 0;
1712 }
1713 j++;
1714 }
1715 return -EINVAL;
1716}
1717
1718static int vpfe_enum_input(struct file *file, void *priv,
1719 struct v4l2_input *inp)
1720{
1721 struct vpfe_device *vpfe = video_drvdata(file);
1722 struct vpfe_subdev_info *sdinfo;
1723 int subdev, index;
1724
1725 vpfe_dbg(2, vpfe, "vpfe_enum_input\n");
1726
1727 if (vpfe_get_subdev_input_index(vpfe, &subdev, &index,
1728 inp->index) < 0) {
1729 vpfe_dbg(1, vpfe,
1730 "input information not found for the subdev\n");
1731 return -EINVAL;
1732 }
1733 sdinfo = &vpfe->cfg->sub_devs[subdev];
1734 *inp = sdinfo->inputs[index];
1735
1736 return 0;
1737}
1738
1739static int vpfe_g_input(struct file *file, void *priv, unsigned int *index)
1740{
1741 struct vpfe_device *vpfe = video_drvdata(file);
1742
1743 vpfe_dbg(2, vpfe, "vpfe_g_input\n");
1744
1745 return vpfe_get_app_input_index(vpfe, index);
1746}
1747
1748/* Assumes caller is holding vpfe_dev->lock */
1749static int vpfe_set_input(struct vpfe_device *vpfe, unsigned int index)
1750{
1751 int subdev_index = 0, inp_index = 0;
1752 struct vpfe_subdev_info *sdinfo;
1753 struct vpfe_route *route;
1754 u32 input, output;
1755 int ret;
1756
1757 vpfe_dbg(2, vpfe, "vpfe_set_input: index: %d\n", index);
1758
1759 /* If streaming is started, return error */
1760 if (vb2_is_busy(&vpfe->buffer_queue)) {
1761 vpfe_err(vpfe, "%s device busy\n", __func__);
1762 return -EBUSY;
1763 }
1764 ret = vpfe_get_subdev_input_index(vpfe,
1765 &subdev_index,
1766 &inp_index,
1767 index);
1768 if (ret < 0) {
1769 vpfe_err(vpfe, "invalid input index: %d\n", index);
1770 goto get_out;
1771 }
1772
1773 sdinfo = &vpfe->cfg->sub_devs[subdev_index];
1774 sdinfo->sd = vpfe->sd[subdev_index];
1775 route = &sdinfo->routes[inp_index];
1776 if (route && sdinfo->can_route) {
1777 input = route->input;
1778 output = route->output;
1779 if (sdinfo->sd) {
1780 ret = v4l2_subdev_call(sdinfo->sd, video,
1781 s_routing, input, output, 0);
1782 if (ret) {
1783 vpfe_err(vpfe, "s_routing failed\n");
1784 ret = -EINVAL;
1785 goto get_out;
1786 }
1787 }
1788
1789 }
1790
1791 vpfe->current_subdev = sdinfo;
1792 if (sdinfo->sd)
1793 vpfe->v4l2_dev.ctrl_handler = sdinfo->sd->ctrl_handler;
1794 vpfe->current_input = index;
1795 vpfe->std_index = 0;
1796
1797 /* set the bus/interface parameter for the sub device in ccdc */
1798 ret = vpfe_ccdc_set_hw_if_params(&vpfe->ccdc, &sdinfo->vpfe_param);
1799 if (ret)
1800 return ret;
1801
1802 /* set the default image parameters in the device */
1803 return vpfe_config_image_format(vpfe,
1804 vpfe_standards[vpfe->std_index].std_id);
1805
1806get_out:
1807 return ret;
1808}
1809
1810static int vpfe_s_input(struct file *file, void *priv, unsigned int index)
1811{
1812 struct vpfe_device *vpfe = video_drvdata(file);
1813
1814 vpfe_dbg(2, vpfe,
1815 "vpfe_s_input: index: %d\n", index);
1816
1817 return vpfe_set_input(vpfe, index);
1818}
1819
1820static int vpfe_querystd(struct file *file, void *priv, v4l2_std_id *std_id)
1821{
1822 struct vpfe_device *vpfe = video_drvdata(file);
1823 struct vpfe_subdev_info *sdinfo;
1824
1825 vpfe_dbg(2, vpfe, "vpfe_querystd\n");
1826
1827 sdinfo = vpfe->current_subdev;
1828 if (!(sdinfo->inputs[0].capabilities & V4L2_IN_CAP_STD))
1829 return -ENODATA;
1830
1831 /* Call querystd function of decoder device */
1832 return v4l2_device_call_until_err(&vpfe->v4l2_dev, sdinfo->grp_id,
1833 video, querystd, std_id);
1834}
1835
1836static int vpfe_s_std(struct file *file, void *priv, v4l2_std_id std_id)
1837{
1838 struct vpfe_device *vpfe = video_drvdata(file);
1839 struct vpfe_subdev_info *sdinfo;
1840 int ret;
1841
1842 vpfe_dbg(2, vpfe, "vpfe_s_std\n");
1843
1844 sdinfo = vpfe->current_subdev;
1845 if (!(sdinfo->inputs[0].capabilities & V4L2_IN_CAP_STD))
1846 return -ENODATA;
1847
1848 /* If streaming is started, return error */
1849 if (vb2_is_busy(&vpfe->buffer_queue)) {
1850 vpfe_err(vpfe, "%s device busy\n", __func__);
1851 ret = -EBUSY;
1852 return ret;
1853 }
1854
1855 ret = v4l2_device_call_until_err(&vpfe->v4l2_dev, sdinfo->grp_id,
1856 video, s_std, std_id);
1857 if (ret < 0) {
1858 vpfe_err(vpfe, "Failed to set standard\n");
1859 return ret;
1860 }
1861 ret = vpfe_config_image_format(vpfe, std_id);
1862
1863 return ret;
1864}
1865
1866static int vpfe_g_std(struct file *file, void *priv, v4l2_std_id *std_id)
1867{
1868 struct vpfe_device *vpfe = video_drvdata(file);
1869 struct vpfe_subdev_info *sdinfo;
1870
1871 vpfe_dbg(2, vpfe, "vpfe_g_std\n");
1872
1873 sdinfo = vpfe->current_subdev;
1874 if (sdinfo->inputs[0].capabilities != V4L2_IN_CAP_STD)
1875 return -ENODATA;
1876
1877 *std_id = vpfe_standards[vpfe->std_index].std_id;
1878
1879 return 0;
1880}
1881
1882/*
1883 * vpfe_calculate_offsets : This function calculates buffers offset
1884 * for top and bottom field
1885 */
1886static void vpfe_calculate_offsets(struct vpfe_device *vpfe)
1887{
1888 struct v4l2_rect image_win;
1889
1890 vpfe_dbg(2, vpfe, "vpfe_calculate_offsets\n");
1891
1892 vpfe_ccdc_get_image_window(&vpfe->ccdc, &image_win);
1893 vpfe->field_off = image_win.height * image_win.width;
1894}
1895
1896/*
1897 * vpfe_queue_setup - Callback function for buffer setup.
1898 * @vq: vb2_queue ptr
1899 * @fmt: v4l2 format
1900 * @nbuffers: ptr to number of buffers requested by application
1901 * @nplanes:: contains number of distinct video planes needed to hold a frame
1902 * @sizes[]: contains the size (in bytes) of each plane.
1903 * @alloc_ctxs: ptr to allocation context
1904 *
1905 * This callback function is called when reqbuf() is called to adjust
1906 * the buffer count and buffer size
1907 */
1908static int vpfe_queue_setup(struct vb2_queue *vq,
1909 const struct v4l2_format *fmt,
1910 unsigned int *nbuffers, unsigned int *nplanes,
1911 unsigned int sizes[], void *alloc_ctxs[])
1912{
1913 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
1914
1915 if (fmt && fmt->fmt.pix.sizeimage < vpfe->fmt.fmt.pix.sizeimage)
1916 return -EINVAL;
1917
1918 if (vq->num_buffers + *nbuffers < 3)
1919 *nbuffers = 3 - vq->num_buffers;
1920
1921 *nplanes = 1;
1922 sizes[0] = fmt ? fmt->fmt.pix.sizeimage : vpfe->fmt.fmt.pix.sizeimage;
1923 alloc_ctxs[0] = vpfe->alloc_ctx;
1924
1925 vpfe_dbg(1, vpfe,
1926 "nbuffers=%d, size=%u\n", *nbuffers, sizes[0]);
1927
1928 /* Calculate field offset */
1929 vpfe_calculate_offsets(vpfe);
1930
1931 return 0;
1932}
1933
1934/*
1935 * vpfe_buffer_prepare : callback function for buffer prepare
1936 * @vb: ptr to vb2_buffer
1937 *
1938 * This is the callback function for buffer prepare when vb2_qbuf()
1939 * function is called. The buffer is prepared and user space virtual address
1940 * or user address is converted into physical address
1941 */
1942static int vpfe_buffer_prepare(struct vb2_buffer *vb)
1943{
1944 struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
1945
1946 vb2_set_plane_payload(vb, 0, vpfe->fmt.fmt.pix.sizeimage);
1947
1948 if (vb2_get_plane_payload(vb, 0) > vb2_plane_size(vb, 0))
1949 return -EINVAL;
1950
1951 vb->v4l2_buf.field = vpfe->fmt.fmt.pix.field;
1952
1953 return 0;
1954}
1955
1956/*
1957 * vpfe_buffer_queue : Callback function to add buffer to DMA queue
1958 * @vb: ptr to vb2_buffer
1959 */
1960static void vpfe_buffer_queue(struct vb2_buffer *vb)
1961{
1962 struct vpfe_device *vpfe = vb2_get_drv_priv(vb->vb2_queue);
1963 struct vpfe_cap_buffer *buf = to_vpfe_buffer(vb);
1964 unsigned long flags = 0;
1965
1966 /* add the buffer to the DMA queue */
1967 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
1968 list_add_tail(&buf->list, &vpfe->dma_queue);
1969 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
1970}
1971
1972/*
1973 * vpfe_start_streaming : Starts the DMA engine for streaming
1974 * @vb: ptr to vb2_buffer
1975 * @count: number of buffers
1976 */
1977static int vpfe_start_streaming(struct vb2_queue *vq, unsigned int count)
1978{
1979 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
1980 struct vpfe_cap_buffer *buf, *tmp;
1981 struct vpfe_subdev_info *sdinfo;
1982 unsigned long flags;
1983 unsigned long addr;
1984 int ret;
1985
1986 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
1987
1988 vpfe->field = 0;
1989 vpfe->sequence = 0;
1990
1991 sdinfo = vpfe->current_subdev;
1992
1993 vpfe_attach_irq(vpfe);
1994
1995 if (vpfe->ccdc.ccdc_cfg.if_type == VPFE_RAW_BAYER)
1996 vpfe_ccdc_config_raw(&vpfe->ccdc);
1997 else
1998 vpfe_ccdc_config_ycbcr(&vpfe->ccdc);
1999
2000 /* Get the next frame from the buffer queue */
2001 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
2002 struct vpfe_cap_buffer, list);
2003 vpfe->cur_frm = vpfe->next_frm;
2004 /* Remove buffer from the buffer queue */
2005 list_del(&vpfe->cur_frm->list);
2006 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
2007
2008 addr = vb2_dma_contig_plane_dma_addr(&vpfe->cur_frm->vb, 0);
2009
2010 vpfe_set_sdr_addr(&vpfe->ccdc, (unsigned long)(addr));
2011
2012 vpfe_pcr_enable(&vpfe->ccdc, 1);
2013
2014 ret = v4l2_subdev_call(sdinfo->sd, video, s_stream, 1);
2015 if (ret < 0) {
2016 vpfe_err(vpfe, "Error in attaching interrupt handle\n");
2017 goto err;
2018 }
2019
2020 return 0;
2021
2022err:
2023 list_for_each_entry_safe(buf, tmp, &vpfe->dma_queue, list) {
2024 list_del(&buf->list);
2025 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_QUEUED);
2026 }
2027
2028 return ret;
2029}
2030
2031/*
2032 * vpfe_stop_streaming : Stop the DMA engine
2033 * @vq: ptr to vb2_queue
2034 *
2035 * This callback stops the DMA engine and any remaining buffers
2036 * in the DMA queue are released.
2037 */
2038static void vpfe_stop_streaming(struct vb2_queue *vq)
2039{
2040 struct vpfe_device *vpfe = vb2_get_drv_priv(vq);
2041 struct vpfe_subdev_info *sdinfo;
2042 unsigned long flags;
2043 int ret;
2044
2045 vpfe_pcr_enable(&vpfe->ccdc, 0);
2046
2047 vpfe_detach_irq(vpfe);
2048
2049 sdinfo = vpfe->current_subdev;
2050 ret = v4l2_subdev_call(sdinfo->sd, video, s_stream, 0);
2051 if (ret && ret != -ENOIOCTLCMD && ret != -ENODEV)
2052 vpfe_dbg(1, vpfe, "stream off failed in subdev\n");
2053
2054 /* release all active buffers */
2055 spin_lock_irqsave(&vpfe->dma_queue_lock, flags);
2056 if (vpfe->cur_frm == vpfe->next_frm) {
2057 vb2_buffer_done(&vpfe->cur_frm->vb, VB2_BUF_STATE_ERROR);
2058 } else {
2059 if (vpfe->cur_frm != NULL)
2060 vb2_buffer_done(&vpfe->cur_frm->vb,
2061 VB2_BUF_STATE_ERROR);
2062 if (vpfe->next_frm != NULL)
2063 vb2_buffer_done(&vpfe->next_frm->vb,
2064 VB2_BUF_STATE_ERROR);
2065 }
2066
2067 while (!list_empty(&vpfe->dma_queue)) {
2068 vpfe->next_frm = list_entry(vpfe->dma_queue.next,
2069 struct vpfe_cap_buffer, list);
2070 list_del(&vpfe->next_frm->list);
2071 vb2_buffer_done(&vpfe->next_frm->vb, VB2_BUF_STATE_ERROR);
2072 }
2073 spin_unlock_irqrestore(&vpfe->dma_queue_lock, flags);
2074}
2075
2076static int vpfe_cropcap(struct file *file, void *priv,
2077 struct v4l2_cropcap *crop)
2078{
2079 struct vpfe_device *vpfe = video_drvdata(file);
2080
2081 vpfe_dbg(2, vpfe, "vpfe_cropcap\n");
2082
2083 if (vpfe->std_index >= ARRAY_SIZE(vpfe_standards))
2084 return -EINVAL;
2085
2086 memset(crop, 0, sizeof(struct v4l2_cropcap));
2087
2088 crop->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2089 crop->defrect.width = vpfe_standards[vpfe->std_index].width;
2090 crop->bounds.width = crop->defrect.width;
2091 crop->defrect.height = vpfe_standards[vpfe->std_index].height;
2092 crop->bounds.height = crop->defrect.height;
2093 crop->pixelaspect = vpfe_standards[vpfe->std_index].pixelaspect;
2094
2095 return 0;
2096}
2097
2098static int
2099vpfe_g_selection(struct file *file, void *fh, struct v4l2_selection *s)
2100{
2101 struct vpfe_device *vpfe = video_drvdata(file);
2102
2103 switch (s->target) {
2104 case V4L2_SEL_TGT_CROP_BOUNDS:
2105 case V4L2_SEL_TGT_CROP_DEFAULT:
2106 s->r.left = s->r.top = 0;
2107 s->r.width = vpfe->crop.width;
2108 s->r.height = vpfe->crop.height;
2109 break;
2110
2111 case V4L2_SEL_TGT_CROP:
2112 s->r = vpfe->crop;
2113 break;
2114
2115 default:
2116 return -EINVAL;
2117 }
2118
2119 return 0;
2120}
2121
2122static int enclosed_rectangle(struct v4l2_rect *a, struct v4l2_rect *b)
2123{
2124 if (a->left < b->left || a->top < b->top)
2125 return 0;
2126
2127 if (a->left + a->width > b->left + b->width)
2128 return 0;
2129
2130 if (a->top + a->height > b->top + b->height)
2131 return 0;
2132
2133 return 1;
2134}
2135
2136static int
2137vpfe_s_selection(struct file *file, void *fh, struct v4l2_selection *s)
2138{
2139 struct vpfe_device *vpfe = video_drvdata(file);
2140 struct v4l2_rect cr = vpfe->crop;
2141 struct v4l2_rect r = s->r;
2142
2143 /* If streaming is started, return error */
2144 if (vb2_is_busy(&vpfe->buffer_queue)) {
2145 vpfe_err(vpfe, "%s device busy\n", __func__);
2146 return -EBUSY;
2147 }
2148
2149 if (s->type != V4L2_BUF_TYPE_VIDEO_CAPTURE ||
2150 s->target != V4L2_SEL_TGT_CROP)
2151 return -EINVAL;
2152
2153 v4l_bound_align_image(&r.width, 0, cr.width, 0,
2154 &r.height, 0, cr.height, 0, 0);
2155
2156 r.left = clamp_t(unsigned int, r.left, 0, cr.width - r.width);
2157 r.top = clamp_t(unsigned int, r.top, 0, cr.height - r.height);
2158
2159 if (s->flags & V4L2_SEL_FLAG_LE && !enclosed_rectangle(&r, &s->r))
2160 return -ERANGE;
2161
2162 if (s->flags & V4L2_SEL_FLAG_GE && !enclosed_rectangle(&s->r, &r))
2163 return -ERANGE;
2164
2165 s->r = vpfe->crop = r;
2166
2167 vpfe_ccdc_set_image_window(&vpfe->ccdc, &r, vpfe->bpp);
2168 vpfe->fmt.fmt.pix.width = r.width;
2169 vpfe->fmt.fmt.pix.height = r.height;
2170 vpfe->fmt.fmt.pix.bytesperline = vpfe_ccdc_get_line_length(&vpfe->ccdc);
2171 vpfe->fmt.fmt.pix.sizeimage = vpfe->fmt.fmt.pix.bytesperline *
2172 vpfe->fmt.fmt.pix.height;
2173
2174 vpfe_dbg(1, vpfe, "cropped (%d,%d)/%dx%d of %dx%d\n",
2175 r.left, r.top, r.width, r.height, cr.width, cr.height);
2176
2177 return 0;
2178}
2179
2180static long vpfe_ioctl_default(struct file *file, void *priv,
2181 bool valid_prio, unsigned int cmd, void *param)
2182{
2183 struct vpfe_device *vpfe = video_drvdata(file);
2184 int ret;
2185
2186 vpfe_dbg(2, vpfe, "vpfe_ioctl_default\n");
2187
2188 if (!valid_prio) {
2189 vpfe_err(vpfe, "%s device busy\n", __func__);
2190 return -EBUSY;
2191 }
2192
2193 /* If streaming is started, return error */
2194 if (vb2_is_busy(&vpfe->buffer_queue)) {
2195 vpfe_err(vpfe, "%s device busy\n", __func__);
2196 return -EBUSY;
2197 }
2198
2199 switch (cmd) {
2200 case VIDIOC_AM437X_CCDC_CFG:
2201 ret = vpfe_ccdc_set_params(&vpfe->ccdc, (void __user *)param);
2202 if (ret) {
2203 vpfe_dbg(2, vpfe,
2204 "Error setting parameters in CCDC\n");
2205 return ret;
2206 }
2207 ret = vpfe_get_ccdc_image_format(vpfe,
2208 &vpfe->fmt);
2209 if (ret < 0) {
2210 vpfe_dbg(2, vpfe,
2211 "Invalid image format at CCDC\n");
2212 return ret;
2213 }
2214 break;
2215
2216 default:
2217 ret = -ENOTTY;
2218 break;
2219 }
2220
2221 return ret;
2222}
2223
2224static const struct vb2_ops vpfe_video_qops = {
2225 .wait_prepare = vb2_ops_wait_prepare,
2226 .wait_finish = vb2_ops_wait_finish,
2227 .queue_setup = vpfe_queue_setup,
2228 .buf_prepare = vpfe_buffer_prepare,
2229 .buf_queue = vpfe_buffer_queue,
2230 .start_streaming = vpfe_start_streaming,
2231 .stop_streaming = vpfe_stop_streaming,
2232};
2233
2234/* vpfe capture driver file operations */
2235static const struct v4l2_file_operations vpfe_fops = {
2236 .owner = THIS_MODULE,
2237 .open = vpfe_open,
2238 .release = vpfe_release,
2239 .read = vb2_fop_read,
2240 .poll = vb2_fop_poll,
2241 .unlocked_ioctl = video_ioctl2,
2242 .mmap = vb2_fop_mmap,
2243};
2244
2245/* vpfe capture ioctl operations */
2246static const struct v4l2_ioctl_ops vpfe_ioctl_ops = {
2247 .vidioc_querycap = vpfe_querycap,
2248 .vidioc_enum_fmt_vid_cap = vpfe_enum_fmt,
2249 .vidioc_g_fmt_vid_cap = vpfe_g_fmt,
2250 .vidioc_s_fmt_vid_cap = vpfe_s_fmt,
2251 .vidioc_try_fmt_vid_cap = vpfe_try_fmt,
2252
2253 .vidioc_enum_framesizes = vpfe_enum_size,
2254
2255 .vidioc_enum_input = vpfe_enum_input,
2256 .vidioc_g_input = vpfe_g_input,
2257 .vidioc_s_input = vpfe_s_input,
2258
2259 .vidioc_querystd = vpfe_querystd,
2260 .vidioc_s_std = vpfe_s_std,
2261 .vidioc_g_std = vpfe_g_std,
2262
2263 .vidioc_reqbufs = vb2_ioctl_reqbufs,
2264 .vidioc_create_bufs = vb2_ioctl_create_bufs,
2265 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
2266 .vidioc_querybuf = vb2_ioctl_querybuf,
2267 .vidioc_qbuf = vb2_ioctl_qbuf,
2268 .vidioc_dqbuf = vb2_ioctl_dqbuf,
2269 .vidioc_expbuf = vb2_ioctl_expbuf,
2270 .vidioc_streamon = vb2_ioctl_streamon,
2271 .vidioc_streamoff = vb2_ioctl_streamoff,
2272
2273 .vidioc_log_status = v4l2_ctrl_log_status,
2274 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
2275 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
2276
2277 .vidioc_cropcap = vpfe_cropcap,
2278 .vidioc_g_selection = vpfe_g_selection,
2279 .vidioc_s_selection = vpfe_s_selection,
2280
2281 .vidioc_default = vpfe_ioctl_default,
2282};
2283
2284static int
2285vpfe_async_bound(struct v4l2_async_notifier *notifier,
2286 struct v4l2_subdev *subdev,
2287 struct v4l2_async_subdev *asd)
2288{
2289 struct vpfe_device *vpfe = container_of(notifier->v4l2_dev,
2290 struct vpfe_device, v4l2_dev);
2291 struct v4l2_subdev_mbus_code_enum mbus_code;
2292 struct vpfe_subdev_info *sdinfo;
2293 bool found = false;
2294 int i, j;
2295
2296 vpfe_dbg(1, vpfe, "vpfe_async_bound\n");
2297
2298 for (i = 0; i < ARRAY_SIZE(vpfe->cfg->asd); i++) {
2299 sdinfo = &vpfe->cfg->sub_devs[i];
2300
2301 if (!strcmp(sdinfo->name, subdev->name)) {
2302 vpfe->sd[i] = subdev;
2303 vpfe_info(vpfe,
2304 "v4l2 sub device %s registered\n",
2305 subdev->name);
2306 vpfe->sd[i]->grp_id =
2307 sdinfo->grp_id;
2308 /* update tvnorms from the sub devices */
2309 for (j = 0; j < 1; j++)
2310 vpfe->video_dev->tvnorms |=
2311 sdinfo->inputs[j].std;
2312
2313 found = true;
2314 break;
2315 }
2316 }
2317
2318 if (!found) {
2319 vpfe_info(vpfe, "sub device (%s) not matched\n", subdev->name);
2320 return -EINVAL;
2321 }
2322
2323 /* setup the supported formats & indexes */
2324 for (j = 0, i = 0; ; ++j) {
2325 struct vpfe_fmt *fmt;
2326 int ret;
2327
2328 memset(&mbus_code, 0, sizeof(mbus_code));
2329 mbus_code.index = j;
2330 ret = v4l2_subdev_call(subdev, pad, enum_mbus_code,
2331 NULL, &mbus_code);
2332 if (ret)
2333 break;
2334
2335 fmt = find_format_by_code(mbus_code.code);
2336 if (!fmt)
2337 continue;
2338
2339 fmt->supported = true;
2340 fmt->index = i++;
2341 }
2342
2343 return 0;
2344}
2345
2346static int vpfe_probe_complete(struct vpfe_device *vpfe)
2347{
2348 struct video_device *vdev;
2349 struct vb2_queue *q;
2350 int err;
2351
2352 spin_lock_init(&vpfe->dma_queue_lock);
2353 mutex_init(&vpfe->lock);
2354
2355 vpfe->fmt.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2356
2357 /* set first sub device as current one */
2358 vpfe->current_subdev = &vpfe->cfg->sub_devs[0];
2359 vpfe->v4l2_dev.ctrl_handler = vpfe->sd[0]->ctrl_handler;
2360
2361 err = vpfe_set_input(vpfe, 0);
2362 if (err)
2363 goto probe_out;
2364
2365 /* Initialize videobuf2 queue as per the buffer type */
2366 vpfe->alloc_ctx = vb2_dma_contig_init_ctx(vpfe->pdev);
2367 if (IS_ERR(vpfe->alloc_ctx)) {
2368 vpfe_err(vpfe, "Failed to get the context\n");
2369 err = PTR_ERR(vpfe->alloc_ctx);
2370 goto probe_out;
2371 }
2372
2373 q = &vpfe->buffer_queue;
2374 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
2375 q->io_modes = VB2_MMAP | VB2_DMABUF | VB2_READ;
2376 q->drv_priv = vpfe;
2377 q->ops = &vpfe_video_qops;
2378 q->mem_ops = &vb2_dma_contig_memops;
2379 q->buf_struct_size = sizeof(struct vpfe_cap_buffer);
2380 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
2381 q->lock = &vpfe->lock;
2382 q->min_buffers_needed = 1;
2383
2384 err = vb2_queue_init(q);
2385 if (err) {
2386 vpfe_err(vpfe, "vb2_queue_init() failed\n");
2387 vb2_dma_contig_cleanup_ctx(vpfe->alloc_ctx);
2388 goto probe_out;
2389 }
2390
2391 INIT_LIST_HEAD(&vpfe->dma_queue);
2392
2393 vdev = vpfe->video_dev;
2394 strlcpy(vdev->name, VPFE_MODULE_NAME, sizeof(vdev->name));
2395 vdev->release = video_device_release;
2396 vdev->fops = &vpfe_fops;
2397 vdev->ioctl_ops = &vpfe_ioctl_ops;
2398 vdev->v4l2_dev = &vpfe->v4l2_dev;
2399 vdev->vfl_dir = VFL_DIR_RX;
2400 vdev->queue = q;
2401 vdev->lock = &vpfe->lock;
2402 video_set_drvdata(vdev, vpfe);
2403 err = video_register_device(vpfe->video_dev, VFL_TYPE_GRABBER, -1);
2404 if (err) {
2405 vpfe_err(vpfe,
2406 "Unable to register video device.\n");
2407 goto probe_out;
2408 }
2409
2410 return 0;
2411
2412probe_out:
2413 v4l2_device_unregister(&vpfe->v4l2_dev);
2414 return err;
2415}
2416
2417static int vpfe_async_complete(struct v4l2_async_notifier *notifier)
2418{
2419 struct vpfe_device *vpfe = container_of(notifier->v4l2_dev,
2420 struct vpfe_device, v4l2_dev);
2421
2422 return vpfe_probe_complete(vpfe);
2423}
2424
2425static struct vpfe_config *
2426vpfe_get_pdata(struct platform_device *pdev)
2427{
2428 struct device_node *endpoint = NULL, *rem = NULL;
2429 struct v4l2_of_endpoint bus_cfg;
2430 struct vpfe_subdev_info *sdinfo;
2431 struct vpfe_config *pdata;
2432 unsigned int flags;
2433 unsigned int i;
2434 int err;
2435
2436 dev_dbg(&pdev->dev, "vpfe_get_pdata\n");
2437
2438 if (!IS_ENABLED(CONFIG_OF) || !pdev->dev.of_node)
2439 return pdev->dev.platform_data;
2440
2441 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
2442 if (!pdata)
2443 return NULL;
2444
2445 for (i = 0; ; i++) {
2446 endpoint = of_graph_get_next_endpoint(pdev->dev.of_node,
2447 endpoint);
2448 if (!endpoint)
2449 break;
2450
2451 sdinfo = &pdata->sub_devs[i];
2452 sdinfo->grp_id = 0;
2453
2454 /* we only support camera */
2455 sdinfo->inputs[0].index = i;
2456 strcpy(sdinfo->inputs[0].name, "Camera");
2457 sdinfo->inputs[0].type = V4L2_INPUT_TYPE_CAMERA;
2458 sdinfo->inputs[0].std = V4L2_STD_ALL;
2459 sdinfo->inputs[0].capabilities = V4L2_IN_CAP_STD;
2460
2461 sdinfo->can_route = 0;
2462 sdinfo->routes = NULL;
2463
2464 of_property_read_u32(endpoint, "ti,am437x-vpfe-interface",
2465 &sdinfo->vpfe_param.if_type);
2466 if (sdinfo->vpfe_param.if_type < 0 ||
2467 sdinfo->vpfe_param.if_type > 4) {
2468 sdinfo->vpfe_param.if_type = VPFE_RAW_BAYER;
2469 }
2470
2471 err = v4l2_of_parse_endpoint(endpoint, &bus_cfg);
2472 if (err) {
2473 dev_err(&pdev->dev, "Could not parse the endpoint\n");
2474 goto done;
2475 }
2476
2477 sdinfo->vpfe_param.bus_width = bus_cfg.bus.parallel.bus_width;
2478
2479 if (sdinfo->vpfe_param.bus_width < 8 ||
2480 sdinfo->vpfe_param.bus_width > 16) {
2481 dev_err(&pdev->dev, "Invalid bus width.\n");
2482 goto done;
2483 }
2484
2485 flags = bus_cfg.bus.parallel.flags;
2486
2487 if (flags & V4L2_MBUS_HSYNC_ACTIVE_HIGH)
2488 sdinfo->vpfe_param.hdpol = 1;
2489
2490 if (flags & V4L2_MBUS_VSYNC_ACTIVE_HIGH)
2491 sdinfo->vpfe_param.vdpol = 1;
2492
2493 rem = of_graph_get_remote_port_parent(endpoint);
2494 if (!rem) {
2495 dev_err(&pdev->dev, "Remote device at %s not found\n",
2496 endpoint->full_name);
2497 goto done;
2498 }
2499
2500 strncpy(sdinfo->name, rem->name, sizeof(sdinfo->name));
2501
2502 pdata->asd[i] = devm_kzalloc(&pdev->dev,
2503 sizeof(struct v4l2_async_subdev),
2504 GFP_KERNEL);
2505 pdata->asd[i]->match_type = V4L2_ASYNC_MATCH_OF;
2506 pdata->asd[i]->match.of.node = rem;
2507 of_node_put(endpoint);
2508 of_node_put(rem);
2509 }
2510
2511 of_node_put(endpoint);
2512 return pdata;
2513
2514done:
2515 of_node_put(endpoint);
2516 of_node_put(rem);
2517 return NULL;
2518}
2519
2520/*
2521 * vpfe_probe : This function creates device entries by register
2522 * itself to the V4L2 driver and initializes fields of each
2523 * device objects
2524 */
2525static int vpfe_probe(struct platform_device *pdev)
2526{
2527 struct vpfe_config *vpfe_cfg = vpfe_get_pdata(pdev);
2528 struct vpfe_device *vpfe;
2529 struct vpfe_ccdc *ccdc;
2530 struct resource *res;
2531 int ret;
2532
2533 if (!vpfe_cfg) {
2534 dev_err(&pdev->dev, "No platform data\n");
2535 return -EINVAL;
2536 }
2537
2538 vpfe = devm_kzalloc(&pdev->dev, sizeof(*vpfe), GFP_KERNEL);
2539 if (!vpfe)
2540 return -ENOMEM;
2541
2542 vpfe->pdev = &pdev->dev;
2543 vpfe->cfg = vpfe_cfg;
2544 ccdc = &vpfe->ccdc;
2545
2546 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2547 ccdc->ccdc_cfg.base_addr = devm_ioremap_resource(&pdev->dev, res);
2548 if (IS_ERR(ccdc->ccdc_cfg.base_addr))
2549 return PTR_ERR(ccdc->ccdc_cfg.base_addr);
2550
2551 vpfe->irq = platform_get_irq(pdev, 0);
2552 if (vpfe->irq <= 0) {
2553 dev_err(&pdev->dev, "No IRQ resource\n");
2554 return -ENODEV;
2555 }
2556
2557 ret = devm_request_irq(vpfe->pdev, vpfe->irq, vpfe_isr, 0,
2558 "vpfe_capture0", vpfe);
2559 if (ret) {
2560 dev_err(&pdev->dev, "Unable to request interrupt\n");
2561 return -EINVAL;
2562 }
2563
2564 vpfe->video_dev = video_device_alloc();
2565 if (!vpfe->video_dev) {
2566 dev_err(&pdev->dev, "Unable to allocate video device\n");
2567 return -ENOMEM;
2568 }
2569
2570 ret = v4l2_device_register(&pdev->dev, &vpfe->v4l2_dev);
2571 if (ret) {
2572 vpfe_err(vpfe,
2573 "Unable to register v4l2 device.\n");
2574 goto probe_out_video_release;
2575 }
2576
2577 /* set the driver data in platform device */
2578 platform_set_drvdata(pdev, vpfe);
2579 /* Enabling module functional clock */
2580 pm_runtime_enable(&pdev->dev);
2581
2582 /* for now just enable it here instead of waiting for the open */
2583 pm_runtime_get_sync(&pdev->dev);
2584
2585 vpfe_ccdc_config_defaults(ccdc);
2586
2587 pm_runtime_put_sync(&pdev->dev);
2588
2589 vpfe->sd = devm_kzalloc(&pdev->dev, sizeof(struct v4l2_subdev *) *
2590 ARRAY_SIZE(vpfe->cfg->asd), GFP_KERNEL);
2591 if (!vpfe->sd) {
2592 ret = -ENOMEM;
2593 goto probe_out_v4l2_unregister;
2594 }
2595
2596 vpfe->notifier.subdevs = vpfe->cfg->asd;
2597 vpfe->notifier.num_subdevs = ARRAY_SIZE(vpfe->cfg->asd);
2598 vpfe->notifier.bound = vpfe_async_bound;
2599 vpfe->notifier.complete = vpfe_async_complete;
2600 ret = v4l2_async_notifier_register(&vpfe->v4l2_dev,
2601 &vpfe->notifier);
2602 if (ret) {
2603 vpfe_err(vpfe, "Error registering async notifier\n");
2604 ret = -EINVAL;
2605 goto probe_out_v4l2_unregister;
2606 }
2607
2608 return 0;
2609
2610probe_out_v4l2_unregister:
2611 v4l2_device_unregister(&vpfe->v4l2_dev);
2612probe_out_video_release:
2613 if (!video_is_registered(vpfe->video_dev))
2614 video_device_release(vpfe->video_dev);
2615 return ret;
2616}
2617
2618/*
2619 * vpfe_remove : It un-register device from V4L2 driver
2620 */
2621static int vpfe_remove(struct platform_device *pdev)
2622{
2623 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2624
2625 vpfe_dbg(2, vpfe, "vpfe_remove\n");
2626
2627 pm_runtime_disable(&pdev->dev);
2628
2629 v4l2_async_notifier_unregister(&vpfe->notifier);
2630 v4l2_device_unregister(&vpfe->v4l2_dev);
2631 video_unregister_device(vpfe->video_dev);
2632
2633 return 0;
2634}
2635
2636#ifdef CONFIG_PM_SLEEP
2637
2638static void vpfe_save_context(struct vpfe_ccdc *ccdc)
2639{
2640 ccdc->ccdc_ctx[VPFE_PCR >> 2] = vpfe_reg_read(ccdc, VPFE_PCR);
2641 ccdc->ccdc_ctx[VPFE_SYNMODE >> 2] = vpfe_reg_read(ccdc, VPFE_SYNMODE);
2642 ccdc->ccdc_ctx[VPFE_SDOFST >> 2] = vpfe_reg_read(ccdc, VPFE_SDOFST);
2643 ccdc->ccdc_ctx[VPFE_SDR_ADDR >> 2] = vpfe_reg_read(ccdc, VPFE_SDR_ADDR);
2644 ccdc->ccdc_ctx[VPFE_CLAMP >> 2] = vpfe_reg_read(ccdc, VPFE_CLAMP);
2645 ccdc->ccdc_ctx[VPFE_DCSUB >> 2] = vpfe_reg_read(ccdc, VPFE_DCSUB);
2646 ccdc->ccdc_ctx[VPFE_COLPTN >> 2] = vpfe_reg_read(ccdc, VPFE_COLPTN);
2647 ccdc->ccdc_ctx[VPFE_BLKCMP >> 2] = vpfe_reg_read(ccdc, VPFE_BLKCMP);
2648 ccdc->ccdc_ctx[VPFE_VDINT >> 2] = vpfe_reg_read(ccdc, VPFE_VDINT);
2649 ccdc->ccdc_ctx[VPFE_ALAW >> 2] = vpfe_reg_read(ccdc, VPFE_ALAW);
2650 ccdc->ccdc_ctx[VPFE_REC656IF >> 2] = vpfe_reg_read(ccdc, VPFE_REC656IF);
2651 ccdc->ccdc_ctx[VPFE_CCDCFG >> 2] = vpfe_reg_read(ccdc, VPFE_CCDCFG);
2652 ccdc->ccdc_ctx[VPFE_CULLING >> 2] = vpfe_reg_read(ccdc, VPFE_CULLING);
2653 ccdc->ccdc_ctx[VPFE_HD_VD_WID >> 2] = vpfe_reg_read(ccdc,
2654 VPFE_HD_VD_WID);
2655 ccdc->ccdc_ctx[VPFE_PIX_LINES >> 2] = vpfe_reg_read(ccdc,
2656 VPFE_PIX_LINES);
2657 ccdc->ccdc_ctx[VPFE_HORZ_INFO >> 2] = vpfe_reg_read(ccdc,
2658 VPFE_HORZ_INFO);
2659 ccdc->ccdc_ctx[VPFE_VERT_START >> 2] = vpfe_reg_read(ccdc,
2660 VPFE_VERT_START);
2661 ccdc->ccdc_ctx[VPFE_VERT_LINES >> 2] = vpfe_reg_read(ccdc,
2662 VPFE_VERT_LINES);
2663 ccdc->ccdc_ctx[VPFE_HSIZE_OFF >> 2] = vpfe_reg_read(ccdc,
2664 VPFE_HSIZE_OFF);
2665}
2666
2667static int vpfe_suspend(struct device *dev)
2668{
2669 struct platform_device *pdev = to_platform_device(dev);
2670 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2671 struct vpfe_ccdc *ccdc = &vpfe->ccdc;
2672
2673 /* if streaming has not started we don't care */
2674 if (!vb2_start_streaming_called(&vpfe->buffer_queue))
2675 return 0;
2676
2677 pm_runtime_get_sync(dev);
2678 vpfe_config_enable(ccdc, 1);
2679
2680 /* Save VPFE context */
2681 vpfe_save_context(ccdc);
2682
2683 /* Disable CCDC */
2684 vpfe_pcr_enable(ccdc, 0);
2685 vpfe_config_enable(ccdc, 0);
2686
2687 /* Disable both master and slave clock */
2688 pm_runtime_put_sync(dev);
2689
2690 /* Select sleep pin state */
2691 pinctrl_pm_select_sleep_state(dev);
2692
2693 return 0;
2694}
2695
2696static void vpfe_restore_context(struct vpfe_ccdc *ccdc)
2697{
2698 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SYNMODE >> 2], VPFE_SYNMODE);
2699 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CULLING >> 2], VPFE_CULLING);
2700 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SDOFST >> 2], VPFE_SDOFST);
2701 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_SDR_ADDR >> 2], VPFE_SDR_ADDR);
2702 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CLAMP >> 2], VPFE_CLAMP);
2703 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_DCSUB >> 2], VPFE_DCSUB);
2704 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_COLPTN >> 2], VPFE_COLPTN);
2705 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_BLKCMP >> 2], VPFE_BLKCMP);
2706 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VDINT >> 2], VPFE_VDINT);
2707 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_ALAW >> 2], VPFE_ALAW);
2708 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_REC656IF >> 2], VPFE_REC656IF);
2709 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_CCDCFG >> 2], VPFE_CCDCFG);
2710 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_PCR >> 2], VPFE_PCR);
2711 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HD_VD_WID >> 2],
2712 VPFE_HD_VD_WID);
2713 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_PIX_LINES >> 2],
2714 VPFE_PIX_LINES);
2715 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HORZ_INFO >> 2],
2716 VPFE_HORZ_INFO);
2717 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VERT_START >> 2],
2718 VPFE_VERT_START);
2719 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_VERT_LINES >> 2],
2720 VPFE_VERT_LINES);
2721 vpfe_reg_write(ccdc, ccdc->ccdc_ctx[VPFE_HSIZE_OFF >> 2],
2722 VPFE_HSIZE_OFF);
2723}
2724
2725static int vpfe_resume(struct device *dev)
2726{
2727 struct platform_device *pdev = to_platform_device(dev);
2728 struct vpfe_device *vpfe = platform_get_drvdata(pdev);
2729 struct vpfe_ccdc *ccdc = &vpfe->ccdc;
2730
2731 /* if streaming has not started we don't care */
2732 if (!vb2_start_streaming_called(&vpfe->buffer_queue))
2733 return 0;
2734
2735 /* Enable both master and slave clock */
2736 pm_runtime_get_sync(dev);
2737 vpfe_config_enable(ccdc, 1);
2738
2739 /* Restore VPFE context */
2740 vpfe_restore_context(ccdc);
2741
2742 vpfe_config_enable(ccdc, 0);
2743 pm_runtime_put_sync(dev);
2744
2745 /* Select default pin state */
2746 pinctrl_pm_select_default_state(dev);
2747
2748 return 0;
2749}
2750
2751#endif
2752
2753static SIMPLE_DEV_PM_OPS(vpfe_pm_ops, vpfe_suspend, vpfe_resume);
2754
2755static const struct of_device_id vpfe_of_match[] = {
2756 { .compatible = "ti,am437x-vpfe", },
2757 { /* sentinel */ },
2758};
2759MODULE_DEVICE_TABLE(of, vpfe_of_match);
2760
2761static struct platform_driver vpfe_driver = {
2762 .probe = vpfe_probe,
2763 .remove = vpfe_remove,
2764 .driver = {
2765 .name = VPFE_MODULE_NAME,
2766 .pm = &vpfe_pm_ops,
2767 .of_match_table = of_match_ptr(vpfe_of_match),
2768 },
2769};
2770
2771module_platform_driver(vpfe_driver);
2772
2773MODULE_AUTHOR("Texas Instruments");
2774MODULE_DESCRIPTION("TI AM437x VPFE driver");
2775MODULE_LICENSE("GPL");
2776MODULE_VERSION(VPFE_VERSION);
diff --git a/drivers/media/platform/am437x/am437x-vpfe.h b/drivers/media/platform/am437x/am437x-vpfe.h
new file mode 100644
index 000000000000..0f557352313d
--- /dev/null
+++ b/drivers/media/platform/am437x/am437x-vpfe.h
@@ -0,0 +1,283 @@
1/*
2 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
3 *
4 * Benoit Parrot <bparrot@ti.com>
5 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
6 *
7 * This program is free software; you may redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
12 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
15 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
16 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
17 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
18 * SOFTWARE.
19 */
20
21#ifndef AM437X_VPFE_H
22#define AM437X_VPFE_H
23
24#include <linux/am437x-vpfe.h>
25#include <linux/clk.h>
26#include <linux/device.h>
27#include <linux/io.h>
28#include <linux/i2c.h>
29#include <linux/videodev2.h>
30
31#include <media/v4l2-dev.h>
32#include <media/v4l2-device.h>
33#include <media/v4l2-ioctl.h>
34#include <media/videobuf2-dma-contig.h>
35
36#include "am437x-vpfe_regs.h"
37
38enum vpfe_pin_pol {
39 VPFE_PINPOL_POSITIVE = 0,
40 VPFE_PINPOL_NEGATIVE,
41};
42
43enum vpfe_hw_if_type {
44 /* Raw Bayer */
45 VPFE_RAW_BAYER = 0,
46 /* BT656 - 8 bit */
47 VPFE_BT656,
48 /* BT656 - 10 bit */
49 VPFE_BT656_10BIT,
50 /* YCbCr - 8 bit with external sync */
51 VPFE_YCBCR_SYNC_8,
52 /* YCbCr - 16 bit with external sync */
53 VPFE_YCBCR_SYNC_16,
54};
55
56/* interface description */
57struct vpfe_hw_if_param {
58 enum vpfe_hw_if_type if_type;
59 enum vpfe_pin_pol hdpol;
60 enum vpfe_pin_pol vdpol;
61 unsigned int bus_width;
62};
63
64#define VPFE_MAX_SUBDEV 1
65#define VPFE_MAX_INPUTS 1
66
67struct vpfe_pixel_format {
68 struct v4l2_fmtdesc fmtdesc;
69 /* bytes per pixel */
70 int bpp;
71};
72
73struct vpfe_std_info {
74 int active_pixels;
75 int active_lines;
76 /* current frame format */
77 int frame_format;
78};
79
80struct vpfe_route {
81 u32 input;
82 u32 output;
83};
84
85struct vpfe_subdev_info {
86 char name[32];
87 /* Sub device group id */
88 int grp_id;
89 /* inputs available at the sub device */
90 struct v4l2_input inputs[VPFE_MAX_INPUTS];
91 /* Sub dev routing information for each input */
92 struct vpfe_route *routes;
93 /* check if sub dev supports routing */
94 int can_route;
95 /* ccdc bus/interface configuration */
96 struct vpfe_hw_if_param vpfe_param;
97 struct v4l2_subdev *sd;
98};
99
100struct vpfe_config {
101 /* information about each subdev */
102 struct vpfe_subdev_info sub_devs[VPFE_MAX_SUBDEV];
103 /* Flat array, arranged in groups */
104 struct v4l2_async_subdev *asd[VPFE_MAX_SUBDEV];
105};
106
107struct vpfe_cap_buffer {
108 struct vb2_buffer vb;
109 struct list_head list;
110};
111
112enum ccdc_pixfmt {
113 CCDC_PIXFMT_RAW = 0,
114 CCDC_PIXFMT_YCBCR_16BIT,
115 CCDC_PIXFMT_YCBCR_8BIT,
116};
117
118enum ccdc_frmfmt {
119 CCDC_FRMFMT_PROGRESSIVE = 0,
120 CCDC_FRMFMT_INTERLACED,
121};
122
123/* PIXEL ORDER IN MEMORY from LSB to MSB */
124/* only applicable for 8-bit input mode */
125enum ccdc_pixorder {
126 CCDC_PIXORDER_YCBYCR,
127 CCDC_PIXORDER_CBYCRY,
128};
129
130enum ccdc_buftype {
131 CCDC_BUFTYPE_FLD_INTERLEAVED,
132 CCDC_BUFTYPE_FLD_SEPARATED
133};
134
135
136/* returns the highest bit used for the gamma */
137static inline u8 ccdc_gamma_width_max_bit(enum vpfe_ccdc_gamma_width width)
138{
139 return 15 - width;
140}
141
142/* returns the highest bit used for this data size */
143static inline u8 ccdc_data_size_max_bit(enum vpfe_ccdc_data_size sz)
144{
145 return sz == VPFE_CCDC_DATA_8BITS ? 7 : 15 - sz;
146}
147
148/* Structure for CCDC configuration parameters for raw capture mode */
149struct ccdc_params_raw {
150 /* pixel format */
151 enum ccdc_pixfmt pix_fmt;
152 /* progressive or interlaced frame */
153 enum ccdc_frmfmt frm_fmt;
154 struct v4l2_rect win;
155 /* Current Format Bytes Per Pixels */
156 unsigned int bytesperpixel;
157 /* Current Format Bytes per Lines
158 * (Aligned to 32 bytes) used for HORZ_INFO
159 */
160 unsigned int bytesperline;
161 /* field id polarity */
162 enum vpfe_pin_pol fid_pol;
163 /* vertical sync polarity */
164 enum vpfe_pin_pol vd_pol;
165 /* horizontal sync polarity */
166 enum vpfe_pin_pol hd_pol;
167 /* interleaved or separated fields */
168 enum ccdc_buftype buf_type;
169 /*
170 * enable to store the image in inverse
171 * order in memory(bottom to top)
172 */
173 unsigned char image_invert_enable;
174 /* configurable parameters */
175 struct vpfe_ccdc_config_params_raw config_params;
176};
177
178struct ccdc_params_ycbcr {
179 /* pixel format */
180 enum ccdc_pixfmt pix_fmt;
181 /* progressive or interlaced frame */
182 enum ccdc_frmfmt frm_fmt;
183 struct v4l2_rect win;
184 /* Current Format Bytes Per Pixels */
185 unsigned int bytesperpixel;
186 /* Current Format Bytes per Lines
187 * (Aligned to 32 bytes) used for HORZ_INFO
188 */
189 unsigned int bytesperline;
190 /* field id polarity */
191 enum vpfe_pin_pol fid_pol;
192 /* vertical sync polarity */
193 enum vpfe_pin_pol vd_pol;
194 /* horizontal sync polarity */
195 enum vpfe_pin_pol hd_pol;
196 /* enable BT.656 embedded sync mode */
197 int bt656_enable;
198 /* cb:y:cr:y or y:cb:y:cr in memory */
199 enum ccdc_pixorder pix_order;
200 /* interleaved or separated fields */
201 enum ccdc_buftype buf_type;
202};
203
204/*
205 * CCDC operational configuration
206 */
207struct ccdc_config {
208 /* CCDC interface type */
209 enum vpfe_hw_if_type if_type;
210 /* Raw Bayer configuration */
211 struct ccdc_params_raw bayer;
212 /* YCbCr configuration */
213 struct ccdc_params_ycbcr ycbcr;
214 /* ccdc base address */
215 void __iomem *base_addr;
216};
217
218struct vpfe_ccdc {
219 struct ccdc_config ccdc_cfg;
220 u32 ccdc_ctx[VPFE_REG_END / sizeof(u32)];
221};
222
223struct vpfe_device {
224 /* V4l2 specific parameters */
225 /* Identifies video device for this channel */
226 struct video_device *video_dev;
227 /* sub devices */
228 struct v4l2_subdev **sd;
229 /* vpfe cfg */
230 struct vpfe_config *cfg;
231 /* V4l2 device */
232 struct v4l2_device v4l2_dev;
233 /* parent device */
234 struct device *pdev;
235 /* subdevice async Notifier */
236 struct v4l2_async_notifier notifier;
237 /* Indicates id of the field which is being displayed */
238 unsigned field;
239 unsigned sequence;
240 /* current interface type */
241 struct vpfe_hw_if_param vpfe_if_params;
242 /* ptr to currently selected sub device */
243 struct vpfe_subdev_info *current_subdev;
244 /* current input at the sub device */
245 int current_input;
246 /* Keeps track of the information about the standard */
247 struct vpfe_std_info std_info;
248 /* std index into std table */
249 int std_index;
250 /* IRQs used when CCDC output to SDRAM */
251 unsigned int irq;
252 /* Pointer pointing to current v4l2_buffer */
253 struct vpfe_cap_buffer *cur_frm;
254 /* Pointer pointing to next v4l2_buffer */
255 struct vpfe_cap_buffer *next_frm;
256 /* Used to store pixel format */
257 struct v4l2_format fmt;
258 /* Used to store current bytes per pixel based on current format */
259 unsigned int bpp;
260 /*
261 * used when IMP is chained to store the crop window which
262 * is different from the image window
263 */
264 struct v4l2_rect crop;
265 /* Buffer queue used in video-buf */
266 struct vb2_queue buffer_queue;
267 /* Allocator-specific contexts for each plane */
268 struct vb2_alloc_ctx *alloc_ctx;
269 /* Queue of filled frames */
270 struct list_head dma_queue;
271 /* IRQ lock for DMA queue */
272 spinlock_t dma_queue_lock;
273 /* lock used to access this structure */
274 struct mutex lock;
275 /*
276 * offset where second field starts from the starting of the
277 * buffer for field separated YCbCr formats
278 */
279 u32 field_off;
280 struct vpfe_ccdc ccdc;
281};
282
283#endif /* AM437X_VPFE_H */
diff --git a/drivers/media/platform/am437x/am437x-vpfe_regs.h b/drivers/media/platform/am437x/am437x-vpfe_regs.h
new file mode 100644
index 000000000000..4a0ed29723e8
--- /dev/null
+++ b/drivers/media/platform/am437x/am437x-vpfe_regs.h
@@ -0,0 +1,140 @@
1/*
2 * TI AM437x Image Sensor Interface Registers
3 *
4 * Copyright (C) 2013 - 2014 Texas Instruments, Inc.
5 *
6 * Benoit Parrot <bparrot@ti.com>
7 * Lad, Prabhakar <prabhakar.csengg@gmail.com>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
12 *
13 * This program is distributed "as is" WITHOUT ANY WARRANTY of any
14 * kind, whether express or implied; without even the implied warranty
15 * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 */
18
19#ifndef AM437X_VPFE_REGS_H
20#define AM437X_VPFE_REGS_H
21
22/* VPFE module register offset */
23#define VPFE_REVISION 0x0
24#define VPFE_PCR 0x4
25#define VPFE_SYNMODE 0x8
26#define VPFE_HD_VD_WID 0xc
27#define VPFE_PIX_LINES 0x10
28#define VPFE_HORZ_INFO 0x14
29#define VPFE_VERT_START 0x18
30#define VPFE_VERT_LINES 0x1c
31#define VPFE_CULLING 0x20
32#define VPFE_HSIZE_OFF 0x24
33#define VPFE_SDOFST 0x28
34#define VPFE_SDR_ADDR 0x2c
35#define VPFE_CLAMP 0x30
36#define VPFE_DCSUB 0x34
37#define VPFE_COLPTN 0x38
38#define VPFE_BLKCMP 0x3c
39#define VPFE_VDINT 0x48
40#define VPFE_ALAW 0x4c
41#define VPFE_REC656IF 0x50
42#define VPFE_CCDCFG 0x54
43#define VPFE_DMA_CNTL 0x98
44#define VPFE_SYSCONFIG 0x104
45#define VPFE_CONFIG 0x108
46#define VPFE_IRQ_EOI 0x110
47#define VPFE_IRQ_STS_RAW 0x114
48#define VPFE_IRQ_STS 0x118
49#define VPFE_IRQ_EN_SET 0x11c
50#define VPFE_IRQ_EN_CLR 0x120
51#define VPFE_REG_END 0x124
52
53/* Define bit fields within selected registers */
54#define VPFE_FID_POL_MASK 1
55#define VPFE_FID_POL_SHIFT 4
56#define VPFE_HD_POL_MASK 1
57#define VPFE_HD_POL_SHIFT 3
58#define VPFE_VD_POL_MASK 1
59#define VPFE_VD_POL_SHIFT 2
60#define VPFE_HSIZE_OFF_MASK 0xffffffe0
61#define VPFE_32BYTE_ALIGN_VAL 31
62#define VPFE_FRM_FMT_MASK 0x1
63#define VPFE_FRM_FMT_SHIFT 7
64#define VPFE_DATA_SZ_MASK 7
65#define VPFE_DATA_SZ_SHIFT 8
66#define VPFE_PIX_FMT_MASK 3
67#define VPFE_PIX_FMT_SHIFT 12
68#define VPFE_VP2SDR_DISABLE 0xfffbffff
69#define VPFE_WEN_ENABLE (1 << 17)
70#define VPFE_SDR2RSZ_DISABLE 0xfff7ffff
71#define VPFE_VDHDEN_ENABLE (1 << 16)
72#define VPFE_LPF_ENABLE (1 << 14)
73#define VPFE_ALAW_ENABLE (1 << 3)
74#define VPFE_ALAW_GAMMA_WD_MASK 7
75#define VPFE_BLK_CLAMP_ENABLE (1 << 31)
76#define VPFE_BLK_SGAIN_MASK 0x1f
77#define VPFE_BLK_ST_PXL_MASK 0x7fff
78#define VPFE_BLK_ST_PXL_SHIFT 10
79#define VPFE_BLK_SAMPLE_LN_MASK 7
80#define VPFE_BLK_SAMPLE_LN_SHIFT 28
81#define VPFE_BLK_SAMPLE_LINE_MASK 7
82#define VPFE_BLK_SAMPLE_LINE_SHIFT 25
83#define VPFE_BLK_DC_SUB_MASK 0x03fff
84#define VPFE_BLK_COMP_MASK 0xff
85#define VPFE_BLK_COMP_GB_COMP_SHIFT 8
86#define VPFE_BLK_COMP_GR_COMP_SHIFT 16
87#define VPFE_BLK_COMP_R_COMP_SHIFT 24
88#define VPFE_LATCH_ON_VSYNC_DISABLE (1 << 15)
89#define VPFE_DATA_PACK_ENABLE (1 << 11)
90#define VPFE_HORZ_INFO_SPH_SHIFT 16
91#define VPFE_VERT_START_SLV0_SHIFT 16
92#define VPFE_VDINT_VDINT0_SHIFT 16
93#define VPFE_VDINT_VDINT1_MASK 0xffff
94#define VPFE_PPC_RAW 1
95#define VPFE_DCSUB_DEFAULT_VAL 0
96#define VPFE_CLAMP_DEFAULT_VAL 0
97#define VPFE_COLPTN_VAL 0xbb11bb11
98#define VPFE_TWO_BYTES_PER_PIXEL 2
99#define VPFE_INTERLACED_IMAGE_INVERT 0x4b6d
100#define VPFE_INTERLACED_NO_IMAGE_INVERT 0x0249
101#define VPFE_PROGRESSIVE_IMAGE_INVERT 0x4000
102#define VPFE_PROGRESSIVE_NO_IMAGE_INVERT 0
103#define VPFE_INTERLACED_HEIGHT_SHIFT 1
104#define VPFE_SYN_MODE_INPMOD_SHIFT 12
105#define VPFE_SYN_MODE_INPMOD_MASK 3
106#define VPFE_SYN_MODE_8BITS (7 << 8)
107#define VPFE_SYN_MODE_10BITS (6 << 8)
108#define VPFE_SYN_MODE_11BITS (5 << 8)
109#define VPFE_SYN_MODE_12BITS (4 << 8)
110#define VPFE_SYN_MODE_13BITS (3 << 8)
111#define VPFE_SYN_MODE_14BITS (2 << 8)
112#define VPFE_SYN_MODE_15BITS (1 << 8)
113#define VPFE_SYN_MODE_16BITS (0 << 8)
114#define VPFE_SYN_FLDMODE_MASK 1
115#define VPFE_SYN_FLDMODE_SHIFT 7
116#define VPFE_REC656IF_BT656_EN 3
117#define VPFE_SYN_MODE_VD_POL_NEGATIVE (1 << 2)
118#define VPFE_CCDCFG_Y8POS_SHIFT 11
119#define VPFE_CCDCFG_BW656_10BIT (1 << 5)
120#define VPFE_SDOFST_FIELD_INTERLEAVED 0x249
121#define VPFE_NO_CULLING 0xffff00ff
122#define VPFE_VDINT0 (1 << 0)
123#define VPFE_VDINT1 (1 << 1)
124#define VPFE_VDINT2 (1 << 2)
125#define VPFE_DMA_CNTL_OVERFLOW (1 << 31)
126
127#define VPFE_CONFIG_PCLK_INV_SHIFT 0
128#define VPFE_CONFIG_PCLK_INV_MASK 1
129#define VPFE_CONFIG_PCLK_INV_NOT_INV 0
130#define VPFE_CONFIG_PCLK_INV_INV 1
131#define VPFE_CONFIG_EN_SHIFT 1
132#define VPFE_CONFIG_EN_MASK 2
133#define VPFE_CONFIG_EN_DISABLE 0
134#define VPFE_CONFIG_EN_ENABLE 1
135#define VPFE_CONFIG_ST_SHIFT 2
136#define VPFE_CONFIG_ST_MASK 4
137#define VPFE_CONFIG_ST_OCP_ACTIVE 0
138#define VPFE_CONFIG_ST_OCP_STANDBY 1
139
140#endif /* AM437X_VPFE_REGS_H */
diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index b4029ae293d3..856b542b35b9 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -718,6 +718,7 @@ static int coda_start_encoding(struct coda_ctx *ctx)
718 struct vb2_buffer *buf; 718 struct vb2_buffer *buf;
719 int gamma, ret, value; 719 int gamma, ret, value;
720 u32 dst_fourcc; 720 u32 dst_fourcc;
721 int num_fb;
721 u32 stride; 722 u32 stride;
722 723
723 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT); 724 q_data_src = get_q_data(ctx, V4L2_BUF_TYPE_VIDEO_OUTPUT);
@@ -983,12 +984,14 @@ static int coda_start_encoding(struct coda_ctx *ctx)
983 v4l2_err(v4l2_dev, "failed to allocate framebuffers\n"); 984 v4l2_err(v4l2_dev, "failed to allocate framebuffers\n");
984 goto out; 985 goto out;
985 } 986 }
987 num_fb = 2;
986 stride = q_data_src->bytesperline; 988 stride = q_data_src->bytesperline;
987 } else { 989 } else {
988 ctx->num_internal_frames = 0; 990 ctx->num_internal_frames = 0;
991 num_fb = 0;
989 stride = 0; 992 stride = 0;
990 } 993 }
991 coda_write(dev, ctx->num_internal_frames, CODA_CMD_SET_FRAME_BUF_NUM); 994 coda_write(dev, num_fb, CODA_CMD_SET_FRAME_BUF_NUM);
992 coda_write(dev, stride, CODA_CMD_SET_FRAME_BUF_STRIDE); 995 coda_write(dev, stride, CODA_CMD_SET_FRAME_BUF_STRIDE);
993 996
994 if (dev->devtype->product == CODA_7541) { 997 if (dev->devtype->product == CODA_7541) {
@@ -1316,8 +1319,10 @@ static void coda_seq_end_work(struct work_struct *work)
1316 1319
1317static void coda_bit_release(struct coda_ctx *ctx) 1320static void coda_bit_release(struct coda_ctx *ctx)
1318{ 1321{
1322 mutex_lock(&ctx->buffer_mutex);
1319 coda_free_framebuffers(ctx); 1323 coda_free_framebuffers(ctx);
1320 coda_free_context_buffers(ctx); 1324 coda_free_context_buffers(ctx);
1325 mutex_unlock(&ctx->buffer_mutex);
1321} 1326}
1322 1327
1323const struct coda_context_ops coda_bit_encode_ops = { 1328const struct coda_context_ops coda_bit_encode_ops = {
@@ -1431,9 +1436,10 @@ static int __coda_start_decoding(struct coda_ctx *ctx)
1431 height = val & CODA7_PICHEIGHT_MASK; 1436 height = val & CODA7_PICHEIGHT_MASK;
1432 } 1437 }
1433 1438
1434 if (width > q_data_dst->width || height > q_data_dst->height) { 1439 if (width > q_data_dst->bytesperline || height > q_data_dst->height) {
1435 v4l2_err(&dev->v4l2_dev, "stream is %dx%d, not %dx%d\n", 1440 v4l2_err(&dev->v4l2_dev, "stream is %dx%d, not %dx%d\n",
1436 width, height, q_data_dst->width, q_data_dst->height); 1441 width, height, q_data_dst->bytesperline,
1442 q_data_dst->height);
1437 return -EINVAL; 1443 return -EINVAL;
1438 } 1444 }
1439 1445
@@ -1565,6 +1571,7 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
1565 struct vb2_buffer *dst_buf; 1571 struct vb2_buffer *dst_buf;
1566 struct coda_dev *dev = ctx->dev; 1572 struct coda_dev *dev = ctx->dev;
1567 struct coda_q_data *q_data_dst; 1573 struct coda_q_data *q_data_dst;
1574 struct coda_buffer_meta *meta;
1568 u32 reg_addr, reg_stride; 1575 u32 reg_addr, reg_stride;
1569 1576
1570 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); 1577 dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx);
@@ -1643,12 +1650,12 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
1643 coda_write(dev, ctx->iram_info.axi_sram_use, 1650 coda_write(dev, ctx->iram_info.axi_sram_use,
1644 CODA7_REG_BIT_AXI_SRAM_USE); 1651 CODA7_REG_BIT_AXI_SRAM_USE);
1645 1652
1646 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) { 1653 meta = list_first_entry_or_null(&ctx->buffer_meta_list,
1647 struct coda_buffer_meta *meta; 1654 struct coda_buffer_meta, list);
1655
1656 if (meta && ctx->codec->src_fourcc == V4L2_PIX_FMT_JPEG) {
1648 1657
1649 /* If this is the last buffer in the bitstream, add padding */ 1658 /* If this is the last buffer in the bitstream, add padding */
1650 meta = list_first_entry(&ctx->buffer_meta_list,
1651 struct coda_buffer_meta, list);
1652 if (meta->end == (ctx->bitstream_fifo.kfifo.in & 1659 if (meta->end == (ctx->bitstream_fifo.kfifo.in &
1653 ctx->bitstream_fifo.kfifo.mask)) { 1660 ctx->bitstream_fifo.kfifo.mask)) {
1654 static unsigned char buf[512]; 1661 static unsigned char buf[512];
@@ -1665,6 +1672,9 @@ static int coda_prepare_decode(struct coda_ctx *ctx)
1665 1672
1666 coda_kfifo_sync_to_device_full(ctx); 1673 coda_kfifo_sync_to_device_full(ctx);
1667 1674
1675 /* Clear decode success flag */
1676 coda_write(dev, 0, CODA_RET_DEC_PIC_SUCCESS);
1677
1668 coda_command_async(ctx, CODA_COMMAND_PIC_RUN); 1678 coda_command_async(ctx, CODA_COMMAND_PIC_RUN);
1669 1679
1670 return 0; 1680 return 0;
@@ -1821,6 +1831,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
1821 memset(&ctx->frame_metas[decoded_idx], 0, 1831 memset(&ctx->frame_metas[decoded_idx], 0,
1822 sizeof(struct coda_buffer_meta)); 1832 sizeof(struct coda_buffer_meta));
1823 ctx->frame_metas[decoded_idx].sequence = val; 1833 ctx->frame_metas[decoded_idx].sequence = val;
1834 ctx->sequence_offset++;
1824 } 1835 }
1825 mutex_unlock(&ctx->bitstream_mutex); 1836 mutex_unlock(&ctx->bitstream_mutex);
1826 1837
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 39330a70f752..6f32e6d6b156 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -37,6 +37,7 @@
37#include <media/v4l2-mem2mem.h> 37#include <media/v4l2-mem2mem.h>
38#include <media/videobuf2-core.h> 38#include <media/videobuf2-core.h>
39#include <media/videobuf2-dma-contig.h> 39#include <media/videobuf2-dma-contig.h>
40#include <media/videobuf2-vmalloc.h>
40 41
41#include "coda.h" 42#include "coda.h"
42 43
@@ -180,6 +181,7 @@ struct coda_video_device {
180 const char *name; 181 const char *name;
181 enum coda_inst_type type; 182 enum coda_inst_type type;
182 const struct coda_context_ops *ops; 183 const struct coda_context_ops *ops;
184 bool direct;
183 u32 src_formats[CODA_MAX_FORMATS]; 185 u32 src_formats[CODA_MAX_FORMATS];
184 u32 dst_formats[CODA_MAX_FORMATS]; 186 u32 dst_formats[CODA_MAX_FORMATS];
185}; 187};
@@ -468,6 +470,18 @@ static int coda_try_pixelformat(struct coda_ctx *ctx, struct v4l2_format *f)
468 return 0; 470 return 0;
469} 471}
470 472
473static unsigned int coda_estimate_sizeimage(struct coda_ctx *ctx, u32 sizeimage,
474 u32 width, u32 height)
475{
476 /*
477 * This is a rough estimate for sensible compressed buffer
478 * sizes (between 1 and 16 bits per pixel). This could be
479 * improved by better format specific worst case estimates.
480 */
481 return round_up(clamp(sizeimage, width * height / 8,
482 width * height * 2), PAGE_SIZE);
483}
484
471static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec, 485static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
472 struct v4l2_format *f) 486 struct v4l2_format *f)
473{ 487{
@@ -513,15 +527,10 @@ static int coda_try_fmt(struct coda_ctx *ctx, const struct coda_codec *codec,
513 case V4L2_PIX_FMT_H264: 527 case V4L2_PIX_FMT_H264:
514 case V4L2_PIX_FMT_MPEG4: 528 case V4L2_PIX_FMT_MPEG4:
515 f->fmt.pix.bytesperline = 0; 529 f->fmt.pix.bytesperline = 0;
516 /* 530 f->fmt.pix.sizeimage = coda_estimate_sizeimage(ctx,
517 * This is a rough estimate for sensible compressed buffer 531 f->fmt.pix.sizeimage,
518 * sizes (between 1 and 16 bits per pixel). This could be 532 f->fmt.pix.width,
519 * improved by better format specific worst case estimates. 533 f->fmt.pix.height);
520 */
521 f->fmt.pix.sizeimage = round_up(clamp(f->fmt.pix.sizeimage,
522 f->fmt.pix.width * f->fmt.pix.height / 8,
523 f->fmt.pix.width * f->fmt.pix.height * 2),
524 PAGE_SIZE);
525 break; 534 break;
526 default: 535 default:
527 BUG(); 536 BUG();
@@ -592,7 +601,11 @@ static int coda_try_fmt_vid_out(struct file *file, void *priv,
592 if (ret < 0) 601 if (ret < 0)
593 return ret; 602 return ret;
594 603
595 if (!f->fmt.pix.colorspace) { 604 switch (f->fmt.pix.colorspace) {
605 case V4L2_COLORSPACE_REC709:
606 case V4L2_COLORSPACE_JPEG:
607 break;
608 default:
596 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG) 609 if (f->fmt.pix.pixelformat == V4L2_PIX_FMT_JPEG)
597 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG; 610 f->fmt.pix.colorspace = V4L2_COLORSPACE_JPEG;
598 else 611 else
@@ -670,6 +683,7 @@ static int coda_s_fmt_vid_out(struct file *file, void *priv,
670 683
671 ctx->colorspace = f->fmt.pix.colorspace; 684 ctx->colorspace = f->fmt.pix.colorspace;
672 685
686 memset(&f_cap, 0, sizeof(f_cap));
673 f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 687 f_cap.type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
674 coda_g_fmt(file, priv, &f_cap); 688 coda_g_fmt(file, priv, &f_cap);
675 f_cap.fmt.pix.width = f->fmt.pix.width; 689 f_cap.fmt.pix.width = f->fmt.pix.width;
@@ -908,7 +922,8 @@ static void coda_pic_run_work(struct work_struct *work)
908 ctx->ops->finish_run(ctx); 922 ctx->ops->finish_run(ctx);
909 } 923 }
910 924
911 if (ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) 925 if ((ctx->aborting || (!ctx->streamon_cap && !ctx->streamon_out)) &&
926 ctx->ops->seq_end_work)
912 queue_work(dev->workqueue, &ctx->seq_end_work); 927 queue_work(dev->workqueue, &ctx->seq_end_work);
913 928
914 mutex_unlock(&dev->coda_mutex); 929 mutex_unlock(&dev->coda_mutex);
@@ -939,15 +954,43 @@ static int coda_job_ready(void *m2m_priv)
939 return 0; 954 return 0;
940 } 955 }
941 956
942 if (ctx->hold || 957 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit) {
943 ((ctx->inst_type == CODA_INST_DECODER) && 958 struct list_head *meta;
944 !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) && 959 bool stream_end;
945 (coda_get_bitstream_payload(ctx) < 512) && 960 int num_metas;
946 !(ctx->bit_stream_param & CODA_BIT_STREAM_END_FLAG))) { 961 int src_bufs;
947 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 962
948 "%d: not ready: not enough bitstream data.\n", 963 if (ctx->hold && !v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx)) {
949 ctx->idx); 964 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
950 return 0; 965 "%d: not ready: on hold for more buffers.\n",
966 ctx->idx);
967 return 0;
968 }
969
970 stream_end = ctx->bit_stream_param &
971 CODA_BIT_STREAM_END_FLAG;
972
973 num_metas = 0;
974 list_for_each(meta, &ctx->buffer_meta_list)
975 num_metas++;
976
977 src_bufs = v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx);
978
979 if (!stream_end && (num_metas + src_bufs) < 2) {
980 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
981 "%d: not ready: need 2 buffers available (%d, %d)\n",
982 ctx->idx, num_metas, src_bufs);
983 return 0;
984 }
985
986
987 if (!v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) &&
988 !stream_end && (coda_get_bitstream_payload(ctx) < 512)) {
989 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
990 "%d: not ready: not enough bitstream data (%d).\n",
991 ctx->idx, coda_get_bitstream_payload(ctx));
992 return 0;
993 }
951 } 994 }
952 995
953 if (ctx->aborting) { 996 if (ctx->aborting) {
@@ -1023,13 +1066,14 @@ static void coda_set_tiled_map_type(struct coda_ctx *ctx, int tiled_map_type)
1023 1066
1024static void set_default_params(struct coda_ctx *ctx) 1067static void set_default_params(struct coda_ctx *ctx)
1025{ 1068{
1026 unsigned int max_w, max_h, size; 1069 unsigned int max_w, max_h, usize, csize;
1027 1070
1028 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0], 1071 ctx->codec = coda_find_codec(ctx->dev, ctx->cvd->src_formats[0],
1029 ctx->cvd->dst_formats[0]); 1072 ctx->cvd->dst_formats[0]);
1030 max_w = min(ctx->codec->max_w, 1920U); 1073 max_w = min(ctx->codec->max_w, 1920U);
1031 max_h = min(ctx->codec->max_h, 1088U); 1074 max_h = min(ctx->codec->max_h, 1088U);
1032 size = max_w * max_h * 3 / 2; 1075 usize = max_w * max_h * 3 / 2;
1076 csize = coda_estimate_sizeimage(ctx, usize, max_w, max_h);
1033 1077
1034 ctx->params.codec_mode = ctx->codec->mode; 1078 ctx->params.codec_mode = ctx->codec->mode;
1035 ctx->colorspace = V4L2_COLORSPACE_REC709; 1079 ctx->colorspace = V4L2_COLORSPACE_REC709;
@@ -1044,14 +1088,14 @@ static void set_default_params(struct coda_ctx *ctx)
1044 ctx->q_data[V4L2_M2M_DST].height = max_h; 1088 ctx->q_data[V4L2_M2M_DST].height = max_h;
1045 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) { 1089 if (ctx->codec->src_fourcc == V4L2_PIX_FMT_YUV420) {
1046 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w; 1090 ctx->q_data[V4L2_M2M_SRC].bytesperline = max_w;
1047 ctx->q_data[V4L2_M2M_SRC].sizeimage = size; 1091 ctx->q_data[V4L2_M2M_SRC].sizeimage = usize;
1048 ctx->q_data[V4L2_M2M_DST].bytesperline = 0; 1092 ctx->q_data[V4L2_M2M_DST].bytesperline = 0;
1049 ctx->q_data[V4L2_M2M_DST].sizeimage = round_up(size, PAGE_SIZE); 1093 ctx->q_data[V4L2_M2M_DST].sizeimage = csize;
1050 } else { 1094 } else {
1051 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0; 1095 ctx->q_data[V4L2_M2M_SRC].bytesperline = 0;
1052 ctx->q_data[V4L2_M2M_SRC].sizeimage = round_up(size, PAGE_SIZE); 1096 ctx->q_data[V4L2_M2M_SRC].sizeimage = csize;
1053 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w; 1097 ctx->q_data[V4L2_M2M_DST].bytesperline = max_w;
1054 ctx->q_data[V4L2_M2M_DST].sizeimage = size; 1098 ctx->q_data[V4L2_M2M_DST].sizeimage = usize;
1055 } 1099 }
1056 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w; 1100 ctx->q_data[V4L2_M2M_SRC].rect.width = max_w;
1057 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h; 1101 ctx->q_data[V4L2_M2M_SRC].rect.height = max_h;
@@ -1080,6 +1124,7 @@ static int coda_queue_setup(struct vb2_queue *vq,
1080 *nplanes = 1; 1124 *nplanes = 1;
1081 sizes[0] = size; 1125 sizes[0] = size;
1082 1126
1127 /* Set to vb2-dma-contig allocator context, ignored by vb2-vmalloc */
1083 alloc_ctxs[0] = ctx->dev->alloc_ctx; 1128 alloc_ctxs[0] = ctx->dev->alloc_ctx;
1084 1129
1085 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev, 1130 v4l2_dbg(1, coda_debug, &ctx->dev->v4l2_dev,
@@ -1109,6 +1154,7 @@ static int coda_buf_prepare(struct vb2_buffer *vb)
1109static void coda_buf_queue(struct vb2_buffer *vb) 1154static void coda_buf_queue(struct vb2_buffer *vb)
1110{ 1155{
1111 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1156 struct coda_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1157 struct vb2_queue *vq = vb->vb2_queue;
1112 struct coda_q_data *q_data; 1158 struct coda_q_data *q_data;
1113 1159
1114 q_data = get_q_data(ctx, vb->vb2_queue->type); 1160 q_data = get_q_data(ctx, vb->vb2_queue->type);
@@ -1117,8 +1163,7 @@ static void coda_buf_queue(struct vb2_buffer *vb)
1117 * In the decoder case, immediately try to copy the buffer into the 1163 * In the decoder case, immediately try to copy the buffer into the
1118 * bitstream ringbuffer and mark it as ready to be dequeued. 1164 * bitstream ringbuffer and mark it as ready to be dequeued.
1119 */ 1165 */
1120 if (ctx->inst_type == CODA_INST_DECODER && 1166 if (ctx->bitstream.size && vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1121 vb->vb2_queue->type == V4L2_BUF_TYPE_VIDEO_OUTPUT) {
1122 /* 1167 /*
1123 * For backwards compatibility, queuing an empty buffer marks 1168 * For backwards compatibility, queuing an empty buffer marks
1124 * the stream end 1169 * the stream end
@@ -1218,7 +1263,7 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
1218 return 0; 1263 return 0;
1219 1264
1220 /* Allow BIT decoder device_run with no new buffers queued */ 1265 /* Allow BIT decoder device_run with no new buffers queued */
1221 if (ctx->inst_type == CODA_INST_DECODER) 1266 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
1222 v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true); 1267 v4l2_m2m_set_src_buffered(ctx->fh.m2m_ctx, true);
1223 1268
1224 ctx->gopcounter = ctx->params.gop_size - 1; 1269 ctx->gopcounter = ctx->params.gop_size - 1;
@@ -1271,7 +1316,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
1271 1316
1272 coda_bit_stream_end_flag(ctx); 1317 coda_bit_stream_end_flag(ctx);
1273 1318
1274 ctx->isequence = 0; 1319 ctx->qsequence = 0;
1275 1320
1276 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx))) 1321 while ((buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx)))
1277 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR); 1322 v4l2_m2m_buf_done(buf, VB2_BUF_STATE_ERROR);
@@ -1290,6 +1335,10 @@ static void coda_stop_streaming(struct vb2_queue *q)
1290 if (!ctx->streamon_out && !ctx->streamon_cap) { 1335 if (!ctx->streamon_out && !ctx->streamon_cap) {
1291 struct coda_buffer_meta *meta; 1336 struct coda_buffer_meta *meta;
1292 1337
1338 if (ctx->ops->seq_end_work) {
1339 queue_work(dev->workqueue, &ctx->seq_end_work);
1340 flush_work(&ctx->seq_end_work);
1341 }
1293 mutex_lock(&ctx->bitstream_mutex); 1342 mutex_lock(&ctx->bitstream_mutex);
1294 while (!list_empty(&ctx->buffer_meta_list)) { 1343 while (!list_empty(&ctx->buffer_meta_list)) {
1295 meta = list_first_entry(&ctx->buffer_meta_list, 1344 meta = list_first_entry(&ctx->buffer_meta_list,
@@ -1300,6 +1349,7 @@ static void coda_stop_streaming(struct vb2_queue *q)
1300 mutex_unlock(&ctx->bitstream_mutex); 1349 mutex_unlock(&ctx->bitstream_mutex);
1301 kfifo_init(&ctx->bitstream_fifo, 1350 kfifo_init(&ctx->bitstream_fifo,
1302 ctx->bitstream.vaddr, ctx->bitstream.size); 1351 ctx->bitstream.vaddr, ctx->bitstream.size);
1352 ctx->initialized = 0;
1303 ctx->runcounter = 0; 1353 ctx->runcounter = 0;
1304 ctx->aborting = 0; 1354 ctx->aborting = 0;
1305 } 1355 }
@@ -1521,8 +1571,8 @@ int coda_decoder_queue_init(void *priv, struct vb2_queue *src_vq,
1521 int ret; 1571 int ret;
1522 1572
1523 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 1573 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
1524 src_vq->io_modes = VB2_DMABUF | VB2_MMAP; 1574 src_vq->io_modes = VB2_DMABUF | VB2_MMAP | VB2_USERPTR;
1525 src_vq->mem_ops = &vb2_dma_contig_memops; 1575 src_vq->mem_ops = &vb2_vmalloc_memops;
1526 1576
1527 ret = coda_queue_init(priv, src_vq); 1577 ret = coda_queue_init(priv, src_vq);
1528 if (ret) 1578 if (ret)
@@ -1577,9 +1627,11 @@ static int coda_open(struct file *file)
1577 ctx->cvd = to_coda_video_device(vdev); 1627 ctx->cvd = to_coda_video_device(vdev);
1578 ctx->inst_type = ctx->cvd->type; 1628 ctx->inst_type = ctx->cvd->type;
1579 ctx->ops = ctx->cvd->ops; 1629 ctx->ops = ctx->cvd->ops;
1630 ctx->use_bit = !ctx->cvd->direct;
1580 init_completion(&ctx->completion); 1631 init_completion(&ctx->completion);
1581 INIT_WORK(&ctx->pic_run_work, coda_pic_run_work); 1632 INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
1582 INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work); 1633 if (ctx->ops->seq_end_work)
1634 INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
1583 v4l2_fh_init(&ctx->fh, video_devdata(file)); 1635 v4l2_fh_init(&ctx->fh, video_devdata(file));
1584 file->private_data = &ctx->fh; 1636 file->private_data = &ctx->fh;
1585 v4l2_fh_add(&ctx->fh); 1637 v4l2_fh_add(&ctx->fh);
@@ -1630,22 +1682,25 @@ static int coda_open(struct file *file)
1630 1682
1631 ctx->fh.ctrl_handler = &ctx->ctrls; 1683 ctx->fh.ctrl_handler = &ctx->ctrls;
1632 1684
1633 ret = coda_alloc_context_buf(ctx, &ctx->parabuf, 1685 if (ctx->use_bit) {
1634 CODA_PARA_BUF_SIZE, "parabuf"); 1686 ret = coda_alloc_context_buf(ctx, &ctx->parabuf,
1635 if (ret < 0) { 1687 CODA_PARA_BUF_SIZE, "parabuf");
1636 v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf"); 1688 if (ret < 0) {
1637 goto err_dma_alloc; 1689 v4l2_err(&dev->v4l2_dev, "failed to allocate parabuf");
1690 goto err_dma_alloc;
1691 }
1638 } 1692 }
1639 1693 if (ctx->use_bit && ctx->inst_type == CODA_INST_DECODER) {
1640 ctx->bitstream.size = CODA_MAX_FRAME_SIZE; 1694 ctx->bitstream.size = CODA_MAX_FRAME_SIZE;
1641 ctx->bitstream.vaddr = dma_alloc_writecombine( 1695 ctx->bitstream.vaddr = dma_alloc_writecombine(
1642 &dev->plat_dev->dev, ctx->bitstream.size, 1696 &dev->plat_dev->dev, ctx->bitstream.size,
1643 &ctx->bitstream.paddr, GFP_KERNEL); 1697 &ctx->bitstream.paddr, GFP_KERNEL);
1644 if (!ctx->bitstream.vaddr) { 1698 if (!ctx->bitstream.vaddr) {
1645 v4l2_err(&dev->v4l2_dev, 1699 v4l2_err(&dev->v4l2_dev,
1646 "failed to allocate bitstream ringbuffer"); 1700 "failed to allocate bitstream ringbuffer");
1647 ret = -ENOMEM; 1701 ret = -ENOMEM;
1648 goto err_dma_writecombine; 1702 goto err_dma_writecombine;
1703 }
1649 } 1704 }
1650 kfifo_init(&ctx->bitstream_fifo, 1705 kfifo_init(&ctx->bitstream_fifo,
1651 ctx->bitstream.vaddr, ctx->bitstream.size); 1706 ctx->bitstream.vaddr, ctx->bitstream.size);
@@ -1693,16 +1748,14 @@ static int coda_release(struct file *file)
1693 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n", 1748 v4l2_dbg(1, coda_debug, &dev->v4l2_dev, "Releasing instance %p\n",
1694 ctx); 1749 ctx);
1695 1750
1696 debugfs_remove_recursive(ctx->debugfs_entry); 1751 if (ctx->inst_type == CODA_INST_DECODER && ctx->use_bit)
1697
1698 if (ctx->inst_type == CODA_INST_DECODER)
1699 coda_bit_stream_end_flag(ctx); 1752 coda_bit_stream_end_flag(ctx);
1700 1753
1701 /* If this instance is running, call .job_abort and wait for it to end */ 1754 /* If this instance is running, call .job_abort and wait for it to end */
1702 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx); 1755 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
1703 1756
1704 /* In case the instance was not running, we still need to call SEQ_END */ 1757 /* In case the instance was not running, we still need to call SEQ_END */
1705 if (ctx->initialized) { 1758 if (ctx->initialized && ctx->ops->seq_end_work) {
1706 queue_work(dev->workqueue, &ctx->seq_end_work); 1759 queue_work(dev->workqueue, &ctx->seq_end_work);
1707 flush_work(&ctx->seq_end_work); 1760 flush_work(&ctx->seq_end_work);
1708 } 1761 }
@@ -1728,6 +1781,7 @@ static int coda_release(struct file *file)
1728 clear_bit(ctx->idx, &dev->instance_mask); 1781 clear_bit(ctx->idx, &dev->instance_mask);
1729 if (ctx->ops->release) 1782 if (ctx->ops->release)
1730 ctx->ops->release(ctx); 1783 ctx->ops->release(ctx);
1784 debugfs_remove_recursive(ctx->debugfs_entry);
1731 kfree(ctx); 1785 kfree(ctx);
1732 1786
1733 return 0; 1787 return 0;
@@ -1844,10 +1898,11 @@ static int coda_register_device(struct coda_dev *dev, int i)
1844{ 1898{
1845 struct video_device *vfd = &dev->vfd[i]; 1899 struct video_device *vfd = &dev->vfd[i];
1846 1900
1847 if (i > ARRAY_SIZE(dev->vfd)) 1901 if (i >= dev->devtype->num_vdevs)
1848 return -EINVAL; 1902 return -EINVAL;
1849 1903
1850 snprintf(vfd->name, sizeof(vfd->name), dev->devtype->vdevs[i]->name); 1904 snprintf(vfd->name, sizeof(vfd->name), "%s",
1905 dev->devtype->vdevs[i]->name);
1851 vfd->fops = &coda_fops; 1906 vfd->fops = &coda_fops;
1852 vfd->ioctl_ops = &coda_ioctl_ops; 1907 vfd->ioctl_ops = &coda_ioctl_ops;
1853 vfd->release = video_device_release_empty, 1908 vfd->release = video_device_release_empty,
@@ -2001,7 +2056,6 @@ static const struct coda_devtype coda_devdata[] = {
2001 2056
2002static struct platform_device_id coda_platform_ids[] = { 2057static struct platform_device_id coda_platform_ids[] = {
2003 { .name = "coda-imx27", .driver_data = CODA_IMX27 }, 2058 { .name = "coda-imx27", .driver_data = CODA_IMX27 },
2004 { .name = "coda-imx53", .driver_data = CODA_IMX53 },
2005 { /* sentinel */ } 2059 { /* sentinel */ }
2006}; 2060};
2007MODULE_DEVICE_TABLE(platform, coda_platform_ids); 2061MODULE_DEVICE_TABLE(platform, coda_platform_ids);
@@ -2142,6 +2196,7 @@ static int coda_probe(struct platform_device *pdev)
2142 if (!dev->iram.vaddr) { 2196 if (!dev->iram.vaddr) {
2143 dev_warn(&pdev->dev, "unable to alloc iram\n"); 2197 dev_warn(&pdev->dev, "unable to alloc iram\n");
2144 } else { 2198 } else {
2199 memset(dev->iram.vaddr, 0, dev->iram.size);
2145 dev->iram.blob.data = dev->iram.vaddr; 2200 dev->iram.blob.data = dev->iram.vaddr;
2146 dev->iram.blob.size = dev->iram.size; 2201 dev->iram.blob.size = dev->iram.size;
2147 dev->iram.dentry = debugfs_create_blob("iram", 0644, 2202 dev->iram.dentry = debugfs_create_blob("iram", 0644,
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 5dd47e5f97c1..0c35cd5032ff 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -198,7 +198,6 @@ struct coda_ctx {
198 int initialized; 198 int initialized;
199 int streamon_out; 199 int streamon_out;
200 int streamon_cap; 200 int streamon_cap;
201 u32 isequence;
202 u32 qsequence; 201 u32 qsequence;
203 u32 osequence; 202 u32 osequence;
204 u32 sequence_offset; 203 u32 sequence_offset;
@@ -236,6 +235,7 @@ struct coda_ctx {
236 u32 frame_mem_ctrl; 235 u32 frame_mem_ctrl;
237 int display_idx; 236 int display_idx;
238 struct dentry *debugfs_entry; 237 struct dentry *debugfs_entry;
238 bool use_bit;
239}; 239};
240 240
241extern int coda_debug; 241extern int coda_debug;
diff --git a/drivers/media/platform/coda/coda_regs.h b/drivers/media/platform/coda/coda_regs.h
index 8e015b8aa8fa..7d026241171b 100644
--- a/drivers/media/platform/coda/coda_regs.h
+++ b/drivers/media/platform/coda/coda_regs.h
@@ -304,9 +304,9 @@
304#define CODA_RATECONTROL_AUTOSKIP_OFFSET 31 304#define CODA_RATECONTROL_AUTOSKIP_OFFSET 31
305#define CODA_RATECONTROL_AUTOSKIP_MASK 0x01 305#define CODA_RATECONTROL_AUTOSKIP_MASK 0x01
306#define CODA_RATECONTROL_INITIALDELAY_OFFSET 16 306#define CODA_RATECONTROL_INITIALDELAY_OFFSET 16
307#define CODA_RATECONTROL_INITIALDELAY_MASK 0x7f 307#define CODA_RATECONTROL_INITIALDELAY_MASK 0x7fff
308#define CODA_RATECONTROL_BITRATE_OFFSET 1 308#define CODA_RATECONTROL_BITRATE_OFFSET 1
309#define CODA_RATECONTROL_BITRATE_MASK 0x7f 309#define CODA_RATECONTROL_BITRATE_MASK 0x7fff
310#define CODA_RATECONTROL_ENABLE_OFFSET 0 310#define CODA_RATECONTROL_ENABLE_OFFSET 0
311#define CODA_RATECONTROL_ENABLE_MASK 0x01 311#define CODA_RATECONTROL_ENABLE_MASK 0x01
312#define CODA_CMD_ENC_SEQ_RC_BUF_SIZE 0x1b0 312#define CODA_CMD_ENC_SEQ_RC_BUF_SIZE 0x1b0
diff --git a/drivers/media/platform/davinci/Kconfig b/drivers/media/platform/davinci/Kconfig
index d9e1ddb586b1..469e9d28cec0 100644
--- a/drivers/media/platform/davinci/Kconfig
+++ b/drivers/media/platform/davinci/Kconfig
@@ -1,6 +1,6 @@
1config VIDEO_DAVINCI_VPIF_DISPLAY 1config VIDEO_DAVINCI_VPIF_DISPLAY
2 tristate "TI DaVinci VPIF V4L2-Display driver" 2 tristate "TI DaVinci VPIF V4L2-Display driver"
3 depends on VIDEO_DEV 3 depends on VIDEO_V4L2
4 depends on ARCH_DAVINCI || COMPILE_TEST 4 depends on ARCH_DAVINCI || COMPILE_TEST
5 depends on HAS_DMA 5 depends on HAS_DMA
6 select VIDEOBUF2_DMA_CONTIG 6 select VIDEOBUF2_DMA_CONTIG
@@ -16,7 +16,7 @@ config VIDEO_DAVINCI_VPIF_DISPLAY
16 16
17config VIDEO_DAVINCI_VPIF_CAPTURE 17config VIDEO_DAVINCI_VPIF_CAPTURE
18 tristate "TI DaVinci VPIF video capture driver" 18 tristate "TI DaVinci VPIF video capture driver"
19 depends on VIDEO_DEV 19 depends on VIDEO_V4L2
20 depends on ARCH_DAVINCI || COMPILE_TEST 20 depends on ARCH_DAVINCI || COMPILE_TEST
21 depends on HAS_DMA 21 depends on HAS_DMA
22 select VIDEOBUF2_DMA_CONTIG 22 select VIDEOBUF2_DMA_CONTIG
@@ -75,7 +75,7 @@ config VIDEO_DM365_ISIF
75 75
76config VIDEO_DAVINCI_VPBE_DISPLAY 76config VIDEO_DAVINCI_VPBE_DISPLAY
77 tristate "TI DaVinci VPBE V4L2-Display driver" 77 tristate "TI DaVinci VPBE V4L2-Display driver"
78 depends on ARCH_DAVINCI 78 depends on VIDEO_V4L2 && ARCH_DAVINCI
79 depends on HAS_DMA 79 depends on HAS_DMA
80 select VIDEOBUF2_DMA_CONTIG 80 select VIDEOBUF2_DMA_CONTIG
81 help 81 help
diff --git a/drivers/media/platform/exynos-gsc/gsc-core.h b/drivers/media/platform/exynos-gsc/gsc-core.h
index 0abdb17fb19c..fa572aacdb3f 100644
--- a/drivers/media/platform/exynos-gsc/gsc-core.h
+++ b/drivers/media/platform/exynos-gsc/gsc-core.h
@@ -466,18 +466,6 @@ static inline void gsc_hw_clear_irq(struct gsc_dev *dev, int irq)
466 writel(cfg, dev->regs + GSC_IRQ); 466 writel(cfg, dev->regs + GSC_IRQ);
467} 467}
468 468
469static inline void gsc_lock(struct vb2_queue *vq)
470{
471 struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
472 mutex_lock(&ctx->gsc_dev->lock);
473}
474
475static inline void gsc_unlock(struct vb2_queue *vq)
476{
477 struct gsc_ctx *ctx = vb2_get_drv_priv(vq);
478 mutex_unlock(&ctx->gsc_dev->lock);
479}
480
481static inline bool gsc_ctx_state_is_set(u32 mask, struct gsc_ctx *ctx) 469static inline bool gsc_ctx_state_is_set(u32 mask, struct gsc_ctx *ctx)
482{ 470{
483 unsigned long flags; 471 unsigned long flags;
diff --git a/drivers/media/platform/exynos-gsc/gsc-m2m.c b/drivers/media/platform/exynos-gsc/gsc-m2m.c
index 74e1de637e8f..d5cffef2e227 100644
--- a/drivers/media/platform/exynos-gsc/gsc-m2m.c
+++ b/drivers/media/platform/exynos-gsc/gsc-m2m.c
@@ -267,8 +267,8 @@ static struct vb2_ops gsc_m2m_qops = {
267 .queue_setup = gsc_m2m_queue_setup, 267 .queue_setup = gsc_m2m_queue_setup,
268 .buf_prepare = gsc_m2m_buf_prepare, 268 .buf_prepare = gsc_m2m_buf_prepare,
269 .buf_queue = gsc_m2m_buf_queue, 269 .buf_queue = gsc_m2m_buf_queue,
270 .wait_prepare = gsc_unlock, 270 .wait_prepare = vb2_ops_wait_prepare,
271 .wait_finish = gsc_lock, 271 .wait_finish = vb2_ops_wait_finish,
272 .stop_streaming = gsc_m2m_stop_streaming, 272 .stop_streaming = gsc_m2m_stop_streaming,
273 .start_streaming = gsc_m2m_start_streaming, 273 .start_streaming = gsc_m2m_start_streaming,
274}; 274};
@@ -590,6 +590,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
590 src_vq->mem_ops = &vb2_dma_contig_memops; 590 src_vq->mem_ops = &vb2_dma_contig_memops;
591 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 591 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
592 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 592 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
593 src_vq->lock = &ctx->gsc_dev->lock;
593 594
594 ret = vb2_queue_init(src_vq); 595 ret = vb2_queue_init(src_vq);
595 if (ret) 596 if (ret)
@@ -603,6 +604,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
603 dst_vq->mem_ops = &vb2_dma_contig_memops; 604 dst_vq->mem_ops = &vb2_dma_contig_memops;
604 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 605 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
605 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 606 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
607 dst_vq->lock = &ctx->gsc_dev->lock;
606 608
607 return vb2_queue_init(dst_vq); 609 return vb2_queue_init(dst_vq);
608} 610}
diff --git a/drivers/media/platform/marvell-ccic/Kconfig b/drivers/media/platform/marvell-ccic/Kconfig
index 6265d36adceb..4bf5bd1e90d6 100644
--- a/drivers/media/platform/marvell-ccic/Kconfig
+++ b/drivers/media/platform/marvell-ccic/Kconfig
@@ -5,6 +5,7 @@ config VIDEO_CAFE_CCIC
5 select VIDEO_OV7670 5 select VIDEO_OV7670
6 select VIDEOBUF2_VMALLOC 6 select VIDEOBUF2_VMALLOC
7 select VIDEOBUF2_DMA_CONTIG 7 select VIDEOBUF2_DMA_CONTIG
8 select VIDEOBUF2_DMA_SG
8 ---help--- 9 ---help---
9 This is a video4linux2 driver for the Marvell 88ALP01 integrated 10 This is a video4linux2 driver for the Marvell 88ALP01 integrated
10 CMOS camera controller. This is the controller found on first- 11 CMOS camera controller. This is the controller found on first-
@@ -13,7 +14,7 @@ config VIDEO_CAFE_CCIC
13config VIDEO_MMP_CAMERA 14config VIDEO_MMP_CAMERA
14 tristate "Marvell Armada 610 integrated camera controller support" 15 tristate "Marvell Armada 610 integrated camera controller support"
15 depends on ARCH_MMP && I2C && VIDEO_V4L2 16 depends on ARCH_MMP && I2C && VIDEO_V4L2
16 depends on HAS_DMA 17 depends on HAS_DMA && BROKEN
17 select VIDEO_OV7670 18 select VIDEO_OV7670
18 select I2C_GPIO 19 select I2C_GPIO
19 select VIDEOBUF2_DMA_SG 20 select VIDEOBUF2_DMA_SG
diff --git a/drivers/media/platform/marvell-ccic/mcam-core.c b/drivers/media/platform/marvell-ccic/mcam-core.c
index 193373ff268d..dd5b1415f974 100644
--- a/drivers/media/platform/marvell-ccic/mcam-core.c
+++ b/drivers/media/platform/marvell-ccic/mcam-core.c
@@ -1913,7 +1913,6 @@ int mccic_register(struct mcam_camera *cam)
1913 1913
1914 mutex_lock(&cam->s_mutex); 1914 mutex_lock(&cam->s_mutex);
1915 cam->vdev = mcam_v4l_template; 1915 cam->vdev = mcam_v4l_template;
1916 cam->vdev.debug = 0;
1917 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1916 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1918 video_set_drvdata(&cam->vdev, cam); 1917 video_set_drvdata(&cam->vdev, cam);
1919 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1); 1918 ret = video_register_device(&cam->vdev, VFL_TYPE_GRABBER, -1);
diff --git a/drivers/media/platform/omap3isp/isp.c b/drivers/media/platform/omap3isp/isp.c
index 51c2129bdcc6..deca80903c3a 100644
--- a/drivers/media/platform/omap3isp/isp.c
+++ b/drivers/media/platform/omap3isp/isp.c
@@ -220,6 +220,9 @@ static u32 isp_xclk_calc_divider(unsigned long *rate, unsigned long parent_rate)
220 return ISPTCTRL_CTRL_DIV_BYPASS; 220 return ISPTCTRL_CTRL_DIV_BYPASS;
221 } 221 }
222 222
223 if (*rate == 0)
224 *rate = 1;
225
223 divider = DIV_ROUND_CLOSEST(parent_rate, *rate); 226 divider = DIV_ROUND_CLOSEST(parent_rate, *rate);
224 if (divider >= ISPTCTRL_CTRL_DIV_BYPASS) 227 if (divider >= ISPTCTRL_CTRL_DIV_BYPASS)
225 divider = ISPTCTRL_CTRL_DIV_BYPASS - 1; 228 divider = ISPTCTRL_CTRL_DIV_BYPASS - 1;
diff --git a/drivers/media/platform/s3c-camif/camif-capture.c b/drivers/media/platform/s3c-camif/camif-capture.c
index aa40c8269ab8..54479d60cc0d 100644
--- a/drivers/media/platform/s3c-camif/camif-capture.c
+++ b/drivers/media/platform/s3c-camif/camif-capture.c
@@ -536,24 +536,12 @@ static void buffer_queue(struct vb2_buffer *vb)
536 spin_unlock_irqrestore(&camif->slock, flags); 536 spin_unlock_irqrestore(&camif->slock, flags);
537} 537}
538 538
539static void camif_lock(struct vb2_queue *vq)
540{
541 struct camif_vp *vp = vb2_get_drv_priv(vq);
542 mutex_lock(&vp->camif->lock);
543}
544
545static void camif_unlock(struct vb2_queue *vq)
546{
547 struct camif_vp *vp = vb2_get_drv_priv(vq);
548 mutex_unlock(&vp->camif->lock);
549}
550
551static const struct vb2_ops s3c_camif_qops = { 539static const struct vb2_ops s3c_camif_qops = {
552 .queue_setup = queue_setup, 540 .queue_setup = queue_setup,
553 .buf_prepare = buffer_prepare, 541 .buf_prepare = buffer_prepare,
554 .buf_queue = buffer_queue, 542 .buf_queue = buffer_queue,
555 .wait_prepare = camif_unlock, 543 .wait_prepare = vb2_ops_wait_prepare,
556 .wait_finish = camif_lock, 544 .wait_finish = vb2_ops_wait_finish,
557 .start_streaming = start_streaming, 545 .start_streaming = start_streaming,
558 .stop_streaming = stop_streaming, 546 .stop_streaming = stop_streaming,
559}; 547};
@@ -1161,6 +1149,7 @@ int s3c_camif_register_video_node(struct camif_dev *camif, int idx)
1161 q->buf_struct_size = sizeof(struct camif_buffer); 1149 q->buf_struct_size = sizeof(struct camif_buffer);
1162 q->drv_priv = vp; 1150 q->drv_priv = vp;
1163 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1151 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1152 q->lock = &vp->camif->lock;
1164 1153
1165 ret = vb2_queue_init(q); 1154 ret = vb2_queue_init(q);
1166 if (ret) 1155 if (ret)
diff --git a/drivers/media/platform/s5p-g2d/g2d.c b/drivers/media/platform/s5p-g2d/g2d.c
index 47ba8fbb0426..ec3e1248923d 100644
--- a/drivers/media/platform/s5p-g2d/g2d.c
+++ b/drivers/media/platform/s5p-g2d/g2d.c
@@ -12,7 +12,6 @@
12 12
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/fs.h> 14#include <linux/fs.h>
15#include <linux/version.h>
16#include <linux/timer.h> 15#include <linux/timer.h>
17#include <linux/sched.h> 16#include <linux/sched.h>
18#include <linux/slab.h> 17#include <linux/slab.h>
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc.c b/drivers/media/platform/s5p-mfc/s5p_mfc.c
index fbfdf03b9054..8e44a59d8ec2 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc.c
@@ -810,6 +810,7 @@ static int s5p_mfc_open(struct file *file)
810 q = &ctx->vq_dst; 810 q = &ctx->vq_dst;
811 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; 811 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE;
812 q->drv_priv = &ctx->fh; 812 q->drv_priv = &ctx->fh;
813 q->lock = &dev->mfc_mutex;
813 if (vdev == dev->vfd_dec) { 814 if (vdev == dev->vfd_dec) {
814 q->io_modes = VB2_MMAP; 815 q->io_modes = VB2_MMAP;
815 q->ops = get_dec_queue_ops(); 816 q->ops = get_dec_queue_ops();
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
index c6c3452ccca1..aebe4fd7f03a 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_dec.c
@@ -18,7 +18,6 @@
18#include <linux/platform_device.h> 18#include <linux/platform_device.h>
19#include <linux/sched.h> 19#include <linux/sched.h>
20#include <linux/slab.h> 20#include <linux/slab.h>
21#include <linux/version.h>
22#include <linux/videodev2.h> 21#include <linux/videodev2.h>
23#include <linux/workqueue.h> 22#include <linux/workqueue.h>
24#include <media/v4l2-ctrls.h> 23#include <media/v4l2-ctrls.h>
@@ -813,7 +812,7 @@ static int vidioc_decoder_cmd(struct file *file, void *priv,
813 unsigned long flags; 812 unsigned long flags;
814 813
815 switch (cmd->cmd) { 814 switch (cmd->cmd) {
816 case V4L2_ENC_CMD_STOP: 815 case V4L2_DEC_CMD_STOP:
817 if (cmd->flags != 0) 816 if (cmd->flags != 0)
818 return -EINVAL; 817 return -EINVAL;
819 818
@@ -944,22 +943,6 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
944 return 0; 943 return 0;
945} 944}
946 945
947static void s5p_mfc_unlock(struct vb2_queue *q)
948{
949 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
950 struct s5p_mfc_dev *dev = ctx->dev;
951
952 mutex_unlock(&dev->mfc_mutex);
953}
954
955static void s5p_mfc_lock(struct vb2_queue *q)
956{
957 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
958 struct s5p_mfc_dev *dev = ctx->dev;
959
960 mutex_lock(&dev->mfc_mutex);
961}
962
963static int s5p_mfc_buf_init(struct vb2_buffer *vb) 946static int s5p_mfc_buf_init(struct vb2_buffer *vb)
964{ 947{
965 struct vb2_queue *vq = vb->vb2_queue; 948 struct vb2_queue *vq = vb->vb2_queue;
@@ -1107,8 +1090,8 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
1107 1090
1108static struct vb2_ops s5p_mfc_dec_qops = { 1091static struct vb2_ops s5p_mfc_dec_qops = {
1109 .queue_setup = s5p_mfc_queue_setup, 1092 .queue_setup = s5p_mfc_queue_setup,
1110 .wait_prepare = s5p_mfc_unlock, 1093 .wait_prepare = vb2_ops_wait_prepare,
1111 .wait_finish = s5p_mfc_lock, 1094 .wait_finish = vb2_ops_wait_finish,
1112 .buf_init = s5p_mfc_buf_init, 1095 .buf_init = s5p_mfc_buf_init,
1113 .start_streaming = s5p_mfc_start_streaming, 1096 .start_streaming = s5p_mfc_start_streaming,
1114 .stop_streaming = s5p_mfc_stop_streaming, 1097 .stop_streaming = s5p_mfc_stop_streaming,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
index bd64f1dcbdb5..e65993f4b901 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_enc.c
@@ -19,7 +19,6 @@
19#include <linux/module.h> 19#include <linux/module.h>
20#include <linux/platform_device.h> 20#include <linux/platform_device.h>
21#include <linux/sched.h> 21#include <linux/sched.h>
22#include <linux/version.h>
23#include <linux/videodev2.h> 22#include <linux/videodev2.h>
24#include <media/v4l2-event.h> 23#include <media/v4l2-event.h>
25#include <linux/workqueue.h> 24#include <linux/workqueue.h>
@@ -1867,22 +1866,6 @@ static int s5p_mfc_queue_setup(struct vb2_queue *vq,
1867 return 0; 1866 return 0;
1868} 1867}
1869 1868
1870static void s5p_mfc_unlock(struct vb2_queue *q)
1871{
1872 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
1873 struct s5p_mfc_dev *dev = ctx->dev;
1874
1875 mutex_unlock(&dev->mfc_mutex);
1876}
1877
1878static void s5p_mfc_lock(struct vb2_queue *q)
1879{
1880 struct s5p_mfc_ctx *ctx = fh_to_ctx(q->drv_priv);
1881 struct s5p_mfc_dev *dev = ctx->dev;
1882
1883 mutex_lock(&dev->mfc_mutex);
1884}
1885
1886static int s5p_mfc_buf_init(struct vb2_buffer *vb) 1869static int s5p_mfc_buf_init(struct vb2_buffer *vb)
1887{ 1870{
1888 struct vb2_queue *vq = vb->vb2_queue; 1871 struct vb2_queue *vq = vb->vb2_queue;
@@ -2052,8 +2035,8 @@ static void s5p_mfc_buf_queue(struct vb2_buffer *vb)
2052 2035
2053static struct vb2_ops s5p_mfc_enc_qops = { 2036static struct vb2_ops s5p_mfc_enc_qops = {
2054 .queue_setup = s5p_mfc_queue_setup, 2037 .queue_setup = s5p_mfc_queue_setup,
2055 .wait_prepare = s5p_mfc_unlock, 2038 .wait_prepare = vb2_ops_wait_prepare,
2056 .wait_finish = s5p_mfc_lock, 2039 .wait_finish = vb2_ops_wait_finish,
2057 .buf_init = s5p_mfc_buf_init, 2040 .buf_init = s5p_mfc_buf_init,
2058 .buf_prepare = s5p_mfc_buf_prepare, 2041 .buf_prepare = s5p_mfc_buf_prepare,
2059 .start_streaming = s5p_mfc_start_streaming, 2042 .start_streaming = s5p_mfc_start_streaming,
diff --git a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
index 9aea179943ce..d826c58b5d53 100644
--- a/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
+++ b/drivers/media/platform/s5p-mfc/s5p_mfc_opr_v6.c
@@ -1340,11 +1340,7 @@ static int s5p_mfc_init_decode_v6(struct s5p_mfc_ctx *ctx)
1340 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */ 1340 /* FMO_ASO_CTRL - 0: Enable, 1: Disable */
1341 reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6); 1341 reg |= (fmo_aso_ctrl << S5P_FIMV_D_OPT_FMO_ASO_CTRL_MASK_V6);
1342 1342
1343 /* When user sets desplay_delay to 0, 1343 if (ctx->display_delay_enable) {
1344 * It works as "display_delay enable" and delay set to 0.
1345 * If user wants display_delay disable, It should be
1346 * set to negative value. */
1347 if (ctx->display_delay >= 0) {
1348 reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6); 1344 reg |= (0x1 << S5P_FIMV_D_OPT_DDELAY_EN_SHIFT_V6);
1349 writel(ctx->display_delay, mfc_regs->d_display_delay); 1345 writel(ctx->display_delay, mfc_regs->d_display_delay);
1350 } 1346 }
diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
index b4d2696501e4..72d4f2e1efc0 100644
--- a/drivers/media/platform/s5p-tv/mixer_video.c
+++ b/drivers/media/platform/s5p-tv/mixer_video.c
@@ -926,22 +926,6 @@ static void buf_queue(struct vb2_buffer *vb)
926 mxr_dbg(mdev, "queuing buffer\n"); 926 mxr_dbg(mdev, "queuing buffer\n");
927} 927}
928 928
929static void wait_lock(struct vb2_queue *vq)
930{
931 struct mxr_layer *layer = vb2_get_drv_priv(vq);
932
933 mxr_dbg(layer->mdev, "%s\n", __func__);
934 mutex_lock(&layer->mutex);
935}
936
937static void wait_unlock(struct vb2_queue *vq)
938{
939 struct mxr_layer *layer = vb2_get_drv_priv(vq);
940
941 mxr_dbg(layer->mdev, "%s\n", __func__);
942 mutex_unlock(&layer->mutex);
943}
944
945static int start_streaming(struct vb2_queue *vq, unsigned int count) 929static int start_streaming(struct vb2_queue *vq, unsigned int count)
946{ 930{
947 struct mxr_layer *layer = vb2_get_drv_priv(vq); 931 struct mxr_layer *layer = vb2_get_drv_priv(vq);
@@ -1040,8 +1024,8 @@ static void stop_streaming(struct vb2_queue *vq)
1040static struct vb2_ops mxr_video_qops = { 1024static struct vb2_ops mxr_video_qops = {
1041 .queue_setup = queue_setup, 1025 .queue_setup = queue_setup,
1042 .buf_queue = buf_queue, 1026 .buf_queue = buf_queue,
1043 .wait_prepare = wait_unlock, 1027 .wait_prepare = vb2_ops_wait_prepare,
1044 .wait_finish = wait_lock, 1028 .wait_finish = vb2_ops_wait_finish,
1045 .start_streaming = start_streaming, 1029 .start_streaming = start_streaming,
1046 .stop_streaming = stop_streaming, 1030 .stop_streaming = stop_streaming,
1047}; 1031};
@@ -1122,6 +1106,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
1122 .ops = &mxr_video_qops, 1106 .ops = &mxr_video_qops,
1123 .min_buffers_needed = 1, 1107 .min_buffers_needed = 1,
1124 .mem_ops = &vb2_dma_contig_memops, 1108 .mem_ops = &vb2_dma_contig_memops,
1109 .lock = &layer->mutex,
1125 }; 1110 };
1126 1111
1127 return layer; 1112 return layer;
diff --git a/drivers/media/platform/sh_veu.c b/drivers/media/platform/sh_veu.c
index aaa1f6f25a29..a901b6248557 100644
--- a/drivers/media/platform/sh_veu.c
+++ b/drivers/media/platform/sh_veu.c
@@ -242,20 +242,6 @@ static void sh_veu_job_abort(void *priv)
242 veu->aborting = true; 242 veu->aborting = true;
243} 243}
244 244
245static void sh_veu_lock(void *priv)
246{
247 struct sh_veu_dev *veu = priv;
248
249 mutex_lock(&veu->fop_lock);
250}
251
252static void sh_veu_unlock(void *priv)
253{
254 struct sh_veu_dev *veu = priv;
255
256 mutex_unlock(&veu->fop_lock);
257}
258
259static void sh_veu_process(struct sh_veu_dev *veu, 245static void sh_veu_process(struct sh_veu_dev *veu,
260 struct vb2_buffer *src_buf, 246 struct vb2_buffer *src_buf,
261 struct vb2_buffer *dst_buf) 247 struct vb2_buffer *dst_buf)
@@ -950,36 +936,28 @@ static void sh_veu_buf_queue(struct vb2_buffer *vb)
950 v4l2_m2m_buf_queue(veu->m2m_ctx, vb); 936 v4l2_m2m_buf_queue(veu->m2m_ctx, vb);
951} 937}
952 938
953static void sh_veu_wait_prepare(struct vb2_queue *q)
954{
955 sh_veu_unlock(vb2_get_drv_priv(q));
956}
957
958static void sh_veu_wait_finish(struct vb2_queue *q)
959{
960 sh_veu_lock(vb2_get_drv_priv(q));
961}
962
963static const struct vb2_ops sh_veu_qops = { 939static const struct vb2_ops sh_veu_qops = {
964 .queue_setup = sh_veu_queue_setup, 940 .queue_setup = sh_veu_queue_setup,
965 .buf_prepare = sh_veu_buf_prepare, 941 .buf_prepare = sh_veu_buf_prepare,
966 .buf_queue = sh_veu_buf_queue, 942 .buf_queue = sh_veu_buf_queue,
967 .wait_prepare = sh_veu_wait_prepare, 943 .wait_prepare = vb2_ops_wait_prepare,
968 .wait_finish = sh_veu_wait_finish, 944 .wait_finish = vb2_ops_wait_finish,
969}; 945};
970 946
971static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq, 947static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
972 struct vb2_queue *dst_vq) 948 struct vb2_queue *dst_vq)
973{ 949{
950 struct sh_veu_dev *veu = priv;
974 int ret; 951 int ret;
975 952
976 memset(src_vq, 0, sizeof(*src_vq)); 953 memset(src_vq, 0, sizeof(*src_vq));
977 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT; 954 src_vq->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
978 src_vq->io_modes = VB2_MMAP | VB2_USERPTR; 955 src_vq->io_modes = VB2_MMAP | VB2_USERPTR;
979 src_vq->drv_priv = priv; 956 src_vq->drv_priv = veu;
980 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 957 src_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
981 src_vq->ops = &sh_veu_qops; 958 src_vq->ops = &sh_veu_qops;
982 src_vq->mem_ops = &vb2_dma_contig_memops; 959 src_vq->mem_ops = &vb2_dma_contig_memops;
960 src_vq->lock = &veu->fop_lock;
983 961
984 ret = vb2_queue_init(src_vq); 962 ret = vb2_queue_init(src_vq);
985 if (ret < 0) 963 if (ret < 0)
@@ -988,10 +966,11 @@ static int sh_veu_queue_init(void *priv, struct vb2_queue *src_vq,
988 memset(dst_vq, 0, sizeof(*dst_vq)); 966 memset(dst_vq, 0, sizeof(*dst_vq));
989 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 967 dst_vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
990 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR; 968 dst_vq->io_modes = VB2_MMAP | VB2_USERPTR;
991 dst_vq->drv_priv = priv; 969 dst_vq->drv_priv = veu;
992 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer); 970 dst_vq->buf_struct_size = sizeof(struct v4l2_m2m_buffer);
993 dst_vq->ops = &sh_veu_qops; 971 dst_vq->ops = &sh_veu_qops;
994 dst_vq->mem_ops = &vb2_dma_contig_memops; 972 dst_vq->mem_ops = &vb2_dma_contig_memops;
973 dst_vq->lock = &veu->fop_lock;
995 974
996 return vb2_queue_init(dst_vq); 975 return vb2_queue_init(dst_vq);
997} 976}
diff --git a/drivers/media/platform/soc_camera/atmel-isi.c b/drivers/media/platform/soc_camera/atmel-isi.c
index 6d885239b16a..8526bf5c8429 100644
--- a/drivers/media/platform/soc_camera/atmel-isi.c
+++ b/drivers/media/platform/soc_camera/atmel-isi.c
@@ -455,8 +455,8 @@ static struct vb2_ops isi_video_qops = {
455 .buf_queue = buffer_queue, 455 .buf_queue = buffer_queue,
456 .start_streaming = start_streaming, 456 .start_streaming = start_streaming,
457 .stop_streaming = stop_streaming, 457 .stop_streaming = stop_streaming,
458 .wait_prepare = soc_camera_unlock, 458 .wait_prepare = vb2_ops_wait_prepare,
459 .wait_finish = soc_camera_lock, 459 .wait_finish = vb2_ops_wait_finish,
460}; 460};
461 461
462/* ------------------------------------------------------------------ 462/* ------------------------------------------------------------------
@@ -465,6 +465,8 @@ static struct vb2_ops isi_video_qops = {
465static int isi_camera_init_videobuf(struct vb2_queue *q, 465static int isi_camera_init_videobuf(struct vb2_queue *q,
466 struct soc_camera_device *icd) 466 struct soc_camera_device *icd)
467{ 467{
468 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
469
468 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 470 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
469 q->io_modes = VB2_MMAP; 471 q->io_modes = VB2_MMAP;
470 q->drv_priv = icd; 472 q->drv_priv = icd;
@@ -472,6 +474,7 @@ static int isi_camera_init_videobuf(struct vb2_queue *q,
472 q->ops = &isi_video_qops; 474 q->ops = &isi_video_qops;
473 q->mem_ops = &vb2_dma_contig_memops; 475 q->mem_ops = &vb2_dma_contig_memops;
474 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 476 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
477 q->lock = &ici->host_lock;
475 478
476 return vb2_queue_init(q); 479 return vb2_queue_init(q);
477} 480}
diff --git a/drivers/media/platform/soc_camera/mx3_camera.c b/drivers/media/platform/soc_camera/mx3_camera.c
index 0b3299dee05d..3435fd2ca8ec 100644
--- a/drivers/media/platform/soc_camera/mx3_camera.c
+++ b/drivers/media/platform/soc_camera/mx3_camera.c
@@ -435,14 +435,16 @@ static struct vb2_ops mx3_videobuf_ops = {
435 .buf_queue = mx3_videobuf_queue, 435 .buf_queue = mx3_videobuf_queue,
436 .buf_cleanup = mx3_videobuf_release, 436 .buf_cleanup = mx3_videobuf_release,
437 .buf_init = mx3_videobuf_init, 437 .buf_init = mx3_videobuf_init,
438 .wait_prepare = soc_camera_unlock, 438 .wait_prepare = vb2_ops_wait_prepare,
439 .wait_finish = soc_camera_lock, 439 .wait_finish = vb2_ops_wait_finish,
440 .stop_streaming = mx3_stop_streaming, 440 .stop_streaming = mx3_stop_streaming,
441}; 441};
442 442
443static int mx3_camera_init_videobuf(struct vb2_queue *q, 443static int mx3_camera_init_videobuf(struct vb2_queue *q,
444 struct soc_camera_device *icd) 444 struct soc_camera_device *icd)
445{ 445{
446 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
447
446 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 448 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
447 q->io_modes = VB2_MMAP | VB2_USERPTR; 449 q->io_modes = VB2_MMAP | VB2_USERPTR;
448 q->drv_priv = icd; 450 q->drv_priv = icd;
@@ -450,6 +452,7 @@ static int mx3_camera_init_videobuf(struct vb2_queue *q,
450 q->mem_ops = &vb2_dma_contig_memops; 452 q->mem_ops = &vb2_dma_contig_memops;
451 q->buf_struct_size = sizeof(struct mx3_camera_buffer); 453 q->buf_struct_size = sizeof(struct mx3_camera_buffer);
452 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 454 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
455 q->lock = &ici->host_lock;
453 456
454 return vb2_queue_init(q); 457 return vb2_queue_init(q);
455} 458}
diff --git a/drivers/media/platform/soc_camera/rcar_vin.c b/drivers/media/platform/soc_camera/rcar_vin.c
index 9f1473c0a0cf..279ab9f6ae38 100644
--- a/drivers/media/platform/soc_camera/rcar_vin.c
+++ b/drivers/media/platform/soc_camera/rcar_vin.c
@@ -804,62 +804,26 @@ error:
804 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR); 804 vb2_buffer_done(vb, VB2_BUF_STATE_ERROR);
805} 805}
806 806
807static void rcar_vin_videobuf_release(struct vb2_buffer *vb) 807/*
808 * Wait for capture to stop and all in-flight buffers to be finished with by
809 * the video hardware. This must be called under &priv->lock
810 *
811 */
812static void rcar_vin_wait_stop_streaming(struct rcar_vin_priv *priv)
808{ 813{
809 struct soc_camera_device *icd = soc_camera_from_vb2q(vb->vb2_queue); 814 while (priv->state != STOPPED) {
810 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 815 /* issue stop if running */
811 struct rcar_vin_priv *priv = ici->priv; 816 if (priv->state == RUNNING)
812 unsigned int i; 817 rcar_vin_request_capture_stop(priv);
813 int buf_in_use = 0;
814
815 spin_lock_irq(&priv->lock);
816
817 /* Is the buffer in use by the VIN hardware? */
818 for (i = 0; i < MAX_BUFFER_NUM; i++) {
819 if (priv->queue_buf[i] == vb) {
820 buf_in_use = 1;
821 break;
822 }
823 }
824
825 if (buf_in_use) {
826 while (priv->state != STOPPED) {
827
828 /* issue stop if running */
829 if (priv->state == RUNNING)
830 rcar_vin_request_capture_stop(priv);
831 818
832 /* wait until capturing has been stopped */ 819 /* wait until capturing has been stopped */
833 if (priv->state == STOPPING) { 820 if (priv->state == STOPPING) {
834 priv->request_to_stop = true; 821 priv->request_to_stop = true;
835 spin_unlock_irq(&priv->lock); 822 spin_unlock_irq(&priv->lock);
836 wait_for_completion(&priv->capture_stop); 823 wait_for_completion(&priv->capture_stop);
837 spin_lock_irq(&priv->lock); 824 spin_lock_irq(&priv->lock);
838 }
839 }
840 /*
841 * Capturing has now stopped. The buffer we have been asked
842 * to release could be any of the current buffers in use, so
843 * release all buffers that are in use by HW
844 */
845 for (i = 0; i < MAX_BUFFER_NUM; i++) {
846 if (priv->queue_buf[i]) {
847 vb2_buffer_done(priv->queue_buf[i],
848 VB2_BUF_STATE_ERROR);
849 priv->queue_buf[i] = NULL;
850 }
851 } 825 }
852 } else {
853 list_del_init(to_buf_list(vb));
854 } 826 }
855
856 spin_unlock_irq(&priv->lock);
857}
858
859static int rcar_vin_videobuf_init(struct vb2_buffer *vb)
860{
861 INIT_LIST_HEAD(to_buf_list(vb));
862 return 0;
863} 827}
864 828
865static void rcar_vin_stop_streaming(struct vb2_queue *vq) 829static void rcar_vin_stop_streaming(struct vb2_queue *vq)
@@ -868,21 +832,34 @@ static void rcar_vin_stop_streaming(struct vb2_queue *vq)
868 struct soc_camera_host *ici = to_soc_camera_host(icd->parent); 832 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
869 struct rcar_vin_priv *priv = ici->priv; 833 struct rcar_vin_priv *priv = ici->priv;
870 struct list_head *buf_head, *tmp; 834 struct list_head *buf_head, *tmp;
835 int i;
871 836
872 spin_lock_irq(&priv->lock); 837 spin_lock_irq(&priv->lock);
873 list_for_each_safe(buf_head, tmp, &priv->capture) 838 rcar_vin_wait_stop_streaming(priv);
839
840 for (i = 0; i < MAX_BUFFER_NUM; i++) {
841 if (priv->queue_buf[i]) {
842 vb2_buffer_done(priv->queue_buf[i],
843 VB2_BUF_STATE_ERROR);
844 priv->queue_buf[i] = NULL;
845 }
846 }
847
848 list_for_each_safe(buf_head, tmp, &priv->capture) {
849 vb2_buffer_done(&list_entry(buf_head,
850 struct rcar_vin_buffer, list)->vb,
851 VB2_BUF_STATE_ERROR);
874 list_del_init(buf_head); 852 list_del_init(buf_head);
853 }
875 spin_unlock_irq(&priv->lock); 854 spin_unlock_irq(&priv->lock);
876} 855}
877 856
878static struct vb2_ops rcar_vin_vb2_ops = { 857static struct vb2_ops rcar_vin_vb2_ops = {
879 .queue_setup = rcar_vin_videobuf_setup, 858 .queue_setup = rcar_vin_videobuf_setup,
880 .buf_init = rcar_vin_videobuf_init,
881 .buf_cleanup = rcar_vin_videobuf_release,
882 .buf_queue = rcar_vin_videobuf_queue, 859 .buf_queue = rcar_vin_videobuf_queue,
883 .stop_streaming = rcar_vin_stop_streaming, 860 .stop_streaming = rcar_vin_stop_streaming,
884 .wait_prepare = soc_camera_unlock, 861 .wait_prepare = vb2_ops_wait_prepare,
885 .wait_finish = soc_camera_lock, 862 .wait_finish = vb2_ops_wait_finish,
886}; 863};
887 864
888static irqreturn_t rcar_vin_irq(int irq, void *data) 865static irqreturn_t rcar_vin_irq(int irq, void *data)
@@ -1808,6 +1785,8 @@ static int rcar_vin_querycap(struct soc_camera_host *ici,
1808static int rcar_vin_init_videobuf2(struct vb2_queue *vq, 1785static int rcar_vin_init_videobuf2(struct vb2_queue *vq,
1809 struct soc_camera_device *icd) 1786 struct soc_camera_device *icd)
1810{ 1787{
1788 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1789
1811 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1790 vq->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1812 vq->io_modes = VB2_MMAP | VB2_USERPTR; 1791 vq->io_modes = VB2_MMAP | VB2_USERPTR;
1813 vq->drv_priv = icd; 1792 vq->drv_priv = icd;
@@ -1815,6 +1794,7 @@ static int rcar_vin_init_videobuf2(struct vb2_queue *vq,
1815 vq->mem_ops = &vb2_dma_contig_memops; 1794 vq->mem_ops = &vb2_dma_contig_memops;
1816 vq->buf_struct_size = sizeof(struct rcar_vin_buffer); 1795 vq->buf_struct_size = sizeof(struct rcar_vin_buffer);
1817 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1796 vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1797 vq->lock = &ici->host_lock;
1818 1798
1819 return vb2_queue_init(vq); 1799 return vb2_queue_init(vq);
1820} 1800}
diff --git a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
index 71787702d4a2..9ce202f53934 100644
--- a/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
+++ b/drivers/media/platform/soc_camera/sh_mobile_ceu_camera.c
@@ -496,8 +496,8 @@ static struct vb2_ops sh_mobile_ceu_videobuf_ops = {
496 .buf_queue = sh_mobile_ceu_videobuf_queue, 496 .buf_queue = sh_mobile_ceu_videobuf_queue,
497 .buf_cleanup = sh_mobile_ceu_videobuf_release, 497 .buf_cleanup = sh_mobile_ceu_videobuf_release,
498 .buf_init = sh_mobile_ceu_videobuf_init, 498 .buf_init = sh_mobile_ceu_videobuf_init,
499 .wait_prepare = soc_camera_unlock, 499 .wait_prepare = vb2_ops_wait_prepare,
500 .wait_finish = soc_camera_lock, 500 .wait_finish = vb2_ops_wait_finish,
501 .stop_streaming = sh_mobile_ceu_stop_streaming, 501 .stop_streaming = sh_mobile_ceu_stop_streaming,
502}; 502};
503 503
@@ -1661,6 +1661,8 @@ static int sh_mobile_ceu_querycap(struct soc_camera_host *ici,
1661static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q, 1661static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
1662 struct soc_camera_device *icd) 1662 struct soc_camera_device *icd)
1663{ 1663{
1664 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
1665
1664 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1666 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1665 q->io_modes = VB2_MMAP | VB2_USERPTR; 1667 q->io_modes = VB2_MMAP | VB2_USERPTR;
1666 q->drv_priv = icd; 1668 q->drv_priv = icd;
@@ -1668,6 +1670,7 @@ static int sh_mobile_ceu_init_videobuf(struct vb2_queue *q,
1668 q->mem_ops = &vb2_dma_contig_memops; 1670 q->mem_ops = &vb2_dma_contig_memops;
1669 q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer); 1671 q->buf_struct_size = sizeof(struct sh_mobile_ceu_buffer);
1670 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC; 1672 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1673 q->lock = &ici->host_lock;
1671 1674
1672 return vb2_queue_init(q); 1675 return vb2_queue_init(q);
1673} 1676}
diff --git a/drivers/media/platform/soc_camera/soc_camera.c b/drivers/media/platform/soc_camera/soc_camera.c
index b3db51c82bde..cee7b56f8404 100644
--- a/drivers/media/platform/soc_camera/soc_camera.c
+++ b/drivers/media/platform/soc_camera/soc_camera.c
@@ -843,22 +843,6 @@ static unsigned int soc_camera_poll(struct file *file, poll_table *pt)
843 return res; 843 return res;
844} 844}
845 845
846void soc_camera_lock(struct vb2_queue *vq)
847{
848 struct soc_camera_device *icd = vb2_get_drv_priv(vq);
849 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
850 mutex_lock(&ici->host_lock);
851}
852EXPORT_SYMBOL(soc_camera_lock);
853
854void soc_camera_unlock(struct vb2_queue *vq)
855{
856 struct soc_camera_device *icd = vb2_get_drv_priv(vq);
857 struct soc_camera_host *ici = to_soc_camera_host(icd->parent);
858 mutex_unlock(&ici->host_lock);
859}
860EXPORT_SYMBOL(soc_camera_unlock);
861
862static struct v4l2_file_operations soc_camera_fops = { 846static struct v4l2_file_operations soc_camera_fops = {
863 .owner = THIS_MODULE, 847 .owner = THIS_MODULE,
864 .open = soc_camera_open, 848 .open = soc_camera_open,
@@ -1813,8 +1797,6 @@ eadddev:
1813 mutex_unlock(&ici->clk_lock); 1797 mutex_unlock(&ici->clk_lock);
1814 } 1798 }
1815eadd: 1799eadd:
1816 video_device_release(icd->vdev);
1817 icd->vdev = NULL;
1818 if (icd->vdev) { 1800 if (icd->vdev) {
1819 video_device_release(icd->vdev); 1801 video_device_release(icd->vdev);
1820 icd->vdev = NULL; 1802 icd->vdev = NULL;
diff --git a/drivers/media/platform/ti-vpe/vpe.c b/drivers/media/platform/ti-vpe/vpe.c
index d628d1a7cf9e..c44760b705da 100644
--- a/drivers/media/platform/ti-vpe/vpe.c
+++ b/drivers/media/platform/ti-vpe/vpe.c
@@ -25,6 +25,7 @@
25#include <linux/io.h> 25#include <linux/io.h>
26#include <linux/ioctl.h> 26#include <linux/ioctl.h>
27#include <linux/module.h> 27#include <linux/module.h>
28#include <linux/of.h>
28#include <linux/platform_device.h> 29#include <linux/platform_device.h>
29#include <linux/pm_runtime.h> 30#include <linux/pm_runtime.h>
30#include <linux/sched.h> 31#include <linux/sched.h>
@@ -74,7 +75,7 @@
74#define VPE_DEF_BUFS_PER_JOB 1 /* default one buffer per batch job */ 75#define VPE_DEF_BUFS_PER_JOB 1 /* default one buffer per batch job */
75 76
76/* 77/*
77 * each VPE context can need up to 3 config desciptors, 7 input descriptors, 78 * each VPE context can need up to 3 config descriptors, 7 input descriptors,
78 * 3 output descriptors, and 10 control descriptors 79 * 3 output descriptors, and 10 control descriptors
79 */ 80 */
80#define VPE_DESC_LIST_SIZE (10 * VPDMA_DTD_DESC_SIZE + \ 81#define VPE_DESC_LIST_SIZE (10 * VPDMA_DTD_DESC_SIZE + \
@@ -373,7 +374,6 @@ struct vpe_dev {
373struct vpe_ctx { 374struct vpe_ctx {
374 struct v4l2_fh fh; 375 struct v4l2_fh fh;
375 struct vpe_dev *dev; 376 struct vpe_dev *dev;
376 struct v4l2_m2m_ctx *m2m_ctx;
377 struct v4l2_ctrl_handler hdl; 377 struct v4l2_ctrl_handler hdl;
378 378
379 unsigned int field; /* current field */ 379 unsigned int field; /* current field */
@@ -887,10 +887,10 @@ static int job_ready(void *priv)
887 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) 887 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL)
888 needed += 2; /* need additional two most recent fields */ 888 needed += 2; /* need additional two most recent fields */
889 889
890 if (v4l2_m2m_num_src_bufs_ready(ctx->m2m_ctx) < needed) 890 if (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) < needed)
891 return 0; 891 return 0;
892 892
893 if (v4l2_m2m_num_dst_bufs_ready(ctx->m2m_ctx) < needed) 893 if (v4l2_m2m_num_dst_bufs_ready(ctx->fh.m2m_ctx) < needed)
894 return 0; 894 return 0;
895 895
896 return 1; 896 return 1;
@@ -1100,15 +1100,15 @@ static void device_run(void *priv)
1100 struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST]; 1100 struct vpe_q_data *d_q_data = &ctx->q_data[Q_DATA_DST];
1101 1101
1102 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) { 1102 if (ctx->deinterlacing && ctx->src_vbs[2] == NULL) {
1103 ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1103 ctx->src_vbs[2] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
1104 WARN_ON(ctx->src_vbs[2] == NULL); 1104 WARN_ON(ctx->src_vbs[2] == NULL);
1105 ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1105 ctx->src_vbs[1] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
1106 WARN_ON(ctx->src_vbs[1] == NULL); 1106 WARN_ON(ctx->src_vbs[1] == NULL);
1107 } 1107 }
1108 1108
1109 ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->m2m_ctx); 1109 ctx->src_vbs[0] = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
1110 WARN_ON(ctx->src_vbs[0] == NULL); 1110 WARN_ON(ctx->src_vbs[0] == NULL);
1111 ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx); 1111 ctx->dst_vb = v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx);
1112 WARN_ON(ctx->dst_vb == NULL); 1112 WARN_ON(ctx->dst_vb == NULL);
1113 1113
1114 /* config descriptors */ 1114 /* config descriptors */
@@ -1334,7 +1334,7 @@ static irqreturn_t vpe_irq(int irq_vpe, void *data)
1334finished: 1334finished:
1335 vpe_dbg(ctx->dev, "finishing transaction\n"); 1335 vpe_dbg(ctx->dev, "finishing transaction\n");
1336 ctx->bufs_completed = 0; 1336 ctx->bufs_completed = 0;
1337 v4l2_m2m_job_finish(dev->m2m_dev, ctx->m2m_ctx); 1337 v4l2_m2m_job_finish(dev->m2m_dev, ctx->fh.m2m_ctx);
1338handled: 1338handled:
1339 return IRQ_HANDLED; 1339 return IRQ_HANDLED;
1340} 1340}
@@ -1395,7 +1395,7 @@ static int vpe_g_fmt(struct file *file, void *priv, struct v4l2_format *f)
1395 struct vpe_q_data *q_data; 1395 struct vpe_q_data *q_data;
1396 int i; 1396 int i;
1397 1397
1398 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 1398 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
1399 if (!vq) 1399 if (!vq)
1400 return -EINVAL; 1400 return -EINVAL;
1401 1401
@@ -1527,7 +1527,7 @@ static int __vpe_s_fmt(struct vpe_ctx *ctx, struct v4l2_format *f)
1527 struct vb2_queue *vq; 1527 struct vb2_queue *vq;
1528 int i; 1528 int i;
1529 1529
1530 vq = v4l2_m2m_get_vq(ctx->m2m_ctx, f->type); 1530 vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx, f->type);
1531 if (!vq) 1531 if (!vq)
1532 return -EINVAL; 1532 return -EINVAL;
1533 1533
@@ -1739,52 +1739,6 @@ static int vpe_s_selection(struct file *file, void *fh,
1739 return set_srcdst_params(ctx); 1739 return set_srcdst_params(ctx);
1740} 1740}
1741 1741
1742static int vpe_reqbufs(struct file *file, void *priv,
1743 struct v4l2_requestbuffers *reqbufs)
1744{
1745 struct vpe_ctx *ctx = file2ctx(file);
1746
1747 return v4l2_m2m_reqbufs(file, ctx->m2m_ctx, reqbufs);
1748}
1749
1750static int vpe_querybuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1751{
1752 struct vpe_ctx *ctx = file2ctx(file);
1753
1754 return v4l2_m2m_querybuf(file, ctx->m2m_ctx, buf);
1755}
1756
1757static int vpe_qbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1758{
1759 struct vpe_ctx *ctx = file2ctx(file);
1760
1761 return v4l2_m2m_qbuf(file, ctx->m2m_ctx, buf);
1762}
1763
1764static int vpe_dqbuf(struct file *file, void *priv, struct v4l2_buffer *buf)
1765{
1766 struct vpe_ctx *ctx = file2ctx(file);
1767
1768 return v4l2_m2m_dqbuf(file, ctx->m2m_ctx, buf);
1769}
1770
1771static int vpe_streamon(struct file *file, void *priv, enum v4l2_buf_type type)
1772{
1773 struct vpe_ctx *ctx = file2ctx(file);
1774
1775 return v4l2_m2m_streamon(file, ctx->m2m_ctx, type);
1776}
1777
1778static int vpe_streamoff(struct file *file, void *priv, enum v4l2_buf_type type)
1779{
1780 struct vpe_ctx *ctx = file2ctx(file);
1781
1782 vpe_dump_regs(ctx->dev);
1783 vpdma_dump_regs(ctx->dev->vpdma);
1784
1785 return v4l2_m2m_streamoff(file, ctx->m2m_ctx, type);
1786}
1787
1788/* 1742/*
1789 * defines number of buffers/frames a context can process with VPE before 1743 * defines number of buffers/frames a context can process with VPE before
1790 * switching to a different context. default value is 1 buffer per context 1744 * switching to a different context. default value is 1 buffer per context
@@ -1814,14 +1768,14 @@ static const struct v4l2_ctrl_ops vpe_ctrl_ops = {
1814}; 1768};
1815 1769
1816static const struct v4l2_ioctl_ops vpe_ioctl_ops = { 1770static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
1817 .vidioc_querycap = vpe_querycap, 1771 .vidioc_querycap = vpe_querycap,
1818 1772
1819 .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt, 1773 .vidioc_enum_fmt_vid_cap_mplane = vpe_enum_fmt,
1820 .vidioc_g_fmt_vid_cap_mplane = vpe_g_fmt, 1774 .vidioc_g_fmt_vid_cap_mplane = vpe_g_fmt,
1821 .vidioc_try_fmt_vid_cap_mplane = vpe_try_fmt, 1775 .vidioc_try_fmt_vid_cap_mplane = vpe_try_fmt,
1822 .vidioc_s_fmt_vid_cap_mplane = vpe_s_fmt, 1776 .vidioc_s_fmt_vid_cap_mplane = vpe_s_fmt,
1823 1777
1824 .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt, 1778 .vidioc_enum_fmt_vid_out_mplane = vpe_enum_fmt,
1825 .vidioc_g_fmt_vid_out_mplane = vpe_g_fmt, 1779 .vidioc_g_fmt_vid_out_mplane = vpe_g_fmt,
1826 .vidioc_try_fmt_vid_out_mplane = vpe_try_fmt, 1780 .vidioc_try_fmt_vid_out_mplane = vpe_try_fmt,
1827 .vidioc_s_fmt_vid_out_mplane = vpe_s_fmt, 1781 .vidioc_s_fmt_vid_out_mplane = vpe_s_fmt,
@@ -1829,16 +1783,15 @@ static const struct v4l2_ioctl_ops vpe_ioctl_ops = {
1829 .vidioc_g_selection = vpe_g_selection, 1783 .vidioc_g_selection = vpe_g_selection,
1830 .vidioc_s_selection = vpe_s_selection, 1784 .vidioc_s_selection = vpe_s_selection,
1831 1785
1832 .vidioc_reqbufs = vpe_reqbufs, 1786 .vidioc_reqbufs = v4l2_m2m_ioctl_reqbufs,
1833 .vidioc_querybuf = vpe_querybuf, 1787 .vidioc_querybuf = v4l2_m2m_ioctl_querybuf,
1788 .vidioc_qbuf = v4l2_m2m_ioctl_qbuf,
1789 .vidioc_dqbuf = v4l2_m2m_ioctl_dqbuf,
1790 .vidioc_streamon = v4l2_m2m_ioctl_streamon,
1791 .vidioc_streamoff = v4l2_m2m_ioctl_streamoff,
1834 1792
1835 .vidioc_qbuf = vpe_qbuf, 1793 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1836 .vidioc_dqbuf = vpe_dqbuf, 1794 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1837
1838 .vidioc_streamon = vpe_streamon,
1839 .vidioc_streamoff = vpe_streamoff,
1840 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
1841 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
1842}; 1795};
1843 1796
1844/* 1797/*
@@ -1910,33 +1863,40 @@ static int vpe_buf_prepare(struct vb2_buffer *vb)
1910static void vpe_buf_queue(struct vb2_buffer *vb) 1863static void vpe_buf_queue(struct vb2_buffer *vb)
1911{ 1864{
1912 struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue); 1865 struct vpe_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
1913 v4l2_m2m_buf_queue(ctx->m2m_ctx, vb); 1866
1867 v4l2_m2m_buf_queue(ctx->fh.m2m_ctx, vb);
1914} 1868}
1915 1869
1916static void vpe_wait_prepare(struct vb2_queue *q) 1870static int vpe_start_streaming(struct vb2_queue *q, unsigned int count)
1917{ 1871{
1918 struct vpe_ctx *ctx = vb2_get_drv_priv(q); 1872 /* currently we do nothing here */
1919 vpe_unlock(ctx); 1873
1874 return 0;
1920} 1875}
1921 1876
1922static void vpe_wait_finish(struct vb2_queue *q) 1877static void vpe_stop_streaming(struct vb2_queue *q)
1923{ 1878{
1924 struct vpe_ctx *ctx = vb2_get_drv_priv(q); 1879 struct vpe_ctx *ctx = vb2_get_drv_priv(q);
1925 vpe_lock(ctx); 1880
1881 vpe_dump_regs(ctx->dev);
1882 vpdma_dump_regs(ctx->dev->vpdma);
1926} 1883}
1927 1884
1928static struct vb2_ops vpe_qops = { 1885static struct vb2_ops vpe_qops = {
1929 .queue_setup = vpe_queue_setup, 1886 .queue_setup = vpe_queue_setup,
1930 .buf_prepare = vpe_buf_prepare, 1887 .buf_prepare = vpe_buf_prepare,
1931 .buf_queue = vpe_buf_queue, 1888 .buf_queue = vpe_buf_queue,
1932 .wait_prepare = vpe_wait_prepare, 1889 .wait_prepare = vb2_ops_wait_prepare,
1933 .wait_finish = vpe_wait_finish, 1890 .wait_finish = vb2_ops_wait_finish,
1891 .start_streaming = vpe_start_streaming,
1892 .stop_streaming = vpe_stop_streaming,
1934}; 1893};
1935 1894
1936static int queue_init(void *priv, struct vb2_queue *src_vq, 1895static int queue_init(void *priv, struct vb2_queue *src_vq,
1937 struct vb2_queue *dst_vq) 1896 struct vb2_queue *dst_vq)
1938{ 1897{
1939 struct vpe_ctx *ctx = priv; 1898 struct vpe_ctx *ctx = priv;
1899 struct vpe_dev *dev = ctx->dev;
1940 int ret; 1900 int ret;
1941 1901
1942 memset(src_vq, 0, sizeof(*src_vq)); 1902 memset(src_vq, 0, sizeof(*src_vq));
@@ -1947,6 +1907,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
1947 src_vq->ops = &vpe_qops; 1907 src_vq->ops = &vpe_qops;
1948 src_vq->mem_ops = &vb2_dma_contig_memops; 1908 src_vq->mem_ops = &vb2_dma_contig_memops;
1949 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1909 src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1910 src_vq->lock = &dev->dev_mutex;
1950 1911
1951 ret = vb2_queue_init(src_vq); 1912 ret = vb2_queue_init(src_vq);
1952 if (ret) 1913 if (ret)
@@ -1960,6 +1921,7 @@ static int queue_init(void *priv, struct vb2_queue *src_vq,
1960 dst_vq->ops = &vpe_qops; 1921 dst_vq->ops = &vpe_qops;
1961 dst_vq->mem_ops = &vb2_dma_contig_memops; 1922 dst_vq->mem_ops = &vb2_dma_contig_memops;
1962 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY; 1923 dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
1924 dst_vq->lock = &dev->dev_mutex;
1963 1925
1964 return vb2_queue_init(dst_vq); 1926 return vb2_queue_init(dst_vq);
1965} 1927}
@@ -1981,9 +1943,9 @@ static const struct v4l2_ctrl_config vpe_bufs_per_job = {
1981static int vpe_open(struct file *file) 1943static int vpe_open(struct file *file)
1982{ 1944{
1983 struct vpe_dev *dev = video_drvdata(file); 1945 struct vpe_dev *dev = video_drvdata(file);
1984 struct vpe_ctx *ctx = NULL;
1985 struct vpe_q_data *s_q_data; 1946 struct vpe_q_data *s_q_data;
1986 struct v4l2_ctrl_handler *hdl; 1947 struct v4l2_ctrl_handler *hdl;
1948 struct vpe_ctx *ctx;
1987 int ret; 1949 int ret;
1988 1950
1989 vpe_dbg(dev, "vpe_open\n"); 1951 vpe_dbg(dev, "vpe_open\n");
@@ -2056,10 +2018,10 @@ static int vpe_open(struct file *file)
2056 if (ret) 2018 if (ret)
2057 goto exit_fh; 2019 goto exit_fh;
2058 2020
2059 ctx->m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init); 2021 ctx->fh.m2m_ctx = v4l2_m2m_ctx_init(dev->m2m_dev, ctx, &queue_init);
2060 2022
2061 if (IS_ERR(ctx->m2m_ctx)) { 2023 if (IS_ERR(ctx->fh.m2m_ctx)) {
2062 ret = PTR_ERR(ctx->m2m_ctx); 2024 ret = PTR_ERR(ctx->fh.m2m_ctx);
2063 goto exit_fh; 2025 goto exit_fh;
2064 } 2026 }
2065 2027
@@ -2078,7 +2040,7 @@ static int vpe_open(struct file *file)
2078 ctx->load_mmrs = true; 2040 ctx->load_mmrs = true;
2079 2041
2080 vpe_dbg(dev, "created instance %p, m2m_ctx: %p\n", 2042 vpe_dbg(dev, "created instance %p, m2m_ctx: %p\n",
2081 ctx, ctx->m2m_ctx); 2043 ctx, ctx->fh.m2m_ctx);
2082 2044
2083 mutex_unlock(&dev->dev_mutex); 2045 mutex_unlock(&dev->dev_mutex);
2084 2046
@@ -2116,7 +2078,7 @@ static int vpe_release(struct file *file)
2116 v4l2_fh_del(&ctx->fh); 2078 v4l2_fh_del(&ctx->fh);
2117 v4l2_fh_exit(&ctx->fh); 2079 v4l2_fh_exit(&ctx->fh);
2118 v4l2_ctrl_handler_free(&ctx->hdl); 2080 v4l2_ctrl_handler_free(&ctx->hdl);
2119 v4l2_m2m_ctx_release(ctx->m2m_ctx); 2081 v4l2_m2m_ctx_release(ctx->fh.m2m_ctx);
2120 2082
2121 kfree(ctx); 2083 kfree(ctx);
2122 2084
@@ -2133,39 +2095,13 @@ static int vpe_release(struct file *file)
2133 return 0; 2095 return 0;
2134} 2096}
2135 2097
2136static unsigned int vpe_poll(struct file *file,
2137 struct poll_table_struct *wait)
2138{
2139 struct vpe_ctx *ctx = file2ctx(file);
2140 struct vpe_dev *dev = ctx->dev;
2141 int ret;
2142
2143 mutex_lock(&dev->dev_mutex);
2144 ret = v4l2_m2m_poll(file, ctx->m2m_ctx, wait);
2145 mutex_unlock(&dev->dev_mutex);
2146 return ret;
2147}
2148
2149static int vpe_mmap(struct file *file, struct vm_area_struct *vma)
2150{
2151 struct vpe_ctx *ctx = file2ctx(file);
2152 struct vpe_dev *dev = ctx->dev;
2153 int ret;
2154
2155 if (mutex_lock_interruptible(&dev->dev_mutex))
2156 return -ERESTARTSYS;
2157 ret = v4l2_m2m_mmap(file, ctx->m2m_ctx, vma);
2158 mutex_unlock(&dev->dev_mutex);
2159 return ret;
2160}
2161
2162static const struct v4l2_file_operations vpe_fops = { 2098static const struct v4l2_file_operations vpe_fops = {
2163 .owner = THIS_MODULE, 2099 .owner = THIS_MODULE,
2164 .open = vpe_open, 2100 .open = vpe_open,
2165 .release = vpe_release, 2101 .release = vpe_release,
2166 .poll = vpe_poll, 2102 .poll = v4l2_m2m_fop_poll,
2167 .unlocked_ioctl = video_ioctl2, 2103 .unlocked_ioctl = video_ioctl2,
2168 .mmap = vpe_mmap, 2104 .mmap = v4l2_m2m_fop_mmap,
2169}; 2105};
2170 2106
2171static struct video_device vpe_videodev = { 2107static struct video_device vpe_videodev = {
@@ -2367,8 +2303,6 @@ static const struct of_device_id vpe_of_match[] = {
2367 }, 2303 },
2368 {}, 2304 {},
2369}; 2305};
2370#else
2371#define vpe_of_match NULL
2372#endif 2306#endif
2373 2307
2374static struct platform_driver vpe_pdrv = { 2308static struct platform_driver vpe_pdrv = {
@@ -2376,7 +2310,7 @@ static struct platform_driver vpe_pdrv = {
2376 .remove = vpe_remove, 2310 .remove = vpe_remove,
2377 .driver = { 2311 .driver = {
2378 .name = VPE_MODULE_NAME, 2312 .name = VPE_MODULE_NAME,
2379 .of_match_table = vpe_of_match, 2313 .of_match_table = of_match_ptr(vpe_of_match),
2380 }, 2314 },
2381}; 2315};
2382 2316
diff --git a/drivers/media/platform/vivid/vivid-ctrls.c b/drivers/media/platform/vivid/vivid-ctrls.c
index 857e7866e8bc..32a798f2d953 100644
--- a/drivers/media/platform/vivid/vivid-ctrls.c
+++ b/drivers/media/platform/vivid/vivid-ctrls.c
@@ -689,7 +689,7 @@ static const struct v4l2_ctrl_config vivid_ctrl_max_edid_blocks = {
689 689
690static const char * const vivid_ctrl_colorspace_strings[] = { 690static const char * const vivid_ctrl_colorspace_strings[] = {
691 "SMPTE 170M", 691 "SMPTE 170M",
692 "REC 709", 692 "Rec. 709",
693 "sRGB", 693 "sRGB",
694 "AdobeRGB", 694 "AdobeRGB",
695 "BT.2020", 695 "BT.2020",
@@ -716,7 +716,7 @@ static const char * const vivid_ctrl_ycbcr_enc_strings[] = {
716 "xvYCC 601", 716 "xvYCC 601",
717 "xvYCC 709", 717 "xvYCC 709",
718 "sYCC", 718 "sYCC",
719 "BT.2020 Non-Constant Luminance", 719 "BT.2020",
720 "BT.2020 Constant Luminance", 720 "BT.2020 Constant Luminance",
721 "SMPTE 240M", 721 "SMPTE 240M",
722 NULL, 722 NULL,
diff --git a/drivers/media/platform/vivid/vivid-tpg.c b/drivers/media/platform/vivid/vivid-tpg.c
index fc9c6536ba02..34493f435d5a 100644
--- a/drivers/media/platform/vivid/vivid-tpg.c
+++ b/drivers/media/platform/vivid/vivid-tpg.c
@@ -352,13 +352,14 @@ static void color_to_ycbcr(struct tpg_data *tpg, int r, int g, int b,
352 { COEFF(0.5, 224), COEFF(-0.4629, 224), COEFF(-0.0405, 224) }, 352 { COEFF(0.5, 224), COEFF(-0.4629, 224), COEFF(-0.0405, 224) },
353 }; 353 };
354 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; 354 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
355 unsigned y_offset = full ? 0 : 16;
355 int lin_y, yc; 356 int lin_y, yc;
356 357
357 switch (tpg->real_ycbcr_enc) { 358 switch (tpg->real_ycbcr_enc) {
358 case V4L2_YCBCR_ENC_601: 359 case V4L2_YCBCR_ENC_601:
359 case V4L2_YCBCR_ENC_XV601: 360 case V4L2_YCBCR_ENC_XV601:
360 case V4L2_YCBCR_ENC_SYCC: 361 case V4L2_YCBCR_ENC_SYCC:
361 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, 16, y, cb, cr); 362 rgb2ycbcr(full ? bt601_full : bt601, r, g, b, y_offset, y, cb, cr);
362 break; 363 break;
363 case V4L2_YCBCR_ENC_BT2020: 364 case V4L2_YCBCR_ENC_BT2020:
364 rgb2ycbcr(bt2020, r, g, b, 16, y, cb, cr); 365 rgb2ycbcr(bt2020, r, g, b, 16, y, cb, cr);
@@ -384,7 +385,7 @@ static void color_to_ycbcr(struct tpg_data *tpg, int r, int g, int b,
384 case V4L2_YCBCR_ENC_709: 385 case V4L2_YCBCR_ENC_709:
385 case V4L2_YCBCR_ENC_XV709: 386 case V4L2_YCBCR_ENC_XV709:
386 default: 387 default:
387 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, 0, y, cb, cr); 388 rgb2ycbcr(full ? rec709_full : rec709, r, g, b, y_offset, y, cb, cr);
388 break; 389 break;
389 } 390 }
390} 391}
@@ -439,13 +440,14 @@ static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr,
439 { COEFF(1, 219), COEFF(1.8814, 224), COEFF(0, 224) }, 440 { COEFF(1, 219), COEFF(1.8814, 224), COEFF(0, 224) },
440 }; 441 };
441 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE; 442 bool full = tpg->real_quantization == V4L2_QUANTIZATION_FULL_RANGE;
443 unsigned y_offset = full ? 0 : 16;
442 int lin_r, lin_g, lin_b, lin_y; 444 int lin_r, lin_g, lin_b, lin_y;
443 445
444 switch (tpg->real_ycbcr_enc) { 446 switch (tpg->real_ycbcr_enc) {
445 case V4L2_YCBCR_ENC_601: 447 case V4L2_YCBCR_ENC_601:
446 case V4L2_YCBCR_ENC_XV601: 448 case V4L2_YCBCR_ENC_XV601:
447 case V4L2_YCBCR_ENC_SYCC: 449 case V4L2_YCBCR_ENC_SYCC:
448 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, 16, r, g, b); 450 ycbcr2rgb(full ? bt601_full : bt601, y, cb, cr, y_offset, r, g, b);
449 break; 451 break;
450 case V4L2_YCBCR_ENC_BT2020: 452 case V4L2_YCBCR_ENC_BT2020:
451 ycbcr2rgb(bt2020, y, cb, cr, 16, r, g, b); 453 ycbcr2rgb(bt2020, y, cb, cr, 16, r, g, b);
@@ -480,7 +482,7 @@ static void ycbcr_to_color(struct tpg_data *tpg, int y, int cb, int cr,
480 case V4L2_YCBCR_ENC_709: 482 case V4L2_YCBCR_ENC_709:
481 case V4L2_YCBCR_ENC_XV709: 483 case V4L2_YCBCR_ENC_XV709:
482 default: 484 default:
483 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, 16, r, g, b); 485 ycbcr2rgb(full ? rec709_full : rec709, y, cb, cr, y_offset, r, g, b);
484 break; 486 break;
485 } 487 }
486} 488}
diff --git a/drivers/media/platform/vivid/vivid-tpg.h b/drivers/media/platform/vivid/vivid-tpg.h
index 9dc463a40ed3..bd8b1c760b3f 100644
--- a/drivers/media/platform/vivid/vivid-tpg.h
+++ b/drivers/media/platform/vivid/vivid-tpg.h
@@ -20,7 +20,6 @@
20#ifndef _VIVID_TPG_H_ 20#ifndef _VIVID_TPG_H_
21#define _VIVID_TPG_H_ 21#define _VIVID_TPG_H_
22 22
23#include <linux/version.h>
24#include <linux/types.h> 23#include <linux/types.h>
25#include <linux/errno.h> 24#include <linux/errno.h>
26#include <linux/random.h> 25#include <linux/random.h>
diff --git a/drivers/media/platform/vsp1/vsp1.h b/drivers/media/platform/vsp1/vsp1.h
index 12467191dff4..989e96f7e360 100644
--- a/drivers/media/platform/vsp1/vsp1.h
+++ b/drivers/media/platform/vsp1/vsp1.h
@@ -16,7 +16,6 @@
16#include <linux/io.h> 16#include <linux/io.h>
17#include <linux/list.h> 17#include <linux/list.h>
18#include <linux/mutex.h> 18#include <linux/mutex.h>
19#include <linux/platform_data/vsp1.h>
20 19
21#include <media/media-device.h> 20#include <media/media-device.h>
22#include <media/v4l2-device.h> 21#include <media/v4l2-device.h>
@@ -40,9 +39,20 @@ struct vsp1_uds;
40#define VSP1_MAX_UDS 3 39#define VSP1_MAX_UDS 3
41#define VSP1_MAX_WPF 4 40#define VSP1_MAX_WPF 4
42 41
42#define VSP1_HAS_LIF (1 << 0)
43#define VSP1_HAS_LUT (1 << 1)
44#define VSP1_HAS_SRU (1 << 2)
45
46struct vsp1_platform_data {
47 unsigned int features;
48 unsigned int rpf_count;
49 unsigned int uds_count;
50 unsigned int wpf_count;
51};
52
43struct vsp1_device { 53struct vsp1_device {
44 struct device *dev; 54 struct device *dev;
45 struct vsp1_platform_data *pdata; 55 struct vsp1_platform_data pdata;
46 56
47 void __iomem *mmio; 57 void __iomem *mmio;
48 struct clk *clock; 58 struct clk *clock;
diff --git a/drivers/media/platform/vsp1/vsp1_bru.c b/drivers/media/platform/vsp1/vsp1_bru.c
index b21f381a9862..401e2b77a0b6 100644
--- a/drivers/media/platform/vsp1/vsp1_bru.c
+++ b/drivers/media/platform/vsp1/vsp1_bru.c
@@ -20,7 +20,7 @@
20#include "vsp1_bru.h" 20#include "vsp1_bru.h"
21#include "vsp1_rwpf.h" 21#include "vsp1_rwpf.h"
22 22
23#define BRU_MIN_SIZE 4U 23#define BRU_MIN_SIZE 1U
24#define BRU_MAX_SIZE 8190U 24#define BRU_MAX_SIZE 8190U
25 25
26/* ----------------------------------------------------------------------------- 26/* -----------------------------------------------------------------------------
diff --git a/drivers/media/platform/vsp1/vsp1_drv.c b/drivers/media/platform/vsp1/vsp1_drv.c
index 5eb16e87d53f..913485a90e97 100644
--- a/drivers/media/platform/vsp1/vsp1_drv.c
+++ b/drivers/media/platform/vsp1/vsp1_drv.c
@@ -40,7 +40,7 @@ static irqreturn_t vsp1_irq_handler(int irq, void *data)
40 irqreturn_t ret = IRQ_NONE; 40 irqreturn_t ret = IRQ_NONE;
41 unsigned int i; 41 unsigned int i;
42 42
43 for (i = 0; i < vsp1->pdata->wpf_count; ++i) { 43 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
44 struct vsp1_rwpf *wpf = vsp1->wpf[i]; 44 struct vsp1_rwpf *wpf = vsp1->wpf[i];
45 struct vsp1_pipeline *pipe; 45 struct vsp1_pipeline *pipe;
46 u32 status; 46 u32 status;
@@ -181,7 +181,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
181 181
182 list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities); 182 list_add_tail(&vsp1->hst->entity.list_dev, &vsp1->entities);
183 183
184 if (vsp1->pdata->features & VSP1_HAS_LIF) { 184 if (vsp1->pdata.features & VSP1_HAS_LIF) {
185 vsp1->lif = vsp1_lif_create(vsp1); 185 vsp1->lif = vsp1_lif_create(vsp1);
186 if (IS_ERR(vsp1->lif)) { 186 if (IS_ERR(vsp1->lif)) {
187 ret = PTR_ERR(vsp1->lif); 187 ret = PTR_ERR(vsp1->lif);
@@ -191,7 +191,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
191 list_add_tail(&vsp1->lif->entity.list_dev, &vsp1->entities); 191 list_add_tail(&vsp1->lif->entity.list_dev, &vsp1->entities);
192 } 192 }
193 193
194 if (vsp1->pdata->features & VSP1_HAS_LUT) { 194 if (vsp1->pdata.features & VSP1_HAS_LUT) {
195 vsp1->lut = vsp1_lut_create(vsp1); 195 vsp1->lut = vsp1_lut_create(vsp1);
196 if (IS_ERR(vsp1->lut)) { 196 if (IS_ERR(vsp1->lut)) {
197 ret = PTR_ERR(vsp1->lut); 197 ret = PTR_ERR(vsp1->lut);
@@ -201,7 +201,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
201 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities); 201 list_add_tail(&vsp1->lut->entity.list_dev, &vsp1->entities);
202 } 202 }
203 203
204 for (i = 0; i < vsp1->pdata->rpf_count; ++i) { 204 for (i = 0; i < vsp1->pdata.rpf_count; ++i) {
205 struct vsp1_rwpf *rpf; 205 struct vsp1_rwpf *rpf;
206 206
207 rpf = vsp1_rpf_create(vsp1, i); 207 rpf = vsp1_rpf_create(vsp1, i);
@@ -214,7 +214,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
214 list_add_tail(&rpf->entity.list_dev, &vsp1->entities); 214 list_add_tail(&rpf->entity.list_dev, &vsp1->entities);
215 } 215 }
216 216
217 if (vsp1->pdata->features & VSP1_HAS_SRU) { 217 if (vsp1->pdata.features & VSP1_HAS_SRU) {
218 vsp1->sru = vsp1_sru_create(vsp1); 218 vsp1->sru = vsp1_sru_create(vsp1);
219 if (IS_ERR(vsp1->sru)) { 219 if (IS_ERR(vsp1->sru)) {
220 ret = PTR_ERR(vsp1->sru); 220 ret = PTR_ERR(vsp1->sru);
@@ -224,7 +224,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
224 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities); 224 list_add_tail(&vsp1->sru->entity.list_dev, &vsp1->entities);
225 } 225 }
226 226
227 for (i = 0; i < vsp1->pdata->uds_count; ++i) { 227 for (i = 0; i < vsp1->pdata.uds_count; ++i) {
228 struct vsp1_uds *uds; 228 struct vsp1_uds *uds;
229 229
230 uds = vsp1_uds_create(vsp1, i); 230 uds = vsp1_uds_create(vsp1, i);
@@ -237,7 +237,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
237 list_add_tail(&uds->entity.list_dev, &vsp1->entities); 237 list_add_tail(&uds->entity.list_dev, &vsp1->entities);
238 } 238 }
239 239
240 for (i = 0; i < vsp1->pdata->wpf_count; ++i) { 240 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
241 struct vsp1_rwpf *wpf; 241 struct vsp1_rwpf *wpf;
242 242
243 wpf = vsp1_wpf_create(vsp1, i); 243 wpf = vsp1_wpf_create(vsp1, i);
@@ -261,7 +261,7 @@ static int vsp1_create_entities(struct vsp1_device *vsp1)
261 goto done; 261 goto done;
262 } 262 }
263 263
264 if (vsp1->pdata->features & VSP1_HAS_LIF) { 264 if (vsp1->pdata.features & VSP1_HAS_LIF) {
265 ret = media_entity_create_link( 265 ret = media_entity_create_link(
266 &vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE, 266 &vsp1->wpf[0]->entity.subdev.entity, RWPF_PAD_SOURCE,
267 &vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0); 267 &vsp1->lif->entity.subdev.entity, LIF_PAD_SINK, 0);
@@ -294,7 +294,7 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
294 /* Reset any channel that might be running. */ 294 /* Reset any channel that might be running. */
295 status = vsp1_read(vsp1, VI6_STATUS); 295 status = vsp1_read(vsp1, VI6_STATUS);
296 296
297 for (i = 0; i < vsp1->pdata->wpf_count; ++i) { 297 for (i = 0; i < vsp1->pdata.wpf_count; ++i) {
298 unsigned int timeout; 298 unsigned int timeout;
299 299
300 if (!(status & VI6_STATUS_SYS_ACT(i))) 300 if (!(status & VI6_STATUS_SYS_ACT(i)))
@@ -318,10 +318,10 @@ static int vsp1_device_init(struct vsp1_device *vsp1)
318 vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) | 318 vsp1_write(vsp1, VI6_CLK_DCSWT, (8 << VI6_CLK_DCSWT_CSTPW_SHIFT) |
319 (8 << VI6_CLK_DCSWT_CSTRW_SHIFT)); 319 (8 << VI6_CLK_DCSWT_CSTRW_SHIFT));
320 320
321 for (i = 0; i < vsp1->pdata->rpf_count; ++i) 321 for (i = 0; i < vsp1->pdata.rpf_count; ++i)
322 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED); 322 vsp1_write(vsp1, VI6_DPR_RPF_ROUTE(i), VI6_DPR_NODE_UNUSED);
323 323
324 for (i = 0; i < vsp1->pdata->uds_count; ++i) 324 for (i = 0; i < vsp1->pdata.uds_count; ++i)
325 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED); 325 vsp1_write(vsp1, VI6_DPR_UDS_ROUTE(i), VI6_DPR_NODE_UNUSED);
326 326
327 vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED); 327 vsp1_write(vsp1, VI6_DPR_SRU_ROUTE, VI6_DPR_NODE_UNUSED);
@@ -428,28 +428,36 @@ static const struct dev_pm_ops vsp1_pm_ops = {
428 * Platform Driver 428 * Platform Driver
429 */ 429 */
430 430
431static int vsp1_validate_platform_data(struct platform_device *pdev, 431static int vsp1_parse_dt(struct vsp1_device *vsp1)
432 struct vsp1_platform_data *pdata)
433{ 432{
434 if (pdata == NULL) { 433 struct device_node *np = vsp1->dev->of_node;
435 dev_err(&pdev->dev, "missing platform data\n"); 434 struct vsp1_platform_data *pdata = &vsp1->pdata;
436 return -EINVAL; 435
437 } 436 if (of_property_read_bool(np, "renesas,has-lif"))
437 pdata->features |= VSP1_HAS_LIF;
438 if (of_property_read_bool(np, "renesas,has-lut"))
439 pdata->features |= VSP1_HAS_LUT;
440 if (of_property_read_bool(np, "renesas,has-sru"))
441 pdata->features |= VSP1_HAS_SRU;
442
443 of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
444 of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
445 of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);
438 446
439 if (pdata->rpf_count <= 0 || pdata->rpf_count > VSP1_MAX_RPF) { 447 if (pdata->rpf_count <= 0 || pdata->rpf_count > VSP1_MAX_RPF) {
440 dev_err(&pdev->dev, "invalid number of RPF (%u)\n", 448 dev_err(vsp1->dev, "invalid number of RPF (%u)\n",
441 pdata->rpf_count); 449 pdata->rpf_count);
442 return -EINVAL; 450 return -EINVAL;
443 } 451 }
444 452
445 if (pdata->uds_count <= 0 || pdata->uds_count > VSP1_MAX_UDS) { 453 if (pdata->uds_count <= 0 || pdata->uds_count > VSP1_MAX_UDS) {
446 dev_err(&pdev->dev, "invalid number of UDS (%u)\n", 454 dev_err(vsp1->dev, "invalid number of UDS (%u)\n",
447 pdata->uds_count); 455 pdata->uds_count);
448 return -EINVAL; 456 return -EINVAL;
449 } 457 }
450 458
451 if (pdata->wpf_count <= 0 || pdata->wpf_count > VSP1_MAX_WPF) { 459 if (pdata->wpf_count <= 0 || pdata->wpf_count > VSP1_MAX_WPF) {
452 dev_err(&pdev->dev, "invalid number of WPF (%u)\n", 460 dev_err(vsp1->dev, "invalid number of WPF (%u)\n",
453 pdata->wpf_count); 461 pdata->wpf_count);
454 return -EINVAL; 462 return -EINVAL;
455 } 463 }
@@ -457,33 +465,6 @@ static int vsp1_validate_platform_data(struct platform_device *pdev,
457 return 0; 465 return 0;
458} 466}
459 467
460static struct vsp1_platform_data *
461vsp1_get_platform_data(struct platform_device *pdev)
462{
463 struct device_node *np = pdev->dev.of_node;
464 struct vsp1_platform_data *pdata;
465
466 if (!IS_ENABLED(CONFIG_OF) || np == NULL)
467 return pdev->dev.platform_data;
468
469 pdata = devm_kzalloc(&pdev->dev, sizeof(*pdata), GFP_KERNEL);
470 if (pdata == NULL)
471 return NULL;
472
473 if (of_property_read_bool(np, "renesas,has-lif"))
474 pdata->features |= VSP1_HAS_LIF;
475 if (of_property_read_bool(np, "renesas,has-lut"))
476 pdata->features |= VSP1_HAS_LUT;
477 if (of_property_read_bool(np, "renesas,has-sru"))
478 pdata->features |= VSP1_HAS_SRU;
479
480 of_property_read_u32(np, "renesas,#rpf", &pdata->rpf_count);
481 of_property_read_u32(np, "renesas,#uds", &pdata->uds_count);
482 of_property_read_u32(np, "renesas,#wpf", &pdata->wpf_count);
483
484 return pdata;
485}
486
487static int vsp1_probe(struct platform_device *pdev) 468static int vsp1_probe(struct platform_device *pdev)
488{ 469{
489 struct vsp1_device *vsp1; 470 struct vsp1_device *vsp1;
@@ -499,11 +480,7 @@ static int vsp1_probe(struct platform_device *pdev)
499 mutex_init(&vsp1->lock); 480 mutex_init(&vsp1->lock);
500 INIT_LIST_HEAD(&vsp1->entities); 481 INIT_LIST_HEAD(&vsp1->entities);
501 482
502 vsp1->pdata = vsp1_get_platform_data(pdev); 483 ret = vsp1_parse_dt(vsp1);
503 if (vsp1->pdata == NULL)
504 return -ENODEV;
505
506 ret = vsp1_validate_platform_data(pdev, vsp1->pdata);
507 if (ret < 0) 484 if (ret < 0)
508 return ret; 485 return ret;
509 486
diff --git a/drivers/media/platform/vsp1/vsp1_hsit.c b/drivers/media/platform/vsp1/vsp1_hsit.c
index 80bedc554ee3..0bc0471746c9 100644
--- a/drivers/media/platform/vsp1/vsp1_hsit.c
+++ b/drivers/media/platform/vsp1/vsp1_hsit.c
@@ -26,11 +26,6 @@
26 * Device Access 26 * Device Access
27 */ 27 */
28 28
29static inline u32 vsp1_hsit_read(struct vsp1_hsit *hsit, u32 reg)
30{
31 return vsp1_read(hsit->entity.vsp1, reg);
32}
33
34static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, u32 reg, u32 data) 29static inline void vsp1_hsit_write(struct vsp1_hsit *hsit, u32 reg, u32 data)
35{ 30{
36 vsp1_write(hsit->entity.vsp1, reg, data); 31 vsp1_write(hsit->entity.vsp1, reg, data);
diff --git a/drivers/media/platform/vsp1/vsp1_regs.h b/drivers/media/platform/vsp1/vsp1_regs.h
index 55f163d32d15..da3c573e1efc 100644
--- a/drivers/media/platform/vsp1/vsp1_regs.h
+++ b/drivers/media/platform/vsp1/vsp1_regs.h
@@ -43,12 +43,12 @@
43#define VI6_DISP_IRQ_ENB 0x0078 43#define VI6_DISP_IRQ_ENB 0x0078
44#define VI6_DISP_IRQ_ENB_DSTE (1 << 8) 44#define VI6_DISP_IRQ_ENB_DSTE (1 << 8)
45#define VI6_DISP_IRQ_ENB_MAEE (1 << 5) 45#define VI6_DISP_IRQ_ENB_MAEE (1 << 5)
46#define VI6_DISP_IRQ_ENB_LNEE(n) (1 << ((n) + 4)) 46#define VI6_DISP_IRQ_ENB_LNEE(n) (1 << (n))
47 47
48#define VI6_DISP_IRQ_STA 0x007c 48#define VI6_DISP_IRQ_STA 0x007c
49#define VI6_DISP_IRQ_STA_DSE (1 << 8) 49#define VI6_DISP_IRQ_STA_DSE (1 << 8)
50#define VI6_DISP_IRQ_STA_MAE (1 << 5) 50#define VI6_DISP_IRQ_STA_MAE (1 << 5)
51#define VI6_DISP_IRQ_STA_LNE(n) (1 << ((n) + 4)) 51#define VI6_DISP_IRQ_STA_LNE(n) (1 << (n))
52 52
53#define VI6_WPF_LINE_COUNT(n) (0x0084 + (n) * 4) 53#define VI6_WPF_LINE_COUNT(n) (0x0084 + (n) * 4)
54#define VI6_WPF_LINE_COUNT_MASK (0x1fffff << 0) 54#define VI6_WPF_LINE_COUNT_MASK (0x1fffff << 0)
diff --git a/drivers/media/platform/vsp1/vsp1_rpf.c b/drivers/media/platform/vsp1/vsp1_rpf.c
index d14d26b718ef..3294529a3108 100644
--- a/drivers/media/platform/vsp1/vsp1_rpf.c
+++ b/drivers/media/platform/vsp1/vsp1_rpf.c
@@ -106,11 +106,22 @@ static int rpf_s_stream(struct v4l2_subdev *subdev, int enable)
106 + crop->left * fmtinfo->bpp[0] / 8; 106 + crop->left * fmtinfo->bpp[0] / 8;
107 pstride = format->plane_fmt[0].bytesperline 107 pstride = format->plane_fmt[0].bytesperline
108 << VI6_RPF_SRCM_PSTRIDE_Y_SHIFT; 108 << VI6_RPF_SRCM_PSTRIDE_Y_SHIFT;
109
110 vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y,
111 rpf->buf_addr[0] + rpf->offsets[0]);
112
109 if (format->num_planes > 1) { 113 if (format->num_planes > 1) {
110 rpf->offsets[1] = crop->top * format->plane_fmt[1].bytesperline 114 rpf->offsets[1] = crop->top * format->plane_fmt[1].bytesperline
111 + crop->left * fmtinfo->bpp[1] / 8; 115 + crop->left * fmtinfo->bpp[1] / 8;
112 pstride |= format->plane_fmt[1].bytesperline 116 pstride |= format->plane_fmt[1].bytesperline
113 << VI6_RPF_SRCM_PSTRIDE_C_SHIFT; 117 << VI6_RPF_SRCM_PSTRIDE_C_SHIFT;
118
119 vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C0,
120 rpf->buf_addr[1] + rpf->offsets[1]);
121
122 if (format->num_planes > 2)
123 vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_C1,
124 rpf->buf_addr[2] + rpf->offsets[1]);
114 } 125 }
115 126
116 vsp1_rpf_write(rpf, VI6_RPF_SRCM_PSTRIDE, pstride); 127 vsp1_rpf_write(rpf, VI6_RPF_SRCM_PSTRIDE, pstride);
@@ -179,6 +190,13 @@ static void rpf_vdev_queue(struct vsp1_video *video,
179 struct vsp1_video_buffer *buf) 190 struct vsp1_video_buffer *buf)
180{ 191{
181 struct vsp1_rwpf *rpf = container_of(video, struct vsp1_rwpf, video); 192 struct vsp1_rwpf *rpf = container_of(video, struct vsp1_rwpf, video);
193 unsigned int i;
194
195 for (i = 0; i < 3; ++i)
196 rpf->buf_addr[i] = buf->addr[i];
197
198 if (!vsp1_entity_is_streaming(&rpf->entity))
199 return;
182 200
183 vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y, 201 vsp1_rpf_write(rpf, VI6_RPF_SRCM_ADDR_Y,
184 buf->addr[0] + rpf->offsets[0]); 202 buf->addr[0] + rpf->offsets[0]);
diff --git a/drivers/media/platform/vsp1/vsp1_rwpf.h b/drivers/media/platform/vsp1/vsp1_rwpf.h
index 28dd9e7b3838..2cf1f13d3bf9 100644
--- a/drivers/media/platform/vsp1/vsp1_rwpf.h
+++ b/drivers/media/platform/vsp1/vsp1_rwpf.h
@@ -39,6 +39,7 @@ struct vsp1_rwpf {
39 struct v4l2_rect crop; 39 struct v4l2_rect crop;
40 40
41 unsigned int offsets[2]; 41 unsigned int offsets[2];
42 dma_addr_t buf_addr[3];
42}; 43};
43 44
44static inline struct vsp1_rwpf *to_rwpf(struct v4l2_subdev *subdev) 45static inline struct vsp1_rwpf *to_rwpf(struct v4l2_subdev *subdev)
diff --git a/drivers/media/platform/vsp1/vsp1_wpf.c b/drivers/media/platform/vsp1/vsp1_wpf.c
index 6e057762c933..1d2b3a2f1573 100644
--- a/drivers/media/platform/vsp1/vsp1_wpf.c
+++ b/drivers/media/platform/vsp1/vsp1_wpf.c
@@ -92,19 +92,20 @@ static int wpf_s_stream(struct v4l2_subdev *subdev, int enable)
92 return 0; 92 return 0;
93 } 93 }
94 94
95 /* Sources. If the pipeline has a single input configure it as the 95 /* Sources. If the pipeline has a single input and BRU is not used,
96 * master layer. Otherwise configure all inputs as sub-layers and 96 * configure it as the master layer. Otherwise configure all
97 * select the virtual RPF as the master layer. 97 * inputs as sub-layers and select the virtual RPF as the master
98 * layer.
98 */ 99 */
99 for (i = 0; i < pipe->num_inputs; ++i) { 100 for (i = 0; i < pipe->num_inputs; ++i) {
100 struct vsp1_rwpf *input = pipe->inputs[i]; 101 struct vsp1_rwpf *input = pipe->inputs[i];
101 102
102 srcrpf |= pipe->num_inputs == 1 103 srcrpf |= (!pipe->bru && pipe->num_inputs == 1)
103 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index) 104 ? VI6_WPF_SRCRPF_RPF_ACT_MST(input->entity.index)
104 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index); 105 : VI6_WPF_SRCRPF_RPF_ACT_SUB(input->entity.index);
105 } 106 }
106 107
107 if (pipe->num_inputs > 1) 108 if (pipe->bru || pipe->num_inputs > 1)
108 srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST; 109 srcrpf |= VI6_WPF_SRCRPF_VIRACT_MST;
109 110
110 vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf); 111 vsp1_wpf_write(wpf, VI6_WPF_SRCRPF, srcrpf);
@@ -280,7 +281,7 @@ struct vsp1_rwpf *vsp1_wpf_create(struct vsp1_device *vsp1, unsigned int index)
280 * except for the WPF0 source link if a LIF is present. 281 * except for the WPF0 source link if a LIF is present.
281 */ 282 */
282 flags = MEDIA_LNK_FL_ENABLED; 283 flags = MEDIA_LNK_FL_ENABLED;
283 if (!(vsp1->pdata->features & VSP1_HAS_LIF) || index != 0) 284 if (!(vsp1->pdata.features & VSP1_HAS_LIF) || index != 0)
284 flags |= MEDIA_LNK_FL_IMMUTABLE; 285 flags |= MEDIA_LNK_FL_IMMUTABLE;
285 286
286 ret = media_entity_create_link(&wpf->entity.subdev.entity, 287 ret = media_entity_create_link(&wpf->entity.subdev.entity,
diff --git a/drivers/media/radio/radio-aimslab.c b/drivers/media/radio/radio-aimslab.c
index a739ad492e7b..ea9308796741 100644
--- a/drivers/media/radio/radio-aimslab.c
+++ b/drivers/media/radio/radio-aimslab.c
@@ -129,11 +129,11 @@ static int rtrack_s_mute_volume(struct radio_isa_card *isa, bool mute, int vol)
129 } else if (curvol < vol) { 129 } else if (curvol < vol) {
130 outb(0x98, isa->io); /* volume up + sigstr + on */ 130 outb(0x98, isa->io); /* volume up + sigstr + on */
131 for (; curvol < vol; curvol++) 131 for (; curvol < vol; curvol++)
132 udelay(3000); 132 mdelay(3);
133 } else if (curvol > vol) { 133 } else if (curvol > vol) {
134 outb(0x58, isa->io); /* volume down + sigstr + on */ 134 outb(0x58, isa->io); /* volume down + sigstr + on */
135 for (; curvol > vol; curvol--) 135 for (; curvol > vol; curvol--)
136 udelay(3000); 136 mdelay(3);
137 } 137 }
138 outb(0xd8, isa->io); /* volume steady + sigstr + on */ 138 outb(0xd8, isa->io); /* volume steady + sigstr + on */
139 rt->curvol = vol; 139 rt->curvol = vol;
diff --git a/drivers/media/radio/tea575x.c b/drivers/media/radio/tea575x.c
index f1a0867789fe..43d1ea53cb66 100644
--- a/drivers/media/radio/tea575x.c
+++ b/drivers/media/radio/tea575x.c
@@ -247,10 +247,9 @@ static int vidioc_querycap(struct file *file, void *priv,
247 return 0; 247 return 0;
248} 248}
249 249
250static int vidioc_enum_freq_bands(struct file *file, void *priv, 250int snd_tea575x_enum_freq_bands(struct snd_tea575x *tea,
251 struct v4l2_frequency_band *band) 251 struct v4l2_frequency_band *band)
252{ 252{
253 struct snd_tea575x *tea = video_drvdata(file);
254 int index; 253 int index;
255 254
256 if (band->tuner != 0) 255 if (band->tuner != 0)
@@ -279,18 +278,25 @@ static int vidioc_enum_freq_bands(struct file *file, void *priv,
279 278
280 return 0; 279 return 0;
281} 280}
281EXPORT_SYMBOL(snd_tea575x_enum_freq_bands);
282 282
283static int vidioc_g_tuner(struct file *file, void *priv, 283static int vidioc_enum_freq_bands(struct file *file, void *priv,
284 struct v4l2_tuner *v) 284 struct v4l2_frequency_band *band)
285{ 285{
286 struct snd_tea575x *tea = video_drvdata(file); 286 struct snd_tea575x *tea = video_drvdata(file);
287
288 return snd_tea575x_enum_freq_bands(tea, band);
289}
290
291int snd_tea575x_g_tuner(struct snd_tea575x *tea, struct v4l2_tuner *v)
292{
287 struct v4l2_frequency_band band_fm = { 0, }; 293 struct v4l2_frequency_band band_fm = { 0, };
288 294
289 if (v->index > 0) 295 if (v->index > 0)
290 return -EINVAL; 296 return -EINVAL;
291 297
292 snd_tea575x_read(tea); 298 snd_tea575x_read(tea);
293 vidioc_enum_freq_bands(file, priv, &band_fm); 299 snd_tea575x_enum_freq_bands(tea, &band_fm);
294 300
295 memset(v, 0, sizeof(*v)); 301 memset(v, 0, sizeof(*v));
296 strlcpy(v->name, tea->has_am ? "FM/AM" : "FM", sizeof(v->name)); 302 strlcpy(v->name, tea->has_am ? "FM/AM" : "FM", sizeof(v->name));
@@ -304,6 +310,15 @@ static int vidioc_g_tuner(struct file *file, void *priv,
304 v->signal = tea->tuned ? 0xffff : 0; 310 v->signal = tea->tuned ? 0xffff : 0;
305 return 0; 311 return 0;
306} 312}
313EXPORT_SYMBOL(snd_tea575x_g_tuner);
314
315static int vidioc_g_tuner(struct file *file, void *priv,
316 struct v4l2_tuner *v)
317{
318 struct snd_tea575x *tea = video_drvdata(file);
319
320 return snd_tea575x_g_tuner(tea, v);
321}
307 322
308static int vidioc_s_tuner(struct file *file, void *priv, 323static int vidioc_s_tuner(struct file *file, void *priv,
309 const struct v4l2_tuner *v) 324 const struct v4l2_tuner *v)
@@ -356,10 +371,9 @@ static int vidioc_s_frequency(struct file *file, void *priv,
356 return 0; 371 return 0;
357} 372}
358 373
359static int vidioc_s_hw_freq_seek(struct file *file, void *fh, 374int snd_tea575x_s_hw_freq_seek(struct file *file, struct snd_tea575x *tea,
360 const struct v4l2_hw_freq_seek *a) 375 const struct v4l2_hw_freq_seek *a)
361{ 376{
362 struct snd_tea575x *tea = video_drvdata(file);
363 unsigned long timeout; 377 unsigned long timeout;
364 int i, spacing; 378 int i, spacing;
365 379
@@ -442,6 +456,15 @@ static int vidioc_s_hw_freq_seek(struct file *file, void *fh,
442 snd_tea575x_set_freq(tea); 456 snd_tea575x_set_freq(tea);
443 return -ENODATA; 457 return -ENODATA;
444} 458}
459EXPORT_SYMBOL(snd_tea575x_s_hw_freq_seek);
460
461static int vidioc_s_hw_freq_seek(struct file *file, void *fh,
462 const struct v4l2_hw_freq_seek *a)
463{
464 struct snd_tea575x *tea = video_drvdata(file);
465
466 return snd_tea575x_s_hw_freq_seek(file, tea, a);
467}
445 468
446static int tea575x_s_ctrl(struct v4l2_ctrl *ctrl) 469static int tea575x_s_ctrl(struct v4l2_ctrl *ctrl)
447{ 470{
diff --git a/drivers/media/radio/wl128x/fmdrv_rx.c b/drivers/media/radio/wl128x/fmdrv_rx.c
index 09632cb26cb6..cfaeb2417fbb 100644
--- a/drivers/media/radio/wl128x/fmdrv_rx.c
+++ b/drivers/media/radio/wl128x/fmdrv_rx.c
@@ -785,22 +785,6 @@ int fm_rx_set_rds_system(struct fmdev *fmdev, u8 rds_mode)
785 return 0; 785 return 0;
786} 786}
787 787
788/* Returns current RDS operation mode */
789int fm_rx_get_rds_system(struct fmdev *fmdev, u8 *rds_mode)
790{
791 if (fmdev->curr_fmmode != FM_MODE_RX)
792 return -EPERM;
793
794 if (rds_mode == NULL) {
795 fmerr("Invalid memory\n");
796 return -ENOMEM;
797 }
798
799 *rds_mode = fmdev->rx.rds_mode;
800
801 return 0;
802}
803
804/* Configures Alternate Frequency switch mode */ 788/* Configures Alternate Frequency switch mode */
805int fm_rx_set_af_switch(struct fmdev *fmdev, u8 af_mode) 789int fm_rx_set_af_switch(struct fmdev *fmdev, u8 af_mode)
806{ 790{
diff --git a/drivers/media/radio/wl128x/fmdrv_rx.h b/drivers/media/radio/wl128x/fmdrv_rx.h
index 32add81f8d87..23922188882f 100644
--- a/drivers/media/radio/wl128x/fmdrv_rx.h
+++ b/drivers/media/radio/wl128x/fmdrv_rx.h
@@ -40,7 +40,6 @@ void fm_rx_reset_station_info(struct fmdev *);
40int fm_rx_seek(struct fmdev *, u32, u32, u32); 40int fm_rx_seek(struct fmdev *, u32, u32, u32);
41 41
42int fm_rx_get_rds_mode(struct fmdev *, u8 *); 42int fm_rx_get_rds_mode(struct fmdev *, u8 *);
43int fm_rx_get_rds_system(struct fmdev *, u8 *);
44int fm_rx_get_mute_mode(struct fmdev *, u8 *); 43int fm_rx_get_mute_mode(struct fmdev *, u8 *);
45int fm_rx_get_volume(struct fmdev *, u16 *); 44int fm_rx_get_volume(struct fmdev *, u16 *);
46int fm_rx_get_band_freq_range(struct fmdev *, 45int fm_rx_get_band_freq_range(struct fmdev *,
diff --git a/drivers/media/rc/img-ir/Kconfig b/drivers/media/rc/img-ir/Kconfig
index 580715c7fc5e..a896d3c83a1c 100644
--- a/drivers/media/rc/img-ir/Kconfig
+++ b/drivers/media/rc/img-ir/Kconfig
@@ -60,3 +60,18 @@ config IR_IMG_SANYO
60 help 60 help
61 Say Y here to enable support for the Sanyo protocol (used by Sanyo, 61 Say Y here to enable support for the Sanyo protocol (used by Sanyo,
62 Aiwa, Chinon remotes) in the ImgTec infrared decoder block. 62 Aiwa, Chinon remotes) in the ImgTec infrared decoder block.
63
64config IR_IMG_RC5
65 bool "Philips RC5 protocol support"
66 depends on IR_IMG_HW
67 help
68 Say Y here to enable support for the RC5 protocol in the ImgTec
69 infrared decoder block.
70
71config IR_IMG_RC6
72 bool "Philips RC6 protocol support"
73 depends on IR_IMG_HW
74 help
75 Say Y here to enable support for the RC6 protocol in the ImgTec
76 infrared decoder block.
77 Note: This version only supports mode 0.
diff --git a/drivers/media/rc/img-ir/Makefile b/drivers/media/rc/img-ir/Makefile
index 92a459d99509..8e6d458e66ad 100644
--- a/drivers/media/rc/img-ir/Makefile
+++ b/drivers/media/rc/img-ir/Makefile
@@ -6,6 +6,8 @@ img-ir-$(CONFIG_IR_IMG_JVC) += img-ir-jvc.o
6img-ir-$(CONFIG_IR_IMG_SONY) += img-ir-sony.o 6img-ir-$(CONFIG_IR_IMG_SONY) += img-ir-sony.o
7img-ir-$(CONFIG_IR_IMG_SHARP) += img-ir-sharp.o 7img-ir-$(CONFIG_IR_IMG_SHARP) += img-ir-sharp.o
8img-ir-$(CONFIG_IR_IMG_SANYO) += img-ir-sanyo.o 8img-ir-$(CONFIG_IR_IMG_SANYO) += img-ir-sanyo.o
9img-ir-$(CONFIG_IR_IMG_RC5) += img-ir-rc5.o
10img-ir-$(CONFIG_IR_IMG_RC6) += img-ir-rc6.o
9img-ir-objs := $(img-ir-y) 11img-ir-objs := $(img-ir-y)
10 12
11obj-$(CONFIG_IR_IMG) += img-ir.o 13obj-$(CONFIG_IR_IMG) += img-ir.o
diff --git a/drivers/media/rc/img-ir/img-ir-hw.c b/drivers/media/rc/img-ir/img-ir-hw.c
index 2fd47c9bf5d8..7bb71bc9f534 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.c
+++ b/drivers/media/rc/img-ir/img-ir-hw.c
@@ -42,6 +42,12 @@ static struct img_ir_decoder *img_ir_decoders[] = {
42#ifdef CONFIG_IR_IMG_SANYO 42#ifdef CONFIG_IR_IMG_SANYO
43 &img_ir_sanyo, 43 &img_ir_sanyo,
44#endif 44#endif
45#ifdef CONFIG_IR_IMG_RC5
46 &img_ir_rc5,
47#endif
48#ifdef CONFIG_IR_IMG_RC6
49 &img_ir_rc6,
50#endif
45 NULL 51 NULL
46}; 52};
47 53
@@ -52,6 +58,11 @@ static struct img_ir_decoder *img_ir_decoders[] = {
52 58
53#define IMG_IR_QUIRK_CODE_BROKEN 0x1 /* Decode is broken */ 59#define IMG_IR_QUIRK_CODE_BROKEN 0x1 /* Decode is broken */
54#define IMG_IR_QUIRK_CODE_LEN_INCR 0x2 /* Bit length needs increment */ 60#define IMG_IR_QUIRK_CODE_LEN_INCR 0x2 /* Bit length needs increment */
61/*
62 * The decoder generates rapid interrupts without actually having
63 * received any new data after an incomplete IR code is decoded.
64 */
65#define IMG_IR_QUIRK_CODE_IRQ 0x4
55 66
56/* functions for preprocessing timings, ensuring max is set */ 67/* functions for preprocessing timings, ensuring max is set */
57 68
@@ -542,6 +553,7 @@ static void img_ir_set_decoder(struct img_ir_priv *priv,
542 */ 553 */
543 spin_unlock_irq(&priv->lock); 554 spin_unlock_irq(&priv->lock);
544 del_timer_sync(&hw->end_timer); 555 del_timer_sync(&hw->end_timer);
556 del_timer_sync(&hw->suspend_timer);
545 spin_lock_irq(&priv->lock); 557 spin_lock_irq(&priv->lock);
546 558
547 hw->stopping = false; 559 hw->stopping = false;
@@ -806,20 +818,24 @@ static void img_ir_handle_data(struct img_ir_priv *priv, u32 len, u64 raw)
806 struct img_ir_priv_hw *hw = &priv->hw; 818 struct img_ir_priv_hw *hw = &priv->hw;
807 const struct img_ir_decoder *dec = hw->decoder; 819 const struct img_ir_decoder *dec = hw->decoder;
808 int ret = IMG_IR_SCANCODE; 820 int ret = IMG_IR_SCANCODE;
809 u32 scancode; 821 struct img_ir_scancode_req request;
810 enum rc_type protocol = RC_TYPE_UNKNOWN; 822
823 request.protocol = RC_TYPE_UNKNOWN;
824 request.toggle = 0;
811 825
812 if (dec->scancode) 826 if (dec->scancode)
813 ret = dec->scancode(len, raw, &protocol, &scancode, hw->enabled_protocols); 827 ret = dec->scancode(len, raw, hw->enabled_protocols, &request);
814 else if (len >= 32) 828 else if (len >= 32)
815 scancode = (u32)raw; 829 request.scancode = (u32)raw;
816 else if (len < 32) 830 else if (len < 32)
817 scancode = (u32)raw & ((1 << len)-1); 831 request.scancode = (u32)raw & ((1 << len)-1);
818 dev_dbg(priv->dev, "data (%u bits) = %#llx\n", 832 dev_dbg(priv->dev, "data (%u bits) = %#llx\n",
819 len, (unsigned long long)raw); 833 len, (unsigned long long)raw);
820 if (ret == IMG_IR_SCANCODE) { 834 if (ret == IMG_IR_SCANCODE) {
821 dev_dbg(priv->dev, "decoded scan code %#x\n", scancode); 835 dev_dbg(priv->dev, "decoded scan code %#x, toggle %u\n",
822 rc_keydown(hw->rdev, protocol, scancode, 0); 836 request.scancode, request.toggle);
837 rc_keydown(hw->rdev, request.protocol, request.scancode,
838 request.toggle);
823 img_ir_end_repeat(priv); 839 img_ir_end_repeat(priv);
824 } else if (ret == IMG_IR_REPEATCODE) { 840 } else if (ret == IMG_IR_REPEATCODE) {
825 if (hw->mode == IMG_IR_M_REPEATING) { 841 if (hw->mode == IMG_IR_M_REPEATING) {
@@ -857,6 +873,29 @@ static void img_ir_end_timer(unsigned long arg)
857 spin_unlock_irq(&priv->lock); 873 spin_unlock_irq(&priv->lock);
858} 874}
859 875
876/*
877 * Timer function to re-enable the current protocol after it had been
878 * cleared when invalid interrupts were generated due to a quirk in the
879 * img-ir decoder.
880 */
881static void img_ir_suspend_timer(unsigned long arg)
882{
883 struct img_ir_priv *priv = (struct img_ir_priv *)arg;
884
885 spin_lock_irq(&priv->lock);
886 /*
887 * Don't overwrite enabled valid/match IRQs if they have already been
888 * changed by e.g. a filter change.
889 */
890 if ((priv->hw.quirk_suspend_irq & IMG_IR_IRQ_EDGE) ==
891 img_ir_read(priv, IMG_IR_IRQ_ENABLE))
892 img_ir_write(priv, IMG_IR_IRQ_ENABLE,
893 priv->hw.quirk_suspend_irq);
894 /* enable */
895 img_ir_write(priv, IMG_IR_CONTROL, priv->hw.reg_timings.ctrl);
896 spin_unlock_irq(&priv->lock);
897}
898
860#ifdef CONFIG_COMMON_CLK 899#ifdef CONFIG_COMMON_CLK
861static void img_ir_change_frequency(struct img_ir_priv *priv, 900static void img_ir_change_frequency(struct img_ir_priv *priv,
862 struct clk_notifier_data *change) 901 struct clk_notifier_data *change)
@@ -922,15 +961,38 @@ void img_ir_isr_hw(struct img_ir_priv *priv, u32 irq_status)
922 if (!hw->decoder) 961 if (!hw->decoder)
923 return; 962 return;
924 963
964 ct = hw->decoder->control.code_type;
965
925 ir_status = img_ir_read(priv, IMG_IR_STATUS); 966 ir_status = img_ir_read(priv, IMG_IR_STATUS);
926 if (!(ir_status & (IMG_IR_RXDVAL | IMG_IR_RXDVALD2))) 967 if (!(ir_status & (IMG_IR_RXDVAL | IMG_IR_RXDVALD2))) {
968 if (!(priv->hw.ct_quirks[ct] & IMG_IR_QUIRK_CODE_IRQ) ||
969 hw->stopping)
970 return;
971 /*
972 * The below functionality is added as a work around to stop
973 * multiple Interrupts generated when an incomplete IR code is
974 * received by the decoder.
975 * The decoder generates rapid interrupts without actually
976 * having received any new data. After a single interrupt it's
977 * expected to clear up, but instead multiple interrupts are
978 * rapidly generated. only way to get out of this loop is to
979 * reset the control register after a short delay.
980 */
981 img_ir_write(priv, IMG_IR_CONTROL, 0);
982 hw->quirk_suspend_irq = img_ir_read(priv, IMG_IR_IRQ_ENABLE);
983 img_ir_write(priv, IMG_IR_IRQ_ENABLE,
984 hw->quirk_suspend_irq & IMG_IR_IRQ_EDGE);
985
986 /* Timer activated to re-enable the protocol. */
987 mod_timer(&hw->suspend_timer,
988 jiffies + msecs_to_jiffies(5));
927 return; 989 return;
990 }
928 ir_status &= ~(IMG_IR_RXDVAL | IMG_IR_RXDVALD2); 991 ir_status &= ~(IMG_IR_RXDVAL | IMG_IR_RXDVALD2);
929 img_ir_write(priv, IMG_IR_STATUS, ir_status); 992 img_ir_write(priv, IMG_IR_STATUS, ir_status);
930 993
931 len = (ir_status & IMG_IR_RXDLEN) >> IMG_IR_RXDLEN_SHIFT; 994 len = (ir_status & IMG_IR_RXDLEN) >> IMG_IR_RXDLEN_SHIFT;
932 /* some versions report wrong length for certain code types */ 995 /* some versions report wrong length for certain code types */
933 ct = hw->decoder->control.code_type;
934 if (hw->ct_quirks[ct] & IMG_IR_QUIRK_CODE_LEN_INCR) 996 if (hw->ct_quirks[ct] & IMG_IR_QUIRK_CODE_LEN_INCR)
935 ++len; 997 ++len;
936 998
@@ -972,7 +1034,7 @@ static void img_ir_probe_hw_caps(struct img_ir_priv *priv)
972 hw->ct_quirks[IMG_IR_CODETYPE_PULSELEN] 1034 hw->ct_quirks[IMG_IR_CODETYPE_PULSELEN]
973 |= IMG_IR_QUIRK_CODE_LEN_INCR; 1035 |= IMG_IR_QUIRK_CODE_LEN_INCR;
974 hw->ct_quirks[IMG_IR_CODETYPE_BIPHASE] 1036 hw->ct_quirks[IMG_IR_CODETYPE_BIPHASE]
975 |= IMG_IR_QUIRK_CODE_BROKEN; 1037 |= IMG_IR_QUIRK_CODE_IRQ;
976 hw->ct_quirks[IMG_IR_CODETYPE_2BITPULSEPOS] 1038 hw->ct_quirks[IMG_IR_CODETYPE_2BITPULSEPOS]
977 |= IMG_IR_QUIRK_CODE_BROKEN; 1039 |= IMG_IR_QUIRK_CODE_BROKEN;
978} 1040}
@@ -991,6 +1053,8 @@ int img_ir_probe_hw(struct img_ir_priv *priv)
991 1053
992 /* Set up the end timer */ 1054 /* Set up the end timer */
993 setup_timer(&hw->end_timer, img_ir_end_timer, (unsigned long)priv); 1055 setup_timer(&hw->end_timer, img_ir_end_timer, (unsigned long)priv);
1056 setup_timer(&hw->suspend_timer, img_ir_suspend_timer,
1057 (unsigned long)priv);
994 1058
995 /* Register a clock notifier */ 1059 /* Register a clock notifier */
996 if (!IS_ERR(priv->clk)) { 1060 if (!IS_ERR(priv->clk)) {
diff --git a/drivers/media/rc/img-ir/img-ir-hw.h b/drivers/media/rc/img-ir/img-ir-hw.h
index 5c2b216c5fe3..91a297731661 100644
--- a/drivers/media/rc/img-ir/img-ir-hw.h
+++ b/drivers/media/rc/img-ir/img-ir-hw.h
@@ -133,6 +133,20 @@ struct img_ir_timing_regvals {
133#define IMG_IR_REPEATCODE 1 /* repeat the previous code */ 133#define IMG_IR_REPEATCODE 1 /* repeat the previous code */
134 134
135/** 135/**
136 * struct img_ir_scancode_req - Scancode request data.
137 * @protocol: Protocol code of received message (defaults to
138 * RC_TYPE_UNKNOWN).
139 * @scancode: Scan code of received message (must be written by
140 * handler if IMG_IR_SCANCODE is returned).
141 * @toggle: Toggle bit (defaults to 0).
142 */
143struct img_ir_scancode_req {
144 enum rc_type protocol;
145 u32 scancode;
146 u8 toggle;
147};
148
149/**
136 * struct img_ir_decoder - Decoder settings for an IR protocol. 150 * struct img_ir_decoder - Decoder settings for an IR protocol.
137 * @type: Protocol types bitmap. 151 * @type: Protocol types bitmap.
138 * @tolerance: Timing tolerance as a percentage (default 10%). 152 * @tolerance: Timing tolerance as a percentage (default 10%).
@@ -162,8 +176,8 @@ struct img_ir_decoder {
162 struct img_ir_control control; 176 struct img_ir_control control;
163 177
164 /* scancode logic */ 178 /* scancode logic */
165 int (*scancode)(int len, u64 raw, enum rc_type *protocol, 179 int (*scancode)(int len, u64 raw, u64 enabled_protocols,
166 u32 *scancode, u64 enabled_protocols); 180 struct img_ir_scancode_req *request);
167 int (*filter)(const struct rc_scancode_filter *in, 181 int (*filter)(const struct rc_scancode_filter *in,
168 struct img_ir_filter *out, u64 protocols); 182 struct img_ir_filter *out, u64 protocols);
169}; 183};
@@ -173,6 +187,8 @@ extern struct img_ir_decoder img_ir_jvc;
173extern struct img_ir_decoder img_ir_sony; 187extern struct img_ir_decoder img_ir_sony;
174extern struct img_ir_decoder img_ir_sharp; 188extern struct img_ir_decoder img_ir_sharp;
175extern struct img_ir_decoder img_ir_sanyo; 189extern struct img_ir_decoder img_ir_sanyo;
190extern struct img_ir_decoder img_ir_rc5;
191extern struct img_ir_decoder img_ir_rc6;
176 192
177/** 193/**
178 * struct img_ir_reg_timings - Reg values for decoder timings at clock rate. 194 * struct img_ir_reg_timings - Reg values for decoder timings at clock rate.
@@ -204,6 +220,7 @@ enum img_ir_mode {
204 * @rdev: Remote control device 220 * @rdev: Remote control device
205 * @clk_nb: Notifier block for clock notify events. 221 * @clk_nb: Notifier block for clock notify events.
206 * @end_timer: Timer until repeat timeout. 222 * @end_timer: Timer until repeat timeout.
223 * @suspend_timer: Timer to re-enable protocol.
207 * @decoder: Current decoder settings. 224 * @decoder: Current decoder settings.
208 * @enabled_protocols: Currently enabled protocols. 225 * @enabled_protocols: Currently enabled protocols.
209 * @clk_hz: Current core clock rate in Hz. 226 * @clk_hz: Current core clock rate in Hz.
@@ -214,12 +231,14 @@ enum img_ir_mode {
214 * @stopping: Indicates that decoder is being taken down and timers 231 * @stopping: Indicates that decoder is being taken down and timers
215 * should not be restarted. 232 * should not be restarted.
216 * @suspend_irqen: Saved IRQ enable mask over suspend. 233 * @suspend_irqen: Saved IRQ enable mask over suspend.
234 * @quirk_suspend_irq: Saved IRQ enable mask over quirk suspend timer.
217 */ 235 */
218struct img_ir_priv_hw { 236struct img_ir_priv_hw {
219 unsigned int ct_quirks[4]; 237 unsigned int ct_quirks[4];
220 struct rc_dev *rdev; 238 struct rc_dev *rdev;
221 struct notifier_block clk_nb; 239 struct notifier_block clk_nb;
222 struct timer_list end_timer; 240 struct timer_list end_timer;
241 struct timer_list suspend_timer;
223 const struct img_ir_decoder *decoder; 242 const struct img_ir_decoder *decoder;
224 u64 enabled_protocols; 243 u64 enabled_protocols;
225 unsigned long clk_hz; 244 unsigned long clk_hz;
@@ -230,6 +249,7 @@ struct img_ir_priv_hw {
230 enum img_ir_mode mode; 249 enum img_ir_mode mode;
231 bool stopping; 250 bool stopping;
232 u32 suspend_irqen; 251 u32 suspend_irqen;
252 u32 quirk_suspend_irq;
233}; 253};
234 254
235static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw) 255static inline bool img_ir_hw_enabled(struct img_ir_priv_hw *hw)
diff --git a/drivers/media/rc/img-ir/img-ir-jvc.c b/drivers/media/rc/img-ir/img-ir-jvc.c
index a60dda8bf706..d3e2fc0bcfe1 100644
--- a/drivers/media/rc/img-ir/img-ir-jvc.c
+++ b/drivers/media/rc/img-ir/img-ir-jvc.c
@@ -12,8 +12,8 @@
12#include "img-ir-hw.h" 12#include "img-ir-hw.h"
13 13
14/* Convert JVC data to a scancode */ 14/* Convert JVC data to a scancode */
15static int img_ir_jvc_scancode(int len, u64 raw, enum rc_type *protocol, 15static int img_ir_jvc_scancode(int len, u64 raw, u64 enabled_protocols,
16 u32 *scancode, u64 enabled_protocols) 16 struct img_ir_scancode_req *request)
17{ 17{
18 unsigned int cust, data; 18 unsigned int cust, data;
19 19
@@ -23,8 +23,8 @@ static int img_ir_jvc_scancode(int len, u64 raw, enum rc_type *protocol,
23 cust = (raw >> 0) & 0xff; 23 cust = (raw >> 0) & 0xff;
24 data = (raw >> 8) & 0xff; 24 data = (raw >> 8) & 0xff;
25 25
26 *protocol = RC_TYPE_JVC; 26 request->protocol = RC_TYPE_JVC;
27 *scancode = cust << 8 | data; 27 request->scancode = cust << 8 | data;
28 return IMG_IR_SCANCODE; 28 return IMG_IR_SCANCODE;
29} 29}
30 30
diff --git a/drivers/media/rc/img-ir/img-ir-nec.c b/drivers/media/rc/img-ir/img-ir-nec.c
index 739897549b5b..27a7ea8f1260 100644
--- a/drivers/media/rc/img-ir/img-ir-nec.c
+++ b/drivers/media/rc/img-ir/img-ir-nec.c
@@ -13,8 +13,8 @@
13#include <linux/bitrev.h> 13#include <linux/bitrev.h>
14 14
15/* Convert NEC data to a scancode */ 15/* Convert NEC data to a scancode */
16static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol, 16static int img_ir_nec_scancode(int len, u64 raw, u64 enabled_protocols,
17 u32 *scancode, u64 enabled_protocols) 17 struct img_ir_scancode_req *request)
18{ 18{
19 unsigned int addr, addr_inv, data, data_inv; 19 unsigned int addr, addr_inv, data, data_inv;
20 /* a repeat code has no data */ 20 /* a repeat code has no data */
@@ -30,23 +30,23 @@ static int img_ir_nec_scancode(int len, u64 raw, enum rc_type *protocol,
30 if ((data_inv ^ data) != 0xff) { 30 if ((data_inv ^ data) != 0xff) {
31 /* 32-bit NEC (used by Apple and TiVo remotes) */ 31 /* 32-bit NEC (used by Apple and TiVo remotes) */
32 /* scan encoding: as transmitted, MSBit = first received bit */ 32 /* scan encoding: as transmitted, MSBit = first received bit */
33 *scancode = bitrev8(addr) << 24 | 33 request->scancode = bitrev8(addr) << 24 |
34 bitrev8(addr_inv) << 16 | 34 bitrev8(addr_inv) << 16 |
35 bitrev8(data) << 8 | 35 bitrev8(data) << 8 |
36 bitrev8(data_inv); 36 bitrev8(data_inv);
37 } else if ((addr_inv ^ addr) != 0xff) { 37 } else if ((addr_inv ^ addr) != 0xff) {
38 /* Extended NEC */ 38 /* Extended NEC */
39 /* scan encoding: AAaaDD */ 39 /* scan encoding: AAaaDD */
40 *scancode = addr << 16 | 40 request->scancode = addr << 16 |
41 addr_inv << 8 | 41 addr_inv << 8 |
42 data; 42 data;
43 } else { 43 } else {
44 /* Normal NEC */ 44 /* Normal NEC */
45 /* scan encoding: AADD */ 45 /* scan encoding: AADD */
46 *scancode = addr << 8 | 46 request->scancode = addr << 8 |
47 data; 47 data;
48 } 48 }
49 *protocol = RC_TYPE_NEC; 49 request->protocol = RC_TYPE_NEC;
50 return IMG_IR_SCANCODE; 50 return IMG_IR_SCANCODE;
51} 51}
52 52
diff --git a/drivers/media/rc/img-ir/img-ir-rc5.c b/drivers/media/rc/img-ir/img-ir-rc5.c
new file mode 100644
index 000000000000..a8a28a377eee
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-rc5.c
@@ -0,0 +1,88 @@
1/*
2 * ImgTec IR Decoder setup for Philips RC-5 protocol.
3 *
4 * Copyright 2012-2014 Imagination Technologies Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include "img-ir-hw.h"
13
14/* Convert RC5 data to a scancode */
15static int img_ir_rc5_scancode(int len, u64 raw, u64 enabled_protocols,
16 struct img_ir_scancode_req *request)
17{
18 unsigned int addr, cmd, tgl, start;
19
20 /* Quirk in the decoder shifts everything by 2 to the left. */
21 raw >>= 2;
22
23 start = (raw >> 13) & 0x01;
24 tgl = (raw >> 11) & 0x01;
25 addr = (raw >> 6) & 0x1f;
26 cmd = raw & 0x3f;
27 /*
28 * 12th bit is used to extend the command in extended RC5 and has
29 * no effect on standard RC5.
30 */
31 cmd += ((raw >> 12) & 0x01) ? 0 : 0x40;
32
33 if (!start)
34 return -EINVAL;
35
36 request->protocol = RC_TYPE_RC5;
37 request->scancode = addr << 8 | cmd;
38 request->toggle = tgl;
39 return IMG_IR_SCANCODE;
40}
41
42/* Convert RC5 scancode to RC5 data filter */
43static int img_ir_rc5_filter(const struct rc_scancode_filter *in,
44 struct img_ir_filter *out, u64 protocols)
45{
46 /* Not supported by the hw. */
47 return -EINVAL;
48}
49
50/*
51 * RC-5 decoder
52 * see http://www.sbprojects.com/knowledge/ir/rc5.php
53 */
54struct img_ir_decoder img_ir_rc5 = {
55 .type = RC_BIT_RC5,
56 .control = {
57 .bitoriend2 = 1,
58 .code_type = IMG_IR_CODETYPE_BIPHASE,
59 .decodend2 = 1,
60 },
61 /* main timings */
62 .tolerance = 16,
63 .unit = 888888, /* 1/36k*32=888.888microseconds */
64 .timings = {
65 /* 10 symbol */
66 .s10 = {
67 .pulse = { 1 },
68 .space = { 1 },
69 },
70
71 /* 11 symbol */
72 .s11 = {
73 .pulse = { 1 },
74 .space = { 1 },
75 },
76
77 /* free time */
78 .ft = {
79 .minlen = 14,
80 .maxlen = 14,
81 .ft_min = 5,
82 },
83 },
84
85 /* scancode logic */
86 .scancode = img_ir_rc5_scancode,
87 .filter = img_ir_rc5_filter,
88};
diff --git a/drivers/media/rc/img-ir/img-ir-rc6.c b/drivers/media/rc/img-ir/img-ir-rc6.c
new file mode 100644
index 000000000000..de1e27534968
--- /dev/null
+++ b/drivers/media/rc/img-ir/img-ir-rc6.c
@@ -0,0 +1,117 @@
1/*
2 * ImgTec IR Decoder setup for Philips RC-6 protocol.
3 *
4 * Copyright 2012-2014 Imagination Technologies Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2 of the License, or (at your
9 * option) any later version.
10 */
11
12#include "img-ir-hw.h"
13
14/* Convert RC6 data to a scancode */
15static int img_ir_rc6_scancode(int len, u64 raw, u64 enabled_protocols,
16 struct img_ir_scancode_req *request)
17{
18 unsigned int addr, cmd, mode, trl1, trl2;
19
20 /*
21 * Due to a side effect of the decoder handling the double length
22 * Trailer bit, the header information is a bit scrambled, and the
23 * raw data is shifted incorrectly.
24 * This workaround effectively recovers the header bits.
25 *
26 * The Header field should look like this:
27 *
28 * StartBit ModeBit2 ModeBit1 ModeBit0 TrailerBit
29 *
30 * But what we get is:
31 *
32 * ModeBit2 ModeBit1 ModeBit0 TrailerBit1 TrailerBit2
33 *
34 * The start bit is not important to recover the scancode.
35 */
36
37 raw >>= 27;
38
39 trl1 = (raw >> 17) & 0x01;
40 trl2 = (raw >> 16) & 0x01;
41
42 mode = (raw >> 18) & 0x07;
43 addr = (raw >> 8) & 0xff;
44 cmd = raw & 0xff;
45
46 /*
47 * Due to the above explained irregularity the trailer bits cannot
48 * have the same value.
49 */
50 if (trl1 == trl2)
51 return -EINVAL;
52
53 /* Only mode 0 supported for now */
54 if (mode)
55 return -EINVAL;
56
57 request->protocol = RC_TYPE_RC6_0;
58 request->scancode = addr << 8 | cmd;
59 request->toggle = trl2;
60 return IMG_IR_SCANCODE;
61}
62
63/* Convert RC6 scancode to RC6 data filter */
64static int img_ir_rc6_filter(const struct rc_scancode_filter *in,
65 struct img_ir_filter *out, u64 protocols)
66{
67 /* Not supported by the hw. */
68 return -EINVAL;
69}
70
71/*
72 * RC-6 decoder
73 * see http://www.sbprojects.com/knowledge/ir/rc6.php
74 */
75struct img_ir_decoder img_ir_rc6 = {
76 .type = RC_BIT_RC6_0,
77 .control = {
78 .bitorien = 1,
79 .code_type = IMG_IR_CODETYPE_BIPHASE,
80 .decoden = 1,
81 .decodinpol = 1,
82 },
83 /* main timings */
84 .tolerance = 20,
85 /*
86 * Due to a quirk in the img-ir decoder, default header values do
87 * not work, the values described below were extracted from
88 * successful RTL test cases.
89 */
90 .timings = {
91 /* leader symbol */
92 .ldr = {
93 .pulse = { 650 },
94 .space = { 660 },
95 },
96 /* 0 symbol */
97 .s00 = {
98 .pulse = { 370 },
99 .space = { 370 },
100 },
101 /* 01 symbol */
102 .s01 = {
103 .pulse = { 370 },
104 .space = { 370 },
105 },
106 /* free time */
107 .ft = {
108 .minlen = 21,
109 .maxlen = 21,
110 .ft_min = 2666, /* 2.666 ms */
111 },
112 },
113
114 /* scancode logic */
115 .scancode = img_ir_rc6_scancode,
116 .filter = img_ir_rc6_filter,
117};
diff --git a/drivers/media/rc/img-ir/img-ir-sanyo.c b/drivers/media/rc/img-ir/img-ir-sanyo.c
index 6b0653ecdf5a..f394994ffc22 100644
--- a/drivers/media/rc/img-ir/img-ir-sanyo.c
+++ b/drivers/media/rc/img-ir/img-ir-sanyo.c
@@ -23,8 +23,8 @@
23#include "img-ir-hw.h" 23#include "img-ir-hw.h"
24 24
25/* Convert Sanyo data to a scancode */ 25/* Convert Sanyo data to a scancode */
26static int img_ir_sanyo_scancode(int len, u64 raw, enum rc_type *protocol, 26static int img_ir_sanyo_scancode(int len, u64 raw, u64 enabled_protocols,
27 u32 *scancode, u64 enabled_protocols) 27 struct img_ir_scancode_req *request)
28{ 28{
29 unsigned int addr, addr_inv, data, data_inv; 29 unsigned int addr, addr_inv, data, data_inv;
30 /* a repeat code has no data */ 30 /* a repeat code has no data */
@@ -44,8 +44,8 @@ static int img_ir_sanyo_scancode(int len, u64 raw, enum rc_type *protocol,
44 return -EINVAL; 44 return -EINVAL;
45 45
46 /* Normal Sanyo */ 46 /* Normal Sanyo */
47 *protocol = RC_TYPE_SANYO; 47 request->protocol = RC_TYPE_SANYO;
48 *scancode = addr << 8 | data; 48 request->scancode = addr << 8 | data;
49 return IMG_IR_SCANCODE; 49 return IMG_IR_SCANCODE;
50} 50}
51 51
diff --git a/drivers/media/rc/img-ir/img-ir-sharp.c b/drivers/media/rc/img-ir/img-ir-sharp.c
index 3300a38802ac..fe5acc4f030e 100644
--- a/drivers/media/rc/img-ir/img-ir-sharp.c
+++ b/drivers/media/rc/img-ir/img-ir-sharp.c
@@ -12,8 +12,8 @@
12#include "img-ir-hw.h" 12#include "img-ir-hw.h"
13 13
14/* Convert Sharp data to a scancode */ 14/* Convert Sharp data to a scancode */
15static int img_ir_sharp_scancode(int len, u64 raw, enum rc_type *protocol, 15static int img_ir_sharp_scancode(int len, u64 raw, u64 enabled_protocols,
16 u32 *scancode, u64 enabled_protocols) 16 struct img_ir_scancode_req *request)
17{ 17{
18 unsigned int addr, cmd, exp, chk; 18 unsigned int addr, cmd, exp, chk;
19 19
@@ -32,8 +32,8 @@ static int img_ir_sharp_scancode(int len, u64 raw, enum rc_type *protocol,
32 /* probably the second half of the message */ 32 /* probably the second half of the message */
33 return -EINVAL; 33 return -EINVAL;
34 34
35 *protocol = RC_TYPE_SHARP; 35 request->protocol = RC_TYPE_SHARP;
36 *scancode = addr << 8 | cmd; 36 request->scancode = addr << 8 | cmd;
37 return IMG_IR_SCANCODE; 37 return IMG_IR_SCANCODE;
38} 38}
39 39
diff --git a/drivers/media/rc/img-ir/img-ir-sony.c b/drivers/media/rc/img-ir/img-ir-sony.c
index 3a0f17b0752c..7f7375f82ed6 100644
--- a/drivers/media/rc/img-ir/img-ir-sony.c
+++ b/drivers/media/rc/img-ir/img-ir-sony.c
@@ -12,8 +12,8 @@
12#include "img-ir-hw.h" 12#include "img-ir-hw.h"
13 13
14/* Convert Sony data to a scancode */ 14/* Convert Sony data to a scancode */
15static int img_ir_sony_scancode(int len, u64 raw, enum rc_type *protocol, 15static int img_ir_sony_scancode(int len, u64 raw, u64 enabled_protocols,
16 u32 *scancode, u64 enabled_protocols) 16 struct img_ir_scancode_req *request)
17{ 17{
18 unsigned int dev, subdev, func; 18 unsigned int dev, subdev, func;
19 19
@@ -25,7 +25,7 @@ static int img_ir_sony_scancode(int len, u64 raw, enum rc_type *protocol,
25 raw >>= 7; 25 raw >>= 7;
26 dev = raw & 0x1f; /* next 5 bits */ 26 dev = raw & 0x1f; /* next 5 bits */
27 subdev = 0; 27 subdev = 0;
28 *protocol = RC_TYPE_SONY12; 28 request->protocol = RC_TYPE_SONY12;
29 break; 29 break;
30 case 15: 30 case 15:
31 if (!(enabled_protocols & RC_BIT_SONY15)) 31 if (!(enabled_protocols & RC_BIT_SONY15))
@@ -34,7 +34,7 @@ static int img_ir_sony_scancode(int len, u64 raw, enum rc_type *protocol,
34 raw >>= 7; 34 raw >>= 7;
35 dev = raw & 0xff; /* next 8 bits */ 35 dev = raw & 0xff; /* next 8 bits */
36 subdev = 0; 36 subdev = 0;
37 *protocol = RC_TYPE_SONY15; 37 request->protocol = RC_TYPE_SONY15;
38 break; 38 break;
39 case 20: 39 case 20:
40 if (!(enabled_protocols & RC_BIT_SONY20)) 40 if (!(enabled_protocols & RC_BIT_SONY20))
@@ -44,12 +44,12 @@ static int img_ir_sony_scancode(int len, u64 raw, enum rc_type *protocol,
44 dev = raw & 0x1f; /* next 5 bits */ 44 dev = raw & 0x1f; /* next 5 bits */
45 raw >>= 5; 45 raw >>= 5;
46 subdev = raw & 0xff; /* next 8 bits */ 46 subdev = raw & 0xff; /* next 8 bits */
47 *protocol = RC_TYPE_SONY20; 47 request->protocol = RC_TYPE_SONY20;
48 break; 48 break;
49 default: 49 default:
50 return -EINVAL; 50 return -EINVAL;
51 } 51 }
52 *scancode = dev << 16 | subdev << 8 | func; 52 request->scancode = dev << 16 | subdev << 8 | func;
53 return IMG_IR_SCANCODE; 53 return IMG_IR_SCANCODE;
54} 54}
55 55
diff --git a/drivers/media/rc/lirc_dev.c b/drivers/media/rc/lirc_dev.c
index 1e0545a67959..4de0e85af805 100644
--- a/drivers/media/rc/lirc_dev.c
+++ b/drivers/media/rc/lirc_dev.c
@@ -553,14 +553,14 @@ unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait)
553 if (!ir->attached) 553 if (!ir->attached)
554 return POLLERR; 554 return POLLERR;
555 555
556 poll_wait(file, &ir->buf->wait_poll, wait); 556 if (ir->buf) {
557 poll_wait(file, &ir->buf->wait_poll, wait);
557 558
558 if (ir->buf)
559 if (lirc_buffer_empty(ir->buf)) 559 if (lirc_buffer_empty(ir->buf))
560 ret = 0; 560 ret = 0;
561 else 561 else
562 ret = POLLIN | POLLRDNORM; 562 ret = POLLIN | POLLRDNORM;
563 else 563 } else
564 ret = POLLERR; 564 ret = POLLERR;
565 565
566 dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n", 566 dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n",
diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
index 86ffcd54339e..f8c5e47a30aa 100644
--- a/drivers/media/rc/rc-main.c
+++ b/drivers/media/rc/rc-main.c
@@ -1021,16 +1021,16 @@ static ssize_t store_protocols(struct device *device,
1021 goto out; 1021 goto out;
1022 } 1022 }
1023 1023
1024 if (new_protocols == old_protocols) { 1024 if (new_protocols != old_protocols) {
1025 rc = len; 1025 *current_protocols = new_protocols;
1026 goto out; 1026 IR_dprintk(1, "Protocols changed to 0x%llx\n",
1027 (long long)new_protocols);
1027 } 1028 }
1028 1029
1029 *current_protocols = new_protocols;
1030 IR_dprintk(1, "Protocols changed to 0x%llx\n", (long long)new_protocols);
1031
1032 /* 1030 /*
1033 * If the protocol is changed the filter needs updating. 1031 * If a protocol change was attempted the filter may need updating, even
1032 * if the actual protocol mask hasn't changed (since the driver may have
1033 * cleared the filter).
1034 * Try setting the same filter with the new protocol (if any). 1034 * Try setting the same filter with the new protocol (if any).
1035 * Fall back to clearing the filter. 1035 * Fall back to clearing the filter.
1036 */ 1036 */
diff --git a/drivers/media/rc/sunxi-cir.c b/drivers/media/rc/sunxi-cir.c
index 340f7f51eed4..7830aef3db45 100644
--- a/drivers/media/rc/sunxi-cir.c
+++ b/drivers/media/rc/sunxi-cir.c
@@ -23,6 +23,7 @@
23#include <linux/interrupt.h> 23#include <linux/interrupt.h>
24#include <linux/module.h> 24#include <linux/module.h>
25#include <linux/of_platform.h> 25#include <linux/of_platform.h>
26#include <linux/reset.h>
26#include <media/rc-core.h> 27#include <media/rc-core.h>
27 28
28#define SUNXI_IR_DEV "sunxi-ir" 29#define SUNXI_IR_DEV "sunxi-ir"
@@ -55,12 +56,12 @@
55#define REG_RXINT_RAI_EN BIT(4) 56#define REG_RXINT_RAI_EN BIT(4)
56 57
57/* Rx FIFO available byte level */ 58/* Rx FIFO available byte level */
58#define REG_RXINT_RAL(val) (((val) << 8) & (GENMASK(11, 8))) 59#define REG_RXINT_RAL(val) ((val) << 8)
59 60
60/* Rx Interrupt Status */ 61/* Rx Interrupt Status */
61#define SUNXI_IR_RXSTA_REG 0x30 62#define SUNXI_IR_RXSTA_REG 0x30
62/* RX FIFO Get Available Counter */ 63/* RX FIFO Get Available Counter */
63#define REG_RXSTA_GET_AC(val) (((val) >> 8) & (GENMASK(5, 0))) 64#define REG_RXSTA_GET_AC(val) (((val) >> 8) & (ir->fifo_size * 2 - 1))
64/* Clear all interrupt status value */ 65/* Clear all interrupt status value */
65#define REG_RXSTA_CLEARALL 0xff 66#define REG_RXSTA_CLEARALL 0xff
66 67
@@ -71,10 +72,6 @@
71/* CIR_REG register idle threshold */ 72/* CIR_REG register idle threshold */
72#define REG_CIR_ITHR(val) (((val) << 8) & (GENMASK(15, 8))) 73#define REG_CIR_ITHR(val) (((val) << 8) & (GENMASK(15, 8)))
73 74
74/* Hardware supported fifo size */
75#define SUNXI_IR_FIFO_SIZE 16
76/* How many messages in FIFO trigger IRQ */
77#define TRIGGER_LEVEL 8
78/* Required frequency for IR0 or IR1 clock in CIR mode */ 75/* Required frequency for IR0 or IR1 clock in CIR mode */
79#define SUNXI_IR_BASE_CLK 8000000 76#define SUNXI_IR_BASE_CLK 8000000
80/* Frequency after IR internal divider */ 77/* Frequency after IR internal divider */
@@ -93,8 +90,10 @@ struct sunxi_ir {
93 struct rc_dev *rc; 90 struct rc_dev *rc;
94 void __iomem *base; 91 void __iomem *base;
95 int irq; 92 int irq;
93 int fifo_size;
96 struct clk *clk; 94 struct clk *clk;
97 struct clk *apb_clk; 95 struct clk *apb_clk;
96 struct reset_control *rst;
98 const char *map_name; 97 const char *map_name;
99}; 98};
100 99
@@ -113,11 +112,11 @@ static irqreturn_t sunxi_ir_irq(int irqno, void *dev_id)
113 /* clean all pending statuses */ 112 /* clean all pending statuses */
114 writel(status | REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG); 113 writel(status | REG_RXSTA_CLEARALL, ir->base + SUNXI_IR_RXSTA_REG);
115 114
116 if (status & REG_RXINT_RAI_EN) { 115 if (status & (REG_RXINT_RAI_EN | REG_RXINT_RPEI_EN)) {
117 /* How many messages in fifo */ 116 /* How many messages in fifo */
118 rc = REG_RXSTA_GET_AC(status); 117 rc = REG_RXSTA_GET_AC(status);
119 /* Sanity check */ 118 /* Sanity check */
120 rc = rc > SUNXI_IR_FIFO_SIZE ? SUNXI_IR_FIFO_SIZE : rc; 119 rc = rc > ir->fifo_size ? ir->fifo_size : rc;
121 /* If we have data */ 120 /* If we have data */
122 for (cnt = 0; cnt < rc; cnt++) { 121 for (cnt = 0; cnt < rc; cnt++) {
123 /* for each bit in fifo */ 122 /* for each bit in fifo */
@@ -154,6 +153,11 @@ static int sunxi_ir_probe(struct platform_device *pdev)
154 if (!ir) 153 if (!ir)
155 return -ENOMEM; 154 return -ENOMEM;
156 155
156 if (of_device_is_compatible(dn, "allwinner,sun5i-a13-ir"))
157 ir->fifo_size = 64;
158 else
159 ir->fifo_size = 16;
160
157 /* Clock */ 161 /* Clock */
158 ir->apb_clk = devm_clk_get(dev, "apb"); 162 ir->apb_clk = devm_clk_get(dev, "apb");
159 if (IS_ERR(ir->apb_clk)) { 163 if (IS_ERR(ir->apb_clk)) {
@@ -166,15 +170,29 @@ static int sunxi_ir_probe(struct platform_device *pdev)
166 return PTR_ERR(ir->clk); 170 return PTR_ERR(ir->clk);
167 } 171 }
168 172
173 /* Reset (optional) */
174 ir->rst = devm_reset_control_get_optional(dev, NULL);
175 if (IS_ERR(ir->rst)) {
176 ret = PTR_ERR(ir->rst);
177 if (ret == -EPROBE_DEFER)
178 return ret;
179 ir->rst = NULL;
180 } else {
181 ret = reset_control_deassert(ir->rst);
182 if (ret)
183 return ret;
184 }
185
169 ret = clk_set_rate(ir->clk, SUNXI_IR_BASE_CLK); 186 ret = clk_set_rate(ir->clk, SUNXI_IR_BASE_CLK);
170 if (ret) { 187 if (ret) {
171 dev_err(dev, "set ir base clock failed!\n"); 188 dev_err(dev, "set ir base clock failed!\n");
172 return ret; 189 goto exit_reset_assert;
173 } 190 }
174 191
175 if (clk_prepare_enable(ir->apb_clk)) { 192 if (clk_prepare_enable(ir->apb_clk)) {
176 dev_err(dev, "try to enable apb_ir_clk failed\n"); 193 dev_err(dev, "try to enable apb_ir_clk failed\n");
177 return -EINVAL; 194 ret = -EINVAL;
195 goto exit_reset_assert;
178 } 196 }
179 197
180 if (clk_prepare_enable(ir->clk)) { 198 if (clk_prepare_enable(ir->clk)) {
@@ -255,7 +273,7 @@ static int sunxi_ir_probe(struct platform_device *pdev)
255 * level 273 * level
256 */ 274 */
257 writel(REG_RXINT_ROI_EN | REG_RXINT_RPEI_EN | 275 writel(REG_RXINT_ROI_EN | REG_RXINT_RPEI_EN |
258 REG_RXINT_RAI_EN | REG_RXINT_RAL(TRIGGER_LEVEL - 1), 276 REG_RXINT_RAI_EN | REG_RXINT_RAL(ir->fifo_size / 2 - 1),
259 ir->base + SUNXI_IR_RXINT_REG); 277 ir->base + SUNXI_IR_RXINT_REG);
260 278
261 /* Enable IR Module */ 279 /* Enable IR Module */
@@ -271,6 +289,9 @@ exit_clkdisable_clk:
271 clk_disable_unprepare(ir->clk); 289 clk_disable_unprepare(ir->clk);
272exit_clkdisable_apb_clk: 290exit_clkdisable_apb_clk:
273 clk_disable_unprepare(ir->apb_clk); 291 clk_disable_unprepare(ir->apb_clk);
292exit_reset_assert:
293 if (ir->rst)
294 reset_control_assert(ir->rst);
274 295
275 return ret; 296 return ret;
276} 297}
@@ -282,6 +303,8 @@ static int sunxi_ir_remove(struct platform_device *pdev)
282 303
283 clk_disable_unprepare(ir->clk); 304 clk_disable_unprepare(ir->clk);
284 clk_disable_unprepare(ir->apb_clk); 305 clk_disable_unprepare(ir->apb_clk);
306 if (ir->rst)
307 reset_control_assert(ir->rst);
285 308
286 spin_lock_irqsave(&ir->ir_lock, flags); 309 spin_lock_irqsave(&ir->ir_lock, flags);
287 /* disable IR IRQ */ 310 /* disable IR IRQ */
@@ -298,6 +321,7 @@ static int sunxi_ir_remove(struct platform_device *pdev)
298 321
299static const struct of_device_id sunxi_ir_match[] = { 322static const struct of_device_id sunxi_ir_match[] = {
300 { .compatible = "allwinner,sun4i-a10-ir", }, 323 { .compatible = "allwinner,sun4i-a10-ir", },
324 { .compatible = "allwinner,sun5i-a13-ir", },
301 {}, 325 {},
302}; 326};
303 327
diff --git a/drivers/media/tuners/mt20xx.c b/drivers/media/tuners/mt20xx.c
index 0e74e97e0d1a..9e031040c13f 100644
--- a/drivers/media/tuners/mt20xx.c
+++ b/drivers/media/tuners/mt20xx.c
@@ -660,11 +660,3 @@ EXPORT_SYMBOL_GPL(microtune_attach);
660MODULE_DESCRIPTION("Microtune tuner driver"); 660MODULE_DESCRIPTION("Microtune tuner driver");
661MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); 661MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
662MODULE_LICENSE("GPL"); 662MODULE_LICENSE("GPL");
663
664/*
665 * Overrides for Emacs so that we follow Linus's tabbing style.
666 * ---------------------------------------------------------------------------
667 * Local variables:
668 * c-basic-offset: 8
669 * End:
670 */
diff --git a/drivers/media/tuners/mt2131.c b/drivers/media/tuners/mt2131.c
index f83b0c1ea6c8..6e2cdd2b6175 100644
--- a/drivers/media/tuners/mt2131.c
+++ b/drivers/media/tuners/mt2131.c
@@ -294,8 +294,3 @@ EXPORT_SYMBOL(mt2131_attach);
294MODULE_AUTHOR("Steven Toth"); 294MODULE_AUTHOR("Steven Toth");
295MODULE_DESCRIPTION("Microtune MT2131 silicon tuner driver"); 295MODULE_DESCRIPTION("Microtune MT2131 silicon tuner driver");
296MODULE_LICENSE("GPL"); 296MODULE_LICENSE("GPL");
297
298/*
299 * Local variables:
300 * c-basic-offset: 8
301 */
diff --git a/drivers/media/tuners/mt2131.h b/drivers/media/tuners/mt2131.h
index 09ceaf68e47c..837c854b9c65 100644
--- a/drivers/media/tuners/mt2131.h
+++ b/drivers/media/tuners/mt2131.h
@@ -47,8 +47,3 @@ static inline struct dvb_frontend* mt2131_attach(struct dvb_frontend *fe,
47#endif /* CONFIG_MEDIA_TUNER_MT2131 */ 47#endif /* CONFIG_MEDIA_TUNER_MT2131 */
48 48
49#endif /* __MT2131_H__ */ 49#endif /* __MT2131_H__ */
50
51/*
52 * Local variables:
53 * c-basic-offset: 8
54 */
diff --git a/drivers/media/tuners/mt2131_priv.h b/drivers/media/tuners/mt2131_priv.h
index 62aeedf5c550..91283b599cb3 100644
--- a/drivers/media/tuners/mt2131_priv.h
+++ b/drivers/media/tuners/mt2131_priv.h
@@ -41,8 +41,3 @@ struct mt2131_priv {
41}; 41};
42 42
43#endif /* __MT2131_PRIV_H__ */ 43#endif /* __MT2131_PRIV_H__ */
44
45/*
46 * Local variables:
47 * c-basic-offset: 8
48 */
diff --git a/drivers/media/tuners/mxl5007t.c b/drivers/media/tuners/mxl5007t.c
index 1810ad66888e..f4ae04c3328a 100644
--- a/drivers/media/tuners/mxl5007t.c
+++ b/drivers/media/tuners/mxl5007t.c
@@ -938,11 +938,3 @@ MODULE_DESCRIPTION("MaxLinear MxL5007T Silicon IC tuner driver");
938MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 938MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
939MODULE_LICENSE("GPL"); 939MODULE_LICENSE("GPL");
940MODULE_VERSION("0.2"); 940MODULE_VERSION("0.2");
941
942/*
943 * Overrides for Emacs so that we follow Linus's tabbing style.
944 * ---------------------------------------------------------------------------
945 * Local variables:
946 * c-basic-offset: 8
947 * End:
948 */
diff --git a/drivers/media/tuners/mxl5007t.h b/drivers/media/tuners/mxl5007t.h
index 37b0942e2385..ae7037d681c5 100644
--- a/drivers/media/tuners/mxl5007t.h
+++ b/drivers/media/tuners/mxl5007t.h
@@ -93,12 +93,3 @@ static inline struct dvb_frontend *mxl5007t_attach(struct dvb_frontend *fe,
93#endif 93#endif
94 94
95#endif /* __MXL5007T_H__ */ 95#endif /* __MXL5007T_H__ */
96
97/*
98 * Overrides for Emacs so that we follow Linus's tabbing style.
99 * ---------------------------------------------------------------------------
100 * Local variables:
101 * c-basic-offset: 8
102 * End:
103 */
104
diff --git a/drivers/media/tuners/si2157.c b/drivers/media/tuners/si2157.c
index 2180de9d654a..fcf139dfdec6 100644
--- a/drivers/media/tuners/si2157.c
+++ b/drivers/media/tuners/si2157.c
@@ -19,16 +19,17 @@
19static const struct dvb_tuner_ops si2157_ops; 19static const struct dvb_tuner_ops si2157_ops;
20 20
21/* execute firmware command */ 21/* execute firmware command */
22static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd) 22static int si2157_cmd_execute(struct i2c_client *client, struct si2157_cmd *cmd)
23{ 23{
24 struct si2157_dev *dev = i2c_get_clientdata(client);
24 int ret; 25 int ret;
25 unsigned long timeout; 26 unsigned long timeout;
26 27
27 mutex_lock(&s->i2c_mutex); 28 mutex_lock(&dev->i2c_mutex);
28 29
29 if (cmd->wlen) { 30 if (cmd->wlen) {
30 /* write cmd and args for firmware */ 31 /* write cmd and args for firmware */
31 ret = i2c_master_send(s->client, cmd->args, cmd->wlen); 32 ret = i2c_master_send(client, cmd->args, cmd->wlen);
32 if (ret < 0) { 33 if (ret < 0) {
33 goto err_mutex_unlock; 34 goto err_mutex_unlock;
34 } else if (ret != cmd->wlen) { 35 } else if (ret != cmd->wlen) {
@@ -42,7 +43,7 @@ static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
42 #define TIMEOUT 80 43 #define TIMEOUT 80
43 timeout = jiffies + msecs_to_jiffies(TIMEOUT); 44 timeout = jiffies + msecs_to_jiffies(TIMEOUT);
44 while (!time_after(jiffies, timeout)) { 45 while (!time_after(jiffies, timeout)) {
45 ret = i2c_master_recv(s->client, cmd->args, cmd->rlen); 46 ret = i2c_master_recv(client, cmd->args, cmd->rlen);
46 if (ret < 0) { 47 if (ret < 0) {
47 goto err_mutex_unlock; 48 goto err_mutex_unlock;
48 } else if (ret != cmd->rlen) { 49 } else if (ret != cmd->rlen) {
@@ -55,7 +56,7 @@ static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
55 break; 56 break;
56 } 57 }
57 58
58 dev_dbg(&s->client->dev, "cmd execution took %d ms\n", 59 dev_dbg(&client->dev, "cmd execution took %d ms\n",
59 jiffies_to_msecs(jiffies) - 60 jiffies_to_msecs(jiffies) -
60 (jiffies_to_msecs(timeout) - TIMEOUT)); 61 (jiffies_to_msecs(timeout) - TIMEOUT));
61 62
@@ -65,35 +66,32 @@ static int si2157_cmd_execute(struct si2157 *s, struct si2157_cmd *cmd)
65 } 66 }
66 } 67 }
67 68
68 ret = 0; 69 mutex_unlock(&dev->i2c_mutex);
70 return 0;
69 71
70err_mutex_unlock: 72err_mutex_unlock:
71 mutex_unlock(&s->i2c_mutex); 73 mutex_unlock(&dev->i2c_mutex);
72 if (ret) 74 dev_dbg(&client->dev, "failed=%d\n", ret);
73 goto err;
74
75 return 0;
76err:
77 dev_dbg(&s->client->dev, "failed=%d\n", ret);
78 return ret; 75 return ret;
79} 76}
80 77
81static int si2157_init(struct dvb_frontend *fe) 78static int si2157_init(struct dvb_frontend *fe)
82{ 79{
83 struct si2157 *s = fe->tuner_priv; 80 struct i2c_client *client = fe->tuner_priv;
81 struct si2157_dev *dev = i2c_get_clientdata(client);
84 int ret, len, remaining; 82 int ret, len, remaining;
85 struct si2157_cmd cmd; 83 struct si2157_cmd cmd;
86 const struct firmware *fw = NULL; 84 const struct firmware *fw;
87 u8 *fw_file; 85 const char *fw_name;
88 unsigned int chip_id; 86 unsigned int chip_id;
89 87
90 dev_dbg(&s->client->dev, "\n"); 88 dev_dbg(&client->dev, "\n");
91 89
92 if (s->fw_loaded) 90 if (dev->fw_loaded)
93 goto warm; 91 goto warm;
94 92
95 /* power up */ 93 /* power up */
96 if (s->chiptype == SI2157_CHIPTYPE_SI2146) { 94 if (dev->chiptype == SI2157_CHIPTYPE_SI2146) {
97 memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9); 95 memcpy(cmd.args, "\xc0\x05\x01\x00\x00\x0b\x00\x00\x01", 9);
98 cmd.wlen = 9; 96 cmd.wlen = 9;
99 } else { 97 } else {
@@ -101,7 +99,7 @@ static int si2157_init(struct dvb_frontend *fe)
101 cmd.wlen = 15; 99 cmd.wlen = 15;
102 } 100 }
103 cmd.rlen = 1; 101 cmd.rlen = 1;
104 ret = si2157_cmd_execute(s, &cmd); 102 ret = si2157_cmd_execute(client, &cmd);
105 if (ret) 103 if (ret)
106 goto err; 104 goto err;
107 105
@@ -109,7 +107,7 @@ static int si2157_init(struct dvb_frontend *fe)
109 memcpy(cmd.args, "\x02", 1); 107 memcpy(cmd.args, "\x02", 1);
110 cmd.wlen = 1; 108 cmd.wlen = 1;
111 cmd.rlen = 13; 109 cmd.rlen = 13;
112 ret = si2157_cmd_execute(s, &cmd); 110 ret = si2157_cmd_execute(client, &cmd);
113 if (ret) 111 if (ret)
114 goto err; 112 goto err;
115 113
@@ -125,121 +123,133 @@ static int si2157_init(struct dvb_frontend *fe)
125 switch (chip_id) { 123 switch (chip_id) {
126 case SI2158_A20: 124 case SI2158_A20:
127 case SI2148_A20: 125 case SI2148_A20:
128 fw_file = SI2158_A20_FIRMWARE; 126 fw_name = SI2158_A20_FIRMWARE;
129 break; 127 break;
130 case SI2157_A30: 128 case SI2157_A30:
131 case SI2147_A30: 129 case SI2147_A30:
132 case SI2146_A10: 130 case SI2146_A10:
133 goto skip_fw_download; 131 fw_name = NULL;
132 break;
134 default: 133 default:
135 dev_err(&s->client->dev, 134 dev_err(&client->dev, "unknown chip version Si21%d-%c%c%c\n",
136 "unknown chip version Si21%d-%c%c%c\n",
137 cmd.args[2], cmd.args[1], 135 cmd.args[2], cmd.args[1],
138 cmd.args[3], cmd.args[4]); 136 cmd.args[3], cmd.args[4]);
139 ret = -EINVAL; 137 ret = -EINVAL;
140 goto err; 138 goto err;
141 } 139 }
142 140
143 /* cold state - try to download firmware */ 141 dev_info(&client->dev, "found a 'Silicon Labs Si21%d-%c%c%c'\n",
144 dev_info(&s->client->dev, "found a '%s' in cold state\n", 142 cmd.args[2], cmd.args[1], cmd.args[3], cmd.args[4]);
145 si2157_ops.info.name); 143
144 if (fw_name == NULL)
145 goto skip_fw_download;
146 146
147 /* request the firmware, this will block and timeout */ 147 /* request the firmware, this will block and timeout */
148 ret = request_firmware(&fw, fw_file, &s->client->dev); 148 ret = request_firmware(&fw, fw_name, &client->dev);
149 if (ret) { 149 if (ret) {
150 dev_err(&s->client->dev, "firmware file '%s' not found\n", 150 dev_err(&client->dev, "firmware file '%s' not found\n",
151 fw_file); 151 fw_name);
152 goto err; 152 goto err;
153 } 153 }
154 154
155 /* firmware should be n chunks of 17 bytes */ 155 /* firmware should be n chunks of 17 bytes */
156 if (fw->size % 17 != 0) { 156 if (fw->size % 17 != 0) {
157 dev_err(&s->client->dev, "firmware file '%s' is invalid\n", 157 dev_err(&client->dev, "firmware file '%s' is invalid\n",
158 fw_file); 158 fw_name);
159 ret = -EINVAL; 159 ret = -EINVAL;
160 goto fw_release_exit; 160 goto err_release_firmware;
161 } 161 }
162 162
163 dev_info(&s->client->dev, "downloading firmware from file '%s'\n", 163 dev_info(&client->dev, "downloading firmware from file '%s'\n",
164 fw_file); 164 fw_name);
165 165
166 for (remaining = fw->size; remaining > 0; remaining -= 17) { 166 for (remaining = fw->size; remaining > 0; remaining -= 17) {
167 len = fw->data[fw->size - remaining]; 167 len = fw->data[fw->size - remaining];
168 memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len); 168 memcpy(cmd.args, &fw->data[(fw->size - remaining) + 1], len);
169 cmd.wlen = len; 169 cmd.wlen = len;
170 cmd.rlen = 1; 170 cmd.rlen = 1;
171 ret = si2157_cmd_execute(s, &cmd); 171 ret = si2157_cmd_execute(client, &cmd);
172 if (ret) { 172 if (ret) {
173 dev_err(&s->client->dev, 173 dev_err(&client->dev, "firmware download failed %d\n",
174 "firmware download failed=%d\n",
175 ret); 174 ret);
176 goto fw_release_exit; 175 goto err_release_firmware;
177 } 176 }
178 } 177 }
179 178
180 release_firmware(fw); 179 release_firmware(fw);
181 fw = NULL;
182 180
183skip_fw_download: 181skip_fw_download:
184 /* reboot the tuner with new firmware? */ 182 /* reboot the tuner with new firmware? */
185 memcpy(cmd.args, "\x01\x01", 2); 183 memcpy(cmd.args, "\x01\x01", 2);
186 cmd.wlen = 2; 184 cmd.wlen = 2;
187 cmd.rlen = 1; 185 cmd.rlen = 1;
188 ret = si2157_cmd_execute(s, &cmd); 186 ret = si2157_cmd_execute(client, &cmd);
189 if (ret) 187 if (ret)
190 goto err; 188 goto err;
191 189
192 s->fw_loaded = true; 190 /* query firmware version */
191 memcpy(cmd.args, "\x11", 1);
192 cmd.wlen = 1;
193 cmd.rlen = 10;
194 ret = si2157_cmd_execute(client, &cmd);
195 if (ret)
196 goto err;
197
198 dev_info(&client->dev, "firmware version: %c.%c.%d\n",
199 cmd.args[6], cmd.args[7], cmd.args[8]);
200
201 dev->fw_loaded = true;
193 202
194warm: 203warm:
195 s->active = true; 204 dev->active = true;
196 return 0; 205 return 0;
197 206
198fw_release_exit: 207err_release_firmware:
199 release_firmware(fw); 208 release_firmware(fw);
200err: 209err:
201 dev_dbg(&s->client->dev, "failed=%d\n", ret); 210 dev_dbg(&client->dev, "failed=%d\n", ret);
202 return ret; 211 return ret;
203} 212}
204 213
205static int si2157_sleep(struct dvb_frontend *fe) 214static int si2157_sleep(struct dvb_frontend *fe)
206{ 215{
207 struct si2157 *s = fe->tuner_priv; 216 struct i2c_client *client = fe->tuner_priv;
217 struct si2157_dev *dev = i2c_get_clientdata(client);
208 int ret; 218 int ret;
209 struct si2157_cmd cmd; 219 struct si2157_cmd cmd;
210 220
211 dev_dbg(&s->client->dev, "\n"); 221 dev_dbg(&client->dev, "\n");
212 222
213 s->active = false; 223 dev->active = false;
214 224
215 /* standby */ 225 /* standby */
216 memcpy(cmd.args, "\x16\x00", 2); 226 memcpy(cmd.args, "\x16\x00", 2);
217 cmd.wlen = 2; 227 cmd.wlen = 2;
218 cmd.rlen = 1; 228 cmd.rlen = 1;
219 ret = si2157_cmd_execute(s, &cmd); 229 ret = si2157_cmd_execute(client, &cmd);
220 if (ret) 230 if (ret)
221 goto err; 231 goto err;
222 232
223 return 0; 233 return 0;
224err: 234err:
225 dev_dbg(&s->client->dev, "failed=%d\n", ret); 235 dev_dbg(&client->dev, "failed=%d\n", ret);
226 return ret; 236 return ret;
227} 237}
228 238
229static int si2157_set_params(struct dvb_frontend *fe) 239static int si2157_set_params(struct dvb_frontend *fe)
230{ 240{
231 struct si2157 *s = fe->tuner_priv; 241 struct i2c_client *client = fe->tuner_priv;
242 struct si2157_dev *dev = i2c_get_clientdata(client);
232 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 243 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
233 int ret; 244 int ret;
234 struct si2157_cmd cmd; 245 struct si2157_cmd cmd;
235 u8 bandwidth, delivery_system; 246 u8 bandwidth, delivery_system;
236 247
237 dev_dbg(&s->client->dev, 248 dev_dbg(&client->dev,
238 "delivery_system=%d frequency=%u bandwidth_hz=%u\n", 249 "delivery_system=%d frequency=%u bandwidth_hz=%u\n",
239 c->delivery_system, c->frequency, 250 c->delivery_system, c->frequency, c->bandwidth_hz);
240 c->bandwidth_hz);
241 251
242 if (!s->active) { 252 if (!dev->active) {
243 ret = -EAGAIN; 253 ret = -EAGAIN;
244 goto err; 254 goto err;
245 } 255 }
@@ -274,21 +284,21 @@ static int si2157_set_params(struct dvb_frontend *fe)
274 284
275 memcpy(cmd.args, "\x14\x00\x03\x07\x00\x00", 6); 285 memcpy(cmd.args, "\x14\x00\x03\x07\x00\x00", 6);
276 cmd.args[4] = delivery_system | bandwidth; 286 cmd.args[4] = delivery_system | bandwidth;
277 if (s->inversion) 287 if (dev->inversion)
278 cmd.args[5] = 0x01; 288 cmd.args[5] = 0x01;
279 cmd.wlen = 6; 289 cmd.wlen = 6;
280 cmd.rlen = 4; 290 cmd.rlen = 4;
281 ret = si2157_cmd_execute(s, &cmd); 291 ret = si2157_cmd_execute(client, &cmd);
282 if (ret) 292 if (ret)
283 goto err; 293 goto err;
284 294
285 if (s->chiptype == SI2157_CHIPTYPE_SI2146) 295 if (dev->chiptype == SI2157_CHIPTYPE_SI2146)
286 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6); 296 memcpy(cmd.args, "\x14\x00\x02\x07\x00\x01", 6);
287 else 297 else
288 memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6); 298 memcpy(cmd.args, "\x14\x00\x02\x07\x01\x00", 6);
289 cmd.wlen = 6; 299 cmd.wlen = 6;
290 cmd.rlen = 4; 300 cmd.rlen = 4;
291 ret = si2157_cmd_execute(s, &cmd); 301 ret = si2157_cmd_execute(client, &cmd);
292 if (ret) 302 if (ret)
293 goto err; 303 goto err;
294 304
@@ -300,13 +310,13 @@ static int si2157_set_params(struct dvb_frontend *fe)
300 cmd.args[7] = (c->frequency >> 24) & 0xff; 310 cmd.args[7] = (c->frequency >> 24) & 0xff;
301 cmd.wlen = 8; 311 cmd.wlen = 8;
302 cmd.rlen = 1; 312 cmd.rlen = 1;
303 ret = si2157_cmd_execute(s, &cmd); 313 ret = si2157_cmd_execute(client, &cmd);
304 if (ret) 314 if (ret)
305 goto err; 315 goto err;
306 316
307 return 0; 317 return 0;
308err: 318err:
309 dev_dbg(&s->client->dev, "failed=%d\n", ret); 319 dev_dbg(&client->dev, "failed=%d\n", ret);
310 return ret; 320 return ret;
311} 321}
312 322
@@ -334,70 +344,67 @@ static int si2157_probe(struct i2c_client *client,
334{ 344{
335 struct si2157_config *cfg = client->dev.platform_data; 345 struct si2157_config *cfg = client->dev.platform_data;
336 struct dvb_frontend *fe = cfg->fe; 346 struct dvb_frontend *fe = cfg->fe;
337 struct si2157 *s; 347 struct si2157_dev *dev;
338 struct si2157_cmd cmd; 348 struct si2157_cmd cmd;
339 int ret; 349 int ret;
340 350
341 s = kzalloc(sizeof(struct si2157), GFP_KERNEL); 351 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
342 if (!s) { 352 if (!dev) {
343 ret = -ENOMEM; 353 ret = -ENOMEM;
344 dev_err(&client->dev, "kzalloc() failed\n"); 354 dev_err(&client->dev, "kzalloc() failed\n");
345 goto err; 355 goto err;
346 } 356 }
347 357
348 s->client = client; 358 i2c_set_clientdata(client, dev);
349 s->fe = cfg->fe; 359 dev->fe = cfg->fe;
350 s->inversion = cfg->inversion; 360 dev->inversion = cfg->inversion;
351 s->fw_loaded = false; 361 dev->fw_loaded = false;
352 s->chiptype = (u8)id->driver_data; 362 dev->chiptype = (u8)id->driver_data;
353 mutex_init(&s->i2c_mutex); 363 mutex_init(&dev->i2c_mutex);
354 364
355 /* check if the tuner is there */ 365 /* check if the tuner is there */
356 cmd.wlen = 0; 366 cmd.wlen = 0;
357 cmd.rlen = 1; 367 cmd.rlen = 1;
358 ret = si2157_cmd_execute(s, &cmd); 368 ret = si2157_cmd_execute(client, &cmd);
359 if (ret) 369 if (ret)
360 goto err; 370 goto err_kfree;
361 371
362 fe->tuner_priv = s; 372 memcpy(&fe->ops.tuner_ops, &si2157_ops, sizeof(struct dvb_tuner_ops));
363 memcpy(&fe->ops.tuner_ops, &si2157_ops, 373 fe->tuner_priv = client;
364 sizeof(struct dvb_tuner_ops));
365 374
366 i2c_set_clientdata(client, s); 375 dev_info(&client->dev, "Silicon Labs %s successfully attached\n",
367 376 dev->chiptype == SI2157_CHIPTYPE_SI2146 ?
368 dev_info(&s->client->dev,
369 "Silicon Labs %s successfully attached\n",
370 s->chiptype == SI2157_CHIPTYPE_SI2146 ?
371 "Si2146" : "Si2147/2148/2157/2158"); 377 "Si2146" : "Si2147/2148/2157/2158");
372 378
373 return 0; 379 return 0;
380
381err_kfree:
382 kfree(dev);
374err: 383err:
375 dev_dbg(&client->dev, "failed=%d\n", ret); 384 dev_dbg(&client->dev, "failed=%d\n", ret);
376 kfree(s);
377
378 return ret; 385 return ret;
379} 386}
380 387
381static int si2157_remove(struct i2c_client *client) 388static int si2157_remove(struct i2c_client *client)
382{ 389{
383 struct si2157 *s = i2c_get_clientdata(client); 390 struct si2157_dev *dev = i2c_get_clientdata(client);
384 struct dvb_frontend *fe = s->fe; 391 struct dvb_frontend *fe = dev->fe;
385 392
386 dev_dbg(&client->dev, "\n"); 393 dev_dbg(&client->dev, "\n");
387 394
388 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops)); 395 memset(&fe->ops.tuner_ops, 0, sizeof(struct dvb_tuner_ops));
389 fe->tuner_priv = NULL; 396 fe->tuner_priv = NULL;
390 kfree(s); 397 kfree(dev);
391 398
392 return 0; 399 return 0;
393} 400}
394 401
395static const struct i2c_device_id si2157_id[] = { 402static const struct i2c_device_id si2157_id_table[] = {
396 {"si2157", 0}, 403 {"si2157", SI2157_CHIPTYPE_SI2157},
397 {"si2146", 1}, 404 {"si2146", SI2157_CHIPTYPE_SI2146},
398 {} 405 {}
399}; 406};
400MODULE_DEVICE_TABLE(i2c, si2157_id); 407MODULE_DEVICE_TABLE(i2c, si2157_id_table);
401 408
402static struct i2c_driver si2157_driver = { 409static struct i2c_driver si2157_driver = {
403 .driver = { 410 .driver = {
@@ -406,7 +413,7 @@ static struct i2c_driver si2157_driver = {
406 }, 413 },
407 .probe = si2157_probe, 414 .probe = si2157_probe,
408 .remove = si2157_remove, 415 .remove = si2157_remove,
409 .id_table = si2157_id, 416 .id_table = si2157_id_table,
410}; 417};
411 418
412module_i2c_driver(si2157_driver); 419module_i2c_driver(si2157_driver);
diff --git a/drivers/media/tuners/si2157_priv.h b/drivers/media/tuners/si2157_priv.h
index d6e07cdd2a07..7aa53bce5593 100644
--- a/drivers/media/tuners/si2157_priv.h
+++ b/drivers/media/tuners/si2157_priv.h
@@ -21,9 +21,8 @@
21#include "si2157.h" 21#include "si2157.h"
22 22
23/* state struct */ 23/* state struct */
24struct si2157 { 24struct si2157_dev {
25 struct mutex i2c_mutex; 25 struct mutex i2c_mutex;
26 struct i2c_client *client;
27 struct dvb_frontend *fe; 26 struct dvb_frontend *fe;
28 bool active; 27 bool active;
29 bool fw_loaded; 28 bool fw_loaded;
diff --git a/drivers/media/tuners/tda18271-fe.c b/drivers/media/tuners/tda18271-fe.c
index 4995b890c164..f8620741bb5f 100644
--- a/drivers/media/tuners/tda18271-fe.c
+++ b/drivers/media/tuners/tda18271-fe.c
@@ -1355,11 +1355,3 @@ MODULE_DESCRIPTION("NXP TDA18271HD analog / digital tuner driver");
1355MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 1355MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1356MODULE_LICENSE("GPL"); 1356MODULE_LICENSE("GPL");
1357MODULE_VERSION("0.4"); 1357MODULE_VERSION("0.4");
1358
1359/*
1360 * Overrides for Emacs so that we follow Linus's tabbing style.
1361 * ---------------------------------------------------------------------------
1362 * Local variables:
1363 * c-basic-offset: 8
1364 * End:
1365 */
diff --git a/drivers/media/tuners/tda18271-maps.c b/drivers/media/tuners/tda18271-maps.c
index b62e925f643f..1e89dd93c4bb 100644
--- a/drivers/media/tuners/tda18271-maps.c
+++ b/drivers/media/tuners/tda18271-maps.c
@@ -1305,11 +1305,3 @@ int tda18271_assign_map_layout(struct dvb_frontend *fe)
1305 1305
1306 return ret; 1306 return ret;
1307} 1307}
1308
1309/*
1310 * Overrides for Emacs so that we follow Linus's tabbing style.
1311 * ---------------------------------------------------------------------------
1312 * Local variables:
1313 * c-basic-offset: 8
1314 * End:
1315 */
diff --git a/drivers/media/tuners/tda18271-priv.h b/drivers/media/tuners/tda18271-priv.h
index b36a7b754772..cc80f544af34 100644
--- a/drivers/media/tuners/tda18271-priv.h
+++ b/drivers/media/tuners/tda18271-priv.h
@@ -226,11 +226,3 @@ extern int tda18271_calc_ir_measure(struct dvb_frontend *fe, u32 *freq);
226extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq); 226extern int tda18271_calc_rf_cal(struct dvb_frontend *fe, u32 *freq);
227 227
228#endif /* __TDA18271_PRIV_H__ */ 228#endif /* __TDA18271_PRIV_H__ */
229
230/*
231 * Overrides for Emacs so that we follow Linus's tabbing style.
232 * ---------------------------------------------------------------------------
233 * Local variables:
234 * c-basic-offset: 8
235 * End:
236 */
diff --git a/drivers/media/tuners/tda827x.c b/drivers/media/tuners/tda827x.c
index 73453a255cdc..edcb4a723aa1 100644
--- a/drivers/media/tuners/tda827x.c
+++ b/drivers/media/tuners/tda827x.c
@@ -907,11 +907,3 @@ MODULE_DESCRIPTION("DVB TDA827x driver");
907MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>"); 907MODULE_AUTHOR("Hartmut Hackmann <hartmut.hackmann@t-online.de>");
908MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 908MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
909MODULE_LICENSE("GPL"); 909MODULE_LICENSE("GPL");
910
911/*
912 * Overrides for Emacs so that we follow Linus's tabbing style.
913 * ---------------------------------------------------------------------------
914 * Local variables:
915 * c-basic-offset: 8
916 * End:
917 */
diff --git a/drivers/media/tuners/tda8290.c b/drivers/media/tuners/tda8290.c
index ab4106c17b4c..998e82bba9c0 100644
--- a/drivers/media/tuners/tda8290.c
+++ b/drivers/media/tuners/tda8290.c
@@ -881,11 +881,3 @@ EXPORT_SYMBOL_GPL(tda829x_probe);
881MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver"); 881MODULE_DESCRIPTION("Philips/NXP TDA8290/TDA8295 analog IF demodulator driver");
882MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky"); 882MODULE_AUTHOR("Gerd Knorr, Hartmut Hackmann, Michael Krufky");
883MODULE_LICENSE("GPL"); 883MODULE_LICENSE("GPL");
884
885/*
886 * Overrides for Emacs so that we follow Linus's tabbing style.
887 * ---------------------------------------------------------------------------
888 * Local variables:
889 * c-basic-offset: 8
890 * End:
891 */
diff --git a/drivers/media/tuners/tda9887.c b/drivers/media/tuners/tda9887.c
index 9823248d743f..56be6c29399b 100644
--- a/drivers/media/tuners/tda9887.c
+++ b/drivers/media/tuners/tda9887.c
@@ -707,11 +707,3 @@ struct dvb_frontend *tda9887_attach(struct dvb_frontend *fe,
707EXPORT_SYMBOL_GPL(tda9887_attach); 707EXPORT_SYMBOL_GPL(tda9887_attach);
708 708
709MODULE_LICENSE("GPL"); 709MODULE_LICENSE("GPL");
710
711/*
712 * Overrides for Emacs so that we follow Linus's tabbing style.
713 * ---------------------------------------------------------------------------
714 * Local variables:
715 * c-basic-offset: 8
716 * End:
717 */
diff --git a/drivers/media/tuners/tuner-simple.c b/drivers/media/tuners/tuner-simple.c
index ca274c2d8c70..8e9ce144da9a 100644
--- a/drivers/media/tuners/tuner-simple.c
+++ b/drivers/media/tuners/tuner-simple.c
@@ -1148,11 +1148,3 @@ EXPORT_SYMBOL_GPL(simple_tuner_attach);
1148MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver"); 1148MODULE_DESCRIPTION("Simple 4-control-bytes style tuner driver");
1149MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer"); 1149MODULE_AUTHOR("Ralph Metzler, Gerd Knorr, Gunther Mayer");
1150MODULE_LICENSE("GPL"); 1150MODULE_LICENSE("GPL");
1151
1152/*
1153 * Overrides for Emacs so that we follow Linus's tabbing style.
1154 * ---------------------------------------------------------------------------
1155 * Local variables:
1156 * c-basic-offset: 8
1157 * End:
1158 */
diff --git a/drivers/media/usb/au0828/Kconfig b/drivers/media/usb/au0828/Kconfig
index 1d410ac8f9a8..78b797e0b434 100644
--- a/drivers/media/usb/au0828/Kconfig
+++ b/drivers/media/usb/au0828/Kconfig
@@ -4,7 +4,7 @@ config VIDEO_AU0828
4 depends on I2C && INPUT && DVB_CORE && USB 4 depends on I2C && INPUT && DVB_CORE && USB
5 select I2C_ALGOBIT 5 select I2C_ALGOBIT
6 select VIDEO_TVEEPROM 6 select VIDEO_TVEEPROM
7 select VIDEOBUF_VMALLOC 7 select VIDEOBUF2_VMALLOC
8 select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT 8 select DVB_AU8522_DTV if MEDIA_SUBDRV_AUTOSELECT
9 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT 9 select MEDIA_TUNER_XC5000 if MEDIA_SUBDRV_AUTOSELECT
10 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT 10 select MEDIA_TUNER_MXL5007T if MEDIA_SUBDRV_AUTOSELECT
diff --git a/drivers/media/usb/au0828/au0828-cards.c b/drivers/media/usb/au0828/au0828-cards.c
index da87f1cc31a9..edc27355f271 100644
--- a/drivers/media/usb/au0828/au0828-cards.c
+++ b/drivers/media/usb/au0828/au0828-cards.c
@@ -44,7 +44,7 @@ static void hvr950q_cs5340_audio(void *priv, int enable)
44struct au0828_board au0828_boards[] = { 44struct au0828_board au0828_boards[] = {
45 [AU0828_BOARD_UNKNOWN] = { 45 [AU0828_BOARD_UNKNOWN] = {
46 .name = "Unknown board", 46 .name = "Unknown board",
47 .tuner_type = UNSET, 47 .tuner_type = -1U,
48 .tuner_addr = ADDR_UNSET, 48 .tuner_addr = ADDR_UNSET,
49 }, 49 },
50 [AU0828_BOARD_HAUPPAUGE_HVR850] = { 50 [AU0828_BOARD_HAUPPAUGE_HVR850] = {
diff --git a/drivers/media/usb/au0828/au0828-vbi.c b/drivers/media/usb/au0828/au0828-vbi.c
index 932d24f42b24..f67247cf1a5a 100644
--- a/drivers/media/usb/au0828/au0828-vbi.c
+++ b/drivers/media/usb/au0828/au0828-vbi.c
@@ -28,111 +28,67 @@
28#include <linux/init.h> 28#include <linux/init.h>
29#include <linux/slab.h> 29#include <linux/slab.h>
30 30
31static unsigned int vbibufs = 5;
32module_param(vbibufs, int, 0644);
33MODULE_PARM_DESC(vbibufs, "number of vbi buffers, range 2-32");
34
35/* ------------------------------------------------------------------ */ 31/* ------------------------------------------------------------------ */
36 32
37static void 33static int vbi_queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
38free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf) 34 unsigned int *nbuffers, unsigned int *nplanes,
35 unsigned int sizes[], void *alloc_ctxs[])
39{ 36{
40 struct au0828_fh *fh = vq->priv_data; 37 struct au0828_dev *dev = vb2_get_drv_priv(vq);
41 struct au0828_dev *dev = fh->dev; 38 unsigned long img_size = dev->vbi_width * dev->vbi_height * 2;
42 unsigned long flags = 0; 39 unsigned long size;
43 if (in_interrupt())
44 BUG();
45
46 /* We used to wait for the buffer to finish here, but this didn't work
47 because, as we were keeping the state as VIDEOBUF_QUEUED,
48 videobuf_queue_cancel marked it as finished for us.
49 (Also, it could wedge forever if the hardware was misconfigured.)
50
51 This should be safe; by the time we get here, the buffer isn't
52 queued anymore. If we ever start marking the buffers as
53 VIDEOBUF_ACTIVE, it won't be, though.
54 */
55 spin_lock_irqsave(&dev->slock, flags);
56 if (dev->isoc_ctl.vbi_buf == buf)
57 dev->isoc_ctl.vbi_buf = NULL;
58 spin_unlock_irqrestore(&dev->slock, flags);
59 40
60 videobuf_vmalloc_free(&buf->vb); 41 size = fmt ? (fmt->fmt.vbi.samples_per_line *
61 buf->vb.state = VIDEOBUF_NEEDS_INIT; 42 (fmt->fmt.vbi.count[0] + fmt->fmt.vbi.count[1])) : img_size;
62} 43 if (size < img_size)
63 44 return -EINVAL;
64static int
65vbi_setup(struct videobuf_queue *q, unsigned int *count, unsigned int *size)
66{
67 struct au0828_fh *fh = q->priv_data;
68 struct au0828_dev *dev = fh->dev;
69 45
70 *size = dev->vbi_width * dev->vbi_height * 2; 46 *nplanes = 1;
47 sizes[0] = size;
71 48
72 if (0 == *count)
73 *count = vbibufs;
74 if (*count < 2)
75 *count = 2;
76 if (*count > 32)
77 *count = 32;
78 return 0; 49 return 0;
79} 50}
80 51
81static int 52static int vbi_buffer_prepare(struct vb2_buffer *vb)
82vbi_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
83 enum v4l2_field field)
84{ 53{
85 struct au0828_fh *fh = q->priv_data; 54 struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
86 struct au0828_dev *dev = fh->dev;
87 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); 55 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
88 int rc = 0; 56 unsigned long size;
89 57
90 buf->vb.size = dev->vbi_width * dev->vbi_height * 2; 58 size = dev->vbi_width * dev->vbi_height * 2;
91 59
92 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 60 if (vb2_plane_size(vb, 0) < size) {
61 pr_err("%s data will not fit into plane (%lu < %lu)\n",
62 __func__, vb2_plane_size(vb, 0), size);
93 return -EINVAL; 63 return -EINVAL;
94
95 buf->vb.width = dev->vbi_width;
96 buf->vb.height = dev->vbi_height;
97 buf->vb.field = field;
98
99 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
100 rc = videobuf_iolock(q, &buf->vb, NULL);
101 if (rc < 0)
102 goto fail;
103 } 64 }
65 vb2_set_plane_payload(&buf->vb, 0, size);
104 66
105 buf->vb.state = VIDEOBUF_PREPARED;
106 return 0; 67 return 0;
107
108fail:
109 free_buffer(q, buf);
110 return rc;
111} 68}
112 69
113static void 70static void
114vbi_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 71vbi_buffer_queue(struct vb2_buffer *vb)
115{
116 struct au0828_buffer *buf = container_of(vb,
117 struct au0828_buffer,
118 vb);
119 struct au0828_fh *fh = vq->priv_data;
120 struct au0828_dev *dev = fh->dev;
121 struct au0828_dmaqueue *vbiq = &dev->vbiq;
122
123 buf->vb.state = VIDEOBUF_QUEUED;
124 list_add_tail(&buf->vb.queue, &vbiq->active);
125}
126
127static void vbi_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
128{ 72{
73 struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
129 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); 74 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
130 free_buffer(q, buf); 75 struct au0828_dmaqueue *vbiq = &dev->vbiq;
76 unsigned long flags = 0;
77
78 buf->mem = vb2_plane_vaddr(vb, 0);
79 buf->length = vb2_plane_size(vb, 0);
80
81 spin_lock_irqsave(&dev->slock, flags);
82 list_add_tail(&buf->list, &vbiq->active);
83 spin_unlock_irqrestore(&dev->slock, flags);
131} 84}
132 85
133struct videobuf_queue_ops au0828_vbi_qops = { 86struct vb2_ops au0828_vbi_qops = {
134 .buf_setup = vbi_setup, 87 .queue_setup = vbi_queue_setup,
135 .buf_prepare = vbi_prepare, 88 .buf_prepare = vbi_buffer_prepare,
136 .buf_queue = vbi_queue, 89 .buf_queue = vbi_buffer_queue,
137 .buf_release = vbi_release, 90 .start_streaming = au0828_start_analog_streaming,
91 .stop_streaming = au0828_stop_vbi_streaming,
92 .wait_prepare = vb2_ops_wait_prepare,
93 .wait_finish = vb2_ops_wait_finish,
138}; 94};
diff --git a/drivers/media/usb/au0828/au0828-video.c b/drivers/media/usb/au0828/au0828-video.c
index 5f337b118bff..a27cb5fcdef8 100644
--- a/drivers/media/usb/au0828/au0828-video.c
+++ b/drivers/media/usb/au0828/au0828-video.c
@@ -22,7 +22,6 @@
22 22
23/* Developer Notes: 23/* Developer Notes:
24 * 24 *
25 * VBI support is not yet working
26 * The hardware scaler supported is unimplemented 25 * The hardware scaler supported is unimplemented
27 * AC97 audio support is unimplemented (only i2s audio mode) 26 * AC97 audio support is unimplemented (only i2s audio mode)
28 * 27 *
@@ -219,9 +218,6 @@ static int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
219 218
220 au0828_isocdbg("au0828: called au0828_prepare_isoc\n"); 219 au0828_isocdbg("au0828: called au0828_prepare_isoc\n");
221 220
222 /* De-allocates all pending stuff */
223 au0828_uninit_isoc(dev);
224
225 dev->isoc_ctl.isoc_copy = isoc_copy; 221 dev->isoc_ctl.isoc_copy = isoc_copy;
226 dev->isoc_ctl.num_bufs = num_bufs; 222 dev->isoc_ctl.num_bufs = num_bufs;
227 223
@@ -285,8 +281,6 @@ static int au0828_init_isoc(struct au0828_dev *dev, int max_packets,
285 } 281 }
286 } 282 }
287 283
288 init_waitqueue_head(&dma_q->wq);
289
290 /* submit urbs and enables IRQ */ 284 /* submit urbs and enables IRQ */
291 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) { 285 for (i = 0; i < dev->isoc_ctl.num_bufs; i++) {
292 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC); 286 rc = usb_submit_urb(dev->isoc_ctl.urb[i], GFP_ATOMIC);
@@ -309,16 +303,12 @@ static inline void buffer_filled(struct au0828_dev *dev,
309 struct au0828_buffer *buf) 303 struct au0828_buffer *buf)
310{ 304{
311 /* Advice that buffer was filled */ 305 /* Advice that buffer was filled */
312 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); 306 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field);
313
314 buf->vb.state = VIDEOBUF_DONE;
315 buf->vb.field_count++;
316 v4l2_get_timestamp(&buf->vb.ts);
317 307
318 dev->isoc_ctl.buf = NULL; 308 buf->vb.v4l2_buf.sequence = dev->frame_count++;
319 309 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
320 list_del(&buf->vb.queue); 310 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
321 wake_up(&buf->vb.done); 311 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
322} 312}
323 313
324static inline void vbi_buffer_filled(struct au0828_dev *dev, 314static inline void vbi_buffer_filled(struct au0828_dev *dev,
@@ -326,16 +316,12 @@ static inline void vbi_buffer_filled(struct au0828_dev *dev,
326 struct au0828_buffer *buf) 316 struct au0828_buffer *buf)
327{ 317{
328 /* Advice that buffer was filled */ 318 /* Advice that buffer was filled */
329 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->vb.i); 319 au0828_isocdbg("[%p/%d] wakeup\n", buf, buf->top_field);
330
331 buf->vb.state = VIDEOBUF_DONE;
332 buf->vb.field_count++;
333 v4l2_get_timestamp(&buf->vb.ts);
334 320
335 dev->isoc_ctl.vbi_buf = NULL; 321 buf->vb.v4l2_buf.sequence = dev->vbi_frame_count++;
336 322 buf->vb.v4l2_buf.field = V4L2_FIELD_INTERLACED;
337 list_del(&buf->vb.queue); 323 v4l2_get_timestamp(&buf->vb.v4l2_buf.timestamp);
338 wake_up(&buf->vb.done); 324 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_DONE);
339} 325}
340 326
341/* 327/*
@@ -354,8 +340,8 @@ static void au0828_copy_video(struct au0828_dev *dev,
354 if (len == 0) 340 if (len == 0)
355 return; 341 return;
356 342
357 if (dma_q->pos + len > buf->vb.size) 343 if (dma_q->pos + len > buf->length)
358 len = buf->vb.size - dma_q->pos; 344 len = buf->length - dma_q->pos;
359 345
360 startread = p; 346 startread = p;
361 remain = len; 347 remain = len;
@@ -373,11 +359,11 @@ static void au0828_copy_video(struct au0828_dev *dev,
373 lencopy = bytesperline - currlinedone; 359 lencopy = bytesperline - currlinedone;
374 lencopy = lencopy > remain ? remain : lencopy; 360 lencopy = lencopy > remain ? remain : lencopy;
375 361
376 if ((char *)startwrite + lencopy > (char *)outp + buf->vb.size) { 362 if ((char *)startwrite + lencopy > (char *)outp + buf->length) {
377 au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n", 363 au0828_isocdbg("Overflow of %zi bytes past buffer end (1)\n",
378 ((char *)startwrite + lencopy) - 364 ((char *)startwrite + lencopy) -
379 ((char *)outp + buf->vb.size)); 365 ((char *)outp + buf->length));
380 remain = (char *)outp + buf->vb.size - (char *)startwrite; 366 remain = (char *)outp + buf->length - (char *)startwrite;
381 lencopy = remain; 367 lencopy = remain;
382 } 368 }
383 if (lencopy <= 0) 369 if (lencopy <= 0)
@@ -395,11 +381,11 @@ static void au0828_copy_video(struct au0828_dev *dev,
395 lencopy = bytesperline; 381 lencopy = bytesperline;
396 382
397 if ((char *)startwrite + lencopy > (char *)outp + 383 if ((char *)startwrite + lencopy > (char *)outp +
398 buf->vb.size) { 384 buf->length) {
399 au0828_isocdbg("Overflow %zi bytes past buf end (2)\n", 385 au0828_isocdbg("Overflow %zi bytes past buf end (2)\n",
400 ((char *)startwrite + lencopy) - 386 ((char *)startwrite + lencopy) -
401 ((char *)outp + buf->vb.size)); 387 ((char *)outp + buf->length));
402 lencopy = remain = (char *)outp + buf->vb.size - 388 lencopy = remain = (char *)outp + buf->length -
403 (char *)startwrite; 389 (char *)startwrite;
404 } 390 }
405 if (lencopy <= 0) 391 if (lencopy <= 0)
@@ -435,7 +421,11 @@ static inline void get_next_buf(struct au0828_dmaqueue *dma_q,
435 } 421 }
436 422
437 /* Get the next buffer */ 423 /* Get the next buffer */
438 *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); 424 *buf = list_entry(dma_q->active.next, struct au0828_buffer, list);
425 /* Cleans up buffer - Useful for testing for frame/URB loss */
426 list_del(&(*buf)->list);
427 dma_q->pos = 0;
428 (*buf)->vb_buf = (*buf)->mem;
439 dev->isoc_ctl.buf = *buf; 429 dev->isoc_ctl.buf = *buf;
440 430
441 return; 431 return;
@@ -473,8 +463,8 @@ static void au0828_copy_vbi(struct au0828_dev *dev,
473 463
474 bytesperline = dev->vbi_width; 464 bytesperline = dev->vbi_width;
475 465
476 if (dma_q->pos + len > buf->vb.size) 466 if (dma_q->pos + len > buf->length)
477 len = buf->vb.size - dma_q->pos; 467 len = buf->length - dma_q->pos;
478 468
479 startread = p; 469 startread = p;
480 startwrite = outp + (dma_q->pos / 2); 470 startwrite = outp + (dma_q->pos / 2);
@@ -497,7 +487,6 @@ static inline void vbi_get_next_buf(struct au0828_dmaqueue *dma_q,
497 struct au0828_buffer **buf) 487 struct au0828_buffer **buf)
498{ 488{
499 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vbiq); 489 struct au0828_dev *dev = container_of(dma_q, struct au0828_dev, vbiq);
500 char *outp;
501 490
502 if (list_empty(&dma_q->active)) { 491 if (list_empty(&dma_q->active)) {
503 au0828_isocdbg("No active queue to serve\n"); 492 au0828_isocdbg("No active queue to serve\n");
@@ -507,13 +496,12 @@ static inline void vbi_get_next_buf(struct au0828_dmaqueue *dma_q,
507 } 496 }
508 497
509 /* Get the next buffer */ 498 /* Get the next buffer */
510 *buf = list_entry(dma_q->active.next, struct au0828_buffer, vb.queue); 499 *buf = list_entry(dma_q->active.next, struct au0828_buffer, list);
511 /* Cleans up buffer - Useful for testing for frame/URB loss */ 500 /* Cleans up buffer - Useful for testing for frame/URB loss */
512 outp = videobuf_to_vmalloc(&(*buf)->vb); 501 list_del(&(*buf)->list);
513 memset(outp, 0x00, (*buf)->vb.size); 502 dma_q->pos = 0;
514 503 (*buf)->vb_buf = (*buf)->mem;
515 dev->isoc_ctl.vbi_buf = *buf; 504 dev->isoc_ctl.vbi_buf = *buf;
516
517 return; 505 return;
518} 506}
519 507
@@ -549,11 +537,11 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
549 537
550 buf = dev->isoc_ctl.buf; 538 buf = dev->isoc_ctl.buf;
551 if (buf != NULL) 539 if (buf != NULL)
552 outp = videobuf_to_vmalloc(&buf->vb); 540 outp = vb2_plane_vaddr(&buf->vb, 0);
553 541
554 vbi_buf = dev->isoc_ctl.vbi_buf; 542 vbi_buf = dev->isoc_ctl.vbi_buf;
555 if (vbi_buf != NULL) 543 if (vbi_buf != NULL)
556 vbioutp = videobuf_to_vmalloc(&vbi_buf->vb); 544 vbioutp = vb2_plane_vaddr(&vbi_buf->vb, 0);
557 545
558 for (i = 0; i < urb->number_of_packets; i++) { 546 for (i = 0; i < urb->number_of_packets; i++) {
559 int status = urb->iso_frame_desc[i].status; 547 int status = urb->iso_frame_desc[i].status;
@@ -593,8 +581,8 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
593 if (vbi_buf == NULL) 581 if (vbi_buf == NULL)
594 vbioutp = NULL; 582 vbioutp = NULL;
595 else 583 else
596 vbioutp = videobuf_to_vmalloc( 584 vbioutp = vb2_plane_vaddr(
597 &vbi_buf->vb); 585 &vbi_buf->vb, 0);
598 586
599 /* Video */ 587 /* Video */
600 if (buf != NULL) 588 if (buf != NULL)
@@ -603,7 +591,7 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
603 if (buf == NULL) 591 if (buf == NULL)
604 outp = NULL; 592 outp = NULL;
605 else 593 else
606 outp = videobuf_to_vmalloc(&buf->vb); 594 outp = vb2_plane_vaddr(&buf->vb, 0);
607 595
608 /* As long as isoc traffic is arriving, keep 596 /* As long as isoc traffic is arriving, keep
609 resetting the timer */ 597 resetting the timer */
@@ -657,130 +645,59 @@ static inline int au0828_isoc_copy(struct au0828_dev *dev, struct urb *urb)
657 return rc; 645 return rc;
658} 646}
659 647
660static int 648static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
661buffer_setup(struct videobuf_queue *vq, unsigned int *count, 649 unsigned int *nbuffers, unsigned int *nplanes,
662 unsigned int *size) 650 unsigned int sizes[], void *alloc_ctxs[])
663{ 651{
664 struct au0828_fh *fh = vq->priv_data; 652 struct au0828_dev *dev = vb2_get_drv_priv(vq);
665 *size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; 653 unsigned long img_size = dev->height * dev->bytesperline;
654 unsigned long size;
666 655
667 if (0 == *count) 656 size = fmt ? fmt->fmt.pix.sizeimage : img_size;
668 *count = AU0828_DEF_BUF; 657 if (size < img_size)
658 return -EINVAL;
669 659
670 if (*count < AU0828_MIN_BUF) 660 *nplanes = 1;
671 *count = AU0828_MIN_BUF; 661 sizes[0] = size;
672 return 0;
673}
674 662
675/* This is called *without* dev->slock held; please keep it that way */ 663 return 0;
676static void free_buffer(struct videobuf_queue *vq, struct au0828_buffer *buf)
677{
678 struct au0828_fh *fh = vq->priv_data;
679 struct au0828_dev *dev = fh->dev;
680 unsigned long flags = 0;
681 if (in_interrupt())
682 BUG();
683
684 /* We used to wait for the buffer to finish here, but this didn't work
685 because, as we were keeping the state as VIDEOBUF_QUEUED,
686 videobuf_queue_cancel marked it as finished for us.
687 (Also, it could wedge forever if the hardware was misconfigured.)
688
689 This should be safe; by the time we get here, the buffer isn't
690 queued anymore. If we ever start marking the buffers as
691 VIDEOBUF_ACTIVE, it won't be, though.
692 */
693 spin_lock_irqsave(&dev->slock, flags);
694 if (dev->isoc_ctl.buf == buf)
695 dev->isoc_ctl.buf = NULL;
696 spin_unlock_irqrestore(&dev->slock, flags);
697
698 videobuf_vmalloc_free(&buf->vb);
699 buf->vb.state = VIDEOBUF_NEEDS_INIT;
700} 664}
701 665
702static int 666static int
703buffer_prepare(struct videobuf_queue *vq, struct videobuf_buffer *vb, 667buffer_prepare(struct vb2_buffer *vb)
704 enum v4l2_field field)
705{ 668{
706 struct au0828_fh *fh = vq->priv_data;
707 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb); 669 struct au0828_buffer *buf = container_of(vb, struct au0828_buffer, vb);
708 struct au0828_dev *dev = fh->dev; 670 struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
709 int rc = 0, urb_init = 0;
710 671
711 buf->vb.size = (fh->dev->width * fh->dev->height * 16 + 7) >> 3; 672 buf->length = dev->height * dev->bytesperline;
712 673
713 if (0 != buf->vb.baddr && buf->vb.bsize < buf->vb.size) 674 if (vb2_plane_size(vb, 0) < buf->length) {
675 pr_err("%s data will not fit into plane (%lu < %lu)\n",
676 __func__, vb2_plane_size(vb, 0), buf->length);
714 return -EINVAL; 677 return -EINVAL;
715
716 buf->vb.width = dev->width;
717 buf->vb.height = dev->height;
718 buf->vb.field = field;
719
720 if (VIDEOBUF_NEEDS_INIT == buf->vb.state) {
721 rc = videobuf_iolock(vq, &buf->vb, NULL);
722 if (rc < 0) {
723 pr_info("videobuf_iolock failed\n");
724 goto fail;
725 }
726 } 678 }
727 679 vb2_set_plane_payload(&buf->vb, 0, buf->length);
728 if (!dev->isoc_ctl.num_bufs)
729 urb_init = 1;
730
731 if (urb_init) {
732 rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB,
733 AU0828_MAX_ISO_BUFS, dev->max_pkt_size,
734 au0828_isoc_copy);
735 if (rc < 0) {
736 pr_info("au0828_init_isoc failed\n");
737 goto fail;
738 }
739 }
740
741 buf->vb.state = VIDEOBUF_PREPARED;
742 return 0; 680 return 0;
743
744fail:
745 free_buffer(vq, buf);
746 return rc;
747} 681}
748 682
749static void 683static void
750buffer_queue(struct videobuf_queue *vq, struct videobuf_buffer *vb) 684buffer_queue(struct vb2_buffer *vb)
751{ 685{
752 struct au0828_buffer *buf = container_of(vb, 686 struct au0828_buffer *buf = container_of(vb,
753 struct au0828_buffer, 687 struct au0828_buffer,
754 vb); 688 vb);
755 struct au0828_fh *fh = vq->priv_data; 689 struct au0828_dev *dev = vb2_get_drv_priv(vb->vb2_queue);
756 struct au0828_dev *dev = fh->dev;
757 struct au0828_dmaqueue *vidq = &dev->vidq; 690 struct au0828_dmaqueue *vidq = &dev->vidq;
691 unsigned long flags = 0;
758 692
759 buf->vb.state = VIDEOBUF_QUEUED; 693 buf->mem = vb2_plane_vaddr(vb, 0);
760 list_add_tail(&buf->vb.queue, &vidq->active); 694 buf->length = vb2_plane_size(vb, 0);
761}
762
763static void buffer_release(struct videobuf_queue *vq,
764 struct videobuf_buffer *vb)
765{
766 struct au0828_buffer *buf = container_of(vb,
767 struct au0828_buffer,
768 vb);
769 695
770 free_buffer(vq, buf); 696 spin_lock_irqsave(&dev->slock, flags);
697 list_add_tail(&buf->list, &vidq->active);
698 spin_unlock_irqrestore(&dev->slock, flags);
771} 699}
772 700
773static struct videobuf_queue_ops au0828_video_qops = {
774 .buf_setup = buffer_setup,
775 .buf_prepare = buffer_prepare,
776 .buf_queue = buffer_queue,
777 .buf_release = buffer_release,
778};
779
780/* ------------------------------------------------------------------
781 V4L2 interface
782 ------------------------------------------------------------------*/
783
784static int au0828_i2s_init(struct au0828_dev *dev) 701static int au0828_i2s_init(struct au0828_dev *dev)
785{ 702{
786 /* Enable i2s mode */ 703 /* Enable i2s mode */
@@ -829,7 +746,7 @@ static int au0828_analog_stream_enable(struct au0828_dev *d)
829 return 0; 746 return 0;
830} 747}
831 748
832int au0828_analog_stream_disable(struct au0828_dev *d) 749static int au0828_analog_stream_disable(struct au0828_dev *d)
833{ 750{
834 dprintk(1, "au0828_analog_stream_disable called\n"); 751 dprintk(1, "au0828_analog_stream_disable called\n");
835 au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0); 752 au0828_writereg(d, AU0828_SENSORCTRL_100, 0x0);
@@ -862,78 +779,133 @@ static int au0828_stream_interrupt(struct au0828_dev *dev)
862 return 0; 779 return 0;
863} 780}
864 781
865/* 782int au0828_start_analog_streaming(struct vb2_queue *vq, unsigned int count)
866 * au0828_release_resources
867 * unregister v4l2 devices
868 */
869void au0828_analog_unregister(struct au0828_dev *dev)
870{ 783{
871 dprintk(1, "au0828_release_resources called\n"); 784 struct au0828_dev *dev = vb2_get_drv_priv(vq);
872 mutex_lock(&au0828_sysfs_lock); 785 int rc = 0;
873 786
874 if (dev->vdev) 787 dprintk(1, "au0828_start_analog_streaming called %d\n",
875 video_unregister_device(dev->vdev); 788 dev->streaming_users);
876 if (dev->vbi_dev)
877 video_unregister_device(dev->vbi_dev);
878 789
879 mutex_unlock(&au0828_sysfs_lock); 790 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
880} 791 dev->frame_count = 0;
792 else
793 dev->vbi_frame_count = 0;
794
795 if (dev->streaming_users == 0) {
796 /* If we were doing ac97 instead of i2s, it would go here...*/
797 au0828_i2s_init(dev);
798 rc = au0828_init_isoc(dev, AU0828_ISO_PACKETS_PER_URB,
799 AU0828_MAX_ISO_BUFS, dev->max_pkt_size,
800 au0828_isoc_copy);
801 if (rc < 0) {
802 pr_info("au0828_init_isoc failed\n");
803 return rc;
804 }
881 805
806 if (vq->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
807 v4l2_device_call_all(&dev->v4l2_dev, 0, video,
808 s_stream, 1);
809 dev->vid_timeout_running = 1;
810 mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
811 } else if (vq->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
812 dev->vbi_timeout_running = 1;
813 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
814 }
815 }
816 dev->streaming_users++;
817 return rc;
818}
882 819
883/* Usage lock check functions */ 820static void au0828_stop_streaming(struct vb2_queue *vq)
884static int res_get(struct au0828_fh *fh, unsigned int bit)
885{ 821{
886 struct au0828_dev *dev = fh->dev; 822 struct au0828_dev *dev = vb2_get_drv_priv(vq);
823 struct au0828_dmaqueue *vidq = &dev->vidq;
824 unsigned long flags = 0;
887 825
888 if (fh->resources & bit) 826 dprintk(1, "au0828_stop_streaming called %d\n", dev->streaming_users);
889 /* have it already allocated */
890 return 1;
891 827
892 /* is it free? */ 828 if (dev->streaming_users-- == 1)
893 if (dev->resources & bit) { 829 au0828_uninit_isoc(dev);
894 /* no, someone else uses it */ 830
895 return 0; 831 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
832 dev->vid_timeout_running = 0;
833 del_timer_sync(&dev->vid_timeout);
834
835 spin_lock_irqsave(&dev->slock, flags);
836 if (dev->isoc_ctl.buf != NULL) {
837 vb2_buffer_done(&dev->isoc_ctl.buf->vb, VB2_BUF_STATE_ERROR);
838 dev->isoc_ctl.buf = NULL;
896 } 839 }
897 /* it's free, grab it */ 840 while (!list_empty(&vidq->active)) {
898 fh->resources |= bit; 841 struct au0828_buffer *buf;
899 dev->resources |= bit;
900 dprintk(1, "res: get %d\n", bit);
901 842
902 return 1; 843 buf = list_entry(vidq->active.next, struct au0828_buffer, list);
844 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
845 list_del(&buf->list);
846 }
847 spin_unlock_irqrestore(&dev->slock, flags);
903} 848}
904 849
905static int res_check(struct au0828_fh *fh, unsigned int bit) 850void au0828_stop_vbi_streaming(struct vb2_queue *vq)
906{ 851{
907 return fh->resources & bit; 852 struct au0828_dev *dev = vb2_get_drv_priv(vq);
908} 853 struct au0828_dmaqueue *vbiq = &dev->vbiq;
854 unsigned long flags = 0;
909 855
910static int res_locked(struct au0828_dev *dev, unsigned int bit) 856 dprintk(1, "au0828_stop_vbi_streaming called %d\n",
911{ 857 dev->streaming_users);
912 return dev->resources & bit;
913}
914 858
915static void res_free(struct au0828_fh *fh, unsigned int bits) 859 if (dev->streaming_users-- == 1)
916{ 860 au0828_uninit_isoc(dev);
917 struct au0828_dev *dev = fh->dev;
918 861
919 BUG_ON((fh->resources & bits) != bits); 862 spin_lock_irqsave(&dev->slock, flags);
863 if (dev->isoc_ctl.vbi_buf != NULL) {
864 vb2_buffer_done(&dev->isoc_ctl.vbi_buf->vb,
865 VB2_BUF_STATE_ERROR);
866 dev->isoc_ctl.vbi_buf = NULL;
867 }
868 while (!list_empty(&vbiq->active)) {
869 struct au0828_buffer *buf;
870
871 buf = list_entry(vbiq->active.next, struct au0828_buffer, list);
872 list_del(&buf->list);
873 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR);
874 }
875 spin_unlock_irqrestore(&dev->slock, flags);
920 876
921 fh->resources &= ~bits; 877 dev->vbi_timeout_running = 0;
922 dev->resources &= ~bits; 878 del_timer_sync(&dev->vbi_timeout);
923 dprintk(1, "res: put %d\n", bits);
924} 879}
925 880
926static int get_ressource(struct au0828_fh *fh) 881static struct vb2_ops au0828_video_qops = {
882 .queue_setup = queue_setup,
883 .buf_prepare = buffer_prepare,
884 .buf_queue = buffer_queue,
885 .start_streaming = au0828_start_analog_streaming,
886 .stop_streaming = au0828_stop_streaming,
887 .wait_prepare = vb2_ops_wait_prepare,
888 .wait_finish = vb2_ops_wait_finish,
889};
890
891/* ------------------------------------------------------------------
892 V4L2 interface
893 ------------------------------------------------------------------*/
894/*
895 * au0828_analog_unregister
896 * unregister v4l2 devices
897 */
898void au0828_analog_unregister(struct au0828_dev *dev)
927{ 899{
928 switch (fh->type) { 900 dprintk(1, "au0828_analog_unregister called\n");
929 case V4L2_BUF_TYPE_VIDEO_CAPTURE: 901 mutex_lock(&au0828_sysfs_lock);
930 return AU0828_RESOURCE_VIDEO; 902
931 case V4L2_BUF_TYPE_VBI_CAPTURE: 903 if (dev->vdev)
932 return AU0828_RESOURCE_VBI; 904 video_unregister_device(dev->vdev);
933 default: 905 if (dev->vbi_dev)
934 BUG(); 906 video_unregister_device(dev->vbi_dev);
935 return 0; 907
936 } 908 mutex_unlock(&au0828_sysfs_lock);
937} 909}
938 910
939/* This function ensures that video frames continue to be delivered even if 911/* This function ensures that video frames continue to be delivered even if
@@ -951,8 +923,8 @@ static void au0828_vid_buffer_timeout(unsigned long data)
951 923
952 buf = dev->isoc_ctl.buf; 924 buf = dev->isoc_ctl.buf;
953 if (buf != NULL) { 925 if (buf != NULL) {
954 vid_data = videobuf_to_vmalloc(&buf->vb); 926 vid_data = vb2_plane_vaddr(&buf->vb, 0);
955 memset(vid_data, 0x00, buf->vb.size); /* Blank green frame */ 927 memset(vid_data, 0x00, buf->length); /* Blank green frame */
956 buffer_filled(dev, dma_q, buf); 928 buffer_filled(dev, dma_q, buf);
957 } 929 }
958 get_next_buf(dma_q, &buf); 930 get_next_buf(dma_q, &buf);
@@ -975,8 +947,8 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
975 947
976 buf = dev->isoc_ctl.vbi_buf; 948 buf = dev->isoc_ctl.vbi_buf;
977 if (buf != NULL) { 949 if (buf != NULL) {
978 vbi_data = videobuf_to_vmalloc(&buf->vb); 950 vbi_data = vb2_plane_vaddr(&buf->vb, 0);
979 memset(vbi_data, 0x00, buf->vb.size); 951 memset(vbi_data, 0x00, buf->length);
980 vbi_buffer_filled(dev, dma_q, buf); 952 vbi_buffer_filled(dev, dma_q, buf);
981 } 953 }
982 vbi_get_next_buf(dma_q, &buf); 954 vbi_get_next_buf(dma_q, &buf);
@@ -986,105 +958,65 @@ static void au0828_vbi_buffer_timeout(unsigned long data)
986 spin_unlock_irqrestore(&dev->slock, flags); 958 spin_unlock_irqrestore(&dev->slock, flags);
987} 959}
988 960
989
990static int au0828_v4l2_open(struct file *filp) 961static int au0828_v4l2_open(struct file *filp)
991{ 962{
992 int ret = 0;
993 struct video_device *vdev = video_devdata(filp);
994 struct au0828_dev *dev = video_drvdata(filp); 963 struct au0828_dev *dev = video_drvdata(filp);
995 struct au0828_fh *fh; 964 int ret;
996 int type;
997
998 switch (vdev->vfl_type) {
999 case VFL_TYPE_GRABBER:
1000 type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1001 break;
1002 case VFL_TYPE_VBI:
1003 type = V4L2_BUF_TYPE_VBI_CAPTURE;
1004 break;
1005 default:
1006 return -EINVAL;
1007 }
1008
1009 fh = kzalloc(sizeof(struct au0828_fh), GFP_KERNEL);
1010 if (NULL == fh) {
1011 dprintk(1, "Failed allocate au0828_fh struct!\n");
1012 return -ENOMEM;
1013 }
1014 965
1015 fh->type = type; 966 dprintk(1,
1016 fh->dev = dev; 967 "%s called std_set %d dev_state %d stream users %d users %d\n",
1017 v4l2_fh_init(&fh->fh, vdev); 968 __func__, dev->std_set_in_tuner_core, dev->dev_state,
1018 filp->private_data = fh; 969 dev->streaming_users, dev->users);
1019 970
1020 if (mutex_lock_interruptible(&dev->lock)) { 971 if (mutex_lock_interruptible(&dev->lock))
1021 kfree(fh);
1022 return -ERESTARTSYS; 972 return -ERESTARTSYS;
973
974 ret = v4l2_fh_open(filp);
975 if (ret) {
976 au0828_isocdbg("%s: v4l2_fh_open() returned error %d\n",
977 __func__, ret);
978 mutex_unlock(&dev->lock);
979 return ret;
1023 } 980 }
981
1024 if (dev->users == 0) { 982 if (dev->users == 0) {
1025 au0828_analog_stream_enable(dev); 983 au0828_analog_stream_enable(dev);
1026 au0828_analog_stream_reset(dev); 984 au0828_analog_stream_reset(dev);
1027
1028 /* If we were doing ac97 instead of i2s, it would go here...*/
1029 au0828_i2s_init(dev);
1030
1031 dev->stream_state = STREAM_OFF; 985 dev->stream_state = STREAM_OFF;
1032 dev->dev_state |= DEV_INITIALIZED; 986 dev->dev_state |= DEV_INITIALIZED;
1033 } 987 }
1034
1035 dev->users++; 988 dev->users++;
1036 mutex_unlock(&dev->lock); 989 mutex_unlock(&dev->lock);
1037
1038 videobuf_queue_vmalloc_init(&fh->vb_vidq, &au0828_video_qops,
1039 NULL, &dev->slock,
1040 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1041 V4L2_FIELD_INTERLACED,
1042 sizeof(struct au0828_buffer), fh,
1043 &dev->lock);
1044
1045 /* VBI Setup */
1046 videobuf_queue_vmalloc_init(&fh->vb_vbiq, &au0828_vbi_qops,
1047 NULL, &dev->slock,
1048 V4L2_BUF_TYPE_VBI_CAPTURE,
1049 V4L2_FIELD_SEQ_TB,
1050 sizeof(struct au0828_buffer), fh,
1051 &dev->lock);
1052 v4l2_fh_add(&fh->fh);
1053 return ret; 990 return ret;
1054} 991}
1055 992
1056static int au0828_v4l2_close(struct file *filp) 993static int au0828_v4l2_close(struct file *filp)
1057{ 994{
1058 int ret; 995 int ret;
1059 struct au0828_fh *fh = filp->private_data; 996 struct au0828_dev *dev = video_drvdata(filp);
1060 struct au0828_dev *dev = fh->dev; 997 struct video_device *vdev = video_devdata(filp);
998
999 dprintk(1,
1000 "%s called std_set %d dev_state %d stream users %d users %d\n",
1001 __func__, dev->std_set_in_tuner_core, dev->dev_state,
1002 dev->streaming_users, dev->users);
1061 1003
1062 v4l2_fh_del(&fh->fh);
1063 v4l2_fh_exit(&fh->fh);
1064 mutex_lock(&dev->lock); 1004 mutex_lock(&dev->lock);
1065 if (res_check(fh, AU0828_RESOURCE_VIDEO)) { 1005 if (vdev->vfl_type == VFL_TYPE_GRABBER && dev->vid_timeout_running) {
1066 /* Cancel timeout thread in case they didn't call streamoff */ 1006 /* Cancel timeout thread in case they didn't call streamoff */
1067 dev->vid_timeout_running = 0; 1007 dev->vid_timeout_running = 0;
1068 del_timer_sync(&dev->vid_timeout); 1008 del_timer_sync(&dev->vid_timeout);
1069 1009 } else if (vdev->vfl_type == VFL_TYPE_VBI &&
1070 videobuf_stop(&fh->vb_vidq); 1010 dev->vbi_timeout_running) {
1071 res_free(fh, AU0828_RESOURCE_VIDEO);
1072 }
1073
1074 if (res_check(fh, AU0828_RESOURCE_VBI)) {
1075 /* Cancel timeout thread in case they didn't call streamoff */ 1011 /* Cancel timeout thread in case they didn't call streamoff */
1076 dev->vbi_timeout_running = 0; 1012 dev->vbi_timeout_running = 0;
1077 del_timer_sync(&dev->vbi_timeout); 1013 del_timer_sync(&dev->vbi_timeout);
1078
1079 videobuf_stop(&fh->vb_vbiq);
1080 res_free(fh, AU0828_RESOURCE_VBI);
1081 } 1014 }
1082 1015
1083 if (dev->users == 1 && video_is_registered(video_devdata(filp))) { 1016 if (dev->dev_state == DEV_DISCONNECTED)
1084 au0828_analog_stream_disable(dev); 1017 goto end;
1085
1086 au0828_uninit_isoc(dev);
1087 1018
1019 if (dev->users == 1) {
1088 /* Save some power by putting tuner to sleep */ 1020 /* Save some power by putting tuner to sleep */
1089 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0); 1021 v4l2_device_call_all(&dev->v4l2_dev, 0, core, s_power, 0);
1090 dev->std_set_in_tuner_core = 0; 1022 dev->std_set_in_tuner_core = 0;
@@ -1095,13 +1027,10 @@ static int au0828_v4l2_close(struct file *filp)
1095 if (ret < 0) 1027 if (ret < 0)
1096 pr_info("Au0828 can't set alternate to 0!\n"); 1028 pr_info("Au0828 can't set alternate to 0!\n");
1097 } 1029 }
1098 mutex_unlock(&dev->lock); 1030end:
1099 1031 _vb2_fop_release(filp, NULL);
1100 videobuf_mmap_free(&fh->vb_vidq);
1101 videobuf_mmap_free(&fh->vb_vbiq);
1102 kfree(fh);
1103 dev->users--; 1032 dev->users--;
1104 wake_up_interruptible_nr(&dev->open, 1); 1033 mutex_unlock(&dev->lock);
1105 return 0; 1034 return 0;
1106} 1035}
1107 1036
@@ -1113,6 +1042,9 @@ static void au0828_init_tuner(struct au0828_dev *dev)
1113 .type = V4L2_TUNER_ANALOG_TV, 1042 .type = V4L2_TUNER_ANALOG_TV,
1114 }; 1043 };
1115 1044
1045 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1046 dev->std_set_in_tuner_core, dev->dev_state);
1047
1116 if (dev->std_set_in_tuner_core) 1048 if (dev->std_set_in_tuner_core)
1117 return; 1049 return;
1118 dev->std_set_in_tuner_core = 1; 1050 dev->std_set_in_tuner_core = 1;
@@ -1125,98 +1057,6 @@ static void au0828_init_tuner(struct au0828_dev *dev)
1125 i2c_gate_ctrl(dev, 0); 1057 i2c_gate_ctrl(dev, 0);
1126} 1058}
1127 1059
1128static ssize_t au0828_v4l2_read(struct file *filp, char __user *buf,
1129 size_t count, loff_t *pos)
1130{
1131 struct au0828_fh *fh = filp->private_data;
1132 struct au0828_dev *dev = fh->dev;
1133 int rc;
1134
1135 rc = check_dev(dev);
1136 if (rc < 0)
1137 return rc;
1138
1139 if (mutex_lock_interruptible(&dev->lock))
1140 return -ERESTARTSYS;
1141 au0828_init_tuner(dev);
1142 mutex_unlock(&dev->lock);
1143
1144 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1145 if (res_locked(dev, AU0828_RESOURCE_VIDEO))
1146 return -EBUSY;
1147
1148 return videobuf_read_stream(&fh->vb_vidq, buf, count, pos, 0,
1149 filp->f_flags & O_NONBLOCK);
1150 }
1151
1152 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1153 if (!res_get(fh, AU0828_RESOURCE_VBI))
1154 return -EBUSY;
1155
1156 if (dev->vbi_timeout_running == 0) {
1157 /* Handle case where caller tries to read without
1158 calling streamon first */
1159 dev->vbi_timeout_running = 1;
1160 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
1161 }
1162
1163 return videobuf_read_stream(&fh->vb_vbiq, buf, count, pos, 0,
1164 filp->f_flags & O_NONBLOCK);
1165 }
1166
1167 return 0;
1168}
1169
1170static unsigned int au0828_v4l2_poll(struct file *filp, poll_table *wait)
1171{
1172 struct au0828_fh *fh = filp->private_data;
1173 struct au0828_dev *dev = fh->dev;
1174 unsigned long req_events = poll_requested_events(wait);
1175 unsigned int res;
1176
1177 if (check_dev(dev) < 0)
1178 return POLLERR;
1179
1180 res = v4l2_ctrl_poll(filp, wait);
1181 if (!(req_events & (POLLIN | POLLRDNORM)))
1182 return res;
1183
1184 if (mutex_lock_interruptible(&dev->lock))
1185 return -ERESTARTSYS;
1186 au0828_init_tuner(dev);
1187 mutex_unlock(&dev->lock);
1188
1189 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1190 if (!res_get(fh, AU0828_RESOURCE_VIDEO))
1191 return POLLERR;
1192 return res | videobuf_poll_stream(filp, &fh->vb_vidq, wait);
1193 }
1194 if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1195 if (!res_get(fh, AU0828_RESOURCE_VBI))
1196 return POLLERR;
1197 return res | videobuf_poll_stream(filp, &fh->vb_vbiq, wait);
1198 }
1199 return POLLERR;
1200}
1201
1202static int au0828_v4l2_mmap(struct file *filp, struct vm_area_struct *vma)
1203{
1204 struct au0828_fh *fh = filp->private_data;
1205 struct au0828_dev *dev = fh->dev;
1206 int rc;
1207
1208 rc = check_dev(dev);
1209 if (rc < 0)
1210 return rc;
1211
1212 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1213 rc = videobuf_mmap_mapper(&fh->vb_vidq, vma);
1214 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1215 rc = videobuf_mmap_mapper(&fh->vb_vbiq, vma);
1216
1217 return rc;
1218}
1219
1220static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd, 1060static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
1221 struct v4l2_format *format) 1061 struct v4l2_format *format)
1222{ 1062{
@@ -1268,13 +1108,14 @@ static int au0828_set_format(struct au0828_dev *dev, unsigned int cmd,
1268 return 0; 1108 return 0;
1269} 1109}
1270 1110
1271
1272static int vidioc_querycap(struct file *file, void *priv, 1111static int vidioc_querycap(struct file *file, void *priv,
1273 struct v4l2_capability *cap) 1112 struct v4l2_capability *cap)
1274{ 1113{
1275 struct video_device *vdev = video_devdata(file); 1114 struct video_device *vdev = video_devdata(file);
1276 struct au0828_fh *fh = priv; 1115 struct au0828_dev *dev = video_drvdata(file);
1277 struct au0828_dev *dev = fh->dev; 1116
1117 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1118 dev->std_set_in_tuner_core, dev->dev_state);
1278 1119
1279 strlcpy(cap->driver, "au0828", sizeof(cap->driver)); 1120 strlcpy(cap->driver, "au0828", sizeof(cap->driver));
1280 strlcpy(cap->card, dev->board.name, sizeof(cap->card)); 1121 strlcpy(cap->card, dev->board.name, sizeof(cap->card));
@@ -1300,6 +1141,8 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1300 if (f->index) 1141 if (f->index)
1301 return -EINVAL; 1142 return -EINVAL;
1302 1143
1144 dprintk(1, "%s called\n", __func__);
1145
1303 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE; 1146 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1304 strcpy(f->description, "Packed YUV2"); 1147 strcpy(f->description, "Packed YUV2");
1305 1148
@@ -1312,8 +1155,10 @@ static int vidioc_enum_fmt_vid_cap(struct file *file, void *priv,
1312static int vidioc_g_fmt_vid_cap(struct file *file, void *priv, 1155static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1313 struct v4l2_format *f) 1156 struct v4l2_format *f)
1314{ 1157{
1315 struct au0828_fh *fh = priv; 1158 struct au0828_dev *dev = video_drvdata(file);
1316 struct au0828_dev *dev = fh->dev; 1159
1160 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1161 dev->std_set_in_tuner_core, dev->dev_state);
1317 1162
1318 f->fmt.pix.width = dev->width; 1163 f->fmt.pix.width = dev->width;
1319 f->fmt.pix.height = dev->height; 1164 f->fmt.pix.height = dev->height;
@@ -1329,8 +1174,10 @@ static int vidioc_g_fmt_vid_cap(struct file *file, void *priv,
1329static int vidioc_try_fmt_vid_cap(struct file *file, void *priv, 1174static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1330 struct v4l2_format *f) 1175 struct v4l2_format *f)
1331{ 1176{
1332 struct au0828_fh *fh = priv; 1177 struct au0828_dev *dev = video_drvdata(file);
1333 struct au0828_dev *dev = fh->dev; 1178
1179 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1180 dev->std_set_in_tuner_core, dev->dev_state);
1334 1181
1335 return au0828_set_format(dev, VIDIOC_TRY_FMT, f); 1182 return au0828_set_format(dev, VIDIOC_TRY_FMT, f);
1336} 1183}
@@ -1338,15 +1185,17 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
1338static int vidioc_s_fmt_vid_cap(struct file *file, void *priv, 1185static int vidioc_s_fmt_vid_cap(struct file *file, void *priv,
1339 struct v4l2_format *f) 1186 struct v4l2_format *f)
1340{ 1187{
1341 struct au0828_fh *fh = priv; 1188 struct au0828_dev *dev = video_drvdata(file);
1342 struct au0828_dev *dev = fh->dev;
1343 int rc; 1189 int rc;
1344 1190
1191 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1192 dev->std_set_in_tuner_core, dev->dev_state);
1193
1345 rc = check_dev(dev); 1194 rc = check_dev(dev);
1346 if (rc < 0) 1195 if (rc < 0)
1347 return rc; 1196 return rc;
1348 1197
1349 if (videobuf_queue_is_busy(&fh->vb_vidq)) { 1198 if (vb2_is_busy(&dev->vb_vidq)) {
1350 pr_info("%s queue busy\n", __func__); 1199 pr_info("%s queue busy\n", __func__);
1351 rc = -EBUSY; 1200 rc = -EBUSY;
1352 goto out; 1201 goto out;
@@ -1359,8 +1208,16 @@ out:
1359 1208
1360static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm) 1209static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1361{ 1210{
1362 struct au0828_fh *fh = priv; 1211 struct au0828_dev *dev = video_drvdata(file);
1363 struct au0828_dev *dev = fh->dev; 1212
1213 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1214 dev->std_set_in_tuner_core, dev->dev_state);
1215
1216 if (norm == dev->std)
1217 return 0;
1218
1219 if (dev->streaming_users > 0)
1220 return -EBUSY;
1364 1221
1365 dev->std = norm; 1222 dev->std = norm;
1366 1223
@@ -1383,8 +1240,10 @@ static int vidioc_s_std(struct file *file, void *priv, v4l2_std_id norm)
1383 1240
1384static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm) 1241static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1385{ 1242{
1386 struct au0828_fh *fh = priv; 1243 struct au0828_dev *dev = video_drvdata(file);
1387 struct au0828_dev *dev = fh->dev; 1244
1245 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1246 dev->std_set_in_tuner_core, dev->dev_state);
1388 1247
1389 *norm = dev->std; 1248 *norm = dev->std;
1390 return 0; 1249 return 0;
@@ -1393,8 +1252,7 @@ static int vidioc_g_std(struct file *file, void *priv, v4l2_std_id *norm)
1393static int vidioc_enum_input(struct file *file, void *priv, 1252static int vidioc_enum_input(struct file *file, void *priv,
1394 struct v4l2_input *input) 1253 struct v4l2_input *input)
1395{ 1254{
1396 struct au0828_fh *fh = priv; 1255 struct au0828_dev *dev = video_drvdata(file);
1397 struct au0828_dev *dev = fh->dev;
1398 unsigned int tmp; 1256 unsigned int tmp;
1399 1257
1400 static const char *inames[] = { 1258 static const char *inames[] = {
@@ -1407,6 +1265,9 @@ static int vidioc_enum_input(struct file *file, void *priv,
1407 [AU0828_VMUX_DEBUG] = "tv debug" 1265 [AU0828_VMUX_DEBUG] = "tv debug"
1408 }; 1266 };
1409 1267
1268 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1269 dev->std_set_in_tuner_core, dev->dev_state);
1270
1410 tmp = input->index; 1271 tmp = input->index;
1411 1272
1412 if (tmp >= AU0828_MAX_INPUT) 1273 if (tmp >= AU0828_MAX_INPUT)
@@ -1432,8 +1293,11 @@ static int vidioc_enum_input(struct file *file, void *priv,
1432 1293
1433static int vidioc_g_input(struct file *file, void *priv, unsigned int *i) 1294static int vidioc_g_input(struct file *file, void *priv, unsigned int *i)
1434{ 1295{
1435 struct au0828_fh *fh = priv; 1296 struct au0828_dev *dev = video_drvdata(file);
1436 struct au0828_dev *dev = fh->dev; 1297
1298 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1299 dev->std_set_in_tuner_core, dev->dev_state);
1300
1437 *i = dev->ctrl_input; 1301 *i = dev->ctrl_input;
1438 return 0; 1302 return 0;
1439} 1303}
@@ -1442,6 +1306,9 @@ static void au0828_s_input(struct au0828_dev *dev, int index)
1442{ 1306{
1443 int i; 1307 int i;
1444 1308
1309 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1310 dev->std_set_in_tuner_core, dev->dev_state);
1311
1445 switch (AUVI_INPUT(index).type) { 1312 switch (AUVI_INPUT(index).type) {
1446 case AU0828_VMUX_SVIDEO: 1313 case AU0828_VMUX_SVIDEO:
1447 dev->input_type = AU0828_VMUX_SVIDEO; 1314 dev->input_type = AU0828_VMUX_SVIDEO;
@@ -1491,8 +1358,7 @@ static void au0828_s_input(struct au0828_dev *dev, int index)
1491 1358
1492static int vidioc_s_input(struct file *file, void *priv, unsigned int index) 1359static int vidioc_s_input(struct file *file, void *priv, unsigned int index)
1493{ 1360{
1494 struct au0828_fh *fh = priv; 1361 struct au0828_dev *dev = video_drvdata(file);
1495 struct au0828_dev *dev = fh->dev;
1496 1362
1497 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__, 1363 dprintk(1, "VIDIOC_S_INPUT in function %s, input=%d\n", __func__,
1498 index); 1364 index);
@@ -1510,6 +1376,8 @@ static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)
1510 if (a->index > 1) 1376 if (a->index > 1)
1511 return -EINVAL; 1377 return -EINVAL;
1512 1378
1379 dprintk(1, "%s called\n", __func__);
1380
1513 if (a->index == 0) 1381 if (a->index == 0)
1514 strcpy(a->name, "Television"); 1382 strcpy(a->name, "Television");
1515 else 1383 else
@@ -1521,8 +1389,10 @@ static int vidioc_enumaudio(struct file *file, void *priv, struct v4l2_audio *a)
1521 1389
1522static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a) 1390static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1523{ 1391{
1524 struct au0828_fh *fh = priv; 1392 struct au0828_dev *dev = video_drvdata(file);
1525 struct au0828_dev *dev = fh->dev; 1393
1394 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1395 dev->std_set_in_tuner_core, dev->dev_state);
1526 1396
1527 a->index = dev->ctrl_ainput; 1397 a->index = dev->ctrl_ainput;
1528 if (a->index == 0) 1398 if (a->index == 0)
@@ -1536,22 +1406,26 @@ static int vidioc_g_audio(struct file *file, void *priv, struct v4l2_audio *a)
1536 1406
1537static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a) 1407static int vidioc_s_audio(struct file *file, void *priv, const struct v4l2_audio *a)
1538{ 1408{
1539 struct au0828_fh *fh = priv; 1409 struct au0828_dev *dev = video_drvdata(file);
1540 struct au0828_dev *dev = fh->dev;
1541 1410
1542 if (a->index != dev->ctrl_ainput) 1411 if (a->index != dev->ctrl_ainput)
1543 return -EINVAL; 1412 return -EINVAL;
1413
1414 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1415 dev->std_set_in_tuner_core, dev->dev_state);
1544 return 0; 1416 return 0;
1545} 1417}
1546 1418
1547static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t) 1419static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1548{ 1420{
1549 struct au0828_fh *fh = priv; 1421 struct au0828_dev *dev = video_drvdata(file);
1550 struct au0828_dev *dev = fh->dev;
1551 1422
1552 if (t->index != 0) 1423 if (t->index != 0)
1553 return -EINVAL; 1424 return -EINVAL;
1554 1425
1426 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1427 dev->std_set_in_tuner_core, dev->dev_state);
1428
1555 strcpy(t->name, "Auvitek tuner"); 1429 strcpy(t->name, "Auvitek tuner");
1556 1430
1557 au0828_init_tuner(dev); 1431 au0828_init_tuner(dev);
@@ -1564,12 +1438,14 @@ static int vidioc_g_tuner(struct file *file, void *priv, struct v4l2_tuner *t)
1564static int vidioc_s_tuner(struct file *file, void *priv, 1438static int vidioc_s_tuner(struct file *file, void *priv,
1565 const struct v4l2_tuner *t) 1439 const struct v4l2_tuner *t)
1566{ 1440{
1567 struct au0828_fh *fh = priv; 1441 struct au0828_dev *dev = video_drvdata(file);
1568 struct au0828_dev *dev = fh->dev;
1569 1442
1570 if (t->index != 0) 1443 if (t->index != 0)
1571 return -EINVAL; 1444 return -EINVAL;
1572 1445
1446 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1447 dev->std_set_in_tuner_core, dev->dev_state);
1448
1573 au0828_init_tuner(dev); 1449 au0828_init_tuner(dev);
1574 i2c_gate_ctrl(dev, 1); 1450 i2c_gate_ctrl(dev, 1);
1575 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t); 1451 v4l2_device_call_all(&dev->v4l2_dev, 0, tuner, s_tuner, t);
@@ -1585,11 +1461,12 @@ static int vidioc_s_tuner(struct file *file, void *priv,
1585static int vidioc_g_frequency(struct file *file, void *priv, 1461static int vidioc_g_frequency(struct file *file, void *priv,
1586 struct v4l2_frequency *freq) 1462 struct v4l2_frequency *freq)
1587{ 1463{
1588 struct au0828_fh *fh = priv; 1464 struct au0828_dev *dev = video_drvdata(file);
1589 struct au0828_dev *dev = fh->dev;
1590 1465
1591 if (freq->tuner != 0) 1466 if (freq->tuner != 0)
1592 return -EINVAL; 1467 return -EINVAL;
1468 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1469 dev->std_set_in_tuner_core, dev->dev_state);
1593 freq->frequency = dev->ctrl_freq; 1470 freq->frequency = dev->ctrl_freq;
1594 return 0; 1471 return 0;
1595} 1472}
@@ -1597,13 +1474,15 @@ static int vidioc_g_frequency(struct file *file, void *priv,
1597static int vidioc_s_frequency(struct file *file, void *priv, 1474static int vidioc_s_frequency(struct file *file, void *priv,
1598 const struct v4l2_frequency *freq) 1475 const struct v4l2_frequency *freq)
1599{ 1476{
1600 struct au0828_fh *fh = priv; 1477 struct au0828_dev *dev = video_drvdata(file);
1601 struct au0828_dev *dev = fh->dev;
1602 struct v4l2_frequency new_freq = *freq; 1478 struct v4l2_frequency new_freq = *freq;
1603 1479
1604 if (freq->tuner != 0) 1480 if (freq->tuner != 0)
1605 return -EINVAL; 1481 return -EINVAL;
1606 1482
1483 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1484 dev->std_set_in_tuner_core, dev->dev_state);
1485
1607 au0828_init_tuner(dev); 1486 au0828_init_tuner(dev);
1608 i2c_gate_ctrl(dev, 1); 1487 i2c_gate_ctrl(dev, 1);
1609 1488
@@ -1625,8 +1504,10 @@ static int vidioc_s_frequency(struct file *file, void *priv,
1625static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv, 1504static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1626 struct v4l2_format *format) 1505 struct v4l2_format *format)
1627{ 1506{
1628 struct au0828_fh *fh = priv; 1507 struct au0828_dev *dev = video_drvdata(file);
1629 struct au0828_dev *dev = fh->dev; 1508
1509 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1510 dev->std_set_in_tuner_core, dev->dev_state);
1630 1511
1631 format->fmt.vbi.samples_per_line = dev->vbi_width; 1512 format->fmt.vbi.samples_per_line = dev->vbi_width;
1632 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY; 1513 format->fmt.vbi.sample_format = V4L2_PIX_FMT_GREY;
@@ -1646,12 +1527,14 @@ static int vidioc_g_fmt_vbi_cap(struct file *file, void *priv,
1646static int vidioc_cropcap(struct file *file, void *priv, 1527static int vidioc_cropcap(struct file *file, void *priv,
1647 struct v4l2_cropcap *cc) 1528 struct v4l2_cropcap *cc)
1648{ 1529{
1649 struct au0828_fh *fh = priv; 1530 struct au0828_dev *dev = video_drvdata(file);
1650 struct au0828_dev *dev = fh->dev;
1651 1531
1652 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE) 1532 if (cc->type != V4L2_BUF_TYPE_VIDEO_CAPTURE)
1653 return -EINVAL; 1533 return -EINVAL;
1654 1534
1535 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1536 dev->std_set_in_tuner_core, dev->dev_state);
1537
1655 cc->bounds.left = 0; 1538 cc->bounds.left = 0;
1656 cc->bounds.top = 0; 1539 cc->bounds.top = 0;
1657 cc->bounds.width = dev->width; 1540 cc->bounds.width = dev->width;
@@ -1665,105 +1548,14 @@ static int vidioc_cropcap(struct file *file, void *priv,
1665 return 0; 1548 return 0;
1666} 1549}
1667 1550
1668static int vidioc_streamon(struct file *file, void *priv,
1669 enum v4l2_buf_type type)
1670{
1671 struct au0828_fh *fh = priv;
1672 struct au0828_dev *dev = fh->dev;
1673 int rc = -EINVAL;
1674
1675 rc = check_dev(dev);
1676 if (rc < 0)
1677 return rc;
1678
1679 if (unlikely(type != fh->type))
1680 return -EINVAL;
1681
1682 dprintk(1, "vidioc_streamon fh=%p t=%d fh->res=%d dev->res=%d\n",
1683 fh, type, fh->resources, dev->resources);
1684
1685 if (unlikely(!res_get(fh, get_ressource(fh))))
1686 return -EBUSY;
1687
1688 au0828_init_tuner(dev);
1689 if (type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1690 au0828_analog_stream_enable(dev);
1691 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 1);
1692 }
1693
1694 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1695 rc = videobuf_streamon(&fh->vb_vidq);
1696 dev->vid_timeout_running = 1;
1697 mod_timer(&dev->vid_timeout, jiffies + (HZ / 10));
1698 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1699 rc = videobuf_streamon(&fh->vb_vbiq);
1700 dev->vbi_timeout_running = 1;
1701 mod_timer(&dev->vbi_timeout, jiffies + (HZ / 10));
1702 }
1703
1704 return rc;
1705}
1706
1707static int vidioc_streamoff(struct file *file, void *priv,
1708 enum v4l2_buf_type type)
1709{
1710 struct au0828_fh *fh = priv;
1711 struct au0828_dev *dev = fh->dev;
1712 int rc;
1713 int i;
1714
1715 rc = check_dev(dev);
1716 if (rc < 0)
1717 return rc;
1718
1719 if (fh->type != V4L2_BUF_TYPE_VIDEO_CAPTURE &&
1720 fh->type != V4L2_BUF_TYPE_VBI_CAPTURE)
1721 return -EINVAL;
1722 if (type != fh->type)
1723 return -EINVAL;
1724
1725 dprintk(1, "vidioc_streamoff fh=%p t=%d fh->res=%d dev->res=%d\n",
1726 fh, type, fh->resources, dev->resources);
1727
1728 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1729 dev->vid_timeout_running = 0;
1730 del_timer_sync(&dev->vid_timeout);
1731
1732 au0828_analog_stream_disable(dev);
1733 v4l2_device_call_all(&dev->v4l2_dev, 0, video, s_stream, 0);
1734 rc = au0828_stream_interrupt(dev);
1735 if (rc != 0)
1736 return rc;
1737
1738 for (i = 0; i < AU0828_MAX_INPUT; i++) {
1739 if (AUVI_INPUT(i).audio_setup == NULL)
1740 continue;
1741 (AUVI_INPUT(i).audio_setup)(dev, 0);
1742 }
1743
1744 if (res_check(fh, AU0828_RESOURCE_VIDEO)) {
1745 videobuf_streamoff(&fh->vb_vidq);
1746 res_free(fh, AU0828_RESOURCE_VIDEO);
1747 }
1748 } else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1749 dev->vbi_timeout_running = 0;
1750 del_timer_sync(&dev->vbi_timeout);
1751
1752 if (res_check(fh, AU0828_RESOURCE_VBI)) {
1753 videobuf_streamoff(&fh->vb_vbiq);
1754 res_free(fh, AU0828_RESOURCE_VBI);
1755 }
1756 }
1757
1758 return 0;
1759}
1760
1761#ifdef CONFIG_VIDEO_ADV_DEBUG 1551#ifdef CONFIG_VIDEO_ADV_DEBUG
1762static int vidioc_g_register(struct file *file, void *priv, 1552static int vidioc_g_register(struct file *file, void *priv,
1763 struct v4l2_dbg_register *reg) 1553 struct v4l2_dbg_register *reg)
1764{ 1554{
1765 struct au0828_fh *fh = priv; 1555 struct au0828_dev *dev = video_drvdata(file);
1766 struct au0828_dev *dev = fh->dev; 1556
1557 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1558 dev->std_set_in_tuner_core, dev->dev_state);
1767 1559
1768 reg->val = au0828_read(dev, reg->reg); 1560 reg->val = au0828_read(dev, reg->reg);
1769 reg->size = 1; 1561 reg->size = 1;
@@ -1773,8 +1565,10 @@ static int vidioc_g_register(struct file *file, void *priv,
1773static int vidioc_s_register(struct file *file, void *priv, 1565static int vidioc_s_register(struct file *file, void *priv,
1774 const struct v4l2_dbg_register *reg) 1566 const struct v4l2_dbg_register *reg)
1775{ 1567{
1776 struct au0828_fh *fh = priv; 1568 struct au0828_dev *dev = video_drvdata(file);
1777 struct au0828_dev *dev = fh->dev; 1569
1570 dprintk(1, "%s called std_set %d dev_state %d\n", __func__,
1571 dev->std_set_in_tuner_core, dev->dev_state);
1778 1572
1779 return au0828_writereg(dev, reg->reg, reg->val); 1573 return au0828_writereg(dev, reg->reg, reg->val);
1780} 1574}
@@ -1784,93 +1578,13 @@ static int vidioc_log_status(struct file *file, void *fh)
1784{ 1578{
1785 struct video_device *vdev = video_devdata(file); 1579 struct video_device *vdev = video_devdata(file);
1786 1580
1581 dprintk(1, "%s called\n", __func__);
1582
1787 v4l2_ctrl_log_status(file, fh); 1583 v4l2_ctrl_log_status(file, fh);
1788 v4l2_device_call_all(vdev->v4l2_dev, 0, core, log_status); 1584 v4l2_device_call_all(vdev->v4l2_dev, 0, core, log_status);
1789 return 0; 1585 return 0;
1790} 1586}
1791 1587
1792static int vidioc_reqbufs(struct file *file, void *priv,
1793 struct v4l2_requestbuffers *rb)
1794{
1795 struct au0828_fh *fh = priv;
1796 struct au0828_dev *dev = fh->dev;
1797 int rc;
1798
1799 rc = check_dev(dev);
1800 if (rc < 0)
1801 return rc;
1802
1803 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1804 rc = videobuf_reqbufs(&fh->vb_vidq, rb);
1805 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1806 rc = videobuf_reqbufs(&fh->vb_vbiq, rb);
1807
1808 return rc;
1809}
1810
1811static int vidioc_querybuf(struct file *file, void *priv,
1812 struct v4l2_buffer *b)
1813{
1814 struct au0828_fh *fh = priv;
1815 struct au0828_dev *dev = fh->dev;
1816 int rc;
1817
1818 rc = check_dev(dev);
1819 if (rc < 0)
1820 return rc;
1821
1822 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1823 rc = videobuf_querybuf(&fh->vb_vidq, b);
1824 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1825 rc = videobuf_querybuf(&fh->vb_vbiq, b);
1826
1827 return rc;
1828}
1829
1830static int vidioc_qbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1831{
1832 struct au0828_fh *fh = priv;
1833 struct au0828_dev *dev = fh->dev;
1834 int rc;
1835
1836 rc = check_dev(dev);
1837 if (rc < 0)
1838 return rc;
1839
1840 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1841 rc = videobuf_qbuf(&fh->vb_vidq, b);
1842 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1843 rc = videobuf_qbuf(&fh->vb_vbiq, b);
1844
1845 return rc;
1846}
1847
1848static int vidioc_dqbuf(struct file *file, void *priv, struct v4l2_buffer *b)
1849{
1850 struct au0828_fh *fh = priv;
1851 struct au0828_dev *dev = fh->dev;
1852 int rc;
1853
1854 rc = check_dev(dev);
1855 if (rc < 0)
1856 return rc;
1857
1858 /* Workaround for a bug in the au0828 hardware design that sometimes
1859 results in the colorspace being inverted */
1860 if (dev->greenscreen_detected == 1) {
1861 dprintk(1, "Detected green frame. Resetting stream...\n");
1862 au0828_analog_stream_reset(dev);
1863 dev->greenscreen_detected = 0;
1864 }
1865
1866 if (fh->type == V4L2_BUF_TYPE_VIDEO_CAPTURE)
1867 rc = videobuf_dqbuf(&fh->vb_vidq, b, file->f_flags & O_NONBLOCK);
1868 else if (fh->type == V4L2_BUF_TYPE_VBI_CAPTURE)
1869 rc = videobuf_dqbuf(&fh->vb_vbiq, b, file->f_flags & O_NONBLOCK);
1870
1871 return rc;
1872}
1873
1874void au0828_v4l2_suspend(struct au0828_dev *dev) 1588void au0828_v4l2_suspend(struct au0828_dev *dev)
1875{ 1589{
1876 struct urb *urb; 1590 struct urb *urb;
@@ -1938,9 +1652,9 @@ static struct v4l2_file_operations au0828_v4l_fops = {
1938 .owner = THIS_MODULE, 1652 .owner = THIS_MODULE,
1939 .open = au0828_v4l2_open, 1653 .open = au0828_v4l2_open,
1940 .release = au0828_v4l2_close, 1654 .release = au0828_v4l2_close,
1941 .read = au0828_v4l2_read, 1655 .read = vb2_fop_read,
1942 .poll = au0828_v4l2_poll, 1656 .poll = vb2_fop_poll,
1943 .mmap = au0828_v4l2_mmap, 1657 .mmap = vb2_fop_mmap,
1944 .unlocked_ioctl = video_ioctl2, 1658 .unlocked_ioctl = video_ioctl2,
1945}; 1659};
1946 1660
@@ -1957,17 +1671,24 @@ static const struct v4l2_ioctl_ops video_ioctl_ops = {
1957 .vidioc_g_audio = vidioc_g_audio, 1671 .vidioc_g_audio = vidioc_g_audio,
1958 .vidioc_s_audio = vidioc_s_audio, 1672 .vidioc_s_audio = vidioc_s_audio,
1959 .vidioc_cropcap = vidioc_cropcap, 1673 .vidioc_cropcap = vidioc_cropcap,
1960 .vidioc_reqbufs = vidioc_reqbufs, 1674
1961 .vidioc_querybuf = vidioc_querybuf, 1675 .vidioc_reqbufs = vb2_ioctl_reqbufs,
1962 .vidioc_qbuf = vidioc_qbuf, 1676 .vidioc_create_bufs = vb2_ioctl_create_bufs,
1963 .vidioc_dqbuf = vidioc_dqbuf, 1677 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
1678 .vidioc_querybuf = vb2_ioctl_querybuf,
1679 .vidioc_qbuf = vb2_ioctl_qbuf,
1680 .vidioc_dqbuf = vb2_ioctl_dqbuf,
1681 .vidioc_expbuf = vb2_ioctl_expbuf,
1682
1964 .vidioc_s_std = vidioc_s_std, 1683 .vidioc_s_std = vidioc_s_std,
1965 .vidioc_g_std = vidioc_g_std, 1684 .vidioc_g_std = vidioc_g_std,
1966 .vidioc_enum_input = vidioc_enum_input, 1685 .vidioc_enum_input = vidioc_enum_input,
1967 .vidioc_g_input = vidioc_g_input, 1686 .vidioc_g_input = vidioc_g_input,
1968 .vidioc_s_input = vidioc_s_input, 1687 .vidioc_s_input = vidioc_s_input,
1969 .vidioc_streamon = vidioc_streamon, 1688
1970 .vidioc_streamoff = vidioc_streamoff, 1689 .vidioc_streamon = vb2_ioctl_streamon,
1690 .vidioc_streamoff = vb2_ioctl_streamoff,
1691
1971 .vidioc_g_tuner = vidioc_g_tuner, 1692 .vidioc_g_tuner = vidioc_g_tuner,
1972 .vidioc_s_tuner = vidioc_s_tuner, 1693 .vidioc_s_tuner = vidioc_s_tuner,
1973 .vidioc_g_frequency = vidioc_g_frequency, 1694 .vidioc_g_frequency = vidioc_g_frequency,
@@ -1988,6 +1709,42 @@ static const struct video_device au0828_video_template = {
1988 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M, 1709 .tvnorms = V4L2_STD_NTSC_M | V4L2_STD_PAL_M,
1989}; 1710};
1990 1711
1712static int au0828_vb2_setup(struct au0828_dev *dev)
1713{
1714 int rc;
1715 struct vb2_queue *q;
1716
1717 /* Setup Videobuf2 for Video capture */
1718 q = &dev->vb_vidq;
1719 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1720 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1721 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1722 q->drv_priv = dev;
1723 q->buf_struct_size = sizeof(struct au0828_buffer);
1724 q->ops = &au0828_video_qops;
1725 q->mem_ops = &vb2_vmalloc_memops;
1726
1727 rc = vb2_queue_init(q);
1728 if (rc < 0)
1729 return rc;
1730
1731 /* Setup Videobuf2 for VBI capture */
1732 q = &dev->vb_vbiq;
1733 q->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1734 q->io_modes = VB2_READ | VB2_MMAP | VB2_USERPTR | VB2_DMABUF;
1735 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
1736 q->drv_priv = dev;
1737 q->buf_struct_size = sizeof(struct au0828_buffer);
1738 q->ops = &au0828_vbi_qops;
1739 q->mem_ops = &vb2_vmalloc_memops;
1740
1741 rc = vb2_queue_init(q);
1742 if (rc < 0)
1743 return rc;
1744
1745 return 0;
1746}
1747
1991/**************************************************************************/ 1748/**************************************************************************/
1992 1749
1993int au0828_analog_register(struct au0828_dev *dev, 1750int au0828_analog_register(struct au0828_dev *dev,
@@ -2030,7 +1787,6 @@ int au0828_analog_register(struct au0828_dev *dev,
2030 } 1787 }
2031 if (!(dev->isoc_in_endpointaddr)) { 1788 if (!(dev->isoc_in_endpointaddr)) {
2032 pr_info("Could not locate isoc endpoint\n"); 1789 pr_info("Could not locate isoc endpoint\n");
2033 kfree(dev);
2034 return -ENODEV; 1790 return -ENODEV;
2035 } 1791 }
2036 1792
@@ -2039,17 +1795,12 @@ int au0828_analog_register(struct au0828_dev *dev,
2039 1795
2040 /* init video dma queues */ 1796 /* init video dma queues */
2041 INIT_LIST_HEAD(&dev->vidq.active); 1797 INIT_LIST_HEAD(&dev->vidq.active);
2042 INIT_LIST_HEAD(&dev->vidq.queued);
2043 INIT_LIST_HEAD(&dev->vbiq.active); 1798 INIT_LIST_HEAD(&dev->vbiq.active);
2044 INIT_LIST_HEAD(&dev->vbiq.queued);
2045
2046 dev->vid_timeout.function = au0828_vid_buffer_timeout;
2047 dev->vid_timeout.data = (unsigned long) dev;
2048 init_timer(&dev->vid_timeout);
2049 1799
2050 dev->vbi_timeout.function = au0828_vbi_buffer_timeout; 1800 setup_timer(&dev->vid_timeout, au0828_vid_buffer_timeout,
2051 dev->vbi_timeout.data = (unsigned long) dev; 1801 (unsigned long)dev);
2052 init_timer(&dev->vbi_timeout); 1802 setup_timer(&dev->vbi_timeout, au0828_vbi_buffer_timeout,
1803 (unsigned long)dev);
2053 1804
2054 dev->width = NTSC_STD_W; 1805 dev->width = NTSC_STD_W;
2055 dev->height = NTSC_STD_H; 1806 dev->height = NTSC_STD_H;
@@ -2078,18 +1829,34 @@ int au0828_analog_register(struct au0828_dev *dev,
2078 goto err_vdev; 1829 goto err_vdev;
2079 } 1830 }
2080 1831
1832 mutex_init(&dev->vb_queue_lock);
1833 mutex_init(&dev->vb_vbi_queue_lock);
1834
2081 /* Fill the video capture device struct */ 1835 /* Fill the video capture device struct */
2082 *dev->vdev = au0828_video_template; 1836 *dev->vdev = au0828_video_template;
2083 dev->vdev->v4l2_dev = &dev->v4l2_dev; 1837 dev->vdev->v4l2_dev = &dev->v4l2_dev;
2084 dev->vdev->lock = &dev->lock; 1838 dev->vdev->lock = &dev->lock;
1839 dev->vdev->queue = &dev->vb_vidq;
1840 dev->vdev->queue->lock = &dev->vb_queue_lock;
2085 strcpy(dev->vdev->name, "au0828a video"); 1841 strcpy(dev->vdev->name, "au0828a video");
2086 1842
2087 /* Setup the VBI device */ 1843 /* Setup the VBI device */
2088 *dev->vbi_dev = au0828_video_template; 1844 *dev->vbi_dev = au0828_video_template;
2089 dev->vbi_dev->v4l2_dev = &dev->v4l2_dev; 1845 dev->vbi_dev->v4l2_dev = &dev->v4l2_dev;
2090 dev->vbi_dev->lock = &dev->lock; 1846 dev->vbi_dev->lock = &dev->lock;
1847 dev->vbi_dev->queue = &dev->vb_vbiq;
1848 dev->vbi_dev->queue->lock = &dev->vb_vbi_queue_lock;
2091 strcpy(dev->vbi_dev->name, "au0828a vbi"); 1849 strcpy(dev->vbi_dev->name, "au0828a vbi");
2092 1850
1851 /* initialize videobuf2 stuff */
1852 retval = au0828_vb2_setup(dev);
1853 if (retval != 0) {
1854 dprintk(1, "unable to setup videobuf2 queues (error = %d).\n",
1855 retval);
1856 ret = -ENODEV;
1857 goto err_vbi_dev;
1858 }
1859
2093 /* Register the v4l2 device */ 1860 /* Register the v4l2 device */
2094 video_set_drvdata(dev->vdev, dev); 1861 video_set_drvdata(dev->vdev, dev);
2095 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1); 1862 retval = video_register_device(dev->vdev, VFL_TYPE_GRABBER, -1);
@@ -2097,7 +1864,7 @@ int au0828_analog_register(struct au0828_dev *dev,
2097 dprintk(1, "unable to register video device (error = %d).\n", 1864 dprintk(1, "unable to register video device (error = %d).\n",
2098 retval); 1865 retval);
2099 ret = -ENODEV; 1866 ret = -ENODEV;
2100 goto err_vbi_dev; 1867 goto err_reg_vdev;
2101 } 1868 }
2102 1869
2103 /* Register the vbi device */ 1870 /* Register the vbi device */
@@ -2107,13 +1874,18 @@ int au0828_analog_register(struct au0828_dev *dev,
2107 dprintk(1, "unable to register vbi device (error = %d).\n", 1874 dprintk(1, "unable to register vbi device (error = %d).\n",
2108 retval); 1875 retval);
2109 ret = -ENODEV; 1876 ret = -ENODEV;
2110 goto err_vbi_dev; 1877 goto err_reg_vbi_dev;
2111 } 1878 }
2112 1879
2113 dprintk(1, "%s completed!\n", __func__); 1880 dprintk(1, "%s completed!\n", __func__);
2114 1881
2115 return 0; 1882 return 0;
2116 1883
1884err_reg_vbi_dev:
1885 video_unregister_device(dev->vdev);
1886err_reg_vdev:
1887 vb2_queue_release(&dev->vb_vidq);
1888 vb2_queue_release(&dev->vb_vbiq);
2117err_vbi_dev: 1889err_vbi_dev:
2118 video_device_release(dev->vbi_dev); 1890 video_device_release(dev->vbi_dev);
2119err_vdev: 1891err_vdev:
diff --git a/drivers/media/usb/au0828/au0828.h b/drivers/media/usb/au0828/au0828.h
index 36815a369c68..eb1518742ae6 100644
--- a/drivers/media/usb/au0828/au0828.h
+++ b/drivers/media/usb/au0828/au0828.h
@@ -28,7 +28,7 @@
28 28
29/* Analog */ 29/* Analog */
30#include <linux/videodev2.h> 30#include <linux/videodev2.h>
31#include <media/videobuf-vmalloc.h> 31#include <media/videobuf2-vmalloc.h>
32#include <media/v4l2-device.h> 32#include <media/v4l2-device.h>
33#include <media/v4l2-ctrls.h> 33#include <media/v4l2-ctrls.h>
34#include <media/v4l2-fh.h> 34#include <media/v4l2-fh.h>
@@ -126,17 +126,7 @@ enum au0828_dev_state {
126 DEV_MISCONFIGURED = 0x04 126 DEV_MISCONFIGURED = 0x04
127}; 127};
128 128
129struct au0828_fh { 129struct au0828_dev;
130 /* must be the first field of this struct! */
131 struct v4l2_fh fh;
132
133 struct au0828_dev *dev;
134 unsigned int resources;
135
136 struct videobuf_queue vb_vidq;
137 struct videobuf_queue vb_vbiq;
138 enum v4l2_buf_type type;
139};
140 130
141struct au0828_usb_isoc_ctl { 131struct au0828_usb_isoc_ctl {
142 /* max packet size of isoc transaction */ 132 /* max packet size of isoc transaction */
@@ -177,21 +167,20 @@ struct au0828_usb_isoc_ctl {
177/* buffer for one video frame */ 167/* buffer for one video frame */
178struct au0828_buffer { 168struct au0828_buffer {
179 /* common v4l buffer stuff -- must be first */ 169 /* common v4l buffer stuff -- must be first */
180 struct videobuf_buffer vb; 170 struct vb2_buffer vb;
171 struct list_head list;
181 172
182 struct list_head frame; 173 void *mem;
174 unsigned long length;
183 int top_field; 175 int top_field;
184 int receiving; 176 /* pointer to vmalloc memory address in vb */
177 char *vb_buf;
185}; 178};
186 179
187struct au0828_dmaqueue { 180struct au0828_dmaqueue {
188 struct list_head active; 181 struct list_head active;
189 struct list_head queued;
190
191 wait_queue_head_t wq;
192
193 /* Counters to control buffer fill */ 182 /* Counters to control buffer fill */
194 int pos; 183 int pos;
195}; 184};
196 185
197struct au0828_dev { 186struct au0828_dev {
@@ -220,14 +209,26 @@ struct au0828_dev {
220 struct au0828_rc *ir; 209 struct au0828_rc *ir;
221#endif 210#endif
222 211
223 int users;
224 unsigned int resources; /* resources in use */
225 struct video_device *vdev; 212 struct video_device *vdev;
226 struct video_device *vbi_dev; 213 struct video_device *vbi_dev;
214
215 /* Videobuf2 */
216 struct vb2_queue vb_vidq;
217 struct vb2_queue vb_vbiq;
218 struct mutex vb_queue_lock;
219 struct mutex vb_vbi_queue_lock;
220
221 unsigned int frame_count;
222 unsigned int vbi_frame_count;
223
227 struct timer_list vid_timeout; 224 struct timer_list vid_timeout;
228 int vid_timeout_running; 225 int vid_timeout_running;
229 struct timer_list vbi_timeout; 226 struct timer_list vbi_timeout;
230 int vbi_timeout_running; 227 int vbi_timeout_running;
228
229 int users;
230 int streaming_users;
231
231 int width; 232 int width;
232 int height; 233 int height;
233 int vbi_width; 234 int vbi_width;
@@ -242,7 +243,6 @@ struct au0828_dev {
242 __u8 isoc_in_endpointaddr; 243 __u8 isoc_in_endpointaddr;
243 u8 isoc_init_ok; 244 u8 isoc_init_ok;
244 int greenscreen_detected; 245 int greenscreen_detected;
245 unsigned int frame_count;
246 int ctrl_freq; 246 int ctrl_freq;
247 int input_type; 247 int input_type;
248 int std_set_in_tuner_core; 248 int std_set_in_tuner_core;
@@ -277,6 +277,7 @@ struct au0828_dev {
277 char *dig_transfer_buffer[URB_COUNT]; 277 char *dig_transfer_buffer[URB_COUNT];
278}; 278};
279 279
280
280/* ----------------------------------------------------------- */ 281/* ----------------------------------------------------------- */
281#define au0828_read(dev, reg) au0828_readreg(dev, reg) 282#define au0828_read(dev, reg) au0828_readreg(dev, reg)
282#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value) 283#define au0828_write(dev, reg, value) au0828_writereg(dev, reg, value)
@@ -309,13 +310,15 @@ extern int au0828_i2c_unregister(struct au0828_dev *dev);
309 310
310/* ----------------------------------------------------------- */ 311/* ----------------------------------------------------------- */
311/* au0828-video.c */ 312/* au0828-video.c */
312int au0828_analog_register(struct au0828_dev *dev, 313extern int au0828_analog_register(struct au0828_dev *dev,
313 struct usb_interface *interface); 314 struct usb_interface *interface);
314int au0828_analog_stream_disable(struct au0828_dev *d); 315extern void au0828_analog_unregister(struct au0828_dev *dev);
315void au0828_analog_unregister(struct au0828_dev *dev); 316extern int au0828_start_analog_streaming(struct vb2_queue *vq,
317 unsigned int count);
318extern void au0828_stop_vbi_streaming(struct vb2_queue *vq);
316#ifdef CONFIG_VIDEO_AU0828_V4L2 319#ifdef CONFIG_VIDEO_AU0828_V4L2
317void au0828_v4l2_suspend(struct au0828_dev *dev); 320extern void au0828_v4l2_suspend(struct au0828_dev *dev);
318void au0828_v4l2_resume(struct au0828_dev *dev); 321extern void au0828_v4l2_resume(struct au0828_dev *dev);
319#else 322#else
320static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { }; 323static inline void au0828_v4l2_suspend(struct au0828_dev *dev) { };
321static inline void au0828_v4l2_resume(struct au0828_dev *dev) { }; 324static inline void au0828_v4l2_resume(struct au0828_dev *dev) { };
@@ -329,7 +332,7 @@ void au0828_dvb_suspend(struct au0828_dev *dev);
329void au0828_dvb_resume(struct au0828_dev *dev); 332void au0828_dvb_resume(struct au0828_dev *dev);
330 333
331/* au0828-vbi.c */ 334/* au0828-vbi.c */
332extern struct videobuf_queue_ops au0828_vbi_qops; 335extern struct vb2_ops au0828_vbi_qops;
333 336
334#define dprintk(level, fmt, arg...)\ 337#define dprintk(level, fmt, arg...)\
335 do { if (au0828_debug & level)\ 338 do { if (au0828_debug & level)\
diff --git a/drivers/media/usb/cx231xx/cx231xx-cards.c b/drivers/media/usb/cx231xx/cx231xx-cards.c
index ae05d591f228..da03733690bd 100644
--- a/drivers/media/usb/cx231xx/cx231xx-cards.c
+++ b/drivers/media/usb/cx231xx/cx231xx-cards.c
@@ -1403,7 +1403,6 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1403 struct usb_interface_assoc_descriptor *assoc_desc; 1403 struct usb_interface_assoc_descriptor *assoc_desc;
1404 1404
1405 ifnum = interface->altsetting[0].desc.bInterfaceNumber; 1405 ifnum = interface->altsetting[0].desc.bInterfaceNumber;
1406 udev = usb_get_dev(interface_to_usbdev(interface));
1407 1406
1408 /* 1407 /*
1409 * Interface number 0 - IR interface (handled by mceusb driver) 1408 * Interface number 0 - IR interface (handled by mceusb driver)
@@ -1424,11 +1423,13 @@ static int cx231xx_usb_probe(struct usb_interface *interface,
1424 } 1423 }
1425 } while (test_and_set_bit(nr, &cx231xx_devused)); 1424 } while (test_and_set_bit(nr, &cx231xx_devused));
1426 1425
1426 udev = usb_get_dev(interface_to_usbdev(interface));
1427
1427 /* allocate memory for our device state and initialize it */ 1428 /* allocate memory for our device state and initialize it */
1428 dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL); 1429 dev = devm_kzalloc(&udev->dev, sizeof(*dev), GFP_KERNEL);
1429 if (dev == NULL) { 1430 if (dev == NULL) {
1430 clear_bit(nr, &cx231xx_devused); 1431 retval = -ENOMEM;
1431 return -ENOMEM; 1432 goto err_if;
1432 } 1433 }
1433 1434
1434 snprintf(dev->name, 29, "cx231xx #%d", nr); 1435 snprintf(dev->name, 29, "cx231xx #%d", nr);
@@ -1582,7 +1583,7 @@ err_v4l2:
1582 usb_set_intfdata(interface, NULL); 1583 usb_set_intfdata(interface, NULL);
1583err_if: 1584err_if:
1584 usb_put_dev(udev); 1585 usb_put_dev(udev);
1585 clear_bit(dev->devno, &cx231xx_devused); 1586 clear_bit(nr, &cx231xx_devused);
1586 return retval; 1587 return retval;
1587} 1588}
1588 1589
diff --git a/drivers/media/usb/cx231xx/cx231xx-video.c b/drivers/media/usb/cx231xx/cx231xx-video.c
index 53ca12c1ff69..ecea76fe07f6 100644
--- a/drivers/media/usb/cx231xx/cx231xx-video.c
+++ b/drivers/media/usb/cx231xx/cx231xx-video.c
@@ -2062,7 +2062,6 @@ static struct video_device *cx231xx_vdev_init(struct cx231xx *dev,
2062 *vfd = *template; 2062 *vfd = *template;
2063 vfd->v4l2_dev = &dev->v4l2_dev; 2063 vfd->v4l2_dev = &dev->v4l2_dev;
2064 vfd->release = video_device_release; 2064 vfd->release = video_device_release;
2065 vfd->debug = video_debug;
2066 vfd->lock = &dev->lock; 2065 vfd->lock = &dev->lock;
2067 2066
2068 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); 2067 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
diff --git a/drivers/media/usb/cx231xx/cx231xx.h b/drivers/media/usb/cx231xx/cx231xx.h
index f9e262eb0db9..6d6f3ee812f6 100644
--- a/drivers/media/usb/cx231xx/cx231xx.h
+++ b/drivers/media/usb/cx231xx/cx231xx.h
@@ -532,15 +532,7 @@ struct cx231xx_video_mode {
532 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */ 532 unsigned int *alt_max_pkt_size; /* array of wMaxPacketSize */
533 u16 end_point_addr; 533 u16 end_point_addr;
534}; 534};
535/* 535
536struct cx23885_dmaqueue {
537 struct list_head active;
538 struct list_head queued;
539 struct timer_list timeout;
540 struct btcx_riscmem stopper;
541 u32 count;
542};
543*/
544struct cx231xx_tsport { 536struct cx231xx_tsport {
545 struct cx231xx *dev; 537 struct cx231xx *dev;
546 538
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb.h b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
index 14e111e13e54..41c6363dff08 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb.h
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb.h
@@ -354,6 +354,7 @@ struct dvb_usb_adapter {
354 * @name: device name 354 * @name: device name
355 * @rc_map: name of rc codes table 355 * @rc_map: name of rc codes table
356 * @rc_polling_active: set when RC polling is active 356 * @rc_polling_active: set when RC polling is active
357 * @intf: pointer to the device's struct usb_interface
357 * @udev: pointer to the device's struct usb_device 358 * @udev: pointer to the device's struct usb_device
358 * @rc: remote controller configuration 359 * @rc: remote controller configuration
359 * @powered: indicated whether the device is power or not 360 * @powered: indicated whether the device is power or not
@@ -370,6 +371,7 @@ struct dvb_usb_device {
370 const char *name; 371 const char *name;
371 const char *rc_map; 372 const char *rc_map;
372 bool rc_polling_active; 373 bool rc_polling_active;
374 struct usb_interface *intf;
373 struct usb_device *udev; 375 struct usb_device *udev;
374 struct dvb_usb_rc rc; 376 struct dvb_usb_rc rc;
375 int powered; 377 int powered;
diff --git a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
index 1950f37df835..9913e0f59485 100644
--- a/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
+++ b/drivers/media/usb/dvb-usb-v2/dvb_usb_core.c
@@ -868,6 +868,7 @@ int dvb_usbv2_probe(struct usb_interface *intf,
868 goto err; 868 goto err;
869 } 869 }
870 870
871 d->intf = intf;
871 d->name = driver_info->name; 872 d->name = driver_info->name;
872 d->rc_map = driver_info->rc_map; 873 d->rc_map = driver_info->rc_map;
873 d->udev = udev; 874 d->udev = udev;
diff --git a/drivers/media/usb/dvb-usb-v2/lmedm04.c b/drivers/media/usb/dvb-usb-v2/lmedm04.c
index 994de53a574b..5de6f7c04d09 100644
--- a/drivers/media/usb/dvb-usb-v2/lmedm04.c
+++ b/drivers/media/usb/dvb-usb-v2/lmedm04.c
@@ -126,9 +126,9 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
126 126
127struct lme2510_state { 127struct lme2510_state {
128 unsigned long int_urb_due; 128 unsigned long int_urb_due;
129 fe_status_t lock_status;
129 u8 id; 130 u8 id;
130 u8 tuner_config; 131 u8 tuner_config;
131 u8 signal_lock;
132 u8 signal_level; 132 u8 signal_level;
133 u8 signal_sn; 133 u8 signal_sn;
134 u8 time_key; 134 u8 time_key;
@@ -143,6 +143,12 @@ struct lme2510_state {
143 void *buffer; 143 void *buffer;
144 struct urb *lme_urb; 144 struct urb *lme_urb;
145 void *usb_buffer; 145 void *usb_buffer;
146 /* Frontend original calls */
147 int (*fe_read_status)(struct dvb_frontend *, fe_status_t *);
148 int (*fe_read_signal_strength)(struct dvb_frontend *, u16 *);
149 int (*fe_read_snr)(struct dvb_frontend *, u16 *);
150 int (*fe_read_ber)(struct dvb_frontend *, u32 *);
151 int (*fe_read_ucblocks)(struct dvb_frontend *, u32 *);
146 int (*fe_set_voltage)(struct dvb_frontend *, fe_sec_voltage_t); 152 int (*fe_set_voltage)(struct dvb_frontend *, fe_sec_voltage_t);
147 u8 dvb_usb_lme2510_firmware; 153 u8 dvb_usb_lme2510_firmware;
148}; 154};
@@ -258,6 +264,7 @@ static void lme2510_int_response(struct urb *lme_urb)
258 static u8 *ibuf, *rbuf; 264 static u8 *ibuf, *rbuf;
259 int i = 0, offset; 265 int i = 0, offset;
260 u32 key; 266 u32 key;
267 u8 signal_lock = 0;
261 268
262 switch (lme_urb->status) { 269 switch (lme_urb->status) {
263 case 0: 270 case 0:
@@ -298,8 +305,7 @@ static void lme2510_int_response(struct urb *lme_urb)
298 case 0xbb: 305 case 0xbb:
299 switch (st->tuner_config) { 306 switch (st->tuner_config) {
300 case TUNER_LG: 307 case TUNER_LG:
301 if (ibuf[2] > 0) 308 signal_lock = ibuf[2] & BIT(5);
302 st->signal_lock = ibuf[2];
303 st->signal_level = ibuf[4]; 309 st->signal_level = ibuf[4];
304 st->signal_sn = ibuf[3]; 310 st->signal_sn = ibuf[3];
305 st->time_key = ibuf[7]; 311 st->time_key = ibuf[7];
@@ -308,29 +314,29 @@ static void lme2510_int_response(struct urb *lme_urb)
308 case TUNER_S0194: 314 case TUNER_S0194:
309 /* Tweak for earlier firmware*/ 315 /* Tweak for earlier firmware*/
310 if (ibuf[1] == 0x03) { 316 if (ibuf[1] == 0x03) {
311 if (ibuf[2] > 1) 317 signal_lock = ibuf[2] & BIT(4);
312 st->signal_lock = ibuf[2];
313 st->signal_level = ibuf[3]; 318 st->signal_level = ibuf[3];
314 st->signal_sn = ibuf[4]; 319 st->signal_sn = ibuf[4];
315 } else { 320 } else {
316 st->signal_level = ibuf[4]; 321 st->signal_level = ibuf[4];
317 st->signal_sn = ibuf[5]; 322 st->signal_sn = ibuf[5];
318 st->signal_lock =
319 (st->signal_lock & 0xf7) +
320 ((ibuf[2] & 0x01) << 0x03);
321 } 323 }
322 break; 324 break;
323 case TUNER_RS2000: 325 case TUNER_RS2000:
324 if (ibuf[2] & 0x1) 326 signal_lock = ibuf[2] & 0xee;
325 st->signal_lock = 0xff;
326 else
327 st->signal_lock = 0x00;
328 st->signal_level = ibuf[5]; 327 st->signal_level = ibuf[5];
329 st->signal_sn = ibuf[4]; 328 st->signal_sn = ibuf[4];
330 st->time_key = ibuf[7]; 329 st->time_key = ibuf[7];
331 default: 330 default:
332 break; 331 break;
333 } 332 }
333
334 /* Interrupt will also throw just BIT 0 as lock */
335 signal_lock |= ibuf[2] & BIT(0);
336
337 if (!signal_lock)
338 st->lock_status &= ~FE_HAS_LOCK;
339
334 debug_data_snipet(5, "INT Remote data snipet in", ibuf); 340 debug_data_snipet(5, "INT Remote data snipet in", ibuf);
335 break; 341 break;
336 case 0xcc: 342 case 0xcc:
@@ -344,15 +350,17 @@ static void lme2510_int_response(struct urb *lme_urb)
344 350
345 usb_submit_urb(lme_urb, GFP_ATOMIC); 351 usb_submit_urb(lme_urb, GFP_ATOMIC);
346 352
347 /* interrupt urb is due every 48 msecs while streaming 353 /* Interrupt urb is due every 48 msecs while streaming the buffer
348 * add 12msecs for system lag */ 354 * stores up to 4 periods if missed. Allow 200 msec for next interrupt.
349 st->int_urb_due = jiffies + msecs_to_jiffies(60); 355 */
356 st->int_urb_due = jiffies + msecs_to_jiffies(200);
350} 357}
351 358
352static int lme2510_int_read(struct dvb_usb_adapter *adap) 359static int lme2510_int_read(struct dvb_usb_adapter *adap)
353{ 360{
354 struct dvb_usb_device *d = adap_to_d(adap); 361 struct dvb_usb_device *d = adap_to_d(adap);
355 struct lme2510_state *lme_int = adap_to_priv(adap); 362 struct lme2510_state *lme_int = adap_to_priv(adap);
363 struct usb_host_endpoint *ep;
356 364
357 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC); 365 lme_int->lme_urb = usb_alloc_urb(0, GFP_ATOMIC);
358 366
@@ -374,6 +382,12 @@ static int lme2510_int_read(struct dvb_usb_adapter *adap)
374 adap, 382 adap,
375 8); 383 8);
376 384
385 /* Quirk of pipe reporting PIPE_BULK but behaves as interrupt */
386 ep = usb_pipe_endpoint(d->udev, lme_int->lme_urb->pipe);
387
388 if (usb_endpoint_type(&ep->desc) == USB_ENDPOINT_XFER_BULK)
389 lme_int->lme_urb->pipe = usb_rcvbulkpipe(d->udev, 0xa),
390
377 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 391 lme_int->lme_urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
378 392
379 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC); 393 usb_submit_urb(lme_int->lme_urb, GFP_ATOMIC);
@@ -449,170 +463,13 @@ static int lme2510_return_status(struct dvb_usb_device *d)
449static int lme2510_msg(struct dvb_usb_device *d, 463static int lme2510_msg(struct dvb_usb_device *d,
450 u8 *wbuf, int wlen, u8 *rbuf, int rlen) 464 u8 *wbuf, int wlen, u8 *rbuf, int rlen)
451{ 465{
452 int ret = 0;
453 struct lme2510_state *st = d->priv; 466 struct lme2510_state *st = d->priv;
454 467
455 if (st->i2c_talk_onoff == 1) { 468 st->i2c_talk_onoff = 1;
456
457 ret = lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
458
459 switch (st->tuner_config) {
460 case TUNER_LG:
461 if (wbuf[2] == 0x1c) {
462 if (wbuf[3] == 0x0e) {
463 st->signal_lock = rbuf[1];
464 if ((st->stream_on & 1) &&
465 (st->signal_lock & 0x10)) {
466 lme2510_stream_restart(d);
467 st->i2c_talk_onoff = 0;
468 }
469 msleep(80);
470 }
471 }
472 break;
473 case TUNER_S7395:
474 if (wbuf[2] == 0xd0) {
475 if (wbuf[3] == 0x24) {
476 st->signal_lock = rbuf[1];
477 if ((st->stream_on & 1) &&
478 (st->signal_lock & 0x8)) {
479 lme2510_stream_restart(d);
480 st->i2c_talk_onoff = 0;
481 }
482 }
483 }
484 break;
485 case TUNER_S0194:
486 if (wbuf[2] == 0xd0) {
487 if (wbuf[3] == 0x1b) {
488 st->signal_lock = rbuf[1];
489 if ((st->stream_on & 1) &&
490 (st->signal_lock & 0x8)) {
491 lme2510_stream_restart(d);
492 st->i2c_talk_onoff = 0;
493 }
494 }
495 }
496 break;
497 case TUNER_RS2000:
498 default:
499 break;
500 }
501 } else {
502 /* TODO rewrite this section */
503 switch (st->tuner_config) {
504 case TUNER_LG:
505 switch (wbuf[3]) {
506 case 0x0e:
507 rbuf[0] = 0x55;
508 rbuf[1] = st->signal_lock;
509 break;
510 case 0x43:
511 rbuf[0] = 0x55;
512 rbuf[1] = st->signal_level;
513 break;
514 case 0x1c:
515 rbuf[0] = 0x55;
516 rbuf[1] = st->signal_sn;
517 break;
518 case 0x15:
519 case 0x16:
520 case 0x17:
521 case 0x18:
522 rbuf[0] = 0x55;
523 rbuf[1] = 0x00;
524 break;
525 default:
526 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
527 st->i2c_talk_onoff = 1;
528 break;
529 }
530 break;
531 case TUNER_S7395:
532 switch (wbuf[3]) {
533 case 0x10:
534 rbuf[0] = 0x55;
535 rbuf[1] = (st->signal_level & 0x80)
536 ? 0 : (st->signal_level * 2);
537 break;
538 case 0x2d:
539 rbuf[0] = 0x55;
540 rbuf[1] = st->signal_sn;
541 break;
542 case 0x24:
543 rbuf[0] = 0x55;
544 rbuf[1] = st->signal_lock;
545 break;
546 case 0x2e:
547 case 0x26:
548 case 0x27:
549 rbuf[0] = 0x55;
550 rbuf[1] = 0x00;
551 break;
552 default:
553 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
554 st->i2c_talk_onoff = 1;
555 break;
556 }
557 break;
558 case TUNER_S0194:
559 switch (wbuf[3]) {
560 case 0x18:
561 rbuf[0] = 0x55;
562 rbuf[1] = (st->signal_level & 0x80)
563 ? 0 : (st->signal_level * 2);
564 break;
565 case 0x24:
566 rbuf[0] = 0x55;
567 rbuf[1] = st->signal_sn;
568 break;
569 case 0x1b:
570 rbuf[0] = 0x55;
571 rbuf[1] = st->signal_lock;
572 break;
573 case 0x19:
574 case 0x25:
575 case 0x1e:
576 case 0x1d:
577 rbuf[0] = 0x55;
578 rbuf[1] = 0x00;
579 break;
580 default:
581 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
582 st->i2c_talk_onoff = 1;
583 break;
584 }
585 break;
586 case TUNER_RS2000:
587 switch (wbuf[3]) {
588 case 0x8c:
589 rbuf[0] = 0x55;
590 rbuf[1] = st->signal_lock;
591
592 /* If int_urb_due overdue
593 * set rbuf[1] to 0 to clear lock */
594 if (time_after(jiffies, st->int_urb_due))
595 rbuf[1] = 0;
596
597 break;
598 default:
599 lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
600 st->i2c_talk_onoff = 1;
601 break;
602 }
603 default:
604 break;
605 }
606
607 deb_info(4, "I2C From Interrupt Message out(%02x) in(%02x)",
608 wbuf[3], rbuf[1]);
609
610 }
611 469
612 return ret; 470 return lme2510_usb_talk(d, wbuf, wlen, rbuf, rlen);
613} 471}
614 472
615
616static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[], 473static int lme2510_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
617 int num) 474 int num)
618{ 475{
@@ -935,26 +792,8 @@ static struct stv0299_config sharp_z0194_config = {
935 .set_symbol_rate = sharp_z0194a_set_symbol_rate, 792 .set_symbol_rate = sharp_z0194a_set_symbol_rate,
936}; 793};
937 794
938static int dm04_rs2000_set_ts_param(struct dvb_frontend *fe,
939 int caller)
940{
941 struct dvb_usb_adapter *adap = fe_to_adap(fe);
942 struct dvb_usb_device *d = adap_to_d(adap);
943 struct lme2510_state *st = d->priv;
944
945 mutex_lock(&d->i2c_mutex);
946 if ((st->i2c_talk_onoff == 1) && (st->stream_on & 1)) {
947 st->i2c_talk_onoff = 0;
948 lme2510_stream_restart(d);
949 }
950 mutex_unlock(&d->i2c_mutex);
951
952 return 0;
953}
954
955static struct m88rs2000_config m88rs2000_config = { 795static struct m88rs2000_config m88rs2000_config = {
956 .demod_addr = 0x68, 796 .demod_addr = 0x68
957 .set_ts_params = dm04_rs2000_set_ts_param,
958}; 797};
959 798
960static struct ts2020_config ts2020_config = { 799static struct ts2020_config ts2020_config = {
@@ -998,27 +837,101 @@ static int dm04_lme2510_set_voltage(struct dvb_frontend *fe,
998 return (ret < 0) ? -ENODEV : 0; 837 return (ret < 0) ? -ENODEV : 0;
999} 838}
1000 839
1001static int dm04_rs2000_read_signal_strength(struct dvb_frontend *fe, 840static int dm04_read_status(struct dvb_frontend *fe, fe_status_t *status)
1002 u16 *strength) 841{
842 struct dvb_usb_device *d = fe_to_d(fe);
843 struct lme2510_state *st = d->priv;
844 int ret = 0;
845
846 if (st->i2c_talk_onoff) {
847 if (st->fe_read_status) {
848 ret = st->fe_read_status(fe, status);
849 if (ret < 0)
850 return ret;
851 }
852
853 st->lock_status = *status;
854
855 if (*status & FE_HAS_LOCK && st->stream_on) {
856 mutex_lock(&d->i2c_mutex);
857
858 st->i2c_talk_onoff = 0;
859 ret = lme2510_stream_restart(d);
860
861 mutex_unlock(&d->i2c_mutex);
862 }
863
864 return ret;
865 }
866
867 /* Timeout of interrupt reached on RS2000 */
868 if (st->tuner_config == TUNER_RS2000 &&
869 time_after(jiffies, st->int_urb_due))
870 st->lock_status &= ~FE_HAS_LOCK;
871
872 *status = st->lock_status;
873
874 if (!(*status & FE_HAS_LOCK))
875 st->i2c_talk_onoff = 1;
876
877 return ret;
878}
879
880static int dm04_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
1003{ 881{
1004 struct lme2510_state *st = fe_to_priv(fe); 882 struct lme2510_state *st = fe_to_priv(fe);
1005 883
1006 *strength = (u16)((u32)st->signal_level * 0xffff / 0xff); 884 if (st->fe_read_signal_strength && !st->stream_on)
885 return st->fe_read_signal_strength(fe, strength);
886
887 switch (st->tuner_config) {
888 case TUNER_LG:
889 *strength = 0xff - st->signal_level;
890 *strength |= *strength << 8;
891 break;
892 /* fall through */
893 case TUNER_S7395:
894 case TUNER_S0194:
895 *strength = 0xffff - (((st->signal_level * 2) << 8) * 5 / 4);
896 break;
897 case TUNER_RS2000:
898 *strength = (u16)((u32)st->signal_level * 0xffff / 0xff);
899 }
1007 900
1008 return 0; 901 return 0;
1009} 902}
1010 903
1011static int dm04_rs2000_read_snr(struct dvb_frontend *fe, u16 *snr) 904static int dm04_read_snr(struct dvb_frontend *fe, u16 *snr)
1012{ 905{
1013 struct lme2510_state *st = fe_to_priv(fe); 906 struct lme2510_state *st = fe_to_priv(fe);
1014 907
1015 *snr = (u16)((u32)st->signal_sn * 0xffff / 0x7f); 908 if (st->fe_read_snr && !st->stream_on)
909 return st->fe_read_snr(fe, snr);
910
911 switch (st->tuner_config) {
912 case TUNER_LG:
913 *snr = 0xff - st->signal_sn;
914 *snr |= *snr << 8;
915 break;
916 /* fall through */
917 case TUNER_S7395:
918 case TUNER_S0194:
919 *snr = (u16)((0xff - st->signal_sn - 0xa1) * 3) << 8;
920 break;
921 case TUNER_RS2000:
922 *snr = (u16)((u32)st->signal_sn * 0xffff / 0x7f);
923 }
1016 924
1017 return 0; 925 return 0;
1018} 926}
1019 927
1020static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber) 928static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber)
1021{ 929{
930 struct lme2510_state *st = fe_to_priv(fe);
931
932 if (st->fe_read_ber && !st->stream_on)
933 return st->fe_read_ber(fe, ber);
934
1022 *ber = 0; 935 *ber = 0;
1023 936
1024 return 0; 937 return 0;
@@ -1026,6 +939,11 @@ static int dm04_read_ber(struct dvb_frontend *fe, u32 *ber)
1026 939
1027static int dm04_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks) 940static int dm04_read_ucblocks(struct dvb_frontend *fe, u32 *ucblocks)
1028{ 941{
942 struct lme2510_state *st = fe_to_priv(fe);
943
944 if (st->fe_read_ucblocks && !st->stream_on)
945 return st->fe_read_ucblocks(fe, ucblocks);
946
1029 *ucblocks = 0; 947 *ucblocks = 0;
1030 948
1031 return 0; 949 return 0;
@@ -1119,15 +1037,6 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1119 st->tuner_config = TUNER_RS2000; 1037 st->tuner_config = TUNER_RS2000;
1120 st->fe_set_voltage = 1038 st->fe_set_voltage =
1121 adap->fe[0]->ops.set_voltage; 1039 adap->fe[0]->ops.set_voltage;
1122
1123 adap->fe[0]->ops.read_signal_strength =
1124 dm04_rs2000_read_signal_strength;
1125 adap->fe[0]->ops.read_snr =
1126 dm04_rs2000_read_snr;
1127 adap->fe[0]->ops.read_ber =
1128 dm04_read_ber;
1129 adap->fe[0]->ops.read_ucblocks =
1130 dm04_read_ucblocks;
1131 } 1040 }
1132 break; 1041 break;
1133 } 1042 }
@@ -1146,7 +1055,19 @@ static int dm04_lme2510_frontend_attach(struct dvb_usb_adapter *adap)
1146 return -ENODEV; 1055 return -ENODEV;
1147 } 1056 }
1148 1057
1058 st->fe_read_status = adap->fe[0]->ops.read_status;
1059 st->fe_read_signal_strength = adap->fe[0]->ops.read_signal_strength;
1060 st->fe_read_snr = adap->fe[0]->ops.read_snr;
1061 st->fe_read_ber = adap->fe[0]->ops.read_ber;
1062 st->fe_read_ucblocks = adap->fe[0]->ops.read_ucblocks;
1063
1064 adap->fe[0]->ops.read_status = dm04_read_status;
1065 adap->fe[0]->ops.read_signal_strength = dm04_read_signal_strength;
1066 adap->fe[0]->ops.read_snr = dm04_read_snr;
1067 adap->fe[0]->ops.read_ber = dm04_read_ber;
1068 adap->fe[0]->ops.read_ucblocks = dm04_read_ucblocks;
1149 adap->fe[0]->ops.set_voltage = dm04_lme2510_set_voltage; 1069 adap->fe[0]->ops.set_voltage = dm04_lme2510_set_voltage;
1070
1150 ret = lme_name(adap); 1071 ret = lme_name(adap);
1151 return ret; 1072 return ret;
1152} 1073}
@@ -1288,7 +1209,6 @@ static void *lme2510_exit_int(struct dvb_usb_device *d)
1288 1209
1289 if (st->usb_buffer != NULL) { 1210 if (st->usb_buffer != NULL) {
1290 st->i2c_talk_onoff = 1; 1211 st->i2c_talk_onoff = 1;
1291 st->signal_lock = 0;
1292 st->signal_level = 0; 1212 st->signal_level = 0;
1293 st->signal_sn = 0; 1213 st->signal_sn = 0;
1294 buffer = st->usb_buffer; 1214 buffer = st->usb_buffer;
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
index 0a98d04c53e4..ecefa5c477fa 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.c
@@ -604,9 +604,3 @@ MODULE_DESCRIPTION("MaxLinear MxL111SF DVB-T demodulator driver");
604MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 604MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
605MODULE_LICENSE("GPL"); 605MODULE_LICENSE("GPL");
606MODULE_VERSION("0.1"); 606MODULE_VERSION("0.1");
607
608/*
609 * Local variables:
610 * c-basic-offset: 8
611 * End:
612 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
index 2d4530f5be54..0bd83e52669c 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-demod.h
@@ -47,9 +47,3 @@ struct dvb_frontend *mxl111sf_demod_attach(struct mxl111sf_state *mxl_state,
47#endif /* CONFIG_DVB_USB_MXL111SF */ 47#endif /* CONFIG_DVB_USB_MXL111SF */
48 48
49#endif /* __MXL111SF_DEMOD_H__ */ 49#endif /* __MXL111SF_DEMOD_H__ */
50
51/*
52 * Local variables:
53 * c-basic-offset: 8
54 * End:
55 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
index a619410adde4..2180c13a6dcc 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.c
@@ -755,9 +755,3 @@ int mxl111sf_gpio_mode_switch(struct mxl111sf_state *state, unsigned int mode)
755 } 755 }
756 return 0; 756 return 0;
757} 757}
758
759/*
760 * Local variables:
761 * c-basic-offset: 8
762 * End:
763 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
index b85a5772d771..16fa4d4daf88 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-gpio.h
@@ -48,9 +48,3 @@ int mxl111sf_config_pin_mux_modes(struct mxl111sf_state *state,
48 enum mxl111sf_mux_config pin_mux_config); 48 enum mxl111sf_mux_config pin_mux_config);
49 49
50#endif /* _DVB_USB_MXL111SF_GPIO_H_ */ 50#endif /* _DVB_USB_MXL111SF_GPIO_H_ */
51
52/*
53 * Local variables:
54 * c-basic-offset: 8
55 * End:
56 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
index a101d06eb143..283495c84ba3 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.c
@@ -842,9 +842,3 @@ int mxl111sf_i2c_xfer(struct i2c_adapter *adap,
842 842
843 return i == num ? num : -EREMOTEIO; 843 return i == num ? num : -EREMOTEIO;
844} 844}
845
846/*
847 * Local variables:
848 * c-basic-offset: 8
849 * End:
850 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
index 465762145ad2..c486fe02f018 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-i2c.h
@@ -27,9 +27,3 @@ int mxl111sf_i2c_xfer(struct i2c_adapter *adap,
27 struct i2c_msg msg[], int num); 27 struct i2c_msg msg[], int num);
28 28
29#endif /* _DVB_USB_MXL111SF_I2C_H_ */ 29#endif /* _DVB_USB_MXL111SF_I2C_H_ */
30
31/*
32 * Local variables:
33 * c-basic-offset: 8
34 * End:
35 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
index f6b348024bec..5b0191178f9f 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.c
@@ -335,9 +335,3 @@ int mxl111sf_idac_config(struct mxl111sf_state *state,
335 335
336 return ret; 336 return ret;
337} 337}
338
339/*
340 * Local variables:
341 * c-basic-offset: 8
342 * End:
343 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
index 0643738de7de..25aa4a1ea755 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-phy.h
@@ -45,9 +45,3 @@ int mxl111sf_idac_config(struct mxl111sf_state *state,
45 u8 current_value, u8 hysteresis_value); 45 u8 current_value, u8 hysteresis_value);
46 46
47#endif /* _DVB_USB_MXL111SF_PHY_H_ */ 47#endif /* _DVB_USB_MXL111SF_PHY_H_ */
48
49/*
50 * Local variables:
51 * c-basic-offset: 8
52 * End:
53 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
index 89bf115e927e..1f4bfbcdbabb 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-reg.h
@@ -171,9 +171,3 @@
171#define V6_DIG_RF_PWR_MSB_REG 0x47 171#define V6_DIG_RF_PWR_MSB_REG 0x47
172 172
173#endif /* _DVB_USB_MXL111SF_REG_H_ */ 173#endif /* _DVB_USB_MXL111SF_REG_H_ */
174
175/*
176 * Local variables:
177 * c-basic-offset: 8
178 * End:
179 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
index a8d2c7053674..444579be0b77 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.c
@@ -515,11 +515,3 @@ MODULE_DESCRIPTION("MaxLinear MxL111SF CMOS tuner driver");
515MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>"); 515MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
516MODULE_LICENSE("GPL"); 516MODULE_LICENSE("GPL");
517MODULE_VERSION("0.1"); 517MODULE_VERSION("0.1");
518
519/*
520 * Overrides for Emacs so that we follow Linus's tabbing style.
521 * ---------------------------------------------------------------------------
522 * Local variables:
523 * c-basic-offset: 8
524 * End:
525 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
index 2046db22519e..e6caab21a197 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf-tuner.h
@@ -77,12 +77,3 @@ struct dvb_frontend *mxl111sf_tuner_attach(struct dvb_frontend *fe,
77#endif 77#endif
78 78
79#endif /* __MXL111SF_TUNER_H__ */ 79#endif /* __MXL111SF_TUNER_H__ */
80
81/*
82 * Overrides for Emacs so that we follow Linus's tabbing style.
83 * ---------------------------------------------------------------------------
84 * Local variables:
85 * c-basic-offset: 8
86 * End:
87 */
88
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.c b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
index c3447eaf1104..bec12b0e076b 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.c
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.c
@@ -1425,9 +1425,3 @@ MODULE_AUTHOR("Michael Krufky <mkrufky@linuxtv.org>");
1425MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF"); 1425MODULE_DESCRIPTION("Driver for MaxLinear MxL111SF");
1426MODULE_VERSION("1.0"); 1426MODULE_VERSION("1.0");
1427MODULE_LICENSE("GPL"); 1427MODULE_LICENSE("GPL");
1428
1429/*
1430 * Local variables:
1431 * c-basic-offset: 8
1432 * End:
1433 */
diff --git a/drivers/media/usb/dvb-usb-v2/mxl111sf.h b/drivers/media/usb/dvb-usb-v2/mxl111sf.h
index 8516c011b7cc..ee70df1f1e94 100644
--- a/drivers/media/usb/dvb-usb-v2/mxl111sf.h
+++ b/drivers/media/usb/dvb-usb-v2/mxl111sf.h
@@ -152,9 +152,3 @@ extern int dvb_usb_mxl111sf_debug;
152}) 152})
153 153
154#endif /* _DVB_USB_MXL111SF_H_ */ 154#endif /* _DVB_USB_MXL111SF_H_ */
155
156/*
157 * Local variables:
158 * c-basic-offset: 8
159 * End:
160 */
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
index 896a225ee011..77dcfdf547ac 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.c
@@ -22,42 +22,6 @@
22 22
23#include "rtl28xxu.h" 23#include "rtl28xxu.h"
24 24
25#include "rtl2830.h"
26#include "rtl2832.h"
27#include "rtl2832_sdr.h"
28#include "mn88472.h"
29#include "mn88473.h"
30
31#include "qt1010.h"
32#include "mt2060.h"
33#include "mxl5005s.h"
34#include "fc0012.h"
35#include "fc0013.h"
36#include "e4000.h"
37#include "fc2580.h"
38#include "tua9001.h"
39#include "r820t.h"
40
41
42#ifdef CONFIG_MEDIA_ATTACH
43#define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
44 void *__r = NULL; \
45 typeof(&FUNCTION) __a = symbol_request(FUNCTION); \
46 if (__a) { \
47 __r = (void *) __a(ARGS); \
48 if (__r == NULL) \
49 symbol_put(FUNCTION); \
50 } \
51 __r; \
52})
53
54#else
55#define dvb_attach_sdr(FUNCTION, ARGS...) ({ \
56 FUNCTION(ARGS); \
57})
58
59#endif
60
61static int rtl28xxu_disable_rc; 25static int rtl28xxu_disable_rc;
62module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644); 26module_param_named(disable_rc, rtl28xxu_disable_rc, int, 0644);
63MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller"); 27MODULE_PARM_DESC(disable_rc, "disable RTL2832U remote controller");
@@ -65,20 +29,14 @@ DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
65 29
66static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req) 30static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
67{ 31{
32 struct rtl28xxu_dev *dev = d->priv;
68 int ret; 33 int ret;
69 unsigned int pipe; 34 unsigned int pipe;
70 u8 requesttype; 35 u8 requesttype;
71 u8 *buf;
72
73 buf = kmalloc(req->size, GFP_KERNEL);
74 if (!buf) {
75 ret = -ENOMEM;
76 goto err;
77 }
78 36
79 if (req->index & CMD_WR_FLAG) { 37 if (req->index & CMD_WR_FLAG) {
80 /* write */ 38 /* write */
81 memcpy(buf, req->data, req->size); 39 memcpy(dev->buf, req->data, req->size);
82 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT); 40 requesttype = (USB_TYPE_VENDOR | USB_DIR_OUT);
83 pipe = usb_sndctrlpipe(d->udev, 0); 41 pipe = usb_sndctrlpipe(d->udev, 0);
84 } else { 42 } else {
@@ -88,30 +46,23 @@ static int rtl28xxu_ctrl_msg(struct dvb_usb_device *d, struct rtl28xxu_req *req)
88 } 46 }
89 47
90 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value, 48 ret = usb_control_msg(d->udev, pipe, 0, requesttype, req->value,
91 req->index, buf, req->size, 1000); 49 req->index, dev->buf, req->size, 1000);
92
93 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value, 50 dvb_usb_dbg_usb_control_msg(d->udev, 0, requesttype, req->value,
94 req->index, buf, req->size); 51 req->index, dev->buf, req->size);
95 52 if (ret < 0)
96 if (ret > 0) 53 goto err;
97 ret = 0;
98 54
99 /* read request, copy returned data to return buf */ 55 /* read request, copy returned data to return buf */
100 if (!ret && requesttype == (USB_TYPE_VENDOR | USB_DIR_IN)) 56 if (requesttype == (USB_TYPE_VENDOR | USB_DIR_IN))
101 memcpy(req->data, buf, req->size); 57 memcpy(req->data, dev->buf, req->size);
102 58
103 kfree(buf); 59 return 0;
104
105 if (ret)
106 goto err;
107
108 return ret;
109err: 60err:
110 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 61 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
111 return ret; 62 return ret;
112} 63}
113 64
114static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) 65static int rtl28xxu_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
115{ 66{
116 struct rtl28xxu_req req; 67 struct rtl28xxu_req req;
117 68
@@ -129,7 +80,7 @@ static int rtl28xx_wr_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
129 return rtl28xxu_ctrl_msg(d, &req); 80 return rtl28xxu_ctrl_msg(d, &req);
130} 81}
131 82
132static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len) 83static int rtl28xxu_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
133{ 84{
134 struct rtl28xxu_req req; 85 struct rtl28xxu_req req;
135 86
@@ -147,17 +98,17 @@ static int rtl2831_rd_regs(struct dvb_usb_device *d, u16 reg, u8 *val, int len)
147 return rtl28xxu_ctrl_msg(d, &req); 98 return rtl28xxu_ctrl_msg(d, &req);
148} 99}
149 100
150static int rtl28xx_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val) 101static int rtl28xxu_wr_reg(struct dvb_usb_device *d, u16 reg, u8 val)
151{ 102{
152 return rtl28xx_wr_regs(d, reg, &val, 1); 103 return rtl28xxu_wr_regs(d, reg, &val, 1);
153} 104}
154 105
155static int rtl28xx_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val) 106static int rtl28xxu_rd_reg(struct dvb_usb_device *d, u16 reg, u8 *val)
156{ 107{
157 return rtl2831_rd_regs(d, reg, val, 1); 108 return rtl28xxu_rd_regs(d, reg, val, 1);
158} 109}
159 110
160static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val, 111static int rtl28xxu_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
161 u8 mask) 112 u8 mask)
162{ 113{
163 int ret; 114 int ret;
@@ -165,7 +116,7 @@ static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
165 116
166 /* no need for read if whole reg is written */ 117 /* no need for read if whole reg is written */
167 if (mask != 0xff) { 118 if (mask != 0xff) {
168 ret = rtl28xx_rd_reg(d, reg, &tmp); 119 ret = rtl28xxu_rd_reg(d, reg, &tmp);
169 if (ret) 120 if (ret)
170 return ret; 121 return ret;
171 122
@@ -174,7 +125,7 @@ static int rtl28xx_wr_reg_mask(struct dvb_usb_device *d, u16 reg, u8 val,
174 val |= tmp; 125 val |= tmp;
175 } 126 }
176 127
177 return rtl28xx_wr_reg(d, reg, val); 128 return rtl28xxu_wr_reg(d, reg, val);
178} 129}
179 130
180/* I2C */ 131/* I2C */
@@ -183,7 +134,7 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
183{ 134{
184 int ret; 135 int ret;
185 struct dvb_usb_device *d = i2c_get_adapdata(adap); 136 struct dvb_usb_device *d = i2c_get_adapdata(adap);
186 struct rtl28xxu_priv *priv = d->priv; 137 struct rtl28xxu_dev *dev = d->priv;
187 struct rtl28xxu_req req; 138 struct rtl28xxu_req req;
188 139
189 /* 140 /*
@@ -220,7 +171,7 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
220 } else if (msg[0].addr == 0x10) { 171 } else if (msg[0].addr == 0x10) {
221 /* method 1 - integrated demod */ 172 /* method 1 - integrated demod */
222 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1); 173 req.value = (msg[0].buf[0] << 8) | (msg[0].addr << 1);
223 req.index = CMD_DEMOD_RD | priv->page; 174 req.index = CMD_DEMOD_RD | dev->page;
224 req.size = msg[1].len; 175 req.size = msg[1].len;
225 req.data = &msg[1].buf[0]; 176 req.data = &msg[1].buf[0];
226 ret = rtl28xxu_ctrl_msg(d, &req); 177 ret = rtl28xxu_ctrl_msg(d, &req);
@@ -256,12 +207,12 @@ static int rtl28xxu_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg msg[],
256 /* method 1 - integrated demod */ 207 /* method 1 - integrated demod */
257 if (msg[0].buf[0] == 0x00) { 208 if (msg[0].buf[0] == 0x00) {
258 /* save demod page for later demod access */ 209 /* save demod page for later demod access */
259 priv->page = msg[0].buf[1]; 210 dev->page = msg[0].buf[1];
260 ret = 0; 211 ret = 0;
261 } else { 212 } else {
262 req.value = (msg[0].buf[0] << 8) | 213 req.value = (msg[0].buf[0] << 8) |
263 (msg[0].addr << 1); 214 (msg[0].addr << 1);
264 req.index = CMD_DEMOD_WR | priv->page; 215 req.index = CMD_DEMOD_WR | dev->page;
265 req.size = msg[0].len-1; 216 req.size = msg[0].len-1;
266 req.data = &msg[0].buf[1]; 217 req.data = &msg[0].buf[1];
267 ret = rtl28xxu_ctrl_msg(d, &req); 218 ret = rtl28xxu_ctrl_msg(d, &req);
@@ -303,7 +254,7 @@ static struct i2c_algorithm rtl28xxu_i2c_algo = {
303 254
304static int rtl2831u_read_config(struct dvb_usb_device *d) 255static int rtl2831u_read_config(struct dvb_usb_device *d)
305{ 256{
306 struct rtl28xxu_priv *priv = d_to_priv(d); 257 struct rtl28xxu_dev *dev = d_to_priv(d);
307 int ret; 258 int ret;
308 u8 buf[1]; 259 u8 buf[1];
309 /* open RTL2831U/RTL2830 I2C gate */ 260 /* open RTL2831U/RTL2830 I2C gate */
@@ -312,7 +263,7 @@ static int rtl2831u_read_config(struct dvb_usb_device *d)
312 struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf}; 263 struct rtl28xxu_req req_mt2060 = {0x00c0, CMD_I2C_RD, 1, buf};
313 struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf}; 264 struct rtl28xxu_req req_qt1010 = {0x0fc4, CMD_I2C_RD, 1, buf};
314 265
315 dev_dbg(&d->udev->dev, "%s:\n", __func__); 266 dev_dbg(&d->intf->dev, "\n");
316 267
317 /* 268 /*
318 * RTL2831U GPIOs 269 * RTL2831U GPIOs
@@ -323,12 +274,12 @@ static int rtl2831u_read_config(struct dvb_usb_device *d)
323 */ 274 */
324 275
325 /* GPIO direction */ 276 /* GPIO direction */
326 ret = rtl28xx_wr_reg(d, SYS_GPIO_DIR, 0x0a); 277 ret = rtl28xxu_wr_reg(d, SYS_GPIO_DIR, 0x0a);
327 if (ret) 278 if (ret)
328 goto err; 279 goto err;
329 280
330 /* enable as output GPIO0, GPIO2, GPIO4 */ 281 /* enable as output GPIO0, GPIO2, GPIO4 */
331 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_EN, 0x15); 282 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_EN, 0x15);
332 if (ret) 283 if (ret)
333 goto err; 284 goto err;
334 285
@@ -340,7 +291,7 @@ static int rtl2831u_read_config(struct dvb_usb_device *d)
340 /* demod needs some time to wake up */ 291 /* demod needs some time to wake up */
341 msleep(20); 292 msleep(20);
342 293
343 priv->tuner_name = "NONE"; 294 dev->tuner_name = "NONE";
344 295
345 /* open demod I2C gate */ 296 /* open demod I2C gate */
346 ret = rtl28xxu_ctrl_msg(d, &req_gate_open); 297 ret = rtl28xxu_ctrl_msg(d, &req_gate_open);
@@ -350,8 +301,8 @@ static int rtl2831u_read_config(struct dvb_usb_device *d)
350 /* check QT1010 ID(?) register; reg=0f val=2c */ 301 /* check QT1010 ID(?) register; reg=0f val=2c */
351 ret = rtl28xxu_ctrl_msg(d, &req_qt1010); 302 ret = rtl28xxu_ctrl_msg(d, &req_qt1010);
352 if (ret == 0 && buf[0] == 0x2c) { 303 if (ret == 0 && buf[0] == 0x2c) {
353 priv->tuner = TUNER_RTL2830_QT1010; 304 dev->tuner = TUNER_RTL2830_QT1010;
354 priv->tuner_name = "QT1010"; 305 dev->tuner_name = "QT1010";
355 goto found; 306 goto found;
356 } 307 }
357 308
@@ -363,28 +314,28 @@ static int rtl2831u_read_config(struct dvb_usb_device *d)
363 /* check MT2060 ID register; reg=00 val=63 */ 314 /* check MT2060 ID register; reg=00 val=63 */
364 ret = rtl28xxu_ctrl_msg(d, &req_mt2060); 315 ret = rtl28xxu_ctrl_msg(d, &req_mt2060);
365 if (ret == 0 && buf[0] == 0x63) { 316 if (ret == 0 && buf[0] == 0x63) {
366 priv->tuner = TUNER_RTL2830_MT2060; 317 dev->tuner = TUNER_RTL2830_MT2060;
367 priv->tuner_name = "MT2060"; 318 dev->tuner_name = "MT2060";
368 goto found; 319 goto found;
369 } 320 }
370 321
371 /* assume MXL5005S */ 322 /* assume MXL5005S */
372 priv->tuner = TUNER_RTL2830_MXL5005S; 323 dev->tuner = TUNER_RTL2830_MXL5005S;
373 priv->tuner_name = "MXL5005S"; 324 dev->tuner_name = "MXL5005S";
374 goto found; 325 goto found;
375 326
376found: 327found:
377 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name); 328 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
378 329
379 return 0; 330 return 0;
380err: 331err:
381 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 332 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
382 return ret; 333 return ret;
383} 334}
384 335
385static int rtl2832u_read_config(struct dvb_usb_device *d) 336static int rtl2832u_read_config(struct dvb_usb_device *d)
386{ 337{
387 struct rtl28xxu_priv *priv = d_to_priv(d); 338 struct rtl28xxu_dev *dev = d_to_priv(d);
388 int ret; 339 int ret;
389 u8 buf[2]; 340 u8 buf[2];
390 /* open RTL2832U/RTL2832 I2C gate */ 341 /* open RTL2832U/RTL2832 I2C gate */
@@ -407,14 +358,14 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
407 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf}; 358 struct rtl28xxu_req req_mn88472 = {0xff38, CMD_I2C_RD, 1, buf};
408 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf}; 359 struct rtl28xxu_req req_mn88473 = {0xff38, CMD_I2C_RD, 1, buf};
409 360
410 dev_dbg(&d->udev->dev, "%s:\n", __func__); 361 dev_dbg(&d->intf->dev, "\n");
411 362
412 /* enable GPIO3 and GPIO6 as output */ 363 /* enable GPIO3 and GPIO6 as output */
413 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40); 364 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x40);
414 if (ret) 365 if (ret)
415 goto err; 366 goto err;
416 367
417 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48); 368 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x48, 0x48);
418 if (ret) 369 if (ret)
419 goto err; 370 goto err;
420 371
@@ -428,134 +379,134 @@ static int rtl2832u_read_config(struct dvb_usb_device *d)
428 if (ret) 379 if (ret)
429 goto err; 380 goto err;
430 381
431 priv->tuner_name = "NONE"; 382 dev->tuner_name = "NONE";
432 383
433 /* check FC0012 ID register; reg=00 val=a1 */ 384 /* check FC0012 ID register; reg=00 val=a1 */
434 ret = rtl28xxu_ctrl_msg(d, &req_fc0012); 385 ret = rtl28xxu_ctrl_msg(d, &req_fc0012);
435 if (ret == 0 && buf[0] == 0xa1) { 386 if (ret == 0 && buf[0] == 0xa1) {
436 priv->tuner = TUNER_RTL2832_FC0012; 387 dev->tuner = TUNER_RTL2832_FC0012;
437 priv->tuner_name = "FC0012"; 388 dev->tuner_name = "FC0012";
438 goto tuner_found; 389 goto tuner_found;
439 } 390 }
440 391
441 /* check FC0013 ID register; reg=00 val=a3 */ 392 /* check FC0013 ID register; reg=00 val=a3 */
442 ret = rtl28xxu_ctrl_msg(d, &req_fc0013); 393 ret = rtl28xxu_ctrl_msg(d, &req_fc0013);
443 if (ret == 0 && buf[0] == 0xa3) { 394 if (ret == 0 && buf[0] == 0xa3) {
444 priv->tuner = TUNER_RTL2832_FC0013; 395 dev->tuner = TUNER_RTL2832_FC0013;
445 priv->tuner_name = "FC0013"; 396 dev->tuner_name = "FC0013";
446 goto tuner_found; 397 goto tuner_found;
447 } 398 }
448 399
449 /* check MT2266 ID register; reg=00 val=85 */ 400 /* check MT2266 ID register; reg=00 val=85 */
450 ret = rtl28xxu_ctrl_msg(d, &req_mt2266); 401 ret = rtl28xxu_ctrl_msg(d, &req_mt2266);
451 if (ret == 0 && buf[0] == 0x85) { 402 if (ret == 0 && buf[0] == 0x85) {
452 priv->tuner = TUNER_RTL2832_MT2266; 403 dev->tuner = TUNER_RTL2832_MT2266;
453 priv->tuner_name = "MT2266"; 404 dev->tuner_name = "MT2266";
454 goto tuner_found; 405 goto tuner_found;
455 } 406 }
456 407
457 /* check FC2580 ID register; reg=01 val=56 */ 408 /* check FC2580 ID register; reg=01 val=56 */
458 ret = rtl28xxu_ctrl_msg(d, &req_fc2580); 409 ret = rtl28xxu_ctrl_msg(d, &req_fc2580);
459 if (ret == 0 && buf[0] == 0x56) { 410 if (ret == 0 && buf[0] == 0x56) {
460 priv->tuner = TUNER_RTL2832_FC2580; 411 dev->tuner = TUNER_RTL2832_FC2580;
461 priv->tuner_name = "FC2580"; 412 dev->tuner_name = "FC2580";
462 goto tuner_found; 413 goto tuner_found;
463 } 414 }
464 415
465 /* check MT2063 ID register; reg=00 val=9e || 9c */ 416 /* check MT2063 ID register; reg=00 val=9e || 9c */
466 ret = rtl28xxu_ctrl_msg(d, &req_mt2063); 417 ret = rtl28xxu_ctrl_msg(d, &req_mt2063);
467 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) { 418 if (ret == 0 && (buf[0] == 0x9e || buf[0] == 0x9c)) {
468 priv->tuner = TUNER_RTL2832_MT2063; 419 dev->tuner = TUNER_RTL2832_MT2063;
469 priv->tuner_name = "MT2063"; 420 dev->tuner_name = "MT2063";
470 goto tuner_found; 421 goto tuner_found;
471 } 422 }
472 423
473 /* check MAX3543 ID register; reg=00 val=38 */ 424 /* check MAX3543 ID register; reg=00 val=38 */
474 ret = rtl28xxu_ctrl_msg(d, &req_max3543); 425 ret = rtl28xxu_ctrl_msg(d, &req_max3543);
475 if (ret == 0 && buf[0] == 0x38) { 426 if (ret == 0 && buf[0] == 0x38) {
476 priv->tuner = TUNER_RTL2832_MAX3543; 427 dev->tuner = TUNER_RTL2832_MAX3543;
477 priv->tuner_name = "MAX3543"; 428 dev->tuner_name = "MAX3543";
478 goto tuner_found; 429 goto tuner_found;
479 } 430 }
480 431
481 /* check TUA9001 ID register; reg=7e val=2328 */ 432 /* check TUA9001 ID register; reg=7e val=2328 */
482 ret = rtl28xxu_ctrl_msg(d, &req_tua9001); 433 ret = rtl28xxu_ctrl_msg(d, &req_tua9001);
483 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) { 434 if (ret == 0 && buf[0] == 0x23 && buf[1] == 0x28) {
484 priv->tuner = TUNER_RTL2832_TUA9001; 435 dev->tuner = TUNER_RTL2832_TUA9001;
485 priv->tuner_name = "TUA9001"; 436 dev->tuner_name = "TUA9001";
486 goto tuner_found; 437 goto tuner_found;
487 } 438 }
488 439
489 /* check MXL5007R ID register; reg=d9 val=14 */ 440 /* check MXL5007R ID register; reg=d9 val=14 */
490 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t); 441 ret = rtl28xxu_ctrl_msg(d, &req_mxl5007t);
491 if (ret == 0 && buf[0] == 0x14) { 442 if (ret == 0 && buf[0] == 0x14) {
492 priv->tuner = TUNER_RTL2832_MXL5007T; 443 dev->tuner = TUNER_RTL2832_MXL5007T;
493 priv->tuner_name = "MXL5007T"; 444 dev->tuner_name = "MXL5007T";
494 goto tuner_found; 445 goto tuner_found;
495 } 446 }
496 447
497 /* check E4000 ID register; reg=02 val=40 */ 448 /* check E4000 ID register; reg=02 val=40 */
498 ret = rtl28xxu_ctrl_msg(d, &req_e4000); 449 ret = rtl28xxu_ctrl_msg(d, &req_e4000);
499 if (ret == 0 && buf[0] == 0x40) { 450 if (ret == 0 && buf[0] == 0x40) {
500 priv->tuner = TUNER_RTL2832_E4000; 451 dev->tuner = TUNER_RTL2832_E4000;
501 priv->tuner_name = "E4000"; 452 dev->tuner_name = "E4000";
502 goto tuner_found; 453 goto tuner_found;
503 } 454 }
504 455
505 /* check TDA18272 ID register; reg=00 val=c760 */ 456 /* check TDA18272 ID register; reg=00 val=c760 */
506 ret = rtl28xxu_ctrl_msg(d, &req_tda18272); 457 ret = rtl28xxu_ctrl_msg(d, &req_tda18272);
507 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) { 458 if (ret == 0 && (buf[0] == 0xc7 || buf[1] == 0x60)) {
508 priv->tuner = TUNER_RTL2832_TDA18272; 459 dev->tuner = TUNER_RTL2832_TDA18272;
509 priv->tuner_name = "TDA18272"; 460 dev->tuner_name = "TDA18272";
510 goto tuner_found; 461 goto tuner_found;
511 } 462 }
512 463
513 /* check R820T ID register; reg=00 val=69 */ 464 /* check R820T ID register; reg=00 val=69 */
514 ret = rtl28xxu_ctrl_msg(d, &req_r820t); 465 ret = rtl28xxu_ctrl_msg(d, &req_r820t);
515 if (ret == 0 && buf[0] == 0x69) { 466 if (ret == 0 && buf[0] == 0x69) {
516 priv->tuner = TUNER_RTL2832_R820T; 467 dev->tuner = TUNER_RTL2832_R820T;
517 priv->tuner_name = "R820T"; 468 dev->tuner_name = "R820T";
518 goto tuner_found; 469 goto tuner_found;
519 } 470 }
520 471
521 /* check R828D ID register; reg=00 val=69 */ 472 /* check R828D ID register; reg=00 val=69 */
522 ret = rtl28xxu_ctrl_msg(d, &req_r828d); 473 ret = rtl28xxu_ctrl_msg(d, &req_r828d);
523 if (ret == 0 && buf[0] == 0x69) { 474 if (ret == 0 && buf[0] == 0x69) {
524 priv->tuner = TUNER_RTL2832_R828D; 475 dev->tuner = TUNER_RTL2832_R828D;
525 priv->tuner_name = "R828D"; 476 dev->tuner_name = "R828D";
526 goto tuner_found; 477 goto tuner_found;
527 } 478 }
528 479
529tuner_found: 480tuner_found:
530 dev_dbg(&d->udev->dev, "%s: tuner=%s\n", __func__, priv->tuner_name); 481 dev_dbg(&d->intf->dev, "tuner=%s\n", dev->tuner_name);
531 482
532 /* probe slave demod */ 483 /* probe slave demod */
533 if (priv->tuner == TUNER_RTL2832_R828D) { 484 if (dev->tuner == TUNER_RTL2832_R828D) {
534 /* power on MN88472 demod on GPIO0 */ 485 /* power on MN88472 demod on GPIO0 */
535 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01); 486 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x01, 0x01);
536 if (ret) 487 if (ret)
537 goto err; 488 goto err;
538 489
539 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01); 490 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x01);
540 if (ret) 491 if (ret)
541 goto err; 492 goto err;
542 493
543 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01); 494 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x01, 0x01);
544 if (ret) 495 if (ret)
545 goto err; 496 goto err;
546 497
547 /* check MN88472 answers */ 498 /* check MN88472 answers */
548 ret = rtl28xxu_ctrl_msg(d, &req_mn88472); 499 ret = rtl28xxu_ctrl_msg(d, &req_mn88472);
549 if (ret == 0 && buf[0] == 0x02) { 500 if (ret == 0 && buf[0] == 0x02) {
550 dev_dbg(&d->udev->dev, "%s: MN88472 found\n", __func__); 501 dev_dbg(&d->intf->dev, "MN88472 found\n");
551 priv->slave_demod = SLAVE_DEMOD_MN88472; 502 dev->slave_demod = SLAVE_DEMOD_MN88472;
552 goto demod_found; 503 goto demod_found;
553 } 504 }
554 505
555 ret = rtl28xxu_ctrl_msg(d, &req_mn88473); 506 ret = rtl28xxu_ctrl_msg(d, &req_mn88473);
556 if (ret == 0 && buf[0] == 0x03) { 507 if (ret == 0 && buf[0] == 0x03) {
557 dev_dbg(&d->udev->dev, "%s: MN88473 found\n", __func__); 508 dev_dbg(&d->intf->dev, "MN88473 found\n");
558 priv->slave_demod = SLAVE_DEMOD_MN88473; 509 dev->slave_demod = SLAVE_DEMOD_MN88473;
559 goto demod_found; 510 goto demod_found;
560 } 511 }
561 } 512 }
@@ -568,14 +519,51 @@ demod_found:
568 519
569 return 0; 520 return 0;
570err: 521err:
571 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 522 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
572 return ret; 523 return ret;
573} 524}
574 525
575static const struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = { 526static int rtl28xxu_read_config(struct dvb_usb_device *d)
576 .i2c_addr = 0x10, /* 0x20 */ 527{
577 .xtal = 28800000, 528 struct rtl28xxu_dev *dev = d_to_priv(d);
578 .ts_mode = 0, 529
530 if (dev->chip_id == CHIP_ID_RTL2831U)
531 return rtl2831u_read_config(d);
532 else
533 return rtl2832u_read_config(d);
534}
535
536static int rtl28xxu_identify_state(struct dvb_usb_device *d, const char **name)
537{
538 struct rtl28xxu_dev *dev = d_to_priv(d);
539 int ret;
540 struct rtl28xxu_req req_demod_i2c = {0x0020, CMD_I2C_DA_RD, 0, NULL};
541
542 dev_dbg(&d->intf->dev, "\n");
543
544 /*
545 * Detect chip type using I2C command that is not supported
546 * by old RTL2831U.
547 */
548 ret = rtl28xxu_ctrl_msg(d, &req_demod_i2c);
549 if (ret == -EPIPE) {
550 dev->chip_id = CHIP_ID_RTL2831U;
551 } else if (ret == 0) {
552 dev->chip_id = CHIP_ID_RTL2832U;
553 } else {
554 dev_err(&d->intf->dev, "chip type detection failed %d\n", ret);
555 goto err;
556 }
557 dev_dbg(&d->intf->dev, "chip_id=%u\n", dev->chip_id);
558
559 return WARM;
560err:
561 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
562 return ret;
563}
564
565static const struct rtl2830_platform_data rtl2830_mt2060_platform_data = {
566 .clk = 28800000,
579 .spec_inv = 1, 567 .spec_inv = 1,
580 .vtop = 0x20, 568 .vtop = 0x20,
581 .krf = 0x04, 569 .krf = 0x04,
@@ -583,20 +571,16 @@ static const struct rtl2830_config rtl28xxu_rtl2830_mt2060_config = {
583 571
584}; 572};
585 573
586static const struct rtl2830_config rtl28xxu_rtl2830_qt1010_config = { 574static const struct rtl2830_platform_data rtl2830_qt1010_platform_data = {
587 .i2c_addr = 0x10, /* 0x20 */ 575 .clk = 28800000,
588 .xtal = 28800000,
589 .ts_mode = 0,
590 .spec_inv = 1, 576 .spec_inv = 1,
591 .vtop = 0x20, 577 .vtop = 0x20,
592 .krf = 0x04, 578 .krf = 0x04,
593 .agc_targ_val = 0x2d, 579 .agc_targ_val = 0x2d,
594}; 580};
595 581
596static const struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = { 582static const struct rtl2830_platform_data rtl2830_mxl5005s_platform_data = {
597 .i2c_addr = 0x10, /* 0x20 */ 583 .clk = 28800000,
598 .xtal = 28800000,
599 .ts_mode = 0,
600 .spec_inv = 0, 584 .spec_inv = 0,
601 .vtop = 0x3f, 585 .vtop = 0x3f,
602 .krf = 0x04, 586 .krf = 0x04,
@@ -606,69 +590,81 @@ static const struct rtl2830_config rtl28xxu_rtl2830_mxl5005s_config = {
606static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap) 590static int rtl2831u_frontend_attach(struct dvb_usb_adapter *adap)
607{ 591{
608 struct dvb_usb_device *d = adap_to_d(adap); 592 struct dvb_usb_device *d = adap_to_d(adap);
609 struct rtl28xxu_priv *priv = d_to_priv(d); 593 struct rtl28xxu_dev *dev = d_to_priv(d);
610 const struct rtl2830_config *rtl2830_config; 594 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
595 struct i2c_board_info board_info;
596 struct i2c_client *client;
611 int ret; 597 int ret;
612 598
613 dev_dbg(&d->udev->dev, "%s:\n", __func__); 599 dev_dbg(&d->intf->dev, "\n");
614 600
615 switch (priv->tuner) { 601 switch (dev->tuner) {
616 case TUNER_RTL2830_QT1010: 602 case TUNER_RTL2830_QT1010:
617 rtl2830_config = &rtl28xxu_rtl2830_qt1010_config; 603 *pdata = rtl2830_qt1010_platform_data;
618 break; 604 break;
619 case TUNER_RTL2830_MT2060: 605 case TUNER_RTL2830_MT2060:
620 rtl2830_config = &rtl28xxu_rtl2830_mt2060_config; 606 *pdata = rtl2830_mt2060_platform_data;
621 break; 607 break;
622 case TUNER_RTL2830_MXL5005S: 608 case TUNER_RTL2830_MXL5005S:
623 rtl2830_config = &rtl28xxu_rtl2830_mxl5005s_config; 609 *pdata = rtl2830_mxl5005s_platform_data;
624 break; 610 break;
625 default: 611 default:
626 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n", 612 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
627 KBUILD_MODNAME, priv->tuner_name);
628 ret = -ENODEV; 613 ret = -ENODEV;
629 goto err; 614 goto err;
630 } 615 }
631 616
632 /* attach demodulator */ 617 /* attach demodulator */
633 adap->fe[0] = dvb_attach(rtl2830_attach, rtl2830_config, &d->i2c_adap); 618 memset(&board_info, 0, sizeof(board_info));
634 if (!adap->fe[0]) { 619 strlcpy(board_info.type, "rtl2830", I2C_NAME_SIZE);
620 board_info.addr = 0x10;
621 board_info.platform_data = pdata;
622 request_module("%s", board_info.type);
623 client = i2c_new_device(&d->i2c_adap, &board_info);
624 if (client == NULL || client->dev.driver == NULL) {
625 ret = -ENODEV;
626 goto err;
627 }
628
629 if (!try_module_get(client->dev.driver->owner)) {
630 i2c_unregister_device(client);
635 ret = -ENODEV; 631 ret = -ENODEV;
636 goto err; 632 goto err;
637 } 633 }
638 634
635 adap->fe[0] = pdata->get_dvb_frontend(client);
636 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
637
638 dev->i2c_client_demod = client;
639
639 return 0; 640 return 0;
640err: 641err:
641 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 642 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
642 return ret; 643 return ret;
643} 644}
644 645
645static const struct rtl2832_config rtl28xxu_rtl2832_fc0012_config = { 646static const struct rtl2832_platform_data rtl2832_fc0012_platform_data = {
646 .i2c_addr = 0x10, /* 0x20 */ 647 .clk = 28800000,
647 .xtal = 28800000,
648 .tuner = TUNER_RTL2832_FC0012 648 .tuner = TUNER_RTL2832_FC0012
649}; 649};
650 650
651static const struct rtl2832_config rtl28xxu_rtl2832_fc0013_config = { 651static const struct rtl2832_platform_data rtl2832_fc0013_platform_data = {
652 .i2c_addr = 0x10, /* 0x20 */ 652 .clk = 28800000,
653 .xtal = 28800000,
654 .tuner = TUNER_RTL2832_FC0013 653 .tuner = TUNER_RTL2832_FC0013
655}; 654};
656 655
657static const struct rtl2832_config rtl28xxu_rtl2832_tua9001_config = { 656static const struct rtl2832_platform_data rtl2832_tua9001_platform_data = {
658 .i2c_addr = 0x10, /* 0x20 */ 657 .clk = 28800000,
659 .xtal = 28800000,
660 .tuner = TUNER_RTL2832_TUA9001, 658 .tuner = TUNER_RTL2832_TUA9001,
661}; 659};
662 660
663static const struct rtl2832_config rtl28xxu_rtl2832_e4000_config = { 661static const struct rtl2832_platform_data rtl2832_e4000_platform_data = {
664 .i2c_addr = 0x10, /* 0x20 */ 662 .clk = 28800000,
665 .xtal = 28800000,
666 .tuner = TUNER_RTL2832_E4000, 663 .tuner = TUNER_RTL2832_E4000,
667}; 664};
668 665
669static const struct rtl2832_config rtl28xxu_rtl2832_r820t_config = { 666static const struct rtl2832_platform_data rtl2832_r820t_platform_data = {
670 .i2c_addr = 0x10, 667 .clk = 28800000,
671 .xtal = 28800000,
672 .tuner = TUNER_RTL2832_R820T, 668 .tuner = TUNER_RTL2832_R820T,
673}; 669};
674 670
@@ -678,12 +674,12 @@ static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
678 int ret; 674 int ret;
679 u8 val; 675 u8 val;
680 676
681 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); 677 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
682 678
683 switch (cmd) { 679 switch (cmd) {
684 case FC_FE_CALLBACK_VHF_ENABLE: 680 case FC_FE_CALLBACK_VHF_ENABLE:
685 /* set output values */ 681 /* set output values */
686 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &val); 682 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &val);
687 if (ret) 683 if (ret)
688 goto err; 684 goto err;
689 685
@@ -693,7 +689,7 @@ static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
693 val |= 0x40; /* set GPIO6 high */ 689 val |= 0x40; /* set GPIO6 high */
694 690
695 691
696 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, val); 692 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, val);
697 if (ret) 693 if (ret)
698 goto err; 694 goto err;
699 break; 695 break;
@@ -703,7 +699,7 @@ static int rtl2832u_fc0012_tuner_callback(struct dvb_usb_device *d,
703 } 699 }
704 return 0; 700 return 0;
705err: 701err:
706 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 702 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
707 return ret; 703 return ret;
708} 704}
709 705
@@ -713,7 +709,7 @@ static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
713 int ret; 709 int ret;
714 u8 val; 710 u8 val;
715 711
716 dev_dbg(&d->udev->dev, "%s: cmd=%d arg=%d\n", __func__, cmd, arg); 712 dev_dbg(&d->intf->dev, "cmd=%d arg=%d\n", cmd, arg);
717 713
718 /* 714 /*
719 * CEN always enabled by hardware wiring 715 * CEN always enabled by hardware wiring
@@ -728,7 +724,7 @@ static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
728 else 724 else
729 val = (0 << 4); 725 val = (0 << 4);
730 726
731 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10); 727 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x10);
732 if (ret) 728 if (ret)
733 goto err; 729 goto err;
734 break; 730 break;
@@ -738,7 +734,7 @@ static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
738 else 734 else
739 val = (0 << 1); 735 val = (0 << 1);
740 736
741 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02); 737 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, val, 0x02);
742 if (ret) 738 if (ret)
743 goto err; 739 goto err;
744 break; 740 break;
@@ -746,40 +742,46 @@ static int rtl2832u_tua9001_tuner_callback(struct dvb_usb_device *d,
746 742
747 return 0; 743 return 0;
748err: 744err:
749 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 745 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
750 return ret; 746 return ret;
751} 747}
752 748
753static int rtl2832u_tuner_callback(struct dvb_usb_device *d, int cmd, int arg)
754{
755 struct rtl28xxu_priv *priv = d->priv;
756
757 switch (priv->tuner) {
758 case TUNER_RTL2832_FC0012:
759 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
760 case TUNER_RTL2832_TUA9001:
761 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
762 default:
763 break;
764 }
765
766 return 0;
767}
768
769static int rtl2832u_frontend_callback(void *adapter_priv, int component, 749static int rtl2832u_frontend_callback(void *adapter_priv, int component,
770 int cmd, int arg) 750 int cmd, int arg)
771{ 751{
772 struct i2c_adapter *adap = adapter_priv; 752 struct i2c_adapter *adapter = adapter_priv;
773 struct dvb_usb_device *d = i2c_get_adapdata(adap); 753 struct device *parent = adapter->dev.parent;
754 struct i2c_adapter *parent_adapter;
755 struct dvb_usb_device *d;
756 struct rtl28xxu_dev *dev;
757
758 /*
759 * All tuners are connected to demod muxed I2C adapter. We have to
760 * resolve its parent adapter in order to get handle for this driver
761 * private data. That is a bit hackish solution, GPIO or direct driver
762 * callback would be better...
763 */
764 if (parent != NULL && parent->type == &i2c_adapter_type)
765 parent_adapter = to_i2c_adapter(parent);
766 else
767 return -EINVAL;
768
769 d = i2c_get_adapdata(parent_adapter);
770 dev = d->priv;
774 771
775 dev_dbg(&d->udev->dev, "%s: component=%d cmd=%d arg=%d\n", 772 dev_dbg(&d->intf->dev, "component=%d cmd=%d arg=%d\n",
776 __func__, component, cmd, arg); 773 component, cmd, arg);
777 774
778 switch (component) { 775 switch (component) {
779 case DVB_FRONTEND_COMPONENT_TUNER: 776 case DVB_FRONTEND_COMPONENT_TUNER:
780 return rtl2832u_tuner_callback(d, cmd, arg); 777 switch (dev->tuner) {
778 case TUNER_RTL2832_FC0012:
779 return rtl2832u_fc0012_tuner_callback(d, cmd, arg);
780 case TUNER_RTL2832_TUA9001:
781 return rtl2832u_tua9001_tuner_callback(d, cmd, arg);
782 }
781 default: 783 default:
782 break; 784 return -EINVAL;
783 } 785 }
784 786
785 return 0; 787 return 0;
@@ -787,57 +789,70 @@ static int rtl2832u_frontend_callback(void *adapter_priv, int component,
787 789
788static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap) 790static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
789{ 791{
790 int ret;
791 struct dvb_usb_device *d = adap_to_d(adap); 792 struct dvb_usb_device *d = adap_to_d(adap);
792 struct rtl28xxu_priv *priv = d_to_priv(d); 793 struct rtl28xxu_dev *dev = d_to_priv(d);
793 const struct rtl2832_config *rtl2832_config; 794 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
795 struct i2c_board_info board_info;
796 struct i2c_client *client;
797 int ret;
794 798
795 dev_dbg(&d->udev->dev, "%s:\n", __func__); 799 dev_dbg(&d->intf->dev, "\n");
796 800
797 switch (priv->tuner) { 801 switch (dev->tuner) {
798 case TUNER_RTL2832_FC0012: 802 case TUNER_RTL2832_FC0012:
799 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; 803 *pdata = rtl2832_fc0012_platform_data;
800 break; 804 break;
801 case TUNER_RTL2832_FC0013: 805 case TUNER_RTL2832_FC0013:
802 rtl2832_config = &rtl28xxu_rtl2832_fc0013_config; 806 *pdata = rtl2832_fc0013_platform_data;
803 break; 807 break;
804 case TUNER_RTL2832_FC2580: 808 case TUNER_RTL2832_FC2580:
805 /* FIXME: do not abuse fc0012 settings */ 809 /* FIXME: do not abuse fc0012 settings */
806 rtl2832_config = &rtl28xxu_rtl2832_fc0012_config; 810 *pdata = rtl2832_fc0012_platform_data;
807 break; 811 break;
808 case TUNER_RTL2832_TUA9001: 812 case TUNER_RTL2832_TUA9001:
809 rtl2832_config = &rtl28xxu_rtl2832_tua9001_config; 813 *pdata = rtl2832_tua9001_platform_data;
810 break; 814 break;
811 case TUNER_RTL2832_E4000: 815 case TUNER_RTL2832_E4000:
812 rtl2832_config = &rtl28xxu_rtl2832_e4000_config; 816 *pdata = rtl2832_e4000_platform_data;
813 break; 817 break;
814 case TUNER_RTL2832_R820T: 818 case TUNER_RTL2832_R820T:
815 case TUNER_RTL2832_R828D: 819 case TUNER_RTL2832_R828D:
816 rtl2832_config = &rtl28xxu_rtl2832_r820t_config; 820 *pdata = rtl2832_r820t_platform_data;
817 break; 821 break;
818 default: 822 default:
819 dev_err(&d->udev->dev, "%s: unknown tuner=%s\n", 823 dev_err(&d->intf->dev, "unknown tuner %s\n", dev->tuner_name);
820 KBUILD_MODNAME, priv->tuner_name);
821 ret = -ENODEV; 824 ret = -ENODEV;
822 goto err; 825 goto err;
823 } 826 }
824 827
825 /* attach demodulator */ 828 /* attach demodulator */
826 adap->fe[0] = dvb_attach(rtl2832_attach, rtl2832_config, &d->i2c_adap); 829 memset(&board_info, 0, sizeof(board_info));
827 if (!adap->fe[0]) { 830 strlcpy(board_info.type, "rtl2832", I2C_NAME_SIZE);
831 board_info.addr = 0x10;
832 board_info.platform_data = pdata;
833 request_module("%s", board_info.type);
834 client = i2c_new_device(&d->i2c_adap, &board_info);
835 if (client == NULL || client->dev.driver == NULL) {
828 ret = -ENODEV; 836 ret = -ENODEV;
829 goto err; 837 goto err;
830 } 838 }
831 839
832 /* RTL2832 I2C repeater */ 840 if (!try_module_get(client->dev.driver->owner)) {
833 priv->demod_i2c_adapter = rtl2832_get_i2c_adapter(adap->fe[0]); 841 i2c_unregister_device(client);
842 ret = -ENODEV;
843 goto err;
844 }
845
846 adap->fe[0] = pdata->get_dvb_frontend(client);
847 dev->demod_i2c_adapter = pdata->get_i2c_adapter(client);
848
849 dev->i2c_client_demod = client;
834 850
835 /* set fe callback */ 851 /* set fe callback */
836 adap->fe[0]->callback = rtl2832u_frontend_callback; 852 adap->fe[0]->callback = rtl2832u_frontend_callback;
837 853
838 if (priv->slave_demod) { 854 if (dev->slave_demod) {
839 struct i2c_board_info info = {}; 855 struct i2c_board_info info = {};
840 struct i2c_client *client;
841 856
842 /* 857 /*
843 * We continue on reduced mode, without DVB-T2/C, using master 858 * We continue on reduced mode, without DVB-T2/C, using master
@@ -846,28 +861,29 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
846 ret = 0; 861 ret = 0;
847 862
848 /* attach slave demodulator */ 863 /* attach slave demodulator */
849 if (priv->slave_demod == SLAVE_DEMOD_MN88472) { 864 if (dev->slave_demod == SLAVE_DEMOD_MN88472) {
850 struct mn88472_config mn88472_config = {}; 865 struct mn88472_config mn88472_config = {};
851 866
852 mn88472_config.fe = &adap->fe[1]; 867 mn88472_config.fe = &adap->fe[1];
853 mn88472_config.i2c_wr_max = 22, 868 mn88472_config.i2c_wr_max = 22,
854 strlcpy(info.type, "mn88472", I2C_NAME_SIZE); 869 strlcpy(info.type, "mn88472", I2C_NAME_SIZE);
870 mn88472_config.xtal = 20500000;
855 info.addr = 0x18; 871 info.addr = 0x18;
856 info.platform_data = &mn88472_config; 872 info.platform_data = &mn88472_config;
857 request_module(info.type); 873 request_module(info.type);
858 client = i2c_new_device(priv->demod_i2c_adapter, &info); 874 client = i2c_new_device(&d->i2c_adap, &info);
859 if (client == NULL || client->dev.driver == NULL) { 875 if (client == NULL || client->dev.driver == NULL) {
860 priv->slave_demod = SLAVE_DEMOD_NONE; 876 dev->slave_demod = SLAVE_DEMOD_NONE;
861 goto err_slave_demod_failed; 877 goto err_slave_demod_failed;
862 } 878 }
863 879
864 if (!try_module_get(client->dev.driver->owner)) { 880 if (!try_module_get(client->dev.driver->owner)) {
865 i2c_unregister_device(client); 881 i2c_unregister_device(client);
866 priv->slave_demod = SLAVE_DEMOD_NONE; 882 dev->slave_demod = SLAVE_DEMOD_NONE;
867 goto err_slave_demod_failed; 883 goto err_slave_demod_failed;
868 } 884 }
869 885
870 priv->i2c_client_slave_demod = client; 886 dev->i2c_client_slave_demod = client;
871 } else { 887 } else {
872 struct mn88473_config mn88473_config = {}; 888 struct mn88473_config mn88473_config = {};
873 889
@@ -877,29 +893,64 @@ static int rtl2832u_frontend_attach(struct dvb_usb_adapter *adap)
877 info.addr = 0x18; 893 info.addr = 0x18;
878 info.platform_data = &mn88473_config; 894 info.platform_data = &mn88473_config;
879 request_module(info.type); 895 request_module(info.type);
880 client = i2c_new_device(priv->demod_i2c_adapter, &info); 896 client = i2c_new_device(&d->i2c_adap, &info);
881 if (client == NULL || client->dev.driver == NULL) { 897 if (client == NULL || client->dev.driver == NULL) {
882 priv->slave_demod = SLAVE_DEMOD_NONE; 898 dev->slave_demod = SLAVE_DEMOD_NONE;
883 goto err_slave_demod_failed; 899 goto err_slave_demod_failed;
884 } 900 }
885 901
886 if (!try_module_get(client->dev.driver->owner)) { 902 if (!try_module_get(client->dev.driver->owner)) {
887 i2c_unregister_device(client); 903 i2c_unregister_device(client);
888 priv->slave_demod = SLAVE_DEMOD_NONE; 904 dev->slave_demod = SLAVE_DEMOD_NONE;
889 goto err_slave_demod_failed; 905 goto err_slave_demod_failed;
890 } 906 }
891 907
892 priv->i2c_client_slave_demod = client; 908 dev->i2c_client_slave_demod = client;
893 } 909 }
894 } 910 }
895 911
896 return 0; 912 return 0;
897err_slave_demod_failed: 913err_slave_demod_failed:
898err: 914err:
899 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 915 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
900 return ret; 916 return ret;
901} 917}
902 918
919static int rtl28xxu_frontend_attach(struct dvb_usb_adapter *adap)
920{
921 struct rtl28xxu_dev *dev = adap_to_priv(adap);
922
923 if (dev->chip_id == CHIP_ID_RTL2831U)
924 return rtl2831u_frontend_attach(adap);
925 else
926 return rtl2832u_frontend_attach(adap);
927}
928
929static int rtl28xxu_frontend_detach(struct dvb_usb_adapter *adap)
930{
931 struct dvb_usb_device *d = adap_to_d(adap);
932 struct rtl28xxu_dev *dev = d_to_priv(d);
933 struct i2c_client *client;
934
935 dev_dbg(&d->intf->dev, "\n");
936
937 /* remove I2C slave demod */
938 client = dev->i2c_client_slave_demod;
939 if (client) {
940 module_put(client->dev.driver->owner);
941 i2c_unregister_device(client);
942 }
943
944 /* remove I2C demod */
945 client = dev->i2c_client_demod;
946 if (client) {
947 module_put(client->dev.driver->owner);
948 i2c_unregister_device(client);
949 }
950
951 return 0;
952}
953
903static struct qt1010_config rtl28xxu_qt1010_config = { 954static struct qt1010_config rtl28xxu_qt1010_config = {
904 .i2c_address = 0x62, /* 0xc4 */ 955 .i2c_address = 0x62, /* 0xc4 */
905}; 956};
@@ -930,33 +981,30 @@ static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
930{ 981{
931 int ret; 982 int ret;
932 struct dvb_usb_device *d = adap_to_d(adap); 983 struct dvb_usb_device *d = adap_to_d(adap);
933 struct rtl28xxu_priv *priv = d_to_priv(d); 984 struct rtl28xxu_dev *dev = d_to_priv(d);
934 struct i2c_adapter *rtl2830_tuner_i2c;
935 struct dvb_frontend *fe; 985 struct dvb_frontend *fe;
936 986
937 dev_dbg(&d->udev->dev, "%s:\n", __func__); 987 dev_dbg(&d->intf->dev, "\n");
938
939 /* use rtl2830 driver I2C adapter, for more info see rtl2830 driver */
940 rtl2830_tuner_i2c = rtl2830_get_tuner_i2c_adapter(adap->fe[0]);
941 988
942 switch (priv->tuner) { 989 switch (dev->tuner) {
943 case TUNER_RTL2830_QT1010: 990 case TUNER_RTL2830_QT1010:
944 fe = dvb_attach(qt1010_attach, adap->fe[0], 991 fe = dvb_attach(qt1010_attach, adap->fe[0],
945 rtl2830_tuner_i2c, &rtl28xxu_qt1010_config); 992 dev->demod_i2c_adapter,
993 &rtl28xxu_qt1010_config);
946 break; 994 break;
947 case TUNER_RTL2830_MT2060: 995 case TUNER_RTL2830_MT2060:
948 fe = dvb_attach(mt2060_attach, adap->fe[0], 996 fe = dvb_attach(mt2060_attach, adap->fe[0],
949 rtl2830_tuner_i2c, &rtl28xxu_mt2060_config, 997 dev->demod_i2c_adapter,
950 1220); 998 &rtl28xxu_mt2060_config, 1220);
951 break; 999 break;
952 case TUNER_RTL2830_MXL5005S: 1000 case TUNER_RTL2830_MXL5005S:
953 fe = dvb_attach(mxl5005s_attach, adap->fe[0], 1001 fe = dvb_attach(mxl5005s_attach, adap->fe[0],
954 rtl2830_tuner_i2c, &rtl28xxu_mxl5005s_config); 1002 dev->demod_i2c_adapter,
1003 &rtl28xxu_mxl5005s_config);
955 break; 1004 break;
956 default: 1005 default:
957 fe = NULL; 1006 fe = NULL;
958 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, 1007 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
959 priv->tuner);
960 } 1008 }
961 1009
962 if (fe == NULL) { 1010 if (fe == NULL) {
@@ -966,7 +1014,7 @@ static int rtl2831u_tuner_attach(struct dvb_usb_adapter *adap)
966 1014
967 return 0; 1015 return 0;
968err: 1016err:
969 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1017 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
970 return ret; 1018 return ret;
971} 1019}
972 1020
@@ -1002,45 +1050,38 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1002{ 1050{
1003 int ret; 1051 int ret;
1004 struct dvb_usb_device *d = adap_to_d(adap); 1052 struct dvb_usb_device *d = adap_to_d(adap);
1005 struct rtl28xxu_priv *priv = d_to_priv(d); 1053 struct rtl28xxu_dev *dev = d_to_priv(d);
1006 struct dvb_frontend *fe = NULL; 1054 struct dvb_frontend *fe = NULL;
1007 struct i2c_board_info info; 1055 struct i2c_board_info info;
1008 struct i2c_client *client; 1056 struct i2c_client *client;
1057 struct v4l2_subdev *subdev = NULL;
1058 struct platform_device *pdev;
1059 struct rtl2832_sdr_platform_data pdata;
1009 1060
1010 dev_dbg(&d->udev->dev, "%s:\n", __func__); 1061 dev_dbg(&d->intf->dev, "\n");
1011 1062
1012 memset(&info, 0, sizeof(struct i2c_board_info)); 1063 memset(&info, 0, sizeof(struct i2c_board_info));
1064 memset(&pdata, 0, sizeof(pdata));
1013 1065
1014 switch (priv->tuner) { 1066 switch (dev->tuner) {
1015 case TUNER_RTL2832_FC0012: 1067 case TUNER_RTL2832_FC0012:
1016 fe = dvb_attach(fc0012_attach, adap->fe[0], 1068 fe = dvb_attach(fc0012_attach, adap->fe[0],
1017 &d->i2c_adap, &rtl2832u_fc0012_config); 1069 dev->demod_i2c_adapter, &rtl2832u_fc0012_config);
1018 1070
1019 /* since fc0012 includs reading the signal strength delegate 1071 /* since fc0012 includs reading the signal strength delegate
1020 * that to the tuner driver */ 1072 * that to the tuner driver */
1021 adap->fe[0]->ops.read_signal_strength = 1073 adap->fe[0]->ops.read_signal_strength =
1022 adap->fe[0]->ops.tuner_ops.get_rf_strength; 1074 adap->fe[0]->ops.tuner_ops.get_rf_strength;
1023
1024 /* attach SDR */
1025 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
1026 &rtl28xxu_rtl2832_fc0012_config, NULL);
1027 break; 1075 break;
1028 case TUNER_RTL2832_FC0013: 1076 case TUNER_RTL2832_FC0013:
1029 fe = dvb_attach(fc0013_attach, adap->fe[0], 1077 fe = dvb_attach(fc0013_attach, adap->fe[0],
1030 &d->i2c_adap, 0xc6>>1, 0, FC_XTAL_28_8_MHZ); 1078 dev->demod_i2c_adapter, 0xc6>>1, 0, FC_XTAL_28_8_MHZ);
1031 1079
1032 /* fc0013 also supports signal strength reading */ 1080 /* fc0013 also supports signal strength reading */
1033 adap->fe[0]->ops.read_signal_strength = 1081 adap->fe[0]->ops.read_signal_strength =
1034 adap->fe[0]->ops.tuner_ops.get_rf_strength; 1082 adap->fe[0]->ops.tuner_ops.get_rf_strength;
1035
1036 /* attach SDR */
1037 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
1038 &rtl28xxu_rtl2832_fc0013_config, NULL);
1039 break; 1083 break;
1040 case TUNER_RTL2832_E4000: { 1084 case TUNER_RTL2832_E4000: {
1041 struct v4l2_subdev *sd;
1042 struct i2c_adapter *i2c_adap_internal =
1043 rtl2832_get_private_i2c_adapter(adap->fe[0]);
1044 struct e4000_config e4000_config = { 1085 struct e4000_config e4000_config = {
1045 .fe = adap->fe[0], 1086 .fe = adap->fe[0],
1046 .clock = 28800000, 1087 .clock = 28800000,
@@ -1051,7 +1092,7 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1051 info.platform_data = &e4000_config; 1092 info.platform_data = &e4000_config;
1052 1093
1053 request_module(info.type); 1094 request_module(info.type);
1054 client = i2c_new_device(priv->demod_i2c_adapter, &info); 1095 client = i2c_new_device(dev->demod_i2c_adapter, &info);
1055 if (client == NULL || client->dev.driver == NULL) 1096 if (client == NULL || client->dev.driver == NULL)
1056 break; 1097 break;
1057 1098
@@ -1060,157 +1101,183 @@ static int rtl2832u_tuner_attach(struct dvb_usb_adapter *adap)
1060 break; 1101 break;
1061 } 1102 }
1062 1103
1063 priv->i2c_client_tuner = client; 1104 dev->i2c_client_tuner = client;
1064 sd = i2c_get_clientdata(client); 1105 subdev = i2c_get_clientdata(client);
1065 i2c_set_adapdata(i2c_adap_internal, d);
1066
1067 /* attach SDR */
1068 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0],
1069 i2c_adap_internal,
1070 &rtl28xxu_rtl2832_e4000_config, sd);
1071 } 1106 }
1072 break; 1107 break;
1073 case TUNER_RTL2832_FC2580: 1108 case TUNER_RTL2832_FC2580:
1074 fe = dvb_attach(fc2580_attach, adap->fe[0], &d->i2c_adap, 1109 fe = dvb_attach(fc2580_attach, adap->fe[0],
1110 dev->demod_i2c_adapter,
1075 &rtl2832u_fc2580_config); 1111 &rtl2832u_fc2580_config);
1076 break; 1112 break;
1077 case TUNER_RTL2832_TUA9001: 1113 case TUNER_RTL2832_TUA9001:
1078 /* enable GPIO1 and GPIO4 as output */ 1114 /* enable GPIO1 and GPIO4 as output */
1079 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12); 1115 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_DIR, 0x00, 0x12);
1080 if (ret) 1116 if (ret)
1081 goto err; 1117 goto err;
1082 1118
1083 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12); 1119 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_EN, 0x12, 0x12);
1084 if (ret) 1120 if (ret)
1085 goto err; 1121 goto err;
1086 1122
1087 fe = dvb_attach(tua9001_attach, adap->fe[0], &d->i2c_adap, 1123 fe = dvb_attach(tua9001_attach, adap->fe[0],
1124 dev->demod_i2c_adapter,
1088 &rtl2832u_tua9001_config); 1125 &rtl2832u_tua9001_config);
1089 break; 1126 break;
1090 case TUNER_RTL2832_R820T: 1127 case TUNER_RTL2832_R820T:
1091 fe = dvb_attach(r820t_attach, adap->fe[0], &d->i2c_adap, 1128 fe = dvb_attach(r820t_attach, adap->fe[0],
1129 dev->demod_i2c_adapter,
1092 &rtl2832u_r820t_config); 1130 &rtl2832u_r820t_config);
1093 1131
1094 /* Use tuner to get the signal strength */ 1132 /* Use tuner to get the signal strength */
1095 adap->fe[0]->ops.read_signal_strength = 1133 adap->fe[0]->ops.read_signal_strength =
1096 adap->fe[0]->ops.tuner_ops.get_rf_strength; 1134 adap->fe[0]->ops.tuner_ops.get_rf_strength;
1097
1098 /* attach SDR */
1099 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
1100 &rtl28xxu_rtl2832_r820t_config, NULL);
1101 break; 1135 break;
1102 case TUNER_RTL2832_R828D: 1136 case TUNER_RTL2832_R828D:
1103 fe = dvb_attach(r820t_attach, adap->fe[0], 1137 fe = dvb_attach(r820t_attach, adap->fe[0],
1104 priv->demod_i2c_adapter, 1138 dev->demod_i2c_adapter,
1105 &rtl2832u_r828d_config); 1139 &rtl2832u_r828d_config);
1106 adap->fe[0]->ops.read_signal_strength = 1140 adap->fe[0]->ops.read_signal_strength =
1107 adap->fe[0]->ops.tuner_ops.get_rf_strength; 1141 adap->fe[0]->ops.tuner_ops.get_rf_strength;
1108 1142
1109 if (adap->fe[1]) { 1143 if (adap->fe[1]) {
1110 fe = dvb_attach(r820t_attach, adap->fe[1], 1144 fe = dvb_attach(r820t_attach, adap->fe[1],
1111 priv->demod_i2c_adapter, 1145 dev->demod_i2c_adapter,
1112 &rtl2832u_r828d_config); 1146 &rtl2832u_r828d_config);
1113 adap->fe[1]->ops.read_signal_strength = 1147 adap->fe[1]->ops.read_signal_strength =
1114 adap->fe[1]->ops.tuner_ops.get_rf_strength; 1148 adap->fe[1]->ops.tuner_ops.get_rf_strength;
1115 } 1149 }
1116
1117 /* attach SDR */
1118 dvb_attach_sdr(rtl2832_sdr_attach, adap->fe[0], &d->i2c_adap,
1119 &rtl28xxu_rtl2832_r820t_config, NULL);
1120 break; 1150 break;
1121 default: 1151 default:
1122 dev_err(&d->udev->dev, "%s: unknown tuner=%d\n", KBUILD_MODNAME, 1152 dev_err(&d->intf->dev, "unknown tuner %d\n", dev->tuner);
1123 priv->tuner);
1124 } 1153 }
1125 1154 if (fe == NULL && dev->i2c_client_tuner == NULL) {
1126 if (fe == NULL && priv->i2c_client_tuner == NULL) {
1127 ret = -ENODEV; 1155 ret = -ENODEV;
1128 goto err; 1156 goto err;
1129 } 1157 }
1130 1158
1159 /* register SDR */
1160 switch (dev->tuner) {
1161 case TUNER_RTL2832_FC0012:
1162 case TUNER_RTL2832_FC0013:
1163 case TUNER_RTL2832_E4000:
1164 case TUNER_RTL2832_R820T:
1165 case TUNER_RTL2832_R828D:
1166 pdata.clk = dev->rtl2832_platform_data.clk;
1167 pdata.tuner = dev->tuner;
1168 pdata.i2c_client = dev->i2c_client_demod;
1169 pdata.bulk_read = dev->rtl2832_platform_data.bulk_read;
1170 pdata.bulk_write = dev->rtl2832_platform_data.bulk_write;
1171 pdata.update_bits = dev->rtl2832_platform_data.update_bits;
1172 pdata.dvb_frontend = adap->fe[0];
1173 pdata.dvb_usb_device = d;
1174 pdata.v4l2_subdev = subdev;
1175
1176 request_module("%s", "rtl2832_sdr");
1177 pdev = platform_device_register_data(&d->intf->dev,
1178 "rtl2832_sdr",
1179 PLATFORM_DEVID_AUTO,
1180 &pdata, sizeof(pdata));
1181 if (pdev == NULL || pdev->dev.driver == NULL)
1182 break;
1183 dev->platform_device_sdr = pdev;
1184 break;
1185 default:
1186 dev_dbg(&d->intf->dev, "no SDR for tuner=%d\n", dev->tuner);
1187 }
1188
1131 return 0; 1189 return 0;
1132err: 1190err:
1133 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1191 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1134 return ret; 1192 return ret;
1135} 1193}
1136 1194
1195static int rtl28xxu_tuner_attach(struct dvb_usb_adapter *adap)
1196{
1197 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1198
1199 if (dev->chip_id == CHIP_ID_RTL2831U)
1200 return rtl2831u_tuner_attach(adap);
1201 else
1202 return rtl2832u_tuner_attach(adap);
1203}
1204
1205static int rtl28xxu_tuner_detach(struct dvb_usb_adapter *adap)
1206{
1207 struct dvb_usb_device *d = adap_to_d(adap);
1208 struct rtl28xxu_dev *dev = d_to_priv(d);
1209 struct i2c_client *client;
1210 struct platform_device *pdev;
1211
1212 dev_dbg(&d->intf->dev, "\n");
1213
1214 /* remove platform SDR */
1215 pdev = dev->platform_device_sdr;
1216 if (pdev)
1217 platform_device_unregister(pdev);
1218
1219 /* remove I2C tuner */
1220 client = dev->i2c_client_tuner;
1221 if (client) {
1222 module_put(client->dev.driver->owner);
1223 i2c_unregister_device(client);
1224 }
1225
1226 return 0;
1227}
1228
1137static int rtl28xxu_init(struct dvb_usb_device *d) 1229static int rtl28xxu_init(struct dvb_usb_device *d)
1138{ 1230{
1139 int ret; 1231 int ret;
1140 u8 val; 1232 u8 val;
1141 1233
1142 dev_dbg(&d->udev->dev, "%s:\n", __func__); 1234 dev_dbg(&d->intf->dev, "\n");
1143 1235
1144 /* init USB endpoints */ 1236 /* init USB endpoints */
1145 ret = rtl28xx_rd_reg(d, USB_SYSCTL_0, &val); 1237 ret = rtl28xxu_rd_reg(d, USB_SYSCTL_0, &val);
1146 if (ret) 1238 if (ret)
1147 goto err; 1239 goto err;
1148 1240
1149 /* enable DMA and Full Packet Mode*/ 1241 /* enable DMA and Full Packet Mode*/
1150 val |= 0x09; 1242 val |= 0x09;
1151 ret = rtl28xx_wr_reg(d, USB_SYSCTL_0, val); 1243 ret = rtl28xxu_wr_reg(d, USB_SYSCTL_0, val);
1152 if (ret) 1244 if (ret)
1153 goto err; 1245 goto err;
1154 1246
1155 /* set EPA maximum packet size to 0x0200 */ 1247 /* set EPA maximum packet size to 0x0200 */
1156 ret = rtl28xx_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4); 1248 ret = rtl28xxu_wr_regs(d, USB_EPA_MAXPKT, "\x00\x02\x00\x00", 4);
1157 if (ret) 1249 if (ret)
1158 goto err; 1250 goto err;
1159 1251
1160 /* change EPA FIFO length */ 1252 /* change EPA FIFO length */
1161 ret = rtl28xx_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4); 1253 ret = rtl28xxu_wr_regs(d, USB_EPA_FIFO_CFG, "\x14\x00\x00\x00", 4);
1162 if (ret) 1254 if (ret)
1163 goto err; 1255 goto err;
1164 1256
1165 return ret; 1257 return ret;
1166err: 1258err:
1167 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1259 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1168 return ret; 1260 return ret;
1169} 1261}
1170 1262
1171static void rtl28xxu_exit(struct dvb_usb_device *d)
1172{
1173 struct rtl28xxu_priv *priv = d->priv;
1174 struct i2c_client *client;
1175
1176 dev_dbg(&d->udev->dev, "%s:\n", __func__);
1177
1178 /* remove I2C tuner */
1179 client = priv->i2c_client_tuner;
1180 if (client) {
1181 module_put(client->dev.driver->owner);
1182 i2c_unregister_device(client);
1183 }
1184
1185 /* remove I2C slave demod */
1186 client = priv->i2c_client_slave_demod;
1187 if (client) {
1188 module_put(client->dev.driver->owner);
1189 i2c_unregister_device(client);
1190 }
1191
1192 return;
1193}
1194
1195static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff) 1263static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
1196{ 1264{
1197 int ret; 1265 int ret;
1198 u8 gpio, sys0, epa_ctl[2]; 1266 u8 gpio, sys0, epa_ctl[2];
1199 1267
1200 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); 1268 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
1201 1269
1202 /* demod adc */ 1270 /* demod adc */
1203 ret = rtl28xx_rd_reg(d, SYS_SYS0, &sys0); 1271 ret = rtl28xxu_rd_reg(d, SYS_SYS0, &sys0);
1204 if (ret) 1272 if (ret)
1205 goto err; 1273 goto err;
1206 1274
1207 /* tuner power, read GPIOs */ 1275 /* tuner power, read GPIOs */
1208 ret = rtl28xx_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio); 1276 ret = rtl28xxu_rd_reg(d, SYS_GPIO_OUT_VAL, &gpio);
1209 if (ret) 1277 if (ret)
1210 goto err; 1278 goto err;
1211 1279
1212 dev_dbg(&d->udev->dev, "%s: RD SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, 1280 dev_dbg(&d->intf->dev, "RD SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
1213 sys0, gpio);
1214 1281
1215 if (onoff) { 1282 if (onoff) {
1216 gpio |= 0x01; /* GPIO0 = 1 */ 1283 gpio |= 0x01; /* GPIO0 = 1 */
@@ -1229,21 +1296,20 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
1229 epa_ctl[1] = 0x02; /* set reset */ 1296 epa_ctl[1] = 0x02; /* set reset */
1230 } 1297 }
1231 1298
1232 dev_dbg(&d->udev->dev, "%s: WR SYS0=%02x GPIO_OUT_VAL=%02x\n", __func__, 1299 dev_dbg(&d->intf->dev, "WR SYS0=%02x GPIO_OUT_VAL=%02x\n", sys0, gpio);
1233 sys0, gpio);
1234 1300
1235 /* demod adc */ 1301 /* demod adc */
1236 ret = rtl28xx_wr_reg(d, SYS_SYS0, sys0); 1302 ret = rtl28xxu_wr_reg(d, SYS_SYS0, sys0);
1237 if (ret) 1303 if (ret)
1238 goto err; 1304 goto err;
1239 1305
1240 /* tuner power, write GPIOs */ 1306 /* tuner power, write GPIOs */
1241 ret = rtl28xx_wr_reg(d, SYS_GPIO_OUT_VAL, gpio); 1307 ret = rtl28xxu_wr_reg(d, SYS_GPIO_OUT_VAL, gpio);
1242 if (ret) 1308 if (ret)
1243 goto err; 1309 goto err;
1244 1310
1245 /* streaming EP: stall & reset */ 1311 /* streaming EP: stall & reset */
1246 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, epa_ctl, 2); 1312 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, epa_ctl, 2);
1247 if (ret) 1313 if (ret)
1248 goto err; 1314 goto err;
1249 1315
@@ -1252,7 +1318,7 @@ static int rtl2831u_power_ctrl(struct dvb_usb_device *d, int onoff)
1252 1318
1253 return ret; 1319 return ret;
1254err: 1320err:
1255 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1321 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1256 return ret; 1322 return ret;
1257} 1323}
1258 1324
@@ -1260,31 +1326,31 @@ static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1260{ 1326{
1261 int ret; 1327 int ret;
1262 1328
1263 dev_dbg(&d->udev->dev, "%s: onoff=%d\n", __func__, onoff); 1329 dev_dbg(&d->intf->dev, "onoff=%d\n", onoff);
1264 1330
1265 if (onoff) { 1331 if (onoff) {
1266 /* GPIO3=1, GPIO4=0 */ 1332 /* GPIO3=1, GPIO4=0 */
1267 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18); 1333 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x08, 0x18);
1268 if (ret) 1334 if (ret)
1269 goto err; 1335 goto err;
1270 1336
1271 /* suspend? */ 1337 /* suspend? */
1272 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10); 1338 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL1, 0x00, 0x10);
1273 if (ret) 1339 if (ret)
1274 goto err; 1340 goto err;
1275 1341
1276 /* enable PLL */ 1342 /* enable PLL */
1277 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80); 1343 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x80, 0x80);
1278 if (ret) 1344 if (ret)
1279 goto err; 1345 goto err;
1280 1346
1281 /* disable reset */ 1347 /* disable reset */
1282 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20); 1348 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x20, 0x20);
1283 if (ret) 1349 if (ret)
1284 goto err; 1350 goto err;
1285 1351
1286 /* streaming EP: clear stall & reset */ 1352 /* streaming EP: clear stall & reset */
1287 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2); 1353 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x00\x00", 2);
1288 if (ret) 1354 if (ret)
1289 goto err; 1355 goto err;
1290 1356
@@ -1293,35 +1359,49 @@ static int rtl2832u_power_ctrl(struct dvb_usb_device *d, int onoff)
1293 goto err; 1359 goto err;
1294 } else { 1360 } else {
1295 /* GPIO4=1 */ 1361 /* GPIO4=1 */
1296 ret = rtl28xx_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10); 1362 ret = rtl28xxu_wr_reg_mask(d, SYS_GPIO_OUT_VAL, 0x10, 0x10);
1297 if (ret) 1363 if (ret)
1298 goto err; 1364 goto err;
1299 1365
1300 /* disable PLL */ 1366 /* disable PLL */
1301 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80); 1367 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, 0x00, 0x80);
1302 if (ret) 1368 if (ret)
1303 goto err; 1369 goto err;
1304 1370
1305 /* streaming EP: set stall & reset */ 1371 /* streaming EP: set stall & reset */
1306 ret = rtl28xx_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2); 1372 ret = rtl28xxu_wr_regs(d, USB_EPA_CTL, "\x10\x02", 2);
1307 if (ret) 1373 if (ret)
1308 goto err; 1374 goto err;
1309 } 1375 }
1310 1376
1311 return ret; 1377 return ret;
1312err: 1378err:
1313 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1379 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1314 return ret; 1380 return ret;
1315} 1381}
1316 1382
1317static int rtl2832u_frontend_ctrl(struct dvb_frontend *fe, int onoff) 1383static int rtl28xxu_power_ctrl(struct dvb_usb_device *d, int onoff)
1384{
1385 struct rtl28xxu_dev *dev = d_to_priv(d);
1386
1387 if (dev->chip_id == CHIP_ID_RTL2831U)
1388 return rtl2831u_power_ctrl(d, onoff);
1389 else
1390 return rtl2832u_power_ctrl(d, onoff);
1391}
1392
1393static int rtl28xxu_frontend_ctrl(struct dvb_frontend *fe, int onoff)
1318{ 1394{
1319 struct dvb_usb_device *d = fe_to_d(fe); 1395 struct dvb_usb_device *d = fe_to_d(fe);
1320 struct dvb_usb_adapter *adap = fe_to_adap(fe); 1396 struct rtl28xxu_dev *dev = fe_to_priv(fe);
1397 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
1321 int ret; 1398 int ret;
1322 u8 val; 1399 u8 val;
1323 1400
1324 dev_dbg(&d->udev->dev, "%s: fe=%d onoff=%d\n", __func__, fe->id, onoff); 1401 dev_dbg(&d->intf->dev, "fe=%d onoff=%d\n", fe->id, onoff);
1402
1403 if (dev->chip_id == CHIP_ID_RTL2831U)
1404 return 0;
1325 1405
1326 /* control internal demod ADC */ 1406 /* control internal demod ADC */
1327 if (fe->id == 0 && onoff) 1407 if (fe->id == 0 && onoff)
@@ -1329,20 +1409,20 @@ static int rtl2832u_frontend_ctrl(struct dvb_frontend *fe, int onoff)
1329 else 1409 else
1330 val = 0x00; /* disable ADC */ 1410 val = 0x00; /* disable ADC */
1331 1411
1332 ret = rtl28xx_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48); 1412 ret = rtl28xxu_wr_reg_mask(d, SYS_DEMOD_CTL, val, 0x48);
1333 if (ret) 1413 if (ret)
1334 goto err; 1414 goto err;
1335 1415
1336 /* bypass slave demod TS through master demod */ 1416 /* bypass slave demod TS through master demod */
1337 if (fe->id == 1 && onoff) { 1417 if (fe->id == 1 && onoff) {
1338 ret = rtl2832_enable_external_ts_if(adap->fe[0]); 1418 ret = pdata->enable_slave_ts(dev->i2c_client_demod);
1339 if (ret) 1419 if (ret)
1340 goto err; 1420 goto err;
1341 } 1421 }
1342 1422
1343 return 0; 1423 return 0;
1344err: 1424err:
1345 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1425 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1346 return ret; 1426 return ret;
1347} 1427}
1348 1428
@@ -1350,7 +1430,7 @@ err:
1350static int rtl2831u_rc_query(struct dvb_usb_device *d) 1430static int rtl2831u_rc_query(struct dvb_usb_device *d)
1351{ 1431{
1352 int ret, i; 1432 int ret, i;
1353 struct rtl28xxu_priv *priv = d->priv; 1433 struct rtl28xxu_dev *dev = d->priv;
1354 u8 buf[5]; 1434 u8 buf[5];
1355 u32 rc_code; 1435 u32 rc_code;
1356 struct rtl28xxu_reg_val rc_nec_tab[] = { 1436 struct rtl28xxu_reg_val rc_nec_tab[] = {
@@ -1371,17 +1451,17 @@ static int rtl2831u_rc_query(struct dvb_usb_device *d)
1371 }; 1451 };
1372 1452
1373 /* init remote controller */ 1453 /* init remote controller */
1374 if (!priv->rc_active) { 1454 if (!dev->rc_active) {
1375 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) { 1455 for (i = 0; i < ARRAY_SIZE(rc_nec_tab); i++) {
1376 ret = rtl28xx_wr_reg(d, rc_nec_tab[i].reg, 1456 ret = rtl28xxu_wr_reg(d, rc_nec_tab[i].reg,
1377 rc_nec_tab[i].val); 1457 rc_nec_tab[i].val);
1378 if (ret) 1458 if (ret)
1379 goto err; 1459 goto err;
1380 } 1460 }
1381 priv->rc_active = true; 1461 dev->rc_active = true;
1382 } 1462 }
1383 1463
1384 ret = rtl2831_rd_regs(d, SYS_IRRC_RP, buf, 5); 1464 ret = rtl28xxu_rd_regs(d, SYS_IRRC_RP, buf, 5);
1385 if (ret) 1465 if (ret)
1386 goto err; 1466 goto err;
1387 1467
@@ -1403,19 +1483,19 @@ static int rtl2831u_rc_query(struct dvb_usb_device *d)
1403 1483
1404 rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0); 1484 rc_keydown(d->rc_dev, RC_TYPE_NEC, rc_code, 0);
1405 1485
1406 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); 1486 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
1407 if (ret) 1487 if (ret)
1408 goto err; 1488 goto err;
1409 1489
1410 /* repeated intentionally to avoid extra keypress */ 1490 /* repeated intentionally to avoid extra keypress */
1411 ret = rtl28xx_wr_reg(d, SYS_IRRC_SR, 1); 1491 ret = rtl28xxu_wr_reg(d, SYS_IRRC_SR, 1);
1412 if (ret) 1492 if (ret)
1413 goto err; 1493 goto err;
1414 } 1494 }
1415 1495
1416 return ret; 1496 return ret;
1417err: 1497err:
1418 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1498 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1419 return ret; 1499 return ret;
1420} 1500}
1421 1501
@@ -1433,7 +1513,7 @@ static int rtl2831u_get_rc_config(struct dvb_usb_device *d,
1433static int rtl2832u_rc_query(struct dvb_usb_device *d) 1513static int rtl2832u_rc_query(struct dvb_usb_device *d)
1434{ 1514{
1435 int ret, i, len; 1515 int ret, i, len;
1436 struct rtl28xxu_priv *priv = d->priv; 1516 struct rtl28xxu_dev *dev = d->priv;
1437 struct ir_raw_event ev; 1517 struct ir_raw_event ev;
1438 u8 buf[128]; 1518 u8 buf[128];
1439 static const struct rtl28xxu_reg_val_mask refresh_tab[] = { 1519 static const struct rtl28xxu_reg_val_mask refresh_tab[] = {
@@ -1443,7 +1523,7 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
1443 }; 1523 };
1444 1524
1445 /* init remote controller */ 1525 /* init remote controller */
1446 if (!priv->rc_active) { 1526 if (!dev->rc_active) {
1447 static const struct rtl28xxu_reg_val_mask init_tab[] = { 1527 static const struct rtl28xxu_reg_val_mask init_tab[] = {
1448 {SYS_DEMOD_CTL1, 0x00, 0x04}, 1528 {SYS_DEMOD_CTL1, 0x00, 0x04},
1449 {SYS_DEMOD_CTL1, 0x00, 0x08}, 1529 {SYS_DEMOD_CTL1, 0x00, 0x08},
@@ -1464,36 +1544,36 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
1464 }; 1544 };
1465 1545
1466 for (i = 0; i < ARRAY_SIZE(init_tab); i++) { 1546 for (i = 0; i < ARRAY_SIZE(init_tab); i++) {
1467 ret = rtl28xx_wr_reg_mask(d, init_tab[i].reg, 1547 ret = rtl28xxu_wr_reg_mask(d, init_tab[i].reg,
1468 init_tab[i].val, init_tab[i].mask); 1548 init_tab[i].val, init_tab[i].mask);
1469 if (ret) 1549 if (ret)
1470 goto err; 1550 goto err;
1471 } 1551 }
1472 1552
1473 priv->rc_active = true; 1553 dev->rc_active = true;
1474 } 1554 }
1475 1555
1476 ret = rtl28xx_rd_reg(d, IR_RX_IF, &buf[0]); 1556 ret = rtl28xxu_rd_reg(d, IR_RX_IF, &buf[0]);
1477 if (ret) 1557 if (ret)
1478 goto err; 1558 goto err;
1479 1559
1480 if (buf[0] != 0x83) 1560 if (buf[0] != 0x83)
1481 goto exit; 1561 goto exit;
1482 1562
1483 ret = rtl28xx_rd_reg(d, IR_RX_BC, &buf[0]); 1563 ret = rtl28xxu_rd_reg(d, IR_RX_BC, &buf[0]);
1484 if (ret) 1564 if (ret)
1485 goto err; 1565 goto err;
1486 1566
1487 len = buf[0]; 1567 len = buf[0];
1488 1568
1489 /* read raw code from hw */ 1569 /* read raw code from hw */
1490 ret = rtl2831_rd_regs(d, IR_RX_BUF, buf, len); 1570 ret = rtl28xxu_rd_regs(d, IR_RX_BUF, buf, len);
1491 if (ret) 1571 if (ret)
1492 goto err; 1572 goto err;
1493 1573
1494 /* let hw receive new code */ 1574 /* let hw receive new code */
1495 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) { 1575 for (i = 0; i < ARRAY_SIZE(refresh_tab); i++) {
1496 ret = rtl28xx_wr_reg_mask(d, refresh_tab[i].reg, 1576 ret = rtl28xxu_wr_reg_mask(d, refresh_tab[i].reg,
1497 refresh_tab[i].val, refresh_tab[i].mask); 1577 refresh_tab[i].val, refresh_tab[i].mask);
1498 if (ret) 1578 if (ret)
1499 goto err; 1579 goto err;
@@ -1514,7 +1594,7 @@ static int rtl2832u_rc_query(struct dvb_usb_device *d)
1514exit: 1594exit:
1515 return ret; 1595 return ret;
1516err: 1596err:
1517 dev_dbg(&d->udev->dev, "%s: failed=%d\n", __func__, ret); 1597 dev_dbg(&d->intf->dev, "failed=%d\n", ret);
1518 return ret; 1598 return ret;
1519} 1599}
1520 1600
@@ -1523,7 +1603,7 @@ static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1523{ 1603{
1524 /* disable IR interrupts in order to avoid SDR sample loss */ 1604 /* disable IR interrupts in order to avoid SDR sample loss */
1525 if (rtl28xxu_disable_rc) 1605 if (rtl28xxu_disable_rc)
1526 return rtl28xx_wr_reg(d, IR_RX_IE, 0x00); 1606 return rtl28xxu_wr_reg(d, IR_RX_IE, 0x00);
1527 1607
1528 /* load empty to enable rc */ 1608 /* load empty to enable rc */
1529 if (!rc->map_name) 1609 if (!rc->map_name)
@@ -1535,52 +1615,80 @@ static int rtl2832u_get_rc_config(struct dvb_usb_device *d,
1535 1615
1536 return 0; 1616 return 0;
1537} 1617}
1618
1619static int rtl28xxu_get_rc_config(struct dvb_usb_device *d,
1620 struct dvb_usb_rc *rc)
1621{
1622 struct rtl28xxu_dev *dev = d_to_priv(d);
1623
1624 if (dev->chip_id == CHIP_ID_RTL2831U)
1625 return rtl2831u_get_rc_config(d, rc);
1626 else
1627 return rtl2832u_get_rc_config(d, rc);
1628}
1538#else 1629#else
1539#define rtl2831u_get_rc_config NULL 1630#define rtl28xxu_get_rc_config NULL
1540#define rtl2832u_get_rc_config NULL
1541#endif 1631#endif
1542 1632
1543static const struct dvb_usb_device_properties rtl2831u_props = { 1633static int rtl28xxu_pid_filter_ctrl(struct dvb_usb_adapter *adap, int onoff)
1544 .driver_name = KBUILD_MODNAME, 1634{
1545 .owner = THIS_MODULE, 1635 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1546 .adapter_nr = adapter_nr,
1547 .size_of_priv = sizeof(struct rtl28xxu_priv),
1548 1636
1549 .power_ctrl = rtl2831u_power_ctrl, 1637 if (dev->chip_id == CHIP_ID_RTL2831U) {
1550 .i2c_algo = &rtl28xxu_i2c_algo, 1638 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
1551 .read_config = rtl2831u_read_config,
1552 .frontend_attach = rtl2831u_frontend_attach,
1553 .tuner_attach = rtl2831u_tuner_attach,
1554 .init = rtl28xxu_init,
1555 .get_rc_config = rtl2831u_get_rc_config,
1556 1639
1557 .num_adapters = 1, 1640 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1558 .adapter = { 1641 } else {
1559 { 1642 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
1560 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
1561 },
1562 },
1563};
1564 1643
1565static const struct dvb_usb_device_properties rtl2832u_props = { 1644 return pdata->pid_filter_ctrl(adap->fe[0], onoff);
1645 }
1646}
1647
1648static int rtl28xxu_pid_filter(struct dvb_usb_adapter *adap, int index,
1649 u16 pid, int onoff)
1650{
1651 struct rtl28xxu_dev *dev = adap_to_priv(adap);
1652
1653 if (dev->chip_id == CHIP_ID_RTL2831U) {
1654 struct rtl2830_platform_data *pdata = &dev->rtl2830_platform_data;
1655
1656 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1657 } else {
1658 struct rtl2832_platform_data *pdata = &dev->rtl2832_platform_data;
1659
1660 return pdata->pid_filter(adap->fe[0], index, pid, onoff);
1661 }
1662}
1663
1664static const struct dvb_usb_device_properties rtl28xxu_props = {
1566 .driver_name = KBUILD_MODNAME, 1665 .driver_name = KBUILD_MODNAME,
1567 .owner = THIS_MODULE, 1666 .owner = THIS_MODULE,
1568 .adapter_nr = adapter_nr, 1667 .adapter_nr = adapter_nr,
1569 .size_of_priv = sizeof(struct rtl28xxu_priv), 1668 .size_of_priv = sizeof(struct rtl28xxu_dev),
1570 1669
1571 .power_ctrl = rtl2832u_power_ctrl, 1670 .identify_state = rtl28xxu_identify_state,
1572 .frontend_ctrl = rtl2832u_frontend_ctrl, 1671 .power_ctrl = rtl28xxu_power_ctrl,
1672 .frontend_ctrl = rtl28xxu_frontend_ctrl,
1573 .i2c_algo = &rtl28xxu_i2c_algo, 1673 .i2c_algo = &rtl28xxu_i2c_algo,
1574 .read_config = rtl2832u_read_config, 1674 .read_config = rtl28xxu_read_config,
1575 .frontend_attach = rtl2832u_frontend_attach, 1675 .frontend_attach = rtl28xxu_frontend_attach,
1576 .tuner_attach = rtl2832u_tuner_attach, 1676 .frontend_detach = rtl28xxu_frontend_detach,
1677 .tuner_attach = rtl28xxu_tuner_attach,
1678 .tuner_detach = rtl28xxu_tuner_detach,
1577 .init = rtl28xxu_init, 1679 .init = rtl28xxu_init,
1578 .exit = rtl28xxu_exit, 1680 .get_rc_config = rtl28xxu_get_rc_config,
1579 .get_rc_config = rtl2832u_get_rc_config,
1580 1681
1581 .num_adapters = 1, 1682 .num_adapters = 1,
1582 .adapter = { 1683 .adapter = {
1583 { 1684 {
1685 .caps = DVB_USB_ADAP_HAS_PID_FILTER |
1686 DVB_USB_ADAP_PID_FILTER_CAN_BE_TURNED_OFF,
1687
1688 .pid_filter_count = 32,
1689 .pid_filter_ctrl = rtl28xxu_pid_filter_ctrl,
1690 .pid_filter = rtl28xxu_pid_filter,
1691
1584 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512), 1692 .stream = DVB_USB_STREAM_BULK(0x81, 6, 8 * 512),
1585 }, 1693 },
1586 }, 1694 },
@@ -1589,69 +1697,69 @@ static const struct dvb_usb_device_properties rtl2832u_props = {
1589static const struct usb_device_id rtl28xxu_id_table[] = { 1697static const struct usb_device_id rtl28xxu_id_table[] = {
1590 /* RTL2831U devices: */ 1698 /* RTL2831U devices: */
1591 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U, 1699 { DVB_USB_DEVICE(USB_VID_REALTEK, USB_PID_REALTEK_RTL2831U,
1592 &rtl2831u_props, "Realtek RTL2831U reference design", NULL) }, 1700 &rtl28xxu_props, "Realtek RTL2831U reference design", NULL) },
1593 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT, 1701 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT,
1594 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, 1702 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
1595 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2, 1703 { DVB_USB_DEVICE(USB_VID_WIDEVIEW, USB_PID_FREECOM_DVBT_2,
1596 &rtl2831u_props, "Freecom USB2.0 DVB-T", NULL) }, 1704 &rtl28xxu_props, "Freecom USB2.0 DVB-T", NULL) },
1597 1705
1598 /* RTL2832U devices: */ 1706 /* RTL2832U devices: */
1599 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832, 1707 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2832,
1600 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, 1708 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
1601 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838, 1709 { DVB_USB_DEVICE(USB_VID_REALTEK, 0x2838,
1602 &rtl2832u_props, "Realtek RTL2832U reference design", NULL) }, 1710 &rtl28xxu_props, "Realtek RTL2832U reference design", NULL) },
1603 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1, 1711 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_TERRATEC_CINERGY_T_STICK_BLACK_REV1,
1604 &rtl2832u_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) }, 1712 &rtl28xxu_props, "TerraTec Cinergy T Stick Black", RC_MAP_TERRATEC_SLIM) },
1605 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT, 1713 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_DELOCK_USB2_DVBT,
1606 &rtl2832u_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) }, 1714 &rtl28xxu_props, "G-Tek Electronics Group Lifeview LV5TDLX DVB-T", NULL) },
1607 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK, 1715 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK,
1608 &rtl2832u_props, "TerraTec NOXON DAB Stick", NULL) }, 1716 &rtl28xxu_props, "TerraTec NOXON DAB Stick", NULL) },
1609 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2, 1717 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV2,
1610 &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) }, 1718 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 2)", NULL) },
1611 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3, 1719 { DVB_USB_DEVICE(USB_VID_TERRATEC, USB_PID_NOXON_DAB_STICK_REV3,
1612 &rtl2832u_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) }, 1720 &rtl28xxu_props, "TerraTec NOXON DAB Stick (rev 3)", NULL) },
1613 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0, 1721 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_TREKSTOR_TERRES_2_0,
1614 &rtl2832u_props, "Trekstor DVB-T Stick Terres 2.0", NULL) }, 1722 &rtl28xxu_props, "Trekstor DVB-T Stick Terres 2.0", NULL) },
1615 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101, 1723 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1101,
1616 &rtl2832u_props, "Dexatek DK DVB-T Dongle", NULL) }, 1724 &rtl28xxu_props, "Dexatek DK DVB-T Dongle", NULL) },
1617 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680, 1725 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6680,
1618 &rtl2832u_props, "DigitalNow Quad DVB-T Receiver", NULL) }, 1726 &rtl28xxu_props, "DigitalNow Quad DVB-T Receiver", NULL) },
1619 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID, 1727 { DVB_USB_DEVICE(USB_VID_LEADTEK, USB_PID_WINFAST_DTV_DONGLE_MINID,
1620 &rtl2832u_props, "Leadtek Winfast DTV Dongle Mini D", NULL) }, 1728 &rtl28xxu_props, "Leadtek Winfast DTV Dongle Mini D", NULL) },
1621 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3, 1729 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d3,
1622 &rtl2832u_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) }, 1730 &rtl28xxu_props, "TerraTec Cinergy T Stick RC (Rev. 3)", NULL) },
1623 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102, 1731 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1102,
1624 &rtl2832u_props, "Dexatek DK mini DVB-T Dongle", NULL) }, 1732 &rtl28xxu_props, "Dexatek DK mini DVB-T Dongle", NULL) },
1625 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7, 1733 { DVB_USB_DEVICE(USB_VID_TERRATEC, 0x00d7,
1626 &rtl2832u_props, "TerraTec Cinergy T Stick+", NULL) }, 1734 &rtl28xxu_props, "TerraTec Cinergy T Stick+", NULL) },
1627 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8, 1735 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd3a8,
1628 &rtl2832u_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) }, 1736 &rtl28xxu_props, "ASUS My Cinema-U3100Mini Plus V2", NULL) },
1629 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393, 1737 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd393,
1630 &rtl2832u_props, "GIGABYTE U7300", NULL) }, 1738 &rtl28xxu_props, "GIGABYTE U7300", NULL) },
1631 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104, 1739 { DVB_USB_DEVICE(USB_VID_DEXATEK, 0x1104,
1632 &rtl2832u_props, "MSI DIGIVOX Micro HD", NULL) }, 1740 &rtl28xxu_props, "MSI DIGIVOX Micro HD", NULL) },
1633 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620, 1741 { DVB_USB_DEVICE(USB_VID_COMPRO, 0x0620,
1634 &rtl2832u_props, "Compro VideoMate U620F", NULL) }, 1742 &rtl28xxu_props, "Compro VideoMate U620F", NULL) },
1635 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394, 1743 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd394,
1636 &rtl2832u_props, "MaxMedia HU394-T", NULL) }, 1744 &rtl28xxu_props, "MaxMedia HU394-T", NULL) },
1637 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03, 1745 { DVB_USB_DEVICE(USB_VID_LEADTEK, 0x6a03,
1638 &rtl2832u_props, "Leadtek WinFast DTV Dongle mini", NULL) }, 1746 &rtl28xxu_props, "Leadtek WinFast DTV Dongle mini", NULL) },
1639 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A, 1747 { DVB_USB_DEVICE(USB_VID_GTEK, USB_PID_CPYTO_REDI_PC50A,
1640 &rtl2832u_props, "Crypto ReDi PC 50 A", NULL) }, 1748 &rtl28xxu_props, "Crypto ReDi PC 50 A", NULL) },
1641 { DVB_USB_DEVICE(USB_VID_KYE, 0x707f, 1749 { DVB_USB_DEVICE(USB_VID_KYE, 0x707f,
1642 &rtl2832u_props, "Genius TVGo DVB-T03", NULL) }, 1750 &rtl28xxu_props, "Genius TVGo DVB-T03", NULL) },
1643 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395, 1751 { DVB_USB_DEVICE(USB_VID_KWORLD_2, 0xd395,
1644 &rtl2832u_props, "Peak DVB-T USB", NULL) }, 1752 &rtl28xxu_props, "Peak DVB-T USB", NULL) },
1645 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U, 1753 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV20_RTL2832U,
1646 &rtl2832u_props, "Sveon STV20", NULL) }, 1754 &rtl28xxu_props, "Sveon STV20", NULL) },
1647 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21, 1755 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV21,
1648 &rtl2832u_props, "Sveon STV21", NULL) }, 1756 &rtl28xxu_props, "Sveon STV21", NULL) },
1649 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27, 1757 { DVB_USB_DEVICE(USB_VID_KWORLD_2, USB_PID_SVEON_STV27,
1650 &rtl2832u_props, "Sveon STV27", NULL) }, 1758 &rtl28xxu_props, "Sveon STV27", NULL) },
1651 1759
1652 /* RTL2832P devices: */ 1760 /* RTL2832P devices: */
1653 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131, 1761 { DVB_USB_DEVICE(USB_VID_HANFTEK, 0x0131,
1654 &rtl2832u_props, "Astrometa DVB-T2", NULL) }, 1762 &rtl28xxu_props, "Astrometa DVB-T2", NULL) },
1655 { } 1763 { }
1656}; 1764};
1657MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table); 1765MODULE_DEVICE_TABLE(usb, rtl28xxu_id_table);
diff --git a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
index 3e3ea9d64a38..1b5d7ffb685e 100644
--- a/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
+++ b/drivers/media/usb/dvb-usb-v2/rtl28xxu.h
@@ -22,8 +22,26 @@
22#ifndef RTL28XXU_H 22#ifndef RTL28XXU_H
23#define RTL28XXU_H 23#define RTL28XXU_H
24 24
25#include <linux/platform_device.h>
26
25#include "dvb_usb.h" 27#include "dvb_usb.h"
26 28
29#include "rtl2830.h"
30#include "rtl2832.h"
31#include "rtl2832_sdr.h"
32#include "mn88472.h"
33#include "mn88473.h"
34
35#include "qt1010.h"
36#include "mt2060.h"
37#include "mxl5005s.h"
38#include "fc0012.h"
39#include "fc0013.h"
40#include "e4000.h"
41#include "fc2580.h"
42#include "tua9001.h"
43#include "r820t.h"
44
27/* 45/*
28 * USB commands 46 * USB commands
29 * (usb_control_msg() index parameter) 47 * (usb_control_msg() index parameter)
@@ -50,19 +68,26 @@
50#define CMD_I2C_DA_WR 0x0610 68#define CMD_I2C_DA_WR 0x0610
51 69
52 70
53struct rtl28xxu_priv { 71struct rtl28xxu_dev {
72 u8 buf[28];
54 u8 chip_id; 73 u8 chip_id;
55 u8 tuner; 74 u8 tuner;
56 char *tuner_name; 75 char *tuner_name;
57 u8 page; /* integrated demod active register page */ 76 u8 page; /* integrated demod active register page */
58 struct i2c_adapter *demod_i2c_adapter; 77 struct i2c_adapter *demod_i2c_adapter;
59 bool rc_active; 78 bool rc_active;
79 struct i2c_client *i2c_client_demod;
60 struct i2c_client *i2c_client_tuner; 80 struct i2c_client *i2c_client_tuner;
61 struct i2c_client *i2c_client_slave_demod; 81 struct i2c_client *i2c_client_slave_demod;
82 struct platform_device *platform_device_sdr;
62 #define SLAVE_DEMOD_NONE 0 83 #define SLAVE_DEMOD_NONE 0
63 #define SLAVE_DEMOD_MN88472 1 84 #define SLAVE_DEMOD_MN88472 1
64 #define SLAVE_DEMOD_MN88473 2 85 #define SLAVE_DEMOD_MN88473 2
65 unsigned int slave_demod:2; 86 unsigned int slave_demod:2;
87 union {
88 struct rtl2830_platform_data rtl2830_platform_data;
89 struct rtl2832_platform_data rtl2832_platform_data;
90 };
66}; 91};
67 92
68enum rtl28xxu_chip_id { 93enum rtl28xxu_chip_id {
diff --git a/drivers/media/usb/dvb-usb/m920x.c b/drivers/media/usb/dvb-usb/m920x.c
index abf8ab2e02e5..eafc5c82467f 100644
--- a/drivers/media/usb/dvb-usb/m920x.c
+++ b/drivers/media/usb/dvb-usb/m920x.c
@@ -1269,8 +1269,3 @@ MODULE_AUTHOR("Aapo Tahkola <aet@rasterburn.org>");
1269MODULE_DESCRIPTION("DVB Driver for ULI M920x"); 1269MODULE_DESCRIPTION("DVB Driver for ULI M920x");
1270MODULE_VERSION("0.1"); 1270MODULE_VERSION("0.1");
1271MODULE_LICENSE("GPL"); 1271MODULE_LICENSE("GPL");
1272
1273/*
1274 * Local variables:
1275 * c-basic-offset: 8
1276 */
diff --git a/drivers/media/usb/em28xx/em28xx-audio.c b/drivers/media/usb/em28xx/em28xx-audio.c
index 44ae1e0661e6..49a5f9532bd8 100644
--- a/drivers/media/usb/em28xx/em28xx-audio.c
+++ b/drivers/media/usb/em28xx/em28xx-audio.c
@@ -820,7 +820,7 @@ static int em28xx_audio_urb_init(struct em28xx *dev)
820 if (urb_size > ep_size * npackets) 820 if (urb_size > ep_size * npackets)
821 npackets = DIV_ROUND_UP(urb_size, ep_size); 821 npackets = DIV_ROUND_UP(urb_size, ep_size);
822 822
823 em28xx_info("Number of URBs: %d, with %d packets and %d size", 823 em28xx_info("Number of URBs: %d, with %d packets and %d size\n",
824 num_urb, npackets, urb_size); 824 num_urb, npackets, urb_size);
825 825
826 /* Estimate the bytes per period */ 826 /* Estimate the bytes per period */
@@ -981,7 +981,7 @@ static int em28xx_audio_fini(struct em28xx *dev)
981 return 0; 981 return 0;
982 } 982 }
983 983
984 em28xx_info("Closing audio extension"); 984 em28xx_info("Closing audio extension\n");
985 985
986 if (dev->adev.sndcard) { 986 if (dev->adev.sndcard) {
987 snd_card_disconnect(dev->adev.sndcard); 987 snd_card_disconnect(dev->adev.sndcard);
@@ -1005,7 +1005,7 @@ static int em28xx_audio_suspend(struct em28xx *dev)
1005 if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) 1005 if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
1006 return 0; 1006 return 0;
1007 1007
1008 em28xx_info("Suspending audio extension"); 1008 em28xx_info("Suspending audio extension\n");
1009 em28xx_deinit_isoc_audio(dev); 1009 em28xx_deinit_isoc_audio(dev);
1010 atomic_set(&dev->adev.stream_started, 0); 1010 atomic_set(&dev->adev.stream_started, 0);
1011 return 0; 1011 return 0;
@@ -1019,7 +1019,7 @@ static int em28xx_audio_resume(struct em28xx *dev)
1019 if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR) 1019 if (dev->usb_audio_type != EM28XX_USB_AUDIO_VENDOR)
1020 return 0; 1020 return 0;
1021 1021
1022 em28xx_info("Resuming audio extension"); 1022 em28xx_info("Resuming audio extension\n");
1023 /* Nothing to do other than schedule_work() ?? */ 1023 /* Nothing to do other than schedule_work() ?? */
1024 schedule_work(&dev->adev.wq_trigger); 1024 schedule_work(&dev->adev.wq_trigger);
1025 return 0; 1025 return 0;
diff --git a/drivers/media/usb/em28xx/em28xx-core.c b/drivers/media/usb/em28xx/em28xx-core.c
index 86461a708abe..37456079f490 100644
--- a/drivers/media/usb/em28xx/em28xx-core.c
+++ b/drivers/media/usb/em28xx/em28xx-core.c
@@ -1125,7 +1125,7 @@ int em28xx_suspend_extension(struct em28xx *dev)
1125{ 1125{
1126 const struct em28xx_ops *ops = NULL; 1126 const struct em28xx_ops *ops = NULL;
1127 1127
1128 em28xx_info("Suspending extensions"); 1128 em28xx_info("Suspending extensions\n");
1129 mutex_lock(&em28xx_devlist_mutex); 1129 mutex_lock(&em28xx_devlist_mutex);
1130 list_for_each_entry(ops, &em28xx_extension_devlist, next) { 1130 list_for_each_entry(ops, &em28xx_extension_devlist, next) {
1131 if (ops->suspend) 1131 if (ops->suspend)
@@ -1139,7 +1139,7 @@ int em28xx_resume_extension(struct em28xx *dev)
1139{ 1139{
1140 const struct em28xx_ops *ops = NULL; 1140 const struct em28xx_ops *ops = NULL;
1141 1141
1142 em28xx_info("Resuming extensions"); 1142 em28xx_info("Resuming extensions\n");
1143 mutex_lock(&em28xx_devlist_mutex); 1143 mutex_lock(&em28xx_devlist_mutex);
1144 list_for_each_entry(ops, &em28xx_extension_devlist, next) { 1144 list_for_each_entry(ops, &em28xx_extension_devlist, next) {
1145 if (ops->resume) 1145 if (ops->resume)
diff --git a/drivers/media/usb/em28xx/em28xx-dvb.c b/drivers/media/usb/em28xx/em28xx-dvb.c
index 9877b699c6bc..aee70d483264 100644
--- a/drivers/media/usb/em28xx/em28xx-dvb.c
+++ b/drivers/media/usb/em28xx/em28xx-dvb.c
@@ -1724,7 +1724,7 @@ static int em28xx_dvb_fini(struct em28xx *dev)
1724 if (!dev->dvb) 1724 if (!dev->dvb)
1725 return 0; 1725 return 0;
1726 1726
1727 em28xx_info("Closing DVB extension"); 1727 em28xx_info("Closing DVB extension\n");
1728 1728
1729 dvb = dev->dvb; 1729 dvb = dev->dvb;
1730 client = dvb->i2c_client_tuner; 1730 client = dvb->i2c_client_tuner;
@@ -1775,17 +1775,17 @@ static int em28xx_dvb_suspend(struct em28xx *dev)
1775 if (!dev->board.has_dvb) 1775 if (!dev->board.has_dvb)
1776 return 0; 1776 return 0;
1777 1777
1778 em28xx_info("Suspending DVB extension"); 1778 em28xx_info("Suspending DVB extension\n");
1779 if (dev->dvb) { 1779 if (dev->dvb) {
1780 struct em28xx_dvb *dvb = dev->dvb; 1780 struct em28xx_dvb *dvb = dev->dvb;
1781 1781
1782 if (dvb->fe[0]) { 1782 if (dvb->fe[0]) {
1783 ret = dvb_frontend_suspend(dvb->fe[0]); 1783 ret = dvb_frontend_suspend(dvb->fe[0]);
1784 em28xx_info("fe0 suspend %d", ret); 1784 em28xx_info("fe0 suspend %d\n", ret);
1785 } 1785 }
1786 if (dvb->fe[1]) { 1786 if (dvb->fe[1]) {
1787 dvb_frontend_suspend(dvb->fe[1]); 1787 dvb_frontend_suspend(dvb->fe[1]);
1788 em28xx_info("fe1 suspend %d", ret); 1788 em28xx_info("fe1 suspend %d\n", ret);
1789 } 1789 }
1790 } 1790 }
1791 1791
@@ -1802,18 +1802,18 @@ static int em28xx_dvb_resume(struct em28xx *dev)
1802 if (!dev->board.has_dvb) 1802 if (!dev->board.has_dvb)
1803 return 0; 1803 return 0;
1804 1804
1805 em28xx_info("Resuming DVB extension"); 1805 em28xx_info("Resuming DVB extension\n");
1806 if (dev->dvb) { 1806 if (dev->dvb) {
1807 struct em28xx_dvb *dvb = dev->dvb; 1807 struct em28xx_dvb *dvb = dev->dvb;
1808 1808
1809 if (dvb->fe[0]) { 1809 if (dvb->fe[0]) {
1810 ret = dvb_frontend_resume(dvb->fe[0]); 1810 ret = dvb_frontend_resume(dvb->fe[0]);
1811 em28xx_info("fe0 resume %d", ret); 1811 em28xx_info("fe0 resume %d\n", ret);
1812 } 1812 }
1813 1813
1814 if (dvb->fe[1]) { 1814 if (dvb->fe[1]) {
1815 ret = dvb_frontend_resume(dvb->fe[1]); 1815 ret = dvb_frontend_resume(dvb->fe[1]);
1816 em28xx_info("fe1 resume %d", ret); 1816 em28xx_info("fe1 resume %d\n", ret);
1817 } 1817 }
1818 } 1818 }
1819 1819
diff --git a/drivers/media/usb/em28xx/em28xx-input.c b/drivers/media/usb/em28xx/em28xx-input.c
index d8dc03aadfbd..4007356d991d 100644
--- a/drivers/media/usb/em28xx/em28xx-input.c
+++ b/drivers/media/usb/em28xx/em28xx-input.c
@@ -654,8 +654,6 @@ next_button:
654 if (dev->num_button_polling_addresses) { 654 if (dev->num_button_polling_addresses) {
655 memset(dev->button_polling_last_values, 0, 655 memset(dev->button_polling_last_values, 0,
656 EM28XX_NUM_BUTTON_ADDRESSES_MAX); 656 EM28XX_NUM_BUTTON_ADDRESSES_MAX);
657 INIT_DELAYED_WORK(&dev->buttons_query_work,
658 em28xx_query_buttons);
659 schedule_delayed_work(&dev->buttons_query_work, 657 schedule_delayed_work(&dev->buttons_query_work,
660 msecs_to_jiffies(dev->button_polling_interval)); 658 msecs_to_jiffies(dev->button_polling_interval));
661 } 659 }
@@ -689,6 +687,7 @@ static int em28xx_ir_init(struct em28xx *dev)
689 } 687 }
690 688
691 kref_get(&dev->ref); 689 kref_get(&dev->ref);
690 INIT_DELAYED_WORK(&dev->buttons_query_work, em28xx_query_buttons);
692 691
693 if (dev->board.buttons) 692 if (dev->board.buttons)
694 em28xx_init_buttons(dev); 693 em28xx_init_buttons(dev);
@@ -833,7 +832,7 @@ static int em28xx_ir_fini(struct em28xx *dev)
833 return 0; 832 return 0;
834 } 833 }
835 834
836 em28xx_info("Closing input extension"); 835 em28xx_info("Closing input extension\n");
837 836
838 em28xx_shutdown_buttons(dev); 837 em28xx_shutdown_buttons(dev);
839 838
@@ -862,7 +861,7 @@ static int em28xx_ir_suspend(struct em28xx *dev)
862 if (dev->is_audio_only) 861 if (dev->is_audio_only)
863 return 0; 862 return 0;
864 863
865 em28xx_info("Suspending input extension"); 864 em28xx_info("Suspending input extension\n");
866 if (ir) 865 if (ir)
867 cancel_delayed_work_sync(&ir->work); 866 cancel_delayed_work_sync(&ir->work);
868 cancel_delayed_work_sync(&dev->buttons_query_work); 867 cancel_delayed_work_sync(&dev->buttons_query_work);
@@ -879,7 +878,7 @@ static int em28xx_ir_resume(struct em28xx *dev)
879 if (dev->is_audio_only) 878 if (dev->is_audio_only)
880 return 0; 879 return 0;
881 880
882 em28xx_info("Resuming input extension"); 881 em28xx_info("Resuming input extension\n");
883 /* if suspend calls ir_raw_event_unregister(), the should call 882 /* if suspend calls ir_raw_event_unregister(), the should call
884 ir_raw_event_register() */ 883 ir_raw_event_register() */
885 if (ir) 884 if (ir)
diff --git a/drivers/media/usb/em28xx/em28xx-video.c b/drivers/media/usb/em28xx/em28xx-video.c
index cf7f58b76292..9ecf65629b3d 100644
--- a/drivers/media/usb/em28xx/em28xx-video.c
+++ b/drivers/media/usb/em28xx/em28xx-video.c
@@ -1958,7 +1958,7 @@ static int em28xx_v4l2_fini(struct em28xx *dev)
1958 if (v4l2 == NULL) 1958 if (v4l2 == NULL)
1959 return 0; 1959 return 0;
1960 1960
1961 em28xx_info("Closing video extension"); 1961 em28xx_info("Closing video extension\n");
1962 1962
1963 mutex_lock(&dev->lock); 1963 mutex_lock(&dev->lock);
1964 1964
@@ -2007,7 +2007,7 @@ static int em28xx_v4l2_suspend(struct em28xx *dev)
2007 if (!dev->has_video) 2007 if (!dev->has_video)
2008 return 0; 2008 return 0;
2009 2009
2010 em28xx_info("Suspending video extension"); 2010 em28xx_info("Suspending video extension\n");
2011 em28xx_stop_urbs(dev); 2011 em28xx_stop_urbs(dev);
2012 return 0; 2012 return 0;
2013} 2013}
@@ -2020,7 +2020,7 @@ static int em28xx_v4l2_resume(struct em28xx *dev)
2020 if (!dev->has_video) 2020 if (!dev->has_video)
2021 return 0; 2021 return 0;
2022 2022
2023 em28xx_info("Resuming video extension"); 2023 em28xx_info("Resuming video extension\n");
2024 /* what do we do here */ 2024 /* what do we do here */
2025 return 0; 2025 return 0;
2026} 2026}
@@ -2192,7 +2192,6 @@ static struct video_device
2192 2192
2193 *vfd = *template; 2193 *vfd = *template;
2194 vfd->v4l2_dev = &dev->v4l2->v4l2_dev; 2194 vfd->v4l2_dev = &dev->v4l2->v4l2_dev;
2195 vfd->debug = video_debug;
2196 vfd->lock = &dev->lock; 2195 vfd->lock = &dev->lock;
2197 if (dev->board.is_webcam) 2196 if (dev->board.is_webcam)
2198 vfd->tvnorms = 0; 2197 vfd->tvnorms = 0;
diff --git a/drivers/media/usb/gspca/Kconfig b/drivers/media/usb/gspca/Kconfig
index eed10d782535..60af3b167f3b 100644
--- a/drivers/media/usb/gspca/Kconfig
+++ b/drivers/media/usb/gspca/Kconfig
@@ -395,6 +395,16 @@ config USB_GSPCA_TOPRO
395 To compile this driver as a module, choose M here: the 395 To compile this driver as a module, choose M here: the
396 module will be called gspca_topro. 396 module will be called gspca_topro.
397 397
398config USB_GSPCA_TOUPTEK
399 tristate "Touptek USB Camera Driver"
400 depends on VIDEO_V4L2 && USB_GSPCA
401 help
402 Say Y here if you want support for cameras based on the ToupTek UCMOS
403 / AmScope MU series camera.
404
405 To compile this driver as a module, choose M here: the
406 module will be called gspca_touptek.
407
398config USB_GSPCA_TV8532 408config USB_GSPCA_TV8532
399 tristate "TV8532 USB Camera Driver" 409 tristate "TV8532 USB Camera Driver"
400 depends on VIDEO_V4L2 && USB_GSPCA 410 depends on VIDEO_V4L2 && USB_GSPCA
diff --git a/drivers/media/usb/gspca/Makefile b/drivers/media/usb/gspca/Makefile
index f46975e4c82d..9f5ccecb9c8a 100644
--- a/drivers/media/usb/gspca/Makefile
+++ b/drivers/media/usb/gspca/Makefile
@@ -39,6 +39,7 @@ obj-$(CONFIG_USB_GSPCA_STK1135) += gspca_stk1135.o
39obj-$(CONFIG_USB_GSPCA_STV0680) += gspca_stv0680.o 39obj-$(CONFIG_USB_GSPCA_STV0680) += gspca_stv0680.o
40obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o 40obj-$(CONFIG_USB_GSPCA_T613) += gspca_t613.o
41obj-$(CONFIG_USB_GSPCA_TOPRO) += gspca_topro.o 41obj-$(CONFIG_USB_GSPCA_TOPRO) += gspca_topro.o
42obj-$(CONFIG_USB_GSPCA_TOUPTEK) += gspca_touptek.o
42obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o 43obj-$(CONFIG_USB_GSPCA_TV8532) += gspca_tv8532.o
43obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o 44obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o
44obj-$(CONFIG_USB_GSPCA_VICAM) += gspca_vicam.o 45obj-$(CONFIG_USB_GSPCA_VICAM) += gspca_vicam.o
@@ -86,6 +87,7 @@ gspca_stv0680-objs := stv0680.o
86gspca_sunplus-objs := sunplus.o 87gspca_sunplus-objs := sunplus.o
87gspca_t613-objs := t613.o 88gspca_t613-objs := t613.o
88gspca_topro-objs := topro.o 89gspca_topro-objs := topro.o
90gspca_touptek-objs := touptek.o
89gspca_tv8532-objs := tv8532.o 91gspca_tv8532-objs := tv8532.o
90gspca_vc032x-objs := vc032x.o 92gspca_vc032x-objs := vc032x.o
91gspca_vicam-objs := vicam.o 93gspca_vicam-objs := vicam.o
diff --git a/drivers/media/usb/gspca/gspca.c b/drivers/media/usb/gspca/gspca.c
index 43d65057a5fe..e54cee856a80 100644
--- a/drivers/media/usb/gspca/gspca.c
+++ b/drivers/media/usb/gspca/gspca.c
@@ -1562,7 +1562,7 @@ static int vidioc_s_parm(struct file *filp, void *priv,
1562 struct v4l2_streamparm *parm) 1562 struct v4l2_streamparm *parm)
1563{ 1563{
1564 struct gspca_dev *gspca_dev = video_drvdata(filp); 1564 struct gspca_dev *gspca_dev = video_drvdata(filp);
1565 int n; 1565 unsigned int n;
1566 1566
1567 n = parm->parm.capture.readbuffers; 1567 n = parm->parm.capture.readbuffers;
1568 if (n == 0 || n >= GSPCA_MAX_FRAMES) 1568 if (n == 0 || n >= GSPCA_MAX_FRAMES)
diff --git a/drivers/media/usb/gspca/ov534.c b/drivers/media/usb/gspca/ov534.c
index 90f0d637cd9d..a9c866d6d82d 100644
--- a/drivers/media/usb/gspca/ov534.c
+++ b/drivers/media/usb/gspca/ov534.c
@@ -12,6 +12,8 @@
12 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr 12 * PS3 Eye camera enhanced by Richard Kaswy http://kaswy.free.fr
13 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls 13 * PS3 Eye camera - brightness, contrast, awb, agc, aec controls
14 * added by Max Thrun <bear24rw@gmail.com> 14 * added by Max Thrun <bear24rw@gmail.com>
15 * PS3 Eye camera - FPS range extended by Joseph Howse
16 * <josephhowse@nummist.com> http://nummist.com
15 * 17 *
16 * This program is free software; you can redistribute it and/or modify 18 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by 19 * it under the terms of the GNU General Public License as published by
@@ -116,7 +118,7 @@ static const struct v4l2_pix_format ov767x_mode[] = {
116 .colorspace = V4L2_COLORSPACE_JPEG}, 118 .colorspace = V4L2_COLORSPACE_JPEG},
117}; 119};
118 120
119static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30}; 121static const u8 qvga_rates[] = {187, 150, 137, 125, 100, 75, 60, 50, 37, 30};
120static const u8 vga_rates[] = {60, 50, 40, 30, 15}; 122static const u8 vga_rates[] = {60, 50, 40, 30, 15};
121 123
122static const struct framerates ov772x_framerates[] = { 124static const struct framerates ov772x_framerates[] = {
@@ -769,12 +771,16 @@ static void set_frame_rate(struct gspca_dev *gspca_dev)
769 {15, 0x03, 0x41, 0x04}, 771 {15, 0x03, 0x41, 0x04},
770 }; 772 };
771 static const struct rate_s rate_1[] = { /* 320x240 */ 773 static const struct rate_s rate_1[] = { /* 320x240 */
774/* {205, 0x01, 0xc1, 0x02}, * 205 FPS: video is partly corrupt */
775 {187, 0x01, 0x81, 0x02}, /* 187 FPS or below: video is valid */
776 {150, 0x01, 0xc1, 0x04},
777 {137, 0x02, 0xc1, 0x02},
772 {125, 0x02, 0x81, 0x02}, 778 {125, 0x02, 0x81, 0x02},
773 {100, 0x02, 0xc1, 0x04}, 779 {100, 0x02, 0xc1, 0x04},
774 {75, 0x03, 0xc1, 0x04}, 780 {75, 0x03, 0xc1, 0x04},
775 {60, 0x04, 0xc1, 0x04}, 781 {60, 0x04, 0xc1, 0x04},
776 {50, 0x02, 0x41, 0x04}, 782 {50, 0x02, 0x41, 0x04},
777 {40, 0x03, 0x41, 0x04}, 783 {37, 0x03, 0x41, 0x04},
778 {30, 0x04, 0x41, 0x04}, 784 {30, 0x04, 0x41, 0x04},
779 }; 785 };
780 786
diff --git a/drivers/media/usb/gspca/stv06xx/stv06xx.c b/drivers/media/usb/gspca/stv06xx/stv06xx.c
index 49d209bbf9ee..6ac93d8db427 100644
--- a/drivers/media/usb/gspca/stv06xx/stv06xx.c
+++ b/drivers/media/usb/gspca/stv06xx/stv06xx.c
@@ -505,13 +505,13 @@ static int sd_int_pkt_scan(struct gspca_dev *gspca_dev,
505{ 505{
506 int ret = -EINVAL; 506 int ret = -EINVAL;
507 507
508 if (len == 1 && data[0] == 0x80) { 508 if (len == 1 && (data[0] == 0x80 || data[0] == 0x10)) {
509 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); 509 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1);
510 input_sync(gspca_dev->input_dev); 510 input_sync(gspca_dev->input_dev);
511 ret = 0; 511 ret = 0;
512 } 512 }
513 513
514 if (len == 1 && data[0] == 0x88) { 514 if (len == 1 && (data[0] == 0x88 || data[0] == 0x11)) {
515 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); 515 input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0);
516 input_sync(gspca_dev->input_dev); 516 input_sync(gspca_dev->input_dev);
517 ret = 0; 517 ret = 0;
diff --git a/drivers/media/usb/gspca/touptek.c b/drivers/media/usb/gspca/touptek.c
new file mode 100644
index 000000000000..7bac6bc96063
--- /dev/null
+++ b/drivers/media/usb/gspca/touptek.c
@@ -0,0 +1,731 @@
1/*
2 * ToupTek UCMOS / AmScope MU series camera driver
3 * TODO: contrast with ScopeTek / AmScope MDC cameras
4 *
5 * Copyright (C) 2012-2014 John McMaster <JohnDMcMaster@gmail.com>
6 *
7 * Special thanks to Bushing for helping with the decrypt algorithm and
8 * Sean O'Sullivan / the Rensselaer Center for Open Source
9 * Software (RCOS) for helping me learn kernel development
10 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 */
21
22#include "gspca.h"
23
24#define MODULE_NAME "touptek"
25
26MODULE_AUTHOR("John McMaster");
27MODULE_DESCRIPTION("ToupTek UCMOS / Amscope MU microscope camera driver");
28MODULE_LICENSE("GPL");
29
30/*
31 * Exposure reg is linear with exposure time
32 * Exposure (sec), E (reg)
33 * 0.000400, 0x0002
34 * 0.001000, 0x0005
35 * 0.005000, 0x0019
36 * 0.020000, 0x0064
37 * 0.080000, 0x0190
38 * 0.400000, 0x07D0
39 * 1.000000, 0x1388
40 * 2.000000, 0x2710
41 *
42 * Three gain stages
43 * 0x1000: master channel enable bit
44 * 0x007F: low gain bits
45 * 0x0080: medium gain bit
46 * 0x0100: high gain bit
47 * gain = enable * (1 + regH) * (1 + regM) * z * regL
48 *
49 * Gain implementation
50 * Want to do something similar to mt9v011.c's set_balance
51 *
52 * Gain does not vary with resolution (checked 640x480 vs 1600x1200)
53 *
54 * Constant derivation:
55 *
56 * Raw data:
57 * Gain, GTOP, B, R, GBOT
58 * 1.00, 0x105C, 0x1068, 0x10C8, 0x105C
59 * 1.20, 0x106E, 0x107E, 0x10D6, 0x106E
60 * 1.40, 0x10C0, 0x10CA, 0x10E5, 0x10C0
61 * 1.60, 0x10C9, 0x10D4, 0x10F3, 0x10C9
62 * 1.80, 0x10D2, 0x10DE, 0x11C1, 0x10D2
63 * 2.00, 0x10DC, 0x10E9, 0x11C8, 0x10DC
64 * 2.20, 0x10E5, 0x10F3, 0x11CF, 0x10E5
65 * 2.40, 0x10EE, 0x10FE, 0x11D7, 0x10EE
66 * 2.60, 0x10F7, 0x11C4, 0x11DE, 0x10F7
67 * 2.80, 0x11C0, 0x11CA, 0x11E5, 0x11C0
68 * 3.00, 0x11C5, 0x11CF, 0x11ED, 0x11C5
69 *
70 * zR = 0.0069605943152454778
71 * about 3/431 = 0.0069605568445475635
72 * zB = 0.0095695970695970703
73 * about 6/627 = 0.0095693779904306216
74 * zG = 0.010889328063241107
75 * about 6/551 = 0.010889292196007259
76 * about 10 bits for constant + 7 bits for value => at least 17 bit
77 * intermediate with 32 bit ints should be fine for overflow etc
78 * Essentially gains are in range 0-0x001FF
79 *
80 * However, V4L expects a main gain channel + R and B balance
81 * To keep things simple for now saturate the values of balance is too high/low
82 * This isn't really ideal but easy way to fit the Linux model
83 *
84 * Converted using gain model turns out to be quite linear:
85 * Gain, GTOP, B, R, GBOT
86 * 1.00, 92, 104, 144, 92
87 * 1.20, 110, 126, 172, 110
88 * 1.40, 128, 148, 202, 128
89 * 1.60, 146, 168, 230, 146
90 * 1.80, 164, 188, 260, 164
91 * 2.00, 184, 210, 288, 184
92 * 2.20, 202, 230, 316, 202
93 * 2.40, 220, 252, 348, 220
94 * 2.60, 238, 272, 376, 238
95 * 2.80, 256, 296, 404, 256
96 * 3.00, 276, 316, 436, 276
97 *
98 * Maximum gain is 0x7FF * 2 * 2 => 0x1FFC (8188)
99 * or about 13 effective bits of gain
100 * The highest the commercial driver goes in my setup 436
101 * However, because could *maybe* damage circuits
102 * limit the gain until have a reason to go higher
103 * Solution: gain clipped and warning emitted
104 */
105#define GAIN_MAX 511
106
107/* Frame sync is a short read */
108#define BULK_SIZE 0x4000
109
110/* MT9E001 reg names to give a rough approximation */
111#define REG_COARSE_INTEGRATION_TIME_ 0x3012
112#define REG_GROUPED_PARAMETER_HOLD_ 0x3022
113#define REG_MODE_SELECT 0x0100
114#define REG_OP_SYS_CLK_DIV 0x030A
115#define REG_VT_SYS_CLK_DIV 0x0302
116#define REG_PRE_PLL_CLK_DIV 0x0304
117#define REG_VT_PIX_CLK_DIV 0x0300
118#define REG_OP_PIX_CLK_DIV 0x0308
119#define REG_PLL_MULTIPLIER 0x0306
120#define REG_COARSE_INTEGRATION_TIME_ 0x3012
121#define REG_FRAME_LENGTH_LINES 0x0340
122#define REG_FRAME_LENGTH_LINES_ 0x300A
123#define REG_GREEN1_GAIN 0x3056
124#define REG_GREEN2_GAIN 0x305C
125#define REG_GROUPED_PARAMETER_HOLD 0x0104
126#define REG_LINE_LENGTH_PCK_ 0x300C
127#define REG_MODE_SELECT 0x0100
128#define REG_PLL_MULTIPLIER 0x0306
129#define REG_READ_MODE 0x3040
130#define REG_BLUE_GAIN 0x3058
131#define REG_RED_GAIN 0x305A
132#define REG_RESET_REGISTER 0x301A
133#define REG_SCALE_M 0x0404
134#define REG_SCALING_MODE 0x0400
135#define REG_SOFTWARE_RESET 0x0103
136#define REG_X_ADDR_END 0x0348
137#define REG_X_ADDR_START 0x0344
138#define REG_X_ADDR_START 0x0344
139#define REG_X_OUTPUT_SIZE 0x034C
140#define REG_Y_ADDR_END 0x034A
141#define REG_Y_ADDR_START 0x0346
142#define REG_Y_OUTPUT_SIZE 0x034E
143
144
145/* specific webcam descriptor */
146struct sd {
147 struct gspca_dev gspca_dev; /* !! must be the first item */
148 /* How many bytes this frame */
149 unsigned int this_f;
150
151 /*
152 Device has separate gains for each Bayer quadrant
153 V4L supports master gain which is referenced to G1/G2 and supplies
154 individual balance controls for R/B
155 */
156 struct v4l2_ctrl *blue;
157 struct v4l2_ctrl *red;
158};
159
160/* Used to simplify reg write error handling */
161struct cmd {
162 u16 value;
163 u16 index;
164};
165
166static const struct v4l2_pix_format vga_mode[] = {
167 {800, 600,
168 V4L2_PIX_FMT_SGRBG8,
169 V4L2_FIELD_NONE,
170 .bytesperline = 800,
171 .sizeimage = 800 * 600,
172 .colorspace = V4L2_COLORSPACE_SRGB},
173 {1600, 1200,
174 V4L2_PIX_FMT_SGRBG8,
175 V4L2_FIELD_NONE,
176 .bytesperline = 1600,
177 .sizeimage = 1600 * 1200,
178 .colorspace = V4L2_COLORSPACE_SRGB},
179 {3264, 2448,
180 V4L2_PIX_FMT_SGRBG8,
181 V4L2_FIELD_NONE,
182 .bytesperline = 3264,
183 .sizeimage = 3264 * 2448,
184 .colorspace = V4L2_COLORSPACE_SRGB},
185};
186
187/*
188 * As theres no known frame sync, the only way to keep synced is to try hard
189 * to never miss any packets
190 */
191#if MAX_NURBS < 4
192#error "Not enough URBs in the gspca table"
193#endif
194
195static int val_reply(struct gspca_dev *gspca_dev, const char *reply, int rc)
196{
197 if (rc < 0) {
198 PERR("reply has error %d", rc);
199 return -EIO;
200 }
201 if (rc != 1) {
202 PERR("Bad reply size %d", rc);
203 return -EIO;
204 }
205 if (reply[0] != 0x08) {
206 PERR("Bad reply 0x%02X", reply[0]);
207 return -EIO;
208 }
209 return 0;
210}
211
212static void reg_w(struct gspca_dev *gspca_dev, u16 value, u16 index)
213{
214 char buff[1];
215 int rc;
216
217 PDEBUG(D_USBO,
218 "reg_w bReq=0x0B, bReqT=0xC0, wVal=0x%04X, wInd=0x%04X\n",
219 value, index);
220 rc = usb_control_msg(gspca_dev->dev, usb_rcvctrlpipe(gspca_dev->dev, 0),
221 0x0B, 0xC0, value, index, buff, 1, 500);
222 PDEBUG(D_USBO, "rc=%d, ret={0x%02X}", rc, buff[0]);
223 if (rc < 0) {
224 PERR("Failed reg_w(0x0B, 0xC0, 0x%04X, 0x%04X) w/ rc %d\n",
225 value, index, rc);
226 gspca_dev->usb_err = rc;
227 return;
228 }
229 if (val_reply(gspca_dev, buff, rc)) {
230 PERR("Bad reply to reg_w(0x0B, 0xC0, 0x%04X, 0x%04X\n",
231 value, index);
232 gspca_dev->usb_err = -EIO;
233 }
234}
235
236static void reg_w_buf(struct gspca_dev *gspca_dev,
237 const struct cmd *p, int l)
238{
239 do {
240 reg_w(gspca_dev, p->value, p->index);
241 p++;
242 } while (--l > 0);
243}
244
245static void setexposure(struct gspca_dev *gspca_dev, s32 val)
246{
247 u16 value;
248 unsigned int w = gspca_dev->pixfmt.width;
249
250 if (w == 800)
251 value = val * 5;
252 else if (w == 1600)
253 value = val * 3;
254 else if (w == 3264)
255 value = val * 3 / 2;
256 else {
257 PERR("Invalid width %u\n", w);
258 gspca_dev->usb_err = -EINVAL;
259 return;
260 }
261 PDEBUG(D_STREAM, "exposure: 0x%04X ms\n", value);
262 /* Wonder if theres a good reason for sending it twice */
263 /* probably not but leave it in because...why not */
264 reg_w(gspca_dev, value, REG_COARSE_INTEGRATION_TIME_);
265 reg_w(gspca_dev, value, REG_COARSE_INTEGRATION_TIME_);
266}
267
268static int gainify(int in)
269{
270 /*
271 * TODO: check if there are any issues with corner cases
272 * 0x000 (0):0x07F (127): regL
273 * 0x080 (128) - 0x0FF (255): regM, regL
274 * 0x100 (256) - max: regH, regM, regL
275 */
276 if (in <= 0x7F)
277 return 0x1000 | in;
278 else if (in <= 0xFF)
279 return 0x1080 | in / 2;
280 else
281 return 0x1180 | in / 4;
282}
283
284static void setggain(struct gspca_dev *gspca_dev, u16 global_gain)
285{
286 u16 normalized;
287
288 normalized = gainify(global_gain);
289 PDEBUG(D_STREAM, "gain G1/G2 (0x%04X): 0x%04X (src 0x%04X)\n",
290 REG_GREEN1_GAIN,
291 normalized, global_gain);
292
293 reg_w(gspca_dev, normalized, REG_GREEN1_GAIN);
294 reg_w(gspca_dev, normalized, REG_GREEN2_GAIN);
295}
296
297static void setbgain(struct gspca_dev *gspca_dev,
298 u16 gain, u16 global_gain)
299{
300 u16 normalized;
301
302 normalized = global_gain +
303 ((u32)global_gain) * gain / GAIN_MAX;
304 if (normalized > GAIN_MAX) {
305 PDEBUG(D_STREAM, "Truncating blue 0x%04X w/ value 0x%04X\n",
306 GAIN_MAX, normalized);
307 normalized = GAIN_MAX;
308 }
309 normalized = gainify(normalized);
310 PDEBUG(D_STREAM, "gain B (0x%04X): 0x%04X w/ source 0x%04X\n",
311 REG_BLUE_GAIN, normalized, gain);
312
313 reg_w(gspca_dev, normalized, REG_BLUE_GAIN);
314}
315
316static void setrgain(struct gspca_dev *gspca_dev,
317 u16 gain, u16 global_gain)
318{
319 u16 normalized;
320
321 normalized = global_gain +
322 ((u32)global_gain) * gain / GAIN_MAX;
323 if (normalized > GAIN_MAX) {
324 PDEBUG(D_STREAM, "Truncating gain 0x%04X w/ value 0x%04X\n",
325 GAIN_MAX, normalized);
326 normalized = GAIN_MAX;
327 }
328 normalized = gainify(normalized);
329 PDEBUG(D_STREAM, "gain R (0x%04X): 0x%04X w / source 0x%04X\n",
330 REG_RED_GAIN, normalized, gain);
331
332 reg_w(gspca_dev, normalized, REG_RED_GAIN);
333}
334
335static void configure_wh(struct gspca_dev *gspca_dev)
336{
337 unsigned int w = gspca_dev->pixfmt.width;
338
339 PDEBUG(D_STREAM, "configure_wh\n");
340
341 if (w == 800) {
342 static const struct cmd reg_init_res[] = {
343 {0x0060, REG_X_ADDR_START},
344 {0x0CD9, REG_X_ADDR_END},
345 {0x0036, REG_Y_ADDR_START},
346 {0x098F, REG_Y_ADDR_END},
347 {0x07C7, REG_READ_MODE},
348 };
349
350 reg_w_buf(gspca_dev,
351 reg_init_res, ARRAY_SIZE(reg_init_res));
352 } else if (w == 1600) {
353 static const struct cmd reg_init_res[] = {
354 {0x009C, REG_X_ADDR_START},
355 {0x0D19, REG_X_ADDR_END},
356 {0x0068, REG_Y_ADDR_START},
357 {0x09C5, REG_Y_ADDR_END},
358 {0x06C3, REG_READ_MODE},
359 };
360
361 reg_w_buf(gspca_dev,
362 reg_init_res, ARRAY_SIZE(reg_init_res));
363 } else if (w == 3264) {
364 static const struct cmd reg_init_res[] = {
365 {0x00E8, REG_X_ADDR_START},
366 {0x0DA7, REG_X_ADDR_END},
367 {0x009E, REG_Y_ADDR_START},
368 {0x0A2D, REG_Y_ADDR_END},
369 {0x0241, REG_READ_MODE},
370 };
371
372 reg_w_buf(gspca_dev,
373 reg_init_res, ARRAY_SIZE(reg_init_res));
374 } else {
375 PERR("bad width %u\n", w);
376 gspca_dev->usb_err = -EINVAL;
377 return;
378 }
379
380 reg_w(gspca_dev, 0x0000, REG_SCALING_MODE);
381 reg_w(gspca_dev, 0x0010, REG_SCALE_M);
382 reg_w(gspca_dev, w, REG_X_OUTPUT_SIZE);
383 reg_w(gspca_dev, gspca_dev->pixfmt.height, REG_Y_OUTPUT_SIZE);
384
385 if (w == 800) {
386 reg_w(gspca_dev, 0x0384, REG_FRAME_LENGTH_LINES_);
387 reg_w(gspca_dev, 0x0960, REG_LINE_LENGTH_PCK_);
388 } else if (w == 1600) {
389 reg_w(gspca_dev, 0x0640, REG_FRAME_LENGTH_LINES_);
390 reg_w(gspca_dev, 0x0FA0, REG_LINE_LENGTH_PCK_);
391 } else if (w == 3264) {
392 reg_w(gspca_dev, 0x0B4B, REG_FRAME_LENGTH_LINES_);
393 reg_w(gspca_dev, 0x1F40, REG_LINE_LENGTH_PCK_);
394 } else {
395 PERR("bad width %u\n", w);
396 gspca_dev->usb_err = -EINVAL;
397 return;
398 }
399}
400
401/* Packets that were encrypted, no idea if the grouping is significant */
402static void configure_encrypted(struct gspca_dev *gspca_dev)
403{
404 static const struct cmd reg_init_begin[] = {
405 {0x0100, REG_SOFTWARE_RESET},
406 {0x0000, REG_MODE_SELECT},
407 {0x0100, REG_GROUPED_PARAMETER_HOLD},
408 {0x0004, REG_VT_PIX_CLK_DIV},
409 {0x0001, REG_VT_SYS_CLK_DIV},
410 {0x0008, REG_OP_PIX_CLK_DIV},
411 {0x0001, REG_OP_SYS_CLK_DIV},
412 {0x0004, REG_PRE_PLL_CLK_DIV},
413 {0x0040, REG_PLL_MULTIPLIER},
414 {0x0000, REG_GROUPED_PARAMETER_HOLD},
415 {0x0100, REG_GROUPED_PARAMETER_HOLD},
416 };
417 static const struct cmd reg_init_end[] = {
418 {0x0000, REG_GROUPED_PARAMETER_HOLD},
419 {0x0301, 0x31AE},
420 {0x0805, 0x3064},
421 {0x0071, 0x3170},
422 {0x10DE, REG_RESET_REGISTER},
423 {0x0000, REG_MODE_SELECT},
424 {0x0010, REG_PLL_MULTIPLIER},
425 {0x0100, REG_MODE_SELECT},
426 };
427
428 PDEBUG(D_STREAM, "Encrypted begin, w = %u\n", gspca_dev->pixfmt.width);
429 reg_w_buf(gspca_dev, reg_init_begin, ARRAY_SIZE(reg_init_begin));
430 configure_wh(gspca_dev);
431 reg_w_buf(gspca_dev, reg_init_end, ARRAY_SIZE(reg_init_end));
432 reg_w(gspca_dev, 0x0100, REG_GROUPED_PARAMETER_HOLD);
433 reg_w(gspca_dev, 0x0000, REG_GROUPED_PARAMETER_HOLD);
434
435 PDEBUG(D_STREAM, "Encrypted end\n");
436}
437
438static int configure(struct gspca_dev *gspca_dev)
439{
440 int rc;
441 uint8_t buff[4];
442
443 PDEBUG(D_STREAM, "configure()\n");
444
445 /*
446 * First driver sets a sort of encryption key
447 * A number of futur requests of this type have wValue and wIndex
448 * encrypted as follows:
449 * -Compute key = this wValue rotate left by 4 bits
450 * (decrypt.py rotates right because we are decrypting)
451 * -Later packets encrypt packets by XOR'ing with key
452 * XOR encrypt/decrypt is symmetrical
453 * wValue, and wIndex are encrypted
454 * bRequest is not and bRequestType is always 0xC0
455 * This allows resyncing if key is unknown?
456 * By setting 0 we XOR with 0 and the shifting and XOR drops out
457 */
458 rc = usb_control_msg(gspca_dev->dev, usb_rcvctrlpipe(gspca_dev->dev, 0),
459 0x16, 0xC0, 0x0000, 0x0000, buff, 2, 500);
460 if (val_reply(gspca_dev, buff, rc)) {
461 PERR("failed key req");
462 return -EIO;
463 }
464
465 /*
466 * Next does some sort of 2 packet challenge / response
467 * evidence suggests its an Atmel I2C crypto part but nobody cares to
468 * look
469 * (to make sure its not cloned hardware?)
470 * Ignore: I want to work with their hardware, not clone it
471 * 16 bytes out challenge, requestType: 0x40
472 * 16 bytes in response, requestType: 0xC0
473 */
474
475 rc = usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
476 0x01, 0x40, 0x0001, 0x000F, NULL, 0, 500);
477 if (rc < 0) {
478 PERR("failed to replay packet 176 w/ rc %d\n", rc);
479 return rc;
480 }
481
482 rc = usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
483 0x01, 0x40, 0x0000, 0x000F, NULL, 0, 500);
484 if (rc < 0) {
485 PERR("failed to replay packet 178 w/ rc %d\n", rc);
486 return rc;
487 }
488
489 rc = usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
490 0x01, 0x40, 0x0001, 0x000F, NULL, 0, 500);
491 if (rc < 0) {
492 PERR("failed to replay packet 180 w/ rc %d\n", rc);
493 return rc;
494 }
495
496 /*
497 * Serial number? Doesn't seem to be required
498 * cam1: \xE6\x0D\x00\x00, cam2: \x70\x19\x00\x00
499 * rc = usb_control_msg(gspca_dev->dev,
500 * usb_rcvctrlpipe(gspca_dev->dev, 0),
501 * 0x20, 0xC0, 0x0000, 0x0000, buff, 4, 500);
502 */
503
504 /* Large (EEPROM?) read, skip it since no idea what to do with it */
505 gspca_dev->usb_err = 0;
506 configure_encrypted(gspca_dev);
507 if (gspca_dev->usb_err)
508 return gspca_dev->usb_err;
509
510 /* Omitted this by accident, does not work without it */
511 rc = usb_control_msg(gspca_dev->dev, usb_sndctrlpipe(gspca_dev->dev, 0),
512 0x01, 0x40, 0x0003, 0x000F, NULL, 0, 500);
513 if (rc < 0) {
514 PERR("failed to replay final packet w/ rc %d\n", rc);
515 return rc;
516 }
517
518 PDEBUG(D_STREAM, "Configure complete\n");
519 return 0;
520}
521
522static int sd_config(struct gspca_dev *gspca_dev,
523 const struct usb_device_id *id)
524{
525 gspca_dev->cam.cam_mode = vga_mode;
526 gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode);
527
528 /* Yes we want URBs and we want them now! */
529 gspca_dev->cam.no_urb_create = 0;
530 gspca_dev->cam.bulk_nurbs = 4;
531 /* Largest size the windows driver uses */
532 gspca_dev->cam.bulk_size = BULK_SIZE;
533 /* Def need to use bulk transfers */
534 gspca_dev->cam.bulk = 1;
535
536 return 0;
537}
538
539static int sd_start(struct gspca_dev *gspca_dev)
540{
541 struct sd *sd = (struct sd *) gspca_dev;
542 int rc;
543
544 sd->this_f = 0;
545
546 rc = configure(gspca_dev);
547 if (rc < 0) {
548 PERR("Failed configure");
549 return rc;
550 }
551 /* First two frames have messed up gains
552 Drop them to avoid special cases in user apps? */
553 return 0;
554}
555
556static void sd_pkt_scan(struct gspca_dev *gspca_dev,
557 u8 *data, /* isoc packet */
558 int len) /* iso packet length */
559{
560 struct sd *sd = (struct sd *) gspca_dev;
561
562 if (len != BULK_SIZE) {
563 /* can we finish a frame? */
564 if (sd->this_f + len == gspca_dev->pixfmt.sizeimage) {
565 gspca_frame_add(gspca_dev, LAST_PACKET, data, len);
566 PDEBUG(D_FRAM, "finish frame sz %u/%u w/ len %u\n",
567 sd->this_f, gspca_dev->pixfmt.sizeimage, len);
568 /* lost some data, discard the frame */
569 } else {
570 gspca_frame_add(gspca_dev, DISCARD_PACKET, NULL, 0);
571 PDEBUG(D_FRAM, "abort frame sz %u/%u w/ len %u\n",
572 sd->this_f, gspca_dev->pixfmt.sizeimage, len);
573 }
574 sd->this_f = 0;
575 } else {
576 if (sd->this_f == 0)
577 gspca_frame_add(gspca_dev, FIRST_PACKET, data, len);
578 else
579 gspca_frame_add(gspca_dev, INTER_PACKET, data, len);
580 sd->this_f += len;
581 }
582}
583
584static int sd_init(struct gspca_dev *gspca_dev)
585{
586 return 0;
587}
588
589static int sd_s_ctrl(struct v4l2_ctrl *ctrl)
590{
591 struct gspca_dev *gspca_dev =
592 container_of(ctrl->handler, struct gspca_dev, ctrl_handler);
593 struct sd *sd = (struct sd *) gspca_dev;
594
595 gspca_dev->usb_err = 0;
596
597 if (!gspca_dev->streaming)
598 return 0;
599
600 switch (ctrl->id) {
601 case V4L2_CID_EXPOSURE:
602 setexposure(gspca_dev, ctrl->val);
603 break;
604 case V4L2_CID_GAIN:
605 /* gspca_dev->gain automatically updated */
606 setggain(gspca_dev, gspca_dev->gain->val);
607 break;
608 case V4L2_CID_BLUE_BALANCE:
609 sd->blue->val = ctrl->val;
610 setbgain(gspca_dev, sd->blue->val, gspca_dev->gain->val);
611 break;
612 case V4L2_CID_RED_BALANCE:
613 sd->red->val = ctrl->val;
614 setrgain(gspca_dev, sd->red->val, gspca_dev->gain->val);
615 break;
616 }
617 return gspca_dev->usb_err;
618}
619
620static const struct v4l2_ctrl_ops sd_ctrl_ops = {
621 .s_ctrl = sd_s_ctrl,
622};
623
624static int sd_init_controls(struct gspca_dev *gspca_dev)
625{
626 struct sd *sd = (struct sd *) gspca_dev;
627 struct v4l2_ctrl_handler *hdl = &gspca_dev->ctrl_handler;
628
629 gspca_dev->vdev.ctrl_handler = hdl;
630 v4l2_ctrl_handler_init(hdl, 4);
631
632 gspca_dev->exposure = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
633 /* Mostly limited by URB timeouts */
634 /* XXX: make dynamic based on frame rate? */
635 V4L2_CID_EXPOSURE, 0, 800, 1, 350);
636 gspca_dev->gain = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
637 V4L2_CID_GAIN, 0, 511, 1, 128);
638 sd->blue = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
639 V4L2_CID_BLUE_BALANCE, 0, 1023, 1, 80);
640 sd->red = v4l2_ctrl_new_std(hdl, &sd_ctrl_ops,
641 V4L2_CID_RED_BALANCE, 0, 1023, 1, 295);
642
643 if (hdl->error) {
644 PERR("Could not initialize controls\n");
645 return hdl->error;
646 }
647 return 0;
648}
649
650/* sub-driver description */
651static const struct sd_desc sd_desc = {
652 .name = MODULE_NAME,
653 .config = sd_config,
654 .init = sd_init,
655 .init_controls = sd_init_controls,
656 .start = sd_start,
657 .pkt_scan = sd_pkt_scan,
658};
659
660/* Table of supported USB devices */
661static const struct usb_device_id device_table[] = {
662 /* Commented out devices should be related */
663 /* AS: AmScope, TT: ToupTek */
664 /* { USB_DEVICE(0x0547, 0x6035) }, TT UCMOS00350KPA */
665 /* { USB_DEVICE(0x0547, 0x6130) }, TT UCMOS01300KPA */
666 /* { USB_DEVICE(0x0547, 0x6200) }, TT UCMOS02000KPA */
667 /* { USB_DEVICE(0x0547, 0x6310) }, TT UCMOS03100KPA */
668 /* { USB_DEVICE(0x0547, 0x6510) }, TT UCMOS05100KPA */
669 /* { USB_DEVICE(0x0547, 0x6800) }, TT UCMOS08000KPA */
670 /* { USB_DEVICE(0x0547, 0x6801) }, TT UCMOS08000KPB */
671 { USB_DEVICE(0x0547, 0x6801) }, /* TT UCMOS08000KPB, AS MU800 */
672 /* { USB_DEVICE(0x0547, 0x6900) }, TT UCMOS09000KPA */
673 /* { USB_DEVICE(0x0547, 0x6901) }, TT UCMOS09000KPB */
674 /* { USB_DEVICE(0x0547, 0x6010) }, TT UCMOS10000KPA */
675 /* { USB_DEVICE(0x0547, 0x6014) }, TT UCMOS14000KPA */
676 /* { USB_DEVICE(0x0547, 0x6131) }, TT UCMOS01300KMA */
677 /* { USB_DEVICE(0x0547, 0x6511) }, TT UCMOS05100KMA */
678 /* { USB_DEVICE(0x0547, 0x8080) }, TT UHCCD00800KPA */
679 /* { USB_DEVICE(0x0547, 0x8140) }, TT UHCCD01400KPA */
680 /* { USB_DEVICE(0x0547, 0x8141) }, TT EXCCD01400KPA */
681 /* { USB_DEVICE(0x0547, 0x8200) }, TT UHCCD02000KPA */
682 /* { USB_DEVICE(0x0547, 0x8201) }, TT UHCCD02000KPB */
683 /* { USB_DEVICE(0x0547, 0x8310) }, TT UHCCD03100KPA */
684 /* { USB_DEVICE(0x0547, 0x8500) }, TT UHCCD05000KPA */
685 /* { USB_DEVICE(0x0547, 0x8510) }, TT UHCCD05100KPA */
686 /* { USB_DEVICE(0x0547, 0x8600) }, TT UHCCD06000KPA */
687 /* { USB_DEVICE(0x0547, 0x8800) }, TT UHCCD08000KPA */
688 /* { USB_DEVICE(0x0547, 0x8315) }, TT UHCCD03150KPA */
689 /* { USB_DEVICE(0x0547, 0x7800) }, TT UHCCD00800KMA */
690 /* { USB_DEVICE(0x0547, 0x7140) }, TT UHCCD01400KMA */
691 /* { USB_DEVICE(0x0547, 0x7141) }, TT UHCCD01400KMB */
692 /* { USB_DEVICE(0x0547, 0x7200) }, TT UHCCD02000KMA */
693 /* { USB_DEVICE(0x0547, 0x7315) }, TT UHCCD03150KMA */
694 { }
695};
696MODULE_DEVICE_TABLE(usb, device_table);
697
698static int sd_probe(struct usb_interface *intf,
699 const struct usb_device_id *id)
700{
701 return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd),
702 THIS_MODULE);
703}
704
705static struct usb_driver sd_driver = {
706 .name = MODULE_NAME,
707 .id_table = device_table,
708 .probe = sd_probe,
709 .disconnect = gspca_disconnect,
710#ifdef CONFIG_PM
711 .suspend = gspca_suspend,
712 .resume = gspca_resume,
713#endif
714};
715
716static int __init sd_mod_init(void)
717{
718 int ret;
719
720 ret = usb_register(&sd_driver);
721 if (ret < 0)
722 return ret;
723 return 0;
724}
725static void __exit sd_mod_exit(void)
726{
727 usb_deregister(&sd_driver);
728}
729
730module_init(sd_mod_init);
731module_exit(sd_mod_exit);
diff --git a/drivers/media/usb/gspca/vc032x.c b/drivers/media/usb/gspca/vc032x.c
index c00ac57de510..b4efb2fb36fa 100644
--- a/drivers/media/usb/gspca/vc032x.c
+++ b/drivers/media/usb/gspca/vc032x.c
@@ -68,12 +68,12 @@ enum sensors {
68 68
69static const struct v4l2_pix_format vc0321_mode[] = { 69static const struct v4l2_pix_format vc0321_mode[] = {
70 {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, 70 {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
71 .bytesperline = 320, 71 .bytesperline = 320 * 2,
72 .sizeimage = 320 * 240 * 2, 72 .sizeimage = 320 * 240 * 2,
73 .colorspace = V4L2_COLORSPACE_SRGB, 73 .colorspace = V4L2_COLORSPACE_SRGB,
74 .priv = 1}, 74 .priv = 1},
75 {640, 480, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, 75 {640, 480, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE,
76 .bytesperline = 640, 76 .bytesperline = 640 * 2,
77 .sizeimage = 640 * 480 * 2, 77 .sizeimage = 640 * 480 * 2,
78 .colorspace = V4L2_COLORSPACE_SRGB, 78 .colorspace = V4L2_COLORSPACE_SRGB,
79 .priv = 0}, 79 .priv = 0},
@@ -97,17 +97,17 @@ static const struct v4l2_pix_format vc0323_mode[] = {
97}; 97};
98static const struct v4l2_pix_format bi_mode[] = { 98static const struct v4l2_pix_format bi_mode[] = {
99 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 99 {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
100 .bytesperline = 320, 100 .bytesperline = 320 * 2,
101 .sizeimage = 320 * 240 * 2, 101 .sizeimage = 320 * 240 * 2,
102 .colorspace = V4L2_COLORSPACE_SRGB, 102 .colorspace = V4L2_COLORSPACE_SRGB,
103 .priv = 2}, 103 .priv = 2},
104 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 104 {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
105 .bytesperline = 640, 105 .bytesperline = 640 * 2,
106 .sizeimage = 640 * 480 * 2, 106 .sizeimage = 640 * 480 * 2,
107 .colorspace = V4L2_COLORSPACE_SRGB, 107 .colorspace = V4L2_COLORSPACE_SRGB,
108 .priv = 1}, 108 .priv = 1},
109 {1280, 1024, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, 109 {1280, 1024, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE,
110 .bytesperline = 1280, 110 .bytesperline = 1280 * 2,
111 .sizeimage = 1280 * 1024 * 2, 111 .sizeimage = 1280 * 1024 * 2,
112 .colorspace = V4L2_COLORSPACE_SRGB, 112 .colorspace = V4L2_COLORSPACE_SRGB,
113 .priv = 0}, 113 .priv = 0},
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-audio.c b/drivers/media/usb/pvrusb2/pvrusb2-audio.c
index cc06d5e4adcc..45276c628482 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-audio.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-audio.c
@@ -84,13 +84,3 @@ void pvr2_msp3400_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
84 MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0); 84 MSP_OUTPUT(MSP_SC_IN_DSP_SCART1), 0);
85 } 85 }
86} 86}
87
88/*
89 Stuff for Emacs to see, in order to encourage consistent editing style:
90 *** Local Variables: ***
91 *** mode: c ***
92 *** fill-column: 70 ***
93 *** tab-width: 8 ***
94 *** c-basic-offset: 8 ***
95 *** End: ***
96 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-audio.h b/drivers/media/usb/pvrusb2/pvrusb2-audio.h
index e3e63d750891..27cefb5cb170 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-audio.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-audio.h
@@ -25,13 +25,3 @@
25#include "pvrusb2-hdw-internal.h" 25#include "pvrusb2-hdw-internal.h"
26void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); 26void pvr2_msp3400_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
27#endif /* __PVRUSB2_AUDIO_H */ 27#endif /* __PVRUSB2_AUDIO_H */
28
29/*
30 Stuff for Emacs to see, in order to encourage consistent editing style:
31 *** Local Variables: ***
32 *** mode: c ***
33 *** fill-column: 70 ***
34 *** tab-width: 8 ***
35 *** c-basic-offset: 8 ***
36 *** End: ***
37 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.c b/drivers/media/usb/pvrusb2/pvrusb2-context.c
index c8761c71c9d2..924fc4c6019a 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-context.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-context.c
@@ -418,14 +418,3 @@ struct pvr2_ioread *pvr2_channel_create_mpeg_stream(
418 pvr2_ioread_set_sync_key(cp,stream_sync_key,sizeof(stream_sync_key)); 418 pvr2_ioread_set_sync_key(cp,stream_sync_key,sizeof(stream_sync_key));
419 return cp; 419 return cp;
420} 420}
421
422
423/*
424 Stuff for Emacs to see, in order to encourage consistent editing style:
425 *** Local Variables: ***
426 *** mode: c ***
427 *** fill-column: 75 ***
428 *** tab-width: 8 ***
429 *** c-basic-offset: 8 ***
430 *** End: ***
431 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-context.h b/drivers/media/usb/pvrusb2/pvrusb2-context.h
index d657e53bbfa3..1c1d442d9ea3 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-context.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-context.h
@@ -83,12 +83,3 @@ int pvr2_context_global_init(void);
83void pvr2_context_global_done(void); 83void pvr2_context_global_done(void);
84 84
85#endif /* __PVRUSB2_CONTEXT_H */ 85#endif /* __PVRUSB2_CONTEXT_H */
86/*
87 Stuff for Emacs to see, in order to encourage consistent editing style:
88 *** Local Variables: ***
89 *** mode: c ***
90 *** fill-column: 75 ***
91 *** tab-width: 8 ***
92 *** c-basic-offset: 8 ***
93 *** End: ***
94 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.c b/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.c
index 88320900dbd4..f82f0f0f2c04 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.c
@@ -82,14 +82,3 @@ void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
82 sd->ops->audio->s_routing(sd, input, 0, 0); 82 sd->ops->audio->s_routing(sd, input, 0, 0);
83 } 83 }
84} 84}
85
86
87/*
88 Stuff for Emacs to see, in order to encourage consistent editing style:
89 *** Local Variables: ***
90 *** mode: c ***
91 *** fill-column: 70 ***
92 *** tab-width: 8 ***
93 *** c-basic-offset: 8 ***
94 *** End: ***
95 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.h b/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.h
index 53ba548b72a7..86c17bee56f9 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cs53l32a.h
@@ -36,13 +36,3 @@
36void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); 36void pvr2_cs53l32a_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
37 37
38#endif /* __PVRUSB2_AUDIO_CS53L32A_H */ 38#endif /* __PVRUSB2_AUDIO_CS53L32A_H */
39
40/*
41 Stuff for Emacs to see, in order to encourage consistent editing style:
42 *** Local Variables: ***
43 *** mode: c ***
44 *** fill-column: 70 ***
45 *** tab-width: 8 ***
46 *** c-basic-offset: 8 ***
47 *** End: ***
48 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c
index 7d5a7139a45a..958db170a048 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.c
@@ -596,14 +596,3 @@ int pvr2_ctrl_value_to_sym(struct pvr2_ctrl *cptr,
596 } while(0); LOCK_GIVE(cptr->hdw->big_lock); 596 } while(0); LOCK_GIVE(cptr->hdw->big_lock);
597 return ret; 597 return ret;
598} 598}
599
600
601/*
602 Stuff for Emacs to see, in order to encourage consistent editing style:
603 *** Local Variables: ***
604 *** mode: c ***
605 *** fill-column: 75 ***
606 *** tab-width: 8 ***
607 *** c-basic-offset: 8 ***
608 *** End: ***
609 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.h b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.h
index 794ff90121c7..c175571868a3 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ctrl.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ctrl.h
@@ -110,13 +110,3 @@ int pvr2_ctrl_value_to_sym_internal(struct pvr2_ctrl *,
110 unsigned int *len); 110 unsigned int *len);
111 111
112#endif /* __PVRUSB2_CTRL_H */ 112#endif /* __PVRUSB2_CTRL_H */
113
114/*
115 Stuff for Emacs to see, in order to encourage consistent editing style:
116 *** Local Variables: ***
117 *** mode: c ***
118 *** fill-column: 75 ***
119 *** tab-width: 8 ***
120 *** c-basic-offset: 8 ***
121 *** End: ***
122 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
index c514d0b9ffdc..1a81aa70509b 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.c
@@ -152,15 +152,3 @@ void pvr2_cx25840_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
152 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0); 152 sd->ops->audio->s_routing(sd, (u32)aud_input, 0, 0);
153 } 153 }
154} 154}
155
156
157
158/*
159 Stuff for Emacs to see, in order to encourage consistent editing style:
160 *** Local Variables: ***
161 *** mode: c ***
162 *** fill-column: 70 ***
163 *** tab-width: 8 ***
164 *** c-basic-offset: 8 ***
165 *** End: ***
166 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.h b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.h
index e35c2322a08c..2eed7b7ee25e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-cx2584x-v4l.h
@@ -40,13 +40,3 @@ void pvr2_cx25840_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);
40 40
41 41
42#endif /* __PVRUSB2_CX2584X_V4L_H */ 42#endif /* __PVRUSB2_CX2584X_V4L_H */
43
44/*
45 Stuff for Emacs to see, in order to encourage consistent editing style:
46 *** Local Variables: ***
47 *** mode: c ***
48 *** fill-column: 70 ***
49 *** tab-width: 8 ***
50 *** c-basic-offset: 8 ***
51 *** End: ***
52 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-debug.h b/drivers/media/usb/pvrusb2/pvrusb2-debug.h
index be79249f8628..4ef2ebcd97a5 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-debug.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-debug.h
@@ -57,13 +57,3 @@ extern int pvrusb2_debug;
57 57
58 58
59#endif /* __PVRUSB2_HDW_INTERNAL_H */ 59#endif /* __PVRUSB2_HDW_INTERNAL_H */
60
61/*
62 Stuff for Emacs to see, in order to encourage consistent editing style:
63 *** Local Variables: ***
64 *** mode: c ***
65 *** fill-column: 75 ***
66 *** tab-width: 8 ***
67 *** c-basic-offset: 8 ***
68 *** End: ***
69 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-debugifc.c b/drivers/media/usb/pvrusb2/pvrusb2-debugifc.c
index 4279ebb811a1..e4022bcb155b 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-debugifc.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-debugifc.c
@@ -322,14 +322,3 @@ int pvr2_debugifc_docmd(struct pvr2_hdw *hdw,const char *buf,
322 322
323 return 0; 323 return 0;
324} 324}
325
326
327/*
328 Stuff for Emacs to see, in order to encourage consistent editing style:
329 *** Local Variables: ***
330 *** mode: c ***
331 *** fill-column: 75 ***
332 *** tab-width: 8 ***
333 *** c-basic-offset: 8 ***
334 *** End: ***
335 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-debugifc.h b/drivers/media/usb/pvrusb2/pvrusb2-debugifc.h
index 2f8d46761cd0..a8dfc55f136f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-debugifc.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-debugifc.h
@@ -40,13 +40,3 @@ int pvr2_debugifc_docmd(struct pvr2_hdw *,
40 const char *buf_ptr,unsigned int buf_size); 40 const char *buf_ptr,unsigned int buf_size);
41 41
42#endif /* __PVRUSB2_DEBUGIFC_H */ 42#endif /* __PVRUSB2_DEBUGIFC_H */
43
44/*
45 Stuff for Emacs to see, in order to encourage consistent editing style:
46 *** Local Variables: ***
47 *** mode: c ***
48 *** fill-column: 75 ***
49 *** tab-width: 8 ***
50 *** c-basic-offset: 8 ***
51 *** End: ***
52 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-devattr.c b/drivers/media/usb/pvrusb2/pvrusb2-devattr.c
index adc501d3c287..06c4c3dabcde 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-devattr.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-devattr.c
@@ -564,13 +564,3 @@ MODULE_FIRMWARE(PVR2_FIRMWARE_29xxx);
564MODULE_FIRMWARE(PVR2_FIRMWARE_24xxx); 564MODULE_FIRMWARE(PVR2_FIRMWARE_24xxx);
565MODULE_FIRMWARE(PVR2_FIRMWARE_73xxx); 565MODULE_FIRMWARE(PVR2_FIRMWARE_73xxx);
566MODULE_FIRMWARE(PVR2_FIRMWARE_75xxx); 566MODULE_FIRMWARE(PVR2_FIRMWARE_75xxx);
567
568/*
569 Stuff for Emacs to see, in order to encourage consistent editing style:
570 *** Local Variables: ***
571 *** mode: c ***
572 *** fill-column: 75 ***
573 *** tab-width: 8 ***
574 *** c-basic-offset: 8 ***
575 *** End: ***
576 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-devattr.h b/drivers/media/usb/pvrusb2/pvrusb2-devattr.h
index 273c8d4b3853..5aeefb6a991f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-devattr.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-devattr.h
@@ -187,13 +187,3 @@ struct pvr2_device_desc {
187extern struct usb_device_id pvr2_device_table[]; 187extern struct usb_device_id pvr2_device_table[];
188 188
189#endif /* __PVRUSB2_HDW_INTERNAL_H */ 189#endif /* __PVRUSB2_HDW_INTERNAL_H */
190
191/*
192 Stuff for Emacs to see, in order to encourage consistent editing style:
193 *** Local Variables: ***
194 *** mode: c ***
195 *** fill-column: 75 ***
196 *** tab-width: 8 ***
197 *** c-basic-offset: 8 ***
198 *** End: ***
199 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
index 9515f3a68f8f..e1907cd0c3b7 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.c
@@ -152,13 +152,3 @@ int pvr2_eeprom_analyze(struct pvr2_hdw *hdw)
152 152
153 return 0; 153 return 0;
154} 154}
155
156/*
157 Stuff for Emacs to see, in order to encourage consistent editing style:
158 *** Local Variables: ***
159 *** mode: c ***
160 *** fill-column: 70 ***
161 *** tab-width: 8 ***
162 *** c-basic-offset: 8 ***
163 *** End: ***
164 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.h b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.h
index cca3216f94cc..f1e33c807f46 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-eeprom.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-eeprom.h
@@ -27,13 +27,3 @@ struct pvr2_hdw;
27int pvr2_eeprom_analyze(struct pvr2_hdw *); 27int pvr2_eeprom_analyze(struct pvr2_hdw *);
28 28
29#endif /* __PVRUSB2_EEPROM_H */ 29#endif /* __PVRUSB2_EEPROM_H */
30
31/*
32 Stuff for Emacs to see, in order to encourage consistent editing style:
33 *** Local Variables: ***
34 *** mode: c ***
35 *** fill-column: 70 ***
36 *** tab-width: 8 ***
37 *** c-basic-offset: 8 ***
38 *** End: ***
39 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
index f7702aeeda3f..593b3e9b6bfd 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-encoder.c
@@ -538,14 +538,3 @@ int pvr2_encoder_stop(struct pvr2_hdw *hdw)
538 538
539 return status; 539 return status;
540} 540}
541
542
543/*
544 Stuff for Emacs to see, in order to encourage consistent editing style:
545 *** Local Variables: ***
546 *** mode: c ***
547 *** fill-column: 70 ***
548 *** tab-width: 8 ***
549 *** c-basic-offset: 8 ***
550 *** End: ***
551 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-encoder.h b/drivers/media/usb/pvrusb2/pvrusb2-encoder.h
index 232fefbcd1ac..a2bfb48f1ecd 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-encoder.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-encoder.h
@@ -30,13 +30,3 @@ int pvr2_encoder_start(struct pvr2_hdw *);
30int pvr2_encoder_stop(struct pvr2_hdw *); 30int pvr2_encoder_stop(struct pvr2_hdw *);
31 31
32#endif /* __PVRUSB2_ENCODER_H */ 32#endif /* __PVRUSB2_ENCODER_H */
33
34/*
35 Stuff for Emacs to see, in order to encourage consistent editing style:
36 *** Local Variables: ***
37 *** mode: c ***
38 *** fill-column: 70 ***
39 *** tab-width: 8 ***
40 *** c-basic-offset: 8 ***
41 *** End: ***
42 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-fx2-cmd.h b/drivers/media/usb/pvrusb2/pvrusb2-fx2-cmd.h
index 614755ea2ea3..06a15a68bcfd 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-fx2-cmd.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-fx2-cmd.h
@@ -60,13 +60,3 @@
60#define FX2CMD_ONAIR_DTV_POWER_OFF 0xa3u 60#define FX2CMD_ONAIR_DTV_POWER_OFF 0xa3u
61 61
62#endif /* _PVRUSB2_FX2_CMD_H_ */ 62#endif /* _PVRUSB2_FX2_CMD_H_ */
63
64/*
65 Stuff for Emacs to see, in order to encourage consistent editing style:
66 *** Local Variables: ***
67 *** mode: c ***
68 *** fill-column: 75 ***
69 *** tab-width: 8 ***
70 *** c-basic-offset: 8 ***
71 *** End: ***
72 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
index 036952f2a3cb..1f9c02801cee 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw-internal.h
@@ -394,13 +394,3 @@ unsigned long pvr2_hdw_get_cur_freq(struct pvr2_hdw *);
394void pvr2_hdw_status_poll(struct pvr2_hdw *); 394void pvr2_hdw_status_poll(struct pvr2_hdw *);
395 395
396#endif /* __PVRUSB2_HDW_INTERNAL_H */ 396#endif /* __PVRUSB2_HDW_INTERNAL_H */
397
398/*
399 Stuff for Emacs to see, in order to encourage consistent editing style:
400 *** Local Variables: ***
401 *** mode: c ***
402 *** fill-column: 75 ***
403 *** tab-width: 8 ***
404 *** c-basic-offset: 8 ***
405 *** End: ***
406 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
index 2fd9b5e0e2a9..930593d7028d 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.c
@@ -2425,22 +2425,18 @@ struct pvr2_hdw *pvr2_hdw_create(struct usb_interface *intf,
2425 } 2425 }
2426 if (!hdw) goto fail; 2426 if (!hdw) goto fail;
2427 2427
2428 init_timer(&hdw->quiescent_timer); 2428 setup_timer(&hdw->quiescent_timer, pvr2_hdw_quiescent_timeout,
2429 hdw->quiescent_timer.data = (unsigned long)hdw; 2429 (unsigned long)hdw);
2430 hdw->quiescent_timer.function = pvr2_hdw_quiescent_timeout;
2431 2430
2432 init_timer(&hdw->decoder_stabilization_timer); 2431 setup_timer(&hdw->decoder_stabilization_timer,
2433 hdw->decoder_stabilization_timer.data = (unsigned long)hdw; 2432 pvr2_hdw_decoder_stabilization_timeout,
2434 hdw->decoder_stabilization_timer.function = 2433 (unsigned long)hdw);
2435 pvr2_hdw_decoder_stabilization_timeout;
2436 2434
2437 init_timer(&hdw->encoder_wait_timer); 2435 setup_timer(&hdw->encoder_wait_timer, pvr2_hdw_encoder_wait_timeout,
2438 hdw->encoder_wait_timer.data = (unsigned long)hdw; 2436 (unsigned long)hdw);
2439 hdw->encoder_wait_timer.function = pvr2_hdw_encoder_wait_timeout;
2440 2437
2441 init_timer(&hdw->encoder_run_timer); 2438 setup_timer(&hdw->encoder_run_timer, pvr2_hdw_encoder_run_timeout,
2442 hdw->encoder_run_timer.data = (unsigned long)hdw; 2439 (unsigned long)hdw);
2443 hdw->encoder_run_timer.function = pvr2_hdw_encoder_run_timeout;
2444 2440
2445 hdw->master_state = PVR2_STATE_DEAD; 2441 hdw->master_state = PVR2_STATE_DEAD;
2446 2442
@@ -3680,10 +3676,8 @@ static int pvr2_send_request_ex(struct pvr2_hdw *hdw,
3680 hdw->ctl_timeout_flag = 0; 3676 hdw->ctl_timeout_flag = 0;
3681 hdw->ctl_write_pend_flag = 0; 3677 hdw->ctl_write_pend_flag = 0;
3682 hdw->ctl_read_pend_flag = 0; 3678 hdw->ctl_read_pend_flag = 0;
3683 init_timer(&timer); 3679 setup_timer(&timer, pvr2_ctl_timeout, (unsigned long)hdw);
3684 timer.expires = jiffies + timeout; 3680 timer.expires = jiffies + timeout;
3685 timer.data = (unsigned long)hdw;
3686 timer.function = pvr2_ctl_timeout;
3687 3681
3688 if (write_len) { 3682 if (write_len) {
3689 hdw->cmd_debug_state = 2; 3683 hdw->cmd_debug_state = 2;
@@ -4035,11 +4029,6 @@ int pvr2_hdw_cmd_powerup(struct pvr2_hdw *hdw)
4035} 4029}
4036 4030
4037 4031
4038int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *hdw)
4039{
4040 return pvr2_issue_simple_cmd(hdw,FX2CMD_POWER_OFF);
4041}
4042
4043 4032
4044int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw) 4033int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *hdw)
4045{ 4034{
@@ -4301,9 +4290,8 @@ static int state_eval_encoder_config(struct pvr2_hdw *hdw)
4301 the encoder. */ 4290 the encoder. */
4302 if (!hdw->state_encoder_waitok) { 4291 if (!hdw->state_encoder_waitok) {
4303 hdw->encoder_wait_timer.expires = 4292 hdw->encoder_wait_timer.expires =
4304 jiffies + 4293 jiffies + msecs_to_jiffies(
4305 (HZ * TIME_MSEC_ENCODER_WAIT 4294 TIME_MSEC_ENCODER_WAIT);
4306 / 1000);
4307 add_timer(&hdw->encoder_wait_timer); 4295 add_timer(&hdw->encoder_wait_timer);
4308 } 4296 }
4309 } 4297 }
@@ -4426,8 +4414,8 @@ static int state_eval_encoder_run(struct pvr2_hdw *hdw)
4426 if (pvr2_encoder_start(hdw) < 0) return !0; 4414 if (pvr2_encoder_start(hdw) < 0) return !0;
4427 hdw->state_encoder_run = !0; 4415 hdw->state_encoder_run = !0;
4428 if (!hdw->state_encoder_runok) { 4416 if (!hdw->state_encoder_runok) {
4429 hdw->encoder_run_timer.expires = 4417 hdw->encoder_run_timer.expires = jiffies +
4430 jiffies + (HZ * TIME_MSEC_ENCODER_OK / 1000); 4418 msecs_to_jiffies(TIME_MSEC_ENCODER_OK);
4431 add_timer(&hdw->encoder_run_timer); 4419 add_timer(&hdw->encoder_run_timer);
4432 } 4420 }
4433 } 4421 }
@@ -4518,9 +4506,8 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
4518 but before we did the pending check. */ 4506 but before we did the pending check. */
4519 if (!hdw->state_decoder_quiescent) { 4507 if (!hdw->state_decoder_quiescent) {
4520 hdw->quiescent_timer.expires = 4508 hdw->quiescent_timer.expires =
4521 jiffies + 4509 jiffies + msecs_to_jiffies(
4522 (HZ * TIME_MSEC_DECODER_WAIT 4510 TIME_MSEC_DECODER_WAIT);
4523 / 1000);
4524 add_timer(&hdw->quiescent_timer); 4511 add_timer(&hdw->quiescent_timer);
4525 } 4512 }
4526 } 4513 }
@@ -4544,9 +4531,8 @@ static int state_eval_decoder_run(struct pvr2_hdw *hdw)
4544 hdw->state_decoder_run = !0; 4531 hdw->state_decoder_run = !0;
4545 if (hdw->decoder_client_id == PVR2_CLIENT_ID_SAA7115) { 4532 if (hdw->decoder_client_id == PVR2_CLIENT_ID_SAA7115) {
4546 hdw->decoder_stabilization_timer.expires = 4533 hdw->decoder_stabilization_timer.expires =
4547 jiffies + 4534 jiffies + msecs_to_jiffies(
4548 (HZ * TIME_MSEC_DECODER_STABILIZATION_WAIT / 4535 TIME_MSEC_DECODER_STABILIZATION_WAIT);
4549 1000);
4550 add_timer(&hdw->decoder_stabilization_timer); 4536 add_timer(&hdw->decoder_stabilization_timer);
4551 } else { 4537 } else {
4552 hdw->state_decoder_ready = !0; 4538 hdw->state_decoder_ready = !0;
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
index 41847076f51a..a82a00dd7329 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-hdw.h
@@ -271,9 +271,6 @@ int pvr2_hdw_cmd_deep_reset(struct pvr2_hdw *);
271/* Execute simple reset command */ 271/* Execute simple reset command */
272int pvr2_hdw_cmd_powerup(struct pvr2_hdw *); 272int pvr2_hdw_cmd_powerup(struct pvr2_hdw *);
273 273
274/* suspend */
275int pvr2_hdw_cmd_powerdown(struct pvr2_hdw *);
276
277/* Order decoder to reset */ 274/* Order decoder to reset */
278int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *); 275int pvr2_hdw_cmd_decoder_reset(struct pvr2_hdw *);
279 276
@@ -343,13 +340,3 @@ void pvr2_hdw_trigger_module_log(struct pvr2_hdw *hdw);
343int pvr2_upload_firmware2(struct pvr2_hdw *hdw); 340int pvr2_upload_firmware2(struct pvr2_hdw *hdw);
344 341
345#endif /* __PVRUSB2_HDW_H */ 342#endif /* __PVRUSB2_HDW_H */
346
347/*
348 Stuff for Emacs to see, in order to encourage consistent editing style:
349 *** Local Variables: ***
350 *** mode: c ***
351 *** fill-column: 75 ***
352 *** tab-width: 8 ***
353 *** c-basic-offset: 8 ***
354 *** End: ***
355 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
index b5e929f1bf82..4baa9d632a4e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.c
@@ -686,13 +686,3 @@ void pvr2_i2c_core_done(struct pvr2_hdw *hdw)
686 hdw->i2c_linked = 0; 686 hdw->i2c_linked = 0;
687 } 687 }
688} 688}
689
690/*
691 Stuff for Emacs to see, in order to encourage consistent editing style:
692 *** Local Variables: ***
693 *** mode: c ***
694 *** fill-column: 75 ***
695 *** tab-width: 8 ***
696 *** c-basic-offset: 8 ***
697 *** End: ***
698 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.h b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.h
index 6a75769200bd..a10a3e8e9345 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-i2c-core.h
@@ -27,14 +27,3 @@ void pvr2_i2c_core_done(struct pvr2_hdw *);
27 27
28 28
29#endif /* __PVRUSB2_I2C_ADAPTER_H */ 29#endif /* __PVRUSB2_I2C_ADAPTER_H */
30
31
32/*
33 Stuff for Emacs to see, in order to encourage consistent editing style:
34 *** Local Variables: ***
35 *** mode: c ***
36 *** fill-column: 75 ***
37 *** tab-width: 8 ***
38 *** c-basic-offset: 8 ***
39 *** End: ***
40 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.c b/drivers/media/usb/pvrusb2/pvrusb2-io.c
index 1e354747de3f..0c08f22bdfce 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-io.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-io.c
@@ -682,14 +682,3 @@ int pvr2_buffer_get_id(struct pvr2_buffer *bp)
682{ 682{
683 return bp->id; 683 return bp->id;
684} 684}
685
686
687/*
688 Stuff for Emacs to see, in order to encourage consistent editing style:
689 *** Local Variables: ***
690 *** mode: c ***
691 *** fill-column: 75 ***
692 *** tab-width: 8 ***
693 *** c-basic-offset: 8 ***
694 *** End: ***
695 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-io.h b/drivers/media/usb/pvrusb2/pvrusb2-io.h
index afb7e87c0394..0c47c6a95ab2 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-io.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-io.h
@@ -90,13 +90,3 @@ int pvr2_buffer_get_id(struct pvr2_buffer *);
90int pvr2_buffer_queue(struct pvr2_buffer *); 90int pvr2_buffer_queue(struct pvr2_buffer *);
91 91
92#endif /* __PVRUSB2_IO_H */ 92#endif /* __PVRUSB2_IO_H */
93
94/*
95 Stuff for Emacs to see, in order to encourage consistent editing style:
96 *** Local Variables: ***
97 *** mode: c ***
98 *** fill-column: 75 ***
99 *** tab-width: 8 ***
100 *** c-basic-offset: 8 ***
101 *** End: ***
102 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
index bba6115c9ae8..cd995b54732e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.c
@@ -499,14 +499,3 @@ int pvr2_ioread_read(struct pvr2_ioread *cp,void __user *buf,unsigned int cnt)
499 cp,req_cnt,ret); 499 cp,req_cnt,ret);
500 return ret; 500 return ret;
501} 501}
502
503
504/*
505 Stuff for Emacs to see, in order to encourage consistent editing style:
506 *** Local Variables: ***
507 *** mode: c ***
508 *** fill-column: 75 ***
509 *** tab-width: 8 ***
510 *** c-basic-offset: 8 ***
511 *** End: ***
512 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-ioread.h b/drivers/media/usb/pvrusb2/pvrusb2-ioread.h
index 100e0780e1aa..0b1f0fbc3438 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-ioread.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-ioread.h
@@ -36,13 +36,3 @@ int pvr2_ioread_read(struct pvr2_ioread *,void __user *buf,unsigned int cnt);
36int pvr2_ioread_avail(struct pvr2_ioread *); 36int pvr2_ioread_avail(struct pvr2_ioread *);
37 37
38#endif /* __PVRUSB2_IOREAD_H */ 38#endif /* __PVRUSB2_IOREAD_H */
39
40/*
41 Stuff for Emacs to see, in order to encourage consistent editing style:
42 *** Local Variables: ***
43 *** mode: c ***
44 *** fill-column: 75 ***
45 *** tab-width: 8 ***
46 *** c-basic-offset: 8 ***
47 *** End: ***
48 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-main.c b/drivers/media/usb/pvrusb2/pvrusb2-main.c
index c1d9bb61cd77..86be902a0049 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-main.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-main.c
@@ -169,14 +169,3 @@ MODULE_AUTHOR(DRIVER_AUTHOR);
169MODULE_DESCRIPTION(DRIVER_DESC); 169MODULE_DESCRIPTION(DRIVER_DESC);
170MODULE_LICENSE("GPL"); 170MODULE_LICENSE("GPL");
171MODULE_VERSION("0.9.1"); 171MODULE_VERSION("0.9.1");
172
173
174/*
175 Stuff for Emacs to see, in order to encourage consistent editing style:
176 *** Local Variables: ***
177 *** mode: c ***
178 *** fill-column: 70 ***
179 *** tab-width: 8 ***
180 *** c-basic-offset: 8 ***
181 *** End: ***
182 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-std.c b/drivers/media/usb/pvrusb2/pvrusb2-std.c
index 453627b07833..9a596a3a4c27 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-std.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-std.c
@@ -398,14 +398,3 @@ v4l2_std_id pvr2_std_get_usable(void)
398{ 398{
399 return CSTD_ALL; 399 return CSTD_ALL;
400} 400}
401
402
403/*
404 Stuff for Emacs to see, in order to encourage consistent editing style:
405 *** Local Variables: ***
406 *** mode: c ***
407 *** fill-column: 75 ***
408 *** tab-width: 8 ***
409 *** c-basic-offset: 8 ***
410 *** End: ***
411 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-std.h b/drivers/media/usb/pvrusb2/pvrusb2-std.h
index a35c53d0b320..ed4ec0474429 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-std.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-std.h
@@ -47,13 +47,3 @@ struct v4l2_standard *pvr2_std_create_enum(unsigned int *countptr,
47v4l2_std_id pvr2_std_get_usable(void); 47v4l2_std_id pvr2_std_get_usable(void);
48 48
49#endif /* __PVRUSB2_STD_H */ 49#endif /* __PVRUSB2_STD_H */
50
51/*
52 Stuff for Emacs to see, in order to encourage consistent editing style:
53 *** Local Variables: ***
54 *** mode: c ***
55 *** fill-column: 75 ***
56 *** tab-width: 8 ***
57 *** c-basic-offset: 8 ***
58 *** End: ***
59 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-sysfs.c b/drivers/media/usb/pvrusb2/pvrusb2-sysfs.c
index 6ef1335b2858..06fe63ced58c 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-sysfs.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-sysfs.c
@@ -848,14 +848,3 @@ static ssize_t debugcmd_store(struct device *class_dev,
848 return count; 848 return count;
849} 849}
850#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */ 850#endif /* CONFIG_VIDEO_PVRUSB2_DEBUGIFC */
851
852
853/*
854 Stuff for Emacs to see, in order to encourage consistent editing style:
855 *** Local Variables: ***
856 *** mode: c ***
857 *** fill-column: 75 ***
858 *** tab-width: 8 ***
859 *** c-basic-offset: 8 ***
860 *** End: ***
861 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-sysfs.h b/drivers/media/usb/pvrusb2/pvrusb2-sysfs.h
index 6d875bfe7991..6f0579e1e07b 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-sysfs.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-sysfs.h
@@ -34,13 +34,3 @@ struct pvr2_sysfs *pvr2_sysfs_create(struct pvr2_context *,
34 struct pvr2_sysfs_class *); 34 struct pvr2_sysfs_class *);
35 35
36#endif /* __PVRUSB2_SYSFS_H */ 36#endif /* __PVRUSB2_SYSFS_H */
37
38/*
39 Stuff for Emacs to see, in order to encourage consistent editing style:
40 *** Local Variables: ***
41 *** mode: c ***
42 *** fill-column: 75 ***
43 *** tab-width: 8 ***
44 *** c-basic-offset: 8 ***
45 *** End: ***
46 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-util.h b/drivers/media/usb/pvrusb2/pvrusb2-util.h
index 92b75544ee2e..5465bf9cd73e 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-util.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-util.h
@@ -50,13 +50,3 @@
50 50
51 51
52#endif /* __PVRUSB2_UTIL_H */ 52#endif /* __PVRUSB2_UTIL_H */
53
54/*
55 Stuff for Emacs to see, in order to encourage consistent editing style:
56 *** Local Variables: ***
57 *** mode: c ***
58 *** fill-column: 75 ***
59 *** tab-width: 8 ***
60 *** c-basic-offset: 8 ***
61 *** End: ***
62 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
index 536210b39428..35e4ea530494 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.c
@@ -1362,13 +1362,3 @@ struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *mnp)
1362 pvr2_v4l2_destroy_no_lock(vp); 1362 pvr2_v4l2_destroy_no_lock(vp);
1363 return NULL; 1363 return NULL;
1364} 1364}
1365
1366/*
1367 Stuff for Emacs to see, in order to encourage consistent editing style:
1368 *** Local Variables: ***
1369 *** mode: c ***
1370 *** fill-column: 75 ***
1371 *** tab-width: 8 ***
1372 *** c-basic-offset: 8 ***
1373 *** End: ***
1374 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.h b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.h
index 34c011a7b107..e455c9515841 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-v4l2.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-v4l2.h
@@ -27,13 +27,3 @@ struct pvr2_v4l2;
27struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *); 27struct pvr2_v4l2 *pvr2_v4l2_create(struct pvr2_context *);
28 28
29#endif /* __PVRUSB2_V4L2_H */ 29#endif /* __PVRUSB2_V4L2_H */
30
31/*
32 Stuff for Emacs to see, in order to encourage consistent editing style:
33 *** Local Variables: ***
34 *** mode: c ***
35 *** fill-column: 75 ***
36 *** tab-width: 8 ***
37 *** c-basic-offset: 8 ***
38 *** End: ***
39 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.c b/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.c
index 2e205c99eb96..139b39740534 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.c
@@ -101,14 +101,3 @@ void pvr2_saa7115_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
101 sd->ops->video->s_routing(sd, input, 0, 0); 101 sd->ops->video->s_routing(sd, input, 0, 0);
102 } 102 }
103} 103}
104
105
106/*
107 Stuff for Emacs to see, in order to encourage consistent editing style:
108 *** Local Variables: ***
109 *** mode: c ***
110 *** fill-column: 70 ***
111 *** tab-width: 8 ***
112 *** c-basic-offset: 8 ***
113 *** End: ***
114 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.h b/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.h
index 3b0bd5db602b..dacf3ec7f9e1 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-video-v4l.h
@@ -36,13 +36,3 @@
36void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *); 36void pvr2_saa7115_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *);
37 37
38#endif /* __PVRUSB2_VIDEO_V4L_H */ 38#endif /* __PVRUSB2_VIDEO_V4L_H */
39
40/*
41 Stuff for Emacs to see, in order to encourage consistent editing style:
42 *** Local Variables: ***
43 *** mode: c ***
44 *** fill-column: 70 ***
45 *** tab-width: 8 ***
46 *** c-basic-offset: 8 ***
47 *** End: ***
48 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-wm8775.c b/drivers/media/usb/pvrusb2/pvrusb2-wm8775.c
index 3ac8d751a5c0..f1df94a2436f 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-wm8775.c
+++ b/drivers/media/usb/pvrusb2/pvrusb2-wm8775.c
@@ -56,15 +56,3 @@ void pvr2_wm8775_subdev_update(struct pvr2_hdw *hdw, struct v4l2_subdev *sd)
56 sd->ops->audio->s_routing(sd, input, 0, 0); 56 sd->ops->audio->s_routing(sd, input, 0, 0);
57 } 57 }
58} 58}
59
60
61
62/*
63 Stuff for Emacs to see, in order to encourage consistent editing style:
64 *** Local Variables: ***
65 *** mode: c ***
66 *** fill-column: 70 ***
67 *** tab-width: 8 ***
68 *** c-basic-offset: 8 ***
69 *** End: ***
70 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2-wm8775.h b/drivers/media/usb/pvrusb2/pvrusb2-wm8775.h
index 0577bc7246fb..a4ee12e28d5c 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2-wm8775.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2-wm8775.h
@@ -40,13 +40,3 @@ void pvr2_wm8775_subdev_update(struct pvr2_hdw *, struct v4l2_subdev *sd);
40 40
41 41
42#endif /* __PVRUSB2_WM8775_H */ 42#endif /* __PVRUSB2_WM8775_H */
43
44/*
45 Stuff for Emacs to see, in order to encourage consistent editing style:
46 *** Local Variables: ***
47 *** mode: c ***
48 *** fill-column: 70 ***
49 *** tab-width: 8 ***
50 *** c-basic-offset: 8 ***
51 *** End: ***
52 */
diff --git a/drivers/media/usb/pvrusb2/pvrusb2.h b/drivers/media/usb/pvrusb2/pvrusb2.h
index 240de9b35661..95f98a87abb3 100644
--- a/drivers/media/usb/pvrusb2/pvrusb2.h
+++ b/drivers/media/usb/pvrusb2/pvrusb2.h
@@ -30,13 +30,3 @@
30#define PVR_NUM 20 30#define PVR_NUM 20
31 31
32#endif /* __PVRUSB2_H */ 32#endif /* __PVRUSB2_H */
33
34/*
35 Stuff for Emacs to see, in order to encourage consistent editing style:
36 *** Local Variables: ***
37 *** mode: c ***
38 *** fill-column: 70 ***
39 *** tab-width: 8 ***
40 *** c-basic-offset: 8 ***
41 *** End: ***
42 */
diff --git a/drivers/media/usb/pwc/pwc-if.c b/drivers/media/usb/pwc/pwc-if.c
index 15b754da4a2c..702267e208ba 100644
--- a/drivers/media/usb/pwc/pwc-if.c
+++ b/drivers/media/usb/pwc/pwc-if.c
@@ -508,7 +508,8 @@ static void pwc_isoc_cleanup(struct pwc_device *pdev)
508} 508}
509 509
510/* Must be called with vb_queue_lock hold */ 510/* Must be called with vb_queue_lock hold */
511static void pwc_cleanup_queued_bufs(struct pwc_device *pdev) 511static void pwc_cleanup_queued_bufs(struct pwc_device *pdev,
512 enum vb2_buffer_state state)
512{ 513{
513 unsigned long flags = 0; 514 unsigned long flags = 0;
514 515
@@ -519,7 +520,7 @@ static void pwc_cleanup_queued_bufs(struct pwc_device *pdev)
519 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf, 520 buf = list_entry(pdev->queued_bufs.next, struct pwc_frame_buf,
520 list); 521 list);
521 list_del(&buf->list); 522 list_del(&buf->list);
522 vb2_buffer_done(&buf->vb, VB2_BUF_STATE_ERROR); 523 vb2_buffer_done(&buf->vb, state);
523 } 524 }
524 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags); 525 spin_unlock_irqrestore(&pdev->queued_bufs_lock, flags);
525} 526}
@@ -674,7 +675,7 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
674 pwc_set_leds(pdev, 0, 0); 675 pwc_set_leds(pdev, 0, 0);
675 pwc_camera_power(pdev, 0); 676 pwc_camera_power(pdev, 0);
676 /* And cleanup any queued bufs!! */ 677 /* And cleanup any queued bufs!! */
677 pwc_cleanup_queued_bufs(pdev); 678 pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_QUEUED);
678 } 679 }
679 mutex_unlock(&pdev->v4l2_lock); 680 mutex_unlock(&pdev->v4l2_lock);
680 681
@@ -692,7 +693,9 @@ static void stop_streaming(struct vb2_queue *vq)
692 pwc_isoc_cleanup(pdev); 693 pwc_isoc_cleanup(pdev);
693 } 694 }
694 695
695 pwc_cleanup_queued_bufs(pdev); 696 pwc_cleanup_queued_bufs(pdev, VB2_BUF_STATE_ERROR);
697 if (pdev->fill_buf)
698 vb2_buffer_done(&pdev->fill_buf->vb, VB2_BUF_STATE_ERROR);
696 mutex_unlock(&pdev->v4l2_lock); 699 mutex_unlock(&pdev->v4l2_lock);
697} 700}
698 701
@@ -1125,7 +1128,6 @@ static void usb_pwc_disconnect(struct usb_interface *intf)
1125 if (pdev->vb_queue.streaming) 1128 if (pdev->vb_queue.streaming)
1126 pwc_isoc_cleanup(pdev); 1129 pwc_isoc_cleanup(pdev);
1127 pdev->udev = NULL; 1130 pdev->udev = NULL;
1128 pwc_cleanup_queued_bufs(pdev);
1129 1131
1130 v4l2_device_disconnect(&pdev->v4l2_dev); 1132 v4l2_device_disconnect(&pdev->v4l2_dev);
1131 video_unregister_device(&pdev->vdev); 1133 video_unregister_device(&pdev->vdev);
diff --git a/drivers/media/usb/s2255/s2255drv.c b/drivers/media/usb/s2255/s2255drv.c
index de55e96fed15..0f3c34d47ec3 100644
--- a/drivers/media/usb/s2255/s2255drv.c
+++ b/drivers/media/usb/s2255/s2255drv.c
@@ -2274,9 +2274,7 @@ static int s2255_probe(struct usb_interface *interface,
2274 dev_err(&interface->dev, "Could not find bulk-in endpoint\n"); 2274 dev_err(&interface->dev, "Could not find bulk-in endpoint\n");
2275 goto errorEP; 2275 goto errorEP;
2276 } 2276 }
2277 init_timer(&dev->timer); 2277 setup_timer(&dev->timer, s2255_timer, (unsigned long)dev->fw_data);
2278 dev->timer.function = s2255_timer;
2279 dev->timer.data = (unsigned long)dev->fw_data;
2280 init_waitqueue_head(&dev->fw_data->wait_fw); 2278 init_waitqueue_head(&dev->fw_data->wait_fw);
2281 for (i = 0; i < MAX_CHANNELS; i++) { 2279 for (i = 0; i < MAX_CHANNELS; i++) {
2282 struct s2255_vc *vc = &dev->vc[i]; 2280 struct s2255_vc *vc = &dev->vc[i];
diff --git a/drivers/media/usb/siano/Kconfig b/drivers/media/usb/siano/Kconfig
index 5afbd9a4b55c..d37b742d4f7a 100644
--- a/drivers/media/usb/siano/Kconfig
+++ b/drivers/media/usb/siano/Kconfig
@@ -5,7 +5,9 @@
5config SMS_USB_DRV 5config SMS_USB_DRV
6 tristate "Siano SMS1xxx based MDTV receiver" 6 tristate "Siano SMS1xxx based MDTV receiver"
7 depends on DVB_CORE && HAS_DMA 7 depends on DVB_CORE && HAS_DMA
8 depends on !RC_CORE || RC_CORE
8 select MEDIA_COMMON_OPTIONS 9 select MEDIA_COMMON_OPTIONS
10 select SMS_SIANO_MDTV
9 ---help--- 11 ---help---
10 Choose if you would like to have Siano's support for USB interface 12 Choose if you would like to have Siano's support for USB interface
11 13
diff --git a/drivers/media/usb/stk1160/stk1160-v4l.c b/drivers/media/usb/stk1160/stk1160-v4l.c
index a47629108c1b..65a326c5128f 100644
--- a/drivers/media/usb/stk1160/stk1160-v4l.c
+++ b/drivers/media/usb/stk1160/stk1160-v4l.c
@@ -38,10 +38,6 @@
38#include "stk1160.h" 38#include "stk1160.h"
39#include "stk1160-reg.h" 39#include "stk1160-reg.h"
40 40
41static unsigned int vidioc_debug;
42module_param(vidioc_debug, int, 0644);
43MODULE_PARM_DESC(vidioc_debug, "enable debug messages [vidioc]");
44
45static bool keep_buffers; 41static bool keep_buffers;
46module_param(keep_buffers, bool, 0644); 42module_param(keep_buffers, bool, 0644);
47MODULE_PARM_DESC(keep_buffers, "don't release buffers upon stop streaming"); 43MODULE_PARM_DESC(keep_buffers, "don't release buffers upon stop streaming");
@@ -659,7 +655,6 @@ int stk1160_video_register(struct stk1160 *dev)
659 655
660 /* Initialize video_device with a template structure */ 656 /* Initialize video_device with a template structure */
661 dev->vdev = v4l_template; 657 dev->vdev = v4l_template;
662 dev->vdev.debug = vidioc_debug;
663 dev->vdev.queue = &dev->vb_vidq; 658 dev->vdev.queue = &dev->vb_vidq;
664 659
665 /* 660 /*
diff --git a/drivers/media/usb/stkwebcam/stk-webcam.c b/drivers/media/usb/stkwebcam/stk-webcam.c
index 3588dc38db87..e08fa587332f 100644
--- a/drivers/media/usb/stkwebcam/stk-webcam.c
+++ b/drivers/media/usb/stkwebcam/stk-webcam.c
@@ -1262,7 +1262,6 @@ static int stk_register_video_device(struct stk_camera *dev)
1262 1262
1263 dev->vdev = stk_v4l_data; 1263 dev->vdev = stk_v4l_data;
1264 dev->vdev.lock = &dev->lock; 1264 dev->vdev.lock = &dev->lock;
1265 dev->vdev.debug = debug;
1266 dev->vdev.v4l2_dev = &dev->v4l2_dev; 1265 dev->vdev.v4l2_dev = &dev->v4l2_dev;
1267 video_set_drvdata(&dev->vdev, dev); 1266 video_set_drvdata(&dev->vdev, dev);
1268 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1); 1267 err = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, -1);
diff --git a/drivers/media/usb/tm6000/tm6000-video.c b/drivers/media/usb/tm6000/tm6000-video.c
index 793577fc4633..0f14d3ccc7b4 100644
--- a/drivers/media/usb/tm6000/tm6000-video.c
+++ b/drivers/media/usb/tm6000/tm6000-video.c
@@ -941,7 +941,7 @@ static int vidioc_try_fmt_vid_cap(struct file *file, void *priv,
941 941
942 fmt = format_by_fourcc(f->fmt.pix.pixelformat); 942 fmt = format_by_fourcc(f->fmt.pix.pixelformat);
943 if (NULL == fmt) { 943 if (NULL == fmt) {
944 dprintk(dev, V4L2_DEBUG_IOCTL_ARG, "Fourcc format (0x%08x)" 944 dprintk(dev, 2, "Fourcc format (0x%08x)"
945 " invalid.\n", f->fmt.pix.pixelformat); 945 " invalid.\n", f->fmt.pix.pixelformat);
946 return -EINVAL; 946 return -EINVAL;
947 } 947 }
@@ -1622,7 +1622,6 @@ static struct video_device *vdev_init(struct tm6000_core *dev,
1622 *vfd = *template; 1622 *vfd = *template;
1623 vfd->v4l2_dev = &dev->v4l2_dev; 1623 vfd->v4l2_dev = &dev->v4l2_dev;
1624 vfd->release = video_device_release; 1624 vfd->release = video_device_release;
1625 vfd->debug = tm6000_debug;
1626 vfd->lock = &dev->lock; 1625 vfd->lock = &dev->lock;
1627 1626
1628 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name); 1627 snprintf(vfd->name, sizeof(vfd->name), "%s %s", dev->name, type_name);
diff --git a/drivers/media/usb/usbvision/usbvision-core.c b/drivers/media/usb/usbvision/usbvision-core.c
index 302aa07c458f..44b0c28d69b6 100644
--- a/drivers/media/usb/usbvision/usbvision-core.c
+++ b/drivers/media/usb/usbvision/usbvision-core.c
@@ -2194,9 +2194,8 @@ static void usbvision_power_off_timer(unsigned long data)
2194 2194
2195void usbvision_init_power_off_timer(struct usb_usbvision *usbvision) 2195void usbvision_init_power_off_timer(struct usb_usbvision *usbvision)
2196{ 2196{
2197 init_timer(&usbvision->power_off_timer); 2197 setup_timer(&usbvision->power_off_timer, usbvision_power_off_timer,
2198 usbvision->power_off_timer.data = (long)usbvision; 2198 (unsigned long)usbvision);
2199 usbvision->power_off_timer.function = usbvision_power_off_timer;
2200} 2199}
2201 2200
2202void usbvision_set_power_off_timer(struct usb_usbvision *usbvision) 2201void usbvision_set_power_off_timer(struct usb_usbvision *usbvision)
@@ -2502,11 +2501,3 @@ int usbvision_muxsel(struct usb_usbvision *usbvision, int channel)
2502 usbvision_set_audio(usbvision, audio[channel]); 2501 usbvision_set_audio(usbvision, audio[channel]);
2503 return 0; 2502 return 0;
2504} 2503}
2505
2506/*
2507 * Overrides for Emacs so that we follow Linus's tabbing style.
2508 * ---------------------------------------------------------------------------
2509 * Local variables:
2510 * c-basic-offset: 8
2511 * End:
2512 */
diff --git a/drivers/media/usb/usbvision/usbvision-i2c.c b/drivers/media/usb/usbvision/usbvision-i2c.c
index ba262a32bd3a..26dbcb1146af 100644
--- a/drivers/media/usb/usbvision/usbvision-i2c.c
+++ b/drivers/media/usb/usbvision/usbvision-i2c.c
@@ -445,11 +445,3 @@ static struct i2c_adapter i2c_adap_template = {
445 .owner = THIS_MODULE, 445 .owner = THIS_MODULE,
446 .name = "usbvision", 446 .name = "usbvision",
447}; 447};
448
449/*
450 * Overrides for Emacs so that we follow Linus's tabbing style.
451 * ---------------------------------------------------------------------------
452 * Local variables:
453 * c-basic-offset: 8
454 * End:
455 */
diff --git a/drivers/media/usb/usbvision/usbvision-video.c b/drivers/media/usb/usbvision/usbvision-video.c
index 693d5f409138..cd2fbf11e3b4 100644
--- a/drivers/media/usb/usbvision/usbvision-video.c
+++ b/drivers/media/usb/usbvision/usbvision-video.c
@@ -1716,11 +1716,3 @@ static void __exit usbvision_exit(void)
1716 1716
1717module_init(usbvision_init); 1717module_init(usbvision_init);
1718module_exit(usbvision_exit); 1718module_exit(usbvision_exit);
1719
1720/*
1721 * Overrides for Emacs so that we follow Linus's tabbing style.
1722 * ---------------------------------------------------------------------------
1723 * Local variables:
1724 * c-basic-offset: 8
1725 * End:
1726 */
diff --git a/drivers/media/usb/usbvision/usbvision.h b/drivers/media/usb/usbvision/usbvision.h
index a0c73cf1517c..77aeb1ed9a81 100644
--- a/drivers/media/usb/usbvision/usbvision.h
+++ b/drivers/media/usb/usbvision/usbvision.h
@@ -517,11 +517,3 @@ int usbvision_power_off(struct usb_usbvision *usbvision);
517int usbvision_power_on(struct usb_usbvision *usbvision); 517int usbvision_power_on(struct usb_usbvision *usbvision);
518 518
519#endif /* __LINUX_USBVISION_H */ 519#endif /* __LINUX_USBVISION_H */
520
521/*
522 * Overrides for Emacs so that we follow Linus's tabbing style.
523 * ---------------------------------------------------------------------------
524 * Local variables:
525 * c-basic-offset: 8
526 * End:
527 */
diff --git a/drivers/media/usb/uvc/uvc_driver.c b/drivers/media/usb/uvc/uvc_driver.c
index 6a4b0b8cd270..cf27006c29dc 100644
--- a/drivers/media/usb/uvc/uvc_driver.c
+++ b/drivers/media/usb/uvc/uvc_driver.c
@@ -138,6 +138,11 @@ static struct uvc_format_desc uvc_fmts[] = {
138 .fcc = V4L2_PIX_FMT_RGB565, 138 .fcc = V4L2_PIX_FMT_RGB565,
139 }, 139 },
140 { 140 {
141 .name = "BGR 8:8:8 (BGR3)",
142 .guid = UVC_GUID_FORMAT_BGR3,
143 .fcc = V4L2_PIX_FMT_BGR24,
144 },
145 {
141 .name = "H.264", 146 .name = "H.264",
142 .guid = UVC_GUID_FORMAT_H264, 147 .guid = UVC_GUID_FORMAT_H264,
143 .fcc = V4L2_PIX_FMT_H264, 148 .fcc = V4L2_PIX_FMT_H264,
diff --git a/drivers/media/usb/uvc/uvc_queue.c b/drivers/media/usb/uvc/uvc_queue.c
index cc960723b926..10c554e7655c 100644
--- a/drivers/media/usb/uvc/uvc_queue.c
+++ b/drivers/media/usb/uvc/uvc_queue.c
@@ -143,20 +143,6 @@ static void uvc_buffer_finish(struct vb2_buffer *vb)
143 uvc_video_clock_update(stream, &vb->v4l2_buf, buf); 143 uvc_video_clock_update(stream, &vb->v4l2_buf, buf);
144} 144}
145 145
146static void uvc_wait_prepare(struct vb2_queue *vq)
147{
148 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
149
150 mutex_unlock(&queue->mutex);
151}
152
153static void uvc_wait_finish(struct vb2_queue *vq)
154{
155 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
156
157 mutex_lock(&queue->mutex);
158}
159
160static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count) 146static int uvc_start_streaming(struct vb2_queue *vq, unsigned int count)
161{ 147{
162 struct uvc_video_queue *queue = vb2_get_drv_priv(vq); 148 struct uvc_video_queue *queue = vb2_get_drv_priv(vq);
@@ -195,8 +181,8 @@ static struct vb2_ops uvc_queue_qops = {
195 .buf_prepare = uvc_buffer_prepare, 181 .buf_prepare = uvc_buffer_prepare,
196 .buf_queue = uvc_buffer_queue, 182 .buf_queue = uvc_buffer_queue,
197 .buf_finish = uvc_buffer_finish, 183 .buf_finish = uvc_buffer_finish,
198 .wait_prepare = uvc_wait_prepare, 184 .wait_prepare = vb2_ops_wait_prepare,
199 .wait_finish = uvc_wait_finish, 185 .wait_finish = vb2_ops_wait_finish,
200 .start_streaming = uvc_start_streaming, 186 .start_streaming = uvc_start_streaming,
201 .stop_streaming = uvc_stop_streaming, 187 .stop_streaming = uvc_stop_streaming,
202}; 188};
@@ -214,6 +200,7 @@ int uvc_queue_init(struct uvc_video_queue *queue, enum v4l2_buf_type type,
214 queue->queue.mem_ops = &vb2_vmalloc_memops; 200 queue->queue.mem_ops = &vb2_vmalloc_memops;
215 queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC 201 queue->queue.timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC
216 | V4L2_BUF_FLAG_TSTAMP_SRC_SOE; 202 | V4L2_BUF_FLAG_TSTAMP_SRC_SOE;
203 queue->queue.lock = &queue->mutex;
217 ret = vb2_queue_init(&queue->queue); 204 ret = vb2_queue_init(&queue->queue);
218 if (ret) 205 if (ret)
219 return ret; 206 return ret;
diff --git a/drivers/media/usb/uvc/uvc_v4l2.c b/drivers/media/usb/uvc/uvc_v4l2.c
index 9c5cbcf16529..43e953f73e02 100644
--- a/drivers/media/usb/uvc/uvc_v4l2.c
+++ b/drivers/media/usb/uvc/uvc_v4l2.c
@@ -13,7 +13,6 @@
13 13
14#include <linux/compat.h> 14#include <linux/compat.h>
15#include <linux/kernel.h> 15#include <linux/kernel.h>
16#include <linux/version.h>
17#include <linux/list.h> 16#include <linux/list.h>
18#include <linux/module.h> 17#include <linux/module.h>
19#include <linux/slab.h> 18#include <linux/slab.h>
diff --git a/drivers/media/usb/uvc/uvc_video.c b/drivers/media/usb/uvc/uvc_video.c
index 9637e8b86949..20ccc9d315dc 100644
--- a/drivers/media/usb/uvc/uvc_video.c
+++ b/drivers/media/usb/uvc/uvc_video.c
@@ -1734,13 +1734,13 @@ int uvc_video_resume(struct uvc_streaming *stream, int reset)
1734 1734
1735 uvc_video_clock_reset(stream); 1735 uvc_video_clock_reset(stream);
1736 1736
1737 if (!uvc_queue_streaming(&stream->queue))
1738 return 0;
1739
1737 ret = uvc_commit_video(stream, &stream->ctrl); 1740 ret = uvc_commit_video(stream, &stream->ctrl);
1738 if (ret < 0) 1741 if (ret < 0)
1739 return ret; 1742 return ret;
1740 1743
1741 if (!uvc_queue_streaming(&stream->queue))
1742 return 0;
1743
1744 return uvc_init_video(stream, GFP_NOIO); 1744 return uvc_init_video(stream, GFP_NOIO);
1745} 1745}
1746 1746
diff --git a/drivers/media/usb/uvc/uvcvideo.h b/drivers/media/usb/uvc/uvcvideo.h
index f0a04b532ede..c63e5b55e143 100644
--- a/drivers/media/usb/uvc/uvcvideo.h
+++ b/drivers/media/usb/uvc/uvcvideo.h
@@ -109,6 +109,9 @@
109#define UVC_GUID_FORMAT_RGBP \ 109#define UVC_GUID_FORMAT_RGBP \
110 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \ 110 { 'R', 'G', 'B', 'P', 0x00, 0x00, 0x10, 0x00, \
111 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 111 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
112#define UVC_GUID_FORMAT_BGR3 \
113 { 0x7d, 0xeb, 0x36, 0xe4, 0x4f, 0x52, 0xce, 0x11, \
114 0x9f, 0x53, 0x00, 0x20, 0xaf, 0x0b, 0xa7, 0x70}
112#define UVC_GUID_FORMAT_M420 \ 115#define UVC_GUID_FORMAT_M420 \
113 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \ 116 { 'M', '4', '2', '0', 0x00, 0x00, 0x10, 0x00, \
114 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71} 117 0x80, 0x00, 0x00, 0xaa, 0x00, 0x38, 0x9b, 0x71}
diff --git a/drivers/media/usb/zr364xx/zr364xx.c b/drivers/media/usb/zr364xx/zr364xx.c
index 5c006277b8b1..ca850316d379 100644
--- a/drivers/media/usb/zr364xx/zr364xx.c
+++ b/drivers/media/usb/zr364xx/zr364xx.c
@@ -1454,8 +1454,6 @@ static int zr364xx_probe(struct usb_interface *intf,
1454 cam->vdev.v4l2_dev = &cam->v4l2_dev; 1454 cam->vdev.v4l2_dev = &cam->v4l2_dev;
1455 cam->vdev.ctrl_handler = &cam->ctrl_handler; 1455 cam->vdev.ctrl_handler = &cam->ctrl_handler;
1456 video_set_drvdata(&cam->vdev, cam); 1456 video_set_drvdata(&cam->vdev, cam);
1457 if (debug)
1458 cam->vdev.debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
1459 1457
1460 cam->udev = udev; 1458 cam->udev = udev;
1461 1459
diff --git a/drivers/media/v4l2-core/v4l2-dev.c b/drivers/media/v4l2-core/v4l2-dev.c
index 9aa530a8bea9..86bb93fd7db8 100644
--- a/drivers/media/v4l2-core/v4l2-dev.c
+++ b/drivers/media/v4l2-core/v4l2-dev.c
@@ -47,15 +47,15 @@ static ssize_t index_show(struct device *cd,
47} 47}
48static DEVICE_ATTR_RO(index); 48static DEVICE_ATTR_RO(index);
49 49
50static ssize_t debug_show(struct device *cd, 50static ssize_t dev_debug_show(struct device *cd,
51 struct device_attribute *attr, char *buf) 51 struct device_attribute *attr, char *buf)
52{ 52{
53 struct video_device *vdev = to_video_device(cd); 53 struct video_device *vdev = to_video_device(cd);
54 54
55 return sprintf(buf, "%i\n", vdev->debug); 55 return sprintf(buf, "%i\n", vdev->dev_debug);
56} 56}
57 57
58static ssize_t debug_store(struct device *cd, struct device_attribute *attr, 58static ssize_t dev_debug_store(struct device *cd, struct device_attribute *attr,
59 const char *buf, size_t len) 59 const char *buf, size_t len)
60{ 60{
61 struct video_device *vdev = to_video_device(cd); 61 struct video_device *vdev = to_video_device(cd);
@@ -66,10 +66,10 @@ static ssize_t debug_store(struct device *cd, struct device_attribute *attr,
66 if (res) 66 if (res)
67 return res; 67 return res;
68 68
69 vdev->debug = value; 69 vdev->dev_debug = value;
70 return len; 70 return len;
71} 71}
72static DEVICE_ATTR_RW(debug); 72static DEVICE_ATTR_RW(dev_debug);
73 73
74static ssize_t name_show(struct device *cd, 74static ssize_t name_show(struct device *cd,
75 struct device_attribute *attr, char *buf) 75 struct device_attribute *attr, char *buf)
@@ -82,7 +82,7 @@ static DEVICE_ATTR_RO(name);
82 82
83static struct attribute *video_device_attrs[] = { 83static struct attribute *video_device_attrs[] = {
84 &dev_attr_name.attr, 84 &dev_attr_name.attr,
85 &dev_attr_debug.attr, 85 &dev_attr_dev_debug.attr,
86 &dev_attr_index.attr, 86 &dev_attr_index.attr,
87 NULL, 87 NULL,
88}; 88};
@@ -304,7 +304,8 @@ static ssize_t v4l2_read(struct file *filp, char __user *buf,
304 return -EINVAL; 304 return -EINVAL;
305 if (video_is_registered(vdev)) 305 if (video_is_registered(vdev))
306 ret = vdev->fops->read(filp, buf, sz, off); 306 ret = vdev->fops->read(filp, buf, sz, off);
307 if (vdev->debug) 307 if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) &&
308 (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING))
308 printk(KERN_DEBUG "%s: read: %zd (%d)\n", 309 printk(KERN_DEBUG "%s: read: %zd (%d)\n",
309 video_device_node_name(vdev), sz, ret); 310 video_device_node_name(vdev), sz, ret);
310 return ret; 311 return ret;
@@ -320,7 +321,8 @@ static ssize_t v4l2_write(struct file *filp, const char __user *buf,
320 return -EINVAL; 321 return -EINVAL;
321 if (video_is_registered(vdev)) 322 if (video_is_registered(vdev))
322 ret = vdev->fops->write(filp, buf, sz, off); 323 ret = vdev->fops->write(filp, buf, sz, off);
323 if (vdev->debug) 324 if ((vdev->dev_debug & V4L2_DEV_DEBUG_FOP) &&
325 (vdev->dev_debug & V4L2_DEV_DEBUG_STREAMING))
324 printk(KERN_DEBUG "%s: write: %zd (%d)\n", 326 printk(KERN_DEBUG "%s: write: %zd (%d)\n",
325 video_device_node_name(vdev), sz, ret); 327 video_device_node_name(vdev), sz, ret);
326 return ret; 328 return ret;
@@ -335,7 +337,7 @@ static unsigned int v4l2_poll(struct file *filp, struct poll_table_struct *poll)
335 return DEFAULT_POLLMASK; 337 return DEFAULT_POLLMASK;
336 if (video_is_registered(vdev)) 338 if (video_is_registered(vdev))
337 res = vdev->fops->poll(filp, poll); 339 res = vdev->fops->poll(filp, poll);
338 if (vdev->debug > 2) 340 if (vdev->dev_debug & V4L2_DEV_DEBUG_POLL)
339 printk(KERN_DEBUG "%s: poll: %08x\n", 341 printk(KERN_DEBUG "%s: poll: %08x\n",
340 video_device_node_name(vdev), res); 342 video_device_node_name(vdev), res);
341 return res; 343 return res;
@@ -404,7 +406,7 @@ static unsigned long v4l2_get_unmapped_area(struct file *filp,
404 if (!video_is_registered(vdev)) 406 if (!video_is_registered(vdev))
405 return -ENODEV; 407 return -ENODEV;
406 ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags); 408 ret = vdev->fops->get_unmapped_area(filp, addr, len, pgoff, flags);
407 if (vdev->debug) 409 if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
408 printk(KERN_DEBUG "%s: get_unmapped_area (%d)\n", 410 printk(KERN_DEBUG "%s: get_unmapped_area (%d)\n",
409 video_device_node_name(vdev), ret); 411 video_device_node_name(vdev), ret);
410 return ret; 412 return ret;
@@ -420,7 +422,7 @@ static int v4l2_mmap(struct file *filp, struct vm_area_struct *vm)
420 return -ENODEV; 422 return -ENODEV;
421 if (video_is_registered(vdev)) 423 if (video_is_registered(vdev))
422 ret = vdev->fops->mmap(filp, vm); 424 ret = vdev->fops->mmap(filp, vm);
423 if (vdev->debug) 425 if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
424 printk(KERN_DEBUG "%s: mmap (%d)\n", 426 printk(KERN_DEBUG "%s: mmap (%d)\n",
425 video_device_node_name(vdev), ret); 427 video_device_node_name(vdev), ret);
426 return ret; 428 return ret;
@@ -450,7 +452,7 @@ static int v4l2_open(struct inode *inode, struct file *filp)
450 ret = -ENODEV; 452 ret = -ENODEV;
451 } 453 }
452 454
453 if (vdev->debug) 455 if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
454 printk(KERN_DEBUG "%s: open (%d)\n", 456 printk(KERN_DEBUG "%s: open (%d)\n",
455 video_device_node_name(vdev), ret); 457 video_device_node_name(vdev), ret);
456 /* decrease the refcount in case of an error */ 458 /* decrease the refcount in case of an error */
@@ -467,7 +469,7 @@ static int v4l2_release(struct inode *inode, struct file *filp)
467 469
468 if (vdev->fops->release) 470 if (vdev->fops->release)
469 ret = vdev->fops->release(filp); 471 ret = vdev->fops->release(filp);
470 if (vdev->debug) 472 if (vdev->dev_debug & V4L2_DEV_DEBUG_FOP)
471 printk(KERN_DEBUG "%s: release\n", 473 printk(KERN_DEBUG "%s: release\n",
472 video_device_node_name(vdev)); 474 video_device_node_name(vdev));
473 475
@@ -1033,10 +1035,3 @@ MODULE_AUTHOR("Alan Cox, Mauro Carvalho Chehab <mchehab@infradead.org>");
1033MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2"); 1035MODULE_DESCRIPTION("Device registrar for Video4Linux drivers v2");
1034MODULE_LICENSE("GPL"); 1036MODULE_LICENSE("GPL");
1035MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR); 1037MODULE_ALIAS_CHARDEV_MAJOR(VIDEO_MAJOR);
1036
1037
1038/*
1039 * Local variables:
1040 * c-basic-offset: 8
1041 * End:
1042 */
diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
index faac2f4e0f3a..b08407225db1 100644
--- a/drivers/media/v4l2-core/v4l2-ioctl.c
+++ b/drivers/media/v4l2-core/v4l2-ioctl.c
@@ -2339,7 +2339,7 @@ static long __video_do_ioctl(struct file *file,
2339 const struct v4l2_ioctl_info *info; 2339 const struct v4l2_ioctl_info *info;
2340 void *fh = file->private_data; 2340 void *fh = file->private_data;
2341 struct v4l2_fh *vfh = NULL; 2341 struct v4l2_fh *vfh = NULL;
2342 int debug = vfd->debug; 2342 int dev_debug = vfd->dev_debug;
2343 long ret = -ENOTTY; 2343 long ret = -ENOTTY;
2344 2344
2345 if (ops == NULL) { 2345 if (ops == NULL) {
@@ -2388,11 +2388,15 @@ static long __video_do_ioctl(struct file *file,
2388 } 2388 }
2389 2389
2390done: 2390done:
2391 if (debug) { 2391 if (dev_debug & (V4L2_DEV_DEBUG_IOCTL | V4L2_DEV_DEBUG_IOCTL_ARG)) {
2392 if (!(dev_debug & V4L2_DEV_DEBUG_STREAMING) &&
2393 (cmd == VIDIOC_QBUF || cmd == VIDIOC_DQBUF))
2394 return ret;
2395
2392 v4l_printk_ioctl(video_device_node_name(vfd), cmd); 2396 v4l_printk_ioctl(video_device_node_name(vfd), cmd);
2393 if (ret < 0) 2397 if (ret < 0)
2394 pr_cont(": error %ld", ret); 2398 pr_cont(": error %ld", ret);
2395 if (debug == V4L2_DEBUG_IOCTL) 2399 if (!(dev_debug & V4L2_DEV_DEBUG_IOCTL_ARG))
2396 pr_cont("\n"); 2400 pr_cont("\n");
2397 else if (_IOC_DIR(cmd) == _IOC_NONE) 2401 else if (_IOC_DIR(cmd) == _IOC_NONE)
2398 info->debug(arg, write_only); 2402 info->debug(arg, write_only);
diff --git a/drivers/media/v4l2-core/v4l2-subdev.c b/drivers/media/v4l2-core/v4l2-subdev.c
index 543631c3557a..19a034e79be4 100644
--- a/drivers/media/v4l2-core/v4l2-subdev.c
+++ b/drivers/media/v4l2-core/v4l2-subdev.c
@@ -283,10 +283,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
283 if (rval) 283 if (rval)
284 return rval; 284 return rval;
285 285
286 rval = v4l2_subdev_call(sd, pad, get_crop, subdev_fh, crop);
287 if (rval != -ENOIOCTLCMD)
288 return rval;
289
290 memset(&sel, 0, sizeof(sel)); 286 memset(&sel, 0, sizeof(sel));
291 sel.which = crop->which; 287 sel.which = crop->which;
292 sel.pad = crop->pad; 288 sel.pad = crop->pad;
@@ -308,10 +304,6 @@ static long subdev_do_ioctl(struct file *file, unsigned int cmd, void *arg)
308 if (rval) 304 if (rval)
309 return rval; 305 return rval;
310 306
311 rval = v4l2_subdev_call(sd, pad, set_crop, subdev_fh, crop);
312 if (rval != -ENOIOCTLCMD)
313 return rval;
314
315 memset(&sel, 0, sizeof(sel)); 307 memset(&sel, 0, sizeof(sel));
316 sel.which = crop->which; 308 sel.which = crop->which;
317 sel.pad = crop->pad; 309 sel.pad = crop->pad;
diff --git a/drivers/media/v4l2-core/videobuf-dma-sg.c b/drivers/media/v4l2-core/videobuf-dma-sg.c
index 3ff15f1c9d70..f669cedca8bd 100644
--- a/drivers/media/v4l2-core/videobuf-dma-sg.c
+++ b/drivers/media/v4l2-core/videobuf-dma-sg.c
@@ -145,12 +145,11 @@ struct videobuf_dmabuf *videobuf_to_dma(struct videobuf_buffer *buf)
145} 145}
146EXPORT_SYMBOL_GPL(videobuf_to_dma); 146EXPORT_SYMBOL_GPL(videobuf_to_dma);
147 147
148void videobuf_dma_init(struct videobuf_dmabuf *dma) 148static void videobuf_dma_init(struct videobuf_dmabuf *dma)
149{ 149{
150 memset(dma, 0, sizeof(*dma)); 150 memset(dma, 0, sizeof(*dma));
151 dma->magic = MAGIC_DMABUF; 151 dma->magic = MAGIC_DMABUF;
152} 152}
153EXPORT_SYMBOL_GPL(videobuf_dma_init);
154 153
155static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma, 154static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
156 int direction, unsigned long data, unsigned long size) 155 int direction, unsigned long data, unsigned long size)
@@ -195,7 +194,7 @@ static int videobuf_dma_init_user_locked(struct videobuf_dmabuf *dma,
195 return 0; 194 return 0;
196} 195}
197 196
198int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction, 197static int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
199 unsigned long data, unsigned long size) 198 unsigned long data, unsigned long size)
200{ 199{
201 int ret; 200 int ret;
@@ -206,9 +205,8 @@ int videobuf_dma_init_user(struct videobuf_dmabuf *dma, int direction,
206 205
207 return ret; 206 return ret;
208} 207}
209EXPORT_SYMBOL_GPL(videobuf_dma_init_user);
210 208
211int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction, 209static int videobuf_dma_init_kernel(struct videobuf_dmabuf *dma, int direction,
212 int nr_pages) 210 int nr_pages)
213{ 211{
214 int i; 212 int i;
@@ -267,9 +265,8 @@ out_free_pages:
267 return -ENOMEM; 265 return -ENOMEM;
268 266
269} 267}
270EXPORT_SYMBOL_GPL(videobuf_dma_init_kernel);
271 268
272int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction, 269static int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
273 dma_addr_t addr, int nr_pages) 270 dma_addr_t addr, int nr_pages)
274{ 271{
275 dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n", 272 dprintk(1, "init overlay [%d pages @ bus 0x%lx]\n",
@@ -284,9 +281,8 @@ int videobuf_dma_init_overlay(struct videobuf_dmabuf *dma, int direction,
284 281
285 return 0; 282 return 0;
286} 283}
287EXPORT_SYMBOL_GPL(videobuf_dma_init_overlay);
288 284
289int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma) 285static int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
290{ 286{
291 MAGIC_CHECK(dma->magic, MAGIC_DMABUF); 287 MAGIC_CHECK(dma->magic, MAGIC_DMABUF);
292 BUG_ON(0 == dma->nr_pages); 288 BUG_ON(0 == dma->nr_pages);
@@ -328,7 +324,6 @@ int videobuf_dma_map(struct device *dev, struct videobuf_dmabuf *dma)
328 324
329 return 0; 325 return 0;
330} 326}
331EXPORT_SYMBOL_GPL(videobuf_dma_map);
332 327
333int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma) 328int videobuf_dma_unmap(struct device *dev, struct videobuf_dmabuf *dma)
334{ 329{
diff --git a/drivers/media/v4l2-core/videobuf2-vmalloc.c b/drivers/media/v4l2-core/videobuf2-vmalloc.c
index fba944e50227..bcde88572429 100644
--- a/drivers/media/v4l2-core/videobuf2-vmalloc.c
+++ b/drivers/media/v4l2-core/videobuf2-vmalloc.c
@@ -95,7 +95,7 @@ static void *vb2_vmalloc_get_userptr(void *alloc_ctx, unsigned long vaddr,
95 if (vb2_get_contig_userptr(vaddr, size, &vma, &physp)) 95 if (vb2_get_contig_userptr(vaddr, size, &vma, &physp))
96 goto fail_pages_array_alloc; 96 goto fail_pages_array_alloc;
97 buf->vma = vma; 97 buf->vma = vma;
98 buf->vaddr = ioremap_nocache(physp, size); 98 buf->vaddr = (__force void *)ioremap_nocache(physp, size);
99 if (!buf->vaddr) 99 if (!buf->vaddr)
100 goto fail_pages_array_alloc; 100 goto fail_pages_array_alloc;
101 } else { 101 } else {
@@ -155,7 +155,7 @@ static void vb2_vmalloc_put_userptr(void *buf_priv)
155 kfree(buf->pages); 155 kfree(buf->pages);
156 } else { 156 } else {
157 vb2_put_vma(buf->vma); 157 vb2_put_vma(buf->vma);
158 iounmap(buf->vaddr); 158 iounmap((__force void __iomem *)buf->vaddr);
159 } 159 }
160 kfree(buf); 160 kfree(buf);
161} 161}
@@ -211,6 +211,7 @@ static int vb2_vmalloc_mmap(void *buf_priv, struct vm_area_struct *vma)
211 return 0; 211 return 0;
212} 212}
213 213
214#ifdef CONFIG_HAS_DMA
214/*********************************************/ 215/*********************************************/
215/* DMABUF ops for exporters */ 216/* DMABUF ops for exporters */
216/*********************************************/ 217/*********************************************/
@@ -380,6 +381,8 @@ static struct dma_buf *vb2_vmalloc_get_dmabuf(void *buf_priv, unsigned long flag
380 381
381 return dbuf; 382 return dbuf;
382} 383}
384#endif /* CONFIG_HAS_DMA */
385
383 386
384/*********************************************/ 387/*********************************************/
385/* callbacks for DMABUF buffers */ 388/* callbacks for DMABUF buffers */
@@ -437,7 +440,9 @@ const struct vb2_mem_ops vb2_vmalloc_memops = {
437 .put = vb2_vmalloc_put, 440 .put = vb2_vmalloc_put,
438 .get_userptr = vb2_vmalloc_get_userptr, 441 .get_userptr = vb2_vmalloc_get_userptr,
439 .put_userptr = vb2_vmalloc_put_userptr, 442 .put_userptr = vb2_vmalloc_put_userptr,
443#ifdef CONFIG_HAS_DMA
440 .get_dmabuf = vb2_vmalloc_get_dmabuf, 444 .get_dmabuf = vb2_vmalloc_get_dmabuf,
445#endif
441 .map_dmabuf = vb2_vmalloc_map_dmabuf, 446 .map_dmabuf = vb2_vmalloc_map_dmabuf,
442 .unmap_dmabuf = vb2_vmalloc_unmap_dmabuf, 447 .unmap_dmabuf = vb2_vmalloc_unmap_dmabuf,
443 .attach_dmabuf = vb2_vmalloc_attach_dmabuf, 448 .attach_dmabuf = vb2_vmalloc_attach_dmabuf,
diff --git a/drivers/staging/media/Kconfig b/drivers/staging/media/Kconfig
index 2a054a99d433..96498b7fc20e 100644
--- a/drivers/staging/media/Kconfig
+++ b/drivers/staging/media/Kconfig
@@ -27,18 +27,12 @@ source "drivers/staging/media/davinci_vpfe/Kconfig"
27 27
28source "drivers/staging/media/dt3155v4l/Kconfig" 28source "drivers/staging/media/dt3155v4l/Kconfig"
29 29
30source "drivers/staging/media/tlg2300/Kconfig"
31
32source "drivers/staging/media/mn88472/Kconfig" 30source "drivers/staging/media/mn88472/Kconfig"
33 31
34source "drivers/staging/media/mn88473/Kconfig" 32source "drivers/staging/media/mn88473/Kconfig"
35 33
36source "drivers/staging/media/omap4iss/Kconfig" 34source "drivers/staging/media/omap4iss/Kconfig"
37 35
38source "drivers/staging/media/parport/Kconfig"
39
40source "drivers/staging/media/vino/Kconfig"
41
42# Keep LIRC at the end, as it has sub-menus 36# Keep LIRC at the end, as it has sub-menus
43source "drivers/staging/media/lirc/Kconfig" 37source "drivers/staging/media/lirc/Kconfig"
44 38
diff --git a/drivers/staging/media/Makefile b/drivers/staging/media/Makefile
index 412b28408398..a9006bcb4472 100644
--- a/drivers/staging/media/Makefile
+++ b/drivers/staging/media/Makefile
@@ -6,7 +6,3 @@ obj-$(CONFIG_VIDEO_DM365_VPFE) += davinci_vpfe/
6obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/ 6obj-$(CONFIG_VIDEO_OMAP4) += omap4iss/
7obj-$(CONFIG_DVB_MN88472) += mn88472/ 7obj-$(CONFIG_DVB_MN88472) += mn88472/
8obj-$(CONFIG_DVB_MN88473) += mn88473/ 8obj-$(CONFIG_DVB_MN88473) += mn88473/
9obj-y += parport/
10obj-$(CONFIG_VIDEO_TLG2300) += tlg2300/
11obj-y += vino/
12
diff --git a/drivers/staging/media/bcm2048/radio-bcm2048.c b/drivers/staging/media/bcm2048/radio-bcm2048.c
index 60a57b2a8fb2..538250667918 100644
--- a/drivers/staging/media/bcm2048/radio-bcm2048.c
+++ b/drivers/staging/media/bcm2048/radio-bcm2048.c
@@ -2684,9 +2684,7 @@ static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client)
2684 vd = bdev->videodev; 2684 vd = bdev->videodev;
2685 2685
2686 bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs)); 2686 bcm2048_sysfs_unregister_properties(bdev, ARRAY_SIZE(attrs));
2687 2687 video_unregister_device(vd);
2688 if (vd)
2689 video_unregister_device(vd);
2690 2688
2691 if (bdev->power_state) 2689 if (bdev->power_state)
2692 bcm2048_set_power_state(bdev, BCM2048_POWER_OFF); 2690 bcm2048_set_power_state(bdev, BCM2048_POWER_OFF);
@@ -2699,8 +2697,6 @@ static int __exit bcm2048_i2c_driver_remove(struct i2c_client *client)
2699 kfree(bdev); 2697 kfree(bdev);
2700 } 2698 }
2701 2699
2702 i2c_set_clientdata(client, NULL);
2703
2704 return 0; 2700 return 0;
2705} 2701}
2706 2702
diff --git a/drivers/staging/media/davinci_vpfe/dm365_isif.c b/drivers/staging/media/davinci_vpfe/dm365_isif.c
index 0ba0bf2c1cff..bcf762bc233d 100644
--- a/drivers/staging/media/davinci_vpfe/dm365_isif.c
+++ b/drivers/staging/media/davinci_vpfe/dm365_isif.c
@@ -1535,7 +1535,7 @@ isif_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1535} 1535}
1536 1536
1537/* 1537/*
1538 * isif_pad_set_crop() - set crop rectangle on pad 1538 * isif_pad_set_selection() - set crop rectangle on pad
1539 * @sd: VPFE isif V4L2 subdevice 1539 * @sd: VPFE isif V4L2 subdevice
1540 * @fh: V4L2 subdev file handle 1540 * @fh: V4L2 subdev file handle
1541 * @code: pointer to v4l2_subdev_mbus_code_enum structure 1541 * @code: pointer to v4l2_subdev_mbus_code_enum structure
@@ -1543,35 +1543,36 @@ isif_enum_mbus_code(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1543 * Return 0 on success, -EINVAL if pad is invalid 1543 * Return 0 on success, -EINVAL if pad is invalid
1544 */ 1544 */
1545static int 1545static int
1546isif_pad_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, 1546isif_pad_set_selection(struct v4l2_subdev *sd,
1547 struct v4l2_subdev_crop *crop) 1547 struct v4l2_subdev_fh *fh,
1548 struct v4l2_subdev_selection *sel)
1548{ 1549{
1549 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd); 1550 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
1550 struct v4l2_mbus_framefmt *format; 1551 struct v4l2_mbus_framefmt *format;
1551 1552
1552 /* check wether its a valid pad */ 1553 /* check whether it's a valid pad and target */
1553 if (crop->pad != ISIF_PAD_SINK) 1554 if (sel->pad != ISIF_PAD_SINK || sel->target != V4L2_SEL_TGT_CROP)
1554 return -EINVAL; 1555 return -EINVAL;
1555 1556
1556 format = __isif_get_format(vpfe_isif, fh, crop->pad, crop->which); 1557 format = __isif_get_format(vpfe_isif, fh, sel->pad, sel->which);
1557 if (format == NULL) 1558 if (format == NULL)
1558 return -EINVAL; 1559 return -EINVAL;
1559 1560
1560 /* check wether crop rect is within limits */ 1561 /* check wether crop rect is within limits */
1561 if (crop->rect.top < 0 || crop->rect.left < 0 || 1562 if (sel->r.top < 0 || sel->r.left < 0 ||
1562 (crop->rect.left + crop->rect.width > 1563 (sel->r.left + sel->r.width >
1563 vpfe_isif->formats[ISIF_PAD_SINK].width) || 1564 vpfe_isif->formats[ISIF_PAD_SINK].width) ||
1564 (crop->rect.top + crop->rect.height > 1565 (sel->r.top + sel->r.height >
1565 vpfe_isif->formats[ISIF_PAD_SINK].height)) { 1566 vpfe_isif->formats[ISIF_PAD_SINK].height)) {
1566 crop->rect.left = 0; 1567 sel->r.left = 0;
1567 crop->rect.top = 0; 1568 sel->r.top = 0;
1568 crop->rect.width = format->width; 1569 sel->r.width = format->width;
1569 crop->rect.height = format->height; 1570 sel->r.height = format->height;
1570 } 1571 }
1571 /* adjust the width to 16 pixel boundary */ 1572 /* adjust the width to 16 pixel boundary */
1572 crop->rect.width = ((crop->rect.width + 15) & ~0xf); 1573 sel->r.width = ((sel->r.width + 15) & ~0xf);
1573 vpfe_isif->crop = crop->rect; 1574 vpfe_isif->crop = sel->r;
1574 if (crop->which == V4L2_SUBDEV_FORMAT_ACTIVE) { 1575 if (sel->which == V4L2_SUBDEV_FORMAT_ACTIVE) {
1575 isif_set_image_window(vpfe_isif); 1576 isif_set_image_window(vpfe_isif);
1576 } else { 1577 } else {
1577 struct v4l2_rect *rect; 1578 struct v4l2_rect *rect;
@@ -1583,7 +1584,7 @@ isif_pad_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1583} 1584}
1584 1585
1585/* 1586/*
1586 * isif_pad_get_crop() - get crop rectangle on pad 1587 * isif_pad_get_selection() - get crop rectangle on pad
1587 * @sd: VPFE isif V4L2 subdevice 1588 * @sd: VPFE isif V4L2 subdevice
1588 * @fh: V4L2 subdev file handle 1589 * @fh: V4L2 subdev file handle
1589 * @code: pointer to v4l2_subdev_mbus_code_enum structure 1590 * @code: pointer to v4l2_subdev_mbus_code_enum structure
@@ -1591,22 +1592,23 @@ isif_pad_set_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh,
1591 * Return 0 on success, -EINVAL if pad is invalid 1592 * Return 0 on success, -EINVAL if pad is invalid
1592 */ 1593 */
1593static int 1594static int
1594isif_pad_get_crop(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh, 1595isif_pad_get_selection(struct v4l2_subdev *sd,
1595 struct v4l2_subdev_crop *crop) 1596 struct v4l2_subdev_fh *fh,
1597 struct v4l2_subdev_selection *sel)
1596{ 1598{
1597 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd); 1599 struct vpfe_isif_device *vpfe_isif = v4l2_get_subdevdata(sd);
1598 1600
1599 /* check wether its a valid pad */ 1601 /* check whether it's a valid pad and target */
1600 if (crop->pad != ISIF_PAD_SINK) 1602 if (sel->pad != ISIF_PAD_SINK || sel->target != V4L2_SEL_TGT_CROP)
1601 return -EINVAL; 1603 return -EINVAL;
1602 1604
1603 if (crop->which == V4L2_SUBDEV_FORMAT_TRY) { 1605 if (sel->which == V4L2_SUBDEV_FORMAT_TRY) {
1604 struct v4l2_rect *rect; 1606 struct v4l2_rect *rect;
1605 1607
1606 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK); 1608 rect = v4l2_subdev_get_try_crop(fh, ISIF_PAD_SINK);
1607 memcpy(&crop->rect, rect, sizeof(*rect)); 1609 memcpy(&sel->r, rect, sizeof(*rect));
1608 } else { 1610 } else {
1609 crop->rect = vpfe_isif->crop; 1611 sel->r = vpfe_isif->crop;
1610 } 1612 }
1611 1613
1612 return 0; 1614 return 0;
@@ -1626,7 +1628,7 @@ isif_init_formats(struct v4l2_subdev *sd,
1626 struct v4l2_subdev_fh *fh) 1628 struct v4l2_subdev_fh *fh)
1627{ 1629{
1628 struct v4l2_subdev_format format; 1630 struct v4l2_subdev_format format;
1629 struct v4l2_subdev_crop crop; 1631 struct v4l2_subdev_selection sel;
1630 1632
1631 memset(&format, 0, sizeof(format)); 1633 memset(&format, 0, sizeof(format));
1632 format.pad = ISIF_PAD_SINK; 1634 format.pad = ISIF_PAD_SINK;
@@ -1644,12 +1646,13 @@ isif_init_formats(struct v4l2_subdev *sd,
1644 format.format.height = MAX_HEIGHT; 1646 format.format.height = MAX_HEIGHT;
1645 isif_set_format(sd, fh, &format); 1647 isif_set_format(sd, fh, &format);
1646 1648
1647 memset(&crop, 0, sizeof(crop)); 1649 memset(&sel, 0, sizeof(sel));
1648 crop.pad = ISIF_PAD_SINK; 1650 sel.pad = ISIF_PAD_SINK;
1649 crop.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE; 1651 sel.which = fh ? V4L2_SUBDEV_FORMAT_TRY : V4L2_SUBDEV_FORMAT_ACTIVE;
1650 crop.rect.width = MAX_WIDTH; 1652 sel.target = V4L2_SEL_TGT_CROP;
1651 crop.rect.height = MAX_HEIGHT; 1653 sel.r.width = MAX_WIDTH;
1652 isif_pad_set_crop(sd, fh, &crop); 1654 sel.r.height = MAX_HEIGHT;
1655 isif_pad_set_selection(sd, fh, &sel);
1653 1656
1654 return 0; 1657 return 0;
1655} 1658}
@@ -1675,8 +1678,8 @@ static const struct v4l2_subdev_pad_ops isif_v4l2_pad_ops = {
1675 .enum_frame_size = isif_enum_frame_size, 1678 .enum_frame_size = isif_enum_frame_size,
1676 .get_fmt = isif_get_format, 1679 .get_fmt = isif_get_format,
1677 .set_fmt = isif_set_format, 1680 .set_fmt = isif_set_format,
1678 .set_crop = isif_pad_set_crop, 1681 .set_selection = isif_pad_set_selection,
1679 .get_crop = isif_pad_get_crop, 1682 .get_selection = isif_pad_get_selection,
1680}; 1683};
1681 1684
1682/* subdev operations */ 1685/* subdev operations */
diff --git a/drivers/staging/media/lirc/lirc_serial.c b/drivers/staging/media/lirc/lirc_serial.c
index eb4ccb8d2a93..19628d0104ab 100644
--- a/drivers/staging/media/lirc/lirc_serial.c
+++ b/drivers/staging/media/lirc/lirc_serial.c
@@ -107,7 +107,7 @@ static int io;
107static int irq; 107static int irq;
108static bool iommap; 108static bool iommap;
109static int ioshift; 109static int ioshift;
110static bool softcarrier = 1; 110static bool softcarrier = true;
111static bool share_irq; 111static bool share_irq;
112static bool debug; 112static bool debug;
113static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */ 113static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */
@@ -266,7 +266,7 @@ static unsigned long space_width;
266/* fetch serial input packet (1 byte) from register offset */ 266/* fetch serial input packet (1 byte) from register offset */
267static u8 sinp(int offset) 267static u8 sinp(int offset)
268{ 268{
269 if (iommap != 0) 269 if (iommap)
270 /* the register is memory-mapped */ 270 /* the register is memory-mapped */
271 offset <<= ioshift; 271 offset <<= ioshift;
272 272
@@ -276,7 +276,7 @@ static u8 sinp(int offset)
276/* write serial output packet (1 byte) of value to register offset */ 276/* write serial output packet (1 byte) of value to register offset */
277static void soutp(int offset, u8 value) 277static void soutp(int offset, u8 value)
278{ 278{
279 if (iommap != 0) 279 if (iommap)
280 /* the register is memory-mapped */ 280 /* the register is memory-mapped */
281 offset <<= ioshift; 281 offset <<= ioshift;
282 282
@@ -799,10 +799,10 @@ static int lirc_serial_probe(struct platform_device *dev)
799 * For memory mapped I/O you *might* need to use ioremap() first, 799 * For memory mapped I/O you *might* need to use ioremap() first,
800 * for the NSLU2 it's done in boot code. 800 * for the NSLU2 it's done in boot code.
801 */ 801 */
802 if (((iommap != 0) 802 if (((iommap)
803 && (devm_request_mem_region(&dev->dev, iommap, 8 << ioshift, 803 && (devm_request_mem_region(&dev->dev, iommap, 8 << ioshift,
804 LIRC_DRIVER_NAME) == NULL)) 804 LIRC_DRIVER_NAME) == NULL))
805 || ((iommap == 0) 805 || ((!iommap)
806 && (devm_request_region(&dev->dev, io, 8, 806 && (devm_request_region(&dev->dev, io, 8,
807 LIRC_DRIVER_NAME) == NULL))) { 807 LIRC_DRIVER_NAME) == NULL))) {
808 dev_err(&dev->dev, "port %04x already in use\n", io); 808 dev_err(&dev->dev, "port %04x already in use\n", io);
diff --git a/drivers/staging/media/lirc/lirc_zilog.c b/drivers/staging/media/lirc/lirc_zilog.c
index cc872fb4ca68..e16627ca488e 100644
--- a/drivers/staging/media/lirc/lirc_zilog.c
+++ b/drivers/staging/media/lirc/lirc_zilog.c
@@ -369,17 +369,17 @@ static int add_to_buf(struct IR *ir)
369 ret = i2c_master_send(rx->c, sendbuf, 1); 369 ret = i2c_master_send(rx->c, sendbuf, 1);
370 if (ret != 1) { 370 if (ret != 1) {
371 dev_err(ir->l.dev, "i2c_master_send failed with %d\n", 371 dev_err(ir->l.dev, "i2c_master_send failed with %d\n",
372 ret); 372 ret);
373 if (failures >= 3) { 373 if (failures >= 3) {
374 mutex_unlock(&ir->ir_lock); 374 mutex_unlock(&ir->ir_lock);
375 dev_err(ir->l.dev, "unable to read from the IR chip " 375 dev_err(ir->l.dev,
376 "after 3 resets, giving up\n"); 376 "unable to read from the IR chip after 3 resets, giving up\n");
377 break; 377 break;
378 } 378 }
379 379
380 /* Looks like the chip crashed, reset it */ 380 /* Looks like the chip crashed, reset it */
381 dev_err(ir->l.dev, "polling the IR receiver chip failed, " 381 dev_err(ir->l.dev,
382 "trying reset\n"); 382 "polling the IR receiver chip failed, trying reset\n");
383 383
384 set_current_state(TASK_UNINTERRUPTIBLE); 384 set_current_state(TASK_UNINTERRUPTIBLE);
385 if (kthread_should_stop()) { 385 if (kthread_should_stop()) {
@@ -405,14 +405,16 @@ static int add_to_buf(struct IR *ir)
405 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf)); 405 ret = i2c_master_recv(rx->c, keybuf, sizeof(keybuf));
406 mutex_unlock(&ir->ir_lock); 406 mutex_unlock(&ir->ir_lock);
407 if (ret != sizeof(keybuf)) { 407 if (ret != sizeof(keybuf)) {
408 dev_err(ir->l.dev, "i2c_master_recv failed with %d -- " 408 dev_err(ir->l.dev,
409 "keeping last read buffer\n", ret); 409 "i2c_master_recv failed with %d -- keeping last read buffer\n",
410 ret);
410 } else { 411 } else {
411 rx->b[0] = keybuf[3]; 412 rx->b[0] = keybuf[3];
412 rx->b[1] = keybuf[4]; 413 rx->b[1] = keybuf[4];
413 rx->b[2] = keybuf[5]; 414 rx->b[2] = keybuf[5];
414 dev_dbg(ir->l.dev, "key (0x%02x/0x%02x)\n", 415 dev_dbg(ir->l.dev,
415 rx->b[0], rx->b[1]); 416 "key (0x%02x/0x%02x)\n",
417 rx->b[0], rx->b[1]);
416 } 418 }
417 419
418 /* key pressed ? */ 420 /* key pressed ? */
@@ -656,8 +658,8 @@ static int send_data_block(struct IR_tx *tx, unsigned char *data_block)
656 dev_dbg(tx->ir->l.dev, "%*ph", 5, buf); 658 dev_dbg(tx->ir->l.dev, "%*ph", 5, buf);
657 ret = i2c_master_send(tx->c, buf, tosend + 1); 659 ret = i2c_master_send(tx->c, buf, tosend + 1);
658 if (ret != tosend + 1) { 660 if (ret != tosend + 1) {
659 dev_err(tx->ir->l.dev, "i2c_master_send failed with %d\n", 661 dev_err(tx->ir->l.dev,
660 ret); 662 "i2c_master_send failed with %d\n", ret);
661 return ret < 0 ? ret : -EFAULT; 663 return ret < 0 ? ret : -EFAULT;
662 } 664 }
663 i += tosend; 665 i += tosend;
@@ -710,11 +712,12 @@ static int send_boot_data(struct IR_tx *tx)
710 } 712 }
711 if ((buf[0] != 0x80) && (buf[0] != 0xa0)) { 713 if ((buf[0] != 0x80) && (buf[0] != 0xa0)) {
712 dev_err(tx->ir->l.dev, "unexpected IR TX init response: %02x\n", 714 dev_err(tx->ir->l.dev, "unexpected IR TX init response: %02x\n",
713 buf[0]); 715 buf[0]);
714 return 0; 716 return 0;
715 } 717 }
716 dev_notice(tx->ir->l.dev, "Zilog/Hauppauge IR blaster firmware version " 718 dev_notice(tx->ir->l.dev,
717 "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]); 719 "Zilog/Hauppauge IR blaster firmware version %d.%d.%d loaded\n",
720 buf[1], buf[2], buf[3]);
718 721
719 return 0; 722 return 0;
720} 723}
@@ -759,8 +762,9 @@ static int fw_load(struct IR_tx *tx)
759 /* Request codeset data file */ 762 /* Request codeset data file */
760 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", tx->ir->l.dev); 763 ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", tx->ir->l.dev);
761 if (ret != 0) { 764 if (ret != 0) {
762 dev_err(tx->ir->l.dev, "firmware haup-ir-blaster.bin not available (%d)\n", 765 dev_err(tx->ir->l.dev,
763 ret); 766 "firmware haup-ir-blaster.bin not available (%d)\n",
767 ret);
764 ret = ret < 0 ? ret : -EFAULT; 768 ret = ret < 0 ? ret : -EFAULT;
765 goto out; 769 goto out;
766 } 770 }
@@ -792,9 +796,9 @@ static int fw_load(struct IR_tx *tx)
792 if (!read_uint8(&data, tx_data->endp, &version)) 796 if (!read_uint8(&data, tx_data->endp, &version))
793 goto corrupt; 797 goto corrupt;
794 if (version != 1) { 798 if (version != 1) {
795 dev_err(tx->ir->l.dev, "unsupported code set file version (%u, expected" 799 dev_err(tx->ir->l.dev,
796 "1) -- please upgrade to a newer driver", 800 "unsupported code set file version (%u, expected 1) -- please upgrade to a newer driver\n",
797 version); 801 version);
798 fw_unload_locked(); 802 fw_unload_locked();
799 ret = -EFAULT; 803 ret = -EFAULT;
800 goto out; 804 goto out;
@@ -810,7 +814,7 @@ static int fw_load(struct IR_tx *tx)
810 goto corrupt; 814 goto corrupt;
811 815
812 dev_dbg(tx->ir->l.dev, "%u IR blaster codesets loaded\n", 816 dev_dbg(tx->ir->l.dev, "%u IR blaster codesets loaded\n",
813 tx_data->num_code_sets); 817 tx_data->num_code_sets);
814 818
815 tx_data->code_sets = vmalloc( 819 tx_data->code_sets = vmalloc(
816 tx_data->num_code_sets * sizeof(char *)); 820 tx_data->num_code_sets * sizeof(char *));
@@ -940,8 +944,9 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
940 unsigned char buf[MAX_XFER_SIZE]; 944 unsigned char buf[MAX_XFER_SIZE];
941 945
942 if (rbuf->chunk_size > sizeof(buf)) { 946 if (rbuf->chunk_size > sizeof(buf)) {
943 dev_err(ir->l.dev, "chunk_size is too big (%d)!\n", 947 dev_err(ir->l.dev,
944 rbuf->chunk_size); 948 "chunk_size is too big (%d)!\n",
949 rbuf->chunk_size);
945 ret = -EINVAL; 950 ret = -EINVAL;
946 break; 951 break;
947 } 952 }
@@ -964,8 +969,8 @@ static ssize_t read(struct file *filep, char __user *outbuf, size_t n,
964 put_ir_rx(rx, false); 969 put_ir_rx(rx, false);
965 set_current_state(TASK_RUNNING); 970 set_current_state(TASK_RUNNING);
966 971
967 dev_dbg(ir->l.dev, "read result = %d (%s)\n", 972 dev_dbg(ir->l.dev, "read result = %d (%s)\n", ret,
968 ret, ret ? "Error" : "OK"); 973 ret ? "Error" : "OK");
969 974
970 return ret ? ret : written; 975 return ret ? ret : written;
971} 976}
@@ -981,8 +986,9 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
981 ret = get_key_data(data_block, code, key); 986 ret = get_key_data(data_block, code, key);
982 987
983 if (ret == -EPROTO) { 988 if (ret == -EPROTO) {
984 dev_err(tx->ir->l.dev, "failed to get data for code %u, key %u -- check " 989 dev_err(tx->ir->l.dev,
985 "lircd.conf entries\n", code, key); 990 "failed to get data for code %u, key %u -- check lircd.conf entries\n",
991 code, key);
986 return ret; 992 return ret;
987 } else if (ret != 0) 993 } else if (ret != 0)
988 return ret; 994 return ret;
@@ -1057,12 +1063,14 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1057 ret = i2c_master_send(tx->c, buf, 1); 1063 ret = i2c_master_send(tx->c, buf, 1);
1058 if (ret == 1) 1064 if (ret == 1)
1059 break; 1065 break;
1060 dev_dbg(tx->ir->l.dev, "NAK expected: i2c_master_send " 1066 dev_dbg(tx->ir->l.dev,
1061 "failed with %d (try %d)\n", ret, i+1); 1067 "NAK expected: i2c_master_send failed with %d (try %d)\n",
1068 ret, i+1);
1062 } 1069 }
1063 if (ret != 1) { 1070 if (ret != 1) {
1064 dev_err(tx->ir->l.dev, "IR TX chip never got ready: last i2c_master_send " 1071 dev_err(tx->ir->l.dev,
1065 "failed with %d\n", ret); 1072 "IR TX chip never got ready: last i2c_master_send failed with %d\n",
1073 ret);
1066 return ret < 0 ? ret : -EFAULT; 1074 return ret < 0 ? ret : -EFAULT;
1067 } 1075 }
1068 1076
@@ -1074,7 +1082,7 @@ static int send_code(struct IR_tx *tx, unsigned int code, unsigned int key)
1074 } 1082 }
1075 if (buf[0] != 0x80) { 1083 if (buf[0] != 0x80) {
1076 dev_err(tx->ir->l.dev, "unexpected IR TX response #2: %02x\n", 1084 dev_err(tx->ir->l.dev, "unexpected IR TX response #2: %02x\n",
1077 buf[0]); 1085 buf[0]);
1078 return -EFAULT; 1086 return -EFAULT;
1079 } 1087 }
1080 1088
@@ -1165,12 +1173,12 @@ static ssize_t write(struct file *filep, const char __user *buf, size_t n,
1165 */ 1173 */
1166 if (ret != 0) { 1174 if (ret != 0) {
1167 /* Looks like the chip crashed, reset it */ 1175 /* Looks like the chip crashed, reset it */
1168 dev_err(tx->ir->l.dev, "sending to the IR transmitter chip " 1176 dev_err(tx->ir->l.dev,
1169 "failed, trying reset\n"); 1177 "sending to the IR transmitter chip failed, trying reset\n");
1170 1178
1171 if (failures >= 3) { 1179 if (failures >= 3) {
1172 dev_err(tx->ir->l.dev, "unable to send to the IR chip " 1180 dev_err(tx->ir->l.dev,
1173 "after 3 resets, giving up\n"); 1181 "unable to send to the IR chip after 3 resets, giving up\n");
1174 mutex_unlock(&ir->ir_lock); 1182 mutex_unlock(&ir->ir_lock);
1175 mutex_unlock(&tx->client_lock); 1183 mutex_unlock(&tx->client_lock);
1176 put_ir_tx(tx, false); 1184 put_ir_tx(tx, false);
@@ -1226,7 +1234,7 @@ static unsigned int poll(struct file *filep, poll_table *wait)
1226 ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM); 1234 ret = lirc_buffer_empty(rbuf) ? 0 : (POLLIN|POLLRDNORM);
1227 1235
1228 dev_dbg(ir->l.dev, "poll result = %s\n", 1236 dev_dbg(ir->l.dev, "poll result = %s\n",
1229 ret ? "POLLIN|POLLRDNORM" : "none"); 1237 ret ? "POLLIN|POLLRDNORM" : "none");
1230 return ret; 1238 return ret;
1231} 1239}
1232 1240
@@ -1333,7 +1341,8 @@ static int close(struct inode *node, struct file *filep)
1333 struct IR *ir = filep->private_data; 1341 struct IR *ir = filep->private_data;
1334 1342
1335 if (ir == NULL) { 1343 if (ir == NULL) {
1336 dev_err(ir->l.dev, "close: no private_data attached to the file!\n"); 1344 dev_err(ir->l.dev,
1345 "close: no private_data attached to the file!\n");
1337 return -ENODEV; 1346 return -ENODEV;
1338 } 1347 }
1339 1348
@@ -1540,8 +1549,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1540 1549
1541 /* Proceed only if the Rx client is also ready or not needed */ 1550 /* Proceed only if the Rx client is also ready or not needed */
1542 if (rx == NULL && !tx_only) { 1551 if (rx == NULL && !tx_only) {
1543 dev_info(tx->ir->l.dev, "probe of IR Tx on %s (i2c-%d) done. Waiting" 1552 dev_info(tx->ir->l.dev,
1544 " on IR Rx.\n", adap->name, adap->nr); 1553 "probe of IR Tx on %s (i2c-%d) done. Waiting on IR Rx.\n",
1554 adap->name, adap->nr);
1545 goto out_ok; 1555 goto out_ok;
1546 } 1556 }
1547 } else { 1557 } else {
@@ -1579,8 +1589,9 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1579 "zilog-rx-i2c-%d", adap->nr); 1589 "zilog-rx-i2c-%d", adap->nr);
1580 if (IS_ERR(rx->task)) { 1590 if (IS_ERR(rx->task)) {
1581 ret = PTR_ERR(rx->task); 1591 ret = PTR_ERR(rx->task);
1582 dev_err(tx->ir->l.dev, "%s: could not start IR Rx polling thread" 1592 dev_err(tx->ir->l.dev,
1583 "\n", __func__); 1593 "%s: could not start IR Rx polling thread\n",
1594 __func__);
1584 /* Failed kthread, so put back the ir ref */ 1595 /* Failed kthread, so put back the ir ref */
1585 put_ir_device(ir, true); 1596 put_ir_device(ir, true);
1586 /* Failure exit, so put back rx ref from i2c_client */ 1597 /* Failure exit, so put back rx ref from i2c_client */
@@ -1592,8 +1603,8 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1592 1603
1593 /* Proceed only if the Tx client is also ready */ 1604 /* Proceed only if the Tx client is also ready */
1594 if (tx == NULL) { 1605 if (tx == NULL) {
1595 pr_info("probe of IR Rx on %s (i2c-%d) done. Waiting" 1606 pr_info("probe of IR Rx on %s (i2c-%d) done. Waiting on IR Tx.\n",
1596 " on IR Tx.\n", adap->name, adap->nr); 1607 adap->name, adap->nr);
1597 goto out_ok; 1608 goto out_ok;
1598 } 1609 }
1599 } 1610 }
@@ -1602,13 +1613,15 @@ static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id)
1602 ir->l.minor = minor; /* module option: user requested minor number */ 1613 ir->l.minor = minor; /* module option: user requested minor number */
1603 ir->l.minor = lirc_register_driver(&ir->l); 1614 ir->l.minor = lirc_register_driver(&ir->l);
1604 if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) { 1615 if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) {
1605 dev_err(tx->ir->l.dev, "%s: \"minor\" must be between 0 and %d (%d)!\n", 1616 dev_err(tx->ir->l.dev,
1606 __func__, MAX_IRCTL_DEVICES-1, ir->l.minor); 1617 "%s: \"minor\" must be between 0 and %d (%d)!\n",
1618 __func__, MAX_IRCTL_DEVICES-1, ir->l.minor);
1607 ret = -EBADRQC; 1619 ret = -EBADRQC;
1608 goto out_put_xx; 1620 goto out_put_xx;
1609 } 1621 }
1610 dev_info(ir->l.dev, "IR unit on %s (i2c-%d) registered as lirc%d and ready\n", 1622 dev_info(ir->l.dev,
1611 adap->name, adap->nr, ir->l.minor); 1623 "IR unit on %s (i2c-%d) registered as lirc%d and ready\n",
1624 adap->name, adap->nr, ir->l.minor);
1612 1625
1613out_ok: 1626out_ok:
1614 if (rx != NULL) 1627 if (rx != NULL)
@@ -1616,8 +1629,9 @@ out_ok:
1616 if (tx != NULL) 1629 if (tx != NULL)
1617 put_ir_tx(tx, true); 1630 put_ir_tx(tx, true);
1618 put_ir_device(ir, true); 1631 put_ir_device(ir, true);
1619 dev_info(ir->l.dev, "probe of IR %s on %s (i2c-%d) done\n", 1632 dev_info(ir->l.dev,
1620 tx_probe ? "Tx" : "Rx", adap->name, adap->nr); 1633 "probe of IR %s on %s (i2c-%d) done\n",
1634 tx_probe ? "Tx" : "Rx", adap->name, adap->nr);
1621 mutex_unlock(&ir_devices_lock); 1635 mutex_unlock(&ir_devices_lock);
1622 return 0; 1636 return 0;
1623 1637
@@ -1629,9 +1643,9 @@ out_put_xx:
1629out_put_ir: 1643out_put_ir:
1630 put_ir_device(ir, true); 1644 put_ir_device(ir, true);
1631out_no_ir: 1645out_no_ir:
1632 dev_err(&client->dev, "%s: probing IR %s on %s (i2c-%d) failed with %d\n", 1646 dev_err(&client->dev,
1633 __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr, 1647 "%s: probing IR %s on %s (i2c-%d) failed with %d\n",
1634 ret); 1648 __func__, tx_probe ? "Tx" : "Rx", adap->name, adap->nr, ret);
1635 mutex_unlock(&ir_devices_lock); 1649 mutex_unlock(&ir_devices_lock);
1636 return ret; 1650 return ret;
1637} 1651}
diff --git a/drivers/staging/media/mn88472/mn88472.c b/drivers/staging/media/mn88472/mn88472.c
index 52de8f85d36c..6eebe564e557 100644
--- a/drivers/staging/media/mn88472/mn88472.c
+++ b/drivers/staging/media/mn88472/mn88472.c
@@ -30,6 +30,7 @@ static int mn88472_set_frontend(struct dvb_frontend *fe)
30 struct dtv_frontend_properties *c = &fe->dtv_property_cache; 30 struct dtv_frontend_properties *c = &fe->dtv_property_cache;
31 int ret, i; 31 int ret, i;
32 u32 if_frequency = 0; 32 u32 if_frequency = 0;
33 u64 tmp;
33 u8 delivery_system_val, if_val[3], bw_val[7], bw_val2; 34 u8 delivery_system_val, if_val[3], bw_val[7], bw_val2;
34 35
35 dev_dbg(&client->dev, 36 dev_dbg(&client->dev,
@@ -57,36 +58,22 @@ static int mn88472_set_frontend(struct dvb_frontend *fe)
57 goto err; 58 goto err;
58 } 59 }
59 60
60 switch (c->delivery_system) { 61 if (c->bandwidth_hz <= 5000000) {
61 case SYS_DVBT: 62 memcpy(bw_val, "\xe5\x99\x9a\x1b\xa9\x1b\xa9", 7);
62 case SYS_DVBT2: 63 bw_val2 = 0x03;
63 if (c->bandwidth_hz <= 6000000) { 64 } else if (c->bandwidth_hz <= 6000000) {
64 /* IF 3570000 Hz, BW 6000000 Hz */ 65 /* IF 3570000 Hz, BW 6000000 Hz */
65 memcpy(if_val, "\x2c\x94\xdb", 3); 66 memcpy(bw_val, "\xbf\x55\x55\x15\x6b\x15\x6b", 7);
66 memcpy(bw_val, "\xbf\x55\x55\x15\x6b\x15\x6b", 7); 67 bw_val2 = 0x02;
67 bw_val2 = 0x02; 68 } else if (c->bandwidth_hz <= 7000000) {
68 } else if (c->bandwidth_hz <= 7000000) { 69 /* IF 4570000 Hz, BW 7000000 Hz */
69 /* IF 4570000 Hz, BW 7000000 Hz */ 70 memcpy(bw_val, "\xa4\x00\x00\x0f\x2c\x0f\x2c", 7);
70 memcpy(if_val, "\x39\x11\xbc", 3); 71 bw_val2 = 0x01;
71 memcpy(bw_val, "\xa4\x00\x00\x0f\x2c\x0f\x2c", 7); 72 } else if (c->bandwidth_hz <= 8000000) {
72 bw_val2 = 0x01; 73 /* IF 4570000 Hz, BW 8000000 Hz */
73 } else if (c->bandwidth_hz <= 8000000) {
74 /* IF 4570000 Hz, BW 8000000 Hz */
75 memcpy(if_val, "\x39\x11\xbc", 3);
76 memcpy(bw_val, "\x8f\x80\x00\x08\xee\x08\xee", 7);
77 bw_val2 = 0x00;
78 } else {
79 ret = -EINVAL;
80 goto err;
81 }
82 break;
83 case SYS_DVBC_ANNEX_A:
84 /* IF 5070000 Hz, BW 8000000 Hz */
85 memcpy(if_val, "\x3f\x50\x2c", 3);
86 memcpy(bw_val, "\x8f\x80\x00\x08\xee\x08\xee", 7); 74 memcpy(bw_val, "\x8f\x80\x00\x08\xee\x08\xee", 7);
87 bw_val2 = 0x00; 75 bw_val2 = 0x00;
88 break; 76 } else {
89 default:
90 ret = -EINVAL; 77 ret = -EINVAL;
91 goto err; 78 goto err;
92 } 79 }
@@ -106,17 +93,12 @@ static int mn88472_set_frontend(struct dvb_frontend *fe)
106 dev_dbg(&client->dev, "get_if_frequency=%d\n", if_frequency); 93 dev_dbg(&client->dev, "get_if_frequency=%d\n", if_frequency);
107 } 94 }
108 95
109 switch (if_frequency) { 96 /* Calculate IF registers ( (1<<24)*IF / Xtal ) */
110 case 3570000: 97 tmp = div_u64(if_frequency * (u64)(1<<24) + (dev->xtal / 2),
111 case 4570000: 98 dev->xtal);
112 case 5070000: 99 if_val[0] = ((tmp >> 16) & 0xff);
113 break; 100 if_val[1] = ((tmp >> 8) & 0xff);
114 default: 101 if_val[2] = ((tmp >> 0) & 0xff);
115 dev_err(&client->dev, "IF frequency %d not supported\n",
116 if_frequency);
117 ret = -EINVAL;
118 goto err;
119 }
120 102
121 ret = regmap_write(dev->regmap[2], 0xfb, 0x13); 103 ret = regmap_write(dev->regmap[2], 0xfb, 0x13);
122 ret = regmap_write(dev->regmap[2], 0xef, 0x13); 104 ret = regmap_write(dev->regmap[2], 0xef, 0x13);
@@ -198,6 +180,8 @@ static int mn88472_set_frontend(struct dvb_frontend *fe)
198 ret = regmap_write(dev->regmap[0], 0xae, 0x00); 180 ret = regmap_write(dev->regmap[0], 0xae, 0x00);
199 ret = regmap_write(dev->regmap[2], 0x08, 0x1d); 181 ret = regmap_write(dev->regmap[2], 0x08, 0x1d);
200 ret = regmap_write(dev->regmap[0], 0xd9, 0xe3); 182 ret = regmap_write(dev->regmap[0], 0xd9, 0xe3);
183
184 /* Reset demod */
201 ret = regmap_write(dev->regmap[2], 0xf8, 0x9f); 185 ret = regmap_write(dev->regmap[2], 0xf8, 0x9f);
202 if (ret) 186 if (ret)
203 goto err; 187 goto err;
@@ -411,6 +395,7 @@ static int mn88472_probe(struct i2c_client *client,
411 } 395 }
412 396
413 dev->i2c_wr_max = config->i2c_wr_max; 397 dev->i2c_wr_max = config->i2c_wr_max;
398 dev->xtal = config->xtal;
414 dev->client[0] = client; 399 dev->client[0] = client;
415 dev->regmap[0] = regmap_init_i2c(dev->client[0], &regmap_config); 400 dev->regmap[0] = regmap_init_i2c(dev->client[0], &regmap_config);
416 if (IS_ERR(dev->regmap[0])) { 401 if (IS_ERR(dev->regmap[0])) {
diff --git a/drivers/staging/media/mn88472/mn88472_priv.h b/drivers/staging/media/mn88472/mn88472_priv.h
index 1095949f040d..b12b731e2d4e 100644
--- a/drivers/staging/media/mn88472/mn88472_priv.h
+++ b/drivers/staging/media/mn88472/mn88472_priv.h
@@ -31,6 +31,7 @@ struct mn88472_dev {
31 u16 i2c_wr_max; 31 u16 i2c_wr_max;
32 fe_delivery_system_t delivery_system; 32 fe_delivery_system_t delivery_system;
33 bool warm; /* FW running */ 33 bool warm; /* FW running */
34 u32 xtal;
34}; 35};
35 36
36#endif 37#endif
diff --git a/drivers/staging/media/omap4iss/iss.c b/drivers/staging/media/omap4iss/iss.c
index cc1dfadd91eb..44b81a2c8b6f 100644
--- a/drivers/staging/media/omap4iss/iss.c
+++ b/drivers/staging/media/omap4iss/iss.c
@@ -560,41 +560,28 @@ static int iss_pipeline_link_notify(struct media_link *link, u32 flags,
560 */ 560 */
561 561
562/* 562/*
563 * iss_pipeline_enable - Enable streaming on a pipeline 563 * iss_pipeline_disable - Disable streaming on a pipeline
564 * @pipe: ISS pipeline 564 * @pipe: ISS pipeline
565 * @mode: Stream mode (single shot or continuous) 565 * @until: entity at which to stop pipeline walk
566 * 566 *
567 * Walk the entities chain starting at the pipeline output video node and start 567 * Walk the entities chain starting at the pipeline output video node and stop
568 * all modules in the chain in the given mode. 568 * all modules in the chain. Wait synchronously for the modules to be stopped if
569 * necessary.
569 * 570 *
570 * Return 0 if successful, or the return value of the failed video::s_stream 571 * If the until argument isn't NULL, stop the pipeline walk when reaching the
571 * operation otherwise. 572 * until entity. This is used to disable a partially started pipeline due to a
573 * subdev start error.
572 */ 574 */
573static int iss_pipeline_enable(struct iss_pipeline *pipe, 575static int iss_pipeline_disable(struct iss_pipeline *pipe,
574 enum iss_pipeline_stream_state mode) 576 struct media_entity *until)
575{ 577{
576 struct iss_device *iss = pipe->output->iss; 578 struct iss_device *iss = pipe->output->iss;
577 struct media_entity *entity; 579 struct media_entity *entity;
578 struct media_pad *pad; 580 struct media_pad *pad;
579 struct v4l2_subdev *subdev; 581 struct v4l2_subdev *subdev;
580 unsigned long flags; 582 int failure = 0;
581 int ret; 583 int ret;
582 584
583 /* If one of the entities in the pipeline has crashed it will not work
584 * properly. Refuse to start streaming in that case. This check must be
585 * performed before the loop below to avoid starting entities if the
586 * pipeline won't start anyway (those entities would then likely fail to
587 * stop, making the problem worse).
588 */
589 if (pipe->entities & iss->crashed)
590 return -EIO;
591
592 spin_lock_irqsave(&pipe->lock, flags);
593 pipe->state &= ~(ISS_PIPELINE_IDLE_INPUT | ISS_PIPELINE_IDLE_OUTPUT);
594 spin_unlock_irqrestore(&pipe->lock, flags);
595
596 pipe->do_propagation = false;
597
598 entity = &pipe->output->video.entity; 585 entity = &pipe->output->video.entity;
599 while (1) { 586 while (1) {
600 pad = &entity->pads[0]; 587 pad = &entity->pads[0];
@@ -607,33 +594,62 @@ static int iss_pipeline_enable(struct iss_pipeline *pipe,
607 break; 594 break;
608 595
609 entity = pad->entity; 596 entity = pad->entity;
610 subdev = media_entity_to_v4l2_subdev(entity); 597 if (entity == until)
598 break;
611 599
612 ret = v4l2_subdev_call(subdev, video, s_stream, mode); 600 subdev = media_entity_to_v4l2_subdev(entity);
613 if (ret < 0 && ret != -ENOIOCTLCMD) 601 ret = v4l2_subdev_call(subdev, video, s_stream, 0);
614 return ret; 602 if (ret < 0) {
603 dev_dbg(iss->dev, "%s: module stop timeout.\n",
604 subdev->name);
605 /* If the entity failed to stopped, assume it has
606 * crashed. Mark it as such, the ISS will be reset when
607 * applications will release it.
608 */
609 iss->crashed |= 1U << subdev->entity.id;
610 failure = -ETIMEDOUT;
611 }
615 } 612 }
616 iss_print_status(pipe->output->iss); 613
617 return 0; 614 return failure;
618} 615}
619 616
620/* 617/*
621 * iss_pipeline_disable - Disable streaming on a pipeline 618 * iss_pipeline_enable - Enable streaming on a pipeline
622 * @pipe: ISS pipeline 619 * @pipe: ISS pipeline
620 * @mode: Stream mode (single shot or continuous)
623 * 621 *
624 * Walk the entities chain starting at the pipeline output video node and stop 622 * Walk the entities chain starting at the pipeline output video node and start
625 * all modules in the chain. Wait synchronously for the modules to be stopped if 623 * all modules in the chain in the given mode.
626 * necessary. 624 *
625 * Return 0 if successful, or the return value of the failed video::s_stream
626 * operation otherwise.
627 */ 627 */
628static int iss_pipeline_disable(struct iss_pipeline *pipe) 628static int iss_pipeline_enable(struct iss_pipeline *pipe,
629 enum iss_pipeline_stream_state mode)
629{ 630{
630 struct iss_device *iss = pipe->output->iss; 631 struct iss_device *iss = pipe->output->iss;
631 struct media_entity *entity; 632 struct media_entity *entity;
632 struct media_pad *pad; 633 struct media_pad *pad;
633 struct v4l2_subdev *subdev; 634 struct v4l2_subdev *subdev;
634 int failure = 0; 635 unsigned long flags;
635 int ret; 636 int ret;
636 637
638 /* If one of the entities in the pipeline has crashed it will not work
639 * properly. Refuse to start streaming in that case. This check must be
640 * performed before the loop below to avoid starting entities if the
641 * pipeline won't start anyway (those entities would then likely fail to
642 * stop, making the problem worse).
643 */
644 if (pipe->entities & iss->crashed)
645 return -EIO;
646
647 spin_lock_irqsave(&pipe->lock, flags);
648 pipe->state &= ~(ISS_PIPELINE_IDLE_INPUT | ISS_PIPELINE_IDLE_OUTPUT);
649 spin_unlock_irqrestore(&pipe->lock, flags);
650
651 pipe->do_propagation = false;
652
637 entity = &pipe->output->video.entity; 653 entity = &pipe->output->video.entity;
638 while (1) { 654 while (1) {
639 pad = &entity->pads[0]; 655 pad = &entity->pads[0];
@@ -648,20 +664,19 @@ static int iss_pipeline_disable(struct iss_pipeline *pipe)
648 entity = pad->entity; 664 entity = pad->entity;
649 subdev = media_entity_to_v4l2_subdev(entity); 665 subdev = media_entity_to_v4l2_subdev(entity);
650 666
651 ret = v4l2_subdev_call(subdev, video, s_stream, 0); 667 ret = v4l2_subdev_call(subdev, video, s_stream, mode);
652 if (ret < 0) { 668 if (ret < 0 && ret != -ENOIOCTLCMD) {
653 dev_dbg(iss->dev, "%s: module stop timeout.\n", 669 iss_pipeline_disable(pipe, entity);
654 subdev->name); 670 return ret;
655 /* If the entity failed to stopped, assume it has
656 * crashed. Mark it as such, the ISS will be reset when
657 * applications will release it.
658 */
659 iss->crashed |= 1U << subdev->entity.id;
660 failure = -ETIMEDOUT;
661 } 671 }
672
673 if (subdev == &iss->csi2a.subdev ||
674 subdev == &iss->csi2b.subdev)
675 pipe->do_propagation = true;
662 } 676 }
663 677
664 return failure; 678 iss_print_status(pipe->output->iss);
679 return 0;
665} 680}
666 681
667/* 682/*
@@ -682,7 +697,7 @@ int omap4iss_pipeline_set_stream(struct iss_pipeline *pipe,
682 int ret; 697 int ret;
683 698
684 if (state == ISS_PIPELINE_STREAM_STOPPED) 699 if (state == ISS_PIPELINE_STREAM_STOPPED)
685 ret = iss_pipeline_disable(pipe); 700 ret = iss_pipeline_disable(pipe, NULL);
686 else 701 else
687 ret = iss_pipeline_enable(pipe, state); 702 ret = iss_pipeline_enable(pipe, state);
688 703
diff --git a/drivers/staging/media/omap4iss/iss_csi2.c b/drivers/staging/media/omap4iss/iss_csi2.c
index 21971c675b8c..2d96fb3eca53 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.c
+++ b/drivers/staging/media/omap4iss/iss_csi2.c
@@ -319,6 +319,8 @@ static void csi2_ctx_config(struct iss_csi2_device *csi2,
319{ 319{
320 u32 reg = 0; 320 u32 reg = 0;
321 321
322 ctx->frame = 0;
323
322 /* Set up CSI2_CTx_CTRL1 */ 324 /* Set up CSI2_CTx_CTRL1 */
323 if (ctx->eof_enabled) 325 if (ctx->eof_enabled)
324 reg = CSI2_CTX_CTRL1_EOF_EN; 326 reg = CSI2_CTX_CTRL1_EOF_EN;
@@ -396,21 +398,18 @@ static void csi2_timing_config(struct iss_csi2_device *csi2,
396 */ 398 */
397static void csi2_irq_ctx_set(struct iss_csi2_device *csi2, int enable) 399static void csi2_irq_ctx_set(struct iss_csi2_device *csi2, int enable)
398{ 400{
399 u32 reg = CSI2_CTX_IRQ_FE; 401 const u32 mask = CSI2_CTX_IRQ_FE | CSI2_CTX_IRQ_FS;
400 int i; 402 int i;
401 403
402 if (csi2->use_fs_irq)
403 reg |= CSI2_CTX_IRQ_FS;
404
405 for (i = 0; i < 8; i++) { 404 for (i = 0; i < 8; i++) {
406 iss_reg_write(csi2->iss, csi2->regs1, CSI2_CTX_IRQSTATUS(i), 405 iss_reg_write(csi2->iss, csi2->regs1, CSI2_CTX_IRQSTATUS(i),
407 reg); 406 mask);
408 if (enable) 407 if (enable)
409 iss_reg_set(csi2->iss, csi2->regs1, 408 iss_reg_set(csi2->iss, csi2->regs1,
410 CSI2_CTX_IRQENABLE(i), reg); 409 CSI2_CTX_IRQENABLE(i), mask);
411 else 410 else
412 iss_reg_clr(csi2->iss, csi2->regs1, 411 iss_reg_clr(csi2->iss, csi2->regs1,
413 CSI2_CTX_IRQENABLE(i), reg); 412 CSI2_CTX_IRQENABLE(i), mask);
414 } 413 }
415} 414}
416 415
@@ -679,8 +678,34 @@ static void csi2_isr_ctx(struct iss_csi2_device *csi2,
679 if (status & CSI2_CTX_IRQ_FS) { 678 if (status & CSI2_CTX_IRQ_FS) {
680 struct iss_pipeline *pipe = 679 struct iss_pipeline *pipe =
681 to_iss_pipeline(&csi2->subdev.entity); 680 to_iss_pipeline(&csi2->subdev.entity);
682 if (pipe->do_propagation) 681 u16 frame;
682 u16 delta;
683
684 frame = iss_reg_read(csi2->iss, csi2->regs1,
685 CSI2_CTX_CTRL2(ctx->ctxnum))
686 >> CSI2_CTX_CTRL2_FRAME_SHIFT;
687
688 if (frame == 0) {
689 /* A zero value means that the counter isn't implemented
690 * by the source. Increment the frame number in software
691 * in that case.
692 */
683 atomic_inc(&pipe->frame_number); 693 atomic_inc(&pipe->frame_number);
694 } else {
695 /* Extend the 16 bit frame number to 32 bits by
696 * computing the delta between two consecutive CSI2
697 * frame numbers and adding it to the software frame
698 * number. The hardware counter starts at 1 and wraps
699 * from 0xffff to 1 without going through 0, so subtract
700 * 1 when the counter wraps.
701 */
702 delta = frame - ctx->frame;
703 if (frame < ctx->frame)
704 delta--;
705 ctx->frame = frame;
706
707 atomic_add(delta, &pipe->frame_number);
708 }
684 } 709 }
685 710
686 if (!(status & CSI2_CTX_IRQ_FE)) 711 if (!(status & CSI2_CTX_IRQ_FE))
@@ -1039,7 +1064,6 @@ static int csi2_set_stream(struct v4l2_subdev *sd, int enable)
1039{ 1064{
1040 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd); 1065 struct iss_csi2_device *csi2 = v4l2_get_subdevdata(sd);
1041 struct iss_device *iss = csi2->iss; 1066 struct iss_device *iss = csi2->iss;
1042 struct iss_pipeline *pipe = to_iss_pipeline(&csi2->subdev.entity);
1043 struct iss_video *video_out = &csi2->video_out; 1067 struct iss_video *video_out = &csi2->video_out;
1044 int ret = 0; 1068 int ret = 0;
1045 1069
@@ -1058,7 +1082,6 @@ static int csi2_set_stream(struct v4l2_subdev *sd, int enable)
1058 1082
1059 if (omap4iss_csiphy_acquire(csi2->phy) < 0) 1083 if (omap4iss_csiphy_acquire(csi2->phy) < 0)
1060 return -ENODEV; 1084 return -ENODEV;
1061 csi2->use_fs_irq = pipe->do_propagation;
1062 csi2_configure(csi2); 1085 csi2_configure(csi2);
1063 csi2_print_status(csi2); 1086 csi2_print_status(csi2);
1064 1087
diff --git a/drivers/staging/media/omap4iss/iss_csi2.h b/drivers/staging/media/omap4iss/iss_csi2.h
index 971aa7b08013..3b37978a3bdf 100644
--- a/drivers/staging/media/omap4iss/iss_csi2.h
+++ b/drivers/staging/media/omap4iss/iss_csi2.h
@@ -82,6 +82,7 @@ struct iss_csi2_ctx_cfg {
82 u8 virtual_id; 82 u8 virtual_id;
83 u16 format_id; /* as in CSI2_CTx_CTRL2[9:0] */ 83 u16 format_id; /* as in CSI2_CTx_CTRL2[9:0] */
84 u8 dpcm_predictor; /* 1: simple, 0: advanced */ 84 u8 dpcm_predictor; /* 1: simple, 0: advanced */
85 u16 frame;
85 86
86 /* Fields in CSI2_CTx_CTRL1/3 - Shadowed */ 87 /* Fields in CSI2_CTx_CTRL1/3 - Shadowed */
87 u16 alpha; 88 u16 alpha;
@@ -137,7 +138,6 @@ struct iss_csi2_device {
137 u32 output; /* output to IPIPEIF, memory or both? */ 138 u32 output; /* output to IPIPEIF, memory or both? */
138 bool dpcm_decompress; 139 bool dpcm_decompress;
139 unsigned int frame_skip; 140 unsigned int frame_skip;
140 bool use_fs_irq;
141 141
142 struct iss_csiphy *phy; 142 struct iss_csiphy *phy;
143 struct iss_csi2_ctx_cfg contexts[ISS_CSI2_MAX_CTX_NUM + 1]; 143 struct iss_csi2_ctx_cfg contexts[ISS_CSI2_MAX_CTX_NUM + 1];
diff --git a/drivers/staging/media/omap4iss/iss_ipipeif.c b/drivers/staging/media/omap4iss/iss_ipipeif.c
index 32a748398ced..3943fae699ee 100644
--- a/drivers/staging/media/omap4iss/iss_ipipeif.c
+++ b/drivers/staging/media/omap4iss/iss_ipipeif.c
@@ -242,23 +242,6 @@ static void ipipeif_isr_buffer(struct iss_ipipeif_device *ipipeif)
242} 242}
243 243
244/* 244/*
245 * ipipeif_isif0_isr - Handle ISIF0 event
246 * @ipipeif: Pointer to ISP IPIPEIF device.
247 *
248 * Executes LSC deferred enablement before next frame starts.
249 */
250static void ipipeif_isif0_isr(struct iss_ipipeif_device *ipipeif)
251{
252 struct iss_pipeline *pipe =
253 to_iss_pipeline(&ipipeif->subdev.entity);
254 if (pipe->do_propagation)
255 atomic_inc(&pipe->frame_number);
256
257 if (ipipeif->output & IPIPEIF_OUTPUT_MEMORY)
258 ipipeif_isr_buffer(ipipeif);
259}
260
261/*
262 * omap4iss_ipipeif_isr - Configure ipipeif during interframe time. 245 * omap4iss_ipipeif_isr - Configure ipipeif during interframe time.
263 * @ipipeif: Pointer to ISP IPIPEIF device. 246 * @ipipeif: Pointer to ISP IPIPEIF device.
264 * @events: IPIPEIF events 247 * @events: IPIPEIF events
@@ -269,8 +252,9 @@ void omap4iss_ipipeif_isr(struct iss_ipipeif_device *ipipeif, u32 events)
269 &ipipeif->stopping)) 252 &ipipeif->stopping))
270 return; 253 return;
271 254
272 if (events & ISP5_IRQ_ISIF_INT(0)) 255 if ((events & ISP5_IRQ_ISIF_INT(0)) &&
273 ipipeif_isif0_isr(ipipeif); 256 (ipipeif->output & IPIPEIF_OUTPUT_MEMORY))
257 ipipeif_isr_buffer(ipipeif);
274} 258}
275 259
276/* ----------------------------------------------------------------------------- 260/* -----------------------------------------------------------------------------
diff --git a/drivers/staging/media/omap4iss/iss_regs.h b/drivers/staging/media/omap4iss/iss_regs.h
index efd0291a86f7..d2b6b6ae9174 100644
--- a/drivers/staging/media/omap4iss/iss_regs.h
+++ b/drivers/staging/media/omap4iss/iss_regs.h
@@ -215,6 +215,8 @@
215#define CSI2_CTX_CTRL1_CTX_EN (1 << 0) 215#define CSI2_CTX_CTRL1_CTX_EN (1 << 0)
216 216
217#define CSI2_CTX_CTRL2(i) (0x74 + (0x20 * i)) 217#define CSI2_CTX_CTRL2(i) (0x74 + (0x20 * i))
218#define CSI2_CTX_CTRL2_FRAME_MASK (0xffff << 16)
219#define CSI2_CTX_CTRL2_FRAME_SHIFT 16
218#define CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT 13 220#define CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT 13
219#define CSI2_CTX_CTRL2_USER_DEF_MAP_MASK \ 221#define CSI2_CTX_CTRL2_USER_DEF_MAP_MASK \
220 (0x3 << CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT) 222 (0x3 << CSI2_CTX_CTRL2_USER_DEF_MAP_SHIFT)
diff --git a/drivers/staging/media/omap4iss/iss_resizer.c b/drivers/staging/media/omap4iss/iss_resizer.c
index 88522a8cdf56..3ab972818f1b 100644
--- a/drivers/staging/media/omap4iss/iss_resizer.c
+++ b/drivers/staging/media/omap4iss/iss_resizer.c
@@ -283,22 +283,6 @@ static void resizer_isr_buffer(struct iss_resizer_device *resizer)
283} 283}
284 284
285/* 285/*
286 * resizer_isif0_isr - Handle ISIF0 event
287 * @resizer: Pointer to ISP RESIZER device.
288 *
289 * Executes LSC deferred enablement before next frame starts.
290 */
291static void resizer_int_dma_isr(struct iss_resizer_device *resizer)
292{
293 struct iss_pipeline *pipe =
294 to_iss_pipeline(&resizer->subdev.entity);
295 if (pipe->do_propagation)
296 atomic_inc(&pipe->frame_number);
297
298 resizer_isr_buffer(resizer);
299}
300
301/*
302 * omap4iss_resizer_isr - Configure resizer during interframe time. 286 * omap4iss_resizer_isr - Configure resizer during interframe time.
303 * @resizer: Pointer to ISP RESIZER device. 287 * @resizer: Pointer to ISP RESIZER device.
304 * @events: RESIZER events 288 * @events: RESIZER events
@@ -322,7 +306,7 @@ void omap4iss_resizer_isr(struct iss_resizer_device *resizer, u32 events)
322 return; 306 return;
323 307
324 if (events & ISP5_IRQ_RSZ_INT_DMA) 308 if (events & ISP5_IRQ_RSZ_INT_DMA)
325 resizer_int_dma_isr(resizer); 309 resizer_isr_buffer(resizer);
326} 310}
327 311
328/* ----------------------------------------------------------------------------- 312/* -----------------------------------------------------------------------------
diff --git a/drivers/staging/media/omap4iss/iss_video.c b/drivers/staging/media/omap4iss/iss_video.c
index cdee5966cbca..69550445a341 100644
--- a/drivers/staging/media/omap4iss/iss_video.c
+++ b/drivers/staging/media/omap4iss/iss_video.c
@@ -25,9 +25,6 @@
25#include "iss_video.h" 25#include "iss_video.h"
26#include "iss.h" 26#include "iss.h"
27 27
28static unsigned debug;
29module_param(debug, uint, 0644);
30MODULE_PARM_DESC(debug, "activates debug info");
31 28
32/* ----------------------------------------------------------------------------- 29/* -----------------------------------------------------------------------------
33 * Helper functions 30 * Helper functions
@@ -773,6 +770,14 @@ iss_video_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
773} 770}
774 771
775static int 772static int
773iss_video_expbuf(struct file *file, void *fh, struct v4l2_exportbuffer *e)
774{
775 struct iss_video_fh *vfh = to_iss_video_fh(fh);
776
777 return vb2_expbuf(&vfh->queue, e);
778}
779
780static int
776iss_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b) 781iss_video_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
777{ 782{
778 struct iss_video_fh *vfh = to_iss_video_fh(fh); 783 struct iss_video_fh *vfh = to_iss_video_fh(fh);
@@ -1021,6 +1026,7 @@ static const struct v4l2_ioctl_ops iss_video_ioctl_ops = {
1021 .vidioc_reqbufs = iss_video_reqbufs, 1026 .vidioc_reqbufs = iss_video_reqbufs,
1022 .vidioc_querybuf = iss_video_querybuf, 1027 .vidioc_querybuf = iss_video_querybuf,
1023 .vidioc_qbuf = iss_video_qbuf, 1028 .vidioc_qbuf = iss_video_qbuf,
1029 .vidioc_expbuf = iss_video_expbuf,
1024 .vidioc_dqbuf = iss_video_dqbuf, 1030 .vidioc_dqbuf = iss_video_dqbuf,
1025 .vidioc_streamon = iss_video_streamon, 1031 .vidioc_streamon = iss_video_streamon,
1026 .vidioc_streamoff = iss_video_streamoff, 1032 .vidioc_streamoff = iss_video_streamoff,
@@ -1044,8 +1050,6 @@ static int iss_video_open(struct file *file)
1044 if (handle == NULL) 1050 if (handle == NULL)
1045 return -ENOMEM; 1051 return -ENOMEM;
1046 1052
1047 video->video.debug = debug;
1048
1049 v4l2_fh_init(&handle->vfh, &video->video); 1053 v4l2_fh_init(&handle->vfh, &video->video);
1050 v4l2_fh_add(&handle->vfh); 1054 v4l2_fh_add(&handle->vfh);
1051 1055
@@ -1071,7 +1075,7 @@ static int iss_video_open(struct file *file)
1071 q = &handle->queue; 1075 q = &handle->queue;
1072 1076
1073 q->type = video->type; 1077 q->type = video->type;
1074 q->io_modes = VB2_MMAP; 1078 q->io_modes = VB2_MMAP | VB2_DMABUF;
1075 q->drv_priv = handle; 1079 q->drv_priv = handle;
1076 q->ops = &iss_video_vb2ops; 1080 q->ops = &iss_video_vb2ops;
1077 q->mem_ops = &vb2_dma_contig_memops; 1081 q->mem_ops = &vb2_dma_contig_memops;
diff --git a/drivers/staging/media/parport/Kconfig b/drivers/staging/media/parport/Kconfig
deleted file mode 100644
index 15974efdba1d..000000000000
--- a/drivers/staging/media/parport/Kconfig
+++ /dev/null
@@ -1,69 +0,0 @@
1menuconfig MEDIA_PARPORT_SUPPORT
2 bool "ISA and parallel port devices"
3 depends on (ISA || PARPORT) && MEDIA_CAMERA_SUPPORT
4 help
5 Enables drivers for ISA and parallel port bus. If you
6 need media drivers using those legacy buses, say Y.
7
8if MEDIA_PARPORT_SUPPORT
9config VIDEO_BWQCAM
10 tristate "Quickcam BW Video For Linux (Deprecated)"
11 depends on PARPORT && VIDEO_V4L2
12 select VIDEOBUF2_VMALLOC
13 help
14 Say Y have if you the black and white version of the QuickCam
15 camera. See the next option for the color version.
16
17 This driver is deprecated and will be removed soon. If you have
18 hardware for this and you want to work on this driver, then contact
19 the linux-media mailinglist.
20
21 To compile this driver as a module, choose M here: the
22 module will be called bw-qcam.
23
24config VIDEO_CQCAM
25 tristate "QuickCam Colour Video For Linux (Deprecated)"
26 depends on PARPORT && VIDEO_V4L2
27 help
28 This is the video4linux driver for the colour version of the
29 Connectix QuickCam. If you have one of these cameras, say Y here,
30 otherwise say N. This driver does not work with the original
31 monochrome QuickCam, QuickCam VC or QuickClip. It is also available
32 as a module (c-qcam).
33 Read <file:Documentation/video4linux/CQcam.txt> for more information.
34
35 This driver is deprecated and will be removed soon. If you have
36 hardware for this and you want to work on this driver, then contact
37 the linux-media mailinglist.
38
39config VIDEO_PMS
40 tristate "Mediavision Pro Movie Studio Video For Linux (Deprecated)"
41 depends on ISA && VIDEO_V4L2
42 help
43 Say Y if you have the ISA Mediavision Pro Movie Studio
44 capture card.
45
46 This driver is deprecated and will be removed soon. If you have
47 hardware for this and you want to work on this driver, then contact
48 the linux-media mailinglist.
49
50 To compile this driver as a module, choose M here: the
51 module will be called pms.
52
53config VIDEO_W9966
54 tristate "W9966CF Webcam (FlyCam Supra and others) Video For Linux (Deprecated)"
55 depends on PARPORT_1284 && PARPORT && VIDEO_V4L2
56 help
57 Video4linux driver for Winbond's w9966 based Webcams.
58 Currently tested with the LifeView FlyCam Supra.
59 If you have one of these cameras, say Y here
60 otherwise say N.
61 This driver is also available as a module (w9966).
62
63 Check out <file:Documentation/video4linux/w9966.txt> for more
64 information.
65
66 This driver is deprecated and will be removed soon. If you have
67 hardware for this and you want to work on this driver, then contact
68 the linux-media mailinglist.
69endif
diff --git a/drivers/staging/media/parport/Makefile b/drivers/staging/media/parport/Makefile
deleted file mode 100644
index 4eea06d7af5b..000000000000
--- a/drivers/staging/media/parport/Makefile
+++ /dev/null
@@ -1,4 +0,0 @@
1obj-$(CONFIG_VIDEO_CQCAM) += c-qcam.o
2obj-$(CONFIG_VIDEO_BWQCAM) += bw-qcam.o
3obj-$(CONFIG_VIDEO_W9966) += w9966.o
4obj-$(CONFIG_VIDEO_PMS) += pms.o
diff --git a/drivers/staging/media/parport/bw-qcam.c b/drivers/staging/media/parport/bw-qcam.c
deleted file mode 100644
index 67b9da1dc43f..000000000000
--- a/drivers/staging/media/parport/bw-qcam.c
+++ /dev/null
@@ -1,1177 +0,0 @@
1/*
2 * QuickCam Driver For Video4Linux.
3 *
4 * Video4Linux conversion work by Alan Cox.
5 * Parport compatibility by Phil Blundell.
6 * Busy loop avoidance by Mark Cooke.
7 *
8 * Module parameters:
9 *
10 * maxpoll=<1 - 5000>
11 *
12 * When polling the QuickCam for a response, busy-wait for a
13 * maximum of this many loops. The default of 250 gives little
14 * impact on interactive response.
15 *
16 * NOTE: If this parameter is set too high, the processor
17 * will busy wait until this loop times out, and then
18 * slowly poll for a further 5 seconds before failing
19 * the transaction. You have been warned.
20 *
21 * yieldlines=<1 - 250>
22 *
23 * When acquiring a frame from the camera, the data gathering
24 * loop will yield back to the scheduler after completing
25 * this many lines. The default of 4 provides a trade-off
26 * between increased frame acquisition time and impact on
27 * interactive response.
28 */
29
30/* qcam-lib.c -- Library for programming with the Connectix QuickCam.
31 * See the included documentation for usage instructions and details
32 * of the protocol involved. */
33
34
35/* Version 0.5, August 4, 1996 */
36/* Version 0.7, August 27, 1996 */
37/* Version 0.9, November 17, 1996 */
38
39
40/******************************************************************
41
42Copyright (C) 1996 by Scott Laird
43
44Permission is hereby granted, free of charge, to any person obtaining
45a copy of this software and associated documentation files (the
46"Software"), to deal in the Software without restriction, including
47without limitation the rights to use, copy, modify, merge, publish,
48distribute, sublicense, and/or sell copies of the Software, and to
49permit persons to whom the Software is furnished to do so, subject to
50the following conditions:
51
52The above copyright notice and this permission notice shall be
53included in all copies or substantial portions of the Software.
54
55THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
56EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
57MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
58IN NO EVENT SHALL SCOTT LAIRD BE LIABLE FOR ANY CLAIM, DAMAGES OR
59OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
60ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
61OTHER DEALINGS IN THE SOFTWARE.
62
63******************************************************************/
64
65#include <linux/module.h>
66#include <linux/delay.h>
67#include <linux/errno.h>
68#include <linux/fs.h>
69#include <linux/kernel.h>
70#include <linux/slab.h>
71#include <linux/mm.h>
72#include <linux/parport.h>
73#include <linux/sched.h>
74#include <linux/videodev2.h>
75#include <linux/mutex.h>
76#include <asm/uaccess.h>
77#include <media/v4l2-common.h>
78#include <media/v4l2-ioctl.h>
79#include <media/v4l2-device.h>
80#include <media/v4l2-fh.h>
81#include <media/v4l2-ctrls.h>
82#include <media/v4l2-event.h>
83#include <media/videobuf2-vmalloc.h>
84
85/* One from column A... */
86#define QC_NOTSET 0
87#define QC_UNIDIR 1
88#define QC_BIDIR 2
89#define QC_SERIAL 3
90
91/* ... and one from column B */
92#define QC_ANY 0x00
93#define QC_FORCE_UNIDIR 0x10
94#define QC_FORCE_BIDIR 0x20
95#define QC_FORCE_SERIAL 0x30
96/* in the port_mode member */
97
98#define QC_MODE_MASK 0x07
99#define QC_FORCE_MASK 0x70
100
101#define MAX_HEIGHT 243
102#define MAX_WIDTH 336
103
104/* Bit fields for status flags */
105#define QC_PARAM_CHANGE 0x01 /* Camera status change has occurred */
106
107struct qcam {
108 struct v4l2_device v4l2_dev;
109 struct video_device vdev;
110 struct v4l2_ctrl_handler hdl;
111 struct vb2_queue vb_vidq;
112 struct pardevice *pdev;
113 struct parport *pport;
114 struct mutex lock;
115 struct mutex queue_lock;
116 int width, height;
117 int bpp;
118 int mode;
119 int contrast, brightness, whitebal;
120 int port_mode;
121 int transfer_scale;
122 int top, left;
123 int status;
124 unsigned int saved_bits;
125 unsigned long in_use;
126};
127
128static unsigned int maxpoll = 250; /* Maximum busy-loop count for qcam I/O */
129static unsigned int yieldlines = 4; /* Yield after this many during capture */
130static int video_nr = -1;
131static unsigned int force_init; /* Whether to probe aggressively */
132
133module_param(maxpoll, int, 0);
134module_param(yieldlines, int, 0);
135module_param(video_nr, int, 0);
136
137/* Set force_init=1 to avoid detection by polling status register and
138 * immediately attempt to initialize qcam */
139module_param(force_init, int, 0);
140
141#define MAX_CAMS 4
142static struct qcam *qcams[MAX_CAMS];
143static unsigned int num_cams;
144
145static inline int read_lpstatus(struct qcam *q)
146{
147 return parport_read_status(q->pport);
148}
149
150static inline int read_lpdata(struct qcam *q)
151{
152 return parport_read_data(q->pport);
153}
154
155static inline void write_lpdata(struct qcam *q, int d)
156{
157 parport_write_data(q->pport, d);
158}
159
160static void write_lpcontrol(struct qcam *q, int d)
161{
162 if (d & 0x20) {
163 /* Set bidirectional mode to reverse (data in) */
164 parport_data_reverse(q->pport);
165 } else {
166 /* Set bidirectional mode to forward (data out) */
167 parport_data_forward(q->pport);
168 }
169
170 /* Now issue the regular port command, but strip out the
171 * direction flag */
172 d &= ~0x20;
173 parport_write_control(q->pport, d);
174}
175
176
177/* qc_waithand busy-waits for a handshake signal from the QuickCam.
178 * Almost all communication with the camera requires handshaking. */
179
180static int qc_waithand(struct qcam *q, int val)
181{
182 int status;
183 int runs = 0;
184
185 if (val) {
186 while (!((status = read_lpstatus(q)) & 8)) {
187 /* 1000 is enough spins on the I/O for all normal
188 cases, at that point we start to poll slowly
189 until the camera wakes up. However, we are
190 busy blocked until the camera responds, so
191 setting it lower is much better for interactive
192 response. */
193
194 if (runs++ > maxpoll)
195 msleep_interruptible(5);
196 if (runs > (maxpoll + 1000)) /* 5 seconds */
197 return -1;
198 }
199 } else {
200 while (((status = read_lpstatus(q)) & 8)) {
201 /* 1000 is enough spins on the I/O for all normal
202 cases, at that point we start to poll slowly
203 until the camera wakes up. However, we are
204 busy blocked until the camera responds, so
205 setting it lower is much better for interactive
206 response. */
207
208 if (runs++ > maxpoll)
209 msleep_interruptible(5);
210 if (runs++ > (maxpoll + 1000)) /* 5 seconds */
211 return -1;
212 }
213 }
214
215 return status;
216}
217
218/* Waithand2 is used when the qcam is in bidirectional mode, and the
219 * handshaking signal is CamRdy2 (bit 0 of data reg) instead of CamRdy1
220 * (bit 3 of status register). It also returns the last value read,
221 * since this data is useful. */
222
223static unsigned int qc_waithand2(struct qcam *q, int val)
224{
225 unsigned int status;
226 int runs = 0;
227
228 do {
229 status = read_lpdata(q);
230 /* 1000 is enough spins on the I/O for all normal
231 cases, at that point we start to poll slowly
232 until the camera wakes up. However, we are
233 busy blocked until the camera responds, so
234 setting it lower is much better for interactive
235 response. */
236
237 if (runs++ > maxpoll)
238 msleep_interruptible(5);
239 if (runs++ > (maxpoll + 1000)) /* 5 seconds */
240 return 0;
241 } while ((status & 1) != val);
242
243 return status;
244}
245
246/* qc_command is probably a bit of a misnomer -- it's used to send
247 * bytes *to* the camera. Generally, these bytes are either commands
248 * or arguments to commands, so the name fits, but it still bugs me a
249 * bit. See the documentation for a list of commands. */
250
251static int qc_command(struct qcam *q, int command)
252{
253 int n1, n2;
254 int cmd;
255
256 write_lpdata(q, command);
257 write_lpcontrol(q, 6);
258
259 n1 = qc_waithand(q, 1);
260
261 write_lpcontrol(q, 0xe);
262 n2 = qc_waithand(q, 0);
263
264 cmd = (n1 & 0xf0) | ((n2 & 0xf0) >> 4);
265 return cmd;
266}
267
268static int qc_readparam(struct qcam *q)
269{
270 int n1, n2;
271 int cmd;
272
273 write_lpcontrol(q, 6);
274 n1 = qc_waithand(q, 1);
275
276 write_lpcontrol(q, 0xe);
277 n2 = qc_waithand(q, 0);
278
279 cmd = (n1 & 0xf0) | ((n2 & 0xf0) >> 4);
280 return cmd;
281}
282
283
284/* Try to detect a QuickCam. It appears to flash the upper 4 bits of
285 the status register at 5-10 Hz. This is only used in the autoprobe
286 code. Be aware that this isn't the way Connectix detects the
287 camera (they send a reset and try to handshake), but this should be
288 almost completely safe, while their method screws up my printer if
289 I plug it in before the camera. */
290
291static int qc_detect(struct qcam *q)
292{
293 int reg, lastreg;
294 int count = 0;
295 int i;
296
297 if (force_init)
298 return 1;
299
300 lastreg = reg = read_lpstatus(q) & 0xf0;
301
302 for (i = 0; i < 500; i++) {
303 reg = read_lpstatus(q) & 0xf0;
304 if (reg != lastreg)
305 count++;
306 lastreg = reg;
307 mdelay(2);
308 }
309
310
311#if 0
312 /* Force camera detection during testing. Sometimes the camera
313 won't be flashing these bits. Possibly unloading the module
314 in the middle of a grab? Or some timeout condition?
315 I've seen this parameter as low as 19 on my 450Mhz box - mpc */
316 printk(KERN_DEBUG "Debugging: QCam detection counter <30-200 counts as detected>: %d\n", count);
317 return 1;
318#endif
319
320 /* Be (even more) liberal in what you accept... */
321
322 if (count > 20 && count < 400) {
323 return 1; /* found */
324 } else {
325 printk(KERN_ERR "No Quickcam found on port %s\n",
326 q->pport->name);
327 printk(KERN_DEBUG "Quickcam detection counter: %u\n", count);
328 return 0; /* not found */
329 }
330}
331
332/* Decide which scan mode to use. There's no real requirement that
333 * the scanmode match the resolution in q->height and q-> width -- the
334 * camera takes the picture at the resolution specified in the
335 * "scanmode" and then returns the image at the resolution specified
336 * with the resolution commands. If the scan is bigger than the
337 * requested resolution, the upper-left hand corner of the scan is
338 * returned. If the scan is smaller, then the rest of the image
339 * returned contains garbage. */
340
341static int qc_setscanmode(struct qcam *q)
342{
343 int old_mode = q->mode;
344
345 switch (q->transfer_scale) {
346 case 1:
347 q->mode = 0;
348 break;
349 case 2:
350 q->mode = 4;
351 break;
352 case 4:
353 q->mode = 8;
354 break;
355 }
356
357 switch (q->bpp) {
358 case 4:
359 break;
360 case 6:
361 q->mode += 2;
362 break;
363 }
364
365 switch (q->port_mode & QC_MODE_MASK) {
366 case QC_BIDIR:
367 q->mode += 1;
368 break;
369 case QC_NOTSET:
370 case QC_UNIDIR:
371 break;
372 }
373
374 if (q->mode != old_mode)
375 q->status |= QC_PARAM_CHANGE;
376
377 return 0;
378}
379
380
381/* Reset the QuickCam. This uses the same sequence the Windows
382 * QuickPic program uses. Someone with a bi-directional port should
383 * check that bi-directional mode is detected right, and then
384 * implement bi-directional mode in qc_readbyte(). */
385
386static void qc_reset(struct qcam *q)
387{
388 switch (q->port_mode & QC_FORCE_MASK) {
389 case QC_FORCE_UNIDIR:
390 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
391 break;
392
393 case QC_FORCE_BIDIR:
394 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
395 break;
396
397 case QC_ANY:
398 write_lpcontrol(q, 0x20);
399 write_lpdata(q, 0x75);
400
401 if (read_lpdata(q) != 0x75)
402 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_BIDIR;
403 else
404 q->port_mode = (q->port_mode & ~QC_MODE_MASK) | QC_UNIDIR;
405 break;
406 }
407
408 write_lpcontrol(q, 0xb);
409 udelay(250);
410 write_lpcontrol(q, 0xe);
411 qc_setscanmode(q); /* in case port_mode changed */
412}
413
414
415
416/* Reset the QuickCam and program for brightness, contrast,
417 * white-balance, and resolution. */
418
419static void qc_set(struct qcam *q)
420{
421 int val;
422 int val2;
423
424 /* Set the brightness. Yes, this is repetitive, but it works.
425 * Shorter versions seem to fail subtly. Feel free to try :-). */
426 /* I think the problem was in qc_command, not here -- bls */
427
428 qc_command(q, 0xb);
429 qc_command(q, q->brightness);
430
431 val = q->height / q->transfer_scale;
432 qc_command(q, 0x11);
433 qc_command(q, val);
434 if ((q->port_mode & QC_MODE_MASK) == QC_UNIDIR && q->bpp == 6) {
435 /* The normal "transfers per line" calculation doesn't seem to work
436 as expected here (and yet it works fine in qc_scan). No idea
437 why this case is the odd man out. Fortunately, Laird's original
438 working version gives me a good way to guess at working values.
439 -- bls */
440 val = q->width;
441 val2 = q->transfer_scale * 4;
442 } else {
443 val = q->width * q->bpp;
444 val2 = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
445 q->transfer_scale;
446 }
447 val = DIV_ROUND_UP(val, val2);
448 qc_command(q, 0x13);
449 qc_command(q, val);
450
451 /* Setting top and left -- bls */
452 qc_command(q, 0xd);
453 qc_command(q, q->top);
454 qc_command(q, 0xf);
455 qc_command(q, q->left / 2);
456
457 qc_command(q, 0x19);
458 qc_command(q, q->contrast);
459 qc_command(q, 0x1f);
460 qc_command(q, q->whitebal);
461
462 /* Clear flag that we must update the grabbing parameters on the camera
463 before we grab the next frame */
464 q->status &= (~QC_PARAM_CHANGE);
465}
466
467/* Qc_readbytes reads some bytes from the QC and puts them in
468 the supplied buffer. It returns the number of bytes read,
469 or -1 on error. */
470
471static inline int qc_readbytes(struct qcam *q, char buffer[])
472{
473 int ret = 1;
474 unsigned int hi, lo;
475 unsigned int hi2, lo2;
476 static int state;
477
478 if (buffer == NULL) {
479 state = 0;
480 return 0;
481 }
482
483 switch (q->port_mode & QC_MODE_MASK) {
484 case QC_BIDIR: /* Bi-directional Port */
485 write_lpcontrol(q, 0x26);
486 lo = (qc_waithand2(q, 1) >> 1);
487 hi = (read_lpstatus(q) >> 3) & 0x1f;
488 write_lpcontrol(q, 0x2e);
489 lo2 = (qc_waithand2(q, 0) >> 1);
490 hi2 = (read_lpstatus(q) >> 3) & 0x1f;
491 switch (q->bpp) {
492 case 4:
493 buffer[0] = lo & 0xf;
494 buffer[1] = ((lo & 0x70) >> 4) | ((hi & 1) << 3);
495 buffer[2] = (hi & 0x1e) >> 1;
496 buffer[3] = lo2 & 0xf;
497 buffer[4] = ((lo2 & 0x70) >> 4) | ((hi2 & 1) << 3);
498 buffer[5] = (hi2 & 0x1e) >> 1;
499 ret = 6;
500 break;
501 case 6:
502 buffer[0] = lo & 0x3f;
503 buffer[1] = ((lo & 0x40) >> 6) | (hi << 1);
504 buffer[2] = lo2 & 0x3f;
505 buffer[3] = ((lo2 & 0x40) >> 6) | (hi2 << 1);
506 ret = 4;
507 break;
508 }
509 break;
510
511 case QC_UNIDIR: /* Unidirectional Port */
512 write_lpcontrol(q, 6);
513 lo = (qc_waithand(q, 1) & 0xf0) >> 4;
514 write_lpcontrol(q, 0xe);
515 hi = (qc_waithand(q, 0) & 0xf0) >> 4;
516
517 switch (q->bpp) {
518 case 4:
519 buffer[0] = lo;
520 buffer[1] = hi;
521 ret = 2;
522 break;
523 case 6:
524 switch (state) {
525 case 0:
526 buffer[0] = (lo << 2) | ((hi & 0xc) >> 2);
527 q->saved_bits = (hi & 3) << 4;
528 state = 1;
529 ret = 1;
530 break;
531 case 1:
532 buffer[0] = lo | q->saved_bits;
533 q->saved_bits = hi << 2;
534 state = 2;
535 ret = 1;
536 break;
537 case 2:
538 buffer[0] = ((lo & 0xc) >> 2) | q->saved_bits;
539 buffer[1] = ((lo & 3) << 4) | hi;
540 state = 0;
541 ret = 2;
542 break;
543 }
544 break;
545 }
546 break;
547 }
548 return ret;
549}
550
551/* requests a scan from the camera. It sends the correct instructions
552 * to the camera and then reads back the correct number of bytes. In
553 * previous versions of this routine the return structure contained
554 * the raw output from the camera, and there was a 'qc_convertscan'
555 * function that converted that to a useful format. In version 0.3 I
556 * rolled qc_convertscan into qc_scan and now I only return the
557 * converted scan. The format is just an one-dimensional array of
558 * characters, one for each pixel, with 0=black up to n=white, where
559 * n=2^(bit depth)-1. Ask me for more details if you don't understand
560 * this. */
561
562static long qc_capture(struct qcam *q, u8 *buf, unsigned long len)
563{
564 int i, j, k, yield;
565 int bytes;
566 int linestotrans, transperline;
567 int divisor;
568 int pixels_per_line;
569 int pixels_read = 0;
570 int got = 0;
571 char buffer[6];
572 int shift = 8 - q->bpp;
573 char invert;
574
575 if (q->mode == -1)
576 return -ENXIO;
577
578 qc_command(q, 0x7);
579 qc_command(q, q->mode);
580
581 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
582 write_lpcontrol(q, 0x2e); /* turn port around */
583 write_lpcontrol(q, 0x26);
584 qc_waithand(q, 1);
585 write_lpcontrol(q, 0x2e);
586 qc_waithand(q, 0);
587 }
588
589 /* strange -- should be 15:63 below, but 4bpp is odd */
590 invert = (q->bpp == 4) ? 16 : 63;
591
592 linestotrans = q->height / q->transfer_scale;
593 pixels_per_line = q->width / q->transfer_scale;
594 transperline = q->width * q->bpp;
595 divisor = (((q->port_mode & QC_MODE_MASK) == QC_BIDIR) ? 24 : 8) *
596 q->transfer_scale;
597 transperline = DIV_ROUND_UP(transperline, divisor);
598
599 for (i = 0, yield = yieldlines; i < linestotrans; i++) {
600 for (pixels_read = j = 0; j < transperline; j++) {
601 bytes = qc_readbytes(q, buffer);
602 for (k = 0; k < bytes && (pixels_read + k) < pixels_per_line; k++) {
603 int o;
604 if (buffer[k] == 0 && invert == 16) {
605 /* 4bpp is odd (again) -- inverter is 16, not 15, but output
606 must be 0-15 -- bls */
607 buffer[k] = 16;
608 }
609 o = i * pixels_per_line + pixels_read + k;
610 if (o < len) {
611 u8 ch = invert - buffer[k];
612 got++;
613 buf[o] = ch << shift;
614 }
615 }
616 pixels_read += bytes;
617 }
618 qc_readbytes(q, NULL); /* reset state machine */
619
620 /* Grabbing an entire frame from the quickcam is a lengthy
621 process. We don't (usually) want to busy-block the
622 processor for the entire frame. yieldlines is a module
623 parameter. If we yield every line, the minimum frame
624 time will be 240 / 200 = 1.2 seconds. The compile-time
625 default is to yield every 4 lines. */
626 if (i >= yield) {
627 msleep_interruptible(5);
628 yield = i + yieldlines;
629 }
630 }
631
632 if ((q->port_mode & QC_MODE_MASK) == QC_BIDIR) {
633 write_lpcontrol(q, 2);
634 write_lpcontrol(q, 6);
635 udelay(3);
636 write_lpcontrol(q, 0xe);
637 }
638 if (got < len)
639 return got;
640 return len;
641}
642
643/* ------------------------------------------------------------------
644 Videobuf operations
645 ------------------------------------------------------------------*/
646static int queue_setup(struct vb2_queue *vq, const struct v4l2_format *fmt,
647 unsigned int *nbuffers, unsigned int *nplanes,
648 unsigned int sizes[], void *alloc_ctxs[])
649{
650 struct qcam *dev = vb2_get_drv_priv(vq);
651
652 if (0 == *nbuffers)
653 *nbuffers = 3;
654 *nplanes = 1;
655 mutex_lock(&dev->lock);
656 if (fmt)
657 sizes[0] = fmt->fmt.pix.width * fmt->fmt.pix.height;
658 else
659 sizes[0] = (dev->width / dev->transfer_scale) *
660 (dev->height / dev->transfer_scale);
661 mutex_unlock(&dev->lock);
662 return 0;
663}
664
665static void buffer_queue(struct vb2_buffer *vb)
666{
667 vb2_buffer_done(vb, VB2_BUF_STATE_DONE);
668}
669
670static void buffer_finish(struct vb2_buffer *vb)
671{
672 struct qcam *qcam = vb2_get_drv_priv(vb->vb2_queue);
673 void *vbuf = vb2_plane_vaddr(vb, 0);
674 int size = vb->vb2_queue->plane_sizes[0];
675 int len;
676
677 if (!vb2_is_streaming(vb->vb2_queue))
678 return;
679
680 mutex_lock(&qcam->lock);
681 parport_claim_or_block(qcam->pdev);
682
683 qc_reset(qcam);
684
685 /* Update the camera parameters if we need to */
686 if (qcam->status & QC_PARAM_CHANGE)
687 qc_set(qcam);
688
689 len = qc_capture(qcam, vbuf, size);
690
691 parport_release(qcam->pdev);
692 mutex_unlock(&qcam->lock);
693 v4l2_get_timestamp(&vb->v4l2_buf.timestamp);
694 if (len != size)
695 vb->state = VB2_BUF_STATE_ERROR;
696 vb2_set_plane_payload(vb, 0, len);
697}
698
699static struct vb2_ops qcam_video_qops = {
700 .queue_setup = queue_setup,
701 .buf_queue = buffer_queue,
702 .buf_finish = buffer_finish,
703 .wait_prepare = vb2_ops_wait_prepare,
704 .wait_finish = vb2_ops_wait_finish,
705};
706
707/*
708 * Video4linux interfacing
709 */
710
711static int qcam_querycap(struct file *file, void *priv,
712 struct v4l2_capability *vcap)
713{
714 struct qcam *qcam = video_drvdata(file);
715
716 strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver));
717 strlcpy(vcap->card, "Connectix B&W Quickcam", sizeof(vcap->card));
718 strlcpy(vcap->bus_info, qcam->pport->name, sizeof(vcap->bus_info));
719 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE |
720 V4L2_CAP_STREAMING;
721 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
722 return 0;
723}
724
725static int qcam_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
726{
727 if (vin->index > 0)
728 return -EINVAL;
729 strlcpy(vin->name, "Camera", sizeof(vin->name));
730 vin->type = V4L2_INPUT_TYPE_CAMERA;
731 vin->audioset = 0;
732 vin->tuner = 0;
733 vin->std = 0;
734 vin->status = 0;
735 return 0;
736}
737
738static int qcam_g_input(struct file *file, void *fh, unsigned int *inp)
739{
740 *inp = 0;
741 return 0;
742}
743
744static int qcam_s_input(struct file *file, void *fh, unsigned int inp)
745{
746 return (inp > 0) ? -EINVAL : 0;
747}
748
749static int qcam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
750{
751 struct qcam *qcam = video_drvdata(file);
752 struct v4l2_pix_format *pix = &fmt->fmt.pix;
753
754 pix->width = qcam->width / qcam->transfer_scale;
755 pix->height = qcam->height / qcam->transfer_scale;
756 pix->pixelformat = (qcam->bpp == 4) ? V4L2_PIX_FMT_Y4 : V4L2_PIX_FMT_Y6;
757 pix->field = V4L2_FIELD_NONE;
758 pix->bytesperline = pix->width;
759 pix->sizeimage = pix->width * pix->height;
760 /* Just a guess */
761 pix->colorspace = V4L2_COLORSPACE_SRGB;
762 return 0;
763}
764
765static int qcam_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
766{
767 struct v4l2_pix_format *pix = &fmt->fmt.pix;
768
769 if (pix->height <= 60 || pix->width <= 80) {
770 pix->height = 60;
771 pix->width = 80;
772 } else if (pix->height <= 120 || pix->width <= 160) {
773 pix->height = 120;
774 pix->width = 160;
775 } else {
776 pix->height = 240;
777 pix->width = 320;
778 }
779 if (pix->pixelformat != V4L2_PIX_FMT_Y4 &&
780 pix->pixelformat != V4L2_PIX_FMT_Y6)
781 pix->pixelformat = V4L2_PIX_FMT_Y4;
782 pix->field = V4L2_FIELD_NONE;
783 pix->bytesperline = pix->width;
784 pix->sizeimage = pix->width * pix->height;
785 /* Just a guess */
786 pix->colorspace = V4L2_COLORSPACE_SRGB;
787 return 0;
788}
789
790static int qcam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
791{
792 struct qcam *qcam = video_drvdata(file);
793 struct v4l2_pix_format *pix = &fmt->fmt.pix;
794 int ret = qcam_try_fmt_vid_cap(file, fh, fmt);
795
796 if (ret)
797 return ret;
798 if (vb2_is_busy(&qcam->vb_vidq))
799 return -EBUSY;
800 qcam->width = 320;
801 qcam->height = 240;
802 if (pix->height == 60)
803 qcam->transfer_scale = 4;
804 else if (pix->height == 120)
805 qcam->transfer_scale = 2;
806 else
807 qcam->transfer_scale = 1;
808 if (pix->pixelformat == V4L2_PIX_FMT_Y6)
809 qcam->bpp = 6;
810 else
811 qcam->bpp = 4;
812
813 qc_setscanmode(qcam);
814 /* We must update the camera before we grab. We could
815 just have changed the grab size */
816 qcam->status |= QC_PARAM_CHANGE;
817 return 0;
818}
819
820static int qcam_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
821{
822 static struct v4l2_fmtdesc formats[] = {
823 { 0, 0, 0,
824 "4-Bit Monochrome", V4L2_PIX_FMT_Y4,
825 { 0, 0, 0, 0 }
826 },
827 { 1, 0, 0,
828 "6-Bit Monochrome", V4L2_PIX_FMT_Y6,
829 { 0, 0, 0, 0 }
830 },
831 };
832 enum v4l2_buf_type type = fmt->type;
833
834 if (fmt->index > 1)
835 return -EINVAL;
836
837 *fmt = formats[fmt->index];
838 fmt->type = type;
839 return 0;
840}
841
842static int qcam_enum_framesizes(struct file *file, void *fh,
843 struct v4l2_frmsizeenum *fsize)
844{
845 static const struct v4l2_frmsize_discrete sizes[] = {
846 { 80, 60 },
847 { 160, 120 },
848 { 320, 240 },
849 };
850
851 if (fsize->index > 2)
852 return -EINVAL;
853 if (fsize->pixel_format != V4L2_PIX_FMT_Y4 &&
854 fsize->pixel_format != V4L2_PIX_FMT_Y6)
855 return -EINVAL;
856 fsize->type = V4L2_FRMSIZE_TYPE_DISCRETE;
857 fsize->discrete = sizes[fsize->index];
858 return 0;
859}
860
861static int qcam_s_ctrl(struct v4l2_ctrl *ctrl)
862{
863 struct qcam *qcam =
864 container_of(ctrl->handler, struct qcam, hdl);
865 int ret = 0;
866
867 switch (ctrl->id) {
868 case V4L2_CID_BRIGHTNESS:
869 qcam->brightness = ctrl->val;
870 break;
871 case V4L2_CID_CONTRAST:
872 qcam->contrast = ctrl->val;
873 break;
874 case V4L2_CID_GAMMA:
875 qcam->whitebal = ctrl->val;
876 break;
877 default:
878 ret = -EINVAL;
879 break;
880 }
881 if (ret == 0)
882 qcam->status |= QC_PARAM_CHANGE;
883 return ret;
884}
885
886static const struct v4l2_file_operations qcam_fops = {
887 .owner = THIS_MODULE,
888 .open = v4l2_fh_open,
889 .release = vb2_fop_release,
890 .poll = vb2_fop_poll,
891 .unlocked_ioctl = video_ioctl2,
892 .read = vb2_fop_read,
893 .mmap = vb2_fop_mmap,
894};
895
896static const struct v4l2_ioctl_ops qcam_ioctl_ops = {
897 .vidioc_querycap = qcam_querycap,
898 .vidioc_g_input = qcam_g_input,
899 .vidioc_s_input = qcam_s_input,
900 .vidioc_enum_input = qcam_enum_input,
901 .vidioc_enum_fmt_vid_cap = qcam_enum_fmt_vid_cap,
902 .vidioc_enum_framesizes = qcam_enum_framesizes,
903 .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap,
904 .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap,
905 .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap,
906 .vidioc_reqbufs = vb2_ioctl_reqbufs,
907 .vidioc_create_bufs = vb2_ioctl_create_bufs,
908 .vidioc_prepare_buf = vb2_ioctl_prepare_buf,
909 .vidioc_querybuf = vb2_ioctl_querybuf,
910 .vidioc_qbuf = vb2_ioctl_qbuf,
911 .vidioc_dqbuf = vb2_ioctl_dqbuf,
912 .vidioc_streamon = vb2_ioctl_streamon,
913 .vidioc_streamoff = vb2_ioctl_streamoff,
914 .vidioc_log_status = v4l2_ctrl_log_status,
915 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
916 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
917};
918
919static const struct v4l2_ctrl_ops qcam_ctrl_ops = {
920 .s_ctrl = qcam_s_ctrl,
921};
922
923/* Initialize the QuickCam driver control structure. This is where
924 * defaults are set for people who don't have a config file.*/
925
926static struct qcam *qcam_init(struct parport *port)
927{
928 struct qcam *qcam;
929 struct v4l2_device *v4l2_dev;
930 struct vb2_queue *q;
931 int err;
932
933 qcam = kzalloc(sizeof(struct qcam), GFP_KERNEL);
934 if (qcam == NULL)
935 return NULL;
936
937 v4l2_dev = &qcam->v4l2_dev;
938 snprintf(v4l2_dev->name, sizeof(v4l2_dev->name), "bw-qcam%u", num_cams);
939
940 if (v4l2_device_register(port->dev, v4l2_dev) < 0) {
941 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
942 kfree(qcam);
943 return NULL;
944 }
945
946 v4l2_ctrl_handler_init(&qcam->hdl, 3);
947 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
948 V4L2_CID_BRIGHTNESS, 0, 255, 1, 180);
949 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
950 V4L2_CID_CONTRAST, 0, 255, 1, 192);
951 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
952 V4L2_CID_GAMMA, 0, 255, 1, 105);
953 if (qcam->hdl.error) {
954 v4l2_err(v4l2_dev, "couldn't register controls\n");
955 goto exit;
956 }
957
958 mutex_init(&qcam->lock);
959 mutex_init(&qcam->queue_lock);
960
961 /* initialize queue */
962 q = &qcam->vb_vidq;
963 q->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
964 q->io_modes = VB2_MMAP | VB2_USERPTR | VB2_READ;
965 q->drv_priv = qcam;
966 q->ops = &qcam_video_qops;
967 q->mem_ops = &vb2_vmalloc_memops;
968 q->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
969 err = vb2_queue_init(q);
970 if (err < 0) {
971 v4l2_err(v4l2_dev, "couldn't init vb2_queue for %s.\n", port->name);
972 goto exit;
973 }
974 qcam->vdev.queue = q;
975 qcam->vdev.queue->lock = &qcam->queue_lock;
976
977 qcam->pport = port;
978 qcam->pdev = parport_register_device(port, v4l2_dev->name, NULL, NULL,
979 NULL, 0, NULL);
980 if (qcam->pdev == NULL) {
981 v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name);
982 goto exit;
983 }
984
985 strlcpy(qcam->vdev.name, "Connectix QuickCam", sizeof(qcam->vdev.name));
986 qcam->vdev.v4l2_dev = v4l2_dev;
987 qcam->vdev.ctrl_handler = &qcam->hdl;
988 qcam->vdev.fops = &qcam_fops;
989 qcam->vdev.lock = &qcam->lock;
990 qcam->vdev.ioctl_ops = &qcam_ioctl_ops;
991 qcam->vdev.release = video_device_release_empty;
992 video_set_drvdata(&qcam->vdev, qcam);
993
994 qcam->port_mode = (QC_ANY | QC_NOTSET);
995 qcam->width = 320;
996 qcam->height = 240;
997 qcam->bpp = 4;
998 qcam->transfer_scale = 2;
999 qcam->contrast = 192;
1000 qcam->brightness = 180;
1001 qcam->whitebal = 105;
1002 qcam->top = 1;
1003 qcam->left = 14;
1004 qcam->mode = -1;
1005 qcam->status = QC_PARAM_CHANGE;
1006 return qcam;
1007
1008exit:
1009 v4l2_ctrl_handler_free(&qcam->hdl);
1010 kfree(qcam);
1011 return NULL;
1012}
1013
1014static int qc_calibrate(struct qcam *q)
1015{
1016 /*
1017 * Bugfix by Hanno Mueller hmueller@kabel.de, Mai 21 96
1018 * The white balance is an individual value for each
1019 * quickcam.
1020 */
1021
1022 int value;
1023 int count = 0;
1024
1025 qc_command(q, 27); /* AutoAdjustOffset */
1026 qc_command(q, 0); /* Dummy Parameter, ignored by the camera */
1027
1028 /* GetOffset (33) will read 255 until autocalibration */
1029 /* is finished. After that, a value of 1-254 will be */
1030 /* returned. */
1031
1032 do {
1033 qc_command(q, 33);
1034 value = qc_readparam(q);
1035 mdelay(1);
1036 schedule();
1037 count++;
1038 } while (value == 0xff && count < 2048);
1039
1040 q->whitebal = value;
1041 return value;
1042}
1043
1044static int init_bwqcam(struct parport *port)
1045{
1046 struct qcam *qcam;
1047
1048 if (num_cams == MAX_CAMS) {
1049 printk(KERN_ERR "Too many Quickcams (max %d)\n", MAX_CAMS);
1050 return -ENOSPC;
1051 }
1052
1053 qcam = qcam_init(port);
1054 if (qcam == NULL)
1055 return -ENODEV;
1056
1057 parport_claim_or_block(qcam->pdev);
1058
1059 qc_reset(qcam);
1060
1061 if (qc_detect(qcam) == 0) {
1062 parport_release(qcam->pdev);
1063 parport_unregister_device(qcam->pdev);
1064 kfree(qcam);
1065 return -ENODEV;
1066 }
1067 qc_calibrate(qcam);
1068 v4l2_ctrl_handler_setup(&qcam->hdl);
1069
1070 parport_release(qcam->pdev);
1071
1072 v4l2_info(&qcam->v4l2_dev, "Connectix Quickcam on %s\n", qcam->pport->name);
1073
1074 if (video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
1075 parport_unregister_device(qcam->pdev);
1076 kfree(qcam);
1077 return -ENODEV;
1078 }
1079
1080 qcams[num_cams++] = qcam;
1081
1082 return 0;
1083}
1084
1085static void close_bwqcam(struct qcam *qcam)
1086{
1087 video_unregister_device(&qcam->vdev);
1088 v4l2_ctrl_handler_free(&qcam->hdl);
1089 parport_unregister_device(qcam->pdev);
1090 kfree(qcam);
1091}
1092
1093/* The parport parameter controls which parports will be scanned.
1094 * Scanning all parports causes some printers to print a garbage page.
1095 * -- March 14, 1999 Billy Donahue <billy@escape.com> */
1096#ifdef MODULE
1097static char *parport[MAX_CAMS] = { NULL, };
1098module_param_array(parport, charp, NULL, 0);
1099#endif
1100
1101static int accept_bwqcam(struct parport *port)
1102{
1103#ifdef MODULE
1104 int n;
1105
1106 if (parport[0] && strncmp(parport[0], "auto", 4) != 0) {
1107 /* user gave parport parameters */
1108 for (n = 0; n < MAX_CAMS && parport[n]; n++) {
1109 char *ep;
1110 unsigned long r;
1111 r = simple_strtoul(parport[n], &ep, 0);
1112 if (ep == parport[n]) {
1113 printk(KERN_ERR
1114 "bw-qcam: bad port specifier \"%s\"\n",
1115 parport[n]);
1116 continue;
1117 }
1118 if (r == port->number)
1119 return 1;
1120 }
1121 return 0;
1122 }
1123#endif
1124 return 1;
1125}
1126
1127static void bwqcam_attach(struct parport *port)
1128{
1129 if (accept_bwqcam(port))
1130 init_bwqcam(port);
1131}
1132
1133static void bwqcam_detach(struct parport *port)
1134{
1135 int i;
1136 for (i = 0; i < num_cams; i++) {
1137 struct qcam *qcam = qcams[i];
1138 if (qcam && qcam->pdev->port == port) {
1139 qcams[i] = NULL;
1140 close_bwqcam(qcam);
1141 }
1142 }
1143}
1144
1145static struct parport_driver bwqcam_driver = {
1146 .name = "bw-qcam",
1147 .attach = bwqcam_attach,
1148 .detach = bwqcam_detach,
1149};
1150
1151static void __exit exit_bw_qcams(void)
1152{
1153 parport_unregister_driver(&bwqcam_driver);
1154}
1155
1156static int __init init_bw_qcams(void)
1157{
1158#ifdef MODULE
1159 /* Do some sanity checks on the module parameters. */
1160 if (maxpoll > 5000) {
1161 printk(KERN_INFO "Connectix Quickcam max-poll was above 5000. Using 5000.\n");
1162 maxpoll = 5000;
1163 }
1164
1165 if (yieldlines < 1) {
1166 printk(KERN_INFO "Connectix Quickcam yieldlines was less than 1. Using 1.\n");
1167 yieldlines = 1;
1168 }
1169#endif
1170 return parport_register_driver(&bwqcam_driver);
1171}
1172
1173module_init(init_bw_qcams);
1174module_exit(exit_bw_qcams);
1175
1176MODULE_LICENSE("GPL");
1177MODULE_VERSION("0.0.3");
diff --git a/drivers/staging/media/parport/c-qcam.c b/drivers/staging/media/parport/c-qcam.c
deleted file mode 100644
index b9010bd3ed3e..000000000000
--- a/drivers/staging/media/parport/c-qcam.c
+++ /dev/null
@@ -1,882 +0,0 @@
1/*
2 * Video4Linux Colour QuickCam driver
3 * Copyright 1997-2000 Philip Blundell <philb@gnu.org>
4 *
5 * Module parameters:
6 *
7 * parport=auto -- probe all parports (default)
8 * parport=0 -- parport0 becomes qcam1
9 * parport=2,0,1 -- parports 2,0,1 are tried in that order
10 *
11 * probe=0 -- do no probing, assume camera is present
12 * probe=1 -- use IEEE-1284 autoprobe data only (default)
13 * probe=2 -- probe aggressively for cameras
14 *
15 * force_rgb=1 -- force data format to RGB (default is BGR)
16 *
17 * The parport parameter controls which parports will be scanned.
18 * Scanning all parports causes some printers to print a garbage page.
19 * -- March 14, 1999 Billy Donahue <billy@escape.com>
20 *
21 * Fixed data format to BGR, added force_rgb parameter. Added missing
22 * parport_unregister_driver() on module removal.
23 * -- May 28, 2000 Claudio Matsuoka <claudio@conectiva.com>
24 */
25
26#include <linux/module.h>
27#include <linux/delay.h>
28#include <linux/errno.h>
29#include <linux/fs.h>
30#include <linux/init.h>
31#include <linux/kernel.h>
32#include <linux/slab.h>
33#include <linux/mm.h>
34#include <linux/parport.h>
35#include <linux/sched.h>
36#include <linux/mutex.h>
37#include <linux/jiffies.h>
38#include <linux/videodev2.h>
39#include <asm/uaccess.h>
40#include <media/v4l2-device.h>
41#include <media/v4l2-common.h>
42#include <media/v4l2-ioctl.h>
43#include <media/v4l2-fh.h>
44#include <media/v4l2-ctrls.h>
45#include <media/v4l2-event.h>
46
47struct qcam {
48 struct v4l2_device v4l2_dev;
49 struct video_device vdev;
50 struct v4l2_ctrl_handler hdl;
51 struct pardevice *pdev;
52 struct parport *pport;
53 int width, height;
54 int ccd_width, ccd_height;
55 int mode;
56 int contrast, brightness, whitebal;
57 int top, left;
58 unsigned int bidirectional;
59 struct mutex lock;
60};
61
62/* cameras maximum */
63#define MAX_CAMS 4
64
65/* The three possible QuickCam modes */
66#define QC_MILLIONS 0x18
67#define QC_BILLIONS 0x10
68#define QC_THOUSANDS 0x08 /* with VIDEC compression (not supported) */
69
70/* The three possible decimations */
71#define QC_DECIMATION_1 0
72#define QC_DECIMATION_2 2
73#define QC_DECIMATION_4 4
74
75#define BANNER "Colour QuickCam for Video4Linux v0.06"
76
77static int parport[MAX_CAMS] = { [1 ... MAX_CAMS-1] = -1 };
78static int probe = 2;
79static bool force_rgb;
80static int video_nr = -1;
81
82/* FIXME: parport=auto would never have worked, surely? --RR */
83MODULE_PARM_DESC(parport, "parport=<auto|n[,n]...> for port detection method\n"
84 "probe=<0|1|2> for camera detection method\n"
85 "force_rgb=<0|1> for RGB data format (default BGR)");
86module_param_array(parport, int, NULL, 0);
87module_param(probe, int, 0);
88module_param(force_rgb, bool, 0);
89module_param(video_nr, int, 0);
90
91static struct qcam *qcams[MAX_CAMS];
92static unsigned int num_cams;
93
94static inline void qcam_set_ack(struct qcam *qcam, unsigned int i)
95{
96 /* note: the QC specs refer to the PCAck pin by voltage, not
97 software level. PC ports have builtin inverters. */
98 parport_frob_control(qcam->pport, 8, i ? 8 : 0);
99}
100
101static inline unsigned int qcam_ready1(struct qcam *qcam)
102{
103 return (parport_read_status(qcam->pport) & 0x8) ? 1 : 0;
104}
105
106static inline unsigned int qcam_ready2(struct qcam *qcam)
107{
108 return (parport_read_data(qcam->pport) & 0x1) ? 1 : 0;
109}
110
111static unsigned int qcam_await_ready1(struct qcam *qcam, int value)
112{
113 struct v4l2_device *v4l2_dev = &qcam->v4l2_dev;
114 unsigned long oldjiffies = jiffies;
115 unsigned int i;
116
117 for (oldjiffies = jiffies;
118 time_before(jiffies, oldjiffies + msecs_to_jiffies(40));)
119 if (qcam_ready1(qcam) == value)
120 return 0;
121
122 /* If the camera didn't respond within 1/25 second, poll slowly
123 for a while. */
124 for (i = 0; i < 50; i++) {
125 if (qcam_ready1(qcam) == value)
126 return 0;
127 msleep_interruptible(100);
128 }
129
130 /* Probably somebody pulled the plug out. Not much we can do. */
131 v4l2_err(v4l2_dev, "ready1 timeout (%d) %x %x\n", value,
132 parport_read_status(qcam->pport),
133 parport_read_control(qcam->pport));
134 return 1;
135}
136
137static unsigned int qcam_await_ready2(struct qcam *qcam, int value)
138{
139 struct v4l2_device *v4l2_dev = &qcam->v4l2_dev;
140 unsigned long oldjiffies = jiffies;
141 unsigned int i;
142
143 for (oldjiffies = jiffies;
144 time_before(jiffies, oldjiffies + msecs_to_jiffies(40));)
145 if (qcam_ready2(qcam) == value)
146 return 0;
147
148 /* If the camera didn't respond within 1/25 second, poll slowly
149 for a while. */
150 for (i = 0; i < 50; i++) {
151 if (qcam_ready2(qcam) == value)
152 return 0;
153 msleep_interruptible(100);
154 }
155
156 /* Probably somebody pulled the plug out. Not much we can do. */
157 v4l2_err(v4l2_dev, "ready2 timeout (%d) %x %x %x\n", value,
158 parport_read_status(qcam->pport),
159 parport_read_control(qcam->pport),
160 parport_read_data(qcam->pport));
161 return 1;
162}
163
164static int qcam_read_data(struct qcam *qcam)
165{
166 unsigned int idata;
167
168 qcam_set_ack(qcam, 0);
169 if (qcam_await_ready1(qcam, 1))
170 return -1;
171 idata = parport_read_status(qcam->pport) & 0xf0;
172 qcam_set_ack(qcam, 1);
173 if (qcam_await_ready1(qcam, 0))
174 return -1;
175 idata |= parport_read_status(qcam->pport) >> 4;
176 return idata;
177}
178
179static int qcam_write_data(struct qcam *qcam, unsigned int data)
180{
181 struct v4l2_device *v4l2_dev = &qcam->v4l2_dev;
182 unsigned int idata;
183
184 parport_write_data(qcam->pport, data);
185 idata = qcam_read_data(qcam);
186 if (data != idata) {
187 v4l2_warn(v4l2_dev, "sent %x but received %x\n", data,
188 idata);
189 return 1;
190 }
191 return 0;
192}
193
194static inline int qcam_set(struct qcam *qcam, unsigned int cmd, unsigned int data)
195{
196 if (qcam_write_data(qcam, cmd))
197 return -1;
198 if (qcam_write_data(qcam, data))
199 return -1;
200 return 0;
201}
202
203static inline int qcam_get(struct qcam *qcam, unsigned int cmd)
204{
205 if (qcam_write_data(qcam, cmd))
206 return -1;
207 return qcam_read_data(qcam);
208}
209
210static int qc_detect(struct qcam *qcam)
211{
212 unsigned int stat, ostat, i, count = 0;
213
214 /* The probe routine below is not very reliable. The IEEE-1284
215 probe takes precedence. */
216 /* XXX Currently parport provides no way to distinguish between
217 "the IEEE probe was not done" and "the probe was done, but
218 no device was found". Fix this one day. */
219 if (qcam->pport->probe_info[0].class == PARPORT_CLASS_MEDIA
220 && qcam->pport->probe_info[0].model
221 && !strcmp(qcam->pdev->port->probe_info[0].model,
222 "Color QuickCam 2.0")) {
223 printk(KERN_DEBUG "QuickCam: Found by IEEE1284 probe.\n");
224 return 1;
225 }
226
227 if (probe < 2)
228 return 0;
229
230 parport_write_control(qcam->pport, 0xc);
231
232 /* look for a heartbeat */
233 ostat = stat = parport_read_status(qcam->pport);
234 for (i = 0; i < 250; i++) {
235 mdelay(1);
236 stat = parport_read_status(qcam->pport);
237 if (ostat != stat) {
238 if (++count >= 3)
239 return 1;
240 ostat = stat;
241 }
242 }
243
244 /* Reset the camera and try again */
245 parport_write_control(qcam->pport, 0xc);
246 parport_write_control(qcam->pport, 0x8);
247 mdelay(1);
248 parport_write_control(qcam->pport, 0xc);
249 mdelay(1);
250 count = 0;
251
252 ostat = stat = parport_read_status(qcam->pport);
253 for (i = 0; i < 250; i++) {
254 mdelay(1);
255 stat = parport_read_status(qcam->pport);
256 if (ostat != stat) {
257 if (++count >= 3)
258 return 1;
259 ostat = stat;
260 }
261 }
262
263 /* no (or flatline) camera, give up */
264 return 0;
265}
266
267static void qc_reset(struct qcam *qcam)
268{
269 parport_write_control(qcam->pport, 0xc);
270 parport_write_control(qcam->pport, 0x8);
271 mdelay(1);
272 parport_write_control(qcam->pport, 0xc);
273 mdelay(1);
274}
275
276/* Reset the QuickCam and program for brightness, contrast,
277 * white-balance, and resolution. */
278
279static void qc_setup(struct qcam *qcam)
280{
281 qc_reset(qcam);
282
283 /* Set the brightness. */
284 qcam_set(qcam, 11, qcam->brightness);
285
286 /* Set the height and width. These refer to the actual
287 CCD area *before* applying the selected decimation. */
288 qcam_set(qcam, 17, qcam->ccd_height);
289 qcam_set(qcam, 19, qcam->ccd_width / 2);
290
291 /* Set top and left. */
292 qcam_set(qcam, 0xd, qcam->top);
293 qcam_set(qcam, 0xf, qcam->left);
294
295 /* Set contrast and white balance. */
296 qcam_set(qcam, 0x19, qcam->contrast);
297 qcam_set(qcam, 0x1f, qcam->whitebal);
298
299 /* Set the speed. */
300 qcam_set(qcam, 45, 2);
301}
302
303/* Read some bytes from the camera and put them in the buffer.
304 nbytes should be a multiple of 3, because bidirectional mode gives
305 us three bytes at a time. */
306
307static unsigned int qcam_read_bytes(struct qcam *qcam, unsigned char *buf, unsigned int nbytes)
308{
309 unsigned int bytes = 0;
310
311 qcam_set_ack(qcam, 0);
312 if (qcam->bidirectional) {
313 /* It's a bidirectional port */
314 while (bytes < nbytes) {
315 unsigned int lo1, hi1, lo2, hi2;
316 unsigned char r, g, b;
317
318 if (qcam_await_ready2(qcam, 1))
319 return bytes;
320 lo1 = parport_read_data(qcam->pport) >> 1;
321 hi1 = ((parport_read_status(qcam->pport) >> 3) & 0x1f) ^ 0x10;
322 qcam_set_ack(qcam, 1);
323 if (qcam_await_ready2(qcam, 0))
324 return bytes;
325 lo2 = parport_read_data(qcam->pport) >> 1;
326 hi2 = ((parport_read_status(qcam->pport) >> 3) & 0x1f) ^ 0x10;
327 qcam_set_ack(qcam, 0);
328 r = lo1 | ((hi1 & 1) << 7);
329 g = ((hi1 & 0x1e) << 3) | ((hi2 & 0x1e) >> 1);
330 b = lo2 | ((hi2 & 1) << 7);
331 if (force_rgb) {
332 buf[bytes++] = r;
333 buf[bytes++] = g;
334 buf[bytes++] = b;
335 } else {
336 buf[bytes++] = b;
337 buf[bytes++] = g;
338 buf[bytes++] = r;
339 }
340 }
341 } else {
342 /* It's a unidirectional port */
343 int i = 0, n = bytes;
344 unsigned char rgb[3];
345
346 while (bytes < nbytes) {
347 unsigned int hi, lo;
348
349 if (qcam_await_ready1(qcam, 1))
350 return bytes;
351 hi = (parport_read_status(qcam->pport) & 0xf0);
352 qcam_set_ack(qcam, 1);
353 if (qcam_await_ready1(qcam, 0))
354 return bytes;
355 lo = (parport_read_status(qcam->pport) & 0xf0);
356 qcam_set_ack(qcam, 0);
357 /* flip some bits */
358 rgb[(i = bytes++ % 3)] = (hi | (lo >> 4)) ^ 0x88;
359 if (i >= 2) {
360get_fragment:
361 if (force_rgb) {
362 buf[n++] = rgb[0];
363 buf[n++] = rgb[1];
364 buf[n++] = rgb[2];
365 } else {
366 buf[n++] = rgb[2];
367 buf[n++] = rgb[1];
368 buf[n++] = rgb[0];
369 }
370 }
371 }
372 if (i) {
373 i = 0;
374 goto get_fragment;
375 }
376 }
377 return bytes;
378}
379
380#define BUFSZ 150
381
382static long qc_capture(struct qcam *qcam, char __user *buf, unsigned long len)
383{
384 struct v4l2_device *v4l2_dev = &qcam->v4l2_dev;
385 unsigned lines, pixelsperline;
386 unsigned int is_bi_dir = qcam->bidirectional;
387 size_t wantlen, outptr = 0;
388 char tmpbuf[BUFSZ];
389
390 if (!access_ok(VERIFY_WRITE, buf, len))
391 return -EFAULT;
392
393 /* Wait for camera to become ready */
394 for (;;) {
395 int i = qcam_get(qcam, 41);
396
397 if (i == -1) {
398 qc_setup(qcam);
399 return -EIO;
400 }
401 if ((i & 0x80) == 0)
402 break;
403 schedule();
404 }
405
406 if (qcam_set(qcam, 7, (qcam->mode | (is_bi_dir ? 1 : 0)) + 1))
407 return -EIO;
408
409 lines = qcam->height;
410 pixelsperline = qcam->width;
411
412 if (is_bi_dir) {
413 /* Turn the port around */
414 parport_data_reverse(qcam->pport);
415 mdelay(3);
416 qcam_set_ack(qcam, 0);
417 if (qcam_await_ready1(qcam, 1)) {
418 qc_setup(qcam);
419 return -EIO;
420 }
421 qcam_set_ack(qcam, 1);
422 if (qcam_await_ready1(qcam, 0)) {
423 qc_setup(qcam);
424 return -EIO;
425 }
426 }
427
428 wantlen = lines * pixelsperline * 24 / 8;
429
430 while (wantlen) {
431 size_t t, s;
432
433 s = (wantlen > BUFSZ) ? BUFSZ : wantlen;
434 t = qcam_read_bytes(qcam, tmpbuf, s);
435 if (outptr < len) {
436 size_t sz = len - outptr;
437
438 if (sz > t)
439 sz = t;
440 if (__copy_to_user(buf + outptr, tmpbuf, sz))
441 break;
442 outptr += sz;
443 }
444 wantlen -= t;
445 if (t < s)
446 break;
447 cond_resched();
448 }
449
450 len = outptr;
451
452 if (wantlen) {
453 v4l2_err(v4l2_dev, "short read.\n");
454 if (is_bi_dir)
455 parport_data_forward(qcam->pport);
456 qc_setup(qcam);
457 return len;
458 }
459
460 if (is_bi_dir) {
461 int l;
462
463 do {
464 l = qcam_read_bytes(qcam, tmpbuf, 3);
465 cond_resched();
466 } while (l && (tmpbuf[0] == 0x7e || tmpbuf[1] == 0x7e || tmpbuf[2] == 0x7e));
467 if (force_rgb) {
468 if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
469 v4l2_err(v4l2_dev, "bad EOF\n");
470 } else {
471 if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
472 v4l2_err(v4l2_dev, "bad EOF\n");
473 }
474 qcam_set_ack(qcam, 0);
475 if (qcam_await_ready1(qcam, 1)) {
476 v4l2_err(v4l2_dev, "no ack after EOF\n");
477 parport_data_forward(qcam->pport);
478 qc_setup(qcam);
479 return len;
480 }
481 parport_data_forward(qcam->pport);
482 mdelay(3);
483 qcam_set_ack(qcam, 1);
484 if (qcam_await_ready1(qcam, 0)) {
485 v4l2_err(v4l2_dev, "no ack to port turnaround\n");
486 qc_setup(qcam);
487 return len;
488 }
489 } else {
490 int l;
491
492 do {
493 l = qcam_read_bytes(qcam, tmpbuf, 1);
494 cond_resched();
495 } while (l && tmpbuf[0] == 0x7e);
496 l = qcam_read_bytes(qcam, tmpbuf + 1, 2);
497 if (force_rgb) {
498 if (tmpbuf[0] != 0xe || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xf)
499 v4l2_err(v4l2_dev, "bad EOF\n");
500 } else {
501 if (tmpbuf[0] != 0xf || tmpbuf[1] != 0x0 || tmpbuf[2] != 0xe)
502 v4l2_err(v4l2_dev, "bad EOF\n");
503 }
504 }
505
506 qcam_write_data(qcam, 0);
507 return len;
508}
509
510/*
511 * Video4linux interfacing
512 */
513
514static int qcam_querycap(struct file *file, void *priv,
515 struct v4l2_capability *vcap)
516{
517 struct qcam *qcam = video_drvdata(file);
518
519 strlcpy(vcap->driver, qcam->v4l2_dev.name, sizeof(vcap->driver));
520 strlcpy(vcap->card, "Color Quickcam", sizeof(vcap->card));
521 strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info));
522 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
523 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
524 return 0;
525}
526
527static int qcam_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
528{
529 if (vin->index > 0)
530 return -EINVAL;
531 strlcpy(vin->name, "Camera", sizeof(vin->name));
532 vin->type = V4L2_INPUT_TYPE_CAMERA;
533 vin->audioset = 0;
534 vin->tuner = 0;
535 vin->std = 0;
536 vin->status = 0;
537 return 0;
538}
539
540static int qcam_g_input(struct file *file, void *fh, unsigned int *inp)
541{
542 *inp = 0;
543 return 0;
544}
545
546static int qcam_s_input(struct file *file, void *fh, unsigned int inp)
547{
548 return (inp > 0) ? -EINVAL : 0;
549}
550
551static int qcam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
552{
553 struct qcam *qcam = video_drvdata(file);
554 struct v4l2_pix_format *pix = &fmt->fmt.pix;
555
556 pix->width = qcam->width;
557 pix->height = qcam->height;
558 pix->pixelformat = V4L2_PIX_FMT_RGB24;
559 pix->field = V4L2_FIELD_NONE;
560 pix->bytesperline = 3 * qcam->width;
561 pix->sizeimage = 3 * qcam->width * qcam->height;
562 /* Just a guess */
563 pix->colorspace = V4L2_COLORSPACE_SRGB;
564 return 0;
565}
566
567static int qcam_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
568{
569 struct v4l2_pix_format *pix = &fmt->fmt.pix;
570
571 if (pix->height < 60 || pix->width < 80) {
572 pix->height = 60;
573 pix->width = 80;
574 } else if (pix->height < 120 || pix->width < 160) {
575 pix->height = 120;
576 pix->width = 160;
577 } else {
578 pix->height = 240;
579 pix->width = 320;
580 }
581 pix->pixelformat = V4L2_PIX_FMT_RGB24;
582 pix->field = V4L2_FIELD_NONE;
583 pix->bytesperline = 3 * pix->width;
584 pix->sizeimage = 3 * pix->width * pix->height;
585 /* Just a guess */
586 pix->colorspace = V4L2_COLORSPACE_SRGB;
587 return 0;
588}
589
590static int qcam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
591{
592 struct qcam *qcam = video_drvdata(file);
593 struct v4l2_pix_format *pix = &fmt->fmt.pix;
594 int ret = qcam_try_fmt_vid_cap(file, fh, fmt);
595
596 if (ret)
597 return ret;
598 switch (pix->height) {
599 case 60:
600 qcam->mode = QC_DECIMATION_4;
601 break;
602 case 120:
603 qcam->mode = QC_DECIMATION_2;
604 break;
605 default:
606 qcam->mode = QC_DECIMATION_1;
607 break;
608 }
609
610 mutex_lock(&qcam->lock);
611 qcam->mode |= QC_MILLIONS;
612 qcam->height = pix->height;
613 qcam->width = pix->width;
614 parport_claim_or_block(qcam->pdev);
615 qc_setup(qcam);
616 parport_release(qcam->pdev);
617 mutex_unlock(&qcam->lock);
618 return 0;
619}
620
621static int qcam_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
622{
623 static struct v4l2_fmtdesc formats[] = {
624 { 0, 0, 0,
625 "RGB 8:8:8", V4L2_PIX_FMT_RGB24,
626 { 0, 0, 0, 0 }
627 },
628 };
629 enum v4l2_buf_type type = fmt->type;
630
631 if (fmt->index > 0)
632 return -EINVAL;
633
634 *fmt = formats[fmt->index];
635 fmt->type = type;
636 return 0;
637}
638
639static ssize_t qcam_read(struct file *file, char __user *buf,
640 size_t count, loff_t *ppos)
641{
642 struct qcam *qcam = video_drvdata(file);
643 int len;
644
645 mutex_lock(&qcam->lock);
646 parport_claim_or_block(qcam->pdev);
647 /* Probably should have a semaphore against multiple users */
648 len = qc_capture(qcam, buf, count);
649 parport_release(qcam->pdev);
650 mutex_unlock(&qcam->lock);
651 return len;
652}
653
654static int qcam_s_ctrl(struct v4l2_ctrl *ctrl)
655{
656 struct qcam *qcam =
657 container_of(ctrl->handler, struct qcam, hdl);
658 int ret = 0;
659
660 mutex_lock(&qcam->lock);
661 switch (ctrl->id) {
662 case V4L2_CID_BRIGHTNESS:
663 qcam->brightness = ctrl->val;
664 break;
665 case V4L2_CID_CONTRAST:
666 qcam->contrast = ctrl->val;
667 break;
668 case V4L2_CID_GAMMA:
669 qcam->whitebal = ctrl->val;
670 break;
671 default:
672 ret = -EINVAL;
673 break;
674 }
675 if (ret == 0) {
676 parport_claim_or_block(qcam->pdev);
677 qc_setup(qcam);
678 parport_release(qcam->pdev);
679 }
680 mutex_unlock(&qcam->lock);
681 return ret;
682}
683
684static const struct v4l2_file_operations qcam_fops = {
685 .owner = THIS_MODULE,
686 .open = v4l2_fh_open,
687 .release = v4l2_fh_release,
688 .poll = v4l2_ctrl_poll,
689 .unlocked_ioctl = video_ioctl2,
690 .read = qcam_read,
691};
692
693static const struct v4l2_ioctl_ops qcam_ioctl_ops = {
694 .vidioc_querycap = qcam_querycap,
695 .vidioc_g_input = qcam_g_input,
696 .vidioc_s_input = qcam_s_input,
697 .vidioc_enum_input = qcam_enum_input,
698 .vidioc_enum_fmt_vid_cap = qcam_enum_fmt_vid_cap,
699 .vidioc_g_fmt_vid_cap = qcam_g_fmt_vid_cap,
700 .vidioc_s_fmt_vid_cap = qcam_s_fmt_vid_cap,
701 .vidioc_try_fmt_vid_cap = qcam_try_fmt_vid_cap,
702 .vidioc_log_status = v4l2_ctrl_log_status,
703 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
704 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
705};
706
707static const struct v4l2_ctrl_ops qcam_ctrl_ops = {
708 .s_ctrl = qcam_s_ctrl,
709};
710
711/* Initialize the QuickCam driver control structure. */
712
713static struct qcam *qcam_init(struct parport *port)
714{
715 struct qcam *qcam;
716 struct v4l2_device *v4l2_dev;
717
718 qcam = kzalloc(sizeof(*qcam), GFP_KERNEL);
719 if (qcam == NULL)
720 return NULL;
721
722 v4l2_dev = &qcam->v4l2_dev;
723 strlcpy(v4l2_dev->name, "c-qcam", sizeof(v4l2_dev->name));
724
725 if (v4l2_device_register(NULL, v4l2_dev) < 0) {
726 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
727 kfree(qcam);
728 return NULL;
729 }
730
731 v4l2_ctrl_handler_init(&qcam->hdl, 3);
732 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
733 V4L2_CID_BRIGHTNESS, 0, 255, 1, 240);
734 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
735 V4L2_CID_CONTRAST, 0, 255, 1, 192);
736 v4l2_ctrl_new_std(&qcam->hdl, &qcam_ctrl_ops,
737 V4L2_CID_GAMMA, 0, 255, 1, 128);
738 if (qcam->hdl.error) {
739 v4l2_err(v4l2_dev, "couldn't register controls\n");
740 v4l2_ctrl_handler_free(&qcam->hdl);
741 kfree(qcam);
742 return NULL;
743 }
744
745 qcam->pport = port;
746 qcam->pdev = parport_register_device(port, "c-qcam", NULL, NULL,
747 NULL, 0, NULL);
748
749 qcam->bidirectional = (qcam->pport->modes & PARPORT_MODE_TRISTATE) ? 1 : 0;
750
751 if (qcam->pdev == NULL) {
752 v4l2_err(v4l2_dev, "couldn't register for %s.\n", port->name);
753 v4l2_ctrl_handler_free(&qcam->hdl);
754 kfree(qcam);
755 return NULL;
756 }
757
758 strlcpy(qcam->vdev.name, "Colour QuickCam", sizeof(qcam->vdev.name));
759 qcam->vdev.v4l2_dev = v4l2_dev;
760 qcam->vdev.fops = &qcam_fops;
761 qcam->vdev.ioctl_ops = &qcam_ioctl_ops;
762 qcam->vdev.release = video_device_release_empty;
763 qcam->vdev.ctrl_handler = &qcam->hdl;
764 video_set_drvdata(&qcam->vdev, qcam);
765
766 mutex_init(&qcam->lock);
767 qcam->width = qcam->ccd_width = 320;
768 qcam->height = qcam->ccd_height = 240;
769 qcam->mode = QC_MILLIONS | QC_DECIMATION_1;
770 qcam->contrast = 192;
771 qcam->brightness = 240;
772 qcam->whitebal = 128;
773 qcam->top = 1;
774 qcam->left = 14;
775 return qcam;
776}
777
778static int init_cqcam(struct parport *port)
779{
780 struct qcam *qcam;
781 struct v4l2_device *v4l2_dev;
782
783 if (parport[0] != -1) {
784 /* The user gave specific instructions */
785 int i, found = 0;
786
787 for (i = 0; i < MAX_CAMS && parport[i] != -1; i++) {
788 if (parport[0] == port->number)
789 found = 1;
790 }
791 if (!found)
792 return -ENODEV;
793 }
794
795 if (num_cams == MAX_CAMS)
796 return -ENOSPC;
797
798 qcam = qcam_init(port);
799 if (qcam == NULL)
800 return -ENODEV;
801
802 v4l2_dev = &qcam->v4l2_dev;
803
804 parport_claim_or_block(qcam->pdev);
805
806 qc_reset(qcam);
807
808 if (probe && qc_detect(qcam) == 0) {
809 parport_release(qcam->pdev);
810 parport_unregister_device(qcam->pdev);
811 kfree(qcam);
812 return -ENODEV;
813 }
814
815 qc_setup(qcam);
816
817 parport_release(qcam->pdev);
818
819 if (video_register_device(&qcam->vdev, VFL_TYPE_GRABBER, video_nr) < 0) {
820 v4l2_err(v4l2_dev, "Unable to register Colour QuickCam on %s\n",
821 qcam->pport->name);
822 parport_unregister_device(qcam->pdev);
823 kfree(qcam);
824 return -ENODEV;
825 }
826
827 v4l2_info(v4l2_dev, "%s: Colour QuickCam found on %s\n",
828 video_device_node_name(&qcam->vdev), qcam->pport->name);
829
830 qcams[num_cams++] = qcam;
831
832 return 0;
833}
834
835static void close_cqcam(struct qcam *qcam)
836{
837 video_unregister_device(&qcam->vdev);
838 v4l2_ctrl_handler_free(&qcam->hdl);
839 parport_unregister_device(qcam->pdev);
840 kfree(qcam);
841}
842
843static void cq_attach(struct parport *port)
844{
845 init_cqcam(port);
846}
847
848static void cq_detach(struct parport *port)
849{
850 /* Write this some day. */
851}
852
853static struct parport_driver cqcam_driver = {
854 .name = "cqcam",
855 .attach = cq_attach,
856 .detach = cq_detach,
857};
858
859static int __init cqcam_init(void)
860{
861 printk(KERN_INFO BANNER "\n");
862
863 return parport_register_driver(&cqcam_driver);
864}
865
866static void __exit cqcam_cleanup(void)
867{
868 unsigned int i;
869
870 for (i = 0; i < num_cams; i++)
871 close_cqcam(qcams[i]);
872
873 parport_unregister_driver(&cqcam_driver);
874}
875
876MODULE_AUTHOR("Philip Blundell <philb@gnu.org>");
877MODULE_DESCRIPTION(BANNER);
878MODULE_LICENSE("GPL");
879MODULE_VERSION("0.0.4");
880
881module_init(cqcam_init);
882module_exit(cqcam_cleanup);
diff --git a/drivers/staging/media/parport/pms.c b/drivers/staging/media/parport/pms.c
deleted file mode 100644
index e6b497528cea..000000000000
--- a/drivers/staging/media/parport/pms.c
+++ /dev/null
@@ -1,1156 +0,0 @@
1/*
2 * Media Vision Pro Movie Studio
3 * or
4 * "all you need is an I2C bus some RAM and a prayer"
5 *
6 * This draws heavily on code
7 *
8 * (c) Wolfgang Koehler, wolf@first.gmd.de, Dec. 1994
9 * Kiefernring 15
10 * 14478 Potsdam, Germany
11 *
12 * Most of this code is directly derived from his userspace driver.
13 * His driver works so send any reports to alan@lxorguk.ukuu.org.uk
14 * unless the userspace driver also doesn't work for you...
15 *
16 * Changes:
17 * 25-11-2009 Hans Verkuil <hverkuil@xs4all.nl>
18 * - converted to version 2 of the V4L API.
19 * 08/07/2003 Daniele Bellucci <bellucda@tiscali.it>
20 * - pms_capture: report back -EFAULT
21 */
22
23#include <linux/module.h>
24#include <linux/delay.h>
25#include <linux/errno.h>
26#include <linux/fs.h>
27#include <linux/kernel.h>
28#include <linux/mm.h>
29#include <linux/slab.h>
30#include <linux/ioport.h>
31#include <linux/init.h>
32#include <linux/mutex.h>
33#include <linux/uaccess.h>
34#include <linux/isa.h>
35#include <asm/io.h>
36
37#include <linux/videodev2.h>
38#include <media/v4l2-common.h>
39#include <media/v4l2-ioctl.h>
40#include <media/v4l2-ctrls.h>
41#include <media/v4l2-fh.h>
42#include <media/v4l2-event.h>
43#include <media/v4l2-device.h>
44
45MODULE_LICENSE("GPL");
46MODULE_VERSION("0.0.5");
47
48#define MOTOROLA 1
49#define PHILIPS2 2 /* SAA7191 */
50#define PHILIPS1 3
51#define MVVMEMORYWIDTH 0x40 /* 512 bytes */
52
53struct i2c_info {
54 u8 slave;
55 u8 sub;
56 u8 data;
57 u8 hits;
58};
59
60struct pms {
61 struct v4l2_device v4l2_dev;
62 struct video_device vdev;
63 struct v4l2_ctrl_handler hdl;
64 int height;
65 int width;
66 int depth;
67 int input;
68 struct mutex lock;
69 int i2c_count;
70 struct i2c_info i2cinfo[64];
71
72 int decoder;
73 int standard; /* 0 - auto 1 - ntsc 2 - pal 3 - secam */
74 v4l2_std_id std;
75 int io;
76 int data;
77 void __iomem *mem;
78};
79
80/*
81 * I/O ports and Shared Memory
82 */
83
84static int io_port = 0x250;
85module_param(io_port, int, 0);
86
87static int mem_base = 0xc8000;
88module_param(mem_base, int, 0);
89
90static int video_nr = -1;
91module_param(video_nr, int, 0);
92
93
94static inline void mvv_write(struct pms *dev, u8 index, u8 value)
95{
96 outw(index | (value << 8), dev->io);
97}
98
99static inline u8 mvv_read(struct pms *dev, u8 index)
100{
101 outb(index, dev->io);
102 return inb(dev->data);
103}
104
105static int pms_i2c_stat(struct pms *dev, u8 slave)
106{
107 int counter = 0;
108 int i;
109
110 outb(0x28, dev->io);
111
112 while ((inb(dev->data) & 0x01) == 0)
113 if (counter++ == 256)
114 break;
115
116 while ((inb(dev->data) & 0x01) != 0)
117 if (counter++ == 256)
118 break;
119
120 outb(slave, dev->io);
121
122 counter = 0;
123 while ((inb(dev->data) & 0x01) == 0)
124 if (counter++ == 256)
125 break;
126
127 while ((inb(dev->data) & 0x01) != 0)
128 if (counter++ == 256)
129 break;
130
131 for (i = 0; i < 12; i++) {
132 char st = inb(dev->data);
133
134 if ((st & 2) != 0)
135 return -1;
136 if ((st & 1) == 0)
137 break;
138 }
139 outb(0x29, dev->io);
140 return inb(dev->data);
141}
142
143static int pms_i2c_write(struct pms *dev, u16 slave, u16 sub, u16 data)
144{
145 int skip = 0;
146 int count;
147 int i;
148
149 for (i = 0; i < dev->i2c_count; i++) {
150 if ((dev->i2cinfo[i].slave == slave) &&
151 (dev->i2cinfo[i].sub == sub)) {
152 if (dev->i2cinfo[i].data == data)
153 skip = 1;
154 dev->i2cinfo[i].data = data;
155 i = dev->i2c_count + 1;
156 }
157 }
158
159 if (i == dev->i2c_count && dev->i2c_count < 64) {
160 dev->i2cinfo[dev->i2c_count].slave = slave;
161 dev->i2cinfo[dev->i2c_count].sub = sub;
162 dev->i2cinfo[dev->i2c_count].data = data;
163 dev->i2c_count++;
164 }
165
166 if (skip)
167 return 0;
168
169 mvv_write(dev, 0x29, sub);
170 mvv_write(dev, 0x2A, data);
171 mvv_write(dev, 0x28, slave);
172
173 outb(0x28, dev->io);
174
175 count = 0;
176 while ((inb(dev->data) & 1) == 0)
177 if (count > 255)
178 break;
179 while ((inb(dev->data) & 1) != 0)
180 if (count > 255)
181 break;
182
183 count = inb(dev->data);
184
185 if (count & 2)
186 return -1;
187 return count;
188}
189
190static int pms_i2c_read(struct pms *dev, int slave, int sub)
191{
192 int i;
193
194 for (i = 0; i < dev->i2c_count; i++) {
195 if (dev->i2cinfo[i].slave == slave && dev->i2cinfo[i].sub == sub)
196 return dev->i2cinfo[i].data;
197 }
198 return 0;
199}
200
201
202static void pms_i2c_andor(struct pms *dev, int slave, int sub, int and, int or)
203{
204 u8 tmp;
205
206 tmp = pms_i2c_read(dev, slave, sub);
207 tmp = (tmp & and) | or;
208 pms_i2c_write(dev, slave, sub, tmp);
209}
210
211/*
212 * Control functions
213 */
214
215
216static void pms_videosource(struct pms *dev, short source)
217{
218 switch (dev->decoder) {
219 case MOTOROLA:
220 break;
221 case PHILIPS2:
222 pms_i2c_andor(dev, 0x8a, 0x06, 0x7f, source ? 0x80 : 0);
223 break;
224 case PHILIPS1:
225 break;
226 }
227 mvv_write(dev, 0x2E, 0x31);
228 /* Was: mvv_write(dev, 0x2E, source ? 0x31 : 0x30);
229 But could not make this work correctly. Only Composite input
230 worked for me. */
231}
232
233static void pms_hue(struct pms *dev, short hue)
234{
235 switch (dev->decoder) {
236 case MOTOROLA:
237 pms_i2c_write(dev, 0x8a, 0x00, hue);
238 break;
239 case PHILIPS2:
240 pms_i2c_write(dev, 0x8a, 0x07, hue);
241 break;
242 case PHILIPS1:
243 pms_i2c_write(dev, 0x42, 0x07, hue);
244 break;
245 }
246}
247
248static void pms_saturation(struct pms *dev, short sat)
249{
250 switch (dev->decoder) {
251 case MOTOROLA:
252 pms_i2c_write(dev, 0x8a, 0x00, sat);
253 break;
254 case PHILIPS1:
255 pms_i2c_write(dev, 0x42, 0x12, sat);
256 break;
257 }
258}
259
260
261static void pms_contrast(struct pms *dev, short contrast)
262{
263 switch (dev->decoder) {
264 case MOTOROLA:
265 pms_i2c_write(dev, 0x8a, 0x00, contrast);
266 break;
267 case PHILIPS1:
268 pms_i2c_write(dev, 0x42, 0x13, contrast);
269 break;
270 }
271}
272
273static void pms_brightness(struct pms *dev, short brightness)
274{
275 switch (dev->decoder) {
276 case MOTOROLA:
277 pms_i2c_write(dev, 0x8a, 0x00, brightness);
278 pms_i2c_write(dev, 0x8a, 0x00, brightness);
279 pms_i2c_write(dev, 0x8a, 0x00, brightness);
280 break;
281 case PHILIPS1:
282 pms_i2c_write(dev, 0x42, 0x19, brightness);
283 break;
284 }
285}
286
287
288static void pms_format(struct pms *dev, short format)
289{
290 int target;
291
292 dev->standard = format;
293
294 if (dev->decoder == PHILIPS1)
295 target = 0x42;
296 else if (dev->decoder == PHILIPS2)
297 target = 0x8a;
298 else
299 return;
300
301 switch (format) {
302 case 0: /* Auto */
303 pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
304 pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x80);
305 break;
306 case 1: /* NTSC */
307 pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
308 pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x40);
309 break;
310 case 2: /* PAL */
311 pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x00);
312 pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00);
313 break;
314 case 3: /* SECAM */
315 pms_i2c_andor(dev, target, 0x0d, 0xfe, 0x01);
316 pms_i2c_andor(dev, target, 0x0f, 0x3f, 0x00);
317 break;
318 }
319}
320
321#ifdef FOR_FUTURE_EXPANSION
322
323/*
324 * These features of the PMS card are not currently exposes. They
325 * could become a private v4l ioctl for PMSCONFIG or somesuch if
326 * people need it. We also don't yet use the PMS interrupt.
327 */
328
329static void pms_hstart(struct pms *dev, short start)
330{
331 switch (dev->decoder) {
332 case PHILIPS1:
333 pms_i2c_write(dev, 0x8a, 0x05, start);
334 pms_i2c_write(dev, 0x8a, 0x18, start);
335 break;
336 case PHILIPS2:
337 pms_i2c_write(dev, 0x42, 0x05, start);
338 pms_i2c_write(dev, 0x42, 0x18, start);
339 break;
340 }
341}
342
343/*
344 * Bandpass filters
345 */
346
347static void pms_bandpass(struct pms *dev, short pass)
348{
349 if (dev->decoder == PHILIPS2)
350 pms_i2c_andor(dev, 0x8a, 0x06, 0xcf, (pass & 0x03) << 4);
351 else if (dev->decoder == PHILIPS1)
352 pms_i2c_andor(dev, 0x42, 0x06, 0xcf, (pass & 0x03) << 4);
353}
354
355static void pms_antisnow(struct pms *dev, short snow)
356{
357 if (dev->decoder == PHILIPS2)
358 pms_i2c_andor(dev, 0x8a, 0x06, 0xf3, (snow & 0x03) << 2);
359 else if (dev->decoder == PHILIPS1)
360 pms_i2c_andor(dev, 0x42, 0x06, 0xf3, (snow & 0x03) << 2);
361}
362
363static void pms_sharpness(struct pms *dev, short sharp)
364{
365 if (dev->decoder == PHILIPS2)
366 pms_i2c_andor(dev, 0x8a, 0x06, 0xfc, sharp & 0x03);
367 else if (dev->decoder == PHILIPS1)
368 pms_i2c_andor(dev, 0x42, 0x06, 0xfc, sharp & 0x03);
369}
370
371static void pms_chromaagc(struct pms *dev, short agc)
372{
373 if (dev->decoder == PHILIPS2)
374 pms_i2c_andor(dev, 0x8a, 0x0c, 0x9f, (agc & 0x03) << 5);
375 else if (dev->decoder == PHILIPS1)
376 pms_i2c_andor(dev, 0x42, 0x0c, 0x9f, (agc & 0x03) << 5);
377}
378
379static void pms_vertnoise(struct pms *dev, short noise)
380{
381 if (dev->decoder == PHILIPS2)
382 pms_i2c_andor(dev, 0x8a, 0x10, 0xfc, noise & 3);
383 else if (dev->decoder == PHILIPS1)
384 pms_i2c_andor(dev, 0x42, 0x10, 0xfc, noise & 3);
385}
386
387static void pms_forcecolour(struct pms *dev, short colour)
388{
389 if (dev->decoder == PHILIPS2)
390 pms_i2c_andor(dev, 0x8a, 0x0c, 0x7f, (colour & 1) << 7);
391 else if (dev->decoder == PHILIPS1)
392 pms_i2c_andor(dev, 0x42, 0x0c, 0x7, (colour & 1) << 7);
393}
394
395static void pms_antigamma(struct pms *dev, short gamma)
396{
397 if (dev->decoder == PHILIPS2)
398 pms_i2c_andor(dev, 0xb8, 0x00, 0x7f, (gamma & 1) << 7);
399 else if (dev->decoder == PHILIPS1)
400 pms_i2c_andor(dev, 0x42, 0x20, 0x7, (gamma & 1) << 7);
401}
402
403static void pms_prefilter(struct pms *dev, short filter)
404{
405 if (dev->decoder == PHILIPS2)
406 pms_i2c_andor(dev, 0x8a, 0x06, 0xbf, (filter & 1) << 6);
407 else if (dev->decoder == PHILIPS1)
408 pms_i2c_andor(dev, 0x42, 0x06, 0xbf, (filter & 1) << 6);
409}
410
411static void pms_hfilter(struct pms *dev, short filter)
412{
413 if (dev->decoder == PHILIPS2)
414 pms_i2c_andor(dev, 0xb8, 0x04, 0x1f, (filter & 7) << 5);
415 else if (dev->decoder == PHILIPS1)
416 pms_i2c_andor(dev, 0x42, 0x24, 0x1f, (filter & 7) << 5);
417}
418
419static void pms_vfilter(struct pms *dev, short filter)
420{
421 if (dev->decoder == PHILIPS2)
422 pms_i2c_andor(dev, 0xb8, 0x08, 0x9f, (filter & 3) << 5);
423 else if (dev->decoder == PHILIPS1)
424 pms_i2c_andor(dev, 0x42, 0x28, 0x9f, (filter & 3) << 5);
425}
426
427static void pms_killcolour(struct pms *dev, short colour)
428{
429 if (dev->decoder == PHILIPS2) {
430 pms_i2c_andor(dev, 0x8a, 0x08, 0x07, (colour & 0x1f) << 3);
431 pms_i2c_andor(dev, 0x8a, 0x09, 0x07, (colour & 0x1f) << 3);
432 } else if (dev->decoder == PHILIPS1) {
433 pms_i2c_andor(dev, 0x42, 0x08, 0x07, (colour & 0x1f) << 3);
434 pms_i2c_andor(dev, 0x42, 0x09, 0x07, (colour & 0x1f) << 3);
435 }
436}
437
438static void pms_chromagain(struct pms *dev, short chroma)
439{
440 if (dev->decoder == PHILIPS2)
441 pms_i2c_write(dev, 0x8a, 0x11, chroma);
442 else if (dev->decoder == PHILIPS1)
443 pms_i2c_write(dev, 0x42, 0x11, chroma);
444}
445
446
447static void pms_spacialcompl(struct pms *dev, short data)
448{
449 mvv_write(dev, 0x3b, data);
450}
451
452static void pms_spacialcomph(struct pms *dev, short data)
453{
454 mvv_write(dev, 0x3a, data);
455}
456
457static void pms_vstart(struct pms *dev, short start)
458{
459 mvv_write(dev, 0x16, start);
460 mvv_write(dev, 0x17, (start >> 8) & 0x01);
461}
462
463#endif
464
465static void pms_secamcross(struct pms *dev, short cross)
466{
467 if (dev->decoder == PHILIPS2)
468 pms_i2c_andor(dev, 0x8a, 0x0f, 0xdf, (cross & 1) << 5);
469 else if (dev->decoder == PHILIPS1)
470 pms_i2c_andor(dev, 0x42, 0x0f, 0xdf, (cross & 1) << 5);
471}
472
473
474static void pms_swsense(struct pms *dev, short sense)
475{
476 if (dev->decoder == PHILIPS2) {
477 pms_i2c_write(dev, 0x8a, 0x0a, sense);
478 pms_i2c_write(dev, 0x8a, 0x0b, sense);
479 } else if (dev->decoder == PHILIPS1) {
480 pms_i2c_write(dev, 0x42, 0x0a, sense);
481 pms_i2c_write(dev, 0x42, 0x0b, sense);
482 }
483}
484
485
486static void pms_framerate(struct pms *dev, short frr)
487{
488 int fps = (dev->std & V4L2_STD_525_60) ? 30 : 25;
489
490 if (frr == 0)
491 return;
492 fps = fps/frr;
493 mvv_write(dev, 0x14, 0x80 | fps);
494 mvv_write(dev, 0x15, 1);
495}
496
497static void pms_vert(struct pms *dev, u8 deciden, u8 decinum)
498{
499 mvv_write(dev, 0x1c, deciden); /* Denominator */
500 mvv_write(dev, 0x1d, decinum); /* Numerator */
501}
502
503/*
504 * Turn 16bit ratios into best small ratio the chipset can grok
505 */
506
507static void pms_vertdeci(struct pms *dev, unsigned short decinum, unsigned short deciden)
508{
509 /* Knock it down by / 5 once */
510 if (decinum % 5 == 0) {
511 deciden /= 5;
512 decinum /= 5;
513 }
514 /*
515 * 3's
516 */
517 while (decinum % 3 == 0 && deciden % 3 == 0) {
518 deciden /= 3;
519 decinum /= 3;
520 }
521 /*
522 * 2's
523 */
524 while (decinum % 2 == 0 && deciden % 2 == 0) {
525 decinum /= 2;
526 deciden /= 2;
527 }
528 /*
529 * Fudgyify
530 */
531 while (deciden > 32) {
532 deciden /= 2;
533 decinum = (decinum + 1) / 2;
534 }
535 if (deciden == 32)
536 deciden--;
537 pms_vert(dev, deciden, decinum);
538}
539
540static void pms_horzdeci(struct pms *dev, short decinum, short deciden)
541{
542 if (decinum <= 512) {
543 if (decinum % 5 == 0) {
544 decinum /= 5;
545 deciden /= 5;
546 }
547 } else {
548 decinum = 512;
549 deciden = 640; /* 768 would be ideal */
550 }
551
552 while (((decinum | deciden) & 1) == 0) {
553 decinum >>= 1;
554 deciden >>= 1;
555 }
556 while (deciden > 32) {
557 deciden >>= 1;
558 decinum = (decinum + 1) >> 1;
559 }
560 if (deciden == 32)
561 deciden--;
562
563 mvv_write(dev, 0x24, 0x80 | deciden);
564 mvv_write(dev, 0x25, decinum);
565}
566
567static void pms_resolution(struct pms *dev, short width, short height)
568{
569 int fg_height;
570
571 fg_height = height;
572 if (fg_height > 280)
573 fg_height = 280;
574
575 mvv_write(dev, 0x18, fg_height);
576 mvv_write(dev, 0x19, fg_height >> 8);
577
578 if (dev->std & V4L2_STD_525_60) {
579 mvv_write(dev, 0x1a, 0xfc);
580 mvv_write(dev, 0x1b, 0x00);
581 if (height > fg_height)
582 pms_vertdeci(dev, 240, 240);
583 else
584 pms_vertdeci(dev, fg_height, 240);
585 } else {
586 mvv_write(dev, 0x1a, 0x1a);
587 mvv_write(dev, 0x1b, 0x01);
588 if (fg_height > 256)
589 pms_vertdeci(dev, 270, 270);
590 else
591 pms_vertdeci(dev, fg_height, 270);
592 }
593 mvv_write(dev, 0x12, 0);
594 mvv_write(dev, 0x13, MVVMEMORYWIDTH);
595 mvv_write(dev, 0x42, 0x00);
596 mvv_write(dev, 0x43, 0x00);
597 mvv_write(dev, 0x44, MVVMEMORYWIDTH);
598
599 mvv_write(dev, 0x22, width + 8);
600 mvv_write(dev, 0x23, (width + 8) >> 8);
601
602 if (dev->std & V4L2_STD_525_60)
603 pms_horzdeci(dev, width, 640);
604 else
605 pms_horzdeci(dev, width + 8, 768);
606
607 mvv_write(dev, 0x30, mvv_read(dev, 0x30) & 0xfe);
608 mvv_write(dev, 0x08, mvv_read(dev, 0x08) | 0x01);
609 mvv_write(dev, 0x01, mvv_read(dev, 0x01) & 0xfd);
610 mvv_write(dev, 0x32, 0x00);
611 mvv_write(dev, 0x33, MVVMEMORYWIDTH);
612}
613
614
615/*
616 * Set Input
617 */
618
619static void pms_vcrinput(struct pms *dev, short input)
620{
621 if (dev->decoder == PHILIPS2)
622 pms_i2c_andor(dev, 0x8a, 0x0d, 0x7f, (input & 1) << 7);
623 else if (dev->decoder == PHILIPS1)
624 pms_i2c_andor(dev, 0x42, 0x0d, 0x7f, (input & 1) << 7);
625}
626
627
628static int pms_capture(struct pms *dev, char __user *buf, int rgb555, int count)
629{
630 int y;
631 int dw = 2 * dev->width;
632 char *tmp; /* using a temp buffer is faster than direct */
633 int cnt = 0;
634 int len = 0;
635 unsigned char r8 = 0x5; /* value for reg8 */
636
637 tmp = kmalloc(dw + 32, GFP_KERNEL);
638 if (!tmp)
639 return 0;
640
641 if (rgb555)
642 r8 |= 0x20; /* else use untranslated rgb = 565 */
643 mvv_write(dev, 0x08, r8); /* capture rgb555/565, init DRAM, PC enable */
644
645/* printf("%d %d %d %d %d %x %x\n",width,height,voff,nom,den,mvv_buf); */
646
647 for (y = 0; y < dev->height; y++) {
648 writeb(0, dev->mem); /* synchronisiert neue Zeile */
649
650 /*
651 * This is in truth a fifo, be very careful as if you
652 * forgot this odd things will occur 8)
653 */
654
655 memcpy_fromio(tmp, dev->mem, dw + 32); /* discard 16 word */
656 cnt -= dev->height;
657 while (cnt <= 0) {
658 /*
659 * Don't copy too far
660 */
661 int dt = dw;
662 if (dt + len > count)
663 dt = count - len;
664 cnt += dev->height;
665 if (copy_to_user(buf, tmp + 32, dt))
666 return len ? len : -EFAULT;
667 buf += dt;
668 len += dt;
669 }
670 }
671 kfree(tmp);
672 return len;
673}
674
675
676/*
677 * Video4linux interfacing
678 */
679
680static int pms_querycap(struct file *file, void *priv,
681 struct v4l2_capability *vcap)
682{
683 struct pms *dev = video_drvdata(file);
684
685 strlcpy(vcap->driver, dev->v4l2_dev.name, sizeof(vcap->driver));
686 strlcpy(vcap->card, "Mediavision PMS", sizeof(vcap->card));
687 snprintf(vcap->bus_info, sizeof(vcap->bus_info),
688 "ISA:%s", dev->v4l2_dev.name);
689 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
690 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
691 return 0;
692}
693
694static int pms_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
695{
696 static const char *inputs[4] = {
697 "Composite",
698 "S-Video",
699 "Composite (VCR)",
700 "S-Video (VCR)"
701 };
702
703 if (vin->index > 3)
704 return -EINVAL;
705 strlcpy(vin->name, inputs[vin->index], sizeof(vin->name));
706 vin->type = V4L2_INPUT_TYPE_CAMERA;
707 vin->audioset = 0;
708 vin->tuner = 0;
709 vin->std = V4L2_STD_ALL;
710 vin->status = 0;
711 return 0;
712}
713
714static int pms_g_input(struct file *file, void *fh, unsigned int *inp)
715{
716 struct pms *dev = video_drvdata(file);
717
718 *inp = dev->input;
719 return 0;
720}
721
722static int pms_s_input(struct file *file, void *fh, unsigned int inp)
723{
724 struct pms *dev = video_drvdata(file);
725
726 if (inp > 3)
727 return -EINVAL;
728
729 dev->input = inp;
730 pms_videosource(dev, inp & 1);
731 pms_vcrinput(dev, inp >> 1);
732 return 0;
733}
734
735static int pms_g_std(struct file *file, void *fh, v4l2_std_id *std)
736{
737 struct pms *dev = video_drvdata(file);
738
739 *std = dev->std;
740 return 0;
741}
742
743static int pms_s_std(struct file *file, void *fh, v4l2_std_id std)
744{
745 struct pms *dev = video_drvdata(file);
746 int ret = 0;
747
748 dev->std = std;
749 if (dev->std & V4L2_STD_NTSC) {
750 pms_framerate(dev, 30);
751 pms_secamcross(dev, 0);
752 pms_format(dev, 1);
753 } else if (dev->std & V4L2_STD_PAL) {
754 pms_framerate(dev, 25);
755 pms_secamcross(dev, 0);
756 pms_format(dev, 2);
757 } else if (dev->std & V4L2_STD_SECAM) {
758 pms_framerate(dev, 25);
759 pms_secamcross(dev, 1);
760 pms_format(dev, 2);
761 } else {
762 ret = -EINVAL;
763 }
764 /*
765 switch (v->mode) {
766 case VIDEO_MODE_AUTO:
767 pms_framerate(dev, 25);
768 pms_secamcross(dev, 0);
769 pms_format(dev, 0);
770 break;
771 }*/
772 return ret;
773}
774
775static int pms_s_ctrl(struct v4l2_ctrl *ctrl)
776{
777 struct pms *dev = container_of(ctrl->handler, struct pms, hdl);
778 int ret = 0;
779
780 switch (ctrl->id) {
781 case V4L2_CID_BRIGHTNESS:
782 pms_brightness(dev, ctrl->val);
783 break;
784 case V4L2_CID_CONTRAST:
785 pms_contrast(dev, ctrl->val);
786 break;
787 case V4L2_CID_SATURATION:
788 pms_saturation(dev, ctrl->val);
789 break;
790 case V4L2_CID_HUE:
791 pms_hue(dev, ctrl->val);
792 break;
793 default:
794 ret = -EINVAL;
795 break;
796 }
797 return ret;
798}
799
800static int pms_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
801{
802 struct pms *dev = video_drvdata(file);
803 struct v4l2_pix_format *pix = &fmt->fmt.pix;
804
805 pix->width = dev->width;
806 pix->height = dev->height;
807 pix->pixelformat = dev->width == 15 ?
808 V4L2_PIX_FMT_RGB555 : V4L2_PIX_FMT_RGB565;
809 pix->field = V4L2_FIELD_NONE;
810 pix->bytesperline = 2 * dev->width;
811 pix->sizeimage = 2 * dev->width * dev->height;
812 /* Just a guess */
813 pix->colorspace = V4L2_COLORSPACE_SRGB;
814 return 0;
815}
816
817static int pms_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
818{
819 struct v4l2_pix_format *pix = &fmt->fmt.pix;
820
821 if (pix->height < 16 || pix->height > 480)
822 return -EINVAL;
823 if (pix->width < 16 || pix->width > 640)
824 return -EINVAL;
825 if (pix->pixelformat != V4L2_PIX_FMT_RGB555 &&
826 pix->pixelformat != V4L2_PIX_FMT_RGB565)
827 return -EINVAL;
828 pix->field = V4L2_FIELD_NONE;
829 pix->bytesperline = 2 * pix->width;
830 pix->sizeimage = 2 * pix->width * pix->height;
831 /* Just a guess */
832 pix->colorspace = V4L2_COLORSPACE_SRGB;
833 return 0;
834}
835
836static int pms_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
837{
838 struct pms *dev = video_drvdata(file);
839 struct v4l2_pix_format *pix = &fmt->fmt.pix;
840 int ret = pms_try_fmt_vid_cap(file, fh, fmt);
841
842 if (ret)
843 return ret;
844 dev->width = pix->width;
845 dev->height = pix->height;
846 dev->depth = (pix->pixelformat == V4L2_PIX_FMT_RGB555) ? 15 : 16;
847 pms_resolution(dev, dev->width, dev->height);
848 /* Ok we figured out what to use from our wide choice */
849 return 0;
850}
851
852static int pms_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
853{
854 static struct v4l2_fmtdesc formats[] = {
855 { 0, 0, 0,
856 "RGB 5:5:5", V4L2_PIX_FMT_RGB555,
857 { 0, 0, 0, 0 }
858 },
859 { 1, 0, 0,
860 "RGB 5:6:5", V4L2_PIX_FMT_RGB565,
861 { 0, 0, 0, 0 }
862 },
863 };
864 enum v4l2_buf_type type = fmt->type;
865
866 if (fmt->index > 1)
867 return -EINVAL;
868
869 *fmt = formats[fmt->index];
870 fmt->type = type;
871 return 0;
872}
873
874static ssize_t pms_read(struct file *file, char __user *buf,
875 size_t count, loff_t *ppos)
876{
877 struct pms *dev = video_drvdata(file);
878 int len;
879
880 len = pms_capture(dev, buf, (dev->depth == 15), count);
881 return len;
882}
883
884static unsigned int pms_poll(struct file *file, struct poll_table_struct *wait)
885{
886 struct v4l2_fh *fh = file->private_data;
887 unsigned int res = POLLIN | POLLRDNORM;
888
889 if (v4l2_event_pending(fh))
890 res |= POLLPRI;
891 poll_wait(file, &fh->wait, wait);
892 return res;
893}
894
895static const struct v4l2_file_operations pms_fops = {
896 .owner = THIS_MODULE,
897 .open = v4l2_fh_open,
898 .release = v4l2_fh_release,
899 .poll = pms_poll,
900 .unlocked_ioctl = video_ioctl2,
901 .read = pms_read,
902};
903
904static const struct v4l2_ioctl_ops pms_ioctl_ops = {
905 .vidioc_querycap = pms_querycap,
906 .vidioc_g_input = pms_g_input,
907 .vidioc_s_input = pms_s_input,
908 .vidioc_enum_input = pms_enum_input,
909 .vidioc_g_std = pms_g_std,
910 .vidioc_s_std = pms_s_std,
911 .vidioc_enum_fmt_vid_cap = pms_enum_fmt_vid_cap,
912 .vidioc_g_fmt_vid_cap = pms_g_fmt_vid_cap,
913 .vidioc_s_fmt_vid_cap = pms_s_fmt_vid_cap,
914 .vidioc_try_fmt_vid_cap = pms_try_fmt_vid_cap,
915 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
916 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
917};
918
919/*
920 * Probe for and initialise the Mediavision PMS
921 */
922
923static int init_mediavision(struct pms *dev)
924{
925 int idec, decst;
926 int i;
927 static const unsigned char i2c_defs[] = {
928 0x4c, 0x30, 0x00, 0xe8,
929 0xb6, 0xe2, 0x00, 0x00,
930 0xff, 0xff, 0x00, 0x00,
931 0x00, 0x00, 0x78, 0x98,
932 0x00, 0x00, 0x00, 0x00,
933 0x34, 0x0a, 0xf4, 0xce,
934 0xe4
935 };
936
937 dev->mem = ioremap(mem_base, 0x800);
938 if (!dev->mem)
939 return -ENOMEM;
940
941 if (!request_region(0x9a01, 1, "Mediavision PMS config")) {
942 printk(KERN_WARNING "mediavision: unable to detect: 0x9a01 in use.\n");
943 iounmap(dev->mem);
944 return -EBUSY;
945 }
946 if (!request_region(dev->io, 3, "Mediavision PMS")) {
947 printk(KERN_WARNING "mediavision: I/O port %d in use.\n", dev->io);
948 release_region(0x9a01, 1);
949 iounmap(dev->mem);
950 return -EBUSY;
951 }
952 outb(0xb8, 0x9a01); /* Unlock */
953 outb(dev->io >> 4, 0x9a01); /* Set IO port */
954
955
956 decst = pms_i2c_stat(dev, 0x43);
957
958 if (decst != -1)
959 idec = 2;
960 else if (pms_i2c_stat(dev, 0xb9) != -1)
961 idec = 3;
962 else if (pms_i2c_stat(dev, 0x8b) != -1)
963 idec = 1;
964 else
965 idec = 0;
966
967 printk(KERN_INFO "PMS type is %d\n", idec);
968 if (idec == 0) {
969 release_region(dev->io, 3);
970 release_region(0x9a01, 1);
971 iounmap(dev->mem);
972 return -ENODEV;
973 }
974
975 /*
976 * Ok we have a PMS of some sort
977 */
978
979 mvv_write(dev, 0x04, mem_base >> 12); /* Set the memory area */
980
981 /* Ok now load the defaults */
982
983 for (i = 0; i < 0x19; i++) {
984 if (i2c_defs[i] == 0xff)
985 pms_i2c_andor(dev, 0x8a, i, 0x07, 0x00);
986 else
987 pms_i2c_write(dev, 0x8a, i, i2c_defs[i]);
988 }
989
990 pms_i2c_write(dev, 0xb8, 0x00, 0x12);
991 pms_i2c_write(dev, 0xb8, 0x04, 0x00);
992 pms_i2c_write(dev, 0xb8, 0x07, 0x00);
993 pms_i2c_write(dev, 0xb8, 0x08, 0x00);
994 pms_i2c_write(dev, 0xb8, 0x09, 0xff);
995 pms_i2c_write(dev, 0xb8, 0x0a, 0x00);
996 pms_i2c_write(dev, 0xb8, 0x0b, 0x10);
997 pms_i2c_write(dev, 0xb8, 0x10, 0x03);
998
999 mvv_write(dev, 0x01, 0x00);
1000 mvv_write(dev, 0x05, 0xa0);
1001 mvv_write(dev, 0x08, 0x25);
1002 mvv_write(dev, 0x09, 0x00);
1003 mvv_write(dev, 0x0a, 0x20 | MVVMEMORYWIDTH);
1004
1005 mvv_write(dev, 0x10, 0x02);
1006 mvv_write(dev, 0x1e, 0x0c);
1007 mvv_write(dev, 0x1f, 0x03);
1008 mvv_write(dev, 0x26, 0x06);
1009
1010 mvv_write(dev, 0x2b, 0x00);
1011 mvv_write(dev, 0x2c, 0x20);
1012 mvv_write(dev, 0x2d, 0x00);
1013 mvv_write(dev, 0x2f, 0x70);
1014 mvv_write(dev, 0x32, 0x00);
1015 mvv_write(dev, 0x33, MVVMEMORYWIDTH);
1016 mvv_write(dev, 0x34, 0x00);
1017 mvv_write(dev, 0x35, 0x00);
1018 mvv_write(dev, 0x3a, 0x80);
1019 mvv_write(dev, 0x3b, 0x10);
1020 mvv_write(dev, 0x20, 0x00);
1021 mvv_write(dev, 0x21, 0x00);
1022 mvv_write(dev, 0x30, 0x22);
1023 return 0;
1024}
1025
1026/*
1027 * Initialization and module stuff
1028 */
1029
1030#ifndef MODULE
1031static int enable;
1032module_param(enable, int, 0);
1033#endif
1034
1035static const struct v4l2_ctrl_ops pms_ctrl_ops = {
1036 .s_ctrl = pms_s_ctrl,
1037};
1038
1039static int pms_probe(struct device *pdev, unsigned int card)
1040{
1041 struct pms *dev;
1042 struct v4l2_device *v4l2_dev;
1043 struct v4l2_ctrl_handler *hdl;
1044 int res;
1045
1046#ifndef MODULE
1047 if (!enable) {
1048 pr_err("PMS: not enabled, use pms.enable=1 to probe\n");
1049 return -ENODEV;
1050 }
1051#endif
1052
1053 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
1054 if (dev == NULL)
1055 return -ENOMEM;
1056
1057 dev->decoder = PHILIPS2;
1058 dev->io = io_port;
1059 dev->data = io_port + 1;
1060 v4l2_dev = &dev->v4l2_dev;
1061 hdl = &dev->hdl;
1062
1063 res = v4l2_device_register(pdev, v4l2_dev);
1064 if (res < 0) {
1065 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
1066 goto free_dev;
1067 }
1068 v4l2_info(v4l2_dev, "Mediavision Pro Movie Studio driver 0.05\n");
1069
1070 res = init_mediavision(dev);
1071 if (res) {
1072 v4l2_err(v4l2_dev, "Board not found.\n");
1073 goto free_io;
1074 }
1075
1076 v4l2_ctrl_handler_init(hdl, 4);
1077 v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
1078 V4L2_CID_BRIGHTNESS, 0, 255, 1, 139);
1079 v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
1080 V4L2_CID_CONTRAST, 0, 255, 1, 70);
1081 v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
1082 V4L2_CID_SATURATION, 0, 255, 1, 64);
1083 v4l2_ctrl_new_std(hdl, &pms_ctrl_ops,
1084 V4L2_CID_HUE, 0, 255, 1, 0);
1085 if (hdl->error) {
1086 res = hdl->error;
1087 goto free_hdl;
1088 }
1089
1090 mutex_init(&dev->lock);
1091 strlcpy(dev->vdev.name, v4l2_dev->name, sizeof(dev->vdev.name));
1092 dev->vdev.v4l2_dev = v4l2_dev;
1093 dev->vdev.ctrl_handler = hdl;
1094 dev->vdev.fops = &pms_fops;
1095 dev->vdev.ioctl_ops = &pms_ioctl_ops;
1096 dev->vdev.release = video_device_release_empty;
1097 dev->vdev.lock = &dev->lock;
1098 dev->vdev.tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
1099 video_set_drvdata(&dev->vdev, dev);
1100 dev->std = V4L2_STD_NTSC_M;
1101 dev->height = 240;
1102 dev->width = 320;
1103 dev->depth = 16;
1104 pms_swsense(dev, 75);
1105 pms_resolution(dev, 320, 240);
1106 pms_videosource(dev, 0);
1107 pms_vcrinput(dev, 0);
1108 v4l2_ctrl_handler_setup(hdl);
1109 res = video_register_device(&dev->vdev, VFL_TYPE_GRABBER, video_nr);
1110 if (res >= 0)
1111 return 0;
1112
1113free_hdl:
1114 v4l2_ctrl_handler_free(hdl);
1115 v4l2_device_unregister(&dev->v4l2_dev);
1116free_io:
1117 release_region(dev->io, 3);
1118 release_region(0x9a01, 1);
1119 iounmap(dev->mem);
1120free_dev:
1121 kfree(dev);
1122 return res;
1123}
1124
1125static int pms_remove(struct device *pdev, unsigned int card)
1126{
1127 struct pms *dev = dev_get_drvdata(pdev);
1128
1129 video_unregister_device(&dev->vdev);
1130 v4l2_ctrl_handler_free(&dev->hdl);
1131 release_region(dev->io, 3);
1132 release_region(0x9a01, 1);
1133 iounmap(dev->mem);
1134 return 0;
1135}
1136
1137static struct isa_driver pms_driver = {
1138 .probe = pms_probe,
1139 .remove = pms_remove,
1140 .driver = {
1141 .name = "pms",
1142 },
1143};
1144
1145static int __init pms_init(void)
1146{
1147 return isa_register_driver(&pms_driver, 1);
1148}
1149
1150static void __exit pms_exit(void)
1151{
1152 isa_unregister_driver(&pms_driver);
1153}
1154
1155module_init(pms_init);
1156module_exit(pms_exit);
diff --git a/drivers/staging/media/parport/w9966.c b/drivers/staging/media/parport/w9966.c
deleted file mode 100644
index f7502f3a6a3c..000000000000
--- a/drivers/staging/media/parport/w9966.c
+++ /dev/null
@@ -1,980 +0,0 @@
1/*
2 Winbond w9966cf Webcam parport driver.
3
4 Version 0.33
5
6 Copyright (C) 2001 Jakob Kemi <jakob.kemi@post.utfors.se>
7
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21*/
22/*
23 Supported devices:
24 *Lifeview FlyCam Supra (using the Philips saa7111a chip)
25
26 Does any other model using the w9966 interface chip exist ?
27
28 Todo:
29
30 *Add a working EPP mode, since DMA ECP read isn't implemented
31 in the parport drivers. (That's why it's so sloow)
32
33 *Add support for other ccd-control chips than the saa7111
34 please send me feedback on what kind of chips you have.
35
36 *Add proper probing. I don't know what's wrong with the IEEE1284
37 parport drivers but (IEEE1284_MODE_NIBBLE|IEEE1284_DEVICE_ID)
38 and nibble read seems to be broken for some peripherals.
39
40 *Add probing for onboard SRAM, port directions etc. (if possible)
41
42 *Add support for the hardware compressed modes (maybe using v4l2)
43
44 *Fix better support for the capture window (no skewed images, v4l
45 interface to capt. window)
46
47 *Probably some bugs that I don't know of
48
49 Please support me by sending feedback!
50
51 Changes:
52
53 Alan Cox: Removed RGB mode for kernel merge, added THIS_MODULE
54 and owner support for newer module locks
55*/
56
57#include <linux/module.h>
58#include <linux/init.h>
59#include <linux/delay.h>
60#include <linux/videodev2.h>
61#include <linux/slab.h>
62#include <media/v4l2-common.h>
63#include <media/v4l2-ioctl.h>
64#include <media/v4l2-device.h>
65#include <media/v4l2-fh.h>
66#include <media/v4l2-ctrls.h>
67#include <media/v4l2-event.h>
68#include <linux/parport.h>
69
70/*#define DEBUG*/ /* Undef me for production */
71
72#ifdef DEBUG
73#define DPRINTF(x, a...) printk(KERN_DEBUG "W9966: %s(): "x, __func__ , ##a)
74#else
75#define DPRINTF(x...)
76#endif
77
78/*
79 * Defines, simple typedefs etc.
80 */
81
82#define W9966_DRIVERNAME "W9966CF Webcam"
83#define W9966_MAXCAMS 4 /* Maximum number of cameras */
84#define W9966_RBUFFER 2048 /* Read buffer (must be an even number) */
85#define W9966_SRAMSIZE 131072 /* 128kb */
86#define W9966_SRAMID 0x02 /* check w9966cf.pdf */
87
88/* Empirically determined window limits */
89#define W9966_WND_MIN_X 16
90#define W9966_WND_MIN_Y 14
91#define W9966_WND_MAX_X 705
92#define W9966_WND_MAX_Y 253
93#define W9966_WND_MAX_W (W9966_WND_MAX_X - W9966_WND_MIN_X)
94#define W9966_WND_MAX_H (W9966_WND_MAX_Y - W9966_WND_MIN_Y)
95
96/* Keep track of our current state */
97#define W9966_STATE_PDEV 0x01
98#define W9966_STATE_CLAIMED 0x02
99#define W9966_STATE_VDEV 0x04
100
101#define W9966_I2C_W_ID 0x48
102#define W9966_I2C_R_ID 0x49
103#define W9966_I2C_R_DATA 0x08
104#define W9966_I2C_R_CLOCK 0x04
105#define W9966_I2C_W_DATA 0x02
106#define W9966_I2C_W_CLOCK 0x01
107
108struct w9966 {
109 struct v4l2_device v4l2_dev;
110 struct v4l2_ctrl_handler hdl;
111 unsigned char dev_state;
112 unsigned char i2c_state;
113 unsigned short ppmode;
114 struct parport *pport;
115 struct pardevice *pdev;
116 struct video_device vdev;
117 unsigned short width;
118 unsigned short height;
119 unsigned char brightness;
120 signed char contrast;
121 signed char color;
122 signed char hue;
123 struct mutex lock;
124};
125
126/*
127 * Module specific properties
128 */
129
130MODULE_AUTHOR("Jakob Kemi <jakob.kemi@post.utfors.se>");
131MODULE_DESCRIPTION("Winbond w9966cf WebCam driver (0.32)");
132MODULE_LICENSE("GPL");
133MODULE_VERSION("0.33.1");
134
135#ifdef MODULE
136static char *pardev[] = {[0 ... W9966_MAXCAMS] = ""};
137#else
138static char *pardev[] = {[0 ... W9966_MAXCAMS] = "aggressive"};
139#endif
140module_param_array(pardev, charp, NULL, 0);
141MODULE_PARM_DESC(pardev, "pardev: where to search for\n"
142 "\teach camera. 'aggressive' means brute-force search.\n"
143 "\tEg: >pardev=parport3,aggressive,parport2,parport1< would assign\n"
144 "\tcam 1 to parport3 and search every parport for cam 2 etc...");
145
146static int parmode;
147module_param(parmode, int, 0);
148MODULE_PARM_DESC(parmode, "parmode: transfer mode (0=auto, 1=ecp, 2=epp");
149
150static int video_nr = -1;
151module_param(video_nr, int, 0);
152
153static struct w9966 w9966_cams[W9966_MAXCAMS];
154
155/*
156 * Private function defines
157 */
158
159
160/* Set camera phase flags, so we know what to uninit when terminating */
161static inline void w9966_set_state(struct w9966 *cam, int mask, int val)
162{
163 cam->dev_state = (cam->dev_state & ~mask) ^ val;
164}
165
166/* Get camera phase flags */
167static inline int w9966_get_state(struct w9966 *cam, int mask, int val)
168{
169 return ((cam->dev_state & mask) == val);
170}
171
172/* Claim parport for ourself */
173static void w9966_pdev_claim(struct w9966 *cam)
174{
175 if (w9966_get_state(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED))
176 return;
177 parport_claim_or_block(cam->pdev);
178 w9966_set_state(cam, W9966_STATE_CLAIMED, W9966_STATE_CLAIMED);
179}
180
181/* Release parport for others to use */
182static void w9966_pdev_release(struct w9966 *cam)
183{
184 if (w9966_get_state(cam, W9966_STATE_CLAIMED, 0))
185 return;
186 parport_release(cam->pdev);
187 w9966_set_state(cam, W9966_STATE_CLAIMED, 0);
188}
189
190/* Read register from W9966 interface-chip
191 Expects a claimed pdev
192 -1 on error, else register data (byte) */
193static int w9966_read_reg(struct w9966 *cam, int reg)
194{
195 /* ECP, read, regtransfer, REG, REG, REG, REG, REG */
196 const unsigned char addr = 0x80 | (reg & 0x1f);
197 unsigned char val;
198
199 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0)
200 return -1;
201 if (parport_write(cam->pport, &addr, 1) != 1)
202 return -1;
203 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_DATA) != 0)
204 return -1;
205 if (parport_read(cam->pport, &val, 1) != 1)
206 return -1;
207
208 return val;
209}
210
211/* Write register to W9966 interface-chip
212 Expects a claimed pdev
213 -1 on error */
214static int w9966_write_reg(struct w9966 *cam, int reg, int data)
215{
216 /* ECP, write, regtransfer, REG, REG, REG, REG, REG */
217 const unsigned char addr = 0xc0 | (reg & 0x1f);
218 const unsigned char val = data;
219
220 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_ADDR) != 0)
221 return -1;
222 if (parport_write(cam->pport, &addr, 1) != 1)
223 return -1;
224 if (parport_negotiate(cam->pport, cam->ppmode | IEEE1284_DATA) != 0)
225 return -1;
226 if (parport_write(cam->pport, &val, 1) != 1)
227 return -1;
228
229 return 0;
230}
231
232/*
233 * Ugly and primitive i2c protocol functions
234 */
235
236/* Sets the data line on the i2c bus.
237 Expects a claimed pdev. */
238static void w9966_i2c_setsda(struct w9966 *cam, int state)
239{
240 if (state)
241 cam->i2c_state |= W9966_I2C_W_DATA;
242 else
243 cam->i2c_state &= ~W9966_I2C_W_DATA;
244
245 w9966_write_reg(cam, 0x18, cam->i2c_state);
246 udelay(5);
247}
248
249/* Get peripheral clock line
250 Expects a claimed pdev. */
251static int w9966_i2c_getscl(struct w9966 *cam)
252{
253 const unsigned char state = w9966_read_reg(cam, 0x18);
254 return ((state & W9966_I2C_R_CLOCK) > 0);
255}
256
257/* Sets the clock line on the i2c bus.
258 Expects a claimed pdev. -1 on error */
259static int w9966_i2c_setscl(struct w9966 *cam, int state)
260{
261 unsigned long timeout;
262
263 if (state)
264 cam->i2c_state |= W9966_I2C_W_CLOCK;
265 else
266 cam->i2c_state &= ~W9966_I2C_W_CLOCK;
267
268 w9966_write_reg(cam, 0x18, cam->i2c_state);
269 udelay(5);
270
271 /* we go to high, we also expect the peripheral to ack. */
272 if (state) {
273 timeout = jiffies + 100;
274 while (!w9966_i2c_getscl(cam)) {
275 if (time_after(jiffies, timeout))
276 return -1;
277 }
278 }
279 return 0;
280}
281
282#if 0
283/* Get peripheral data line
284 Expects a claimed pdev. */
285static int w9966_i2c_getsda(struct w9966 *cam)
286{
287 const unsigned char state = w9966_read_reg(cam, 0x18);
288 return ((state & W9966_I2C_R_DATA) > 0);
289}
290#endif
291
292/* Write a byte with ack to the i2c bus.
293 Expects a claimed pdev. -1 on error */
294static int w9966_i2c_wbyte(struct w9966 *cam, int data)
295{
296 int i;
297
298 for (i = 7; i >= 0; i--) {
299 w9966_i2c_setsda(cam, (data >> i) & 0x01);
300
301 if (w9966_i2c_setscl(cam, 1) == -1)
302 return -1;
303 w9966_i2c_setscl(cam, 0);
304 }
305
306 w9966_i2c_setsda(cam, 1);
307
308 if (w9966_i2c_setscl(cam, 1) == -1)
309 return -1;
310 w9966_i2c_setscl(cam, 0);
311
312 return 0;
313}
314
315/* Read a data byte with ack from the i2c-bus
316 Expects a claimed pdev. -1 on error */
317#if 0
318static int w9966_i2c_rbyte(struct w9966 *cam)
319{
320 unsigned char data = 0x00;
321 int i;
322
323 w9966_i2c_setsda(cam, 1);
324
325 for (i = 0; i < 8; i++) {
326 if (w9966_i2c_setscl(cam, 1) == -1)
327 return -1;
328 data = data << 1;
329 if (w9966_i2c_getsda(cam))
330 data |= 0x01;
331
332 w9966_i2c_setscl(cam, 0);
333 }
334 return data;
335}
336#endif
337
338/* Read a register from the i2c device.
339 Expects claimed pdev. -1 on error */
340#if 0
341static int w9966_read_reg_i2c(struct w9966 *cam, int reg)
342{
343 int data;
344
345 w9966_i2c_setsda(cam, 0);
346 w9966_i2c_setscl(cam, 0);
347
348 if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
349 w9966_i2c_wbyte(cam, reg) == -1)
350 return -1;
351
352 w9966_i2c_setsda(cam, 1);
353 if (w9966_i2c_setscl(cam, 1) == -1)
354 return -1;
355 w9966_i2c_setsda(cam, 0);
356 w9966_i2c_setscl(cam, 0);
357
358 if (w9966_i2c_wbyte(cam, W9966_I2C_R_ID) == -1)
359 return -1;
360 data = w9966_i2c_rbyte(cam);
361 if (data == -1)
362 return -1;
363
364 w9966_i2c_setsda(cam, 0);
365
366 if (w9966_i2c_setscl(cam, 1) == -1)
367 return -1;
368 w9966_i2c_setsda(cam, 1);
369
370 return data;
371}
372#endif
373
374/* Write a register to the i2c device.
375 Expects claimed pdev. -1 on error */
376static int w9966_write_reg_i2c(struct w9966 *cam, int reg, int data)
377{
378 w9966_i2c_setsda(cam, 0);
379 w9966_i2c_setscl(cam, 0);
380
381 if (w9966_i2c_wbyte(cam, W9966_I2C_W_ID) == -1 ||
382 w9966_i2c_wbyte(cam, reg) == -1 ||
383 w9966_i2c_wbyte(cam, data) == -1)
384 return -1;
385
386 w9966_i2c_setsda(cam, 0);
387 if (w9966_i2c_setscl(cam, 1) == -1)
388 return -1;
389
390 w9966_i2c_setsda(cam, 1);
391
392 return 0;
393}
394
395/* Find a good length for capture window (used both for W and H)
396 A bit ugly but pretty functional. The capture length
397 have to match the downscale */
398static int w9966_findlen(int near, int size, int maxlen)
399{
400 int bestlen = size;
401 int besterr = abs(near - bestlen);
402 int len;
403
404 for (len = size + 1; len < maxlen; len++) {
405 int err;
406 if (((64 * size) % len) != 0)
407 continue;
408
409 err = abs(near - len);
410
411 /* Only continue as long as we keep getting better values */
412 if (err > besterr)
413 break;
414
415 besterr = err;
416 bestlen = len;
417 }
418
419 return bestlen;
420}
421
422/* Modify capture window (if necessary)
423 and calculate downscaling
424 Return -1 on error */
425static int w9966_calcscale(int size, int min, int max, int *beg, int *end, unsigned char *factor)
426{
427 int maxlen = max - min;
428 int len = *end - *beg + 1;
429 int newlen = w9966_findlen(len, size, maxlen);
430 int err = newlen - len;
431
432 /* Check for bad format */
433 if (newlen > maxlen || newlen < size)
434 return -1;
435
436 /* Set factor (6 bit fixed) */
437 *factor = (64 * size) / newlen;
438 if (*factor == 64)
439 *factor = 0x00; /* downscale is disabled */
440 else
441 *factor |= 0x80; /* set downscale-enable bit */
442
443 /* Modify old beginning and end */
444 *beg -= err / 2;
445 *end += err - (err / 2);
446
447 /* Move window if outside borders */
448 if (*beg < min) {
449 *end += min - *beg;
450 *beg += min - *beg;
451 }
452 if (*end > max) {
453 *beg -= *end - max;
454 *end -= *end - max;
455 }
456
457 return 0;
458}
459
460/* Setup the cameras capture window etc.
461 Expects a claimed pdev
462 return -1 on error */
463static int w9966_setup(struct w9966 *cam, int x1, int y1, int x2, int y2, int w, int h)
464{
465 unsigned int i;
466 unsigned int enh_s, enh_e;
467 unsigned char scale_x, scale_y;
468 unsigned char regs[0x1c];
469 unsigned char saa7111_regs[] = {
470 0x21, 0x00, 0xd8, 0x23, 0x00, 0x80, 0x80, 0x00,
471 0x88, 0x10, 0x80, 0x40, 0x40, 0x00, 0x01, 0x00,
472 0x48, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
473 0x00, 0x00, 0x00, 0x71, 0xe7, 0x00, 0x00, 0xc0
474 };
475
476
477 if (w * h * 2 > W9966_SRAMSIZE) {
478 DPRINTF("capture window exceeds SRAM size!.\n");
479 w = 200; h = 160; /* Pick default values */
480 }
481
482 w &= ~0x1;
483 if (w < 2)
484 w = 2;
485 if (h < 1)
486 h = 1;
487 if (w > W9966_WND_MAX_W)
488 w = W9966_WND_MAX_W;
489 if (h > W9966_WND_MAX_H)
490 h = W9966_WND_MAX_H;
491
492 cam->width = w;
493 cam->height = h;
494
495 enh_s = 0;
496 enh_e = w * h * 2;
497
498 /* Modify capture window if necessary and calculate downscaling */
499 if (w9966_calcscale(w, W9966_WND_MIN_X, W9966_WND_MAX_X, &x1, &x2, &scale_x) != 0 ||
500 w9966_calcscale(h, W9966_WND_MIN_Y, W9966_WND_MAX_Y, &y1, &y2, &scale_y) != 0)
501 return -1;
502
503 DPRINTF("%dx%d, x: %d<->%d, y: %d<->%d, sx: %d/64, sy: %d/64.\n",
504 w, h, x1, x2, y1, y2, scale_x & ~0x80, scale_y & ~0x80);
505
506 /* Setup registers */
507 regs[0x00] = 0x00; /* Set normal operation */
508 regs[0x01] = 0x18; /* Capture mode */
509 regs[0x02] = scale_y; /* V-scaling */
510 regs[0x03] = scale_x; /* H-scaling */
511
512 /* Capture window */
513 regs[0x04] = (x1 & 0x0ff); /* X-start (8 low bits) */
514 regs[0x05] = (x1 & 0x300)>>8; /* X-start (2 high bits) */
515 regs[0x06] = (y1 & 0x0ff); /* Y-start (8 low bits) */
516 regs[0x07] = (y1 & 0x300)>>8; /* Y-start (2 high bits) */
517 regs[0x08] = (x2 & 0x0ff); /* X-end (8 low bits) */
518 regs[0x09] = (x2 & 0x300)>>8; /* X-end (2 high bits) */
519 regs[0x0a] = (y2 & 0x0ff); /* Y-end (8 low bits) */
520
521 regs[0x0c] = W9966_SRAMID; /* SRAM-banks (1x 128kb) */
522
523 /* Enhancement layer */
524 regs[0x0d] = (enh_s & 0x000ff); /* Enh. start (0-7) */
525 regs[0x0e] = (enh_s & 0x0ff00) >> 8; /* Enh. start (8-15) */
526 regs[0x0f] = (enh_s & 0x70000) >> 16; /* Enh. start (16-17/18??) */
527 regs[0x10] = (enh_e & 0x000ff); /* Enh. end (0-7) */
528 regs[0x11] = (enh_e & 0x0ff00) >> 8; /* Enh. end (8-15) */
529 regs[0x12] = (enh_e & 0x70000) >> 16; /* Enh. end (16-17/18??) */
530
531 /* Misc */
532 regs[0x13] = 0x40; /* VEE control (raw 4:2:2) */
533 regs[0x17] = 0x00; /* ??? */
534 regs[0x18] = cam->i2c_state = 0x00; /* Serial bus */
535 regs[0x19] = 0xff; /* I/O port direction control */
536 regs[0x1a] = 0xff; /* I/O port data register */
537 regs[0x1b] = 0x10; /* ??? */
538
539 /* SAA7111 chip settings */
540 saa7111_regs[0x0a] = cam->brightness;
541 saa7111_regs[0x0b] = cam->contrast;
542 saa7111_regs[0x0c] = cam->color;
543 saa7111_regs[0x0d] = cam->hue;
544
545 /* Reset (ECP-fifo & serial-bus) */
546 if (w9966_write_reg(cam, 0x00, 0x03) == -1)
547 return -1;
548
549 /* Write regs to w9966cf chip */
550 for (i = 0; i < 0x1c; i++)
551 if (w9966_write_reg(cam, i, regs[i]) == -1)
552 return -1;
553
554 /* Write regs to saa7111 chip */
555 for (i = 0; i < 0x20; i++)
556 if (w9966_write_reg_i2c(cam, i, saa7111_regs[i]) == -1)
557 return -1;
558
559 return 0;
560}
561
562/*
563 * Video4linux interfacing
564 */
565
566static int cam_querycap(struct file *file, void *priv,
567 struct v4l2_capability *vcap)
568{
569 struct w9966 *cam = video_drvdata(file);
570
571 strlcpy(vcap->driver, cam->v4l2_dev.name, sizeof(vcap->driver));
572 strlcpy(vcap->card, W9966_DRIVERNAME, sizeof(vcap->card));
573 strlcpy(vcap->bus_info, "parport", sizeof(vcap->bus_info));
574 vcap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_READWRITE;
575 vcap->capabilities = vcap->device_caps | V4L2_CAP_DEVICE_CAPS;
576 return 0;
577}
578
579static int cam_enum_input(struct file *file, void *fh, struct v4l2_input *vin)
580{
581 if (vin->index > 0)
582 return -EINVAL;
583 strlcpy(vin->name, "Camera", sizeof(vin->name));
584 vin->type = V4L2_INPUT_TYPE_CAMERA;
585 vin->audioset = 0;
586 vin->tuner = 0;
587 vin->std = 0;
588 vin->status = 0;
589 return 0;
590}
591
592static int cam_g_input(struct file *file, void *fh, unsigned int *inp)
593{
594 *inp = 0;
595 return 0;
596}
597
598static int cam_s_input(struct file *file, void *fh, unsigned int inp)
599{
600 return (inp > 0) ? -EINVAL : 0;
601}
602
603static int cam_s_ctrl(struct v4l2_ctrl *ctrl)
604{
605 struct w9966 *cam =
606 container_of(ctrl->handler, struct w9966, hdl);
607 int ret = 0;
608
609 mutex_lock(&cam->lock);
610 switch (ctrl->id) {
611 case V4L2_CID_BRIGHTNESS:
612 cam->brightness = ctrl->val;
613 break;
614 case V4L2_CID_CONTRAST:
615 cam->contrast = ctrl->val;
616 break;
617 case V4L2_CID_SATURATION:
618 cam->color = ctrl->val;
619 break;
620 case V4L2_CID_HUE:
621 cam->hue = ctrl->val;
622 break;
623 default:
624 ret = -EINVAL;
625 break;
626 }
627
628 if (ret == 0) {
629 w9966_pdev_claim(cam);
630
631 if (w9966_write_reg_i2c(cam, 0x0a, cam->brightness) == -1 ||
632 w9966_write_reg_i2c(cam, 0x0b, cam->contrast) == -1 ||
633 w9966_write_reg_i2c(cam, 0x0c, cam->color) == -1 ||
634 w9966_write_reg_i2c(cam, 0x0d, cam->hue) == -1) {
635 ret = -EIO;
636 }
637
638 w9966_pdev_release(cam);
639 }
640 mutex_unlock(&cam->lock);
641 return ret;
642}
643
644static int cam_g_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
645{
646 struct w9966 *cam = video_drvdata(file);
647 struct v4l2_pix_format *pix = &fmt->fmt.pix;
648
649 pix->width = cam->width;
650 pix->height = cam->height;
651 pix->pixelformat = V4L2_PIX_FMT_YUYV;
652 pix->field = V4L2_FIELD_NONE;
653 pix->bytesperline = 2 * cam->width;
654 pix->sizeimage = 2 * cam->width * cam->height;
655 /* Just a guess */
656 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
657 return 0;
658}
659
660static int cam_try_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
661{
662 struct v4l2_pix_format *pix = &fmt->fmt.pix;
663
664 if (pix->width < 2)
665 pix->width = 2;
666 if (pix->height < 1)
667 pix->height = 1;
668 if (pix->width > W9966_WND_MAX_W)
669 pix->width = W9966_WND_MAX_W;
670 if (pix->height > W9966_WND_MAX_H)
671 pix->height = W9966_WND_MAX_H;
672 pix->pixelformat = V4L2_PIX_FMT_YUYV;
673 pix->field = V4L2_FIELD_NONE;
674 pix->bytesperline = 2 * pix->width;
675 pix->sizeimage = 2 * pix->width * pix->height;
676 /* Just a guess */
677 pix->colorspace = V4L2_COLORSPACE_SMPTE170M;
678 return 0;
679}
680
681static int cam_s_fmt_vid_cap(struct file *file, void *fh, struct v4l2_format *fmt)
682{
683 struct w9966 *cam = video_drvdata(file);
684 struct v4l2_pix_format *pix = &fmt->fmt.pix;
685 int ret = cam_try_fmt_vid_cap(file, fh, fmt);
686
687 if (ret)
688 return ret;
689
690 mutex_lock(&cam->lock);
691 /* Update camera regs */
692 w9966_pdev_claim(cam);
693 ret = w9966_setup(cam, 0, 0, 1023, 1023, pix->width, pix->height);
694 w9966_pdev_release(cam);
695 mutex_unlock(&cam->lock);
696 return ret;
697}
698
699static int cam_enum_fmt_vid_cap(struct file *file, void *fh, struct v4l2_fmtdesc *fmt)
700{
701 static struct v4l2_fmtdesc formats[] = {
702 { 0, 0, 0,
703 "YUV 4:2:2", V4L2_PIX_FMT_YUYV,
704 { 0, 0, 0, 0 }
705 },
706 };
707 enum v4l2_buf_type type = fmt->type;
708
709 if (fmt->index > 0)
710 return -EINVAL;
711
712 *fmt = formats[fmt->index];
713 fmt->type = type;
714 return 0;
715}
716
717/* Capture data */
718static ssize_t w9966_v4l_read(struct file *file, char __user *buf,
719 size_t count, loff_t *ppos)
720{
721 struct w9966 *cam = video_drvdata(file);
722 unsigned char addr = 0xa0; /* ECP, read, CCD-transfer, 00000 */
723 unsigned char __user *dest = (unsigned char __user *)buf;
724 unsigned long dleft = count;
725 unsigned char *tbuf;
726
727 /* Why would anyone want more than this?? */
728 if (count > cam->width * cam->height * 2)
729 return -EINVAL;
730
731 mutex_lock(&cam->lock);
732 w9966_pdev_claim(cam);
733 w9966_write_reg(cam, 0x00, 0x02); /* Reset ECP-FIFO buffer */
734 w9966_write_reg(cam, 0x00, 0x00); /* Return to normal operation */
735 w9966_write_reg(cam, 0x01, 0x98); /* Enable capture */
736
737 /* write special capture-addr and negotiate into data transfer */
738 if ((parport_negotiate(cam->pport, cam->ppmode|IEEE1284_ADDR) != 0) ||
739 (parport_write(cam->pport, &addr, 1) != 1) ||
740 (parport_negotiate(cam->pport, cam->ppmode|IEEE1284_DATA) != 0)) {
741 w9966_pdev_release(cam);
742 mutex_unlock(&cam->lock);
743 return -EFAULT;
744 }
745
746 tbuf = kmalloc(W9966_RBUFFER, GFP_KERNEL);
747 if (tbuf == NULL) {
748 count = -ENOMEM;
749 goto out;
750 }
751
752 while (dleft > 0) {
753 unsigned long tsize = (dleft > W9966_RBUFFER) ? W9966_RBUFFER : dleft;
754
755 if (parport_read(cam->pport, tbuf, tsize) < tsize) {
756 count = -EFAULT;
757 goto out;
758 }
759 if (copy_to_user(dest, tbuf, tsize) != 0) {
760 count = -EFAULT;
761 goto out;
762 }
763 dest += tsize;
764 dleft -= tsize;
765 }
766
767 w9966_write_reg(cam, 0x01, 0x18); /* Disable capture */
768
769out:
770 kfree(tbuf);
771 w9966_pdev_release(cam);
772 mutex_unlock(&cam->lock);
773
774 return count;
775}
776
777static const struct v4l2_file_operations w9966_fops = {
778 .owner = THIS_MODULE,
779 .open = v4l2_fh_open,
780 .release = v4l2_fh_release,
781 .poll = v4l2_ctrl_poll,
782 .unlocked_ioctl = video_ioctl2,
783 .read = w9966_v4l_read,
784};
785
786static const struct v4l2_ioctl_ops w9966_ioctl_ops = {
787 .vidioc_querycap = cam_querycap,
788 .vidioc_g_input = cam_g_input,
789 .vidioc_s_input = cam_s_input,
790 .vidioc_enum_input = cam_enum_input,
791 .vidioc_enum_fmt_vid_cap = cam_enum_fmt_vid_cap,
792 .vidioc_g_fmt_vid_cap = cam_g_fmt_vid_cap,
793 .vidioc_s_fmt_vid_cap = cam_s_fmt_vid_cap,
794 .vidioc_try_fmt_vid_cap = cam_try_fmt_vid_cap,
795 .vidioc_log_status = v4l2_ctrl_log_status,
796 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
797 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
798};
799
800static const struct v4l2_ctrl_ops cam_ctrl_ops = {
801 .s_ctrl = cam_s_ctrl,
802};
803
804
805/* Initialize camera device. Setup all internal flags, set a
806 default video mode, setup ccd-chip, register v4l device etc..
807 Also used for 'probing' of hardware.
808 -1 on error */
809static int w9966_init(struct w9966 *cam, struct parport *port)
810{
811 struct v4l2_device *v4l2_dev = &cam->v4l2_dev;
812
813 if (cam->dev_state != 0)
814 return -1;
815
816 strlcpy(v4l2_dev->name, "w9966", sizeof(v4l2_dev->name));
817
818 if (v4l2_device_register(NULL, v4l2_dev) < 0) {
819 v4l2_err(v4l2_dev, "Could not register v4l2_device\n");
820 return -1;
821 }
822
823 v4l2_ctrl_handler_init(&cam->hdl, 4);
824 v4l2_ctrl_new_std(&cam->hdl, &cam_ctrl_ops,
825 V4L2_CID_BRIGHTNESS, 0, 255, 1, 128);
826 v4l2_ctrl_new_std(&cam->hdl, &cam_ctrl_ops,
827 V4L2_CID_CONTRAST, -64, 64, 1, 64);
828 v4l2_ctrl_new_std(&cam->hdl, &cam_ctrl_ops,
829 V4L2_CID_SATURATION, -64, 64, 1, 64);
830 v4l2_ctrl_new_std(&cam->hdl, &cam_ctrl_ops,
831 V4L2_CID_HUE, -128, 127, 1, 0);
832 if (cam->hdl.error) {
833 v4l2_err(v4l2_dev, "couldn't register controls\n");
834 return -1;
835 }
836 cam->pport = port;
837 cam->brightness = 128;
838 cam->contrast = 64;
839 cam->color = 64;
840 cam->hue = 0;
841
842 /* Select requested transfer mode */
843 switch (parmode) {
844 default: /* Auto-detect (priority: hw-ecp, hw-epp, sw-ecp) */
845 case 0:
846 if (port->modes & PARPORT_MODE_ECP)
847 cam->ppmode = IEEE1284_MODE_ECP;
848 else if (port->modes & PARPORT_MODE_EPP)
849 cam->ppmode = IEEE1284_MODE_EPP;
850 else
851 cam->ppmode = IEEE1284_MODE_ECP;
852 break;
853 case 1: /* hw- or sw-ecp */
854 cam->ppmode = IEEE1284_MODE_ECP;
855 break;
856 case 2: /* hw- or sw-epp */
857 cam->ppmode = IEEE1284_MODE_EPP;
858 break;
859 }
860
861 /* Tell the parport driver that we exists */
862 cam->pdev = parport_register_device(port, "w9966", NULL, NULL, NULL, 0, NULL);
863 if (cam->pdev == NULL) {
864 DPRINTF("parport_register_device() failed\n");
865 return -1;
866 }
867 w9966_set_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV);
868
869 w9966_pdev_claim(cam);
870
871 /* Setup a default capture mode */
872 if (w9966_setup(cam, 0, 0, 1023, 1023, 200, 160) != 0) {
873 DPRINTF("w9966_setup() failed.\n");
874 return -1;
875 }
876
877 w9966_pdev_release(cam);
878
879 /* Fill in the video_device struct and register us to v4l */
880 strlcpy(cam->vdev.name, W9966_DRIVERNAME, sizeof(cam->vdev.name));
881 cam->vdev.v4l2_dev = v4l2_dev;
882 cam->vdev.fops = &w9966_fops;
883 cam->vdev.ioctl_ops = &w9966_ioctl_ops;
884 cam->vdev.release = video_device_release_empty;
885 cam->vdev.ctrl_handler = &cam->hdl;
886 video_set_drvdata(&cam->vdev, cam);
887
888 mutex_init(&cam->lock);
889
890 if (video_register_device(&cam->vdev, VFL_TYPE_GRABBER, video_nr) < 0)
891 return -1;
892
893 w9966_set_state(cam, W9966_STATE_VDEV, W9966_STATE_VDEV);
894
895 /* All ok */
896 v4l2_info(v4l2_dev, "Found and initialized a webcam on %s.\n",
897 cam->pport->name);
898 return 0;
899}
900
901
902/* Terminate everything gracefully */
903static void w9966_term(struct w9966 *cam)
904{
905 /* Unregister from v4l */
906 if (w9966_get_state(cam, W9966_STATE_VDEV, W9966_STATE_VDEV)) {
907 video_unregister_device(&cam->vdev);
908 w9966_set_state(cam, W9966_STATE_VDEV, 0);
909 }
910
911 v4l2_ctrl_handler_free(&cam->hdl);
912
913 /* Terminate from IEEE1284 mode and release pdev block */
914 if (w9966_get_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
915 w9966_pdev_claim(cam);
916 parport_negotiate(cam->pport, IEEE1284_MODE_COMPAT);
917 w9966_pdev_release(cam);
918 }
919
920 /* Unregister from parport */
921 if (w9966_get_state(cam, W9966_STATE_PDEV, W9966_STATE_PDEV)) {
922 parport_unregister_device(cam->pdev);
923 w9966_set_state(cam, W9966_STATE_PDEV, 0);
924 }
925 memset(cam, 0, sizeof(*cam));
926}
927
928
929/* Called once for every parport on init */
930static void w9966_attach(struct parport *port)
931{
932 int i;
933
934 for (i = 0; i < W9966_MAXCAMS; i++) {
935 if (w9966_cams[i].dev_state != 0) /* Cam is already assigned */
936 continue;
937 if (strcmp(pardev[i], "aggressive") == 0 || strcmp(pardev[i], port->name) == 0) {
938 if (w9966_init(&w9966_cams[i], port) != 0)
939 w9966_term(&w9966_cams[i]);
940 break; /* return */
941 }
942 }
943}
944
945/* Called once for every parport on termination */
946static void w9966_detach(struct parport *port)
947{
948 int i;
949
950 for (i = 0; i < W9966_MAXCAMS; i++)
951 if (w9966_cams[i].dev_state != 0 && w9966_cams[i].pport == port)
952 w9966_term(&w9966_cams[i]);
953}
954
955
956static struct parport_driver w9966_ppd = {
957 .name = W9966_DRIVERNAME,
958 .attach = w9966_attach,
959 .detach = w9966_detach,
960};
961
962/* Module entry point */
963static int __init w9966_mod_init(void)
964{
965 int i;
966
967 for (i = 0; i < W9966_MAXCAMS; i++)
968 w9966_cams[i].dev_state = 0;
969
970 return parport_register_driver(&w9966_ppd);
971}
972
973/* Module cleanup */
974static void __exit w9966_mod_term(void)
975{
976 parport_unregister_driver(&w9966_ppd);
977}
978
979module_init(w9966_mod_init);
980module_exit(w9966_mod_term);
diff --git a/drivers/staging/media/tlg2300/Kconfig b/drivers/staging/media/tlg2300/Kconfig
deleted file mode 100644
index 77d8753f6ba4..000000000000
--- a/drivers/staging/media/tlg2300/Kconfig
+++ /dev/null
@@ -1,21 +0,0 @@
1config VIDEO_TLG2300
2 tristate "Telegent TLG2300 USB video capture support (Deprecated)"
3 depends on VIDEO_DEV && I2C && SND && DVB_CORE
4 depends on MEDIA_USB_SUPPORT
5 select VIDEO_TUNER
6 select VIDEO_TVEEPROM
7 depends on RC_CORE
8 select VIDEOBUF_VMALLOC
9 select SND_PCM
10 select VIDEOBUF_DVB
11
12 ---help---
13 This is a video4linux driver for Telegent tlg2300 based TV cards.
14 The driver supports V4L2, DVB-T and radio.
15
16 This driver is deprecated and will be removed soon. If you have
17 hardware for this and you want to work on this driver, then contact
18 the linux-media mailinglist.
19
20 To compile this driver as a module, choose M here: the
21 module will be called poseidon
diff --git a/drivers/staging/media/tlg2300/Makefile b/drivers/staging/media/tlg2300/Makefile
deleted file mode 100644
index 137f8e38cdec..000000000000
--- a/drivers/staging/media/tlg2300/Makefile
+++ /dev/null
@@ -1,9 +0,0 @@
1poseidon-objs := pd-video.o pd-alsa.o pd-dvb.o pd-radio.o pd-main.o
2
3obj-$(CONFIG_VIDEO_TLG2300) += poseidon.o
4
5ccflags-y += -Idrivers/media/i2c
6ccflags-y += -Idrivers/media/tuners
7ccflags-y += -Idrivers/media/dvb-core
8ccflags-y += -Idrivers/media/dvb-frontends
9
diff --git a/drivers/staging/media/tlg2300/pd-alsa.c b/drivers/staging/media/tlg2300/pd-alsa.c
deleted file mode 100644
index dd8fe100590f..000000000000
--- a/drivers/staging/media/tlg2300/pd-alsa.c
+++ /dev/null
@@ -1,337 +0,0 @@
1#include <linux/kernel.h>
2#include <linux/usb.h>
3#include <linux/init.h>
4#include <linux/sound.h>
5#include <linux/spinlock.h>
6#include <linux/soundcard.h>
7#include <linux/vmalloc.h>
8#include <linux/proc_fs.h>
9#include <linux/module.h>
10#include <linux/gfp.h>
11#include <sound/core.h>
12#include <sound/pcm.h>
13#include <sound/pcm_params.h>
14#include <sound/info.h>
15#include <sound/initval.h>
16#include <sound/control.h>
17#include <media/v4l2-common.h>
18#include "pd-common.h"
19#include "vendorcmds.h"
20
21static void complete_handler_audio(struct urb *urb);
22#define AUDIO_EP (0x83)
23#define AUDIO_BUF_SIZE (512)
24#define PERIOD_SIZE (1024 * 8)
25#define PERIOD_MIN (4)
26#define PERIOD_MAX PERIOD_MIN
27
28static struct snd_pcm_hardware snd_pd_hw_capture = {
29 .info = SNDRV_PCM_INFO_BLOCK_TRANSFER |
30 SNDRV_PCM_INFO_MMAP |
31 SNDRV_PCM_INFO_INTERLEAVED |
32 SNDRV_PCM_INFO_MMAP_VALID,
33
34 .formats = SNDRV_PCM_FMTBIT_S16_LE,
35 .rates = SNDRV_PCM_RATE_48000,
36
37 .rate_min = 48000,
38 .rate_max = 48000,
39 .channels_min = 2,
40 .channels_max = 2,
41 .buffer_bytes_max = PERIOD_SIZE * PERIOD_MIN,
42 .period_bytes_min = PERIOD_SIZE,
43 .period_bytes_max = PERIOD_SIZE,
44 .periods_min = PERIOD_MIN,
45 .periods_max = PERIOD_MAX,
46 /*
47 .buffer_bytes_max = 62720 * 8,
48 .period_bytes_min = 64,
49 .period_bytes_max = 12544,
50 .periods_min = 2,
51 .periods_max = 98
52 */
53};
54
55static int snd_pd_capture_open(struct snd_pcm_substream *substream)
56{
57 struct poseidon *p = snd_pcm_substream_chip(substream);
58 struct poseidon_audio *pa = &p->audio;
59 struct snd_pcm_runtime *runtime = substream->runtime;
60
61 if (!p)
62 return -ENODEV;
63 pa->users++;
64 pa->card_close = 0;
65 pa->capture_pcm_substream = substream;
66 runtime->private_data = p;
67
68 runtime->hw = snd_pd_hw_capture;
69 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
70 usb_autopm_get_interface(p->interface);
71 kref_get(&p->kref);
72 return 0;
73}
74
75static int snd_pd_pcm_close(struct snd_pcm_substream *substream)
76{
77 struct poseidon *p = snd_pcm_substream_chip(substream);
78 struct poseidon_audio *pa = &p->audio;
79
80 pa->users--;
81 pa->card_close = 1;
82 usb_autopm_put_interface(p->interface);
83 kref_put(&p->kref, poseidon_delete);
84 return 0;
85}
86
87static int snd_pd_hw_capture_params(struct snd_pcm_substream *substream,
88 struct snd_pcm_hw_params *hw_params)
89{
90 struct snd_pcm_runtime *runtime = substream->runtime;
91 unsigned int size;
92
93 size = params_buffer_bytes(hw_params);
94 if (runtime->dma_area) {
95 if (runtime->dma_bytes > size)
96 return 0;
97 vfree(runtime->dma_area);
98 }
99 runtime->dma_area = vmalloc(size);
100 if (!runtime->dma_area)
101 return -ENOMEM;
102 else
103 runtime->dma_bytes = size;
104 return 0;
105}
106
107static int audio_buf_free(struct poseidon *p)
108{
109 struct poseidon_audio *pa = &p->audio;
110 int i;
111
112 for (i = 0; i < AUDIO_BUFS; i++)
113 if (pa->urb_array[i])
114 usb_kill_urb(pa->urb_array[i]);
115 free_all_urb_generic(pa->urb_array, AUDIO_BUFS);
116 logpm();
117 return 0;
118}
119
120static int snd_pd_hw_capture_free(struct snd_pcm_substream *substream)
121{
122 struct poseidon *p = snd_pcm_substream_chip(substream);
123
124 logpm();
125 audio_buf_free(p);
126 return 0;
127}
128
129static int snd_pd_prepare(struct snd_pcm_substream *substream)
130{
131 return 0;
132}
133
134#define AUDIO_TRAILER_SIZE (16)
135static inline void handle_audio_data(struct urb *urb, int *period_elapsed)
136{
137 struct poseidon_audio *pa = urb->context;
138 struct snd_pcm_runtime *runtime = pa->capture_pcm_substream->runtime;
139
140 int stride = runtime->frame_bits >> 3;
141 int len = urb->actual_length / stride;
142 unsigned char *cp = urb->transfer_buffer;
143 unsigned int oldptr = pa->rcv_position;
144
145 if (urb->actual_length == AUDIO_BUF_SIZE - 4)
146 len -= (AUDIO_TRAILER_SIZE / stride);
147
148 /* do the copy */
149 if (oldptr + len >= runtime->buffer_size) {
150 unsigned int cnt = runtime->buffer_size - oldptr;
151
152 memcpy(runtime->dma_area + oldptr * stride, cp, cnt * stride);
153 memcpy(runtime->dma_area, (cp + cnt * stride),
154 (len * stride - cnt * stride));
155 } else
156 memcpy(runtime->dma_area + oldptr * stride, cp, len * stride);
157
158 /* update the statas */
159 snd_pcm_stream_lock(pa->capture_pcm_substream);
160 pa->rcv_position += len;
161 if (pa->rcv_position >= runtime->buffer_size)
162 pa->rcv_position -= runtime->buffer_size;
163
164 pa->copied_position += (len);
165 if (pa->copied_position >= runtime->period_size) {
166 pa->copied_position -= runtime->period_size;
167 *period_elapsed = 1;
168 }
169 snd_pcm_stream_unlock(pa->capture_pcm_substream);
170}
171
172static void complete_handler_audio(struct urb *urb)
173{
174 struct poseidon_audio *pa = urb->context;
175 struct snd_pcm_substream *substream = pa->capture_pcm_substream;
176 int period_elapsed = 0;
177 int ret;
178
179 if (1 == pa->card_close || pa->capture_stream != STREAM_ON)
180 return;
181
182 if (urb->status != 0) {
183 /*if (urb->status == -ESHUTDOWN)*/
184 return;
185 }
186
187 if (substream) {
188 if (urb->actual_length) {
189 handle_audio_data(urb, &period_elapsed);
190 if (period_elapsed)
191 snd_pcm_period_elapsed(substream);
192 }
193 }
194
195 ret = usb_submit_urb(urb, GFP_ATOMIC);
196 if (ret < 0)
197 log("audio urb failed (errcod = %i)", ret);
198 return;
199}
200
201static int fire_audio_urb(struct poseidon *p)
202{
203 int i, ret = 0;
204 struct poseidon_audio *pa = &p->audio;
205
206 alloc_bulk_urbs_generic(pa->urb_array, AUDIO_BUFS,
207 p->udev, AUDIO_EP,
208 AUDIO_BUF_SIZE, GFP_ATOMIC,
209 complete_handler_audio, pa);
210
211 for (i = 0; i < AUDIO_BUFS; i++) {
212 ret = usb_submit_urb(pa->urb_array[i], GFP_KERNEL);
213 if (ret)
214 log("urb err : %d", ret);
215 }
216 log();
217 return ret;
218}
219
220static int snd_pd_capture_trigger(struct snd_pcm_substream *substream, int cmd)
221{
222 struct poseidon *p = snd_pcm_substream_chip(substream);
223 struct poseidon_audio *pa = &p->audio;
224
225 if (debug_mode)
226 log("cmd %d, audio stat : %d\n", cmd, pa->capture_stream);
227
228 switch (cmd) {
229 case SNDRV_PCM_TRIGGER_RESUME:
230 case SNDRV_PCM_TRIGGER_START:
231 if (pa->capture_stream == STREAM_ON)
232 return 0;
233
234 pa->rcv_position = pa->copied_position = 0;
235 pa->capture_stream = STREAM_ON;
236
237 if (in_hibernation(p))
238 return 0;
239 fire_audio_urb(p);
240 return 0;
241
242 case SNDRV_PCM_TRIGGER_SUSPEND:
243 pa->capture_stream = STREAM_SUSPEND;
244 return 0;
245 case SNDRV_PCM_TRIGGER_STOP:
246 pa->capture_stream = STREAM_OFF;
247 return 0;
248 default:
249 return -EINVAL;
250 }
251}
252
253static snd_pcm_uframes_t
254snd_pd_capture_pointer(struct snd_pcm_substream *substream)
255{
256 struct poseidon *p = snd_pcm_substream_chip(substream);
257 struct poseidon_audio *pa = &p->audio;
258 return pa->rcv_position;
259}
260
261static struct page *snd_pcm_pd_get_page(struct snd_pcm_substream *subs,
262 unsigned long offset)
263{
264 void *pageptr = subs->runtime->dma_area + offset;
265 return vmalloc_to_page(pageptr);
266}
267
268static struct snd_pcm_ops pcm_capture_ops = {
269 .open = snd_pd_capture_open,
270 .close = snd_pd_pcm_close,
271 .ioctl = snd_pcm_lib_ioctl,
272 .hw_params = snd_pd_hw_capture_params,
273 .hw_free = snd_pd_hw_capture_free,
274 .prepare = snd_pd_prepare,
275 .trigger = snd_pd_capture_trigger,
276 .pointer = snd_pd_capture_pointer,
277 .page = snd_pcm_pd_get_page,
278};
279
280#ifdef CONFIG_PM
281int pm_alsa_suspend(struct poseidon *p)
282{
283 logpm(p);
284 audio_buf_free(p);
285 return 0;
286}
287
288int pm_alsa_resume(struct poseidon *p)
289{
290 logpm(p);
291 fire_audio_urb(p);
292 return 0;
293}
294#endif
295
296int poseidon_audio_init(struct poseidon *p)
297{
298 struct poseidon_audio *pa = &p->audio;
299 struct snd_card *card;
300 struct snd_pcm *pcm;
301 int ret;
302
303 ret = snd_card_new(&p->interface->dev, -1, "Telegent",
304 THIS_MODULE, 0, &card);
305 if (ret != 0)
306 return ret;
307
308 ret = snd_pcm_new(card, "poseidon audio", 0, 0, 1, &pcm);
309 if (ret < 0) {
310 snd_card_free(card);
311 return ret;
312 }
313 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &pcm_capture_ops);
314 pcm->info_flags = 0;
315 pcm->private_data = p;
316 strcpy(pcm->name, "poseidon audio capture");
317
318 strcpy(card->driver, "ALSA driver");
319 strcpy(card->shortname, "poseidon Audio");
320 strcpy(card->longname, "poseidon ALSA Audio");
321
322 if (snd_card_register(card)) {
323 snd_card_free(card);
324 return -ENOMEM;
325 }
326 pa->card = card;
327 return 0;
328}
329
330int poseidon_audio_free(struct poseidon *p)
331{
332 struct poseidon_audio *pa = &p->audio;
333
334 if (pa->card)
335 snd_card_free(pa->card);
336 return 0;
337}
diff --git a/drivers/staging/media/tlg2300/pd-common.h b/drivers/staging/media/tlg2300/pd-common.h
deleted file mode 100644
index 9e23ad32d2fe..000000000000
--- a/drivers/staging/media/tlg2300/pd-common.h
+++ /dev/null
@@ -1,271 +0,0 @@
1#ifndef PD_COMMON_H
2#define PD_COMMON_H
3
4#include <linux/fs.h>
5#include <linux/wait.h>
6#include <linux/list.h>
7#include <linux/videodev2.h>
8#include <linux/semaphore.h>
9#include <linux/usb.h>
10#include <linux/poll.h>
11#include <media/videobuf-vmalloc.h>
12#include <media/v4l2-device.h>
13#include <media/v4l2-ctrls.h>
14
15#include "dvb_frontend.h"
16#include "dvbdev.h"
17#include "dvb_demux.h"
18#include "dmxdev.h"
19
20#define SBUF_NUM 8
21#define MAX_BUFFER_NUM 6
22#define PK_PER_URB 32
23#define ISO_PKT_SIZE 3072
24
25#define POSEIDON_STATE_NONE (0x0000)
26#define POSEIDON_STATE_ANALOG (0x0001)
27#define POSEIDON_STATE_FM (0x0002)
28#define POSEIDON_STATE_DVBT (0x0004)
29#define POSEIDON_STATE_DISCONNECT (0x0080)
30
31#define PM_SUSPEND_DELAY 3
32
33#define V4L_PAL_VBI_LINES 18
34#define V4L_NTSC_VBI_LINES 12
35#define V4L_PAL_VBI_FRAMESIZE (V4L_PAL_VBI_LINES * 1440 * 2)
36#define V4L_NTSC_VBI_FRAMESIZE (V4L_NTSC_VBI_LINES * 1440 * 2)
37
38#define TUNER_FREQ_MIN (45000000U)
39#define TUNER_FREQ_MAX (862000000U)
40
41struct vbi_data {
42 struct video_device v_dev;
43 struct video_data *video;
44 struct front_face *front;
45
46 unsigned int copied;
47 unsigned int vbi_size; /* the whole size of two fields */
48 int users;
49};
50
51/*
52 * This is the running context of the video, it is useful for
53 * resume()
54 */
55struct running_context {
56 u32 freq; /* VIDIOC_S_FREQUENCY */
57 int audio_idx; /* VIDIOC_S_TUNER */
58 v4l2_std_id tvnormid; /* VIDIOC_S_STD */
59 int sig_index; /* VIDIOC_S_INPUT */
60 struct v4l2_pix_format pix; /* VIDIOC_S_FMT */
61};
62
63struct video_data {
64 /* v4l2 video device */
65 struct video_device v_dev;
66 struct v4l2_ctrl_handler ctrl_handler;
67
68 /* the working context */
69 struct running_context context;
70
71 /* for data copy */
72 int field_count;
73
74 char *dst;
75 int lines_copied;
76 int prev_left;
77
78 int lines_per_field;
79 int lines_size;
80
81 /* for communication */
82 u8 endpoint_addr;
83 struct urb *urb_array[SBUF_NUM];
84 struct vbi_data *vbi;
85 struct poseidon *pd;
86 struct front_face *front;
87
88 int is_streaming;
89 int users;
90
91 /* for bubble handler */
92 struct work_struct bubble_work;
93};
94
95enum pcm_stream_state {
96 STREAM_OFF,
97 STREAM_ON,
98 STREAM_SUSPEND,
99};
100
101#define AUDIO_BUFS (3)
102#define CAPTURE_STREAM_EN 1
103struct poseidon_audio {
104 struct urb *urb_array[AUDIO_BUFS];
105 unsigned int copied_position;
106 struct snd_pcm_substream *capture_pcm_substream;
107
108 unsigned int rcv_position;
109 struct snd_card *card;
110 int card_close;
111
112 int users;
113 int pm_state;
114 enum pcm_stream_state capture_stream;
115};
116
117struct radio_data {
118 __u32 fm_freq;
119 unsigned int is_radio_streaming;
120 int pre_emphasis;
121 struct video_device fm_dev;
122 struct v4l2_ctrl_handler ctrl_handler;
123};
124
125#define DVB_SBUF_NUM 4
126#define DVB_URB_BUF_SIZE 0x2000
127struct pd_dvb_adapter {
128 struct dvb_adapter dvb_adap;
129 struct dvb_frontend dvb_fe;
130 struct dmxdev dmxdev;
131 struct dvb_demux demux;
132
133 atomic_t users;
134 atomic_t active_feed;
135
136 /* data transfer */
137 s32 is_streaming;
138 struct urb *urb_array[DVB_SBUF_NUM];
139 struct poseidon *pd_device;
140 u8 ep_addr;
141 u8 reserved[3];
142
143 /* data for power resume*/
144 struct dtv_frontend_properties fe_param;
145
146 /* for channel scanning */
147 int prev_freq;
148 int bandwidth;
149 unsigned long last_jiffies;
150};
151
152struct front_face {
153 /* use this field to distinguish VIDEO and VBI */
154 enum v4l2_buf_type type;
155
156 /* for host */
157 struct videobuf_queue q;
158
159 /* the bridge for host and device */
160 struct videobuf_buffer *curr_frame;
161
162 /* for device */
163 spinlock_t queue_lock;
164 struct list_head active;
165 struct poseidon *pd;
166};
167
168struct poseidon {
169 struct list_head device_list;
170
171 struct mutex lock;
172 struct kref kref;
173
174 /* for V4L2 */
175 struct v4l2_device v4l2_dev;
176
177 /* hardware info */
178 struct usb_device *udev;
179 struct usb_interface *interface;
180 int cur_transfer_mode;
181
182 struct video_data video_data; /* video */
183 struct vbi_data vbi_data; /* vbi */
184 struct poseidon_audio audio; /* audio (alsa) */
185 struct radio_data radio_data; /* FM */
186 struct pd_dvb_adapter dvb_data; /* DVB */
187
188 u32 state;
189 struct file *file_for_stream; /* the active stream*/
190
191#ifdef CONFIG_PM
192 int (*pm_suspend)(struct poseidon *);
193 int (*pm_resume)(struct poseidon *);
194 pm_message_t msg;
195
196 struct work_struct pm_work;
197 u8 portnum;
198#endif
199};
200
201struct poseidon_format {
202 char *name;
203 int fourcc; /* video4linux 2 */
204 int depth; /* bit/pixel */
205 int flags;
206};
207
208struct poseidon_tvnorm {
209 v4l2_std_id v4l2_id;
210 char name[12];
211 u32 tlg_tvnorm;
212};
213
214/* video */
215int pd_video_init(struct poseidon *);
216void pd_video_exit(struct poseidon *);
217int stop_all_video_stream(struct poseidon *);
218
219/* alsa audio */
220int poseidon_audio_init(struct poseidon *);
221int poseidon_audio_free(struct poseidon *);
222#ifdef CONFIG_PM
223int pm_alsa_suspend(struct poseidon *);
224int pm_alsa_resume(struct poseidon *);
225#endif
226
227/* dvb */
228int pd_dvb_usb_device_init(struct poseidon *);
229void pd_dvb_usb_device_exit(struct poseidon *);
230void pd_dvb_usb_device_cleanup(struct poseidon *);
231int pd_dvb_get_adapter_num(struct pd_dvb_adapter *);
232void dvb_stop_streaming(struct pd_dvb_adapter *);
233
234/* FM */
235int poseidon_fm_init(struct poseidon *);
236int poseidon_fm_exit(struct poseidon *);
237
238/* vendor command ops */
239int send_set_req(struct poseidon*, u8, s32, s32*);
240int send_get_req(struct poseidon*, u8, s32, void*, s32*, s32);
241s32 set_tuner_mode(struct poseidon*, unsigned char);
242
243/* bulk urb alloc/free */
244int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
245 struct usb_device *udev, u8 ep_addr,
246 int buf_size, gfp_t gfp_flags,
247 usb_complete_t complete_fn, void *context);
248void free_all_urb_generic(struct urb **urb_array, int num);
249
250/* misc */
251void poseidon_delete(struct kref *kref);
252extern int debug_mode;
253void set_debug_mode(struct video_device *vfd, int debug_mode);
254
255#ifdef CONFIG_PM
256#define in_hibernation(pd) (pd->msg.event == PM_EVENT_FREEZE)
257#else
258#define in_hibernation(pd) (0)
259#endif
260#define get_pm_count(p) (atomic_read(&(p)->interface->pm_usage_cnt))
261
262#define log(a, ...) printk(KERN_DEBUG "\t[ %s : %.3d ] "a"\n", \
263 __func__, __LINE__, ## __VA_ARGS__)
264
265/* for power management */
266#define logpm(pd) do {\
267 if (debug_mode & 0x10)\
268 log();\
269 } while (0)
270
271#endif
diff --git a/drivers/staging/media/tlg2300/pd-dvb.c b/drivers/staging/media/tlg2300/pd-dvb.c
deleted file mode 100644
index ca4994a5190c..000000000000
--- a/drivers/staging/media/tlg2300/pd-dvb.c
+++ /dev/null
@@ -1,597 +0,0 @@
1#include "pd-common.h"
2#include <linux/kernel.h>
3#include <linux/usb.h>
4#include <linux/time.h>
5#include <linux/dvb/dmx.h>
6#include <linux/delay.h>
7#include <linux/gfp.h>
8
9#include "vendorcmds.h"
10#include <linux/sched.h>
11#include <linux/atomic.h>
12
13static void dvb_urb_cleanup(struct pd_dvb_adapter *pd_dvb);
14
15static int dvb_bandwidth[][2] = {
16 { TLG_BW_8, 8000000 },
17 { TLG_BW_7, 7000000 },
18 { TLG_BW_6, 6000000 }
19};
20static int dvb_bandwidth_length = ARRAY_SIZE(dvb_bandwidth);
21
22static s32 dvb_start_streaming(struct pd_dvb_adapter *pd_dvb);
23static int poseidon_check_mode_dvbt(struct poseidon *pd)
24{
25 s32 ret = 0, cmd_status = 0;
26
27 set_current_state(TASK_INTERRUPTIBLE);
28 schedule_timeout(HZ/4);
29
30 ret = usb_set_interface(pd->udev, 0, BULK_ALTERNATE_IFACE);
31 if (ret != 0)
32 return ret;
33
34 ret = set_tuner_mode(pd, TLG_MODE_CAPS_DVB_T);
35 if (ret)
36 return ret;
37
38 /* signal source */
39 ret = send_set_req(pd, SGNL_SRC_SEL, TLG_SIG_SRC_ANTENNA, &cmd_status);
40 if (ret|cmd_status)
41 return ret;
42
43 return 0;
44}
45
46/* acquire :
47 * 1 == open
48 * 0 == release
49 */
50static int poseidon_ts_bus_ctrl(struct dvb_frontend *fe, int acquire)
51{
52 struct poseidon *pd = fe->demodulator_priv;
53 struct pd_dvb_adapter *pd_dvb;
54 int ret = 0;
55
56 if (!pd)
57 return -ENODEV;
58
59 pd_dvb = container_of(fe, struct pd_dvb_adapter, dvb_fe);
60 if (acquire) {
61 mutex_lock(&pd->lock);
62 if (pd->state & POSEIDON_STATE_DISCONNECT) {
63 ret = -ENODEV;
64 goto open_out;
65 }
66
67 if (pd->state && !(pd->state & POSEIDON_STATE_DVBT)) {
68 ret = -EBUSY;
69 goto open_out;
70 }
71
72 usb_autopm_get_interface(pd->interface);
73 if (0 == pd->state) {
74 ret = poseidon_check_mode_dvbt(pd);
75 if (ret < 0) {
76 usb_autopm_put_interface(pd->interface);
77 goto open_out;
78 }
79 pd->state |= POSEIDON_STATE_DVBT;
80 pd_dvb->bandwidth = 0;
81 pd_dvb->prev_freq = 0;
82 }
83 atomic_inc(&pd_dvb->users);
84 kref_get(&pd->kref);
85open_out:
86 mutex_unlock(&pd->lock);
87 } else {
88 dvb_stop_streaming(pd_dvb);
89
90 if (atomic_dec_and_test(&pd_dvb->users)) {
91 mutex_lock(&pd->lock);
92 pd->state &= ~POSEIDON_STATE_DVBT;
93 mutex_unlock(&pd->lock);
94 }
95 kref_put(&pd->kref, poseidon_delete);
96 usb_autopm_put_interface(pd->interface);
97 }
98 return ret;
99}
100
101#ifdef CONFIG_PM
102static void poseidon_fe_release(struct dvb_frontend *fe)
103{
104 struct poseidon *pd = fe->demodulator_priv;
105
106 pd->pm_suspend = NULL;
107 pd->pm_resume = NULL;
108}
109#else
110#define poseidon_fe_release NULL
111#endif
112
113static s32 poseidon_fe_sleep(struct dvb_frontend *fe)
114{
115 return 0;
116}
117
118/*
119 * return true if we can satisfy the conditions, else return false.
120 */
121static bool check_scan_ok(__u32 freq, int bandwidth,
122 struct pd_dvb_adapter *adapter)
123{
124 if (bandwidth < 0)
125 return false;
126
127 if (adapter->prev_freq == freq
128 && adapter->bandwidth == bandwidth) {
129 long nl = jiffies - adapter->last_jiffies;
130 unsigned int msec ;
131
132 msec = jiffies_to_msecs(abs(nl));
133 return msec > 15000 ? true : false;
134 }
135 return true;
136}
137
138/*
139 * Check if the firmware delays too long for an invalid frequency.
140 */
141static int fw_delay_overflow(struct pd_dvb_adapter *adapter)
142{
143 long nl = jiffies - adapter->last_jiffies;
144 unsigned int msec ;
145
146 msec = jiffies_to_msecs(abs(nl));
147 return msec > 800 ? true : false;
148}
149
150static int poseidon_set_fe(struct dvb_frontend *fe)
151{
152 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
153 s32 ret = 0, cmd_status = 0;
154 s32 i, bandwidth = -1;
155 struct poseidon *pd = fe->demodulator_priv;
156 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
157
158 if (in_hibernation(pd))
159 return -EBUSY;
160
161 mutex_lock(&pd->lock);
162 for (i = 0; i < dvb_bandwidth_length; i++)
163 if (fep->bandwidth_hz == dvb_bandwidth[i][1])
164 bandwidth = dvb_bandwidth[i][0];
165
166 if (check_scan_ok(fep->frequency, bandwidth, pd_dvb)) {
167 ret = send_set_req(pd, TUNE_FREQ_SELECT,
168 fep->frequency / 1000, &cmd_status);
169 if (ret | cmd_status) {
170 log("error line");
171 goto front_out;
172 }
173
174 ret = send_set_req(pd, DVBT_BANDW_SEL,
175 bandwidth, &cmd_status);
176 if (ret | cmd_status) {
177 log("error line");
178 goto front_out;
179 }
180
181 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
182 if (ret | cmd_status) {
183 log("error line");
184 goto front_out;
185 }
186
187 /* save the context for future */
188 memcpy(&pd_dvb->fe_param, fep, sizeof(*fep));
189 pd_dvb->bandwidth = bandwidth;
190 pd_dvb->prev_freq = fep->frequency;
191 pd_dvb->last_jiffies = jiffies;
192 }
193front_out:
194 mutex_unlock(&pd->lock);
195 return ret;
196}
197
198#ifdef CONFIG_PM
199static int pm_dvb_suspend(struct poseidon *pd)
200{
201 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
202 dvb_stop_streaming(pd_dvb);
203 dvb_urb_cleanup(pd_dvb);
204 msleep(500);
205 return 0;
206}
207
208static int pm_dvb_resume(struct poseidon *pd)
209{
210 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
211
212 poseidon_check_mode_dvbt(pd);
213 msleep(300);
214 poseidon_set_fe(&pd_dvb->dvb_fe);
215
216 dvb_start_streaming(pd_dvb);
217 return 0;
218}
219#endif
220
221static s32 poseidon_fe_init(struct dvb_frontend *fe)
222{
223 struct poseidon *pd = fe->demodulator_priv;
224 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
225
226#ifdef CONFIG_PM
227 pd->pm_suspend = pm_dvb_suspend;
228 pd->pm_resume = pm_dvb_resume;
229#endif
230 memset(&pd_dvb->fe_param, 0,
231 sizeof(struct dtv_frontend_properties));
232 return 0;
233}
234
235static int poseidon_get_fe(struct dvb_frontend *fe)
236{
237 struct dtv_frontend_properties *fep = &fe->dtv_property_cache;
238 struct poseidon *pd = fe->demodulator_priv;
239 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
240
241 memcpy(fep, &pd_dvb->fe_param, sizeof(*fep));
242 return 0;
243}
244
245static int poseidon_fe_get_tune_settings(struct dvb_frontend *fe,
246 struct dvb_frontend_tune_settings *tune)
247{
248 tune->min_delay_ms = 1000;
249 return 0;
250}
251
252static int poseidon_read_status(struct dvb_frontend *fe, fe_status_t *stat)
253{
254 struct poseidon *pd = fe->demodulator_priv;
255 s32 ret = -1, cmd_status;
256 struct tuner_dtv_sig_stat_s status = {};
257
258 if (in_hibernation(pd))
259 return -EBUSY;
260 mutex_lock(&pd->lock);
261
262 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_DVB_T,
263 &status, &cmd_status, sizeof(status));
264 if (ret | cmd_status) {
265 log("get tuner status error");
266 goto out;
267 }
268
269 if (debug_mode)
270 log("P : %d, L %d, LB :%d", status.sig_present,
271 status.sig_locked, status.sig_lock_busy);
272
273 if (status.sig_lock_busy) {
274 goto out;
275 } else if (status.sig_present || status.sig_locked) {
276 *stat |= FE_HAS_LOCK | FE_HAS_SIGNAL | FE_HAS_CARRIER
277 | FE_HAS_SYNC | FE_HAS_VITERBI;
278 } else {
279 if (fw_delay_overflow(&pd->dvb_data))
280 *stat |= FE_TIMEDOUT;
281 }
282out:
283 mutex_unlock(&pd->lock);
284 return ret;
285}
286
287static int poseidon_read_ber(struct dvb_frontend *fe, u32 *ber)
288{
289 struct poseidon *pd = fe->demodulator_priv;
290 struct tuner_ber_rate_s tlg_ber = {};
291 s32 ret = -1, cmd_status;
292
293 mutex_lock(&pd->lock);
294 ret = send_get_req(pd, TUNER_BER_RATE, 0,
295 &tlg_ber, &cmd_status, sizeof(tlg_ber));
296 if (ret | cmd_status)
297 goto out;
298 *ber = tlg_ber.ber_rate;
299out:
300 mutex_unlock(&pd->lock);
301 return ret;
302}
303
304static s32 poseidon_read_signal_strength(struct dvb_frontend *fe, u16 *strength)
305{
306 struct poseidon *pd = fe->demodulator_priv;
307 struct tuner_dtv_sig_stat_s status = {};
308 s32 ret = 0, cmd_status;
309
310 mutex_lock(&pd->lock);
311 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_DVB_T,
312 &status, &cmd_status, sizeof(status));
313 if (ret | cmd_status)
314 goto out;
315 if ((status.sig_present || status.sig_locked) && !status.sig_strength)
316 *strength = 0xFFFF;
317 else
318 *strength = status.sig_strength;
319out:
320 mutex_unlock(&pd->lock);
321 return ret;
322}
323
324static int poseidon_read_snr(struct dvb_frontend *fe, u16 *snr)
325{
326 return 0;
327}
328
329static int poseidon_read_unc_blocks(struct dvb_frontend *fe, u32 *unc)
330{
331 *unc = 0;
332 return 0;
333}
334
335static struct dvb_frontend_ops poseidon_frontend_ops = {
336 .delsys = { SYS_DVBT },
337 .info = {
338 .name = "Poseidon DVB-T",
339 .frequency_min = 174000000,
340 .frequency_max = 862000000,
341 .frequency_stepsize = 62500,/* FIXME */
342 .caps = FE_CAN_INVERSION_AUTO |
343 FE_CAN_FEC_1_2 | FE_CAN_FEC_2_3 | FE_CAN_FEC_3_4 |
344 FE_CAN_FEC_5_6 | FE_CAN_FEC_7_8 | FE_CAN_FEC_AUTO |
345 FE_CAN_QPSK | FE_CAN_QAM_16 | FE_CAN_QAM_64 |
346 FE_CAN_QAM_AUTO | FE_CAN_TRANSMISSION_MODE_AUTO |
347 FE_CAN_GUARD_INTERVAL_AUTO |
348 FE_CAN_RECOVER |
349 FE_CAN_HIERARCHY_AUTO,
350 },
351
352 .release = poseidon_fe_release,
353
354 .init = poseidon_fe_init,
355 .sleep = poseidon_fe_sleep,
356
357 .set_frontend = poseidon_set_fe,
358 .get_frontend = poseidon_get_fe,
359 .get_tune_settings = poseidon_fe_get_tune_settings,
360
361 .read_status = poseidon_read_status,
362 .read_ber = poseidon_read_ber,
363 .read_signal_strength = poseidon_read_signal_strength,
364 .read_snr = poseidon_read_snr,
365 .read_ucblocks = poseidon_read_unc_blocks,
366
367 .ts_bus_ctrl = poseidon_ts_bus_ctrl,
368};
369
370static void dvb_urb_irq(struct urb *urb)
371{
372 struct pd_dvb_adapter *pd_dvb = urb->context;
373 int len = urb->transfer_buffer_length;
374 struct dvb_demux *demux = &pd_dvb->demux;
375 s32 ret;
376
377 if (!pd_dvb->is_streaming || urb->status) {
378 if (urb->status == -EPROTO)
379 goto resend;
380 return;
381 }
382
383 if (urb->actual_length == len)
384 dvb_dmx_swfilter(demux, urb->transfer_buffer, len);
385 else if (urb->actual_length == len - 4) {
386 int offset;
387 u8 *buf = urb->transfer_buffer;
388
389 /*
390 * The packet size is 512,
391 * last packet contains 456 bytes tsp data
392 */
393 for (offset = 456; offset < len; offset += 512) {
394 if (!strncmp(buf + offset, "DVHS", 4)) {
395 dvb_dmx_swfilter(demux, buf, offset);
396 if (len > offset + 52 + 4) {
397 /*16 bytes trailer + 36 bytes padding */
398 buf += offset + 52;
399 len -= offset + 52 + 4;
400 dvb_dmx_swfilter(demux, buf, len);
401 }
402 break;
403 }
404 }
405 }
406
407resend:
408 ret = usb_submit_urb(urb, GFP_ATOMIC);
409 if (ret)
410 log(" usb_submit_urb failed: error %d", ret);
411}
412
413static int dvb_urb_init(struct pd_dvb_adapter *pd_dvb)
414{
415 if (pd_dvb->urb_array[0])
416 return 0;
417
418 alloc_bulk_urbs_generic(pd_dvb->urb_array, DVB_SBUF_NUM,
419 pd_dvb->pd_device->udev, pd_dvb->ep_addr,
420 DVB_URB_BUF_SIZE, GFP_KERNEL,
421 dvb_urb_irq, pd_dvb);
422 return 0;
423}
424
425static void dvb_urb_cleanup(struct pd_dvb_adapter *pd_dvb)
426{
427 free_all_urb_generic(pd_dvb->urb_array, DVB_SBUF_NUM);
428}
429
430static s32 dvb_start_streaming(struct pd_dvb_adapter *pd_dvb)
431{
432 struct poseidon *pd = pd_dvb->pd_device;
433 int ret = 0;
434
435 if (pd->state & POSEIDON_STATE_DISCONNECT)
436 return -ENODEV;
437
438 mutex_lock(&pd->lock);
439 if (!pd_dvb->is_streaming) {
440 s32 i, cmd_status = 0;
441 /*
442 * Once upon a time, there was a difficult bug lying here.
443 * ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
444 */
445
446 ret = send_set_req(pd, PLAY_SERVICE, 1, &cmd_status);
447 if (ret | cmd_status)
448 goto out;
449
450 ret = dvb_urb_init(pd_dvb);
451 if (ret < 0)
452 goto out;
453
454 pd_dvb->is_streaming = 1;
455 for (i = 0; i < DVB_SBUF_NUM; i++) {
456 ret = usb_submit_urb(pd_dvb->urb_array[i],
457 GFP_KERNEL);
458 if (ret) {
459 log(" submit urb error %d", ret);
460 goto out;
461 }
462 }
463 }
464out:
465 mutex_unlock(&pd->lock);
466 return ret;
467}
468
469void dvb_stop_streaming(struct pd_dvb_adapter *pd_dvb)
470{
471 struct poseidon *pd = pd_dvb->pd_device;
472
473 mutex_lock(&pd->lock);
474 if (pd_dvb->is_streaming) {
475 s32 i, ret, cmd_status = 0;
476
477 pd_dvb->is_streaming = 0;
478
479 for (i = 0; i < DVB_SBUF_NUM; i++)
480 if (pd_dvb->urb_array[i])
481 usb_kill_urb(pd_dvb->urb_array[i]);
482
483 ret = send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
484 &cmd_status);
485 if (ret | cmd_status)
486 log("error");
487 }
488 mutex_unlock(&pd->lock);
489}
490
491static int pd_start_feed(struct dvb_demux_feed *feed)
492{
493 struct pd_dvb_adapter *pd_dvb = feed->demux->priv;
494 int ret = 0;
495
496 if (!pd_dvb)
497 return -1;
498 if (atomic_inc_return(&pd_dvb->active_feed) == 1)
499 ret = dvb_start_streaming(pd_dvb);
500 return ret;
501}
502
503static int pd_stop_feed(struct dvb_demux_feed *feed)
504{
505 struct pd_dvb_adapter *pd_dvb = feed->demux->priv;
506
507 if (!pd_dvb)
508 return -1;
509 if (atomic_dec_and_test(&pd_dvb->active_feed))
510 dvb_stop_streaming(pd_dvb);
511 return 0;
512}
513
514DVB_DEFINE_MOD_OPT_ADAPTER_NR(adapter_nr);
515int pd_dvb_usb_device_init(struct poseidon *pd)
516{
517 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
518 struct dvb_demux *dvbdemux;
519 int ret = 0;
520
521 pd_dvb->ep_addr = 0x82;
522 atomic_set(&pd_dvb->users, 0);
523 atomic_set(&pd_dvb->active_feed, 0);
524 pd_dvb->pd_device = pd;
525
526 ret = dvb_register_adapter(&pd_dvb->dvb_adap,
527 "Poseidon dvbt adapter",
528 THIS_MODULE,
529 NULL /* for hibernation correctly*/,
530 adapter_nr);
531 if (ret < 0)
532 goto error1;
533
534 /* register frontend */
535 pd_dvb->dvb_fe.demodulator_priv = pd;
536 memcpy(&pd_dvb->dvb_fe.ops, &poseidon_frontend_ops,
537 sizeof(struct dvb_frontend_ops));
538 ret = dvb_register_frontend(&pd_dvb->dvb_adap, &pd_dvb->dvb_fe);
539 if (ret < 0)
540 goto error2;
541
542 /* register demux device */
543 dvbdemux = &pd_dvb->demux;
544 dvbdemux->dmx.capabilities = DMX_TS_FILTERING | DMX_SECTION_FILTERING;
545 dvbdemux->priv = pd_dvb;
546 dvbdemux->feednum = dvbdemux->filternum = 64;
547 dvbdemux->start_feed = pd_start_feed;
548 dvbdemux->stop_feed = pd_stop_feed;
549 dvbdemux->write_to_decoder = NULL;
550
551 ret = dvb_dmx_init(dvbdemux);
552 if (ret < 0)
553 goto error3;
554
555 pd_dvb->dmxdev.filternum = pd_dvb->demux.filternum;
556 pd_dvb->dmxdev.demux = &pd_dvb->demux.dmx;
557 pd_dvb->dmxdev.capabilities = 0;
558
559 ret = dvb_dmxdev_init(&pd_dvb->dmxdev, &pd_dvb->dvb_adap);
560 if (ret < 0)
561 goto error3;
562 return 0;
563
564error3:
565 dvb_unregister_frontend(&pd_dvb->dvb_fe);
566error2:
567 dvb_unregister_adapter(&pd_dvb->dvb_adap);
568error1:
569 return ret;
570}
571
572void pd_dvb_usb_device_exit(struct poseidon *pd)
573{
574 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
575
576 while (atomic_read(&pd_dvb->users) != 0
577 || atomic_read(&pd_dvb->active_feed) != 0) {
578 set_current_state(TASK_INTERRUPTIBLE);
579 schedule_timeout(HZ);
580 }
581 dvb_dmxdev_release(&pd_dvb->dmxdev);
582 dvb_unregister_frontend(&pd_dvb->dvb_fe);
583 dvb_unregister_adapter(&pd_dvb->dvb_adap);
584 pd_dvb_usb_device_cleanup(pd);
585}
586
587void pd_dvb_usb_device_cleanup(struct poseidon *pd)
588{
589 struct pd_dvb_adapter *pd_dvb = &pd->dvb_data;
590
591 dvb_urb_cleanup(pd_dvb);
592}
593
594int pd_dvb_get_adapter_num(struct pd_dvb_adapter *pd_dvb)
595{
596 return pd_dvb->dvb_adap.num;
597}
diff --git a/drivers/staging/media/tlg2300/pd-main.c b/drivers/staging/media/tlg2300/pd-main.c
deleted file mode 100644
index b31f4791b8ff..000000000000
--- a/drivers/staging/media/tlg2300/pd-main.c
+++ /dev/null
@@ -1,553 +0,0 @@
1/*
2 * device driver for Telegent tlg2300 based TV cards
3 *
4 * Author :
5 * Kang Yong <kangyong@telegent.com>
6 * Zhang Xiaobing <xbzhang@telegent.com>
7 * Huang Shijie <zyziii@telegent.com> or <shijie8@gmail.com>
8 *
9 * (c) 2009 Telegent Systems
10 * (c) 2010 Telegent Systems
11 *
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
16 *
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 */
26
27#include <linux/kernel.h>
28#include <linux/errno.h>
29#include <linux/init.h>
30#include <linux/slab.h>
31#include <linux/module.h>
32#include <linux/kref.h>
33#include <linux/suspend.h>
34#include <linux/usb/quirks.h>
35#include <linux/ctype.h>
36#include <linux/string.h>
37#include <linux/types.h>
38#include <linux/firmware.h>
39
40#include "vendorcmds.h"
41#include "pd-common.h"
42
43#define VENDOR_ID 0x1B24
44#define PRODUCT_ID 0x4001
45static struct usb_device_id id_table[] = {
46 { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 0) },
47 { USB_DEVICE_AND_INTERFACE_INFO(VENDOR_ID, PRODUCT_ID, 255, 1, 1) },
48 { },
49};
50MODULE_DEVICE_TABLE(usb, id_table);
51
52int debug_mode;
53module_param(debug_mode, int, 0644);
54MODULE_PARM_DESC(debug_mode, "0 = disable, 1 = enable, 2 = verbose");
55
56#define TLG2300_FIRMWARE "tlg2300_firmware.bin"
57static const char *firmware_name = TLG2300_FIRMWARE;
58static LIST_HEAD(pd_device_list);
59
60/*
61 * send set request to USB firmware.
62 */
63s32 send_set_req(struct poseidon *pd, u8 cmdid, s32 param, s32 *cmd_status)
64{
65 s32 ret;
66 s8 data[32] = {};
67 u16 lower_16, upper_16;
68
69 if (pd->state & POSEIDON_STATE_DISCONNECT)
70 return -ENODEV;
71
72 mdelay(30);
73
74 if (param == 0) {
75 upper_16 = lower_16 = 0;
76 } else {
77 /* send 32 bit param as two 16 bit param,little endian */
78 lower_16 = (unsigned short)(param & 0xffff);
79 upper_16 = (unsigned short)((param >> 16) & 0xffff);
80 }
81 ret = usb_control_msg(pd->udev,
82 usb_rcvctrlpipe(pd->udev, 0),
83 REQ_SET_CMD | cmdid,
84 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
85 lower_16,
86 upper_16,
87 &data,
88 sizeof(*cmd_status),
89 USB_CTRL_GET_TIMEOUT);
90
91 if (!ret) {
92 return -ENXIO;
93 } else {
94 /* 1st 4 bytes into cmd_status */
95 memcpy((char *)cmd_status, &(data[0]), sizeof(*cmd_status));
96 }
97 return 0;
98}
99
100/*
101 * send get request to Poseidon firmware.
102 */
103s32 send_get_req(struct poseidon *pd, u8 cmdid, s32 param,
104 void *buf, s32 *cmd_status, s32 datalen)
105{
106 s32 ret;
107 s8 data[128] = {};
108 u16 lower_16, upper_16;
109
110 if (pd->state & POSEIDON_STATE_DISCONNECT)
111 return -ENODEV;
112
113 mdelay(30);
114 if (param == 0) {
115 upper_16 = lower_16 = 0;
116 } else {
117 /*send 32 bit param as two 16 bit param, little endian */
118 lower_16 = (unsigned short)(param & 0xffff);
119 upper_16 = (unsigned short)((param >> 16) & 0xffff);
120 }
121 ret = usb_control_msg(pd->udev,
122 usb_rcvctrlpipe(pd->udev, 0),
123 REQ_GET_CMD | cmdid,
124 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
125 lower_16,
126 upper_16,
127 &data,
128 (datalen + sizeof(*cmd_status)),
129 USB_CTRL_GET_TIMEOUT);
130
131 if (ret < 0) {
132 return -ENXIO;
133 } else {
134 /* 1st 4 bytes into cmd_status, remaining data into cmd_data */
135 memcpy((char *)cmd_status, &data[0], sizeof(*cmd_status));
136 memcpy((char *)buf, &data[sizeof(*cmd_status)], datalen);
137 }
138 return 0;
139}
140
141static int pm_notifier_block(struct notifier_block *nb,
142 unsigned long event, void *dummy)
143{
144 struct poseidon *pd = NULL;
145 struct list_head *node, *next;
146
147 switch (event) {
148 case PM_POST_HIBERNATION:
149 list_for_each_safe(node, next, &pd_device_list) {
150 struct usb_device *udev;
151 struct usb_interface *iface;
152 int rc = 0;
153
154 pd = container_of(node, struct poseidon, device_list);
155 udev = pd->udev;
156 iface = pd->interface;
157
158 /* It will cause the system to reload the firmware */
159 rc = usb_lock_device_for_reset(udev, iface);
160 if (rc >= 0) {
161 usb_reset_device(udev);
162 usb_unlock_device(udev);
163 }
164 }
165 break;
166 default:
167 break;
168 }
169 log("event :%ld\n", event);
170 return 0;
171}
172
173static struct notifier_block pm_notifer = {
174 .notifier_call = pm_notifier_block,
175};
176
177int set_tuner_mode(struct poseidon *pd, unsigned char mode)
178{
179 s32 ret, cmd_status;
180
181 if (pd->state & POSEIDON_STATE_DISCONNECT)
182 return -ENODEV;
183
184 ret = send_set_req(pd, TUNE_MODE_SELECT, mode, &cmd_status);
185 if (ret || cmd_status)
186 return -ENXIO;
187 return 0;
188}
189
190void poseidon_delete(struct kref *kref)
191{
192 struct poseidon *pd = container_of(kref, struct poseidon, kref);
193
194 if (!pd)
195 return;
196 list_del_init(&pd->device_list);
197
198 pd_dvb_usb_device_cleanup(pd);
199 /* clean_audio_data(&pd->audio_data);*/
200
201 if (pd->udev) {
202 usb_put_dev(pd->udev);
203 pd->udev = NULL;
204 }
205 if (pd->interface) {
206 usb_put_intf(pd->interface);
207 pd->interface = NULL;
208 }
209 kfree(pd);
210 log();
211}
212
213static int firmware_download(struct usb_device *udev)
214{
215 int ret = 0, actual_length;
216 const struct firmware *fw = NULL;
217 void *fwbuf = NULL;
218 size_t fwlength = 0, offset;
219 size_t max_packet_size;
220
221 ret = request_firmware(&fw, firmware_name, &udev->dev);
222 if (ret) {
223 log("download err : %d", ret);
224 return ret;
225 }
226
227 fwlength = fw->size;
228
229 fwbuf = kmemdup(fw->data, fwlength, GFP_KERNEL);
230 if (!fwbuf) {
231 ret = -ENOMEM;
232 goto out;
233 }
234
235 max_packet_size = le16_to_cpu(udev->ep_out[0x1]->desc.wMaxPacketSize);
236 log("\t\t download size : %d", (int)max_packet_size);
237
238 for (offset = 0; offset < fwlength; offset += max_packet_size) {
239 actual_length = 0;
240 ret = usb_bulk_msg(udev,
241 usb_sndbulkpipe(udev, 0x01), /* ep 1 */
242 fwbuf + offset,
243 min(max_packet_size, fwlength - offset),
244 &actual_length,
245 HZ * 10);
246 if (ret)
247 break;
248 }
249 kfree(fwbuf);
250out:
251 release_firmware(fw);
252 return ret;
253}
254
255static inline struct poseidon *get_pd(struct usb_interface *intf)
256{
257 return usb_get_intfdata(intf);
258}
259
260#ifdef CONFIG_PM
261/* one-to-one map : poseidon{} <----> usb_device{}'s port */
262static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev)
263{
264 pd->portnum = udev->portnum;
265}
266
267static inline int get_autopm_ref(struct poseidon *pd)
268{
269 return pd->video_data.users + pd->vbi_data.users + pd->audio.users
270 + atomic_read(&pd->dvb_data.users) +
271 !list_empty(&pd->radio_data.fm_dev.fh_list);
272}
273
274/* fixup something for poseidon */
275static inline struct poseidon *fixup(struct poseidon *pd)
276{
277 int count;
278
279 /* old udev and interface have gone, so put back reference . */
280 count = get_autopm_ref(pd);
281 log("count : %d, ref count : %d", count, get_pm_count(pd));
282 while (count--)
283 usb_autopm_put_interface(pd->interface);
284 /*usb_autopm_set_interface(pd->interface); */
285
286 usb_put_dev(pd->udev);
287 usb_put_intf(pd->interface);
288 log("event : %d\n", pd->msg.event);
289 return pd;
290}
291
292static struct poseidon *find_old_poseidon(struct usb_device *udev)
293{
294 struct poseidon *pd;
295
296 list_for_each_entry(pd, &pd_device_list, device_list) {
297 if (pd->portnum == udev->portnum && in_hibernation(pd))
298 return fixup(pd);
299 }
300 return NULL;
301}
302
303/* Is the card working now ? */
304static inline int is_working(struct poseidon *pd)
305{
306 return get_pm_count(pd) > 0;
307}
308
309static int poseidon_suspend(struct usb_interface *intf, pm_message_t msg)
310{
311 struct poseidon *pd = get_pd(intf);
312
313 if (!pd)
314 return 0;
315 if (!is_working(pd)) {
316 if (get_pm_count(pd) <= 0 && !in_hibernation(pd)) {
317 pd->msg.event = PM_EVENT_AUTO_SUSPEND;
318 pd->pm_resume = NULL; /* a good guard */
319 printk(KERN_DEBUG "TLG2300 auto suspend\n");
320 }
321 return 0;
322 }
323 pd->msg = msg; /* save it here */
324 logpm(pd);
325 return pd->pm_suspend ? pd->pm_suspend(pd) : 0;
326}
327
328static int poseidon_resume(struct usb_interface *intf)
329{
330 struct poseidon *pd = get_pd(intf);
331
332 if (!pd)
333 return 0;
334 printk(KERN_DEBUG "TLG2300 resume\n");
335
336 if (!is_working(pd)) {
337 if (PM_EVENT_AUTO_SUSPEND == pd->msg.event)
338 pd->msg = PMSG_ON;
339 return 0;
340 }
341 if (in_hibernation(pd)) {
342 logpm(pd);
343 return 0;
344 }
345 logpm(pd);
346 return pd->pm_resume ? pd->pm_resume(pd) : 0;
347}
348
349static void hibernation_resume(struct work_struct *w)
350{
351 struct poseidon *pd = container_of(w, struct poseidon, pm_work);
352 int count;
353
354 pd->msg.event = 0; /* clear it here */
355 pd->state &= ~POSEIDON_STATE_DISCONNECT;
356
357 /* set the new interface's reference */
358 count = get_autopm_ref(pd);
359 while (count--)
360 usb_autopm_get_interface(pd->interface);
361
362 /* resume the context */
363 logpm(pd);
364 if (pd->pm_resume)
365 pd->pm_resume(pd);
366}
367#else /* CONFIG_PM is not enabled: */
368static inline struct poseidon *find_old_poseidon(struct usb_device *udev)
369{
370 return NULL;
371}
372
373static inline void set_map_flags(struct poseidon *pd, struct usb_device *udev)
374{
375}
376#endif
377
378static int check_firmware(struct usb_device *udev)
379{
380 void *buf;
381 int ret;
382 struct cmd_firmware_vers_s *cmd_firm;
383
384 buf = kzalloc(sizeof(*cmd_firm) + sizeof(u32), GFP_KERNEL);
385 if (!buf)
386 return -ENOMEM;
387 ret = usb_control_msg(udev,
388 usb_rcvctrlpipe(udev, 0),
389 REQ_GET_CMD | GET_FW_ID,
390 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
391 0,
392 0,
393 buf,
394 sizeof(*cmd_firm) + sizeof(u32),
395 USB_CTRL_GET_TIMEOUT);
396 kfree(buf);
397
398 if (ret < 0)
399 return firmware_download(udev);
400 return 0;
401}
402
403static int poseidon_probe(struct usb_interface *interface,
404 const struct usb_device_id *id)
405{
406 struct usb_device *udev = interface_to_usbdev(interface);
407 struct poseidon *pd = NULL;
408 int ret = 0;
409 int new_one = 0;
410
411 /* download firmware */
412 ret = check_firmware(udev);
413 if (ret)
414 return ret;
415
416 /* Do I recovery from the hibernate ? */
417 pd = find_old_poseidon(udev);
418 if (!pd) {
419 pd = kzalloc(sizeof(*pd), GFP_KERNEL);
420 if (!pd)
421 return -ENOMEM;
422 kref_init(&pd->kref);
423 set_map_flags(pd, udev);
424 new_one = 1;
425 }
426
427 pd->udev = usb_get_dev(udev);
428 pd->interface = usb_get_intf(interface);
429 usb_set_intfdata(interface, pd);
430
431 if (new_one) {
432 logpm(pd);
433 mutex_init(&pd->lock);
434
435 /* register v4l2 device */
436 ret = v4l2_device_register(&interface->dev, &pd->v4l2_dev);
437 if (ret)
438 goto err_v4l2;
439
440 /* register devices in directory /dev */
441 ret = pd_video_init(pd);
442 if (ret)
443 goto err_video;
444 ret = poseidon_audio_init(pd);
445 if (ret)
446 goto err_audio;
447 ret = poseidon_fm_init(pd);
448 if (ret)
449 goto err_fm;
450 ret = pd_dvb_usb_device_init(pd);
451 if (ret)
452 goto err_dvb;
453
454 INIT_LIST_HEAD(&pd->device_list);
455 list_add_tail(&pd->device_list, &pd_device_list);
456 }
457
458 device_init_wakeup(&udev->dev, 1);
459#ifdef CONFIG_PM
460 pm_runtime_set_autosuspend_delay(&pd->udev->dev,
461 1000 * PM_SUSPEND_DELAY);
462 usb_enable_autosuspend(pd->udev);
463
464 if (in_hibernation(pd)) {
465 INIT_WORK(&pd->pm_work, hibernation_resume);
466 schedule_work(&pd->pm_work);
467 }
468#endif
469 return 0;
470err_dvb:
471 poseidon_fm_exit(pd);
472err_fm:
473 poseidon_audio_free(pd);
474err_audio:
475 pd_video_exit(pd);
476err_video:
477 v4l2_device_unregister(&pd->v4l2_dev);
478err_v4l2:
479 usb_put_intf(pd->interface);
480 usb_put_dev(pd->udev);
481 kfree(pd);
482 return ret;
483}
484
485static void poseidon_disconnect(struct usb_interface *interface)
486{
487 struct poseidon *pd = get_pd(interface);
488
489 if (!pd)
490 return;
491 logpm(pd);
492 if (in_hibernation(pd))
493 return;
494
495 mutex_lock(&pd->lock);
496 pd->state |= POSEIDON_STATE_DISCONNECT;
497 mutex_unlock(&pd->lock);
498
499 /* stop urb transferring */
500 stop_all_video_stream(pd);
501 dvb_stop_streaming(&pd->dvb_data);
502
503 /*unregister v4l2 device */
504 v4l2_device_unregister(&pd->v4l2_dev);
505
506 pd_dvb_usb_device_exit(pd);
507 poseidon_fm_exit(pd);
508
509 poseidon_audio_free(pd);
510 pd_video_exit(pd);
511
512 usb_set_intfdata(interface, NULL);
513 kref_put(&pd->kref, poseidon_delete);
514}
515
516static struct usb_driver poseidon_driver = {
517 .name = "poseidon",
518 .probe = poseidon_probe,
519 .disconnect = poseidon_disconnect,
520 .id_table = id_table,
521#ifdef CONFIG_PM
522 .suspend = poseidon_suspend,
523 .resume = poseidon_resume,
524#endif
525 .supports_autosuspend = 1,
526};
527
528static int __init poseidon_init(void)
529{
530 int ret;
531
532 ret = usb_register(&poseidon_driver);
533 if (ret)
534 return ret;
535 register_pm_notifier(&pm_notifer);
536 return ret;
537}
538
539static void __exit poseidon_exit(void)
540{
541 log();
542 unregister_pm_notifier(&pm_notifer);
543 usb_deregister(&poseidon_driver);
544}
545
546module_init(poseidon_init);
547module_exit(poseidon_exit);
548
549MODULE_AUTHOR("Telegent Systems");
550MODULE_DESCRIPTION("For tlg2300-based USB device");
551MODULE_LICENSE("GPL");
552MODULE_VERSION("0.0.2");
553MODULE_FIRMWARE(TLG2300_FIRMWARE);
diff --git a/drivers/staging/media/tlg2300/pd-radio.c b/drivers/staging/media/tlg2300/pd-radio.c
deleted file mode 100644
index b391194a840c..000000000000
--- a/drivers/staging/media/tlg2300/pd-radio.c
+++ /dev/null
@@ -1,339 +0,0 @@
1#include <linux/init.h>
2#include <linux/list.h>
3#include <linux/module.h>
4#include <linux/kernel.h>
5#include <linux/bitmap.h>
6#include <linux/usb.h>
7#include <linux/i2c.h>
8#include <media/v4l2-dev.h>
9#include <linux/mm.h>
10#include <linux/mutex.h>
11#include <media/v4l2-ioctl.h>
12#include <media/v4l2-event.h>
13#include <media/v4l2-fh.h>
14#include <linux/sched.h>
15
16#include "pd-common.h"
17#include "vendorcmds.h"
18
19static int set_frequency(struct poseidon *p, __u32 frequency);
20static int poseidon_fm_close(struct file *filp);
21static int poseidon_fm_open(struct file *filp);
22
23#define TUNER_FREQ_MIN_FM 76000000U
24#define TUNER_FREQ_MAX_FM 108000000U
25
26#define MAX_PREEMPHASIS (V4L2_PREEMPHASIS_75_uS + 1)
27static int preemphasis[MAX_PREEMPHASIS] = {
28 TLG_TUNE_ASTD_NONE, /* V4L2_PREEMPHASIS_DISABLED */
29 TLG_TUNE_ASTD_FM_EUR, /* V4L2_PREEMPHASIS_50_uS */
30 TLG_TUNE_ASTD_FM_US, /* V4L2_PREEMPHASIS_75_uS */
31};
32
33static int poseidon_check_mode_radio(struct poseidon *p)
34{
35 int ret;
36 u32 status;
37
38 set_current_state(TASK_INTERRUPTIBLE);
39 schedule_timeout(HZ/2);
40 ret = usb_set_interface(p->udev, 0, BULK_ALTERNATE_IFACE);
41 if (ret < 0)
42 goto out;
43
44 ret = set_tuner_mode(p, TLG_MODE_FM_RADIO);
45 if (ret != 0)
46 goto out;
47
48 ret = send_set_req(p, SGNL_SRC_SEL, TLG_SIG_SRC_ANTENNA, &status);
49 ret = send_set_req(p, TUNER_AUD_ANA_STD,
50 p->radio_data.pre_emphasis, &status);
51 ret |= send_set_req(p, TUNER_AUD_MODE,
52 TLG_TUNE_TVAUDIO_MODE_STEREO, &status);
53 ret |= send_set_req(p, AUDIO_SAMPLE_RATE_SEL,
54 ATV_AUDIO_RATE_48K, &status);
55 ret |= send_set_req(p, TUNE_FREQ_SELECT, TUNER_FREQ_MIN_FM, &status);
56out:
57 return ret;
58}
59
60#ifdef CONFIG_PM
61static int pm_fm_suspend(struct poseidon *p)
62{
63 logpm(p);
64 pm_alsa_suspend(p);
65 usb_set_interface(p->udev, 0, 0);
66 msleep(300);
67 return 0;
68}
69
70static int pm_fm_resume(struct poseidon *p)
71{
72 logpm(p);
73 poseidon_check_mode_radio(p);
74 set_frequency(p, p->radio_data.fm_freq);
75 pm_alsa_resume(p);
76 return 0;
77}
78#endif
79
80static int poseidon_fm_open(struct file *filp)
81{
82 struct poseidon *p = video_drvdata(filp);
83 int ret = 0;
84
85 mutex_lock(&p->lock);
86 if (p->state & POSEIDON_STATE_DISCONNECT) {
87 ret = -ENODEV;
88 goto out;
89 }
90
91 if (p->state && !(p->state & POSEIDON_STATE_FM)) {
92 ret = -EBUSY;
93 goto out;
94 }
95 ret = v4l2_fh_open(filp);
96 if (ret)
97 goto out;
98
99 usb_autopm_get_interface(p->interface);
100 if (0 == p->state) {
101 struct video_device *vfd = &p->radio_data.fm_dev;
102
103 /* default pre-emphasis */
104 if (p->radio_data.pre_emphasis == 0)
105 p->radio_data.pre_emphasis = TLG_TUNE_ASTD_FM_EUR;
106 set_debug_mode(vfd, debug_mode);
107
108 ret = poseidon_check_mode_radio(p);
109 if (ret < 0) {
110 usb_autopm_put_interface(p->interface);
111 goto out;
112 }
113 p->state |= POSEIDON_STATE_FM;
114 }
115 kref_get(&p->kref);
116out:
117 mutex_unlock(&p->lock);
118 return ret;
119}
120
121static int poseidon_fm_close(struct file *filp)
122{
123 struct poseidon *p = video_drvdata(filp);
124 struct radio_data *fm = &p->radio_data;
125 uint32_t status;
126
127 mutex_lock(&p->lock);
128 if (v4l2_fh_is_singular_file(filp))
129 p->state &= ~POSEIDON_STATE_FM;
130
131 if (fm->is_radio_streaming && filp == p->file_for_stream) {
132 fm->is_radio_streaming = 0;
133 send_set_req(p, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP, &status);
134 }
135 usb_autopm_put_interface(p->interface);
136 mutex_unlock(&p->lock);
137
138 kref_put(&p->kref, poseidon_delete);
139 return v4l2_fh_release(filp);
140}
141
142static int vidioc_querycap(struct file *file, void *priv,
143 struct v4l2_capability *v)
144{
145 struct poseidon *p = video_drvdata(file);
146
147 strlcpy(v->driver, "tele-radio", sizeof(v->driver));
148 strlcpy(v->card, "Telegent Poseidon", sizeof(v->card));
149 usb_make_path(p->udev, v->bus_info, sizeof(v->bus_info));
150 v->device_caps = V4L2_CAP_TUNER | V4L2_CAP_RADIO;
151 /* Report all capabilities of the USB device */
152 v->capabilities = v->device_caps | V4L2_CAP_DEVICE_CAPS |
153 V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_VBI_CAPTURE |
154 V4L2_CAP_AUDIO | V4L2_CAP_STREAMING |
155 V4L2_CAP_READWRITE;
156 return 0;
157}
158
159static const struct v4l2_file_operations poseidon_fm_fops = {
160 .owner = THIS_MODULE,
161 .open = poseidon_fm_open,
162 .release = poseidon_fm_close,
163 .poll = v4l2_ctrl_poll,
164 .unlocked_ioctl = video_ioctl2,
165};
166
167static int tlg_fm_vidioc_g_tuner(struct file *file, void *priv,
168 struct v4l2_tuner *vt)
169{
170 struct poseidon *p = video_drvdata(file);
171 struct tuner_fm_sig_stat_s fm_stat = {};
172 int ret, status, count = 5;
173
174 if (vt->index != 0)
175 return -EINVAL;
176
177 vt->type = V4L2_TUNER_RADIO;
178 vt->capability = V4L2_TUNER_CAP_STEREO | V4L2_TUNER_CAP_LOW;
179 vt->rangelow = TUNER_FREQ_MIN_FM * 2 / 125;
180 vt->rangehigh = TUNER_FREQ_MAX_FM * 2 / 125;
181 vt->rxsubchans = V4L2_TUNER_SUB_STEREO;
182 vt->audmode = V4L2_TUNER_MODE_STEREO;
183 vt->signal = 0;
184 vt->afc = 0;
185 strlcpy(vt->name, "Radio", sizeof(vt->name));
186
187 mutex_lock(&p->lock);
188 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO,
189 &fm_stat, &status, sizeof(fm_stat));
190
191 while (fm_stat.sig_lock_busy && count-- && !ret) {
192 set_current_state(TASK_INTERRUPTIBLE);
193 schedule_timeout(HZ);
194
195 ret = send_get_req(p, TUNER_STATUS, TLG_MODE_FM_RADIO,
196 &fm_stat, &status, sizeof(fm_stat));
197 }
198 mutex_unlock(&p->lock);
199
200 if (ret || status) {
201 vt->signal = 0;
202 } else if ((fm_stat.sig_present || fm_stat.sig_locked)
203 && fm_stat.sig_strength == 0) {
204 vt->signal = 0xffff;
205 } else
206 vt->signal = (fm_stat.sig_strength * 255 / 10) << 8;
207
208 return 0;
209}
210
211static int fm_get_freq(struct file *file, void *priv,
212 struct v4l2_frequency *argp)
213{
214 struct poseidon *p = video_drvdata(file);
215
216 if (argp->tuner)
217 return -EINVAL;
218 argp->frequency = p->radio_data.fm_freq;
219 return 0;
220}
221
222static int set_frequency(struct poseidon *p, __u32 frequency)
223{
224 __u32 freq ;
225 int ret, status;
226
227 mutex_lock(&p->lock);
228
229 ret = send_set_req(p, TUNER_AUD_ANA_STD,
230 p->radio_data.pre_emphasis, &status);
231
232 freq = (frequency * 125) / 2; /* Hz */
233 freq = clamp(freq, TUNER_FREQ_MIN_FM, TUNER_FREQ_MAX_FM);
234
235 ret = send_set_req(p, TUNE_FREQ_SELECT, freq, &status);
236 if (ret < 0)
237 goto error ;
238 ret = send_set_req(p, TAKE_REQUEST, 0, &status);
239
240 set_current_state(TASK_INTERRUPTIBLE);
241 schedule_timeout(HZ/4);
242 if (!p->radio_data.is_radio_streaming) {
243 ret = send_set_req(p, TAKE_REQUEST, 0, &status);
244 ret = send_set_req(p, PLAY_SERVICE,
245 TLG_TUNE_PLAY_SVC_START, &status);
246 p->radio_data.is_radio_streaming = 1;
247 }
248 p->radio_data.fm_freq = freq * 2 / 125;
249error:
250 mutex_unlock(&p->lock);
251 return ret;
252}
253
254static int fm_set_freq(struct file *file, void *priv,
255 const struct v4l2_frequency *argp)
256{
257 struct poseidon *p = video_drvdata(file);
258
259 if (argp->tuner)
260 return -EINVAL;
261 p->file_for_stream = file;
262#ifdef CONFIG_PM
263 p->pm_suspend = pm_fm_suspend;
264 p->pm_resume = pm_fm_resume;
265#endif
266 return set_frequency(p, argp->frequency);
267}
268
269static int tlg_fm_s_ctrl(struct v4l2_ctrl *ctrl)
270{
271 struct poseidon *p = container_of(ctrl->handler, struct poseidon,
272 radio_data.ctrl_handler);
273 int pre_emphasis;
274 u32 status;
275
276 switch (ctrl->id) {
277 case V4L2_CID_TUNE_PREEMPHASIS:
278 pre_emphasis = preemphasis[ctrl->val];
279 send_set_req(p, TUNER_AUD_ANA_STD, pre_emphasis, &status);
280 p->radio_data.pre_emphasis = pre_emphasis;
281 return 0;
282 }
283 return -EINVAL;
284}
285
286static int vidioc_s_tuner(struct file *file, void *priv, const struct v4l2_tuner *vt)
287{
288 return vt->index > 0 ? -EINVAL : 0;
289}
290
291static const struct v4l2_ctrl_ops tlg_fm_ctrl_ops = {
292 .s_ctrl = tlg_fm_s_ctrl,
293};
294
295static const struct v4l2_ioctl_ops poseidon_fm_ioctl_ops = {
296 .vidioc_querycap = vidioc_querycap,
297 .vidioc_s_tuner = vidioc_s_tuner,
298 .vidioc_g_tuner = tlg_fm_vidioc_g_tuner,
299 .vidioc_g_frequency = fm_get_freq,
300 .vidioc_s_frequency = fm_set_freq,
301 .vidioc_subscribe_event = v4l2_ctrl_subscribe_event,
302 .vidioc_unsubscribe_event = v4l2_event_unsubscribe,
303};
304
305static struct video_device poseidon_fm_template = {
306 .name = "Telegent-Radio",
307 .fops = &poseidon_fm_fops,
308 .minor = -1,
309 .release = video_device_release_empty,
310 .ioctl_ops = &poseidon_fm_ioctl_ops,
311};
312
313int poseidon_fm_init(struct poseidon *p)
314{
315 struct video_device *vfd = &p->radio_data.fm_dev;
316 struct v4l2_ctrl_handler *hdl = &p->radio_data.ctrl_handler;
317
318 *vfd = poseidon_fm_template;
319
320 set_frequency(p, TUNER_FREQ_MIN_FM);
321 v4l2_ctrl_handler_init(hdl, 1);
322 v4l2_ctrl_new_std_menu(hdl, &tlg_fm_ctrl_ops, V4L2_CID_TUNE_PREEMPHASIS,
323 V4L2_PREEMPHASIS_75_uS, 0, V4L2_PREEMPHASIS_50_uS);
324 if (hdl->error) {
325 v4l2_ctrl_handler_free(hdl);
326 return hdl->error;
327 }
328 vfd->v4l2_dev = &p->v4l2_dev;
329 vfd->ctrl_handler = hdl;
330 video_set_drvdata(vfd, p);
331 return video_register_device(vfd, VFL_TYPE_RADIO, -1);
332}
333
334int poseidon_fm_exit(struct poseidon *p)
335{
336 video_unregister_device(&p->radio_data.fm_dev);
337 v4l2_ctrl_handler_free(&p->radio_data.ctrl_handler);
338 return 0;
339}
diff --git a/drivers/staging/media/tlg2300/pd-video.c b/drivers/staging/media/tlg2300/pd-video.c
deleted file mode 100644
index 8cd7f02fcf9f..000000000000
--- a/drivers/staging/media/tlg2300/pd-video.c
+++ /dev/null
@@ -1,1570 +0,0 @@
1#include <linux/fs.h>
2#include <linux/vmalloc.h>
3#include <linux/videodev2.h>
4#include <linux/usb.h>
5#include <linux/mm.h>
6#include <linux/sched.h>
7#include <linux/slab.h>
8
9#include <media/v4l2-ioctl.h>
10#include <media/v4l2-dev.h>
11#include <media/v4l2-ctrls.h>
12
13#include "pd-common.h"
14#include "vendorcmds.h"
15
16#ifdef CONFIG_PM
17static int pm_video_suspend(struct poseidon *pd);
18static int pm_video_resume(struct poseidon *pd);
19#endif
20static void iso_bubble_handler(struct work_struct *w);
21
22static int usb_transfer_mode;
23module_param(usb_transfer_mode, int, 0644);
24MODULE_PARM_DESC(usb_transfer_mode, "0 = Bulk, 1 = Isochronous");
25
26static const struct poseidon_format poseidon_formats[] = {
27 { "YUV 422", V4L2_PIX_FMT_YUYV, 16, 0},
28 { "RGB565", V4L2_PIX_FMT_RGB565, 16, 0},
29};
30
31static const struct poseidon_tvnorm poseidon_tvnorms[] = {
32 { V4L2_STD_PAL_D, "PAL-D", TLG_TUNE_VSTD_PAL_D },
33 { V4L2_STD_PAL_B, "PAL-B", TLG_TUNE_VSTD_PAL_B },
34 { V4L2_STD_PAL_G, "PAL-G", TLG_TUNE_VSTD_PAL_G },
35 { V4L2_STD_PAL_H, "PAL-H", TLG_TUNE_VSTD_PAL_H },
36 { V4L2_STD_PAL_I, "PAL-I", TLG_TUNE_VSTD_PAL_I },
37 { V4L2_STD_PAL_M, "PAL-M", TLG_TUNE_VSTD_PAL_M },
38 { V4L2_STD_PAL_N, "PAL-N", TLG_TUNE_VSTD_PAL_N_COMBO },
39 { V4L2_STD_PAL_Nc, "PAL-Nc", TLG_TUNE_VSTD_PAL_N_COMBO },
40 { V4L2_STD_NTSC_M, "NTSC-M", TLG_TUNE_VSTD_NTSC_M },
41 { V4L2_STD_NTSC_M_JP, "NTSC-JP", TLG_TUNE_VSTD_NTSC_M_J },
42 { V4L2_STD_SECAM_B, "SECAM-B", TLG_TUNE_VSTD_SECAM_B },
43 { V4L2_STD_SECAM_D, "SECAM-D", TLG_TUNE_VSTD_SECAM_D },
44 { V4L2_STD_SECAM_G, "SECAM-G", TLG_TUNE_VSTD_SECAM_G },
45 { V4L2_STD_SECAM_H, "SECAM-H", TLG_TUNE_VSTD_SECAM_H },
46 { V4L2_STD_SECAM_K, "SECAM-K", TLG_TUNE_VSTD_SECAM_K },
47 { V4L2_STD_SECAM_K1, "SECAM-K1", TLG_TUNE_VSTD_SECAM_K1 },
48 { V4L2_STD_SECAM_L, "SECAM-L", TLG_TUNE_VSTD_SECAM_L },
49 { V4L2_STD_SECAM_LC, "SECAM-LC", TLG_TUNE_VSTD_SECAM_L1 },
50};
51static const unsigned int POSEIDON_TVNORMS = ARRAY_SIZE(poseidon_tvnorms);
52
53struct pd_audio_mode {
54 u32 tlg_audio_mode;
55 u32 v4l2_audio_sub;
56 u32 v4l2_audio_mode;
57};
58
59static const struct pd_audio_mode pd_audio_modes[] = {
60 { TLG_TUNE_TVAUDIO_MODE_MONO, V4L2_TUNER_SUB_MONO,
61 V4L2_TUNER_MODE_MONO },
62 { TLG_TUNE_TVAUDIO_MODE_STEREO, V4L2_TUNER_SUB_STEREO,
63 V4L2_TUNER_MODE_STEREO },
64 { TLG_TUNE_TVAUDIO_MODE_LANG_A, V4L2_TUNER_SUB_LANG1,
65 V4L2_TUNER_MODE_LANG1 },
66 { TLG_TUNE_TVAUDIO_MODE_LANG_B, V4L2_TUNER_SUB_LANG2,
67 V4L2_TUNER_MODE_LANG2 },
68 { TLG_TUNE_TVAUDIO_MODE_LANG_C, V4L2_TUNER_SUB_LANG1,
69 V4L2_TUNER_MODE_LANG1_LANG2 }
70};
71static const unsigned int POSEIDON_AUDIOMODS = ARRAY_SIZE(pd_audio_modes);
72
73struct pd_input {
74 char *name;
75 uint32_t tlg_src;
76};
77
78static const struct pd_input pd_inputs[] = {
79 { "TV Antenna", TLG_SIG_SRC_ANTENNA },
80 { "TV Cable", TLG_SIG_SRC_CABLE },
81 { "TV SVideo", TLG_SIG_SRC_SVIDEO },
82 { "TV Composite", TLG_SIG_SRC_COMPOSITE }
83};
84static const unsigned int POSEIDON_INPUTS = ARRAY_SIZE(pd_inputs);
85
86struct video_std_to_audio_std {
87 v4l2_std_id video_std;
88 int audio_std;
89};
90
91static const struct video_std_to_audio_std video_to_audio_map[] = {
92 /* country : { 27, 32, 33, 34, 36, 44, 45, 46, 47, 48, 64,
93 65, 86, 351, 352, 353, 354, 358, 372, 852, 972 } */
94 { (V4L2_STD_PAL_I | V4L2_STD_PAL_B | V4L2_STD_PAL_D |
95 V4L2_STD_SECAM_L | V4L2_STD_SECAM_D), TLG_TUNE_ASTD_NICAM },
96
97 /* country : { 1, 52, 54, 55, 886 } */
98 {V4L2_STD_NTSC_M | V4L2_STD_PAL_N | V4L2_STD_PAL_M, TLG_TUNE_ASTD_BTSC},
99
100 /* country : { 81 } */
101 { V4L2_STD_NTSC_M_JP, TLG_TUNE_ASTD_EIAJ },
102
103 /* other country : TLG_TUNE_ASTD_A2 */
104};
105static const unsigned int map_size = ARRAY_SIZE(video_to_audio_map);
106
107static int get_audio_std(v4l2_std_id v4l2_std)
108{
109 int i = 0;
110
111 for (; i < map_size; i++) {
112 if (v4l2_std & video_to_audio_map[i].video_std)
113 return video_to_audio_map[i].audio_std;
114 }
115 return TLG_TUNE_ASTD_A2;
116}
117
118static int vidioc_querycap(struct file *file, void *fh,
119 struct v4l2_capability *cap)
120{
121 struct video_device *vdev = video_devdata(file);
122 struct poseidon *p = video_get_drvdata(vdev);
123
124 strcpy(cap->driver, "tele-video");
125 strcpy(cap->card, "Telegent Poseidon");
126 usb_make_path(p->udev, cap->bus_info, sizeof(cap->bus_info));
127 cap->device_caps = V4L2_CAP_TUNER | V4L2_CAP_AUDIO |
128 V4L2_CAP_STREAMING | V4L2_CAP_READWRITE;
129 if (vdev->vfl_type == VFL_TYPE_VBI)
130 cap->device_caps |= V4L2_CAP_VBI_CAPTURE;
131 else
132 cap->device_caps |= V4L2_CAP_VIDEO_CAPTURE;
133 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS |
134 V4L2_CAP_RADIO | V4L2_CAP_VBI_CAPTURE | V4L2_CAP_VIDEO_CAPTURE;
135 return 0;
136}
137
138/*====================================================================*/
139static void init_copy(struct video_data *video, bool index)
140{
141 struct front_face *front = video->front;
142
143 video->field_count = index;
144 video->lines_copied = 0;
145 video->prev_left = 0 ;
146 video->dst = (char *)videobuf_to_vmalloc(front->curr_frame)
147 + index * video->lines_size;
148 video->vbi->copied = 0; /* set it here */
149}
150
151static bool get_frame(struct front_face *front, int *need_init)
152{
153 struct videobuf_buffer *vb = front->curr_frame;
154
155 if (vb)
156 return true;
157
158 spin_lock(&front->queue_lock);
159 if (!list_empty(&front->active)) {
160 vb = list_entry(front->active.next,
161 struct videobuf_buffer, queue);
162 if (need_init)
163 *need_init = 1;
164 front->curr_frame = vb;
165 list_del_init(&vb->queue);
166 }
167 spin_unlock(&front->queue_lock);
168
169 return !!vb;
170}
171
172/* check if the video's buffer is ready */
173static bool get_video_frame(struct front_face *front, struct video_data *video)
174{
175 int need_init = 0;
176 bool ret = true;
177
178 ret = get_frame(front, &need_init);
179 if (ret && need_init)
180 init_copy(video, 0);
181 return ret;
182}
183
184static void submit_frame(struct front_face *front)
185{
186 struct videobuf_buffer *vb = front->curr_frame;
187
188 if (vb == NULL)
189 return;
190
191 front->curr_frame = NULL;
192 vb->state = VIDEOBUF_DONE;
193 vb->field_count++;
194 v4l2_get_timestamp(&vb->ts);
195
196 wake_up(&vb->done);
197}
198
199/*
200 * A frame is composed of two fields. If we receive all the two fields,
201 * call the submit_frame() to submit the whole frame to applications.
202 */
203static void end_field(struct video_data *video)
204{
205 if (1 == video->field_count)
206 submit_frame(video->front);
207 else
208 init_copy(video, 1);
209}
210
211static void copy_video_data(struct video_data *video, char *src,
212 unsigned int count)
213{
214#define copy_data(len) \
215 do { \
216 if (++video->lines_copied > video->lines_per_field) \
217 goto overflow; \
218 memcpy(video->dst, src, len);\
219 video->dst += len + video->lines_size; \
220 src += len; \
221 count -= len; \
222 } while (0)
223
224 while (count && count >= video->lines_size) {
225 if (video->prev_left) {
226 copy_data(video->prev_left);
227 video->prev_left = 0;
228 continue;
229 }
230 copy_data(video->lines_size);
231 }
232 if (count && count < video->lines_size) {
233 memcpy(video->dst, src, count);
234
235 video->prev_left = video->lines_size - count;
236 video->dst += count;
237 }
238 return;
239
240overflow:
241 end_field(video);
242}
243
244static void check_trailer(struct video_data *video, char *src, int count)
245{
246 struct vbi_data *vbi = video->vbi;
247 int offset; /* trailer's offset */
248 char *buf;
249
250 offset = (video->context.pix.sizeimage / 2 + vbi->vbi_size / 2)
251 - (vbi->copied + video->lines_size * video->lines_copied);
252 if (video->prev_left)
253 offset -= (video->lines_size - video->prev_left);
254
255 if (offset > count || offset <= 0)
256 goto short_package;
257
258 buf = src + offset;
259
260 /* trailer : (VFHS) + U32 + U32 + field_num */
261 if (!strncmp(buf, "VFHS", 4)) {
262 int field_num = *((u32 *)(buf + 12));
263
264 if ((field_num & 1) ^ video->field_count) {
265 init_copy(video, video->field_count);
266 return;
267 }
268 copy_video_data(video, src, offset);
269 }
270short_package:
271 end_field(video);
272}
273
274/* ========== Check this more carefully! =========== */
275static inline void copy_vbi_data(struct vbi_data *vbi,
276 char *src, unsigned int count)
277{
278 struct front_face *front = vbi->front;
279
280 if (front && get_frame(front, NULL)) {
281 char *buf = videobuf_to_vmalloc(front->curr_frame);
282
283 if (vbi->video->field_count)
284 buf += (vbi->vbi_size / 2);
285 memcpy(buf + vbi->copied, src, count);
286 }
287 vbi->copied += count;
288}
289
290/*
291 * Copy the normal data (VBI or VIDEO) without the trailer.
292 * VBI is not interlaced, while VIDEO is interlaced.
293 */
294static inline void copy_vbi_video_data(struct video_data *video,
295 char *src, unsigned int count)
296{
297 struct vbi_data *vbi = video->vbi;
298 unsigned int vbi_delta = (vbi->vbi_size / 2) - vbi->copied;
299
300 if (vbi_delta >= count) {
301 copy_vbi_data(vbi, src, count);
302 } else {
303 if (vbi_delta) {
304 copy_vbi_data(vbi, src, vbi_delta);
305
306 /* we receive the two fields of the VBI*/
307 if (vbi->front && video->field_count)
308 submit_frame(vbi->front);
309 }
310 copy_video_data(video, src + vbi_delta, count - vbi_delta);
311 }
312}
313
314static void urb_complete_bulk(struct urb *urb)
315{
316 struct front_face *front = urb->context;
317 struct video_data *video = &front->pd->video_data;
318 char *src = (char *)urb->transfer_buffer;
319 int count = urb->actual_length;
320 int ret = 0;
321
322 if (!video->is_streaming || urb->status) {
323 if (urb->status == -EPROTO)
324 goto resend_it;
325 return;
326 }
327 if (!get_video_frame(front, video))
328 goto resend_it;
329
330 if (count == urb->transfer_buffer_length)
331 copy_vbi_video_data(video, src, count);
332 else
333 check_trailer(video, src, count);
334
335resend_it:
336 ret = usb_submit_urb(urb, GFP_ATOMIC);
337 if (ret)
338 log(" submit failed: error %d", ret);
339}
340
341/************************* for ISO *********************/
342#define GET_SUCCESS (0)
343#define GET_TRAILER (1)
344#define GET_TOO_MUCH_BUBBLE (2)
345#define GET_NONE (3)
346static int get_chunk(int start, struct urb *urb,
347 int *head, int *tail, int *bubble_err)
348{
349 struct usb_iso_packet_descriptor *pkt = NULL;
350 int ret = GET_SUCCESS;
351
352 for (*head = *tail = -1; start < urb->number_of_packets; start++) {
353 pkt = &urb->iso_frame_desc[start];
354
355 /* handle the bubble of the Hub */
356 if (-EOVERFLOW == pkt->status) {
357 if (++*bubble_err > urb->number_of_packets / 3)
358 return GET_TOO_MUCH_BUBBLE;
359 continue;
360 }
361
362 /* This is the gap */
363 if (pkt->status || pkt->actual_length <= 0
364 || pkt->actual_length > ISO_PKT_SIZE) {
365 if (*head != -1)
366 break;
367 continue;
368 }
369
370 /* a good isochronous packet */
371 if (pkt->actual_length == ISO_PKT_SIZE) {
372 if (*head == -1)
373 *head = start;
374 *tail = start;
375 continue;
376 }
377
378 /* trailer is here */
379 if (pkt->actual_length < ISO_PKT_SIZE) {
380 if (*head == -1) {
381 *head = start;
382 *tail = start;
383 return GET_TRAILER;
384 }
385 break;
386 }
387 }
388
389 if (*head == -1 && *tail == -1)
390 ret = GET_NONE;
391 return ret;
392}
393
394/*
395 * |__|------|___|-----|_______|
396 * ^ ^
397 * | |
398 * gap gap
399 */
400static void urb_complete_iso(struct urb *urb)
401{
402 struct front_face *front = urb->context;
403 struct video_data *video = &front->pd->video_data;
404 int bubble_err = 0, head = 0, tail = 0;
405 char *src = (char *)urb->transfer_buffer;
406 int ret = 0;
407
408 if (!video->is_streaming)
409 return;
410
411 do {
412 if (!get_video_frame(front, video))
413 goto out;
414
415 switch (get_chunk(head, urb, &head, &tail, &bubble_err)) {
416 case GET_SUCCESS:
417 copy_vbi_video_data(video, src + (head * ISO_PKT_SIZE),
418 (tail - head + 1) * ISO_PKT_SIZE);
419 break;
420 case GET_TRAILER:
421 check_trailer(video, src + (head * ISO_PKT_SIZE),
422 ISO_PKT_SIZE);
423 break;
424 case GET_NONE:
425 goto out;
426 case GET_TOO_MUCH_BUBBLE:
427 log("\t We got too much bubble");
428 schedule_work(&video->bubble_work);
429 return;
430 }
431 } while (head = tail + 1, head < urb->number_of_packets);
432
433out:
434 ret = usb_submit_urb(urb, GFP_ATOMIC);
435 if (ret)
436 log("usb_submit_urb err : %d", ret);
437}
438/*============================= [ end ] =====================*/
439
440static int prepare_iso_urb(struct video_data *video)
441{
442 struct usb_device *udev = video->pd->udev;
443 int i;
444
445 if (video->urb_array[0])
446 return 0;
447
448 for (i = 0; i < SBUF_NUM; i++) {
449 struct urb *urb;
450 void *mem;
451 int j;
452
453 urb = usb_alloc_urb(PK_PER_URB, GFP_KERNEL);
454 if (urb == NULL)
455 goto out;
456
457 video->urb_array[i] = urb;
458 mem = usb_alloc_coherent(udev,
459 ISO_PKT_SIZE * PK_PER_URB,
460 GFP_KERNEL,
461 &urb->transfer_dma);
462
463 urb->complete = urb_complete_iso; /* handler */
464 urb->dev = udev;
465 urb->context = video->front;
466 urb->pipe = usb_rcvisocpipe(udev,
467 video->endpoint_addr);
468 urb->interval = 1;
469 urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
470 urb->number_of_packets = PK_PER_URB;
471 urb->transfer_buffer = mem;
472 urb->transfer_buffer_length = PK_PER_URB * ISO_PKT_SIZE;
473
474 for (j = 0; j < PK_PER_URB; j++) {
475 urb->iso_frame_desc[j].offset = ISO_PKT_SIZE * j;
476 urb->iso_frame_desc[j].length = ISO_PKT_SIZE;
477 }
478 }
479 return 0;
480out:
481 for (; i > 0; i--)
482 ;
483 return -ENOMEM;
484}
485
486/* return the succeeded number of the allocation */
487int alloc_bulk_urbs_generic(struct urb **urb_array, int num,
488 struct usb_device *udev, u8 ep_addr,
489 int buf_size, gfp_t gfp_flags,
490 usb_complete_t complete_fn, void *context)
491{
492 int i = 0;
493
494 for (; i < num; i++) {
495 void *mem;
496 struct urb *urb = usb_alloc_urb(0, gfp_flags);
497 if (urb == NULL)
498 return i;
499
500 mem = usb_alloc_coherent(udev, buf_size, gfp_flags,
501 &urb->transfer_dma);
502 if (mem == NULL) {
503 usb_free_urb(urb);
504 return i;
505 }
506
507 usb_fill_bulk_urb(urb, udev, usb_rcvbulkpipe(udev, ep_addr),
508 mem, buf_size, complete_fn, context);
509 urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
510 urb_array[i] = urb;
511 }
512 return i;
513}
514
515void free_all_urb_generic(struct urb **urb_array, int num)
516{
517 int i;
518 struct urb *urb;
519
520 for (i = 0; i < num; i++) {
521 urb = urb_array[i];
522 if (urb) {
523 usb_free_coherent(urb->dev,
524 urb->transfer_buffer_length,
525 urb->transfer_buffer,
526 urb->transfer_dma);
527 usb_free_urb(urb);
528 urb_array[i] = NULL;
529 }
530 }
531}
532
533static int prepare_bulk_urb(struct video_data *video)
534{
535 if (video->urb_array[0])
536 return 0;
537
538 alloc_bulk_urbs_generic(video->urb_array, SBUF_NUM,
539 video->pd->udev, video->endpoint_addr,
540 0x2000, GFP_KERNEL,
541 urb_complete_bulk, video->front);
542 return 0;
543}
544
545/* free the URBs */
546static void free_all_urb(struct video_data *video)
547{
548 free_all_urb_generic(video->urb_array, SBUF_NUM);
549}
550
551static void pd_buf_release(struct videobuf_queue *q, struct videobuf_buffer *vb)
552{
553 videobuf_vmalloc_free(vb);
554 vb->state = VIDEOBUF_NEEDS_INIT;
555}
556
557static void pd_buf_queue(struct videobuf_queue *q, struct videobuf_buffer *vb)
558{
559 struct front_face *front = q->priv_data;
560 vb->state = VIDEOBUF_QUEUED;
561 list_add_tail(&vb->queue, &front->active);
562}
563
564static int pd_buf_prepare(struct videobuf_queue *q, struct videobuf_buffer *vb,
565 enum v4l2_field field)
566{
567 struct front_face *front = q->priv_data;
568 int rc;
569
570 switch (front->type) {
571 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
572 if (VIDEOBUF_NEEDS_INIT == vb->state) {
573 struct v4l2_pix_format *pix;
574
575 pix = &front->pd->video_data.context.pix;
576 vb->size = pix->sizeimage; /* real frame size */
577 vb->width = pix->width;
578 vb->height = pix->height;
579 rc = videobuf_iolock(q, vb, NULL);
580 if (rc < 0)
581 return rc;
582 }
583 break;
584 case V4L2_BUF_TYPE_VBI_CAPTURE:
585 if (VIDEOBUF_NEEDS_INIT == vb->state) {
586 vb->size = front->pd->vbi_data.vbi_size;
587 rc = videobuf_iolock(q, vb, NULL);
588 if (rc < 0)
589 return rc;
590 }
591 break;
592 default:
593 return -EINVAL;
594 }
595 vb->field = field;
596 vb->state = VIDEOBUF_PREPARED;
597 return 0;
598}
599
600static int fire_all_urb(struct video_data *video)
601{
602 int i, ret;
603
604 video->is_streaming = 1;
605
606 for (i = 0; i < SBUF_NUM; i++) {
607 ret = usb_submit_urb(video->urb_array[i], GFP_KERNEL);
608 if (ret)
609 log("(%d) failed: error %d", i, ret);
610 }
611 return ret;
612}
613
614static int start_video_stream(struct poseidon *pd)
615{
616 struct video_data *video = &pd->video_data;
617 s32 cmd_status;
618
619 send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
620 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_START, &cmd_status);
621
622 if (pd->cur_transfer_mode) {
623 prepare_iso_urb(video);
624 INIT_WORK(&video->bubble_work, iso_bubble_handler);
625 } else {
626 /* The bulk mode does not need a bubble handler */
627 prepare_bulk_urb(video);
628 }
629 fire_all_urb(video);
630 return 0;
631}
632
633static int pd_buf_setup(struct videobuf_queue *q, unsigned int *count,
634 unsigned int *size)
635{
636 struct front_face *front = q->priv_data;
637 struct poseidon *pd = front->pd;
638
639 switch (front->type) {
640 default:
641 return -EINVAL;
642 case V4L2_BUF_TYPE_VIDEO_CAPTURE: {
643 struct video_data *video = &pd->video_data;
644 struct v4l2_pix_format *pix = &video->context.pix;
645
646 *size = PAGE_ALIGN(pix->sizeimage);/* page aligned frame size */
647 if (*count < 4)
648 *count = 4;
649 if (1) {
650 /* same in different altersetting */
651 video->endpoint_addr = 0x82;
652 video->vbi = &pd->vbi_data;
653 video->vbi->video = video;
654 video->pd = pd;
655 video->lines_per_field = pix->height / 2;
656 video->lines_size = pix->width * 2;
657 video->front = front;
658 }
659 return start_video_stream(pd);
660 }
661
662 case V4L2_BUF_TYPE_VBI_CAPTURE: {
663 struct vbi_data *vbi = &pd->vbi_data;
664
665 *size = PAGE_ALIGN(vbi->vbi_size);
666 log("size : %d", *size);
667 if (*count == 0)
668 *count = 4;
669 }
670 break;
671 }
672 return 0;
673}
674
675static struct videobuf_queue_ops pd_video_qops = {
676 .buf_setup = pd_buf_setup,
677 .buf_prepare = pd_buf_prepare,
678 .buf_queue = pd_buf_queue,
679 .buf_release = pd_buf_release,
680};
681
682static int vidioc_enum_fmt(struct file *file, void *fh,
683 struct v4l2_fmtdesc *f)
684{
685 if (ARRAY_SIZE(poseidon_formats) <= f->index)
686 return -EINVAL;
687 f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
688 f->flags = 0;
689 f->pixelformat = poseidon_formats[f->index].fourcc;
690 strcpy(f->description, poseidon_formats[f->index].name);
691 return 0;
692}
693
694static int vidioc_g_fmt(struct file *file, void *fh, struct v4l2_format *f)
695{
696 struct front_face *front = fh;
697 struct poseidon *pd = front->pd;
698
699 f->fmt.pix = pd->video_data.context.pix;
700 return 0;
701}
702
703/*
704 * VLC calls VIDIOC_S_STD before VIDIOC_S_FMT, while
705 * Mplayer calls them in the reverse order.
706 */
707static int pd_vidioc_s_fmt(struct poseidon *pd, struct v4l2_pix_format *pix)
708{
709 struct video_data *video = &pd->video_data;
710 struct running_context *context = &video->context;
711 struct v4l2_pix_format *pix_def = &context->pix;
712 s32 ret = 0, cmd_status = 0, vid_resol;
713
714 /* set the pixel format to firmware */
715 if (pix->pixelformat == V4L2_PIX_FMT_RGB565) {
716 vid_resol = TLG_TUNER_VID_FORMAT_RGB_565;
717 } else {
718 pix->pixelformat = V4L2_PIX_FMT_YUYV;
719 vid_resol = TLG_TUNER_VID_FORMAT_YUV;
720 }
721 ret = send_set_req(pd, VIDEO_STREAM_FMT_SEL,
722 vid_resol, &cmd_status);
723
724 /* set the resolution to firmware */
725 vid_resol = TLG_TUNE_VID_RES_720;
726 switch (pix->width) {
727 case 704:
728 vid_resol = TLG_TUNE_VID_RES_704;
729 break;
730 default:
731 pix->width = 720;
732 case 720:
733 break;
734 }
735 ret |= send_set_req(pd, VIDEO_ROSOLU_SEL,
736 vid_resol, &cmd_status);
737 if (ret || cmd_status)
738 return -EBUSY;
739
740 pix_def->pixelformat = pix->pixelformat; /* save it */
741 pix->height = (context->tvnormid & V4L2_STD_525_60) ? 480 : 576;
742
743 /* Compare with the default setting */
744 if ((pix_def->width != pix->width)
745 || (pix_def->height != pix->height)) {
746 pix_def->width = pix->width;
747 pix_def->height = pix->height;
748 pix_def->bytesperline = pix->width * 2;
749 pix_def->sizeimage = pix->width * pix->height * 2;
750 }
751 *pix = *pix_def;
752
753 return 0;
754}
755
756static int vidioc_s_fmt(struct file *file, void *fh, struct v4l2_format *f)
757{
758 struct front_face *front = fh;
759 struct poseidon *pd = front->pd;
760
761 /* stop VBI here */
762 if (V4L2_BUF_TYPE_VIDEO_CAPTURE != f->type)
763 return -EINVAL;
764
765 mutex_lock(&pd->lock);
766 if (pd->file_for_stream == NULL)
767 pd->file_for_stream = file;
768 else if (file != pd->file_for_stream) {
769 mutex_unlock(&pd->lock);
770 return -EINVAL;
771 }
772
773 pd_vidioc_s_fmt(pd, &f->fmt.pix);
774 mutex_unlock(&pd->lock);
775 return 0;
776}
777
778static int vidioc_g_fmt_vbi(struct file *file, void *fh,
779 struct v4l2_format *v4l2_f)
780{
781 struct front_face *front = fh;
782 struct poseidon *pd = front->pd;
783 struct v4l2_vbi_format *vbi_fmt = &v4l2_f->fmt.vbi;
784
785 vbi_fmt->samples_per_line = 720 * 2;
786 vbi_fmt->sampling_rate = 6750000 * 4;
787 vbi_fmt->sample_format = V4L2_PIX_FMT_GREY;
788 vbi_fmt->offset = 64 * 4; /*FIXME: why offset */
789 if (pd->video_data.context.tvnormid & V4L2_STD_525_60) {
790 vbi_fmt->start[0] = 10;
791 vbi_fmt->start[1] = 264;
792 vbi_fmt->count[0] = V4L_NTSC_VBI_LINES;
793 vbi_fmt->count[1] = V4L_NTSC_VBI_LINES;
794 } else {
795 vbi_fmt->start[0] = 6;
796 vbi_fmt->start[1] = 314;
797 vbi_fmt->count[0] = V4L_PAL_VBI_LINES;
798 vbi_fmt->count[1] = V4L_PAL_VBI_LINES;
799 }
800 vbi_fmt->flags = V4L2_VBI_UNSYNC;
801 return 0;
802}
803
804static int set_std(struct poseidon *pd, v4l2_std_id norm)
805{
806 struct video_data *video = &pd->video_data;
807 struct vbi_data *vbi = &pd->vbi_data;
808 struct running_context *context;
809 struct v4l2_pix_format *pix;
810 s32 i, ret = 0, cmd_status, param;
811 int height;
812
813 for (i = 0; i < POSEIDON_TVNORMS; i++) {
814 if (norm & poseidon_tvnorms[i].v4l2_id) {
815 param = poseidon_tvnorms[i].tlg_tvnorm;
816 log("name : %s", poseidon_tvnorms[i].name);
817 goto found;
818 }
819 }
820 return -EINVAL;
821found:
822 mutex_lock(&pd->lock);
823 ret = send_set_req(pd, VIDEO_STD_SEL, param, &cmd_status);
824 if (ret || cmd_status)
825 goto out;
826
827 /* Set vbi size and check the height of the frame */
828 context = &video->context;
829 context->tvnormid = poseidon_tvnorms[i].v4l2_id;
830 if (context->tvnormid & V4L2_STD_525_60) {
831 vbi->vbi_size = V4L_NTSC_VBI_FRAMESIZE;
832 height = 480;
833 } else {
834 vbi->vbi_size = V4L_PAL_VBI_FRAMESIZE;
835 height = 576;
836 }
837
838 pix = &context->pix;
839 if (pix->height != height) {
840 pix->height = height;
841 pix->sizeimage = pix->width * pix->height * 2;
842 }
843
844out:
845 mutex_unlock(&pd->lock);
846 return ret;
847}
848
849static int vidioc_s_std(struct file *file, void *fh, v4l2_std_id norm)
850{
851 struct front_face *front = fh;
852
853 return set_std(front->pd, norm);
854}
855
856static int vidioc_g_std(struct file *file, void *fh, v4l2_std_id *norm)
857{
858 struct front_face *front = fh;
859
860 *norm = front->pd->video_data.context.tvnormid;
861 return 0;
862}
863
864static int vidioc_enum_input(struct file *file, void *fh, struct v4l2_input *in)
865{
866 if (in->index >= POSEIDON_INPUTS)
867 return -EINVAL;
868 strcpy(in->name, pd_inputs[in->index].name);
869 in->type = V4L2_INPUT_TYPE_TUNER;
870
871 /*
872 * the audio input index mixed with this video input,
873 * Poseidon only have one audio/video, set to "0"
874 */
875 in->audioset = 1;
876 in->tuner = 0;
877 in->std = V4L2_STD_ALL;
878 in->status = 0;
879 return 0;
880}
881
882static int vidioc_g_input(struct file *file, void *fh, unsigned int *i)
883{
884 struct front_face *front = fh;
885 struct poseidon *pd = front->pd;
886 struct running_context *context = &pd->video_data.context;
887
888 *i = context->sig_index;
889 return 0;
890}
891
892/* We can support several inputs */
893static int vidioc_s_input(struct file *file, void *fh, unsigned int i)
894{
895 struct front_face *front = fh;
896 struct poseidon *pd = front->pd;
897 s32 ret, cmd_status;
898
899 if (i >= POSEIDON_INPUTS)
900 return -EINVAL;
901 ret = send_set_req(pd, SGNL_SRC_SEL,
902 pd_inputs[i].tlg_src, &cmd_status);
903 if (ret)
904 return ret;
905
906 pd->video_data.context.sig_index = i;
907 return 0;
908}
909
910static int tlg_s_ctrl(struct v4l2_ctrl *c)
911{
912 struct poseidon *pd = container_of(c->handler, struct poseidon,
913 video_data.ctrl_handler);
914 struct tuner_custom_parameter_s param = {0};
915 s32 ret = 0, cmd_status, params;
916
917 switch (c->id) {
918 case V4L2_CID_BRIGHTNESS:
919 param.param_id = CUST_PARM_ID_BRIGHTNESS_CTRL;
920 break;
921 case V4L2_CID_CONTRAST:
922 param.param_id = CUST_PARM_ID_CONTRAST_CTRL;
923 break;
924 case V4L2_CID_HUE:
925 param.param_id = CUST_PARM_ID_HUE_CTRL;
926 break;
927 case V4L2_CID_SATURATION:
928 param.param_id = CUST_PARM_ID_SATURATION_CTRL;
929 break;
930 }
931 param.param_value = c->val;
932 params = *(s32 *)&param; /* temp code */
933
934 mutex_lock(&pd->lock);
935 ret = send_set_req(pd, TUNER_CUSTOM_PARAMETER, params, &cmd_status);
936 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
937 mutex_unlock(&pd->lock);
938
939 set_current_state(TASK_INTERRUPTIBLE);
940 schedule_timeout(HZ/4);
941 return ret;
942}
943
944/* Audio ioctls */
945static int vidioc_enumaudio(struct file *file, void *fh, struct v4l2_audio *a)
946{
947 if (0 != a->index)
948 return -EINVAL;
949 a->capability = V4L2_AUDCAP_STEREO;
950 strcpy(a->name, "USB audio in");
951 /*Poseidon have no AVL function.*/
952 a->mode = 0;
953 return 0;
954}
955
956static int vidioc_g_audio(struct file *file, void *fh, struct v4l2_audio *a)
957{
958 a->index = 0;
959 a->capability = V4L2_AUDCAP_STEREO;
960 strcpy(a->name, "USB audio in");
961 a->mode = 0;
962 return 0;
963}
964
965static int vidioc_s_audio(struct file *file, void *fh, const struct v4l2_audio *a)
966{
967 return (0 == a->index) ? 0 : -EINVAL;
968}
969
970/* Tuner ioctls */
971static int vidioc_g_tuner(struct file *file, void *fh, struct v4l2_tuner *tuner)
972{
973 struct front_face *front = fh;
974 struct poseidon *pd = front->pd;
975 struct tuner_atv_sig_stat_s atv_stat;
976 s32 count = 5, ret, cmd_status;
977 int index;
978
979 if (0 != tuner->index)
980 return -EINVAL;
981
982 mutex_lock(&pd->lock);
983 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_ANALOG_TV,
984 &atv_stat, &cmd_status, sizeof(atv_stat));
985
986 while (atv_stat.sig_lock_busy && count-- && !ret) {
987 set_current_state(TASK_INTERRUPTIBLE);
988 schedule_timeout(HZ);
989
990 ret = send_get_req(pd, TUNER_STATUS, TLG_MODE_ANALOG_TV,
991 &atv_stat, &cmd_status, sizeof(atv_stat));
992 }
993 mutex_unlock(&pd->lock);
994
995 if (debug_mode)
996 log("P:%d,S:%d", atv_stat.sig_present, atv_stat.sig_strength);
997
998 if (ret || cmd_status)
999 tuner->signal = 0;
1000 else if (atv_stat.sig_present && !atv_stat.sig_strength)
1001 tuner->signal = 0xFFFF;
1002 else
1003 tuner->signal = (atv_stat.sig_strength * 255 / 10) << 8;
1004
1005 strcpy(tuner->name, "Telegent Systems");
1006 tuner->type = V4L2_TUNER_ANALOG_TV;
1007 tuner->rangelow = TUNER_FREQ_MIN / 62500;
1008 tuner->rangehigh = TUNER_FREQ_MAX / 62500;
1009 tuner->capability = V4L2_TUNER_CAP_NORM | V4L2_TUNER_CAP_STEREO |
1010 V4L2_TUNER_CAP_LANG1 | V4L2_TUNER_CAP_LANG2;
1011 index = pd->video_data.context.audio_idx;
1012 tuner->rxsubchans = pd_audio_modes[index].v4l2_audio_sub;
1013 tuner->audmode = pd_audio_modes[index].v4l2_audio_mode;
1014 tuner->afc = 0;
1015 return 0;
1016}
1017
1018static int pd_vidioc_s_tuner(struct poseidon *pd, int index)
1019{
1020 s32 ret = 0, cmd_status, param, audiomode;
1021
1022 mutex_lock(&pd->lock);
1023 param = pd_audio_modes[index].tlg_audio_mode;
1024 ret = send_set_req(pd, TUNER_AUD_MODE, param, &cmd_status);
1025 audiomode = get_audio_std(pd->video_data.context.tvnormid);
1026 ret |= send_set_req(pd, TUNER_AUD_ANA_STD, audiomode,
1027 &cmd_status);
1028 if (!ret)
1029 pd->video_data.context.audio_idx = index;
1030 mutex_unlock(&pd->lock);
1031 return ret;
1032}
1033
1034static int vidioc_s_tuner(struct file *file, void *fh, const struct v4l2_tuner *a)
1035{
1036 struct front_face *front = fh;
1037 struct poseidon *pd = front->pd;
1038 int index;
1039
1040 if (0 != a->index)
1041 return -EINVAL;
1042 for (index = 0; index < POSEIDON_AUDIOMODS; index++)
1043 if (a->audmode == pd_audio_modes[index].v4l2_audio_mode)
1044 return pd_vidioc_s_tuner(pd, index);
1045 return -EINVAL;
1046}
1047
1048static int vidioc_g_frequency(struct file *file, void *fh,
1049 struct v4l2_frequency *freq)
1050{
1051 struct front_face *front = fh;
1052 struct poseidon *pd = front->pd;
1053 struct running_context *context = &pd->video_data.context;
1054
1055 if (0 != freq->tuner)
1056 return -EINVAL;
1057 freq->frequency = context->freq;
1058 freq->type = V4L2_TUNER_ANALOG_TV;
1059 return 0;
1060}
1061
1062static int set_frequency(struct poseidon *pd, u32 *frequency)
1063{
1064 s32 ret = 0, param, cmd_status;
1065 struct running_context *context = &pd->video_data.context;
1066
1067 *frequency = clamp(*frequency,
1068 TUNER_FREQ_MIN / 62500, TUNER_FREQ_MAX / 62500);
1069 param = (*frequency) * 62500 / 1000;
1070
1071 mutex_lock(&pd->lock);
1072 ret = send_set_req(pd, TUNE_FREQ_SELECT, param, &cmd_status);
1073 ret = send_set_req(pd, TAKE_REQUEST, 0, &cmd_status);
1074
1075 msleep(250); /* wait for a while until the hardware is ready. */
1076 context->freq = *frequency;
1077 mutex_unlock(&pd->lock);
1078 return ret;
1079}
1080
1081static int vidioc_s_frequency(struct file *file, void *fh,
1082 const struct v4l2_frequency *freq)
1083{
1084 struct front_face *front = fh;
1085 struct poseidon *pd = front->pd;
1086 u32 frequency = freq->frequency;
1087
1088 if (freq->tuner)
1089 return -EINVAL;
1090#ifdef CONFIG_PM
1091 pd->pm_suspend = pm_video_suspend;
1092 pd->pm_resume = pm_video_resume;
1093#endif
1094 return set_frequency(pd, &frequency);
1095}
1096
1097static int vidioc_reqbufs(struct file *file, void *fh,
1098 struct v4l2_requestbuffers *b)
1099{
1100 struct front_face *front = file->private_data;
1101 return videobuf_reqbufs(&front->q, b);
1102}
1103
1104static int vidioc_querybuf(struct file *file, void *fh, struct v4l2_buffer *b)
1105{
1106 struct front_face *front = file->private_data;
1107 return videobuf_querybuf(&front->q, b);
1108}
1109
1110static int vidioc_qbuf(struct file *file, void *fh, struct v4l2_buffer *b)
1111{
1112 struct front_face *front = file->private_data;
1113 return videobuf_qbuf(&front->q, b);
1114}
1115
1116static int vidioc_dqbuf(struct file *file, void *fh, struct v4l2_buffer *b)
1117{
1118 struct front_face *front = file->private_data;
1119 return videobuf_dqbuf(&front->q, b, file->f_flags & O_NONBLOCK);
1120}
1121
1122/* Just stop the URBs, do not free the URBs */
1123static int usb_transfer_stop(struct video_data *video)
1124{
1125 if (video->is_streaming) {
1126 int i;
1127 s32 cmd_status;
1128 struct poseidon *pd = video->pd;
1129
1130 video->is_streaming = 0;
1131 for (i = 0; i < SBUF_NUM; ++i) {
1132 if (video->urb_array[i])
1133 usb_kill_urb(video->urb_array[i]);
1134 }
1135
1136 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
1137 &cmd_status);
1138 }
1139 return 0;
1140}
1141
1142int stop_all_video_stream(struct poseidon *pd)
1143{
1144 struct video_data *video = &pd->video_data;
1145 struct vbi_data *vbi = &pd->vbi_data;
1146
1147 mutex_lock(&pd->lock);
1148 if (video->is_streaming) {
1149 struct front_face *front = video->front;
1150
1151 /* stop the URBs */
1152 usb_transfer_stop(video);
1153 free_all_urb(video);
1154
1155 /* stop the host side of VIDEO */
1156 videobuf_stop(&front->q);
1157 videobuf_mmap_free(&front->q);
1158
1159 /* stop the host side of VBI */
1160 front = vbi->front;
1161 if (front) {
1162 videobuf_stop(&front->q);
1163 videobuf_mmap_free(&front->q);
1164 }
1165 }
1166 mutex_unlock(&pd->lock);
1167 return 0;
1168}
1169
1170/*
1171 * The bubbles can seriously damage the video's quality,
1172 * though it occurs in very rare situation.
1173 */
1174static void iso_bubble_handler(struct work_struct *w)
1175{
1176 struct video_data *video;
1177 struct poseidon *pd;
1178
1179 video = container_of(w, struct video_data, bubble_work);
1180 pd = video->pd;
1181
1182 mutex_lock(&pd->lock);
1183 usb_transfer_stop(video);
1184 msleep(500);
1185 start_video_stream(pd);
1186 mutex_unlock(&pd->lock);
1187}
1188
1189
1190static int vidioc_streamon(struct file *file, void *fh,
1191 enum v4l2_buf_type type)
1192{
1193 struct front_face *front = fh;
1194
1195 if (unlikely(type != front->type))
1196 return -EINVAL;
1197 return videobuf_streamon(&front->q);
1198}
1199
1200static int vidioc_streamoff(struct file *file, void *fh,
1201 enum v4l2_buf_type type)
1202{
1203 struct front_face *front = file->private_data;
1204
1205 if (unlikely(type != front->type))
1206 return -EINVAL;
1207 return videobuf_streamoff(&front->q);
1208}
1209
1210/* Set the firmware's default values : need altersetting */
1211static int pd_video_checkmode(struct poseidon *pd)
1212{
1213 s32 ret = 0, cmd_status, audiomode;
1214
1215 set_current_state(TASK_INTERRUPTIBLE);
1216 schedule_timeout(HZ/2);
1217
1218 /* choose the altersetting */
1219 ret = usb_set_interface(pd->udev, 0,
1220 (pd->cur_transfer_mode ?
1221 ISO_3K_BULK_ALTERNATE_IFACE :
1222 BULK_ALTERNATE_IFACE));
1223 if (ret < 0)
1224 goto error;
1225
1226 /* set default parameters for PAL-D , with the VBI enabled*/
1227 ret = set_tuner_mode(pd, TLG_MODE_ANALOG_TV);
1228 ret |= send_set_req(pd, SGNL_SRC_SEL,
1229 TLG_SIG_SRC_ANTENNA, &cmd_status);
1230 ret |= send_set_req(pd, VIDEO_STD_SEL,
1231 TLG_TUNE_VSTD_PAL_D, &cmd_status);
1232 ret |= send_set_req(pd, VIDEO_STREAM_FMT_SEL,
1233 TLG_TUNER_VID_FORMAT_YUV, &cmd_status);
1234 ret |= send_set_req(pd, VIDEO_ROSOLU_SEL,
1235 TLG_TUNE_VID_RES_720, &cmd_status);
1236 ret |= send_set_req(pd, TUNE_FREQ_SELECT, TUNER_FREQ_MIN, &cmd_status);
1237 ret |= send_set_req(pd, VBI_DATA_SEL, 1, &cmd_status);/* enable vbi */
1238
1239 /* set the audio */
1240 audiomode = get_audio_std(pd->video_data.context.tvnormid);
1241 ret |= send_set_req(pd, TUNER_AUD_ANA_STD, audiomode, &cmd_status);
1242 ret |= send_set_req(pd, TUNER_AUD_MODE,
1243 TLG_TUNE_TVAUDIO_MODE_STEREO, &cmd_status);
1244 ret |= send_set_req(pd, AUDIO_SAMPLE_RATE_SEL,
1245 ATV_AUDIO_RATE_48K, &cmd_status);
1246error:
1247 return ret;
1248}
1249
1250#ifdef CONFIG_PM
1251static int pm_video_suspend(struct poseidon *pd)
1252{
1253 /* stop audio */
1254 pm_alsa_suspend(pd);
1255
1256 /* stop and free all the URBs */
1257 usb_transfer_stop(&pd->video_data);
1258 free_all_urb(&pd->video_data);
1259
1260 /* reset the interface */
1261 usb_set_interface(pd->udev, 0, 0);
1262 msleep(300);
1263 return 0;
1264}
1265
1266static int restore_v4l2_context(struct poseidon *pd,
1267 struct running_context *context)
1268{
1269 struct front_face *front = pd->video_data.front;
1270
1271 pd_video_checkmode(pd);
1272
1273 set_std(pd, context->tvnormid);
1274 vidioc_s_input(NULL, front, context->sig_index);
1275 pd_vidioc_s_tuner(pd, context->audio_idx);
1276 pd_vidioc_s_fmt(pd, &context->pix);
1277 set_frequency(pd, &context->freq);
1278 return 0;
1279}
1280
1281static int pm_video_resume(struct poseidon *pd)
1282{
1283 struct video_data *video = &pd->video_data;
1284
1285 /* resume the video */
1286 /* [1] restore the origin V4L2 parameters */
1287 restore_v4l2_context(pd, &video->context);
1288
1289 /* [2] initiate video copy variables */
1290 if (video->front->curr_frame)
1291 init_copy(video, 0);
1292
1293 /* [3] fire urbs */
1294 start_video_stream(pd);
1295
1296 /* resume the audio */
1297 pm_alsa_resume(pd);
1298 return 0;
1299}
1300#endif
1301
1302void set_debug_mode(struct video_device *vfd, int debug_mode)
1303{
1304 vfd->debug = 0;
1305 if (debug_mode & 0x1)
1306 vfd->debug = V4L2_DEBUG_IOCTL;
1307 if (debug_mode & 0x2)
1308 vfd->debug = V4L2_DEBUG_IOCTL | V4L2_DEBUG_IOCTL_ARG;
1309}
1310
1311static void init_video_context(struct running_context *context)
1312{
1313 context->sig_index = 0;
1314 context->audio_idx = 1; /* stereo */
1315 context->tvnormid = V4L2_STD_PAL_D;
1316 context->pix = (struct v4l2_pix_format) {
1317 .width = 720,
1318 .height = 576,
1319 .pixelformat = V4L2_PIX_FMT_YUYV,
1320 .field = V4L2_FIELD_INTERLACED,
1321 .bytesperline = 720 * 2,
1322 .sizeimage = 720 * 576 * 2,
1323 .colorspace = V4L2_COLORSPACE_SMPTE170M,
1324 };
1325}
1326
1327static int pd_video_open(struct file *file)
1328{
1329 struct video_device *vfd = video_devdata(file);
1330 struct poseidon *pd = video_get_drvdata(vfd);
1331 struct front_face *front = NULL;
1332 int ret = -ENOMEM;
1333
1334 mutex_lock(&pd->lock);
1335 usb_autopm_get_interface(pd->interface);
1336
1337 if (pd->state && !(pd->state & POSEIDON_STATE_ANALOG)) {
1338 ret = -EBUSY;
1339 goto out;
1340 }
1341 front = kzalloc(sizeof(struct front_face), GFP_KERNEL);
1342 if (!front)
1343 goto out;
1344 if (vfd->vfl_type == VFL_TYPE_GRABBER) {
1345 pd->cur_transfer_mode = usb_transfer_mode;/* bulk or iso */
1346 init_video_context(&pd->video_data.context);
1347
1348 ret = pd_video_checkmode(pd);
1349 if (ret < 0) {
1350 kfree(front);
1351 ret = -1;
1352 goto out;
1353 }
1354
1355 front->type = V4L2_BUF_TYPE_VIDEO_CAPTURE;
1356 pd->video_data.users++;
1357 set_debug_mode(vfd, debug_mode);
1358
1359 videobuf_queue_vmalloc_init(&front->q, &pd_video_qops,
1360 NULL, &front->queue_lock,
1361 V4L2_BUF_TYPE_VIDEO_CAPTURE,
1362 V4L2_FIELD_INTERLACED,/* video is interlacd */
1363 sizeof(struct videobuf_buffer),/*it's enough*/
1364 front, NULL);
1365 } else {
1366 front->type = V4L2_BUF_TYPE_VBI_CAPTURE;
1367 pd->vbi_data.front = front;
1368 pd->vbi_data.users++;
1369
1370 videobuf_queue_vmalloc_init(&front->q, &pd_video_qops,
1371 NULL, &front->queue_lock,
1372 V4L2_BUF_TYPE_VBI_CAPTURE,
1373 V4L2_FIELD_NONE, /* vbi is NONE mode */
1374 sizeof(struct videobuf_buffer),
1375 front, NULL);
1376 }
1377
1378 pd->state |= POSEIDON_STATE_ANALOG;
1379 front->pd = pd;
1380 front->curr_frame = NULL;
1381 INIT_LIST_HEAD(&front->active);
1382 spin_lock_init(&front->queue_lock);
1383
1384 file->private_data = front;
1385 kref_get(&pd->kref);
1386
1387 mutex_unlock(&pd->lock);
1388 return 0;
1389out:
1390 usb_autopm_put_interface(pd->interface);
1391 mutex_unlock(&pd->lock);
1392 return ret;
1393}
1394
1395static int pd_video_release(struct file *file)
1396{
1397 struct front_face *front = file->private_data;
1398 struct poseidon *pd = front->pd;
1399 s32 cmd_status = 0;
1400
1401 mutex_lock(&pd->lock);
1402
1403 if (front->type == V4L2_BUF_TYPE_VIDEO_CAPTURE) {
1404 /* stop the device, and free the URBs */
1405 usb_transfer_stop(&pd->video_data);
1406 free_all_urb(&pd->video_data);
1407
1408 /* stop the firmware */
1409 send_set_req(pd, PLAY_SERVICE, TLG_TUNE_PLAY_SVC_STOP,
1410 &cmd_status);
1411
1412 pd->file_for_stream = NULL;
1413 pd->video_data.users--;
1414 } else if (front->type == V4L2_BUF_TYPE_VBI_CAPTURE) {
1415 pd->vbi_data.front = NULL;
1416 pd->vbi_data.users--;
1417 }
1418 if (!pd->vbi_data.users && !pd->video_data.users)
1419 pd->state &= ~POSEIDON_STATE_ANALOG;
1420 videobuf_stop(&front->q);
1421 videobuf_mmap_free(&front->q);
1422
1423 usb_autopm_put_interface(pd->interface);
1424 mutex_unlock(&pd->lock);
1425
1426 kfree(front);
1427 file->private_data = NULL;
1428 kref_put(&pd->kref, poseidon_delete);
1429 return 0;
1430}
1431
1432static int pd_video_mmap(struct file *file, struct vm_area_struct *vma)
1433{
1434 struct front_face *front = file->private_data;
1435 return videobuf_mmap_mapper(&front->q, vma);
1436}
1437
1438static unsigned int pd_video_poll(struct file *file, poll_table *table)
1439{
1440 struct front_face *front = file->private_data;
1441 return videobuf_poll_stream(file, &front->q, table);
1442}
1443
1444static ssize_t pd_video_read(struct file *file, char __user *buffer,
1445 size_t count, loff_t *ppos)
1446{
1447 struct front_face *front = file->private_data;
1448 return videobuf_read_stream(&front->q, buffer, count, ppos,
1449 0, file->f_flags & O_NONBLOCK);
1450}
1451
1452/* This struct works for both VIDEO and VBI */
1453static const struct v4l2_file_operations pd_video_fops = {
1454 .owner = THIS_MODULE,
1455 .open = pd_video_open,
1456 .release = pd_video_release,
1457 .read = pd_video_read,
1458 .poll = pd_video_poll,
1459 .mmap = pd_video_mmap,
1460 .ioctl = video_ioctl2, /* maybe changed in future */
1461};
1462
1463static const struct v4l2_ioctl_ops pd_video_ioctl_ops = {
1464 .vidioc_querycap = vidioc_querycap,
1465
1466 /* Video format */
1467 .vidioc_g_fmt_vid_cap = vidioc_g_fmt,
1468 .vidioc_enum_fmt_vid_cap = vidioc_enum_fmt,
1469 .vidioc_s_fmt_vid_cap = vidioc_s_fmt,
1470 .vidioc_g_fmt_vbi_cap = vidioc_g_fmt_vbi, /* VBI */
1471
1472 /* Input */
1473 .vidioc_g_input = vidioc_g_input,
1474 .vidioc_s_input = vidioc_s_input,
1475 .vidioc_enum_input = vidioc_enum_input,
1476
1477 /* Audio ioctls */
1478 .vidioc_enumaudio = vidioc_enumaudio,
1479 .vidioc_g_audio = vidioc_g_audio,
1480 .vidioc_s_audio = vidioc_s_audio,
1481
1482 /* Tuner ioctls */
1483 .vidioc_g_tuner = vidioc_g_tuner,
1484 .vidioc_s_tuner = vidioc_s_tuner,
1485 .vidioc_g_std = vidioc_g_std,
1486 .vidioc_s_std = vidioc_s_std,
1487 .vidioc_g_frequency = vidioc_g_frequency,
1488 .vidioc_s_frequency = vidioc_s_frequency,
1489
1490 /* Buffer handlers */
1491 .vidioc_reqbufs = vidioc_reqbufs,
1492 .vidioc_querybuf = vidioc_querybuf,
1493 .vidioc_qbuf = vidioc_qbuf,
1494 .vidioc_dqbuf = vidioc_dqbuf,
1495
1496 /* Stream on/off */
1497 .vidioc_streamon = vidioc_streamon,
1498 .vidioc_streamoff = vidioc_streamoff,
1499};
1500
1501static struct video_device pd_video_template = {
1502 .name = "Telegent-Video",
1503 .fops = &pd_video_fops,
1504 .minor = -1,
1505 .release = video_device_release_empty,
1506 .tvnorms = V4L2_STD_ALL,
1507 .ioctl_ops = &pd_video_ioctl_ops,
1508};
1509
1510static const struct v4l2_ctrl_ops tlg_ctrl_ops = {
1511 .s_ctrl = tlg_s_ctrl,
1512};
1513
1514void pd_video_exit(struct poseidon *pd)
1515{
1516 struct video_data *video = &pd->video_data;
1517 struct vbi_data *vbi = &pd->vbi_data;
1518
1519 video_unregister_device(&video->v_dev);
1520 video_unregister_device(&vbi->v_dev);
1521 v4l2_ctrl_handler_free(&video->ctrl_handler);
1522 log();
1523}
1524
1525int pd_video_init(struct poseidon *pd)
1526{
1527 struct video_data *video = &pd->video_data;
1528 struct vbi_data *vbi = &pd->vbi_data;
1529 struct v4l2_ctrl_handler *hdl = &video->ctrl_handler;
1530 u32 freq = TUNER_FREQ_MIN / 62500;
1531 int ret = -ENOMEM;
1532
1533 v4l2_ctrl_handler_init(hdl, 4);
1534 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_BRIGHTNESS,
1535 0, 10000, 1, 100);
1536 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_CONTRAST,
1537 0, 10000, 1, 100);
1538 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_HUE,
1539 0, 10000, 1, 100);
1540 v4l2_ctrl_new_std(hdl, &tlg_ctrl_ops, V4L2_CID_SATURATION,
1541 0, 10000, 1, 100);
1542 if (hdl->error) {
1543 v4l2_ctrl_handler_free(hdl);
1544 return hdl->error;
1545 }
1546 set_frequency(pd, &freq);
1547 video->v_dev = pd_video_template;
1548 video->v_dev.v4l2_dev = &pd->v4l2_dev;
1549 video->v_dev.ctrl_handler = hdl;
1550 video_set_drvdata(&video->v_dev, pd);
1551
1552 ret = video_register_device(&video->v_dev, VFL_TYPE_GRABBER, -1);
1553 if (ret != 0)
1554 goto out;
1555
1556 /* VBI uses the same template as video */
1557 vbi->v_dev = pd_video_template;
1558 vbi->v_dev.v4l2_dev = &pd->v4l2_dev;
1559 vbi->v_dev.ctrl_handler = hdl;
1560 video_set_drvdata(&vbi->v_dev, pd);
1561 ret = video_register_device(&vbi->v_dev, VFL_TYPE_VBI, -1);
1562 if (ret != 0)
1563 goto out;
1564 log("register VIDEO/VBI devices");
1565 return 0;
1566out:
1567 log("VIDEO/VBI devices register failed, : %d", ret);
1568 pd_video_exit(pd);
1569 return ret;
1570}
diff --git a/drivers/staging/media/tlg2300/vendorcmds.h b/drivers/staging/media/tlg2300/vendorcmds.h
deleted file mode 100644
index ba6f4ae3b2c2..000000000000
--- a/drivers/staging/media/tlg2300/vendorcmds.h
+++ /dev/null
@@ -1,243 +0,0 @@
1#ifndef VENDOR_CMD_H_
2#define VENDOR_CMD_H_
3
4#define BULK_ALTERNATE_IFACE (2)
5#define ISO_3K_BULK_ALTERNATE_IFACE (1)
6#define REQ_SET_CMD (0X00)
7#define REQ_GET_CMD (0X80)
8
9enum tlg__analog_audio_standard {
10 TLG_TUNE_ASTD_NONE = 0x00000000,
11 TLG_TUNE_ASTD_A2 = 0x00000001,
12 TLG_TUNE_ASTD_NICAM = 0x00000002,
13 TLG_TUNE_ASTD_EIAJ = 0x00000004,
14 TLG_TUNE_ASTD_BTSC = 0x00000008,
15 TLG_TUNE_ASTD_FM_US = 0x00000010,
16 TLG_TUNE_ASTD_FM_EUR = 0x00000020,
17 TLG_TUNE_ASTD_ALL = 0x0000003f
18};
19
20/*
21 * identifiers for Custom Parameter messages.
22 * @typedef cmd_custom_param_id_t
23 */
24enum cmd_custom_param_id {
25 CUST_PARM_ID_NONE = 0x00,
26 CUST_PARM_ID_BRIGHTNESS_CTRL = 0x01,
27 CUST_PARM_ID_CONTRAST_CTRL = 0x02,
28 CUST_PARM_ID_HUE_CTRL = 0x03,
29 CUST_PARM_ID_SATURATION_CTRL = 0x04,
30 CUST_PARM_ID_AUDIO_SNR_THRESHOLD = 0x10,
31 CUST_PARM_ID_AUDIO_AGC_THRESHOLD = 0x11,
32 CUST_PARM_ID_MAX
33};
34
35struct tuner_custom_parameter_s {
36 uint16_t param_id; /* Parameter identifier */
37 uint16_t param_value; /* Parameter value */
38};
39
40struct tuner_ber_rate_s {
41 uint32_t ber_rate; /* BER sample rate in seconds */
42};
43
44struct tuner_atv_sig_stat_s {
45 uint32_t sig_present;
46 uint32_t sig_locked;
47 uint32_t sig_lock_busy;
48 uint32_t sig_strength; /* milliDb */
49 uint32_t tv_audio_chan; /* mono/stereo/sap*/
50 uint32_t mvision_stat; /* macrovision status */
51};
52
53struct tuner_dtv_sig_stat_s {
54 uint32_t sig_present; /* Boolean*/
55 uint32_t sig_locked; /* Boolean */
56 uint32_t sig_lock_busy; /* Boolean (Can this time-out?) */
57 uint32_t sig_strength; /* milliDb*/
58};
59
60struct tuner_fm_sig_stat_s {
61 uint32_t sig_present; /* Boolean*/
62 uint32_t sig_locked; /* Boolean */
63 uint32_t sig_lock_busy; /* Boolean */
64 uint32_t sig_stereo_mono;/* TBD*/
65 uint32_t sig_strength; /* milliDb*/
66};
67
68enum _tag_tlg_tune_srv_cmd {
69 TLG_TUNE_PLAY_SVC_START = 1,
70 TLG_TUNE_PLAY_SVC_STOP
71};
72
73enum _tag_tune_atv_audio_mode_caps {
74 TLG_TUNE_TVAUDIO_MODE_MONO = 0x00000001,
75 TLG_TUNE_TVAUDIO_MODE_STEREO = 0x00000002,
76 TLG_TUNE_TVAUDIO_MODE_LANG_A = 0x00000010,/* Primary language*/
77 TLG_TUNE_TVAUDIO_MODE_LANG_B = 0x00000020,/* 2nd avail language*/
78 TLG_TUNE_TVAUDIO_MODE_LANG_C = 0x00000040
79};
80
81
82enum _tag_tuner_atv_audio_rates {
83 ATV_AUDIO_RATE_NONE = 0x00,/* Audio not supported*/
84 ATV_AUDIO_RATE_32K = 0x01,/* Audio rate = 32 KHz*/
85 ATV_AUDIO_RATE_48K = 0x02, /* Audio rate = 48 KHz*/
86 ATV_AUDIO_RATE_31_25K = 0x04 /* Audio rate = 31.25KHz */
87};
88
89enum _tag_tune_atv_vid_res_caps {
90 TLG_TUNE_VID_RES_NONE = 0x00000000,
91 TLG_TUNE_VID_RES_720 = 0x00000001,
92 TLG_TUNE_VID_RES_704 = 0x00000002,
93 TLG_TUNE_VID_RES_360 = 0x00000004
94};
95
96enum _tag_tuner_analog_video_format {
97 TLG_TUNER_VID_FORMAT_YUV = 0x00000001,
98 TLG_TUNER_VID_FORMAT_YCRCB = 0x00000002,
99 TLG_TUNER_VID_FORMAT_RGB_565 = 0x00000004,
100};
101
102enum tlg_ext_audio_support {
103 TLG_EXT_AUDIO_NONE = 0x00,/* No external audio input supported */
104 TLG_EXT_AUDIO_LR = 0x01/* LR external audio inputs supported*/
105};
106
107enum {
108 TLG_MODE_NONE = 0x00, /* No Mode specified*/
109 TLG_MODE_ANALOG_TV = 0x01, /* Analog Television mode*/
110 TLG_MODE_ANALOG_TV_UNCOMP = 0x01, /* Analog Television mode*/
111 TLG_MODE_ANALOG_TV_COMP = 0x02, /* Analog TV mode (compressed)*/
112 TLG_MODE_FM_RADIO = 0x04, /* FM Radio mode*/
113 TLG_MODE_DVB_T = 0x08, /* Digital TV (DVB-T)*/
114};
115
116enum tlg_signal_sources_t {
117 TLG_SIG_SRC_NONE = 0x00,/* Signal source not specified */
118 TLG_SIG_SRC_ANTENNA = 0x01,/* Signal src is: Antenna */
119 TLG_SIG_SRC_CABLE = 0x02,/* Signal src is: Coax Cable*/
120 TLG_SIG_SRC_SVIDEO = 0x04,/* Signal src is: S_VIDEO */
121 TLG_SIG_SRC_COMPOSITE = 0x08 /* Signal src is: Composite Video */
122};
123
124enum tuner_analog_video_standard {
125 TLG_TUNE_VSTD_NONE = 0x00000000,
126 TLG_TUNE_VSTD_NTSC_M = 0x00000001,
127 TLG_TUNE_VSTD_NTSC_M_J = 0x00000002,/* Japan */
128 TLG_TUNE_VSTD_PAL_B = 0x00000010,
129 TLG_TUNE_VSTD_PAL_D = 0x00000020,
130 TLG_TUNE_VSTD_PAL_G = 0x00000040,
131 TLG_TUNE_VSTD_PAL_H = 0x00000080,
132 TLG_TUNE_VSTD_PAL_I = 0x00000100,
133 TLG_TUNE_VSTD_PAL_M = 0x00000200,
134 TLG_TUNE_VSTD_PAL_N = 0x00000400,
135 TLG_TUNE_VSTD_SECAM_B = 0x00001000,
136 TLG_TUNE_VSTD_SECAM_D = 0x00002000,
137 TLG_TUNE_VSTD_SECAM_G = 0x00004000,
138 TLG_TUNE_VSTD_SECAM_H = 0x00008000,
139 TLG_TUNE_VSTD_SECAM_K = 0x00010000,
140 TLG_TUNE_VSTD_SECAM_K1 = 0x00020000,
141 TLG_TUNE_VSTD_SECAM_L = 0x00040000,
142 TLG_TUNE_VSTD_SECAM_L1 = 0x00080000,
143 TLG_TUNE_VSTD_PAL_N_COMBO = 0x00100000
144};
145
146enum tlg_mode_caps {
147 TLG_MODE_CAPS_NONE = 0x00, /* No Mode specified */
148 TLG_MODE_CAPS_ANALOG_TV_UNCOMP = 0x01, /* Analog TV mode */
149 TLG_MODE_CAPS_ANALOG_TV_COMP = 0x02, /* Analog TV (compressed)*/
150 TLG_MODE_CAPS_FM_RADIO = 0x04, /* FM Radio mode */
151 TLG_MODE_CAPS_DVB_T = 0x08, /* Digital TV (DVB-T) */
152};
153
154enum poseidon_vendor_cmds {
155 LAST_CMD_STAT = 0x00,
156 GET_CHIP_ID = 0x01,
157 GET_FW_ID = 0x02,
158 PRODUCT_CAPS = 0x03,
159
160 TUNE_MODE_CAP_ATV = 0x10,
161 TUNE_MODE_CAP_ATVCOMP = 0X10,
162 TUNE_MODE_CAP_DVBT = 0x10,
163 TUNE_MODE_CAP_FM = 0x10,
164 TUNE_MODE_SELECT = 0x11,
165 TUNE_FREQ_SELECT = 0x12,
166 SGNL_SRC_SEL = 0x13,
167
168 VIDEO_STD_SEL = 0x14,
169 VIDEO_STREAM_FMT_SEL = 0x15,
170 VIDEO_ROSOLU_AVAIL = 0x16,
171 VIDEO_ROSOLU_SEL = 0x17,
172 VIDEO_CONT_PROTECT = 0x20,
173
174 VCR_TIMING_MODSEL = 0x21,
175 EXT_AUDIO_CAP = 0x22,
176 EXT_AUDIO_SEL = 0x23,
177 TEST_PATTERN_SEL = 0x24,
178 VBI_DATA_SEL = 0x25,
179 AUDIO_SAMPLE_RATE_CAP = 0x28,
180 AUDIO_SAMPLE_RATE_SEL = 0x29,
181 TUNER_AUD_MODE = 0x2a,
182 TUNER_AUD_MODE_AVAIL = 0x2b,
183 TUNER_AUD_ANA_STD = 0x2c,
184 TUNER_CUSTOM_PARAMETER = 0x2f,
185
186 DVBT_TUNE_MODE_SEL = 0x30,
187 DVBT_BANDW_CAP = 0x31,
188 DVBT_BANDW_SEL = 0x32,
189 DVBT_GUARD_INTERV_CAP = 0x33,
190 DVBT_GUARD_INTERV_SEL = 0x34,
191 DVBT_MODULATION_CAP = 0x35,
192 DVBT_MODULATION_SEL = 0x36,
193 DVBT_INNER_FEC_RATE_CAP = 0x37,
194 DVBT_INNER_FEC_RATE_SEL = 0x38,
195 DVBT_TRANS_MODE_CAP = 0x39,
196 DVBT_TRANS_MODE_SEL = 0x3a,
197 DVBT_SEARCH_RANG = 0x3c,
198
199 TUNER_SETUP_ANALOG = 0x40,
200 TUNER_SETUP_DIGITAL = 0x41,
201 TUNER_SETUP_FM_RADIO = 0x42,
202 TAKE_REQUEST = 0x43, /* Take effect of the command */
203 PLAY_SERVICE = 0x44, /* Play start or Play stop */
204 TUNER_STATUS = 0x45,
205 TUNE_PROP_DVBT = 0x46,
206 ERR_RATE_STATS = 0x47,
207 TUNER_BER_RATE = 0x48,
208
209 SCAN_CAPS = 0x50,
210 SCAN_SETUP = 0x51,
211 SCAN_SERVICE = 0x52,
212 SCAN_STATS = 0x53,
213
214 PID_SET = 0x58,
215 PID_UNSET = 0x59,
216 PID_LIST = 0x5a,
217
218 IRD_CAP = 0x60,
219 IRD_MODE_SEL = 0x61,
220 IRD_SETUP = 0x62,
221
222 PTM_MODE_CAP = 0x70,
223 PTM_MODE_SEL = 0x71,
224 PTM_SERVICE = 0x72,
225 TUNER_REG_SCRIPT = 0x73,
226 CMD_CHIP_RST = 0x74,
227};
228
229enum tlg_bw {
230 TLG_BW_5 = 5,
231 TLG_BW_6 = 6,
232 TLG_BW_7 = 7,
233 TLG_BW_8 = 8,
234 TLG_BW_12 = 12,
235 TLG_BW_15 = 15
236};
237
238struct cmd_firmware_vers_s {
239 uint8_t fw_rev_major;
240 uint8_t fw_rev_minor;
241 uint16_t fw_patch;
242};
243#endif /* VENDOR_CMD_H_ */
diff --git a/drivers/staging/media/vino/Kconfig b/drivers/staging/media/vino/Kconfig
deleted file mode 100644
index 03700dadafd8..000000000000
--- a/drivers/staging/media/vino/Kconfig
+++ /dev/null
@@ -1,24 +0,0 @@
1config VIDEO_VINO
2 tristate "SGI Vino Video For Linux (Deprecated)"
3 depends on I2C && SGI_IP22 && VIDEO_V4L2
4 select VIDEO_SAA7191 if MEDIA_SUBDRV_AUTOSELECT
5 help
6 Say Y here to build in support for the Vino video input system found
7 on SGI Indy machines.
8
9 This driver is deprecated and will be removed soon. If you have
10 hardware for this and you want to work on this driver, then contact
11 the linux-media mailinglist.
12
13config VIDEO_SAA7191
14 tristate "Philips SAA7191 video decoder (Deprecated)"
15 depends on VIDEO_V4L2 && I2C
16 ---help---
17 Support for the Philips SAA7191 video decoder.
18
19 This driver is deprecated and will be removed soon. If you have
20 hardware for this and you want to work on this driver, then contact
21 the linux-media mailinglist.
22
23 To compile this driver as a module, choose M here: the
24 module will be called saa7191.
diff --git a/drivers/staging/media/vino/Makefile b/drivers/staging/media/vino/Makefile
deleted file mode 100644
index 914c2513687c..000000000000
--- a/drivers/staging/media/vino/Makefile
+++ /dev/null
@@ -1,3 +0,0 @@
1obj-$(CONFIG_VIDEO_VINO) += indycam.o
2obj-$(CONFIG_VIDEO_VINO) += vino.o
3obj-$(CONFIG_VIDEO_SAA7191) += saa7191.o
diff --git a/drivers/staging/media/vino/indycam.c b/drivers/staging/media/vino/indycam.c
deleted file mode 100644
index f1d192bbcb4c..000000000000
--- a/drivers/staging/media/vino/indycam.c
+++ /dev/null
@@ -1,378 +0,0 @@
1/*
2 * indycam.c - Silicon Graphics IndyCam digital camera driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/delay.h>
13#include <linux/errno.h>
14#include <linux/fs.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/major.h>
18#include <linux/module.h>
19#include <linux/mm.h>
20#include <linux/slab.h>
21
22/* IndyCam decodes stream of photons into digital image representation ;-) */
23#include <linux/videodev2.h>
24#include <linux/i2c.h>
25#include <media/v4l2-device.h>
26
27#include "indycam.h"
28
29#define INDYCAM_MODULE_VERSION "0.0.5"
30
31MODULE_DESCRIPTION("SGI IndyCam driver");
32MODULE_VERSION(INDYCAM_MODULE_VERSION);
33MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
34MODULE_LICENSE("GPL");
35
36
37// #define INDYCAM_DEBUG
38
39#ifdef INDYCAM_DEBUG
40#define dprintk(x...) printk("IndyCam: " x);
41#define indycam_regdump(client) indycam_regdump_debug(client)
42#else
43#define dprintk(x...)
44#define indycam_regdump(client)
45#endif
46
47struct indycam {
48 struct v4l2_subdev sd;
49 u8 version;
50};
51
52static inline struct indycam *to_indycam(struct v4l2_subdev *sd)
53{
54 return container_of(sd, struct indycam, sd);
55}
56
57static const u8 initseq[] = {
58 INDYCAM_CONTROL_AGCENA, /* INDYCAM_CONTROL */
59 INDYCAM_SHUTTER_60, /* INDYCAM_SHUTTER */
60 INDYCAM_GAIN_DEFAULT, /* INDYCAM_GAIN */
61 0x00, /* INDYCAM_BRIGHTNESS (read-only) */
62 INDYCAM_RED_BALANCE_DEFAULT, /* INDYCAM_RED_BALANCE */
63 INDYCAM_BLUE_BALANCE_DEFAULT, /* INDYCAM_BLUE_BALANCE */
64 INDYCAM_RED_SATURATION_DEFAULT, /* INDYCAM_RED_SATURATION */
65 INDYCAM_BLUE_SATURATION_DEFAULT,/* INDYCAM_BLUE_SATURATION */
66};
67
68/* IndyCam register handling */
69
70static int indycam_read_reg(struct v4l2_subdev *sd, u8 reg, u8 *value)
71{
72 struct i2c_client *client = v4l2_get_subdevdata(sd);
73 int ret;
74
75 if (reg == INDYCAM_REG_RESET) {
76 dprintk("indycam_read_reg(): "
77 "skipping write-only register %d\n", reg);
78 *value = 0;
79 return 0;
80 }
81
82 ret = i2c_smbus_read_byte_data(client, reg);
83
84 if (ret < 0) {
85 printk(KERN_ERR "IndyCam: indycam_read_reg(): read failed, "
86 "register = 0x%02x\n", reg);
87 return ret;
88 }
89
90 *value = (u8)ret;
91
92 return 0;
93}
94
95static int indycam_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
96{
97 struct i2c_client *client = v4l2_get_subdevdata(sd);
98 int err;
99
100 if (reg == INDYCAM_REG_BRIGHTNESS || reg == INDYCAM_REG_VERSION) {
101 dprintk("indycam_write_reg(): "
102 "skipping read-only register %d\n", reg);
103 return 0;
104 }
105
106 dprintk("Writing Reg %d = 0x%02x\n", reg, value);
107 err = i2c_smbus_write_byte_data(client, reg, value);
108
109 if (err) {
110 printk(KERN_ERR "IndyCam: indycam_write_reg(): write failed, "
111 "register = 0x%02x, value = 0x%02x\n", reg, value);
112 }
113 return err;
114}
115
116static int indycam_write_block(struct v4l2_subdev *sd, u8 reg,
117 u8 length, u8 *data)
118{
119 int i, err;
120
121 for (i = 0; i < length; i++) {
122 err = indycam_write_reg(sd, reg + i, data[i]);
123 if (err)
124 return err;
125 }
126
127 return 0;
128}
129
130/* Helper functions */
131
132#ifdef INDYCAM_DEBUG
133static void indycam_regdump_debug(struct v4l2_subdev *sd)
134{
135 int i;
136 u8 val;
137
138 for (i = 0; i < 9; i++) {
139 indycam_read_reg(sd, i, &val);
140 dprintk("Reg %d = 0x%02x\n", i, val);
141 }
142}
143#endif
144
145static int indycam_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
146{
147 struct indycam *camera = to_indycam(sd);
148 u8 reg;
149 int ret = 0;
150
151 switch (ctrl->id) {
152 case V4L2_CID_AUTOGAIN:
153 case V4L2_CID_AUTO_WHITE_BALANCE:
154 ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, &reg);
155 if (ret)
156 return -EIO;
157 if (ctrl->id == V4L2_CID_AUTOGAIN)
158 ctrl->value = (reg & INDYCAM_CONTROL_AGCENA)
159 ? 1 : 0;
160 else
161 ctrl->value = (reg & INDYCAM_CONTROL_AWBCTL)
162 ? 1 : 0;
163 break;
164 case V4L2_CID_EXPOSURE:
165 ret = indycam_read_reg(sd, INDYCAM_REG_SHUTTER, &reg);
166 if (ret)
167 return -EIO;
168 ctrl->value = ((s32)reg == 0x00) ? 0xff : ((s32)reg - 1);
169 break;
170 case V4L2_CID_GAIN:
171 ret = indycam_read_reg(sd, INDYCAM_REG_GAIN, &reg);
172 if (ret)
173 return -EIO;
174 ctrl->value = (s32)reg;
175 break;
176 case V4L2_CID_RED_BALANCE:
177 ret = indycam_read_reg(sd, INDYCAM_REG_RED_BALANCE, &reg);
178 if (ret)
179 return -EIO;
180 ctrl->value = (s32)reg;
181 break;
182 case V4L2_CID_BLUE_BALANCE:
183 ret = indycam_read_reg(sd, INDYCAM_REG_BLUE_BALANCE, &reg);
184 if (ret)
185 return -EIO;
186 ctrl->value = (s32)reg;
187 break;
188 case INDYCAM_CONTROL_RED_SATURATION:
189 ret = indycam_read_reg(sd,
190 INDYCAM_REG_RED_SATURATION, &reg);
191 if (ret)
192 return -EIO;
193 ctrl->value = (s32)reg;
194 break;
195 case INDYCAM_CONTROL_BLUE_SATURATION:
196 ret = indycam_read_reg(sd,
197 INDYCAM_REG_BLUE_SATURATION, &reg);
198 if (ret)
199 return -EIO;
200 ctrl->value = (s32)reg;
201 break;
202 case V4L2_CID_GAMMA:
203 if (camera->version == CAMERA_VERSION_MOOSE) {
204 ret = indycam_read_reg(sd,
205 INDYCAM_REG_GAMMA, &reg);
206 if (ret)
207 return -EIO;
208 ctrl->value = (s32)reg;
209 } else {
210 ctrl->value = INDYCAM_GAMMA_DEFAULT;
211 }
212 break;
213 default:
214 ret = -EINVAL;
215 }
216
217 return ret;
218}
219
220static int indycam_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
221{
222 struct indycam *camera = to_indycam(sd);
223 u8 reg;
224 int ret = 0;
225
226 switch (ctrl->id) {
227 case V4L2_CID_AUTOGAIN:
228 case V4L2_CID_AUTO_WHITE_BALANCE:
229 ret = indycam_read_reg(sd, INDYCAM_REG_CONTROL, &reg);
230 if (ret)
231 break;
232
233 if (ctrl->id == V4L2_CID_AUTOGAIN) {
234 if (ctrl->value)
235 reg |= INDYCAM_CONTROL_AGCENA;
236 else
237 reg &= ~INDYCAM_CONTROL_AGCENA;
238 } else {
239 if (ctrl->value)
240 reg |= INDYCAM_CONTROL_AWBCTL;
241 else
242 reg &= ~INDYCAM_CONTROL_AWBCTL;
243 }
244
245 ret = indycam_write_reg(sd, INDYCAM_REG_CONTROL, reg);
246 break;
247 case V4L2_CID_EXPOSURE:
248 reg = (ctrl->value == 0xff) ? 0x00 : (ctrl->value + 1);
249 ret = indycam_write_reg(sd, INDYCAM_REG_SHUTTER, reg);
250 break;
251 case V4L2_CID_GAIN:
252 ret = indycam_write_reg(sd, INDYCAM_REG_GAIN, ctrl->value);
253 break;
254 case V4L2_CID_RED_BALANCE:
255 ret = indycam_write_reg(sd, INDYCAM_REG_RED_BALANCE,
256 ctrl->value);
257 break;
258 case V4L2_CID_BLUE_BALANCE:
259 ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_BALANCE,
260 ctrl->value);
261 break;
262 case INDYCAM_CONTROL_RED_SATURATION:
263 ret = indycam_write_reg(sd, INDYCAM_REG_RED_SATURATION,
264 ctrl->value);
265 break;
266 case INDYCAM_CONTROL_BLUE_SATURATION:
267 ret = indycam_write_reg(sd, INDYCAM_REG_BLUE_SATURATION,
268 ctrl->value);
269 break;
270 case V4L2_CID_GAMMA:
271 if (camera->version == CAMERA_VERSION_MOOSE) {
272 ret = indycam_write_reg(sd, INDYCAM_REG_GAMMA,
273 ctrl->value);
274 }
275 break;
276 default:
277 ret = -EINVAL;
278 }
279
280 return ret;
281}
282
283/* I2C-interface */
284
285/* ----------------------------------------------------------------------- */
286
287static const struct v4l2_subdev_core_ops indycam_core_ops = {
288 .g_ctrl = indycam_g_ctrl,
289 .s_ctrl = indycam_s_ctrl,
290};
291
292static const struct v4l2_subdev_ops indycam_ops = {
293 .core = &indycam_core_ops,
294};
295
296static int indycam_probe(struct i2c_client *client,
297 const struct i2c_device_id *id)
298{
299 int err = 0;
300 struct indycam *camera;
301 struct v4l2_subdev *sd;
302
303 v4l_info(client, "chip found @ 0x%x (%s)\n",
304 client->addr << 1, client->adapter->name);
305
306 camera = kzalloc(sizeof(struct indycam), GFP_KERNEL);
307 if (!camera)
308 return -ENOMEM;
309
310 sd = &camera->sd;
311 v4l2_i2c_subdev_init(sd, client, &indycam_ops);
312
313 camera->version = i2c_smbus_read_byte_data(client,
314 INDYCAM_REG_VERSION);
315 if (camera->version != CAMERA_VERSION_INDY &&
316 camera->version != CAMERA_VERSION_MOOSE) {
317 kfree(camera);
318 return -ENODEV;
319 }
320
321 printk(KERN_INFO "IndyCam v%d.%d detected\n",
322 INDYCAM_VERSION_MAJOR(camera->version),
323 INDYCAM_VERSION_MINOR(camera->version));
324
325 indycam_regdump(sd);
326
327 // initialize
328 err = indycam_write_block(sd, 0, sizeof(initseq), (u8 *)&initseq);
329 if (err) {
330 printk(KERN_ERR "IndyCam initialization failed\n");
331 kfree(camera);
332 return -EIO;
333 }
334
335 indycam_regdump(sd);
336
337 // white balance
338 err = indycam_write_reg(sd, INDYCAM_REG_CONTROL,
339 INDYCAM_CONTROL_AGCENA | INDYCAM_CONTROL_AWBCTL);
340 if (err) {
341 printk(KERN_ERR "IndyCam: White balancing camera failed\n");
342 kfree(camera);
343 return -EIO;
344 }
345
346 indycam_regdump(sd);
347
348 printk(KERN_INFO "IndyCam initialized\n");
349
350 return 0;
351}
352
353static int indycam_remove(struct i2c_client *client)
354{
355 struct v4l2_subdev *sd = i2c_get_clientdata(client);
356
357 v4l2_device_unregister_subdev(sd);
358 kfree(to_indycam(sd));
359 return 0;
360}
361
362static const struct i2c_device_id indycam_id[] = {
363 { "indycam", 0 },
364 { }
365};
366MODULE_DEVICE_TABLE(i2c, indycam_id);
367
368static struct i2c_driver indycam_driver = {
369 .driver = {
370 .owner = THIS_MODULE,
371 .name = "indycam",
372 },
373 .probe = indycam_probe,
374 .remove = indycam_remove,
375 .id_table = indycam_id,
376};
377
378module_i2c_driver(indycam_driver);
diff --git a/drivers/staging/media/vino/indycam.h b/drivers/staging/media/vino/indycam.h
deleted file mode 100644
index 881f21c474c4..000000000000
--- a/drivers/staging/media/vino/indycam.h
+++ /dev/null
@@ -1,93 +0,0 @@
1/*
2 * indycam.h - Silicon Graphics IndyCam digital camera driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _INDYCAM_H_
13#define _INDYCAM_H_
14
15/* I2C address for the Guinness Camera */
16#define INDYCAM_ADDR 0x56
17
18/* Camera version */
19#define CAMERA_VERSION_INDY 0x10 /* v1.0 */
20#define CAMERA_VERSION_MOOSE 0x12 /* v1.2 */
21#define INDYCAM_VERSION_MAJOR(x) (((x) & 0xf0) >> 4)
22#define INDYCAM_VERSION_MINOR(x) ((x) & 0x0f)
23
24/* Register bus addresses */
25#define INDYCAM_REG_CONTROL 0x00
26#define INDYCAM_REG_SHUTTER 0x01
27#define INDYCAM_REG_GAIN 0x02
28#define INDYCAM_REG_BRIGHTNESS 0x03 /* read-only */
29#define INDYCAM_REG_RED_BALANCE 0x04
30#define INDYCAM_REG_BLUE_BALANCE 0x05
31#define INDYCAM_REG_RED_SATURATION 0x06
32#define INDYCAM_REG_BLUE_SATURATION 0x07
33#define INDYCAM_REG_GAMMA 0x08
34#define INDYCAM_REG_VERSION 0x0e /* read-only */
35#define INDYCAM_REG_RESET 0x0f /* write-only */
36
37#define INDYCAM_REG_LED 0x46
38#define INDYCAM_REG_ORIENTATION 0x47
39#define INDYCAM_REG_BUTTON 0x48
40
41/* Field definitions of registers */
42#define INDYCAM_CONTROL_AGCENA (1<<0) /* automatic gain control */
43#define INDYCAM_CONTROL_AWBCTL (1<<1) /* automatic white balance */
44 /* 2-3 are reserved */
45#define INDYCAM_CONTROL_EVNFLD (1<<4) /* read-only */
46
47#define INDYCAM_SHUTTER_10000 0x02 /* 1/10000 second */
48#define INDYCAM_SHUTTER_4000 0x04 /* 1/4000 second */
49#define INDYCAM_SHUTTER_2000 0x08 /* 1/2000 second */
50#define INDYCAM_SHUTTER_1000 0x10 /* 1/1000 second */
51#define INDYCAM_SHUTTER_500 0x20 /* 1/500 second */
52#define INDYCAM_SHUTTER_250 0x3f /* 1/250 second */
53#define INDYCAM_SHUTTER_125 0x7e /* 1/125 second */
54#define INDYCAM_SHUTTER_100 0x9e /* 1/100 second */
55#define INDYCAM_SHUTTER_60 0x00 /* 1/60 second */
56
57#define INDYCAM_LED_ACTIVE 0x10
58#define INDYCAM_LED_INACTIVE 0x30
59#define INDYCAM_ORIENTATION_BOTTOM_TO_TOP 0x40
60#define INDYCAM_BUTTON_RELEASED 0x10
61
62/* Values for controls */
63#define INDYCAM_SHUTTER_MIN 0x00
64#define INDYCAM_SHUTTER_MAX 0xff
65#define INDYCAM_GAIN_MIN 0x00
66#define INDYCAM_GAIN_MAX 0xff
67#define INDYCAM_RED_BALANCE_MIN 0x00
68#define INDYCAM_RED_BALANCE_MAX 0xff
69#define INDYCAM_BLUE_BALANCE_MIN 0x00
70#define INDYCAM_BLUE_BALANCE_MAX 0xff
71#define INDYCAM_RED_SATURATION_MIN 0x00
72#define INDYCAM_RED_SATURATION_MAX 0xff
73#define INDYCAM_BLUE_SATURATION_MIN 0x00
74#define INDYCAM_BLUE_SATURATION_MAX 0xff
75#define INDYCAM_GAMMA_MIN 0x00
76#define INDYCAM_GAMMA_MAX 0xff
77
78#define INDYCAM_AGC_DEFAULT 1
79#define INDYCAM_AWB_DEFAULT 0
80#define INDYCAM_SHUTTER_DEFAULT 0xff
81#define INDYCAM_GAIN_DEFAULT 0x80
82#define INDYCAM_RED_BALANCE_DEFAULT 0x18
83#define INDYCAM_BLUE_BALANCE_DEFAULT 0xa4
84#define INDYCAM_RED_SATURATION_DEFAULT 0x80
85#define INDYCAM_BLUE_SATURATION_DEFAULT 0xc0
86#define INDYCAM_GAMMA_DEFAULT 0x80
87
88/* Driver interface definitions */
89
90#define INDYCAM_CONTROL_RED_SATURATION (V4L2_CID_PRIVATE_BASE + 0)
91#define INDYCAM_CONTROL_BLUE_SATURATION (V4L2_CID_PRIVATE_BASE + 1)
92
93#endif
diff --git a/drivers/staging/media/vino/saa7191.c b/drivers/staging/media/vino/saa7191.c
deleted file mode 100644
index 8e9699268a63..000000000000
--- a/drivers/staging/media/vino/saa7191.c
+++ /dev/null
@@ -1,649 +0,0 @@
1/*
2 * saa7191.c - Philips SAA7191 video decoder driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/delay.h>
13#include <linux/errno.h>
14#include <linux/fs.h>
15#include <linux/init.h>
16#include <linux/kernel.h>
17#include <linux/major.h>
18#include <linux/module.h>
19#include <linux/mm.h>
20#include <linux/slab.h>
21
22#include <linux/videodev2.h>
23#include <linux/i2c.h>
24#include <media/v4l2-device.h>
25
26#include "saa7191.h"
27
28#define SAA7191_MODULE_VERSION "0.0.5"
29
30MODULE_DESCRIPTION("Philips SAA7191 video decoder driver");
31MODULE_VERSION(SAA7191_MODULE_VERSION);
32MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
33MODULE_LICENSE("GPL");
34
35
36// #define SAA7191_DEBUG
37
38#ifdef SAA7191_DEBUG
39#define dprintk(x...) printk("SAA7191: " x);
40#else
41#define dprintk(x...)
42#endif
43
44#define SAA7191_SYNC_COUNT 30
45#define SAA7191_SYNC_DELAY 100 /* milliseconds */
46
47struct saa7191 {
48 struct v4l2_subdev sd;
49
50 /* the register values are stored here as the actual
51 * I2C-registers are write-only */
52 u8 reg[25];
53
54 int input;
55 v4l2_std_id norm;
56};
57
58static inline struct saa7191 *to_saa7191(struct v4l2_subdev *sd)
59{
60 return container_of(sd, struct saa7191, sd);
61}
62
63static const u8 initseq[] = {
64 0, /* Subaddress */
65
66 0x50, /* (0x50) SAA7191_REG_IDEL */
67
68 /* 50 Hz signal timing */
69 0x30, /* (0x30) SAA7191_REG_HSYB */
70 0x00, /* (0x00) SAA7191_REG_HSYS */
71 0xe8, /* (0xe8) SAA7191_REG_HCLB */
72 0xb6, /* (0xb6) SAA7191_REG_HCLS */
73 0xf4, /* (0xf4) SAA7191_REG_HPHI */
74
75 /* control */
76 SAA7191_LUMA_APER_1, /* (0x01) SAA7191_REG_LUMA - CVBS mode */
77 0x00, /* (0x00) SAA7191_REG_HUEC */
78 0xf8, /* (0xf8) SAA7191_REG_CKTQ */
79 0xf8, /* (0xf8) SAA7191_REG_CKTS */
80 0x90, /* (0x90) SAA7191_REG_PLSE */
81 0x90, /* (0x90) SAA7191_REG_SESE */
82 0x00, /* (0x00) SAA7191_REG_GAIN */
83 SAA7191_STDC_NFEN | SAA7191_STDC_HRMV, /* (0x0c) SAA7191_REG_STDC
84 * - not SECAM,
85 * slow time constant */
86 SAA7191_IOCK_OEDC | SAA7191_IOCK_OEHS | SAA7191_IOCK_OEVS
87 | SAA7191_IOCK_OEDY, /* (0x78) SAA7191_REG_IOCK
88 * - chroma from CVBS, GPSW1 & 2 off */
89 SAA7191_CTL3_AUFD | SAA7191_CTL3_SCEN | SAA7191_CTL3_OFTS
90 | SAA7191_CTL3_YDEL0, /* (0x99) SAA7191_REG_CTL3
91 * - automatic field detection */
92 0x00, /* (0x00) SAA7191_REG_CTL4 */
93 0x2c, /* (0x2c) SAA7191_REG_CHCV - PAL nominal value */
94 0x00, /* unused */
95 0x00, /* unused */
96
97 /* 60 Hz signal timing */
98 0x34, /* (0x34) SAA7191_REG_HS6B */
99 0x0a, /* (0x0a) SAA7191_REG_HS6S */
100 0xf4, /* (0xf4) SAA7191_REG_HC6B */
101 0xce, /* (0xce) SAA7191_REG_HC6S */
102 0xf4, /* (0xf4) SAA7191_REG_HP6I */
103};
104
105/* SAA7191 register handling */
106
107static u8 saa7191_read_reg(struct v4l2_subdev *sd, u8 reg)
108{
109 return to_saa7191(sd)->reg[reg];
110}
111
112static int saa7191_read_status(struct v4l2_subdev *sd, u8 *value)
113{
114 struct i2c_client *client = v4l2_get_subdevdata(sd);
115 int ret;
116
117 ret = i2c_master_recv(client, value, 1);
118 if (ret < 0) {
119 printk(KERN_ERR "SAA7191: saa7191_read_status(): read failed\n");
120 return ret;
121 }
122
123 return 0;
124}
125
126
127static int saa7191_write_reg(struct v4l2_subdev *sd, u8 reg, u8 value)
128{
129 struct i2c_client *client = v4l2_get_subdevdata(sd);
130
131 to_saa7191(sd)->reg[reg] = value;
132 return i2c_smbus_write_byte_data(client, reg, value);
133}
134
135/* the first byte of data must be the first subaddress number (register) */
136static int saa7191_write_block(struct v4l2_subdev *sd,
137 u8 length, const u8 *data)
138{
139 struct i2c_client *client = v4l2_get_subdevdata(sd);
140 struct saa7191 *decoder = to_saa7191(sd);
141 int i;
142 int ret;
143
144 for (i = 0; i < (length - 1); i++) {
145 decoder->reg[data[0] + i] = data[i + 1];
146 }
147
148 ret = i2c_master_send(client, data, length);
149 if (ret < 0) {
150 printk(KERN_ERR "SAA7191: saa7191_write_block(): "
151 "write failed\n");
152 return ret;
153 }
154
155 return 0;
156}
157
158/* Helper functions */
159
160static int saa7191_s_routing(struct v4l2_subdev *sd,
161 u32 input, u32 output, u32 config)
162{
163 struct saa7191 *decoder = to_saa7191(sd);
164 u8 luma = saa7191_read_reg(sd, SAA7191_REG_LUMA);
165 u8 iock = saa7191_read_reg(sd, SAA7191_REG_IOCK);
166 int err;
167
168 switch (input) {
169 case SAA7191_INPUT_COMPOSITE: /* Set Composite input */
170 iock &= ~(SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW1
171 | SAA7191_IOCK_GPSW2);
172 /* Chrominance trap active */
173 luma &= ~SAA7191_LUMA_BYPS;
174 break;
175 case SAA7191_INPUT_SVIDEO: /* Set S-Video input */
176 iock |= SAA7191_IOCK_CHRS | SAA7191_IOCK_GPSW2;
177 /* Chrominance trap bypassed */
178 luma |= SAA7191_LUMA_BYPS;
179 break;
180 default:
181 return -EINVAL;
182 }
183
184 err = saa7191_write_reg(sd, SAA7191_REG_LUMA, luma);
185 if (err)
186 return -EIO;
187 err = saa7191_write_reg(sd, SAA7191_REG_IOCK, iock);
188 if (err)
189 return -EIO;
190
191 decoder->input = input;
192
193 return 0;
194}
195
196static int saa7191_s_std(struct v4l2_subdev *sd, v4l2_std_id norm)
197{
198 struct saa7191 *decoder = to_saa7191(sd);
199 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
200 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
201 u8 chcv = saa7191_read_reg(sd, SAA7191_REG_CHCV);
202 int err;
203
204 if (norm & V4L2_STD_PAL) {
205 stdc &= ~SAA7191_STDC_SECS;
206 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
207 chcv = SAA7191_CHCV_PAL;
208 } else if (norm & V4L2_STD_NTSC) {
209 stdc &= ~SAA7191_STDC_SECS;
210 ctl3 &= ~SAA7191_CTL3_AUFD;
211 ctl3 |= SAA7191_CTL3_FSEL;
212 chcv = SAA7191_CHCV_NTSC;
213 } else if (norm & V4L2_STD_SECAM) {
214 stdc |= SAA7191_STDC_SECS;
215 ctl3 &= ~(SAA7191_CTL3_AUFD | SAA7191_CTL3_FSEL);
216 chcv = SAA7191_CHCV_PAL;
217 } else {
218 return -EINVAL;
219 }
220
221 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
222 if (err)
223 return -EIO;
224 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
225 if (err)
226 return -EIO;
227 err = saa7191_write_reg(sd, SAA7191_REG_CHCV, chcv);
228 if (err)
229 return -EIO;
230
231 decoder->norm = norm;
232
233 dprintk("ctl3: %02x stdc: %02x chcv: %02x\n", ctl3,
234 stdc, chcv);
235 dprintk("norm: %llx\n", norm);
236
237 return 0;
238}
239
240static int saa7191_wait_for_signal(struct v4l2_subdev *sd, u8 *status)
241{
242 int i = 0;
243
244 dprintk("Checking for signal...\n");
245
246 for (i = 0; i < SAA7191_SYNC_COUNT; i++) {
247 if (saa7191_read_status(sd, status))
248 return -EIO;
249
250 if (((*status) & SAA7191_STATUS_HLCK) == 0) {
251 dprintk("Signal found\n");
252 return 0;
253 }
254
255 msleep(SAA7191_SYNC_DELAY);
256 }
257
258 dprintk("No signal\n");
259
260 return -EBUSY;
261}
262
263static int saa7191_querystd(struct v4l2_subdev *sd, v4l2_std_id *norm)
264{
265 struct saa7191 *decoder = to_saa7191(sd);
266 u8 stdc = saa7191_read_reg(sd, SAA7191_REG_STDC);
267 u8 ctl3 = saa7191_read_reg(sd, SAA7191_REG_CTL3);
268 u8 status;
269 v4l2_std_id old_norm = decoder->norm;
270 int err = 0;
271
272 dprintk("SAA7191 extended signal auto-detection...\n");
273
274 *norm &= V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM;
275 stdc &= ~SAA7191_STDC_SECS;
276 ctl3 &= ~(SAA7191_CTL3_FSEL);
277
278 err = saa7191_write_reg(sd, SAA7191_REG_STDC, stdc);
279 if (err) {
280 err = -EIO;
281 goto out;
282 }
283 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
284 if (err) {
285 err = -EIO;
286 goto out;
287 }
288
289 ctl3 |= SAA7191_CTL3_AUFD;
290 err = saa7191_write_reg(sd, SAA7191_REG_CTL3, ctl3);
291 if (err) {
292 err = -EIO;
293 goto out;
294 }
295
296 msleep(SAA7191_SYNC_DELAY);
297
298 err = saa7191_wait_for_signal(sd, &status);
299 if (err)
300 goto out;
301
302 if (status & SAA7191_STATUS_FIDT) {
303 /* 60Hz signal -> NTSC */
304 dprintk("60Hz signal: NTSC\n");
305 *norm &= V4L2_STD_NTSC;
306 return 0;
307 }
308
309 /* 50Hz signal */
310 dprintk("50Hz signal: Trying PAL...\n");
311
312 /* try PAL first */
313 err = saa7191_s_std(sd, V4L2_STD_PAL);
314 if (err)
315 goto out;
316
317 msleep(SAA7191_SYNC_DELAY);
318
319 err = saa7191_wait_for_signal(sd, &status);
320 if (err)
321 goto out;
322
323 /* not 50Hz ? */
324 if (status & SAA7191_STATUS_FIDT) {
325 dprintk("No 50Hz signal\n");
326 saa7191_s_std(sd, old_norm);
327 *norm = V4L2_STD_UNKNOWN;
328 return 0;
329 }
330
331 if (status & SAA7191_STATUS_CODE) {
332 dprintk("PAL\n");
333 *norm &= V4L2_STD_PAL;
334 return saa7191_s_std(sd, old_norm);
335 }
336
337 dprintk("No color detected with PAL - Trying SECAM...\n");
338
339 /* no color detected ? -> try SECAM */
340 err = saa7191_s_std(sd, V4L2_STD_SECAM);
341 if (err)
342 goto out;
343
344 msleep(SAA7191_SYNC_DELAY);
345
346 err = saa7191_wait_for_signal(sd, &status);
347 if (err)
348 goto out;
349
350 /* not 50Hz ? */
351 if (status & SAA7191_STATUS_FIDT) {
352 dprintk("No 50Hz signal\n");
353 *norm = V4L2_STD_UNKNOWN;
354 goto out;
355 }
356
357 if (status & SAA7191_STATUS_CODE) {
358 /* Color detected -> SECAM */
359 dprintk("SECAM\n");
360 *norm &= V4L2_STD_SECAM;
361 return saa7191_s_std(sd, old_norm);
362 }
363
364 dprintk("No color detected with SECAM - Going back to PAL.\n");
365 *norm = V4L2_STD_UNKNOWN;
366
367out:
368 return saa7191_s_std(sd, old_norm);
369}
370
371static int saa7191_autodetect_norm(struct v4l2_subdev *sd)
372{
373 u8 status;
374
375 dprintk("SAA7191 signal auto-detection...\n");
376
377 dprintk("Reading status...\n");
378
379 if (saa7191_read_status(sd, &status))
380 return -EIO;
381
382 dprintk("Checking for signal...\n");
383
384 /* no signal ? */
385 if (status & SAA7191_STATUS_HLCK) {
386 dprintk("No signal\n");
387 return -EBUSY;
388 }
389
390 dprintk("Signal found\n");
391
392 if (status & SAA7191_STATUS_FIDT) {
393 /* 60hz signal -> NTSC */
394 dprintk("NTSC\n");
395 return saa7191_s_std(sd, V4L2_STD_NTSC);
396 } else {
397 /* 50hz signal -> PAL */
398 dprintk("PAL\n");
399 return saa7191_s_std(sd, V4L2_STD_PAL);
400 }
401}
402
403static int saa7191_g_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
404{
405 u8 reg;
406 int ret = 0;
407
408 switch (ctrl->id) {
409 case SAA7191_CONTROL_BANDPASS:
410 case SAA7191_CONTROL_BANDPASS_WEIGHT:
411 case SAA7191_CONTROL_CORING:
412 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
413 switch (ctrl->id) {
414 case SAA7191_CONTROL_BANDPASS:
415 ctrl->value = ((s32)reg & SAA7191_LUMA_BPSS_MASK)
416 >> SAA7191_LUMA_BPSS_SHIFT;
417 break;
418 case SAA7191_CONTROL_BANDPASS_WEIGHT:
419 ctrl->value = ((s32)reg & SAA7191_LUMA_APER_MASK)
420 >> SAA7191_LUMA_APER_SHIFT;
421 break;
422 case SAA7191_CONTROL_CORING:
423 ctrl->value = ((s32)reg & SAA7191_LUMA_CORI_MASK)
424 >> SAA7191_LUMA_CORI_SHIFT;
425 break;
426 }
427 break;
428 case SAA7191_CONTROL_FORCE_COLOUR:
429 case SAA7191_CONTROL_CHROMA_GAIN:
430 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
431 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR)
432 ctrl->value = ((s32)reg & SAA7191_GAIN_COLO) ? 1 : 0;
433 else
434 ctrl->value = ((s32)reg & SAA7191_GAIN_LFIS_MASK)
435 >> SAA7191_GAIN_LFIS_SHIFT;
436 break;
437 case V4L2_CID_HUE:
438 reg = saa7191_read_reg(sd, SAA7191_REG_HUEC);
439 if (reg < 0x80)
440 reg += 0x80;
441 else
442 reg -= 0x80;
443 ctrl->value = (s32)reg;
444 break;
445 case SAA7191_CONTROL_VTRC:
446 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
447 ctrl->value = ((s32)reg & SAA7191_STDC_VTRC) ? 1 : 0;
448 break;
449 case SAA7191_CONTROL_LUMA_DELAY:
450 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
451 ctrl->value = ((s32)reg & SAA7191_CTL3_YDEL_MASK)
452 >> SAA7191_CTL3_YDEL_SHIFT;
453 if (ctrl->value >= 4)
454 ctrl->value -= 8;
455 break;
456 case SAA7191_CONTROL_VNR:
457 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
458 ctrl->value = ((s32)reg & SAA7191_CTL4_VNOI_MASK)
459 >> SAA7191_CTL4_VNOI_SHIFT;
460 break;
461 default:
462 ret = -EINVAL;
463 }
464
465 return ret;
466}
467
468static int saa7191_s_ctrl(struct v4l2_subdev *sd, struct v4l2_control *ctrl)
469{
470 u8 reg;
471 int ret = 0;
472
473 switch (ctrl->id) {
474 case SAA7191_CONTROL_BANDPASS:
475 case SAA7191_CONTROL_BANDPASS_WEIGHT:
476 case SAA7191_CONTROL_CORING:
477 reg = saa7191_read_reg(sd, SAA7191_REG_LUMA);
478 switch (ctrl->id) {
479 case SAA7191_CONTROL_BANDPASS:
480 reg &= ~SAA7191_LUMA_BPSS_MASK;
481 reg |= (ctrl->value << SAA7191_LUMA_BPSS_SHIFT)
482 & SAA7191_LUMA_BPSS_MASK;
483 break;
484 case SAA7191_CONTROL_BANDPASS_WEIGHT:
485 reg &= ~SAA7191_LUMA_APER_MASK;
486 reg |= (ctrl->value << SAA7191_LUMA_APER_SHIFT)
487 & SAA7191_LUMA_APER_MASK;
488 break;
489 case SAA7191_CONTROL_CORING:
490 reg &= ~SAA7191_LUMA_CORI_MASK;
491 reg |= (ctrl->value << SAA7191_LUMA_CORI_SHIFT)
492 & SAA7191_LUMA_CORI_MASK;
493 break;
494 }
495 ret = saa7191_write_reg(sd, SAA7191_REG_LUMA, reg);
496 break;
497 case SAA7191_CONTROL_FORCE_COLOUR:
498 case SAA7191_CONTROL_CHROMA_GAIN:
499 reg = saa7191_read_reg(sd, SAA7191_REG_GAIN);
500 if (ctrl->id == SAA7191_CONTROL_FORCE_COLOUR) {
501 if (ctrl->value)
502 reg |= SAA7191_GAIN_COLO;
503 else
504 reg &= ~SAA7191_GAIN_COLO;
505 } else {
506 reg &= ~SAA7191_GAIN_LFIS_MASK;
507 reg |= (ctrl->value << SAA7191_GAIN_LFIS_SHIFT)
508 & SAA7191_GAIN_LFIS_MASK;
509 }
510 ret = saa7191_write_reg(sd, SAA7191_REG_GAIN, reg);
511 break;
512 case V4L2_CID_HUE:
513 reg = ctrl->value & 0xff;
514 if (reg < 0x80)
515 reg += 0x80;
516 else
517 reg -= 0x80;
518 ret = saa7191_write_reg(sd, SAA7191_REG_HUEC, reg);
519 break;
520 case SAA7191_CONTROL_VTRC:
521 reg = saa7191_read_reg(sd, SAA7191_REG_STDC);
522 if (ctrl->value)
523 reg |= SAA7191_STDC_VTRC;
524 else
525 reg &= ~SAA7191_STDC_VTRC;
526 ret = saa7191_write_reg(sd, SAA7191_REG_STDC, reg);
527 break;
528 case SAA7191_CONTROL_LUMA_DELAY: {
529 s32 value = ctrl->value;
530 if (value < 0)
531 value += 8;
532 reg = saa7191_read_reg(sd, SAA7191_REG_CTL3);
533 reg &= ~SAA7191_CTL3_YDEL_MASK;
534 reg |= (value << SAA7191_CTL3_YDEL_SHIFT)
535 & SAA7191_CTL3_YDEL_MASK;
536 ret = saa7191_write_reg(sd, SAA7191_REG_CTL3, reg);
537 break;
538 }
539 case SAA7191_CONTROL_VNR:
540 reg = saa7191_read_reg(sd, SAA7191_REG_CTL4);
541 reg &= ~SAA7191_CTL4_VNOI_MASK;
542 reg |= (ctrl->value << SAA7191_CTL4_VNOI_SHIFT)
543 & SAA7191_CTL4_VNOI_MASK;
544 ret = saa7191_write_reg(sd, SAA7191_REG_CTL4, reg);
545 break;
546 default:
547 ret = -EINVAL;
548 }
549
550 return ret;
551}
552
553/* I2C-interface */
554
555static int saa7191_g_input_status(struct v4l2_subdev *sd, u32 *status)
556{
557 u8 status_reg;
558 int res = V4L2_IN_ST_NO_SIGNAL;
559
560 if (saa7191_read_status(sd, &status_reg))
561 return -EIO;
562 if ((status_reg & SAA7191_STATUS_HLCK) == 0)
563 res = 0;
564 if (!(status_reg & SAA7191_STATUS_CODE))
565 res |= V4L2_IN_ST_NO_COLOR;
566 *status = res;
567 return 0;
568}
569
570
571/* ----------------------------------------------------------------------- */
572
573static const struct v4l2_subdev_core_ops saa7191_core_ops = {
574 .g_ctrl = saa7191_g_ctrl,
575 .s_ctrl = saa7191_s_ctrl,
576};
577
578static const struct v4l2_subdev_video_ops saa7191_video_ops = {
579 .s_std = saa7191_s_std,
580 .s_routing = saa7191_s_routing,
581 .querystd = saa7191_querystd,
582 .g_input_status = saa7191_g_input_status,
583};
584
585static const struct v4l2_subdev_ops saa7191_ops = {
586 .core = &saa7191_core_ops,
587 .video = &saa7191_video_ops,
588};
589
590static int saa7191_probe(struct i2c_client *client,
591 const struct i2c_device_id *id)
592{
593 int err = 0;
594 struct saa7191 *decoder;
595 struct v4l2_subdev *sd;
596
597 v4l_info(client, "chip found @ 0x%x (%s)\n",
598 client->addr << 1, client->adapter->name);
599
600 decoder = devm_kzalloc(&client->dev, sizeof(*decoder), GFP_KERNEL);
601 if (!decoder)
602 return -ENOMEM;
603
604 sd = &decoder->sd;
605 v4l2_i2c_subdev_init(sd, client, &saa7191_ops);
606
607 err = saa7191_write_block(sd, sizeof(initseq), initseq);
608 if (err) {
609 printk(KERN_ERR "SAA7191 initialization failed\n");
610 return err;
611 }
612
613 printk(KERN_INFO "SAA7191 initialized\n");
614
615 decoder->input = SAA7191_INPUT_COMPOSITE;
616 decoder->norm = V4L2_STD_PAL;
617
618 err = saa7191_autodetect_norm(sd);
619 if (err && (err != -EBUSY))
620 printk(KERN_ERR "SAA7191: Signal auto-detection failed\n");
621
622 return 0;
623}
624
625static int saa7191_remove(struct i2c_client *client)
626{
627 struct v4l2_subdev *sd = i2c_get_clientdata(client);
628
629 v4l2_device_unregister_subdev(sd);
630 return 0;
631}
632
633static const struct i2c_device_id saa7191_id[] = {
634 { "saa7191", 0 },
635 { }
636};
637MODULE_DEVICE_TABLE(i2c, saa7191_id);
638
639static struct i2c_driver saa7191_driver = {
640 .driver = {
641 .owner = THIS_MODULE,
642 .name = "saa7191",
643 },
644 .probe = saa7191_probe,
645 .remove = saa7191_remove,
646 .id_table = saa7191_id,
647};
648
649module_i2c_driver(saa7191_driver);
diff --git a/drivers/staging/media/vino/saa7191.h b/drivers/staging/media/vino/saa7191.h
deleted file mode 100644
index 803c74d6066f..000000000000
--- a/drivers/staging/media/vino/saa7191.h
+++ /dev/null
@@ -1,245 +0,0 @@
1/*
2 * saa7191.h - Philips SAA7191 video decoder driver
3 *
4 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
5 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#ifndef _SAA7191_H_
13#define _SAA7191_H_
14
15/* Philips SAA7191 DMSD I2C bus address */
16#define SAA7191_ADDR 0x8a
17
18/* Register subaddresses. */
19#define SAA7191_REG_IDEL 0x00
20#define SAA7191_REG_HSYB 0x01
21#define SAA7191_REG_HSYS 0x02
22#define SAA7191_REG_HCLB 0x03
23#define SAA7191_REG_HCLS 0x04
24#define SAA7191_REG_HPHI 0x05
25#define SAA7191_REG_LUMA 0x06
26#define SAA7191_REG_HUEC 0x07
27#define SAA7191_REG_CKTQ 0x08 /* bits 3-7 */
28#define SAA7191_REG_CKTS 0x09 /* bits 3-7 */
29#define SAA7191_REG_PLSE 0x0a
30#define SAA7191_REG_SESE 0x0b
31#define SAA7191_REG_GAIN 0x0c
32#define SAA7191_REG_STDC 0x0d
33#define SAA7191_REG_IOCK 0x0e
34#define SAA7191_REG_CTL3 0x0f
35#define SAA7191_REG_CTL4 0x10
36#define SAA7191_REG_CHCV 0x11
37#define SAA7191_REG_HS6B 0x14
38#define SAA7191_REG_HS6S 0x15
39#define SAA7191_REG_HC6B 0x16
40#define SAA7191_REG_HC6S 0x17
41#define SAA7191_REG_HP6I 0x18
42#define SAA7191_REG_STATUS 0xff /* not really a subaddress */
43
44/* Status Register definitions */
45#define SAA7191_STATUS_CODE 0x01 /* color detected flag */
46#define SAA7191_STATUS_FIDT 0x20 /* signal type 50/60 Hz */
47#define SAA7191_STATUS_HLCK 0x40 /* PLL unlocked(1)/locked(0) */
48#define SAA7191_STATUS_STTC 0x80 /* tv/vtr time constant */
49
50/* Luminance Control Register definitions */
51/* input mode select bit:
52 * 0=CVBS (chrominance trap active), 1=S-Video (trap bypassed) */
53#define SAA7191_LUMA_BYPS 0x80
54/* pre-filter (only when chrominance trap is active) */
55#define SAA7191_LUMA_PREF 0x40
56/* aperture bandpass to select different characteristics with maximums
57 * (bits 4-5) */
58#define SAA7191_LUMA_BPSS_MASK 0x30
59#define SAA7191_LUMA_BPSS_SHIFT 4
60#define SAA7191_LUMA_BPSS_3 0x30
61#define SAA7191_LUMA_BPSS_2 0x20
62#define SAA7191_LUMA_BPSS_1 0x10
63#define SAA7191_LUMA_BPSS_0 0x00
64/* coring range for high frequency components according to 8-bit luminance
65 * (bits 2-3)
66 * 0=coring off, n= (+-)n LSB */
67#define SAA7191_LUMA_CORI_MASK 0x0c
68#define SAA7191_LUMA_CORI_SHIFT 2
69#define SAA7191_LUMA_CORI_3 0x0c
70#define SAA7191_LUMA_CORI_2 0x08
71#define SAA7191_LUMA_CORI_1 0x04
72#define SAA7191_LUMA_CORI_0 0x00
73/* aperture bandpass filter weights high frequency components of luminance
74 * signal (bits 0-1)
75 * 0=factor 0, 1=0.25, 2=0.5, 3=1 */
76#define SAA7191_LUMA_APER_MASK 0x03
77#define SAA7191_LUMA_APER_SHIFT 0
78#define SAA7191_LUMA_APER_3 0x03
79#define SAA7191_LUMA_APER_2 0x02
80#define SAA7191_LUMA_APER_1 0x01
81#define SAA7191_LUMA_APER_0 0x00
82
83/* Chrominance Gain Control Settings Register definitions */
84/* colour on: 0=automatic colour-killer enabled, 1=forced colour on */
85#define SAA7191_GAIN_COLO 0x80
86/* chrominance gain control (AGC filter)
87 * 0=loop filter time constant slow, 1=medium, 2=fast, 3=actual gain */
88#define SAA7191_GAIN_LFIS_MASK 0x60
89#define SAA7191_GAIN_LFIS_SHIFT 5
90#define SAA7191_GAIN_LFIS_3 0x60
91#define SAA7191_GAIN_LFIS_2 0x40
92#define SAA7191_GAIN_LFIS_1 0x20
93#define SAA7191_GAIN_LFIS_0 0x00
94
95/* Standard/Mode Control Register definitions */
96/* tv/vtr mode bit: 0=TV mode (slow time constant),
97 * 1=VTR mode (fast time constant) */
98#define SAA7191_STDC_VTRC 0x80
99/* SAA7191B-specific functions enable (RTCO, ODD and GPSW0 outputs)
100 * 0=outputs set to high-impedance (circuit equals SAA7191), 1=enabled */
101#define SAA7191_STDC_NFEN 0x08
102/* HREF generation: 0=like SAA7191, 1=HREF is 8xLLC2 clocks earlier */
103#define SAA7191_STDC_HRMV 0x04
104/* general purpose switch 0
105 * (not used with VINO afaik) */
106#define SAA7191_STDC_GPSW0 0x02
107/* SECAM mode bit: 0=other standards, 1=SECAM */
108#define SAA7191_STDC_SECS 0x01
109
110/* I/O and Clock Control Register definitions */
111/* horizontal clock PLL: 0=PLL closed,
112 * 1=PLL circuit open and horizontal freq fixed */
113#define SAA7191_IOCK_HPLL 0x80
114/* colour-difference output enable (outputs UV0-UV7) */
115#define SAA7191_IOCK_OEDC 0x40
116/* H-sync output enable */
117#define SAA7191_IOCK_OEHS 0x20
118/* V-sync output enable */
119#define SAA7191_IOCK_OEVS 0x10
120/* luminance output enable (outputs Y0-Y7) */
121#define SAA7191_IOCK_OEDY 0x08
122/* S-VHS bit (chrominance from CVBS or from chrominance input):
123 * 0=controlled by BYPS-bit, 1=from chrominance input */
124#define SAA7191_IOCK_CHRS 0x04
125/* general purpose switch 2
126 * VINO-specific: 0=used with CVBS, 1=used with S-Video */
127#define SAA7191_IOCK_GPSW2 0x02
128/* general purpose switch 1 */
129/* VINO-specific: 0=always, 1=not used!*/
130#define SAA7191_IOCK_GPSW1 0x01
131
132/* Miscellaneous Control #1 Register definitions */
133/* automatic field detection (50/60Hz standard) */
134#define SAA7191_CTL3_AUFD 0x80
135/* field select: (if AUFD=0)
136 * 0=50Hz (625 lines), 1=60Hz (525 lines) */
137#define SAA7191_CTL3_FSEL 0x40
138/* SECAM cross-colour reduction enable */
139#define SAA7191_CTL3_SXCR 0x20
140/* sync and clamping pulse enable (HCL and HSY outputs) */
141#define SAA7191_CTL3_SCEN 0x10
142/* output format: 0=4:1:1, 1=4:2:2 (4:2:2 for VINO) */
143#define SAA7191_CTL3_OFTS 0x08
144/* luminance delay compensation
145 * 0=0*2/LLC, 1=+1*2/LLC, 2=+2*2/LLC, 3=+3*2/LLC,
146 * 4=-4*2/LLC, 5=-3*2/LLC, 6=-2*2/LLC, 7=-1*2/LLC
147 * step size = 2/LLC = 67.8ns for 50Hz, 81.5ns for 60Hz */
148#define SAA7191_CTL3_YDEL_MASK 0x07
149#define SAA7191_CTL3_YDEL_SHIFT 0
150#define SAA7191_CTL3_YDEL2 0x04
151#define SAA7191_CTL3_YDEL1 0x02
152#define SAA7191_CTL3_YDEL0 0x01
153
154/* Miscellaneous Control #2 Register definitions */
155/* select HREF position
156 * 0=normal, HREF is matched to YUV output port,
157 * 1=HREF is matched to CVBS input port */
158#define SAA7191_CTL4_HRFS 0x04
159/* vertical noise reduction
160 * 0=normal, 1=searching window, 2=auto-deflection, 3=reduction bypassed */
161#define SAA7191_CTL4_VNOI_MASK 0x03
162#define SAA7191_CTL4_VNOI_SHIFT 0
163#define SAA7191_CTL4_VNOI_3 0x03
164#define SAA7191_CTL4_VNOI_2 0x02
165#define SAA7191_CTL4_VNOI_1 0x01
166#define SAA7191_CTL4_VNOI_0 0x00
167
168/* Chrominance Gain Control Register definitions
169 * - for QAM-modulated input signals, effects output amplitude
170 * (SECAM gain fixed)
171 * (nominal values for UV CCIR level) */
172#define SAA7191_CHCV_NTSC 0x2c
173#define SAA7191_CHCV_PAL 0x59
174
175/* Driver interface definitions */
176#define SAA7191_INPUT_COMPOSITE 0
177#define SAA7191_INPUT_SVIDEO 1
178
179#define SAA7191_NORM_PAL 1
180#define SAA7191_NORM_NTSC 2
181#define SAA7191_NORM_SECAM 3
182
183struct saa7191_status {
184 /* 0=no signal, 1=signal detected */
185 int signal;
186 /* 0=50hz (pal) signal, 1=60hz (ntsc) signal */
187 int signal_60hz;
188 /* 0=no color detected, 1=color detected */
189 int color;
190
191 /* current SAA7191_INPUT_ */
192 int input;
193 /* current SAA7191_NORM_ */
194 int norm;
195};
196
197#define SAA7191_BANDPASS_MIN 0x00
198#define SAA7191_BANDPASS_MAX 0x03
199#define SAA7191_BANDPASS_DEFAULT 0x00
200
201#define SAA7191_BANDPASS_WEIGHT_MIN 0x00
202#define SAA7191_BANDPASS_WEIGHT_MAX 0x03
203#define SAA7191_BANDPASS_WEIGHT_DEFAULT 0x01
204
205#define SAA7191_CORING_MIN 0x00
206#define SAA7191_CORING_MAX 0x03
207#define SAA7191_CORING_DEFAULT 0x00
208
209#define SAA7191_HUE_MIN 0x00
210#define SAA7191_HUE_MAX 0xff
211#define SAA7191_HUE_DEFAULT 0x80
212
213#define SAA7191_VTRC_MIN 0x00
214#define SAA7191_VTRC_MAX 0x01
215#define SAA7191_VTRC_DEFAULT 0x00
216
217#define SAA7191_FORCE_COLOUR_MIN 0x00
218#define SAA7191_FORCE_COLOUR_MAX 0x01
219#define SAA7191_FORCE_COLOUR_DEFAULT 0x00
220
221#define SAA7191_CHROMA_GAIN_MIN 0x00
222#define SAA7191_CHROMA_GAIN_MAX 0x03
223#define SAA7191_CHROMA_GAIN_DEFAULT 0x00
224
225#define SAA7191_LUMA_DELAY_MIN -0x04
226#define SAA7191_LUMA_DELAY_MAX 0x03
227#define SAA7191_LUMA_DELAY_DEFAULT 0x01
228
229#define SAA7191_VNR_MIN 0x00
230#define SAA7191_VNR_MAX 0x03
231#define SAA7191_VNR_DEFAULT 0x00
232
233#define SAA7191_CONTROL_BANDPASS (V4L2_CID_PRIVATE_BASE + 0)
234#define SAA7191_CONTROL_BANDPASS_WEIGHT (V4L2_CID_PRIVATE_BASE + 1)
235#define SAA7191_CONTROL_CORING (V4L2_CID_PRIVATE_BASE + 2)
236#define SAA7191_CONTROL_FORCE_COLOUR (V4L2_CID_PRIVATE_BASE + 3)
237#define SAA7191_CONTROL_CHROMA_GAIN (V4L2_CID_PRIVATE_BASE + 4)
238#define SAA7191_CONTROL_VTRC (V4L2_CID_PRIVATE_BASE + 5)
239#define SAA7191_CONTROL_LUMA_DELAY (V4L2_CID_PRIVATE_BASE + 6)
240#define SAA7191_CONTROL_VNR (V4L2_CID_PRIVATE_BASE + 7)
241
242#define DECODER_SAA7191_GET_STATUS _IOR('d', 195, struct saa7191_status)
243#define DECODER_SAA7191_SET_NORM _IOW('d', 196, int)
244
245#endif
diff --git a/drivers/staging/media/vino/vino.c b/drivers/staging/media/vino/vino.c
deleted file mode 100644
index 2c85357f774d..000000000000
--- a/drivers/staging/media/vino/vino.c
+++ /dev/null
@@ -1,4345 +0,0 @@
1/*
2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation.
6 *
7 * Copyright (C) 2004,2005 Mikael Nousiainen <tmnousia@cc.hut.fi>
8 *
9 * Based on the previous version of the driver for 2.4 kernels by:
10 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
11 *
12 * v4l2_device/v4l2_subdev conversion by:
13 * Copyright (C) 2009 Hans Verkuil <hverkuil@xs4all.nl>
14 *
15 * Note: this conversion is untested! Please contact the linux-media
16 * mailinglist if you can test this, together with the test results.
17 */
18
19/*
20 * TODO:
21 * - remove "mark pages reserved-hacks" from memory allocation code
22 * and implement fault()
23 * - check decimation, calculating and reporting image size when
24 * using decimation
25 * - implement read(), user mode buffers and overlay (?)
26 */
27
28#include <linux/init.h>
29#include <linux/module.h>
30#include <linux/delay.h>
31#include <linux/dma-mapping.h>
32#include <linux/errno.h>
33#include <linux/fs.h>
34#include <linux/interrupt.h>
35#include <linux/kernel.h>
36#include <linux/slab.h>
37#include <linux/mm.h>
38#include <linux/time.h>
39#include <linux/kmod.h>
40
41#include <linux/i2c.h>
42
43#include <linux/videodev2.h>
44#include <media/v4l2-device.h>
45#include <media/v4l2-ioctl.h>
46#include <linux/mutex.h>
47
48#include <asm/paccess.h>
49#include <asm/io.h>
50#include <asm/sgi/ip22.h>
51#include <asm/sgi/mc.h>
52
53#include "vino.h"
54#include "saa7191.h"
55#include "indycam.h"
56
57/* Uncomment the following line to get lots and lots of (mostly useless)
58 * debug info.
59 * Note that the debug output also slows down the driver significantly */
60// #define VINO_DEBUG
61// #define VINO_DEBUG_INT
62
63#define VINO_MODULE_VERSION "0.0.7"
64
65MODULE_DESCRIPTION("SGI VINO Video4Linux2 driver");
66MODULE_VERSION(VINO_MODULE_VERSION);
67MODULE_AUTHOR("Mikael Nousiainen <tmnousia@cc.hut.fi>");
68MODULE_LICENSE("GPL");
69
70#ifdef VINO_DEBUG
71#define dprintk(x...) printk("VINO: " x);
72#else
73#define dprintk(x...)
74#endif
75
76#define VINO_NO_CHANNEL 0
77#define VINO_CHANNEL_A 1
78#define VINO_CHANNEL_B 2
79
80#define VINO_PAL_WIDTH 768
81#define VINO_PAL_HEIGHT 576
82#define VINO_NTSC_WIDTH 640
83#define VINO_NTSC_HEIGHT 480
84
85#define VINO_MIN_WIDTH 32
86#define VINO_MIN_HEIGHT 32
87
88#define VINO_CLIPPING_START_ODD_D1 1
89#define VINO_CLIPPING_START_ODD_PAL 15
90#define VINO_CLIPPING_START_ODD_NTSC 12
91
92#define VINO_CLIPPING_START_EVEN_D1 2
93#define VINO_CLIPPING_START_EVEN_PAL 15
94#define VINO_CLIPPING_START_EVEN_NTSC 12
95
96#define VINO_INPUT_CHANNEL_COUNT 3
97
98/* the number is the index for vino_inputs */
99#define VINO_INPUT_NONE -1
100#define VINO_INPUT_COMPOSITE 0
101#define VINO_INPUT_SVIDEO 1
102#define VINO_INPUT_D1 2
103
104#define VINO_PAGE_RATIO (PAGE_SIZE / VINO_PAGE_SIZE)
105
106#define VINO_FIFO_THRESHOLD_DEFAULT 16
107
108#define VINO_FRAMEBUFFER_SIZE ((VINO_PAL_WIDTH \
109 * VINO_PAL_HEIGHT * 4 \
110 + 3 * PAGE_SIZE) & ~(PAGE_SIZE - 1))
111
112#define VINO_FRAMEBUFFER_COUNT_MAX 8
113
114#define VINO_FRAMEBUFFER_UNUSED 0
115#define VINO_FRAMEBUFFER_IN_USE 1
116#define VINO_FRAMEBUFFER_READY 2
117
118#define VINO_QUEUE_ERROR -1
119#define VINO_QUEUE_MAGIC 0x20050125
120
121#define VINO_MEMORY_NONE 0
122#define VINO_MEMORY_MMAP 1
123#define VINO_MEMORY_USERPTR 2
124
125#define VINO_DUMMY_DESC_COUNT 4
126#define VINO_DESC_FETCH_DELAY 5 /* microseconds */
127
128#define VINO_MAX_FRAME_SKIP_COUNT 128
129
130/* the number is the index for vino_data_formats */
131#define VINO_DATA_FMT_NONE -1
132#define VINO_DATA_FMT_GREY 0
133#define VINO_DATA_FMT_RGB332 1
134#define VINO_DATA_FMT_RGB32 2
135#define VINO_DATA_FMT_YUV 3
136
137#define VINO_DATA_FMT_COUNT 4
138
139/* the number is the index for vino_data_norms */
140#define VINO_DATA_NORM_NONE -1
141#define VINO_DATA_NORM_NTSC 0
142#define VINO_DATA_NORM_PAL 1
143#define VINO_DATA_NORM_SECAM 2
144#define VINO_DATA_NORM_D1 3
145
146#define VINO_DATA_NORM_COUNT 4
147
148/* I2C controller flags */
149#define SGI_I2C_FORCE_IDLE (0 << 0)
150#define SGI_I2C_NOT_IDLE (1 << 0)
151#define SGI_I2C_WRITE (0 << 1)
152#define SGI_I2C_READ (1 << 1)
153#define SGI_I2C_RELEASE_BUS (0 << 2)
154#define SGI_I2C_HOLD_BUS (1 << 2)
155#define SGI_I2C_XFER_DONE (0 << 4)
156#define SGI_I2C_XFER_BUSY (1 << 4)
157#define SGI_I2C_ACK (0 << 5)
158#define SGI_I2C_NACK (1 << 5)
159#define SGI_I2C_BUS_OK (0 << 7)
160#define SGI_I2C_BUS_ERR (1 << 7)
161
162/* Internal data structure definitions */
163
164struct vino_input {
165 char *name;
166 v4l2_std_id std;
167};
168
169struct vino_clipping {
170 unsigned int left, right, top, bottom;
171};
172
173struct vino_data_format {
174 /* the description */
175 char *description;
176 /* bytes per pixel */
177 unsigned int bpp;
178 /* V4L2 fourcc code */
179 __u32 pixelformat;
180 /* V4L2 colorspace (duh!) */
181 enum v4l2_colorspace colorspace;
182};
183
184struct vino_data_norm {
185 char *description;
186 unsigned int width, height;
187 struct vino_clipping odd;
188 struct vino_clipping even;
189
190 v4l2_std_id std;
191 unsigned int fps_min, fps_max;
192 __u32 framelines;
193};
194
195struct vino_descriptor_table {
196 /* the number of PAGE_SIZE sized pages in the buffer */
197 unsigned int page_count;
198 /* virtual (kmalloc'd) pointers to the actual data
199 * (in PAGE_SIZE chunks, used with mmap streaming) */
200 unsigned long *virtual;
201
202 /* cpu address for the VINO descriptor table
203 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
204 unsigned long *dma_cpu;
205 /* dma address for the VINO descriptor table
206 * (contains DMA addresses, VINO_PAGE_SIZE chunks) */
207 dma_addr_t dma;
208};
209
210struct vino_framebuffer {
211 /* identifier nubmer */
212 unsigned int id;
213 /* the length of the whole buffer */
214 unsigned int size;
215 /* the length of actual data in buffer */
216 unsigned int data_size;
217 /* the data format */
218 unsigned int data_format;
219 /* the state of buffer data */
220 unsigned int state;
221 /* is the buffer mapped in user space? */
222 unsigned int map_count;
223 /* memory offset for mmap() */
224 unsigned int offset;
225 /* frame counter */
226 unsigned int frame_counter;
227 /* timestamp (written when image capture finishes) */
228 struct timeval timestamp;
229
230 struct vino_descriptor_table desc_table;
231
232 spinlock_t state_lock;
233};
234
235struct vino_framebuffer_fifo {
236 unsigned int length;
237
238 unsigned int used;
239 unsigned int head;
240 unsigned int tail;
241
242 unsigned int data[VINO_FRAMEBUFFER_COUNT_MAX];
243};
244
245struct vino_framebuffer_queue {
246 unsigned int magic;
247
248 /* VINO_MEMORY_NONE, VINO_MEMORY_MMAP or VINO_MEMORY_USERPTR */
249 unsigned int type;
250 unsigned int length;
251
252 /* data field of in and out contain index numbers for buffer */
253 struct vino_framebuffer_fifo in;
254 struct vino_framebuffer_fifo out;
255
256 struct vino_framebuffer *buffer[VINO_FRAMEBUFFER_COUNT_MAX];
257
258 spinlock_t queue_lock;
259 struct mutex queue_mutex;
260 wait_queue_head_t frame_wait_queue;
261};
262
263struct vino_interrupt_data {
264 struct timeval timestamp;
265 unsigned int frame_counter;
266 unsigned int skip_count;
267 unsigned int skip;
268};
269
270struct vino_channel_settings {
271 unsigned int channel;
272
273 int input;
274 unsigned int data_format;
275 unsigned int data_norm;
276 struct vino_clipping clipping;
277 unsigned int decimation;
278 unsigned int line_size;
279 unsigned int alpha;
280 unsigned int fps;
281 unsigned int framert_reg;
282
283 unsigned int fifo_threshold;
284
285 struct vino_framebuffer_queue fb_queue;
286
287 /* number of the current field */
288 unsigned int field;
289
290 /* read in progress */
291 int reading;
292 /* streaming is active */
293 int streaming;
294 /* the driver is currently processing the queue */
295 int capturing;
296
297 struct mutex mutex;
298 spinlock_t capture_lock;
299
300 unsigned int users;
301
302 struct vino_interrupt_data int_data;
303
304 /* V4L support */
305 struct video_device *vdev;
306};
307
308struct vino_settings {
309 struct v4l2_device v4l2_dev;
310 struct vino_channel_settings a;
311 struct vino_channel_settings b;
312
313 /* the channel which owns this client:
314 * VINO_NO_CHANNEL, VINO_CHANNEL_A or VINO_CHANNEL_B */
315 unsigned int decoder_owner;
316 struct v4l2_subdev *decoder;
317 unsigned int camera_owner;
318 struct v4l2_subdev *camera;
319
320 /* a lock for vino register access */
321 spinlock_t vino_lock;
322 /* a lock for channel input changes */
323 spinlock_t input_lock;
324
325 unsigned long dummy_page;
326 struct vino_descriptor_table dummy_desc_table;
327};
328
329/* Module parameters */
330
331/*
332 * Using vino_pixel_conversion the ABGR32-format pixels supplied
333 * by the VINO chip can be converted to more common formats
334 * like RGBA32 (or probably RGB24 in the future). This way we
335 * can give out data that can be specified correctly with
336 * the V4L2-definitions.
337 *
338 * The pixel format is specified as RGBA32 when no conversion
339 * is used.
340 *
341 * Note that this only affects the 32-bit bit depth.
342 *
343 * Use non-zero value to enable conversion.
344 */
345static int vino_pixel_conversion;
346
347module_param_named(pixelconv, vino_pixel_conversion, int, 0);
348
349MODULE_PARM_DESC(pixelconv,
350 "enable pixel conversion (non-zero value enables)");
351
352/* Internal data structures */
353
354static struct sgi_vino *vino;
355
356static struct vino_settings *vino_drvdata;
357
358#define camera_call(o, f, args...) \
359 v4l2_subdev_call(vino_drvdata->camera, o, f, ##args)
360#define decoder_call(o, f, args...) \
361 v4l2_subdev_call(vino_drvdata->decoder, o, f, ##args)
362
363static const char *vino_driver_name = "vino";
364static const char *vino_driver_description = "SGI VINO";
365static const char *vino_bus_name = "GIO64 bus";
366static const char *vino_vdev_name_a = "SGI VINO Channel A";
367static const char *vino_vdev_name_b = "SGI VINO Channel B";
368
369static void vino_capture_tasklet(unsigned long channel);
370
371DECLARE_TASKLET(vino_tasklet_a, vino_capture_tasklet, VINO_CHANNEL_A);
372DECLARE_TASKLET(vino_tasklet_b, vino_capture_tasklet, VINO_CHANNEL_B);
373
374static const struct vino_input vino_inputs[] = {
375 {
376 .name = "Composite",
377 .std = V4L2_STD_NTSC | V4L2_STD_PAL
378 | V4L2_STD_SECAM,
379 }, {
380 .name = "S-Video",
381 .std = V4L2_STD_NTSC | V4L2_STD_PAL
382 | V4L2_STD_SECAM,
383 }, {
384 .name = "D1/IndyCam",
385 .std = V4L2_STD_NTSC,
386 }
387};
388
389static const struct vino_data_format vino_data_formats[] = {
390 {
391 .description = "8-bit greyscale",
392 .bpp = 1,
393 .pixelformat = V4L2_PIX_FMT_GREY,
394 .colorspace = V4L2_COLORSPACE_SMPTE170M,
395 }, {
396 .description = "8-bit dithered RGB 3-3-2",
397 .bpp = 1,
398 .pixelformat = V4L2_PIX_FMT_RGB332,
399 .colorspace = V4L2_COLORSPACE_SRGB,
400 }, {
401 .description = "32-bit RGB",
402 .bpp = 4,
403 .pixelformat = V4L2_PIX_FMT_RGB32,
404 .colorspace = V4L2_COLORSPACE_SRGB,
405 }, {
406 .description = "YUV 4:2:2",
407 .bpp = 2,
408 .pixelformat = V4L2_PIX_FMT_YUYV, // XXX: swapped?
409 .colorspace = V4L2_COLORSPACE_SMPTE170M,
410 }
411};
412
413static const struct vino_data_norm vino_data_norms[] = {
414 {
415 .description = "NTSC",
416 .std = V4L2_STD_NTSC,
417 .fps_min = 6,
418 .fps_max = 30,
419 .framelines = 525,
420 .width = VINO_NTSC_WIDTH,
421 .height = VINO_NTSC_HEIGHT,
422 .odd = {
423 .top = VINO_CLIPPING_START_ODD_NTSC,
424 .left = 0,
425 .bottom = VINO_CLIPPING_START_ODD_NTSC
426 + VINO_NTSC_HEIGHT / 2 - 1,
427 .right = VINO_NTSC_WIDTH,
428 },
429 .even = {
430 .top = VINO_CLIPPING_START_EVEN_NTSC,
431 .left = 0,
432 .bottom = VINO_CLIPPING_START_EVEN_NTSC
433 + VINO_NTSC_HEIGHT / 2 - 1,
434 .right = VINO_NTSC_WIDTH,
435 },
436 }, {
437 .description = "PAL",
438 .std = V4L2_STD_PAL,
439 .fps_min = 5,
440 .fps_max = 25,
441 .framelines = 625,
442 .width = VINO_PAL_WIDTH,
443 .height = VINO_PAL_HEIGHT,
444 .odd = {
445 .top = VINO_CLIPPING_START_ODD_PAL,
446 .left = 0,
447 .bottom = VINO_CLIPPING_START_ODD_PAL
448 + VINO_PAL_HEIGHT / 2 - 1,
449 .right = VINO_PAL_WIDTH,
450 },
451 .even = {
452 .top = VINO_CLIPPING_START_EVEN_PAL,
453 .left = 0,
454 .bottom = VINO_CLIPPING_START_EVEN_PAL
455 + VINO_PAL_HEIGHT / 2 - 1,
456 .right = VINO_PAL_WIDTH,
457 },
458 }, {
459 .description = "SECAM",
460 .std = V4L2_STD_SECAM,
461 .fps_min = 5,
462 .fps_max = 25,
463 .framelines = 625,
464 .width = VINO_PAL_WIDTH,
465 .height = VINO_PAL_HEIGHT,
466 .odd = {
467 .top = VINO_CLIPPING_START_ODD_PAL,
468 .left = 0,
469 .bottom = VINO_CLIPPING_START_ODD_PAL
470 + VINO_PAL_HEIGHT / 2 - 1,
471 .right = VINO_PAL_WIDTH,
472 },
473 .even = {
474 .top = VINO_CLIPPING_START_EVEN_PAL,
475 .left = 0,
476 .bottom = VINO_CLIPPING_START_EVEN_PAL
477 + VINO_PAL_HEIGHT / 2 - 1,
478 .right = VINO_PAL_WIDTH,
479 },
480 }, {
481 .description = "NTSC/D1",
482 .std = V4L2_STD_NTSC,
483 .fps_min = 6,
484 .fps_max = 30,
485 .framelines = 525,
486 .width = VINO_NTSC_WIDTH,
487 .height = VINO_NTSC_HEIGHT,
488 .odd = {
489 .top = VINO_CLIPPING_START_ODD_D1,
490 .left = 0,
491 .bottom = VINO_CLIPPING_START_ODD_D1
492 + VINO_NTSC_HEIGHT / 2 - 1,
493 .right = VINO_NTSC_WIDTH,
494 },
495 .even = {
496 .top = VINO_CLIPPING_START_EVEN_D1,
497 .left = 0,
498 .bottom = VINO_CLIPPING_START_EVEN_D1
499 + VINO_NTSC_HEIGHT / 2 - 1,
500 .right = VINO_NTSC_WIDTH,
501 },
502 }
503};
504
505#define VINO_INDYCAM_V4L2_CONTROL_COUNT 9
506
507struct v4l2_queryctrl vino_indycam_v4l2_controls[] = {
508 {
509 .id = V4L2_CID_AUTOGAIN,
510 .type = V4L2_CTRL_TYPE_BOOLEAN,
511 .name = "Automatic Gain Control",
512 .minimum = 0,
513 .maximum = 1,
514 .step = 1,
515 .default_value = INDYCAM_AGC_DEFAULT,
516 }, {
517 .id = V4L2_CID_AUTO_WHITE_BALANCE,
518 .type = V4L2_CTRL_TYPE_BOOLEAN,
519 .name = "Automatic White Balance",
520 .minimum = 0,
521 .maximum = 1,
522 .step = 1,
523 .default_value = INDYCAM_AWB_DEFAULT,
524 }, {
525 .id = V4L2_CID_GAIN,
526 .type = V4L2_CTRL_TYPE_INTEGER,
527 .name = "Gain",
528 .minimum = INDYCAM_GAIN_MIN,
529 .maximum = INDYCAM_GAIN_MAX,
530 .step = 1,
531 .default_value = INDYCAM_GAIN_DEFAULT,
532 }, {
533 .id = INDYCAM_CONTROL_RED_SATURATION,
534 .type = V4L2_CTRL_TYPE_INTEGER,
535 .name = "Red Saturation",
536 .minimum = INDYCAM_RED_SATURATION_MIN,
537 .maximum = INDYCAM_RED_SATURATION_MAX,
538 .step = 1,
539 .default_value = INDYCAM_RED_SATURATION_DEFAULT,
540 }, {
541 .id = INDYCAM_CONTROL_BLUE_SATURATION,
542 .type = V4L2_CTRL_TYPE_INTEGER,
543 .name = "Blue Saturation",
544 .minimum = INDYCAM_BLUE_SATURATION_MIN,
545 .maximum = INDYCAM_BLUE_SATURATION_MAX,
546 .step = 1,
547 .default_value = INDYCAM_BLUE_SATURATION_DEFAULT,
548 }, {
549 .id = V4L2_CID_RED_BALANCE,
550 .type = V4L2_CTRL_TYPE_INTEGER,
551 .name = "Red Balance",
552 .minimum = INDYCAM_RED_BALANCE_MIN,
553 .maximum = INDYCAM_RED_BALANCE_MAX,
554 .step = 1,
555 .default_value = INDYCAM_RED_BALANCE_DEFAULT,
556 }, {
557 .id = V4L2_CID_BLUE_BALANCE,
558 .type = V4L2_CTRL_TYPE_INTEGER,
559 .name = "Blue Balance",
560 .minimum = INDYCAM_BLUE_BALANCE_MIN,
561 .maximum = INDYCAM_BLUE_BALANCE_MAX,
562 .step = 1,
563 .default_value = INDYCAM_BLUE_BALANCE_DEFAULT,
564 }, {
565 .id = V4L2_CID_EXPOSURE,
566 .type = V4L2_CTRL_TYPE_INTEGER,
567 .name = "Shutter Control",
568 .minimum = INDYCAM_SHUTTER_MIN,
569 .maximum = INDYCAM_SHUTTER_MAX,
570 .step = 1,
571 .default_value = INDYCAM_SHUTTER_DEFAULT,
572 }, {
573 .id = V4L2_CID_GAMMA,
574 .type = V4L2_CTRL_TYPE_INTEGER,
575 .name = "Gamma",
576 .minimum = INDYCAM_GAMMA_MIN,
577 .maximum = INDYCAM_GAMMA_MAX,
578 .step = 1,
579 .default_value = INDYCAM_GAMMA_DEFAULT,
580 }
581};
582
583#define VINO_SAA7191_V4L2_CONTROL_COUNT 9
584
585struct v4l2_queryctrl vino_saa7191_v4l2_controls[] = {
586 {
587 .id = V4L2_CID_HUE,
588 .type = V4L2_CTRL_TYPE_INTEGER,
589 .name = "Hue",
590 .minimum = SAA7191_HUE_MIN,
591 .maximum = SAA7191_HUE_MAX,
592 .step = 1,
593 .default_value = SAA7191_HUE_DEFAULT,
594 }, {
595 .id = SAA7191_CONTROL_BANDPASS,
596 .type = V4L2_CTRL_TYPE_INTEGER,
597 .name = "Luminance Bandpass",
598 .minimum = SAA7191_BANDPASS_MIN,
599 .maximum = SAA7191_BANDPASS_MAX,
600 .step = 1,
601 .default_value = SAA7191_BANDPASS_DEFAULT,
602 }, {
603 .id = SAA7191_CONTROL_BANDPASS_WEIGHT,
604 .type = V4L2_CTRL_TYPE_INTEGER,
605 .name = "Luminance Bandpass Weight",
606 .minimum = SAA7191_BANDPASS_WEIGHT_MIN,
607 .maximum = SAA7191_BANDPASS_WEIGHT_MAX,
608 .step = 1,
609 .default_value = SAA7191_BANDPASS_WEIGHT_DEFAULT,
610 }, {
611 .id = SAA7191_CONTROL_CORING,
612 .type = V4L2_CTRL_TYPE_INTEGER,
613 .name = "HF Luminance Coring",
614 .minimum = SAA7191_CORING_MIN,
615 .maximum = SAA7191_CORING_MAX,
616 .step = 1,
617 .default_value = SAA7191_CORING_DEFAULT,
618 }, {
619 .id = SAA7191_CONTROL_FORCE_COLOUR,
620 .type = V4L2_CTRL_TYPE_BOOLEAN,
621 .name = "Force Colour",
622 .minimum = SAA7191_FORCE_COLOUR_MIN,
623 .maximum = SAA7191_FORCE_COLOUR_MAX,
624 .step = 1,
625 .default_value = SAA7191_FORCE_COLOUR_DEFAULT,
626 }, {
627 .id = SAA7191_CONTROL_CHROMA_GAIN,
628 .type = V4L2_CTRL_TYPE_INTEGER,
629 .name = "Chrominance Gain Control",
630 .minimum = SAA7191_CHROMA_GAIN_MIN,
631 .maximum = SAA7191_CHROMA_GAIN_MAX,
632 .step = 1,
633 .default_value = SAA7191_CHROMA_GAIN_DEFAULT,
634 }, {
635 .id = SAA7191_CONTROL_VTRC,
636 .type = V4L2_CTRL_TYPE_BOOLEAN,
637 .name = "VTR Time Constant",
638 .minimum = SAA7191_VTRC_MIN,
639 .maximum = SAA7191_VTRC_MAX,
640 .step = 1,
641 .default_value = SAA7191_VTRC_DEFAULT,
642 }, {
643 .id = SAA7191_CONTROL_LUMA_DELAY,
644 .type = V4L2_CTRL_TYPE_INTEGER,
645 .name = "Luminance Delay Compensation",
646 .minimum = SAA7191_LUMA_DELAY_MIN,
647 .maximum = SAA7191_LUMA_DELAY_MAX,
648 .step = 1,
649 .default_value = SAA7191_LUMA_DELAY_DEFAULT,
650 }, {
651 .id = SAA7191_CONTROL_VNR,
652 .type = V4L2_CTRL_TYPE_INTEGER,
653 .name = "Vertical Noise Reduction",
654 .minimum = SAA7191_VNR_MIN,
655 .maximum = SAA7191_VNR_MAX,
656 .step = 1,
657 .default_value = SAA7191_VNR_DEFAULT,
658 }
659};
660
661/* VINO framebuffer/DMA descriptor management */
662
663static void vino_free_buffer_with_count(struct vino_framebuffer *fb,
664 unsigned int count)
665{
666 unsigned int i;
667
668 dprintk("vino_free_buffer_with_count(): count = %d\n", count);
669
670 for (i = 0; i < count; i++) {
671 ClearPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
672 dma_unmap_single(NULL,
673 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
674 PAGE_SIZE, DMA_FROM_DEVICE);
675 free_page(fb->desc_table.virtual[i]);
676 }
677
678 dma_free_coherent(NULL,
679 VINO_PAGE_RATIO * (fb->desc_table.page_count + 4) *
680 sizeof(dma_addr_t), (void *)fb->desc_table.dma_cpu,
681 fb->desc_table.dma);
682 kfree(fb->desc_table.virtual);
683
684 memset(fb, 0, sizeof(struct vino_framebuffer));
685}
686
687static void vino_free_buffer(struct vino_framebuffer *fb)
688{
689 vino_free_buffer_with_count(fb, fb->desc_table.page_count);
690}
691
692static int vino_allocate_buffer(struct vino_framebuffer *fb,
693 unsigned int size)
694{
695 unsigned int count, i, j;
696 int ret = 0;
697
698 dprintk("vino_allocate_buffer():\n");
699
700 if (size < 1)
701 return -EINVAL;
702
703 memset(fb, 0, sizeof(struct vino_framebuffer));
704
705 count = ((size / PAGE_SIZE) + 4) & ~3;
706
707 dprintk("vino_allocate_buffer(): size = %d, count = %d\n",
708 size, count);
709
710 /* allocate memory for table with virtual (page) addresses */
711 fb->desc_table.virtual =
712 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
713 if (!fb->desc_table.virtual)
714 return -ENOMEM;
715
716 /* allocate memory for table with dma addresses
717 * (has space for four extra descriptors) */
718 fb->desc_table.dma_cpu =
719 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
720 sizeof(dma_addr_t), &fb->desc_table.dma,
721 GFP_KERNEL | GFP_DMA);
722 if (!fb->desc_table.dma_cpu) {
723 ret = -ENOMEM;
724 goto out_free_virtual;
725 }
726
727 /* allocate pages for the buffer and acquire the according
728 * dma addresses */
729 for (i = 0; i < count; i++) {
730 dma_addr_t dma_data_addr;
731
732 fb->desc_table.virtual[i] =
733 get_zeroed_page(GFP_KERNEL | GFP_DMA);
734 if (!fb->desc_table.virtual[i]) {
735 ret = -ENOBUFS;
736 break;
737 }
738
739 dma_data_addr =
740 dma_map_single(NULL,
741 (void *)fb->desc_table.virtual[i],
742 PAGE_SIZE, DMA_FROM_DEVICE);
743
744 for (j = 0; j < VINO_PAGE_RATIO; j++) {
745 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
746 dma_data_addr + VINO_PAGE_SIZE * j;
747 }
748
749 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
750 }
751
752 /* page_count needs to be set anyway, because the descriptor table has
753 * been allocated according to this number */
754 fb->desc_table.page_count = count;
755
756 if (ret) {
757 /* the descriptor with index i doesn't contain
758 * a valid address yet */
759 vino_free_buffer_with_count(fb, i);
760 return ret;
761 }
762
763 //fb->size = size;
764 fb->size = count * PAGE_SIZE;
765 fb->data_format = VINO_DATA_FMT_NONE;
766
767 /* set the dma stop-bit for the last (count+1)th descriptor */
768 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
769 return 0;
770
771 out_free_virtual:
772 kfree(fb->desc_table.virtual);
773 return ret;
774}
775
776#if 0
777/* user buffers not fully implemented yet */
778static int vino_prepare_user_buffer(struct vino_framebuffer *fb,
779 void *user,
780 unsigned int size)
781{
782 unsigned int count, i, j;
783 int ret = 0;
784
785 dprintk("vino_prepare_user_buffer():\n");
786
787 if (size < 1)
788 return -EINVAL;
789
790 memset(fb, 0, sizeof(struct vino_framebuffer));
791
792 count = ((size / PAGE_SIZE)) & ~3;
793
794 dprintk("vino_prepare_user_buffer(): size = %d, count = %d\n",
795 size, count);
796
797 /* allocate memory for table with virtual (page) addresses */
798 fb->desc_table.virtual = (unsigned long *)
799 kmalloc(count * sizeof(unsigned long), GFP_KERNEL);
800 if (!fb->desc_table.virtual)
801 return -ENOMEM;
802
803 /* allocate memory for table with dma addresses
804 * (has space for four extra descriptors) */
805 fb->desc_table.dma_cpu =
806 dma_alloc_coherent(NULL, VINO_PAGE_RATIO * (count + 4) *
807 sizeof(dma_addr_t), &fb->desc_table.dma,
808 GFP_KERNEL | GFP_DMA);
809 if (!fb->desc_table.dma_cpu) {
810 ret = -ENOMEM;
811 goto out_free_virtual;
812 }
813
814 /* allocate pages for the buffer and acquire the according
815 * dma addresses */
816 for (i = 0; i < count; i++) {
817 dma_addr_t dma_data_addr;
818
819 fb->desc_table.virtual[i] =
820 get_zeroed_page(GFP_KERNEL | GFP_DMA);
821 if (!fb->desc_table.virtual[i]) {
822 ret = -ENOBUFS;
823 break;
824 }
825
826 dma_data_addr =
827 dma_map_single(NULL,
828 (void *)fb->desc_table.virtual[i],
829 PAGE_SIZE, DMA_FROM_DEVICE);
830
831 for (j = 0; j < VINO_PAGE_RATIO; j++) {
832 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i + j] =
833 dma_data_addr + VINO_PAGE_SIZE * j;
834 }
835
836 SetPageReserved(virt_to_page((void *)fb->desc_table.virtual[i]));
837 }
838
839 /* page_count needs to be set anyway, because the descriptor table has
840 * been allocated according to this number */
841 fb->desc_table.page_count = count;
842
843 if (ret) {
844 /* the descriptor with index i doesn't contain
845 * a valid address yet */
846 vino_free_buffer_with_count(fb, i);
847 return ret;
848 }
849
850 //fb->size = size;
851 fb->size = count * PAGE_SIZE;
852
853 /* set the dma stop-bit for the last (count+1)th descriptor */
854 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * count] = VINO_DESC_STOP;
855 return 0;
856
857 out_free_virtual:
858 kfree(fb->desc_table.virtual);
859 return ret;
860}
861#endif
862
863static void vino_sync_buffer(struct vino_framebuffer *fb)
864{
865 int i;
866
867 dprintk("vino_sync_buffer():\n");
868
869 for (i = 0; i < fb->desc_table.page_count; i++)
870 dma_sync_single_for_cpu(NULL,
871 fb->desc_table.dma_cpu[VINO_PAGE_RATIO * i],
872 PAGE_SIZE, DMA_FROM_DEVICE);
873}
874
875/* Framebuffer fifo functions (need to be locked externally) */
876
877static inline void vino_fifo_init(struct vino_framebuffer_fifo *f,
878 unsigned int length)
879{
880 f->length = 0;
881 f->used = 0;
882 f->head = 0;
883 f->tail = 0;
884
885 if (length > VINO_FRAMEBUFFER_COUNT_MAX)
886 length = VINO_FRAMEBUFFER_COUNT_MAX;
887
888 f->length = length;
889}
890
891/* returns true/false */
892static inline int vino_fifo_has_id(struct vino_framebuffer_fifo *f,
893 unsigned int id)
894{
895 unsigned int i;
896
897 for (i = f->head; i == (f->tail - 1); i = (i + 1) % f->length) {
898 if (f->data[i] == id)
899 return 1;
900 }
901
902 return 0;
903}
904
905#if 0
906/* returns true/false */
907static inline int vino_fifo_full(struct vino_framebuffer_fifo *f)
908{
909 return (f->used == f->length);
910}
911#endif
912
913static inline unsigned int vino_fifo_get_used(struct vino_framebuffer_fifo *f)
914{
915 return f->used;
916}
917
918static int vino_fifo_enqueue(struct vino_framebuffer_fifo *f, unsigned int id)
919{
920 if (id >= f->length) {
921 return VINO_QUEUE_ERROR;
922 }
923
924 if (vino_fifo_has_id(f, id)) {
925 return VINO_QUEUE_ERROR;
926 }
927
928 if (f->used < f->length) {
929 f->data[f->tail] = id;
930 f->tail = (f->tail + 1) % f->length;
931 f->used++;
932 } else {
933 return VINO_QUEUE_ERROR;
934 }
935
936 return 0;
937}
938
939static int vino_fifo_peek(struct vino_framebuffer_fifo *f, unsigned int *id)
940{
941 if (f->used > 0) {
942 *id = f->data[f->head];
943 } else {
944 return VINO_QUEUE_ERROR;
945 }
946
947 return 0;
948}
949
950static int vino_fifo_dequeue(struct vino_framebuffer_fifo *f, unsigned int *id)
951{
952 if (f->used > 0) {
953 *id = f->data[f->head];
954 f->head = (f->head + 1) % f->length;
955 f->used--;
956 } else {
957 return VINO_QUEUE_ERROR;
958 }
959
960 return 0;
961}
962
963/* Framebuffer queue functions */
964
965/* execute with queue_lock locked */
966static void vino_queue_free_with_count(struct vino_framebuffer_queue *q,
967 unsigned int length)
968{
969 unsigned int i;
970
971 q->length = 0;
972 memset(&q->in, 0, sizeof(struct vino_framebuffer_fifo));
973 memset(&q->out, 0, sizeof(struct vino_framebuffer_fifo));
974 for (i = 0; i < length; i++) {
975 dprintk("vino_queue_free_with_count(): freeing buffer %d\n",
976 i);
977 vino_free_buffer(q->buffer[i]);
978 kfree(q->buffer[i]);
979 }
980
981 q->type = VINO_MEMORY_NONE;
982 q->magic = 0;
983}
984
985static void vino_queue_free(struct vino_framebuffer_queue *q)
986{
987 dprintk("vino_queue_free():\n");
988
989 if (q->magic != VINO_QUEUE_MAGIC)
990 return;
991 if (q->type != VINO_MEMORY_MMAP)
992 return;
993
994 mutex_lock(&q->queue_mutex);
995
996 vino_queue_free_with_count(q, q->length);
997
998 mutex_unlock(&q->queue_mutex);
999}
1000
1001static int vino_queue_init(struct vino_framebuffer_queue *q,
1002 unsigned int *length)
1003{
1004 unsigned int i;
1005 int ret = 0;
1006
1007 dprintk("vino_queue_init(): length = %d\n", *length);
1008
1009 if (q->magic == VINO_QUEUE_MAGIC) {
1010 dprintk("vino_queue_init(): queue already initialized!\n");
1011 return -EINVAL;
1012 }
1013
1014 if (q->type != VINO_MEMORY_NONE) {
1015 dprintk("vino_queue_init(): queue already initialized!\n");
1016 return -EINVAL;
1017 }
1018
1019 if (*length < 1)
1020 return -EINVAL;
1021
1022 mutex_lock(&q->queue_mutex);
1023
1024 if (*length > VINO_FRAMEBUFFER_COUNT_MAX)
1025 *length = VINO_FRAMEBUFFER_COUNT_MAX;
1026
1027 q->length = 0;
1028
1029 for (i = 0; i < *length; i++) {
1030 dprintk("vino_queue_init(): allocating buffer %d\n", i);
1031 q->buffer[i] = kmalloc(sizeof(struct vino_framebuffer),
1032 GFP_KERNEL);
1033 if (!q->buffer[i]) {
1034 dprintk("vino_queue_init(): kmalloc() failed\n");
1035 ret = -ENOMEM;
1036 break;
1037 }
1038
1039 ret = vino_allocate_buffer(q->buffer[i],
1040 VINO_FRAMEBUFFER_SIZE);
1041 if (ret) {
1042 kfree(q->buffer[i]);
1043 dprintk("vino_queue_init(): "
1044 "vino_allocate_buffer() failed\n");
1045 break;
1046 }
1047
1048 q->buffer[i]->id = i;
1049 if (i > 0) {
1050 q->buffer[i]->offset = q->buffer[i - 1]->offset +
1051 q->buffer[i - 1]->size;
1052 } else {
1053 q->buffer[i]->offset = 0;
1054 }
1055
1056 spin_lock_init(&q->buffer[i]->state_lock);
1057
1058 dprintk("vino_queue_init(): buffer = %d, offset = %d, "
1059 "size = %d\n", i, q->buffer[i]->offset,
1060 q->buffer[i]->size);
1061 }
1062
1063 if (ret) {
1064 vino_queue_free_with_count(q, i);
1065 *length = 0;
1066 } else {
1067 q->length = *length;
1068 vino_fifo_init(&q->in, q->length);
1069 vino_fifo_init(&q->out, q->length);
1070 q->type = VINO_MEMORY_MMAP;
1071 q->magic = VINO_QUEUE_MAGIC;
1072 }
1073
1074 mutex_unlock(&q->queue_mutex);
1075
1076 return ret;
1077}
1078
1079static struct vino_framebuffer *vino_queue_add(struct
1080 vino_framebuffer_queue *q,
1081 unsigned int id)
1082{
1083 struct vino_framebuffer *ret = NULL;
1084 unsigned int total;
1085 unsigned long flags;
1086
1087 dprintk("vino_queue_add(): id = %d\n", id);
1088
1089 if (q->magic != VINO_QUEUE_MAGIC) {
1090 return ret;
1091 }
1092
1093 spin_lock_irqsave(&q->queue_lock, flags);
1094
1095 if (q->length == 0)
1096 goto out;
1097
1098 if (id >= q->length)
1099 goto out;
1100
1101 /* not needed?: if (vino_fifo_full(&q->out)) {
1102 goto out;
1103 }*/
1104 /* check that outgoing queue isn't already full
1105 * (or that it won't become full) */
1106 total = vino_fifo_get_used(&q->in) +
1107 vino_fifo_get_used(&q->out);
1108 if (total >= q->length)
1109 goto out;
1110
1111 if (vino_fifo_enqueue(&q->in, id))
1112 goto out;
1113
1114 ret = q->buffer[id];
1115
1116out:
1117 spin_unlock_irqrestore(&q->queue_lock, flags);
1118
1119 return ret;
1120}
1121
1122static struct vino_framebuffer *vino_queue_transfer(struct
1123 vino_framebuffer_queue *q)
1124{
1125 struct vino_framebuffer *ret = NULL;
1126 struct vino_framebuffer *fb;
1127 int id;
1128 unsigned long flags;
1129
1130 dprintk("vino_queue_transfer():\n");
1131
1132 if (q->magic != VINO_QUEUE_MAGIC) {
1133 return ret;
1134 }
1135
1136 spin_lock_irqsave(&q->queue_lock, flags);
1137
1138 if (q->length == 0)
1139 goto out;
1140
1141 // now this actually removes an entry from the incoming queue
1142 if (vino_fifo_dequeue(&q->in, &id)) {
1143 goto out;
1144 }
1145
1146 dprintk("vino_queue_transfer(): id = %d\n", id);
1147 fb = q->buffer[id];
1148
1149 // we have already checked that the outgoing queue is not full, but...
1150 if (vino_fifo_enqueue(&q->out, id)) {
1151 printk(KERN_ERR "vino_queue_transfer(): "
1152 "outgoing queue is full, this shouldn't happen!\n");
1153 goto out;
1154 }
1155
1156 ret = fb;
1157out:
1158 spin_unlock_irqrestore(&q->queue_lock, flags);
1159
1160 return ret;
1161}
1162
1163/* returns true/false */
1164static int vino_queue_incoming_contains(struct vino_framebuffer_queue *q,
1165 unsigned int id)
1166{
1167 int ret = 0;
1168 unsigned long flags;
1169
1170 if (q->magic != VINO_QUEUE_MAGIC) {
1171 return ret;
1172 }
1173
1174 spin_lock_irqsave(&q->queue_lock, flags);
1175
1176 if (q->length == 0)
1177 goto out;
1178
1179 ret = vino_fifo_has_id(&q->in, id);
1180
1181out:
1182 spin_unlock_irqrestore(&q->queue_lock, flags);
1183
1184 return ret;
1185}
1186
1187/* returns true/false */
1188static int vino_queue_outgoing_contains(struct vino_framebuffer_queue *q,
1189 unsigned int id)
1190{
1191 int ret = 0;
1192 unsigned long flags;
1193
1194 if (q->magic != VINO_QUEUE_MAGIC) {
1195 return ret;
1196 }
1197
1198 spin_lock_irqsave(&q->queue_lock, flags);
1199
1200 if (q->length == 0)
1201 goto out;
1202
1203 ret = vino_fifo_has_id(&q->out, id);
1204
1205out:
1206 spin_unlock_irqrestore(&q->queue_lock, flags);
1207
1208 return ret;
1209}
1210
1211static int vino_queue_get_incoming(struct vino_framebuffer_queue *q,
1212 unsigned int *used)
1213{
1214 int ret = 0;
1215 unsigned long flags;
1216
1217 if (q->magic != VINO_QUEUE_MAGIC) {
1218 return VINO_QUEUE_ERROR;
1219 }
1220
1221 spin_lock_irqsave(&q->queue_lock, flags);
1222
1223 if (q->length == 0) {
1224 ret = VINO_QUEUE_ERROR;
1225 goto out;
1226 }
1227
1228 *used = vino_fifo_get_used(&q->in);
1229
1230out:
1231 spin_unlock_irqrestore(&q->queue_lock, flags);
1232
1233 return ret;
1234}
1235
1236static int vino_queue_get_outgoing(struct vino_framebuffer_queue *q,
1237 unsigned int *used)
1238{
1239 int ret = 0;
1240 unsigned long flags;
1241
1242 if (q->magic != VINO_QUEUE_MAGIC) {
1243 return VINO_QUEUE_ERROR;
1244 }
1245
1246 spin_lock_irqsave(&q->queue_lock, flags);
1247
1248 if (q->length == 0) {
1249 ret = VINO_QUEUE_ERROR;
1250 goto out;
1251 }
1252
1253 *used = vino_fifo_get_used(&q->out);
1254
1255out:
1256 spin_unlock_irqrestore(&q->queue_lock, flags);
1257
1258 return ret;
1259}
1260
1261#if 0
1262static int vino_queue_get_total(struct vino_framebuffer_queue *q,
1263 unsigned int *total)
1264{
1265 int ret = 0;
1266 unsigned long flags;
1267
1268 if (q->magic != VINO_QUEUE_MAGIC) {
1269 return VINO_QUEUE_ERROR;
1270 }
1271
1272 spin_lock_irqsave(&q->queue_lock, flags);
1273
1274 if (q->length == 0) {
1275 ret = VINO_QUEUE_ERROR;
1276 goto out;
1277 }
1278
1279 *total = vino_fifo_get_used(&q->in) +
1280 vino_fifo_get_used(&q->out);
1281
1282out:
1283 spin_unlock_irqrestore(&q->queue_lock, flags);
1284
1285 return ret;
1286}
1287#endif
1288
1289static struct vino_framebuffer *vino_queue_peek(struct
1290 vino_framebuffer_queue *q,
1291 unsigned int *id)
1292{
1293 struct vino_framebuffer *ret = NULL;
1294 unsigned long flags;
1295
1296 if (q->magic != VINO_QUEUE_MAGIC) {
1297 return ret;
1298 }
1299
1300 spin_lock_irqsave(&q->queue_lock, flags);
1301
1302 if (q->length == 0)
1303 goto out;
1304
1305 if (vino_fifo_peek(&q->in, id)) {
1306 goto out;
1307 }
1308
1309 ret = q->buffer[*id];
1310out:
1311 spin_unlock_irqrestore(&q->queue_lock, flags);
1312
1313 return ret;
1314}
1315
1316static struct vino_framebuffer *vino_queue_remove(struct
1317 vino_framebuffer_queue *q,
1318 unsigned int *id)
1319{
1320 struct vino_framebuffer *ret = NULL;
1321 unsigned long flags;
1322 dprintk("vino_queue_remove():\n");
1323
1324 if (q->magic != VINO_QUEUE_MAGIC) {
1325 return ret;
1326 }
1327
1328 spin_lock_irqsave(&q->queue_lock, flags);
1329
1330 if (q->length == 0)
1331 goto out;
1332
1333 if (vino_fifo_dequeue(&q->out, id)) {
1334 goto out;
1335 }
1336
1337 dprintk("vino_queue_remove(): id = %d\n", *id);
1338 ret = q->buffer[*id];
1339out:
1340 spin_unlock_irqrestore(&q->queue_lock, flags);
1341
1342 return ret;
1343}
1344
1345static struct
1346vino_framebuffer *vino_queue_get_buffer(struct vino_framebuffer_queue *q,
1347 unsigned int id)
1348{
1349 struct vino_framebuffer *ret = NULL;
1350 unsigned long flags;
1351
1352 if (q->magic != VINO_QUEUE_MAGIC) {
1353 return ret;
1354 }
1355
1356 spin_lock_irqsave(&q->queue_lock, flags);
1357
1358 if (q->length == 0)
1359 goto out;
1360
1361 if (id >= q->length)
1362 goto out;
1363
1364 ret = q->buffer[id];
1365 out:
1366 spin_unlock_irqrestore(&q->queue_lock, flags);
1367
1368 return ret;
1369}
1370
1371static unsigned int vino_queue_get_length(struct vino_framebuffer_queue *q)
1372{
1373 unsigned int length = 0;
1374 unsigned long flags;
1375
1376 if (q->magic != VINO_QUEUE_MAGIC) {
1377 return length;
1378 }
1379
1380 spin_lock_irqsave(&q->queue_lock, flags);
1381 length = q->length;
1382 spin_unlock_irqrestore(&q->queue_lock, flags);
1383
1384 return length;
1385}
1386
1387static int vino_queue_has_mapped_buffers(struct vino_framebuffer_queue *q)
1388{
1389 unsigned int i;
1390 int ret = 0;
1391 unsigned long flags;
1392
1393 if (q->magic != VINO_QUEUE_MAGIC) {
1394 return ret;
1395 }
1396
1397 spin_lock_irqsave(&q->queue_lock, flags);
1398 for (i = 0; i < q->length; i++) {
1399 if (q->buffer[i]->map_count > 0) {
1400 ret = 1;
1401 break;
1402 }
1403 }
1404 spin_unlock_irqrestore(&q->queue_lock, flags);
1405
1406 return ret;
1407}
1408
1409/* VINO functions */
1410
1411/* execute with input_lock locked */
1412static void vino_update_line_size(struct vino_channel_settings *vcs)
1413{
1414 unsigned int w = vcs->clipping.right - vcs->clipping.left;
1415 unsigned int d = vcs->decimation;
1416 unsigned int bpp = vino_data_formats[vcs->data_format].bpp;
1417 unsigned int lsize;
1418
1419 dprintk("update_line_size(): before: w = %d, d = %d, "
1420 "line_size = %d\n", w, d, vcs->line_size);
1421
1422 /* line size must be multiple of 8 bytes */
1423 lsize = (bpp * (w / d)) & ~7;
1424 w = (lsize / bpp) * d;
1425
1426 vcs->clipping.right = vcs->clipping.left + w;
1427 vcs->line_size = lsize;
1428
1429 dprintk("update_line_size(): after: w = %d, d = %d, "
1430 "line_size = %d\n", w, d, vcs->line_size);
1431}
1432
1433/* execute with input_lock locked */
1434static void vino_set_clipping(struct vino_channel_settings *vcs,
1435 unsigned int x, unsigned int y,
1436 unsigned int w, unsigned int h)
1437{
1438 unsigned int maxwidth, maxheight;
1439 unsigned int d;
1440
1441 maxwidth = vino_data_norms[vcs->data_norm].width;
1442 maxheight = vino_data_norms[vcs->data_norm].height;
1443 d = vcs->decimation;
1444
1445 y &= ~1; /* odd/even fields */
1446
1447 if (x > maxwidth) {
1448 x = 0;
1449 }
1450 if (y > maxheight) {
1451 y = 0;
1452 }
1453
1454 if (((w / d) < VINO_MIN_WIDTH)
1455 || ((h / d) < VINO_MIN_HEIGHT)) {
1456 w = VINO_MIN_WIDTH * d;
1457 h = VINO_MIN_HEIGHT * d;
1458 }
1459
1460 if ((x + w) > maxwidth) {
1461 w = maxwidth - x;
1462 if ((w / d) < VINO_MIN_WIDTH)
1463 x = maxwidth - VINO_MIN_WIDTH * d;
1464 }
1465 if ((y + h) > maxheight) {
1466 h = maxheight - y;
1467 if ((h / d) < VINO_MIN_HEIGHT)
1468 y = maxheight - VINO_MIN_HEIGHT * d;
1469 }
1470
1471 vcs->clipping.left = x;
1472 vcs->clipping.top = y;
1473 vcs->clipping.right = x + w;
1474 vcs->clipping.bottom = y + h;
1475
1476 vino_update_line_size(vcs);
1477
1478 dprintk("clipping %d, %d, %d, %d / %d - %d\n",
1479 vcs->clipping.left, vcs->clipping.top, vcs->clipping.right,
1480 vcs->clipping.bottom, vcs->decimation, vcs->line_size);
1481}
1482
1483/* execute with input_lock locked */
1484static inline void vino_set_default_clipping(struct vino_channel_settings *vcs)
1485{
1486 vino_set_clipping(vcs, 0, 0, vino_data_norms[vcs->data_norm].width,
1487 vino_data_norms[vcs->data_norm].height);
1488}
1489
1490/* execute with input_lock locked */
1491static void vino_set_scaling(struct vino_channel_settings *vcs,
1492 unsigned int w, unsigned int h)
1493{
1494 unsigned int x, y, curw, curh, d;
1495
1496 x = vcs->clipping.left;
1497 y = vcs->clipping.top;
1498 curw = vcs->clipping.right - vcs->clipping.left;
1499 curh = vcs->clipping.bottom - vcs->clipping.top;
1500
1501 d = max(curw / w, curh / h);
1502
1503 dprintk("scaling w: %d, h: %d, curw: %d, curh: %d, d: %d\n",
1504 w, h, curw, curh, d);
1505
1506 if (d < 1) {
1507 d = 1;
1508 } else if (d > 8) {
1509 d = 8;
1510 }
1511
1512 vcs->decimation = d;
1513 vino_set_clipping(vcs, x, y, w * d, h * d);
1514
1515 dprintk("scaling %d, %d, %d, %d / %d - %d\n", vcs->clipping.left,
1516 vcs->clipping.top, vcs->clipping.right, vcs->clipping.bottom,
1517 vcs->decimation, vcs->line_size);
1518}
1519
1520/* execute with input_lock locked */
1521static inline void vino_set_default_scaling(struct vino_channel_settings *vcs)
1522{
1523 vino_set_scaling(vcs, vcs->clipping.right - vcs->clipping.left,
1524 vcs->clipping.bottom - vcs->clipping.top);
1525}
1526
1527/* execute with input_lock locked */
1528static void vino_set_framerate(struct vino_channel_settings *vcs,
1529 unsigned int fps)
1530{
1531 unsigned int mask;
1532
1533 switch (vcs->data_norm) {
1534 case VINO_DATA_NORM_NTSC:
1535 case VINO_DATA_NORM_D1:
1536 fps = (unsigned int)(fps / 6) * 6; // FIXME: round!
1537
1538 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1539 fps = vino_data_norms[vcs->data_norm].fps_min;
1540 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1541 fps = vino_data_norms[vcs->data_norm].fps_max;
1542
1543 switch (fps) {
1544 case 6:
1545 mask = 0x003;
1546 break;
1547 case 12:
1548 mask = 0x0c3;
1549 break;
1550 case 18:
1551 mask = 0x333;
1552 break;
1553 case 24:
1554 mask = 0x3ff;
1555 break;
1556 case 30:
1557 mask = 0xfff;
1558 break;
1559 default:
1560 mask = VINO_FRAMERT_FULL;
1561 }
1562 vcs->framert_reg = VINO_FRAMERT_RT(mask);
1563 break;
1564 case VINO_DATA_NORM_PAL:
1565 case VINO_DATA_NORM_SECAM:
1566 fps = (unsigned int)(fps / 5) * 5; // FIXME: round!
1567
1568 if (fps < vino_data_norms[vcs->data_norm].fps_min)
1569 fps = vino_data_norms[vcs->data_norm].fps_min;
1570 if (fps > vino_data_norms[vcs->data_norm].fps_max)
1571 fps = vino_data_norms[vcs->data_norm].fps_max;
1572
1573 switch (fps) {
1574 case 5:
1575 mask = 0x003;
1576 break;
1577 case 10:
1578 mask = 0x0c3;
1579 break;
1580 case 15:
1581 mask = 0x333;
1582 break;
1583 case 20:
1584 mask = 0x0ff;
1585 break;
1586 case 25:
1587 mask = 0x3ff;
1588 break;
1589 default:
1590 mask = VINO_FRAMERT_FULL;
1591 }
1592 vcs->framert_reg = VINO_FRAMERT_RT(mask) | VINO_FRAMERT_PAL;
1593 break;
1594 }
1595
1596 vcs->fps = fps;
1597}
1598
1599/* execute with input_lock locked */
1600static inline void vino_set_default_framerate(struct
1601 vino_channel_settings *vcs)
1602{
1603 vino_set_framerate(vcs, vino_data_norms[vcs->data_norm].fps_max);
1604}
1605
1606/* VINO I2C bus functions */
1607
1608struct i2c_algo_sgi_data {
1609 void *data; /* private data for lowlevel routines */
1610 unsigned (*getctrl)(void *data);
1611 void (*setctrl)(void *data, unsigned val);
1612 unsigned (*rdata)(void *data);
1613 void (*wdata)(void *data, unsigned val);
1614
1615 int xfer_timeout;
1616 int ack_timeout;
1617};
1618
1619static int wait_xfer_done(struct i2c_algo_sgi_data *adap)
1620{
1621 int i;
1622
1623 for (i = 0; i < adap->xfer_timeout; i++) {
1624 if ((adap->getctrl(adap->data) & SGI_I2C_XFER_BUSY) == 0)
1625 return 0;
1626 udelay(1);
1627 }
1628
1629 return -ETIMEDOUT;
1630}
1631
1632static int wait_ack(struct i2c_algo_sgi_data *adap)
1633{
1634 int i;
1635
1636 if (wait_xfer_done(adap))
1637 return -ETIMEDOUT;
1638 for (i = 0; i < adap->ack_timeout; i++) {
1639 if ((adap->getctrl(adap->data) & SGI_I2C_NACK) == 0)
1640 return 0;
1641 udelay(1);
1642 }
1643
1644 return -ETIMEDOUT;
1645}
1646
1647static int force_idle(struct i2c_algo_sgi_data *adap)
1648{
1649 int i;
1650
1651 adap->setctrl(adap->data, SGI_I2C_FORCE_IDLE);
1652 for (i = 0; i < adap->xfer_timeout; i++) {
1653 if ((adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE) == 0)
1654 goto out;
1655 udelay(1);
1656 }
1657 return -ETIMEDOUT;
1658out:
1659 if (adap->getctrl(adap->data) & SGI_I2C_BUS_ERR)
1660 return -EIO;
1661 return 0;
1662}
1663
1664static int do_address(struct i2c_algo_sgi_data *adap, unsigned int addr,
1665 int rd)
1666{
1667 if (rd)
1668 adap->setctrl(adap->data, SGI_I2C_NOT_IDLE);
1669 /* Check if bus is idle, eventually force it to do so */
1670 if (adap->getctrl(adap->data) & SGI_I2C_NOT_IDLE)
1671 if (force_idle(adap))
1672 return -EIO;
1673 /* Write out the i2c chip address and specify operation */
1674 adap->setctrl(adap->data,
1675 SGI_I2C_HOLD_BUS | SGI_I2C_WRITE | SGI_I2C_NOT_IDLE);
1676 if (rd)
1677 addr |= 1;
1678 adap->wdata(adap->data, addr);
1679 if (wait_ack(adap))
1680 return -EIO;
1681 return 0;
1682}
1683
1684static int i2c_read(struct i2c_algo_sgi_data *adap, unsigned char *buf,
1685 unsigned int len)
1686{
1687 int i;
1688
1689 adap->setctrl(adap->data,
1690 SGI_I2C_HOLD_BUS | SGI_I2C_READ | SGI_I2C_NOT_IDLE);
1691 for (i = 0; i < len; i++) {
1692 if (wait_xfer_done(adap))
1693 return -EIO;
1694 buf[i] = adap->rdata(adap->data);
1695 }
1696 adap->setctrl(adap->data, SGI_I2C_RELEASE_BUS | SGI_I2C_FORCE_IDLE);
1697
1698 return 0;
1699
1700}
1701
1702static int i2c_write(struct i2c_algo_sgi_data *adap, unsigned char *buf,
1703 unsigned int len)
1704{
1705 int i;
1706
1707 /* We are already in write state */
1708 for (i = 0; i < len; i++) {
1709 adap->wdata(adap->data, buf[i]);
1710 if (wait_ack(adap))
1711 return -EIO;
1712 }
1713 return 0;
1714}
1715
1716static int sgi_xfer(struct i2c_adapter *i2c_adap, struct i2c_msg *msgs,
1717 int num)
1718{
1719 struct i2c_algo_sgi_data *adap = i2c_adap->algo_data;
1720 struct i2c_msg *p;
1721 int i, err = 0;
1722
1723 for (i = 0; !err && i < num; i++) {
1724 p = &msgs[i];
1725 err = do_address(adap, p->addr, p->flags & I2C_M_RD);
1726 if (err || !p->len)
1727 continue;
1728 if (p->flags & I2C_M_RD)
1729 err = i2c_read(adap, p->buf, p->len);
1730 else
1731 err = i2c_write(adap, p->buf, p->len);
1732 }
1733
1734 return (err < 0) ? err : i;
1735}
1736
1737static u32 sgi_func(struct i2c_adapter *adap)
1738{
1739 return I2C_FUNC_SMBUS_EMUL;
1740}
1741
1742static const struct i2c_algorithm sgi_algo = {
1743 .master_xfer = sgi_xfer,
1744 .functionality = sgi_func,
1745};
1746
1747static unsigned i2c_vino_getctrl(void *data)
1748{
1749 return vino->i2c_control;
1750}
1751
1752static void i2c_vino_setctrl(void *data, unsigned val)
1753{
1754 vino->i2c_control = val;
1755}
1756
1757static unsigned i2c_vino_rdata(void *data)
1758{
1759 return vino->i2c_data;
1760}
1761
1762static void i2c_vino_wdata(void *data, unsigned val)
1763{
1764 vino->i2c_data = val;
1765}
1766
1767static struct i2c_algo_sgi_data i2c_sgi_vino_data = {
1768 .getctrl = &i2c_vino_getctrl,
1769 .setctrl = &i2c_vino_setctrl,
1770 .rdata = &i2c_vino_rdata,
1771 .wdata = &i2c_vino_wdata,
1772 .xfer_timeout = 200,
1773 .ack_timeout = 1000,
1774};
1775
1776static struct i2c_adapter vino_i2c_adapter = {
1777 .name = "VINO I2C bus",
1778 .algo = &sgi_algo,
1779 .algo_data = &i2c_sgi_vino_data,
1780 .owner = THIS_MODULE,
1781};
1782
1783/*
1784 * Prepare VINO for DMA transfer...
1785 * (execute only with vino_lock and input_lock locked)
1786 */
1787static int vino_dma_setup(struct vino_channel_settings *vcs,
1788 struct vino_framebuffer *fb)
1789{
1790 u32 ctrl, intr;
1791 struct sgi_vino_channel *ch;
1792 const struct vino_data_norm *norm;
1793
1794 dprintk("vino_dma_setup():\n");
1795
1796 vcs->field = 0;
1797 fb->frame_counter = 0;
1798
1799 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1800 norm = &vino_data_norms[vcs->data_norm];
1801
1802 ch->page_index = 0;
1803 ch->line_count = 0;
1804
1805 /* VINO line size register is set 8 bytes less than actual */
1806 ch->line_size = vcs->line_size - 8;
1807
1808 /* let VINO know where to transfer data */
1809 ch->start_desc_tbl = fb->desc_table.dma;
1810 ch->next_4_desc = fb->desc_table.dma;
1811
1812 /* give vino time to fetch the first four descriptors, 5 usec
1813 * should be more than enough time */
1814 udelay(VINO_DESC_FETCH_DELAY);
1815
1816 dprintk("vino_dma_setup(): start desc = %08x, next 4 desc = %08x\n",
1817 ch->start_desc_tbl, ch->next_4_desc);
1818
1819 /* set the alpha register */
1820 ch->alpha = vcs->alpha;
1821
1822 /* set clipping registers */
1823 ch->clip_start = VINO_CLIP_ODD(norm->odd.top + vcs->clipping.top / 2) |
1824 VINO_CLIP_EVEN(norm->even.top +
1825 vcs->clipping.top / 2) |
1826 VINO_CLIP_X(vcs->clipping.left);
1827 ch->clip_end = VINO_CLIP_ODD(norm->odd.top +
1828 vcs->clipping.bottom / 2 - 1) |
1829 VINO_CLIP_EVEN(norm->even.top +
1830 vcs->clipping.bottom / 2 - 1) |
1831 VINO_CLIP_X(vcs->clipping.right);
1832
1833 /* set the size of actual content in the buffer (DECIMATION !) */
1834 fb->data_size = ((vcs->clipping.right - vcs->clipping.left) /
1835 vcs->decimation) *
1836 ((vcs->clipping.bottom - vcs->clipping.top) /
1837 vcs->decimation) *
1838 vino_data_formats[vcs->data_format].bpp;
1839
1840 ch->frame_rate = vcs->framert_reg;
1841
1842 ctrl = vino->control;
1843 intr = vino->intr_status;
1844
1845 if (vcs->channel == VINO_CHANNEL_A) {
1846 /* All interrupt conditions for this channel was cleared
1847 * so clear the interrupt status register and enable
1848 * interrupts */
1849 intr &= ~VINO_INTSTAT_A;
1850 ctrl |= VINO_CTRL_A_INT;
1851
1852 /* enable synchronization */
1853 ctrl |= VINO_CTRL_A_SYNC_ENBL;
1854
1855 /* enable frame assembly */
1856 ctrl |= VINO_CTRL_A_INTERLEAVE_ENBL;
1857
1858 /* set decimation used */
1859 if (vcs->decimation < 2)
1860 ctrl &= ~VINO_CTRL_A_DEC_ENBL;
1861 else {
1862 ctrl |= VINO_CTRL_A_DEC_ENBL;
1863 ctrl &= ~VINO_CTRL_A_DEC_SCALE_MASK;
1864 ctrl |= (vcs->decimation - 1) <<
1865 VINO_CTRL_A_DEC_SCALE_SHIFT;
1866 }
1867
1868 /* select input interface */
1869 if (vcs->input == VINO_INPUT_D1)
1870 ctrl |= VINO_CTRL_A_SELECT;
1871 else
1872 ctrl &= ~VINO_CTRL_A_SELECT;
1873
1874 /* palette */
1875 ctrl &= ~(VINO_CTRL_A_LUMA_ONLY | VINO_CTRL_A_RGB |
1876 VINO_CTRL_A_DITHER);
1877 } else {
1878 intr &= ~VINO_INTSTAT_B;
1879 ctrl |= VINO_CTRL_B_INT;
1880
1881 ctrl |= VINO_CTRL_B_SYNC_ENBL;
1882 ctrl |= VINO_CTRL_B_INTERLEAVE_ENBL;
1883
1884 if (vcs->decimation < 2)
1885 ctrl &= ~VINO_CTRL_B_DEC_ENBL;
1886 else {
1887 ctrl |= VINO_CTRL_B_DEC_ENBL;
1888 ctrl &= ~VINO_CTRL_B_DEC_SCALE_MASK;
1889 ctrl |= (vcs->decimation - 1) <<
1890 VINO_CTRL_B_DEC_SCALE_SHIFT;
1891
1892 }
1893 if (vcs->input == VINO_INPUT_D1)
1894 ctrl |= VINO_CTRL_B_SELECT;
1895 else
1896 ctrl &= ~VINO_CTRL_B_SELECT;
1897
1898 ctrl &= ~(VINO_CTRL_B_LUMA_ONLY | VINO_CTRL_B_RGB |
1899 VINO_CTRL_B_DITHER);
1900 }
1901
1902 /* set palette */
1903 fb->data_format = vcs->data_format;
1904
1905 switch (vcs->data_format) {
1906 case VINO_DATA_FMT_GREY:
1907 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1908 VINO_CTRL_A_LUMA_ONLY : VINO_CTRL_B_LUMA_ONLY;
1909 break;
1910 case VINO_DATA_FMT_RGB32:
1911 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1912 VINO_CTRL_A_RGB : VINO_CTRL_B_RGB;
1913 break;
1914 case VINO_DATA_FMT_YUV:
1915 /* nothing needs to be done */
1916 break;
1917 case VINO_DATA_FMT_RGB332:
1918 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1919 VINO_CTRL_A_RGB | VINO_CTRL_A_DITHER :
1920 VINO_CTRL_B_RGB | VINO_CTRL_B_DITHER;
1921 break;
1922 }
1923
1924 vino->intr_status = intr;
1925 vino->control = ctrl;
1926
1927 return 0;
1928}
1929
1930/* (execute only with vino_lock locked) */
1931static inline void vino_dma_start(struct vino_channel_settings *vcs)
1932{
1933 u32 ctrl = vino->control;
1934
1935 dprintk("vino_dma_start():\n");
1936 ctrl |= (vcs->channel == VINO_CHANNEL_A) ?
1937 VINO_CTRL_A_DMA_ENBL : VINO_CTRL_B_DMA_ENBL;
1938 vino->control = ctrl;
1939}
1940
1941/* (execute only with vino_lock locked) */
1942static inline void vino_dma_stop(struct vino_channel_settings *vcs)
1943{
1944 u32 ctrl = vino->control;
1945
1946 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1947 ~VINO_CTRL_A_DMA_ENBL : ~VINO_CTRL_B_DMA_ENBL;
1948 ctrl &= (vcs->channel == VINO_CHANNEL_A) ?
1949 ~VINO_CTRL_A_INT : ~VINO_CTRL_B_INT;
1950 vino->control = ctrl;
1951 dprintk("vino_dma_stop():\n");
1952}
1953
1954/*
1955 * Load dummy page to descriptor registers. This prevents generating of
1956 * spurious interrupts. (execute only with vino_lock locked)
1957 */
1958static void vino_clear_interrupt(struct vino_channel_settings *vcs)
1959{
1960 struct sgi_vino_channel *ch;
1961
1962 ch = (vcs->channel == VINO_CHANNEL_A) ? &vino->a : &vino->b;
1963
1964 ch->page_index = 0;
1965 ch->line_count = 0;
1966
1967 ch->start_desc_tbl = vino_drvdata->dummy_desc_table.dma;
1968 ch->next_4_desc = vino_drvdata->dummy_desc_table.dma;
1969
1970 udelay(VINO_DESC_FETCH_DELAY);
1971 dprintk("channel %c clear interrupt condition\n",
1972 (vcs->channel == VINO_CHANNEL_A) ? 'A':'B');
1973}
1974
1975static int vino_capture(struct vino_channel_settings *vcs,
1976 struct vino_framebuffer *fb)
1977{
1978 int err = 0;
1979 unsigned long flags, flags2;
1980
1981 spin_lock_irqsave(&fb->state_lock, flags);
1982
1983 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
1984 err = -EBUSY;
1985 fb->state = VINO_FRAMEBUFFER_IN_USE;
1986
1987 spin_unlock_irqrestore(&fb->state_lock, flags);
1988
1989 if (err)
1990 return err;
1991
1992 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
1993 spin_lock_irqsave(&vino_drvdata->input_lock, flags2);
1994
1995 vino_dma_setup(vcs, fb);
1996 vino_dma_start(vcs);
1997
1998 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags2);
1999 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2000
2001 return err;
2002}
2003
2004static
2005struct vino_framebuffer *vino_capture_enqueue(struct
2006 vino_channel_settings *vcs,
2007 unsigned int index)
2008{
2009 struct vino_framebuffer *fb;
2010 unsigned long flags;
2011
2012 dprintk("vino_capture_enqueue():\n");
2013
2014 spin_lock_irqsave(&vcs->capture_lock, flags);
2015
2016 fb = vino_queue_add(&vcs->fb_queue, index);
2017 if (fb == NULL) {
2018 dprintk("vino_capture_enqueue(): vino_queue_add() failed, "
2019 "queue full?\n");
2020 goto out;
2021 }
2022out:
2023 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2024
2025 return fb;
2026}
2027
2028static int vino_capture_next(struct vino_channel_settings *vcs, int start)
2029{
2030 struct vino_framebuffer *fb;
2031 unsigned int incoming, id;
2032 int err = 0;
2033 unsigned long flags;
2034
2035 dprintk("vino_capture_next():\n");
2036
2037 spin_lock_irqsave(&vcs->capture_lock, flags);
2038
2039 if (start) {
2040 /* start capture only if capture isn't in progress already */
2041 if (vcs->capturing) {
2042 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2043 return 0;
2044 }
2045
2046 } else {
2047 /* capture next frame:
2048 * stop capture if capturing is not set */
2049 if (!vcs->capturing) {
2050 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2051 return 0;
2052 }
2053 }
2054
2055 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
2056 if (err) {
2057 dprintk("vino_capture_next(): vino_queue_get_incoming() "
2058 "failed\n");
2059 err = -EINVAL;
2060 goto out;
2061 }
2062 if (incoming == 0) {
2063 dprintk("vino_capture_next(): no buffers available\n");
2064 goto out;
2065 }
2066
2067 fb = vino_queue_peek(&vcs->fb_queue, &id);
2068 if (fb == NULL) {
2069 dprintk("vino_capture_next(): vino_queue_peek() failed\n");
2070 err = -EINVAL;
2071 goto out;
2072 }
2073
2074 if (start) {
2075 vcs->capturing = 1;
2076 }
2077
2078 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2079
2080 err = vino_capture(vcs, fb);
2081
2082 return err;
2083
2084out:
2085 vcs->capturing = 0;
2086 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2087
2088 return err;
2089}
2090
2091static inline int vino_is_capturing(struct vino_channel_settings *vcs)
2092{
2093 int ret;
2094 unsigned long flags;
2095
2096 spin_lock_irqsave(&vcs->capture_lock, flags);
2097
2098 ret = vcs->capturing;
2099
2100 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2101
2102 return ret;
2103}
2104
2105/* waits until a frame is captured */
2106static int vino_wait_for_frame(struct vino_channel_settings *vcs)
2107{
2108 wait_queue_t wait;
2109 int err = 0;
2110
2111 dprintk("vino_wait_for_frame():\n");
2112
2113 init_waitqueue_entry(&wait, current);
2114 /* add ourselves into wait queue */
2115 add_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2116
2117 /* to ensure that schedule_timeout will return immediately
2118 * if VINO interrupt was triggered meanwhile */
2119 schedule_timeout_interruptible(msecs_to_jiffies(100));
2120
2121 if (signal_pending(current))
2122 err = -EINTR;
2123
2124 remove_wait_queue(&vcs->fb_queue.frame_wait_queue, &wait);
2125
2126 dprintk("vino_wait_for_frame(): waiting for frame %s\n",
2127 err ? "failed" : "ok");
2128
2129 return err;
2130}
2131
2132/* the function assumes that PAGE_SIZE % 4 == 0 */
2133static void vino_convert_to_rgba(struct vino_framebuffer *fb) {
2134 unsigned char *pageptr;
2135 unsigned int page, i;
2136 unsigned char a;
2137
2138 for (page = 0; page < fb->desc_table.page_count; page++) {
2139 pageptr = (unsigned char *)fb->desc_table.virtual[page];
2140
2141 for (i = 0; i < PAGE_SIZE; i += 4) {
2142 a = pageptr[0];
2143 pageptr[0] = pageptr[3];
2144 pageptr[1] = pageptr[2];
2145 pageptr[2] = pageptr[1];
2146 pageptr[3] = a;
2147 pageptr += 4;
2148 }
2149 }
2150}
2151
2152/* checks if the buffer is in correct state and syncs data */
2153static int vino_check_buffer(struct vino_channel_settings *vcs,
2154 struct vino_framebuffer *fb)
2155{
2156 int err = 0;
2157 unsigned long flags;
2158
2159 dprintk("vino_check_buffer():\n");
2160
2161 spin_lock_irqsave(&fb->state_lock, flags);
2162 switch (fb->state) {
2163 case VINO_FRAMEBUFFER_IN_USE:
2164 err = -EIO;
2165 break;
2166 case VINO_FRAMEBUFFER_READY:
2167 vino_sync_buffer(fb);
2168 fb->state = VINO_FRAMEBUFFER_UNUSED;
2169 break;
2170 default:
2171 err = -EINVAL;
2172 }
2173 spin_unlock_irqrestore(&fb->state_lock, flags);
2174
2175 if (!err) {
2176 if (vino_pixel_conversion
2177 && (fb->data_format == VINO_DATA_FMT_RGB32)) {
2178 vino_convert_to_rgba(fb);
2179 }
2180 } else if (err && (err != -EINVAL)) {
2181 dprintk("vino_check_buffer(): buffer not ready\n");
2182
2183 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2184 vino_dma_stop(vcs);
2185 vino_clear_interrupt(vcs);
2186 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2187 }
2188
2189 return err;
2190}
2191
2192/* forcefully terminates capture */
2193static void vino_capture_stop(struct vino_channel_settings *vcs)
2194{
2195 unsigned int incoming = 0, outgoing = 0, id;
2196 unsigned long flags, flags2;
2197
2198 dprintk("vino_capture_stop():\n");
2199
2200 spin_lock_irqsave(&vcs->capture_lock, flags);
2201
2202 /* unset capturing to stop queue processing */
2203 vcs->capturing = 0;
2204
2205 spin_lock_irqsave(&vino_drvdata->vino_lock, flags2);
2206
2207 vino_dma_stop(vcs);
2208 vino_clear_interrupt(vcs);
2209
2210 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags2);
2211
2212 /* remove all items from the queue */
2213 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2214 dprintk("vino_capture_stop(): "
2215 "vino_queue_get_incoming() failed\n");
2216 goto out;
2217 }
2218 while (incoming > 0) {
2219 vino_queue_transfer(&vcs->fb_queue);
2220
2221 if (vino_queue_get_incoming(&vcs->fb_queue, &incoming)) {
2222 dprintk("vino_capture_stop(): "
2223 "vino_queue_get_incoming() failed\n");
2224 goto out;
2225 }
2226 }
2227
2228 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2229 dprintk("vino_capture_stop(): "
2230 "vino_queue_get_outgoing() failed\n");
2231 goto out;
2232 }
2233 while (outgoing > 0) {
2234 vino_queue_remove(&vcs->fb_queue, &id);
2235
2236 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
2237 dprintk("vino_capture_stop(): "
2238 "vino_queue_get_outgoing() failed\n");
2239 goto out;
2240 }
2241 }
2242
2243out:
2244 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2245}
2246
2247#if 0
2248static int vino_capture_failed(struct vino_channel_settings *vcs)
2249{
2250 struct vino_framebuffer *fb;
2251 unsigned long flags;
2252 unsigned int i;
2253 int ret;
2254
2255 dprintk("vino_capture_failed():\n");
2256
2257 spin_lock_irqsave(&vino_drvdata->vino_lock, flags);
2258
2259 vino_dma_stop(vcs);
2260 vino_clear_interrupt(vcs);
2261
2262 spin_unlock_irqrestore(&vino_drvdata->vino_lock, flags);
2263
2264 ret = vino_queue_get_incoming(&vcs->fb_queue, &i);
2265 if (ret == VINO_QUEUE_ERROR) {
2266 dprintk("vino_queue_get_incoming() failed\n");
2267 return -EINVAL;
2268 }
2269 if (i == 0) {
2270 /* no buffers to process */
2271 return 0;
2272 }
2273
2274 fb = vino_queue_peek(&vcs->fb_queue, &i);
2275 if (fb == NULL) {
2276 dprintk("vino_queue_peek() failed\n");
2277 return -EINVAL;
2278 }
2279
2280 spin_lock_irqsave(&fb->state_lock, flags);
2281 if (fb->state == VINO_FRAMEBUFFER_IN_USE) {
2282 fb->state = VINO_FRAMEBUFFER_UNUSED;
2283 vino_queue_transfer(&vcs->fb_queue);
2284 vino_queue_remove(&vcs->fb_queue, &i);
2285 /* we should actually discard the newest frame,
2286 * but who cares ... */
2287 }
2288 spin_unlock_irqrestore(&fb->state_lock, flags);
2289
2290 return 0;
2291}
2292#endif
2293
2294static void vino_skip_frame(struct vino_channel_settings *vcs)
2295{
2296 struct vino_framebuffer *fb;
2297 unsigned long flags;
2298 unsigned int id;
2299
2300 spin_lock_irqsave(&vcs->capture_lock, flags);
2301 fb = vino_queue_peek(&vcs->fb_queue, &id);
2302 if (!fb) {
2303 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2304 dprintk("vino_skip_frame(): vino_queue_peek() failed!\n");
2305 return;
2306 }
2307 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2308
2309 spin_lock_irqsave(&fb->state_lock, flags);
2310 fb->state = VINO_FRAMEBUFFER_UNUSED;
2311 spin_unlock_irqrestore(&fb->state_lock, flags);
2312
2313 vino_capture_next(vcs, 0);
2314}
2315
2316static void vino_frame_done(struct vino_channel_settings *vcs)
2317{
2318 struct vino_framebuffer *fb;
2319 unsigned long flags;
2320
2321 spin_lock_irqsave(&vcs->capture_lock, flags);
2322 fb = vino_queue_transfer(&vcs->fb_queue);
2323 if (!fb) {
2324 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2325 dprintk("vino_frame_done(): vino_queue_transfer() failed!\n");
2326 return;
2327 }
2328 spin_unlock_irqrestore(&vcs->capture_lock, flags);
2329
2330 fb->frame_counter = vcs->int_data.frame_counter;
2331 memcpy(&fb->timestamp, &vcs->int_data.timestamp,
2332 sizeof(struct timeval));
2333
2334 spin_lock_irqsave(&fb->state_lock, flags);
2335 if (fb->state == VINO_FRAMEBUFFER_IN_USE)
2336 fb->state = VINO_FRAMEBUFFER_READY;
2337 spin_unlock_irqrestore(&fb->state_lock, flags);
2338
2339 wake_up(&vcs->fb_queue.frame_wait_queue);
2340
2341 vino_capture_next(vcs, 0);
2342}
2343
2344static void vino_capture_tasklet(unsigned long channel) {
2345 struct vino_channel_settings *vcs;
2346
2347 vcs = (channel == VINO_CHANNEL_A)
2348 ? &vino_drvdata->a : &vino_drvdata->b;
2349
2350 if (vcs->int_data.skip)
2351 vcs->int_data.skip_count++;
2352
2353 if (vcs->int_data.skip && (vcs->int_data.skip_count
2354 <= VINO_MAX_FRAME_SKIP_COUNT)) {
2355 vino_skip_frame(vcs);
2356 } else {
2357 vcs->int_data.skip_count = 0;
2358 vino_frame_done(vcs);
2359 }
2360}
2361
2362static irqreturn_t vino_interrupt(int irq, void *dev_id)
2363{
2364 u32 ctrl, intr;
2365 unsigned int fc_a, fc_b;
2366 int handled_a = 0, skip_a = 0, done_a = 0;
2367 int handled_b = 0, skip_b = 0, done_b = 0;
2368
2369#ifdef VINO_DEBUG_INT
2370 int loop = 0;
2371 unsigned int line_count = vino->a.line_count,
2372 page_index = vino->a.page_index,
2373 field_counter = vino->a.field_counter,
2374 start_desc_tbl = vino->a.start_desc_tbl,
2375 next_4_desc = vino->a.next_4_desc;
2376 unsigned int line_count_2,
2377 page_index_2,
2378 field_counter_2,
2379 start_desc_tbl_2,
2380 next_4_desc_2;
2381#endif
2382
2383 spin_lock(&vino_drvdata->vino_lock);
2384
2385 while ((intr = vino->intr_status)) {
2386 fc_a = vino->a.field_counter >> 1;
2387 fc_b = vino->b.field_counter >> 1;
2388
2389 /* handle error-interrupts in some special way ?
2390 * --> skips frames */
2391 if (intr & VINO_INTSTAT_A) {
2392 if (intr & VINO_INTSTAT_A_EOF) {
2393 vino_drvdata->a.field++;
2394 if (vino_drvdata->a.field > 1) {
2395 vino_dma_stop(&vino_drvdata->a);
2396 vino_clear_interrupt(&vino_drvdata->a);
2397 vino_drvdata->a.field = 0;
2398 done_a = 1;
2399 } else {
2400 if (vino->a.page_index
2401 != vino_drvdata->a.line_size) {
2402 vino->a.line_count = 0;
2403 vino->a.page_index =
2404 vino_drvdata->
2405 a.line_size;
2406 vino->a.next_4_desc =
2407 vino->a.start_desc_tbl;
2408 }
2409 }
2410 dprintk("channel A end-of-field "
2411 "interrupt: %04x\n", intr);
2412 } else {
2413 vino_dma_stop(&vino_drvdata->a);
2414 vino_clear_interrupt(&vino_drvdata->a);
2415 vino_drvdata->a.field = 0;
2416 skip_a = 1;
2417 dprintk("channel A error interrupt: %04x\n",
2418 intr);
2419 }
2420
2421#ifdef VINO_DEBUG_INT
2422 line_count_2 = vino->a.line_count;
2423 page_index_2 = vino->a.page_index;
2424 field_counter_2 = vino->a.field_counter;
2425 start_desc_tbl_2 = vino->a.start_desc_tbl;
2426 next_4_desc_2 = vino->a.next_4_desc;
2427
2428 printk("intr = %04x, loop = %d, field = %d\n",
2429 intr, loop, vino_drvdata->a.field);
2430 printk("1- line count = %04d, page index = %04d, "
2431 "start = %08x, next = %08x\n"
2432 " fieldc = %d, framec = %d\n",
2433 line_count, page_index, start_desc_tbl,
2434 next_4_desc, field_counter, fc_a);
2435 printk("12-line count = %04d, page index = %04d, "
2436 " start = %08x, next = %08x\n",
2437 line_count_2, page_index_2, start_desc_tbl_2,
2438 next_4_desc_2);
2439
2440 if (done_a)
2441 printk("\n");
2442#endif
2443 }
2444
2445 if (intr & VINO_INTSTAT_B) {
2446 if (intr & VINO_INTSTAT_B_EOF) {
2447 vino_drvdata->b.field++;
2448 if (vino_drvdata->b.field > 1) {
2449 vino_dma_stop(&vino_drvdata->b);
2450 vino_clear_interrupt(&vino_drvdata->b);
2451 vino_drvdata->b.field = 0;
2452 done_b = 1;
2453 }
2454 dprintk("channel B end-of-field "
2455 "interrupt: %04x\n", intr);
2456 } else {
2457 vino_dma_stop(&vino_drvdata->b);
2458 vino_clear_interrupt(&vino_drvdata->b);
2459 vino_drvdata->b.field = 0;
2460 skip_b = 1;
2461 dprintk("channel B error interrupt: %04x\n",
2462 intr);
2463 }
2464 }
2465
2466 /* Always remember to clear interrupt status.
2467 * Disable VINO interrupts while we do this. */
2468 ctrl = vino->control;
2469 vino->control = ctrl & ~(VINO_CTRL_A_INT | VINO_CTRL_B_INT);
2470 vino->intr_status = ~intr;
2471 vino->control = ctrl;
2472
2473 spin_unlock(&vino_drvdata->vino_lock);
2474
2475 if ((!handled_a) && (done_a || skip_a)) {
2476 if (!skip_a) {
2477 v4l2_get_timestamp(
2478 &vino_drvdata->a.int_data.timestamp);
2479 vino_drvdata->a.int_data.frame_counter = fc_a;
2480 }
2481 vino_drvdata->a.int_data.skip = skip_a;
2482
2483 dprintk("channel A %s, interrupt: %d\n",
2484 skip_a ? "skipping frame" : "frame done",
2485 intr);
2486 tasklet_hi_schedule(&vino_tasklet_a);
2487 handled_a = 1;
2488 }
2489
2490 if ((!handled_b) && (done_b || skip_b)) {
2491 if (!skip_b) {
2492 v4l2_get_timestamp(
2493 &vino_drvdata->b.int_data.timestamp);
2494 vino_drvdata->b.int_data.frame_counter = fc_b;
2495 }
2496 vino_drvdata->b.int_data.skip = skip_b;
2497
2498 dprintk("channel B %s, interrupt: %d\n",
2499 skip_b ? "skipping frame" : "frame done",
2500 intr);
2501 tasklet_hi_schedule(&vino_tasklet_b);
2502 handled_b = 1;
2503 }
2504
2505#ifdef VINO_DEBUG_INT
2506 loop++;
2507#endif
2508 spin_lock(&vino_drvdata->vino_lock);
2509 }
2510
2511 spin_unlock(&vino_drvdata->vino_lock);
2512
2513 return IRQ_HANDLED;
2514}
2515
2516/* VINO video input management */
2517
2518static int vino_get_saa7191_input(int input)
2519{
2520 switch (input) {
2521 case VINO_INPUT_COMPOSITE:
2522 return SAA7191_INPUT_COMPOSITE;
2523 case VINO_INPUT_SVIDEO:
2524 return SAA7191_INPUT_SVIDEO;
2525 default:
2526 printk(KERN_ERR "VINO: vino_get_saa7191_input(): "
2527 "invalid input!\n");
2528 return -1;
2529 }
2530}
2531
2532/* execute with input_lock locked */
2533static int vino_is_input_owner(struct vino_channel_settings *vcs)
2534{
2535 switch(vcs->input) {
2536 case VINO_INPUT_COMPOSITE:
2537 case VINO_INPUT_SVIDEO:
2538 return vino_drvdata->decoder_owner == vcs->channel;
2539 case VINO_INPUT_D1:
2540 return vino_drvdata->camera_owner == vcs->channel;
2541 default:
2542 return 0;
2543 }
2544}
2545
2546static int vino_acquire_input(struct vino_channel_settings *vcs)
2547{
2548 unsigned long flags;
2549 int ret = 0;
2550
2551 dprintk("vino_acquire_input():\n");
2552
2553 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2554
2555 /* First try D1 and then SAA7191 */
2556 if (vino_drvdata->camera
2557 && (vino_drvdata->camera_owner == VINO_NO_CHANNEL)) {
2558 vino_drvdata->camera_owner = vcs->channel;
2559 vcs->input = VINO_INPUT_D1;
2560 vcs->data_norm = VINO_DATA_NORM_D1;
2561 } else if (vino_drvdata->decoder
2562 && (vino_drvdata->decoder_owner == VINO_NO_CHANNEL)) {
2563 int input;
2564 int data_norm = 0;
2565 v4l2_std_id norm;
2566
2567 input = VINO_INPUT_COMPOSITE;
2568
2569 ret = decoder_call(video, s_routing,
2570 vino_get_saa7191_input(input), 0, 0);
2571 if (ret) {
2572 ret = -EINVAL;
2573 goto out;
2574 }
2575
2576 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2577
2578 /* Don't hold spinlocks while auto-detecting norm
2579 * as it may take a while... */
2580
2581 ret = decoder_call(video, querystd, &norm);
2582 if (!ret) {
2583 for (data_norm = 0; data_norm < 3; data_norm++) {
2584 if (vino_data_norms[data_norm].std & norm)
2585 break;
2586 }
2587 if (data_norm == 3)
2588 data_norm = VINO_DATA_NORM_PAL;
2589 ret = decoder_call(video, s_std, norm);
2590 }
2591
2592 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2593
2594 if (ret) {
2595 ret = -EINVAL;
2596 goto out;
2597 }
2598
2599 vino_drvdata->decoder_owner = vcs->channel;
2600
2601 vcs->input = input;
2602 vcs->data_norm = data_norm;
2603 } else {
2604 vcs->input = (vcs->channel == VINO_CHANNEL_A) ?
2605 vino_drvdata->b.input : vino_drvdata->a.input;
2606 vcs->data_norm = (vcs->channel == VINO_CHANNEL_A) ?
2607 vino_drvdata->b.data_norm : vino_drvdata->a.data_norm;
2608 }
2609
2610 if (vcs->input == VINO_INPUT_NONE) {
2611 ret = -ENODEV;
2612 goto out;
2613 }
2614
2615 vino_set_default_clipping(vcs);
2616 vino_set_default_scaling(vcs);
2617 vino_set_default_framerate(vcs);
2618
2619 dprintk("vino_acquire_input(): %s\n", vino_inputs[vcs->input].name);
2620
2621out:
2622 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2623
2624 return ret;
2625}
2626
2627static int vino_set_input(struct vino_channel_settings *vcs, int input)
2628{
2629 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2630 &vino_drvdata->b : &vino_drvdata->a;
2631 unsigned long flags;
2632 int ret = 0;
2633
2634 dprintk("vino_set_input():\n");
2635
2636 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2637
2638 if (vcs->input == input)
2639 goto out;
2640
2641 switch (input) {
2642 case VINO_INPUT_COMPOSITE:
2643 case VINO_INPUT_SVIDEO:
2644 if (!vino_drvdata->decoder) {
2645 ret = -EINVAL;
2646 goto out;
2647 }
2648
2649 if (vino_drvdata->decoder_owner == VINO_NO_CHANNEL) {
2650 vino_drvdata->decoder_owner = vcs->channel;
2651 }
2652
2653 if (vino_drvdata->decoder_owner == vcs->channel) {
2654 int data_norm = 0;
2655 v4l2_std_id norm;
2656
2657 ret = decoder_call(video, s_routing,
2658 vino_get_saa7191_input(input), 0, 0);
2659 if (ret) {
2660 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2661 ret = -EINVAL;
2662 goto out;
2663 }
2664
2665 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2666
2667 /* Don't hold spinlocks while auto-detecting norm
2668 * as it may take a while... */
2669
2670 ret = decoder_call(video, querystd, &norm);
2671 if (!ret) {
2672 for (data_norm = 0; data_norm < 3; data_norm++) {
2673 if (vino_data_norms[data_norm].std & norm)
2674 break;
2675 }
2676 if (data_norm == 3)
2677 data_norm = VINO_DATA_NORM_PAL;
2678 ret = decoder_call(video, s_std, norm);
2679 }
2680
2681 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2682
2683 if (ret) {
2684 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2685 ret = -EINVAL;
2686 goto out;
2687 }
2688
2689 vcs->input = input;
2690 vcs->data_norm = data_norm;
2691 } else {
2692 if (input != vcs2->input) {
2693 ret = -EBUSY;
2694 goto out;
2695 }
2696
2697 vcs->input = input;
2698 vcs->data_norm = vcs2->data_norm;
2699 }
2700
2701 if (vino_drvdata->camera_owner == vcs->channel) {
2702 /* Transfer the ownership or release the input */
2703 if (vcs2->input == VINO_INPUT_D1) {
2704 vino_drvdata->camera_owner = vcs2->channel;
2705 } else {
2706 vino_drvdata->camera_owner = VINO_NO_CHANNEL;
2707 }
2708 }
2709 break;
2710 case VINO_INPUT_D1:
2711 if (!vino_drvdata->camera) {
2712 ret = -EINVAL;
2713 goto out;
2714 }
2715
2716 if (vino_drvdata->camera_owner == VINO_NO_CHANNEL)
2717 vino_drvdata->camera_owner = vcs->channel;
2718
2719 if (vino_drvdata->decoder_owner == vcs->channel) {
2720 /* Transfer the ownership or release the input */
2721 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2722 (vcs2->input == VINO_INPUT_SVIDEO)) {
2723 vino_drvdata->decoder_owner = vcs2->channel;
2724 } else {
2725 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2726 }
2727 }
2728
2729 vcs->input = input;
2730 vcs->data_norm = VINO_DATA_NORM_D1;
2731 break;
2732 default:
2733 ret = -EINVAL;
2734 goto out;
2735 }
2736
2737 vino_set_default_clipping(vcs);
2738 vino_set_default_scaling(vcs);
2739 vino_set_default_framerate(vcs);
2740
2741 dprintk("vino_set_input(): %s\n", vino_inputs[vcs->input].name);
2742
2743out:
2744 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2745
2746 return ret;
2747}
2748
2749static void vino_release_input(struct vino_channel_settings *vcs)
2750{
2751 struct vino_channel_settings *vcs2 = (vcs->channel == VINO_CHANNEL_A) ?
2752 &vino_drvdata->b : &vino_drvdata->a;
2753 unsigned long flags;
2754
2755 dprintk("vino_release_input():\n");
2756
2757 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2758
2759 /* Release ownership of the channel
2760 * and if the other channel takes input from
2761 * the same source, transfer the ownership */
2762 if (vino_drvdata->camera_owner == vcs->channel) {
2763 if (vcs2->input == VINO_INPUT_D1) {
2764 vino_drvdata->camera_owner = vcs2->channel;
2765 } else {
2766 vino_drvdata->camera_owner = VINO_NO_CHANNEL;
2767 }
2768 } else if (vino_drvdata->decoder_owner == vcs->channel) {
2769 if ((vcs2->input == VINO_INPUT_COMPOSITE) ||
2770 (vcs2->input == VINO_INPUT_SVIDEO)) {
2771 vino_drvdata->decoder_owner = vcs2->channel;
2772 } else {
2773 vino_drvdata->decoder_owner = VINO_NO_CHANNEL;
2774 }
2775 }
2776 vcs->input = VINO_INPUT_NONE;
2777
2778 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2779}
2780
2781/* execute with input_lock locked */
2782static int vino_set_data_norm(struct vino_channel_settings *vcs,
2783 unsigned int data_norm,
2784 unsigned long *flags)
2785{
2786 int err = 0;
2787
2788 if (data_norm == vcs->data_norm)
2789 return 0;
2790
2791 switch (vcs->input) {
2792 case VINO_INPUT_D1:
2793 /* only one "norm" supported */
2794 if (data_norm != VINO_DATA_NORM_D1)
2795 return -EINVAL;
2796 break;
2797 case VINO_INPUT_COMPOSITE:
2798 case VINO_INPUT_SVIDEO: {
2799 v4l2_std_id norm;
2800
2801 if ((data_norm != VINO_DATA_NORM_PAL)
2802 && (data_norm != VINO_DATA_NORM_NTSC)
2803 && (data_norm != VINO_DATA_NORM_SECAM))
2804 return -EINVAL;
2805
2806 spin_unlock_irqrestore(&vino_drvdata->input_lock, *flags);
2807
2808 /* Don't hold spinlocks while setting norm
2809 * as it may take a while... */
2810
2811 norm = vino_data_norms[data_norm].std;
2812 err = decoder_call(video, s_std, norm);
2813
2814 spin_lock_irqsave(&vino_drvdata->input_lock, *flags);
2815
2816 if (err)
2817 goto out;
2818
2819 vcs->data_norm = data_norm;
2820
2821 vino_set_default_clipping(vcs);
2822 vino_set_default_scaling(vcs);
2823 vino_set_default_framerate(vcs);
2824 break;
2825 }
2826 default:
2827 return -EINVAL;
2828 }
2829
2830out:
2831 return err;
2832}
2833
2834/* V4L2 helper functions */
2835
2836static int vino_find_data_format(__u32 pixelformat)
2837{
2838 int i;
2839
2840 for (i = 0; i < VINO_DATA_FMT_COUNT; i++) {
2841 if (vino_data_formats[i].pixelformat == pixelformat)
2842 return i;
2843 }
2844
2845 return VINO_DATA_FMT_NONE;
2846}
2847
2848static int vino_int_enum_input(struct vino_channel_settings *vcs, __u32 index)
2849{
2850 int input = VINO_INPUT_NONE;
2851 unsigned long flags;
2852
2853 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2854 if (vino_drvdata->decoder && vino_drvdata->camera) {
2855 switch (index) {
2856 case 0:
2857 input = VINO_INPUT_COMPOSITE;
2858 break;
2859 case 1:
2860 input = VINO_INPUT_SVIDEO;
2861 break;
2862 case 2:
2863 input = VINO_INPUT_D1;
2864 break;
2865 }
2866 } else if (vino_drvdata->decoder) {
2867 switch (index) {
2868 case 0:
2869 input = VINO_INPUT_COMPOSITE;
2870 break;
2871 case 1:
2872 input = VINO_INPUT_SVIDEO;
2873 break;
2874 }
2875 } else if (vino_drvdata->camera) {
2876 switch (index) {
2877 case 0:
2878 input = VINO_INPUT_D1;
2879 break;
2880 }
2881 }
2882 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2883
2884 return input;
2885}
2886
2887/* execute with input_lock locked */
2888static __u32 vino_find_input_index(struct vino_channel_settings *vcs)
2889{
2890 __u32 index = 0;
2891 // FIXME: detect when no inputs available
2892
2893 if (vino_drvdata->decoder && vino_drvdata->camera) {
2894 switch (vcs->input) {
2895 case VINO_INPUT_COMPOSITE:
2896 index = 0;
2897 break;
2898 case VINO_INPUT_SVIDEO:
2899 index = 1;
2900 break;
2901 case VINO_INPUT_D1:
2902 index = 2;
2903 break;
2904 }
2905 } else if (vino_drvdata->decoder) {
2906 switch (vcs->input) {
2907 case VINO_INPUT_COMPOSITE:
2908 index = 0;
2909 break;
2910 case VINO_INPUT_SVIDEO:
2911 index = 1;
2912 break;
2913 }
2914 } else if (vino_drvdata->camera) {
2915 switch (vcs->input) {
2916 case VINO_INPUT_D1:
2917 index = 0;
2918 break;
2919 }
2920 }
2921
2922 return index;
2923}
2924
2925/* V4L2 ioctls */
2926
2927static int vino_querycap(struct file *file, void *__fh,
2928 struct v4l2_capability *cap)
2929{
2930 memset(cap, 0, sizeof(struct v4l2_capability));
2931
2932 strcpy(cap->driver, vino_driver_name);
2933 strcpy(cap->card, vino_driver_description);
2934 strcpy(cap->bus_info, vino_bus_name);
2935 cap->device_caps = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
2936 cap->capabilities = cap->device_caps | V4L2_CAP_DEVICE_CAPS;
2937 return 0;
2938}
2939
2940static int vino_enum_input(struct file *file, void *__fh,
2941 struct v4l2_input *i)
2942{
2943 struct vino_channel_settings *vcs = video_drvdata(file);
2944 __u32 index = i->index;
2945 int input;
2946 dprintk("requested index = %d\n", index);
2947
2948 input = vino_int_enum_input(vcs, index);
2949 if (input == VINO_INPUT_NONE)
2950 return -EINVAL;
2951
2952 i->type = V4L2_INPUT_TYPE_CAMERA;
2953 i->std = vino_inputs[input].std;
2954 strcpy(i->name, vino_inputs[input].name);
2955
2956 if (input == VINO_INPUT_COMPOSITE || input == VINO_INPUT_SVIDEO)
2957 decoder_call(video, g_input_status, &i->status);
2958 return 0;
2959}
2960
2961static int vino_g_input(struct file *file, void *__fh,
2962 unsigned int *i)
2963{
2964 struct vino_channel_settings *vcs = video_drvdata(file);
2965 __u32 index;
2966 int input;
2967 unsigned long flags;
2968
2969 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
2970 input = vcs->input;
2971 index = vino_find_input_index(vcs);
2972 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
2973
2974 dprintk("input = %d\n", input);
2975
2976 if (input == VINO_INPUT_NONE) {
2977 return -EINVAL;
2978 }
2979
2980 *i = index;
2981
2982 return 0;
2983}
2984
2985static int vino_s_input(struct file *file, void *__fh,
2986 unsigned int i)
2987{
2988 struct vino_channel_settings *vcs = video_drvdata(file);
2989 int input;
2990 dprintk("requested input = %d\n", i);
2991
2992 input = vino_int_enum_input(vcs, i);
2993 if (input == VINO_INPUT_NONE)
2994 return -EINVAL;
2995
2996 return vino_set_input(vcs, input);
2997}
2998
2999static int vino_querystd(struct file *file, void *__fh,
3000 v4l2_std_id *std)
3001{
3002 struct vino_channel_settings *vcs = video_drvdata(file);
3003 unsigned long flags;
3004 int err = 0;
3005
3006 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3007
3008 switch (vcs->input) {
3009 case VINO_INPUT_D1:
3010 *std = vino_inputs[vcs->input].std;
3011 break;
3012 case VINO_INPUT_COMPOSITE:
3013 case VINO_INPUT_SVIDEO: {
3014 decoder_call(video, querystd, std);
3015 break;
3016 }
3017 default:
3018 err = -EINVAL;
3019 }
3020
3021 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3022
3023 return err;
3024}
3025
3026static int vino_g_std(struct file *file, void *__fh,
3027 v4l2_std_id *std)
3028{
3029 struct vino_channel_settings *vcs = video_drvdata(file);
3030 unsigned long flags;
3031
3032 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3033
3034 *std = vino_data_norms[vcs->data_norm].std;
3035 dprintk("current standard = %d\n", vcs->data_norm);
3036
3037 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3038
3039 return 0;
3040}
3041
3042static int vino_s_std(struct file *file, void *__fh,
3043 v4l2_std_id std)
3044{
3045 struct vino_channel_settings *vcs = video_drvdata(file);
3046 unsigned long flags;
3047 int ret = 0;
3048
3049 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3050
3051 if (!vino_is_input_owner(vcs)) {
3052 ret = -EBUSY;
3053 goto out;
3054 }
3055
3056 /* check if the standard is valid for the current input */
3057 if (std & vino_inputs[vcs->input].std) {
3058 dprintk("standard accepted\n");
3059
3060 /* change the video norm for SAA7191
3061 * and accept NTSC for D1 (do nothing) */
3062
3063 if (vcs->input == VINO_INPUT_D1)
3064 goto out;
3065
3066 if (std & V4L2_STD_PAL) {
3067 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_PAL,
3068 &flags);
3069 } else if (std & V4L2_STD_NTSC) {
3070 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_NTSC,
3071 &flags);
3072 } else if (std & V4L2_STD_SECAM) {
3073 ret = vino_set_data_norm(vcs, VINO_DATA_NORM_SECAM,
3074 &flags);
3075 } else {
3076 ret = -EINVAL;
3077 }
3078
3079 if (ret) {
3080 ret = -EINVAL;
3081 }
3082 } else {
3083 ret = -EINVAL;
3084 }
3085
3086out:
3087 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3088
3089 return ret;
3090}
3091
3092static int vino_enum_fmt_vid_cap(struct file *file, void *__fh,
3093 struct v4l2_fmtdesc *fd)
3094{
3095 dprintk("format index = %d\n", fd->index);
3096
3097 if (fd->index >= VINO_DATA_FMT_COUNT)
3098 return -EINVAL;
3099 dprintk("format name = %s\n", vino_data_formats[fd->index].description);
3100
3101 fd->pixelformat = vino_data_formats[fd->index].pixelformat;
3102 strcpy(fd->description, vino_data_formats[fd->index].description);
3103 return 0;
3104}
3105
3106static int vino_try_fmt_vid_cap(struct file *file, void *__fh,
3107 struct v4l2_format *f)
3108{
3109 struct vino_channel_settings *vcs = video_drvdata(file);
3110 struct vino_channel_settings tempvcs;
3111 unsigned long flags;
3112 struct v4l2_pix_format *pf = &f->fmt.pix;
3113
3114 dprintk("requested: w = %d, h = %d\n",
3115 pf->width, pf->height);
3116
3117 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3118 memcpy(&tempvcs, vcs, sizeof(struct vino_channel_settings));
3119 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3120
3121 tempvcs.data_format = vino_find_data_format(pf->pixelformat);
3122 if (tempvcs.data_format == VINO_DATA_FMT_NONE) {
3123 tempvcs.data_format = VINO_DATA_FMT_GREY;
3124 pf->pixelformat =
3125 vino_data_formats[tempvcs.data_format].
3126 pixelformat;
3127 }
3128
3129 /* data format must be set before clipping/scaling */
3130 vino_set_scaling(&tempvcs, pf->width, pf->height);
3131
3132 dprintk("data format = %s\n",
3133 vino_data_formats[tempvcs.data_format].description);
3134
3135 pf->width = (tempvcs.clipping.right - tempvcs.clipping.left) /
3136 tempvcs.decimation;
3137 pf->height = (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3138 tempvcs.decimation;
3139
3140 pf->field = V4L2_FIELD_INTERLACED;
3141 pf->bytesperline = tempvcs.line_size;
3142 pf->sizeimage = tempvcs.line_size *
3143 (tempvcs.clipping.bottom - tempvcs.clipping.top) /
3144 tempvcs.decimation;
3145 pf->colorspace =
3146 vino_data_formats[tempvcs.data_format].colorspace;
3147
3148 return 0;
3149}
3150
3151static int vino_g_fmt_vid_cap(struct file *file, void *__fh,
3152 struct v4l2_format *f)
3153{
3154 struct vino_channel_settings *vcs = video_drvdata(file);
3155 unsigned long flags;
3156 struct v4l2_pix_format *pf = &f->fmt.pix;
3157
3158 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3159
3160 pf->width = (vcs->clipping.right - vcs->clipping.left) /
3161 vcs->decimation;
3162 pf->height = (vcs->clipping.bottom - vcs->clipping.top) /
3163 vcs->decimation;
3164 pf->pixelformat =
3165 vino_data_formats[vcs->data_format].pixelformat;
3166
3167 pf->field = V4L2_FIELD_INTERLACED;
3168 pf->bytesperline = vcs->line_size;
3169 pf->sizeimage = vcs->line_size *
3170 (vcs->clipping.bottom - vcs->clipping.top) /
3171 vcs->decimation;
3172 pf->colorspace =
3173 vino_data_formats[vcs->data_format].colorspace;
3174
3175 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3176 return 0;
3177}
3178
3179static int vino_s_fmt_vid_cap(struct file *file, void *__fh,
3180 struct v4l2_format *f)
3181{
3182 struct vino_channel_settings *vcs = video_drvdata(file);
3183 int data_format;
3184 unsigned long flags;
3185 struct v4l2_pix_format *pf = &f->fmt.pix;
3186
3187 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3188
3189 data_format = vino_find_data_format(pf->pixelformat);
3190
3191 if (data_format == VINO_DATA_FMT_NONE) {
3192 vcs->data_format = VINO_DATA_FMT_GREY;
3193 pf->pixelformat =
3194 vino_data_formats[vcs->data_format].
3195 pixelformat;
3196 } else {
3197 vcs->data_format = data_format;
3198 }
3199
3200 /* data format must be set before clipping/scaling */
3201 vino_set_scaling(vcs, pf->width, pf->height);
3202
3203 dprintk("data format = %s\n",
3204 vino_data_formats[vcs->data_format].description);
3205
3206 pf->width = vcs->clipping.right - vcs->clipping.left;
3207 pf->height = vcs->clipping.bottom - vcs->clipping.top;
3208
3209 pf->field = V4L2_FIELD_INTERLACED;
3210 pf->bytesperline = vcs->line_size;
3211 pf->sizeimage = vcs->line_size *
3212 (vcs->clipping.bottom - vcs->clipping.top) /
3213 vcs->decimation;
3214 pf->colorspace =
3215 vino_data_formats[vcs->data_format].colorspace;
3216
3217 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3218 return 0;
3219}
3220
3221static int vino_cropcap(struct file *file, void *__fh,
3222 struct v4l2_cropcap *ccap)
3223{
3224 struct vino_channel_settings *vcs = video_drvdata(file);
3225 const struct vino_data_norm *norm;
3226 unsigned long flags;
3227
3228 switch (ccap->type) {
3229 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3230 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3231
3232 norm = &vino_data_norms[vcs->data_norm];
3233
3234 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3235
3236 ccap->bounds.left = 0;
3237 ccap->bounds.top = 0;
3238 ccap->bounds.width = norm->width;
3239 ccap->bounds.height = norm->height;
3240 memcpy(&ccap->defrect, &ccap->bounds,
3241 sizeof(struct v4l2_rect));
3242
3243 ccap->pixelaspect.numerator = 1;
3244 ccap->pixelaspect.denominator = 1;
3245 break;
3246 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3247 default:
3248 return -EINVAL;
3249 }
3250
3251 return 0;
3252}
3253
3254static int vino_g_crop(struct file *file, void *__fh,
3255 struct v4l2_crop *c)
3256{
3257 struct vino_channel_settings *vcs = video_drvdata(file);
3258 unsigned long flags;
3259
3260 switch (c->type) {
3261 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3262 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3263
3264 c->c.left = vcs->clipping.left;
3265 c->c.top = vcs->clipping.top;
3266 c->c.width = vcs->clipping.right - vcs->clipping.left;
3267 c->c.height = vcs->clipping.bottom - vcs->clipping.top;
3268
3269 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3270 break;
3271 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3272 default:
3273 return -EINVAL;
3274 }
3275
3276 return 0;
3277}
3278
3279static int vino_s_crop(struct file *file, void *__fh,
3280 const struct v4l2_crop *c)
3281{
3282 struct vino_channel_settings *vcs = video_drvdata(file);
3283 unsigned long flags;
3284
3285 switch (c->type) {
3286 case V4L2_BUF_TYPE_VIDEO_CAPTURE:
3287 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3288
3289 vino_set_clipping(vcs, c->c.left, c->c.top,
3290 c->c.width, c->c.height);
3291
3292 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3293 break;
3294 case V4L2_BUF_TYPE_VIDEO_OVERLAY:
3295 default:
3296 return -EINVAL;
3297 }
3298
3299 return 0;
3300}
3301
3302static int vino_g_parm(struct file *file, void *__fh,
3303 struct v4l2_streamparm *sp)
3304{
3305 struct vino_channel_settings *vcs = video_drvdata(file);
3306 unsigned long flags;
3307 struct v4l2_captureparm *cp = &sp->parm.capture;
3308
3309 cp->capability = V4L2_CAP_TIMEPERFRAME;
3310 cp->timeperframe.numerator = 1;
3311
3312 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3313
3314 cp->timeperframe.denominator = vcs->fps;
3315
3316 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3317
3318 /* TODO: cp->readbuffers = xxx; */
3319
3320 return 0;
3321}
3322
3323static int vino_s_parm(struct file *file, void *__fh,
3324 struct v4l2_streamparm *sp)
3325{
3326 struct vino_channel_settings *vcs = video_drvdata(file);
3327 unsigned long flags;
3328 struct v4l2_captureparm *cp = &sp->parm.capture;
3329
3330 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3331
3332 if ((cp->timeperframe.numerator == 0) ||
3333 (cp->timeperframe.denominator == 0)) {
3334 /* reset framerate */
3335 vino_set_default_framerate(vcs);
3336 } else {
3337 vino_set_framerate(vcs, cp->timeperframe.denominator /
3338 cp->timeperframe.numerator);
3339 }
3340
3341 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3342
3343 return 0;
3344}
3345
3346static int vino_reqbufs(struct file *file, void *__fh,
3347 struct v4l2_requestbuffers *rb)
3348{
3349 struct vino_channel_settings *vcs = video_drvdata(file);
3350
3351 if (vcs->reading)
3352 return -EBUSY;
3353
3354 /* TODO: check queue type */
3355 if (rb->memory != V4L2_MEMORY_MMAP) {
3356 dprintk("type not mmap\n");
3357 return -EINVAL;
3358 }
3359
3360 dprintk("count = %d\n", rb->count);
3361 if (rb->count > 0) {
3362 if (vino_is_capturing(vcs)) {
3363 dprintk("busy, capturing\n");
3364 return -EBUSY;
3365 }
3366
3367 if (vino_queue_has_mapped_buffers(&vcs->fb_queue)) {
3368 dprintk("busy, buffers still mapped\n");
3369 return -EBUSY;
3370 } else {
3371 vcs->streaming = 0;
3372 vino_queue_free(&vcs->fb_queue);
3373 vino_queue_init(&vcs->fb_queue, &rb->count);
3374 }
3375 } else {
3376 vcs->streaming = 0;
3377 vino_capture_stop(vcs);
3378 vino_queue_free(&vcs->fb_queue);
3379 }
3380
3381 return 0;
3382}
3383
3384static void vino_v4l2_get_buffer_status(struct vino_channel_settings *vcs,
3385 struct vino_framebuffer *fb,
3386 struct v4l2_buffer *b)
3387{
3388 if (vino_queue_outgoing_contains(&vcs->fb_queue,
3389 fb->id)) {
3390 b->flags &= ~V4L2_BUF_FLAG_QUEUED;
3391 b->flags |= V4L2_BUF_FLAG_DONE;
3392 } else if (vino_queue_incoming_contains(&vcs->fb_queue,
3393 fb->id)) {
3394 b->flags &= ~V4L2_BUF_FLAG_DONE;
3395 b->flags |= V4L2_BUF_FLAG_QUEUED;
3396 } else {
3397 b->flags &= ~(V4L2_BUF_FLAG_DONE |
3398 V4L2_BUF_FLAG_QUEUED);
3399 }
3400
3401 b->flags &= ~(V4L2_BUF_FLAG_TIMECODE);
3402
3403 if (fb->map_count > 0)
3404 b->flags |= V4L2_BUF_FLAG_MAPPED;
3405
3406 b->flags &= ~V4L2_BUF_FLAG_TIMESTAMP_MASK;
3407 b->flags |= V4L2_BUF_FLAG_TIMESTAMP_MONOTONIC;
3408
3409 b->index = fb->id;
3410 b->memory = (vcs->fb_queue.type == VINO_MEMORY_MMAP) ?
3411 V4L2_MEMORY_MMAP : V4L2_MEMORY_USERPTR;
3412 b->m.offset = fb->offset;
3413 b->bytesused = fb->data_size;
3414 b->length = fb->size;
3415 b->field = V4L2_FIELD_INTERLACED;
3416 b->sequence = fb->frame_counter;
3417 memcpy(&b->timestamp, &fb->timestamp,
3418 sizeof(struct timeval));
3419 // b->input ?
3420
3421 dprintk("buffer %d: length = %d, bytesused = %d, offset = %d\n",
3422 fb->id, fb->size, fb->data_size, fb->offset);
3423}
3424
3425static int vino_querybuf(struct file *file, void *__fh,
3426 struct v4l2_buffer *b)
3427{
3428 struct vino_channel_settings *vcs = video_drvdata(file);
3429 struct vino_framebuffer *fb;
3430
3431 if (vcs->reading)
3432 return -EBUSY;
3433
3434 /* TODO: check queue type */
3435 if (b->index >= vino_queue_get_length(&vcs->fb_queue)) {
3436 dprintk("invalid index = %d\n",
3437 b->index);
3438 return -EINVAL;
3439 }
3440
3441 fb = vino_queue_get_buffer(&vcs->fb_queue,
3442 b->index);
3443 if (fb == NULL) {
3444 dprintk("vino_queue_get_buffer() failed");
3445 return -EINVAL;
3446 }
3447
3448 vino_v4l2_get_buffer_status(vcs, fb, b);
3449
3450 return 0;
3451}
3452
3453static int vino_qbuf(struct file *file, void *__fh,
3454 struct v4l2_buffer *b)
3455{
3456 struct vino_channel_settings *vcs = video_drvdata(file);
3457 struct vino_framebuffer *fb;
3458 int ret;
3459
3460 if (vcs->reading)
3461 return -EBUSY;
3462
3463 /* TODO: check queue type */
3464 if (b->memory != V4L2_MEMORY_MMAP) {
3465 dprintk("type not mmap\n");
3466 return -EINVAL;
3467 }
3468
3469 fb = vino_capture_enqueue(vcs, b->index);
3470 if (fb == NULL)
3471 return -EINVAL;
3472
3473 vino_v4l2_get_buffer_status(vcs, fb, b);
3474
3475 if (vcs->streaming) {
3476 ret = vino_capture_next(vcs, 1);
3477 if (ret)
3478 return ret;
3479 }
3480
3481 return 0;
3482}
3483
3484static int vino_dqbuf(struct file *file, void *__fh,
3485 struct v4l2_buffer *b)
3486{
3487 struct vino_channel_settings *vcs = video_drvdata(file);
3488 unsigned int nonblocking = file->f_flags & O_NONBLOCK;
3489 struct vino_framebuffer *fb;
3490 unsigned int incoming, outgoing;
3491 int err;
3492
3493 if (vcs->reading)
3494 return -EBUSY;
3495
3496 /* TODO: check queue type */
3497
3498 err = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3499 if (err) {
3500 dprintk("vino_queue_get_incoming() failed\n");
3501 return -EINVAL;
3502 }
3503 err = vino_queue_get_outgoing(&vcs->fb_queue, &outgoing);
3504 if (err) {
3505 dprintk("vino_queue_get_outgoing() failed\n");
3506 return -EINVAL;
3507 }
3508
3509 dprintk("incoming = %d, outgoing = %d\n", incoming, outgoing);
3510
3511 if (outgoing == 0) {
3512 if (incoming == 0) {
3513 dprintk("no incoming or outgoing buffers\n");
3514 return -EINVAL;
3515 }
3516 if (nonblocking) {
3517 dprintk("non-blocking I/O was selected and "
3518 "there are no buffers to dequeue\n");
3519 return -EAGAIN;
3520 }
3521
3522 err = vino_wait_for_frame(vcs);
3523 if (err) {
3524 err = vino_wait_for_frame(vcs);
3525 if (err) {
3526 /* interrupted or no frames captured because of
3527 * frame skipping */
3528 /* vino_capture_failed(vcs); */
3529 return -EIO;
3530 }
3531 }
3532 }
3533
3534 fb = vino_queue_remove(&vcs->fb_queue, &b->index);
3535 if (fb == NULL) {
3536 dprintk("vino_queue_remove() failed\n");
3537 return -EINVAL;
3538 }
3539
3540 err = vino_check_buffer(vcs, fb);
3541
3542 vino_v4l2_get_buffer_status(vcs, fb, b);
3543
3544 if (err)
3545 return -EIO;
3546
3547 return 0;
3548}
3549
3550static int vino_streamon(struct file *file, void *__fh,
3551 enum v4l2_buf_type i)
3552{
3553 struct vino_channel_settings *vcs = video_drvdata(file);
3554 unsigned int incoming;
3555 int ret;
3556 if (vcs->reading)
3557 return -EBUSY;
3558
3559 if (vcs->streaming)
3560 return 0;
3561
3562 // TODO: check queue type
3563
3564 if (vino_queue_get_length(&vcs->fb_queue) < 1) {
3565 dprintk("no buffers allocated\n");
3566 return -EINVAL;
3567 }
3568
3569 ret = vino_queue_get_incoming(&vcs->fb_queue, &incoming);
3570 if (ret) {
3571 dprintk("vino_queue_get_incoming() failed\n");
3572 return -EINVAL;
3573 }
3574
3575 vcs->streaming = 1;
3576
3577 if (incoming > 0) {
3578 ret = vino_capture_next(vcs, 1);
3579 if (ret) {
3580 vcs->streaming = 0;
3581
3582 dprintk("couldn't start capture\n");
3583 return -EINVAL;
3584 }
3585 }
3586
3587 return 0;
3588}
3589
3590static int vino_streamoff(struct file *file, void *__fh,
3591 enum v4l2_buf_type i)
3592{
3593 struct vino_channel_settings *vcs = video_drvdata(file);
3594 if (vcs->reading)
3595 return -EBUSY;
3596
3597 if (!vcs->streaming)
3598 return 0;
3599
3600 vcs->streaming = 0;
3601 vino_capture_stop(vcs);
3602
3603 return 0;
3604}
3605
3606static int vino_queryctrl(struct file *file, void *__fh,
3607 struct v4l2_queryctrl *queryctrl)
3608{
3609 struct vino_channel_settings *vcs = video_drvdata(file);
3610 unsigned long flags;
3611 int i;
3612 int err = 0;
3613
3614 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3615
3616 switch (vcs->input) {
3617 case VINO_INPUT_D1:
3618 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3619 if (vino_indycam_v4l2_controls[i].id ==
3620 queryctrl->id) {
3621 memcpy(queryctrl,
3622 &vino_indycam_v4l2_controls[i],
3623 sizeof(struct v4l2_queryctrl));
3624 queryctrl->reserved[0] = 0;
3625 goto found;
3626 }
3627 }
3628
3629 err = -EINVAL;
3630 break;
3631 case VINO_INPUT_COMPOSITE:
3632 case VINO_INPUT_SVIDEO:
3633 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3634 if (vino_saa7191_v4l2_controls[i].id ==
3635 queryctrl->id) {
3636 memcpy(queryctrl,
3637 &vino_saa7191_v4l2_controls[i],
3638 sizeof(struct v4l2_queryctrl));
3639 queryctrl->reserved[0] = 0;
3640 goto found;
3641 }
3642 }
3643
3644 err = -EINVAL;
3645 break;
3646 default:
3647 err = -EINVAL;
3648 }
3649
3650 found:
3651 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3652
3653 return err;
3654}
3655
3656static int vino_g_ctrl(struct file *file, void *__fh,
3657 struct v4l2_control *control)
3658{
3659 struct vino_channel_settings *vcs = video_drvdata(file);
3660 unsigned long flags;
3661 int i;
3662 int err = 0;
3663
3664 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3665
3666 switch (vcs->input) {
3667 case VINO_INPUT_D1: {
3668 err = -EINVAL;
3669 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3670 if (vino_indycam_v4l2_controls[i].id == control->id) {
3671 err = 0;
3672 break;
3673 }
3674 }
3675
3676 if (err)
3677 goto out;
3678
3679 err = camera_call(core, g_ctrl, control);
3680 if (err)
3681 err = -EINVAL;
3682 break;
3683 }
3684 case VINO_INPUT_COMPOSITE:
3685 case VINO_INPUT_SVIDEO: {
3686 err = -EINVAL;
3687 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3688 if (vino_saa7191_v4l2_controls[i].id == control->id) {
3689 err = 0;
3690 break;
3691 }
3692 }
3693
3694 if (err)
3695 goto out;
3696
3697 err = decoder_call(core, g_ctrl, control);
3698 if (err)
3699 err = -EINVAL;
3700 break;
3701 }
3702 default:
3703 err = -EINVAL;
3704 }
3705
3706out:
3707 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3708
3709 return err;
3710}
3711
3712static int vino_s_ctrl(struct file *file, void *__fh,
3713 struct v4l2_control *control)
3714{
3715 struct vino_channel_settings *vcs = video_drvdata(file);
3716 unsigned long flags;
3717 int i;
3718 int err = 0;
3719
3720 spin_lock_irqsave(&vino_drvdata->input_lock, flags);
3721
3722 if (!vino_is_input_owner(vcs)) {
3723 err = -EBUSY;
3724 goto out;
3725 }
3726
3727 switch (vcs->input) {
3728 case VINO_INPUT_D1: {
3729 err = -EINVAL;
3730 for (i = 0; i < VINO_INDYCAM_V4L2_CONTROL_COUNT; i++) {
3731 if (vino_indycam_v4l2_controls[i].id == control->id) {
3732 err = 0;
3733 break;
3734 }
3735 }
3736 if (err)
3737 goto out;
3738 if (control->value < vino_indycam_v4l2_controls[i].minimum ||
3739 control->value > vino_indycam_v4l2_controls[i].maximum) {
3740 err = -ERANGE;
3741 goto out;
3742 }
3743 err = camera_call(core, s_ctrl, control);
3744 if (err)
3745 err = -EINVAL;
3746 break;
3747 }
3748 case VINO_INPUT_COMPOSITE:
3749 case VINO_INPUT_SVIDEO: {
3750 err = -EINVAL;
3751 for (i = 0; i < VINO_SAA7191_V4L2_CONTROL_COUNT; i++) {
3752 if (vino_saa7191_v4l2_controls[i].id == control->id) {
3753 err = 0;
3754 break;
3755 }
3756 }
3757 if (err)
3758 goto out;
3759 if (control->value < vino_saa7191_v4l2_controls[i].minimum ||
3760 control->value > vino_saa7191_v4l2_controls[i].maximum) {
3761 err = -ERANGE;
3762 goto out;
3763 }
3764
3765 err = decoder_call(core, s_ctrl, control);
3766 if (err)
3767 err = -EINVAL;
3768 break;
3769 }
3770 default:
3771 err = -EINVAL;
3772 }
3773
3774out:
3775 spin_unlock_irqrestore(&vino_drvdata->input_lock, flags);
3776
3777 return err;
3778}
3779
3780/* File operations */
3781
3782static int vino_open(struct file *file)
3783{
3784 struct vino_channel_settings *vcs = video_drvdata(file);
3785 int ret = 0;
3786 dprintk("open(): channel = %c\n",
3787 (vcs->channel == VINO_CHANNEL_A) ? 'A' : 'B');
3788
3789 mutex_lock(&vcs->mutex);
3790
3791 if (vcs->users) {
3792 dprintk("open(): driver busy\n");
3793 ret = -EBUSY;
3794 goto out;
3795 }
3796
3797 ret = vino_acquire_input(vcs);
3798 if (ret) {
3799 dprintk("open(): vino_acquire_input() failed\n");
3800 goto out;
3801 }
3802
3803 vcs->users++;
3804
3805 out:
3806 mutex_unlock(&vcs->mutex);
3807
3808 dprintk("open(): %s!\n", ret ? "failed" : "complete");
3809
3810 return ret;
3811}
3812
3813static int vino_close(struct file *file)
3814{
3815 struct vino_channel_settings *vcs = video_drvdata(file);
3816 dprintk("close():\n");
3817
3818 mutex_lock(&vcs->mutex);
3819
3820 vcs->users--;
3821
3822 if (!vcs->users) {
3823 vino_release_input(vcs);
3824
3825 /* stop DMA and free buffers */
3826 vino_capture_stop(vcs);
3827 vino_queue_free(&vcs->fb_queue);
3828 }
3829
3830 mutex_unlock(&vcs->mutex);
3831
3832 return 0;
3833}
3834
3835static void vino_vm_open(struct vm_area_struct *vma)
3836{
3837 struct vino_framebuffer *fb = vma->vm_private_data;
3838
3839 fb->map_count++;
3840 dprintk("vino_vm_open(): count = %d\n", fb->map_count);
3841}
3842
3843static void vino_vm_close(struct vm_area_struct *vma)
3844{
3845 struct vino_framebuffer *fb = vma->vm_private_data;
3846
3847 fb->map_count--;
3848 dprintk("vino_vm_close(): count = %d\n", fb->map_count);
3849}
3850
3851static const struct vm_operations_struct vino_vm_ops = {
3852 .open = vino_vm_open,
3853 .close = vino_vm_close,
3854};
3855
3856static int vino_mmap(struct file *file, struct vm_area_struct *vma)
3857{
3858 struct vino_channel_settings *vcs = video_drvdata(file);
3859
3860 unsigned long start = vma->vm_start;
3861 unsigned long size = vma->vm_end - vma->vm_start;
3862 unsigned long offset = vma->vm_pgoff << PAGE_SHIFT;
3863
3864 struct vino_framebuffer *fb = NULL;
3865 unsigned int i, length;
3866 int ret = 0;
3867
3868 dprintk("mmap():\n");
3869
3870 // TODO: reject mmap if already mapped
3871
3872 if (mutex_lock_interruptible(&vcs->mutex))
3873 return -EINTR;
3874
3875 if (vcs->reading) {
3876 ret = -EBUSY;
3877 goto out;
3878 }
3879
3880 // TODO: check queue type
3881
3882 if (!(vma->vm_flags & VM_WRITE)) {
3883 dprintk("mmap(): app bug: PROT_WRITE please\n");
3884 ret = -EINVAL;
3885 goto out;
3886 }
3887 if (!(vma->vm_flags & VM_SHARED)) {
3888 dprintk("mmap(): app bug: MAP_SHARED please\n");
3889 ret = -EINVAL;
3890 goto out;
3891 }
3892
3893 /* find the correct buffer using offset */
3894 length = vino_queue_get_length(&vcs->fb_queue);
3895 if (length == 0) {
3896 dprintk("mmap(): queue not initialized\n");
3897 ret = -EINVAL;
3898 goto out;
3899 }
3900
3901 for (i = 0; i < length; i++) {
3902 fb = vino_queue_get_buffer(&vcs->fb_queue, i);
3903 if (fb == NULL) {
3904 dprintk("mmap(): vino_queue_get_buffer() failed\n");
3905 ret = -EINVAL;
3906 goto out;
3907 }
3908
3909 if (fb->offset == offset)
3910 goto found;
3911 }
3912
3913 dprintk("mmap(): invalid offset = %lu\n", offset);
3914 ret = -EINVAL;
3915 goto out;
3916
3917found:
3918 dprintk("mmap(): buffer = %d\n", i);
3919
3920 if (size > (fb->desc_table.page_count * PAGE_SIZE)) {
3921 dprintk("mmap(): failed: size = %lu > %lu\n",
3922 size, fb->desc_table.page_count * PAGE_SIZE);
3923 ret = -EINVAL;
3924 goto out;
3925 }
3926
3927 for (i = 0; i < fb->desc_table.page_count; i++) {
3928 unsigned long pfn =
3929 virt_to_phys((void *)fb->desc_table.virtual[i]) >>
3930 PAGE_SHIFT;
3931
3932 if (size < PAGE_SIZE)
3933 break;
3934
3935 // protection was: PAGE_READONLY
3936 if (remap_pfn_range(vma, start, pfn, PAGE_SIZE,
3937 vma->vm_page_prot)) {
3938 dprintk("mmap(): remap_pfn_range() failed\n");
3939 ret = -EAGAIN;
3940 goto out;
3941 }
3942
3943 start += PAGE_SIZE;
3944 size -= PAGE_SIZE;
3945 }
3946
3947 fb->map_count = 1;
3948
3949 vma->vm_flags |= VM_DONTEXPAND | VM_DONTDUMP;
3950 vma->vm_flags &= ~VM_IO;
3951 vma->vm_private_data = fb;
3952 vma->vm_file = file;
3953 vma->vm_ops = &vino_vm_ops;
3954
3955out:
3956 mutex_unlock(&vcs->mutex);
3957
3958 return ret;
3959}
3960
3961static unsigned int vino_poll(struct file *file, poll_table *pt)
3962{
3963 struct vino_channel_settings *vcs = video_drvdata(file);
3964 unsigned int outgoing;
3965 unsigned int ret = 0;
3966
3967 // lock mutex (?)
3968 // TODO: this has to be corrected for different read modes
3969
3970 dprintk("poll():\n");
3971
3972 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
3973 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3974 ret = POLLERR;
3975 goto error;
3976 }
3977 if (outgoing > 0)
3978 goto over;
3979
3980 poll_wait(file, &vcs->fb_queue.frame_wait_queue, pt);
3981
3982 if (vino_queue_get_outgoing(&vcs->fb_queue, &outgoing)) {
3983 dprintk("poll(): vino_queue_get_outgoing() failed\n");
3984 ret = POLLERR;
3985 goto error;
3986 }
3987
3988over:
3989 dprintk("poll(): data %savailable\n",
3990 (outgoing > 0) ? "" : "not ");
3991
3992 if (outgoing > 0)
3993 ret = POLLIN | POLLRDNORM;
3994
3995error:
3996 return ret;
3997}
3998
3999static long vino_ioctl(struct file *file,
4000 unsigned int cmd, unsigned long arg)
4001{
4002 struct vino_channel_settings *vcs = video_drvdata(file);
4003 long ret;
4004
4005 if (mutex_lock_interruptible(&vcs->mutex))
4006 return -EINTR;
4007
4008 ret = video_ioctl2(file, cmd, arg);
4009
4010 mutex_unlock(&vcs->mutex);
4011
4012 return ret;
4013}
4014
4015/* Initialization and cleanup */
4016
4017/* __initdata */
4018static int vino_init_stage;
4019
4020const struct v4l2_ioctl_ops vino_ioctl_ops = {
4021 .vidioc_enum_fmt_vid_cap = vino_enum_fmt_vid_cap,
4022 .vidioc_g_fmt_vid_cap = vino_g_fmt_vid_cap,
4023 .vidioc_s_fmt_vid_cap = vino_s_fmt_vid_cap,
4024 .vidioc_try_fmt_vid_cap = vino_try_fmt_vid_cap,
4025 .vidioc_querycap = vino_querycap,
4026 .vidioc_enum_input = vino_enum_input,
4027 .vidioc_g_input = vino_g_input,
4028 .vidioc_s_input = vino_s_input,
4029 .vidioc_g_std = vino_g_std,
4030 .vidioc_s_std = vino_s_std,
4031 .vidioc_querystd = vino_querystd,
4032 .vidioc_cropcap = vino_cropcap,
4033 .vidioc_s_crop = vino_s_crop,
4034 .vidioc_g_crop = vino_g_crop,
4035 .vidioc_s_parm = vino_s_parm,
4036 .vidioc_g_parm = vino_g_parm,
4037 .vidioc_reqbufs = vino_reqbufs,
4038 .vidioc_querybuf = vino_querybuf,
4039 .vidioc_qbuf = vino_qbuf,
4040 .vidioc_dqbuf = vino_dqbuf,
4041 .vidioc_streamon = vino_streamon,
4042 .vidioc_streamoff = vino_streamoff,
4043 .vidioc_queryctrl = vino_queryctrl,
4044 .vidioc_g_ctrl = vino_g_ctrl,
4045 .vidioc_s_ctrl = vino_s_ctrl,
4046};
4047
4048static const struct v4l2_file_operations vino_fops = {
4049 .owner = THIS_MODULE,
4050 .open = vino_open,
4051 .release = vino_close,
4052 .unlocked_ioctl = vino_ioctl,
4053 .mmap = vino_mmap,
4054 .poll = vino_poll,
4055};
4056
4057static struct video_device vdev_template = {
4058 .name = "NOT SET",
4059 .fops = &vino_fops,
4060 .ioctl_ops = &vino_ioctl_ops,
4061 .tvnorms = V4L2_STD_NTSC | V4L2_STD_PAL | V4L2_STD_SECAM,
4062};
4063
4064static void vino_module_cleanup(int stage)
4065{
4066 switch(stage) {
4067 case 11:
4068 video_unregister_device(vino_drvdata->b.vdev);
4069 vino_drvdata->b.vdev = NULL;
4070 case 10:
4071 video_unregister_device(vino_drvdata->a.vdev);
4072 vino_drvdata->a.vdev = NULL;
4073 case 9:
4074 i2c_del_adapter(&vino_i2c_adapter);
4075 case 8:
4076 free_irq(SGI_VINO_IRQ, NULL);
4077 case 7:
4078 if (vino_drvdata->b.vdev) {
4079 video_device_release(vino_drvdata->b.vdev);
4080 vino_drvdata->b.vdev = NULL;
4081 }
4082 case 6:
4083 if (vino_drvdata->a.vdev) {
4084 video_device_release(vino_drvdata->a.vdev);
4085 vino_drvdata->a.vdev = NULL;
4086 }
4087 case 5:
4088 /* all entries in dma_cpu dummy table have the same address */
4089 dma_unmap_single(NULL,
4090 vino_drvdata->dummy_desc_table.dma_cpu[0],
4091 PAGE_SIZE, DMA_FROM_DEVICE);
4092 dma_free_coherent(NULL, VINO_DUMMY_DESC_COUNT
4093 * sizeof(dma_addr_t),
4094 (void *)vino_drvdata->
4095 dummy_desc_table.dma_cpu,
4096 vino_drvdata->dummy_desc_table.dma);
4097 case 4:
4098 free_page(vino_drvdata->dummy_page);
4099 case 3:
4100 v4l2_device_unregister(&vino_drvdata->v4l2_dev);
4101 case 2:
4102 kfree(vino_drvdata);
4103 case 1:
4104 iounmap(vino);
4105 case 0:
4106 break;
4107 default:
4108 dprintk("vino_module_cleanup(): invalid cleanup stage = %d\n",
4109 stage);
4110 }
4111}
4112
4113static int vino_probe(void)
4114{
4115 unsigned long rev_id;
4116
4117 if (ip22_is_fullhouse()) {
4118 printk(KERN_ERR "VINO doesn't exist in IP22 Fullhouse\n");
4119 return -ENODEV;
4120 }
4121
4122 if (!(sgimc->systemid & SGIMC_SYSID_EPRESENT)) {
4123 printk(KERN_ERR "VINO is not found (EISA BUS not present)\n");
4124 return -ENODEV;
4125 }
4126
4127 vino = (struct sgi_vino *)ioremap(VINO_BASE, sizeof(struct sgi_vino));
4128 if (!vino) {
4129 printk(KERN_ERR "VINO: ioremap() failed\n");
4130 return -EIO;
4131 }
4132 vino_init_stage++;
4133
4134 if (get_dbe(rev_id, &(vino->rev_id))) {
4135 printk(KERN_ERR "Failed to read VINO revision register\n");
4136 vino_module_cleanup(vino_init_stage);
4137 return -ENODEV;
4138 }
4139
4140 if (VINO_ID_VALUE(rev_id) != VINO_CHIP_ID) {
4141 printk(KERN_ERR "Unknown VINO chip ID (Rev/ID: 0x%02lx)\n",
4142 rev_id);
4143 vino_module_cleanup(vino_init_stage);
4144 return -ENODEV;
4145 }
4146
4147 printk(KERN_INFO "VINO revision %ld found\n", VINO_REV_NUM(rev_id));
4148
4149 return 0;
4150}
4151
4152static int vino_init(void)
4153{
4154 dma_addr_t dma_dummy_address;
4155 int err;
4156 int i;
4157
4158 vino_drvdata = kzalloc(sizeof(struct vino_settings), GFP_KERNEL);
4159 if (!vino_drvdata) {
4160 vino_module_cleanup(vino_init_stage);
4161 return -ENOMEM;
4162 }
4163 vino_init_stage++;
4164 strlcpy(vino_drvdata->v4l2_dev.name, "vino",
4165 sizeof(vino_drvdata->v4l2_dev.name));
4166 err = v4l2_device_register(NULL, &vino_drvdata->v4l2_dev);
4167 if (err)
4168 return err;
4169 vino_init_stage++;
4170
4171 /* create a dummy dma descriptor */
4172 vino_drvdata->dummy_page = get_zeroed_page(GFP_KERNEL | GFP_DMA);
4173 if (!vino_drvdata->dummy_page) {
4174 vino_module_cleanup(vino_init_stage);
4175 return -ENOMEM;
4176 }
4177 vino_init_stage++;
4178
4179 // TODO: use page_count in dummy_desc_table
4180
4181 vino_drvdata->dummy_desc_table.dma_cpu =
4182 dma_alloc_coherent(NULL,
4183 VINO_DUMMY_DESC_COUNT * sizeof(dma_addr_t),
4184 &vino_drvdata->dummy_desc_table.dma,
4185 GFP_KERNEL | GFP_DMA);
4186 if (!vino_drvdata->dummy_desc_table.dma_cpu) {
4187 vino_module_cleanup(vino_init_stage);
4188 return -ENOMEM;
4189 }
4190 vino_init_stage++;
4191
4192 dma_dummy_address = dma_map_single(NULL,
4193 (void *)vino_drvdata->dummy_page,
4194 PAGE_SIZE, DMA_FROM_DEVICE);
4195 for (i = 0; i < VINO_DUMMY_DESC_COUNT; i++) {
4196 vino_drvdata->dummy_desc_table.dma_cpu[i] = dma_dummy_address;
4197 }
4198
4199 /* initialize VINO */
4200
4201 vino->control = 0;
4202 vino->a.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4203 vino->b.next_4_desc = vino_drvdata->dummy_desc_table.dma;
4204 udelay(VINO_DESC_FETCH_DELAY);
4205
4206 vino->intr_status = 0;
4207
4208 vino->a.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4209 vino->b.fifo_thres = VINO_FIFO_THRESHOLD_DEFAULT;
4210
4211 return 0;
4212}
4213
4214static int vino_init_channel_settings(struct vino_channel_settings *vcs,
4215 unsigned int channel, const char *name)
4216{
4217 vcs->channel = channel;
4218 vcs->input = VINO_INPUT_NONE;
4219 vcs->alpha = 0;
4220 vcs->users = 0;
4221 vcs->data_format = VINO_DATA_FMT_GREY;
4222 vcs->data_norm = VINO_DATA_NORM_NTSC;
4223 vcs->decimation = 1;
4224 vino_set_default_clipping(vcs);
4225 vino_set_default_framerate(vcs);
4226
4227 vcs->capturing = 0;
4228
4229 mutex_init(&vcs->mutex);
4230 spin_lock_init(&vcs->capture_lock);
4231
4232 mutex_init(&vcs->fb_queue.queue_mutex);
4233 spin_lock_init(&vcs->fb_queue.queue_lock);
4234 init_waitqueue_head(&vcs->fb_queue.frame_wait_queue);
4235
4236 vcs->vdev = video_device_alloc();
4237 if (!vcs->vdev) {
4238 vino_module_cleanup(vino_init_stage);
4239 return -ENOMEM;
4240 }
4241 vino_init_stage++;
4242
4243 memcpy(vcs->vdev, &vdev_template,
4244 sizeof(struct video_device));
4245 strcpy(vcs->vdev->name, name);
4246 vcs->vdev->release = video_device_release;
4247 vcs->vdev->v4l2_dev = &vino_drvdata->v4l2_dev;
4248
4249 video_set_drvdata(vcs->vdev, vcs);
4250
4251 return 0;
4252}
4253
4254static int __init vino_module_init(void)
4255{
4256 int ret;
4257
4258 printk(KERN_INFO "SGI VINO driver version %s\n",
4259 VINO_MODULE_VERSION);
4260
4261 ret = vino_probe();
4262 if (ret)
4263 return ret;
4264
4265 ret = vino_init();
4266 if (ret)
4267 return ret;
4268
4269 /* initialize data structures */
4270
4271 spin_lock_init(&vino_drvdata->vino_lock);
4272 spin_lock_init(&vino_drvdata->input_lock);
4273
4274 ret = vino_init_channel_settings(&vino_drvdata->a, VINO_CHANNEL_A,
4275 vino_vdev_name_a);
4276 if (ret)
4277 return ret;
4278
4279 ret = vino_init_channel_settings(&vino_drvdata->b, VINO_CHANNEL_B,
4280 vino_vdev_name_b);
4281 if (ret)
4282 return ret;
4283
4284 /* initialize hardware and register V4L devices */
4285
4286 ret = request_irq(SGI_VINO_IRQ, vino_interrupt, 0,
4287 vino_driver_description, NULL);
4288 if (ret) {
4289 printk(KERN_ERR "VINO: requesting IRQ %02d failed\n",
4290 SGI_VINO_IRQ);
4291 vino_module_cleanup(vino_init_stage);
4292 return -EAGAIN;
4293 }
4294 vino_init_stage++;
4295
4296 ret = i2c_add_adapter(&vino_i2c_adapter);
4297 if (ret) {
4298 printk(KERN_ERR "VINO I2C bus registration failed\n");
4299 vino_module_cleanup(vino_init_stage);
4300 return ret;
4301 }
4302 i2c_set_adapdata(&vino_i2c_adapter, &vino_drvdata->v4l2_dev);
4303 vino_init_stage++;
4304
4305 ret = video_register_device(vino_drvdata->a.vdev,
4306 VFL_TYPE_GRABBER, -1);
4307 if (ret < 0) {
4308 printk(KERN_ERR "VINO channel A Video4Linux-device "
4309 "registration failed\n");
4310 vino_module_cleanup(vino_init_stage);
4311 return -EINVAL;
4312 }
4313 vino_init_stage++;
4314
4315 ret = video_register_device(vino_drvdata->b.vdev,
4316 VFL_TYPE_GRABBER, -1);
4317 if (ret < 0) {
4318 printk(KERN_ERR "VINO channel B Video4Linux-device "
4319 "registration failed\n");
4320 vino_module_cleanup(vino_init_stage);
4321 return -EINVAL;
4322 }
4323 vino_init_stage++;
4324
4325 vino_drvdata->decoder =
4326 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter,
4327 "saa7191", 0, I2C_ADDRS(0x45));
4328 vino_drvdata->camera =
4329 v4l2_i2c_new_subdev(&vino_drvdata->v4l2_dev, &vino_i2c_adapter,
4330 "indycam", 0, I2C_ADDRS(0x2b));
4331
4332 dprintk("init complete!\n");
4333
4334 return 0;
4335}
4336
4337static void __exit vino_module_exit(void)
4338{
4339 dprintk("exiting, stage = %d ...\n", vino_init_stage);
4340 vino_module_cleanup(vino_init_stage);
4341 dprintk("cleanup complete, exit!\n");
4342}
4343
4344module_init(vino_module_init);
4345module_exit(vino_module_exit);
diff --git a/drivers/staging/media/vino/vino.h b/drivers/staging/media/vino/vino.h
deleted file mode 100644
index de2d615ae7c9..000000000000
--- a/drivers/staging/media/vino/vino.h
+++ /dev/null
@@ -1,138 +0,0 @@
1/*
2 * Driver for the VINO (Video In No Out) system found in SGI Indys.
3 *
4 * This file is subject to the terms and conditions of the GNU General Public
5 * License version 2 as published by the Free Software Foundation.
6 *
7 * Copyright (C) 1999 Ulf Karlsson <ulfc@bun.falkenberg.se>
8 * Copyright (C) 2003 Ladislav Michl <ladis@linux-mips.org>
9 */
10
11#ifndef _VINO_H_
12#define _VINO_H_
13
14#define VINO_BASE 0x00080000 /* Vino is in the EISA address space,
15 * but it is not an EISA bus card */
16#define VINO_PAGE_SIZE 4096
17
18struct sgi_vino_channel {
19 u32 _pad_alpha;
20 volatile u32 alpha;
21
22#define VINO_CLIP_X(x) ((x) & 0x3ff) /* bits 0:9 */
23#define VINO_CLIP_ODD(x) (((x) & 0x1ff) << 10) /* bits 10:18 */
24#define VINO_CLIP_EVEN(x) (((x) & 0x1ff) << 19) /* bits 19:27 */
25 u32 _pad_clip_start;
26 volatile u32 clip_start;
27 u32 _pad_clip_end;
28 volatile u32 clip_end;
29
30#define VINO_FRAMERT_FULL 0xfff
31#define VINO_FRAMERT_PAL (1<<0) /* 0=NTSC 1=PAL */
32#define VINO_FRAMERT_RT(x) (((x) & 0xfff) << 1) /* bits 1:12 */
33 u32 _pad_frame_rate;
34 volatile u32 frame_rate;
35
36 u32 _pad_field_counter;
37 volatile u32 field_counter;
38 u32 _pad_line_size;
39 volatile u32 line_size;
40 u32 _pad_line_count;
41 volatile u32 line_count;
42 u32 _pad_page_index;
43 volatile u32 page_index;
44 u32 _pad_next_4_desc;
45 volatile u32 next_4_desc;
46 u32 _pad_start_desc_tbl;
47 volatile u32 start_desc_tbl;
48
49#define VINO_DESC_JUMP (1<<30)
50#define VINO_DESC_STOP (1<<31)
51#define VINO_DESC_VALID (1<<32)
52 u32 _pad_desc_0;
53 volatile u32 desc_0;
54 u32 _pad_desc_1;
55 volatile u32 desc_1;
56 u32 _pad_desc_2;
57 volatile u32 desc_2;
58 u32 _pad_Bdesc_3;
59 volatile u32 desc_3;
60
61 u32 _pad_fifo_thres;
62 volatile u32 fifo_thres;
63 u32 _pad_fifo_read;
64 volatile u32 fifo_read;
65 u32 _pad_fifo_write;
66 volatile u32 fifo_write;
67};
68
69struct sgi_vino {
70#define VINO_CHIP_ID 0xb
71#define VINO_REV_NUM(x) ((x) & 0x0f)
72#define VINO_ID_VALUE(x) (((x) & 0xf0) >> 4)
73 u32 _pad_rev_id;
74 volatile u32 rev_id;
75
76#define VINO_CTRL_LITTLE_ENDIAN (1<<0)
77#define VINO_CTRL_A_EOF_INT (1<<1) /* Field transferred int */
78#define VINO_CTRL_A_FIFO_INT (1<<2) /* FIFO overflow int */
79#define VINO_CTRL_A_EOD_INT (1<<3) /* End of desc table int */
80#define VINO_CTRL_A_INT (VINO_CTRL_A_EOF_INT | \
81 VINO_CTRL_A_FIFO_INT | \
82 VINO_CTRL_A_EOD_INT)
83#define VINO_CTRL_B_EOF_INT (1<<4) /* Field transferred int */
84#define VINO_CTRL_B_FIFO_INT (1<<5) /* FIFO overflow int */
85#define VINO_CTRL_B_EOD_INT (1<<6) /* End of desc table int */
86#define VINO_CTRL_B_INT (VINO_CTRL_B_EOF_INT | \
87 VINO_CTRL_B_FIFO_INT | \
88 VINO_CTRL_B_EOD_INT)
89#define VINO_CTRL_A_DMA_ENBL (1<<7)
90#define VINO_CTRL_A_INTERLEAVE_ENBL (1<<8)
91#define VINO_CTRL_A_SYNC_ENBL (1<<9)
92#define VINO_CTRL_A_SELECT (1<<10) /* 1=D1 0=Philips */
93#define VINO_CTRL_A_RGB (1<<11) /* 1=RGB 0=YUV */
94#define VINO_CTRL_A_LUMA_ONLY (1<<12)
95#define VINO_CTRL_A_DEC_ENBL (1<<13) /* Decimation */
96#define VINO_CTRL_A_DEC_SCALE_MASK 0x1c000 /* bits 14:17 */
97#define VINO_CTRL_A_DEC_SCALE_SHIFT (14)
98#define VINO_CTRL_A_DEC_HOR_ONLY (1<<17) /* Horizontal only */
99#define VINO_CTRL_A_DITHER (1<<18) /* 24 -> 8 bit dither */
100#define VINO_CTRL_B_DMA_ENBL (1<<19)
101#define VINO_CTRL_B_INTERLEAVE_ENBL (1<<20)
102#define VINO_CTRL_B_SYNC_ENBL (1<<21)
103#define VINO_CTRL_B_SELECT (1<<22) /* 1=D1 0=Philips */
104#define VINO_CTRL_B_RGB (1<<23) /* 1=RGB 0=YUV */
105#define VINO_CTRL_B_LUMA_ONLY (1<<24)
106#define VINO_CTRL_B_DEC_ENBL (1<<25) /* Decimation */
107#define VINO_CTRL_B_DEC_SCALE_MASK 0x1c000000 /* bits 26:28 */
108#define VINO_CTRL_B_DEC_SCALE_SHIFT (26)
109#define VINO_CTRL_B_DEC_HOR_ONLY (1<<29) /* Decimation horizontal only */
110#define VINO_CTRL_B_DITHER (1<<30) /* ChanB 24 -> 8 bit dither */
111 u32 _pad_control;
112 volatile u32 control;
113
114#define VINO_INTSTAT_A_EOF (1<<0) /* Field transferred int */
115#define VINO_INTSTAT_A_FIFO (1<<1) /* FIFO overflow int */
116#define VINO_INTSTAT_A_EOD (1<<2) /* End of desc table int */
117#define VINO_INTSTAT_A (VINO_INTSTAT_A_EOF | \
118 VINO_INTSTAT_A_FIFO | \
119 VINO_INTSTAT_A_EOD)
120#define VINO_INTSTAT_B_EOF (1<<3) /* Field transferred int */
121#define VINO_INTSTAT_B_FIFO (1<<4) /* FIFO overflow int */
122#define VINO_INTSTAT_B_EOD (1<<5) /* End of desc table int */
123#define VINO_INTSTAT_B (VINO_INTSTAT_B_EOF | \
124 VINO_INTSTAT_B_FIFO | \
125 VINO_INTSTAT_B_EOD)
126 u32 _pad_intr_status;
127 volatile u32 intr_status;
128
129 u32 _pad_i2c_control;
130 volatile u32 i2c_control;
131 u32 _pad_i2c_data;
132 volatile u32 i2c_data;
133
134 struct sgi_vino_channel a;
135 struct sgi_vino_channel b;
136};
137
138#endif
diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c
index 9e758a8f890d..162689227a23 100644
--- a/drivers/video/hdmi.c
+++ b/drivers/video/hdmi.c
@@ -27,10 +27,12 @@
27#include <linux/export.h> 27#include <linux/export.h>
28#include <linux/hdmi.h> 28#include <linux/hdmi.h>
29#include <linux/string.h> 29#include <linux/string.h>
30#include <linux/device.h>
30 31
31static void hdmi_infoframe_checksum(void *buffer, size_t size) 32#define hdmi_log(fmt, ...) dev_printk(level, dev, fmt, ##__VA_ARGS__)
33
34static u8 hdmi_infoframe_checksum(u8 *ptr, size_t size)
32{ 35{
33 u8 *ptr = buffer;
34 u8 csum = 0; 36 u8 csum = 0;
35 size_t i; 37 size_t i;
36 38
@@ -38,7 +40,14 @@ static void hdmi_infoframe_checksum(void *buffer, size_t size)
38 for (i = 0; i < size; i++) 40 for (i = 0; i < size; i++)
39 csum += ptr[i]; 41 csum += ptr[i];
40 42
41 ptr[3] = 256 - csum; 43 return 256 - csum;
44}
45
46static void hdmi_infoframe_set_checksum(void *buffer, size_t size)
47{
48 u8 *ptr = buffer;
49
50 ptr[3] = hdmi_infoframe_checksum(buffer, size);
42} 51}
43 52
44/** 53/**
@@ -136,7 +145,7 @@ ssize_t hdmi_avi_infoframe_pack(struct hdmi_avi_infoframe *frame, void *buffer,
136 ptr[11] = frame->right_bar & 0xff; 145 ptr[11] = frame->right_bar & 0xff;
137 ptr[12] = (frame->right_bar >> 8) & 0xff; 146 ptr[12] = (frame->right_bar >> 8) & 0xff;
138 147
139 hdmi_infoframe_checksum(buffer, length); 148 hdmi_infoframe_set_checksum(buffer, length);
140 149
141 return length; 150 return length;
142} 151}
@@ -206,7 +215,7 @@ ssize_t hdmi_spd_infoframe_pack(struct hdmi_spd_infoframe *frame, void *buffer,
206 215
207 ptr[24] = frame->sdi; 216 ptr[24] = frame->sdi;
208 217
209 hdmi_infoframe_checksum(buffer, length); 218 hdmi_infoframe_set_checksum(buffer, length);
210 219
211 return length; 220 return length;
212} 221}
@@ -281,7 +290,7 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame,
281 if (frame->downmix_inhibit) 290 if (frame->downmix_inhibit)
282 ptr[4] |= BIT(7); 291 ptr[4] |= BIT(7);
283 292
284 hdmi_infoframe_checksum(buffer, length); 293 hdmi_infoframe_set_checksum(buffer, length);
285 294
286 return length; 295 return length;
287} 296}
@@ -373,7 +382,7 @@ ssize_t hdmi_vendor_infoframe_pack(struct hdmi_vendor_infoframe *frame,
373 ptr[9] = (frame->s3d_ext_data & 0xf) << 4; 382 ptr[9] = (frame->s3d_ext_data & 0xf) << 4;
374 } 383 }
375 384
376 hdmi_infoframe_checksum(buffer, length); 385 hdmi_infoframe_set_checksum(buffer, length);
377 386
378 return length; 387 return length;
379} 388}
@@ -434,3 +443,802 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, size_t size)
434 return length; 443 return length;
435} 444}
436EXPORT_SYMBOL(hdmi_infoframe_pack); 445EXPORT_SYMBOL(hdmi_infoframe_pack);
446
447static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type)
448{
449 if (type < 0x80 || type > 0x9f)
450 return "Invalid";
451 switch (type) {
452 case HDMI_INFOFRAME_TYPE_VENDOR:
453 return "Vendor";
454 case HDMI_INFOFRAME_TYPE_AVI:
455 return "Auxiliary Video Information (AVI)";
456 case HDMI_INFOFRAME_TYPE_SPD:
457 return "Source Product Description (SPD)";
458 case HDMI_INFOFRAME_TYPE_AUDIO:
459 return "Audio";
460 }
461 return "Reserved";
462}
463
464static void hdmi_infoframe_log_header(const char *level,
465 struct device *dev,
466 struct hdmi_any_infoframe *frame)
467{
468 hdmi_log("HDMI infoframe: %s, version %u, length %u\n",
469 hdmi_infoframe_type_get_name(frame->type),
470 frame->version, frame->length);
471}
472
473static const char *hdmi_colorspace_get_name(enum hdmi_colorspace colorspace)
474{
475 switch (colorspace) {
476 case HDMI_COLORSPACE_RGB:
477 return "RGB";
478 case HDMI_COLORSPACE_YUV422:
479 return "YCbCr 4:2:2";
480 case HDMI_COLORSPACE_YUV444:
481 return "YCbCr 4:4:4";
482 case HDMI_COLORSPACE_YUV420:
483 return "YCbCr 4:2:0";
484 case HDMI_COLORSPACE_RESERVED4:
485 return "Reserved (4)";
486 case HDMI_COLORSPACE_RESERVED5:
487 return "Reserved (5)";
488 case HDMI_COLORSPACE_RESERVED6:
489 return "Reserved (6)";
490 case HDMI_COLORSPACE_IDO_DEFINED:
491 return "IDO Defined";
492 }
493 return "Invalid";
494}
495
496static const char *hdmi_scan_mode_get_name(enum hdmi_scan_mode scan_mode)
497{
498 switch (scan_mode) {
499 case HDMI_SCAN_MODE_NONE:
500 return "No Data";
501 case HDMI_SCAN_MODE_OVERSCAN:
502 return "Overscan";
503 case HDMI_SCAN_MODE_UNDERSCAN:
504 return "Underscan";
505 case HDMI_SCAN_MODE_RESERVED:
506 return "Reserved";
507 }
508 return "Invalid";
509}
510
511static const char *hdmi_colorimetry_get_name(enum hdmi_colorimetry colorimetry)
512{
513 switch (colorimetry) {
514 case HDMI_COLORIMETRY_NONE:
515 return "No Data";
516 case HDMI_COLORIMETRY_ITU_601:
517 return "ITU601";
518 case HDMI_COLORIMETRY_ITU_709:
519 return "ITU709";
520 case HDMI_COLORIMETRY_EXTENDED:
521 return "Extended";
522 }
523 return "Invalid";
524}
525
526static const char *
527hdmi_picture_aspect_get_name(enum hdmi_picture_aspect picture_aspect)
528{
529 switch (picture_aspect) {
530 case HDMI_PICTURE_ASPECT_NONE:
531 return "No Data";
532 case HDMI_PICTURE_ASPECT_4_3:
533 return "4:3";
534 case HDMI_PICTURE_ASPECT_16_9:
535 return "16:9";
536 case HDMI_PICTURE_ASPECT_RESERVED:
537 return "Reserved";
538 }
539 return "Invalid";
540}
541
542static const char *
543hdmi_active_aspect_get_name(enum hdmi_active_aspect active_aspect)
544{
545 if (active_aspect < 0 || active_aspect > 0xf)
546 return "Invalid";
547
548 switch (active_aspect) {
549 case HDMI_ACTIVE_ASPECT_16_9_TOP:
550 return "16:9 Top";
551 case HDMI_ACTIVE_ASPECT_14_9_TOP:
552 return "14:9 Top";
553 case HDMI_ACTIVE_ASPECT_16_9_CENTER:
554 return "16:9 Center";
555 case HDMI_ACTIVE_ASPECT_PICTURE:
556 return "Same as Picture";
557 case HDMI_ACTIVE_ASPECT_4_3:
558 return "4:3";
559 case HDMI_ACTIVE_ASPECT_16_9:
560 return "16:9";
561 case HDMI_ACTIVE_ASPECT_14_9:
562 return "14:9";
563 case HDMI_ACTIVE_ASPECT_4_3_SP_14_9:
564 return "4:3 SP 14:9";
565 case HDMI_ACTIVE_ASPECT_16_9_SP_14_9:
566 return "16:9 SP 14:9";
567 case HDMI_ACTIVE_ASPECT_16_9_SP_4_3:
568 return "16:9 SP 4:3";
569 }
570 return "Reserved";
571}
572
573static const char *
574hdmi_extended_colorimetry_get_name(enum hdmi_extended_colorimetry ext_col)
575{
576 switch (ext_col) {
577 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_601:
578 return "xvYCC 601";
579 case HDMI_EXTENDED_COLORIMETRY_XV_YCC_709:
580 return "xvYCC 709";
581 case HDMI_EXTENDED_COLORIMETRY_S_YCC_601:
582 return "sYCC 601";
583 case HDMI_EXTENDED_COLORIMETRY_ADOBE_YCC_601:
584 return "Adobe YCC 601";
585 case HDMI_EXTENDED_COLORIMETRY_ADOBE_RGB:
586 return "Adobe RGB";
587 case HDMI_EXTENDED_COLORIMETRY_BT2020_CONST_LUM:
588 return "BT.2020 Constant Luminance";
589 case HDMI_EXTENDED_COLORIMETRY_BT2020:
590 return "BT.2020";
591 case HDMI_EXTENDED_COLORIMETRY_RESERVED:
592 return "Reserved";
593 }
594 return "Invalid";
595}
596
597static const char *
598hdmi_quantization_range_get_name(enum hdmi_quantization_range qrange)
599{
600 switch (qrange) {
601 case HDMI_QUANTIZATION_RANGE_DEFAULT:
602 return "Default";
603 case HDMI_QUANTIZATION_RANGE_LIMITED:
604 return "Limited";
605 case HDMI_QUANTIZATION_RANGE_FULL:
606 return "Full";
607 case HDMI_QUANTIZATION_RANGE_RESERVED:
608 return "Reserved";
609 }
610 return "Invalid";
611}
612
613static const char *hdmi_nups_get_name(enum hdmi_nups nups)
614{
615 switch (nups) {
616 case HDMI_NUPS_UNKNOWN:
617 return "Unknown Non-uniform Scaling";
618 case HDMI_NUPS_HORIZONTAL:
619 return "Horizontally Scaled";
620 case HDMI_NUPS_VERTICAL:
621 return "Vertically Scaled";
622 case HDMI_NUPS_BOTH:
623 return "Horizontally and Vertically Scaled";
624 }
625 return "Invalid";
626}
627
628static const char *
629hdmi_ycc_quantization_range_get_name(enum hdmi_ycc_quantization_range qrange)
630{
631 switch (qrange) {
632 case HDMI_YCC_QUANTIZATION_RANGE_LIMITED:
633 return "Limited";
634 case HDMI_YCC_QUANTIZATION_RANGE_FULL:
635 return "Full";
636 }
637 return "Invalid";
638}
639
640static const char *
641hdmi_content_type_get_name(enum hdmi_content_type content_type)
642{
643 switch (content_type) {
644 case HDMI_CONTENT_TYPE_GRAPHICS:
645 return "Graphics";
646 case HDMI_CONTENT_TYPE_PHOTO:
647 return "Photo";
648 case HDMI_CONTENT_TYPE_CINEMA:
649 return "Cinema";
650 case HDMI_CONTENT_TYPE_GAME:
651 return "Game";
652 }
653 return "Invalid";
654}
655
656/**
657 * hdmi_avi_infoframe_log() - log info of HDMI AVI infoframe
658 * @level: logging level
659 * @dev: device
660 * @frame: HDMI AVI infoframe
661 */
662static void hdmi_avi_infoframe_log(const char *level,
663 struct device *dev,
664 struct hdmi_avi_infoframe *frame)
665{
666 hdmi_infoframe_log_header(level, dev,
667 (struct hdmi_any_infoframe *)frame);
668
669 hdmi_log(" colorspace: %s\n",
670 hdmi_colorspace_get_name(frame->colorspace));
671 hdmi_log(" scan mode: %s\n",
672 hdmi_scan_mode_get_name(frame->scan_mode));
673 hdmi_log(" colorimetry: %s\n",
674 hdmi_colorimetry_get_name(frame->colorimetry));
675 hdmi_log(" picture aspect: %s\n",
676 hdmi_picture_aspect_get_name(frame->picture_aspect));
677 hdmi_log(" active aspect: %s\n",
678 hdmi_active_aspect_get_name(frame->active_aspect));
679 hdmi_log(" itc: %s\n", frame->itc ? "IT Content" : "No Data");
680 hdmi_log(" extended colorimetry: %s\n",
681 hdmi_extended_colorimetry_get_name(frame->extended_colorimetry));
682 hdmi_log(" quantization range: %s\n",
683 hdmi_quantization_range_get_name(frame->quantization_range));
684 hdmi_log(" nups: %s\n", hdmi_nups_get_name(frame->nups));
685 hdmi_log(" video code: %u\n", frame->video_code);
686 hdmi_log(" ycc quantization range: %s\n",
687 hdmi_ycc_quantization_range_get_name(frame->ycc_quantization_range));
688 hdmi_log(" hdmi content type: %s\n",
689 hdmi_content_type_get_name(frame->content_type));
690 hdmi_log(" pixel repeat: %u\n", frame->pixel_repeat);
691 hdmi_log(" bar top %u, bottom %u, left %u, right %u\n",
692 frame->top_bar, frame->bottom_bar,
693 frame->left_bar, frame->right_bar);
694}
695
696static const char *hdmi_spd_sdi_get_name(enum hdmi_spd_sdi sdi)
697{
698 if (sdi < 0 || sdi > 0xff)
699 return "Invalid";
700 switch (sdi) {
701 case HDMI_SPD_SDI_UNKNOWN:
702 return "Unknown";
703 case HDMI_SPD_SDI_DSTB:
704 return "Digital STB";
705 case HDMI_SPD_SDI_DVDP:
706 return "DVD Player";
707 case HDMI_SPD_SDI_DVHS:
708 return "D-VHS";
709 case HDMI_SPD_SDI_HDDVR:
710 return "HDD Videorecorder";
711 case HDMI_SPD_SDI_DVC:
712 return "DVC";
713 case HDMI_SPD_SDI_DSC:
714 return "DSC";
715 case HDMI_SPD_SDI_VCD:
716 return "Video CD";
717 case HDMI_SPD_SDI_GAME:
718 return "Game";
719 case HDMI_SPD_SDI_PC:
720 return "PC General";
721 case HDMI_SPD_SDI_BD:
722 return "Blu-Ray Disc (BD)";
723 case HDMI_SPD_SDI_SACD:
724 return "Super Audio CD";
725 case HDMI_SPD_SDI_HDDVD:
726 return "HD DVD";
727 case HDMI_SPD_SDI_PMP:
728 return "PMP";
729 }
730 return "Reserved";
731}
732
733/**
734 * hdmi_spd_infoframe_log() - log info of HDMI SPD infoframe
735 * @level: logging level
736 * @dev: device
737 * @frame: HDMI SPD infoframe
738 */
739static void hdmi_spd_infoframe_log(const char *level,
740 struct device *dev,
741 struct hdmi_spd_infoframe *frame)
742{
743 u8 buf[17];
744
745 hdmi_infoframe_log_header(level, dev,
746 (struct hdmi_any_infoframe *)frame);
747
748 memset(buf, 0, sizeof(buf));
749
750 strncpy(buf, frame->vendor, 8);
751 hdmi_log(" vendor: %s\n", buf);
752 strncpy(buf, frame->product, 16);
753 hdmi_log(" product: %s\n", buf);
754 hdmi_log(" source device information: %s (0x%x)\n",
755 hdmi_spd_sdi_get_name(frame->sdi), frame->sdi);
756}
757
758static const char *
759hdmi_audio_coding_type_get_name(enum hdmi_audio_coding_type coding_type)
760{
761 switch (coding_type) {
762 case HDMI_AUDIO_CODING_TYPE_STREAM:
763 return "Refer to Stream Header";
764 case HDMI_AUDIO_CODING_TYPE_PCM:
765 return "PCM";
766 case HDMI_AUDIO_CODING_TYPE_AC3:
767 return "AC-3";
768 case HDMI_AUDIO_CODING_TYPE_MPEG1:
769 return "MPEG1";
770 case HDMI_AUDIO_CODING_TYPE_MP3:
771 return "MP3";
772 case HDMI_AUDIO_CODING_TYPE_MPEG2:
773 return "MPEG2";
774 case HDMI_AUDIO_CODING_TYPE_AAC_LC:
775 return "AAC";
776 case HDMI_AUDIO_CODING_TYPE_DTS:
777 return "DTS";
778 case HDMI_AUDIO_CODING_TYPE_ATRAC:
779 return "ATRAC";
780 case HDMI_AUDIO_CODING_TYPE_DSD:
781 return "One Bit Audio";
782 case HDMI_AUDIO_CODING_TYPE_EAC3:
783 return "Dolby Digital +";
784 case HDMI_AUDIO_CODING_TYPE_DTS_HD:
785 return "DTS-HD";
786 case HDMI_AUDIO_CODING_TYPE_MLP:
787 return "MAT (MLP)";
788 case HDMI_AUDIO_CODING_TYPE_DST:
789 return "DST";
790 case HDMI_AUDIO_CODING_TYPE_WMA_PRO:
791 return "WMA PRO";
792 case HDMI_AUDIO_CODING_TYPE_CXT:
793 return "Refer to CXT";
794 }
795 return "Invalid";
796}
797
798static const char *
799hdmi_audio_sample_size_get_name(enum hdmi_audio_sample_size sample_size)
800{
801 switch (sample_size) {
802 case HDMI_AUDIO_SAMPLE_SIZE_STREAM:
803 return "Refer to Stream Header";
804 case HDMI_AUDIO_SAMPLE_SIZE_16:
805 return "16 bit";
806 case HDMI_AUDIO_SAMPLE_SIZE_20:
807 return "20 bit";
808 case HDMI_AUDIO_SAMPLE_SIZE_24:
809 return "24 bit";
810 }
811 return "Invalid";
812}
813
814static const char *
815hdmi_audio_sample_frequency_get_name(enum hdmi_audio_sample_frequency freq)
816{
817 switch (freq) {
818 case HDMI_AUDIO_SAMPLE_FREQUENCY_STREAM:
819 return "Refer to Stream Header";
820 case HDMI_AUDIO_SAMPLE_FREQUENCY_32000:
821 return "32 kHz";
822 case HDMI_AUDIO_SAMPLE_FREQUENCY_44100:
823 return "44.1 kHz (CD)";
824 case HDMI_AUDIO_SAMPLE_FREQUENCY_48000:
825 return "48 kHz";
826 case HDMI_AUDIO_SAMPLE_FREQUENCY_88200:
827 return "88.2 kHz";
828 case HDMI_AUDIO_SAMPLE_FREQUENCY_96000:
829 return "96 kHz";
830 case HDMI_AUDIO_SAMPLE_FREQUENCY_176400:
831 return "176.4 kHz";
832 case HDMI_AUDIO_SAMPLE_FREQUENCY_192000:
833 return "192 kHz";
834 }
835 return "Invalid";
836}
837
838static const char *
839hdmi_audio_coding_type_ext_get_name(enum hdmi_audio_coding_type_ext ctx)
840{
841 if (ctx < 0 || ctx > 0x1f)
842 return "Invalid";
843
844 switch (ctx) {
845 case HDMI_AUDIO_CODING_TYPE_EXT_CT:
846 return "Refer to CT";
847 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC:
848 return "HE AAC";
849 case HDMI_AUDIO_CODING_TYPE_EXT_HE_AAC_V2:
850 return "HE AAC v2";
851 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG_SURROUND:
852 return "MPEG SURROUND";
853 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC:
854 return "MPEG-4 HE AAC";
855 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_V2:
856 return "MPEG-4 HE AAC v2";
857 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC:
858 return "MPEG-4 AAC LC";
859 case HDMI_AUDIO_CODING_TYPE_EXT_DRA:
860 return "DRA";
861 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_HE_AAC_SURROUND:
862 return "MPEG-4 HE AAC + MPEG Surround";
863 case HDMI_AUDIO_CODING_TYPE_EXT_MPEG4_AAC_LC_SURROUND:
864 return "MPEG-4 AAC LC + MPEG Surround";
865 }
866 return "Reserved";
867}
868
869/**
870 * hdmi_audio_infoframe_log() - log info of HDMI AUDIO infoframe
871 * @level: logging level
872 * @dev: device
873 * @frame: HDMI AUDIO infoframe
874 */
875static void hdmi_audio_infoframe_log(const char *level,
876 struct device *dev,
877 struct hdmi_audio_infoframe *frame)
878{
879 hdmi_infoframe_log_header(level, dev,
880 (struct hdmi_any_infoframe *)frame);
881
882 if (frame->channels)
883 hdmi_log(" channels: %u\n", frame->channels - 1);
884 else
885 hdmi_log(" channels: Refer to stream header\n");
886 hdmi_log(" coding type: %s\n",
887 hdmi_audio_coding_type_get_name(frame->coding_type));
888 hdmi_log(" sample size: %s\n",
889 hdmi_audio_sample_size_get_name(frame->sample_size));
890 hdmi_log(" sample frequency: %s\n",
891 hdmi_audio_sample_frequency_get_name(frame->sample_frequency));
892 hdmi_log(" coding type ext: %s\n",
893 hdmi_audio_coding_type_ext_get_name(frame->coding_type_ext));
894 hdmi_log(" channel allocation: 0x%x\n",
895 frame->channel_allocation);
896 hdmi_log(" level shift value: %u dB\n",
897 frame->level_shift_value);
898 hdmi_log(" downmix inhibit: %s\n",
899 frame->downmix_inhibit ? "Yes" : "No");
900}
901
902static const char *
903hdmi_3d_structure_get_name(enum hdmi_3d_structure s3d_struct)
904{
905 if (s3d_struct < 0 || s3d_struct > 0xf)
906 return "Invalid";
907
908 switch (s3d_struct) {
909 case HDMI_3D_STRUCTURE_FRAME_PACKING:
910 return "Frame Packing";
911 case HDMI_3D_STRUCTURE_FIELD_ALTERNATIVE:
912 return "Field Alternative";
913 case HDMI_3D_STRUCTURE_LINE_ALTERNATIVE:
914 return "Line Alternative";
915 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_FULL:
916 return "Side-by-side (Full)";
917 case HDMI_3D_STRUCTURE_L_DEPTH:
918 return "L + Depth";
919 case HDMI_3D_STRUCTURE_L_DEPTH_GFX_GFX_DEPTH:
920 return "L + Depth + Graphics + Graphics-depth";
921 case HDMI_3D_STRUCTURE_TOP_AND_BOTTOM:
922 return "Top-and-Bottom";
923 case HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF:
924 return "Side-by-side (Half)";
925 default:
926 break;
927 }
928 return "Reserved";
929}
930
931/**
932 * hdmi_vendor_infoframe_log() - log info of HDMI VENDOR infoframe
933 * @level: logging level
934 * @dev: device
935 * @frame: HDMI VENDOR infoframe
936 */
937static void
938hdmi_vendor_any_infoframe_log(const char *level,
939 struct device *dev,
940 union hdmi_vendor_any_infoframe *frame)
941{
942 struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
943
944 hdmi_infoframe_log_header(level, dev,
945 (struct hdmi_any_infoframe *)frame);
946
947 if (frame->any.oui != HDMI_IEEE_OUI) {
948 hdmi_log(" not a HDMI vendor infoframe\n");
949 return;
950 }
951 if (hvf->vic == 0 && hvf->s3d_struct == HDMI_3D_STRUCTURE_INVALID) {
952 hdmi_log(" empty frame\n");
953 return;
954 }
955
956 if (hvf->vic)
957 hdmi_log(" HDMI VIC: %u\n", hvf->vic);
958 if (hvf->s3d_struct != HDMI_3D_STRUCTURE_INVALID) {
959 hdmi_log(" 3D structure: %s\n",
960 hdmi_3d_structure_get_name(hvf->s3d_struct));
961 if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF)
962 hdmi_log(" 3D extension data: %d\n",
963 hvf->s3d_ext_data);
964 }
965}
966
967/**
968 * hdmi_infoframe_log() - log info of HDMI infoframe
969 * @level: logging level
970 * @dev: device
971 * @frame: HDMI infoframe
972 */
973void hdmi_infoframe_log(const char *level,
974 struct device *dev,
975 union hdmi_infoframe *frame)
976{
977 switch (frame->any.type) {
978 case HDMI_INFOFRAME_TYPE_AVI:
979 hdmi_avi_infoframe_log(level, dev, &frame->avi);
980 break;
981 case HDMI_INFOFRAME_TYPE_SPD:
982 hdmi_spd_infoframe_log(level, dev, &frame->spd);
983 break;
984 case HDMI_INFOFRAME_TYPE_AUDIO:
985 hdmi_audio_infoframe_log(level, dev, &frame->audio);
986 break;
987 case HDMI_INFOFRAME_TYPE_VENDOR:
988 hdmi_vendor_any_infoframe_log(level, dev, &frame->vendor);
989 break;
990 }
991}
992EXPORT_SYMBOL(hdmi_infoframe_log);
993
994/**
995 * hdmi_avi_infoframe_unpack() - unpack binary buffer to a HDMI AVI infoframe
996 * @buffer: source buffer
997 * @frame: HDMI AVI infoframe
998 *
999 * Unpacks the information contained in binary @buffer into a structured
1000 * @frame of the HDMI Auxiliary Video (AVI) information frame.
1001 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1002 * specification.
1003 *
1004 * Returns 0 on success or a negative error code on failure.
1005 */
1006static int hdmi_avi_infoframe_unpack(struct hdmi_avi_infoframe *frame,
1007 void *buffer)
1008{
1009 u8 *ptr = buffer;
1010 int ret;
1011
1012 if (ptr[0] != HDMI_INFOFRAME_TYPE_AVI ||
1013 ptr[1] != 2 ||
1014 ptr[2] != HDMI_AVI_INFOFRAME_SIZE)
1015 return -EINVAL;
1016
1017 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AVI)) != 0)
1018 return -EINVAL;
1019
1020 ret = hdmi_avi_infoframe_init(frame);
1021 if (ret)
1022 return ret;
1023
1024 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1025
1026 frame->colorspace = (ptr[0] >> 5) & 0x3;
1027 if (ptr[0] & 0x10)
1028 frame->active_aspect = ptr[1] & 0xf;
1029 if (ptr[0] & 0x8) {
1030 frame->top_bar = (ptr[5] << 8) + ptr[6];
1031 frame->bottom_bar = (ptr[7] << 8) + ptr[8];
1032 }
1033 if (ptr[0] & 0x4) {
1034 frame->left_bar = (ptr[9] << 8) + ptr[10];
1035 frame->right_bar = (ptr[11] << 8) + ptr[12];
1036 }
1037 frame->scan_mode = ptr[0] & 0x3;
1038
1039 frame->colorimetry = (ptr[1] >> 6) & 0x3;
1040 frame->picture_aspect = (ptr[1] >> 4) & 0x3;
1041 frame->active_aspect = ptr[1] & 0xf;
1042
1043 frame->itc = ptr[2] & 0x80 ? true : false;
1044 frame->extended_colorimetry = (ptr[2] >> 4) & 0x7;
1045 frame->quantization_range = (ptr[2] >> 2) & 0x3;
1046 frame->nups = ptr[2] & 0x3;
1047
1048 frame->video_code = ptr[3] & 0x7f;
1049 frame->ycc_quantization_range = (ptr[4] >> 6) & 0x3;
1050 frame->content_type = (ptr[4] >> 4) & 0x3;
1051
1052 frame->pixel_repeat = ptr[4] & 0xf;
1053
1054 return 0;
1055}
1056
1057/**
1058 * hdmi_spd_infoframe_unpack() - unpack binary buffer to a HDMI SPD infoframe
1059 * @buffer: source buffer
1060 * @frame: HDMI SPD infoframe
1061 *
1062 * Unpacks the information contained in binary @buffer into a structured
1063 * @frame of the HDMI Source Product Description (SPD) information frame.
1064 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1065 * specification.
1066 *
1067 * Returns 0 on success or a negative error code on failure.
1068 */
1069static int hdmi_spd_infoframe_unpack(struct hdmi_spd_infoframe *frame,
1070 void *buffer)
1071{
1072 u8 *ptr = buffer;
1073 int ret;
1074
1075 if (ptr[0] != HDMI_INFOFRAME_TYPE_SPD ||
1076 ptr[1] != 1 ||
1077 ptr[2] != HDMI_SPD_INFOFRAME_SIZE) {
1078 return -EINVAL;
1079 }
1080
1081 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(SPD)) != 0)
1082 return -EINVAL;
1083
1084 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1085
1086 ret = hdmi_spd_infoframe_init(frame, ptr, ptr + 8);
1087 if (ret)
1088 return ret;
1089
1090 frame->sdi = ptr[24];
1091
1092 return 0;
1093}
1094
1095/**
1096 * hdmi_audio_infoframe_unpack() - unpack binary buffer to a HDMI AUDIO infoframe
1097 * @buffer: source buffer
1098 * @frame: HDMI Audio infoframe
1099 *
1100 * Unpacks the information contained in binary @buffer into a structured
1101 * @frame of the HDMI Audio information frame.
1102 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1103 * specification.
1104 *
1105 * Returns 0 on success or a negative error code on failure.
1106 */
1107static int hdmi_audio_infoframe_unpack(struct hdmi_audio_infoframe *frame,
1108 void *buffer)
1109{
1110 u8 *ptr = buffer;
1111 int ret;
1112
1113 if (ptr[0] != HDMI_INFOFRAME_TYPE_AUDIO ||
1114 ptr[1] != 1 ||
1115 ptr[2] != HDMI_AUDIO_INFOFRAME_SIZE) {
1116 return -EINVAL;
1117 }
1118
1119 if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(AUDIO)) != 0)
1120 return -EINVAL;
1121
1122 ret = hdmi_audio_infoframe_init(frame);
1123 if (ret)
1124 return ret;
1125
1126 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1127
1128 frame->channels = ptr[0] & 0x7;
1129 frame->coding_type = (ptr[0] >> 4) & 0xf;
1130 frame->sample_size = ptr[1] & 0x3;
1131 frame->sample_frequency = (ptr[1] >> 2) & 0x7;
1132 frame->coding_type_ext = ptr[2] & 0x1f;
1133 frame->channel_allocation = ptr[3];
1134 frame->level_shift_value = (ptr[4] >> 3) & 0xf;
1135 frame->downmix_inhibit = ptr[4] & 0x80 ? true : false;
1136
1137 return 0;
1138}
1139
1140/**
1141 * hdmi_vendor_infoframe_unpack() - unpack binary buffer to a HDMI vendor infoframe
1142 * @buffer: source buffer
1143 * @frame: HDMI Vendor infoframe
1144 *
1145 * Unpacks the information contained in binary @buffer into a structured
1146 * @frame of the HDMI Vendor information frame.
1147 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1148 * specification.
1149 *
1150 * Returns 0 on success or a negative error code on failure.
1151 */
1152static int
1153hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame,
1154 void *buffer)
1155{
1156 u8 *ptr = buffer;
1157 size_t length;
1158 int ret;
1159 u8 hdmi_video_format;
1160 struct hdmi_vendor_infoframe *hvf = &frame->hdmi;
1161
1162 if (ptr[0] != HDMI_INFOFRAME_TYPE_VENDOR ||
1163 ptr[1] != 1 ||
1164 (ptr[2] != 5 && ptr[2] != 6))
1165 return -EINVAL;
1166
1167 length = ptr[2];
1168
1169 if (hdmi_infoframe_checksum(buffer,
1170 HDMI_INFOFRAME_HEADER_SIZE + length) != 0)
1171 return -EINVAL;
1172
1173 ptr += HDMI_INFOFRAME_HEADER_SIZE;
1174
1175 /* HDMI OUI */
1176 if ((ptr[0] != 0x03) ||
1177 (ptr[1] != 0x0c) ||
1178 (ptr[2] != 0x00))
1179 return -EINVAL;
1180
1181 hdmi_video_format = ptr[3] >> 5;
1182
1183 if (hdmi_video_format > 0x2)
1184 return -EINVAL;
1185
1186 ret = hdmi_vendor_infoframe_init(hvf);
1187 if (ret)
1188 return ret;
1189
1190 hvf->length = length;
1191
1192 if (hdmi_video_format == 0x1) {
1193 hvf->vic = ptr[4];
1194 } else if (hdmi_video_format == 0x2) {
1195 hvf->s3d_struct = ptr[4] >> 4;
1196 if (hvf->s3d_struct >= HDMI_3D_STRUCTURE_SIDE_BY_SIDE_HALF) {
1197 if (length == 6)
1198 hvf->s3d_ext_data = ptr[5] >> 4;
1199 else
1200 return -EINVAL;
1201 }
1202 }
1203
1204 return 0;
1205}
1206
1207/**
1208 * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe
1209 * @buffer: source buffer
1210 * @frame: HDMI infoframe
1211 *
1212 * Unpacks the information contained in binary buffer @buffer into a structured
1213 * @frame of a HDMI infoframe.
1214 * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4
1215 * specification.
1216 *
1217 * Returns 0 on success or a negative error code on failure.
1218 */
1219int hdmi_infoframe_unpack(union hdmi_infoframe *frame, void *buffer)
1220{
1221 int ret;
1222 u8 *ptr = buffer;
1223
1224 switch (ptr[0]) {
1225 case HDMI_INFOFRAME_TYPE_AVI:
1226 ret = hdmi_avi_infoframe_unpack(&frame->avi, buffer);
1227 break;
1228 case HDMI_INFOFRAME_TYPE_SPD:
1229 ret = hdmi_spd_infoframe_unpack(&frame->spd, buffer);
1230 break;
1231 case HDMI_INFOFRAME_TYPE_AUDIO:
1232 ret = hdmi_audio_infoframe_unpack(&frame->audio, buffer);
1233 break;
1234 case HDMI_INFOFRAME_TYPE_VENDOR:
1235 ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer);
1236 break;
1237 default:
1238 ret = -EINVAL;
1239 break;
1240 }
1241
1242 return ret;
1243}
1244EXPORT_SYMBOL(hdmi_infoframe_unpack);